1 /* Target-struct-independent code to start (run) and stop an inferior
4 Copyright (C) 1986-2021 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"
76 /* Prototypes for local functions */
78 static void sig_print_info (enum gdb_signal
);
80 static void sig_print_header (void);
82 static void follow_inferior_reset_breakpoints (void);
84 static bool currently_stepping (struct thread_info
*tp
);
86 static void insert_hp_step_resume_breakpoint_at_frame (struct frame_info
*);
88 static void insert_step_resume_breakpoint_at_caller (struct frame_info
*);
90 static void insert_longjmp_resume_breakpoint (struct gdbarch
*, CORE_ADDR
);
92 static bool maybe_software_singlestep (struct gdbarch
*gdbarch
);
94 static void resume (gdb_signal sig
);
96 static void wait_for_inferior (inferior
*inf
);
98 /* Asynchronous signal handler registered as event loop source for
99 when we have pending events ready to be passed to the core. */
100 static struct async_event_handler
*infrun_async_inferior_event_token
;
102 /* Stores whether infrun_async was previously enabled or disabled.
103 Starts off as -1, indicating "never enabled/disabled". */
104 static int infrun_is_async
= -1;
109 infrun_async (int enable
)
111 if (infrun_is_async
!= enable
)
113 infrun_is_async
= enable
;
115 infrun_debug_printf ("enable=%d", enable
);
118 mark_async_event_handler (infrun_async_inferior_event_token
);
120 clear_async_event_handler (infrun_async_inferior_event_token
);
127 mark_infrun_async_event_handler (void)
129 mark_async_event_handler (infrun_async_inferior_event_token
);
132 /* When set, stop the 'step' command if we enter a function which has
133 no line number information. The normal behavior is that we step
134 over such function. */
135 bool step_stop_if_no_debug
= false;
137 show_step_stop_if_no_debug (struct ui_file
*file
, int from_tty
,
138 struct cmd_list_element
*c
, const char *value
)
140 fprintf_filtered (file
, _("Mode of the step operation is %s.\n"), value
);
143 /* proceed and normal_stop use this to notify the user when the
144 inferior stopped in a different thread than it had been running
147 static ptid_t previous_inferior_ptid
;
149 /* If set (default for legacy reasons), when following a fork, GDB
150 will detach from one of the fork branches, child or parent.
151 Exactly which branch is detached depends on 'set follow-fork-mode'
154 static bool detach_fork
= true;
156 bool debug_infrun
= false;
158 show_debug_infrun (struct ui_file
*file
, int from_tty
,
159 struct cmd_list_element
*c
, const char *value
)
161 fprintf_filtered (file
, _("Inferior debugging is %s.\n"), value
);
164 /* Support for disabling address space randomization. */
166 bool disable_randomization
= true;
169 show_disable_randomization (struct ui_file
*file
, int from_tty
,
170 struct cmd_list_element
*c
, const char *value
)
172 if (target_supports_disable_randomization ())
173 fprintf_filtered (file
,
174 _("Disabling randomization of debuggee's "
175 "virtual address space is %s.\n"),
178 fputs_filtered (_("Disabling randomization of debuggee's "
179 "virtual address space is unsupported on\n"
180 "this platform.\n"), file
);
184 set_disable_randomization (const char *args
, int from_tty
,
185 struct cmd_list_element
*c
)
187 if (!target_supports_disable_randomization ())
188 error (_("Disabling randomization of debuggee's "
189 "virtual address space is unsupported on\n"
193 /* User interface for non-stop mode. */
195 bool non_stop
= false;
196 static bool non_stop_1
= false;
199 set_non_stop (const char *args
, int from_tty
,
200 struct cmd_list_element
*c
)
202 if (target_has_execution ())
204 non_stop_1
= non_stop
;
205 error (_("Cannot change this setting while the inferior is running."));
208 non_stop
= non_stop_1
;
212 show_non_stop (struct ui_file
*file
, int from_tty
,
213 struct cmd_list_element
*c
, const char *value
)
215 fprintf_filtered (file
,
216 _("Controlling the inferior in non-stop mode is %s.\n"),
220 /* "Observer mode" is somewhat like a more extreme version of
221 non-stop, in which all GDB operations that might affect the
222 target's execution have been disabled. */
224 static bool observer_mode
= false;
225 static bool observer_mode_1
= false;
228 set_observer_mode (const char *args
, int from_tty
,
229 struct cmd_list_element
*c
)
231 if (target_has_execution ())
233 observer_mode_1
= observer_mode
;
234 error (_("Cannot change this setting while the inferior is running."));
237 observer_mode
= observer_mode_1
;
239 may_write_registers
= !observer_mode
;
240 may_write_memory
= !observer_mode
;
241 may_insert_breakpoints
= !observer_mode
;
242 may_insert_tracepoints
= !observer_mode
;
243 /* We can insert fast tracepoints in or out of observer mode,
244 but enable them if we're going into this mode. */
246 may_insert_fast_tracepoints
= true;
247 may_stop
= !observer_mode
;
248 update_target_permissions ();
250 /* Going *into* observer mode we must force non-stop, then
251 going out we leave it that way. */
254 pagination_enabled
= 0;
255 non_stop
= non_stop_1
= true;
259 printf_filtered (_("Observer mode is now %s.\n"),
260 (observer_mode
? "on" : "off"));
264 show_observer_mode (struct ui_file
*file
, int from_tty
,
265 struct cmd_list_element
*c
, const char *value
)
267 fprintf_filtered (file
, _("Observer mode is %s.\n"), value
);
270 /* This updates the value of observer mode based on changes in
271 permissions. Note that we are deliberately ignoring the values of
272 may-write-registers and may-write-memory, since the user may have
273 reason to enable these during a session, for instance to turn on a
274 debugging-related global. */
277 update_observer_mode (void)
279 bool newval
= (!may_insert_breakpoints
280 && !may_insert_tracepoints
281 && may_insert_fast_tracepoints
285 /* Let the user know if things change. */
286 if (newval
!= observer_mode
)
287 printf_filtered (_("Observer mode is now %s.\n"),
288 (newval
? "on" : "off"));
290 observer_mode
= observer_mode_1
= newval
;
293 /* Tables of how to react to signals; the user sets them. */
295 static unsigned char signal_stop
[GDB_SIGNAL_LAST
];
296 static unsigned char signal_print
[GDB_SIGNAL_LAST
];
297 static unsigned char signal_program
[GDB_SIGNAL_LAST
];
299 /* Table of signals that are registered with "catch signal". A
300 non-zero entry indicates that the signal is caught by some "catch
302 static unsigned char signal_catch
[GDB_SIGNAL_LAST
];
304 /* Table of signals that the target may silently handle.
305 This is automatically determined from the flags above,
306 and simply cached here. */
307 static unsigned char signal_pass
[GDB_SIGNAL_LAST
];
309 #define SET_SIGS(nsigs,sigs,flags) \
311 int signum = (nsigs); \
312 while (signum-- > 0) \
313 if ((sigs)[signum]) \
314 (flags)[signum] = 1; \
317 #define UNSET_SIGS(nsigs,sigs,flags) \
319 int signum = (nsigs); \
320 while (signum-- > 0) \
321 if ((sigs)[signum]) \
322 (flags)[signum] = 0; \
325 /* Update the target's copy of SIGNAL_PROGRAM. The sole purpose of
326 this function is to avoid exporting `signal_program'. */
329 update_signals_program_target (void)
331 target_program_signals (signal_program
);
334 /* Value to pass to target_resume() to cause all threads to resume. */
336 #define RESUME_ALL minus_one_ptid
338 /* Command list pointer for the "stop" placeholder. */
340 static struct cmd_list_element
*stop_command
;
342 /* Nonzero if we want to give control to the user when we're notified
343 of shared library events by the dynamic linker. */
344 int stop_on_solib_events
;
346 /* Enable or disable optional shared library event breakpoints
347 as appropriate when the above flag is changed. */
350 set_stop_on_solib_events (const char *args
,
351 int from_tty
, struct cmd_list_element
*c
)
353 update_solib_breakpoints ();
357 show_stop_on_solib_events (struct ui_file
*file
, int from_tty
,
358 struct cmd_list_element
*c
, const char *value
)
360 fprintf_filtered (file
, _("Stopping for shared library events is %s.\n"),
364 /* True after stop if current stack frame should be printed. */
366 static bool stop_print_frame
;
368 /* This is a cached copy of the target/ptid/waitstatus of the last
369 event returned by target_wait()/deprecated_target_wait_hook().
370 This information is returned by get_last_target_status(). */
371 static process_stratum_target
*target_last_proc_target
;
372 static ptid_t target_last_wait_ptid
;
373 static struct target_waitstatus target_last_waitstatus
;
375 void init_thread_stepping_state (struct thread_info
*tss
);
377 static const char follow_fork_mode_child
[] = "child";
378 static const char follow_fork_mode_parent
[] = "parent";
380 static const char *const follow_fork_mode_kind_names
[] = {
381 follow_fork_mode_child
,
382 follow_fork_mode_parent
,
386 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
388 show_follow_fork_mode_string (struct ui_file
*file
, int from_tty
,
389 struct cmd_list_element
*c
, const char *value
)
391 fprintf_filtered (file
,
392 _("Debugger response to a program "
393 "call of fork or vfork is \"%s\".\n"),
398 /* Handle changes to the inferior list based on the type of fork,
399 which process is being followed, and whether the other process
400 should be detached. On entry inferior_ptid must be the ptid of
401 the fork parent. At return inferior_ptid is the ptid of the
402 followed inferior. */
405 follow_fork_inferior (bool follow_child
, bool detach_fork
)
407 target_waitkind fork_kind
= inferior_thread ()->pending_follow
.kind
;
408 gdb_assert (fork_kind
== TARGET_WAITKIND_FORKED
409 || fork_kind
== TARGET_WAITKIND_VFORKED
);
410 bool has_vforked
= fork_kind
== TARGET_WAITKIND_VFORKED
;
411 ptid_t parent_ptid
= inferior_ptid
;
412 ptid_t child_ptid
= inferior_thread ()->pending_follow
.value
.related_pid
;
415 && !non_stop
/* Non-stop always resumes both branches. */
416 && current_ui
->prompt_state
== PROMPT_BLOCKED
417 && !(follow_child
|| detach_fork
|| sched_multi
))
419 /* The parent stays blocked inside the vfork syscall until the
420 child execs or exits. If we don't let the child run, then
421 the parent stays blocked. If we're telling the parent to run
422 in the foreground, the user will not be able to ctrl-c to get
423 back the terminal, effectively hanging the debug session. */
424 fprintf_filtered (gdb_stderr
, _("\
425 Can not resume the parent process over vfork in the foreground while\n\
426 holding the child stopped. Try \"set detach-on-fork\" or \
427 \"set schedule-multiple\".\n"));
431 inferior
*parent_inf
= current_inferior ();
432 inferior
*child_inf
= nullptr;
436 /* Detach new forked process? */
439 /* Before detaching from the child, remove all breakpoints
440 from it. If we forked, then this has already been taken
441 care of by infrun.c. If we vforked however, any
442 breakpoint inserted in the parent is visible in the
443 child, even those added while stopped in a vfork
444 catchpoint. This will remove the breakpoints from the
445 parent also, but they'll be reinserted below. */
448 /* Keep breakpoints list in sync. */
449 remove_breakpoints_inf (current_inferior ());
452 if (print_inferior_events
)
454 /* Ensure that we have a process ptid. */
455 ptid_t process_ptid
= ptid_t (child_ptid
.pid ());
457 target_terminal::ours_for_output ();
458 fprintf_filtered (gdb_stdlog
,
459 _("[Detaching after %s from child %s]\n"),
460 has_vforked
? "vfork" : "fork",
461 target_pid_to_str (process_ptid
).c_str ());
466 /* Add process to GDB's tables. */
467 child_inf
= add_inferior (child_ptid
.pid ());
469 child_inf
->attach_flag
= parent_inf
->attach_flag
;
470 copy_terminal_info (child_inf
, parent_inf
);
471 child_inf
->gdbarch
= parent_inf
->gdbarch
;
472 copy_inferior_target_desc_info (child_inf
, parent_inf
);
474 child_inf
->symfile_flags
= SYMFILE_NO_READ
;
476 /* If this is a vfork child, then the address-space is
477 shared with the parent. */
480 child_inf
->pspace
= parent_inf
->pspace
;
481 child_inf
->aspace
= parent_inf
->aspace
;
483 exec_on_vfork (child_inf
);
485 /* The parent will be frozen until the child is done
486 with the shared region. Keep track of the
488 child_inf
->vfork_parent
= parent_inf
;
489 child_inf
->pending_detach
= 0;
490 parent_inf
->vfork_child
= child_inf
;
491 parent_inf
->pending_detach
= 0;
495 child_inf
->aspace
= new_address_space ();
496 child_inf
->pspace
= new program_space (child_inf
->aspace
);
497 child_inf
->removable
= 1;
498 clone_program_space (child_inf
->pspace
, parent_inf
->pspace
);
504 /* If we detached from the child, then we have to be careful
505 to not insert breakpoints in the parent until the child
506 is done with the shared memory region. However, if we're
507 staying attached to the child, then we can and should
508 insert breakpoints, so that we can debug it. A
509 subsequent child exec or exit is enough to know when does
510 the child stops using the parent's address space. */
511 parent_inf
->waiting_for_vfork_done
= detach_fork
;
512 parent_inf
->pspace
->breakpoints_not_allowed
= detach_fork
;
517 /* Follow the child. */
519 if (print_inferior_events
)
521 std::string parent_pid
= target_pid_to_str (parent_ptid
);
522 std::string child_pid
= target_pid_to_str (child_ptid
);
524 target_terminal::ours_for_output ();
525 fprintf_filtered (gdb_stdlog
,
526 _("[Attaching after %s %s to child %s]\n"),
528 has_vforked
? "vfork" : "fork",
532 /* Add the new inferior first, so that the target_detach below
533 doesn't unpush the target. */
535 child_inf
= add_inferior (child_ptid
.pid ());
537 child_inf
->attach_flag
= parent_inf
->attach_flag
;
538 copy_terminal_info (child_inf
, parent_inf
);
539 child_inf
->gdbarch
= parent_inf
->gdbarch
;
540 copy_inferior_target_desc_info (child_inf
, parent_inf
);
544 /* If this is a vfork child, then the address-space is shared
546 child_inf
->aspace
= parent_inf
->aspace
;
547 child_inf
->pspace
= parent_inf
->pspace
;
549 exec_on_vfork (child_inf
);
551 else if (detach_fork
)
553 /* We follow the child and detach from the parent: move the parent's
554 program space to the child. This simplifies some things, like
555 doing "next" over fork() and landing on the expected line in the
556 child (note, that is broken with "set detach-on-fork off").
558 Before assigning brand new spaces for the parent, remove
559 breakpoints from it: because the new pspace won't match
560 currently inserted locations, the normal detach procedure
561 wouldn't remove them, and we would leave them inserted when
563 remove_breakpoints_inf (parent_inf
);
565 child_inf
->aspace
= parent_inf
->aspace
;
566 child_inf
->pspace
= parent_inf
->pspace
;
567 parent_inf
->aspace
= new_address_space ();
568 parent_inf
->pspace
= new program_space (parent_inf
->aspace
);
569 clone_program_space (parent_inf
->pspace
, child_inf
->pspace
);
571 /* The parent inferior is still the current one, so keep things
573 set_current_program_space (parent_inf
->pspace
);
577 child_inf
->aspace
= new_address_space ();
578 child_inf
->pspace
= new program_space (child_inf
->aspace
);
579 child_inf
->removable
= 1;
580 child_inf
->symfile_flags
= SYMFILE_NO_READ
;
581 clone_program_space (child_inf
->pspace
, parent_inf
->pspace
);
585 gdb_assert (current_inferior () == parent_inf
);
587 /* If we are setting up an inferior for the child, target_follow_fork is
588 responsible for pushing the appropriate targets on the new inferior's
589 target stack and adding the initial thread (with ptid CHILD_PTID).
591 If we are not setting up an inferior for the child (because following
592 the parent and detach_fork is true), it is responsible for detaching
594 target_follow_fork (child_inf
, child_ptid
, fork_kind
, follow_child
,
597 /* target_follow_fork must leave the parent as the current inferior. If we
598 want to follow the child, we make it the current one below. */
599 gdb_assert (current_inferior () == parent_inf
);
601 /* If there is a child inferior, target_follow_fork must have created a thread
603 if (child_inf
!= nullptr)
604 gdb_assert (!child_inf
->thread_list
.empty ());
606 /* Detach the parent if needed. */
609 /* If we're vforking, we want to hold on to the parent until
610 the child exits or execs. At child exec or exit time we
611 can remove the old breakpoints from the parent and detach
612 or resume debugging it. Otherwise, detach the parent now;
613 we'll want to reuse it's program/address spaces, but we
614 can't set them to the child before removing breakpoints
615 from the parent, otherwise, the breakpoints module could
616 decide to remove breakpoints from the wrong process (since
617 they'd be assigned to the same address space). */
621 gdb_assert (child_inf
->vfork_parent
== NULL
);
622 gdb_assert (parent_inf
->vfork_child
== NULL
);
623 child_inf
->vfork_parent
= parent_inf
;
624 child_inf
->pending_detach
= 0;
625 parent_inf
->vfork_child
= child_inf
;
626 parent_inf
->pending_detach
= detach_fork
;
627 parent_inf
->waiting_for_vfork_done
= 0;
629 else if (detach_fork
)
631 if (print_inferior_events
)
633 /* Ensure that we have a process ptid. */
634 ptid_t process_ptid
= ptid_t (parent_ptid
.pid ());
636 target_terminal::ours_for_output ();
637 fprintf_filtered (gdb_stdlog
,
638 _("[Detaching after fork from "
640 target_pid_to_str (process_ptid
).c_str ());
643 target_detach (parent_inf
, 0);
647 /* If we ended up creating a new inferior, call post_create_inferior to inform
648 the various subcomponents. */
649 if (child_inf
!= nullptr)
651 /* If FOLLOW_CHILD, we leave CHILD_INF as the current inferior
652 (do not restore the parent as the current inferior). */
653 gdb::optional
<scoped_restore_current_thread
> maybe_restore
;
656 maybe_restore
.emplace ();
658 switch_to_thread (*child_inf
->threads ().begin ());
659 post_create_inferior (0);
665 /* Tell the target to follow the fork we're stopped at. Returns true
666 if the inferior should be resumed; false, if the target for some
667 reason decided it's best not to resume. */
672 bool follow_child
= (follow_fork_mode_string
== follow_fork_mode_child
);
673 bool should_resume
= true;
674 struct thread_info
*tp
;
676 /* Copy user stepping state to the new inferior thread. FIXME: the
677 followed fork child thread should have a copy of most of the
678 parent thread structure's run control related fields, not just these.
679 Initialized to avoid "may be used uninitialized" warnings from gcc. */
680 struct breakpoint
*step_resume_breakpoint
= NULL
;
681 struct breakpoint
*exception_resume_breakpoint
= NULL
;
682 CORE_ADDR step_range_start
= 0;
683 CORE_ADDR step_range_end
= 0;
684 int current_line
= 0;
685 symtab
*current_symtab
= NULL
;
686 struct frame_id step_frame_id
= { 0 };
687 struct thread_fsm
*thread_fsm
= NULL
;
691 process_stratum_target
*wait_target
;
693 struct target_waitstatus wait_status
;
695 /* Get the last target status returned by target_wait(). */
696 get_last_target_status (&wait_target
, &wait_ptid
, &wait_status
);
698 /* If not stopped at a fork event, then there's nothing else to
700 if (wait_status
.kind
!= TARGET_WAITKIND_FORKED
701 && wait_status
.kind
!= TARGET_WAITKIND_VFORKED
)
704 /* Check if we switched over from WAIT_PTID, since the event was
706 if (wait_ptid
!= minus_one_ptid
707 && (current_inferior ()->process_target () != wait_target
708 || inferior_ptid
!= wait_ptid
))
710 /* We did. Switch back to WAIT_PTID thread, to tell the
711 target to follow it (in either direction). We'll
712 afterwards refuse to resume, and inform the user what
714 thread_info
*wait_thread
= find_thread_ptid (wait_target
, wait_ptid
);
715 switch_to_thread (wait_thread
);
716 should_resume
= false;
720 tp
= inferior_thread ();
722 /* If there were any forks/vforks that were caught and are now to be
723 followed, then do so now. */
724 switch (tp
->pending_follow
.kind
)
726 case TARGET_WAITKIND_FORKED
:
727 case TARGET_WAITKIND_VFORKED
:
729 ptid_t parent
, child
;
731 /* If the user did a next/step, etc, over a fork call,
732 preserve the stepping state in the fork child. */
733 if (follow_child
&& should_resume
)
735 step_resume_breakpoint
= clone_momentary_breakpoint
736 (tp
->control
.step_resume_breakpoint
);
737 step_range_start
= tp
->control
.step_range_start
;
738 step_range_end
= tp
->control
.step_range_end
;
739 current_line
= tp
->current_line
;
740 current_symtab
= tp
->current_symtab
;
741 step_frame_id
= tp
->control
.step_frame_id
;
742 exception_resume_breakpoint
743 = clone_momentary_breakpoint (tp
->control
.exception_resume_breakpoint
);
744 thread_fsm
= tp
->thread_fsm
;
746 /* For now, delete the parent's sr breakpoint, otherwise,
747 parent/child sr breakpoints are considered duplicates,
748 and the child version will not be installed. Remove
749 this when the breakpoints module becomes aware of
750 inferiors and address spaces. */
751 delete_step_resume_breakpoint (tp
);
752 tp
->control
.step_range_start
= 0;
753 tp
->control
.step_range_end
= 0;
754 tp
->control
.step_frame_id
= null_frame_id
;
755 delete_exception_resume_breakpoint (tp
);
756 tp
->thread_fsm
= NULL
;
759 parent
= inferior_ptid
;
760 child
= tp
->pending_follow
.value
.related_pid
;
762 process_stratum_target
*parent_targ
= tp
->inf
->process_target ();
763 /* Set up inferior(s) as specified by the caller, and tell the
764 target to do whatever is necessary to follow either parent
766 if (follow_fork_inferior (follow_child
, detach_fork
))
768 /* Target refused to follow, or there's some other reason
769 we shouldn't resume. */
774 /* This pending follow fork event is now handled, one way
775 or another. The previous selected thread may be gone
776 from the lists by now, but if it is still around, need
777 to clear the pending follow request. */
778 tp
= find_thread_ptid (parent_targ
, parent
);
780 tp
->pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
782 /* This makes sure we don't try to apply the "Switched
783 over from WAIT_PID" logic above. */
784 nullify_last_target_wait_ptid ();
786 /* If we followed the child, switch to it... */
789 thread_info
*child_thr
= find_thread_ptid (parent_targ
, child
);
790 switch_to_thread (child_thr
);
792 /* ... and preserve the stepping state, in case the
793 user was stepping over the fork call. */
796 tp
= inferior_thread ();
797 tp
->control
.step_resume_breakpoint
798 = step_resume_breakpoint
;
799 tp
->control
.step_range_start
= step_range_start
;
800 tp
->control
.step_range_end
= step_range_end
;
801 tp
->current_line
= current_line
;
802 tp
->current_symtab
= current_symtab
;
803 tp
->control
.step_frame_id
= step_frame_id
;
804 tp
->control
.exception_resume_breakpoint
805 = exception_resume_breakpoint
;
806 tp
->thread_fsm
= thread_fsm
;
810 /* If we get here, it was because we're trying to
811 resume from a fork catchpoint, but, the user
812 has switched threads away from the thread that
813 forked. In that case, the resume command
814 issued is most likely not applicable to the
815 child, so just warn, and refuse to resume. */
816 warning (_("Not resuming: switched threads "
817 "before following fork child."));
820 /* Reset breakpoints in the child as appropriate. */
821 follow_inferior_reset_breakpoints ();
826 case TARGET_WAITKIND_SPURIOUS
:
827 /* Nothing to follow. */
830 internal_error (__FILE__
, __LINE__
,
831 "Unexpected pending_follow.kind %d\n",
832 tp
->pending_follow
.kind
);
836 return should_resume
;
840 follow_inferior_reset_breakpoints (void)
842 struct thread_info
*tp
= inferior_thread ();
844 /* Was there a step_resume breakpoint? (There was if the user
845 did a "next" at the fork() call.) If so, explicitly reset its
846 thread number. Cloned step_resume breakpoints are disabled on
847 creation, so enable it here now that it is associated with the
850 step_resumes are a form of bp that are made to be per-thread.
851 Since we created the step_resume bp when the parent process
852 was being debugged, and now are switching to the child process,
853 from the breakpoint package's viewpoint, that's a switch of
854 "threads". We must update the bp's notion of which thread
855 it is for, or it'll be ignored when it triggers. */
857 if (tp
->control
.step_resume_breakpoint
)
859 breakpoint_re_set_thread (tp
->control
.step_resume_breakpoint
);
860 tp
->control
.step_resume_breakpoint
->loc
->enabled
= 1;
863 /* Treat exception_resume breakpoints like step_resume breakpoints. */
864 if (tp
->control
.exception_resume_breakpoint
)
866 breakpoint_re_set_thread (tp
->control
.exception_resume_breakpoint
);
867 tp
->control
.exception_resume_breakpoint
->loc
->enabled
= 1;
870 /* Reinsert all breakpoints in the child. The user may have set
871 breakpoints after catching the fork, in which case those
872 were never set in the child, but only in the parent. This makes
873 sure the inserted breakpoints match the breakpoint list. */
875 breakpoint_re_set ();
876 insert_breakpoints ();
879 /* The child has exited or execed: resume THREAD, a thread of the parent,
880 if it was meant to be executing. */
883 proceed_after_vfork_done (thread_info
*thread
)
885 if (thread
->state
== THREAD_RUNNING
886 && !thread
->executing ()
887 && !thread
->stop_requested
888 && thread
->stop_signal () == GDB_SIGNAL_0
)
890 infrun_debug_printf ("resuming vfork parent thread %s",
891 target_pid_to_str (thread
->ptid
).c_str ());
893 switch_to_thread (thread
);
894 clear_proceed_status (0);
895 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
899 /* Called whenever we notice an exec or exit event, to handle
900 detaching or resuming a vfork parent. */
903 handle_vfork_child_exec_or_exit (int exec
)
905 struct inferior
*inf
= current_inferior ();
907 if (inf
->vfork_parent
)
909 inferior
*resume_parent
= nullptr;
911 /* This exec or exit marks the end of the shared memory region
912 between the parent and the child. Break the bonds. */
913 inferior
*vfork_parent
= inf
->vfork_parent
;
914 inf
->vfork_parent
->vfork_child
= NULL
;
915 inf
->vfork_parent
= NULL
;
917 /* If the user wanted to detach from the parent, now is the
919 if (vfork_parent
->pending_detach
)
921 struct program_space
*pspace
;
922 struct address_space
*aspace
;
924 /* follow-fork child, detach-on-fork on. */
926 vfork_parent
->pending_detach
= 0;
928 scoped_restore_current_pspace_and_thread restore_thread
;
930 /* We're letting loose of the parent. */
931 thread_info
*tp
= any_live_thread_of_inferior (vfork_parent
);
932 switch_to_thread (tp
);
934 /* We're about to detach from the parent, which implicitly
935 removes breakpoints from its address space. There's a
936 catch here: we want to reuse the spaces for the child,
937 but, parent/child are still sharing the pspace at this
938 point, although the exec in reality makes the kernel give
939 the child a fresh set of new pages. The problem here is
940 that the breakpoints module being unaware of this, would
941 likely chose the child process to write to the parent
942 address space. Swapping the child temporarily away from
943 the spaces has the desired effect. Yes, this is "sort
946 pspace
= inf
->pspace
;
947 aspace
= inf
->aspace
;
951 if (print_inferior_events
)
954 = target_pid_to_str (ptid_t (vfork_parent
->pid
));
956 target_terminal::ours_for_output ();
960 fprintf_filtered (gdb_stdlog
,
961 _("[Detaching vfork parent %s "
962 "after child exec]\n"), pidstr
.c_str ());
966 fprintf_filtered (gdb_stdlog
,
967 _("[Detaching vfork parent %s "
968 "after child exit]\n"), pidstr
.c_str ());
972 target_detach (vfork_parent
, 0);
975 inf
->pspace
= pspace
;
976 inf
->aspace
= aspace
;
980 /* We're staying attached to the parent, so, really give the
981 child a new address space. */
982 inf
->pspace
= new program_space (maybe_new_address_space ());
983 inf
->aspace
= inf
->pspace
->aspace
;
985 set_current_program_space (inf
->pspace
);
987 resume_parent
= vfork_parent
;
991 /* If this is a vfork child exiting, then the pspace and
992 aspaces were shared with the parent. Since we're
993 reporting the process exit, we'll be mourning all that is
994 found in the address space, and switching to null_ptid,
995 preparing to start a new inferior. But, since we don't
996 want to clobber the parent's address/program spaces, we
997 go ahead and create a new one for this exiting
1000 /* Switch to no-thread while running clone_program_space, so
1001 that clone_program_space doesn't want to read the
1002 selected frame of a dead process. */
1003 scoped_restore_current_thread restore_thread
;
1004 switch_to_no_thread ();
1006 inf
->pspace
= new program_space (maybe_new_address_space ());
1007 inf
->aspace
= inf
->pspace
->aspace
;
1008 set_current_program_space (inf
->pspace
);
1010 inf
->symfile_flags
= SYMFILE_NO_READ
;
1011 clone_program_space (inf
->pspace
, vfork_parent
->pspace
);
1013 resume_parent
= vfork_parent
;
1016 gdb_assert (current_program_space
== inf
->pspace
);
1018 if (non_stop
&& resume_parent
!= nullptr)
1020 /* If the user wanted the parent to be running, let it go
1022 scoped_restore_current_thread restore_thread
;
1024 infrun_debug_printf ("resuming vfork parent process %d",
1025 resume_parent
->pid
);
1027 for (thread_info
*thread
: resume_parent
->threads ())
1028 proceed_after_vfork_done (thread
);
1033 /* Enum strings for "set|show follow-exec-mode". */
1035 static const char follow_exec_mode_new
[] = "new";
1036 static const char follow_exec_mode_same
[] = "same";
1037 static const char *const follow_exec_mode_names
[] =
1039 follow_exec_mode_new
,
1040 follow_exec_mode_same
,
1044 static const char *follow_exec_mode_string
= follow_exec_mode_same
;
1046 show_follow_exec_mode_string (struct ui_file
*file
, int from_tty
,
1047 struct cmd_list_element
*c
, const char *value
)
1049 fprintf_filtered (file
, _("Follow exec mode is \"%s\".\n"), value
);
1052 /* EXEC_FILE_TARGET is assumed to be non-NULL. */
1055 follow_exec (ptid_t ptid
, const char *exec_file_target
)
1057 int pid
= ptid
.pid ();
1058 ptid_t process_ptid
;
1060 /* Switch terminal for any messages produced e.g. by
1061 breakpoint_re_set. */
1062 target_terminal::ours_for_output ();
1064 /* This is an exec event that we actually wish to pay attention to.
1065 Refresh our symbol table to the newly exec'd program, remove any
1066 momentary bp's, etc.
1068 If there are breakpoints, they aren't really inserted now,
1069 since the exec() transformed our inferior into a fresh set
1072 We want to preserve symbolic breakpoints on the list, since
1073 we have hopes that they can be reset after the new a.out's
1074 symbol table is read.
1076 However, any "raw" breakpoints must be removed from the list
1077 (e.g., the solib bp's), since their address is probably invalid
1080 And, we DON'T want to call delete_breakpoints() here, since
1081 that may write the bp's "shadow contents" (the instruction
1082 value that was overwritten with a TRAP instruction). Since
1083 we now have a new a.out, those shadow contents aren't valid. */
1085 mark_breakpoints_out ();
1087 /* The target reports the exec event to the main thread, even if
1088 some other thread does the exec, and even if the main thread was
1089 stopped or already gone. We may still have non-leader threads of
1090 the process on our list. E.g., on targets that don't have thread
1091 exit events (like remote); or on native Linux in non-stop mode if
1092 there were only two threads in the inferior and the non-leader
1093 one is the one that execs (and nothing forces an update of the
1094 thread list up to here). When debugging remotely, it's best to
1095 avoid extra traffic, when possible, so avoid syncing the thread
1096 list with the target, and instead go ahead and delete all threads
1097 of the process but one that reported the event. Note this must
1098 be done before calling update_breakpoints_after_exec, as
1099 otherwise clearing the threads' resources would reference stale
1100 thread breakpoints -- it may have been one of these threads that
1101 stepped across the exec. We could just clear their stepping
1102 states, but as long as we're iterating, might as well delete
1103 them. Deleting them now rather than at the next user-visible
1104 stop provides a nicer sequence of events for user and MI
1106 for (thread_info
*th
: all_threads_safe ())
1107 if (th
->ptid
.pid () == pid
&& th
->ptid
!= ptid
)
1110 /* We also need to clear any left over stale state for the
1111 leader/event thread. E.g., if there was any step-resume
1112 breakpoint or similar, it's gone now. We cannot truly
1113 step-to-next statement through an exec(). */
1114 thread_info
*th
= inferior_thread ();
1115 th
->control
.step_resume_breakpoint
= NULL
;
1116 th
->control
.exception_resume_breakpoint
= NULL
;
1117 th
->control
.single_step_breakpoints
= NULL
;
1118 th
->control
.step_range_start
= 0;
1119 th
->control
.step_range_end
= 0;
1121 /* The user may have had the main thread held stopped in the
1122 previous image (e.g., schedlock on, or non-stop). Release
1124 th
->stop_requested
= 0;
1126 update_breakpoints_after_exec ();
1128 /* What is this a.out's name? */
1129 process_ptid
= ptid_t (pid
);
1130 printf_unfiltered (_("%s is executing new program: %s\n"),
1131 target_pid_to_str (process_ptid
).c_str (),
1134 /* We've followed the inferior through an exec. Therefore, the
1135 inferior has essentially been killed & reborn. */
1137 breakpoint_init_inferior (inf_execd
);
1139 gdb::unique_xmalloc_ptr
<char> exec_file_host
1140 = exec_file_find (exec_file_target
, NULL
);
1142 /* If we were unable to map the executable target pathname onto a host
1143 pathname, tell the user that. Otherwise GDB's subsequent behavior
1144 is confusing. Maybe it would even be better to stop at this point
1145 so that the user can specify a file manually before continuing. */
1146 if (exec_file_host
== NULL
)
1147 warning (_("Could not load symbols for executable %s.\n"
1148 "Do you need \"set sysroot\"?"),
1151 /* Reset the shared library package. This ensures that we get a
1152 shlib event when the child reaches "_start", at which point the
1153 dld will have had a chance to initialize the child. */
1154 /* Also, loading a symbol file below may trigger symbol lookups, and
1155 we don't want those to be satisfied by the libraries of the
1156 previous incarnation of this process. */
1157 no_shared_libraries (NULL
, 0);
1159 struct inferior
*inf
= current_inferior ();
1161 if (follow_exec_mode_string
== follow_exec_mode_new
)
1163 /* The user wants to keep the old inferior and program spaces
1164 around. Create a new fresh one, and switch to it. */
1166 /* Do exit processing for the original inferior before setting the new
1167 inferior's pid. Having two inferiors with the same pid would confuse
1168 find_inferior_p(t)id. Transfer the terminal state and info from the
1169 old to the new inferior. */
1170 inferior
*new_inferior
= add_inferior_with_spaces ();
1172 swap_terminal_info (new_inferior
, inf
);
1173 exit_inferior_silent (inf
);
1175 new_inferior
->pid
= pid
;
1176 target_follow_exec (new_inferior
, ptid
, exec_file_target
);
1178 /* We continue with the new inferior. */
1183 /* The old description may no longer be fit for the new image.
1184 E.g, a 64-bit process exec'ed a 32-bit process. Clear the
1185 old description; we'll read a new one below. No need to do
1186 this on "follow-exec-mode new", as the old inferior stays
1187 around (its description is later cleared/refetched on
1189 target_clear_description ();
1190 target_follow_exec (inf
, ptid
, exec_file_target
);
1193 gdb_assert (current_inferior () == inf
);
1194 gdb_assert (current_program_space
== inf
->pspace
);
1196 /* Attempt to open the exec file. SYMFILE_DEFER_BP_RESET is used
1197 because the proper displacement for a PIE (Position Independent
1198 Executable) main symbol file will only be computed by
1199 solib_create_inferior_hook below. breakpoint_re_set would fail
1200 to insert the breakpoints with the zero displacement. */
1201 try_open_exec_file (exec_file_host
.get (), inf
, SYMFILE_DEFER_BP_RESET
);
1203 /* If the target can specify a description, read it. Must do this
1204 after flipping to the new executable (because the target supplied
1205 description must be compatible with the executable's
1206 architecture, and the old executable may e.g., be 32-bit, while
1207 the new one 64-bit), and before anything involving memory or
1209 target_find_description ();
1211 gdb::observers::inferior_execd
.notify (inf
);
1213 breakpoint_re_set ();
1215 /* Reinsert all breakpoints. (Those which were symbolic have
1216 been reset to the proper address in the new a.out, thanks
1217 to symbol_file_command...). */
1218 insert_breakpoints ();
1220 /* The next resume of this inferior should bring it to the shlib
1221 startup breakpoints. (If the user had also set bp's on
1222 "main" from the old (parent) process, then they'll auto-
1223 matically get reset there in the new process.). */
1226 /* The chain of threads that need to do a step-over operation to get
1227 past e.g., a breakpoint. What technique is used to step over the
1228 breakpoint/watchpoint does not matter -- all threads end up in the
1229 same queue, to maintain rough temporal order of execution, in order
1230 to avoid starvation, otherwise, we could e.g., find ourselves
1231 constantly stepping the same couple threads past their breakpoints
1232 over and over, if the single-step finish fast enough. */
1233 thread_step_over_list global_thread_step_over_list
;
1235 /* Bit flags indicating what the thread needs to step over. */
1237 enum step_over_what_flag
1239 /* Step over a breakpoint. */
1240 STEP_OVER_BREAKPOINT
= 1,
1242 /* Step past a non-continuable watchpoint, in order to let the
1243 instruction execute so we can evaluate the watchpoint
1245 STEP_OVER_WATCHPOINT
= 2
1247 DEF_ENUM_FLAGS_TYPE (enum step_over_what_flag
, step_over_what
);
1249 /* Info about an instruction that is being stepped over. */
1251 struct step_over_info
1253 /* If we're stepping past a breakpoint, this is the address space
1254 and address of the instruction the breakpoint is set at. We'll
1255 skip inserting all breakpoints here. Valid iff ASPACE is
1257 const address_space
*aspace
= nullptr;
1258 CORE_ADDR address
= 0;
1260 /* The instruction being stepped over triggers a nonsteppable
1261 watchpoint. If true, we'll skip inserting watchpoints. */
1262 int nonsteppable_watchpoint_p
= 0;
1264 /* The thread's global number. */
1268 /* The step-over info of the location that is being stepped over.
1270 Note that with async/breakpoint always-inserted mode, a user might
1271 set a new breakpoint/watchpoint/etc. exactly while a breakpoint is
1272 being stepped over. As setting a new breakpoint inserts all
1273 breakpoints, we need to make sure the breakpoint being stepped over
1274 isn't inserted then. We do that by only clearing the step-over
1275 info when the step-over is actually finished (or aborted).
1277 Presently GDB can only step over one breakpoint at any given time.
1278 Given threads that can't run code in the same address space as the
1279 breakpoint's can't really miss the breakpoint, GDB could be taught
1280 to step-over at most one breakpoint per address space (so this info
1281 could move to the address space object if/when GDB is extended).
1282 The set of breakpoints being stepped over will normally be much
1283 smaller than the set of all breakpoints, so a flag in the
1284 breakpoint location structure would be wasteful. A separate list
1285 also saves complexity and run-time, as otherwise we'd have to go
1286 through all breakpoint locations clearing their flag whenever we
1287 start a new sequence. Similar considerations weigh against storing
1288 this info in the thread object. Plus, not all step overs actually
1289 have breakpoint locations -- e.g., stepping past a single-step
1290 breakpoint, or stepping to complete a non-continuable
1292 static struct step_over_info step_over_info
;
1294 /* Record the address of the breakpoint/instruction we're currently
1296 N.B. We record the aspace and address now, instead of say just the thread,
1297 because when we need the info later the thread may be running. */
1300 set_step_over_info (const address_space
*aspace
, CORE_ADDR address
,
1301 int nonsteppable_watchpoint_p
,
1304 step_over_info
.aspace
= aspace
;
1305 step_over_info
.address
= address
;
1306 step_over_info
.nonsteppable_watchpoint_p
= nonsteppable_watchpoint_p
;
1307 step_over_info
.thread
= thread
;
1310 /* Called when we're not longer stepping over a breakpoint / an
1311 instruction, so all breakpoints are free to be (re)inserted. */
1314 clear_step_over_info (void)
1316 infrun_debug_printf ("clearing step over info");
1317 step_over_info
.aspace
= NULL
;
1318 step_over_info
.address
= 0;
1319 step_over_info
.nonsteppable_watchpoint_p
= 0;
1320 step_over_info
.thread
= -1;
1326 stepping_past_instruction_at (struct address_space
*aspace
,
1329 return (step_over_info
.aspace
!= NULL
1330 && breakpoint_address_match (aspace
, address
,
1331 step_over_info
.aspace
,
1332 step_over_info
.address
));
1338 thread_is_stepping_over_breakpoint (int thread
)
1340 return (step_over_info
.thread
!= -1
1341 && thread
== step_over_info
.thread
);
1347 stepping_past_nonsteppable_watchpoint (void)
1349 return step_over_info
.nonsteppable_watchpoint_p
;
1352 /* Returns true if step-over info is valid. */
1355 step_over_info_valid_p (void)
1357 return (step_over_info
.aspace
!= NULL
1358 || stepping_past_nonsteppable_watchpoint ());
1362 /* Displaced stepping. */
1364 /* In non-stop debugging mode, we must take special care to manage
1365 breakpoints properly; in particular, the traditional strategy for
1366 stepping a thread past a breakpoint it has hit is unsuitable.
1367 'Displaced stepping' is a tactic for stepping one thread past a
1368 breakpoint it has hit while ensuring that other threads running
1369 concurrently will hit the breakpoint as they should.
1371 The traditional way to step a thread T off a breakpoint in a
1372 multi-threaded program in all-stop mode is as follows:
1374 a0) Initially, all threads are stopped, and breakpoints are not
1376 a1) We single-step T, leaving breakpoints uninserted.
1377 a2) We insert breakpoints, and resume all threads.
1379 In non-stop debugging, however, this strategy is unsuitable: we
1380 don't want to have to stop all threads in the system in order to
1381 continue or step T past a breakpoint. Instead, we use displaced
1384 n0) Initially, T is stopped, other threads are running, and
1385 breakpoints are inserted.
1386 n1) We copy the instruction "under" the breakpoint to a separate
1387 location, outside the main code stream, making any adjustments
1388 to the instruction, register, and memory state as directed by
1390 n2) We single-step T over the instruction at its new location.
1391 n3) We adjust the resulting register and memory state as directed
1392 by T's architecture. This includes resetting T's PC to point
1393 back into the main instruction stream.
1396 This approach depends on the following gdbarch methods:
1398 - gdbarch_max_insn_length and gdbarch_displaced_step_location
1399 indicate where to copy the instruction, and how much space must
1400 be reserved there. We use these in step n1.
1402 - gdbarch_displaced_step_copy_insn copies a instruction to a new
1403 address, and makes any necessary adjustments to the instruction,
1404 register contents, and memory. We use this in step n1.
1406 - gdbarch_displaced_step_fixup adjusts registers and memory after
1407 we have successfully single-stepped the instruction, to yield the
1408 same effect the instruction would have had if we had executed it
1409 at its original address. We use this in step n3.
1411 The gdbarch_displaced_step_copy_insn and
1412 gdbarch_displaced_step_fixup functions must be written so that
1413 copying an instruction with gdbarch_displaced_step_copy_insn,
1414 single-stepping across the copied instruction, and then applying
1415 gdbarch_displaced_insn_fixup should have the same effects on the
1416 thread's memory and registers as stepping the instruction in place
1417 would have. Exactly which responsibilities fall to the copy and
1418 which fall to the fixup is up to the author of those functions.
1420 See the comments in gdbarch.sh for details.
1422 Note that displaced stepping and software single-step cannot
1423 currently be used in combination, although with some care I think
1424 they could be made to. Software single-step works by placing
1425 breakpoints on all possible subsequent instructions; if the
1426 displaced instruction is a PC-relative jump, those breakpoints
1427 could fall in very strange places --- on pages that aren't
1428 executable, or at addresses that are not proper instruction
1429 boundaries. (We do generally let other threads run while we wait
1430 to hit the software single-step breakpoint, and they might
1431 encounter such a corrupted instruction.) One way to work around
1432 this would be to have gdbarch_displaced_step_copy_insn fully
1433 simulate the effect of PC-relative instructions (and return NULL)
1434 on architectures that use software single-stepping.
1436 In non-stop mode, we can have independent and simultaneous step
1437 requests, so more than one thread may need to simultaneously step
1438 over a breakpoint. The current implementation assumes there is
1439 only one scratch space per process. In this case, we have to
1440 serialize access to the scratch space. If thread A wants to step
1441 over a breakpoint, but we are currently waiting for some other
1442 thread to complete a displaced step, we leave thread A stopped and
1443 place it in the displaced_step_request_queue. Whenever a displaced
1444 step finishes, we pick the next thread in the queue and start a new
1445 displaced step operation on it. See displaced_step_prepare and
1446 displaced_step_finish for details. */
1448 /* Return true if THREAD is doing a displaced step. */
1451 displaced_step_in_progress_thread (thread_info
*thread
)
1453 gdb_assert (thread
!= NULL
);
1455 return thread
->displaced_step_state
.in_progress ();
1458 /* Return true if INF has a thread doing a displaced step. */
1461 displaced_step_in_progress (inferior
*inf
)
1463 return inf
->displaced_step_state
.in_progress_count
> 0;
1466 /* Return true if any thread is doing a displaced step. */
1469 displaced_step_in_progress_any_thread ()
1471 for (inferior
*inf
: all_non_exited_inferiors ())
1473 if (displaced_step_in_progress (inf
))
1481 infrun_inferior_exit (struct inferior
*inf
)
1483 inf
->displaced_step_state
.reset ();
1487 infrun_inferior_execd (inferior
*inf
)
1489 /* If some threads where was doing a displaced step in this inferior at the
1490 moment of the exec, they no longer exist. Even if the exec'ing thread
1491 doing a displaced step, we don't want to to any fixup nor restore displaced
1492 stepping buffer bytes. */
1493 inf
->displaced_step_state
.reset ();
1495 for (thread_info
*thread
: inf
->threads ())
1496 thread
->displaced_step_state
.reset ();
1498 /* Since an in-line step is done with everything else stopped, if there was
1499 one in progress at the time of the exec, it must have been the exec'ing
1501 clear_step_over_info ();
1504 /* If ON, and the architecture supports it, GDB will use displaced
1505 stepping to step over breakpoints. If OFF, or if the architecture
1506 doesn't support it, GDB will instead use the traditional
1507 hold-and-step approach. If AUTO (which is the default), GDB will
1508 decide which technique to use to step over breakpoints depending on
1509 whether the target works in a non-stop way (see use_displaced_stepping). */
1511 static enum auto_boolean can_use_displaced_stepping
= AUTO_BOOLEAN_AUTO
;
1514 show_can_use_displaced_stepping (struct ui_file
*file
, int from_tty
,
1515 struct cmd_list_element
*c
,
1518 if (can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
)
1519 fprintf_filtered (file
,
1520 _("Debugger's willingness to use displaced stepping "
1521 "to step over breakpoints is %s (currently %s).\n"),
1522 value
, target_is_non_stop_p () ? "on" : "off");
1524 fprintf_filtered (file
,
1525 _("Debugger's willingness to use displaced stepping "
1526 "to step over breakpoints is %s.\n"), value
);
1529 /* Return true if the gdbarch implements the required methods to use
1530 displaced stepping. */
1533 gdbarch_supports_displaced_stepping (gdbarch
*arch
)
1535 /* Only check for the presence of `prepare`. The gdbarch verification ensures
1536 that if `prepare` is provided, so is `finish`. */
1537 return gdbarch_displaced_step_prepare_p (arch
);
1540 /* Return non-zero if displaced stepping can/should be used to step
1541 over breakpoints of thread TP. */
1544 use_displaced_stepping (thread_info
*tp
)
1546 /* If the user disabled it explicitly, don't use displaced stepping. */
1547 if (can_use_displaced_stepping
== AUTO_BOOLEAN_FALSE
)
1550 /* If "auto", only use displaced stepping if the target operates in a non-stop
1552 if (can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
1553 && !target_is_non_stop_p ())
1556 gdbarch
*gdbarch
= get_thread_regcache (tp
)->arch ();
1558 /* If the architecture doesn't implement displaced stepping, don't use
1560 if (!gdbarch_supports_displaced_stepping (gdbarch
))
1563 /* If recording, don't use displaced stepping. */
1564 if (find_record_target () != nullptr)
1567 /* If displaced stepping failed before for this inferior, don't bother trying
1569 if (tp
->inf
->displaced_step_state
.failed_before
)
1575 /* Simple function wrapper around displaced_step_thread_state::reset. */
1578 displaced_step_reset (displaced_step_thread_state
*displaced
)
1580 displaced
->reset ();
1583 /* A cleanup that wraps displaced_step_reset. We use this instead of, say,
1584 SCOPE_EXIT, because it needs to be discardable with "cleanup.release ()". */
1586 using displaced_step_reset_cleanup
= FORWARD_SCOPE_EXIT (displaced_step_reset
);
1591 displaced_step_dump_bytes (const gdb_byte
*buf
, size_t len
)
1595 for (size_t i
= 0; i
< len
; i
++)
1598 ret
+= string_printf ("%02x", buf
[i
]);
1600 ret
+= string_printf (" %02x", buf
[i
]);
1606 /* Prepare to single-step, using displaced stepping.
1608 Note that we cannot use displaced stepping when we have a signal to
1609 deliver. If we have a signal to deliver and an instruction to step
1610 over, then after the step, there will be no indication from the
1611 target whether the thread entered a signal handler or ignored the
1612 signal and stepped over the instruction successfully --- both cases
1613 result in a simple SIGTRAP. In the first case we mustn't do a
1614 fixup, and in the second case we must --- but we can't tell which.
1615 Comments in the code for 'random signals' in handle_inferior_event
1616 explain how we handle this case instead.
1618 Returns DISPLACED_STEP_PREPARE_STATUS_OK if preparing was successful -- this
1619 thread is going to be stepped now; DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
1620 if displaced stepping this thread got queued; or
1621 DISPLACED_STEP_PREPARE_STATUS_CANT if this instruction can't be displaced
1624 static displaced_step_prepare_status
1625 displaced_step_prepare_throw (thread_info
*tp
)
1627 regcache
*regcache
= get_thread_regcache (tp
);
1628 struct gdbarch
*gdbarch
= regcache
->arch ();
1629 displaced_step_thread_state
&disp_step_thread_state
1630 = tp
->displaced_step_state
;
1632 /* We should never reach this function if the architecture does not
1633 support displaced stepping. */
1634 gdb_assert (gdbarch_supports_displaced_stepping (gdbarch
));
1636 /* Nor if the thread isn't meant to step over a breakpoint. */
1637 gdb_assert (tp
->control
.trap_expected
);
1639 /* Disable range stepping while executing in the scratch pad. We
1640 want a single-step even if executing the displaced instruction in
1641 the scratch buffer lands within the stepping range (e.g., a
1643 tp
->control
.may_range_step
= 0;
1645 /* We are about to start a displaced step for this thread. If one is already
1646 in progress, something's wrong. */
1647 gdb_assert (!disp_step_thread_state
.in_progress ());
1649 if (tp
->inf
->displaced_step_state
.unavailable
)
1651 /* The gdbarch tells us it's not worth asking to try a prepare because
1652 it is likely that it will return unavailable, so don't bother asking. */
1654 displaced_debug_printf ("deferring step of %s",
1655 target_pid_to_str (tp
->ptid
).c_str ());
1657 global_thread_step_over_chain_enqueue (tp
);
1658 return DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
;
1661 displaced_debug_printf ("displaced-stepping %s now",
1662 target_pid_to_str (tp
->ptid
).c_str ());
1664 scoped_restore_current_thread restore_thread
;
1666 switch_to_thread (tp
);
1668 CORE_ADDR original_pc
= regcache_read_pc (regcache
);
1669 CORE_ADDR displaced_pc
;
1671 displaced_step_prepare_status status
1672 = gdbarch_displaced_step_prepare (gdbarch
, tp
, displaced_pc
);
1674 if (status
== DISPLACED_STEP_PREPARE_STATUS_CANT
)
1676 displaced_debug_printf ("failed to prepare (%s)",
1677 target_pid_to_str (tp
->ptid
).c_str ());
1679 return DISPLACED_STEP_PREPARE_STATUS_CANT
;
1681 else if (status
== DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
)
1683 /* Not enough displaced stepping resources available, defer this
1684 request by placing it the queue. */
1686 displaced_debug_printf ("not enough resources available, "
1687 "deferring step of %s",
1688 target_pid_to_str (tp
->ptid
).c_str ());
1690 global_thread_step_over_chain_enqueue (tp
);
1692 return DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
;
1695 gdb_assert (status
== DISPLACED_STEP_PREPARE_STATUS_OK
);
1697 /* Save the information we need to fix things up if the step
1699 disp_step_thread_state
.set (gdbarch
);
1701 tp
->inf
->displaced_step_state
.in_progress_count
++;
1703 displaced_debug_printf ("prepared successfully thread=%s, "
1704 "original_pc=%s, displaced_pc=%s",
1705 target_pid_to_str (tp
->ptid
).c_str (),
1706 paddress (gdbarch
, original_pc
),
1707 paddress (gdbarch
, displaced_pc
));
1709 return DISPLACED_STEP_PREPARE_STATUS_OK
;
1712 /* Wrapper for displaced_step_prepare_throw that disabled further
1713 attempts at displaced stepping if we get a memory error. */
1715 static displaced_step_prepare_status
1716 displaced_step_prepare (thread_info
*thread
)
1718 displaced_step_prepare_status status
1719 = DISPLACED_STEP_PREPARE_STATUS_CANT
;
1723 status
= displaced_step_prepare_throw (thread
);
1725 catch (const gdb_exception_error
&ex
)
1727 if (ex
.error
!= MEMORY_ERROR
1728 && ex
.error
!= NOT_SUPPORTED_ERROR
)
1731 infrun_debug_printf ("caught exception, disabling displaced stepping: %s",
1734 /* Be verbose if "set displaced-stepping" is "on", silent if
1736 if (can_use_displaced_stepping
== AUTO_BOOLEAN_TRUE
)
1738 warning (_("disabling displaced stepping: %s"),
1742 /* Disable further displaced stepping attempts. */
1743 thread
->inf
->displaced_step_state
.failed_before
= 1;
1749 /* If we displaced stepped an instruction successfully, adjust registers and
1750 memory to yield the same effect the instruction would have had if we had
1751 executed it at its original address, and return
1752 DISPLACED_STEP_FINISH_STATUS_OK. If the instruction didn't complete,
1753 relocate the PC and return DISPLACED_STEP_FINISH_STATUS_NOT_EXECUTED.
1755 If the thread wasn't displaced stepping, return
1756 DISPLACED_STEP_FINISH_STATUS_OK as well. */
1758 static displaced_step_finish_status
1759 displaced_step_finish (thread_info
*event_thread
, enum gdb_signal signal
)
1761 displaced_step_thread_state
*displaced
= &event_thread
->displaced_step_state
;
1763 /* Was this thread performing a displaced step? */
1764 if (!displaced
->in_progress ())
1765 return DISPLACED_STEP_FINISH_STATUS_OK
;
1767 gdb_assert (event_thread
->inf
->displaced_step_state
.in_progress_count
> 0);
1768 event_thread
->inf
->displaced_step_state
.in_progress_count
--;
1770 /* Fixup may need to read memory/registers. Switch to the thread
1771 that we're fixing up. Also, target_stopped_by_watchpoint checks
1772 the current thread, and displaced_step_restore performs ptid-dependent
1773 memory accesses using current_inferior(). */
1774 switch_to_thread (event_thread
);
1776 displaced_step_reset_cleanup
cleanup (displaced
);
1778 /* Do the fixup, and release the resources acquired to do the displaced
1780 return gdbarch_displaced_step_finish (displaced
->get_original_gdbarch (),
1781 event_thread
, signal
);
1784 /* Data to be passed around while handling an event. This data is
1785 discarded between events. */
1786 struct execution_control_state
1788 process_stratum_target
*target
;
1790 /* The thread that got the event, if this was a thread event; NULL
1792 struct thread_info
*event_thread
;
1794 struct target_waitstatus ws
;
1795 int stop_func_filled_in
;
1796 CORE_ADDR stop_func_start
;
1797 CORE_ADDR stop_func_end
;
1798 const char *stop_func_name
;
1801 /* True if the event thread hit the single-step breakpoint of
1802 another thread. Thus the event doesn't cause a stop, the thread
1803 needs to be single-stepped past the single-step breakpoint before
1804 we can switch back to the original stepping thread. */
1805 int hit_singlestep_breakpoint
;
1808 /* Clear ECS and set it to point at TP. */
1811 reset_ecs (struct execution_control_state
*ecs
, struct thread_info
*tp
)
1813 memset (ecs
, 0, sizeof (*ecs
));
1814 ecs
->event_thread
= tp
;
1815 ecs
->ptid
= tp
->ptid
;
1818 static void keep_going_pass_signal (struct execution_control_state
*ecs
);
1819 static void prepare_to_wait (struct execution_control_state
*ecs
);
1820 static bool keep_going_stepped_thread (struct thread_info
*tp
);
1821 static step_over_what
thread_still_needs_step_over (struct thread_info
*tp
);
1823 /* Are there any pending step-over requests? If so, run all we can
1824 now and return true. Otherwise, return false. */
1827 start_step_over (void)
1829 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
1831 /* Don't start a new step-over if we already have an in-line
1832 step-over operation ongoing. */
1833 if (step_over_info_valid_p ())
1836 /* Steal the global thread step over chain. As we try to initiate displaced
1837 steps, threads will be enqueued in the global chain if no buffers are
1838 available. If we iterated on the global chain directly, we might iterate
1840 thread_step_over_list threads_to_step
1841 = std::move (global_thread_step_over_list
);
1843 infrun_debug_printf ("stealing global queue of threads to step, length = %d",
1844 thread_step_over_chain_length (threads_to_step
));
1846 bool started
= false;
1848 /* On scope exit (whatever the reason, return or exception), if there are
1849 threads left in the THREADS_TO_STEP chain, put back these threads in the
1853 if (threads_to_step
.empty ())
1854 infrun_debug_printf ("step-over queue now empty");
1857 infrun_debug_printf ("putting back %d threads to step in global queue",
1858 thread_step_over_chain_length (threads_to_step
));
1860 global_thread_step_over_chain_enqueue_chain
1861 (std::move (threads_to_step
));
1865 thread_step_over_list_safe_range range
1866 = make_thread_step_over_list_safe_range (threads_to_step
);
1868 for (thread_info
*tp
: range
)
1870 struct execution_control_state ecss
;
1871 struct execution_control_state
*ecs
= &ecss
;
1872 step_over_what step_what
;
1873 int must_be_in_line
;
1875 gdb_assert (!tp
->stop_requested
);
1877 if (tp
->inf
->displaced_step_state
.unavailable
)
1879 /* The arch told us to not even try preparing another displaced step
1880 for this inferior. Just leave the thread in THREADS_TO_STEP, it
1881 will get moved to the global chain on scope exit. */
1885 /* Remove thread from the THREADS_TO_STEP chain. If anything goes wrong
1886 while we try to prepare the displaced step, we don't add it back to
1887 the global step over chain. This is to avoid a thread staying in the
1888 step over chain indefinitely if something goes wrong when resuming it
1889 If the error is intermittent and it still needs a step over, it will
1890 get enqueued again when we try to resume it normally. */
1891 threads_to_step
.erase (threads_to_step
.iterator_to (*tp
));
1893 step_what
= thread_still_needs_step_over (tp
);
1894 must_be_in_line
= ((step_what
& STEP_OVER_WATCHPOINT
)
1895 || ((step_what
& STEP_OVER_BREAKPOINT
)
1896 && !use_displaced_stepping (tp
)));
1898 /* We currently stop all threads of all processes to step-over
1899 in-line. If we need to start a new in-line step-over, let
1900 any pending displaced steps finish first. */
1901 if (must_be_in_line
&& displaced_step_in_progress_any_thread ())
1903 global_thread_step_over_chain_enqueue (tp
);
1907 if (tp
->control
.trap_expected
1909 || tp
->executing ())
1911 internal_error (__FILE__
, __LINE__
,
1912 "[%s] has inconsistent state: "
1913 "trap_expected=%d, resumed=%d, executing=%d\n",
1914 target_pid_to_str (tp
->ptid
).c_str (),
1915 tp
->control
.trap_expected
,
1920 infrun_debug_printf ("resuming [%s] for step-over",
1921 target_pid_to_str (tp
->ptid
).c_str ());
1923 /* keep_going_pass_signal skips the step-over if the breakpoint
1924 is no longer inserted. In all-stop, we want to keep looking
1925 for a thread that needs a step-over instead of resuming TP,
1926 because we wouldn't be able to resume anything else until the
1927 target stops again. In non-stop, the resume always resumes
1928 only TP, so it's OK to let the thread resume freely. */
1929 if (!target_is_non_stop_p () && !step_what
)
1932 switch_to_thread (tp
);
1933 reset_ecs (ecs
, tp
);
1934 keep_going_pass_signal (ecs
);
1936 if (!ecs
->wait_some_more
)
1937 error (_("Command aborted."));
1939 /* If the thread's step over could not be initiated because no buffers
1940 were available, it was re-added to the global step over chain. */
1943 infrun_debug_printf ("[%s] was resumed.",
1944 target_pid_to_str (tp
->ptid
).c_str ());
1945 gdb_assert (!thread_is_in_step_over_chain (tp
));
1949 infrun_debug_printf ("[%s] was NOT resumed.",
1950 target_pid_to_str (tp
->ptid
).c_str ());
1951 gdb_assert (thread_is_in_step_over_chain (tp
));
1954 /* If we started a new in-line step-over, we're done. */
1955 if (step_over_info_valid_p ())
1957 gdb_assert (tp
->control
.trap_expected
);
1962 if (!target_is_non_stop_p ())
1964 /* On all-stop, shouldn't have resumed unless we needed a
1966 gdb_assert (tp
->control
.trap_expected
1967 || tp
->step_after_step_resume_breakpoint
);
1969 /* With remote targets (at least), in all-stop, we can't
1970 issue any further remote commands until the program stops
1976 /* Either the thread no longer needed a step-over, or a new
1977 displaced stepping sequence started. Even in the latter
1978 case, continue looking. Maybe we can also start another
1979 displaced step on a thread of other process. */
1985 /* Update global variables holding ptids to hold NEW_PTID if they were
1986 holding OLD_PTID. */
1988 infrun_thread_ptid_changed (process_stratum_target
*target
,
1989 ptid_t old_ptid
, ptid_t new_ptid
)
1991 if (inferior_ptid
== old_ptid
1992 && current_inferior ()->process_target () == target
)
1993 inferior_ptid
= new_ptid
;
1998 static const char schedlock_off
[] = "off";
1999 static const char schedlock_on
[] = "on";
2000 static const char schedlock_step
[] = "step";
2001 static const char schedlock_replay
[] = "replay";
2002 static const char *const scheduler_enums
[] = {
2009 static const char *scheduler_mode
= schedlock_replay
;
2011 show_scheduler_mode (struct ui_file
*file
, int from_tty
,
2012 struct cmd_list_element
*c
, const char *value
)
2014 fprintf_filtered (file
,
2015 _("Mode for locking scheduler "
2016 "during execution is \"%s\".\n"),
2021 set_schedlock_func (const char *args
, int from_tty
, struct cmd_list_element
*c
)
2023 if (!target_can_lock_scheduler ())
2025 scheduler_mode
= schedlock_off
;
2026 error (_("Target '%s' cannot support this command."),
2027 target_shortname ());
2031 /* True if execution commands resume all threads of all processes by
2032 default; otherwise, resume only threads of the current inferior
2034 bool sched_multi
= false;
2036 /* Try to setup for software single stepping. Return true if target_resume()
2037 should use hardware single step.
2039 GDBARCH the current gdbarch. */
2042 maybe_software_singlestep (struct gdbarch
*gdbarch
)
2044 bool hw_step
= true;
2046 if (execution_direction
== EXEC_FORWARD
2047 && gdbarch_software_single_step_p (gdbarch
))
2048 hw_step
= !insert_single_step_breakpoints (gdbarch
);
2056 user_visible_resume_ptid (int step
)
2062 /* With non-stop mode on, threads are always handled
2064 resume_ptid
= inferior_ptid
;
2066 else if ((scheduler_mode
== schedlock_on
)
2067 || (scheduler_mode
== schedlock_step
&& step
))
2069 /* User-settable 'scheduler' mode requires solo thread
2071 resume_ptid
= inferior_ptid
;
2073 else if ((scheduler_mode
== schedlock_replay
)
2074 && target_record_will_replay (minus_one_ptid
, execution_direction
))
2076 /* User-settable 'scheduler' mode requires solo thread resume in replay
2078 resume_ptid
= inferior_ptid
;
2080 else if (!sched_multi
&& target_supports_multi_process ())
2082 /* Resume all threads of the current process (and none of other
2084 resume_ptid
= ptid_t (inferior_ptid
.pid ());
2088 /* Resume all threads of all processes. */
2089 resume_ptid
= RESUME_ALL
;
2097 process_stratum_target
*
2098 user_visible_resume_target (ptid_t resume_ptid
)
2100 return (resume_ptid
== minus_one_ptid
&& sched_multi
2102 : current_inferior ()->process_target ());
2105 /* Return a ptid representing the set of threads that we will resume,
2106 in the perspective of the target, assuming run control handling
2107 does not require leaving some threads stopped (e.g., stepping past
2108 breakpoint). USER_STEP indicates whether we're about to start the
2109 target for a stepping command. */
2112 internal_resume_ptid (int user_step
)
2114 /* In non-stop, we always control threads individually. Note that
2115 the target may always work in non-stop mode even with "set
2116 non-stop off", in which case user_visible_resume_ptid could
2117 return a wildcard ptid. */
2118 if (target_is_non_stop_p ())
2119 return inferior_ptid
;
2121 return user_visible_resume_ptid (user_step
);
2124 /* Wrapper for target_resume, that handles infrun-specific
2128 do_target_resume (ptid_t resume_ptid
, bool step
, enum gdb_signal sig
)
2130 struct thread_info
*tp
= inferior_thread ();
2132 gdb_assert (!tp
->stop_requested
);
2134 /* Install inferior's terminal modes. */
2135 target_terminal::inferior ();
2137 /* Avoid confusing the next resume, if the next stop/resume
2138 happens to apply to another thread. */
2139 tp
->set_stop_signal (GDB_SIGNAL_0
);
2141 /* Advise target which signals may be handled silently.
2143 If we have removed breakpoints because we are stepping over one
2144 in-line (in any thread), we need to receive all signals to avoid
2145 accidentally skipping a breakpoint during execution of a signal
2148 Likewise if we're displaced stepping, otherwise a trap for a
2149 breakpoint in a signal handler might be confused with the
2150 displaced step finishing. We don't make the displaced_step_finish
2151 step distinguish the cases instead, because:
2153 - a backtrace while stopped in the signal handler would show the
2154 scratch pad as frame older than the signal handler, instead of
2155 the real mainline code.
2157 - when the thread is later resumed, the signal handler would
2158 return to the scratch pad area, which would no longer be
2160 if (step_over_info_valid_p ()
2161 || displaced_step_in_progress (tp
->inf
))
2162 target_pass_signals ({});
2164 target_pass_signals (signal_pass
);
2166 target_resume (resume_ptid
, step
, sig
);
2168 if (target_can_async_p ())
2172 /* Resume the inferior. SIG is the signal to give the inferior
2173 (GDB_SIGNAL_0 for none). Note: don't call this directly; instead
2174 call 'resume', which handles exceptions. */
2177 resume_1 (enum gdb_signal sig
)
2179 struct regcache
*regcache
= get_current_regcache ();
2180 struct gdbarch
*gdbarch
= regcache
->arch ();
2181 struct thread_info
*tp
= inferior_thread ();
2182 const address_space
*aspace
= regcache
->aspace ();
2184 /* This represents the user's step vs continue request. When
2185 deciding whether "set scheduler-locking step" applies, it's the
2186 user's intention that counts. */
2187 const int user_step
= tp
->control
.stepping_command
;
2188 /* This represents what we'll actually request the target to do.
2189 This can decay from a step to a continue, if e.g., we need to
2190 implement single-stepping with breakpoints (software
2194 gdb_assert (!tp
->stop_requested
);
2195 gdb_assert (!thread_is_in_step_over_chain (tp
));
2197 if (tp
->has_pending_waitstatus ())
2200 ("thread %s has pending wait "
2201 "status %s (currently_stepping=%d).",
2202 target_pid_to_str (tp
->ptid
).c_str (),
2203 target_waitstatus_to_string (&tp
->pending_waitstatus ()).c_str (),
2204 currently_stepping (tp
));
2206 tp
->inf
->process_target ()->threads_executing
= true;
2207 tp
->set_resumed (true);
2209 /* FIXME: What should we do if we are supposed to resume this
2210 thread with a signal? Maybe we should maintain a queue of
2211 pending signals to deliver. */
2212 if (sig
!= GDB_SIGNAL_0
)
2214 warning (_("Couldn't deliver signal %s to %s."),
2215 gdb_signal_to_name (sig
),
2216 target_pid_to_str (tp
->ptid
).c_str ());
2219 tp
->set_stop_signal (GDB_SIGNAL_0
);
2221 if (target_can_async_p ())
2224 /* Tell the event loop we have an event to process. */
2225 mark_async_event_handler (infrun_async_inferior_event_token
);
2230 tp
->stepped_breakpoint
= 0;
2232 /* Depends on stepped_breakpoint. */
2233 step
= currently_stepping (tp
);
2235 if (current_inferior ()->waiting_for_vfork_done
)
2237 /* Don't try to single-step a vfork parent that is waiting for
2238 the child to get out of the shared memory region (by exec'ing
2239 or exiting). This is particularly important on software
2240 single-step archs, as the child process would trip on the
2241 software single step breakpoint inserted for the parent
2242 process. Since the parent will not actually execute any
2243 instruction until the child is out of the shared region (such
2244 are vfork's semantics), it is safe to simply continue it.
2245 Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for
2246 the parent, and tell it to `keep_going', which automatically
2247 re-sets it stepping. */
2248 infrun_debug_printf ("resume : clear step");
2252 CORE_ADDR pc
= regcache_read_pc (regcache
);
2254 infrun_debug_printf ("step=%d, signal=%s, trap_expected=%d, "
2255 "current thread [%s] at %s",
2256 step
, gdb_signal_to_symbol_string (sig
),
2257 tp
->control
.trap_expected
,
2258 target_pid_to_str (inferior_ptid
).c_str (),
2259 paddress (gdbarch
, pc
));
2261 /* Normally, by the time we reach `resume', the breakpoints are either
2262 removed or inserted, as appropriate. The exception is if we're sitting
2263 at a permanent breakpoint; we need to step over it, but permanent
2264 breakpoints can't be removed. So we have to test for it here. */
2265 if (breakpoint_here_p (aspace
, pc
) == permanent_breakpoint_here
)
2267 if (sig
!= GDB_SIGNAL_0
)
2269 /* We have a signal to pass to the inferior. The resume
2270 may, or may not take us to the signal handler. If this
2271 is a step, we'll need to stop in the signal handler, if
2272 there's one, (if the target supports stepping into
2273 handlers), or in the next mainline instruction, if
2274 there's no handler. If this is a continue, we need to be
2275 sure to run the handler with all breakpoints inserted.
2276 In all cases, set a breakpoint at the current address
2277 (where the handler returns to), and once that breakpoint
2278 is hit, resume skipping the permanent breakpoint. If
2279 that breakpoint isn't hit, then we've stepped into the
2280 signal handler (or hit some other event). We'll delete
2281 the step-resume breakpoint then. */
2283 infrun_debug_printf ("resume: skipping permanent breakpoint, "
2284 "deliver signal first");
2286 clear_step_over_info ();
2287 tp
->control
.trap_expected
= 0;
2289 if (tp
->control
.step_resume_breakpoint
== NULL
)
2291 /* Set a "high-priority" step-resume, as we don't want
2292 user breakpoints at PC to trigger (again) when this
2294 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
2295 gdb_assert (tp
->control
.step_resume_breakpoint
->loc
->permanent
);
2297 tp
->step_after_step_resume_breakpoint
= step
;
2300 insert_breakpoints ();
2304 /* There's no signal to pass, we can go ahead and skip the
2305 permanent breakpoint manually. */
2306 infrun_debug_printf ("skipping permanent breakpoint");
2307 gdbarch_skip_permanent_breakpoint (gdbarch
, regcache
);
2308 /* Update pc to reflect the new address from which we will
2309 execute instructions. */
2310 pc
= regcache_read_pc (regcache
);
2314 /* We've already advanced the PC, so the stepping part
2315 is done. Now we need to arrange for a trap to be
2316 reported to handle_inferior_event. Set a breakpoint
2317 at the current PC, and run to it. Don't update
2318 prev_pc, because if we end in
2319 switch_back_to_stepped_thread, we want the "expected
2320 thread advanced also" branch to be taken. IOW, we
2321 don't want this thread to step further from PC
2323 gdb_assert (!step_over_info_valid_p ());
2324 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
2325 insert_breakpoints ();
2327 resume_ptid
= internal_resume_ptid (user_step
);
2328 do_target_resume (resume_ptid
, false, GDB_SIGNAL_0
);
2329 tp
->set_resumed (true);
2335 /* If we have a breakpoint to step over, make sure to do a single
2336 step only. Same if we have software watchpoints. */
2337 if (tp
->control
.trap_expected
|| bpstat_should_step ())
2338 tp
->control
.may_range_step
= 0;
2340 /* If displaced stepping is enabled, step over breakpoints by executing a
2341 copy of the instruction at a different address.
2343 We can't use displaced stepping when we have a signal to deliver;
2344 the comments for displaced_step_prepare explain why. The
2345 comments in the handle_inferior event for dealing with 'random
2346 signals' explain what we do instead.
2348 We can't use displaced stepping when we are waiting for vfork_done
2349 event, displaced stepping breaks the vfork child similarly as single
2350 step software breakpoint. */
2351 if (tp
->control
.trap_expected
2352 && use_displaced_stepping (tp
)
2353 && !step_over_info_valid_p ()
2354 && sig
== GDB_SIGNAL_0
2355 && !current_inferior ()->waiting_for_vfork_done
)
2357 displaced_step_prepare_status prepare_status
2358 = displaced_step_prepare (tp
);
2360 if (prepare_status
== DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
)
2362 infrun_debug_printf ("Got placed in step-over queue");
2364 tp
->control
.trap_expected
= 0;
2367 else if (prepare_status
== DISPLACED_STEP_PREPARE_STATUS_CANT
)
2369 /* Fallback to stepping over the breakpoint in-line. */
2371 if (target_is_non_stop_p ())
2372 stop_all_threads ();
2374 set_step_over_info (regcache
->aspace (),
2375 regcache_read_pc (regcache
), 0, tp
->global_num
);
2377 step
= maybe_software_singlestep (gdbarch
);
2379 insert_breakpoints ();
2381 else if (prepare_status
== DISPLACED_STEP_PREPARE_STATUS_OK
)
2383 /* Update pc to reflect the new address from which we will
2384 execute instructions due to displaced stepping. */
2385 pc
= regcache_read_pc (get_thread_regcache (tp
));
2387 step
= gdbarch_displaced_step_hw_singlestep (gdbarch
);
2390 gdb_assert_not_reached (_("Invalid displaced_step_prepare_status "
2394 /* Do we need to do it the hard way, w/temp breakpoints? */
2396 step
= maybe_software_singlestep (gdbarch
);
2398 /* Currently, our software single-step implementation leads to different
2399 results than hardware single-stepping in one situation: when stepping
2400 into delivering a signal which has an associated signal handler,
2401 hardware single-step will stop at the first instruction of the handler,
2402 while software single-step will simply skip execution of the handler.
2404 For now, this difference in behavior is accepted since there is no
2405 easy way to actually implement single-stepping into a signal handler
2406 without kernel support.
2408 However, there is one scenario where this difference leads to follow-on
2409 problems: if we're stepping off a breakpoint by removing all breakpoints
2410 and then single-stepping. In this case, the software single-step
2411 behavior means that even if there is a *breakpoint* in the signal
2412 handler, GDB still would not stop.
2414 Fortunately, we can at least fix this particular issue. We detect
2415 here the case where we are about to deliver a signal while software
2416 single-stepping with breakpoints removed. In this situation, we
2417 revert the decisions to remove all breakpoints and insert single-
2418 step breakpoints, and instead we install a step-resume breakpoint
2419 at the current address, deliver the signal without stepping, and
2420 once we arrive back at the step-resume breakpoint, actually step
2421 over the breakpoint we originally wanted to step over. */
2422 if (thread_has_single_step_breakpoints_set (tp
)
2423 && sig
!= GDB_SIGNAL_0
2424 && step_over_info_valid_p ())
2426 /* If we have nested signals or a pending signal is delivered
2427 immediately after a handler returns, might already have
2428 a step-resume breakpoint set on the earlier handler. We cannot
2429 set another step-resume breakpoint; just continue on until the
2430 original breakpoint is hit. */
2431 if (tp
->control
.step_resume_breakpoint
== NULL
)
2433 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
2434 tp
->step_after_step_resume_breakpoint
= 1;
2437 delete_single_step_breakpoints (tp
);
2439 clear_step_over_info ();
2440 tp
->control
.trap_expected
= 0;
2442 insert_breakpoints ();
2445 /* If STEP is set, it's a request to use hardware stepping
2446 facilities. But in that case, we should never
2447 use singlestep breakpoint. */
2448 gdb_assert (!(thread_has_single_step_breakpoints_set (tp
) && step
));
2450 /* Decide the set of threads to ask the target to resume. */
2451 if (tp
->control
.trap_expected
)
2453 /* We're allowing a thread to run past a breakpoint it has
2454 hit, either by single-stepping the thread with the breakpoint
2455 removed, or by displaced stepping, with the breakpoint inserted.
2456 In the former case, we need to single-step only this thread,
2457 and keep others stopped, as they can miss this breakpoint if
2458 allowed to run. That's not really a problem for displaced
2459 stepping, but, we still keep other threads stopped, in case
2460 another thread is also stopped for a breakpoint waiting for
2461 its turn in the displaced stepping queue. */
2462 resume_ptid
= inferior_ptid
;
2465 resume_ptid
= internal_resume_ptid (user_step
);
2467 if (execution_direction
!= EXEC_REVERSE
2468 && step
&& breakpoint_inserted_here_p (aspace
, pc
))
2470 /* There are two cases where we currently need to step a
2471 breakpoint instruction when we have a signal to deliver:
2473 - See handle_signal_stop where we handle random signals that
2474 could take out us out of the stepping range. Normally, in
2475 that case we end up continuing (instead of stepping) over the
2476 signal handler with a breakpoint at PC, but there are cases
2477 where we should _always_ single-step, even if we have a
2478 step-resume breakpoint, like when a software watchpoint is
2479 set. Assuming single-stepping and delivering a signal at the
2480 same time would takes us to the signal handler, then we could
2481 have removed the breakpoint at PC to step over it. However,
2482 some hardware step targets (like e.g., Mac OS) can't step
2483 into signal handlers, and for those, we need to leave the
2484 breakpoint at PC inserted, as otherwise if the handler
2485 recurses and executes PC again, it'll miss the breakpoint.
2486 So we leave the breakpoint inserted anyway, but we need to
2487 record that we tried to step a breakpoint instruction, so
2488 that adjust_pc_after_break doesn't end up confused.
2490 - In non-stop if we insert a breakpoint (e.g., a step-resume)
2491 in one thread after another thread that was stepping had been
2492 momentarily paused for a step-over. When we re-resume the
2493 stepping thread, it may be resumed from that address with a
2494 breakpoint that hasn't trapped yet. Seen with
2495 gdb.threads/non-stop-fair-events.exp, on targets that don't
2496 do displaced stepping. */
2498 infrun_debug_printf ("resume: [%s] stepped breakpoint",
2499 target_pid_to_str (tp
->ptid
).c_str ());
2501 tp
->stepped_breakpoint
= 1;
2503 /* Most targets can step a breakpoint instruction, thus
2504 executing it normally. But if this one cannot, just
2505 continue and we will hit it anyway. */
2506 if (gdbarch_cannot_step_breakpoint (gdbarch
))
2511 && tp
->control
.trap_expected
2512 && use_displaced_stepping (tp
)
2513 && !step_over_info_valid_p ())
2515 struct regcache
*resume_regcache
= get_thread_regcache (tp
);
2516 struct gdbarch
*resume_gdbarch
= resume_regcache
->arch ();
2517 CORE_ADDR actual_pc
= regcache_read_pc (resume_regcache
);
2520 read_memory (actual_pc
, buf
, sizeof (buf
));
2521 displaced_debug_printf ("run %s: %s",
2522 paddress (resume_gdbarch
, actual_pc
),
2523 displaced_step_dump_bytes
2524 (buf
, sizeof (buf
)).c_str ());
2527 if (tp
->control
.may_range_step
)
2529 /* If we're resuming a thread with the PC out of the step
2530 range, then we're doing some nested/finer run control
2531 operation, like stepping the thread out of the dynamic
2532 linker or the displaced stepping scratch pad. We
2533 shouldn't have allowed a range step then. */
2534 gdb_assert (pc_in_thread_step_range (pc
, tp
));
2537 do_target_resume (resume_ptid
, step
, sig
);
2538 tp
->set_resumed (true);
2541 /* Resume the inferior. SIG is the signal to give the inferior
2542 (GDB_SIGNAL_0 for none). This is a wrapper around 'resume_1' that
2543 rolls back state on error. */
2546 resume (gdb_signal sig
)
2552 catch (const gdb_exception
&ex
)
2554 /* If resuming is being aborted for any reason, delete any
2555 single-step breakpoint resume_1 may have created, to avoid
2556 confusing the following resumption, and to avoid leaving
2557 single-step breakpoints perturbing other threads, in case
2558 we're running in non-stop mode. */
2559 if (inferior_ptid
!= null_ptid
)
2560 delete_single_step_breakpoints (inferior_thread ());
2570 /* Counter that tracks number of user visible stops. This can be used
2571 to tell whether a command has proceeded the inferior past the
2572 current location. This allows e.g., inferior function calls in
2573 breakpoint commands to not interrupt the command list. When the
2574 call finishes successfully, the inferior is standing at the same
2575 breakpoint as if nothing happened (and so we don't call
2577 static ULONGEST current_stop_id
;
2584 return current_stop_id
;
2587 /* Called when we report a user visible stop. */
2595 /* Clear out all variables saying what to do when inferior is continued.
2596 First do this, then set the ones you want, then call `proceed'. */
2599 clear_proceed_status_thread (struct thread_info
*tp
)
2601 infrun_debug_printf ("%s", target_pid_to_str (tp
->ptid
).c_str ());
2603 /* If we're starting a new sequence, then the previous finished
2604 single-step is no longer relevant. */
2605 if (tp
->has_pending_waitstatus ())
2607 if (tp
->stop_reason () == TARGET_STOPPED_BY_SINGLE_STEP
)
2609 infrun_debug_printf ("pending event of %s was a finished step. "
2611 target_pid_to_str (tp
->ptid
).c_str ());
2613 tp
->clear_pending_waitstatus ();
2614 tp
->set_stop_reason (TARGET_STOPPED_BY_NO_REASON
);
2619 ("thread %s has pending wait status %s (currently_stepping=%d).",
2620 target_pid_to_str (tp
->ptid
).c_str (),
2621 target_waitstatus_to_string (&tp
->pending_waitstatus ()).c_str (),
2622 currently_stepping (tp
));
2626 /* If this signal should not be seen by program, give it zero.
2627 Used for debugging signals. */
2628 if (!signal_pass_state (tp
->stop_signal ()))
2629 tp
->set_stop_signal (GDB_SIGNAL_0
);
2631 delete tp
->thread_fsm
;
2632 tp
->thread_fsm
= NULL
;
2634 tp
->control
.trap_expected
= 0;
2635 tp
->control
.step_range_start
= 0;
2636 tp
->control
.step_range_end
= 0;
2637 tp
->control
.may_range_step
= 0;
2638 tp
->control
.step_frame_id
= null_frame_id
;
2639 tp
->control
.step_stack_frame_id
= null_frame_id
;
2640 tp
->control
.step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
2641 tp
->control
.step_start_function
= NULL
;
2642 tp
->stop_requested
= 0;
2644 tp
->control
.stop_step
= 0;
2646 tp
->control
.proceed_to_finish
= 0;
2648 tp
->control
.stepping_command
= 0;
2650 /* Discard any remaining commands or status from previous stop. */
2651 bpstat_clear (&tp
->control
.stop_bpstat
);
2655 clear_proceed_status (int step
)
2657 /* With scheduler-locking replay, stop replaying other threads if we're
2658 not replaying the user-visible resume ptid.
2660 This is a convenience feature to not require the user to explicitly
2661 stop replaying the other threads. We're assuming that the user's
2662 intent is to resume tracing the recorded process. */
2663 if (!non_stop
&& scheduler_mode
== schedlock_replay
2664 && target_record_is_replaying (minus_one_ptid
)
2665 && !target_record_will_replay (user_visible_resume_ptid (step
),
2666 execution_direction
))
2667 target_record_stop_replaying ();
2669 if (!non_stop
&& inferior_ptid
!= null_ptid
)
2671 ptid_t resume_ptid
= user_visible_resume_ptid (step
);
2672 process_stratum_target
*resume_target
2673 = user_visible_resume_target (resume_ptid
);
2675 /* In all-stop mode, delete the per-thread status of all threads
2676 we're about to resume, implicitly and explicitly. */
2677 for (thread_info
*tp
: all_non_exited_threads (resume_target
, resume_ptid
))
2678 clear_proceed_status_thread (tp
);
2681 if (inferior_ptid
!= null_ptid
)
2683 struct inferior
*inferior
;
2687 /* If in non-stop mode, only delete the per-thread status of
2688 the current thread. */
2689 clear_proceed_status_thread (inferior_thread ());
2692 inferior
= current_inferior ();
2693 inferior
->control
.stop_soon
= NO_STOP_QUIETLY
;
2696 gdb::observers::about_to_proceed
.notify ();
2699 /* Returns true if TP is still stopped at a breakpoint that needs
2700 stepping-over in order to make progress. If the breakpoint is gone
2701 meanwhile, we can skip the whole step-over dance. */
2704 thread_still_needs_step_over_bp (struct thread_info
*tp
)
2706 if (tp
->stepping_over_breakpoint
)
2708 struct regcache
*regcache
= get_thread_regcache (tp
);
2710 if (breakpoint_here_p (regcache
->aspace (),
2711 regcache_read_pc (regcache
))
2712 == ordinary_breakpoint_here
)
2715 tp
->stepping_over_breakpoint
= 0;
2721 /* Check whether thread TP still needs to start a step-over in order
2722 to make progress when resumed. Returns an bitwise or of enum
2723 step_over_what bits, indicating what needs to be stepped over. */
2725 static step_over_what
2726 thread_still_needs_step_over (struct thread_info
*tp
)
2728 step_over_what what
= 0;
2730 if (thread_still_needs_step_over_bp (tp
))
2731 what
|= STEP_OVER_BREAKPOINT
;
2733 if (tp
->stepping_over_watchpoint
2734 && !target_have_steppable_watchpoint ())
2735 what
|= STEP_OVER_WATCHPOINT
;
2740 /* Returns true if scheduler locking applies. STEP indicates whether
2741 we're about to do a step/next-like command to a thread. */
2744 schedlock_applies (struct thread_info
*tp
)
2746 return (scheduler_mode
== schedlock_on
2747 || (scheduler_mode
== schedlock_step
2748 && tp
->control
.stepping_command
)
2749 || (scheduler_mode
== schedlock_replay
2750 && target_record_will_replay (minus_one_ptid
,
2751 execution_direction
)));
2754 /* Set process_stratum_target::COMMIT_RESUMED_STATE in all target
2755 stacks that have threads executing and don't have threads with
2759 maybe_set_commit_resumed_all_targets ()
2761 scoped_restore_current_thread restore_thread
;
2763 for (inferior
*inf
: all_non_exited_inferiors ())
2765 process_stratum_target
*proc_target
= inf
->process_target ();
2767 if (proc_target
->commit_resumed_state
)
2769 /* We already set this in a previous iteration, via another
2770 inferior sharing the process_stratum target. */
2774 /* If the target has no resumed threads, it would be useless to
2775 ask it to commit the resumed threads. */
2776 if (!proc_target
->threads_executing
)
2778 infrun_debug_printf ("not requesting commit-resumed for target "
2779 "%s, no resumed threads",
2780 proc_target
->shortname ());
2784 /* As an optimization, if a thread from this target has some
2785 status to report, handle it before requiring the target to
2786 commit its resumed threads: handling the status might lead to
2787 resuming more threads. */
2788 if (proc_target
->has_resumed_with_pending_wait_status ())
2790 infrun_debug_printf ("not requesting commit-resumed for target %s, a"
2791 " thread has a pending waitstatus",
2792 proc_target
->shortname ());
2796 switch_to_inferior_no_thread (inf
);
2798 if (target_has_pending_events ())
2800 infrun_debug_printf ("not requesting commit-resumed for target %s, "
2801 "target has pending events",
2802 proc_target
->shortname ());
2806 infrun_debug_printf ("enabling commit-resumed for target %s",
2807 proc_target
->shortname ());
2809 proc_target
->commit_resumed_state
= true;
2816 maybe_call_commit_resumed_all_targets ()
2818 scoped_restore_current_thread restore_thread
;
2820 for (inferior
*inf
: all_non_exited_inferiors ())
2822 process_stratum_target
*proc_target
= inf
->process_target ();
2824 if (!proc_target
->commit_resumed_state
)
2827 switch_to_inferior_no_thread (inf
);
2829 infrun_debug_printf ("calling commit_resumed for target %s",
2830 proc_target
->shortname());
2832 target_commit_resumed ();
2836 /* To track nesting of scoped_disable_commit_resumed objects, ensuring
2837 that only the outermost one attempts to re-enable
2839 static bool enable_commit_resumed
= true;
2843 scoped_disable_commit_resumed::scoped_disable_commit_resumed
2844 (const char *reason
)
2845 : m_reason (reason
),
2846 m_prev_enable_commit_resumed (enable_commit_resumed
)
2848 infrun_debug_printf ("reason=%s", m_reason
);
2850 enable_commit_resumed
= false;
2852 for (inferior
*inf
: all_non_exited_inferiors ())
2854 process_stratum_target
*proc_target
= inf
->process_target ();
2856 if (m_prev_enable_commit_resumed
)
2858 /* This is the outermost instance: force all
2859 COMMIT_RESUMED_STATE to false. */
2860 proc_target
->commit_resumed_state
= false;
2864 /* This is not the outermost instance, we expect
2865 COMMIT_RESUMED_STATE to have been cleared by the
2866 outermost instance. */
2867 gdb_assert (!proc_target
->commit_resumed_state
);
2875 scoped_disable_commit_resumed::reset ()
2881 infrun_debug_printf ("reason=%s", m_reason
);
2883 gdb_assert (!enable_commit_resumed
);
2885 enable_commit_resumed
= m_prev_enable_commit_resumed
;
2887 if (m_prev_enable_commit_resumed
)
2889 /* This is the outermost instance, re-enable
2890 COMMIT_RESUMED_STATE on the targets where it's possible. */
2891 maybe_set_commit_resumed_all_targets ();
2895 /* This is not the outermost instance, we expect
2896 COMMIT_RESUMED_STATE to still be false. */
2897 for (inferior
*inf
: all_non_exited_inferiors ())
2899 process_stratum_target
*proc_target
= inf
->process_target ();
2900 gdb_assert (!proc_target
->commit_resumed_state
);
2907 scoped_disable_commit_resumed::~scoped_disable_commit_resumed ()
2915 scoped_disable_commit_resumed::reset_and_commit ()
2918 maybe_call_commit_resumed_all_targets ();
2923 scoped_enable_commit_resumed::scoped_enable_commit_resumed
2924 (const char *reason
)
2925 : m_reason (reason
),
2926 m_prev_enable_commit_resumed (enable_commit_resumed
)
2928 infrun_debug_printf ("reason=%s", m_reason
);
2930 if (!enable_commit_resumed
)
2932 enable_commit_resumed
= true;
2934 /* Re-enable COMMIT_RESUMED_STATE on the targets where it's
2936 maybe_set_commit_resumed_all_targets ();
2938 maybe_call_commit_resumed_all_targets ();
2944 scoped_enable_commit_resumed::~scoped_enable_commit_resumed ()
2946 infrun_debug_printf ("reason=%s", m_reason
);
2948 gdb_assert (enable_commit_resumed
);
2950 enable_commit_resumed
= m_prev_enable_commit_resumed
;
2952 if (!enable_commit_resumed
)
2954 /* Force all COMMIT_RESUMED_STATE back to false. */
2955 for (inferior
*inf
: all_non_exited_inferiors ())
2957 process_stratum_target
*proc_target
= inf
->process_target ();
2958 proc_target
->commit_resumed_state
= false;
2963 /* Check that all the targets we're about to resume are in non-stop
2964 mode. Ideally, we'd only care whether all targets support
2965 target-async, but we're not there yet. E.g., stop_all_threads
2966 doesn't know how to handle all-stop targets. Also, the remote
2967 protocol in all-stop mode is synchronous, irrespective of
2968 target-async, which means that things like a breakpoint re-set
2969 triggered by one target would try to read memory from all targets
2973 check_multi_target_resumption (process_stratum_target
*resume_target
)
2975 if (!non_stop
&& resume_target
== nullptr)
2977 scoped_restore_current_thread restore_thread
;
2979 /* This is used to track whether we're resuming more than one
2981 process_stratum_target
*first_connection
= nullptr;
2983 /* The first inferior we see with a target that does not work in
2984 always-non-stop mode. */
2985 inferior
*first_not_non_stop
= nullptr;
2987 for (inferior
*inf
: all_non_exited_inferiors ())
2989 switch_to_inferior_no_thread (inf
);
2991 if (!target_has_execution ())
2994 process_stratum_target
*proc_target
2995 = current_inferior ()->process_target();
2997 if (!target_is_non_stop_p ())
2998 first_not_non_stop
= inf
;
3000 if (first_connection
== nullptr)
3001 first_connection
= proc_target
;
3002 else if (first_connection
!= proc_target
3003 && first_not_non_stop
!= nullptr)
3005 switch_to_inferior_no_thread (first_not_non_stop
);
3007 proc_target
= current_inferior ()->process_target();
3009 error (_("Connection %d (%s) does not support "
3010 "multi-target resumption."),
3011 proc_target
->connection_number
,
3012 make_target_connection_string (proc_target
).c_str ());
3018 /* Basic routine for continuing the program in various fashions.
3020 ADDR is the address to resume at, or -1 for resume where stopped.
3021 SIGGNAL is the signal to give it, or GDB_SIGNAL_0 for none,
3022 or GDB_SIGNAL_DEFAULT for act according to how it stopped.
3024 You should call clear_proceed_status before calling proceed. */
3027 proceed (CORE_ADDR addr
, enum gdb_signal siggnal
)
3029 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
3031 struct regcache
*regcache
;
3032 struct gdbarch
*gdbarch
;
3034 struct execution_control_state ecss
;
3035 struct execution_control_state
*ecs
= &ecss
;
3038 /* If we're stopped at a fork/vfork, follow the branch set by the
3039 "set follow-fork-mode" command; otherwise, we'll just proceed
3040 resuming the current thread. */
3041 if (!follow_fork ())
3043 /* The target for some reason decided not to resume. */
3045 if (target_can_async_p ())
3046 inferior_event_handler (INF_EXEC_COMPLETE
);
3050 /* We'll update this if & when we switch to a new thread. */
3051 previous_inferior_ptid
= inferior_ptid
;
3053 regcache
= get_current_regcache ();
3054 gdbarch
= regcache
->arch ();
3055 const address_space
*aspace
= regcache
->aspace ();
3057 pc
= regcache_read_pc_protected (regcache
);
3059 thread_info
*cur_thr
= inferior_thread ();
3061 /* Fill in with reasonable starting values. */
3062 init_thread_stepping_state (cur_thr
);
3064 gdb_assert (!thread_is_in_step_over_chain (cur_thr
));
3067 = user_visible_resume_ptid (cur_thr
->control
.stepping_command
);
3068 process_stratum_target
*resume_target
3069 = user_visible_resume_target (resume_ptid
);
3071 check_multi_target_resumption (resume_target
);
3073 if (addr
== (CORE_ADDR
) -1)
3075 if (cur_thr
->stop_pc_p ()
3076 && pc
== cur_thr
->stop_pc ()
3077 && breakpoint_here_p (aspace
, pc
) == ordinary_breakpoint_here
3078 && execution_direction
!= EXEC_REVERSE
)
3079 /* There is a breakpoint at the address we will resume at,
3080 step one instruction before inserting breakpoints so that
3081 we do not stop right away (and report a second hit at this
3084 Note, we don't do this in reverse, because we won't
3085 actually be executing the breakpoint insn anyway.
3086 We'll be (un-)executing the previous instruction. */
3087 cur_thr
->stepping_over_breakpoint
= 1;
3088 else if (gdbarch_single_step_through_delay_p (gdbarch
)
3089 && gdbarch_single_step_through_delay (gdbarch
,
3090 get_current_frame ()))
3091 /* We stepped onto an instruction that needs to be stepped
3092 again before re-inserting the breakpoint, do so. */
3093 cur_thr
->stepping_over_breakpoint
= 1;
3097 regcache_write_pc (regcache
, addr
);
3100 if (siggnal
!= GDB_SIGNAL_DEFAULT
)
3101 cur_thr
->set_stop_signal (siggnal
);
3103 /* If an exception is thrown from this point on, make sure to
3104 propagate GDB's knowledge of the executing state to the
3105 frontend/user running state. */
3106 scoped_finish_thread_state
finish_state (resume_target
, resume_ptid
);
3108 /* Even if RESUME_PTID is a wildcard, and we end up resuming fewer
3109 threads (e.g., we might need to set threads stepping over
3110 breakpoints first), from the user/frontend's point of view, all
3111 threads in RESUME_PTID are now running. Unless we're calling an
3112 inferior function, as in that case we pretend the inferior
3113 doesn't run at all. */
3114 if (!cur_thr
->control
.in_infcall
)
3115 set_running (resume_target
, resume_ptid
, true);
3117 infrun_debug_printf ("addr=%s, signal=%s", paddress (gdbarch
, addr
),
3118 gdb_signal_to_symbol_string (siggnal
));
3120 annotate_starting ();
3122 /* Make sure that output from GDB appears before output from the
3124 gdb_flush (gdb_stdout
);
3126 /* Since we've marked the inferior running, give it the terminal. A
3127 QUIT/Ctrl-C from here on is forwarded to the target (which can
3128 still detect attempts to unblock a stuck connection with repeated
3129 Ctrl-C from within target_pass_ctrlc). */
3130 target_terminal::inferior ();
3132 /* In a multi-threaded task we may select another thread and
3133 then continue or step.
3135 But if a thread that we're resuming had stopped at a breakpoint,
3136 it will immediately cause another breakpoint stop without any
3137 execution (i.e. it will report a breakpoint hit incorrectly). So
3138 we must step over it first.
3140 Look for threads other than the current (TP) that reported a
3141 breakpoint hit and haven't been resumed yet since. */
3143 /* If scheduler locking applies, we can avoid iterating over all
3145 if (!non_stop
&& !schedlock_applies (cur_thr
))
3147 for (thread_info
*tp
: all_non_exited_threads (resume_target
,
3150 switch_to_thread_no_regs (tp
);
3152 /* Ignore the current thread here. It's handled
3157 if (!thread_still_needs_step_over (tp
))
3160 gdb_assert (!thread_is_in_step_over_chain (tp
));
3162 infrun_debug_printf ("need to step-over [%s] first",
3163 target_pid_to_str (tp
->ptid
).c_str ());
3165 global_thread_step_over_chain_enqueue (tp
);
3168 switch_to_thread (cur_thr
);
3171 /* Enqueue the current thread last, so that we move all other
3172 threads over their breakpoints first. */
3173 if (cur_thr
->stepping_over_breakpoint
)
3174 global_thread_step_over_chain_enqueue (cur_thr
);
3176 /* If the thread isn't started, we'll still need to set its prev_pc,
3177 so that switch_back_to_stepped_thread knows the thread hasn't
3178 advanced. Must do this before resuming any thread, as in
3179 all-stop/remote, once we resume we can't send any other packet
3180 until the target stops again. */
3181 cur_thr
->prev_pc
= regcache_read_pc_protected (regcache
);
3184 scoped_disable_commit_resumed
disable_commit_resumed ("proceeding");
3186 started
= start_step_over ();
3188 if (step_over_info_valid_p ())
3190 /* Either this thread started a new in-line step over, or some
3191 other thread was already doing one. In either case, don't
3192 resume anything else until the step-over is finished. */
3194 else if (started
&& !target_is_non_stop_p ())
3196 /* A new displaced stepping sequence was started. In all-stop,
3197 we can't talk to the target anymore until it next stops. */
3199 else if (!non_stop
&& target_is_non_stop_p ())
3201 INFRUN_SCOPED_DEBUG_START_END
3202 ("resuming threads, all-stop-on-top-of-non-stop");
3204 /* In all-stop, but the target is always in non-stop mode.
3205 Start all other threads that are implicitly resumed too. */
3206 for (thread_info
*tp
: all_non_exited_threads (resume_target
,
3209 switch_to_thread_no_regs (tp
);
3211 if (!tp
->inf
->has_execution ())
3213 infrun_debug_printf ("[%s] target has no execution",
3214 target_pid_to_str (tp
->ptid
).c_str ());
3220 infrun_debug_printf ("[%s] resumed",
3221 target_pid_to_str (tp
->ptid
).c_str ());
3222 gdb_assert (tp
->executing () || tp
->has_pending_waitstatus ());
3226 if (thread_is_in_step_over_chain (tp
))
3228 infrun_debug_printf ("[%s] needs step-over",
3229 target_pid_to_str (tp
->ptid
).c_str ());
3233 infrun_debug_printf ("resuming %s",
3234 target_pid_to_str (tp
->ptid
).c_str ());
3236 reset_ecs (ecs
, tp
);
3237 switch_to_thread (tp
);
3238 keep_going_pass_signal (ecs
);
3239 if (!ecs
->wait_some_more
)
3240 error (_("Command aborted."));
3243 else if (!cur_thr
->resumed () && !thread_is_in_step_over_chain (cur_thr
))
3245 /* The thread wasn't started, and isn't queued, run it now. */
3246 reset_ecs (ecs
, cur_thr
);
3247 switch_to_thread (cur_thr
);
3248 keep_going_pass_signal (ecs
);
3249 if (!ecs
->wait_some_more
)
3250 error (_("Command aborted."));
3253 disable_commit_resumed
.reset_and_commit ();
3256 finish_state
.release ();
3258 /* If we've switched threads above, switch back to the previously
3259 current thread. We don't want the user to see a different
3261 switch_to_thread (cur_thr
);
3263 /* Tell the event loop to wait for it to stop. If the target
3264 supports asynchronous execution, it'll do this from within
3266 if (!target_can_async_p ())
3267 mark_async_event_handler (infrun_async_inferior_event_token
);
3271 /* Start remote-debugging of a machine over a serial link. */
3274 start_remote (int from_tty
)
3276 inferior
*inf
= current_inferior ();
3277 inf
->control
.stop_soon
= STOP_QUIETLY_REMOTE
;
3279 /* Always go on waiting for the target, regardless of the mode. */
3280 /* FIXME: cagney/1999-09-23: At present it isn't possible to
3281 indicate to wait_for_inferior that a target should timeout if
3282 nothing is returned (instead of just blocking). Because of this,
3283 targets expecting an immediate response need to, internally, set
3284 things up so that the target_wait() is forced to eventually
3286 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
3287 differentiate to its caller what the state of the target is after
3288 the initial open has been performed. Here we're assuming that
3289 the target has stopped. It should be possible to eventually have
3290 target_open() return to the caller an indication that the target
3291 is currently running and GDB state should be set to the same as
3292 for an async run. */
3293 wait_for_inferior (inf
);
3295 /* Now that the inferior has stopped, do any bookkeeping like
3296 loading shared libraries. We want to do this before normal_stop,
3297 so that the displayed frame is up to date. */
3298 post_create_inferior (from_tty
);
3303 /* Initialize static vars when a new inferior begins. */
3306 init_wait_for_inferior (void)
3308 /* These are meaningless until the first time through wait_for_inferior. */
3310 breakpoint_init_inferior (inf_starting
);
3312 clear_proceed_status (0);
3314 nullify_last_target_wait_ptid ();
3316 previous_inferior_ptid
= inferior_ptid
;
3321 static void handle_inferior_event (struct execution_control_state
*ecs
);
3323 static void handle_step_into_function (struct gdbarch
*gdbarch
,
3324 struct execution_control_state
*ecs
);
3325 static void handle_step_into_function_backward (struct gdbarch
*gdbarch
,
3326 struct execution_control_state
*ecs
);
3327 static void handle_signal_stop (struct execution_control_state
*ecs
);
3328 static void check_exception_resume (struct execution_control_state
*,
3329 struct frame_info
*);
3331 static void end_stepping_range (struct execution_control_state
*ecs
);
3332 static void stop_waiting (struct execution_control_state
*ecs
);
3333 static void keep_going (struct execution_control_state
*ecs
);
3334 static void process_event_stop_test (struct execution_control_state
*ecs
);
3335 static bool switch_back_to_stepped_thread (struct execution_control_state
*ecs
);
3337 /* This function is attached as a "thread_stop_requested" observer.
3338 Cleanup local state that assumed the PTID was to be resumed, and
3339 report the stop to the frontend. */
3342 infrun_thread_stop_requested (ptid_t ptid
)
3344 process_stratum_target
*curr_target
= current_inferior ()->process_target ();
3346 /* PTID was requested to stop. If the thread was already stopped,
3347 but the user/frontend doesn't know about that yet (e.g., the
3348 thread had been temporarily paused for some step-over), set up
3349 for reporting the stop now. */
3350 for (thread_info
*tp
: all_threads (curr_target
, ptid
))
3352 if (tp
->state
!= THREAD_RUNNING
)
3354 if (tp
->executing ())
3357 /* Remove matching threads from the step-over queue, so
3358 start_step_over doesn't try to resume them
3360 if (thread_is_in_step_over_chain (tp
))
3361 global_thread_step_over_chain_remove (tp
);
3363 /* If the thread is stopped, but the user/frontend doesn't
3364 know about that yet, queue a pending event, as if the
3365 thread had just stopped now. Unless the thread already had
3367 if (!tp
->has_pending_waitstatus ())
3369 target_waitstatus ws
;
3370 ws
.kind
= TARGET_WAITKIND_STOPPED
;
3371 ws
.value
.sig
= GDB_SIGNAL_0
;
3372 tp
->set_pending_waitstatus (ws
);
3375 /* Clear the inline-frame state, since we're re-processing the
3377 clear_inline_frame_state (tp
);
3379 /* If this thread was paused because some other thread was
3380 doing an inline-step over, let that finish first. Once
3381 that happens, we'll restart all threads and consume pending
3382 stop events then. */
3383 if (step_over_info_valid_p ())
3386 /* Otherwise we can process the (new) pending event now. Set
3387 it so this pending event is considered by
3389 tp
->set_resumed (true);
3394 infrun_thread_thread_exit (struct thread_info
*tp
, int silent
)
3396 if (target_last_proc_target
== tp
->inf
->process_target ()
3397 && target_last_wait_ptid
== tp
->ptid
)
3398 nullify_last_target_wait_ptid ();
3401 /* Delete the step resume, single-step and longjmp/exception resume
3402 breakpoints of TP. */
3405 delete_thread_infrun_breakpoints (struct thread_info
*tp
)
3407 delete_step_resume_breakpoint (tp
);
3408 delete_exception_resume_breakpoint (tp
);
3409 delete_single_step_breakpoints (tp
);
3412 /* If the target still has execution, call FUNC for each thread that
3413 just stopped. In all-stop, that's all the non-exited threads; in
3414 non-stop, that's the current thread, only. */
3416 typedef void (*for_each_just_stopped_thread_callback_func
)
3417 (struct thread_info
*tp
);
3420 for_each_just_stopped_thread (for_each_just_stopped_thread_callback_func func
)
3422 if (!target_has_execution () || inferior_ptid
== null_ptid
)
3425 if (target_is_non_stop_p ())
3427 /* If in non-stop mode, only the current thread stopped. */
3428 func (inferior_thread ());
3432 /* In all-stop mode, all threads have stopped. */
3433 for (thread_info
*tp
: all_non_exited_threads ())
3438 /* Delete the step resume and longjmp/exception resume breakpoints of
3439 the threads that just stopped. */
3442 delete_just_stopped_threads_infrun_breakpoints (void)
3444 for_each_just_stopped_thread (delete_thread_infrun_breakpoints
);
3447 /* Delete the single-step breakpoints of the threads that just
3451 delete_just_stopped_threads_single_step_breakpoints (void)
3453 for_each_just_stopped_thread (delete_single_step_breakpoints
);
3459 print_target_wait_results (ptid_t waiton_ptid
, ptid_t result_ptid
,
3460 const struct target_waitstatus
*ws
)
3462 infrun_debug_printf ("target_wait (%s [%s], status) =",
3463 waiton_ptid
.to_string ().c_str (),
3464 target_pid_to_str (waiton_ptid
).c_str ());
3465 infrun_debug_printf (" %s [%s],",
3466 result_ptid
.to_string ().c_str (),
3467 target_pid_to_str (result_ptid
).c_str ());
3468 infrun_debug_printf (" %s", target_waitstatus_to_string (ws
).c_str ());
3471 /* Select a thread at random, out of those which are resumed and have
3474 static struct thread_info
*
3475 random_pending_event_thread (inferior
*inf
, ptid_t waiton_ptid
)
3477 process_stratum_target
*proc_target
= inf
->process_target ();
3479 = proc_target
->random_resumed_with_pending_wait_status (inf
, waiton_ptid
);
3481 if (thread
== nullptr)
3483 infrun_debug_printf ("None found.");
3487 infrun_debug_printf ("Found %s.", target_pid_to_str (thread
->ptid
).c_str ());
3488 gdb_assert (thread
->resumed ());
3489 gdb_assert (thread
->has_pending_waitstatus ());
3494 /* Wrapper for target_wait that first checks whether threads have
3495 pending statuses to report before actually asking the target for
3496 more events. INF is the inferior we're using to call target_wait
3500 do_target_wait_1 (inferior
*inf
, ptid_t ptid
,
3501 target_waitstatus
*status
, target_wait_flags options
)
3504 struct thread_info
*tp
;
3506 /* We know that we are looking for an event in the target of inferior
3507 INF, but we don't know which thread the event might come from. As
3508 such we want to make sure that INFERIOR_PTID is reset so that none of
3509 the wait code relies on it - doing so is always a mistake. */
3510 switch_to_inferior_no_thread (inf
);
3512 /* First check if there is a resumed thread with a wait status
3514 if (ptid
== minus_one_ptid
|| ptid
.is_pid ())
3516 tp
= random_pending_event_thread (inf
, ptid
);
3520 infrun_debug_printf ("Waiting for specific thread %s.",
3521 target_pid_to_str (ptid
).c_str ());
3523 /* We have a specific thread to check. */
3524 tp
= find_thread_ptid (inf
, ptid
);
3525 gdb_assert (tp
!= NULL
);
3526 if (!tp
->has_pending_waitstatus ())
3531 && (tp
->stop_reason () == TARGET_STOPPED_BY_SW_BREAKPOINT
3532 || tp
->stop_reason () == TARGET_STOPPED_BY_HW_BREAKPOINT
))
3534 struct regcache
*regcache
= get_thread_regcache (tp
);
3535 struct gdbarch
*gdbarch
= regcache
->arch ();
3539 pc
= regcache_read_pc (regcache
);
3541 if (pc
!= tp
->stop_pc ())
3543 infrun_debug_printf ("PC of %s changed. was=%s, now=%s",
3544 target_pid_to_str (tp
->ptid
).c_str (),
3545 paddress (gdbarch
, tp
->stop_pc ()),
3546 paddress (gdbarch
, pc
));
3549 else if (!breakpoint_inserted_here_p (regcache
->aspace (), pc
))
3551 infrun_debug_printf ("previous breakpoint of %s, at %s gone",
3552 target_pid_to_str (tp
->ptid
).c_str (),
3553 paddress (gdbarch
, pc
));
3560 infrun_debug_printf ("pending event of %s cancelled.",
3561 target_pid_to_str (tp
->ptid
).c_str ());
3563 tp
->clear_pending_waitstatus ();
3564 target_waitstatus ws
;
3565 ws
.kind
= TARGET_WAITKIND_SPURIOUS
;
3566 tp
->set_pending_waitstatus (ws
);
3567 tp
->set_stop_reason (TARGET_STOPPED_BY_NO_REASON
);
3573 infrun_debug_printf ("Using pending wait status %s for %s.",
3574 target_waitstatus_to_string
3575 (&tp
->pending_waitstatus ()).c_str (),
3576 target_pid_to_str (tp
->ptid
).c_str ());
3578 /* Now that we've selected our final event LWP, un-adjust its PC
3579 if it was a software breakpoint (and the target doesn't
3580 always adjust the PC itself). */
3581 if (tp
->stop_reason () == TARGET_STOPPED_BY_SW_BREAKPOINT
3582 && !target_supports_stopped_by_sw_breakpoint ())
3584 struct regcache
*regcache
;
3585 struct gdbarch
*gdbarch
;
3588 regcache
= get_thread_regcache (tp
);
3589 gdbarch
= regcache
->arch ();
3591 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
3596 pc
= regcache_read_pc (regcache
);
3597 regcache_write_pc (regcache
, pc
+ decr_pc
);
3601 tp
->set_stop_reason (TARGET_STOPPED_BY_NO_REASON
);
3602 *status
= tp
->pending_waitstatus ();
3603 tp
->clear_pending_waitstatus ();
3605 /* Wake up the event loop again, until all pending events are
3607 if (target_is_async_p ())
3608 mark_async_event_handler (infrun_async_inferior_event_token
);
3612 /* But if we don't find one, we'll have to wait. */
3614 /* We can't ask a non-async target to do a non-blocking wait, so this will be
3616 if (!target_can_async_p ())
3617 options
&= ~TARGET_WNOHANG
;
3619 if (deprecated_target_wait_hook
)
3620 event_ptid
= deprecated_target_wait_hook (ptid
, status
, options
);
3622 event_ptid
= target_wait (ptid
, status
, options
);
3627 /* Wrapper for target_wait that first checks whether threads have
3628 pending statuses to report before actually asking the target for
3629 more events. Polls for events from all inferiors/targets. */
3632 do_target_wait (execution_control_state
*ecs
, target_wait_flags options
)
3634 int num_inferiors
= 0;
3635 int random_selector
;
3637 /* For fairness, we pick the first inferior/target to poll at random
3638 out of all inferiors that may report events, and then continue
3639 polling the rest of the inferior list starting from that one in a
3640 circular fashion until the whole list is polled once. */
3642 auto inferior_matches
= [] (inferior
*inf
)
3644 return inf
->process_target () != nullptr;
3647 /* First see how many matching inferiors we have. */
3648 for (inferior
*inf
: all_inferiors ())
3649 if (inferior_matches (inf
))
3652 if (num_inferiors
== 0)
3654 ecs
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
3658 /* Now randomly pick an inferior out of those that matched. */
3659 random_selector
= (int)
3660 ((num_inferiors
* (double) rand ()) / (RAND_MAX
+ 1.0));
3662 if (num_inferiors
> 1)
3663 infrun_debug_printf ("Found %d inferiors, starting at #%d",
3664 num_inferiors
, random_selector
);
3666 /* Select the Nth inferior that matched. */
3668 inferior
*selected
= nullptr;
3670 for (inferior
*inf
: all_inferiors ())
3671 if (inferior_matches (inf
))
3672 if (random_selector
-- == 0)
3678 /* Now poll for events out of each of the matching inferior's
3679 targets, starting from the selected one. */
3681 auto do_wait
= [&] (inferior
*inf
)
3683 ecs
->ptid
= do_target_wait_1 (inf
, minus_one_ptid
, &ecs
->ws
, options
);
3684 ecs
->target
= inf
->process_target ();
3685 return (ecs
->ws
.kind
!= TARGET_WAITKIND_IGNORE
);
3688 /* Needed in 'all-stop + target-non-stop' mode, because we end up
3689 here spuriously after the target is all stopped and we've already
3690 reported the stop to the user, polling for events. */
3691 scoped_restore_current_thread restore_thread
;
3693 intrusive_list_iterator
<inferior
> start
3694 = inferior_list
.iterator_to (*selected
);
3696 for (intrusive_list_iterator
<inferior
> it
= start
;
3697 it
!= inferior_list
.end ();
3700 inferior
*inf
= &*it
;
3702 if (inferior_matches (inf
) && do_wait (inf
))
3706 for (intrusive_list_iterator
<inferior
> it
= inferior_list
.begin ();
3710 inferior
*inf
= &*it
;
3712 if (inferior_matches (inf
) && do_wait (inf
))
3716 ecs
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
3720 /* An event reported by wait_one. */
3722 struct wait_one_event
3724 /* The target the event came out of. */
3725 process_stratum_target
*target
;
3727 /* The PTID the event was for. */
3730 /* The waitstatus. */
3731 target_waitstatus ws
;
3734 static bool handle_one (const wait_one_event
&event
);
3735 static void restart_threads (struct thread_info
*event_thread
);
3737 /* Prepare and stabilize the inferior for detaching it. E.g.,
3738 detaching while a thread is displaced stepping is a recipe for
3739 crashing it, as nothing would readjust the PC out of the scratch
3743 prepare_for_detach (void)
3745 struct inferior
*inf
= current_inferior ();
3746 ptid_t pid_ptid
= ptid_t (inf
->pid
);
3747 scoped_restore_current_thread restore_thread
;
3749 scoped_restore restore_detaching
= make_scoped_restore (&inf
->detaching
, true);
3751 /* Remove all threads of INF from the global step-over chain. We
3752 want to stop any ongoing step-over, not start any new one. */
3753 thread_step_over_list_safe_range range
3754 = make_thread_step_over_list_safe_range (global_thread_step_over_list
);
3756 for (thread_info
*tp
: range
)
3759 infrun_debug_printf ("removing thread %s from global step over chain",
3760 target_pid_to_str (tp
->ptid
).c_str ());
3761 global_thread_step_over_chain_remove (tp
);
3764 /* If we were already in the middle of an inline step-over, and the
3765 thread stepping belongs to the inferior we're detaching, we need
3766 to restart the threads of other inferiors. */
3767 if (step_over_info
.thread
!= -1)
3769 infrun_debug_printf ("inline step-over in-process while detaching");
3771 thread_info
*thr
= find_thread_global_id (step_over_info
.thread
);
3772 if (thr
->inf
== inf
)
3774 /* Since we removed threads of INF from the step-over chain,
3775 we know this won't start a step-over for INF. */
3776 clear_step_over_info ();
3778 if (target_is_non_stop_p ())
3780 /* Start a new step-over in another thread if there's
3781 one that needs it. */
3784 /* Restart all other threads (except the
3785 previously-stepping thread, since that one is still
3787 if (!step_over_info_valid_p ())
3788 restart_threads (thr
);
3793 if (displaced_step_in_progress (inf
))
3795 infrun_debug_printf ("displaced-stepping in-process while detaching");
3797 /* Stop threads currently displaced stepping, aborting it. */
3799 for (thread_info
*thr
: inf
->non_exited_threads ())
3801 if (thr
->displaced_step_state
.in_progress ())
3803 if (thr
->executing ())
3805 if (!thr
->stop_requested
)
3807 target_stop (thr
->ptid
);
3808 thr
->stop_requested
= true;
3812 thr
->set_resumed (false);
3816 while (displaced_step_in_progress (inf
))
3818 wait_one_event event
;
3820 event
.target
= inf
->process_target ();
3821 event
.ptid
= do_target_wait_1 (inf
, pid_ptid
, &event
.ws
, 0);
3824 print_target_wait_results (pid_ptid
, event
.ptid
, &event
.ws
);
3829 /* It's OK to leave some of the threads of INF stopped, since
3830 they'll be detached shortly. */
3834 /* Wait for control to return from inferior to debugger.
3836 If inferior gets a signal, we may decide to start it up again
3837 instead of returning. That is why there is a loop in this function.
3838 When this function actually returns it means the inferior
3839 should be left stopped and GDB should read more commands. */
3842 wait_for_inferior (inferior
*inf
)
3844 infrun_debug_printf ("wait_for_inferior ()");
3846 SCOPE_EXIT
{ delete_just_stopped_threads_infrun_breakpoints (); };
3848 /* If an error happens while handling the event, propagate GDB's
3849 knowledge of the executing state to the frontend/user running
3851 scoped_finish_thread_state finish_state
3852 (inf
->process_target (), minus_one_ptid
);
3856 struct execution_control_state ecss
;
3857 struct execution_control_state
*ecs
= &ecss
;
3859 memset (ecs
, 0, sizeof (*ecs
));
3861 overlay_cache_invalid
= 1;
3863 /* Flush target cache before starting to handle each event.
3864 Target was running and cache could be stale. This is just a
3865 heuristic. Running threads may modify target memory, but we
3866 don't get any event. */
3867 target_dcache_invalidate ();
3869 ecs
->ptid
= do_target_wait_1 (inf
, minus_one_ptid
, &ecs
->ws
, 0);
3870 ecs
->target
= inf
->process_target ();
3873 print_target_wait_results (minus_one_ptid
, ecs
->ptid
, &ecs
->ws
);
3875 /* Now figure out what to do with the result of the result. */
3876 handle_inferior_event (ecs
);
3878 if (!ecs
->wait_some_more
)
3882 /* No error, don't finish the state yet. */
3883 finish_state
.release ();
3886 /* Cleanup that reinstalls the readline callback handler, if the
3887 target is running in the background. If while handling the target
3888 event something triggered a secondary prompt, like e.g., a
3889 pagination prompt, we'll have removed the callback handler (see
3890 gdb_readline_wrapper_line). Need to do this as we go back to the
3891 event loop, ready to process further input. Note this has no
3892 effect if the handler hasn't actually been removed, because calling
3893 rl_callback_handler_install resets the line buffer, thus losing
3897 reinstall_readline_callback_handler_cleanup ()
3899 struct ui
*ui
= current_ui
;
3903 /* We're not going back to the top level event loop yet. Don't
3904 install the readline callback, as it'd prep the terminal,
3905 readline-style (raw, noecho) (e.g., --batch). We'll install
3906 it the next time the prompt is displayed, when we're ready
3911 if (ui
->command_editing
&& ui
->prompt_state
!= PROMPT_BLOCKED
)
3912 gdb_rl_callback_handler_reinstall ();
3915 /* Clean up the FSMs of threads that are now stopped. In non-stop,
3916 that's just the event thread. In all-stop, that's all threads. */
3919 clean_up_just_stopped_threads_fsms (struct execution_control_state
*ecs
)
3921 if (ecs
->event_thread
!= NULL
3922 && ecs
->event_thread
->thread_fsm
!= NULL
)
3923 ecs
->event_thread
->thread_fsm
->clean_up (ecs
->event_thread
);
3927 for (thread_info
*thr
: all_non_exited_threads ())
3929 if (thr
->thread_fsm
== NULL
)
3931 if (thr
== ecs
->event_thread
)
3934 switch_to_thread (thr
);
3935 thr
->thread_fsm
->clean_up (thr
);
3938 if (ecs
->event_thread
!= NULL
)
3939 switch_to_thread (ecs
->event_thread
);
3943 /* Helper for all_uis_check_sync_execution_done that works on the
3947 check_curr_ui_sync_execution_done (void)
3949 struct ui
*ui
= current_ui
;
3951 if (ui
->prompt_state
== PROMPT_NEEDED
3953 && !gdb_in_secondary_prompt_p (ui
))
3955 target_terminal::ours ();
3956 gdb::observers::sync_execution_done
.notify ();
3957 ui_register_input_event_handler (ui
);
3964 all_uis_check_sync_execution_done (void)
3966 SWITCH_THRU_ALL_UIS ()
3968 check_curr_ui_sync_execution_done ();
3975 all_uis_on_sync_execution_starting (void)
3977 SWITCH_THRU_ALL_UIS ()
3979 if (current_ui
->prompt_state
== PROMPT_NEEDED
)
3980 async_disable_stdin ();
3984 /* Asynchronous version of wait_for_inferior. It is called by the
3985 event loop whenever a change of state is detected on the file
3986 descriptor corresponding to the target. It can be called more than
3987 once to complete a single execution command. In such cases we need
3988 to keep the state in a global variable ECSS. If it is the last time
3989 that this function is called for a single execution command, then
3990 report to the user that the inferior has stopped, and do the
3991 necessary cleanups. */
3994 fetch_inferior_event ()
3996 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
3998 struct execution_control_state ecss
;
3999 struct execution_control_state
*ecs
= &ecss
;
4002 memset (ecs
, 0, sizeof (*ecs
));
4004 /* Events are always processed with the main UI as current UI. This
4005 way, warnings, debug output, etc. are always consistently sent to
4006 the main console. */
4007 scoped_restore save_ui
= make_scoped_restore (¤t_ui
, main_ui
);
4009 /* Temporarily disable pagination. Otherwise, the user would be
4010 given an option to press 'q' to quit, which would cause an early
4011 exit and could leave GDB in a half-baked state. */
4012 scoped_restore save_pagination
4013 = make_scoped_restore (&pagination_enabled
, false);
4015 /* End up with readline processing input, if necessary. */
4017 SCOPE_EXIT
{ reinstall_readline_callback_handler_cleanup (); };
4019 /* We're handling a live event, so make sure we're doing live
4020 debugging. If we're looking at traceframes while the target is
4021 running, we're going to need to get back to that mode after
4022 handling the event. */
4023 gdb::optional
<scoped_restore_current_traceframe
> maybe_restore_traceframe
;
4026 maybe_restore_traceframe
.emplace ();
4027 set_current_traceframe (-1);
4030 /* The user/frontend should not notice a thread switch due to
4031 internal events. Make sure we revert to the user selected
4032 thread and frame after handling the event and running any
4033 breakpoint commands. */
4034 scoped_restore_current_thread restore_thread
;
4036 overlay_cache_invalid
= 1;
4037 /* Flush target cache before starting to handle each event. Target
4038 was running and cache could be stale. This is just a heuristic.
4039 Running threads may modify target memory, but we don't get any
4041 target_dcache_invalidate ();
4043 scoped_restore save_exec_dir
4044 = make_scoped_restore (&execution_direction
,
4045 target_execution_direction ());
4047 /* Allow targets to pause their resumed threads while we handle
4049 scoped_disable_commit_resumed
disable_commit_resumed ("handling event");
4051 if (!do_target_wait (ecs
, TARGET_WNOHANG
))
4053 infrun_debug_printf ("do_target_wait returned no event");
4054 disable_commit_resumed
.reset_and_commit ();
4058 gdb_assert (ecs
->ws
.kind
!= TARGET_WAITKIND_IGNORE
);
4060 /* Switch to the target that generated the event, so we can do
4062 switch_to_target_no_thread (ecs
->target
);
4065 print_target_wait_results (minus_one_ptid
, ecs
->ptid
, &ecs
->ws
);
4067 /* If an error happens while handling the event, propagate GDB's
4068 knowledge of the executing state to the frontend/user running
4070 ptid_t finish_ptid
= !target_is_non_stop_p () ? minus_one_ptid
: ecs
->ptid
;
4071 scoped_finish_thread_state
finish_state (ecs
->target
, finish_ptid
);
4073 /* Get executed before scoped_restore_current_thread above to apply
4074 still for the thread which has thrown the exception. */
4075 auto defer_bpstat_clear
4076 = make_scope_exit (bpstat_clear_actions
);
4077 auto defer_delete_threads
4078 = make_scope_exit (delete_just_stopped_threads_infrun_breakpoints
);
4080 /* Now figure out what to do with the result of the result. */
4081 handle_inferior_event (ecs
);
4083 if (!ecs
->wait_some_more
)
4085 struct inferior
*inf
= find_inferior_ptid (ecs
->target
, ecs
->ptid
);
4086 bool should_stop
= true;
4087 struct thread_info
*thr
= ecs
->event_thread
;
4089 delete_just_stopped_threads_infrun_breakpoints ();
4093 struct thread_fsm
*thread_fsm
= thr
->thread_fsm
;
4095 if (thread_fsm
!= NULL
)
4096 should_stop
= thread_fsm
->should_stop (thr
);
4105 bool should_notify_stop
= true;
4108 clean_up_just_stopped_threads_fsms (ecs
);
4110 if (thr
!= NULL
&& thr
->thread_fsm
!= NULL
)
4111 should_notify_stop
= thr
->thread_fsm
->should_notify_stop ();
4113 if (should_notify_stop
)
4115 /* We may not find an inferior if this was a process exit. */
4116 if (inf
== NULL
|| inf
->control
.stop_soon
== NO_STOP_QUIETLY
)
4117 proceeded
= normal_stop ();
4122 inferior_event_handler (INF_EXEC_COMPLETE
);
4126 /* If we got a TARGET_WAITKIND_NO_RESUMED event, then the
4127 previously selected thread is gone. We have two
4128 choices - switch to no thread selected, or restore the
4129 previously selected thread (now exited). We chose the
4130 later, just because that's what GDB used to do. After
4131 this, "info threads" says "The current thread <Thread
4132 ID 2> has terminated." instead of "No thread
4136 && ecs
->ws
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
4137 restore_thread
.dont_restore ();
4141 defer_delete_threads
.release ();
4142 defer_bpstat_clear
.release ();
4144 /* No error, don't finish the thread states yet. */
4145 finish_state
.release ();
4147 disable_commit_resumed
.reset_and_commit ();
4149 /* This scope is used to ensure that readline callbacks are
4150 reinstalled here. */
4153 /* If a UI was in sync execution mode, and now isn't, restore its
4154 prompt (a synchronous execution command has finished, and we're
4155 ready for input). */
4156 all_uis_check_sync_execution_done ();
4159 && exec_done_display_p
4160 && (inferior_ptid
== null_ptid
4161 || inferior_thread ()->state
!= THREAD_RUNNING
))
4162 printf_unfiltered (_("completed.\n"));
4168 set_step_info (thread_info
*tp
, struct frame_info
*frame
,
4169 struct symtab_and_line sal
)
4171 /* This can be removed once this function no longer implicitly relies on the
4172 inferior_ptid value. */
4173 gdb_assert (inferior_ptid
== tp
->ptid
);
4175 tp
->control
.step_frame_id
= get_frame_id (frame
);
4176 tp
->control
.step_stack_frame_id
= get_stack_frame_id (frame
);
4178 tp
->current_symtab
= sal
.symtab
;
4179 tp
->current_line
= sal
.line
;
4182 /* Clear context switchable stepping state. */
4185 init_thread_stepping_state (struct thread_info
*tss
)
4187 tss
->stepped_breakpoint
= 0;
4188 tss
->stepping_over_breakpoint
= 0;
4189 tss
->stepping_over_watchpoint
= 0;
4190 tss
->step_after_step_resume_breakpoint
= 0;
4196 set_last_target_status (process_stratum_target
*target
, ptid_t ptid
,
4197 target_waitstatus status
)
4199 target_last_proc_target
= target
;
4200 target_last_wait_ptid
= ptid
;
4201 target_last_waitstatus
= status
;
4207 get_last_target_status (process_stratum_target
**target
, ptid_t
*ptid
,
4208 target_waitstatus
*status
)
4210 if (target
!= nullptr)
4211 *target
= target_last_proc_target
;
4212 if (ptid
!= nullptr)
4213 *ptid
= target_last_wait_ptid
;
4214 if (status
!= nullptr)
4215 *status
= target_last_waitstatus
;
4221 nullify_last_target_wait_ptid (void)
4223 target_last_proc_target
= nullptr;
4224 target_last_wait_ptid
= minus_one_ptid
;
4225 target_last_waitstatus
= {};
4228 /* Switch thread contexts. */
4231 context_switch (execution_control_state
*ecs
)
4233 if (ecs
->ptid
!= inferior_ptid
4234 && (inferior_ptid
== null_ptid
4235 || ecs
->event_thread
!= inferior_thread ()))
4237 infrun_debug_printf ("Switching context from %s to %s",
4238 target_pid_to_str (inferior_ptid
).c_str (),
4239 target_pid_to_str (ecs
->ptid
).c_str ());
4242 switch_to_thread (ecs
->event_thread
);
4245 /* If the target can't tell whether we've hit breakpoints
4246 (target_supports_stopped_by_sw_breakpoint), and we got a SIGTRAP,
4247 check whether that could have been caused by a breakpoint. If so,
4248 adjust the PC, per gdbarch_decr_pc_after_break. */
4251 adjust_pc_after_break (struct thread_info
*thread
,
4252 const target_waitstatus
*ws
)
4254 struct regcache
*regcache
;
4255 struct gdbarch
*gdbarch
;
4256 CORE_ADDR breakpoint_pc
, decr_pc
;
4258 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
4259 we aren't, just return.
4261 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
4262 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
4263 implemented by software breakpoints should be handled through the normal
4266 NOTE drow/2004-01-31: On some targets, breakpoints may generate
4267 different signals (SIGILL or SIGEMT for instance), but it is less
4268 clear where the PC is pointing afterwards. It may not match
4269 gdbarch_decr_pc_after_break. I don't know any specific target that
4270 generates these signals at breakpoints (the code has been in GDB since at
4271 least 1992) so I can not guess how to handle them here.
4273 In earlier versions of GDB, a target with
4274 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
4275 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
4276 target with both of these set in GDB history, and it seems unlikely to be
4277 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
4279 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
)
4282 if (ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
4285 /* In reverse execution, when a breakpoint is hit, the instruction
4286 under it has already been de-executed. The reported PC always
4287 points at the breakpoint address, so adjusting it further would
4288 be wrong. E.g., consider this case on a decr_pc_after_break == 1
4291 B1 0x08000000 : INSN1
4292 B2 0x08000001 : INSN2
4294 PC -> 0x08000003 : INSN4
4296 Say you're stopped at 0x08000003 as above. Reverse continuing
4297 from that point should hit B2 as below. Reading the PC when the
4298 SIGTRAP is reported should read 0x08000001 and INSN2 should have
4299 been de-executed already.
4301 B1 0x08000000 : INSN1
4302 B2 PC -> 0x08000001 : INSN2
4306 We can't apply the same logic as for forward execution, because
4307 we would wrongly adjust the PC to 0x08000000, since there's a
4308 breakpoint at PC - 1. We'd then report a hit on B1, although
4309 INSN1 hadn't been de-executed yet. Doing nothing is the correct
4311 if (execution_direction
== EXEC_REVERSE
)
4314 /* If the target can tell whether the thread hit a SW breakpoint,
4315 trust it. Targets that can tell also adjust the PC
4317 if (target_supports_stopped_by_sw_breakpoint ())
4320 /* Note that relying on whether a breakpoint is planted in memory to
4321 determine this can fail. E.g,. the breakpoint could have been
4322 removed since. Or the thread could have been told to step an
4323 instruction the size of a breakpoint instruction, and only
4324 _after_ was a breakpoint inserted at its address. */
4326 /* If this target does not decrement the PC after breakpoints, then
4327 we have nothing to do. */
4328 regcache
= get_thread_regcache (thread
);
4329 gdbarch
= regcache
->arch ();
4331 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
4335 const address_space
*aspace
= regcache
->aspace ();
4337 /* Find the location where (if we've hit a breakpoint) the
4338 breakpoint would be. */
4339 breakpoint_pc
= regcache_read_pc (regcache
) - decr_pc
;
4341 /* If the target can't tell whether a software breakpoint triggered,
4342 fallback to figuring it out based on breakpoints we think were
4343 inserted in the target, and on whether the thread was stepped or
4346 /* Check whether there actually is a software breakpoint inserted at
4349 If in non-stop mode, a race condition is possible where we've
4350 removed a breakpoint, but stop events for that breakpoint were
4351 already queued and arrive later. To suppress those spurious
4352 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
4353 and retire them after a number of stop events are reported. Note
4354 this is an heuristic and can thus get confused. The real fix is
4355 to get the "stopped by SW BP and needs adjustment" info out of
4356 the target/kernel (and thus never reach here; see above). */
4357 if (software_breakpoint_inserted_here_p (aspace
, breakpoint_pc
)
4358 || (target_is_non_stop_p ()
4359 && moribund_breakpoint_here_p (aspace
, breakpoint_pc
)))
4361 gdb::optional
<scoped_restore_tmpl
<int>> restore_operation_disable
;
4363 if (record_full_is_used ())
4364 restore_operation_disable
.emplace
4365 (record_full_gdb_operation_disable_set ());
4367 /* When using hardware single-step, a SIGTRAP is reported for both
4368 a completed single-step and a software breakpoint. Need to
4369 differentiate between the two, as the latter needs adjusting
4370 but the former does not.
4372 The SIGTRAP can be due to a completed hardware single-step only if
4373 - we didn't insert software single-step breakpoints
4374 - this thread is currently being stepped
4376 If any of these events did not occur, we must have stopped due
4377 to hitting a software breakpoint, and have to back up to the
4380 As a special case, we could have hardware single-stepped a
4381 software breakpoint. In this case (prev_pc == breakpoint_pc),
4382 we also need to back up to the breakpoint address. */
4384 if (thread_has_single_step_breakpoints_set (thread
)
4385 || !currently_stepping (thread
)
4386 || (thread
->stepped_breakpoint
4387 && thread
->prev_pc
== breakpoint_pc
))
4388 regcache_write_pc (regcache
, breakpoint_pc
);
4393 stepped_in_from (struct frame_info
*frame
, struct frame_id step_frame_id
)
4395 for (frame
= get_prev_frame (frame
);
4397 frame
= get_prev_frame (frame
))
4399 if (frame_id_eq (get_frame_id (frame
), step_frame_id
))
4402 if (get_frame_type (frame
) != INLINE_FRAME
)
4409 /* Look for an inline frame that is marked for skip.
4410 If PREV_FRAME is TRUE start at the previous frame,
4411 otherwise start at the current frame. Stop at the
4412 first non-inline frame, or at the frame where the
4416 inline_frame_is_marked_for_skip (bool prev_frame
, struct thread_info
*tp
)
4418 struct frame_info
*frame
= get_current_frame ();
4421 frame
= get_prev_frame (frame
);
4423 for (; frame
!= NULL
; frame
= get_prev_frame (frame
))
4425 const char *fn
= NULL
;
4426 symtab_and_line sal
;
4429 if (frame_id_eq (get_frame_id (frame
), tp
->control
.step_frame_id
))
4431 if (get_frame_type (frame
) != INLINE_FRAME
)
4434 sal
= find_frame_sal (frame
);
4435 sym
= get_frame_function (frame
);
4438 fn
= sym
->print_name ();
4441 && function_name_is_marked_for_skip (fn
, sal
))
4448 /* If the event thread has the stop requested flag set, pretend it
4449 stopped for a GDB_SIGNAL_0 (i.e., as if it stopped due to
4453 handle_stop_requested (struct execution_control_state
*ecs
)
4455 if (ecs
->event_thread
->stop_requested
)
4457 ecs
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
4458 ecs
->ws
.value
.sig
= GDB_SIGNAL_0
;
4459 handle_signal_stop (ecs
);
4465 /* Auxiliary function that handles syscall entry/return events.
4466 It returns true if the inferior should keep going (and GDB
4467 should ignore the event), or false if the event deserves to be
4471 handle_syscall_event (struct execution_control_state
*ecs
)
4473 struct regcache
*regcache
;
4476 context_switch (ecs
);
4478 regcache
= get_thread_regcache (ecs
->event_thread
);
4479 syscall_number
= ecs
->ws
.value
.syscall_number
;
4480 ecs
->event_thread
->set_stop_pc (regcache_read_pc (regcache
));
4482 if (catch_syscall_enabled () > 0
4483 && catching_syscall_number (syscall_number
))
4485 infrun_debug_printf ("syscall number=%d", syscall_number
);
4487 ecs
->event_thread
->control
.stop_bpstat
4488 = bpstat_stop_status (regcache
->aspace (),
4489 ecs
->event_thread
->stop_pc (),
4490 ecs
->event_thread
, &ecs
->ws
);
4492 if (handle_stop_requested (ecs
))
4495 if (bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
4497 /* Catchpoint hit. */
4502 if (handle_stop_requested (ecs
))
4505 /* If no catchpoint triggered for this, then keep going. */
4511 /* Lazily fill in the execution_control_state's stop_func_* fields. */
4514 fill_in_stop_func (struct gdbarch
*gdbarch
,
4515 struct execution_control_state
*ecs
)
4517 if (!ecs
->stop_func_filled_in
)
4520 const general_symbol_info
*gsi
;
4522 /* Don't care about return value; stop_func_start and stop_func_name
4523 will both be 0 if it doesn't work. */
4524 find_pc_partial_function_sym (ecs
->event_thread
->stop_pc (),
4526 &ecs
->stop_func_start
,
4527 &ecs
->stop_func_end
,
4529 ecs
->stop_func_name
= gsi
== nullptr ? nullptr : gsi
->print_name ();
4531 /* The call to find_pc_partial_function, above, will set
4532 stop_func_start and stop_func_end to the start and end
4533 of the range containing the stop pc. If this range
4534 contains the entry pc for the block (which is always the
4535 case for contiguous blocks), advance stop_func_start past
4536 the function's start offset and entrypoint. Note that
4537 stop_func_start is NOT advanced when in a range of a
4538 non-contiguous block that does not contain the entry pc. */
4539 if (block
!= nullptr
4540 && ecs
->stop_func_start
<= BLOCK_ENTRY_PC (block
)
4541 && BLOCK_ENTRY_PC (block
) < ecs
->stop_func_end
)
4543 ecs
->stop_func_start
4544 += gdbarch_deprecated_function_start_offset (gdbarch
);
4546 if (gdbarch_skip_entrypoint_p (gdbarch
))
4547 ecs
->stop_func_start
4548 = gdbarch_skip_entrypoint (gdbarch
, ecs
->stop_func_start
);
4551 ecs
->stop_func_filled_in
= 1;
4556 /* Return the STOP_SOON field of the inferior pointed at by ECS. */
4558 static enum stop_kind
4559 get_inferior_stop_soon (execution_control_state
*ecs
)
4561 struct inferior
*inf
= find_inferior_ptid (ecs
->target
, ecs
->ptid
);
4563 gdb_assert (inf
!= NULL
);
4564 return inf
->control
.stop_soon
;
4567 /* Poll for one event out of the current target. Store the resulting
4568 waitstatus in WS, and return the event ptid. Does not block. */
4571 poll_one_curr_target (struct target_waitstatus
*ws
)
4575 overlay_cache_invalid
= 1;
4577 /* Flush target cache before starting to handle each event.
4578 Target was running and cache could be stale. This is just a
4579 heuristic. Running threads may modify target memory, but we
4580 don't get any event. */
4581 target_dcache_invalidate ();
4583 if (deprecated_target_wait_hook
)
4584 event_ptid
= deprecated_target_wait_hook (minus_one_ptid
, ws
, TARGET_WNOHANG
);
4586 event_ptid
= target_wait (minus_one_ptid
, ws
, TARGET_WNOHANG
);
4589 print_target_wait_results (minus_one_ptid
, event_ptid
, ws
);
4594 /* Wait for one event out of any target. */
4596 static wait_one_event
4601 for (inferior
*inf
: all_inferiors ())
4603 process_stratum_target
*target
= inf
->process_target ();
4605 || !target
->is_async_p ()
4606 || !target
->threads_executing
)
4609 switch_to_inferior_no_thread (inf
);
4611 wait_one_event event
;
4612 event
.target
= target
;
4613 event
.ptid
= poll_one_curr_target (&event
.ws
);
4615 if (event
.ws
.kind
== TARGET_WAITKIND_NO_RESUMED
)
4617 /* If nothing is resumed, remove the target from the
4621 else if (event
.ws
.kind
!= TARGET_WAITKIND_IGNORE
)
4625 /* Block waiting for some event. */
4632 for (inferior
*inf
: all_inferiors ())
4634 process_stratum_target
*target
= inf
->process_target ();
4636 || !target
->is_async_p ()
4637 || !target
->threads_executing
)
4640 int fd
= target
->async_wait_fd ();
4641 FD_SET (fd
, &readfds
);
4648 /* No waitable targets left. All must be stopped. */
4649 return {NULL
, minus_one_ptid
, {TARGET_WAITKIND_NO_RESUMED
}};
4654 int numfds
= interruptible_select (nfds
, &readfds
, 0, NULL
, 0);
4660 perror_with_name ("interruptible_select");
4665 /* Save the thread's event and stop reason to process it later. */
4668 save_waitstatus (struct thread_info
*tp
, const target_waitstatus
*ws
)
4670 infrun_debug_printf ("saving status %s for %s",
4671 target_waitstatus_to_string (ws
).c_str (),
4672 tp
->ptid
.to_string ().c_str ());
4674 /* Record for later. */
4675 tp
->set_pending_waitstatus (*ws
);
4677 if (ws
->kind
== TARGET_WAITKIND_STOPPED
4678 && ws
->value
.sig
== GDB_SIGNAL_TRAP
)
4680 struct regcache
*regcache
= get_thread_regcache (tp
);
4681 const address_space
*aspace
= regcache
->aspace ();
4682 CORE_ADDR pc
= regcache_read_pc (regcache
);
4684 adjust_pc_after_break (tp
, &tp
->pending_waitstatus ());
4686 scoped_restore_current_thread restore_thread
;
4687 switch_to_thread (tp
);
4689 if (target_stopped_by_watchpoint ())
4690 tp
->set_stop_reason (TARGET_STOPPED_BY_WATCHPOINT
);
4691 else if (target_supports_stopped_by_sw_breakpoint ()
4692 && target_stopped_by_sw_breakpoint ())
4693 tp
->set_stop_reason (TARGET_STOPPED_BY_SW_BREAKPOINT
);
4694 else if (target_supports_stopped_by_hw_breakpoint ()
4695 && target_stopped_by_hw_breakpoint ())
4696 tp
->set_stop_reason (TARGET_STOPPED_BY_HW_BREAKPOINT
);
4697 else if (!target_supports_stopped_by_hw_breakpoint ()
4698 && hardware_breakpoint_inserted_here_p (aspace
, pc
))
4699 tp
->set_stop_reason (TARGET_STOPPED_BY_HW_BREAKPOINT
);
4700 else if (!target_supports_stopped_by_sw_breakpoint ()
4701 && software_breakpoint_inserted_here_p (aspace
, pc
))
4702 tp
->set_stop_reason (TARGET_STOPPED_BY_SW_BREAKPOINT
);
4703 else if (!thread_has_single_step_breakpoints_set (tp
)
4704 && currently_stepping (tp
))
4705 tp
->set_stop_reason (TARGET_STOPPED_BY_SINGLE_STEP
);
4709 /* Mark the non-executing threads accordingly. In all-stop, all
4710 threads of all processes are stopped when we get any event
4711 reported. In non-stop mode, only the event thread stops. */
4714 mark_non_executing_threads (process_stratum_target
*target
,
4716 struct target_waitstatus ws
)
4720 if (!target_is_non_stop_p ())
4721 mark_ptid
= minus_one_ptid
;
4722 else if (ws
.kind
== TARGET_WAITKIND_SIGNALLED
4723 || ws
.kind
== TARGET_WAITKIND_EXITED
)
4725 /* If we're handling a process exit in non-stop mode, even
4726 though threads haven't been deleted yet, one would think
4727 that there is nothing to do, as threads of the dead process
4728 will be soon deleted, and threads of any other process were
4729 left running. However, on some targets, threads survive a
4730 process exit event. E.g., for the "checkpoint" command,
4731 when the current checkpoint/fork exits, linux-fork.c
4732 automatically switches to another fork from within
4733 target_mourn_inferior, by associating the same
4734 inferior/thread to another fork. We haven't mourned yet at
4735 this point, but we must mark any threads left in the
4736 process as not-executing so that finish_thread_state marks
4737 them stopped (in the user's perspective) if/when we present
4738 the stop to the user. */
4739 mark_ptid
= ptid_t (event_ptid
.pid ());
4742 mark_ptid
= event_ptid
;
4744 set_executing (target
, mark_ptid
, false);
4746 /* Likewise the resumed flag. */
4747 set_resumed (target
, mark_ptid
, false);
4750 /* Handle one event after stopping threads. If the eventing thread
4751 reports back any interesting event, we leave it pending. If the
4752 eventing thread was in the middle of a displaced step, we
4753 cancel/finish it, and unless the thread's inferior is being
4754 detached, put the thread back in the step-over chain. Returns true
4755 if there are no resumed threads left in the target (thus there's no
4756 point in waiting further), false otherwise. */
4759 handle_one (const wait_one_event
&event
)
4762 ("%s %s", target_waitstatus_to_string (&event
.ws
).c_str (),
4763 target_pid_to_str (event
.ptid
).c_str ());
4765 if (event
.ws
.kind
== TARGET_WAITKIND_NO_RESUMED
)
4767 /* All resumed threads exited. */
4770 else if (event
.ws
.kind
== TARGET_WAITKIND_THREAD_EXITED
4771 || event
.ws
.kind
== TARGET_WAITKIND_EXITED
4772 || event
.ws
.kind
== TARGET_WAITKIND_SIGNALLED
)
4774 /* One thread/process exited/signalled. */
4776 thread_info
*t
= nullptr;
4778 /* The target may have reported just a pid. If so, try
4779 the first non-exited thread. */
4780 if (event
.ptid
.is_pid ())
4782 int pid
= event
.ptid
.pid ();
4783 inferior
*inf
= find_inferior_pid (event
.target
, pid
);
4784 for (thread_info
*tp
: inf
->non_exited_threads ())
4790 /* If there is no available thread, the event would
4791 have to be appended to a per-inferior event list,
4792 which does not exist (and if it did, we'd have
4793 to adjust run control command to be able to
4794 resume such an inferior). We assert here instead
4795 of going into an infinite loop. */
4796 gdb_assert (t
!= nullptr);
4799 ("using %s", target_pid_to_str (t
->ptid
).c_str ());
4803 t
= find_thread_ptid (event
.target
, event
.ptid
);
4804 /* Check if this is the first time we see this thread.
4805 Don't bother adding if it individually exited. */
4807 && event
.ws
.kind
!= TARGET_WAITKIND_THREAD_EXITED
)
4808 t
= add_thread (event
.target
, event
.ptid
);
4813 /* Set the threads as non-executing to avoid
4814 another stop attempt on them. */
4815 switch_to_thread_no_regs (t
);
4816 mark_non_executing_threads (event
.target
, event
.ptid
,
4818 save_waitstatus (t
, &event
.ws
);
4819 t
->stop_requested
= false;
4824 thread_info
*t
= find_thread_ptid (event
.target
, event
.ptid
);
4826 t
= add_thread (event
.target
, event
.ptid
);
4828 t
->stop_requested
= 0;
4829 t
->set_executing (false);
4830 t
->set_resumed (false);
4831 t
->control
.may_range_step
= 0;
4833 /* This may be the first time we see the inferior report
4835 inferior
*inf
= find_inferior_ptid (event
.target
, event
.ptid
);
4836 if (inf
->needs_setup
)
4838 switch_to_thread_no_regs (t
);
4842 if (event
.ws
.kind
== TARGET_WAITKIND_STOPPED
4843 && event
.ws
.value
.sig
== GDB_SIGNAL_0
)
4845 /* We caught the event that we intended to catch, so
4846 there's no event to save as pending. */
4848 if (displaced_step_finish (t
, GDB_SIGNAL_0
)
4849 == DISPLACED_STEP_FINISH_STATUS_NOT_EXECUTED
)
4851 /* Add it back to the step-over queue. */
4853 ("displaced-step of %s canceled",
4854 target_pid_to_str (t
->ptid
).c_str ());
4856 t
->control
.trap_expected
= 0;
4857 if (!t
->inf
->detaching
)
4858 global_thread_step_over_chain_enqueue (t
);
4863 enum gdb_signal sig
;
4864 struct regcache
*regcache
;
4867 ("target_wait %s, saving status for %s",
4868 target_waitstatus_to_string (&event
.ws
).c_str (),
4869 t
->ptid
.to_string ().c_str ());
4871 /* Record for later. */
4872 save_waitstatus (t
, &event
.ws
);
4874 sig
= (event
.ws
.kind
== TARGET_WAITKIND_STOPPED
4875 ? event
.ws
.value
.sig
: GDB_SIGNAL_0
);
4877 if (displaced_step_finish (t
, sig
)
4878 == DISPLACED_STEP_FINISH_STATUS_NOT_EXECUTED
)
4880 /* Add it back to the step-over queue. */
4881 t
->control
.trap_expected
= 0;
4882 if (!t
->inf
->detaching
)
4883 global_thread_step_over_chain_enqueue (t
);
4886 regcache
= get_thread_regcache (t
);
4887 t
->set_stop_pc (regcache_read_pc (regcache
));
4889 infrun_debug_printf ("saved stop_pc=%s for %s "
4890 "(currently_stepping=%d)",
4891 paddress (target_gdbarch (), t
->stop_pc ()),
4892 target_pid_to_str (t
->ptid
).c_str (),
4893 currently_stepping (t
));
4903 stop_all_threads (void)
4905 /* We may need multiple passes to discover all threads. */
4909 gdb_assert (exists_non_stop_target ());
4911 infrun_debug_printf ("starting");
4913 scoped_restore_current_thread restore_thread
;
4915 /* Enable thread events of all targets. */
4916 for (auto *target
: all_non_exited_process_targets ())
4918 switch_to_target_no_thread (target
);
4919 target_thread_events (true);
4924 /* Disable thread events of all targets. */
4925 for (auto *target
: all_non_exited_process_targets ())
4927 switch_to_target_no_thread (target
);
4928 target_thread_events (false);
4931 /* Use debug_prefixed_printf directly to get a meaningful function
4934 debug_prefixed_printf ("infrun", "stop_all_threads", "done");
4937 /* Request threads to stop, and then wait for the stops. Because
4938 threads we already know about can spawn more threads while we're
4939 trying to stop them, and we only learn about new threads when we
4940 update the thread list, do this in a loop, and keep iterating
4941 until two passes find no threads that need to be stopped. */
4942 for (pass
= 0; pass
< 2; pass
++, iterations
++)
4944 infrun_debug_printf ("pass=%d, iterations=%d", pass
, iterations
);
4947 int waits_needed
= 0;
4949 for (auto *target
: all_non_exited_process_targets ())
4951 switch_to_target_no_thread (target
);
4952 update_thread_list ();
4955 /* Go through all threads looking for threads that we need
4956 to tell the target to stop. */
4957 for (thread_info
*t
: all_non_exited_threads ())
4959 /* For a single-target setting with an all-stop target,
4960 we would not even arrive here. For a multi-target
4961 setting, until GDB is able to handle a mixture of
4962 all-stop and non-stop targets, simply skip all-stop
4963 targets' threads. This should be fine due to the
4964 protection of 'check_multi_target_resumption'. */
4966 switch_to_thread_no_regs (t
);
4967 if (!target_is_non_stop_p ())
4970 if (t
->executing ())
4972 /* If already stopping, don't request a stop again.
4973 We just haven't seen the notification yet. */
4974 if (!t
->stop_requested
)
4976 infrun_debug_printf (" %s executing, need stop",
4977 target_pid_to_str (t
->ptid
).c_str ());
4978 target_stop (t
->ptid
);
4979 t
->stop_requested
= 1;
4983 infrun_debug_printf (" %s executing, already stopping",
4984 target_pid_to_str (t
->ptid
).c_str ());
4987 if (t
->stop_requested
)
4992 infrun_debug_printf (" %s not executing",
4993 target_pid_to_str (t
->ptid
).c_str ());
4995 /* The thread may be not executing, but still be
4996 resumed with a pending status to process. */
4997 t
->set_resumed (false);
5001 if (waits_needed
== 0)
5004 /* If we find new threads on the second iteration, restart
5005 over. We want to see two iterations in a row with all
5010 for (int i
= 0; i
< waits_needed
; i
++)
5012 wait_one_event event
= wait_one ();
5013 if (handle_one (event
))
5020 /* Handle a TARGET_WAITKIND_NO_RESUMED event. */
5023 handle_no_resumed (struct execution_control_state
*ecs
)
5025 if (target_can_async_p ())
5027 bool any_sync
= false;
5029 for (ui
*ui
: all_uis ())
5031 if (ui
->prompt_state
== PROMPT_BLOCKED
)
5039 /* There were no unwaited-for children left in the target, but,
5040 we're not synchronously waiting for events either. Just
5043 infrun_debug_printf ("TARGET_WAITKIND_NO_RESUMED (ignoring: bg)");
5044 prepare_to_wait (ecs
);
5049 /* Otherwise, if we were running a synchronous execution command, we
5050 may need to cancel it and give the user back the terminal.
5052 In non-stop mode, the target can't tell whether we've already
5053 consumed previous stop events, so it can end up sending us a
5054 no-resumed event like so:
5056 #0 - thread 1 is left stopped
5058 #1 - thread 2 is resumed and hits breakpoint
5059 -> TARGET_WAITKIND_STOPPED
5061 #2 - thread 3 is resumed and exits
5062 this is the last resumed thread, so
5063 -> TARGET_WAITKIND_NO_RESUMED
5065 #3 - gdb processes stop for thread 2 and decides to re-resume
5068 #4 - gdb processes the TARGET_WAITKIND_NO_RESUMED event.
5069 thread 2 is now resumed, so the event should be ignored.
5071 IOW, if the stop for thread 2 doesn't end a foreground command,
5072 then we need to ignore the following TARGET_WAITKIND_NO_RESUMED
5073 event. But it could be that the event meant that thread 2 itself
5074 (or whatever other thread was the last resumed thread) exited.
5076 To address this we refresh the thread list and check whether we
5077 have resumed threads _now_. In the example above, this removes
5078 thread 3 from the thread list. If thread 2 was re-resumed, we
5079 ignore this event. If we find no thread resumed, then we cancel
5080 the synchronous command and show "no unwaited-for " to the
5083 inferior
*curr_inf
= current_inferior ();
5085 scoped_restore_current_thread restore_thread
;
5087 for (auto *target
: all_non_exited_process_targets ())
5089 switch_to_target_no_thread (target
);
5090 update_thread_list ();
5095 - the current target has no thread executing, and
5096 - the current inferior is native, and
5097 - the current inferior is the one which has the terminal, and
5100 then a Ctrl-C from this point on would remain stuck in the
5101 kernel, until a thread resumes and dequeues it. That would
5102 result in the GDB CLI not reacting to Ctrl-C, not able to
5103 interrupt the program. To address this, if the current inferior
5104 no longer has any thread executing, we give the terminal to some
5105 other inferior that has at least one thread executing. */
5106 bool swap_terminal
= true;
5108 /* Whether to ignore this TARGET_WAITKIND_NO_RESUMED event, or
5109 whether to report it to the user. */
5110 bool ignore_event
= false;
5112 for (thread_info
*thread
: all_non_exited_threads ())
5114 if (swap_terminal
&& thread
->executing ())
5116 if (thread
->inf
!= curr_inf
)
5118 target_terminal::ours ();
5120 switch_to_thread (thread
);
5121 target_terminal::inferior ();
5123 swap_terminal
= false;
5127 && (thread
->executing () || thread
->has_pending_waitstatus ()))
5129 /* Either there were no unwaited-for children left in the
5130 target at some point, but there are now, or some target
5131 other than the eventing one has unwaited-for children
5132 left. Just ignore. */
5133 infrun_debug_printf ("TARGET_WAITKIND_NO_RESUMED "
5134 "(ignoring: found resumed)");
5136 ignore_event
= true;
5139 if (ignore_event
&& !swap_terminal
)
5145 switch_to_inferior_no_thread (curr_inf
);
5146 prepare_to_wait (ecs
);
5150 /* Go ahead and report the event. */
5154 /* Given an execution control state that has been freshly filled in by
5155 an event from the inferior, figure out what it means and take
5158 The alternatives are:
5160 1) stop_waiting and return; to really stop and return to the
5163 2) keep_going and return; to wait for the next event (set
5164 ecs->event_thread->stepping_over_breakpoint to 1 to single step
5168 handle_inferior_event (struct execution_control_state
*ecs
)
5170 /* Make sure that all temporary struct value objects that were
5171 created during the handling of the event get deleted at the
5173 scoped_value_mark free_values
;
5175 infrun_debug_printf ("%s", target_waitstatus_to_string (&ecs
->ws
).c_str ());
5177 if (ecs
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
5179 /* We had an event in the inferior, but we are not interested in
5180 handling it at this level. The lower layers have already
5181 done what needs to be done, if anything.
5183 One of the possible circumstances for this is when the
5184 inferior produces output for the console. The inferior has
5185 not stopped, and we are ignoring the event. Another possible
5186 circumstance is any event which the lower level knows will be
5187 reported multiple times without an intervening resume. */
5188 prepare_to_wait (ecs
);
5192 if (ecs
->ws
.kind
== TARGET_WAITKIND_THREAD_EXITED
)
5194 prepare_to_wait (ecs
);
5198 if (ecs
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
5199 && handle_no_resumed (ecs
))
5202 /* Cache the last target/ptid/waitstatus. */
5203 set_last_target_status (ecs
->target
, ecs
->ptid
, ecs
->ws
);
5205 /* Always clear state belonging to the previous time we stopped. */
5206 stop_stack_dummy
= STOP_NONE
;
5208 if (ecs
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
)
5210 /* No unwaited-for children left. IOW, all resumed children
5212 stop_print_frame
= false;
5217 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
5218 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
)
5220 ecs
->event_thread
= find_thread_ptid (ecs
->target
, ecs
->ptid
);
5221 /* If it's a new thread, add it to the thread database. */
5222 if (ecs
->event_thread
== NULL
)
5223 ecs
->event_thread
= add_thread (ecs
->target
, ecs
->ptid
);
5225 /* Disable range stepping. If the next step request could use a
5226 range, this will be end up re-enabled then. */
5227 ecs
->event_thread
->control
.may_range_step
= 0;
5230 /* Dependent on valid ECS->EVENT_THREAD. */
5231 adjust_pc_after_break (ecs
->event_thread
, &ecs
->ws
);
5233 /* Dependent on the current PC value modified by adjust_pc_after_break. */
5234 reinit_frame_cache ();
5236 breakpoint_retire_moribund ();
5238 /* First, distinguish signals caused by the debugger from signals
5239 that have to do with the program's own actions. Note that
5240 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
5241 on the operating system version. Here we detect when a SIGILL or
5242 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
5243 something similar for SIGSEGV, since a SIGSEGV will be generated
5244 when we're trying to execute a breakpoint instruction on a
5245 non-executable stack. This happens for call dummy breakpoints
5246 for architectures like SPARC that place call dummies on the
5248 if (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
5249 && (ecs
->ws
.value
.sig
== GDB_SIGNAL_ILL
5250 || ecs
->ws
.value
.sig
== GDB_SIGNAL_SEGV
5251 || ecs
->ws
.value
.sig
== GDB_SIGNAL_EMT
))
5253 struct regcache
*regcache
= get_thread_regcache (ecs
->event_thread
);
5255 if (breakpoint_inserted_here_p (regcache
->aspace (),
5256 regcache_read_pc (regcache
)))
5258 infrun_debug_printf ("Treating signal as SIGTRAP");
5259 ecs
->ws
.value
.sig
= GDB_SIGNAL_TRAP
;
5263 mark_non_executing_threads (ecs
->target
, ecs
->ptid
, ecs
->ws
);
5265 switch (ecs
->ws
.kind
)
5267 case TARGET_WAITKIND_LOADED
:
5269 context_switch (ecs
);
5270 /* Ignore gracefully during startup of the inferior, as it might
5271 be the shell which has just loaded some objects, otherwise
5272 add the symbols for the newly loaded objects. Also ignore at
5273 the beginning of an attach or remote session; we will query
5274 the full list of libraries once the connection is
5277 stop_kind stop_soon
= get_inferior_stop_soon (ecs
);
5278 if (stop_soon
== NO_STOP_QUIETLY
)
5280 struct regcache
*regcache
;
5282 regcache
= get_thread_regcache (ecs
->event_thread
);
5284 handle_solib_event ();
5286 ecs
->event_thread
->control
.stop_bpstat
5287 = bpstat_stop_status (regcache
->aspace (),
5288 ecs
->event_thread
->stop_pc (),
5289 ecs
->event_thread
, &ecs
->ws
);
5291 if (handle_stop_requested (ecs
))
5294 if (bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
5296 /* A catchpoint triggered. */
5297 process_event_stop_test (ecs
);
5301 /* If requested, stop when the dynamic linker notifies
5302 gdb of events. This allows the user to get control
5303 and place breakpoints in initializer routines for
5304 dynamically loaded objects (among other things). */
5305 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
5306 if (stop_on_solib_events
)
5308 /* Make sure we print "Stopped due to solib-event" in
5310 stop_print_frame
= true;
5317 /* If we are skipping through a shell, or through shared library
5318 loading that we aren't interested in, resume the program. If
5319 we're running the program normally, also resume. */
5320 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== NO_STOP_QUIETLY
)
5322 /* Loading of shared libraries might have changed breakpoint
5323 addresses. Make sure new breakpoints are inserted. */
5324 if (stop_soon
== NO_STOP_QUIETLY
)
5325 insert_breakpoints ();
5326 resume (GDB_SIGNAL_0
);
5327 prepare_to_wait (ecs
);
5331 /* But stop if we're attaching or setting up a remote
5333 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
5334 || stop_soon
== STOP_QUIETLY_REMOTE
)
5336 infrun_debug_printf ("quietly stopped");
5341 internal_error (__FILE__
, __LINE__
,
5342 _("unhandled stop_soon: %d"), (int) stop_soon
);
5345 case TARGET_WAITKIND_SPURIOUS
:
5346 if (handle_stop_requested (ecs
))
5348 context_switch (ecs
);
5349 resume (GDB_SIGNAL_0
);
5350 prepare_to_wait (ecs
);
5353 case TARGET_WAITKIND_THREAD_CREATED
:
5354 if (handle_stop_requested (ecs
))
5356 context_switch (ecs
);
5357 if (!switch_back_to_stepped_thread (ecs
))
5361 case TARGET_WAITKIND_EXITED
:
5362 case TARGET_WAITKIND_SIGNALLED
:
5364 /* Depending on the system, ecs->ptid may point to a thread or
5365 to a process. On some targets, target_mourn_inferior may
5366 need to have access to the just-exited thread. That is the
5367 case of GNU/Linux's "checkpoint" support, for example.
5368 Call the switch_to_xxx routine as appropriate. */
5369 thread_info
*thr
= find_thread_ptid (ecs
->target
, ecs
->ptid
);
5371 switch_to_thread (thr
);
5374 inferior
*inf
= find_inferior_ptid (ecs
->target
, ecs
->ptid
);
5375 switch_to_inferior_no_thread (inf
);
5378 handle_vfork_child_exec_or_exit (0);
5379 target_terminal::ours (); /* Must do this before mourn anyway. */
5381 /* Clearing any previous state of convenience variables. */
5382 clear_exit_convenience_vars ();
5384 if (ecs
->ws
.kind
== TARGET_WAITKIND_EXITED
)
5386 /* Record the exit code in the convenience variable $_exitcode, so
5387 that the user can inspect this again later. */
5388 set_internalvar_integer (lookup_internalvar ("_exitcode"),
5389 (LONGEST
) ecs
->ws
.value
.integer
);
5391 /* Also record this in the inferior itself. */
5392 current_inferior ()->has_exit_code
= 1;
5393 current_inferior ()->exit_code
= (LONGEST
) ecs
->ws
.value
.integer
;
5395 /* Support the --return-child-result option. */
5396 return_child_result_value
= ecs
->ws
.value
.integer
;
5398 gdb::observers::exited
.notify (ecs
->ws
.value
.integer
);
5402 struct gdbarch
*gdbarch
= current_inferior ()->gdbarch
;
5404 if (gdbarch_gdb_signal_to_target_p (gdbarch
))
5406 /* Set the value of the internal variable $_exitsignal,
5407 which holds the signal uncaught by the inferior. */
5408 set_internalvar_integer (lookup_internalvar ("_exitsignal"),
5409 gdbarch_gdb_signal_to_target (gdbarch
,
5410 ecs
->ws
.value
.sig
));
5414 /* We don't have access to the target's method used for
5415 converting between signal numbers (GDB's internal
5416 representation <-> target's representation).
5417 Therefore, we cannot do a good job at displaying this
5418 information to the user. It's better to just warn
5419 her about it (if infrun debugging is enabled), and
5421 infrun_debug_printf ("Cannot fill $_exitsignal with the correct "
5425 gdb::observers::signal_exited
.notify (ecs
->ws
.value
.sig
);
5428 gdb_flush (gdb_stdout
);
5429 target_mourn_inferior (inferior_ptid
);
5430 stop_print_frame
= false;
5434 case TARGET_WAITKIND_FORKED
:
5435 case TARGET_WAITKIND_VFORKED
:
5436 /* Check whether the inferior is displaced stepping. */
5438 struct regcache
*regcache
= get_thread_regcache (ecs
->event_thread
);
5439 struct gdbarch
*gdbarch
= regcache
->arch ();
5440 inferior
*parent_inf
= find_inferior_ptid (ecs
->target
, ecs
->ptid
);
5442 /* If this is a fork (child gets its own address space copy)
5443 and some displaced step buffers were in use at the time of
5444 the fork, restore the displaced step buffer bytes in the
5447 Architectures which support displaced stepping and fork
5448 events must supply an implementation of
5449 gdbarch_displaced_step_restore_all_in_ptid. This is not
5450 enforced during gdbarch validation to support architectures
5451 which support displaced stepping but not forks. */
5452 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
5453 && gdbarch_supports_displaced_stepping (gdbarch
))
5454 gdbarch_displaced_step_restore_all_in_ptid
5455 (gdbarch
, parent_inf
, ecs
->ws
.value
.related_pid
);
5457 /* If displaced stepping is supported, and thread ecs->ptid is
5458 displaced stepping. */
5459 if (displaced_step_in_progress_thread (ecs
->event_thread
))
5461 struct regcache
*child_regcache
;
5462 CORE_ADDR parent_pc
;
5464 /* GDB has got TARGET_WAITKIND_FORKED or TARGET_WAITKIND_VFORKED,
5465 indicating that the displaced stepping of syscall instruction
5466 has been done. Perform cleanup for parent process here. Note
5467 that this operation also cleans up the child process for vfork,
5468 because their pages are shared. */
5469 displaced_step_finish (ecs
->event_thread
, GDB_SIGNAL_TRAP
);
5470 /* Start a new step-over in another thread if there's one
5474 /* Since the vfork/fork syscall instruction was executed in the scratchpad,
5475 the child's PC is also within the scratchpad. Set the child's PC
5476 to the parent's PC value, which has already been fixed up.
5477 FIXME: we use the parent's aspace here, although we're touching
5478 the child, because the child hasn't been added to the inferior
5479 list yet at this point. */
5482 = get_thread_arch_aspace_regcache (parent_inf
->process_target (),
5483 ecs
->ws
.value
.related_pid
,
5485 parent_inf
->aspace
);
5486 /* Read PC value of parent process. */
5487 parent_pc
= regcache_read_pc (regcache
);
5489 displaced_debug_printf ("write child pc from %s to %s",
5491 regcache_read_pc (child_regcache
)),
5492 paddress (gdbarch
, parent_pc
));
5494 regcache_write_pc (child_regcache
, parent_pc
);
5498 context_switch (ecs
);
5500 /* Immediately detach breakpoints from the child before there's
5501 any chance of letting the user delete breakpoints from the
5502 breakpoint lists. If we don't do this early, it's easy to
5503 leave left over traps in the child, vis: "break foo; catch
5504 fork; c; <fork>; del; c; <child calls foo>". We only follow
5505 the fork on the last `continue', and by that time the
5506 breakpoint at "foo" is long gone from the breakpoint table.
5507 If we vforked, then we don't need to unpatch here, since both
5508 parent and child are sharing the same memory pages; we'll
5509 need to unpatch at follow/detach time instead to be certain
5510 that new breakpoints added between catchpoint hit time and
5511 vfork follow are detached. */
5512 if (ecs
->ws
.kind
!= TARGET_WAITKIND_VFORKED
)
5514 /* This won't actually modify the breakpoint list, but will
5515 physically remove the breakpoints from the child. */
5516 detach_breakpoints (ecs
->ws
.value
.related_pid
);
5519 delete_just_stopped_threads_single_step_breakpoints ();
5521 /* In case the event is caught by a catchpoint, remember that
5522 the event is to be followed at the next resume of the thread,
5523 and not immediately. */
5524 ecs
->event_thread
->pending_follow
= ecs
->ws
;
5526 ecs
->event_thread
->set_stop_pc
5527 (regcache_read_pc (get_thread_regcache (ecs
->event_thread
)));
5529 ecs
->event_thread
->control
.stop_bpstat
5530 = bpstat_stop_status (get_current_regcache ()->aspace (),
5531 ecs
->event_thread
->stop_pc (),
5532 ecs
->event_thread
, &ecs
->ws
);
5534 if (handle_stop_requested (ecs
))
5537 /* If no catchpoint triggered for this, then keep going. Note
5538 that we're interested in knowing the bpstat actually causes a
5539 stop, not just if it may explain the signal. Software
5540 watchpoints, for example, always appear in the bpstat. */
5541 if (!bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
5544 = (follow_fork_mode_string
== follow_fork_mode_child
);
5546 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
5548 process_stratum_target
*targ
5549 = ecs
->event_thread
->inf
->process_target ();
5551 bool should_resume
= follow_fork ();
5553 /* Note that one of these may be an invalid pointer,
5554 depending on detach_fork. */
5555 thread_info
*parent
= ecs
->event_thread
;
5557 = find_thread_ptid (targ
, ecs
->ws
.value
.related_pid
);
5559 /* At this point, the parent is marked running, and the
5560 child is marked stopped. */
5562 /* If not resuming the parent, mark it stopped. */
5563 if (follow_child
&& !detach_fork
&& !non_stop
&& !sched_multi
)
5564 parent
->set_running (false);
5566 /* If resuming the child, mark it running. */
5567 if (follow_child
|| (!detach_fork
&& (non_stop
|| sched_multi
)))
5568 child
->set_running (true);
5570 /* In non-stop mode, also resume the other branch. */
5571 if (!detach_fork
&& (non_stop
5572 || (sched_multi
&& target_is_non_stop_p ())))
5575 switch_to_thread (parent
);
5577 switch_to_thread (child
);
5579 ecs
->event_thread
= inferior_thread ();
5580 ecs
->ptid
= inferior_ptid
;
5585 switch_to_thread (child
);
5587 switch_to_thread (parent
);
5589 ecs
->event_thread
= inferior_thread ();
5590 ecs
->ptid
= inferior_ptid
;
5598 process_event_stop_test (ecs
);
5601 case TARGET_WAITKIND_VFORK_DONE
:
5602 /* Done with the shared memory region. Re-insert breakpoints in
5603 the parent, and keep going. */
5605 context_switch (ecs
);
5607 current_inferior ()->waiting_for_vfork_done
= 0;
5608 current_inferior ()->pspace
->breakpoints_not_allowed
= 0;
5610 if (handle_stop_requested (ecs
))
5613 /* This also takes care of reinserting breakpoints in the
5614 previously locked inferior. */
5618 case TARGET_WAITKIND_EXECD
:
5620 /* Note we can't read registers yet (the stop_pc), because we
5621 don't yet know the inferior's post-exec architecture.
5622 'stop_pc' is explicitly read below instead. */
5623 switch_to_thread_no_regs (ecs
->event_thread
);
5625 /* Do whatever is necessary to the parent branch of the vfork. */
5626 handle_vfork_child_exec_or_exit (1);
5628 /* This causes the eventpoints and symbol table to be reset.
5629 Must do this now, before trying to determine whether to
5631 follow_exec (inferior_ptid
, ecs
->ws
.value
.execd_pathname
);
5633 /* In follow_exec we may have deleted the original thread and
5634 created a new one. Make sure that the event thread is the
5635 execd thread for that case (this is a nop otherwise). */
5636 ecs
->event_thread
= inferior_thread ();
5638 ecs
->event_thread
->set_stop_pc
5639 (regcache_read_pc (get_thread_regcache (ecs
->event_thread
)));
5641 ecs
->event_thread
->control
.stop_bpstat
5642 = bpstat_stop_status (get_current_regcache ()->aspace (),
5643 ecs
->event_thread
->stop_pc (),
5644 ecs
->event_thread
, &ecs
->ws
);
5646 /* Note that this may be referenced from inside
5647 bpstat_stop_status above, through inferior_has_execd. */
5648 xfree (ecs
->ws
.value
.execd_pathname
);
5649 ecs
->ws
.value
.execd_pathname
= NULL
;
5651 if (handle_stop_requested (ecs
))
5654 /* If no catchpoint triggered for this, then keep going. */
5655 if (!bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
5657 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
5661 process_event_stop_test (ecs
);
5664 /* Be careful not to try to gather much state about a thread
5665 that's in a syscall. It's frequently a losing proposition. */
5666 case TARGET_WAITKIND_SYSCALL_ENTRY
:
5667 /* Getting the current syscall number. */
5668 if (handle_syscall_event (ecs
) == 0)
5669 process_event_stop_test (ecs
);
5672 /* Before examining the threads further, step this thread to
5673 get it entirely out of the syscall. (We get notice of the
5674 event when the thread is just on the verge of exiting a
5675 syscall. Stepping one instruction seems to get it back
5677 case TARGET_WAITKIND_SYSCALL_RETURN
:
5678 if (handle_syscall_event (ecs
) == 0)
5679 process_event_stop_test (ecs
);
5682 case TARGET_WAITKIND_STOPPED
:
5683 handle_signal_stop (ecs
);
5686 case TARGET_WAITKIND_NO_HISTORY
:
5687 /* Reverse execution: target ran out of history info. */
5689 /* Switch to the stopped thread. */
5690 context_switch (ecs
);
5691 infrun_debug_printf ("stopped");
5693 delete_just_stopped_threads_single_step_breakpoints ();
5694 ecs
->event_thread
->set_stop_pc
5695 (regcache_read_pc (get_thread_regcache (inferior_thread ())));
5697 if (handle_stop_requested (ecs
))
5700 gdb::observers::no_history
.notify ();
5706 /* Restart threads back to what they were trying to do back when we
5707 paused them for an in-line step-over. The EVENT_THREAD thread is
5711 restart_threads (struct thread_info
*event_thread
)
5713 /* In case the instruction just stepped spawned a new thread. */
5714 update_thread_list ();
5716 for (thread_info
*tp
: all_non_exited_threads ())
5718 if (tp
->inf
->detaching
)
5720 infrun_debug_printf ("restart threads: [%s] inferior detaching",
5721 target_pid_to_str (tp
->ptid
).c_str ());
5725 switch_to_thread_no_regs (tp
);
5727 if (tp
== event_thread
)
5729 infrun_debug_printf ("restart threads: [%s] is event thread",
5730 target_pid_to_str (tp
->ptid
).c_str ());
5734 if (!(tp
->state
== THREAD_RUNNING
|| tp
->control
.in_infcall
))
5736 infrun_debug_printf ("restart threads: [%s] not meant to be running",
5737 target_pid_to_str (tp
->ptid
).c_str ());
5743 infrun_debug_printf ("restart threads: [%s] resumed",
5744 target_pid_to_str (tp
->ptid
).c_str ());
5745 gdb_assert (tp
->executing () || tp
->has_pending_waitstatus ());
5749 if (thread_is_in_step_over_chain (tp
))
5751 infrun_debug_printf ("restart threads: [%s] needs step-over",
5752 target_pid_to_str (tp
->ptid
).c_str ());
5753 gdb_assert (!tp
->resumed ());
5758 if (tp
->has_pending_waitstatus ())
5760 infrun_debug_printf ("restart threads: [%s] has pending status",
5761 target_pid_to_str (tp
->ptid
).c_str ());
5762 tp
->set_resumed (true);
5766 gdb_assert (!tp
->stop_requested
);
5768 /* If some thread needs to start a step-over at this point, it
5769 should still be in the step-over queue, and thus skipped
5771 if (thread_still_needs_step_over (tp
))
5773 internal_error (__FILE__
, __LINE__
,
5774 "thread [%s] needs a step-over, but not in "
5775 "step-over queue\n",
5776 target_pid_to_str (tp
->ptid
).c_str ());
5779 if (currently_stepping (tp
))
5781 infrun_debug_printf ("restart threads: [%s] was stepping",
5782 target_pid_to_str (tp
->ptid
).c_str ());
5783 keep_going_stepped_thread (tp
);
5787 struct execution_control_state ecss
;
5788 struct execution_control_state
*ecs
= &ecss
;
5790 infrun_debug_printf ("restart threads: [%s] continuing",
5791 target_pid_to_str (tp
->ptid
).c_str ());
5792 reset_ecs (ecs
, tp
);
5793 switch_to_thread (tp
);
5794 keep_going_pass_signal (ecs
);
5799 /* Callback for iterate_over_threads. Find a resumed thread that has
5800 a pending waitstatus. */
5803 resumed_thread_with_pending_status (struct thread_info
*tp
,
5806 return tp
->resumed () && tp
->has_pending_waitstatus ();
5809 /* Called when we get an event that may finish an in-line or
5810 out-of-line (displaced stepping) step-over started previously.
5811 Return true if the event is processed and we should go back to the
5812 event loop; false if the caller should continue processing the
5816 finish_step_over (struct execution_control_state
*ecs
)
5818 displaced_step_finish (ecs
->event_thread
, ecs
->event_thread
->stop_signal ());
5820 bool had_step_over_info
= step_over_info_valid_p ();
5822 if (had_step_over_info
)
5824 /* If we're stepping over a breakpoint with all threads locked,
5825 then only the thread that was stepped should be reporting
5827 gdb_assert (ecs
->event_thread
->control
.trap_expected
);
5829 clear_step_over_info ();
5832 if (!target_is_non_stop_p ())
5835 /* Start a new step-over in another thread if there's one that
5839 /* If we were stepping over a breakpoint before, and haven't started
5840 a new in-line step-over sequence, then restart all other threads
5841 (except the event thread). We can't do this in all-stop, as then
5842 e.g., we wouldn't be able to issue any other remote packet until
5843 these other threads stop. */
5844 if (had_step_over_info
&& !step_over_info_valid_p ())
5846 struct thread_info
*pending
;
5848 /* If we only have threads with pending statuses, the restart
5849 below won't restart any thread and so nothing re-inserts the
5850 breakpoint we just stepped over. But we need it inserted
5851 when we later process the pending events, otherwise if
5852 another thread has a pending event for this breakpoint too,
5853 we'd discard its event (because the breakpoint that
5854 originally caused the event was no longer inserted). */
5855 context_switch (ecs
);
5856 insert_breakpoints ();
5858 restart_threads (ecs
->event_thread
);
5860 /* If we have events pending, go through handle_inferior_event
5861 again, picking up a pending event at random. This avoids
5862 thread starvation. */
5864 /* But not if we just stepped over a watchpoint in order to let
5865 the instruction execute so we can evaluate its expression.
5866 The set of watchpoints that triggered is recorded in the
5867 breakpoint objects themselves (see bp->watchpoint_triggered).
5868 If we processed another event first, that other event could
5869 clobber this info. */
5870 if (ecs
->event_thread
->stepping_over_watchpoint
)
5873 pending
= iterate_over_threads (resumed_thread_with_pending_status
,
5875 if (pending
!= NULL
)
5877 struct thread_info
*tp
= ecs
->event_thread
;
5878 struct regcache
*regcache
;
5880 infrun_debug_printf ("found resumed threads with "
5881 "pending events, saving status");
5883 gdb_assert (pending
!= tp
);
5885 /* Record the event thread's event for later. */
5886 save_waitstatus (tp
, &ecs
->ws
);
5887 /* This was cleared early, by handle_inferior_event. Set it
5888 so this pending event is considered by
5890 tp
->set_resumed (true);
5892 gdb_assert (!tp
->executing ());
5894 regcache
= get_thread_regcache (tp
);
5895 tp
->set_stop_pc (regcache_read_pc (regcache
));
5897 infrun_debug_printf ("saved stop_pc=%s for %s "
5898 "(currently_stepping=%d)",
5899 paddress (target_gdbarch (), tp
->stop_pc ()),
5900 target_pid_to_str (tp
->ptid
).c_str (),
5901 currently_stepping (tp
));
5903 /* This in-line step-over finished; clear this so we won't
5904 start a new one. This is what handle_signal_stop would
5905 do, if we returned false. */
5906 tp
->stepping_over_breakpoint
= 0;
5908 /* Wake up the event loop again. */
5909 mark_async_event_handler (infrun_async_inferior_event_token
);
5911 prepare_to_wait (ecs
);
5919 /* Come here when the program has stopped with a signal. */
5922 handle_signal_stop (struct execution_control_state
*ecs
)
5924 struct frame_info
*frame
;
5925 struct gdbarch
*gdbarch
;
5926 int stopped_by_watchpoint
;
5927 enum stop_kind stop_soon
;
5930 gdb_assert (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
5932 ecs
->event_thread
->set_stop_signal (ecs
->ws
.value
.sig
);
5934 /* Do we need to clean up the state of a thread that has
5935 completed a displaced single-step? (Doing so usually affects
5936 the PC, so do it here, before we set stop_pc.) */
5937 if (finish_step_over (ecs
))
5940 /* If we either finished a single-step or hit a breakpoint, but
5941 the user wanted this thread to be stopped, pretend we got a
5942 SIG0 (generic unsignaled stop). */
5943 if (ecs
->event_thread
->stop_requested
5944 && ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
)
5945 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
5947 ecs
->event_thread
->set_stop_pc
5948 (regcache_read_pc (get_thread_regcache (ecs
->event_thread
)));
5950 context_switch (ecs
);
5952 if (deprecated_context_hook
)
5953 deprecated_context_hook (ecs
->event_thread
->global_num
);
5957 struct regcache
*regcache
= get_thread_regcache (ecs
->event_thread
);
5958 struct gdbarch
*reg_gdbarch
= regcache
->arch ();
5961 ("stop_pc=%s", paddress (reg_gdbarch
, ecs
->event_thread
->stop_pc ()));
5962 if (target_stopped_by_watchpoint ())
5966 infrun_debug_printf ("stopped by watchpoint");
5968 if (target_stopped_data_address (current_inferior ()->top_target (),
5970 infrun_debug_printf ("stopped data address=%s",
5971 paddress (reg_gdbarch
, addr
));
5973 infrun_debug_printf ("(no data address available)");
5977 /* This is originated from start_remote(), start_inferior() and
5978 shared libraries hook functions. */
5979 stop_soon
= get_inferior_stop_soon (ecs
);
5980 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_REMOTE
)
5982 infrun_debug_printf ("quietly stopped");
5983 stop_print_frame
= true;
5988 /* This originates from attach_command(). We need to overwrite
5989 the stop_signal here, because some kernels don't ignore a
5990 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
5991 See more comments in inferior.h. On the other hand, if we
5992 get a non-SIGSTOP, report it to the user - assume the backend
5993 will handle the SIGSTOP if it should show up later.
5995 Also consider that the attach is complete when we see a
5996 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
5997 target extended-remote report it instead of a SIGSTOP
5998 (e.g. gdbserver). We already rely on SIGTRAP being our
5999 signal, so this is no exception.
6001 Also consider that the attach is complete when we see a
6002 GDB_SIGNAL_0. In non-stop mode, GDB will explicitly tell
6003 the target to stop all threads of the inferior, in case the
6004 low level attach operation doesn't stop them implicitly. If
6005 they weren't stopped implicitly, then the stub will report a
6006 GDB_SIGNAL_0, meaning: stopped for no particular reason
6007 other than GDB's request. */
6008 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
6009 && (ecs
->event_thread
->stop_signal () == GDB_SIGNAL_STOP
6010 || ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6011 || ecs
->event_thread
->stop_signal () == GDB_SIGNAL_0
))
6013 stop_print_frame
= true;
6015 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
6019 /* At this point, get hold of the now-current thread's frame. */
6020 frame
= get_current_frame ();
6021 gdbarch
= get_frame_arch (frame
);
6023 /* Pull the single step breakpoints out of the target. */
6024 if (ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
)
6026 struct regcache
*regcache
;
6029 regcache
= get_thread_regcache (ecs
->event_thread
);
6030 const address_space
*aspace
= regcache
->aspace ();
6032 pc
= regcache_read_pc (regcache
);
6034 /* However, before doing so, if this single-step breakpoint was
6035 actually for another thread, set this thread up for moving
6037 if (!thread_has_single_step_breakpoint_here (ecs
->event_thread
,
6040 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
6042 infrun_debug_printf ("[%s] hit another thread's single-step "
6044 target_pid_to_str (ecs
->ptid
).c_str ());
6045 ecs
->hit_singlestep_breakpoint
= 1;
6050 infrun_debug_printf ("[%s] hit its single-step breakpoint",
6051 target_pid_to_str (ecs
->ptid
).c_str ());
6054 delete_just_stopped_threads_single_step_breakpoints ();
6056 if (ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6057 && ecs
->event_thread
->control
.trap_expected
6058 && ecs
->event_thread
->stepping_over_watchpoint
)
6059 stopped_by_watchpoint
= 0;
6061 stopped_by_watchpoint
= watchpoints_triggered (&ecs
->ws
);
6063 /* If necessary, step over this watchpoint. We'll be back to display
6065 if (stopped_by_watchpoint
6066 && (target_have_steppable_watchpoint ()
6067 || gdbarch_have_nonsteppable_watchpoint (gdbarch
)))
6069 /* At this point, we are stopped at an instruction which has
6070 attempted to write to a piece of memory under control of
6071 a watchpoint. The instruction hasn't actually executed
6072 yet. If we were to evaluate the watchpoint expression
6073 now, we would get the old value, and therefore no change
6074 would seem to have occurred.
6076 In order to make watchpoints work `right', we really need
6077 to complete the memory write, and then evaluate the
6078 watchpoint expression. We do this by single-stepping the
6081 It may not be necessary to disable the watchpoint to step over
6082 it. For example, the PA can (with some kernel cooperation)
6083 single step over a watchpoint without disabling the watchpoint.
6085 It is far more common to need to disable a watchpoint to step
6086 the inferior over it. If we have non-steppable watchpoints,
6087 we must disable the current watchpoint; it's simplest to
6088 disable all watchpoints.
6090 Any breakpoint at PC must also be stepped over -- if there's
6091 one, it will have already triggered before the watchpoint
6092 triggered, and we either already reported it to the user, or
6093 it didn't cause a stop and we called keep_going. In either
6094 case, if there was a breakpoint at PC, we must be trying to
6096 ecs
->event_thread
->stepping_over_watchpoint
= 1;
6101 ecs
->event_thread
->stepping_over_breakpoint
= 0;
6102 ecs
->event_thread
->stepping_over_watchpoint
= 0;
6103 bpstat_clear (&ecs
->event_thread
->control
.stop_bpstat
);
6104 ecs
->event_thread
->control
.stop_step
= 0;
6105 stop_print_frame
= true;
6106 stopped_by_random_signal
= 0;
6107 bpstat stop_chain
= NULL
;
6109 /* Hide inlined functions starting here, unless we just performed stepi or
6110 nexti. After stepi and nexti, always show the innermost frame (not any
6111 inline function call sites). */
6112 if (ecs
->event_thread
->control
.step_range_end
!= 1)
6114 const address_space
*aspace
6115 = get_thread_regcache (ecs
->event_thread
)->aspace ();
6117 /* skip_inline_frames is expensive, so we avoid it if we can
6118 determine that the address is one where functions cannot have
6119 been inlined. This improves performance with inferiors that
6120 load a lot of shared libraries, because the solib event
6121 breakpoint is defined as the address of a function (i.e. not
6122 inline). Note that we have to check the previous PC as well
6123 as the current one to catch cases when we have just
6124 single-stepped off a breakpoint prior to reinstating it.
6125 Note that we're assuming that the code we single-step to is
6126 not inline, but that's not definitive: there's nothing
6127 preventing the event breakpoint function from containing
6128 inlined code, and the single-step ending up there. If the
6129 user had set a breakpoint on that inlined code, the missing
6130 skip_inline_frames call would break things. Fortunately
6131 that's an extremely unlikely scenario. */
6132 if (!pc_at_non_inline_function (aspace
,
6133 ecs
->event_thread
->stop_pc (),
6135 && !(ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6136 && ecs
->event_thread
->control
.trap_expected
6137 && pc_at_non_inline_function (aspace
,
6138 ecs
->event_thread
->prev_pc
,
6141 stop_chain
= build_bpstat_chain (aspace
,
6142 ecs
->event_thread
->stop_pc (),
6144 skip_inline_frames (ecs
->event_thread
, stop_chain
);
6146 /* Re-fetch current thread's frame in case that invalidated
6148 frame
= get_current_frame ();
6149 gdbarch
= get_frame_arch (frame
);
6153 if (ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6154 && ecs
->event_thread
->control
.trap_expected
6155 && gdbarch_single_step_through_delay_p (gdbarch
)
6156 && currently_stepping (ecs
->event_thread
))
6158 /* We're trying to step off a breakpoint. Turns out that we're
6159 also on an instruction that needs to be stepped multiple
6160 times before it's been fully executing. E.g., architectures
6161 with a delay slot. It needs to be stepped twice, once for
6162 the instruction and once for the delay slot. */
6163 int step_through_delay
6164 = gdbarch_single_step_through_delay (gdbarch
, frame
);
6166 if (step_through_delay
)
6167 infrun_debug_printf ("step through delay");
6169 if (ecs
->event_thread
->control
.step_range_end
== 0
6170 && step_through_delay
)
6172 /* The user issued a continue when stopped at a breakpoint.
6173 Set up for another trap and get out of here. */
6174 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6178 else if (step_through_delay
)
6180 /* The user issued a step when stopped at a breakpoint.
6181 Maybe we should stop, maybe we should not - the delay
6182 slot *might* correspond to a line of source. In any
6183 case, don't decide that here, just set
6184 ecs->stepping_over_breakpoint, making sure we
6185 single-step again before breakpoints are re-inserted. */
6186 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6190 /* See if there is a breakpoint/watchpoint/catchpoint/etc. that
6191 handles this event. */
6192 ecs
->event_thread
->control
.stop_bpstat
6193 = bpstat_stop_status (get_current_regcache ()->aspace (),
6194 ecs
->event_thread
->stop_pc (),
6195 ecs
->event_thread
, &ecs
->ws
, stop_chain
);
6197 /* Following in case break condition called a
6199 stop_print_frame
= true;
6201 /* This is where we handle "moribund" watchpoints. Unlike
6202 software breakpoints traps, hardware watchpoint traps are
6203 always distinguishable from random traps. If no high-level
6204 watchpoint is associated with the reported stop data address
6205 anymore, then the bpstat does not explain the signal ---
6206 simply make sure to ignore it if `stopped_by_watchpoint' is
6209 if (ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6210 && !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
6212 && stopped_by_watchpoint
)
6214 infrun_debug_printf ("no user watchpoint explains watchpoint SIGTRAP, "
6218 /* NOTE: cagney/2003-03-29: These checks for a random signal
6219 at one stage in the past included checks for an inferior
6220 function call's call dummy's return breakpoint. The original
6221 comment, that went with the test, read:
6223 ``End of a stack dummy. Some systems (e.g. Sony news) give
6224 another signal besides SIGTRAP, so check here as well as
6227 If someone ever tries to get call dummys on a
6228 non-executable stack to work (where the target would stop
6229 with something like a SIGSEGV), then those tests might need
6230 to be re-instated. Given, however, that the tests were only
6231 enabled when momentary breakpoints were not being used, I
6232 suspect that it won't be the case.
6234 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
6235 be necessary for call dummies on a non-executable stack on
6238 /* See if the breakpoints module can explain the signal. */
6240 = !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
6241 ecs
->event_thread
->stop_signal ());
6243 /* Maybe this was a trap for a software breakpoint that has since
6245 if (random_signal
&& target_stopped_by_sw_breakpoint ())
6247 if (gdbarch_program_breakpoint_here_p (gdbarch
,
6248 ecs
->event_thread
->stop_pc ()))
6250 struct regcache
*regcache
;
6253 /* Re-adjust PC to what the program would see if GDB was not
6255 regcache
= get_thread_regcache (ecs
->event_thread
);
6256 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
6259 gdb::optional
<scoped_restore_tmpl
<int>>
6260 restore_operation_disable
;
6262 if (record_full_is_used ())
6263 restore_operation_disable
.emplace
6264 (record_full_gdb_operation_disable_set ());
6266 regcache_write_pc (regcache
,
6267 ecs
->event_thread
->stop_pc () + decr_pc
);
6272 /* A delayed software breakpoint event. Ignore the trap. */
6273 infrun_debug_printf ("delayed software breakpoint trap, ignoring");
6278 /* Maybe this was a trap for a hardware breakpoint/watchpoint that
6279 has since been removed. */
6280 if (random_signal
&& target_stopped_by_hw_breakpoint ())
6282 /* A delayed hardware breakpoint event. Ignore the trap. */
6283 infrun_debug_printf ("delayed hardware breakpoint/watchpoint "
6288 /* If not, perhaps stepping/nexting can. */
6290 random_signal
= !(ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6291 && currently_stepping (ecs
->event_thread
));
6293 /* Perhaps the thread hit a single-step breakpoint of _another_
6294 thread. Single-step breakpoints are transparent to the
6295 breakpoints module. */
6297 random_signal
= !ecs
->hit_singlestep_breakpoint
;
6299 /* No? Perhaps we got a moribund watchpoint. */
6301 random_signal
= !stopped_by_watchpoint
;
6303 /* Always stop if the user explicitly requested this thread to
6305 if (ecs
->event_thread
->stop_requested
)
6308 infrun_debug_printf ("user-requested stop");
6311 /* For the program's own signals, act according to
6312 the signal handling tables. */
6316 /* Signal not for debugging purposes. */
6317 enum gdb_signal stop_signal
= ecs
->event_thread
->stop_signal ();
6319 infrun_debug_printf ("random signal (%s)",
6320 gdb_signal_to_symbol_string (stop_signal
));
6322 stopped_by_random_signal
= 1;
6324 /* Always stop on signals if we're either just gaining control
6325 of the program, or the user explicitly requested this thread
6326 to remain stopped. */
6327 if (stop_soon
!= NO_STOP_QUIETLY
6328 || ecs
->event_thread
->stop_requested
6329 || signal_stop_state (ecs
->event_thread
->stop_signal ()))
6335 /* Notify observers the signal has "handle print" set. Note we
6336 returned early above if stopping; normal_stop handles the
6337 printing in that case. */
6338 if (signal_print
[ecs
->event_thread
->stop_signal ()])
6340 /* The signal table tells us to print about this signal. */
6341 target_terminal::ours_for_output ();
6342 gdb::observers::signal_received
.notify (ecs
->event_thread
->stop_signal ());
6343 target_terminal::inferior ();
6346 /* Clear the signal if it should not be passed. */
6347 if (signal_program
[ecs
->event_thread
->stop_signal ()] == 0)
6348 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
6350 if (ecs
->event_thread
->prev_pc
== ecs
->event_thread
->stop_pc ()
6351 && ecs
->event_thread
->control
.trap_expected
6352 && ecs
->event_thread
->control
.step_resume_breakpoint
== NULL
)
6354 /* We were just starting a new sequence, attempting to
6355 single-step off of a breakpoint and expecting a SIGTRAP.
6356 Instead this signal arrives. This signal will take us out
6357 of the stepping range so GDB needs to remember to, when
6358 the signal handler returns, resume stepping off that
6360 /* To simplify things, "continue" is forced to use the same
6361 code paths as single-step - set a breakpoint at the
6362 signal return address and then, once hit, step off that
6364 infrun_debug_printf ("signal arrived while stepping over breakpoint");
6366 insert_hp_step_resume_breakpoint_at_frame (frame
);
6367 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
6368 /* Reset trap_expected to ensure breakpoints are re-inserted. */
6369 ecs
->event_thread
->control
.trap_expected
= 0;
6371 /* If we were nexting/stepping some other thread, switch to
6372 it, so that we don't continue it, losing control. */
6373 if (!switch_back_to_stepped_thread (ecs
))
6378 if (ecs
->event_thread
->stop_signal () != GDB_SIGNAL_0
6379 && (pc_in_thread_step_range (ecs
->event_thread
->stop_pc (),
6381 || ecs
->event_thread
->control
.step_range_end
== 1)
6382 && frame_id_eq (get_stack_frame_id (frame
),
6383 ecs
->event_thread
->control
.step_stack_frame_id
)
6384 && ecs
->event_thread
->control
.step_resume_breakpoint
== NULL
)
6386 /* The inferior is about to take a signal that will take it
6387 out of the single step range. Set a breakpoint at the
6388 current PC (which is presumably where the signal handler
6389 will eventually return) and then allow the inferior to
6392 Note that this is only needed for a signal delivered
6393 while in the single-step range. Nested signals aren't a
6394 problem as they eventually all return. */
6395 infrun_debug_printf ("signal may take us out of single-step range");
6397 clear_step_over_info ();
6398 insert_hp_step_resume_breakpoint_at_frame (frame
);
6399 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
6400 /* Reset trap_expected to ensure breakpoints are re-inserted. */
6401 ecs
->event_thread
->control
.trap_expected
= 0;
6406 /* Note: step_resume_breakpoint may be non-NULL. This occurs
6407 when either there's a nested signal, or when there's a
6408 pending signal enabled just as the signal handler returns
6409 (leaving the inferior at the step-resume-breakpoint without
6410 actually executing it). Either way continue until the
6411 breakpoint is really hit. */
6413 if (!switch_back_to_stepped_thread (ecs
))
6415 infrun_debug_printf ("random signal, keep going");
6422 process_event_stop_test (ecs
);
6425 /* Come here when we've got some debug event / signal we can explain
6426 (IOW, not a random signal), and test whether it should cause a
6427 stop, or whether we should resume the inferior (transparently).
6428 E.g., could be a breakpoint whose condition evaluates false; we
6429 could be still stepping within the line; etc. */
6432 process_event_stop_test (struct execution_control_state
*ecs
)
6434 struct symtab_and_line stop_pc_sal
;
6435 struct frame_info
*frame
;
6436 struct gdbarch
*gdbarch
;
6437 CORE_ADDR jmp_buf_pc
;
6438 struct bpstat_what what
;
6440 /* Handle cases caused by hitting a breakpoint. */
6442 frame
= get_current_frame ();
6443 gdbarch
= get_frame_arch (frame
);
6445 what
= bpstat_what (ecs
->event_thread
->control
.stop_bpstat
);
6447 if (what
.call_dummy
)
6449 stop_stack_dummy
= what
.call_dummy
;
6452 /* A few breakpoint types have callbacks associated (e.g.,
6453 bp_jit_event). Run them now. */
6454 bpstat_run_callbacks (ecs
->event_thread
->control
.stop_bpstat
);
6456 /* If we hit an internal event that triggers symbol changes, the
6457 current frame will be invalidated within bpstat_what (e.g., if we
6458 hit an internal solib event). Re-fetch it. */
6459 frame
= get_current_frame ();
6460 gdbarch
= get_frame_arch (frame
);
6462 switch (what
.main_action
)
6464 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
6465 /* If we hit the breakpoint at longjmp while stepping, we
6466 install a momentary breakpoint at the target of the
6469 infrun_debug_printf ("BPSTAT_WHAT_SET_LONGJMP_RESUME");
6471 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6473 if (what
.is_longjmp
)
6475 struct value
*arg_value
;
6477 /* If we set the longjmp breakpoint via a SystemTap probe,
6478 then use it to extract the arguments. The destination PC
6479 is the third argument to the probe. */
6480 arg_value
= probe_safe_evaluate_at_pc (frame
, 2);
6483 jmp_buf_pc
= value_as_address (arg_value
);
6484 jmp_buf_pc
= gdbarch_addr_bits_remove (gdbarch
, jmp_buf_pc
);
6486 else if (!gdbarch_get_longjmp_target_p (gdbarch
)
6487 || !gdbarch_get_longjmp_target (gdbarch
,
6488 frame
, &jmp_buf_pc
))
6490 infrun_debug_printf ("BPSTAT_WHAT_SET_LONGJMP_RESUME "
6491 "(!gdbarch_get_longjmp_target)");
6496 /* Insert a breakpoint at resume address. */
6497 insert_longjmp_resume_breakpoint (gdbarch
, jmp_buf_pc
);
6500 check_exception_resume (ecs
, frame
);
6504 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
6506 struct frame_info
*init_frame
;
6508 /* There are several cases to consider.
6510 1. The initiating frame no longer exists. In this case we
6511 must stop, because the exception or longjmp has gone too
6514 2. The initiating frame exists, and is the same as the
6515 current frame. We stop, because the exception or longjmp
6518 3. The initiating frame exists and is different from the
6519 current frame. This means the exception or longjmp has
6520 been caught beneath the initiating frame, so keep going.
6522 4. longjmp breakpoint has been placed just to protect
6523 against stale dummy frames and user is not interested in
6524 stopping around longjmps. */
6526 infrun_debug_printf ("BPSTAT_WHAT_CLEAR_LONGJMP_RESUME");
6528 gdb_assert (ecs
->event_thread
->control
.exception_resume_breakpoint
6530 delete_exception_resume_breakpoint (ecs
->event_thread
);
6532 if (what
.is_longjmp
)
6534 check_longjmp_breakpoint_for_call_dummy (ecs
->event_thread
);
6536 if (!frame_id_p (ecs
->event_thread
->initiating_frame
))
6544 init_frame
= frame_find_by_id (ecs
->event_thread
->initiating_frame
);
6548 struct frame_id current_id
6549 = get_frame_id (get_current_frame ());
6550 if (frame_id_eq (current_id
,
6551 ecs
->event_thread
->initiating_frame
))
6553 /* Case 2. Fall through. */
6563 /* For Cases 1 and 2, remove the step-resume breakpoint, if it
6565 delete_step_resume_breakpoint (ecs
->event_thread
);
6567 end_stepping_range (ecs
);
6571 case BPSTAT_WHAT_SINGLE
:
6572 infrun_debug_printf ("BPSTAT_WHAT_SINGLE");
6573 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6574 /* Still need to check other stuff, at least the case where we
6575 are stepping and step out of the right range. */
6578 case BPSTAT_WHAT_STEP_RESUME
:
6579 infrun_debug_printf ("BPSTAT_WHAT_STEP_RESUME");
6581 delete_step_resume_breakpoint (ecs
->event_thread
);
6582 if (ecs
->event_thread
->control
.proceed_to_finish
6583 && execution_direction
== EXEC_REVERSE
)
6585 struct thread_info
*tp
= ecs
->event_thread
;
6587 /* We are finishing a function in reverse, and just hit the
6588 step-resume breakpoint at the start address of the
6589 function, and we're almost there -- just need to back up
6590 by one more single-step, which should take us back to the
6592 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
6596 fill_in_stop_func (gdbarch
, ecs
);
6597 if (ecs
->event_thread
->stop_pc () == ecs
->stop_func_start
6598 && execution_direction
== EXEC_REVERSE
)
6600 /* We are stepping over a function call in reverse, and just
6601 hit the step-resume breakpoint at the start address of
6602 the function. Go back to single-stepping, which should
6603 take us back to the function call. */
6604 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6610 case BPSTAT_WHAT_STOP_NOISY
:
6611 infrun_debug_printf ("BPSTAT_WHAT_STOP_NOISY");
6612 stop_print_frame
= true;
6614 /* Assume the thread stopped for a breakpoint. We'll still check
6615 whether a/the breakpoint is there when the thread is next
6617 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6622 case BPSTAT_WHAT_STOP_SILENT
:
6623 infrun_debug_printf ("BPSTAT_WHAT_STOP_SILENT");
6624 stop_print_frame
= false;
6626 /* Assume the thread stopped for a breakpoint. We'll still check
6627 whether a/the breakpoint is there when the thread is next
6629 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6633 case BPSTAT_WHAT_HP_STEP_RESUME
:
6634 infrun_debug_printf ("BPSTAT_WHAT_HP_STEP_RESUME");
6636 delete_step_resume_breakpoint (ecs
->event_thread
);
6637 if (ecs
->event_thread
->step_after_step_resume_breakpoint
)
6639 /* Back when the step-resume breakpoint was inserted, we
6640 were trying to single-step off a breakpoint. Go back to
6642 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
6643 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6649 case BPSTAT_WHAT_KEEP_CHECKING
:
6653 /* If we stepped a permanent breakpoint and we had a high priority
6654 step-resume breakpoint for the address we stepped, but we didn't
6655 hit it, then we must have stepped into the signal handler. The
6656 step-resume was only necessary to catch the case of _not_
6657 stepping into the handler, so delete it, and fall through to
6658 checking whether the step finished. */
6659 if (ecs
->event_thread
->stepped_breakpoint
)
6661 struct breakpoint
*sr_bp
6662 = ecs
->event_thread
->control
.step_resume_breakpoint
;
6665 && sr_bp
->loc
->permanent
6666 && sr_bp
->type
== bp_hp_step_resume
6667 && sr_bp
->loc
->address
== ecs
->event_thread
->prev_pc
)
6669 infrun_debug_printf ("stepped permanent breakpoint, stopped in handler");
6670 delete_step_resume_breakpoint (ecs
->event_thread
);
6671 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
6675 /* We come here if we hit a breakpoint but should not stop for it.
6676 Possibly we also were stepping and should stop for that. So fall
6677 through and test for stepping. But, if not stepping, do not
6680 /* In all-stop mode, if we're currently stepping but have stopped in
6681 some other thread, we need to switch back to the stepped thread. */
6682 if (switch_back_to_stepped_thread (ecs
))
6685 if (ecs
->event_thread
->control
.step_resume_breakpoint
)
6687 infrun_debug_printf ("step-resume breakpoint is inserted");
6689 /* Having a step-resume breakpoint overrides anything
6690 else having to do with stepping commands until
6691 that breakpoint is reached. */
6696 if (ecs
->event_thread
->control
.step_range_end
== 0)
6698 infrun_debug_printf ("no stepping, continue");
6699 /* Likewise if we aren't even stepping. */
6704 /* Re-fetch current thread's frame in case the code above caused
6705 the frame cache to be re-initialized, making our FRAME variable
6706 a dangling pointer. */
6707 frame
= get_current_frame ();
6708 gdbarch
= get_frame_arch (frame
);
6709 fill_in_stop_func (gdbarch
, ecs
);
6711 /* If stepping through a line, keep going if still within it.
6713 Note that step_range_end is the address of the first instruction
6714 beyond the step range, and NOT the address of the last instruction
6717 Note also that during reverse execution, we may be stepping
6718 through a function epilogue and therefore must detect when
6719 the current-frame changes in the middle of a line. */
6721 if (pc_in_thread_step_range (ecs
->event_thread
->stop_pc (),
6723 && (execution_direction
!= EXEC_REVERSE
6724 || frame_id_eq (get_frame_id (frame
),
6725 ecs
->event_thread
->control
.step_frame_id
)))
6728 ("stepping inside range [%s-%s]",
6729 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_start
),
6730 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_end
));
6732 /* Tentatively re-enable range stepping; `resume' disables it if
6733 necessary (e.g., if we're stepping over a breakpoint or we
6734 have software watchpoints). */
6735 ecs
->event_thread
->control
.may_range_step
= 1;
6737 /* When stepping backward, stop at beginning of line range
6738 (unless it's the function entry point, in which case
6739 keep going back to the call point). */
6740 CORE_ADDR stop_pc
= ecs
->event_thread
->stop_pc ();
6741 if (stop_pc
== ecs
->event_thread
->control
.step_range_start
6742 && stop_pc
!= ecs
->stop_func_start
6743 && execution_direction
== EXEC_REVERSE
)
6744 end_stepping_range (ecs
);
6751 /* We stepped out of the stepping range. */
6753 /* If we are stepping at the source level and entered the runtime
6754 loader dynamic symbol resolution code...
6756 EXEC_FORWARD: we keep on single stepping until we exit the run
6757 time loader code and reach the callee's address.
6759 EXEC_REVERSE: we've already executed the callee (backward), and
6760 the runtime loader code is handled just like any other
6761 undebuggable function call. Now we need only keep stepping
6762 backward through the trampoline code, and that's handled further
6763 down, so there is nothing for us to do here. */
6765 if (execution_direction
!= EXEC_REVERSE
6766 && ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
6767 && in_solib_dynsym_resolve_code (ecs
->event_thread
->stop_pc ()))
6769 CORE_ADDR pc_after_resolver
=
6770 gdbarch_skip_solib_resolver (gdbarch
, ecs
->event_thread
->stop_pc ());
6772 infrun_debug_printf ("stepped into dynsym resolve code");
6774 if (pc_after_resolver
)
6776 /* Set up a step-resume breakpoint at the address
6777 indicated by SKIP_SOLIB_RESOLVER. */
6778 symtab_and_line sr_sal
;
6779 sr_sal
.pc
= pc_after_resolver
;
6780 sr_sal
.pspace
= get_frame_program_space (frame
);
6782 insert_step_resume_breakpoint_at_sal (gdbarch
,
6783 sr_sal
, null_frame_id
);
6790 /* Step through an indirect branch thunk. */
6791 if (ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
6792 && gdbarch_in_indirect_branch_thunk (gdbarch
,
6793 ecs
->event_thread
->stop_pc ()))
6795 infrun_debug_printf ("stepped into indirect branch thunk");
6800 if (ecs
->event_thread
->control
.step_range_end
!= 1
6801 && (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
6802 || ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
6803 && get_frame_type (frame
) == SIGTRAMP_FRAME
)
6805 infrun_debug_printf ("stepped into signal trampoline");
6806 /* The inferior, while doing a "step" or "next", has ended up in
6807 a signal trampoline (either by a signal being delivered or by
6808 the signal handler returning). Just single-step until the
6809 inferior leaves the trampoline (either by calling the handler
6815 /* If we're in the return path from a shared library trampoline,
6816 we want to proceed through the trampoline when stepping. */
6817 /* macro/2012-04-25: This needs to come before the subroutine
6818 call check below as on some targets return trampolines look
6819 like subroutine calls (MIPS16 return thunks). */
6820 if (gdbarch_in_solib_return_trampoline (gdbarch
,
6821 ecs
->event_thread
->stop_pc (),
6822 ecs
->stop_func_name
)
6823 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
6825 /* Determine where this trampoline returns. */
6826 CORE_ADDR stop_pc
= ecs
->event_thread
->stop_pc ();
6827 CORE_ADDR real_stop_pc
6828 = gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
6830 infrun_debug_printf ("stepped into solib return tramp");
6832 /* Only proceed through if we know where it's going. */
6835 /* And put the step-breakpoint there and go until there. */
6836 symtab_and_line sr_sal
;
6837 sr_sal
.pc
= real_stop_pc
;
6838 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
6839 sr_sal
.pspace
= get_frame_program_space (frame
);
6841 /* Do not specify what the fp should be when we stop since
6842 on some machines the prologue is where the new fp value
6844 insert_step_resume_breakpoint_at_sal (gdbarch
,
6845 sr_sal
, null_frame_id
);
6847 /* Restart without fiddling with the step ranges or
6854 /* Check for subroutine calls. The check for the current frame
6855 equalling the step ID is not necessary - the check of the
6856 previous frame's ID is sufficient - but it is a common case and
6857 cheaper than checking the previous frame's ID.
6859 NOTE: frame_id_eq will never report two invalid frame IDs as
6860 being equal, so to get into this block, both the current and
6861 previous frame must have valid frame IDs. */
6862 /* The outer_frame_id check is a heuristic to detect stepping
6863 through startup code. If we step over an instruction which
6864 sets the stack pointer from an invalid value to a valid value,
6865 we may detect that as a subroutine call from the mythical
6866 "outermost" function. This could be fixed by marking
6867 outermost frames as !stack_p,code_p,special_p. Then the
6868 initial outermost frame, before sp was valid, would
6869 have code_addr == &_start. See the comment in frame_id_eq
6871 if (!frame_id_eq (get_stack_frame_id (frame
),
6872 ecs
->event_thread
->control
.step_stack_frame_id
)
6873 && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()),
6874 ecs
->event_thread
->control
.step_stack_frame_id
)
6875 && (!frame_id_eq (ecs
->event_thread
->control
.step_stack_frame_id
,
6877 || (ecs
->event_thread
->control
.step_start_function
6878 != find_pc_function (ecs
->event_thread
->stop_pc ())))))
6880 CORE_ADDR stop_pc
= ecs
->event_thread
->stop_pc ();
6881 CORE_ADDR real_stop_pc
;
6883 infrun_debug_printf ("stepped into subroutine");
6885 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_NONE
)
6887 /* I presume that step_over_calls is only 0 when we're
6888 supposed to be stepping at the assembly language level
6889 ("stepi"). Just stop. */
6890 /* And this works the same backward as frontward. MVS */
6891 end_stepping_range (ecs
);
6895 /* Reverse stepping through solib trampolines. */
6897 if (execution_direction
== EXEC_REVERSE
6898 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
6899 && (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
6900 || (ecs
->stop_func_start
== 0
6901 && in_solib_dynsym_resolve_code (stop_pc
))))
6903 /* Any solib trampoline code can be handled in reverse
6904 by simply continuing to single-step. We have already
6905 executed the solib function (backwards), and a few
6906 steps will take us back through the trampoline to the
6912 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
6914 /* We're doing a "next".
6916 Normal (forward) execution: set a breakpoint at the
6917 callee's return address (the address at which the caller
6920 Reverse (backward) execution. set the step-resume
6921 breakpoint at the start of the function that we just
6922 stepped into (backwards), and continue to there. When we
6923 get there, we'll need to single-step back to the caller. */
6925 if (execution_direction
== EXEC_REVERSE
)
6927 /* If we're already at the start of the function, we've either
6928 just stepped backward into a single instruction function,
6929 or stepped back out of a signal handler to the first instruction
6930 of the function. Just keep going, which will single-step back
6932 if (ecs
->stop_func_start
!= stop_pc
&& ecs
->stop_func_start
!= 0)
6934 /* Normal function call return (static or dynamic). */
6935 symtab_and_line sr_sal
;
6936 sr_sal
.pc
= ecs
->stop_func_start
;
6937 sr_sal
.pspace
= get_frame_program_space (frame
);
6938 insert_step_resume_breakpoint_at_sal (gdbarch
,
6939 sr_sal
, null_frame_id
);
6943 insert_step_resume_breakpoint_at_caller (frame
);
6949 /* If we are in a function call trampoline (a stub between the
6950 calling routine and the real function), locate the real
6951 function. That's what tells us (a) whether we want to step
6952 into it at all, and (b) what prologue we want to run to the
6953 end of, if we do step into it. */
6954 real_stop_pc
= skip_language_trampoline (frame
, stop_pc
);
6955 if (real_stop_pc
== 0)
6956 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
6957 if (real_stop_pc
!= 0)
6958 ecs
->stop_func_start
= real_stop_pc
;
6960 if (real_stop_pc
!= 0 && in_solib_dynsym_resolve_code (real_stop_pc
))
6962 symtab_and_line sr_sal
;
6963 sr_sal
.pc
= ecs
->stop_func_start
;
6964 sr_sal
.pspace
= get_frame_program_space (frame
);
6966 insert_step_resume_breakpoint_at_sal (gdbarch
,
6967 sr_sal
, null_frame_id
);
6972 /* If we have line number information for the function we are
6973 thinking of stepping into and the function isn't on the skip
6976 If there are several symtabs at that PC (e.g. with include
6977 files), just want to know whether *any* of them have line
6978 numbers. find_pc_line handles this. */
6980 struct symtab_and_line tmp_sal
;
6982 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
6983 if (tmp_sal
.line
!= 0
6984 && !function_name_is_marked_for_skip (ecs
->stop_func_name
,
6986 && !inline_frame_is_marked_for_skip (true, ecs
->event_thread
))
6988 if (execution_direction
== EXEC_REVERSE
)
6989 handle_step_into_function_backward (gdbarch
, ecs
);
6991 handle_step_into_function (gdbarch
, ecs
);
6996 /* If we have no line number and the step-stop-if-no-debug is
6997 set, we stop the step so that the user has a chance to switch
6998 in assembly mode. */
6999 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
7000 && step_stop_if_no_debug
)
7002 end_stepping_range (ecs
);
7006 if (execution_direction
== EXEC_REVERSE
)
7008 /* If we're already at the start of the function, we've either just
7009 stepped backward into a single instruction function without line
7010 number info, or stepped back out of a signal handler to the first
7011 instruction of the function without line number info. Just keep
7012 going, which will single-step back to the caller. */
7013 if (ecs
->stop_func_start
!= stop_pc
)
7015 /* Set a breakpoint at callee's start address.
7016 From there we can step once and be back in the caller. */
7017 symtab_and_line sr_sal
;
7018 sr_sal
.pc
= ecs
->stop_func_start
;
7019 sr_sal
.pspace
= get_frame_program_space (frame
);
7020 insert_step_resume_breakpoint_at_sal (gdbarch
,
7021 sr_sal
, null_frame_id
);
7025 /* Set a breakpoint at callee's return address (the address
7026 at which the caller will resume). */
7027 insert_step_resume_breakpoint_at_caller (frame
);
7033 /* Reverse stepping through solib trampolines. */
7035 if (execution_direction
== EXEC_REVERSE
7036 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
7038 CORE_ADDR stop_pc
= ecs
->event_thread
->stop_pc ();
7040 if (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
7041 || (ecs
->stop_func_start
== 0
7042 && in_solib_dynsym_resolve_code (stop_pc
)))
7044 /* Any solib trampoline code can be handled in reverse
7045 by simply continuing to single-step. We have already
7046 executed the solib function (backwards), and a few
7047 steps will take us back through the trampoline to the
7052 else if (in_solib_dynsym_resolve_code (stop_pc
))
7054 /* Stepped backward into the solib dynsym resolver.
7055 Set a breakpoint at its start and continue, then
7056 one more step will take us out. */
7057 symtab_and_line sr_sal
;
7058 sr_sal
.pc
= ecs
->stop_func_start
;
7059 sr_sal
.pspace
= get_frame_program_space (frame
);
7060 insert_step_resume_breakpoint_at_sal (gdbarch
,
7061 sr_sal
, null_frame_id
);
7067 /* This always returns the sal for the inner-most frame when we are in a
7068 stack of inlined frames, even if GDB actually believes that it is in a
7069 more outer frame. This is checked for below by calls to
7070 inline_skipped_frames. */
7071 stop_pc_sal
= find_pc_line (ecs
->event_thread
->stop_pc (), 0);
7073 /* NOTE: tausq/2004-05-24: This if block used to be done before all
7074 the trampoline processing logic, however, there are some trampolines
7075 that have no names, so we should do trampoline handling first. */
7076 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
7077 && ecs
->stop_func_name
== NULL
7078 && stop_pc_sal
.line
== 0)
7080 infrun_debug_printf ("stepped into undebuggable function");
7082 /* The inferior just stepped into, or returned to, an
7083 undebuggable function (where there is no debugging information
7084 and no line number corresponding to the address where the
7085 inferior stopped). Since we want to skip this kind of code,
7086 we keep going until the inferior returns from this
7087 function - unless the user has asked us not to (via
7088 set step-mode) or we no longer know how to get back
7089 to the call site. */
7090 if (step_stop_if_no_debug
7091 || !frame_id_p (frame_unwind_caller_id (frame
)))
7093 /* If we have no line number and the step-stop-if-no-debug
7094 is set, we stop the step so that the user has a chance to
7095 switch in assembly mode. */
7096 end_stepping_range (ecs
);
7101 /* Set a breakpoint at callee's return address (the address
7102 at which the caller will resume). */
7103 insert_step_resume_breakpoint_at_caller (frame
);
7109 if (ecs
->event_thread
->control
.step_range_end
== 1)
7111 /* It is stepi or nexti. We always want to stop stepping after
7113 infrun_debug_printf ("stepi/nexti");
7114 end_stepping_range (ecs
);
7118 if (stop_pc_sal
.line
== 0)
7120 /* We have no line number information. That means to stop
7121 stepping (does this always happen right after one instruction,
7122 when we do "s" in a function with no line numbers,
7123 or can this happen as a result of a return or longjmp?). */
7124 infrun_debug_printf ("line number info");
7125 end_stepping_range (ecs
);
7129 /* Look for "calls" to inlined functions, part one. If the inline
7130 frame machinery detected some skipped call sites, we have entered
7131 a new inline function. */
7133 if (frame_id_eq (get_frame_id (get_current_frame ()),
7134 ecs
->event_thread
->control
.step_frame_id
)
7135 && inline_skipped_frames (ecs
->event_thread
))
7137 infrun_debug_printf ("stepped into inlined function");
7139 symtab_and_line call_sal
= find_frame_sal (get_current_frame ());
7141 if (ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_ALL
)
7143 /* For "step", we're going to stop. But if the call site
7144 for this inlined function is on the same source line as
7145 we were previously stepping, go down into the function
7146 first. Otherwise stop at the call site. */
7148 if (call_sal
.line
== ecs
->event_thread
->current_line
7149 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
7151 step_into_inline_frame (ecs
->event_thread
);
7152 if (inline_frame_is_marked_for_skip (false, ecs
->event_thread
))
7159 end_stepping_range (ecs
);
7164 /* For "next", we should stop at the call site if it is on a
7165 different source line. Otherwise continue through the
7166 inlined function. */
7167 if (call_sal
.line
== ecs
->event_thread
->current_line
7168 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
7171 end_stepping_range (ecs
);
7176 /* Look for "calls" to inlined functions, part two. If we are still
7177 in the same real function we were stepping through, but we have
7178 to go further up to find the exact frame ID, we are stepping
7179 through a more inlined call beyond its call site. */
7181 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
7182 && !frame_id_eq (get_frame_id (get_current_frame ()),
7183 ecs
->event_thread
->control
.step_frame_id
)
7184 && stepped_in_from (get_current_frame (),
7185 ecs
->event_thread
->control
.step_frame_id
))
7187 infrun_debug_printf ("stepping through inlined function");
7189 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
7190 || inline_frame_is_marked_for_skip (false, ecs
->event_thread
))
7193 end_stepping_range (ecs
);
7197 bool refresh_step_info
= true;
7198 if ((ecs
->event_thread
->stop_pc () == stop_pc_sal
.pc
)
7199 && (ecs
->event_thread
->current_line
!= stop_pc_sal
.line
7200 || ecs
->event_thread
->current_symtab
!= stop_pc_sal
.symtab
))
7202 /* We are at a different line. */
7204 if (stop_pc_sal
.is_stmt
)
7206 /* We are at the start of a statement.
7208 So stop. Note that we don't stop if we step into the middle of a
7209 statement. That is said to make things like for (;;) statements
7211 infrun_debug_printf ("stepped to a different line");
7212 end_stepping_range (ecs
);
7215 else if (frame_id_eq (get_frame_id (get_current_frame ()),
7216 ecs
->event_thread
->control
.step_frame_id
))
7218 /* We are not at the start of a statement, and we have not changed
7221 We ignore this line table entry, and continue stepping forward,
7222 looking for a better place to stop. */
7223 refresh_step_info
= false;
7224 infrun_debug_printf ("stepped to a different line, but "
7225 "it's not the start of a statement");
7229 /* We are not the start of a statement, and we have changed frame.
7231 We ignore this line table entry, and continue stepping forward,
7232 looking for a better place to stop. Keep refresh_step_info at
7233 true to note that the frame has changed, but ignore the line
7234 number to make sure we don't ignore a subsequent entry with the
7235 same line number. */
7236 stop_pc_sal
.line
= 0;
7237 infrun_debug_printf ("stepped to a different frame, but "
7238 "it's not the start of a statement");
7242 /* We aren't done stepping.
7244 Optimize by setting the stepping range to the line.
7245 (We might not be in the original line, but if we entered a
7246 new line in mid-statement, we continue stepping. This makes
7247 things like for(;;) statements work better.)
7249 If we entered a SAL that indicates a non-statement line table entry,
7250 then we update the stepping range, but we don't update the step info,
7251 which includes things like the line number we are stepping away from.
7252 This means we will stop when we find a line table entry that is marked
7253 as is-statement, even if it matches the non-statement one we just
7256 ecs
->event_thread
->control
.step_range_start
= stop_pc_sal
.pc
;
7257 ecs
->event_thread
->control
.step_range_end
= stop_pc_sal
.end
;
7258 ecs
->event_thread
->control
.may_range_step
= 1;
7259 if (refresh_step_info
)
7260 set_step_info (ecs
->event_thread
, frame
, stop_pc_sal
);
7262 infrun_debug_printf ("keep going");
7266 static bool restart_stepped_thread (process_stratum_target
*resume_target
,
7267 ptid_t resume_ptid
);
7269 /* In all-stop mode, if we're currently stepping but have stopped in
7270 some other thread, we may need to switch back to the stepped
7271 thread. Returns true we set the inferior running, false if we left
7272 it stopped (and the event needs further processing). */
7275 switch_back_to_stepped_thread (struct execution_control_state
*ecs
)
7277 if (!target_is_non_stop_p ())
7279 /* If any thread is blocked on some internal breakpoint, and we
7280 simply need to step over that breakpoint to get it going
7281 again, do that first. */
7283 /* However, if we see an event for the stepping thread, then we
7284 know all other threads have been moved past their breakpoints
7285 already. Let the caller check whether the step is finished,
7286 etc., before deciding to move it past a breakpoint. */
7287 if (ecs
->event_thread
->control
.step_range_end
!= 0)
7290 /* Check if the current thread is blocked on an incomplete
7291 step-over, interrupted by a random signal. */
7292 if (ecs
->event_thread
->control
.trap_expected
7293 && ecs
->event_thread
->stop_signal () != GDB_SIGNAL_TRAP
)
7296 ("need to finish step-over of [%s]",
7297 target_pid_to_str (ecs
->event_thread
->ptid
).c_str ());
7302 /* Check if the current thread is blocked by a single-step
7303 breakpoint of another thread. */
7304 if (ecs
->hit_singlestep_breakpoint
)
7306 infrun_debug_printf ("need to step [%s] over single-step breakpoint",
7307 target_pid_to_str (ecs
->ptid
).c_str ());
7312 /* If this thread needs yet another step-over (e.g., stepping
7313 through a delay slot), do it first before moving on to
7315 if (thread_still_needs_step_over (ecs
->event_thread
))
7318 ("thread [%s] still needs step-over",
7319 target_pid_to_str (ecs
->event_thread
->ptid
).c_str ());
7324 /* If scheduler locking applies even if not stepping, there's no
7325 need to walk over threads. Above we've checked whether the
7326 current thread is stepping. If some other thread not the
7327 event thread is stepping, then it must be that scheduler
7328 locking is not in effect. */
7329 if (schedlock_applies (ecs
->event_thread
))
7332 /* Otherwise, we no longer expect a trap in the current thread.
7333 Clear the trap_expected flag before switching back -- this is
7334 what keep_going does as well, if we call it. */
7335 ecs
->event_thread
->control
.trap_expected
= 0;
7337 /* Likewise, clear the signal if it should not be passed. */
7338 if (!signal_program
[ecs
->event_thread
->stop_signal ()])
7339 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
7341 if (restart_stepped_thread (ecs
->target
, ecs
->ptid
))
7343 prepare_to_wait (ecs
);
7347 switch_to_thread (ecs
->event_thread
);
7353 /* Look for the thread that was stepping, and resume it.
7354 RESUME_TARGET / RESUME_PTID indicate the set of threads the caller
7355 is resuming. Return true if a thread was started, false
7359 restart_stepped_thread (process_stratum_target
*resume_target
,
7362 /* Do all pending step-overs before actually proceeding with
7364 if (start_step_over ())
7367 for (thread_info
*tp
: all_threads_safe ())
7369 if (tp
->state
== THREAD_EXITED
)
7372 if (tp
->has_pending_waitstatus ())
7375 /* Ignore threads of processes the caller is not
7378 && (tp
->inf
->process_target () != resume_target
7379 || tp
->inf
->pid
!= resume_ptid
.pid ()))
7382 if (tp
->control
.trap_expected
)
7384 infrun_debug_printf ("switching back to stepped thread (step-over)");
7386 if (keep_going_stepped_thread (tp
))
7391 for (thread_info
*tp
: all_threads_safe ())
7393 if (tp
->state
== THREAD_EXITED
)
7396 if (tp
->has_pending_waitstatus ())
7399 /* Ignore threads of processes the caller is not
7402 && (tp
->inf
->process_target () != resume_target
7403 || tp
->inf
->pid
!= resume_ptid
.pid ()))
7406 /* Did we find the stepping thread? */
7407 if (tp
->control
.step_range_end
)
7409 infrun_debug_printf ("switching back to stepped thread (stepping)");
7411 if (keep_going_stepped_thread (tp
))
7422 restart_after_all_stop_detach (process_stratum_target
*proc_target
)
7424 /* Note we don't check target_is_non_stop_p() here, because the
7425 current inferior may no longer have a process_stratum target
7426 pushed, as we just detached. */
7428 /* See if we have a THREAD_RUNNING thread that need to be
7429 re-resumed. If we have any thread that is already executing,
7430 then we don't need to resume the target -- it is already been
7431 resumed. With the remote target (in all-stop), it's even
7432 impossible to issue another resumption if the target is already
7433 resumed, until the target reports a stop. */
7434 for (thread_info
*thr
: all_threads (proc_target
))
7436 if (thr
->state
!= THREAD_RUNNING
)
7439 /* If we have any thread that is already executing, then we
7440 don't need to resume the target -- it is already been
7442 if (thr
->executing ())
7445 /* If we have a pending event to process, skip resuming the
7446 target and go straight to processing it. */
7447 if (thr
->resumed () && thr
->has_pending_waitstatus ())
7451 /* Alright, we need to re-resume the target. If a thread was
7452 stepping, we need to restart it stepping. */
7453 if (restart_stepped_thread (proc_target
, minus_one_ptid
))
7456 /* Otherwise, find the first THREAD_RUNNING thread and resume
7458 for (thread_info
*thr
: all_threads (proc_target
))
7460 if (thr
->state
!= THREAD_RUNNING
)
7463 execution_control_state ecs
;
7464 reset_ecs (&ecs
, thr
);
7465 switch_to_thread (thr
);
7471 /* Set a previously stepped thread back to stepping. Returns true on
7472 success, false if the resume is not possible (e.g., the thread
7476 keep_going_stepped_thread (struct thread_info
*tp
)
7478 struct frame_info
*frame
;
7479 struct execution_control_state ecss
;
7480 struct execution_control_state
*ecs
= &ecss
;
7482 /* If the stepping thread exited, then don't try to switch back and
7483 resume it, which could fail in several different ways depending
7484 on the target. Instead, just keep going.
7486 We can find a stepping dead thread in the thread list in two
7489 - The target supports thread exit events, and when the target
7490 tries to delete the thread from the thread list, inferior_ptid
7491 pointed at the exiting thread. In such case, calling
7492 delete_thread does not really remove the thread from the list;
7493 instead, the thread is left listed, with 'exited' state.
7495 - The target's debug interface does not support thread exit
7496 events, and so we have no idea whatsoever if the previously
7497 stepping thread is still alive. For that reason, we need to
7498 synchronously query the target now. */
7500 if (tp
->state
== THREAD_EXITED
|| !target_thread_alive (tp
->ptid
))
7502 infrun_debug_printf ("not resuming previously stepped thread, it has "
7509 infrun_debug_printf ("resuming previously stepped thread");
7511 reset_ecs (ecs
, tp
);
7512 switch_to_thread (tp
);
7514 tp
->set_stop_pc (regcache_read_pc (get_thread_regcache (tp
)));
7515 frame
= get_current_frame ();
7517 /* If the PC of the thread we were trying to single-step has
7518 changed, then that thread has trapped or been signaled, but the
7519 event has not been reported to GDB yet. Re-poll the target
7520 looking for this particular thread's event (i.e. temporarily
7521 enable schedlock) by:
7523 - setting a break at the current PC
7524 - resuming that particular thread, only (by setting trap
7527 This prevents us continuously moving the single-step breakpoint
7528 forward, one instruction at a time, overstepping. */
7530 if (tp
->stop_pc () != tp
->prev_pc
)
7534 infrun_debug_printf ("expected thread advanced also (%s -> %s)",
7535 paddress (target_gdbarch (), tp
->prev_pc
),
7536 paddress (target_gdbarch (), tp
->stop_pc ()));
7538 /* Clear the info of the previous step-over, as it's no longer
7539 valid (if the thread was trying to step over a breakpoint, it
7540 has already succeeded). It's what keep_going would do too,
7541 if we called it. Do this before trying to insert the sss
7542 breakpoint, otherwise if we were previously trying to step
7543 over this exact address in another thread, the breakpoint is
7545 clear_step_over_info ();
7546 tp
->control
.trap_expected
= 0;
7548 insert_single_step_breakpoint (get_frame_arch (frame
),
7549 get_frame_address_space (frame
),
7552 tp
->set_resumed (true);
7553 resume_ptid
= internal_resume_ptid (tp
->control
.stepping_command
);
7554 do_target_resume (resume_ptid
, false, GDB_SIGNAL_0
);
7558 infrun_debug_printf ("expected thread still hasn't advanced");
7560 keep_going_pass_signal (ecs
);
7566 /* Is thread TP in the middle of (software or hardware)
7567 single-stepping? (Note the result of this function must never be
7568 passed directly as target_resume's STEP parameter.) */
7571 currently_stepping (struct thread_info
*tp
)
7573 return ((tp
->control
.step_range_end
7574 && tp
->control
.step_resume_breakpoint
== NULL
)
7575 || tp
->control
.trap_expected
7576 || tp
->stepped_breakpoint
7577 || bpstat_should_step ());
7580 /* Inferior has stepped into a subroutine call with source code that
7581 we should not step over. Do step to the first line of code in
7585 handle_step_into_function (struct gdbarch
*gdbarch
,
7586 struct execution_control_state
*ecs
)
7588 fill_in_stop_func (gdbarch
, ecs
);
7590 compunit_symtab
*cust
7591 = find_pc_compunit_symtab (ecs
->event_thread
->stop_pc ());
7592 if (cust
!= NULL
&& compunit_language (cust
) != language_asm
)
7593 ecs
->stop_func_start
7594 = gdbarch_skip_prologue_noexcept (gdbarch
, ecs
->stop_func_start
);
7596 symtab_and_line stop_func_sal
= find_pc_line (ecs
->stop_func_start
, 0);
7597 /* Use the step_resume_break to step until the end of the prologue,
7598 even if that involves jumps (as it seems to on the vax under
7600 /* If the prologue ends in the middle of a source line, continue to
7601 the end of that source line (if it is still within the function).
7602 Otherwise, just go to end of prologue. */
7603 if (stop_func_sal
.end
7604 && stop_func_sal
.pc
!= ecs
->stop_func_start
7605 && stop_func_sal
.end
< ecs
->stop_func_end
)
7606 ecs
->stop_func_start
= stop_func_sal
.end
;
7608 /* Architectures which require breakpoint adjustment might not be able
7609 to place a breakpoint at the computed address. If so, the test
7610 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
7611 ecs->stop_func_start to an address at which a breakpoint may be
7612 legitimately placed.
7614 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
7615 made, GDB will enter an infinite loop when stepping through
7616 optimized code consisting of VLIW instructions which contain
7617 subinstructions corresponding to different source lines. On
7618 FR-V, it's not permitted to place a breakpoint on any but the
7619 first subinstruction of a VLIW instruction. When a breakpoint is
7620 set, GDB will adjust the breakpoint address to the beginning of
7621 the VLIW instruction. Thus, we need to make the corresponding
7622 adjustment here when computing the stop address. */
7624 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
7626 ecs
->stop_func_start
7627 = gdbarch_adjust_breakpoint_address (gdbarch
,
7628 ecs
->stop_func_start
);
7631 if (ecs
->stop_func_start
== ecs
->event_thread
->stop_pc ())
7633 /* We are already there: stop now. */
7634 end_stepping_range (ecs
);
7639 /* Put the step-breakpoint there and go until there. */
7640 symtab_and_line sr_sal
;
7641 sr_sal
.pc
= ecs
->stop_func_start
;
7642 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
7643 sr_sal
.pspace
= get_frame_program_space (get_current_frame ());
7645 /* Do not specify what the fp should be when we stop since on
7646 some machines the prologue is where the new fp value is
7648 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
, null_frame_id
);
7650 /* And make sure stepping stops right away then. */
7651 ecs
->event_thread
->control
.step_range_end
7652 = ecs
->event_thread
->control
.step_range_start
;
7657 /* Inferior has stepped backward into a subroutine call with source
7658 code that we should not step over. Do step to the beginning of the
7659 last line of code in it. */
7662 handle_step_into_function_backward (struct gdbarch
*gdbarch
,
7663 struct execution_control_state
*ecs
)
7665 struct compunit_symtab
*cust
;
7666 struct symtab_and_line stop_func_sal
;
7668 fill_in_stop_func (gdbarch
, ecs
);
7670 cust
= find_pc_compunit_symtab (ecs
->event_thread
->stop_pc ());
7671 if (cust
!= NULL
&& compunit_language (cust
) != language_asm
)
7672 ecs
->stop_func_start
7673 = gdbarch_skip_prologue_noexcept (gdbarch
, ecs
->stop_func_start
);
7675 stop_func_sal
= find_pc_line (ecs
->event_thread
->stop_pc (), 0);
7677 /* OK, we're just going to keep stepping here. */
7678 if (stop_func_sal
.pc
== ecs
->event_thread
->stop_pc ())
7680 /* We're there already. Just stop stepping now. */
7681 end_stepping_range (ecs
);
7685 /* Else just reset the step range and keep going.
7686 No step-resume breakpoint, they don't work for
7687 epilogues, which can have multiple entry paths. */
7688 ecs
->event_thread
->control
.step_range_start
= stop_func_sal
.pc
;
7689 ecs
->event_thread
->control
.step_range_end
= stop_func_sal
.end
;
7695 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
7696 This is used to both functions and to skip over code. */
7699 insert_step_resume_breakpoint_at_sal_1 (struct gdbarch
*gdbarch
,
7700 struct symtab_and_line sr_sal
,
7701 struct frame_id sr_id
,
7702 enum bptype sr_type
)
7704 /* There should never be more than one step-resume or longjmp-resume
7705 breakpoint per thread, so we should never be setting a new
7706 step_resume_breakpoint when one is already active. */
7707 gdb_assert (inferior_thread ()->control
.step_resume_breakpoint
== NULL
);
7708 gdb_assert (sr_type
== bp_step_resume
|| sr_type
== bp_hp_step_resume
);
7710 infrun_debug_printf ("inserting step-resume breakpoint at %s",
7711 paddress (gdbarch
, sr_sal
.pc
));
7713 inferior_thread ()->control
.step_resume_breakpoint
7714 = set_momentary_breakpoint (gdbarch
, sr_sal
, sr_id
, sr_type
).release ();
7718 insert_step_resume_breakpoint_at_sal (struct gdbarch
*gdbarch
,
7719 struct symtab_and_line sr_sal
,
7720 struct frame_id sr_id
)
7722 insert_step_resume_breakpoint_at_sal_1 (gdbarch
,
7727 /* Insert a "high-priority step-resume breakpoint" at RETURN_FRAME.pc.
7728 This is used to skip a potential signal handler.
7730 This is called with the interrupted function's frame. The signal
7731 handler, when it returns, will resume the interrupted function at
7735 insert_hp_step_resume_breakpoint_at_frame (struct frame_info
*return_frame
)
7737 gdb_assert (return_frame
!= NULL
);
7739 struct gdbarch
*gdbarch
= get_frame_arch (return_frame
);
7741 symtab_and_line sr_sal
;
7742 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
, get_frame_pc (return_frame
));
7743 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
7744 sr_sal
.pspace
= get_frame_program_space (return_frame
);
7746 insert_step_resume_breakpoint_at_sal_1 (gdbarch
, sr_sal
,
7747 get_stack_frame_id (return_frame
),
7751 /* Insert a "step-resume breakpoint" at the previous frame's PC. This
7752 is used to skip a function after stepping into it (for "next" or if
7753 the called function has no debugging information).
7755 The current function has almost always been reached by single
7756 stepping a call or return instruction. NEXT_FRAME belongs to the
7757 current function, and the breakpoint will be set at the caller's
7760 This is a separate function rather than reusing
7761 insert_hp_step_resume_breakpoint_at_frame in order to avoid
7762 get_prev_frame, which may stop prematurely (see the implementation
7763 of frame_unwind_caller_id for an example). */
7766 insert_step_resume_breakpoint_at_caller (struct frame_info
*next_frame
)
7768 /* We shouldn't have gotten here if we don't know where the call site
7770 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame
)));
7772 struct gdbarch
*gdbarch
= frame_unwind_caller_arch (next_frame
);
7774 symtab_and_line sr_sal
;
7775 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
,
7776 frame_unwind_caller_pc (next_frame
));
7777 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
7778 sr_sal
.pspace
= frame_unwind_program_space (next_frame
);
7780 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
,
7781 frame_unwind_caller_id (next_frame
));
7784 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
7785 new breakpoint at the target of a jmp_buf. The handling of
7786 longjmp-resume uses the same mechanisms used for handling
7787 "step-resume" breakpoints. */
7790 insert_longjmp_resume_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
7792 /* There should never be more than one longjmp-resume breakpoint per
7793 thread, so we should never be setting a new
7794 longjmp_resume_breakpoint when one is already active. */
7795 gdb_assert (inferior_thread ()->control
.exception_resume_breakpoint
== NULL
);
7797 infrun_debug_printf ("inserting longjmp-resume breakpoint at %s",
7798 paddress (gdbarch
, pc
));
7800 inferior_thread ()->control
.exception_resume_breakpoint
=
7801 set_momentary_breakpoint_at_pc (gdbarch
, pc
, bp_longjmp_resume
).release ();
7804 /* Insert an exception resume breakpoint. TP is the thread throwing
7805 the exception. The block B is the block of the unwinder debug hook
7806 function. FRAME is the frame corresponding to the call to this
7807 function. SYM is the symbol of the function argument holding the
7808 target PC of the exception. */
7811 insert_exception_resume_breakpoint (struct thread_info
*tp
,
7812 const struct block
*b
,
7813 struct frame_info
*frame
,
7818 struct block_symbol vsym
;
7819 struct value
*value
;
7821 struct breakpoint
*bp
;
7823 vsym
= lookup_symbol_search_name (sym
->search_name (),
7825 value
= read_var_value (vsym
.symbol
, vsym
.block
, frame
);
7826 /* If the value was optimized out, revert to the old behavior. */
7827 if (! value_optimized_out (value
))
7829 handler
= value_as_address (value
);
7831 infrun_debug_printf ("exception resume at %lx",
7832 (unsigned long) handler
);
7834 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
7836 bp_exception_resume
).release ();
7838 /* set_momentary_breakpoint_at_pc invalidates FRAME. */
7841 bp
->thread
= tp
->global_num
;
7842 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
7845 catch (const gdb_exception_error
&e
)
7847 /* We want to ignore errors here. */
7851 /* A helper for check_exception_resume that sets an
7852 exception-breakpoint based on a SystemTap probe. */
7855 insert_exception_resume_from_probe (struct thread_info
*tp
,
7856 const struct bound_probe
*probe
,
7857 struct frame_info
*frame
)
7859 struct value
*arg_value
;
7861 struct breakpoint
*bp
;
7863 arg_value
= probe_safe_evaluate_at_pc (frame
, 1);
7867 handler
= value_as_address (arg_value
);
7869 infrun_debug_printf ("exception resume at %s",
7870 paddress (probe
->objfile
->arch (), handler
));
7872 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
7873 handler
, bp_exception_resume
).release ();
7874 bp
->thread
= tp
->global_num
;
7875 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
7878 /* This is called when an exception has been intercepted. Check to
7879 see whether the exception's destination is of interest, and if so,
7880 set an exception resume breakpoint there. */
7883 check_exception_resume (struct execution_control_state
*ecs
,
7884 struct frame_info
*frame
)
7886 struct bound_probe probe
;
7887 struct symbol
*func
;
7889 /* First see if this exception unwinding breakpoint was set via a
7890 SystemTap probe point. If so, the probe has two arguments: the
7891 CFA and the HANDLER. We ignore the CFA, extract the handler, and
7892 set a breakpoint there. */
7893 probe
= find_probe_by_pc (get_frame_pc (frame
));
7896 insert_exception_resume_from_probe (ecs
->event_thread
, &probe
, frame
);
7900 func
= get_frame_function (frame
);
7906 const struct block
*b
;
7907 struct block_iterator iter
;
7911 /* The exception breakpoint is a thread-specific breakpoint on
7912 the unwinder's debug hook, declared as:
7914 void _Unwind_DebugHook (void *cfa, void *handler);
7916 The CFA argument indicates the frame to which control is
7917 about to be transferred. HANDLER is the destination PC.
7919 We ignore the CFA and set a temporary breakpoint at HANDLER.
7920 This is not extremely efficient but it avoids issues in gdb
7921 with computing the DWARF CFA, and it also works even in weird
7922 cases such as throwing an exception from inside a signal
7925 b
= SYMBOL_BLOCK_VALUE (func
);
7926 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
7928 if (!SYMBOL_IS_ARGUMENT (sym
))
7935 insert_exception_resume_breakpoint (ecs
->event_thread
,
7941 catch (const gdb_exception_error
&e
)
7947 stop_waiting (struct execution_control_state
*ecs
)
7949 infrun_debug_printf ("stop_waiting");
7951 /* Let callers know we don't want to wait for the inferior anymore. */
7952 ecs
->wait_some_more
= 0;
7954 /* If all-stop, but there exists a non-stop target, stop all
7955 threads now that we're presenting the stop to the user. */
7956 if (!non_stop
&& exists_non_stop_target ())
7957 stop_all_threads ();
7960 /* Like keep_going, but passes the signal to the inferior, even if the
7961 signal is set to nopass. */
7964 keep_going_pass_signal (struct execution_control_state
*ecs
)
7966 gdb_assert (ecs
->event_thread
->ptid
== inferior_ptid
);
7967 gdb_assert (!ecs
->event_thread
->resumed ());
7969 /* Save the pc before execution, to compare with pc after stop. */
7970 ecs
->event_thread
->prev_pc
7971 = regcache_read_pc_protected (get_thread_regcache (ecs
->event_thread
));
7973 if (ecs
->event_thread
->control
.trap_expected
)
7975 struct thread_info
*tp
= ecs
->event_thread
;
7977 infrun_debug_printf ("%s has trap_expected set, "
7978 "resuming to collect trap",
7979 target_pid_to_str (tp
->ptid
).c_str ());
7981 /* We haven't yet gotten our trap, and either: intercepted a
7982 non-signal event (e.g., a fork); or took a signal which we
7983 are supposed to pass through to the inferior. Simply
7985 resume (ecs
->event_thread
->stop_signal ());
7987 else if (step_over_info_valid_p ())
7989 /* Another thread is stepping over a breakpoint in-line. If
7990 this thread needs a step-over too, queue the request. In
7991 either case, this resume must be deferred for later. */
7992 struct thread_info
*tp
= ecs
->event_thread
;
7994 if (ecs
->hit_singlestep_breakpoint
7995 || thread_still_needs_step_over (tp
))
7997 infrun_debug_printf ("step-over already in progress: "
7998 "step-over for %s deferred",
7999 target_pid_to_str (tp
->ptid
).c_str ());
8000 global_thread_step_over_chain_enqueue (tp
);
8004 infrun_debug_printf ("step-over in progress: resume of %s deferred",
8005 target_pid_to_str (tp
->ptid
).c_str ());
8010 struct regcache
*regcache
= get_current_regcache ();
8013 step_over_what step_what
;
8015 /* Either the trap was not expected, but we are continuing
8016 anyway (if we got a signal, the user asked it be passed to
8019 We got our expected trap, but decided we should resume from
8022 We're going to run this baby now!
8024 Note that insert_breakpoints won't try to re-insert
8025 already inserted breakpoints. Therefore, we don't
8026 care if breakpoints were already inserted, or not. */
8028 /* If we need to step over a breakpoint, and we're not using
8029 displaced stepping to do so, insert all breakpoints
8030 (watchpoints, etc.) but the one we're stepping over, step one
8031 instruction, and then re-insert the breakpoint when that step
8034 step_what
= thread_still_needs_step_over (ecs
->event_thread
);
8036 remove_bp
= (ecs
->hit_singlestep_breakpoint
8037 || (step_what
& STEP_OVER_BREAKPOINT
));
8038 remove_wps
= (step_what
& STEP_OVER_WATCHPOINT
);
8040 /* We can't use displaced stepping if we need to step past a
8041 watchpoint. The instruction copied to the scratch pad would
8042 still trigger the watchpoint. */
8044 && (remove_wps
|| !use_displaced_stepping (ecs
->event_thread
)))
8046 set_step_over_info (regcache
->aspace (),
8047 regcache_read_pc (regcache
), remove_wps
,
8048 ecs
->event_thread
->global_num
);
8050 else if (remove_wps
)
8051 set_step_over_info (NULL
, 0, remove_wps
, -1);
8053 /* If we now need to do an in-line step-over, we need to stop
8054 all other threads. Note this must be done before
8055 insert_breakpoints below, because that removes the breakpoint
8056 we're about to step over, otherwise other threads could miss
8058 if (step_over_info_valid_p () && target_is_non_stop_p ())
8059 stop_all_threads ();
8061 /* Stop stepping if inserting breakpoints fails. */
8064 insert_breakpoints ();
8066 catch (const gdb_exception_error
&e
)
8068 exception_print (gdb_stderr
, e
);
8070 clear_step_over_info ();
8074 ecs
->event_thread
->control
.trap_expected
= (remove_bp
|| remove_wps
);
8076 resume (ecs
->event_thread
->stop_signal ());
8079 prepare_to_wait (ecs
);
8082 /* Called when we should continue running the inferior, because the
8083 current event doesn't cause a user visible stop. This does the
8084 resuming part; waiting for the next event is done elsewhere. */
8087 keep_going (struct execution_control_state
*ecs
)
8089 if (ecs
->event_thread
->control
.trap_expected
8090 && ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
)
8091 ecs
->event_thread
->control
.trap_expected
= 0;
8093 if (!signal_program
[ecs
->event_thread
->stop_signal ()])
8094 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
8095 keep_going_pass_signal (ecs
);
8098 /* This function normally comes after a resume, before
8099 handle_inferior_event exits. It takes care of any last bits of
8100 housekeeping, and sets the all-important wait_some_more flag. */
8103 prepare_to_wait (struct execution_control_state
*ecs
)
8105 infrun_debug_printf ("prepare_to_wait");
8107 ecs
->wait_some_more
= 1;
8109 /* If the target can't async, emulate it by marking the infrun event
8110 handler such that as soon as we get back to the event-loop, we
8111 immediately end up in fetch_inferior_event again calling
8113 if (!target_can_async_p ())
8114 mark_infrun_async_event_handler ();
8117 /* We are done with the step range of a step/next/si/ni command.
8118 Called once for each n of a "step n" operation. */
8121 end_stepping_range (struct execution_control_state
*ecs
)
8123 ecs
->event_thread
->control
.stop_step
= 1;
8127 /* Several print_*_reason functions to print why the inferior has stopped.
8128 We always print something when the inferior exits, or receives a signal.
8129 The rest of the cases are dealt with later on in normal_stop and
8130 print_it_typical. Ideally there should be a call to one of these
8131 print_*_reason functions functions from handle_inferior_event each time
8132 stop_waiting is called.
8134 Note that we don't call these directly, instead we delegate that to
8135 the interpreters, through observers. Interpreters then call these
8136 with whatever uiout is right. */
8139 print_end_stepping_range_reason (struct ui_out
*uiout
)
8141 /* For CLI-like interpreters, print nothing. */
8143 if (uiout
->is_mi_like_p ())
8145 uiout
->field_string ("reason",
8146 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE
));
8151 print_signal_exited_reason (struct ui_out
*uiout
, enum gdb_signal siggnal
)
8153 annotate_signalled ();
8154 if (uiout
->is_mi_like_p ())
8156 ("reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED
));
8157 uiout
->text ("\nProgram terminated with signal ");
8158 annotate_signal_name ();
8159 uiout
->field_string ("signal-name",
8160 gdb_signal_to_name (siggnal
));
8161 annotate_signal_name_end ();
8163 annotate_signal_string ();
8164 uiout
->field_string ("signal-meaning",
8165 gdb_signal_to_string (siggnal
));
8166 annotate_signal_string_end ();
8167 uiout
->text (".\n");
8168 uiout
->text ("The program no longer exists.\n");
8172 print_exited_reason (struct ui_out
*uiout
, int exitstatus
)
8174 struct inferior
*inf
= current_inferior ();
8175 std::string pidstr
= target_pid_to_str (ptid_t (inf
->pid
));
8177 annotate_exited (exitstatus
);
8180 if (uiout
->is_mi_like_p ())
8181 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXITED
));
8182 std::string exit_code_str
8183 = string_printf ("0%o", (unsigned int) exitstatus
);
8184 uiout
->message ("[Inferior %s (%s) exited with code %pF]\n",
8185 plongest (inf
->num
), pidstr
.c_str (),
8186 string_field ("exit-code", exit_code_str
.c_str ()));
8190 if (uiout
->is_mi_like_p ())
8192 ("reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY
));
8193 uiout
->message ("[Inferior %s (%s) exited normally]\n",
8194 plongest (inf
->num
), pidstr
.c_str ());
8199 print_signal_received_reason (struct ui_out
*uiout
, enum gdb_signal siggnal
)
8201 struct thread_info
*thr
= inferior_thread ();
8205 if (uiout
->is_mi_like_p ())
8207 else if (show_thread_that_caused_stop ())
8209 uiout
->text ("\nThread ");
8210 uiout
->field_string ("thread-id", print_thread_id (thr
));
8212 const char *name
= thread_name (thr
);
8215 uiout
->text (" \"");
8216 uiout
->field_string ("name", name
);
8221 uiout
->text ("\nProgram");
8223 if (siggnal
== GDB_SIGNAL_0
&& !uiout
->is_mi_like_p ())
8224 uiout
->text (" stopped");
8227 uiout
->text (" received signal ");
8228 annotate_signal_name ();
8229 if (uiout
->is_mi_like_p ())
8231 ("reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED
));
8232 uiout
->field_string ("signal-name", gdb_signal_to_name (siggnal
));
8233 annotate_signal_name_end ();
8235 annotate_signal_string ();
8236 uiout
->field_string ("signal-meaning", gdb_signal_to_string (siggnal
));
8238 struct regcache
*regcache
= get_current_regcache ();
8239 struct gdbarch
*gdbarch
= regcache
->arch ();
8240 if (gdbarch_report_signal_info_p (gdbarch
))
8241 gdbarch_report_signal_info (gdbarch
, uiout
, siggnal
);
8243 annotate_signal_string_end ();
8245 uiout
->text (".\n");
8249 print_no_history_reason (struct ui_out
*uiout
)
8251 uiout
->text ("\nNo more reverse-execution history.\n");
8254 /* Print current location without a level number, if we have changed
8255 functions or hit a breakpoint. Print source line if we have one.
8256 bpstat_print contains the logic deciding in detail what to print,
8257 based on the event(s) that just occurred. */
8260 print_stop_location (struct target_waitstatus
*ws
)
8263 enum print_what source_flag
;
8264 int do_frame_printing
= 1;
8265 struct thread_info
*tp
= inferior_thread ();
8267 bpstat_ret
= bpstat_print (tp
->control
.stop_bpstat
, ws
->kind
);
8271 /* FIXME: cagney/2002-12-01: Given that a frame ID does (or
8272 should) carry around the function and does (or should) use
8273 that when doing a frame comparison. */
8274 if (tp
->control
.stop_step
8275 && frame_id_eq (tp
->control
.step_frame_id
,
8276 get_frame_id (get_current_frame ()))
8277 && (tp
->control
.step_start_function
8278 == find_pc_function (tp
->stop_pc ())))
8280 /* Finished step, just print source line. */
8281 source_flag
= SRC_LINE
;
8285 /* Print location and source line. */
8286 source_flag
= SRC_AND_LOC
;
8289 case PRINT_SRC_AND_LOC
:
8290 /* Print location and source line. */
8291 source_flag
= SRC_AND_LOC
;
8293 case PRINT_SRC_ONLY
:
8294 source_flag
= SRC_LINE
;
8297 /* Something bogus. */
8298 source_flag
= SRC_LINE
;
8299 do_frame_printing
= 0;
8302 internal_error (__FILE__
, __LINE__
, _("Unknown value."));
8305 /* The behavior of this routine with respect to the source
8307 SRC_LINE: Print only source line
8308 LOCATION: Print only location
8309 SRC_AND_LOC: Print location and source line. */
8310 if (do_frame_printing
)
8311 print_stack_frame (get_selected_frame (NULL
), 0, source_flag
, 1);
8317 print_stop_event (struct ui_out
*uiout
, bool displays
)
8319 struct target_waitstatus last
;
8320 struct thread_info
*tp
;
8322 get_last_target_status (nullptr, nullptr, &last
);
8325 scoped_restore save_uiout
= make_scoped_restore (¤t_uiout
, uiout
);
8327 print_stop_location (&last
);
8329 /* Display the auto-display expressions. */
8334 tp
= inferior_thread ();
8335 if (tp
->thread_fsm
!= NULL
8336 && tp
->thread_fsm
->finished_p ())
8338 struct return_value_info
*rv
;
8340 rv
= tp
->thread_fsm
->return_value ();
8342 print_return_value (uiout
, rv
);
8349 maybe_remove_breakpoints (void)
8351 if (!breakpoints_should_be_inserted_now () && target_has_execution ())
8353 if (remove_breakpoints ())
8355 target_terminal::ours_for_output ();
8356 printf_filtered (_("Cannot remove breakpoints because "
8357 "program is no longer writable.\nFurther "
8358 "execution is probably impossible.\n"));
8363 /* The execution context that just caused a normal stop. */
8369 DISABLE_COPY_AND_ASSIGN (stop_context
);
8371 bool changed () const;
8376 /* The event PTID. */
8380 /* If stopp for a thread event, this is the thread that caused the
8382 thread_info_ref thread
;
8384 /* The inferior that caused the stop. */
8388 /* Initializes a new stop context. If stopped for a thread event, this
8389 takes a strong reference to the thread. */
8391 stop_context::stop_context ()
8393 stop_id
= get_stop_id ();
8394 ptid
= inferior_ptid
;
8395 inf_num
= current_inferior ()->num
;
8397 if (inferior_ptid
!= null_ptid
)
8399 /* Take a strong reference so that the thread can't be deleted
8401 thread
= thread_info_ref::new_reference (inferior_thread ());
8405 /* Return true if the current context no longer matches the saved stop
8409 stop_context::changed () const
8411 if (ptid
!= inferior_ptid
)
8413 if (inf_num
!= current_inferior ()->num
)
8415 if (thread
!= NULL
&& thread
->state
!= THREAD_STOPPED
)
8417 if (get_stop_id () != stop_id
)
8427 struct target_waitstatus last
;
8429 get_last_target_status (nullptr, nullptr, &last
);
8433 /* If an exception is thrown from this point on, make sure to
8434 propagate GDB's knowledge of the executing state to the
8435 frontend/user running state. A QUIT is an easy exception to see
8436 here, so do this before any filtered output. */
8438 ptid_t finish_ptid
= null_ptid
;
8441 finish_ptid
= minus_one_ptid
;
8442 else if (last
.kind
== TARGET_WAITKIND_SIGNALLED
8443 || last
.kind
== TARGET_WAITKIND_EXITED
)
8445 /* On some targets, we may still have live threads in the
8446 inferior when we get a process exit event. E.g., for
8447 "checkpoint", when the current checkpoint/fork exits,
8448 linux-fork.c automatically switches to another fork from
8449 within target_mourn_inferior. */
8450 if (inferior_ptid
!= null_ptid
)
8451 finish_ptid
= ptid_t (inferior_ptid
.pid ());
8453 else if (last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
8454 finish_ptid
= inferior_ptid
;
8456 gdb::optional
<scoped_finish_thread_state
> maybe_finish_thread_state
;
8457 if (finish_ptid
!= null_ptid
)
8459 maybe_finish_thread_state
.emplace
8460 (user_visible_resume_target (finish_ptid
), finish_ptid
);
8463 /* As we're presenting a stop, and potentially removing breakpoints,
8464 update the thread list so we can tell whether there are threads
8465 running on the target. With target remote, for example, we can
8466 only learn about new threads when we explicitly update the thread
8467 list. Do this before notifying the interpreters about signal
8468 stops, end of stepping ranges, etc., so that the "new thread"
8469 output is emitted before e.g., "Program received signal FOO",
8470 instead of after. */
8471 update_thread_list ();
8473 if (last
.kind
== TARGET_WAITKIND_STOPPED
&& stopped_by_random_signal
)
8474 gdb::observers::signal_received
.notify (inferior_thread ()->stop_signal ());
8476 /* As with the notification of thread events, we want to delay
8477 notifying the user that we've switched thread context until
8478 the inferior actually stops.
8480 There's no point in saying anything if the inferior has exited.
8481 Note that SIGNALLED here means "exited with a signal", not
8482 "received a signal".
8484 Also skip saying anything in non-stop mode. In that mode, as we
8485 don't want GDB to switch threads behind the user's back, to avoid
8486 races where the user is typing a command to apply to thread x,
8487 but GDB switches to thread y before the user finishes entering
8488 the command, fetch_inferior_event installs a cleanup to restore
8489 the current thread back to the thread the user had selected right
8490 after this event is handled, so we're not really switching, only
8491 informing of a stop. */
8493 && previous_inferior_ptid
!= inferior_ptid
8494 && target_has_execution ()
8495 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
8496 && last
.kind
!= TARGET_WAITKIND_EXITED
8497 && last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
8499 SWITCH_THRU_ALL_UIS ()
8501 target_terminal::ours_for_output ();
8502 printf_filtered (_("[Switching to %s]\n"),
8503 target_pid_to_str (inferior_ptid
).c_str ());
8504 annotate_thread_changed ();
8506 previous_inferior_ptid
= inferior_ptid
;
8509 if (last
.kind
== TARGET_WAITKIND_NO_RESUMED
)
8511 SWITCH_THRU_ALL_UIS ()
8512 if (current_ui
->prompt_state
== PROMPT_BLOCKED
)
8514 target_terminal::ours_for_output ();
8515 printf_filtered (_("No unwaited-for children left.\n"));
8519 /* Note: this depends on the update_thread_list call above. */
8520 maybe_remove_breakpoints ();
8522 /* If an auto-display called a function and that got a signal,
8523 delete that auto-display to avoid an infinite recursion. */
8525 if (stopped_by_random_signal
)
8526 disable_current_display ();
8528 SWITCH_THRU_ALL_UIS ()
8530 async_enable_stdin ();
8533 /* Let the user/frontend see the threads as stopped. */
8534 maybe_finish_thread_state
.reset ();
8536 /* Select innermost stack frame - i.e., current frame is frame 0,
8537 and current location is based on that. Handle the case where the
8538 dummy call is returning after being stopped. E.g. the dummy call
8539 previously hit a breakpoint. (If the dummy call returns
8540 normally, we won't reach here.) Do this before the stop hook is
8541 run, so that it doesn't get to see the temporary dummy frame,
8542 which is not where we'll present the stop. */
8543 if (has_stack_frames ())
8545 if (stop_stack_dummy
== STOP_STACK_DUMMY
)
8547 /* Pop the empty frame that contains the stack dummy. This
8548 also restores inferior state prior to the call (struct
8549 infcall_suspend_state). */
8550 struct frame_info
*frame
= get_current_frame ();
8552 gdb_assert (get_frame_type (frame
) == DUMMY_FRAME
);
8554 /* frame_pop calls reinit_frame_cache as the last thing it
8555 does which means there's now no selected frame. */
8558 select_frame (get_current_frame ());
8560 /* Set the current source location. */
8561 set_current_sal_from_frame (get_current_frame ());
8564 /* Look up the hook_stop and run it (CLI internally handles problem
8565 of stop_command's pre-hook not existing). */
8566 if (stop_command
!= NULL
)
8568 stop_context saved_context
;
8572 execute_cmd_pre_hook (stop_command
);
8574 catch (const gdb_exception
&ex
)
8576 exception_fprintf (gdb_stderr
, ex
,
8577 "Error while running hook_stop:\n");
8580 /* If the stop hook resumes the target, then there's no point in
8581 trying to notify about the previous stop; its context is
8582 gone. Likewise if the command switches thread or inferior --
8583 the observers would print a stop for the wrong
8585 if (saved_context
.changed ())
8589 /* Notify observers about the stop. This is where the interpreters
8590 print the stop event. */
8591 if (inferior_ptid
!= null_ptid
)
8592 gdb::observers::normal_stop
.notify (inferior_thread ()->control
.stop_bpstat
,
8595 gdb::observers::normal_stop
.notify (NULL
, stop_print_frame
);
8597 annotate_stopped ();
8599 if (target_has_execution ())
8601 if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
8602 && last
.kind
!= TARGET_WAITKIND_EXITED
8603 && last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
8604 /* Delete the breakpoint we stopped at, if it wants to be deleted.
8605 Delete any breakpoint that is to be deleted at the next stop. */
8606 breakpoint_auto_delete (inferior_thread ()->control
.stop_bpstat
);
8609 /* Try to get rid of automatically added inferiors that are no
8610 longer needed. Keeping those around slows down things linearly.
8611 Note that this never removes the current inferior. */
8618 signal_stop_state (int signo
)
8620 return signal_stop
[signo
];
8624 signal_print_state (int signo
)
8626 return signal_print
[signo
];
8630 signal_pass_state (int signo
)
8632 return signal_program
[signo
];
8636 signal_cache_update (int signo
)
8640 for (signo
= 0; signo
< (int) GDB_SIGNAL_LAST
; signo
++)
8641 signal_cache_update (signo
);
8646 signal_pass
[signo
] = (signal_stop
[signo
] == 0
8647 && signal_print
[signo
] == 0
8648 && signal_program
[signo
] == 1
8649 && signal_catch
[signo
] == 0);
8653 signal_stop_update (int signo
, int state
)
8655 int ret
= signal_stop
[signo
];
8657 signal_stop
[signo
] = state
;
8658 signal_cache_update (signo
);
8663 signal_print_update (int signo
, int state
)
8665 int ret
= signal_print
[signo
];
8667 signal_print
[signo
] = state
;
8668 signal_cache_update (signo
);
8673 signal_pass_update (int signo
, int state
)
8675 int ret
= signal_program
[signo
];
8677 signal_program
[signo
] = state
;
8678 signal_cache_update (signo
);
8682 /* Update the global 'signal_catch' from INFO and notify the
8686 signal_catch_update (const unsigned int *info
)
8690 for (i
= 0; i
< GDB_SIGNAL_LAST
; ++i
)
8691 signal_catch
[i
] = info
[i
] > 0;
8692 signal_cache_update (-1);
8693 target_pass_signals (signal_pass
);
8697 sig_print_header (void)
8699 printf_filtered (_("Signal Stop\tPrint\tPass "
8700 "to program\tDescription\n"));
8704 sig_print_info (enum gdb_signal oursig
)
8706 const char *name
= gdb_signal_to_name (oursig
);
8707 int name_padding
= 13 - strlen (name
);
8709 if (name_padding
<= 0)
8712 printf_filtered ("%s", name
);
8713 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
8714 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
8715 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
8716 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
8717 printf_filtered ("%s\n", gdb_signal_to_string (oursig
));
8720 /* Specify how various signals in the inferior should be handled. */
8723 handle_command (const char *args
, int from_tty
)
8725 int digits
, wordlen
;
8726 int sigfirst
, siglast
;
8727 enum gdb_signal oursig
;
8732 error_no_arg (_("signal to handle"));
8735 /* Allocate and zero an array of flags for which signals to handle. */
8737 const size_t nsigs
= GDB_SIGNAL_LAST
;
8738 unsigned char sigs
[nsigs
] {};
8740 /* Break the command line up into args. */
8742 gdb_argv
built_argv (args
);
8744 /* Walk through the args, looking for signal oursigs, signal names, and
8745 actions. Signal numbers and signal names may be interspersed with
8746 actions, with the actions being performed for all signals cumulatively
8747 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
8749 for (char *arg
: built_argv
)
8751 wordlen
= strlen (arg
);
8752 for (digits
= 0; isdigit (arg
[digits
]); digits
++)
8756 sigfirst
= siglast
= -1;
8758 if (wordlen
>= 1 && !strncmp (arg
, "all", wordlen
))
8760 /* Apply action to all signals except those used by the
8761 debugger. Silently skip those. */
8764 siglast
= nsigs
- 1;
8766 else if (wordlen
>= 1 && !strncmp (arg
, "stop", wordlen
))
8768 SET_SIGS (nsigs
, sigs
, signal_stop
);
8769 SET_SIGS (nsigs
, sigs
, signal_print
);
8771 else if (wordlen
>= 1 && !strncmp (arg
, "ignore", wordlen
))
8773 UNSET_SIGS (nsigs
, sigs
, signal_program
);
8775 else if (wordlen
>= 2 && !strncmp (arg
, "print", wordlen
))
8777 SET_SIGS (nsigs
, sigs
, signal_print
);
8779 else if (wordlen
>= 2 && !strncmp (arg
, "pass", wordlen
))
8781 SET_SIGS (nsigs
, sigs
, signal_program
);
8783 else if (wordlen
>= 3 && !strncmp (arg
, "nostop", wordlen
))
8785 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
8787 else if (wordlen
>= 3 && !strncmp (arg
, "noignore", wordlen
))
8789 SET_SIGS (nsigs
, sigs
, signal_program
);
8791 else if (wordlen
>= 4 && !strncmp (arg
, "noprint", wordlen
))
8793 UNSET_SIGS (nsigs
, sigs
, signal_print
);
8794 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
8796 else if (wordlen
>= 4 && !strncmp (arg
, "nopass", wordlen
))
8798 UNSET_SIGS (nsigs
, sigs
, signal_program
);
8800 else if (digits
> 0)
8802 /* It is numeric. The numeric signal refers to our own
8803 internal signal numbering from target.h, not to host/target
8804 signal number. This is a feature; users really should be
8805 using symbolic names anyway, and the common ones like
8806 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
8808 sigfirst
= siglast
= (int)
8809 gdb_signal_from_command (atoi (arg
));
8810 if (arg
[digits
] == '-')
8813 gdb_signal_from_command (atoi (arg
+ digits
+ 1));
8815 if (sigfirst
> siglast
)
8817 /* Bet he didn't figure we'd think of this case... */
8818 std::swap (sigfirst
, siglast
);
8823 oursig
= gdb_signal_from_name (arg
);
8824 if (oursig
!= GDB_SIGNAL_UNKNOWN
)
8826 sigfirst
= siglast
= (int) oursig
;
8830 /* Not a number and not a recognized flag word => complain. */
8831 error (_("Unrecognized or ambiguous flag word: \"%s\"."), arg
);
8835 /* If any signal numbers or symbol names were found, set flags for
8836 which signals to apply actions to. */
8838 for (int signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
8840 switch ((enum gdb_signal
) signum
)
8842 case GDB_SIGNAL_TRAP
:
8843 case GDB_SIGNAL_INT
:
8844 if (!allsigs
&& !sigs
[signum
])
8846 if (query (_("%s is used by the debugger.\n\
8847 Are you sure you want to change it? "),
8848 gdb_signal_to_name ((enum gdb_signal
) signum
)))
8853 printf_unfiltered (_("Not confirmed, unchanged.\n"));
8857 case GDB_SIGNAL_DEFAULT
:
8858 case GDB_SIGNAL_UNKNOWN
:
8859 /* Make sure that "all" doesn't print these. */
8868 for (int signum
= 0; signum
< nsigs
; signum
++)
8871 signal_cache_update (-1);
8872 target_pass_signals (signal_pass
);
8873 target_program_signals (signal_program
);
8877 /* Show the results. */
8878 sig_print_header ();
8879 for (; signum
< nsigs
; signum
++)
8881 sig_print_info ((enum gdb_signal
) signum
);
8888 /* Complete the "handle" command. */
8891 handle_completer (struct cmd_list_element
*ignore
,
8892 completion_tracker
&tracker
,
8893 const char *text
, const char *word
)
8895 static const char * const keywords
[] =
8909 signal_completer (ignore
, tracker
, text
, word
);
8910 complete_on_enum (tracker
, keywords
, word
, word
);
8914 gdb_signal_from_command (int num
)
8916 if (num
>= 1 && num
<= 15)
8917 return (enum gdb_signal
) num
;
8918 error (_("Only signals 1-15 are valid as numeric signals.\n\
8919 Use \"info signals\" for a list of symbolic signals."));
8922 /* Print current contents of the tables set by the handle command.
8923 It is possible we should just be printing signals actually used
8924 by the current target (but for things to work right when switching
8925 targets, all signals should be in the signal tables). */
8928 info_signals_command (const char *signum_exp
, int from_tty
)
8930 enum gdb_signal oursig
;
8932 sig_print_header ();
8936 /* First see if this is a symbol name. */
8937 oursig
= gdb_signal_from_name (signum_exp
);
8938 if (oursig
== GDB_SIGNAL_UNKNOWN
)
8940 /* No, try numeric. */
8942 gdb_signal_from_command (parse_and_eval_long (signum_exp
));
8944 sig_print_info (oursig
);
8948 printf_filtered ("\n");
8949 /* These ugly casts brought to you by the native VAX compiler. */
8950 for (oursig
= GDB_SIGNAL_FIRST
;
8951 (int) oursig
< (int) GDB_SIGNAL_LAST
;
8952 oursig
= (enum gdb_signal
) ((int) oursig
+ 1))
8956 if (oursig
!= GDB_SIGNAL_UNKNOWN
8957 && oursig
!= GDB_SIGNAL_DEFAULT
&& oursig
!= GDB_SIGNAL_0
)
8958 sig_print_info (oursig
);
8961 printf_filtered (_("\nUse the \"handle\" command "
8962 "to change these tables.\n"));
8965 /* The $_siginfo convenience variable is a bit special. We don't know
8966 for sure the type of the value until we actually have a chance to
8967 fetch the data. The type can change depending on gdbarch, so it is
8968 also dependent on which thread you have selected.
8970 1. making $_siginfo be an internalvar that creates a new value on
8973 2. making the value of $_siginfo be an lval_computed value. */
8975 /* This function implements the lval_computed support for reading a
8979 siginfo_value_read (struct value
*v
)
8981 LONGEST transferred
;
8983 /* If we can access registers, so can we access $_siginfo. Likewise
8985 validate_registers_access ();
8988 target_read (current_inferior ()->top_target (),
8989 TARGET_OBJECT_SIGNAL_INFO
,
8991 value_contents_all_raw (v
),
8993 TYPE_LENGTH (value_type (v
)));
8995 if (transferred
!= TYPE_LENGTH (value_type (v
)))
8996 error (_("Unable to read siginfo"));
8999 /* This function implements the lval_computed support for writing a
9003 siginfo_value_write (struct value
*v
, struct value
*fromval
)
9005 LONGEST transferred
;
9007 /* If we can access registers, so can we access $_siginfo. Likewise
9009 validate_registers_access ();
9011 transferred
= target_write (current_inferior ()->top_target (),
9012 TARGET_OBJECT_SIGNAL_INFO
,
9014 value_contents_all_raw (fromval
),
9016 TYPE_LENGTH (value_type (fromval
)));
9018 if (transferred
!= TYPE_LENGTH (value_type (fromval
)))
9019 error (_("Unable to write siginfo"));
9022 static const struct lval_funcs siginfo_value_funcs
=
9028 /* Return a new value with the correct type for the siginfo object of
9029 the current thread using architecture GDBARCH. Return a void value
9030 if there's no object available. */
9032 static struct value
*
9033 siginfo_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
,
9036 if (target_has_stack ()
9037 && inferior_ptid
!= null_ptid
9038 && gdbarch_get_siginfo_type_p (gdbarch
))
9040 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
9042 return allocate_computed_value (type
, &siginfo_value_funcs
, NULL
);
9045 return allocate_value (builtin_type (gdbarch
)->builtin_void
);
9049 /* infcall_suspend_state contains state about the program itself like its
9050 registers and any signal it received when it last stopped.
9051 This state must be restored regardless of how the inferior function call
9052 ends (either successfully, or after it hits a breakpoint or signal)
9053 if the program is to properly continue where it left off. */
9055 class infcall_suspend_state
9058 /* Capture state from GDBARCH, TP, and REGCACHE that must be restored
9059 once the inferior function call has finished. */
9060 infcall_suspend_state (struct gdbarch
*gdbarch
,
9061 const struct thread_info
*tp
,
9062 struct regcache
*regcache
)
9063 : m_registers (new readonly_detached_regcache (*regcache
))
9065 tp
->save_suspend_to (m_thread_suspend
);
9067 gdb::unique_xmalloc_ptr
<gdb_byte
> siginfo_data
;
9069 if (gdbarch_get_siginfo_type_p (gdbarch
))
9071 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
9072 size_t len
= TYPE_LENGTH (type
);
9074 siginfo_data
.reset ((gdb_byte
*) xmalloc (len
));
9076 if (target_read (current_inferior ()->top_target (),
9077 TARGET_OBJECT_SIGNAL_INFO
, NULL
,
9078 siginfo_data
.get (), 0, len
) != len
)
9080 /* Errors ignored. */
9081 siginfo_data
.reset (nullptr);
9087 m_siginfo_gdbarch
= gdbarch
;
9088 m_siginfo_data
= std::move (siginfo_data
);
9092 /* Return a pointer to the stored register state. */
9094 readonly_detached_regcache
*registers () const
9096 return m_registers
.get ();
9099 /* Restores the stored state into GDBARCH, TP, and REGCACHE. */
9101 void restore (struct gdbarch
*gdbarch
,
9102 struct thread_info
*tp
,
9103 struct regcache
*regcache
) const
9105 tp
->restore_suspend_from (m_thread_suspend
);
9107 if (m_siginfo_gdbarch
== gdbarch
)
9109 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
9111 /* Errors ignored. */
9112 target_write (current_inferior ()->top_target (),
9113 TARGET_OBJECT_SIGNAL_INFO
, NULL
,
9114 m_siginfo_data
.get (), 0, TYPE_LENGTH (type
));
9117 /* The inferior can be gone if the user types "print exit(0)"
9118 (and perhaps other times). */
9119 if (target_has_execution ())
9120 /* NB: The register write goes through to the target. */
9121 regcache
->restore (registers ());
9125 /* How the current thread stopped before the inferior function call was
9127 struct thread_suspend_state m_thread_suspend
;
9129 /* The registers before the inferior function call was executed. */
9130 std::unique_ptr
<readonly_detached_regcache
> m_registers
;
9132 /* Format of SIGINFO_DATA or NULL if it is not present. */
9133 struct gdbarch
*m_siginfo_gdbarch
= nullptr;
9135 /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
9136 TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the
9137 content would be invalid. */
9138 gdb::unique_xmalloc_ptr
<gdb_byte
> m_siginfo_data
;
9141 infcall_suspend_state_up
9142 save_infcall_suspend_state ()
9144 struct thread_info
*tp
= inferior_thread ();
9145 struct regcache
*regcache
= get_current_regcache ();
9146 struct gdbarch
*gdbarch
= regcache
->arch ();
9148 infcall_suspend_state_up inf_state
9149 (new struct infcall_suspend_state (gdbarch
, tp
, regcache
));
9151 /* Having saved the current state, adjust the thread state, discarding
9152 any stop signal information. The stop signal is not useful when
9153 starting an inferior function call, and run_inferior_call will not use
9154 the signal due to its `proceed' call with GDB_SIGNAL_0. */
9155 tp
->set_stop_signal (GDB_SIGNAL_0
);
9160 /* Restore inferior session state to INF_STATE. */
9163 restore_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
9165 struct thread_info
*tp
= inferior_thread ();
9166 struct regcache
*regcache
= get_current_regcache ();
9167 struct gdbarch
*gdbarch
= regcache
->arch ();
9169 inf_state
->restore (gdbarch
, tp
, regcache
);
9170 discard_infcall_suspend_state (inf_state
);
9174 discard_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
9179 readonly_detached_regcache
*
9180 get_infcall_suspend_state_regcache (struct infcall_suspend_state
*inf_state
)
9182 return inf_state
->registers ();
9185 /* infcall_control_state contains state regarding gdb's control of the
9186 inferior itself like stepping control. It also contains session state like
9187 the user's currently selected frame. */
9189 struct infcall_control_state
9191 struct thread_control_state thread_control
;
9192 struct inferior_control_state inferior_control
;
9195 enum stop_stack_kind stop_stack_dummy
= STOP_NONE
;
9196 int stopped_by_random_signal
= 0;
9198 /* ID and level of the selected frame when the inferior function
9200 struct frame_id selected_frame_id
{};
9201 int selected_frame_level
= -1;
9204 /* Save all of the information associated with the inferior<==>gdb
9207 infcall_control_state_up
9208 save_infcall_control_state ()
9210 infcall_control_state_up
inf_status (new struct infcall_control_state
);
9211 struct thread_info
*tp
= inferior_thread ();
9212 struct inferior
*inf
= current_inferior ();
9214 inf_status
->thread_control
= tp
->control
;
9215 inf_status
->inferior_control
= inf
->control
;
9217 tp
->control
.step_resume_breakpoint
= NULL
;
9218 tp
->control
.exception_resume_breakpoint
= NULL
;
9220 /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of
9221 chain. If caller's caller is walking the chain, they'll be happier if we
9222 hand them back the original chain when restore_infcall_control_state is
9224 tp
->control
.stop_bpstat
= bpstat_copy (tp
->control
.stop_bpstat
);
9227 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
9228 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
9230 save_selected_frame (&inf_status
->selected_frame_id
,
9231 &inf_status
->selected_frame_level
);
9236 /* Restore inferior session state to INF_STATUS. */
9239 restore_infcall_control_state (struct infcall_control_state
*inf_status
)
9241 struct thread_info
*tp
= inferior_thread ();
9242 struct inferior
*inf
= current_inferior ();
9244 if (tp
->control
.step_resume_breakpoint
)
9245 tp
->control
.step_resume_breakpoint
->disposition
= disp_del_at_next_stop
;
9247 if (tp
->control
.exception_resume_breakpoint
)
9248 tp
->control
.exception_resume_breakpoint
->disposition
9249 = disp_del_at_next_stop
;
9251 /* Handle the bpstat_copy of the chain. */
9252 bpstat_clear (&tp
->control
.stop_bpstat
);
9254 tp
->control
= inf_status
->thread_control
;
9255 inf
->control
= inf_status
->inferior_control
;
9258 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
9259 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
9261 if (target_has_stack ())
9263 restore_selected_frame (inf_status
->selected_frame_id
,
9264 inf_status
->selected_frame_level
);
9271 discard_infcall_control_state (struct infcall_control_state
*inf_status
)
9273 if (inf_status
->thread_control
.step_resume_breakpoint
)
9274 inf_status
->thread_control
.step_resume_breakpoint
->disposition
9275 = disp_del_at_next_stop
;
9277 if (inf_status
->thread_control
.exception_resume_breakpoint
)
9278 inf_status
->thread_control
.exception_resume_breakpoint
->disposition
9279 = disp_del_at_next_stop
;
9281 /* See save_infcall_control_state for info on stop_bpstat. */
9282 bpstat_clear (&inf_status
->thread_control
.stop_bpstat
);
9290 clear_exit_convenience_vars (void)
9292 clear_internalvar (lookup_internalvar ("_exitsignal"));
9293 clear_internalvar (lookup_internalvar ("_exitcode"));
9297 /* User interface for reverse debugging:
9298 Set exec-direction / show exec-direction commands
9299 (returns error unless target implements to_set_exec_direction method). */
9301 enum exec_direction_kind execution_direction
= EXEC_FORWARD
;
9302 static const char exec_forward
[] = "forward";
9303 static const char exec_reverse
[] = "reverse";
9304 static const char *exec_direction
= exec_forward
;
9305 static const char *const exec_direction_names
[] = {
9312 set_exec_direction_func (const char *args
, int from_tty
,
9313 struct cmd_list_element
*cmd
)
9315 if (target_can_execute_reverse ())
9317 if (!strcmp (exec_direction
, exec_forward
))
9318 execution_direction
= EXEC_FORWARD
;
9319 else if (!strcmp (exec_direction
, exec_reverse
))
9320 execution_direction
= EXEC_REVERSE
;
9324 exec_direction
= exec_forward
;
9325 error (_("Target does not support this operation."));
9330 show_exec_direction_func (struct ui_file
*out
, int from_tty
,
9331 struct cmd_list_element
*cmd
, const char *value
)
9333 switch (execution_direction
) {
9335 fprintf_filtered (out
, _("Forward.\n"));
9338 fprintf_filtered (out
, _("Reverse.\n"));
9341 internal_error (__FILE__
, __LINE__
,
9342 _("bogus execution_direction value: %d"),
9343 (int) execution_direction
);
9348 show_schedule_multiple (struct ui_file
*file
, int from_tty
,
9349 struct cmd_list_element
*c
, const char *value
)
9351 fprintf_filtered (file
, _("Resuming the execution of threads "
9352 "of all processes is %s.\n"), value
);
9355 /* Implementation of `siginfo' variable. */
9357 static const struct internalvar_funcs siginfo_funcs
=
9364 /* Callback for infrun's target events source. This is marked when a
9365 thread has a pending status to process. */
9368 infrun_async_inferior_event_handler (gdb_client_data data
)
9370 clear_async_event_handler (infrun_async_inferior_event_token
);
9371 inferior_event_handler (INF_REG_EVENT
);
9378 /* Verify that when two threads with the same ptid exist (from two different
9379 targets) and one of them changes ptid, we only update inferior_ptid if
9380 it is appropriate. */
9383 infrun_thread_ptid_changed ()
9385 gdbarch
*arch
= current_inferior ()->gdbarch
;
9387 /* The thread which inferior_ptid represents changes ptid. */
9389 scoped_restore_current_pspace_and_thread restore
;
9391 scoped_mock_context
<test_target_ops
> target1 (arch
);
9392 scoped_mock_context
<test_target_ops
> target2 (arch
);
9394 ptid_t
old_ptid (111, 222);
9395 ptid_t
new_ptid (111, 333);
9397 target1
.mock_inferior
.pid
= old_ptid
.pid ();
9398 target1
.mock_thread
.ptid
= old_ptid
;
9399 target1
.mock_inferior
.ptid_thread_map
.clear ();
9400 target1
.mock_inferior
.ptid_thread_map
[old_ptid
] = &target1
.mock_thread
;
9402 target2
.mock_inferior
.pid
= old_ptid
.pid ();
9403 target2
.mock_thread
.ptid
= old_ptid
;
9404 target2
.mock_inferior
.ptid_thread_map
.clear ();
9405 target2
.mock_inferior
.ptid_thread_map
[old_ptid
] = &target2
.mock_thread
;
9407 auto restore_inferior_ptid
= make_scoped_restore (&inferior_ptid
, old_ptid
);
9408 set_current_inferior (&target1
.mock_inferior
);
9410 thread_change_ptid (&target1
.mock_target
, old_ptid
, new_ptid
);
9412 gdb_assert (inferior_ptid
== new_ptid
);
9415 /* A thread with the same ptid as inferior_ptid, but from another target,
9418 scoped_restore_current_pspace_and_thread restore
;
9420 scoped_mock_context
<test_target_ops
> target1 (arch
);
9421 scoped_mock_context
<test_target_ops
> target2 (arch
);
9423 ptid_t
old_ptid (111, 222);
9424 ptid_t
new_ptid (111, 333);
9426 target1
.mock_inferior
.pid
= old_ptid
.pid ();
9427 target1
.mock_thread
.ptid
= old_ptid
;
9428 target1
.mock_inferior
.ptid_thread_map
.clear ();
9429 target1
.mock_inferior
.ptid_thread_map
[old_ptid
] = &target1
.mock_thread
;
9431 target2
.mock_inferior
.pid
= old_ptid
.pid ();
9432 target2
.mock_thread
.ptid
= old_ptid
;
9433 target2
.mock_inferior
.ptid_thread_map
.clear ();
9434 target2
.mock_inferior
.ptid_thread_map
[old_ptid
] = &target2
.mock_thread
;
9436 auto restore_inferior_ptid
= make_scoped_restore (&inferior_ptid
, old_ptid
);
9437 set_current_inferior (&target2
.mock_inferior
);
9439 thread_change_ptid (&target1
.mock_target
, old_ptid
, new_ptid
);
9441 gdb_assert (inferior_ptid
== old_ptid
);
9445 } /* namespace selftests */
9447 #endif /* GDB_SELF_TEST */
9449 void _initialize_infrun ();
9451 _initialize_infrun ()
9453 struct cmd_list_element
*c
;
9455 /* Register extra event sources in the event loop. */
9456 infrun_async_inferior_event_token
9457 = create_async_event_handler (infrun_async_inferior_event_handler
, NULL
,
9460 cmd_list_element
*info_signals_cmd
9461 = add_info ("signals", info_signals_command
, _("\
9462 What debugger does when program gets various signals.\n\
9463 Specify a signal as argument to print info on that signal only."));
9464 add_info_alias ("handle", info_signals_cmd
, 0);
9466 c
= add_com ("handle", class_run
, handle_command
, _("\
9467 Specify how to handle signals.\n\
9468 Usage: handle SIGNAL [ACTIONS]\n\
9469 Args are signals and actions to apply to those signals.\n\
9470 If no actions are specified, the current settings for the specified signals\n\
9471 will be displayed instead.\n\
9473 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
9474 from 1-15 are allowed for compatibility with old versions of GDB.\n\
9475 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
9476 The special arg \"all\" is recognized to mean all signals except those\n\
9477 used by the debugger, typically SIGTRAP and SIGINT.\n\
9479 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
9480 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
9481 Stop means reenter debugger if this signal happens (implies print).\n\
9482 Print means print a message if this signal happens.\n\
9483 Pass means let program see this signal; otherwise program doesn't know.\n\
9484 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
9485 Pass and Stop may be combined.\n\
9487 Multiple signals may be specified. Signal numbers and signal names\n\
9488 may be interspersed with actions, with the actions being performed for\n\
9489 all signals cumulatively specified."));
9490 set_cmd_completer (c
, handle_completer
);
9493 stop_command
= add_cmd ("stop", class_obscure
,
9494 not_just_help_class_command
, _("\
9495 There is no `stop' command, but you can set a hook on `stop'.\n\
9496 This allows you to set a list of commands to be run each time execution\n\
9497 of the program stops."), &cmdlist
);
9499 add_setshow_boolean_cmd
9500 ("infrun", class_maintenance
, &debug_infrun
,
9501 _("Set inferior debugging."),
9502 _("Show inferior debugging."),
9503 _("When non-zero, inferior specific debugging is enabled."),
9504 NULL
, show_debug_infrun
, &setdebuglist
, &showdebuglist
);
9506 add_setshow_boolean_cmd ("non-stop", no_class
,
9508 Set whether gdb controls the inferior in non-stop mode."), _("\
9509 Show whether gdb controls the inferior in non-stop mode."), _("\
9510 When debugging a multi-threaded program and this setting is\n\
9511 off (the default, also called all-stop mode), when one thread stops\n\
9512 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
9513 all other threads in the program while you interact with the thread of\n\
9514 interest. When you continue or step a thread, you can allow the other\n\
9515 threads to run, or have them remain stopped, but while you inspect any\n\
9516 thread's state, all threads stop.\n\
9518 In non-stop mode, when one thread stops, other threads can continue\n\
9519 to run freely. You'll be able to step each thread independently,\n\
9520 leave it stopped or free to run as needed."),
9526 for (size_t i
= 0; i
< GDB_SIGNAL_LAST
; i
++)
9529 signal_print
[i
] = 1;
9530 signal_program
[i
] = 1;
9531 signal_catch
[i
] = 0;
9534 /* Signals caused by debugger's own actions should not be given to
9535 the program afterwards.
9537 Do not deliver GDB_SIGNAL_TRAP by default, except when the user
9538 explicitly specifies that it should be delivered to the target
9539 program. Typically, that would occur when a user is debugging a
9540 target monitor on a simulator: the target monitor sets a
9541 breakpoint; the simulator encounters this breakpoint and halts
9542 the simulation handing control to GDB; GDB, noting that the stop
9543 address doesn't map to any known breakpoint, returns control back
9544 to the simulator; the simulator then delivers the hardware
9545 equivalent of a GDB_SIGNAL_TRAP to the program being
9547 signal_program
[GDB_SIGNAL_TRAP
] = 0;
9548 signal_program
[GDB_SIGNAL_INT
] = 0;
9550 /* Signals that are not errors should not normally enter the debugger. */
9551 signal_stop
[GDB_SIGNAL_ALRM
] = 0;
9552 signal_print
[GDB_SIGNAL_ALRM
] = 0;
9553 signal_stop
[GDB_SIGNAL_VTALRM
] = 0;
9554 signal_print
[GDB_SIGNAL_VTALRM
] = 0;
9555 signal_stop
[GDB_SIGNAL_PROF
] = 0;
9556 signal_print
[GDB_SIGNAL_PROF
] = 0;
9557 signal_stop
[GDB_SIGNAL_CHLD
] = 0;
9558 signal_print
[GDB_SIGNAL_CHLD
] = 0;
9559 signal_stop
[GDB_SIGNAL_IO
] = 0;
9560 signal_print
[GDB_SIGNAL_IO
] = 0;
9561 signal_stop
[GDB_SIGNAL_POLL
] = 0;
9562 signal_print
[GDB_SIGNAL_POLL
] = 0;
9563 signal_stop
[GDB_SIGNAL_URG
] = 0;
9564 signal_print
[GDB_SIGNAL_URG
] = 0;
9565 signal_stop
[GDB_SIGNAL_WINCH
] = 0;
9566 signal_print
[GDB_SIGNAL_WINCH
] = 0;
9567 signal_stop
[GDB_SIGNAL_PRIO
] = 0;
9568 signal_print
[GDB_SIGNAL_PRIO
] = 0;
9570 /* These signals are used internally by user-level thread
9571 implementations. (See signal(5) on Solaris.) Like the above
9572 signals, a healthy program receives and handles them as part of
9573 its normal operation. */
9574 signal_stop
[GDB_SIGNAL_LWP
] = 0;
9575 signal_print
[GDB_SIGNAL_LWP
] = 0;
9576 signal_stop
[GDB_SIGNAL_WAITING
] = 0;
9577 signal_print
[GDB_SIGNAL_WAITING
] = 0;
9578 signal_stop
[GDB_SIGNAL_CANCEL
] = 0;
9579 signal_print
[GDB_SIGNAL_CANCEL
] = 0;
9580 signal_stop
[GDB_SIGNAL_LIBRT
] = 0;
9581 signal_print
[GDB_SIGNAL_LIBRT
] = 0;
9583 /* Update cached state. */
9584 signal_cache_update (-1);
9586 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support
,
9587 &stop_on_solib_events
, _("\
9588 Set stopping for shared library events."), _("\
9589 Show stopping for shared library events."), _("\
9590 If nonzero, gdb will give control to the user when the dynamic linker\n\
9591 notifies gdb of shared library events. The most common event of interest\n\
9592 to the user would be loading/unloading of a new library."),
9593 set_stop_on_solib_events
,
9594 show_stop_on_solib_events
,
9595 &setlist
, &showlist
);
9597 add_setshow_enum_cmd ("follow-fork-mode", class_run
,
9598 follow_fork_mode_kind_names
,
9599 &follow_fork_mode_string
, _("\
9600 Set debugger response to a program call of fork or vfork."), _("\
9601 Show debugger response to a program call of fork or vfork."), _("\
9602 A fork or vfork creates a new process. follow-fork-mode can be:\n\
9603 parent - the original process is debugged after a fork\n\
9604 child - the new process is debugged after a fork\n\
9605 The unfollowed process will continue to run.\n\
9606 By default, the debugger will follow the parent process."),
9608 show_follow_fork_mode_string
,
9609 &setlist
, &showlist
);
9611 add_setshow_enum_cmd ("follow-exec-mode", class_run
,
9612 follow_exec_mode_names
,
9613 &follow_exec_mode_string
, _("\
9614 Set debugger response to a program call of exec."), _("\
9615 Show debugger response to a program call of exec."), _("\
9616 An exec call replaces the program image of a process.\n\
9618 follow-exec-mode can be:\n\
9620 new - the debugger creates a new inferior and rebinds the process\n\
9621 to this new inferior. The program the process was running before\n\
9622 the exec call can be restarted afterwards by restarting the original\n\
9625 same - the debugger keeps the process bound to the same inferior.\n\
9626 The new executable image replaces the previous executable loaded in\n\
9627 the inferior. Restarting the inferior after the exec call restarts\n\
9628 the executable the process was running after the exec call.\n\
9630 By default, the debugger will use the same inferior."),
9632 show_follow_exec_mode_string
,
9633 &setlist
, &showlist
);
9635 add_setshow_enum_cmd ("scheduler-locking", class_run
,
9636 scheduler_enums
, &scheduler_mode
, _("\
9637 Set mode for locking scheduler during execution."), _("\
9638 Show mode for locking scheduler during execution."), _("\
9639 off == no locking (threads may preempt at any time)\n\
9640 on == full locking (no thread except the current thread may run)\n\
9641 This applies to both normal execution and replay mode.\n\
9642 step == scheduler locked during stepping commands (step, next, stepi, nexti).\n\
9643 In this mode, other threads may run during other commands.\n\
9644 This applies to both normal execution and replay mode.\n\
9645 replay == scheduler locked in replay mode and unlocked during normal execution."),
9646 set_schedlock_func
, /* traps on target vector */
9647 show_scheduler_mode
,
9648 &setlist
, &showlist
);
9650 add_setshow_boolean_cmd ("schedule-multiple", class_run
, &sched_multi
, _("\
9651 Set mode for resuming threads of all processes."), _("\
9652 Show mode for resuming threads of all processes."), _("\
9653 When on, execution commands (such as 'continue' or 'next') resume all\n\
9654 threads of all processes. When off (which is the default), execution\n\
9655 commands only resume the threads of the current process. The set of\n\
9656 threads that are resumed is further refined by the scheduler-locking\n\
9657 mode (see help set scheduler-locking)."),
9659 show_schedule_multiple
,
9660 &setlist
, &showlist
);
9662 add_setshow_boolean_cmd ("step-mode", class_run
, &step_stop_if_no_debug
, _("\
9663 Set mode of the step operation."), _("\
9664 Show mode of the step operation."), _("\
9665 When set, doing a step over a function without debug line information\n\
9666 will stop at the first instruction of that function. Otherwise, the\n\
9667 function is skipped and the step command stops at a different source line."),
9669 show_step_stop_if_no_debug
,
9670 &setlist
, &showlist
);
9672 add_setshow_auto_boolean_cmd ("displaced-stepping", class_run
,
9673 &can_use_displaced_stepping
, _("\
9674 Set debugger's willingness to use displaced stepping."), _("\
9675 Show debugger's willingness to use displaced stepping."), _("\
9676 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
9677 supported by the target architecture. If off, gdb will not use displaced\n\
9678 stepping to step over breakpoints, even if such is supported by the target\n\
9679 architecture. If auto (which is the default), gdb will use displaced stepping\n\
9680 if the target architecture supports it and non-stop mode is active, but will not\n\
9681 use it in all-stop mode (see help set non-stop)."),
9683 show_can_use_displaced_stepping
,
9684 &setlist
, &showlist
);
9686 add_setshow_enum_cmd ("exec-direction", class_run
, exec_direction_names
,
9687 &exec_direction
, _("Set direction of execution.\n\
9688 Options are 'forward' or 'reverse'."),
9689 _("Show direction of execution (forward/reverse)."),
9690 _("Tells gdb whether to execute forward or backward."),
9691 set_exec_direction_func
, show_exec_direction_func
,
9692 &setlist
, &showlist
);
9694 /* Set/show detach-on-fork: user-settable mode. */
9696 add_setshow_boolean_cmd ("detach-on-fork", class_run
, &detach_fork
, _("\
9697 Set whether gdb will detach the child of a fork."), _("\
9698 Show whether gdb will detach the child of a fork."), _("\
9699 Tells gdb whether to detach the child of a fork."),
9700 NULL
, NULL
, &setlist
, &showlist
);
9702 /* Set/show disable address space randomization mode. */
9704 add_setshow_boolean_cmd ("disable-randomization", class_support
,
9705 &disable_randomization
, _("\
9706 Set disabling of debuggee's virtual address space randomization."), _("\
9707 Show disabling of debuggee's virtual address space randomization."), _("\
9708 When this mode is on (which is the default), randomization of the virtual\n\
9709 address space is disabled. Standalone programs run with the randomization\n\
9710 enabled by default on some platforms."),
9711 &set_disable_randomization
,
9712 &show_disable_randomization
,
9713 &setlist
, &showlist
);
9715 /* ptid initializations */
9716 inferior_ptid
= null_ptid
;
9717 target_last_wait_ptid
= minus_one_ptid
;
9719 gdb::observers::thread_ptid_changed
.attach (infrun_thread_ptid_changed
,
9721 gdb::observers::thread_stop_requested
.attach (infrun_thread_stop_requested
,
9723 gdb::observers::thread_exit
.attach (infrun_thread_thread_exit
, "infrun");
9724 gdb::observers::inferior_exit
.attach (infrun_inferior_exit
, "infrun");
9725 gdb::observers::inferior_execd
.attach (infrun_inferior_execd
, "infrun");
9727 /* Explicitly create without lookup, since that tries to create a
9728 value with a void typed value, and when we get here, gdbarch
9729 isn't initialized yet. At this point, we're quite sure there
9730 isn't another convenience variable of the same name. */
9731 create_internalvar_type_lazy ("_siginfo", &siginfo_funcs
, NULL
);
9733 add_setshow_boolean_cmd ("observer", no_class
,
9734 &observer_mode_1
, _("\
9735 Set whether gdb controls the inferior in observer mode."), _("\
9736 Show whether gdb controls the inferior in observer mode."), _("\
9737 In observer mode, GDB can get data from the inferior, but not\n\
9738 affect its execution. Registers and memory may not be changed,\n\
9739 breakpoints may not be set, and the program cannot be interrupted\n\
9747 selftests::register_test ("infrun_thread_ptid_changed",
9748 selftests::infrun_thread_ptid_changed
);