1 /* Target-struct-independent code to start (run) and stop an inferior
4 Copyright (C) 1986-2022 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
, CORE_ADDR pc
);
94 static void resume (gdb_signal sig
);
96 static void wait_for_inferior (inferior
*inf
);
98 static void restart_threads (struct thread_info
*event_thread
,
99 inferior
*inf
= nullptr);
101 static bool start_step_over (void);
103 /* Asynchronous signal handler registered as event loop source for
104 when we have pending events ready to be passed to the core. */
105 static struct async_event_handler
*infrun_async_inferior_event_token
;
107 /* Stores whether infrun_async was previously enabled or disabled.
108 Starts off as -1, indicating "never enabled/disabled". */
109 static int infrun_is_async
= -1;
114 infrun_async (int enable
)
116 if (infrun_is_async
!= enable
)
118 infrun_is_async
= enable
;
120 infrun_debug_printf ("enable=%d", enable
);
123 mark_async_event_handler (infrun_async_inferior_event_token
);
125 clear_async_event_handler (infrun_async_inferior_event_token
);
132 mark_infrun_async_event_handler (void)
134 mark_async_event_handler (infrun_async_inferior_event_token
);
137 /* When set, stop the 'step' command if we enter a function which has
138 no line number information. The normal behavior is that we step
139 over such function. */
140 bool step_stop_if_no_debug
= false;
142 show_step_stop_if_no_debug (struct ui_file
*file
, int from_tty
,
143 struct cmd_list_element
*c
, const char *value
)
145 fprintf_filtered (file
, _("Mode of the step operation is %s.\n"), value
);
148 /* proceed and normal_stop use this to notify the user when the
149 inferior stopped in a different thread than it had been running
152 static ptid_t previous_inferior_ptid
;
154 /* If set (default for legacy reasons), when following a fork, GDB
155 will detach from one of the fork branches, child or parent.
156 Exactly which branch is detached depends on 'set follow-fork-mode'
159 static bool detach_fork
= true;
161 bool debug_infrun
= false;
163 show_debug_infrun (struct ui_file
*file
, int from_tty
,
164 struct cmd_list_element
*c
, const char *value
)
166 fprintf_filtered (file
, _("Inferior debugging is %s.\n"), value
);
169 /* Support for disabling address space randomization. */
171 bool disable_randomization
= true;
174 show_disable_randomization (struct ui_file
*file
, int from_tty
,
175 struct cmd_list_element
*c
, const char *value
)
177 if (target_supports_disable_randomization ())
178 fprintf_filtered (file
,
179 _("Disabling randomization of debuggee's "
180 "virtual address space is %s.\n"),
183 fputs_filtered (_("Disabling randomization of debuggee's "
184 "virtual address space is unsupported on\n"
185 "this platform.\n"), file
);
189 set_disable_randomization (const char *args
, int from_tty
,
190 struct cmd_list_element
*c
)
192 if (!target_supports_disable_randomization ())
193 error (_("Disabling randomization of debuggee's "
194 "virtual address space is unsupported on\n"
198 /* User interface for non-stop mode. */
200 bool non_stop
= false;
201 static bool non_stop_1
= false;
204 set_non_stop (const char *args
, int from_tty
,
205 struct cmd_list_element
*c
)
207 if (target_has_execution ())
209 non_stop_1
= non_stop
;
210 error (_("Cannot change this setting while the inferior is running."));
213 non_stop
= non_stop_1
;
217 show_non_stop (struct ui_file
*file
, int from_tty
,
218 struct cmd_list_element
*c
, const char *value
)
220 fprintf_filtered (file
,
221 _("Controlling the inferior in non-stop mode is %s.\n"),
225 /* "Observer mode" is somewhat like a more extreme version of
226 non-stop, in which all GDB operations that might affect the
227 target's execution have been disabled. */
229 static bool observer_mode
= false;
230 static bool observer_mode_1
= false;
233 set_observer_mode (const char *args
, int from_tty
,
234 struct cmd_list_element
*c
)
236 if (target_has_execution ())
238 observer_mode_1
= observer_mode
;
239 error (_("Cannot change this setting while the inferior is running."));
242 observer_mode
= observer_mode_1
;
244 may_write_registers
= !observer_mode
;
245 may_write_memory
= !observer_mode
;
246 may_insert_breakpoints
= !observer_mode
;
247 may_insert_tracepoints
= !observer_mode
;
248 /* We can insert fast tracepoints in or out of observer mode,
249 but enable them if we're going into this mode. */
251 may_insert_fast_tracepoints
= true;
252 may_stop
= !observer_mode
;
253 update_target_permissions ();
255 /* Going *into* observer mode we must force non-stop, then
256 going out we leave it that way. */
259 pagination_enabled
= 0;
260 non_stop
= non_stop_1
= true;
264 printf_filtered (_("Observer mode is now %s.\n"),
265 (observer_mode
? "on" : "off"));
269 show_observer_mode (struct ui_file
*file
, int from_tty
,
270 struct cmd_list_element
*c
, const char *value
)
272 fprintf_filtered (file
, _("Observer mode is %s.\n"), value
);
275 /* This updates the value of observer mode based on changes in
276 permissions. Note that we are deliberately ignoring the values of
277 may-write-registers and may-write-memory, since the user may have
278 reason to enable these during a session, for instance to turn on a
279 debugging-related global. */
282 update_observer_mode (void)
284 bool newval
= (!may_insert_breakpoints
285 && !may_insert_tracepoints
286 && may_insert_fast_tracepoints
290 /* Let the user know if things change. */
291 if (newval
!= observer_mode
)
292 printf_filtered (_("Observer mode is now %s.\n"),
293 (newval
? "on" : "off"));
295 observer_mode
= observer_mode_1
= newval
;
298 /* Tables of how to react to signals; the user sets them. */
300 static unsigned char signal_stop
[GDB_SIGNAL_LAST
];
301 static unsigned char signal_print
[GDB_SIGNAL_LAST
];
302 static unsigned char signal_program
[GDB_SIGNAL_LAST
];
304 /* Table of signals that are registered with "catch signal". A
305 non-zero entry indicates that the signal is caught by some "catch
307 static unsigned char signal_catch
[GDB_SIGNAL_LAST
];
309 /* Table of signals that the target may silently handle.
310 This is automatically determined from the flags above,
311 and simply cached here. */
312 static unsigned char signal_pass
[GDB_SIGNAL_LAST
];
314 #define SET_SIGS(nsigs,sigs,flags) \
316 int signum = (nsigs); \
317 while (signum-- > 0) \
318 if ((sigs)[signum]) \
319 (flags)[signum] = 1; \
322 #define UNSET_SIGS(nsigs,sigs,flags) \
324 int signum = (nsigs); \
325 while (signum-- > 0) \
326 if ((sigs)[signum]) \
327 (flags)[signum] = 0; \
330 /* Update the target's copy of SIGNAL_PROGRAM. The sole purpose of
331 this function is to avoid exporting `signal_program'. */
334 update_signals_program_target (void)
336 target_program_signals (signal_program
);
339 /* Value to pass to target_resume() to cause all threads to resume. */
341 #define RESUME_ALL minus_one_ptid
343 /* Command list pointer for the "stop" placeholder. */
345 static struct cmd_list_element
*stop_command
;
347 /* Nonzero if we want to give control to the user when we're notified
348 of shared library events by the dynamic linker. */
349 int stop_on_solib_events
;
351 /* Enable or disable optional shared library event breakpoints
352 as appropriate when the above flag is changed. */
355 set_stop_on_solib_events (const char *args
,
356 int from_tty
, struct cmd_list_element
*c
)
358 update_solib_breakpoints ();
362 show_stop_on_solib_events (struct ui_file
*file
, int from_tty
,
363 struct cmd_list_element
*c
, const char *value
)
365 fprintf_filtered (file
, _("Stopping for shared library events is %s.\n"),
369 /* True after stop if current stack frame should be printed. */
371 static bool stop_print_frame
;
373 /* This is a cached copy of the target/ptid/waitstatus of the last
374 event returned by target_wait()/deprecated_target_wait_hook().
375 This information is returned by get_last_target_status(). */
376 static process_stratum_target
*target_last_proc_target
;
377 static ptid_t target_last_wait_ptid
;
378 static struct target_waitstatus target_last_waitstatus
;
380 void init_thread_stepping_state (struct thread_info
*tss
);
382 static const char follow_fork_mode_child
[] = "child";
383 static const char follow_fork_mode_parent
[] = "parent";
385 static const char *const follow_fork_mode_kind_names
[] = {
386 follow_fork_mode_child
,
387 follow_fork_mode_parent
,
391 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
393 show_follow_fork_mode_string (struct ui_file
*file
, int from_tty
,
394 struct cmd_list_element
*c
, const char *value
)
396 fprintf_filtered (file
,
397 _("Debugger response to a program "
398 "call of fork or vfork is \"%s\".\n"),
403 /* Handle changes to the inferior list based on the type of fork,
404 which process is being followed, and whether the other process
405 should be detached. On entry inferior_ptid must be the ptid of
406 the fork parent. At return inferior_ptid is the ptid of the
407 followed inferior. */
410 follow_fork_inferior (bool follow_child
, bool detach_fork
)
413 ptid_t parent_ptid
, child_ptid
;
415 has_vforked
= (inferior_thread ()->pending_follow
.kind
416 == TARGET_WAITKIND_VFORKED
);
417 parent_ptid
= inferior_ptid
;
418 child_ptid
= inferior_thread ()->pending_follow
.value
.related_pid
;
421 && !non_stop
/* Non-stop always resumes both branches. */
422 && current_ui
->prompt_state
== PROMPT_BLOCKED
423 && !(follow_child
|| detach_fork
|| sched_multi
))
425 /* The parent stays blocked inside the vfork syscall until the
426 child execs or exits. If we don't let the child run, then
427 the parent stays blocked. If we're telling the parent to run
428 in the foreground, the user will not be able to ctrl-c to get
429 back the terminal, effectively hanging the debug session. */
430 fprintf_filtered (gdb_stderr
, _("\
431 Can not resume the parent process over vfork in the foreground while\n\
432 holding the child stopped. Try \"set detach-on-fork\" or \
433 \"set schedule-multiple\".\n"));
437 inferior
*parent_inf
= current_inferior ();
438 gdb_assert (parent_inf
->thread_waiting_for_vfork_done
== nullptr);
442 /* Detach new forked process? */
445 /* Before detaching from the child, remove all breakpoints
446 from it. If we forked, then this has already been taken
447 care of by infrun.c. If we vforked however, any
448 breakpoint inserted in the parent is visible in the
449 child, even those added while stopped in a vfork
450 catchpoint. This will remove the breakpoints from the
451 parent also, but they'll be reinserted below. */
454 /* Keep breakpoints list in sync. */
455 remove_breakpoints_inf (current_inferior ());
458 if (print_inferior_events
)
460 /* Ensure that we have a process ptid. */
461 ptid_t process_ptid
= ptid_t (child_ptid
.pid ());
463 target_terminal::ours_for_output ();
464 fprintf_filtered (gdb_stdlog
,
465 _("[Detaching after %s from child %s]\n"),
466 has_vforked
? "vfork" : "fork",
467 target_pid_to_str (process_ptid
).c_str ());
472 struct inferior
*parent_inf
, *child_inf
;
474 /* Add process to GDB's tables. */
475 child_inf
= add_inferior (child_ptid
.pid ());
477 parent_inf
= current_inferior ();
478 child_inf
->attach_flag
= parent_inf
->attach_flag
;
479 copy_terminal_info (child_inf
, parent_inf
);
480 child_inf
->gdbarch
= parent_inf
->gdbarch
;
481 copy_inferior_target_desc_info (child_inf
, parent_inf
);
483 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
485 set_current_inferior (child_inf
);
486 switch_to_no_thread ();
487 child_inf
->symfile_flags
= SYMFILE_NO_READ
;
488 child_inf
->push_target (parent_inf
->process_target ());
489 thread_info
*child_thr
490 = add_thread_silent (child_inf
->process_target (), child_ptid
);
492 /* If this is a vfork child, then the address-space is
493 shared with the parent. */
496 child_inf
->pspace
= parent_inf
->pspace
;
497 child_inf
->aspace
= parent_inf
->aspace
;
501 /* The parent will be frozen until the child is done
502 with the shared region. Keep track of the
504 child_inf
->vfork_parent
= parent_inf
;
505 child_inf
->pending_detach
= 0;
506 parent_inf
->vfork_child
= child_inf
;
507 parent_inf
->pending_detach
= 0;
509 /* Now that the inferiors and program spaces are all
510 wired up, we can switch to the child thread (which
511 switches inferior and program space too). */
512 switch_to_thread (child_thr
);
516 child_inf
->aspace
= new_address_space ();
517 child_inf
->pspace
= new program_space (child_inf
->aspace
);
518 child_inf
->removable
= 1;
519 set_current_program_space (child_inf
->pspace
);
520 clone_program_space (child_inf
->pspace
, parent_inf
->pspace
);
522 /* solib_create_inferior_hook relies on the current
524 switch_to_thread (child_thr
);
526 /* Let the shared library layer (e.g., solib-svr4) learn
527 about this new process, relocate the cloned exec, pull
528 in shared libraries, and install the solib event
529 breakpoint. If a "cloned-VM" event was propagated
530 better throughout the core, this wouldn't be
532 scoped_restore restore_in_initial_library_scan
533 = make_scoped_restore (&child_inf
->in_initial_library_scan
,
535 solib_create_inferior_hook (0);
541 struct inferior
*parent_inf
;
543 parent_inf
= current_inferior ();
545 /* If we detached from the child, then we have to be careful
546 to not insert breakpoints in the parent until the child
547 is done with the shared memory region. However, if we're
548 staying attached to the child, then we can and should
549 insert breakpoints, so that we can debug it. A
550 subsequent child exec or exit is enough to know when does
551 the child stops using the parent's address space. */
552 parent_inf
->thread_waiting_for_vfork_done
553 = detach_fork
? inferior_thread () : nullptr;
554 parent_inf
->pspace
->breakpoints_not_allowed
= detach_fork
;
559 /* Follow the child. */
560 struct inferior
*parent_inf
, *child_inf
;
561 struct program_space
*parent_pspace
;
563 if (print_inferior_events
)
565 std::string parent_pid
= target_pid_to_str (parent_ptid
);
566 std::string child_pid
= target_pid_to_str (child_ptid
);
568 target_terminal::ours_for_output ();
569 fprintf_filtered (gdb_stdlog
,
570 _("[Attaching after %s %s to child %s]\n"),
572 has_vforked
? "vfork" : "fork",
576 /* Add the new inferior first, so that the target_detach below
577 doesn't unpush the target. */
579 child_inf
= add_inferior (child_ptid
.pid ());
581 parent_inf
= current_inferior ();
582 child_inf
->attach_flag
= parent_inf
->attach_flag
;
583 copy_terminal_info (child_inf
, parent_inf
);
584 child_inf
->gdbarch
= parent_inf
->gdbarch
;
585 copy_inferior_target_desc_info (child_inf
, parent_inf
);
587 parent_pspace
= parent_inf
->pspace
;
589 process_stratum_target
*target
= parent_inf
->process_target ();
592 /* Hold a strong reference to the target while (maybe)
593 detaching the parent. Otherwise detaching could close the
595 auto target_ref
= target_ops_ref::new_reference (target
);
597 /* If we're vforking, we want to hold on to the parent until
598 the child exits or execs. At child exec or exit time we
599 can remove the old breakpoints from the parent and detach
600 or resume debugging it. Otherwise, detach the parent now;
601 we'll want to reuse it's program/address spaces, but we
602 can't set them to the child before removing breakpoints
603 from the parent, otherwise, the breakpoints module could
604 decide to remove breakpoints from the wrong process (since
605 they'd be assigned to the same address space). */
609 gdb_assert (child_inf
->vfork_parent
== NULL
);
610 gdb_assert (parent_inf
->vfork_child
== NULL
);
611 child_inf
->vfork_parent
= parent_inf
;
612 child_inf
->pending_detach
= 0;
613 parent_inf
->vfork_child
= child_inf
;
614 parent_inf
->pending_detach
= detach_fork
;
616 else if (detach_fork
)
618 if (print_inferior_events
)
620 /* Ensure that we have a process ptid. */
621 ptid_t process_ptid
= ptid_t (parent_ptid
.pid ());
623 target_terminal::ours_for_output ();
624 fprintf_filtered (gdb_stdlog
,
625 _("[Detaching after fork from "
627 target_pid_to_str (process_ptid
).c_str ());
630 target_detach (parent_inf
, 0);
634 /* Note that the detach above makes PARENT_INF dangling. */
636 /* Add the child thread to the appropriate lists, and switch
637 to this new thread, before cloning the program space, and
638 informing the solib layer about this new process. */
640 set_current_inferior (child_inf
);
641 child_inf
->push_target (target
);
644 thread_info
*child_thr
= add_thread_silent (target
, child_ptid
);
646 /* If this is a vfork child, then the address-space is shared
647 with the parent. If we detached from the parent, then we can
648 reuse the parent's program/address spaces. */
649 if (has_vforked
|| detach_fork
)
651 child_inf
->pspace
= parent_pspace
;
652 child_inf
->aspace
= child_inf
->pspace
->aspace
;
658 child_inf
->aspace
= new_address_space ();
659 child_inf
->pspace
= new program_space (child_inf
->aspace
);
660 child_inf
->removable
= 1;
661 child_inf
->symfile_flags
= SYMFILE_NO_READ
;
662 set_current_program_space (child_inf
->pspace
);
663 clone_program_space (child_inf
->pspace
, parent_pspace
);
665 /* Let the shared library layer (e.g., solib-svr4) learn
666 about this new process, relocate the cloned exec, pull in
667 shared libraries, and install the solib event breakpoint.
668 If a "cloned-VM" event was propagated better throughout
669 the core, this wouldn't be required. */
670 scoped_restore restore_in_initial_library_scan
671 = make_scoped_restore (&child_inf
->in_initial_library_scan
, true);
672 solib_create_inferior_hook (0);
675 switch_to_thread (child_thr
);
678 target_follow_fork (follow_child
, detach_fork
);
683 /* Tell the target to follow the fork we're stopped at. Returns true
684 if the inferior should be resumed; false, if the target for some
685 reason decided it's best not to resume. */
690 bool follow_child
= (follow_fork_mode_string
== follow_fork_mode_child
);
691 bool should_resume
= true;
692 struct thread_info
*tp
;
694 /* Copy user stepping state to the new inferior thread. FIXME: the
695 followed fork child thread should have a copy of most of the
696 parent thread structure's run control related fields, not just these.
697 Initialized to avoid "may be used uninitialized" warnings from gcc. */
698 struct breakpoint
*step_resume_breakpoint
= NULL
;
699 struct breakpoint
*exception_resume_breakpoint
= NULL
;
700 CORE_ADDR step_range_start
= 0;
701 CORE_ADDR step_range_end
= 0;
702 int current_line
= 0;
703 symtab
*current_symtab
= NULL
;
704 struct frame_id step_frame_id
= { 0 };
705 struct thread_fsm
*thread_fsm
= NULL
;
709 process_stratum_target
*wait_target
;
711 struct target_waitstatus wait_status
;
713 /* Get the last target status returned by target_wait(). */
714 get_last_target_status (&wait_target
, &wait_ptid
, &wait_status
);
716 /* If not stopped at a fork event, then there's nothing else to
718 if (wait_status
.kind
!= TARGET_WAITKIND_FORKED
719 && wait_status
.kind
!= TARGET_WAITKIND_VFORKED
)
722 /* Check if we switched over from WAIT_PTID, since the event was
724 if (wait_ptid
!= minus_one_ptid
725 && (current_inferior ()->process_target () != wait_target
726 || inferior_ptid
!= wait_ptid
))
728 /* We did. Switch back to WAIT_PTID thread, to tell the
729 target to follow it (in either direction). We'll
730 afterwards refuse to resume, and inform the user what
732 thread_info
*wait_thread
= find_thread_ptid (wait_target
, wait_ptid
);
733 switch_to_thread (wait_thread
);
734 should_resume
= false;
738 tp
= inferior_thread ();
740 /* If there were any forks/vforks that were caught and are now to be
741 followed, then do so now. */
742 switch (tp
->pending_follow
.kind
)
744 case TARGET_WAITKIND_FORKED
:
745 case TARGET_WAITKIND_VFORKED
:
747 ptid_t parent
, child
;
749 /* If the user did a next/step, etc, over a fork call,
750 preserve the stepping state in the fork child. */
751 if (follow_child
&& should_resume
)
753 step_resume_breakpoint
= clone_momentary_breakpoint
754 (tp
->control
.step_resume_breakpoint
);
755 step_range_start
= tp
->control
.step_range_start
;
756 step_range_end
= tp
->control
.step_range_end
;
757 current_line
= tp
->current_line
;
758 current_symtab
= tp
->current_symtab
;
759 step_frame_id
= tp
->control
.step_frame_id
;
760 exception_resume_breakpoint
761 = clone_momentary_breakpoint (tp
->control
.exception_resume_breakpoint
);
762 thread_fsm
= tp
->thread_fsm
;
764 /* For now, delete the parent's sr breakpoint, otherwise,
765 parent/child sr breakpoints are considered duplicates,
766 and the child version will not be installed. Remove
767 this when the breakpoints module becomes aware of
768 inferiors and address spaces. */
769 delete_step_resume_breakpoint (tp
);
770 tp
->control
.step_range_start
= 0;
771 tp
->control
.step_range_end
= 0;
772 tp
->control
.step_frame_id
= null_frame_id
;
773 delete_exception_resume_breakpoint (tp
);
774 tp
->thread_fsm
= NULL
;
777 parent
= inferior_ptid
;
778 child
= tp
->pending_follow
.value
.related_pid
;
780 /* If handling a vfork, stop all the inferior's threads, they will be
781 restarted when the vfork shared region is complete. */
782 if (tp
->pending_follow
.kind
== TARGET_WAITKIND_VFORKED
783 && target_is_non_stop_p ())
784 stop_all_threads ("handling vfork", tp
->inf
);
786 process_stratum_target
*parent_targ
= tp
->inf
->process_target ();
787 /* Set up inferior(s) as specified by the caller, and tell the
788 target to do whatever is necessary to follow either parent
790 if (follow_fork_inferior (follow_child
, detach_fork
))
792 /* Target refused to follow, or there's some other reason
793 we shouldn't resume. */
798 /* This pending follow fork event is now handled, one way
799 or another. The previous selected thread may be gone
800 from the lists by now, but if it is still around, need
801 to clear the pending follow request. */
802 tp
= find_thread_ptid (parent_targ
, parent
);
804 tp
->pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
806 /* This makes sure we don't try to apply the "Switched
807 over from WAIT_PID" logic above. */
808 nullify_last_target_wait_ptid ();
810 /* If we followed the child, switch to it... */
813 thread_info
*child_thr
= find_thread_ptid (parent_targ
, child
);
814 switch_to_thread (child_thr
);
816 /* ... and preserve the stepping state, in case the
817 user was stepping over the fork call. */
820 tp
= inferior_thread ();
821 tp
->control
.step_resume_breakpoint
822 = step_resume_breakpoint
;
823 tp
->control
.step_range_start
= step_range_start
;
824 tp
->control
.step_range_end
= step_range_end
;
825 tp
->current_line
= current_line
;
826 tp
->current_symtab
= current_symtab
;
827 tp
->control
.step_frame_id
= step_frame_id
;
828 tp
->control
.exception_resume_breakpoint
829 = exception_resume_breakpoint
;
830 tp
->thread_fsm
= thread_fsm
;
834 /* If we get here, it was because we're trying to
835 resume from a fork catchpoint, but, the user
836 has switched threads away from the thread that
837 forked. In that case, the resume command
838 issued is most likely not applicable to the
839 child, so just warn, and refuse to resume. */
840 warning (_("Not resuming: switched threads "
841 "before following fork child."));
844 /* Reset breakpoints in the child as appropriate. */
845 follow_inferior_reset_breakpoints ();
850 case TARGET_WAITKIND_SPURIOUS
:
851 /* Nothing to follow. */
854 internal_error (__FILE__
, __LINE__
,
855 "Unexpected pending_follow.kind %d\n",
856 tp
->pending_follow
.kind
);
860 return should_resume
;
864 follow_inferior_reset_breakpoints (void)
866 struct thread_info
*tp
= inferior_thread ();
868 /* Was there a step_resume breakpoint? (There was if the user
869 did a "next" at the fork() call.) If so, explicitly reset its
870 thread number. Cloned step_resume breakpoints are disabled on
871 creation, so enable it here now that it is associated with the
874 step_resumes are a form of bp that are made to be per-thread.
875 Since we created the step_resume bp when the parent process
876 was being debugged, and now are switching to the child process,
877 from the breakpoint package's viewpoint, that's a switch of
878 "threads". We must update the bp's notion of which thread
879 it is for, or it'll be ignored when it triggers. */
881 if (tp
->control
.step_resume_breakpoint
)
883 breakpoint_re_set_thread (tp
->control
.step_resume_breakpoint
);
884 tp
->control
.step_resume_breakpoint
->loc
->enabled
= 1;
887 /* Treat exception_resume breakpoints like step_resume breakpoints. */
888 if (tp
->control
.exception_resume_breakpoint
)
890 breakpoint_re_set_thread (tp
->control
.exception_resume_breakpoint
);
891 tp
->control
.exception_resume_breakpoint
->loc
->enabled
= 1;
894 /* Reinsert all breakpoints in the child. The user may have set
895 breakpoints after catching the fork, in which case those
896 were never set in the child, but only in the parent. This makes
897 sure the inserted breakpoints match the breakpoint list. */
899 breakpoint_re_set ();
900 insert_breakpoints ();
903 /* The child has exited or execed: resume threads of the parent the
904 user wanted to be executing. */
907 proceed_after_vfork_done (struct thread_info
*thread
,
910 int pid
= * (int *) arg
;
912 if (thread
->ptid
.pid () == pid
913 && thread
->state
== THREAD_RUNNING
914 && !thread
->executing
915 && !thread
->stop_requested
916 && thread
->suspend
.stop_signal
== GDB_SIGNAL_0
)
918 infrun_debug_printf ("resuming vfork parent thread %s",
919 target_pid_to_str (thread
->ptid
).c_str ());
921 switch_to_thread (thread
);
922 clear_proceed_status (0);
923 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
929 /* Called whenever we notice an exec or exit event, to handle
930 detaching or resuming a vfork parent. */
933 handle_vfork_child_exec_or_exit (int exec
)
935 struct inferior
*inf
= current_inferior ();
937 if (inf
->vfork_parent
)
939 int resume_parent
= -1;
941 /* This exec or exit marks the end of the shared memory region
942 between the parent and the child. Break the bonds. */
943 inferior
*vfork_parent
= inf
->vfork_parent
;
944 inf
->vfork_parent
->vfork_child
= NULL
;
945 inf
->vfork_parent
= NULL
;
947 /* If the user wanted to detach from the parent, now is the
949 if (vfork_parent
->pending_detach
)
951 struct program_space
*pspace
;
952 struct address_space
*aspace
;
954 /* follow-fork child, detach-on-fork on. */
956 vfork_parent
->pending_detach
= 0;
958 scoped_restore_current_pspace_and_thread restore_thread
;
960 /* We're letting loose of the parent. */
961 thread_info
*tp
= any_live_thread_of_inferior (vfork_parent
);
962 switch_to_thread (tp
);
964 /* We're about to detach from the parent, which implicitly
965 removes breakpoints from its address space. There's a
966 catch here: we want to reuse the spaces for the child,
967 but, parent/child are still sharing the pspace at this
968 point, although the exec in reality makes the kernel give
969 the child a fresh set of new pages. The problem here is
970 that the breakpoints module being unaware of this, would
971 likely chose the child process to write to the parent
972 address space. Swapping the child temporarily away from
973 the spaces has the desired effect. Yes, this is "sort
976 pspace
= inf
->pspace
;
977 aspace
= inf
->aspace
;
981 if (print_inferior_events
)
984 = target_pid_to_str (ptid_t (vfork_parent
->pid
));
986 target_terminal::ours_for_output ();
990 fprintf_filtered (gdb_stdlog
,
991 _("[Detaching vfork parent %s "
992 "after child exec]\n"), pidstr
.c_str ());
996 fprintf_filtered (gdb_stdlog
,
997 _("[Detaching vfork parent %s "
998 "after child exit]\n"), pidstr
.c_str ());
1002 target_detach (vfork_parent
, 0);
1005 inf
->pspace
= pspace
;
1006 inf
->aspace
= aspace
;
1010 /* We're staying attached to the parent, so, really give the
1011 child a new address space. */
1012 inf
->pspace
= new program_space (maybe_new_address_space ());
1013 inf
->aspace
= inf
->pspace
->aspace
;
1015 set_current_program_space (inf
->pspace
);
1017 resume_parent
= vfork_parent
->pid
;
1021 /* If this is a vfork child exiting, then the pspace and
1022 aspaces were shared with the parent. Since we're
1023 reporting the process exit, we'll be mourning all that is
1024 found in the address space, and switching to null_ptid,
1025 preparing to start a new inferior. But, since we don't
1026 want to clobber the parent's address/program spaces, we
1027 go ahead and create a new one for this exiting
1030 /* Switch to no-thread while running clone_program_space, so
1031 that clone_program_space doesn't want to read the
1032 selected frame of a dead process. */
1033 scoped_restore_current_thread restore_thread
;
1034 switch_to_no_thread ();
1036 inf
->pspace
= new program_space (maybe_new_address_space ());
1037 inf
->aspace
= inf
->pspace
->aspace
;
1038 set_current_program_space (inf
->pspace
);
1040 inf
->symfile_flags
= SYMFILE_NO_READ
;
1041 clone_program_space (inf
->pspace
, vfork_parent
->pspace
);
1043 resume_parent
= vfork_parent
->pid
;
1046 gdb_assert (current_program_space
== inf
->pspace
);
1048 if (non_stop
&& resume_parent
!= -1)
1050 /* If the user wanted the parent to be running, let it go
1052 scoped_restore_current_thread restore_thread
;
1054 infrun_debug_printf ("resuming vfork parent process %d",
1057 iterate_over_threads (proceed_after_vfork_done
, &resume_parent
);
1062 /* Handle TARGET_WAITKIND_VFORK_DONE. */
1065 handle_vfork_done (thread_info
*event_thread
)
1067 /* We only care about this event if inferior::thread_waiting_for_vfork_done is
1068 set, that is if we are waiting for a vfork child not under our control
1069 (because we detached it) to exec or exit.
1071 If an inferior has vforked and we are debugging the child, we don't use
1072 the vfork-done event to get notified about the end of the shared address
1073 space window). We rely instead on the child's exec or exit event, and the
1074 inferior::vfork_{parent,child} fields are used instead. See
1075 handle_vfork_child_exec_or_exit for that. */
1076 if (event_thread
->inf
->thread_waiting_for_vfork_done
== nullptr)
1078 infrun_debug_printf ("not waiting for a vfork-done event");
1082 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
1084 /* We stopped all threads (other than the vforking thread) of the inferior in
1085 follow_fork and kept them stopped until now. It should therefore not be
1086 possible for another thread to have reported a vfork during that window.
1087 If THREAD_WAITING_FOR_VFORK_DONE is set, it has to be the same thread whose
1088 vfork-done we are handling right now. */
1089 gdb_assert (event_thread
->inf
->thread_waiting_for_vfork_done
== event_thread
);
1091 event_thread
->inf
->thread_waiting_for_vfork_done
= nullptr;
1092 event_thread
->inf
->pspace
->breakpoints_not_allowed
= 0;
1094 /* On non-stop targets, we stopped all the inferior's threads in follow_fork,
1095 resume them now. On all-stop targets, everything that needs to be resumed
1096 will be when we resume the event thread. */
1097 if (target_is_non_stop_p ())
1099 /* restart_threads and start_step_over may change the current thread, make
1100 sure we leave the event thread as the current thread. */
1101 scoped_restore_current_thread restore_thread
;
1103 insert_breakpoints ();
1104 restart_threads (event_thread
, event_thread
->inf
);
1109 /* Enum strings for "set|show follow-exec-mode". */
1111 static const char follow_exec_mode_new
[] = "new";
1112 static const char follow_exec_mode_same
[] = "same";
1113 static const char *const follow_exec_mode_names
[] =
1115 follow_exec_mode_new
,
1116 follow_exec_mode_same
,
1120 static const char *follow_exec_mode_string
= follow_exec_mode_same
;
1122 show_follow_exec_mode_string (struct ui_file
*file
, int from_tty
,
1123 struct cmd_list_element
*c
, const char *value
)
1125 fprintf_filtered (file
, _("Follow exec mode is \"%s\".\n"), value
);
1128 /* EXEC_FILE_TARGET is assumed to be non-NULL. */
1131 follow_exec (ptid_t ptid
, const char *exec_file_target
)
1133 int pid
= ptid
.pid ();
1134 ptid_t process_ptid
;
1136 /* Switch terminal for any messages produced e.g. by
1137 breakpoint_re_set. */
1138 target_terminal::ours_for_output ();
1140 /* This is an exec event that we actually wish to pay attention to.
1141 Refresh our symbol table to the newly exec'd program, remove any
1142 momentary bp's, etc.
1144 If there are breakpoints, they aren't really inserted now,
1145 since the exec() transformed our inferior into a fresh set
1148 We want to preserve symbolic breakpoints on the list, since
1149 we have hopes that they can be reset after the new a.out's
1150 symbol table is read.
1152 However, any "raw" breakpoints must be removed from the list
1153 (e.g., the solib bp's), since their address is probably invalid
1156 And, we DON'T want to call delete_breakpoints() here, since
1157 that may write the bp's "shadow contents" (the instruction
1158 value that was overwritten with a TRAP instruction). Since
1159 we now have a new a.out, those shadow contents aren't valid. */
1161 mark_breakpoints_out ();
1163 /* The target reports the exec event to the main thread, even if
1164 some other thread does the exec, and even if the main thread was
1165 stopped or already gone. We may still have non-leader threads of
1166 the process on our list. E.g., on targets that don't have thread
1167 exit events (like remote); or on native Linux in non-stop mode if
1168 there were only two threads in the inferior and the non-leader
1169 one is the one that execs (and nothing forces an update of the
1170 thread list up to here). When debugging remotely, it's best to
1171 avoid extra traffic, when possible, so avoid syncing the thread
1172 list with the target, and instead go ahead and delete all threads
1173 of the process but one that reported the event. Note this must
1174 be done before calling update_breakpoints_after_exec, as
1175 otherwise clearing the threads' resources would reference stale
1176 thread breakpoints -- it may have been one of these threads that
1177 stepped across the exec. We could just clear their stepping
1178 states, but as long as we're iterating, might as well delete
1179 them. Deleting them now rather than at the next user-visible
1180 stop provides a nicer sequence of events for user and MI
1182 for (thread_info
*th
: all_threads_safe ())
1183 if (th
->ptid
.pid () == pid
&& th
->ptid
!= ptid
)
1186 /* We also need to clear any left over stale state for the
1187 leader/event thread. E.g., if there was any step-resume
1188 breakpoint or similar, it's gone now. We cannot truly
1189 step-to-next statement through an exec(). */
1190 thread_info
*th
= inferior_thread ();
1191 th
->control
.step_resume_breakpoint
= NULL
;
1192 th
->control
.exception_resume_breakpoint
= NULL
;
1193 th
->control
.single_step_breakpoints
= NULL
;
1194 th
->control
.step_range_start
= 0;
1195 th
->control
.step_range_end
= 0;
1197 /* The user may have had the main thread held stopped in the
1198 previous image (e.g., schedlock on, or non-stop). Release
1200 th
->stop_requested
= 0;
1202 update_breakpoints_after_exec ();
1204 /* What is this a.out's name? */
1205 process_ptid
= ptid_t (pid
);
1206 printf_unfiltered (_("%s is executing new program: %s\n"),
1207 target_pid_to_str (process_ptid
).c_str (),
1210 /* We've followed the inferior through an exec. Therefore, the
1211 inferior has essentially been killed & reborn. */
1213 breakpoint_init_inferior (inf_execd
);
1215 gdb::unique_xmalloc_ptr
<char> exec_file_host
1216 = exec_file_find (exec_file_target
, NULL
);
1218 /* If we were unable to map the executable target pathname onto a host
1219 pathname, tell the user that. Otherwise GDB's subsequent behavior
1220 is confusing. Maybe it would even be better to stop at this point
1221 so that the user can specify a file manually before continuing. */
1222 if (exec_file_host
== NULL
)
1223 warning (_("Could not load symbols for executable %s.\n"
1224 "Do you need \"set sysroot\"?"),
1227 /* Reset the shared library package. This ensures that we get a
1228 shlib event when the child reaches "_start", at which point the
1229 dld will have had a chance to initialize the child. */
1230 /* Also, loading a symbol file below may trigger symbol lookups, and
1231 we don't want those to be satisfied by the libraries of the
1232 previous incarnation of this process. */
1233 no_shared_libraries (NULL
, 0);
1235 struct inferior
*inf
= current_inferior ();
1237 if (follow_exec_mode_string
== follow_exec_mode_new
)
1239 /* The user wants to keep the old inferior and program spaces
1240 around. Create a new fresh one, and switch to it. */
1242 /* Do exit processing for the original inferior before setting the new
1243 inferior's pid. Having two inferiors with the same pid would confuse
1244 find_inferior_p(t)id. Transfer the terminal state and info from the
1245 old to the new inferior. */
1246 inferior
*new_inferior
= add_inferior_with_spaces ();
1248 swap_terminal_info (new_inferior
, inf
);
1249 exit_inferior_silent (inf
);
1251 new_inferior
->pid
= pid
;
1252 target_follow_exec (new_inferior
, ptid
, exec_file_target
);
1254 /* We continue with the new inferior. */
1259 /* The old description may no longer be fit for the new image.
1260 E.g, a 64-bit process exec'ed a 32-bit process. Clear the
1261 old description; we'll read a new one below. No need to do
1262 this on "follow-exec-mode new", as the old inferior stays
1263 around (its description is later cleared/refetched on
1265 target_clear_description ();
1266 target_follow_exec (inf
, ptid
, exec_file_target
);
1269 gdb_assert (current_inferior () == inf
);
1270 gdb_assert (current_program_space
== inf
->pspace
);
1272 /* Attempt to open the exec file. SYMFILE_DEFER_BP_RESET is used
1273 because the proper displacement for a PIE (Position Independent
1274 Executable) main symbol file will only be computed by
1275 solib_create_inferior_hook below. breakpoint_re_set would fail
1276 to insert the breakpoints with the zero displacement. */
1277 try_open_exec_file (exec_file_host
.get (), inf
, SYMFILE_DEFER_BP_RESET
);
1279 /* If the target can specify a description, read it. Must do this
1280 after flipping to the new executable (because the target supplied
1281 description must be compatible with the executable's
1282 architecture, and the old executable may e.g., be 32-bit, while
1283 the new one 64-bit), and before anything involving memory or
1285 target_find_description ();
1287 gdb::observers::inferior_execd
.notify (inf
);
1289 breakpoint_re_set ();
1291 /* Reinsert all breakpoints. (Those which were symbolic have
1292 been reset to the proper address in the new a.out, thanks
1293 to symbol_file_command...). */
1294 insert_breakpoints ();
1296 /* The next resume of this inferior should bring it to the shlib
1297 startup breakpoints. (If the user had also set bp's on
1298 "main" from the old (parent) process, then they'll auto-
1299 matically get reset there in the new process.). */
1302 /* The chain of threads that need to do a step-over operation to get
1303 past e.g., a breakpoint. What technique is used to step over the
1304 breakpoint/watchpoint does not matter -- all threads end up in the
1305 same queue, to maintain rough temporal order of execution, in order
1306 to avoid starvation, otherwise, we could e.g., find ourselves
1307 constantly stepping the same couple threads past their breakpoints
1308 over and over, if the single-step finish fast enough. */
1309 struct thread_info
*global_thread_step_over_chain_head
;
1311 /* Bit flags indicating what the thread needs to step over. */
1313 enum step_over_what_flag
1315 /* Step over a breakpoint. */
1316 STEP_OVER_BREAKPOINT
= 1,
1318 /* Step past a non-continuable watchpoint, in order to let the
1319 instruction execute so we can evaluate the watchpoint
1321 STEP_OVER_WATCHPOINT
= 2
1323 DEF_ENUM_FLAGS_TYPE (enum step_over_what_flag
, step_over_what
);
1325 /* Info about an instruction that is being stepped over. */
1327 struct step_over_info
1329 /* If we're stepping past a breakpoint, this is the address space
1330 and address of the instruction the breakpoint is set at. We'll
1331 skip inserting all breakpoints here. Valid iff ASPACE is
1333 const address_space
*aspace
= nullptr;
1334 CORE_ADDR address
= 0;
1336 /* The instruction being stepped over triggers a nonsteppable
1337 watchpoint. If true, we'll skip inserting watchpoints. */
1338 int nonsteppable_watchpoint_p
= 0;
1340 /* The thread's global number. */
1344 /* The step-over info of the location that is being stepped over.
1346 Note that with async/breakpoint always-inserted mode, a user might
1347 set a new breakpoint/watchpoint/etc. exactly while a breakpoint is
1348 being stepped over. As setting a new breakpoint inserts all
1349 breakpoints, we need to make sure the breakpoint being stepped over
1350 isn't inserted then. We do that by only clearing the step-over
1351 info when the step-over is actually finished (or aborted).
1353 Presently GDB can only step over one breakpoint at any given time.
1354 Given threads that can't run code in the same address space as the
1355 breakpoint's can't really miss the breakpoint, GDB could be taught
1356 to step-over at most one breakpoint per address space (so this info
1357 could move to the address space object if/when GDB is extended).
1358 The set of breakpoints being stepped over will normally be much
1359 smaller than the set of all breakpoints, so a flag in the
1360 breakpoint location structure would be wasteful. A separate list
1361 also saves complexity and run-time, as otherwise we'd have to go
1362 through all breakpoint locations clearing their flag whenever we
1363 start a new sequence. Similar considerations weigh against storing
1364 this info in the thread object. Plus, not all step overs actually
1365 have breakpoint locations -- e.g., stepping past a single-step
1366 breakpoint, or stepping to complete a non-continuable
1368 static struct step_over_info step_over_info
;
1370 /* Record the address of the breakpoint/instruction we're currently
1372 N.B. We record the aspace and address now, instead of say just the thread,
1373 because when we need the info later the thread may be running. */
1376 set_step_over_info (const address_space
*aspace
, CORE_ADDR address
,
1377 int nonsteppable_watchpoint_p
,
1380 step_over_info
.aspace
= aspace
;
1381 step_over_info
.address
= address
;
1382 step_over_info
.nonsteppable_watchpoint_p
= nonsteppable_watchpoint_p
;
1383 step_over_info
.thread
= thread
;
1386 /* Called when we're not longer stepping over a breakpoint / an
1387 instruction, so all breakpoints are free to be (re)inserted. */
1390 clear_step_over_info (void)
1392 infrun_debug_printf ("clearing step over info");
1393 step_over_info
.aspace
= NULL
;
1394 step_over_info
.address
= 0;
1395 step_over_info
.nonsteppable_watchpoint_p
= 0;
1396 step_over_info
.thread
= -1;
1402 stepping_past_instruction_at (struct address_space
*aspace
,
1405 return (step_over_info
.aspace
!= NULL
1406 && breakpoint_address_match (aspace
, address
,
1407 step_over_info
.aspace
,
1408 step_over_info
.address
));
1414 thread_is_stepping_over_breakpoint (int thread
)
1416 return (step_over_info
.thread
!= -1
1417 && thread
== step_over_info
.thread
);
1423 stepping_past_nonsteppable_watchpoint (void)
1425 return step_over_info
.nonsteppable_watchpoint_p
;
1428 /* Returns true if step-over info is valid. */
1431 step_over_info_valid_p (void)
1433 return (step_over_info
.aspace
!= NULL
1434 || stepping_past_nonsteppable_watchpoint ());
1438 /* Displaced stepping. */
1440 /* In non-stop debugging mode, we must take special care to manage
1441 breakpoints properly; in particular, the traditional strategy for
1442 stepping a thread past a breakpoint it has hit is unsuitable.
1443 'Displaced stepping' is a tactic for stepping one thread past a
1444 breakpoint it has hit while ensuring that other threads running
1445 concurrently will hit the breakpoint as they should.
1447 The traditional way to step a thread T off a breakpoint in a
1448 multi-threaded program in all-stop mode is as follows:
1450 a0) Initially, all threads are stopped, and breakpoints are not
1452 a1) We single-step T, leaving breakpoints uninserted.
1453 a2) We insert breakpoints, and resume all threads.
1455 In non-stop debugging, however, this strategy is unsuitable: we
1456 don't want to have to stop all threads in the system in order to
1457 continue or step T past a breakpoint. Instead, we use displaced
1460 n0) Initially, T is stopped, other threads are running, and
1461 breakpoints are inserted.
1462 n1) We copy the instruction "under" the breakpoint to a separate
1463 location, outside the main code stream, making any adjustments
1464 to the instruction, register, and memory state as directed by
1466 n2) We single-step T over the instruction at its new location.
1467 n3) We adjust the resulting register and memory state as directed
1468 by T's architecture. This includes resetting T's PC to point
1469 back into the main instruction stream.
1472 This approach depends on the following gdbarch methods:
1474 - gdbarch_max_insn_length and gdbarch_displaced_step_location
1475 indicate where to copy the instruction, and how much space must
1476 be reserved there. We use these in step n1.
1478 - gdbarch_displaced_step_copy_insn copies a instruction to a new
1479 address, and makes any necessary adjustments to the instruction,
1480 register contents, and memory. We use this in step n1.
1482 - gdbarch_displaced_step_fixup adjusts registers and memory after
1483 we have successfully single-stepped the instruction, to yield the
1484 same effect the instruction would have had if we had executed it
1485 at its original address. We use this in step n3.
1487 The gdbarch_displaced_step_copy_insn and
1488 gdbarch_displaced_step_fixup functions must be written so that
1489 copying an instruction with gdbarch_displaced_step_copy_insn,
1490 single-stepping across the copied instruction, and then applying
1491 gdbarch_displaced_insn_fixup should have the same effects on the
1492 thread's memory and registers as stepping the instruction in place
1493 would have. Exactly which responsibilities fall to the copy and
1494 which fall to the fixup is up to the author of those functions.
1496 See the comments in gdbarch.sh for details.
1498 Note that displaced stepping and software single-step cannot
1499 currently be used in combination, although with some care I think
1500 they could be made to. Software single-step works by placing
1501 breakpoints on all possible subsequent instructions; if the
1502 displaced instruction is a PC-relative jump, those breakpoints
1503 could fall in very strange places --- on pages that aren't
1504 executable, or at addresses that are not proper instruction
1505 boundaries. (We do generally let other threads run while we wait
1506 to hit the software single-step breakpoint, and they might
1507 encounter such a corrupted instruction.) One way to work around
1508 this would be to have gdbarch_displaced_step_copy_insn fully
1509 simulate the effect of PC-relative instructions (and return NULL)
1510 on architectures that use software single-stepping.
1512 In non-stop mode, we can have independent and simultaneous step
1513 requests, so more than one thread may need to simultaneously step
1514 over a breakpoint. The current implementation assumes there is
1515 only one scratch space per process. In this case, we have to
1516 serialize access to the scratch space. If thread A wants to step
1517 over a breakpoint, but we are currently waiting for some other
1518 thread to complete a displaced step, we leave thread A stopped and
1519 place it in the displaced_step_request_queue. Whenever a displaced
1520 step finishes, we pick the next thread in the queue and start a new
1521 displaced step operation on it. See displaced_step_prepare and
1522 displaced_step_finish for details. */
1524 /* Return true if THREAD is doing a displaced step. */
1527 displaced_step_in_progress_thread (thread_info
*thread
)
1529 gdb_assert (thread
!= NULL
);
1531 return thread
->displaced_step_state
.in_progress ();
1534 /* Return true if INF has a thread doing a displaced step. */
1537 displaced_step_in_progress (inferior
*inf
)
1539 return inf
->displaced_step_state
.in_progress_count
> 0;
1542 /* Return true if any thread is doing a displaced step. */
1545 displaced_step_in_progress_any_thread ()
1547 for (inferior
*inf
: all_non_exited_inferiors ())
1549 if (displaced_step_in_progress (inf
))
1557 infrun_inferior_exit (struct inferior
*inf
)
1559 inf
->displaced_step_state
.reset ();
1560 inf
->thread_waiting_for_vfork_done
= nullptr;
1564 infrun_inferior_execd (inferior
*inf
)
1566 /* If some threads where was doing a displaced step in this inferior at the
1567 moment of the exec, they no longer exist. Even if the exec'ing thread
1568 doing a displaced step, we don't want to to any fixup nor restore displaced
1569 stepping buffer bytes. */
1570 inf
->displaced_step_state
.reset ();
1572 for (thread_info
*thread
: inf
->threads ())
1573 thread
->displaced_step_state
.reset ();
1575 /* Since an in-line step is done with everything else stopped, if there was
1576 one in progress at the time of the exec, it must have been the exec'ing
1578 clear_step_over_info ();
1580 inf
->thread_waiting_for_vfork_done
= nullptr;
1583 /* If ON, and the architecture supports it, GDB will use displaced
1584 stepping to step over breakpoints. If OFF, or if the architecture
1585 doesn't support it, GDB will instead use the traditional
1586 hold-and-step approach. If AUTO (which is the default), GDB will
1587 decide which technique to use to step over breakpoints depending on
1588 whether the target works in a non-stop way (see use_displaced_stepping). */
1590 static enum auto_boolean can_use_displaced_stepping
= AUTO_BOOLEAN_AUTO
;
1593 show_can_use_displaced_stepping (struct ui_file
*file
, int from_tty
,
1594 struct cmd_list_element
*c
,
1597 if (can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
)
1598 fprintf_filtered (file
,
1599 _("Debugger's willingness to use displaced stepping "
1600 "to step over breakpoints is %s (currently %s).\n"),
1601 value
, target_is_non_stop_p () ? "on" : "off");
1603 fprintf_filtered (file
,
1604 _("Debugger's willingness to use displaced stepping "
1605 "to step over breakpoints is %s.\n"), value
);
1608 /* Return true if the gdbarch implements the required methods to use
1609 displaced stepping. */
1612 gdbarch_supports_displaced_stepping (gdbarch
*arch
)
1614 /* Only check for the presence of `prepare`. The gdbarch verification ensures
1615 that if `prepare` is provided, so is `finish`. */
1616 return gdbarch_displaced_step_prepare_p (arch
);
1619 /* Return non-zero if displaced stepping can/should be used to step
1620 over breakpoints of thread TP. */
1623 use_displaced_stepping (thread_info
*tp
)
1625 /* If the user disabled it explicitly, don't use displaced stepping. */
1626 if (can_use_displaced_stepping
== AUTO_BOOLEAN_FALSE
)
1629 /* If "auto", only use displaced stepping if the target operates in a non-stop
1631 if (can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
1632 && !target_is_non_stop_p ())
1635 gdbarch
*gdbarch
= get_thread_regcache (tp
)->arch ();
1637 /* If the architecture doesn't implement displaced stepping, don't use
1639 if (!gdbarch_supports_displaced_stepping (gdbarch
))
1642 /* If recording, don't use displaced stepping. */
1643 if (find_record_target () != nullptr)
1646 /* If displaced stepping failed before for this inferior, don't bother trying
1648 if (tp
->inf
->displaced_step_state
.failed_before
)
1654 /* Simple function wrapper around displaced_step_thread_state::reset. */
1657 displaced_step_reset (displaced_step_thread_state
*displaced
)
1659 displaced
->reset ();
1662 /* A cleanup that wraps displaced_step_reset. We use this instead of, say,
1663 SCOPE_EXIT, because it needs to be discardable with "cleanup.release ()". */
1665 using displaced_step_reset_cleanup
= FORWARD_SCOPE_EXIT (displaced_step_reset
);
1670 displaced_step_dump_bytes (const gdb_byte
*buf
, size_t len
)
1674 for (size_t i
= 0; i
< len
; i
++)
1677 ret
+= string_printf ("%02x", buf
[i
]);
1679 ret
+= string_printf (" %02x", buf
[i
]);
1685 /* Prepare to single-step, using displaced stepping.
1687 Note that we cannot use displaced stepping when we have a signal to
1688 deliver. If we have a signal to deliver and an instruction to step
1689 over, then after the step, there will be no indication from the
1690 target whether the thread entered a signal handler or ignored the
1691 signal and stepped over the instruction successfully --- both cases
1692 result in a simple SIGTRAP. In the first case we mustn't do a
1693 fixup, and in the second case we must --- but we can't tell which.
1694 Comments in the code for 'random signals' in handle_inferior_event
1695 explain how we handle this case instead.
1697 Returns DISPLACED_STEP_PREPARE_STATUS_OK if preparing was successful -- this
1698 thread is going to be stepped now; DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
1699 if displaced stepping this thread got queued; or
1700 DISPLACED_STEP_PREPARE_STATUS_CANT if this instruction can't be displaced
1703 static displaced_step_prepare_status
1704 displaced_step_prepare_throw (thread_info
*tp
)
1706 regcache
*regcache
= get_thread_regcache (tp
);
1707 struct gdbarch
*gdbarch
= regcache
->arch ();
1708 displaced_step_thread_state
&disp_step_thread_state
1709 = tp
->displaced_step_state
;
1711 /* We should never reach this function if the architecture does not
1712 support displaced stepping. */
1713 gdb_assert (gdbarch_supports_displaced_stepping (gdbarch
));
1715 /* Nor if the thread isn't meant to step over a breakpoint. */
1716 gdb_assert (tp
->control
.trap_expected
);
1718 /* Disable range stepping while executing in the scratch pad. We
1719 want a single-step even if executing the displaced instruction in
1720 the scratch buffer lands within the stepping range (e.g., a
1722 tp
->control
.may_range_step
= 0;
1724 /* We are about to start a displaced step for this thread. If one is already
1725 in progress, something's wrong. */
1726 gdb_assert (!disp_step_thread_state
.in_progress ());
1728 if (tp
->inf
->displaced_step_state
.unavailable
)
1730 /* The gdbarch tells us it's not worth asking to try a prepare because
1731 it is likely that it will return unavailable, so don't bother asking. */
1733 displaced_debug_printf ("deferring step of %s",
1734 target_pid_to_str (tp
->ptid
).c_str ());
1736 global_thread_step_over_chain_enqueue (tp
);
1737 return DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
;
1740 displaced_debug_printf ("displaced-stepping %s now",
1741 target_pid_to_str (tp
->ptid
).c_str ());
1743 scoped_restore_current_thread restore_thread
;
1745 switch_to_thread (tp
);
1747 CORE_ADDR original_pc
= regcache_read_pc (regcache
);
1748 CORE_ADDR displaced_pc
;
1750 displaced_step_prepare_status status
1751 = gdbarch_displaced_step_prepare (gdbarch
, tp
, displaced_pc
);
1753 if (status
== DISPLACED_STEP_PREPARE_STATUS_CANT
)
1755 displaced_debug_printf ("failed to prepare (%s)",
1756 target_pid_to_str (tp
->ptid
).c_str ());
1758 return DISPLACED_STEP_PREPARE_STATUS_CANT
;
1760 else if (status
== DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
)
1762 /* Not enough displaced stepping resources available, defer this
1763 request by placing it the queue. */
1765 displaced_debug_printf ("not enough resources available, "
1766 "deferring step of %s",
1767 target_pid_to_str (tp
->ptid
).c_str ());
1769 global_thread_step_over_chain_enqueue (tp
);
1771 return DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
;
1774 gdb_assert (status
== DISPLACED_STEP_PREPARE_STATUS_OK
);
1776 /* Save the information we need to fix things up if the step
1778 disp_step_thread_state
.set (gdbarch
);
1780 tp
->inf
->displaced_step_state
.in_progress_count
++;
1782 displaced_debug_printf ("prepared successfully thread=%s, "
1783 "original_pc=%s, displaced_pc=%s",
1784 target_pid_to_str (tp
->ptid
).c_str (),
1785 paddress (gdbarch
, original_pc
),
1786 paddress (gdbarch
, displaced_pc
));
1788 return DISPLACED_STEP_PREPARE_STATUS_OK
;
1791 /* Wrapper for displaced_step_prepare_throw that disabled further
1792 attempts at displaced stepping if we get a memory error. */
1794 static displaced_step_prepare_status
1795 displaced_step_prepare (thread_info
*thread
)
1797 displaced_step_prepare_status status
1798 = DISPLACED_STEP_PREPARE_STATUS_CANT
;
1802 status
= displaced_step_prepare_throw (thread
);
1804 catch (const gdb_exception_error
&ex
)
1806 if (ex
.error
!= MEMORY_ERROR
1807 && ex
.error
!= NOT_SUPPORTED_ERROR
)
1810 infrun_debug_printf ("caught exception, disabling displaced stepping: %s",
1813 /* Be verbose if "set displaced-stepping" is "on", silent if
1815 if (can_use_displaced_stepping
== AUTO_BOOLEAN_TRUE
)
1817 warning (_("disabling displaced stepping: %s"),
1821 /* Disable further displaced stepping attempts. */
1822 thread
->inf
->displaced_step_state
.failed_before
= 1;
1828 /* If we displaced stepped an instruction successfully, adjust registers and
1829 memory to yield the same effect the instruction would have had if we had
1830 executed it at its original address, and return
1831 DISPLACED_STEP_FINISH_STATUS_OK. If the instruction didn't complete,
1832 relocate the PC and return DISPLACED_STEP_FINISH_STATUS_NOT_EXECUTED.
1834 If the thread wasn't displaced stepping, return
1835 DISPLACED_STEP_FINISH_STATUS_OK as well. */
1837 static displaced_step_finish_status
1838 displaced_step_finish (thread_info
*event_thread
, enum gdb_signal signal
)
1840 displaced_step_thread_state
*displaced
= &event_thread
->displaced_step_state
;
1842 /* Was this thread performing a displaced step? */
1843 if (!displaced
->in_progress ())
1844 return DISPLACED_STEP_FINISH_STATUS_OK
;
1846 gdb_assert (event_thread
->inf
->displaced_step_state
.in_progress_count
> 0);
1847 event_thread
->inf
->displaced_step_state
.in_progress_count
--;
1849 /* Fixup may need to read memory/registers. Switch to the thread
1850 that we're fixing up. Also, target_stopped_by_watchpoint checks
1851 the current thread, and displaced_step_restore performs ptid-dependent
1852 memory accesses using current_inferior(). */
1853 switch_to_thread (event_thread
);
1855 displaced_step_reset_cleanup
cleanup (displaced
);
1857 /* Do the fixup, and release the resources acquired to do the displaced
1859 return gdbarch_displaced_step_finish (displaced
->get_original_gdbarch (),
1860 event_thread
, signal
);
1863 /* Data to be passed around while handling an event. This data is
1864 discarded between events. */
1865 struct execution_control_state
1867 process_stratum_target
*target
;
1869 /* The thread that got the event, if this was a thread event; NULL
1871 struct thread_info
*event_thread
;
1873 struct target_waitstatus ws
;
1874 int stop_func_filled_in
;
1875 CORE_ADDR stop_func_start
;
1876 CORE_ADDR stop_func_end
;
1877 const char *stop_func_name
;
1880 /* True if the event thread hit the single-step breakpoint of
1881 another thread. Thus the event doesn't cause a stop, the thread
1882 needs to be single-stepped past the single-step breakpoint before
1883 we can switch back to the original stepping thread. */
1884 int hit_singlestep_breakpoint
;
1887 /* Clear ECS and set it to point at TP. */
1890 reset_ecs (struct execution_control_state
*ecs
, struct thread_info
*tp
)
1892 memset (ecs
, 0, sizeof (*ecs
));
1893 ecs
->event_thread
= tp
;
1894 ecs
->ptid
= tp
->ptid
;
1897 static void keep_going_pass_signal (struct execution_control_state
*ecs
);
1898 static void prepare_to_wait (struct execution_control_state
*ecs
);
1899 static bool keep_going_stepped_thread (struct thread_info
*tp
);
1900 static step_over_what
thread_still_needs_step_over (struct thread_info
*tp
);
1902 /* Are there any pending step-over requests? If so, run all we can
1903 now and return true. Otherwise, return false. */
1906 start_step_over (void)
1908 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
1912 /* Don't start a new step-over if we already have an in-line
1913 step-over operation ongoing. */
1914 if (step_over_info_valid_p ())
1917 /* Steal the global thread step over chain. As we try to initiate displaced
1918 steps, threads will be enqueued in the global chain if no buffers are
1919 available. If we iterated on the global chain directly, we might iterate
1921 thread_info
*threads_to_step
= global_thread_step_over_chain_head
;
1922 global_thread_step_over_chain_head
= NULL
;
1924 infrun_debug_printf ("stealing global queue of threads to step, length = %d",
1925 thread_step_over_chain_length (threads_to_step
));
1927 bool started
= false;
1929 /* On scope exit (whatever the reason, return or exception), if there are
1930 threads left in the THREADS_TO_STEP chain, put back these threads in the
1934 if (threads_to_step
== nullptr)
1935 infrun_debug_printf ("step-over queue now empty");
1938 infrun_debug_printf ("putting back %d threads to step in global queue",
1939 thread_step_over_chain_length (threads_to_step
));
1941 global_thread_step_over_chain_enqueue_chain (threads_to_step
);
1945 for (thread_info
*tp
= threads_to_step
; tp
!= NULL
; tp
= next
)
1947 struct execution_control_state ecss
;
1948 struct execution_control_state
*ecs
= &ecss
;
1949 step_over_what step_what
;
1950 int must_be_in_line
;
1952 gdb_assert (!tp
->stop_requested
);
1954 next
= thread_step_over_chain_next (threads_to_step
, tp
);
1956 if (tp
->inf
->displaced_step_state
.unavailable
)
1958 /* The arch told us to not even try preparing another displaced step
1959 for this inferior. Just leave the thread in THREADS_TO_STEP, it
1960 will get moved to the global chain on scope exit. */
1964 if (tp
->inf
->thread_waiting_for_vfork_done
)
1966 /* When we stop all threads, handling a vfork, any thread in the step
1967 over chain remains there. A user could also try to continue a
1968 thread stopped at a breakpoint while another thread is waiting for
1969 a vfork-done event. In any case, we don't want to start a step
1974 /* Remove thread from the THREADS_TO_STEP chain. If anything goes wrong
1975 while we try to prepare the displaced step, we don't add it back to
1976 the global step over chain. This is to avoid a thread staying in the
1977 step over chain indefinitely if something goes wrong when resuming it
1978 If the error is intermittent and it still needs a step over, it will
1979 get enqueued again when we try to resume it normally. */
1980 thread_step_over_chain_remove (&threads_to_step
, tp
);
1982 step_what
= thread_still_needs_step_over (tp
);
1983 must_be_in_line
= ((step_what
& STEP_OVER_WATCHPOINT
)
1984 || ((step_what
& STEP_OVER_BREAKPOINT
)
1985 && !use_displaced_stepping (tp
)));
1987 /* We currently stop all threads of all processes to step-over
1988 in-line. If we need to start a new in-line step-over, let
1989 any pending displaced steps finish first. */
1990 if (must_be_in_line
&& displaced_step_in_progress_any_thread ())
1992 global_thread_step_over_chain_enqueue (tp
);
1996 if (tp
->control
.trap_expected
2000 internal_error (__FILE__
, __LINE__
,
2001 "[%s] has inconsistent state: "
2002 "trap_expected=%d, resumed=%d, executing=%d\n",
2003 target_pid_to_str (tp
->ptid
).c_str (),
2004 tp
->control
.trap_expected
,
2009 infrun_debug_printf ("resuming [%s] for step-over",
2010 target_pid_to_str (tp
->ptid
).c_str ());
2012 /* keep_going_pass_signal skips the step-over if the breakpoint
2013 is no longer inserted. In all-stop, we want to keep looking
2014 for a thread that needs a step-over instead of resuming TP,
2015 because we wouldn't be able to resume anything else until the
2016 target stops again. In non-stop, the resume always resumes
2017 only TP, so it's OK to let the thread resume freely. */
2018 if (!target_is_non_stop_p () && !step_what
)
2021 switch_to_thread (tp
);
2022 reset_ecs (ecs
, tp
);
2023 keep_going_pass_signal (ecs
);
2025 if (!ecs
->wait_some_more
)
2026 error (_("Command aborted."));
2028 /* If the thread's step over could not be initiated because no buffers
2029 were available, it was re-added to the global step over chain. */
2032 infrun_debug_printf ("[%s] was resumed.",
2033 target_pid_to_str (tp
->ptid
).c_str ());
2034 gdb_assert (!thread_is_in_step_over_chain (tp
));
2038 infrun_debug_printf ("[%s] was NOT resumed.",
2039 target_pid_to_str (tp
->ptid
).c_str ());
2040 gdb_assert (thread_is_in_step_over_chain (tp
));
2043 /* If we started a new in-line step-over, we're done. */
2044 if (step_over_info_valid_p ())
2046 gdb_assert (tp
->control
.trap_expected
);
2051 if (!target_is_non_stop_p ())
2053 /* On all-stop, shouldn't have resumed unless we needed a
2055 gdb_assert (tp
->control
.trap_expected
2056 || tp
->step_after_step_resume_breakpoint
);
2058 /* With remote targets (at least), in all-stop, we can't
2059 issue any further remote commands until the program stops
2065 /* Either the thread no longer needed a step-over, or a new
2066 displaced stepping sequence started. Even in the latter
2067 case, continue looking. Maybe we can also start another
2068 displaced step on a thread of other process. */
2074 /* Update global variables holding ptids to hold NEW_PTID if they were
2075 holding OLD_PTID. */
2077 infrun_thread_ptid_changed (process_stratum_target
*target
,
2078 ptid_t old_ptid
, ptid_t new_ptid
)
2080 if (inferior_ptid
== old_ptid
2081 && current_inferior ()->process_target () == target
)
2082 inferior_ptid
= new_ptid
;
2087 static const char schedlock_off
[] = "off";
2088 static const char schedlock_on
[] = "on";
2089 static const char schedlock_step
[] = "step";
2090 static const char schedlock_replay
[] = "replay";
2091 static const char *const scheduler_enums
[] = {
2098 static const char *scheduler_mode
= schedlock_replay
;
2100 show_scheduler_mode (struct ui_file
*file
, int from_tty
,
2101 struct cmd_list_element
*c
, const char *value
)
2103 fprintf_filtered (file
,
2104 _("Mode for locking scheduler "
2105 "during execution is \"%s\".\n"),
2110 set_schedlock_func (const char *args
, int from_tty
, struct cmd_list_element
*c
)
2112 if (!target_can_lock_scheduler ())
2114 scheduler_mode
= schedlock_off
;
2115 error (_("Target '%s' cannot support this command."),
2116 target_shortname ());
2120 /* True if execution commands resume all threads of all processes by
2121 default; otherwise, resume only threads of the current inferior
2123 bool sched_multi
= false;
2125 /* Try to setup for software single stepping over the specified location.
2126 Return true if target_resume() should use hardware single step.
2128 GDBARCH the current gdbarch.
2129 PC the location to step over. */
2132 maybe_software_singlestep (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
2134 bool hw_step
= true;
2136 if (execution_direction
== EXEC_FORWARD
2137 && gdbarch_software_single_step_p (gdbarch
))
2138 hw_step
= !insert_single_step_breakpoints (gdbarch
);
2146 user_visible_resume_ptid (int step
)
2152 /* With non-stop mode on, threads are always handled
2154 resume_ptid
= inferior_ptid
;
2156 else if ((scheduler_mode
== schedlock_on
)
2157 || (scheduler_mode
== schedlock_step
&& step
))
2159 /* User-settable 'scheduler' mode requires solo thread
2161 resume_ptid
= inferior_ptid
;
2163 else if ((scheduler_mode
== schedlock_replay
)
2164 && target_record_will_replay (minus_one_ptid
, execution_direction
))
2166 /* User-settable 'scheduler' mode requires solo thread resume in replay
2168 resume_ptid
= inferior_ptid
;
2170 else if (!sched_multi
&& target_supports_multi_process ())
2172 /* Resume all threads of the current process (and none of other
2174 resume_ptid
= ptid_t (inferior_ptid
.pid ());
2178 /* Resume all threads of all processes. */
2179 resume_ptid
= RESUME_ALL
;
2187 process_stratum_target
*
2188 user_visible_resume_target (ptid_t resume_ptid
)
2190 return (resume_ptid
== minus_one_ptid
&& sched_multi
2192 : current_inferior ()->process_target ());
2195 /* Return a ptid representing the set of threads that we will resume,
2196 in the perspective of the target, assuming run control handling
2197 does not require leaving some threads stopped (e.g., stepping past
2198 breakpoint). USER_STEP indicates whether we're about to start the
2199 target for a stepping command. */
2202 internal_resume_ptid (int user_step
)
2204 /* In non-stop, we always control threads individually. Note that
2205 the target may always work in non-stop mode even with "set
2206 non-stop off", in which case user_visible_resume_ptid could
2207 return a wildcard ptid. */
2208 if (target_is_non_stop_p ())
2209 return inferior_ptid
;
2211 /* The rest of the function assumes non-stop==off and
2212 target-non-stop==off.
2214 If a thread is waiting for a vfork-done event, it means breakpoints are out
2215 for this inferior (well, program space in fact). We don't want to resume
2216 any thread other than the one waiting for vfork done, otherwise these other
2217 threads could miss breakpoints. So if a thread in the resumption set is
2218 waiting for a vfork-done event, resume only that thread.
2220 The resumption set width depends on whether schedule-multiple is on or off.
2222 Note that if the target_resume interface was more flexible, we could be
2223 smarter here when schedule-multiple is on. For example, imagine 3
2224 inferiors with 2 threads each (1.1, 1.2, 2.1, 2.2, 3.1 and 3.2). Threads
2225 2.1 and 3.2 are both waiting for a vfork-done event. Then we could ask the
2226 target(s) to resume:
2228 - All threads of inferior 1
2232 Since we don't have that flexibility (we can only pass one ptid), just
2233 resume the first thread waiting for a vfork-done event we find (e.g. thread
2237 for (inferior
*inf
: all_non_exited_inferiors ())
2238 if (inf
->thread_waiting_for_vfork_done
!= nullptr)
2239 return inf
->thread_waiting_for_vfork_done
->ptid
;
2241 else if (current_inferior ()->thread_waiting_for_vfork_done
!= nullptr)
2242 return current_inferior ()->thread_waiting_for_vfork_done
->ptid
;
2244 return user_visible_resume_ptid (user_step
);
2247 /* Wrapper for target_resume, that handles infrun-specific
2251 do_target_resume (ptid_t resume_ptid
, bool step
, enum gdb_signal sig
)
2253 struct thread_info
*tp
= inferior_thread ();
2255 gdb_assert (!tp
->stop_requested
);
2257 /* Install inferior's terminal modes. */
2258 target_terminal::inferior ();
2260 /* Avoid confusing the next resume, if the next stop/resume
2261 happens to apply to another thread. */
2262 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2264 /* Advise target which signals may be handled silently.
2266 If we have removed breakpoints because we are stepping over one
2267 in-line (in any thread), we need to receive all signals to avoid
2268 accidentally skipping a breakpoint during execution of a signal
2271 Likewise if we're displaced stepping, otherwise a trap for a
2272 breakpoint in a signal handler might be confused with the
2273 displaced step finishing. We don't make the displaced_step_finish
2274 step distinguish the cases instead, because:
2276 - a backtrace while stopped in the signal handler would show the
2277 scratch pad as frame older than the signal handler, instead of
2278 the real mainline code.
2280 - when the thread is later resumed, the signal handler would
2281 return to the scratch pad area, which would no longer be
2283 if (step_over_info_valid_p ()
2284 || displaced_step_in_progress (tp
->inf
))
2285 target_pass_signals ({});
2287 target_pass_signals (signal_pass
);
2289 infrun_debug_printf ("resume_ptid=%s, step=%d, sig=%s",
2290 resume_ptid
.to_string ().c_str (),
2291 step
, gdb_signal_to_symbol_string (sig
));
2293 target_resume (resume_ptid
, step
, sig
);
2295 if (target_can_async_p ())
2299 /* Resume the inferior. SIG is the signal to give the inferior
2300 (GDB_SIGNAL_0 for none). Note: don't call this directly; instead
2301 call 'resume', which handles exceptions. */
2304 resume_1 (enum gdb_signal sig
)
2306 struct regcache
*regcache
= get_current_regcache ();
2307 struct gdbarch
*gdbarch
= regcache
->arch ();
2308 struct thread_info
*tp
= inferior_thread ();
2309 const address_space
*aspace
= regcache
->aspace ();
2311 /* This represents the user's step vs continue request. When
2312 deciding whether "set scheduler-locking step" applies, it's the
2313 user's intention that counts. */
2314 const int user_step
= tp
->control
.stepping_command
;
2315 /* This represents what we'll actually request the target to do.
2316 This can decay from a step to a continue, if e.g., we need to
2317 implement single-stepping with breakpoints (software
2321 gdb_assert (!tp
->stop_requested
);
2322 gdb_assert (!thread_is_in_step_over_chain (tp
));
2324 if (tp
->suspend
.waitstatus_pending_p
)
2327 ("thread %s has pending wait "
2328 "status %s (currently_stepping=%d).",
2329 target_pid_to_str (tp
->ptid
).c_str (),
2330 target_waitstatus_to_string (&tp
->suspend
.waitstatus
).c_str (),
2331 currently_stepping (tp
));
2333 tp
->inf
->process_target ()->threads_executing
= true;
2336 /* FIXME: What should we do if we are supposed to resume this
2337 thread with a signal? Maybe we should maintain a queue of
2338 pending signals to deliver. */
2339 if (sig
!= GDB_SIGNAL_0
)
2341 warning (_("Couldn't deliver signal %s to %s."),
2342 gdb_signal_to_name (sig
),
2343 target_pid_to_str (tp
->ptid
).c_str ());
2346 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2348 if (target_can_async_p ())
2351 /* Tell the event loop we have an event to process. */
2352 mark_async_event_handler (infrun_async_inferior_event_token
);
2357 tp
->stepped_breakpoint
= 0;
2359 /* Depends on stepped_breakpoint. */
2360 step
= currently_stepping (tp
);
2362 if (current_inferior ()->thread_waiting_for_vfork_done
!= nullptr)
2364 /* Don't try to single-step a vfork parent that is waiting for
2365 the child to get out of the shared memory region (by exec'ing
2366 or exiting). This is particularly important on software
2367 single-step archs, as the child process would trip on the
2368 software single step breakpoint inserted for the parent
2369 process. Since the parent will not actually execute any
2370 instruction until the child is out of the shared region (such
2371 are vfork's semantics), it is safe to simply continue it.
2372 Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for
2373 the parent, and tell it to `keep_going', which automatically
2374 re-sets it stepping. */
2375 infrun_debug_printf ("resume : clear step");
2379 CORE_ADDR pc
= regcache_read_pc (regcache
);
2381 infrun_debug_printf ("step=%d, signal=%s, trap_expected=%d, "
2382 "current thread [%s] at %s",
2383 step
, gdb_signal_to_symbol_string (sig
),
2384 tp
->control
.trap_expected
,
2385 target_pid_to_str (inferior_ptid
).c_str (),
2386 paddress (gdbarch
, pc
));
2388 /* Normally, by the time we reach `resume', the breakpoints are either
2389 removed or inserted, as appropriate. The exception is if we're sitting
2390 at a permanent breakpoint; we need to step over it, but permanent
2391 breakpoints can't be removed. So we have to test for it here. */
2392 if (breakpoint_here_p (aspace
, pc
) == permanent_breakpoint_here
)
2394 if (sig
!= GDB_SIGNAL_0
)
2396 /* We have a signal to pass to the inferior. The resume
2397 may, or may not take us to the signal handler. If this
2398 is a step, we'll need to stop in the signal handler, if
2399 there's one, (if the target supports stepping into
2400 handlers), or in the next mainline instruction, if
2401 there's no handler. If this is a continue, we need to be
2402 sure to run the handler with all breakpoints inserted.
2403 In all cases, set a breakpoint at the current address
2404 (where the handler returns to), and once that breakpoint
2405 is hit, resume skipping the permanent breakpoint. If
2406 that breakpoint isn't hit, then we've stepped into the
2407 signal handler (or hit some other event). We'll delete
2408 the step-resume breakpoint then. */
2410 infrun_debug_printf ("resume: skipping permanent breakpoint, "
2411 "deliver signal first");
2413 clear_step_over_info ();
2414 tp
->control
.trap_expected
= 0;
2416 if (tp
->control
.step_resume_breakpoint
== NULL
)
2418 /* Set a "high-priority" step-resume, as we don't want
2419 user breakpoints at PC to trigger (again) when this
2421 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
2422 gdb_assert (tp
->control
.step_resume_breakpoint
->loc
->permanent
);
2424 tp
->step_after_step_resume_breakpoint
= step
;
2427 insert_breakpoints ();
2431 /* There's no signal to pass, we can go ahead and skip the
2432 permanent breakpoint manually. */
2433 infrun_debug_printf ("skipping permanent breakpoint");
2434 gdbarch_skip_permanent_breakpoint (gdbarch
, regcache
);
2435 /* Update pc to reflect the new address from which we will
2436 execute instructions. */
2437 pc
= regcache_read_pc (regcache
);
2441 /* We've already advanced the PC, so the stepping part
2442 is done. Now we need to arrange for a trap to be
2443 reported to handle_inferior_event. Set a breakpoint
2444 at the current PC, and run to it. Don't update
2445 prev_pc, because if we end in
2446 switch_back_to_stepped_thread, we want the "expected
2447 thread advanced also" branch to be taken. IOW, we
2448 don't want this thread to step further from PC
2450 gdb_assert (!step_over_info_valid_p ());
2451 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
2452 insert_breakpoints ();
2454 resume_ptid
= internal_resume_ptid (user_step
);
2455 do_target_resume (resume_ptid
, false, GDB_SIGNAL_0
);
2462 /* If we have a breakpoint to step over, make sure to do a single
2463 step only. Same if we have software watchpoints. */
2464 if (tp
->control
.trap_expected
|| bpstat_should_step ())
2465 tp
->control
.may_range_step
= 0;
2467 /* If displaced stepping is enabled, step over breakpoints by executing a
2468 copy of the instruction at a different address.
2470 We can't use displaced stepping when we have a signal to deliver;
2471 the comments for displaced_step_prepare explain why. The
2472 comments in the handle_inferior event for dealing with 'random
2473 signals' explain what we do instead.
2475 We can't use displaced stepping when we are waiting for vfork_done
2476 event, displaced stepping breaks the vfork child similarly as single
2477 step software breakpoint. */
2478 if (tp
->control
.trap_expected
2479 && use_displaced_stepping (tp
)
2480 && !step_over_info_valid_p ()
2481 && sig
== GDB_SIGNAL_0
2482 && current_inferior ()->thread_waiting_for_vfork_done
== nullptr)
2484 displaced_step_prepare_status prepare_status
2485 = displaced_step_prepare (tp
);
2487 if (prepare_status
== DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
)
2489 infrun_debug_printf ("Got placed in step-over queue");
2491 tp
->control
.trap_expected
= 0;
2494 else if (prepare_status
== DISPLACED_STEP_PREPARE_STATUS_CANT
)
2496 /* Fallback to stepping over the breakpoint in-line. */
2498 if (target_is_non_stop_p ())
2499 stop_all_threads ("displaced stepping falling back on inline stepping");
2501 set_step_over_info (regcache
->aspace (),
2502 regcache_read_pc (regcache
), 0, tp
->global_num
);
2504 step
= maybe_software_singlestep (gdbarch
, pc
);
2506 insert_breakpoints ();
2508 else if (prepare_status
== DISPLACED_STEP_PREPARE_STATUS_OK
)
2510 /* Update pc to reflect the new address from which we will
2511 execute instructions due to displaced stepping. */
2512 pc
= regcache_read_pc (get_thread_regcache (tp
));
2514 step
= gdbarch_displaced_step_hw_singlestep (gdbarch
);
2517 gdb_assert_not_reached (_("Invalid displaced_step_prepare_status "
2521 /* Do we need to do it the hard way, w/temp breakpoints? */
2523 step
= maybe_software_singlestep (gdbarch
, pc
);
2525 /* Currently, our software single-step implementation leads to different
2526 results than hardware single-stepping in one situation: when stepping
2527 into delivering a signal which has an associated signal handler,
2528 hardware single-step will stop at the first instruction of the handler,
2529 while software single-step will simply skip execution of the handler.
2531 For now, this difference in behavior is accepted since there is no
2532 easy way to actually implement single-stepping into a signal handler
2533 without kernel support.
2535 However, there is one scenario where this difference leads to follow-on
2536 problems: if we're stepping off a breakpoint by removing all breakpoints
2537 and then single-stepping. In this case, the software single-step
2538 behavior means that even if there is a *breakpoint* in the signal
2539 handler, GDB still would not stop.
2541 Fortunately, we can at least fix this particular issue. We detect
2542 here the case where we are about to deliver a signal while software
2543 single-stepping with breakpoints removed. In this situation, we
2544 revert the decisions to remove all breakpoints and insert single-
2545 step breakpoints, and instead we install a step-resume breakpoint
2546 at the current address, deliver the signal without stepping, and
2547 once we arrive back at the step-resume breakpoint, actually step
2548 over the breakpoint we originally wanted to step over. */
2549 if (thread_has_single_step_breakpoints_set (tp
)
2550 && sig
!= GDB_SIGNAL_0
2551 && step_over_info_valid_p ())
2553 /* If we have nested signals or a pending signal is delivered
2554 immediately after a handler returns, might already have
2555 a step-resume breakpoint set on the earlier handler. We cannot
2556 set another step-resume breakpoint; just continue on until the
2557 original breakpoint is hit. */
2558 if (tp
->control
.step_resume_breakpoint
== NULL
)
2560 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
2561 tp
->step_after_step_resume_breakpoint
= 1;
2564 delete_single_step_breakpoints (tp
);
2566 clear_step_over_info ();
2567 tp
->control
.trap_expected
= 0;
2569 insert_breakpoints ();
2572 /* If STEP is set, it's a request to use hardware stepping
2573 facilities. But in that case, we should never
2574 use singlestep breakpoint. */
2575 gdb_assert (!(thread_has_single_step_breakpoints_set (tp
) && step
));
2577 /* Decide the set of threads to ask the target to resume. */
2578 if (tp
->control
.trap_expected
)
2580 /* We're allowing a thread to run past a breakpoint it has
2581 hit, either by single-stepping the thread with the breakpoint
2582 removed, or by displaced stepping, with the breakpoint inserted.
2583 In the former case, we need to single-step only this thread,
2584 and keep others stopped, as they can miss this breakpoint if
2585 allowed to run. That's not really a problem for displaced
2586 stepping, but, we still keep other threads stopped, in case
2587 another thread is also stopped for a breakpoint waiting for
2588 its turn in the displaced stepping queue. */
2589 resume_ptid
= inferior_ptid
;
2592 resume_ptid
= internal_resume_ptid (user_step
);
2594 if (execution_direction
!= EXEC_REVERSE
2595 && step
&& breakpoint_inserted_here_p (aspace
, pc
))
2597 /* There are two cases where we currently need to step a
2598 breakpoint instruction when we have a signal to deliver:
2600 - See handle_signal_stop where we handle random signals that
2601 could take out us out of the stepping range. Normally, in
2602 that case we end up continuing (instead of stepping) over the
2603 signal handler with a breakpoint at PC, but there are cases
2604 where we should _always_ single-step, even if we have a
2605 step-resume breakpoint, like when a software watchpoint is
2606 set. Assuming single-stepping and delivering a signal at the
2607 same time would takes us to the signal handler, then we could
2608 have removed the breakpoint at PC to step over it. However,
2609 some hardware step targets (like e.g., Mac OS) can't step
2610 into signal handlers, and for those, we need to leave the
2611 breakpoint at PC inserted, as otherwise if the handler
2612 recurses and executes PC again, it'll miss the breakpoint.
2613 So we leave the breakpoint inserted anyway, but we need to
2614 record that we tried to step a breakpoint instruction, so
2615 that adjust_pc_after_break doesn't end up confused.
2617 - In non-stop if we insert a breakpoint (e.g., a step-resume)
2618 in one thread after another thread that was stepping had been
2619 momentarily paused for a step-over. When we re-resume the
2620 stepping thread, it may be resumed from that address with a
2621 breakpoint that hasn't trapped yet. Seen with
2622 gdb.threads/non-stop-fair-events.exp, on targets that don't
2623 do displaced stepping. */
2625 infrun_debug_printf ("resume: [%s] stepped breakpoint",
2626 target_pid_to_str (tp
->ptid
).c_str ());
2628 tp
->stepped_breakpoint
= 1;
2630 /* Most targets can step a breakpoint instruction, thus
2631 executing it normally. But if this one cannot, just
2632 continue and we will hit it anyway. */
2633 if (gdbarch_cannot_step_breakpoint (gdbarch
))
2638 && tp
->control
.trap_expected
2639 && use_displaced_stepping (tp
)
2640 && !step_over_info_valid_p ())
2642 struct regcache
*resume_regcache
= get_thread_regcache (tp
);
2643 struct gdbarch
*resume_gdbarch
= resume_regcache
->arch ();
2644 CORE_ADDR actual_pc
= regcache_read_pc (resume_regcache
);
2647 read_memory (actual_pc
, buf
, sizeof (buf
));
2648 displaced_debug_printf ("run %s: %s",
2649 paddress (resume_gdbarch
, actual_pc
),
2650 displaced_step_dump_bytes
2651 (buf
, sizeof (buf
)).c_str ());
2654 if (tp
->control
.may_range_step
)
2656 /* If we're resuming a thread with the PC out of the step
2657 range, then we're doing some nested/finer run control
2658 operation, like stepping the thread out of the dynamic
2659 linker or the displaced stepping scratch pad. We
2660 shouldn't have allowed a range step then. */
2661 gdb_assert (pc_in_thread_step_range (pc
, tp
));
2664 do_target_resume (resume_ptid
, step
, sig
);
2668 /* Resume the inferior. SIG is the signal to give the inferior
2669 (GDB_SIGNAL_0 for none). This is a wrapper around 'resume_1' that
2670 rolls back state on error. */
2673 resume (gdb_signal sig
)
2679 catch (const gdb_exception
&ex
)
2681 /* If resuming is being aborted for any reason, delete any
2682 single-step breakpoint resume_1 may have created, to avoid
2683 confusing the following resumption, and to avoid leaving
2684 single-step breakpoints perturbing other threads, in case
2685 we're running in non-stop mode. */
2686 if (inferior_ptid
!= null_ptid
)
2687 delete_single_step_breakpoints (inferior_thread ());
2697 /* Counter that tracks number of user visible stops. This can be used
2698 to tell whether a command has proceeded the inferior past the
2699 current location. This allows e.g., inferior function calls in
2700 breakpoint commands to not interrupt the command list. When the
2701 call finishes successfully, the inferior is standing at the same
2702 breakpoint as if nothing happened (and so we don't call
2704 static ULONGEST current_stop_id
;
2711 return current_stop_id
;
2714 /* Called when we report a user visible stop. */
2722 /* Clear out all variables saying what to do when inferior is continued.
2723 First do this, then set the ones you want, then call `proceed'. */
2726 clear_proceed_status_thread (struct thread_info
*tp
)
2728 infrun_debug_printf ("%s", target_pid_to_str (tp
->ptid
).c_str ());
2730 /* If we're starting a new sequence, then the previous finished
2731 single-step is no longer relevant. */
2732 if (tp
->suspend
.waitstatus_pending_p
)
2734 if (tp
->suspend
.stop_reason
== TARGET_STOPPED_BY_SINGLE_STEP
)
2736 infrun_debug_printf ("pending event of %s was a finished step. "
2738 target_pid_to_str (tp
->ptid
).c_str ());
2740 tp
->suspend
.waitstatus_pending_p
= 0;
2741 tp
->suspend
.stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
2746 ("thread %s has pending wait status %s (currently_stepping=%d).",
2747 target_pid_to_str (tp
->ptid
).c_str (),
2748 target_waitstatus_to_string (&tp
->suspend
.waitstatus
).c_str (),
2749 currently_stepping (tp
));
2753 /* If this signal should not be seen by program, give it zero.
2754 Used for debugging signals. */
2755 if (!signal_pass_state (tp
->suspend
.stop_signal
))
2756 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2758 delete tp
->thread_fsm
;
2759 tp
->thread_fsm
= NULL
;
2761 tp
->control
.trap_expected
= 0;
2762 tp
->control
.step_range_start
= 0;
2763 tp
->control
.step_range_end
= 0;
2764 tp
->control
.may_range_step
= 0;
2765 tp
->control
.step_frame_id
= null_frame_id
;
2766 tp
->control
.step_stack_frame_id
= null_frame_id
;
2767 tp
->control
.step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
2768 tp
->control
.step_start_function
= NULL
;
2769 tp
->stop_requested
= 0;
2771 tp
->control
.stop_step
= 0;
2773 tp
->control
.proceed_to_finish
= 0;
2775 tp
->control
.stepping_command
= 0;
2777 /* Discard any remaining commands or status from previous stop. */
2778 bpstat_clear (&tp
->control
.stop_bpstat
);
2782 clear_proceed_status (int step
)
2784 /* With scheduler-locking replay, stop replaying other threads if we're
2785 not replaying the user-visible resume ptid.
2787 This is a convenience feature to not require the user to explicitly
2788 stop replaying the other threads. We're assuming that the user's
2789 intent is to resume tracing the recorded process. */
2790 if (!non_stop
&& scheduler_mode
== schedlock_replay
2791 && target_record_is_replaying (minus_one_ptid
)
2792 && !target_record_will_replay (user_visible_resume_ptid (step
),
2793 execution_direction
))
2794 target_record_stop_replaying ();
2796 if (!non_stop
&& inferior_ptid
!= null_ptid
)
2798 ptid_t resume_ptid
= user_visible_resume_ptid (step
);
2799 process_stratum_target
*resume_target
2800 = user_visible_resume_target (resume_ptid
);
2802 /* In all-stop mode, delete the per-thread status of all threads
2803 we're about to resume, implicitly and explicitly. */
2804 for (thread_info
*tp
: all_non_exited_threads (resume_target
, resume_ptid
))
2805 clear_proceed_status_thread (tp
);
2808 if (inferior_ptid
!= null_ptid
)
2810 struct inferior
*inferior
;
2814 /* If in non-stop mode, only delete the per-thread status of
2815 the current thread. */
2816 clear_proceed_status_thread (inferior_thread ());
2819 inferior
= current_inferior ();
2820 inferior
->control
.stop_soon
= NO_STOP_QUIETLY
;
2823 gdb::observers::about_to_proceed
.notify ();
2826 /* Returns true if TP is still stopped at a breakpoint that needs
2827 stepping-over in order to make progress. If the breakpoint is gone
2828 meanwhile, we can skip the whole step-over dance. */
2831 thread_still_needs_step_over_bp (struct thread_info
*tp
)
2833 if (tp
->stepping_over_breakpoint
)
2835 struct regcache
*regcache
= get_thread_regcache (tp
);
2837 if (breakpoint_here_p (regcache
->aspace (),
2838 regcache_read_pc (regcache
))
2839 == ordinary_breakpoint_here
)
2842 tp
->stepping_over_breakpoint
= 0;
2848 /* Check whether thread TP still needs to start a step-over in order
2849 to make progress when resumed. Returns an bitwise or of enum
2850 step_over_what bits, indicating what needs to be stepped over. */
2852 static step_over_what
2853 thread_still_needs_step_over (struct thread_info
*tp
)
2855 step_over_what what
= 0;
2857 if (thread_still_needs_step_over_bp (tp
))
2858 what
|= STEP_OVER_BREAKPOINT
;
2860 if (tp
->stepping_over_watchpoint
2861 && !target_have_steppable_watchpoint ())
2862 what
|= STEP_OVER_WATCHPOINT
;
2867 /* Returns true if scheduler locking applies. STEP indicates whether
2868 we're about to do a step/next-like command to a thread. */
2871 schedlock_applies (struct thread_info
*tp
)
2873 return (scheduler_mode
== schedlock_on
2874 || (scheduler_mode
== schedlock_step
2875 && tp
->control
.stepping_command
)
2876 || (scheduler_mode
== schedlock_replay
2877 && target_record_will_replay (minus_one_ptid
,
2878 execution_direction
)));
2881 /* Set process_stratum_target::COMMIT_RESUMED_STATE in all target
2882 stacks that have threads executing and don't have threads with
2886 maybe_set_commit_resumed_all_targets ()
2888 scoped_restore_current_thread restore_thread
;
2890 for (inferior
*inf
: all_non_exited_inferiors ())
2892 process_stratum_target
*proc_target
= inf
->process_target ();
2894 if (proc_target
->commit_resumed_state
)
2896 /* We already set this in a previous iteration, via another
2897 inferior sharing the process_stratum target. */
2901 /* If the target has no resumed threads, it would be useless to
2902 ask it to commit the resumed threads. */
2903 if (!proc_target
->threads_executing
)
2905 infrun_debug_printf ("not requesting commit-resumed for target "
2906 "%s, no resumed threads",
2907 proc_target
->shortname ());
2911 /* As an optimization, if a thread from this target has some
2912 status to report, handle it before requiring the target to
2913 commit its resumed threads: handling the status might lead to
2914 resuming more threads. */
2915 bool has_thread_with_pending_status
= false;
2916 for (thread_info
*thread
: all_non_exited_threads (proc_target
))
2917 if (thread
->resumed
&& thread
->suspend
.waitstatus_pending_p
)
2919 has_thread_with_pending_status
= true;
2923 if (has_thread_with_pending_status
)
2925 infrun_debug_printf ("not requesting commit-resumed for target %s, a"
2926 " thread has a pending waitstatus",
2927 proc_target
->shortname ());
2931 switch_to_inferior_no_thread (inf
);
2933 if (target_has_pending_events ())
2935 infrun_debug_printf ("not requesting commit-resumed for target %s, "
2936 "target has pending events",
2937 proc_target
->shortname ());
2941 infrun_debug_printf ("enabling commit-resumed for target %s",
2942 proc_target
->shortname ());
2944 proc_target
->commit_resumed_state
= true;
2951 maybe_call_commit_resumed_all_targets ()
2953 scoped_restore_current_thread restore_thread
;
2955 for (inferior
*inf
: all_non_exited_inferiors ())
2957 process_stratum_target
*proc_target
= inf
->process_target ();
2959 if (!proc_target
->commit_resumed_state
)
2962 switch_to_inferior_no_thread (inf
);
2964 infrun_debug_printf ("calling commit_resumed for target %s",
2965 proc_target
->shortname());
2967 target_commit_resumed ();
2971 /* To track nesting of scoped_disable_commit_resumed objects, ensuring
2972 that only the outermost one attempts to re-enable
2974 static bool enable_commit_resumed
= true;
2978 scoped_disable_commit_resumed::scoped_disable_commit_resumed
2979 (const char *reason
)
2980 : m_reason (reason
),
2981 m_prev_enable_commit_resumed (enable_commit_resumed
)
2983 infrun_debug_printf ("reason=%s", m_reason
);
2985 enable_commit_resumed
= false;
2987 for (inferior
*inf
: all_non_exited_inferiors ())
2989 process_stratum_target
*proc_target
= inf
->process_target ();
2991 if (m_prev_enable_commit_resumed
)
2993 /* This is the outermost instance: force all
2994 COMMIT_RESUMED_STATE to false. */
2995 proc_target
->commit_resumed_state
= false;
2999 /* This is not the outermost instance, we expect
3000 COMMIT_RESUMED_STATE to have been cleared by the
3001 outermost instance. */
3002 gdb_assert (!proc_target
->commit_resumed_state
);
3010 scoped_disable_commit_resumed::reset ()
3016 infrun_debug_printf ("reason=%s", m_reason
);
3018 gdb_assert (!enable_commit_resumed
);
3020 enable_commit_resumed
= m_prev_enable_commit_resumed
;
3022 if (m_prev_enable_commit_resumed
)
3024 /* This is the outermost instance, re-enable
3025 COMMIT_RESUMED_STATE on the targets where it's possible. */
3026 maybe_set_commit_resumed_all_targets ();
3030 /* This is not the outermost instance, we expect
3031 COMMIT_RESUMED_STATE to still be false. */
3032 for (inferior
*inf
: all_non_exited_inferiors ())
3034 process_stratum_target
*proc_target
= inf
->process_target ();
3035 gdb_assert (!proc_target
->commit_resumed_state
);
3042 scoped_disable_commit_resumed::~scoped_disable_commit_resumed ()
3050 scoped_disable_commit_resumed::reset_and_commit ()
3053 maybe_call_commit_resumed_all_targets ();
3058 scoped_enable_commit_resumed::scoped_enable_commit_resumed
3059 (const char *reason
)
3060 : m_reason (reason
),
3061 m_prev_enable_commit_resumed (enable_commit_resumed
)
3063 infrun_debug_printf ("reason=%s", m_reason
);
3065 if (!enable_commit_resumed
)
3067 enable_commit_resumed
= true;
3069 /* Re-enable COMMIT_RESUMED_STATE on the targets where it's
3071 maybe_set_commit_resumed_all_targets ();
3073 maybe_call_commit_resumed_all_targets ();
3079 scoped_enable_commit_resumed::~scoped_enable_commit_resumed ()
3081 infrun_debug_printf ("reason=%s", m_reason
);
3083 gdb_assert (enable_commit_resumed
);
3085 enable_commit_resumed
= m_prev_enable_commit_resumed
;
3087 if (!enable_commit_resumed
)
3089 /* Force all COMMIT_RESUMED_STATE back to false. */
3090 for (inferior
*inf
: all_non_exited_inferiors ())
3092 process_stratum_target
*proc_target
= inf
->process_target ();
3093 proc_target
->commit_resumed_state
= false;
3098 /* Check that all the targets we're about to resume are in non-stop
3099 mode. Ideally, we'd only care whether all targets support
3100 target-async, but we're not there yet. E.g., stop_all_threads
3101 doesn't know how to handle all-stop targets. Also, the remote
3102 protocol in all-stop mode is synchronous, irrespective of
3103 target-async, which means that things like a breakpoint re-set
3104 triggered by one target would try to read memory from all targets
3108 check_multi_target_resumption (process_stratum_target
*resume_target
)
3110 if (!non_stop
&& resume_target
== nullptr)
3112 scoped_restore_current_thread restore_thread
;
3114 /* This is used to track whether we're resuming more than one
3116 process_stratum_target
*first_connection
= nullptr;
3118 /* The first inferior we see with a target that does not work in
3119 always-non-stop mode. */
3120 inferior
*first_not_non_stop
= nullptr;
3122 for (inferior
*inf
: all_non_exited_inferiors ())
3124 switch_to_inferior_no_thread (inf
);
3126 if (!target_has_execution ())
3129 process_stratum_target
*proc_target
3130 = current_inferior ()->process_target();
3132 if (!target_is_non_stop_p ())
3133 first_not_non_stop
= inf
;
3135 if (first_connection
== nullptr)
3136 first_connection
= proc_target
;
3137 else if (first_connection
!= proc_target
3138 && first_not_non_stop
!= nullptr)
3140 switch_to_inferior_no_thread (first_not_non_stop
);
3142 proc_target
= current_inferior ()->process_target();
3144 error (_("Connection %d (%s) does not support "
3145 "multi-target resumption."),
3146 proc_target
->connection_number
,
3147 make_target_connection_string (proc_target
).c_str ());
3153 /* Basic routine for continuing the program in various fashions.
3155 ADDR is the address to resume at, or -1 for resume where stopped.
3156 SIGGNAL is the signal to give it, or GDB_SIGNAL_0 for none,
3157 or GDB_SIGNAL_DEFAULT for act according to how it stopped.
3159 You should call clear_proceed_status before calling proceed. */
3162 proceed (CORE_ADDR addr
, enum gdb_signal siggnal
)
3164 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
3166 struct regcache
*regcache
;
3167 struct gdbarch
*gdbarch
;
3169 struct execution_control_state ecss
;
3170 struct execution_control_state
*ecs
= &ecss
;
3173 /* If we're stopped at a fork/vfork, follow the branch set by the
3174 "set follow-fork-mode" command; otherwise, we'll just proceed
3175 resuming the current thread. */
3176 if (!follow_fork ())
3178 /* The target for some reason decided not to resume. */
3180 if (target_can_async_p ())
3181 inferior_event_handler (INF_EXEC_COMPLETE
);
3185 /* We'll update this if & when we switch to a new thread. */
3186 previous_inferior_ptid
= inferior_ptid
;
3188 regcache
= get_current_regcache ();
3189 gdbarch
= regcache
->arch ();
3190 const address_space
*aspace
= regcache
->aspace ();
3192 pc
= regcache_read_pc_protected (regcache
);
3194 thread_info
*cur_thr
= inferior_thread ();
3196 /* Fill in with reasonable starting values. */
3197 init_thread_stepping_state (cur_thr
);
3199 gdb_assert (!thread_is_in_step_over_chain (cur_thr
));
3202 = user_visible_resume_ptid (cur_thr
->control
.stepping_command
);
3203 process_stratum_target
*resume_target
3204 = user_visible_resume_target (resume_ptid
);
3206 check_multi_target_resumption (resume_target
);
3208 if (addr
== (CORE_ADDR
) -1)
3210 if (pc
== cur_thr
->suspend
.stop_pc
3211 && breakpoint_here_p (aspace
, pc
) == ordinary_breakpoint_here
3212 && execution_direction
!= EXEC_REVERSE
)
3213 /* There is a breakpoint at the address we will resume at,
3214 step one instruction before inserting breakpoints so that
3215 we do not stop right away (and report a second hit at this
3218 Note, we don't do this in reverse, because we won't
3219 actually be executing the breakpoint insn anyway.
3220 We'll be (un-)executing the previous instruction. */
3221 cur_thr
->stepping_over_breakpoint
= 1;
3222 else if (gdbarch_single_step_through_delay_p (gdbarch
)
3223 && gdbarch_single_step_through_delay (gdbarch
,
3224 get_current_frame ()))
3225 /* We stepped onto an instruction that needs to be stepped
3226 again before re-inserting the breakpoint, do so. */
3227 cur_thr
->stepping_over_breakpoint
= 1;
3231 regcache_write_pc (regcache
, addr
);
3234 if (siggnal
!= GDB_SIGNAL_DEFAULT
)
3235 cur_thr
->suspend
.stop_signal
= siggnal
;
3237 /* If an exception is thrown from this point on, make sure to
3238 propagate GDB's knowledge of the executing state to the
3239 frontend/user running state. */
3240 scoped_finish_thread_state
finish_state (resume_target
, resume_ptid
);
3242 /* Even if RESUME_PTID is a wildcard, and we end up resuming fewer
3243 threads (e.g., we might need to set threads stepping over
3244 breakpoints first), from the user/frontend's point of view, all
3245 threads in RESUME_PTID are now running. Unless we're calling an
3246 inferior function, as in that case we pretend the inferior
3247 doesn't run at all. */
3248 if (!cur_thr
->control
.in_infcall
)
3249 set_running (resume_target
, resume_ptid
, true);
3251 infrun_debug_printf ("addr=%s, signal=%s", paddress (gdbarch
, addr
),
3252 gdb_signal_to_symbol_string (siggnal
));
3254 annotate_starting ();
3256 /* Make sure that output from GDB appears before output from the
3258 gdb_flush (gdb_stdout
);
3260 /* Since we've marked the inferior running, give it the terminal. A
3261 QUIT/Ctrl-C from here on is forwarded to the target (which can
3262 still detect attempts to unblock a stuck connection with repeated
3263 Ctrl-C from within target_pass_ctrlc). */
3264 target_terminal::inferior ();
3266 /* In a multi-threaded task we may select another thread and
3267 then continue or step.
3269 But if a thread that we're resuming had stopped at a breakpoint,
3270 it will immediately cause another breakpoint stop without any
3271 execution (i.e. it will report a breakpoint hit incorrectly). So
3272 we must step over it first.
3274 Look for threads other than the current (TP) that reported a
3275 breakpoint hit and haven't been resumed yet since. */
3277 /* If scheduler locking applies, we can avoid iterating over all
3279 if (!non_stop
&& !schedlock_applies (cur_thr
))
3281 for (thread_info
*tp
: all_non_exited_threads (resume_target
,
3284 switch_to_thread_no_regs (tp
);
3286 /* Ignore the current thread here. It's handled
3291 if (!thread_still_needs_step_over (tp
))
3294 gdb_assert (!thread_is_in_step_over_chain (tp
));
3296 infrun_debug_printf ("need to step-over [%s] first",
3297 target_pid_to_str (tp
->ptid
).c_str ());
3299 global_thread_step_over_chain_enqueue (tp
);
3302 switch_to_thread (cur_thr
);
3305 /* Enqueue the current thread last, so that we move all other
3306 threads over their breakpoints first. */
3307 if (cur_thr
->stepping_over_breakpoint
)
3308 global_thread_step_over_chain_enqueue (cur_thr
);
3310 /* If the thread isn't started, we'll still need to set its prev_pc,
3311 so that switch_back_to_stepped_thread knows the thread hasn't
3312 advanced. Must do this before resuming any thread, as in
3313 all-stop/remote, once we resume we can't send any other packet
3314 until the target stops again. */
3315 cur_thr
->prev_pc
= regcache_read_pc_protected (regcache
);
3318 scoped_disable_commit_resumed
disable_commit_resumed ("proceeding");
3320 started
= start_step_over ();
3322 if (step_over_info_valid_p ())
3324 /* Either this thread started a new in-line step over, or some
3325 other thread was already doing one. In either case, don't
3326 resume anything else until the step-over is finished. */
3328 else if (started
&& !target_is_non_stop_p ())
3330 /* A new displaced stepping sequence was started. In all-stop,
3331 we can't talk to the target anymore until it next stops. */
3333 else if (!non_stop
&& target_is_non_stop_p ())
3335 INFRUN_SCOPED_DEBUG_START_END
3336 ("resuming threads, all-stop-on-top-of-non-stop");
3338 /* In all-stop, but the target is always in non-stop mode.
3339 Start all other threads that are implicitly resumed too. */
3340 for (thread_info
*tp
: all_non_exited_threads (resume_target
,
3343 switch_to_thread_no_regs (tp
);
3345 if (!tp
->inf
->has_execution ())
3347 infrun_debug_printf ("[%s] target has no execution",
3348 target_pid_to_str (tp
->ptid
).c_str ());
3354 infrun_debug_printf ("[%s] resumed",
3355 target_pid_to_str (tp
->ptid
).c_str ());
3356 gdb_assert (tp
->executing
|| tp
->suspend
.waitstatus_pending_p
);
3360 if (thread_is_in_step_over_chain (tp
))
3362 infrun_debug_printf ("[%s] needs step-over",
3363 target_pid_to_str (tp
->ptid
).c_str ());
3367 /* If a thread of that inferior is waiting for a vfork-done
3368 (for a detached vfork child to exec or exit), breakpoints are
3369 removed. We must not resume any thread of that inferior, other
3370 than the one waiting for the vfork-done. */
3371 if (tp
->inf
->thread_waiting_for_vfork_done
!= nullptr
3372 && tp
!= tp
->inf
->thread_waiting_for_vfork_done
)
3374 infrun_debug_printf ("[%s] another thread of this inferior is "
3375 "waiting for vfork-done",
3376 tp
->ptid
.to_string ().c_str ());
3380 infrun_debug_printf ("resuming %s",
3381 target_pid_to_str (tp
->ptid
).c_str ());
3383 reset_ecs (ecs
, tp
);
3384 switch_to_thread (tp
);
3385 keep_going_pass_signal (ecs
);
3386 if (!ecs
->wait_some_more
)
3387 error (_("Command aborted."));
3390 else if (!cur_thr
->resumed
3391 && !thread_is_in_step_over_chain (cur_thr
)
3392 /* In non-stop, forbid resume a thread if some other thread of
3393 that inferior is waiting for a vfork-done event (this means
3394 breakpoints are out for this inferior). */
3395 && !(non_stop
&& cur_thr
->inf
->thread_waiting_for_vfork_done
))
3397 /* The thread wasn't started, and isn't queued, run it now. */
3398 reset_ecs (ecs
, cur_thr
);
3399 switch_to_thread (cur_thr
);
3400 keep_going_pass_signal (ecs
);
3401 if (!ecs
->wait_some_more
)
3402 error (_("Command aborted."));
3405 disable_commit_resumed
.reset_and_commit ();
3408 finish_state
.release ();
3410 /* If we've switched threads above, switch back to the previously
3411 current thread. We don't want the user to see a different
3413 switch_to_thread (cur_thr
);
3415 /* Tell the event loop to wait for it to stop. If the target
3416 supports asynchronous execution, it'll do this from within
3418 if (!target_can_async_p ())
3419 mark_async_event_handler (infrun_async_inferior_event_token
);
3423 /* Start remote-debugging of a machine over a serial link. */
3426 start_remote (int from_tty
)
3428 inferior
*inf
= current_inferior ();
3429 inf
->control
.stop_soon
= STOP_QUIETLY_REMOTE
;
3431 /* Always go on waiting for the target, regardless of the mode. */
3432 /* FIXME: cagney/1999-09-23: At present it isn't possible to
3433 indicate to wait_for_inferior that a target should timeout if
3434 nothing is returned (instead of just blocking). Because of this,
3435 targets expecting an immediate response need to, internally, set
3436 things up so that the target_wait() is forced to eventually
3438 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
3439 differentiate to its caller what the state of the target is after
3440 the initial open has been performed. Here we're assuming that
3441 the target has stopped. It should be possible to eventually have
3442 target_open() return to the caller an indication that the target
3443 is currently running and GDB state should be set to the same as
3444 for an async run. */
3445 wait_for_inferior (inf
);
3447 /* Now that the inferior has stopped, do any bookkeeping like
3448 loading shared libraries. We want to do this before normal_stop,
3449 so that the displayed frame is up to date. */
3450 post_create_inferior (from_tty
);
3455 /* Initialize static vars when a new inferior begins. */
3458 init_wait_for_inferior (void)
3460 /* These are meaningless until the first time through wait_for_inferior. */
3462 breakpoint_init_inferior (inf_starting
);
3464 clear_proceed_status (0);
3466 nullify_last_target_wait_ptid ();
3468 previous_inferior_ptid
= inferior_ptid
;
3473 static void handle_inferior_event (struct execution_control_state
*ecs
);
3475 static void handle_step_into_function (struct gdbarch
*gdbarch
,
3476 struct execution_control_state
*ecs
);
3477 static void handle_step_into_function_backward (struct gdbarch
*gdbarch
,
3478 struct execution_control_state
*ecs
);
3479 static void handle_signal_stop (struct execution_control_state
*ecs
);
3480 static void check_exception_resume (struct execution_control_state
*,
3481 struct frame_info
*);
3483 static void end_stepping_range (struct execution_control_state
*ecs
);
3484 static void stop_waiting (struct execution_control_state
*ecs
);
3485 static void keep_going (struct execution_control_state
*ecs
);
3486 static void process_event_stop_test (struct execution_control_state
*ecs
);
3487 static bool switch_back_to_stepped_thread (struct execution_control_state
*ecs
);
3489 /* This function is attached as a "thread_stop_requested" observer.
3490 Cleanup local state that assumed the PTID was to be resumed, and
3491 report the stop to the frontend. */
3494 infrun_thread_stop_requested (ptid_t ptid
)
3496 process_stratum_target
*curr_target
= current_inferior ()->process_target ();
3498 /* PTID was requested to stop. If the thread was already stopped,
3499 but the user/frontend doesn't know about that yet (e.g., the
3500 thread had been temporarily paused for some step-over), set up
3501 for reporting the stop now. */
3502 for (thread_info
*tp
: all_threads (curr_target
, ptid
))
3504 if (tp
->state
!= THREAD_RUNNING
)
3509 /* Remove matching threads from the step-over queue, so
3510 start_step_over doesn't try to resume them
3512 if (thread_is_in_step_over_chain (tp
))
3513 global_thread_step_over_chain_remove (tp
);
3515 /* If the thread is stopped, but the user/frontend doesn't
3516 know about that yet, queue a pending event, as if the
3517 thread had just stopped now. Unless the thread already had
3519 if (!tp
->suspend
.waitstatus_pending_p
)
3521 tp
->suspend
.waitstatus_pending_p
= 1;
3522 tp
->suspend
.waitstatus
.kind
= TARGET_WAITKIND_STOPPED
;
3523 tp
->suspend
.waitstatus
.value
.sig
= GDB_SIGNAL_0
;
3526 /* Clear the inline-frame state, since we're re-processing the
3528 clear_inline_frame_state (tp
);
3530 /* If this thread was paused because some other thread was
3531 doing an inline-step over, let that finish first. Once
3532 that happens, we'll restart all threads and consume pending
3533 stop events then. */
3534 if (step_over_info_valid_p ())
3537 /* Otherwise we can process the (new) pending event now. Set
3538 it so this pending event is considered by
3545 infrun_thread_thread_exit (struct thread_info
*tp
, int silent
)
3547 if (target_last_proc_target
== tp
->inf
->process_target ()
3548 && target_last_wait_ptid
== tp
->ptid
)
3549 nullify_last_target_wait_ptid ();
3552 /* Delete the step resume, single-step and longjmp/exception resume
3553 breakpoints of TP. */
3556 delete_thread_infrun_breakpoints (struct thread_info
*tp
)
3558 delete_step_resume_breakpoint (tp
);
3559 delete_exception_resume_breakpoint (tp
);
3560 delete_single_step_breakpoints (tp
);
3563 /* If the target still has execution, call FUNC for each thread that
3564 just stopped. In all-stop, that's all the non-exited threads; in
3565 non-stop, that's the current thread, only. */
3567 typedef void (*for_each_just_stopped_thread_callback_func
)
3568 (struct thread_info
*tp
);
3571 for_each_just_stopped_thread (for_each_just_stopped_thread_callback_func func
)
3573 if (!target_has_execution () || inferior_ptid
== null_ptid
)
3576 if (target_is_non_stop_p ())
3578 /* If in non-stop mode, only the current thread stopped. */
3579 func (inferior_thread ());
3583 /* In all-stop mode, all threads have stopped. */
3584 for (thread_info
*tp
: all_non_exited_threads ())
3589 /* Delete the step resume and longjmp/exception resume breakpoints of
3590 the threads that just stopped. */
3593 delete_just_stopped_threads_infrun_breakpoints (void)
3595 for_each_just_stopped_thread (delete_thread_infrun_breakpoints
);
3598 /* Delete the single-step breakpoints of the threads that just
3602 delete_just_stopped_threads_single_step_breakpoints (void)
3604 for_each_just_stopped_thread (delete_single_step_breakpoints
);
3610 print_target_wait_results (ptid_t waiton_ptid
, ptid_t result_ptid
,
3611 const struct target_waitstatus
*ws
)
3613 infrun_debug_printf ("target_wait (%d.%ld.%ld [%s], status) =",
3617 target_pid_to_str (waiton_ptid
).c_str ());
3618 infrun_debug_printf (" %d.%ld.%ld [%s],",
3622 target_pid_to_str (result_ptid
).c_str ());
3623 infrun_debug_printf (" %s", target_waitstatus_to_string (ws
).c_str ());
3626 /* Select a thread at random, out of those which are resumed and have
3629 static struct thread_info
*
3630 random_pending_event_thread (inferior
*inf
, ptid_t waiton_ptid
)
3634 auto has_event
= [&] (thread_info
*tp
)
3636 return (tp
->ptid
.matches (waiton_ptid
)
3638 && tp
->suspend
.waitstatus_pending_p
);
3641 /* First see how many events we have. Count only resumed threads
3642 that have an event pending. */
3643 for (thread_info
*tp
: inf
->non_exited_threads ())
3647 if (num_events
== 0)
3650 /* Now randomly pick a thread out of those that have had events. */
3651 int random_selector
= (int) ((num_events
* (double) rand ())
3652 / (RAND_MAX
+ 1.0));
3655 infrun_debug_printf ("Found %d events, selecting #%d",
3656 num_events
, random_selector
);
3658 /* Select the Nth thread that has had an event. */
3659 for (thread_info
*tp
: inf
->non_exited_threads ())
3661 if (random_selector
-- == 0)
3664 gdb_assert_not_reached ("event thread not found");
3667 /* Wrapper for target_wait that first checks whether threads have
3668 pending statuses to report before actually asking the target for
3669 more events. INF is the inferior we're using to call target_wait
3673 do_target_wait_1 (inferior
*inf
, ptid_t ptid
,
3674 target_waitstatus
*status
, target_wait_flags options
)
3677 struct thread_info
*tp
;
3679 /* We know that we are looking for an event in the target of inferior
3680 INF, but we don't know which thread the event might come from. As
3681 such we want to make sure that INFERIOR_PTID is reset so that none of
3682 the wait code relies on it - doing so is always a mistake. */
3683 switch_to_inferior_no_thread (inf
);
3685 /* First check if there is a resumed thread with a wait status
3687 if (ptid
== minus_one_ptid
|| ptid
.is_pid ())
3689 tp
= random_pending_event_thread (inf
, ptid
);
3693 infrun_debug_printf ("Waiting for specific thread %s.",
3694 target_pid_to_str (ptid
).c_str ());
3696 /* We have a specific thread to check. */
3697 tp
= find_thread_ptid (inf
, ptid
);
3698 gdb_assert (tp
!= NULL
);
3699 if (!tp
->suspend
.waitstatus_pending_p
)
3704 && (tp
->suspend
.stop_reason
== TARGET_STOPPED_BY_SW_BREAKPOINT
3705 || tp
->suspend
.stop_reason
== TARGET_STOPPED_BY_HW_BREAKPOINT
))
3707 struct regcache
*regcache
= get_thread_regcache (tp
);
3708 struct gdbarch
*gdbarch
= regcache
->arch ();
3712 pc
= regcache_read_pc (regcache
);
3714 if (pc
!= tp
->suspend
.stop_pc
)
3716 infrun_debug_printf ("PC of %s changed. was=%s, now=%s",
3717 target_pid_to_str (tp
->ptid
).c_str (),
3718 paddress (gdbarch
, tp
->suspend
.stop_pc
),
3719 paddress (gdbarch
, pc
));
3722 else if (!breakpoint_inserted_here_p (regcache
->aspace (), pc
))
3724 infrun_debug_printf ("previous breakpoint of %s, at %s gone",
3725 target_pid_to_str (tp
->ptid
).c_str (),
3726 paddress (gdbarch
, pc
));
3733 infrun_debug_printf ("pending event of %s cancelled.",
3734 target_pid_to_str (tp
->ptid
).c_str ());
3736 tp
->suspend
.waitstatus
.kind
= TARGET_WAITKIND_SPURIOUS
;
3737 tp
->suspend
.stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
3743 infrun_debug_printf ("Using pending wait status %s for %s.",
3744 target_waitstatus_to_string
3745 (&tp
->suspend
.waitstatus
).c_str (),
3746 target_pid_to_str (tp
->ptid
).c_str ());
3748 /* Now that we've selected our final event LWP, un-adjust its PC
3749 if it was a software breakpoint (and the target doesn't
3750 always adjust the PC itself). */
3751 if (tp
->suspend
.stop_reason
== TARGET_STOPPED_BY_SW_BREAKPOINT
3752 && !target_supports_stopped_by_sw_breakpoint ())
3754 struct regcache
*regcache
;
3755 struct gdbarch
*gdbarch
;
3758 regcache
= get_thread_regcache (tp
);
3759 gdbarch
= regcache
->arch ();
3761 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
3766 pc
= regcache_read_pc (regcache
);
3767 regcache_write_pc (regcache
, pc
+ decr_pc
);
3771 tp
->suspend
.stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
3772 *status
= tp
->suspend
.waitstatus
;
3773 tp
->suspend
.waitstatus_pending_p
= 0;
3775 /* Wake up the event loop again, until all pending events are
3777 if (target_is_async_p ())
3778 mark_async_event_handler (infrun_async_inferior_event_token
);
3782 /* But if we don't find one, we'll have to wait. */
3784 /* We can't ask a non-async target to do a non-blocking wait, so this will be
3786 if (!target_can_async_p ())
3787 options
&= ~TARGET_WNOHANG
;
3789 if (deprecated_target_wait_hook
)
3790 event_ptid
= deprecated_target_wait_hook (ptid
, status
, options
);
3792 event_ptid
= target_wait (ptid
, status
, options
);
3797 /* Wrapper for target_wait that first checks whether threads have
3798 pending statuses to report before actually asking the target for
3799 more events. Polls for events from all inferiors/targets. */
3802 do_target_wait (execution_control_state
*ecs
, target_wait_flags options
)
3804 int num_inferiors
= 0;
3805 int random_selector
;
3807 /* For fairness, we pick the first inferior/target to poll at random
3808 out of all inferiors that may report events, and then continue
3809 polling the rest of the inferior list starting from that one in a
3810 circular fashion until the whole list is polled once. */
3812 auto inferior_matches
= [] (inferior
*inf
)
3814 return inf
->process_target () != nullptr;
3817 /* First see how many matching inferiors we have. */
3818 for (inferior
*inf
: all_inferiors ())
3819 if (inferior_matches (inf
))
3822 if (num_inferiors
== 0)
3824 ecs
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
3828 /* Now randomly pick an inferior out of those that matched. */
3829 random_selector
= (int)
3830 ((num_inferiors
* (double) rand ()) / (RAND_MAX
+ 1.0));
3832 if (num_inferiors
> 1)
3833 infrun_debug_printf ("Found %d inferiors, starting at #%d",
3834 num_inferiors
, random_selector
);
3836 /* Select the Nth inferior that matched. */
3838 inferior
*selected
= nullptr;
3840 for (inferior
*inf
: all_inferiors ())
3841 if (inferior_matches (inf
))
3842 if (random_selector
-- == 0)
3848 /* Now poll for events out of each of the matching inferior's
3849 targets, starting from the selected one. */
3851 auto do_wait
= [&] (inferior
*inf
)
3853 ecs
->ptid
= do_target_wait_1 (inf
, minus_one_ptid
, &ecs
->ws
, options
);
3854 ecs
->target
= inf
->process_target ();
3855 return (ecs
->ws
.kind
!= TARGET_WAITKIND_IGNORE
);
3858 /* Needed in 'all-stop + target-non-stop' mode, because we end up
3859 here spuriously after the target is all stopped and we've already
3860 reported the stop to the user, polling for events. */
3861 scoped_restore_current_thread restore_thread
;
3863 int inf_num
= selected
->num
;
3864 for (inferior
*inf
= selected
; inf
!= NULL
; inf
= inf
->next
)
3865 if (inferior_matches (inf
))
3869 for (inferior
*inf
= inferior_list
;
3870 inf
!= NULL
&& inf
->num
< inf_num
;
3872 if (inferior_matches (inf
))
3876 ecs
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
3880 /* An event reported by wait_one. */
3882 struct wait_one_event
3884 /* The target the event came out of. */
3885 process_stratum_target
*target
;
3887 /* The PTID the event was for. */
3890 /* The waitstatus. */
3891 target_waitstatus ws
;
3894 static bool handle_one (const wait_one_event
&event
);
3896 /* Prepare and stabilize the inferior for detaching it. E.g.,
3897 detaching while a thread is displaced stepping is a recipe for
3898 crashing it, as nothing would readjust the PC out of the scratch
3902 prepare_for_detach (void)
3904 struct inferior
*inf
= current_inferior ();
3905 ptid_t pid_ptid
= ptid_t (inf
->pid
);
3906 scoped_restore_current_thread restore_thread
;
3908 scoped_restore restore_detaching
= make_scoped_restore (&inf
->detaching
, true);
3910 /* Remove all threads of INF from the global step-over chain. We
3911 want to stop any ongoing step-over, not start any new one. */
3913 for (thread_info
*tp
= global_thread_step_over_chain_head
;
3917 next
= global_thread_step_over_chain_next (tp
);
3919 global_thread_step_over_chain_remove (tp
);
3922 /* If we were already in the middle of an inline step-over, and the
3923 thread stepping belongs to the inferior we're detaching, we need
3924 to restart the threads of other inferiors. */
3925 if (step_over_info
.thread
!= -1)
3927 infrun_debug_printf ("inline step-over in-process while detaching");
3929 thread_info
*thr
= find_thread_global_id (step_over_info
.thread
);
3930 if (thr
->inf
== inf
)
3932 /* Since we removed threads of INF from the step-over chain,
3933 we know this won't start a step-over for INF. */
3934 clear_step_over_info ();
3936 if (target_is_non_stop_p ())
3938 /* Start a new step-over in another thread if there's
3939 one that needs it. */
3942 /* Restart all other threads (except the
3943 previously-stepping thread, since that one is still
3945 if (!step_over_info_valid_p ())
3946 restart_threads (thr
);
3951 if (displaced_step_in_progress (inf
))
3953 infrun_debug_printf ("displaced-stepping in-process while detaching");
3955 /* Stop threads currently displaced stepping, aborting it. */
3957 for (thread_info
*thr
: inf
->non_exited_threads ())
3959 if (thr
->displaced_step_state
.in_progress ())
3963 if (!thr
->stop_requested
)
3965 target_stop (thr
->ptid
);
3966 thr
->stop_requested
= true;
3970 thr
->resumed
= false;
3974 while (displaced_step_in_progress (inf
))
3976 wait_one_event event
;
3978 event
.target
= inf
->process_target ();
3979 event
.ptid
= do_target_wait_1 (inf
, pid_ptid
, &event
.ws
, 0);
3982 print_target_wait_results (pid_ptid
, event
.ptid
, &event
.ws
);
3987 /* It's OK to leave some of the threads of INF stopped, since
3988 they'll be detached shortly. */
3992 /* Wait for control to return from inferior to debugger.
3994 If inferior gets a signal, we may decide to start it up again
3995 instead of returning. That is why there is a loop in this function.
3996 When this function actually returns it means the inferior
3997 should be left stopped and GDB should read more commands. */
4000 wait_for_inferior (inferior
*inf
)
4002 infrun_debug_printf ("wait_for_inferior ()");
4004 SCOPE_EXIT
{ delete_just_stopped_threads_infrun_breakpoints (); };
4006 /* If an error happens while handling the event, propagate GDB's
4007 knowledge of the executing state to the frontend/user running
4009 scoped_finish_thread_state finish_state
4010 (inf
->process_target (), minus_one_ptid
);
4014 struct execution_control_state ecss
;
4015 struct execution_control_state
*ecs
= &ecss
;
4017 memset (ecs
, 0, sizeof (*ecs
));
4019 overlay_cache_invalid
= 1;
4021 /* Flush target cache before starting to handle each event.
4022 Target was running and cache could be stale. This is just a
4023 heuristic. Running threads may modify target memory, but we
4024 don't get any event. */
4025 target_dcache_invalidate ();
4027 ecs
->ptid
= do_target_wait_1 (inf
, minus_one_ptid
, &ecs
->ws
, 0);
4028 ecs
->target
= inf
->process_target ();
4031 print_target_wait_results (minus_one_ptid
, ecs
->ptid
, &ecs
->ws
);
4033 /* Now figure out what to do with the result of the result. */
4034 handle_inferior_event (ecs
);
4036 if (!ecs
->wait_some_more
)
4040 /* No error, don't finish the state yet. */
4041 finish_state
.release ();
4044 /* Cleanup that reinstalls the readline callback handler, if the
4045 target is running in the background. If while handling the target
4046 event something triggered a secondary prompt, like e.g., a
4047 pagination prompt, we'll have removed the callback handler (see
4048 gdb_readline_wrapper_line). Need to do this as we go back to the
4049 event loop, ready to process further input. Note this has no
4050 effect if the handler hasn't actually been removed, because calling
4051 rl_callback_handler_install resets the line buffer, thus losing
4055 reinstall_readline_callback_handler_cleanup ()
4057 struct ui
*ui
= current_ui
;
4061 /* We're not going back to the top level event loop yet. Don't
4062 install the readline callback, as it'd prep the terminal,
4063 readline-style (raw, noecho) (e.g., --batch). We'll install
4064 it the next time the prompt is displayed, when we're ready
4069 if (ui
->command_editing
&& ui
->prompt_state
!= PROMPT_BLOCKED
)
4070 gdb_rl_callback_handler_reinstall ();
4073 /* Clean up the FSMs of threads that are now stopped. In non-stop,
4074 that's just the event thread. In all-stop, that's all threads. */
4077 clean_up_just_stopped_threads_fsms (struct execution_control_state
*ecs
)
4079 if (ecs
->event_thread
!= NULL
4080 && ecs
->event_thread
->thread_fsm
!= NULL
)
4081 ecs
->event_thread
->thread_fsm
->clean_up (ecs
->event_thread
);
4085 for (thread_info
*thr
: all_non_exited_threads ())
4087 if (thr
->thread_fsm
== NULL
)
4089 if (thr
== ecs
->event_thread
)
4092 switch_to_thread (thr
);
4093 thr
->thread_fsm
->clean_up (thr
);
4096 if (ecs
->event_thread
!= NULL
)
4097 switch_to_thread (ecs
->event_thread
);
4101 /* Helper for all_uis_check_sync_execution_done that works on the
4105 check_curr_ui_sync_execution_done (void)
4107 struct ui
*ui
= current_ui
;
4109 if (ui
->prompt_state
== PROMPT_NEEDED
4111 && !gdb_in_secondary_prompt_p (ui
))
4113 target_terminal::ours ();
4114 gdb::observers::sync_execution_done
.notify ();
4115 ui_register_input_event_handler (ui
);
4122 all_uis_check_sync_execution_done (void)
4124 SWITCH_THRU_ALL_UIS ()
4126 check_curr_ui_sync_execution_done ();
4133 all_uis_on_sync_execution_starting (void)
4135 SWITCH_THRU_ALL_UIS ()
4137 if (current_ui
->prompt_state
== PROMPT_NEEDED
)
4138 async_disable_stdin ();
4142 /* Asynchronous version of wait_for_inferior. It is called by the
4143 event loop whenever a change of state is detected on the file
4144 descriptor corresponding to the target. It can be called more than
4145 once to complete a single execution command. In such cases we need
4146 to keep the state in a global variable ECSS. If it is the last time
4147 that this function is called for a single execution command, then
4148 report to the user that the inferior has stopped, and do the
4149 necessary cleanups. */
4152 fetch_inferior_event ()
4154 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
4156 struct execution_control_state ecss
;
4157 struct execution_control_state
*ecs
= &ecss
;
4160 memset (ecs
, 0, sizeof (*ecs
));
4162 /* Events are always processed with the main UI as current UI. This
4163 way, warnings, debug output, etc. are always consistently sent to
4164 the main console. */
4165 scoped_restore save_ui
= make_scoped_restore (¤t_ui
, main_ui
);
4167 /* Temporarily disable pagination. Otherwise, the user would be
4168 given an option to press 'q' to quit, which would cause an early
4169 exit and could leave GDB in a half-baked state. */
4170 scoped_restore save_pagination
4171 = make_scoped_restore (&pagination_enabled
, false);
4173 /* End up with readline processing input, if necessary. */
4175 SCOPE_EXIT
{ reinstall_readline_callback_handler_cleanup (); };
4177 /* We're handling a live event, so make sure we're doing live
4178 debugging. If we're looking at traceframes while the target is
4179 running, we're going to need to get back to that mode after
4180 handling the event. */
4181 gdb::optional
<scoped_restore_current_traceframe
> maybe_restore_traceframe
;
4184 maybe_restore_traceframe
.emplace ();
4185 set_current_traceframe (-1);
4188 /* The user/frontend should not notice a thread switch due to
4189 internal events. Make sure we revert to the user selected
4190 thread and frame after handling the event and running any
4191 breakpoint commands. */
4192 scoped_restore_current_thread restore_thread
;
4194 overlay_cache_invalid
= 1;
4195 /* Flush target cache before starting to handle each event. Target
4196 was running and cache could be stale. This is just a heuristic.
4197 Running threads may modify target memory, but we don't get any
4199 target_dcache_invalidate ();
4201 scoped_restore save_exec_dir
4202 = make_scoped_restore (&execution_direction
,
4203 target_execution_direction ());
4205 /* Allow targets to pause their resumed threads while we handle
4207 scoped_disable_commit_resumed
disable_commit_resumed ("handling event");
4209 if (!do_target_wait (ecs
, TARGET_WNOHANG
))
4211 infrun_debug_printf ("do_target_wait returned no event");
4212 disable_commit_resumed
.reset_and_commit ();
4216 gdb_assert (ecs
->ws
.kind
!= TARGET_WAITKIND_IGNORE
);
4218 /* Switch to the target that generated the event, so we can do
4220 switch_to_target_no_thread (ecs
->target
);
4223 print_target_wait_results (minus_one_ptid
, ecs
->ptid
, &ecs
->ws
);
4225 /* If an error happens while handling the event, propagate GDB's
4226 knowledge of the executing state to the frontend/user running
4228 ptid_t finish_ptid
= !target_is_non_stop_p () ? minus_one_ptid
: ecs
->ptid
;
4229 scoped_finish_thread_state
finish_state (ecs
->target
, finish_ptid
);
4231 /* Get executed before scoped_restore_current_thread above to apply
4232 still for the thread which has thrown the exception. */
4233 auto defer_bpstat_clear
4234 = make_scope_exit (bpstat_clear_actions
);
4235 auto defer_delete_threads
4236 = make_scope_exit (delete_just_stopped_threads_infrun_breakpoints
);
4238 /* Now figure out what to do with the result of the result. */
4239 handle_inferior_event (ecs
);
4241 if (!ecs
->wait_some_more
)
4243 struct inferior
*inf
= find_inferior_ptid (ecs
->target
, ecs
->ptid
);
4244 bool should_stop
= true;
4245 struct thread_info
*thr
= ecs
->event_thread
;
4247 delete_just_stopped_threads_infrun_breakpoints ();
4251 struct thread_fsm
*thread_fsm
= thr
->thread_fsm
;
4253 if (thread_fsm
!= NULL
)
4254 should_stop
= thread_fsm
->should_stop (thr
);
4263 bool should_notify_stop
= true;
4266 clean_up_just_stopped_threads_fsms (ecs
);
4268 if (thr
!= NULL
&& thr
->thread_fsm
!= NULL
)
4269 should_notify_stop
= thr
->thread_fsm
->should_notify_stop ();
4271 if (should_notify_stop
)
4273 /* We may not find an inferior if this was a process exit. */
4274 if (inf
== NULL
|| inf
->control
.stop_soon
== NO_STOP_QUIETLY
)
4275 proceeded
= normal_stop ();
4280 inferior_event_handler (INF_EXEC_COMPLETE
);
4284 /* If we got a TARGET_WAITKIND_NO_RESUMED event, then the
4285 previously selected thread is gone. We have two
4286 choices - switch to no thread selected, or restore the
4287 previously selected thread (now exited). We chose the
4288 later, just because that's what GDB used to do. After
4289 this, "info threads" says "The current thread <Thread
4290 ID 2> has terminated." instead of "No thread
4294 && ecs
->ws
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
4295 restore_thread
.dont_restore ();
4299 defer_delete_threads
.release ();
4300 defer_bpstat_clear
.release ();
4302 /* No error, don't finish the thread states yet. */
4303 finish_state
.release ();
4305 disable_commit_resumed
.reset_and_commit ();
4307 /* This scope is used to ensure that readline callbacks are
4308 reinstalled here. */
4311 /* If a UI was in sync execution mode, and now isn't, restore its
4312 prompt (a synchronous execution command has finished, and we're
4313 ready for input). */
4314 all_uis_check_sync_execution_done ();
4317 && exec_done_display_p
4318 && (inferior_ptid
== null_ptid
4319 || inferior_thread ()->state
!= THREAD_RUNNING
))
4320 printf_unfiltered (_("completed.\n"));
4326 set_step_info (thread_info
*tp
, struct frame_info
*frame
,
4327 struct symtab_and_line sal
)
4329 /* This can be removed once this function no longer implicitly relies on the
4330 inferior_ptid value. */
4331 gdb_assert (inferior_ptid
== tp
->ptid
);
4333 tp
->control
.step_frame_id
= get_frame_id (frame
);
4334 tp
->control
.step_stack_frame_id
= get_stack_frame_id (frame
);
4336 tp
->current_symtab
= sal
.symtab
;
4337 tp
->current_line
= sal
.line
;
4340 /* Clear context switchable stepping state. */
4343 init_thread_stepping_state (struct thread_info
*tss
)
4345 tss
->stepped_breakpoint
= 0;
4346 tss
->stepping_over_breakpoint
= 0;
4347 tss
->stepping_over_watchpoint
= 0;
4348 tss
->step_after_step_resume_breakpoint
= 0;
4354 set_last_target_status (process_stratum_target
*target
, ptid_t ptid
,
4355 target_waitstatus status
)
4357 target_last_proc_target
= target
;
4358 target_last_wait_ptid
= ptid
;
4359 target_last_waitstatus
= status
;
4365 get_last_target_status (process_stratum_target
**target
, ptid_t
*ptid
,
4366 target_waitstatus
*status
)
4368 if (target
!= nullptr)
4369 *target
= target_last_proc_target
;
4370 if (ptid
!= nullptr)
4371 *ptid
= target_last_wait_ptid
;
4372 if (status
!= nullptr)
4373 *status
= target_last_waitstatus
;
4379 nullify_last_target_wait_ptid (void)
4381 target_last_proc_target
= nullptr;
4382 target_last_wait_ptid
= minus_one_ptid
;
4383 target_last_waitstatus
= {};
4386 /* Switch thread contexts. */
4389 context_switch (execution_control_state
*ecs
)
4391 if (ecs
->ptid
!= inferior_ptid
4392 && (inferior_ptid
== null_ptid
4393 || ecs
->event_thread
!= inferior_thread ()))
4395 infrun_debug_printf ("Switching context from %s to %s",
4396 target_pid_to_str (inferior_ptid
).c_str (),
4397 target_pid_to_str (ecs
->ptid
).c_str ());
4400 switch_to_thread (ecs
->event_thread
);
4403 /* If the target can't tell whether we've hit breakpoints
4404 (target_supports_stopped_by_sw_breakpoint), and we got a SIGTRAP,
4405 check whether that could have been caused by a breakpoint. If so,
4406 adjust the PC, per gdbarch_decr_pc_after_break. */
4409 adjust_pc_after_break (struct thread_info
*thread
,
4410 struct target_waitstatus
*ws
)
4412 struct regcache
*regcache
;
4413 struct gdbarch
*gdbarch
;
4414 CORE_ADDR breakpoint_pc
, decr_pc
;
4416 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
4417 we aren't, just return.
4419 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
4420 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
4421 implemented by software breakpoints should be handled through the normal
4424 NOTE drow/2004-01-31: On some targets, breakpoints may generate
4425 different signals (SIGILL or SIGEMT for instance), but it is less
4426 clear where the PC is pointing afterwards. It may not match
4427 gdbarch_decr_pc_after_break. I don't know any specific target that
4428 generates these signals at breakpoints (the code has been in GDB since at
4429 least 1992) so I can not guess how to handle them here.
4431 In earlier versions of GDB, a target with
4432 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
4433 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
4434 target with both of these set in GDB history, and it seems unlikely to be
4435 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
4437 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
)
4440 if (ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
4443 /* In reverse execution, when a breakpoint is hit, the instruction
4444 under it has already been de-executed. The reported PC always
4445 points at the breakpoint address, so adjusting it further would
4446 be wrong. E.g., consider this case on a decr_pc_after_break == 1
4449 B1 0x08000000 : INSN1
4450 B2 0x08000001 : INSN2
4452 PC -> 0x08000003 : INSN4
4454 Say you're stopped at 0x08000003 as above. Reverse continuing
4455 from that point should hit B2 as below. Reading the PC when the
4456 SIGTRAP is reported should read 0x08000001 and INSN2 should have
4457 been de-executed already.
4459 B1 0x08000000 : INSN1
4460 B2 PC -> 0x08000001 : INSN2
4464 We can't apply the same logic as for forward execution, because
4465 we would wrongly adjust the PC to 0x08000000, since there's a
4466 breakpoint at PC - 1. We'd then report a hit on B1, although
4467 INSN1 hadn't been de-executed yet. Doing nothing is the correct
4469 if (execution_direction
== EXEC_REVERSE
)
4472 /* If the target can tell whether the thread hit a SW breakpoint,
4473 trust it. Targets that can tell also adjust the PC
4475 if (target_supports_stopped_by_sw_breakpoint ())
4478 /* Note that relying on whether a breakpoint is planted in memory to
4479 determine this can fail. E.g,. the breakpoint could have been
4480 removed since. Or the thread could have been told to step an
4481 instruction the size of a breakpoint instruction, and only
4482 _after_ was a breakpoint inserted at its address. */
4484 /* If this target does not decrement the PC after breakpoints, then
4485 we have nothing to do. */
4486 regcache
= get_thread_regcache (thread
);
4487 gdbarch
= regcache
->arch ();
4489 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
4493 const address_space
*aspace
= regcache
->aspace ();
4495 /* Find the location where (if we've hit a breakpoint) the
4496 breakpoint would be. */
4497 breakpoint_pc
= regcache_read_pc (regcache
) - decr_pc
;
4499 /* If the target can't tell whether a software breakpoint triggered,
4500 fallback to figuring it out based on breakpoints we think were
4501 inserted in the target, and on whether the thread was stepped or
4504 /* Check whether there actually is a software breakpoint inserted at
4507 If in non-stop mode, a race condition is possible where we've
4508 removed a breakpoint, but stop events for that breakpoint were
4509 already queued and arrive later. To suppress those spurious
4510 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
4511 and retire them after a number of stop events are reported. Note
4512 this is an heuristic and can thus get confused. The real fix is
4513 to get the "stopped by SW BP and needs adjustment" info out of
4514 the target/kernel (and thus never reach here; see above). */
4515 if (software_breakpoint_inserted_here_p (aspace
, breakpoint_pc
)
4516 || (target_is_non_stop_p ()
4517 && moribund_breakpoint_here_p (aspace
, breakpoint_pc
)))
4519 gdb::optional
<scoped_restore_tmpl
<int>> restore_operation_disable
;
4521 if (record_full_is_used ())
4522 restore_operation_disable
.emplace
4523 (record_full_gdb_operation_disable_set ());
4525 /* When using hardware single-step, a SIGTRAP is reported for both
4526 a completed single-step and a software breakpoint. Need to
4527 differentiate between the two, as the latter needs adjusting
4528 but the former does not.
4530 The SIGTRAP can be due to a completed hardware single-step only if
4531 - we didn't insert software single-step breakpoints
4532 - this thread is currently being stepped
4534 If any of these events did not occur, we must have stopped due
4535 to hitting a software breakpoint, and have to back up to the
4538 As a special case, we could have hardware single-stepped a
4539 software breakpoint. In this case (prev_pc == breakpoint_pc),
4540 we also need to back up to the breakpoint address. */
4542 if (thread_has_single_step_breakpoints_set (thread
)
4543 || !currently_stepping (thread
)
4544 || (thread
->stepped_breakpoint
4545 && thread
->prev_pc
== breakpoint_pc
))
4546 regcache_write_pc (regcache
, breakpoint_pc
);
4551 stepped_in_from (struct frame_info
*frame
, struct frame_id step_frame_id
)
4553 for (frame
= get_prev_frame (frame
);
4555 frame
= get_prev_frame (frame
))
4557 if (frame_id_eq (get_frame_id (frame
), step_frame_id
))
4560 if (get_frame_type (frame
) != INLINE_FRAME
)
4567 /* Look for an inline frame that is marked for skip.
4568 If PREV_FRAME is TRUE start at the previous frame,
4569 otherwise start at the current frame. Stop at the
4570 first non-inline frame, or at the frame where the
4574 inline_frame_is_marked_for_skip (bool prev_frame
, struct thread_info
*tp
)
4576 struct frame_info
*frame
= get_current_frame ();
4579 frame
= get_prev_frame (frame
);
4581 for (; frame
!= NULL
; frame
= get_prev_frame (frame
))
4583 const char *fn
= NULL
;
4584 symtab_and_line sal
;
4587 if (frame_id_eq (get_frame_id (frame
), tp
->control
.step_frame_id
))
4589 if (get_frame_type (frame
) != INLINE_FRAME
)
4592 sal
= find_frame_sal (frame
);
4593 sym
= get_frame_function (frame
);
4596 fn
= sym
->print_name ();
4599 && function_name_is_marked_for_skip (fn
, sal
))
4606 /* If the event thread has the stop requested flag set, pretend it
4607 stopped for a GDB_SIGNAL_0 (i.e., as if it stopped due to
4611 handle_stop_requested (struct execution_control_state
*ecs
)
4613 if (ecs
->event_thread
->stop_requested
)
4615 ecs
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
4616 ecs
->ws
.value
.sig
= GDB_SIGNAL_0
;
4617 handle_signal_stop (ecs
);
4623 /* Auxiliary function that handles syscall entry/return events.
4624 It returns true if the inferior should keep going (and GDB
4625 should ignore the event), or false if the event deserves to be
4629 handle_syscall_event (struct execution_control_state
*ecs
)
4631 struct regcache
*regcache
;
4634 context_switch (ecs
);
4636 regcache
= get_thread_regcache (ecs
->event_thread
);
4637 syscall_number
= ecs
->ws
.value
.syscall_number
;
4638 ecs
->event_thread
->suspend
.stop_pc
= regcache_read_pc (regcache
);
4640 if (catch_syscall_enabled () > 0
4641 && catching_syscall_number (syscall_number
) > 0)
4643 infrun_debug_printf ("syscall number=%d", syscall_number
);
4645 ecs
->event_thread
->control
.stop_bpstat
4646 = bpstat_stop_status (regcache
->aspace (),
4647 ecs
->event_thread
->suspend
.stop_pc
,
4648 ecs
->event_thread
, &ecs
->ws
);
4650 if (handle_stop_requested (ecs
))
4653 if (bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
4655 /* Catchpoint hit. */
4660 if (handle_stop_requested (ecs
))
4663 /* If no catchpoint triggered for this, then keep going. */
4669 /* Lazily fill in the execution_control_state's stop_func_* fields. */
4672 fill_in_stop_func (struct gdbarch
*gdbarch
,
4673 struct execution_control_state
*ecs
)
4675 if (!ecs
->stop_func_filled_in
)
4678 const general_symbol_info
*gsi
;
4680 /* Don't care about return value; stop_func_start and stop_func_name
4681 will both be 0 if it doesn't work. */
4682 find_pc_partial_function_sym (ecs
->event_thread
->suspend
.stop_pc
,
4684 &ecs
->stop_func_start
,
4685 &ecs
->stop_func_end
,
4687 ecs
->stop_func_name
= gsi
== nullptr ? nullptr : gsi
->print_name ();
4689 /* The call to find_pc_partial_function, above, will set
4690 stop_func_start and stop_func_end to the start and end
4691 of the range containing the stop pc. If this range
4692 contains the entry pc for the block (which is always the
4693 case for contiguous blocks), advance stop_func_start past
4694 the function's start offset and entrypoint. Note that
4695 stop_func_start is NOT advanced when in a range of a
4696 non-contiguous block that does not contain the entry pc. */
4697 if (block
!= nullptr
4698 && ecs
->stop_func_start
<= BLOCK_ENTRY_PC (block
)
4699 && BLOCK_ENTRY_PC (block
) < ecs
->stop_func_end
)
4701 ecs
->stop_func_start
4702 += gdbarch_deprecated_function_start_offset (gdbarch
);
4704 if (gdbarch_skip_entrypoint_p (gdbarch
))
4705 ecs
->stop_func_start
4706 = gdbarch_skip_entrypoint (gdbarch
, ecs
->stop_func_start
);
4709 ecs
->stop_func_filled_in
= 1;
4714 /* Return the STOP_SOON field of the inferior pointed at by ECS. */
4716 static enum stop_kind
4717 get_inferior_stop_soon (execution_control_state
*ecs
)
4719 struct inferior
*inf
= find_inferior_ptid (ecs
->target
, ecs
->ptid
);
4721 gdb_assert (inf
!= NULL
);
4722 return inf
->control
.stop_soon
;
4725 /* Poll for one event out of the current target. Store the resulting
4726 waitstatus in WS, and return the event ptid. Does not block. */
4729 poll_one_curr_target (struct target_waitstatus
*ws
)
4733 overlay_cache_invalid
= 1;
4735 /* Flush target cache before starting to handle each event.
4736 Target was running and cache could be stale. This is just a
4737 heuristic. Running threads may modify target memory, but we
4738 don't get any event. */
4739 target_dcache_invalidate ();
4741 if (deprecated_target_wait_hook
)
4742 event_ptid
= deprecated_target_wait_hook (minus_one_ptid
, ws
, TARGET_WNOHANG
);
4744 event_ptid
= target_wait (minus_one_ptid
, ws
, TARGET_WNOHANG
);
4747 print_target_wait_results (minus_one_ptid
, event_ptid
, ws
);
4752 /* Wait for one event out of any target. */
4754 static wait_one_event
4759 for (inferior
*inf
: all_inferiors ())
4761 process_stratum_target
*target
= inf
->process_target ();
4763 || !target
->is_async_p ()
4764 || !target
->threads_executing
)
4767 switch_to_inferior_no_thread (inf
);
4769 wait_one_event event
;
4770 event
.target
= target
;
4771 event
.ptid
= poll_one_curr_target (&event
.ws
);
4773 if (event
.ws
.kind
== TARGET_WAITKIND_NO_RESUMED
)
4775 /* If nothing is resumed, remove the target from the
4779 else if (event
.ws
.kind
!= TARGET_WAITKIND_IGNORE
)
4783 /* Block waiting for some event. */
4790 for (inferior
*inf
: all_inferiors ())
4792 process_stratum_target
*target
= inf
->process_target ();
4794 || !target
->is_async_p ()
4795 || !target
->threads_executing
)
4798 int fd
= target
->async_wait_fd ();
4799 FD_SET (fd
, &readfds
);
4806 /* No waitable targets left. All must be stopped. */
4807 return {NULL
, minus_one_ptid
, {TARGET_WAITKIND_NO_RESUMED
}};
4812 int numfds
= interruptible_select (nfds
, &readfds
, 0, NULL
, 0);
4818 perror_with_name ("interruptible_select");
4823 /* Save the thread's event and stop reason to process it later. */
4826 save_waitstatus (struct thread_info
*tp
, const target_waitstatus
*ws
)
4828 infrun_debug_printf ("saving status %s for %d.%ld.%ld",
4829 target_waitstatus_to_string (ws
).c_str (),
4834 /* Record for later. */
4835 tp
->suspend
.waitstatus
= *ws
;
4836 tp
->suspend
.waitstatus_pending_p
= 1;
4838 if (ws
->kind
== TARGET_WAITKIND_STOPPED
4839 && ws
->value
.sig
== GDB_SIGNAL_TRAP
)
4841 struct regcache
*regcache
= get_thread_regcache (tp
);
4842 const address_space
*aspace
= regcache
->aspace ();
4843 CORE_ADDR pc
= regcache_read_pc (regcache
);
4845 adjust_pc_after_break (tp
, &tp
->suspend
.waitstatus
);
4847 scoped_restore_current_thread restore_thread
;
4848 switch_to_thread (tp
);
4850 if (target_stopped_by_watchpoint ())
4852 tp
->suspend
.stop_reason
4853 = TARGET_STOPPED_BY_WATCHPOINT
;
4855 else if (target_supports_stopped_by_sw_breakpoint ()
4856 && target_stopped_by_sw_breakpoint ())
4858 tp
->suspend
.stop_reason
4859 = TARGET_STOPPED_BY_SW_BREAKPOINT
;
4861 else if (target_supports_stopped_by_hw_breakpoint ()
4862 && target_stopped_by_hw_breakpoint ())
4864 tp
->suspend
.stop_reason
4865 = TARGET_STOPPED_BY_HW_BREAKPOINT
;
4867 else if (!target_supports_stopped_by_hw_breakpoint ()
4868 && hardware_breakpoint_inserted_here_p (aspace
,
4871 tp
->suspend
.stop_reason
4872 = TARGET_STOPPED_BY_HW_BREAKPOINT
;
4874 else if (!target_supports_stopped_by_sw_breakpoint ()
4875 && software_breakpoint_inserted_here_p (aspace
,
4878 tp
->suspend
.stop_reason
4879 = TARGET_STOPPED_BY_SW_BREAKPOINT
;
4881 else if (!thread_has_single_step_breakpoints_set (tp
)
4882 && currently_stepping (tp
))
4884 tp
->suspend
.stop_reason
4885 = TARGET_STOPPED_BY_SINGLE_STEP
;
4890 /* Mark the non-executing threads accordingly. In all-stop, all
4891 threads of all processes are stopped when we get any event
4892 reported. In non-stop mode, only the event thread stops. */
4895 mark_non_executing_threads (process_stratum_target
*target
,
4897 struct target_waitstatus ws
)
4901 if (!target_is_non_stop_p ())
4902 mark_ptid
= minus_one_ptid
;
4903 else if (ws
.kind
== TARGET_WAITKIND_SIGNALLED
4904 || ws
.kind
== TARGET_WAITKIND_EXITED
)
4906 /* If we're handling a process exit in non-stop mode, even
4907 though threads haven't been deleted yet, one would think
4908 that there is nothing to do, as threads of the dead process
4909 will be soon deleted, and threads of any other process were
4910 left running. However, on some targets, threads survive a
4911 process exit event. E.g., for the "checkpoint" command,
4912 when the current checkpoint/fork exits, linux-fork.c
4913 automatically switches to another fork from within
4914 target_mourn_inferior, by associating the same
4915 inferior/thread to another fork. We haven't mourned yet at
4916 this point, but we must mark any threads left in the
4917 process as not-executing so that finish_thread_state marks
4918 them stopped (in the user's perspective) if/when we present
4919 the stop to the user. */
4920 mark_ptid
= ptid_t (event_ptid
.pid ());
4923 mark_ptid
= event_ptid
;
4925 set_executing (target
, mark_ptid
, false);
4927 /* Likewise the resumed flag. */
4928 set_resumed (target
, mark_ptid
, false);
4931 /* Handle one event after stopping threads. If the eventing thread
4932 reports back any interesting event, we leave it pending. If the
4933 eventing thread was in the middle of a displaced step, we
4934 cancel/finish it, and unless the thread's inferior is being
4935 detached, put the thread back in the step-over chain. Returns true
4936 if there are no resumed threads left in the target (thus there's no
4937 point in waiting further), false otherwise. */
4940 handle_one (const wait_one_event
&event
)
4943 ("%s %s", target_waitstatus_to_string (&event
.ws
).c_str (),
4944 target_pid_to_str (event
.ptid
).c_str ());
4946 if (event
.ws
.kind
== TARGET_WAITKIND_NO_RESUMED
)
4948 /* All resumed threads exited. */
4951 else if (event
.ws
.kind
== TARGET_WAITKIND_THREAD_EXITED
4952 || event
.ws
.kind
== TARGET_WAITKIND_EXITED
4953 || event
.ws
.kind
== TARGET_WAITKIND_SIGNALLED
)
4955 /* One thread/process exited/signalled. */
4957 thread_info
*t
= nullptr;
4959 /* The target may have reported just a pid. If so, try
4960 the first non-exited thread. */
4961 if (event
.ptid
.is_pid ())
4963 int pid
= event
.ptid
.pid ();
4964 inferior
*inf
= find_inferior_pid (event
.target
, pid
);
4965 for (thread_info
*tp
: inf
->non_exited_threads ())
4971 /* If there is no available thread, the event would
4972 have to be appended to a per-inferior event list,
4973 which does not exist (and if it did, we'd have
4974 to adjust run control command to be able to
4975 resume such an inferior). We assert here instead
4976 of going into an infinite loop. */
4977 gdb_assert (t
!= nullptr);
4980 ("using %s", target_pid_to_str (t
->ptid
).c_str ());
4984 t
= find_thread_ptid (event
.target
, event
.ptid
);
4985 /* Check if this is the first time we see this thread.
4986 Don't bother adding if it individually exited. */
4988 && event
.ws
.kind
!= TARGET_WAITKIND_THREAD_EXITED
)
4989 t
= add_thread (event
.target
, event
.ptid
);
4994 /* Set the threads as non-executing to avoid
4995 another stop attempt on them. */
4996 switch_to_thread_no_regs (t
);
4997 mark_non_executing_threads (event
.target
, event
.ptid
,
4999 save_waitstatus (t
, &event
.ws
);
5000 t
->stop_requested
= false;
5005 thread_info
*t
= find_thread_ptid (event
.target
, event
.ptid
);
5007 t
= add_thread (event
.target
, event
.ptid
);
5009 t
->stop_requested
= 0;
5012 t
->control
.may_range_step
= 0;
5014 /* This may be the first time we see the inferior report
5016 inferior
*inf
= find_inferior_ptid (event
.target
, event
.ptid
);
5017 if (inf
->needs_setup
)
5019 switch_to_thread_no_regs (t
);
5023 if (event
.ws
.kind
== TARGET_WAITKIND_STOPPED
5024 && event
.ws
.value
.sig
== GDB_SIGNAL_0
)
5026 /* We caught the event that we intended to catch, so
5027 there's no event pending. */
5028 t
->suspend
.waitstatus
.kind
= TARGET_WAITKIND_IGNORE
;
5029 t
->suspend
.waitstatus_pending_p
= 0;
5031 if (displaced_step_finish (t
, GDB_SIGNAL_0
)
5032 == DISPLACED_STEP_FINISH_STATUS_NOT_EXECUTED
)
5034 /* Add it back to the step-over queue. */
5036 ("displaced-step of %s canceled",
5037 target_pid_to_str (t
->ptid
).c_str ());
5039 t
->control
.trap_expected
= 0;
5040 if (!t
->inf
->detaching
)
5041 global_thread_step_over_chain_enqueue (t
);
5046 enum gdb_signal sig
;
5047 struct regcache
*regcache
;
5050 ("target_wait %s, saving status for %d.%ld.%ld",
5051 target_waitstatus_to_string (&event
.ws
).c_str (),
5052 t
->ptid
.pid (), t
->ptid
.lwp (), t
->ptid
.tid ());
5054 /* Record for later. */
5055 save_waitstatus (t
, &event
.ws
);
5057 sig
= (event
.ws
.kind
== TARGET_WAITKIND_STOPPED
5058 ? event
.ws
.value
.sig
: GDB_SIGNAL_0
);
5060 if (displaced_step_finish (t
, sig
)
5061 == DISPLACED_STEP_FINISH_STATUS_NOT_EXECUTED
)
5063 /* Add it back to the step-over queue. */
5064 t
->control
.trap_expected
= 0;
5065 if (!t
->inf
->detaching
)
5066 global_thread_step_over_chain_enqueue (t
);
5069 regcache
= get_thread_regcache (t
);
5070 t
->suspend
.stop_pc
= regcache_read_pc (regcache
);
5072 infrun_debug_printf ("saved stop_pc=%s for %s "
5073 "(currently_stepping=%d)",
5074 paddress (target_gdbarch (),
5075 t
->suspend
.stop_pc
),
5076 target_pid_to_str (t
->ptid
).c_str (),
5077 currently_stepping (t
));
5087 stop_all_threads (const char *reason
, inferior
*inf
)
5089 /* We may need multiple passes to discover all threads. */
5093 gdb_assert (exists_non_stop_target ());
5095 INFRUN_SCOPED_DEBUG_START_END ("reason=%s, inf=%d", reason
,
5096 inf
!= nullptr ? inf
->num
: -1);
5098 scoped_restore_current_thread restore_thread
;
5100 /* Enable thread events on relevant targets. */
5101 for (auto *target
: all_non_exited_process_targets ())
5103 if (inf
!= nullptr && inf
->process_target () != target
)
5106 switch_to_target_no_thread (target
);
5107 target_thread_events (true);
5112 /* Disable thread events on relevant targets. */
5113 for (auto *target
: all_non_exited_process_targets ())
5115 if (inf
!= nullptr && inf
->process_target () != target
)
5118 switch_to_target_no_thread (target
);
5119 target_thread_events (false);
5122 /* Use debug_prefixed_printf directly to get a meaningful function
5125 debug_prefixed_printf ("infrun", "stop_all_threads", "done");
5128 /* Request threads to stop, and then wait for the stops. Because
5129 threads we already know about can spawn more threads while we're
5130 trying to stop them, and we only learn about new threads when we
5131 update the thread list, do this in a loop, and keep iterating
5132 until two passes find no threads that need to be stopped. */
5133 for (pass
= 0; pass
< 2; pass
++, iterations
++)
5135 infrun_debug_printf ("pass=%d, iterations=%d", pass
, iterations
);
5138 int waits_needed
= 0;
5140 for (auto *target
: all_non_exited_process_targets ())
5142 if (inf
!= nullptr && inf
->process_target () != target
)
5145 switch_to_target_no_thread (target
);
5146 update_thread_list ();
5149 /* Go through all threads looking for threads that we need
5150 to tell the target to stop. */
5151 for (thread_info
*t
: all_non_exited_threads ())
5153 if (inf
!= nullptr && t
->inf
!= inf
)
5156 /* For a single-target setting with an all-stop target,
5157 we would not even arrive here. For a multi-target
5158 setting, until GDB is able to handle a mixture of
5159 all-stop and non-stop targets, simply skip all-stop
5160 targets' threads. This should be fine due to the
5161 protection of 'check_multi_target_resumption'. */
5163 switch_to_thread_no_regs (t
);
5164 if (!target_is_non_stop_p ())
5169 /* If already stopping, don't request a stop again.
5170 We just haven't seen the notification yet. */
5171 if (!t
->stop_requested
)
5173 infrun_debug_printf (" %s executing, need stop",
5174 target_pid_to_str (t
->ptid
).c_str ());
5175 target_stop (t
->ptid
);
5176 t
->stop_requested
= 1;
5180 infrun_debug_printf (" %s executing, already stopping",
5181 target_pid_to_str (t
->ptid
).c_str ());
5184 if (t
->stop_requested
)
5189 infrun_debug_printf (" %s not executing",
5190 target_pid_to_str (t
->ptid
).c_str ());
5192 /* The thread may be not executing, but still be
5193 resumed with a pending status to process. */
5198 if (waits_needed
== 0)
5201 /* If we find new threads on the second iteration, restart
5202 over. We want to see two iterations in a row with all
5207 for (int i
= 0; i
< waits_needed
; i
++)
5209 wait_one_event event
= wait_one ();
5210 if (handle_one (event
))
5217 /* Handle a TARGET_WAITKIND_NO_RESUMED event. */
5220 handle_no_resumed (struct execution_control_state
*ecs
)
5222 if (target_can_async_p ())
5224 bool any_sync
= false;
5226 for (ui
*ui
: all_uis ())
5228 if (ui
->prompt_state
== PROMPT_BLOCKED
)
5236 /* There were no unwaited-for children left in the target, but,
5237 we're not synchronously waiting for events either. Just
5240 infrun_debug_printf ("TARGET_WAITKIND_NO_RESUMED (ignoring: bg)");
5241 prepare_to_wait (ecs
);
5246 /* Otherwise, if we were running a synchronous execution command, we
5247 may need to cancel it and give the user back the terminal.
5249 In non-stop mode, the target can't tell whether we've already
5250 consumed previous stop events, so it can end up sending us a
5251 no-resumed event like so:
5253 #0 - thread 1 is left stopped
5255 #1 - thread 2 is resumed and hits breakpoint
5256 -> TARGET_WAITKIND_STOPPED
5258 #2 - thread 3 is resumed and exits
5259 this is the last resumed thread, so
5260 -> TARGET_WAITKIND_NO_RESUMED
5262 #3 - gdb processes stop for thread 2 and decides to re-resume
5265 #4 - gdb processes the TARGET_WAITKIND_NO_RESUMED event.
5266 thread 2 is now resumed, so the event should be ignored.
5268 IOW, if the stop for thread 2 doesn't end a foreground command,
5269 then we need to ignore the following TARGET_WAITKIND_NO_RESUMED
5270 event. But it could be that the event meant that thread 2 itself
5271 (or whatever other thread was the last resumed thread) exited.
5273 To address this we refresh the thread list and check whether we
5274 have resumed threads _now_. In the example above, this removes
5275 thread 3 from the thread list. If thread 2 was re-resumed, we
5276 ignore this event. If we find no thread resumed, then we cancel
5277 the synchronous command and show "no unwaited-for " to the
5280 inferior
*curr_inf
= current_inferior ();
5282 scoped_restore_current_thread restore_thread
;
5284 for (auto *target
: all_non_exited_process_targets ())
5286 switch_to_target_no_thread (target
);
5287 update_thread_list ();
5292 - the current target has no thread executing, and
5293 - the current inferior is native, and
5294 - the current inferior is the one which has the terminal, and
5297 then a Ctrl-C from this point on would remain stuck in the
5298 kernel, until a thread resumes and dequeues it. That would
5299 result in the GDB CLI not reacting to Ctrl-C, not able to
5300 interrupt the program. To address this, if the current inferior
5301 no longer has any thread executing, we give the terminal to some
5302 other inferior that has at least one thread executing. */
5303 bool swap_terminal
= true;
5305 /* Whether to ignore this TARGET_WAITKIND_NO_RESUMED event, or
5306 whether to report it to the user. */
5307 bool ignore_event
= false;
5309 for (thread_info
*thread
: all_non_exited_threads ())
5311 if (swap_terminal
&& thread
->executing
)
5313 if (thread
->inf
!= curr_inf
)
5315 target_terminal::ours ();
5317 switch_to_thread (thread
);
5318 target_terminal::inferior ();
5320 swap_terminal
= false;
5324 && (thread
->executing
5325 || thread
->suspend
.waitstatus_pending_p
))
5327 /* Either there were no unwaited-for children left in the
5328 target at some point, but there are now, or some target
5329 other than the eventing one has unwaited-for children
5330 left. Just ignore. */
5331 infrun_debug_printf ("TARGET_WAITKIND_NO_RESUMED "
5332 "(ignoring: found resumed)");
5334 ignore_event
= true;
5337 if (ignore_event
&& !swap_terminal
)
5343 switch_to_inferior_no_thread (curr_inf
);
5344 prepare_to_wait (ecs
);
5348 /* Go ahead and report the event. */
5352 /* Given an execution control state that has been freshly filled in by
5353 an event from the inferior, figure out what it means and take
5356 The alternatives are:
5358 1) stop_waiting and return; to really stop and return to the
5361 2) keep_going and return; to wait for the next event (set
5362 ecs->event_thread->stepping_over_breakpoint to 1 to single step
5366 handle_inferior_event (struct execution_control_state
*ecs
)
5368 /* Make sure that all temporary struct value objects that were
5369 created during the handling of the event get deleted at the
5371 scoped_value_mark free_values
;
5373 infrun_debug_printf ("%s", target_waitstatus_to_string (&ecs
->ws
).c_str ());
5375 if (ecs
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
5377 /* We had an event in the inferior, but we are not interested in
5378 handling it at this level. The lower layers have already
5379 done what needs to be done, if anything.
5381 One of the possible circumstances for this is when the
5382 inferior produces output for the console. The inferior has
5383 not stopped, and we are ignoring the event. Another possible
5384 circumstance is any event which the lower level knows will be
5385 reported multiple times without an intervening resume. */
5386 prepare_to_wait (ecs
);
5390 if (ecs
->ws
.kind
== TARGET_WAITKIND_THREAD_EXITED
)
5392 prepare_to_wait (ecs
);
5396 if (ecs
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
5397 && handle_no_resumed (ecs
))
5400 /* Cache the last target/ptid/waitstatus. */
5401 set_last_target_status (ecs
->target
, ecs
->ptid
, ecs
->ws
);
5403 /* Always clear state belonging to the previous time we stopped. */
5404 stop_stack_dummy
= STOP_NONE
;
5406 if (ecs
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
)
5408 /* No unwaited-for children left. IOW, all resumed children
5410 stop_print_frame
= false;
5415 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
5416 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
)
5418 ecs
->event_thread
= find_thread_ptid (ecs
->target
, ecs
->ptid
);
5419 /* If it's a new thread, add it to the thread database. */
5420 if (ecs
->event_thread
== NULL
)
5421 ecs
->event_thread
= add_thread (ecs
->target
, ecs
->ptid
);
5423 /* Disable range stepping. If the next step request could use a
5424 range, this will be end up re-enabled then. */
5425 ecs
->event_thread
->control
.may_range_step
= 0;
5428 /* Dependent on valid ECS->EVENT_THREAD. */
5429 adjust_pc_after_break (ecs
->event_thread
, &ecs
->ws
);
5431 /* Dependent on the current PC value modified by adjust_pc_after_break. */
5432 reinit_frame_cache ();
5434 breakpoint_retire_moribund ();
5436 /* First, distinguish signals caused by the debugger from signals
5437 that have to do with the program's own actions. Note that
5438 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
5439 on the operating system version. Here we detect when a SIGILL or
5440 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
5441 something similar for SIGSEGV, since a SIGSEGV will be generated
5442 when we're trying to execute a breakpoint instruction on a
5443 non-executable stack. This happens for call dummy breakpoints
5444 for architectures like SPARC that place call dummies on the
5446 if (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
5447 && (ecs
->ws
.value
.sig
== GDB_SIGNAL_ILL
5448 || ecs
->ws
.value
.sig
== GDB_SIGNAL_SEGV
5449 || ecs
->ws
.value
.sig
== GDB_SIGNAL_EMT
))
5451 struct regcache
*regcache
= get_thread_regcache (ecs
->event_thread
);
5453 if (breakpoint_inserted_here_p (regcache
->aspace (),
5454 regcache_read_pc (regcache
)))
5456 infrun_debug_printf ("Treating signal as SIGTRAP");
5457 ecs
->ws
.value
.sig
= GDB_SIGNAL_TRAP
;
5461 mark_non_executing_threads (ecs
->target
, ecs
->ptid
, ecs
->ws
);
5463 switch (ecs
->ws
.kind
)
5465 case TARGET_WAITKIND_LOADED
:
5467 context_switch (ecs
);
5468 /* Ignore gracefully during startup of the inferior, as it might
5469 be the shell which has just loaded some objects, otherwise
5470 add the symbols for the newly loaded objects. Also ignore at
5471 the beginning of an attach or remote session; we will query
5472 the full list of libraries once the connection is
5475 stop_kind stop_soon
= get_inferior_stop_soon (ecs
);
5476 if (stop_soon
== NO_STOP_QUIETLY
)
5478 struct regcache
*regcache
;
5480 regcache
= get_thread_regcache (ecs
->event_thread
);
5482 handle_solib_event ();
5484 ecs
->event_thread
->control
.stop_bpstat
5485 = bpstat_stop_status (regcache
->aspace (),
5486 ecs
->event_thread
->suspend
.stop_pc
,
5487 ecs
->event_thread
, &ecs
->ws
);
5489 if (handle_stop_requested (ecs
))
5492 if (bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
5494 /* A catchpoint triggered. */
5495 process_event_stop_test (ecs
);
5499 /* If requested, stop when the dynamic linker notifies
5500 gdb of events. This allows the user to get control
5501 and place breakpoints in initializer routines for
5502 dynamically loaded objects (among other things). */
5503 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5504 if (stop_on_solib_events
)
5506 /* Make sure we print "Stopped due to solib-event" in
5508 stop_print_frame
= true;
5515 /* If we are skipping through a shell, or through shared library
5516 loading that we aren't interested in, resume the program. If
5517 we're running the program normally, also resume. */
5518 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== NO_STOP_QUIETLY
)
5520 /* Loading of shared libraries might have changed breakpoint
5521 addresses. Make sure new breakpoints are inserted. */
5522 if (stop_soon
== NO_STOP_QUIETLY
)
5523 insert_breakpoints ();
5524 resume (GDB_SIGNAL_0
);
5525 prepare_to_wait (ecs
);
5529 /* But stop if we're attaching or setting up a remote
5531 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
5532 || stop_soon
== STOP_QUIETLY_REMOTE
)
5534 infrun_debug_printf ("quietly stopped");
5539 internal_error (__FILE__
, __LINE__
,
5540 _("unhandled stop_soon: %d"), (int) stop_soon
);
5543 case TARGET_WAITKIND_SPURIOUS
:
5544 if (handle_stop_requested (ecs
))
5546 context_switch (ecs
);
5547 resume (GDB_SIGNAL_0
);
5548 prepare_to_wait (ecs
);
5551 case TARGET_WAITKIND_THREAD_CREATED
:
5552 if (handle_stop_requested (ecs
))
5554 context_switch (ecs
);
5555 if (!switch_back_to_stepped_thread (ecs
))
5559 case TARGET_WAITKIND_EXITED
:
5560 case TARGET_WAITKIND_SIGNALLED
:
5562 /* Depending on the system, ecs->ptid may point to a thread or
5563 to a process. On some targets, target_mourn_inferior may
5564 need to have access to the just-exited thread. That is the
5565 case of GNU/Linux's "checkpoint" support, for example.
5566 Call the switch_to_xxx routine as appropriate. */
5567 thread_info
*thr
= find_thread_ptid (ecs
->target
, ecs
->ptid
);
5569 switch_to_thread (thr
);
5572 inferior
*inf
= find_inferior_ptid (ecs
->target
, ecs
->ptid
);
5573 switch_to_inferior_no_thread (inf
);
5576 handle_vfork_child_exec_or_exit (0);
5577 target_terminal::ours (); /* Must do this before mourn anyway. */
5579 /* Clearing any previous state of convenience variables. */
5580 clear_exit_convenience_vars ();
5582 if (ecs
->ws
.kind
== TARGET_WAITKIND_EXITED
)
5584 /* Record the exit code in the convenience variable $_exitcode, so
5585 that the user can inspect this again later. */
5586 set_internalvar_integer (lookup_internalvar ("_exitcode"),
5587 (LONGEST
) ecs
->ws
.value
.integer
);
5589 /* Also record this in the inferior itself. */
5590 current_inferior ()->has_exit_code
= 1;
5591 current_inferior ()->exit_code
= (LONGEST
) ecs
->ws
.value
.integer
;
5593 /* Support the --return-child-result option. */
5594 return_child_result_value
= ecs
->ws
.value
.integer
;
5596 gdb::observers::exited
.notify (ecs
->ws
.value
.integer
);
5600 struct gdbarch
*gdbarch
= current_inferior ()->gdbarch
;
5602 if (gdbarch_gdb_signal_to_target_p (gdbarch
))
5604 /* Set the value of the internal variable $_exitsignal,
5605 which holds the signal uncaught by the inferior. */
5606 set_internalvar_integer (lookup_internalvar ("_exitsignal"),
5607 gdbarch_gdb_signal_to_target (gdbarch
,
5608 ecs
->ws
.value
.sig
));
5612 /* We don't have access to the target's method used for
5613 converting between signal numbers (GDB's internal
5614 representation <-> target's representation).
5615 Therefore, we cannot do a good job at displaying this
5616 information to the user. It's better to just warn
5617 her about it (if infrun debugging is enabled), and
5619 infrun_debug_printf ("Cannot fill $_exitsignal with the correct "
5623 gdb::observers::signal_exited
.notify (ecs
->ws
.value
.sig
);
5626 gdb_flush (gdb_stdout
);
5627 target_mourn_inferior (inferior_ptid
);
5628 stop_print_frame
= false;
5632 case TARGET_WAITKIND_FORKED
:
5633 case TARGET_WAITKIND_VFORKED
:
5634 /* Check whether the inferior is displaced stepping. */
5636 struct regcache
*regcache
= get_thread_regcache (ecs
->event_thread
);
5637 struct gdbarch
*gdbarch
= regcache
->arch ();
5638 inferior
*parent_inf
= find_inferior_ptid (ecs
->target
, ecs
->ptid
);
5640 /* If this is a fork (child gets its own address space copy)
5641 and some displaced step buffers were in use at the time of
5642 the fork, restore the displaced step buffer bytes in the
5645 Architectures which support displaced stepping and fork
5646 events must supply an implementation of
5647 gdbarch_displaced_step_restore_all_in_ptid. This is not
5648 enforced during gdbarch validation to support architectures
5649 which support displaced stepping but not forks. */
5650 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
5651 && gdbarch_supports_displaced_stepping (gdbarch
))
5652 gdbarch_displaced_step_restore_all_in_ptid
5653 (gdbarch
, parent_inf
, ecs
->ws
.value
.related_pid
);
5655 /* If displaced stepping is supported, and thread ecs->ptid is
5656 displaced stepping. */
5657 if (displaced_step_in_progress_thread (ecs
->event_thread
))
5659 struct regcache
*child_regcache
;
5660 CORE_ADDR parent_pc
;
5662 /* GDB has got TARGET_WAITKIND_FORKED or TARGET_WAITKIND_VFORKED,
5663 indicating that the displaced stepping of syscall instruction
5664 has been done. Perform cleanup for parent process here. Note
5665 that this operation also cleans up the child process for vfork,
5666 because their pages are shared. */
5667 displaced_step_finish (ecs
->event_thread
, GDB_SIGNAL_TRAP
);
5668 /* Start a new step-over in another thread if there's one
5672 /* Since the vfork/fork syscall instruction was executed in the scratchpad,
5673 the child's PC is also within the scratchpad. Set the child's PC
5674 to the parent's PC value, which has already been fixed up.
5675 FIXME: we use the parent's aspace here, although we're touching
5676 the child, because the child hasn't been added to the inferior
5677 list yet at this point. */
5680 = get_thread_arch_aspace_regcache (parent_inf
->process_target (),
5681 ecs
->ws
.value
.related_pid
,
5683 parent_inf
->aspace
);
5684 /* Read PC value of parent process. */
5685 parent_pc
= regcache_read_pc (regcache
);
5687 displaced_debug_printf ("write child pc from %s to %s",
5689 regcache_read_pc (child_regcache
)),
5690 paddress (gdbarch
, parent_pc
));
5692 regcache_write_pc (child_regcache
, parent_pc
);
5696 context_switch (ecs
);
5698 /* Immediately detach breakpoints from the child before there's
5699 any chance of letting the user delete breakpoints from the
5700 breakpoint lists. If we don't do this early, it's easy to
5701 leave left over traps in the child, vis: "break foo; catch
5702 fork; c; <fork>; del; c; <child calls foo>". We only follow
5703 the fork on the last `continue', and by that time the
5704 breakpoint at "foo" is long gone from the breakpoint table.
5705 If we vforked, then we don't need to unpatch here, since both
5706 parent and child are sharing the same memory pages; we'll
5707 need to unpatch at follow/detach time instead to be certain
5708 that new breakpoints added between catchpoint hit time and
5709 vfork follow are detached. */
5710 if (ecs
->ws
.kind
!= TARGET_WAITKIND_VFORKED
)
5712 /* This won't actually modify the breakpoint list, but will
5713 physically remove the breakpoints from the child. */
5714 detach_breakpoints (ecs
->ws
.value
.related_pid
);
5717 delete_just_stopped_threads_single_step_breakpoints ();
5719 /* In case the event is caught by a catchpoint, remember that
5720 the event is to be followed at the next resume of the thread,
5721 and not immediately. */
5722 ecs
->event_thread
->pending_follow
= ecs
->ws
;
5724 ecs
->event_thread
->suspend
.stop_pc
5725 = regcache_read_pc (get_thread_regcache (ecs
->event_thread
));
5727 ecs
->event_thread
->control
.stop_bpstat
5728 = bpstat_stop_status (get_current_regcache ()->aspace (),
5729 ecs
->event_thread
->suspend
.stop_pc
,
5730 ecs
->event_thread
, &ecs
->ws
);
5732 if (handle_stop_requested (ecs
))
5735 /* If no catchpoint triggered for this, then keep going. Note
5736 that we're interested in knowing the bpstat actually causes a
5737 stop, not just if it may explain the signal. Software
5738 watchpoints, for example, always appear in the bpstat. */
5739 if (!bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
5742 = (follow_fork_mode_string
== follow_fork_mode_child
);
5744 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5746 process_stratum_target
*targ
5747 = ecs
->event_thread
->inf
->process_target ();
5749 bool should_resume
= follow_fork ();
5751 /* Note that one of these may be an invalid pointer,
5752 depending on detach_fork. */
5753 thread_info
*parent
= ecs
->event_thread
;
5755 = find_thread_ptid (targ
, ecs
->ws
.value
.related_pid
);
5757 /* At this point, the parent is marked running, and the
5758 child is marked stopped. */
5760 /* If not resuming the parent, mark it stopped. */
5761 if (follow_child
&& !detach_fork
&& !non_stop
&& !sched_multi
)
5762 parent
->set_running (false);
5764 /* If resuming the child, mark it running. */
5765 if (follow_child
|| (!detach_fork
&& (non_stop
|| sched_multi
)))
5766 child
->set_running (true);
5768 /* In non-stop mode, also resume the other branch. */
5769 if (!detach_fork
&& (non_stop
5770 || (sched_multi
&& target_is_non_stop_p ())))
5773 switch_to_thread (parent
);
5775 switch_to_thread (child
);
5777 ecs
->event_thread
= inferior_thread ();
5778 ecs
->ptid
= inferior_ptid
;
5783 switch_to_thread (child
);
5785 switch_to_thread (parent
);
5787 ecs
->event_thread
= inferior_thread ();
5788 ecs
->ptid
= inferior_ptid
;
5792 /* Never call switch_back_to_stepped_thread if we are waiting for
5793 vfork-done (waiting for an external vfork child to exec or
5794 exit). We will resume only the vforking thread for the purpose
5795 of collecting the vfork-done event, and we will restart any
5796 step once the critical shared address space window is done. */
5797 if (parent
->inf
->thread_waiting_for_vfork_done
!= nullptr
5798 || !switch_back_to_stepped_thread (ecs
))
5805 process_event_stop_test (ecs
);
5808 case TARGET_WAITKIND_VFORK_DONE
:
5809 /* Done with the shared memory region. Re-insert breakpoints in
5810 the parent, and keep going. */
5812 context_switch (ecs
);
5814 handle_vfork_done (ecs
->event_thread
);
5815 gdb_assert (inferior_thread () == ecs
->event_thread
);
5817 if (handle_stop_requested (ecs
))
5820 if (!switch_back_to_stepped_thread (ecs
))
5822 gdb_assert (inferior_thread () == ecs
->event_thread
);
5823 /* This also takes care of reinserting breakpoints in the
5824 previously locked inferior. */
5829 case TARGET_WAITKIND_EXECD
:
5831 /* Note we can't read registers yet (the stop_pc), because we
5832 don't yet know the inferior's post-exec architecture.
5833 'stop_pc' is explicitly read below instead. */
5834 switch_to_thread_no_regs (ecs
->event_thread
);
5836 /* Do whatever is necessary to the parent branch of the vfork. */
5837 handle_vfork_child_exec_or_exit (1);
5839 /* This causes the eventpoints and symbol table to be reset.
5840 Must do this now, before trying to determine whether to
5842 follow_exec (inferior_ptid
, ecs
->ws
.value
.execd_pathname
);
5844 /* In follow_exec we may have deleted the original thread and
5845 created a new one. Make sure that the event thread is the
5846 execd thread for that case (this is a nop otherwise). */
5847 ecs
->event_thread
= inferior_thread ();
5849 ecs
->event_thread
->suspend
.stop_pc
5850 = regcache_read_pc (get_thread_regcache (ecs
->event_thread
));
5852 ecs
->event_thread
->control
.stop_bpstat
5853 = bpstat_stop_status (get_current_regcache ()->aspace (),
5854 ecs
->event_thread
->suspend
.stop_pc
,
5855 ecs
->event_thread
, &ecs
->ws
);
5857 /* Note that this may be referenced from inside
5858 bpstat_stop_status above, through inferior_has_execd. */
5859 xfree (ecs
->ws
.value
.execd_pathname
);
5860 ecs
->ws
.value
.execd_pathname
= NULL
;
5862 if (handle_stop_requested (ecs
))
5865 /* If no catchpoint triggered for this, then keep going. */
5866 if (!bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
5868 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5872 process_event_stop_test (ecs
);
5875 /* Be careful not to try to gather much state about a thread
5876 that's in a syscall. It's frequently a losing proposition. */
5877 case TARGET_WAITKIND_SYSCALL_ENTRY
:
5878 /* Getting the current syscall number. */
5879 if (handle_syscall_event (ecs
) == 0)
5880 process_event_stop_test (ecs
);
5883 /* Before examining the threads further, step this thread to
5884 get it entirely out of the syscall. (We get notice of the
5885 event when the thread is just on the verge of exiting a
5886 syscall. Stepping one instruction seems to get it back
5888 case TARGET_WAITKIND_SYSCALL_RETURN
:
5889 if (handle_syscall_event (ecs
) == 0)
5890 process_event_stop_test (ecs
);
5893 case TARGET_WAITKIND_STOPPED
:
5894 handle_signal_stop (ecs
);
5897 case TARGET_WAITKIND_NO_HISTORY
:
5898 /* Reverse execution: target ran out of history info. */
5900 /* Switch to the stopped thread. */
5901 context_switch (ecs
);
5902 infrun_debug_printf ("stopped");
5904 delete_just_stopped_threads_single_step_breakpoints ();
5905 ecs
->event_thread
->suspend
.stop_pc
5906 = regcache_read_pc (get_thread_regcache (inferior_thread ()));
5908 if (handle_stop_requested (ecs
))
5911 gdb::observers::no_history
.notify ();
5917 /* Restart threads back to what they were trying to do back when we
5918 paused them (because of an in-line step-over or vfork, for example).
5919 The EVENT_THREAD thread is ignored (not restarted).
5921 If INF is non-nullptr, only resume threads from INF. */
5924 restart_threads (struct thread_info
*event_thread
, inferior
*inf
)
5926 INFRUN_SCOPED_DEBUG_START_END ("event_thread=%s, inf=%d",
5927 event_thread
->ptid
.to_string ().c_str (),
5928 inf
!= nullptr ? inf
->num
: -1);
5930 /* In case the instruction just stepped spawned a new thread. */
5931 update_thread_list ();
5933 for (thread_info
*tp
: all_non_exited_threads ())
5935 if (inf
!= nullptr && tp
->inf
!= inf
)
5938 if (tp
->inf
->detaching
)
5940 infrun_debug_printf ("restart threads: [%s] inferior detaching",
5941 target_pid_to_str (tp
->ptid
).c_str ());
5945 switch_to_thread_no_regs (tp
);
5947 if (tp
== event_thread
)
5949 infrun_debug_printf ("restart threads: [%s] is event thread",
5950 target_pid_to_str (tp
->ptid
).c_str ());
5954 if (!(tp
->state
== THREAD_RUNNING
|| tp
->control
.in_infcall
))
5956 infrun_debug_printf ("restart threads: [%s] not meant to be running",
5957 target_pid_to_str (tp
->ptid
).c_str ());
5963 infrun_debug_printf ("restart threads: [%s] resumed",
5964 target_pid_to_str (tp
->ptid
).c_str ());
5965 gdb_assert (tp
->executing
|| tp
->suspend
.waitstatus_pending_p
);
5969 if (thread_is_in_step_over_chain (tp
))
5971 infrun_debug_printf ("restart threads: [%s] needs step-over",
5972 target_pid_to_str (tp
->ptid
).c_str ());
5973 gdb_assert (!tp
->resumed
);
5978 if (tp
->suspend
.waitstatus_pending_p
)
5980 infrun_debug_printf ("restart threads: [%s] has pending status",
5981 target_pid_to_str (tp
->ptid
).c_str ());
5986 gdb_assert (!tp
->stop_requested
);
5988 /* If some thread needs to start a step-over at this point, it
5989 should still be in the step-over queue, and thus skipped
5991 if (thread_still_needs_step_over (tp
))
5993 internal_error (__FILE__
, __LINE__
,
5994 "thread [%s] needs a step-over, but not in "
5995 "step-over queue\n",
5996 target_pid_to_str (tp
->ptid
).c_str ());
5999 if (currently_stepping (tp
))
6001 infrun_debug_printf ("restart threads: [%s] was stepping",
6002 target_pid_to_str (tp
->ptid
).c_str ());
6003 keep_going_stepped_thread (tp
);
6007 struct execution_control_state ecss
;
6008 struct execution_control_state
*ecs
= &ecss
;
6010 infrun_debug_printf ("restart threads: [%s] continuing",
6011 target_pid_to_str (tp
->ptid
).c_str ());
6012 reset_ecs (ecs
, tp
);
6013 switch_to_thread (tp
);
6014 keep_going_pass_signal (ecs
);
6019 /* Callback for iterate_over_threads. Find a resumed thread that has
6020 a pending waitstatus. */
6023 resumed_thread_with_pending_status (struct thread_info
*tp
,
6027 && tp
->suspend
.waitstatus_pending_p
);
6030 /* Called when we get an event that may finish an in-line or
6031 out-of-line (displaced stepping) step-over started previously.
6032 Return true if the event is processed and we should go back to the
6033 event loop; false if the caller should continue processing the
6037 finish_step_over (struct execution_control_state
*ecs
)
6039 displaced_step_finish (ecs
->event_thread
,
6040 ecs
->event_thread
->suspend
.stop_signal
);
6042 bool had_step_over_info
= step_over_info_valid_p ();
6044 if (had_step_over_info
)
6046 /* If we're stepping over a breakpoint with all threads locked,
6047 then only the thread that was stepped should be reporting
6049 gdb_assert (ecs
->event_thread
->control
.trap_expected
);
6051 clear_step_over_info ();
6054 if (!target_is_non_stop_p ())
6057 /* Start a new step-over in another thread if there's one that
6061 /* If we were stepping over a breakpoint before, and haven't started
6062 a new in-line step-over sequence, then restart all other threads
6063 (except the event thread). We can't do this in all-stop, as then
6064 e.g., we wouldn't be able to issue any other remote packet until
6065 these other threads stop. */
6066 if (had_step_over_info
&& !step_over_info_valid_p ())
6068 struct thread_info
*pending
;
6070 /* If we only have threads with pending statuses, the restart
6071 below won't restart any thread and so nothing re-inserts the
6072 breakpoint we just stepped over. But we need it inserted
6073 when we later process the pending events, otherwise if
6074 another thread has a pending event for this breakpoint too,
6075 we'd discard its event (because the breakpoint that
6076 originally caused the event was no longer inserted). */
6077 context_switch (ecs
);
6078 insert_breakpoints ();
6080 restart_threads (ecs
->event_thread
);
6082 /* If we have events pending, go through handle_inferior_event
6083 again, picking up a pending event at random. This avoids
6084 thread starvation. */
6086 /* But not if we just stepped over a watchpoint in order to let
6087 the instruction execute so we can evaluate its expression.
6088 The set of watchpoints that triggered is recorded in the
6089 breakpoint objects themselves (see bp->watchpoint_triggered).
6090 If we processed another event first, that other event could
6091 clobber this info. */
6092 if (ecs
->event_thread
->stepping_over_watchpoint
)
6095 pending
= iterate_over_threads (resumed_thread_with_pending_status
,
6097 if (pending
!= NULL
)
6099 struct thread_info
*tp
= ecs
->event_thread
;
6100 struct regcache
*regcache
;
6102 infrun_debug_printf ("found resumed threads with "
6103 "pending events, saving status");
6105 gdb_assert (pending
!= tp
);
6107 /* Record the event thread's event for later. */
6108 save_waitstatus (tp
, &ecs
->ws
);
6109 /* This was cleared early, by handle_inferior_event. Set it
6110 so this pending event is considered by
6114 gdb_assert (!tp
->executing
);
6116 regcache
= get_thread_regcache (tp
);
6117 tp
->suspend
.stop_pc
= regcache_read_pc (regcache
);
6119 infrun_debug_printf ("saved stop_pc=%s for %s "
6120 "(currently_stepping=%d)",
6121 paddress (target_gdbarch (),
6122 tp
->suspend
.stop_pc
),
6123 target_pid_to_str (tp
->ptid
).c_str (),
6124 currently_stepping (tp
));
6126 /* This in-line step-over finished; clear this so we won't
6127 start a new one. This is what handle_signal_stop would
6128 do, if we returned false. */
6129 tp
->stepping_over_breakpoint
= 0;
6131 /* Wake up the event loop again. */
6132 mark_async_event_handler (infrun_async_inferior_event_token
);
6134 prepare_to_wait (ecs
);
6142 /* Come here when the program has stopped with a signal. */
6145 handle_signal_stop (struct execution_control_state
*ecs
)
6147 struct frame_info
*frame
;
6148 struct gdbarch
*gdbarch
;
6149 int stopped_by_watchpoint
;
6150 enum stop_kind stop_soon
;
6153 gdb_assert (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
6155 ecs
->event_thread
->suspend
.stop_signal
= ecs
->ws
.value
.sig
;
6157 /* Do we need to clean up the state of a thread that has
6158 completed a displaced single-step? (Doing so usually affects
6159 the PC, so do it here, before we set stop_pc.) */
6160 if (finish_step_over (ecs
))
6163 /* If we either finished a single-step or hit a breakpoint, but
6164 the user wanted this thread to be stopped, pretend we got a
6165 SIG0 (generic unsignaled stop). */
6166 if (ecs
->event_thread
->stop_requested
6167 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
6168 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
6170 ecs
->event_thread
->suspend
.stop_pc
6171 = regcache_read_pc (get_thread_regcache (ecs
->event_thread
));
6173 context_switch (ecs
);
6175 if (deprecated_context_hook
)
6176 deprecated_context_hook (ecs
->event_thread
->global_num
);
6180 struct regcache
*regcache
= get_thread_regcache (ecs
->event_thread
);
6181 struct gdbarch
*reg_gdbarch
= regcache
->arch ();
6183 infrun_debug_printf ("stop_pc=%s",
6184 paddress (reg_gdbarch
,
6185 ecs
->event_thread
->suspend
.stop_pc
));
6186 if (target_stopped_by_watchpoint ())
6190 infrun_debug_printf ("stopped by watchpoint");
6192 if (target_stopped_data_address (current_inferior ()->top_target (),
6194 infrun_debug_printf ("stopped data address=%s",
6195 paddress (reg_gdbarch
, addr
));
6197 infrun_debug_printf ("(no data address available)");
6201 /* This is originated from start_remote(), start_inferior() and
6202 shared libraries hook functions. */
6203 stop_soon
= get_inferior_stop_soon (ecs
);
6204 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_REMOTE
)
6206 infrun_debug_printf ("quietly stopped");
6207 stop_print_frame
= true;
6212 /* This originates from attach_command(). We need to overwrite
6213 the stop_signal here, because some kernels don't ignore a
6214 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
6215 See more comments in inferior.h. On the other hand, if we
6216 get a non-SIGSTOP, report it to the user - assume the backend
6217 will handle the SIGSTOP if it should show up later.
6219 Also consider that the attach is complete when we see a
6220 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
6221 target extended-remote report it instead of a SIGSTOP
6222 (e.g. gdbserver). We already rely on SIGTRAP being our
6223 signal, so this is no exception.
6225 Also consider that the attach is complete when we see a
6226 GDB_SIGNAL_0. In non-stop mode, GDB will explicitly tell
6227 the target to stop all threads of the inferior, in case the
6228 low level attach operation doesn't stop them implicitly. If
6229 they weren't stopped implicitly, then the stub will report a
6230 GDB_SIGNAL_0, meaning: stopped for no particular reason
6231 other than GDB's request. */
6232 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
6233 && (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_STOP
6234 || ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
6235 || ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_0
))
6237 stop_print_frame
= true;
6239 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
6243 /* At this point, get hold of the now-current thread's frame. */
6244 frame
= get_current_frame ();
6245 gdbarch
= get_frame_arch (frame
);
6247 /* Pull the single step breakpoints out of the target. */
6248 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
6250 struct regcache
*regcache
;
6253 regcache
= get_thread_regcache (ecs
->event_thread
);
6254 const address_space
*aspace
= regcache
->aspace ();
6256 pc
= regcache_read_pc (regcache
);
6258 /* However, before doing so, if this single-step breakpoint was
6259 actually for another thread, set this thread up for moving
6261 if (!thread_has_single_step_breakpoint_here (ecs
->event_thread
,
6264 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
6266 infrun_debug_printf ("[%s] hit another thread's single-step "
6268 target_pid_to_str (ecs
->ptid
).c_str ());
6269 ecs
->hit_singlestep_breakpoint
= 1;
6274 infrun_debug_printf ("[%s] hit its single-step breakpoint",
6275 target_pid_to_str (ecs
->ptid
).c_str ());
6278 delete_just_stopped_threads_single_step_breakpoints ();
6280 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
6281 && ecs
->event_thread
->control
.trap_expected
6282 && ecs
->event_thread
->stepping_over_watchpoint
)
6283 stopped_by_watchpoint
= 0;
6285 stopped_by_watchpoint
= watchpoints_triggered (&ecs
->ws
);
6287 /* If necessary, step over this watchpoint. We'll be back to display
6289 if (stopped_by_watchpoint
6290 && (target_have_steppable_watchpoint ()
6291 || gdbarch_have_nonsteppable_watchpoint (gdbarch
)))
6293 /* At this point, we are stopped at an instruction which has
6294 attempted to write to a piece of memory under control of
6295 a watchpoint. The instruction hasn't actually executed
6296 yet. If we were to evaluate the watchpoint expression
6297 now, we would get the old value, and therefore no change
6298 would seem to have occurred.
6300 In order to make watchpoints work `right', we really need
6301 to complete the memory write, and then evaluate the
6302 watchpoint expression. We do this by single-stepping the
6305 It may not be necessary to disable the watchpoint to step over
6306 it. For example, the PA can (with some kernel cooperation)
6307 single step over a watchpoint without disabling the watchpoint.
6309 It is far more common to need to disable a watchpoint to step
6310 the inferior over it. If we have non-steppable watchpoints,
6311 we must disable the current watchpoint; it's simplest to
6312 disable all watchpoints.
6314 Any breakpoint at PC must also be stepped over -- if there's
6315 one, it will have already triggered before the watchpoint
6316 triggered, and we either already reported it to the user, or
6317 it didn't cause a stop and we called keep_going. In either
6318 case, if there was a breakpoint at PC, we must be trying to
6320 ecs
->event_thread
->stepping_over_watchpoint
= 1;
6325 ecs
->event_thread
->stepping_over_breakpoint
= 0;
6326 ecs
->event_thread
->stepping_over_watchpoint
= 0;
6327 bpstat_clear (&ecs
->event_thread
->control
.stop_bpstat
);
6328 ecs
->event_thread
->control
.stop_step
= 0;
6329 stop_print_frame
= true;
6330 stopped_by_random_signal
= 0;
6331 bpstat stop_chain
= NULL
;
6333 /* Hide inlined functions starting here, unless we just performed stepi or
6334 nexti. After stepi and nexti, always show the innermost frame (not any
6335 inline function call sites). */
6336 if (ecs
->event_thread
->control
.step_range_end
!= 1)
6338 const address_space
*aspace
6339 = get_thread_regcache (ecs
->event_thread
)->aspace ();
6341 /* skip_inline_frames is expensive, so we avoid it if we can
6342 determine that the address is one where functions cannot have
6343 been inlined. This improves performance with inferiors that
6344 load a lot of shared libraries, because the solib event
6345 breakpoint is defined as the address of a function (i.e. not
6346 inline). Note that we have to check the previous PC as well
6347 as the current one to catch cases when we have just
6348 single-stepped off a breakpoint prior to reinstating it.
6349 Note that we're assuming that the code we single-step to is
6350 not inline, but that's not definitive: there's nothing
6351 preventing the event breakpoint function from containing
6352 inlined code, and the single-step ending up there. If the
6353 user had set a breakpoint on that inlined code, the missing
6354 skip_inline_frames call would break things. Fortunately
6355 that's an extremely unlikely scenario. */
6356 if (!pc_at_non_inline_function (aspace
,
6357 ecs
->event_thread
->suspend
.stop_pc
,
6359 && !(ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
6360 && ecs
->event_thread
->control
.trap_expected
6361 && pc_at_non_inline_function (aspace
,
6362 ecs
->event_thread
->prev_pc
,
6365 stop_chain
= build_bpstat_chain (aspace
,
6366 ecs
->event_thread
->suspend
.stop_pc
,
6368 skip_inline_frames (ecs
->event_thread
, stop_chain
);
6370 /* Re-fetch current thread's frame in case that invalidated
6372 frame
= get_current_frame ();
6373 gdbarch
= get_frame_arch (frame
);
6377 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
6378 && ecs
->event_thread
->control
.trap_expected
6379 && gdbarch_single_step_through_delay_p (gdbarch
)
6380 && currently_stepping (ecs
->event_thread
))
6382 /* We're trying to step off a breakpoint. Turns out that we're
6383 also on an instruction that needs to be stepped multiple
6384 times before it's been fully executing. E.g., architectures
6385 with a delay slot. It needs to be stepped twice, once for
6386 the instruction and once for the delay slot. */
6387 int step_through_delay
6388 = gdbarch_single_step_through_delay (gdbarch
, frame
);
6390 if (step_through_delay
)
6391 infrun_debug_printf ("step through delay");
6393 if (ecs
->event_thread
->control
.step_range_end
== 0
6394 && step_through_delay
)
6396 /* The user issued a continue when stopped at a breakpoint.
6397 Set up for another trap and get out of here. */
6398 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6402 else if (step_through_delay
)
6404 /* The user issued a step when stopped at a breakpoint.
6405 Maybe we should stop, maybe we should not - the delay
6406 slot *might* correspond to a line of source. In any
6407 case, don't decide that here, just set
6408 ecs->stepping_over_breakpoint, making sure we
6409 single-step again before breakpoints are re-inserted. */
6410 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6414 /* See if there is a breakpoint/watchpoint/catchpoint/etc. that
6415 handles this event. */
6416 ecs
->event_thread
->control
.stop_bpstat
6417 = bpstat_stop_status (get_current_regcache ()->aspace (),
6418 ecs
->event_thread
->suspend
.stop_pc
,
6419 ecs
->event_thread
, &ecs
->ws
, stop_chain
);
6421 /* Following in case break condition called a
6423 stop_print_frame
= true;
6425 /* This is where we handle "moribund" watchpoints. Unlike
6426 software breakpoints traps, hardware watchpoint traps are
6427 always distinguishable from random traps. If no high-level
6428 watchpoint is associated with the reported stop data address
6429 anymore, then the bpstat does not explain the signal ---
6430 simply make sure to ignore it if `stopped_by_watchpoint' is
6433 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
6434 && !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
6436 && stopped_by_watchpoint
)
6438 infrun_debug_printf ("no user watchpoint explains watchpoint SIGTRAP, "
6442 /* NOTE: cagney/2003-03-29: These checks for a random signal
6443 at one stage in the past included checks for an inferior
6444 function call's call dummy's return breakpoint. The original
6445 comment, that went with the test, read:
6447 ``End of a stack dummy. Some systems (e.g. Sony news) give
6448 another signal besides SIGTRAP, so check here as well as
6451 If someone ever tries to get call dummys on a
6452 non-executable stack to work (where the target would stop
6453 with something like a SIGSEGV), then those tests might need
6454 to be re-instated. Given, however, that the tests were only
6455 enabled when momentary breakpoints were not being used, I
6456 suspect that it won't be the case.
6458 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
6459 be necessary for call dummies on a non-executable stack on
6462 /* See if the breakpoints module can explain the signal. */
6464 = !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
6465 ecs
->event_thread
->suspend
.stop_signal
);
6467 /* Maybe this was a trap for a software breakpoint that has since
6469 if (random_signal
&& target_stopped_by_sw_breakpoint ())
6471 if (gdbarch_program_breakpoint_here_p (gdbarch
,
6472 ecs
->event_thread
->suspend
.stop_pc
))
6474 struct regcache
*regcache
;
6477 /* Re-adjust PC to what the program would see if GDB was not
6479 regcache
= get_thread_regcache (ecs
->event_thread
);
6480 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
6483 gdb::optional
<scoped_restore_tmpl
<int>>
6484 restore_operation_disable
;
6486 if (record_full_is_used ())
6487 restore_operation_disable
.emplace
6488 (record_full_gdb_operation_disable_set ());
6490 regcache_write_pc (regcache
,
6491 ecs
->event_thread
->suspend
.stop_pc
+ decr_pc
);
6496 /* A delayed software breakpoint event. Ignore the trap. */
6497 infrun_debug_printf ("delayed software breakpoint trap, ignoring");
6502 /* Maybe this was a trap for a hardware breakpoint/watchpoint that
6503 has since been removed. */
6504 if (random_signal
&& target_stopped_by_hw_breakpoint ())
6506 /* A delayed hardware breakpoint event. Ignore the trap. */
6507 infrun_debug_printf ("delayed hardware breakpoint/watchpoint "
6512 /* If not, perhaps stepping/nexting can. */
6514 random_signal
= !(ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
6515 && currently_stepping (ecs
->event_thread
));
6517 /* Perhaps the thread hit a single-step breakpoint of _another_
6518 thread. Single-step breakpoints are transparent to the
6519 breakpoints module. */
6521 random_signal
= !ecs
->hit_singlestep_breakpoint
;
6523 /* No? Perhaps we got a moribund watchpoint. */
6525 random_signal
= !stopped_by_watchpoint
;
6527 /* Always stop if the user explicitly requested this thread to
6529 if (ecs
->event_thread
->stop_requested
)
6532 infrun_debug_printf ("user-requested stop");
6535 /* For the program's own signals, act according to
6536 the signal handling tables. */
6540 /* Signal not for debugging purposes. */
6541 enum gdb_signal stop_signal
= ecs
->event_thread
->suspend
.stop_signal
;
6543 infrun_debug_printf ("random signal (%s)",
6544 gdb_signal_to_symbol_string (stop_signal
));
6546 stopped_by_random_signal
= 1;
6548 /* Always stop on signals if we're either just gaining control
6549 of the program, or the user explicitly requested this thread
6550 to remain stopped. */
6551 if (stop_soon
!= NO_STOP_QUIETLY
6552 || ecs
->event_thread
->stop_requested
6553 || signal_stop_state (ecs
->event_thread
->suspend
.stop_signal
))
6559 /* Notify observers the signal has "handle print" set. Note we
6560 returned early above if stopping; normal_stop handles the
6561 printing in that case. */
6562 if (signal_print
[ecs
->event_thread
->suspend
.stop_signal
])
6564 /* The signal table tells us to print about this signal. */
6565 target_terminal::ours_for_output ();
6566 gdb::observers::signal_received
.notify (ecs
->event_thread
->suspend
.stop_signal
);
6567 target_terminal::inferior ();
6570 /* Clear the signal if it should not be passed. */
6571 if (signal_program
[ecs
->event_thread
->suspend
.stop_signal
] == 0)
6572 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
6574 if (ecs
->event_thread
->prev_pc
== ecs
->event_thread
->suspend
.stop_pc
6575 && ecs
->event_thread
->control
.trap_expected
6576 && ecs
->event_thread
->control
.step_resume_breakpoint
== NULL
)
6578 /* We were just starting a new sequence, attempting to
6579 single-step off of a breakpoint and expecting a SIGTRAP.
6580 Instead this signal arrives. This signal will take us out
6581 of the stepping range so GDB needs to remember to, when
6582 the signal handler returns, resume stepping off that
6584 /* To simplify things, "continue" is forced to use the same
6585 code paths as single-step - set a breakpoint at the
6586 signal return address and then, once hit, step off that
6588 infrun_debug_printf ("signal arrived while stepping over breakpoint");
6590 insert_hp_step_resume_breakpoint_at_frame (frame
);
6591 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
6592 /* Reset trap_expected to ensure breakpoints are re-inserted. */
6593 ecs
->event_thread
->control
.trap_expected
= 0;
6595 /* If we were nexting/stepping some other thread, switch to
6596 it, so that we don't continue it, losing control. */
6597 if (!switch_back_to_stepped_thread (ecs
))
6602 if (ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
6603 && (pc_in_thread_step_range (ecs
->event_thread
->suspend
.stop_pc
,
6605 || ecs
->event_thread
->control
.step_range_end
== 1)
6606 && frame_id_eq (get_stack_frame_id (frame
),
6607 ecs
->event_thread
->control
.step_stack_frame_id
)
6608 && ecs
->event_thread
->control
.step_resume_breakpoint
== NULL
)
6610 /* The inferior is about to take a signal that will take it
6611 out of the single step range. Set a breakpoint at the
6612 current PC (which is presumably where the signal handler
6613 will eventually return) and then allow the inferior to
6616 Note that this is only needed for a signal delivered
6617 while in the single-step range. Nested signals aren't a
6618 problem as they eventually all return. */
6619 infrun_debug_printf ("signal may take us out of single-step range");
6621 clear_step_over_info ();
6622 insert_hp_step_resume_breakpoint_at_frame (frame
);
6623 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
6624 /* Reset trap_expected to ensure breakpoints are re-inserted. */
6625 ecs
->event_thread
->control
.trap_expected
= 0;
6630 /* Note: step_resume_breakpoint may be non-NULL. This occurs
6631 when either there's a nested signal, or when there's a
6632 pending signal enabled just as the signal handler returns
6633 (leaving the inferior at the step-resume-breakpoint without
6634 actually executing it). Either way continue until the
6635 breakpoint is really hit. */
6637 if (!switch_back_to_stepped_thread (ecs
))
6639 infrun_debug_printf ("random signal, keep going");
6646 process_event_stop_test (ecs
);
6649 /* Come here when we've got some debug event / signal we can explain
6650 (IOW, not a random signal), and test whether it should cause a
6651 stop, or whether we should resume the inferior (transparently).
6652 E.g., could be a breakpoint whose condition evaluates false; we
6653 could be still stepping within the line; etc. */
6656 process_event_stop_test (struct execution_control_state
*ecs
)
6658 struct symtab_and_line stop_pc_sal
;
6659 struct frame_info
*frame
;
6660 struct gdbarch
*gdbarch
;
6661 CORE_ADDR jmp_buf_pc
;
6662 struct bpstat_what what
;
6664 /* Handle cases caused by hitting a breakpoint. */
6666 frame
= get_current_frame ();
6667 gdbarch
= get_frame_arch (frame
);
6669 what
= bpstat_what (ecs
->event_thread
->control
.stop_bpstat
);
6671 if (what
.call_dummy
)
6673 stop_stack_dummy
= what
.call_dummy
;
6676 /* A few breakpoint types have callbacks associated (e.g.,
6677 bp_jit_event). Run them now. */
6678 bpstat_run_callbacks (ecs
->event_thread
->control
.stop_bpstat
);
6680 /* If we hit an internal event that triggers symbol changes, the
6681 current frame will be invalidated within bpstat_what (e.g., if we
6682 hit an internal solib event). Re-fetch it. */
6683 frame
= get_current_frame ();
6684 gdbarch
= get_frame_arch (frame
);
6686 switch (what
.main_action
)
6688 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
6689 /* If we hit the breakpoint at longjmp while stepping, we
6690 install a momentary breakpoint at the target of the
6693 infrun_debug_printf ("BPSTAT_WHAT_SET_LONGJMP_RESUME");
6695 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6697 if (what
.is_longjmp
)
6699 struct value
*arg_value
;
6701 /* If we set the longjmp breakpoint via a SystemTap probe,
6702 then use it to extract the arguments. The destination PC
6703 is the third argument to the probe. */
6704 arg_value
= probe_safe_evaluate_at_pc (frame
, 2);
6707 jmp_buf_pc
= value_as_address (arg_value
);
6708 jmp_buf_pc
= gdbarch_addr_bits_remove (gdbarch
, jmp_buf_pc
);
6710 else if (!gdbarch_get_longjmp_target_p (gdbarch
)
6711 || !gdbarch_get_longjmp_target (gdbarch
,
6712 frame
, &jmp_buf_pc
))
6714 infrun_debug_printf ("BPSTAT_WHAT_SET_LONGJMP_RESUME "
6715 "(!gdbarch_get_longjmp_target)");
6720 /* Insert a breakpoint at resume address. */
6721 insert_longjmp_resume_breakpoint (gdbarch
, jmp_buf_pc
);
6724 check_exception_resume (ecs
, frame
);
6728 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
6730 struct frame_info
*init_frame
;
6732 /* There are several cases to consider.
6734 1. The initiating frame no longer exists. In this case we
6735 must stop, because the exception or longjmp has gone too
6738 2. The initiating frame exists, and is the same as the
6739 current frame. We stop, because the exception or longjmp
6742 3. The initiating frame exists and is different from the
6743 current frame. This means the exception or longjmp has
6744 been caught beneath the initiating frame, so keep going.
6746 4. longjmp breakpoint has been placed just to protect
6747 against stale dummy frames and user is not interested in
6748 stopping around longjmps. */
6750 infrun_debug_printf ("BPSTAT_WHAT_CLEAR_LONGJMP_RESUME");
6752 gdb_assert (ecs
->event_thread
->control
.exception_resume_breakpoint
6754 delete_exception_resume_breakpoint (ecs
->event_thread
);
6756 if (what
.is_longjmp
)
6758 check_longjmp_breakpoint_for_call_dummy (ecs
->event_thread
);
6760 if (!frame_id_p (ecs
->event_thread
->initiating_frame
))
6768 init_frame
= frame_find_by_id (ecs
->event_thread
->initiating_frame
);
6772 struct frame_id current_id
6773 = get_frame_id (get_current_frame ());
6774 if (frame_id_eq (current_id
,
6775 ecs
->event_thread
->initiating_frame
))
6777 /* Case 2. Fall through. */
6787 /* For Cases 1 and 2, remove the step-resume breakpoint, if it
6789 delete_step_resume_breakpoint (ecs
->event_thread
);
6791 end_stepping_range (ecs
);
6795 case BPSTAT_WHAT_SINGLE
:
6796 infrun_debug_printf ("BPSTAT_WHAT_SINGLE");
6797 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6798 /* Still need to check other stuff, at least the case where we
6799 are stepping and step out of the right range. */
6802 case BPSTAT_WHAT_STEP_RESUME
:
6803 infrun_debug_printf ("BPSTAT_WHAT_STEP_RESUME");
6805 delete_step_resume_breakpoint (ecs
->event_thread
);
6806 if (ecs
->event_thread
->control
.proceed_to_finish
6807 && execution_direction
== EXEC_REVERSE
)
6809 struct thread_info
*tp
= ecs
->event_thread
;
6811 /* We are finishing a function in reverse, and just hit the
6812 step-resume breakpoint at the start address of the
6813 function, and we're almost there -- just need to back up
6814 by one more single-step, which should take us back to the
6816 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
6820 fill_in_stop_func (gdbarch
, ecs
);
6821 if (ecs
->event_thread
->suspend
.stop_pc
== ecs
->stop_func_start
6822 && execution_direction
== EXEC_REVERSE
)
6824 /* We are stepping over a function call in reverse, and just
6825 hit the step-resume breakpoint at the start address of
6826 the function. Go back to single-stepping, which should
6827 take us back to the function call. */
6828 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6834 case BPSTAT_WHAT_STOP_NOISY
:
6835 infrun_debug_printf ("BPSTAT_WHAT_STOP_NOISY");
6836 stop_print_frame
= true;
6838 /* Assume the thread stopped for a breakpoint. We'll still check
6839 whether a/the breakpoint is there when the thread is next
6841 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6846 case BPSTAT_WHAT_STOP_SILENT
:
6847 infrun_debug_printf ("BPSTAT_WHAT_STOP_SILENT");
6848 stop_print_frame
= false;
6850 /* Assume the thread stopped for a breakpoint. We'll still check
6851 whether a/the breakpoint is there when the thread is next
6853 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6857 case BPSTAT_WHAT_HP_STEP_RESUME
:
6858 infrun_debug_printf ("BPSTAT_WHAT_HP_STEP_RESUME");
6860 delete_step_resume_breakpoint (ecs
->event_thread
);
6861 if (ecs
->event_thread
->step_after_step_resume_breakpoint
)
6863 /* Back when the step-resume breakpoint was inserted, we
6864 were trying to single-step off a breakpoint. Go back to
6866 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
6867 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6873 case BPSTAT_WHAT_KEEP_CHECKING
:
6877 /* If we stepped a permanent breakpoint and we had a high priority
6878 step-resume breakpoint for the address we stepped, but we didn't
6879 hit it, then we must have stepped into the signal handler. The
6880 step-resume was only necessary to catch the case of _not_
6881 stepping into the handler, so delete it, and fall through to
6882 checking whether the step finished. */
6883 if (ecs
->event_thread
->stepped_breakpoint
)
6885 struct breakpoint
*sr_bp
6886 = ecs
->event_thread
->control
.step_resume_breakpoint
;
6889 && sr_bp
->loc
->permanent
6890 && sr_bp
->type
== bp_hp_step_resume
6891 && sr_bp
->loc
->address
== ecs
->event_thread
->prev_pc
)
6893 infrun_debug_printf ("stepped permanent breakpoint, stopped in handler");
6894 delete_step_resume_breakpoint (ecs
->event_thread
);
6895 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
6899 /* We come here if we hit a breakpoint but should not stop for it.
6900 Possibly we also were stepping and should stop for that. So fall
6901 through and test for stepping. But, if not stepping, do not
6904 /* In all-stop mode, if we're currently stepping but have stopped in
6905 some other thread, we need to switch back to the stepped thread. */
6906 if (switch_back_to_stepped_thread (ecs
))
6909 if (ecs
->event_thread
->control
.step_resume_breakpoint
)
6911 infrun_debug_printf ("step-resume breakpoint is inserted");
6913 /* Having a step-resume breakpoint overrides anything
6914 else having to do with stepping commands until
6915 that breakpoint is reached. */
6920 if (ecs
->event_thread
->control
.step_range_end
== 0)
6922 infrun_debug_printf ("no stepping, continue");
6923 /* Likewise if we aren't even stepping. */
6928 /* Re-fetch current thread's frame in case the code above caused
6929 the frame cache to be re-initialized, making our FRAME variable
6930 a dangling pointer. */
6931 frame
= get_current_frame ();
6932 gdbarch
= get_frame_arch (frame
);
6933 fill_in_stop_func (gdbarch
, ecs
);
6935 /* If stepping through a line, keep going if still within it.
6937 Note that step_range_end is the address of the first instruction
6938 beyond the step range, and NOT the address of the last instruction
6941 Note also that during reverse execution, we may be stepping
6942 through a function epilogue and therefore must detect when
6943 the current-frame changes in the middle of a line. */
6945 if (pc_in_thread_step_range (ecs
->event_thread
->suspend
.stop_pc
,
6947 && (execution_direction
!= EXEC_REVERSE
6948 || frame_id_eq (get_frame_id (frame
),
6949 ecs
->event_thread
->control
.step_frame_id
)))
6952 ("stepping inside range [%s-%s]",
6953 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_start
),
6954 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_end
));
6956 /* Tentatively re-enable range stepping; `resume' disables it if
6957 necessary (e.g., if we're stepping over a breakpoint or we
6958 have software watchpoints). */
6959 ecs
->event_thread
->control
.may_range_step
= 1;
6961 /* When stepping backward, stop at beginning of line range
6962 (unless it's the function entry point, in which case
6963 keep going back to the call point). */
6964 CORE_ADDR stop_pc
= ecs
->event_thread
->suspend
.stop_pc
;
6965 if (stop_pc
== ecs
->event_thread
->control
.step_range_start
6966 && stop_pc
!= ecs
->stop_func_start
6967 && execution_direction
== EXEC_REVERSE
)
6968 end_stepping_range (ecs
);
6975 /* We stepped out of the stepping range. */
6977 /* If we are stepping at the source level and entered the runtime
6978 loader dynamic symbol resolution code...
6980 EXEC_FORWARD: we keep on single stepping until we exit the run
6981 time loader code and reach the callee's address.
6983 EXEC_REVERSE: we've already executed the callee (backward), and
6984 the runtime loader code is handled just like any other
6985 undebuggable function call. Now we need only keep stepping
6986 backward through the trampoline code, and that's handled further
6987 down, so there is nothing for us to do here. */
6989 if (execution_direction
!= EXEC_REVERSE
6990 && ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
6991 && in_solib_dynsym_resolve_code (ecs
->event_thread
->suspend
.stop_pc
))
6993 CORE_ADDR pc_after_resolver
=
6994 gdbarch_skip_solib_resolver (gdbarch
,
6995 ecs
->event_thread
->suspend
.stop_pc
);
6997 infrun_debug_printf ("stepped into dynsym resolve code");
6999 if (pc_after_resolver
)
7001 /* Set up a step-resume breakpoint at the address
7002 indicated by SKIP_SOLIB_RESOLVER. */
7003 symtab_and_line sr_sal
;
7004 sr_sal
.pc
= pc_after_resolver
;
7005 sr_sal
.pspace
= get_frame_program_space (frame
);
7007 insert_step_resume_breakpoint_at_sal (gdbarch
,
7008 sr_sal
, null_frame_id
);
7015 /* Step through an indirect branch thunk. */
7016 if (ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
7017 && gdbarch_in_indirect_branch_thunk (gdbarch
,
7018 ecs
->event_thread
->suspend
.stop_pc
))
7020 infrun_debug_printf ("stepped into indirect branch thunk");
7025 if (ecs
->event_thread
->control
.step_range_end
!= 1
7026 && (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
7027 || ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
7028 && get_frame_type (frame
) == SIGTRAMP_FRAME
)
7030 infrun_debug_printf ("stepped into signal trampoline");
7031 /* The inferior, while doing a "step" or "next", has ended up in
7032 a signal trampoline (either by a signal being delivered or by
7033 the signal handler returning). Just single-step until the
7034 inferior leaves the trampoline (either by calling the handler
7040 /* If we're in the return path from a shared library trampoline,
7041 we want to proceed through the trampoline when stepping. */
7042 /* macro/2012-04-25: This needs to come before the subroutine
7043 call check below as on some targets return trampolines look
7044 like subroutine calls (MIPS16 return thunks). */
7045 if (gdbarch_in_solib_return_trampoline (gdbarch
,
7046 ecs
->event_thread
->suspend
.stop_pc
,
7047 ecs
->stop_func_name
)
7048 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
7050 /* Determine where this trampoline returns. */
7051 CORE_ADDR stop_pc
= ecs
->event_thread
->suspend
.stop_pc
;
7052 CORE_ADDR real_stop_pc
7053 = gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
7055 infrun_debug_printf ("stepped into solib return tramp");
7057 /* Only proceed through if we know where it's going. */
7060 /* And put the step-breakpoint there and go until there. */
7061 symtab_and_line sr_sal
;
7062 sr_sal
.pc
= real_stop_pc
;
7063 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
7064 sr_sal
.pspace
= get_frame_program_space (frame
);
7066 /* Do not specify what the fp should be when we stop since
7067 on some machines the prologue is where the new fp value
7069 insert_step_resume_breakpoint_at_sal (gdbarch
,
7070 sr_sal
, null_frame_id
);
7072 /* Restart without fiddling with the step ranges or
7079 /* Check for subroutine calls. The check for the current frame
7080 equalling the step ID is not necessary - the check of the
7081 previous frame's ID is sufficient - but it is a common case and
7082 cheaper than checking the previous frame's ID.
7084 NOTE: frame_id_eq will never report two invalid frame IDs as
7085 being equal, so to get into this block, both the current and
7086 previous frame must have valid frame IDs. */
7087 /* The outer_frame_id check is a heuristic to detect stepping
7088 through startup code. If we step over an instruction which
7089 sets the stack pointer from an invalid value to a valid value,
7090 we may detect that as a subroutine call from the mythical
7091 "outermost" function. This could be fixed by marking
7092 outermost frames as !stack_p,code_p,special_p. Then the
7093 initial outermost frame, before sp was valid, would
7094 have code_addr == &_start. See the comment in frame_id_eq
7096 if (!frame_id_eq (get_stack_frame_id (frame
),
7097 ecs
->event_thread
->control
.step_stack_frame_id
)
7098 && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()),
7099 ecs
->event_thread
->control
.step_stack_frame_id
)
7100 && (!frame_id_eq (ecs
->event_thread
->control
.step_stack_frame_id
,
7102 || (ecs
->event_thread
->control
.step_start_function
7103 != find_pc_function (ecs
->event_thread
->suspend
.stop_pc
)))))
7105 CORE_ADDR stop_pc
= ecs
->event_thread
->suspend
.stop_pc
;
7106 CORE_ADDR real_stop_pc
;
7108 infrun_debug_printf ("stepped into subroutine");
7110 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_NONE
)
7112 /* I presume that step_over_calls is only 0 when we're
7113 supposed to be stepping at the assembly language level
7114 ("stepi"). Just stop. */
7115 /* And this works the same backward as frontward. MVS */
7116 end_stepping_range (ecs
);
7120 /* Reverse stepping through solib trampolines. */
7122 if (execution_direction
== EXEC_REVERSE
7123 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
7124 && (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
7125 || (ecs
->stop_func_start
== 0
7126 && in_solib_dynsym_resolve_code (stop_pc
))))
7128 /* Any solib trampoline code can be handled in reverse
7129 by simply continuing to single-step. We have already
7130 executed the solib function (backwards), and a few
7131 steps will take us back through the trampoline to the
7137 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
7139 /* We're doing a "next".
7141 Normal (forward) execution: set a breakpoint at the
7142 callee's return address (the address at which the caller
7145 Reverse (backward) execution. set the step-resume
7146 breakpoint at the start of the function that we just
7147 stepped into (backwards), and continue to there. When we
7148 get there, we'll need to single-step back to the caller. */
7150 if (execution_direction
== EXEC_REVERSE
)
7152 /* If we're already at the start of the function, we've either
7153 just stepped backward into a single instruction function,
7154 or stepped back out of a signal handler to the first instruction
7155 of the function. Just keep going, which will single-step back
7157 if (ecs
->stop_func_start
!= stop_pc
&& ecs
->stop_func_start
!= 0)
7159 /* Normal function call return (static or dynamic). */
7160 symtab_and_line sr_sal
;
7161 sr_sal
.pc
= ecs
->stop_func_start
;
7162 sr_sal
.pspace
= get_frame_program_space (frame
);
7163 insert_step_resume_breakpoint_at_sal (gdbarch
,
7164 sr_sal
, null_frame_id
);
7168 insert_step_resume_breakpoint_at_caller (frame
);
7174 /* If we are in a function call trampoline (a stub between the
7175 calling routine and the real function), locate the real
7176 function. That's what tells us (a) whether we want to step
7177 into it at all, and (b) what prologue we want to run to the
7178 end of, if we do step into it. */
7179 real_stop_pc
= skip_language_trampoline (frame
, stop_pc
);
7180 if (real_stop_pc
== 0)
7181 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
7182 if (real_stop_pc
!= 0)
7183 ecs
->stop_func_start
= real_stop_pc
;
7185 if (real_stop_pc
!= 0 && in_solib_dynsym_resolve_code (real_stop_pc
))
7187 symtab_and_line sr_sal
;
7188 sr_sal
.pc
= ecs
->stop_func_start
;
7189 sr_sal
.pspace
= get_frame_program_space (frame
);
7191 insert_step_resume_breakpoint_at_sal (gdbarch
,
7192 sr_sal
, null_frame_id
);
7197 /* If we have line number information for the function we are
7198 thinking of stepping into and the function isn't on the skip
7201 If there are several symtabs at that PC (e.g. with include
7202 files), just want to know whether *any* of them have line
7203 numbers. find_pc_line handles this. */
7205 struct symtab_and_line tmp_sal
;
7207 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
7208 if (tmp_sal
.line
!= 0
7209 && !function_name_is_marked_for_skip (ecs
->stop_func_name
,
7211 && !inline_frame_is_marked_for_skip (true, ecs
->event_thread
))
7213 if (execution_direction
== EXEC_REVERSE
)
7214 handle_step_into_function_backward (gdbarch
, ecs
);
7216 handle_step_into_function (gdbarch
, ecs
);
7221 /* If we have no line number and the step-stop-if-no-debug is
7222 set, we stop the step so that the user has a chance to switch
7223 in assembly mode. */
7224 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
7225 && step_stop_if_no_debug
)
7227 end_stepping_range (ecs
);
7231 if (execution_direction
== EXEC_REVERSE
)
7233 /* If we're already at the start of the function, we've either just
7234 stepped backward into a single instruction function without line
7235 number info, or stepped back out of a signal handler to the first
7236 instruction of the function without line number info. Just keep
7237 going, which will single-step back to the caller. */
7238 if (ecs
->stop_func_start
!= stop_pc
)
7240 /* Set a breakpoint at callee's start address.
7241 From there we can step once and be back in the caller. */
7242 symtab_and_line sr_sal
;
7243 sr_sal
.pc
= ecs
->stop_func_start
;
7244 sr_sal
.pspace
= get_frame_program_space (frame
);
7245 insert_step_resume_breakpoint_at_sal (gdbarch
,
7246 sr_sal
, null_frame_id
);
7250 /* Set a breakpoint at callee's return address (the address
7251 at which the caller will resume). */
7252 insert_step_resume_breakpoint_at_caller (frame
);
7258 /* Reverse stepping through solib trampolines. */
7260 if (execution_direction
== EXEC_REVERSE
7261 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
7263 CORE_ADDR stop_pc
= ecs
->event_thread
->suspend
.stop_pc
;
7265 if (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
7266 || (ecs
->stop_func_start
== 0
7267 && in_solib_dynsym_resolve_code (stop_pc
)))
7269 /* Any solib trampoline code can be handled in reverse
7270 by simply continuing to single-step. We have already
7271 executed the solib function (backwards), and a few
7272 steps will take us back through the trampoline to the
7277 else if (in_solib_dynsym_resolve_code (stop_pc
))
7279 /* Stepped backward into the solib dynsym resolver.
7280 Set a breakpoint at its start and continue, then
7281 one more step will take us out. */
7282 symtab_and_line sr_sal
;
7283 sr_sal
.pc
= ecs
->stop_func_start
;
7284 sr_sal
.pspace
= get_frame_program_space (frame
);
7285 insert_step_resume_breakpoint_at_sal (gdbarch
,
7286 sr_sal
, null_frame_id
);
7292 /* This always returns the sal for the inner-most frame when we are in a
7293 stack of inlined frames, even if GDB actually believes that it is in a
7294 more outer frame. This is checked for below by calls to
7295 inline_skipped_frames. */
7296 stop_pc_sal
= find_pc_line (ecs
->event_thread
->suspend
.stop_pc
, 0);
7298 /* NOTE: tausq/2004-05-24: This if block used to be done before all
7299 the trampoline processing logic, however, there are some trampolines
7300 that have no names, so we should do trampoline handling first. */
7301 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
7302 && ecs
->stop_func_name
== NULL
7303 && stop_pc_sal
.line
== 0)
7305 infrun_debug_printf ("stepped into undebuggable function");
7307 /* The inferior just stepped into, or returned to, an
7308 undebuggable function (where there is no debugging information
7309 and no line number corresponding to the address where the
7310 inferior stopped). Since we want to skip this kind of code,
7311 we keep going until the inferior returns from this
7312 function - unless the user has asked us not to (via
7313 set step-mode) or we no longer know how to get back
7314 to the call site. */
7315 if (step_stop_if_no_debug
7316 || !frame_id_p (frame_unwind_caller_id (frame
)))
7318 /* If we have no line number and the step-stop-if-no-debug
7319 is set, we stop the step so that the user has a chance to
7320 switch in assembly mode. */
7321 end_stepping_range (ecs
);
7326 /* Set a breakpoint at callee's return address (the address
7327 at which the caller will resume). */
7328 insert_step_resume_breakpoint_at_caller (frame
);
7334 if (ecs
->event_thread
->control
.step_range_end
== 1)
7336 /* It is stepi or nexti. We always want to stop stepping after
7338 infrun_debug_printf ("stepi/nexti");
7339 end_stepping_range (ecs
);
7343 if (stop_pc_sal
.line
== 0)
7345 /* We have no line number information. That means to stop
7346 stepping (does this always happen right after one instruction,
7347 when we do "s" in a function with no line numbers,
7348 or can this happen as a result of a return or longjmp?). */
7349 infrun_debug_printf ("line number info");
7350 end_stepping_range (ecs
);
7354 /* Look for "calls" to inlined functions, part one. If the inline
7355 frame machinery detected some skipped call sites, we have entered
7356 a new inline function. */
7358 if (frame_id_eq (get_frame_id (get_current_frame ()),
7359 ecs
->event_thread
->control
.step_frame_id
)
7360 && inline_skipped_frames (ecs
->event_thread
))
7362 infrun_debug_printf ("stepped into inlined function");
7364 symtab_and_line call_sal
= find_frame_sal (get_current_frame ());
7366 if (ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_ALL
)
7368 /* For "step", we're going to stop. But if the call site
7369 for this inlined function is on the same source line as
7370 we were previously stepping, go down into the function
7371 first. Otherwise stop at the call site. */
7373 if (call_sal
.line
== ecs
->event_thread
->current_line
7374 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
7376 step_into_inline_frame (ecs
->event_thread
);
7377 if (inline_frame_is_marked_for_skip (false, ecs
->event_thread
))
7384 end_stepping_range (ecs
);
7389 /* For "next", we should stop at the call site if it is on a
7390 different source line. Otherwise continue through the
7391 inlined function. */
7392 if (call_sal
.line
== ecs
->event_thread
->current_line
7393 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
7396 end_stepping_range (ecs
);
7401 /* Look for "calls" to inlined functions, part two. If we are still
7402 in the same real function we were stepping through, but we have
7403 to go further up to find the exact frame ID, we are stepping
7404 through a more inlined call beyond its call site. */
7406 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
7407 && !frame_id_eq (get_frame_id (get_current_frame ()),
7408 ecs
->event_thread
->control
.step_frame_id
)
7409 && stepped_in_from (get_current_frame (),
7410 ecs
->event_thread
->control
.step_frame_id
))
7412 infrun_debug_printf ("stepping through inlined function");
7414 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
7415 || inline_frame_is_marked_for_skip (false, ecs
->event_thread
))
7418 end_stepping_range (ecs
);
7422 bool refresh_step_info
= true;
7423 if ((ecs
->event_thread
->suspend
.stop_pc
== stop_pc_sal
.pc
)
7424 && (ecs
->event_thread
->current_line
!= stop_pc_sal
.line
7425 || ecs
->event_thread
->current_symtab
!= stop_pc_sal
.symtab
))
7427 /* We are at a different line. */
7429 if (stop_pc_sal
.is_stmt
)
7431 /* We are at the start of a statement.
7433 So stop. Note that we don't stop if we step into the middle of a
7434 statement. That is said to make things like for (;;) statements
7436 infrun_debug_printf ("stepped to a different line");
7437 end_stepping_range (ecs
);
7440 else if (frame_id_eq (get_frame_id (get_current_frame ()),
7441 ecs
->event_thread
->control
.step_frame_id
))
7443 /* We are not at the start of a statement, and we have not changed
7446 We ignore this line table entry, and continue stepping forward,
7447 looking for a better place to stop. */
7448 refresh_step_info
= false;
7449 infrun_debug_printf ("stepped to a different line, but "
7450 "it's not the start of a statement");
7454 /* We are not the start of a statement, and we have changed frame.
7456 We ignore this line table entry, and continue stepping forward,
7457 looking for a better place to stop. Keep refresh_step_info at
7458 true to note that the frame has changed, but ignore the line
7459 number to make sure we don't ignore a subsequent entry with the
7460 same line number. */
7461 stop_pc_sal
.line
= 0;
7462 infrun_debug_printf ("stepped to a different frame, but "
7463 "it's not the start of a statement");
7467 /* We aren't done stepping.
7469 Optimize by setting the stepping range to the line.
7470 (We might not be in the original line, but if we entered a
7471 new line in mid-statement, we continue stepping. This makes
7472 things like for(;;) statements work better.)
7474 If we entered a SAL that indicates a non-statement line table entry,
7475 then we update the stepping range, but we don't update the step info,
7476 which includes things like the line number we are stepping away from.
7477 This means we will stop when we find a line table entry that is marked
7478 as is-statement, even if it matches the non-statement one we just
7481 ecs
->event_thread
->control
.step_range_start
= stop_pc_sal
.pc
;
7482 ecs
->event_thread
->control
.step_range_end
= stop_pc_sal
.end
;
7483 ecs
->event_thread
->control
.may_range_step
= 1;
7484 if (refresh_step_info
)
7485 set_step_info (ecs
->event_thread
, frame
, stop_pc_sal
);
7487 infrun_debug_printf ("keep going");
7491 static bool restart_stepped_thread (process_stratum_target
*resume_target
,
7492 ptid_t resume_ptid
);
7494 /* In all-stop mode, if we're currently stepping but have stopped in
7495 some other thread, we may need to switch back to the stepped
7496 thread. Returns true we set the inferior running, false if we left
7497 it stopped (and the event needs further processing). */
7500 switch_back_to_stepped_thread (struct execution_control_state
*ecs
)
7502 if (!target_is_non_stop_p ())
7504 /* If any thread is blocked on some internal breakpoint, and we
7505 simply need to step over that breakpoint to get it going
7506 again, do that first. */
7508 /* However, if we see an event for the stepping thread, then we
7509 know all other threads have been moved past their breakpoints
7510 already. Let the caller check whether the step is finished,
7511 etc., before deciding to move it past a breakpoint. */
7512 if (ecs
->event_thread
->control
.step_range_end
!= 0)
7515 /* Check if the current thread is blocked on an incomplete
7516 step-over, interrupted by a random signal. */
7517 if (ecs
->event_thread
->control
.trap_expected
7518 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_TRAP
)
7521 ("need to finish step-over of [%s]",
7522 target_pid_to_str (ecs
->event_thread
->ptid
).c_str ());
7527 /* Check if the current thread is blocked by a single-step
7528 breakpoint of another thread. */
7529 if (ecs
->hit_singlestep_breakpoint
)
7531 infrun_debug_printf ("need to step [%s] over single-step breakpoint",
7532 target_pid_to_str (ecs
->ptid
).c_str ());
7537 /* If this thread needs yet another step-over (e.g., stepping
7538 through a delay slot), do it first before moving on to
7540 if (thread_still_needs_step_over (ecs
->event_thread
))
7543 ("thread [%s] still needs step-over",
7544 target_pid_to_str (ecs
->event_thread
->ptid
).c_str ());
7549 /* If scheduler locking applies even if not stepping, there's no
7550 need to walk over threads. Above we've checked whether the
7551 current thread is stepping. If some other thread not the
7552 event thread is stepping, then it must be that scheduler
7553 locking is not in effect. */
7554 if (schedlock_applies (ecs
->event_thread
))
7557 /* Otherwise, we no longer expect a trap in the current thread.
7558 Clear the trap_expected flag before switching back -- this is
7559 what keep_going does as well, if we call it. */
7560 ecs
->event_thread
->control
.trap_expected
= 0;
7562 /* Likewise, clear the signal if it should not be passed. */
7563 if (!signal_program
[ecs
->event_thread
->suspend
.stop_signal
])
7564 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
7566 if (restart_stepped_thread (ecs
->target
, ecs
->ptid
))
7568 prepare_to_wait (ecs
);
7572 switch_to_thread (ecs
->event_thread
);
7578 /* Look for the thread that was stepping, and resume it.
7579 RESUME_TARGET / RESUME_PTID indicate the set of threads the caller
7580 is resuming. Return true if a thread was started, false
7584 restart_stepped_thread (process_stratum_target
*resume_target
,
7587 /* Do all pending step-overs before actually proceeding with
7589 if (start_step_over ())
7592 for (thread_info
*tp
: all_threads_safe ())
7594 if (tp
->state
== THREAD_EXITED
)
7597 if (tp
->suspend
.waitstatus_pending_p
)
7600 /* Ignore threads of processes the caller is not
7603 && (tp
->inf
->process_target () != resume_target
7604 || tp
->inf
->pid
!= resume_ptid
.pid ()))
7607 if (tp
->control
.trap_expected
)
7609 infrun_debug_printf ("switching back to stepped thread (step-over)");
7611 if (keep_going_stepped_thread (tp
))
7616 for (thread_info
*tp
: all_threads_safe ())
7618 if (tp
->state
== THREAD_EXITED
)
7621 if (tp
->suspend
.waitstatus_pending_p
)
7624 /* Ignore threads of processes the caller is not
7627 && (tp
->inf
->process_target () != resume_target
7628 || tp
->inf
->pid
!= resume_ptid
.pid ()))
7631 /* Did we find the stepping thread? */
7632 if (tp
->control
.step_range_end
)
7634 infrun_debug_printf ("switching back to stepped thread (stepping)");
7636 if (keep_going_stepped_thread (tp
))
7647 restart_after_all_stop_detach (process_stratum_target
*proc_target
)
7649 /* Note we don't check target_is_non_stop_p() here, because the
7650 current inferior may no longer have a process_stratum target
7651 pushed, as we just detached. */
7653 /* See if we have a THREAD_RUNNING thread that need to be
7654 re-resumed. If we have any thread that is already executing,
7655 then we don't need to resume the target -- it is already been
7656 resumed. With the remote target (in all-stop), it's even
7657 impossible to issue another resumption if the target is already
7658 resumed, until the target reports a stop. */
7659 for (thread_info
*thr
: all_threads (proc_target
))
7661 if (thr
->state
!= THREAD_RUNNING
)
7664 /* If we have any thread that is already executing, then we
7665 don't need to resume the target -- it is already been
7670 /* If we have a pending event to process, skip resuming the
7671 target and go straight to processing it. */
7672 if (thr
->resumed
&& thr
->suspend
.waitstatus_pending_p
)
7676 /* Alright, we need to re-resume the target. If a thread was
7677 stepping, we need to restart it stepping. */
7678 if (restart_stepped_thread (proc_target
, minus_one_ptid
))
7681 /* Otherwise, find the first THREAD_RUNNING thread and resume
7683 for (thread_info
*thr
: all_threads (proc_target
))
7685 if (thr
->state
!= THREAD_RUNNING
)
7688 execution_control_state ecs
;
7689 reset_ecs (&ecs
, thr
);
7690 switch_to_thread (thr
);
7696 /* Set a previously stepped thread back to stepping. Returns true on
7697 success, false if the resume is not possible (e.g., the thread
7701 keep_going_stepped_thread (struct thread_info
*tp
)
7703 struct frame_info
*frame
;
7704 struct execution_control_state ecss
;
7705 struct execution_control_state
*ecs
= &ecss
;
7707 /* If the stepping thread exited, then don't try to switch back and
7708 resume it, which could fail in several different ways depending
7709 on the target. Instead, just keep going.
7711 We can find a stepping dead thread in the thread list in two
7714 - The target supports thread exit events, and when the target
7715 tries to delete the thread from the thread list, inferior_ptid
7716 pointed at the exiting thread. In such case, calling
7717 delete_thread does not really remove the thread from the list;
7718 instead, the thread is left listed, with 'exited' state.
7720 - The target's debug interface does not support thread exit
7721 events, and so we have no idea whatsoever if the previously
7722 stepping thread is still alive. For that reason, we need to
7723 synchronously query the target now. */
7725 if (tp
->state
== THREAD_EXITED
|| !target_thread_alive (tp
->ptid
))
7727 infrun_debug_printf ("not resuming previously stepped thread, it has "
7734 infrun_debug_printf ("resuming previously stepped thread");
7736 reset_ecs (ecs
, tp
);
7737 switch_to_thread (tp
);
7739 tp
->suspend
.stop_pc
= regcache_read_pc (get_thread_regcache (tp
));
7740 frame
= get_current_frame ();
7742 /* If the PC of the thread we were trying to single-step has
7743 changed, then that thread has trapped or been signaled, but the
7744 event has not been reported to GDB yet. Re-poll the target
7745 looking for this particular thread's event (i.e. temporarily
7746 enable schedlock) by:
7748 - setting a break at the current PC
7749 - resuming that particular thread, only (by setting trap
7752 This prevents us continuously moving the single-step breakpoint
7753 forward, one instruction at a time, overstepping. */
7755 if (tp
->suspend
.stop_pc
!= tp
->prev_pc
)
7759 infrun_debug_printf ("expected thread advanced also (%s -> %s)",
7760 paddress (target_gdbarch (), tp
->prev_pc
),
7761 paddress (target_gdbarch (), tp
->suspend
.stop_pc
));
7763 /* Clear the info of the previous step-over, as it's no longer
7764 valid (if the thread was trying to step over a breakpoint, it
7765 has already succeeded). It's what keep_going would do too,
7766 if we called it. Do this before trying to insert the sss
7767 breakpoint, otherwise if we were previously trying to step
7768 over this exact address in another thread, the breakpoint is
7770 clear_step_over_info ();
7771 tp
->control
.trap_expected
= 0;
7773 insert_single_step_breakpoint (get_frame_arch (frame
),
7774 get_frame_address_space (frame
),
7775 tp
->suspend
.stop_pc
);
7778 resume_ptid
= internal_resume_ptid (tp
->control
.stepping_command
);
7779 do_target_resume (resume_ptid
, false, GDB_SIGNAL_0
);
7783 infrun_debug_printf ("expected thread still hasn't advanced");
7785 keep_going_pass_signal (ecs
);
7791 /* Is thread TP in the middle of (software or hardware)
7792 single-stepping? (Note the result of this function must never be
7793 passed directly as target_resume's STEP parameter.) */
7796 currently_stepping (struct thread_info
*tp
)
7798 return ((tp
->control
.step_range_end
7799 && tp
->control
.step_resume_breakpoint
== NULL
)
7800 || tp
->control
.trap_expected
7801 || tp
->stepped_breakpoint
7802 || bpstat_should_step ());
7805 /* Inferior has stepped into a subroutine call with source code that
7806 we should not step over. Do step to the first line of code in
7810 handle_step_into_function (struct gdbarch
*gdbarch
,
7811 struct execution_control_state
*ecs
)
7813 fill_in_stop_func (gdbarch
, ecs
);
7815 compunit_symtab
*cust
7816 = find_pc_compunit_symtab (ecs
->event_thread
->suspend
.stop_pc
);
7817 if (cust
!= NULL
&& compunit_language (cust
) != language_asm
)
7818 ecs
->stop_func_start
7819 = gdbarch_skip_prologue_noexcept (gdbarch
, ecs
->stop_func_start
);
7821 symtab_and_line stop_func_sal
= find_pc_line (ecs
->stop_func_start
, 0);
7822 /* Use the step_resume_break to step until the end of the prologue,
7823 even if that involves jumps (as it seems to on the vax under
7825 /* If the prologue ends in the middle of a source line, continue to
7826 the end of that source line (if it is still within the function).
7827 Otherwise, just go to end of prologue. */
7828 if (stop_func_sal
.end
7829 && stop_func_sal
.pc
!= ecs
->stop_func_start
7830 && stop_func_sal
.end
< ecs
->stop_func_end
)
7831 ecs
->stop_func_start
= stop_func_sal
.end
;
7833 /* Architectures which require breakpoint adjustment might not be able
7834 to place a breakpoint at the computed address. If so, the test
7835 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
7836 ecs->stop_func_start to an address at which a breakpoint may be
7837 legitimately placed.
7839 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
7840 made, GDB will enter an infinite loop when stepping through
7841 optimized code consisting of VLIW instructions which contain
7842 subinstructions corresponding to different source lines. On
7843 FR-V, it's not permitted to place a breakpoint on any but the
7844 first subinstruction of a VLIW instruction. When a breakpoint is
7845 set, GDB will adjust the breakpoint address to the beginning of
7846 the VLIW instruction. Thus, we need to make the corresponding
7847 adjustment here when computing the stop address. */
7849 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
7851 ecs
->stop_func_start
7852 = gdbarch_adjust_breakpoint_address (gdbarch
,
7853 ecs
->stop_func_start
);
7856 if (ecs
->stop_func_start
== ecs
->event_thread
->suspend
.stop_pc
)
7858 /* We are already there: stop now. */
7859 end_stepping_range (ecs
);
7864 /* Put the step-breakpoint there and go until there. */
7865 symtab_and_line sr_sal
;
7866 sr_sal
.pc
= ecs
->stop_func_start
;
7867 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
7868 sr_sal
.pspace
= get_frame_program_space (get_current_frame ());
7870 /* Do not specify what the fp should be when we stop since on
7871 some machines the prologue is where the new fp value is
7873 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
, null_frame_id
);
7875 /* And make sure stepping stops right away then. */
7876 ecs
->event_thread
->control
.step_range_end
7877 = ecs
->event_thread
->control
.step_range_start
;
7882 /* Inferior has stepped backward into a subroutine call with source
7883 code that we should not step over. Do step to the beginning of the
7884 last line of code in it. */
7887 handle_step_into_function_backward (struct gdbarch
*gdbarch
,
7888 struct execution_control_state
*ecs
)
7890 struct compunit_symtab
*cust
;
7891 struct symtab_and_line stop_func_sal
;
7893 fill_in_stop_func (gdbarch
, ecs
);
7895 cust
= find_pc_compunit_symtab (ecs
->event_thread
->suspend
.stop_pc
);
7896 if (cust
!= NULL
&& compunit_language (cust
) != language_asm
)
7897 ecs
->stop_func_start
7898 = gdbarch_skip_prologue_noexcept (gdbarch
, ecs
->stop_func_start
);
7900 stop_func_sal
= find_pc_line (ecs
->event_thread
->suspend
.stop_pc
, 0);
7902 /* OK, we're just going to keep stepping here. */
7903 if (stop_func_sal
.pc
== ecs
->event_thread
->suspend
.stop_pc
)
7905 /* We're there already. Just stop stepping now. */
7906 end_stepping_range (ecs
);
7910 /* Else just reset the step range and keep going.
7911 No step-resume breakpoint, they don't work for
7912 epilogues, which can have multiple entry paths. */
7913 ecs
->event_thread
->control
.step_range_start
= stop_func_sal
.pc
;
7914 ecs
->event_thread
->control
.step_range_end
= stop_func_sal
.end
;
7920 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
7921 This is used to both functions and to skip over code. */
7924 insert_step_resume_breakpoint_at_sal_1 (struct gdbarch
*gdbarch
,
7925 struct symtab_and_line sr_sal
,
7926 struct frame_id sr_id
,
7927 enum bptype sr_type
)
7929 /* There should never be more than one step-resume or longjmp-resume
7930 breakpoint per thread, so we should never be setting a new
7931 step_resume_breakpoint when one is already active. */
7932 gdb_assert (inferior_thread ()->control
.step_resume_breakpoint
== NULL
);
7933 gdb_assert (sr_type
== bp_step_resume
|| sr_type
== bp_hp_step_resume
);
7935 infrun_debug_printf ("inserting step-resume breakpoint at %s",
7936 paddress (gdbarch
, sr_sal
.pc
));
7938 inferior_thread ()->control
.step_resume_breakpoint
7939 = set_momentary_breakpoint (gdbarch
, sr_sal
, sr_id
, sr_type
).release ();
7943 insert_step_resume_breakpoint_at_sal (struct gdbarch
*gdbarch
,
7944 struct symtab_and_line sr_sal
,
7945 struct frame_id sr_id
)
7947 insert_step_resume_breakpoint_at_sal_1 (gdbarch
,
7952 /* Insert a "high-priority step-resume breakpoint" at RETURN_FRAME.pc.
7953 This is used to skip a potential signal handler.
7955 This is called with the interrupted function's frame. The signal
7956 handler, when it returns, will resume the interrupted function at
7960 insert_hp_step_resume_breakpoint_at_frame (struct frame_info
*return_frame
)
7962 gdb_assert (return_frame
!= NULL
);
7964 struct gdbarch
*gdbarch
= get_frame_arch (return_frame
);
7966 symtab_and_line sr_sal
;
7967 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
, get_frame_pc (return_frame
));
7968 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
7969 sr_sal
.pspace
= get_frame_program_space (return_frame
);
7971 insert_step_resume_breakpoint_at_sal_1 (gdbarch
, sr_sal
,
7972 get_stack_frame_id (return_frame
),
7976 /* Insert a "step-resume breakpoint" at the previous frame's PC. This
7977 is used to skip a function after stepping into it (for "next" or if
7978 the called function has no debugging information).
7980 The current function has almost always been reached by single
7981 stepping a call or return instruction. NEXT_FRAME belongs to the
7982 current function, and the breakpoint will be set at the caller's
7985 This is a separate function rather than reusing
7986 insert_hp_step_resume_breakpoint_at_frame in order to avoid
7987 get_prev_frame, which may stop prematurely (see the implementation
7988 of frame_unwind_caller_id for an example). */
7991 insert_step_resume_breakpoint_at_caller (struct frame_info
*next_frame
)
7993 /* We shouldn't have gotten here if we don't know where the call site
7995 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame
)));
7997 struct gdbarch
*gdbarch
= frame_unwind_caller_arch (next_frame
);
7999 symtab_and_line sr_sal
;
8000 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
,
8001 frame_unwind_caller_pc (next_frame
));
8002 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
8003 sr_sal
.pspace
= frame_unwind_program_space (next_frame
);
8005 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
,
8006 frame_unwind_caller_id (next_frame
));
8009 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
8010 new breakpoint at the target of a jmp_buf. The handling of
8011 longjmp-resume uses the same mechanisms used for handling
8012 "step-resume" breakpoints. */
8015 insert_longjmp_resume_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
8017 /* There should never be more than one longjmp-resume breakpoint per
8018 thread, so we should never be setting a new
8019 longjmp_resume_breakpoint when one is already active. */
8020 gdb_assert (inferior_thread ()->control
.exception_resume_breakpoint
== NULL
);
8022 infrun_debug_printf ("inserting longjmp-resume breakpoint at %s",
8023 paddress (gdbarch
, pc
));
8025 inferior_thread ()->control
.exception_resume_breakpoint
=
8026 set_momentary_breakpoint_at_pc (gdbarch
, pc
, bp_longjmp_resume
).release ();
8029 /* Insert an exception resume breakpoint. TP is the thread throwing
8030 the exception. The block B is the block of the unwinder debug hook
8031 function. FRAME is the frame corresponding to the call to this
8032 function. SYM is the symbol of the function argument holding the
8033 target PC of the exception. */
8036 insert_exception_resume_breakpoint (struct thread_info
*tp
,
8037 const struct block
*b
,
8038 struct frame_info
*frame
,
8043 struct block_symbol vsym
;
8044 struct value
*value
;
8046 struct breakpoint
*bp
;
8048 vsym
= lookup_symbol_search_name (sym
->search_name (),
8050 value
= read_var_value (vsym
.symbol
, vsym
.block
, frame
);
8051 /* If the value was optimized out, revert to the old behavior. */
8052 if (! value_optimized_out (value
))
8054 handler
= value_as_address (value
);
8056 infrun_debug_printf ("exception resume at %lx",
8057 (unsigned long) handler
);
8059 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
8061 bp_exception_resume
).release ();
8063 /* set_momentary_breakpoint_at_pc invalidates FRAME. */
8066 bp
->thread
= tp
->global_num
;
8067 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
8070 catch (const gdb_exception_error
&e
)
8072 /* We want to ignore errors here. */
8076 /* A helper for check_exception_resume that sets an
8077 exception-breakpoint based on a SystemTap probe. */
8080 insert_exception_resume_from_probe (struct thread_info
*tp
,
8081 const struct bound_probe
*probe
,
8082 struct frame_info
*frame
)
8084 struct value
*arg_value
;
8086 struct breakpoint
*bp
;
8088 arg_value
= probe_safe_evaluate_at_pc (frame
, 1);
8092 handler
= value_as_address (arg_value
);
8094 infrun_debug_printf ("exception resume at %s",
8095 paddress (probe
->objfile
->arch (), handler
));
8097 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
8098 handler
, bp_exception_resume
).release ();
8099 bp
->thread
= tp
->global_num
;
8100 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
8103 /* This is called when an exception has been intercepted. Check to
8104 see whether the exception's destination is of interest, and if so,
8105 set an exception resume breakpoint there. */
8108 check_exception_resume (struct execution_control_state
*ecs
,
8109 struct frame_info
*frame
)
8111 struct bound_probe probe
;
8112 struct symbol
*func
;
8114 /* First see if this exception unwinding breakpoint was set via a
8115 SystemTap probe point. If so, the probe has two arguments: the
8116 CFA and the HANDLER. We ignore the CFA, extract the handler, and
8117 set a breakpoint there. */
8118 probe
= find_probe_by_pc (get_frame_pc (frame
));
8121 insert_exception_resume_from_probe (ecs
->event_thread
, &probe
, frame
);
8125 func
= get_frame_function (frame
);
8131 const struct block
*b
;
8132 struct block_iterator iter
;
8136 /* The exception breakpoint is a thread-specific breakpoint on
8137 the unwinder's debug hook, declared as:
8139 void _Unwind_DebugHook (void *cfa, void *handler);
8141 The CFA argument indicates the frame to which control is
8142 about to be transferred. HANDLER is the destination PC.
8144 We ignore the CFA and set a temporary breakpoint at HANDLER.
8145 This is not extremely efficient but it avoids issues in gdb
8146 with computing the DWARF CFA, and it also works even in weird
8147 cases such as throwing an exception from inside a signal
8150 b
= SYMBOL_BLOCK_VALUE (func
);
8151 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
8153 if (!SYMBOL_IS_ARGUMENT (sym
))
8160 insert_exception_resume_breakpoint (ecs
->event_thread
,
8166 catch (const gdb_exception_error
&e
)
8172 stop_waiting (struct execution_control_state
*ecs
)
8174 infrun_debug_printf ("stop_waiting");
8176 /* Let callers know we don't want to wait for the inferior anymore. */
8177 ecs
->wait_some_more
= 0;
8179 /* If all-stop, but there exists a non-stop target, stop all
8180 threads now that we're presenting the stop to the user. */
8181 if (!non_stop
&& exists_non_stop_target ())
8182 stop_all_threads ("presenting stop to user in all-stop");
8185 /* Like keep_going, but passes the signal to the inferior, even if the
8186 signal is set to nopass. */
8189 keep_going_pass_signal (struct execution_control_state
*ecs
)
8191 gdb_assert (ecs
->event_thread
->ptid
== inferior_ptid
);
8192 gdb_assert (!ecs
->event_thread
->resumed
);
8194 /* Save the pc before execution, to compare with pc after stop. */
8195 ecs
->event_thread
->prev_pc
8196 = regcache_read_pc_protected (get_thread_regcache (ecs
->event_thread
));
8198 if (ecs
->event_thread
->control
.trap_expected
)
8200 struct thread_info
*tp
= ecs
->event_thread
;
8202 infrun_debug_printf ("%s has trap_expected set, "
8203 "resuming to collect trap",
8204 target_pid_to_str (tp
->ptid
).c_str ());
8206 /* We haven't yet gotten our trap, and either: intercepted a
8207 non-signal event (e.g., a fork); or took a signal which we
8208 are supposed to pass through to the inferior. Simply
8210 resume (ecs
->event_thread
->suspend
.stop_signal
);
8212 else if (step_over_info_valid_p ())
8214 /* Another thread is stepping over a breakpoint in-line. If
8215 this thread needs a step-over too, queue the request. In
8216 either case, this resume must be deferred for later. */
8217 struct thread_info
*tp
= ecs
->event_thread
;
8219 if (ecs
->hit_singlestep_breakpoint
8220 || thread_still_needs_step_over (tp
))
8222 infrun_debug_printf ("step-over already in progress: "
8223 "step-over for %s deferred",
8224 target_pid_to_str (tp
->ptid
).c_str ());
8225 global_thread_step_over_chain_enqueue (tp
);
8229 infrun_debug_printf ("step-over in progress: resume of %s deferred",
8230 target_pid_to_str (tp
->ptid
).c_str ());
8235 struct regcache
*regcache
= get_current_regcache ();
8238 step_over_what step_what
;
8240 /* Either the trap was not expected, but we are continuing
8241 anyway (if we got a signal, the user asked it be passed to
8244 We got our expected trap, but decided we should resume from
8247 We're going to run this baby now!
8249 Note that insert_breakpoints won't try to re-insert
8250 already inserted breakpoints. Therefore, we don't
8251 care if breakpoints were already inserted, or not. */
8253 /* If we need to step over a breakpoint, and we're not using
8254 displaced stepping to do so, insert all breakpoints
8255 (watchpoints, etc.) but the one we're stepping over, step one
8256 instruction, and then re-insert the breakpoint when that step
8259 step_what
= thread_still_needs_step_over (ecs
->event_thread
);
8261 remove_bp
= (ecs
->hit_singlestep_breakpoint
8262 || (step_what
& STEP_OVER_BREAKPOINT
));
8263 remove_wps
= (step_what
& STEP_OVER_WATCHPOINT
);
8265 /* We can't use displaced stepping if we need to step past a
8266 watchpoint. The instruction copied to the scratch pad would
8267 still trigger the watchpoint. */
8269 && (remove_wps
|| !use_displaced_stepping (ecs
->event_thread
)))
8271 set_step_over_info (regcache
->aspace (),
8272 regcache_read_pc (regcache
), remove_wps
,
8273 ecs
->event_thread
->global_num
);
8275 else if (remove_wps
)
8276 set_step_over_info (NULL
, 0, remove_wps
, -1);
8278 /* If we now need to do an in-line step-over, we need to stop
8279 all other threads. Note this must be done before
8280 insert_breakpoints below, because that removes the breakpoint
8281 we're about to step over, otherwise other threads could miss
8283 if (step_over_info_valid_p () && target_is_non_stop_p ())
8284 stop_all_threads ("starting in-line step-over");
8286 /* Stop stepping if inserting breakpoints fails. */
8289 insert_breakpoints ();
8291 catch (const gdb_exception_error
&e
)
8293 exception_print (gdb_stderr
, e
);
8295 clear_step_over_info ();
8299 ecs
->event_thread
->control
.trap_expected
= (remove_bp
|| remove_wps
);
8301 resume (ecs
->event_thread
->suspend
.stop_signal
);
8304 prepare_to_wait (ecs
);
8307 /* Called when we should continue running the inferior, because the
8308 current event doesn't cause a user visible stop. This does the
8309 resuming part; waiting for the next event is done elsewhere. */
8312 keep_going (struct execution_control_state
*ecs
)
8314 if (ecs
->event_thread
->control
.trap_expected
8315 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
8316 ecs
->event_thread
->control
.trap_expected
= 0;
8318 if (!signal_program
[ecs
->event_thread
->suspend
.stop_signal
])
8319 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
8320 keep_going_pass_signal (ecs
);
8323 /* This function normally comes after a resume, before
8324 handle_inferior_event exits. It takes care of any last bits of
8325 housekeeping, and sets the all-important wait_some_more flag. */
8328 prepare_to_wait (struct execution_control_state
*ecs
)
8330 infrun_debug_printf ("prepare_to_wait");
8332 ecs
->wait_some_more
= 1;
8334 /* If the target can't async, emulate it by marking the infrun event
8335 handler such that as soon as we get back to the event-loop, we
8336 immediately end up in fetch_inferior_event again calling
8338 if (!target_can_async_p ())
8339 mark_infrun_async_event_handler ();
8342 /* We are done with the step range of a step/next/si/ni command.
8343 Called once for each n of a "step n" operation. */
8346 end_stepping_range (struct execution_control_state
*ecs
)
8348 ecs
->event_thread
->control
.stop_step
= 1;
8352 /* Several print_*_reason functions to print why the inferior has stopped.
8353 We always print something when the inferior exits, or receives a signal.
8354 The rest of the cases are dealt with later on in normal_stop and
8355 print_it_typical. Ideally there should be a call to one of these
8356 print_*_reason functions functions from handle_inferior_event each time
8357 stop_waiting is called.
8359 Note that we don't call these directly, instead we delegate that to
8360 the interpreters, through observers. Interpreters then call these
8361 with whatever uiout is right. */
8364 print_end_stepping_range_reason (struct ui_out
*uiout
)
8366 /* For CLI-like interpreters, print nothing. */
8368 if (uiout
->is_mi_like_p ())
8370 uiout
->field_string ("reason",
8371 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE
));
8376 print_signal_exited_reason (struct ui_out
*uiout
, enum gdb_signal siggnal
)
8378 annotate_signalled ();
8379 if (uiout
->is_mi_like_p ())
8381 ("reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED
));
8382 uiout
->text ("\nProgram terminated with signal ");
8383 annotate_signal_name ();
8384 uiout
->field_string ("signal-name",
8385 gdb_signal_to_name (siggnal
));
8386 annotate_signal_name_end ();
8388 annotate_signal_string ();
8389 uiout
->field_string ("signal-meaning",
8390 gdb_signal_to_string (siggnal
));
8391 annotate_signal_string_end ();
8392 uiout
->text (".\n");
8393 uiout
->text ("The program no longer exists.\n");
8397 print_exited_reason (struct ui_out
*uiout
, int exitstatus
)
8399 struct inferior
*inf
= current_inferior ();
8400 std::string pidstr
= target_pid_to_str (ptid_t (inf
->pid
));
8402 annotate_exited (exitstatus
);
8405 if (uiout
->is_mi_like_p ())
8406 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXITED
));
8407 std::string exit_code_str
8408 = string_printf ("0%o", (unsigned int) exitstatus
);
8409 uiout
->message ("[Inferior %s (%s) exited with code %pF]\n",
8410 plongest (inf
->num
), pidstr
.c_str (),
8411 string_field ("exit-code", exit_code_str
.c_str ()));
8415 if (uiout
->is_mi_like_p ())
8417 ("reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY
));
8418 uiout
->message ("[Inferior %s (%s) exited normally]\n",
8419 plongest (inf
->num
), pidstr
.c_str ());
8424 print_signal_received_reason (struct ui_out
*uiout
, enum gdb_signal siggnal
)
8426 struct thread_info
*thr
= inferior_thread ();
8430 if (uiout
->is_mi_like_p ())
8432 else if (show_thread_that_caused_stop ())
8436 uiout
->text ("\nThread ");
8437 uiout
->field_string ("thread-id", print_thread_id (thr
));
8439 name
= thr
->name
!= NULL
? thr
->name
: target_thread_name (thr
);
8442 uiout
->text (" \"");
8443 uiout
->field_string ("name", name
);
8448 uiout
->text ("\nProgram");
8450 if (siggnal
== GDB_SIGNAL_0
&& !uiout
->is_mi_like_p ())
8451 uiout
->text (" stopped");
8454 uiout
->text (" received signal ");
8455 annotate_signal_name ();
8456 if (uiout
->is_mi_like_p ())
8458 ("reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED
));
8459 uiout
->field_string ("signal-name", gdb_signal_to_name (siggnal
));
8460 annotate_signal_name_end ();
8462 annotate_signal_string ();
8463 uiout
->field_string ("signal-meaning", gdb_signal_to_string (siggnal
));
8465 struct regcache
*regcache
= get_current_regcache ();
8466 struct gdbarch
*gdbarch
= regcache
->arch ();
8467 if (gdbarch_report_signal_info_p (gdbarch
))
8468 gdbarch_report_signal_info (gdbarch
, uiout
, siggnal
);
8470 annotate_signal_string_end ();
8472 uiout
->text (".\n");
8476 print_no_history_reason (struct ui_out
*uiout
)
8478 uiout
->text ("\nNo more reverse-execution history.\n");
8481 /* Print current location without a level number, if we have changed
8482 functions or hit a breakpoint. Print source line if we have one.
8483 bpstat_print contains the logic deciding in detail what to print,
8484 based on the event(s) that just occurred. */
8487 print_stop_location (struct target_waitstatus
*ws
)
8490 enum print_what source_flag
;
8491 int do_frame_printing
= 1;
8492 struct thread_info
*tp
= inferior_thread ();
8494 bpstat_ret
= bpstat_print (tp
->control
.stop_bpstat
, ws
->kind
);
8498 /* FIXME: cagney/2002-12-01: Given that a frame ID does (or
8499 should) carry around the function and does (or should) use
8500 that when doing a frame comparison. */
8501 if (tp
->control
.stop_step
8502 && frame_id_eq (tp
->control
.step_frame_id
,
8503 get_frame_id (get_current_frame ()))
8504 && (tp
->control
.step_start_function
8505 == find_pc_function (tp
->suspend
.stop_pc
)))
8507 /* Finished step, just print source line. */
8508 source_flag
= SRC_LINE
;
8512 /* Print location and source line. */
8513 source_flag
= SRC_AND_LOC
;
8516 case PRINT_SRC_AND_LOC
:
8517 /* Print location and source line. */
8518 source_flag
= SRC_AND_LOC
;
8520 case PRINT_SRC_ONLY
:
8521 source_flag
= SRC_LINE
;
8524 /* Something bogus. */
8525 source_flag
= SRC_LINE
;
8526 do_frame_printing
= 0;
8529 internal_error (__FILE__
, __LINE__
, _("Unknown value."));
8532 /* The behavior of this routine with respect to the source
8534 SRC_LINE: Print only source line
8535 LOCATION: Print only location
8536 SRC_AND_LOC: Print location and source line. */
8537 if (do_frame_printing
)
8538 print_stack_frame (get_selected_frame (NULL
), 0, source_flag
, 1);
8544 print_stop_event (struct ui_out
*uiout
, bool displays
)
8546 struct target_waitstatus last
;
8547 struct thread_info
*tp
;
8549 get_last_target_status (nullptr, nullptr, &last
);
8552 scoped_restore save_uiout
= make_scoped_restore (¤t_uiout
, uiout
);
8554 print_stop_location (&last
);
8556 /* Display the auto-display expressions. */
8561 tp
= inferior_thread ();
8562 if (tp
->thread_fsm
!= NULL
8563 && tp
->thread_fsm
->finished_p ())
8565 struct return_value_info
*rv
;
8567 rv
= tp
->thread_fsm
->return_value ();
8569 print_return_value (uiout
, rv
);
8576 maybe_remove_breakpoints (void)
8578 if (!breakpoints_should_be_inserted_now () && target_has_execution ())
8580 if (remove_breakpoints ())
8582 target_terminal::ours_for_output ();
8583 printf_filtered (_("Cannot remove breakpoints because "
8584 "program is no longer writable.\nFurther "
8585 "execution is probably impossible.\n"));
8590 /* The execution context that just caused a normal stop. */
8596 DISABLE_COPY_AND_ASSIGN (stop_context
);
8598 bool changed () const;
8603 /* The event PTID. */
8607 /* If stopp for a thread event, this is the thread that caused the
8609 thread_info_ref thread
;
8611 /* The inferior that caused the stop. */
8615 /* Initializes a new stop context. If stopped for a thread event, this
8616 takes a strong reference to the thread. */
8618 stop_context::stop_context ()
8620 stop_id
= get_stop_id ();
8621 ptid
= inferior_ptid
;
8622 inf_num
= current_inferior ()->num
;
8624 if (inferior_ptid
!= null_ptid
)
8626 /* Take a strong reference so that the thread can't be deleted
8628 thread
= thread_info_ref::new_reference (inferior_thread ());
8632 /* Return true if the current context no longer matches the saved stop
8636 stop_context::changed () const
8638 if (ptid
!= inferior_ptid
)
8640 if (inf_num
!= current_inferior ()->num
)
8642 if (thread
!= NULL
&& thread
->state
!= THREAD_STOPPED
)
8644 if (get_stop_id () != stop_id
)
8654 struct target_waitstatus last
;
8656 get_last_target_status (nullptr, nullptr, &last
);
8660 /* If an exception is thrown from this point on, make sure to
8661 propagate GDB's knowledge of the executing state to the
8662 frontend/user running state. A QUIT is an easy exception to see
8663 here, so do this before any filtered output. */
8665 ptid_t finish_ptid
= null_ptid
;
8668 finish_ptid
= minus_one_ptid
;
8669 else if (last
.kind
== TARGET_WAITKIND_SIGNALLED
8670 || last
.kind
== TARGET_WAITKIND_EXITED
)
8672 /* On some targets, we may still have live threads in the
8673 inferior when we get a process exit event. E.g., for
8674 "checkpoint", when the current checkpoint/fork exits,
8675 linux-fork.c automatically switches to another fork from
8676 within target_mourn_inferior. */
8677 if (inferior_ptid
!= null_ptid
)
8678 finish_ptid
= ptid_t (inferior_ptid
.pid ());
8680 else if (last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
8681 finish_ptid
= inferior_ptid
;
8683 gdb::optional
<scoped_finish_thread_state
> maybe_finish_thread_state
;
8684 if (finish_ptid
!= null_ptid
)
8686 maybe_finish_thread_state
.emplace
8687 (user_visible_resume_target (finish_ptid
), finish_ptid
);
8690 /* As we're presenting a stop, and potentially removing breakpoints,
8691 update the thread list so we can tell whether there are threads
8692 running on the target. With target remote, for example, we can
8693 only learn about new threads when we explicitly update the thread
8694 list. Do this before notifying the interpreters about signal
8695 stops, end of stepping ranges, etc., so that the "new thread"
8696 output is emitted before e.g., "Program received signal FOO",
8697 instead of after. */
8698 update_thread_list ();
8700 if (last
.kind
== TARGET_WAITKIND_STOPPED
&& stopped_by_random_signal
)
8701 gdb::observers::signal_received
.notify (inferior_thread ()->suspend
.stop_signal
);
8703 /* As with the notification of thread events, we want to delay
8704 notifying the user that we've switched thread context until
8705 the inferior actually stops.
8707 There's no point in saying anything if the inferior has exited.
8708 Note that SIGNALLED here means "exited with a signal", not
8709 "received a signal".
8711 Also skip saying anything in non-stop mode. In that mode, as we
8712 don't want GDB to switch threads behind the user's back, to avoid
8713 races where the user is typing a command to apply to thread x,
8714 but GDB switches to thread y before the user finishes entering
8715 the command, fetch_inferior_event installs a cleanup to restore
8716 the current thread back to the thread the user had selected right
8717 after this event is handled, so we're not really switching, only
8718 informing of a stop. */
8720 && previous_inferior_ptid
!= inferior_ptid
8721 && target_has_execution ()
8722 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
8723 && last
.kind
!= TARGET_WAITKIND_EXITED
8724 && last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
8726 SWITCH_THRU_ALL_UIS ()
8728 target_terminal::ours_for_output ();
8729 printf_filtered (_("[Switching to %s]\n"),
8730 target_pid_to_str (inferior_ptid
).c_str ());
8731 annotate_thread_changed ();
8733 previous_inferior_ptid
= inferior_ptid
;
8736 if (last
.kind
== TARGET_WAITKIND_NO_RESUMED
)
8738 SWITCH_THRU_ALL_UIS ()
8739 if (current_ui
->prompt_state
== PROMPT_BLOCKED
)
8741 target_terminal::ours_for_output ();
8742 printf_filtered (_("No unwaited-for children left.\n"));
8746 /* Note: this depends on the update_thread_list call above. */
8747 maybe_remove_breakpoints ();
8749 /* If an auto-display called a function and that got a signal,
8750 delete that auto-display to avoid an infinite recursion. */
8752 if (stopped_by_random_signal
)
8753 disable_current_display ();
8755 SWITCH_THRU_ALL_UIS ()
8757 async_enable_stdin ();
8760 /* Let the user/frontend see the threads as stopped. */
8761 maybe_finish_thread_state
.reset ();
8763 /* Select innermost stack frame - i.e., current frame is frame 0,
8764 and current location is based on that. Handle the case where the
8765 dummy call is returning after being stopped. E.g. the dummy call
8766 previously hit a breakpoint. (If the dummy call returns
8767 normally, we won't reach here.) Do this before the stop hook is
8768 run, so that it doesn't get to see the temporary dummy frame,
8769 which is not where we'll present the stop. */
8770 if (has_stack_frames ())
8772 if (stop_stack_dummy
== STOP_STACK_DUMMY
)
8774 /* Pop the empty frame that contains the stack dummy. This
8775 also restores inferior state prior to the call (struct
8776 infcall_suspend_state). */
8777 struct frame_info
*frame
= get_current_frame ();
8779 gdb_assert (get_frame_type (frame
) == DUMMY_FRAME
);
8781 /* frame_pop calls reinit_frame_cache as the last thing it
8782 does which means there's now no selected frame. */
8785 select_frame (get_current_frame ());
8787 /* Set the current source location. */
8788 set_current_sal_from_frame (get_current_frame ());
8791 /* Look up the hook_stop and run it (CLI internally handles problem
8792 of stop_command's pre-hook not existing). */
8793 if (stop_command
!= NULL
)
8795 stop_context saved_context
;
8799 execute_cmd_pre_hook (stop_command
);
8801 catch (const gdb_exception
&ex
)
8803 exception_fprintf (gdb_stderr
, ex
,
8804 "Error while running hook_stop:\n");
8807 /* If the stop hook resumes the target, then there's no point in
8808 trying to notify about the previous stop; its context is
8809 gone. Likewise if the command switches thread or inferior --
8810 the observers would print a stop for the wrong
8812 if (saved_context
.changed ())
8816 /* Notify observers about the stop. This is where the interpreters
8817 print the stop event. */
8818 if (inferior_ptid
!= null_ptid
)
8819 gdb::observers::normal_stop
.notify (inferior_thread ()->control
.stop_bpstat
,
8822 gdb::observers::normal_stop
.notify (NULL
, stop_print_frame
);
8824 annotate_stopped ();
8826 if (target_has_execution ())
8828 if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
8829 && last
.kind
!= TARGET_WAITKIND_EXITED
8830 && last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
8831 /* Delete the breakpoint we stopped at, if it wants to be deleted.
8832 Delete any breakpoint that is to be deleted at the next stop. */
8833 breakpoint_auto_delete (inferior_thread ()->control
.stop_bpstat
);
8836 /* Try to get rid of automatically added inferiors that are no
8837 longer needed. Keeping those around slows down things linearly.
8838 Note that this never removes the current inferior. */
8845 signal_stop_state (int signo
)
8847 return signal_stop
[signo
];
8851 signal_print_state (int signo
)
8853 return signal_print
[signo
];
8857 signal_pass_state (int signo
)
8859 return signal_program
[signo
];
8863 signal_cache_update (int signo
)
8867 for (signo
= 0; signo
< (int) GDB_SIGNAL_LAST
; signo
++)
8868 signal_cache_update (signo
);
8873 signal_pass
[signo
] = (signal_stop
[signo
] == 0
8874 && signal_print
[signo
] == 0
8875 && signal_program
[signo
] == 1
8876 && signal_catch
[signo
] == 0);
8880 signal_stop_update (int signo
, int state
)
8882 int ret
= signal_stop
[signo
];
8884 signal_stop
[signo
] = state
;
8885 signal_cache_update (signo
);
8890 signal_print_update (int signo
, int state
)
8892 int ret
= signal_print
[signo
];
8894 signal_print
[signo
] = state
;
8895 signal_cache_update (signo
);
8900 signal_pass_update (int signo
, int state
)
8902 int ret
= signal_program
[signo
];
8904 signal_program
[signo
] = state
;
8905 signal_cache_update (signo
);
8909 /* Update the global 'signal_catch' from INFO and notify the
8913 signal_catch_update (const unsigned int *info
)
8917 for (i
= 0; i
< GDB_SIGNAL_LAST
; ++i
)
8918 signal_catch
[i
] = info
[i
] > 0;
8919 signal_cache_update (-1);
8920 target_pass_signals (signal_pass
);
8924 sig_print_header (void)
8926 printf_filtered (_("Signal Stop\tPrint\tPass "
8927 "to program\tDescription\n"));
8931 sig_print_info (enum gdb_signal oursig
)
8933 const char *name
= gdb_signal_to_name (oursig
);
8934 int name_padding
= 13 - strlen (name
);
8936 if (name_padding
<= 0)
8939 printf_filtered ("%s", name
);
8940 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
8941 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
8942 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
8943 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
8944 printf_filtered ("%s\n", gdb_signal_to_string (oursig
));
8947 /* Specify how various signals in the inferior should be handled. */
8950 handle_command (const char *args
, int from_tty
)
8952 int digits
, wordlen
;
8953 int sigfirst
, siglast
;
8954 enum gdb_signal oursig
;
8959 error_no_arg (_("signal to handle"));
8962 /* Allocate and zero an array of flags for which signals to handle. */
8964 const size_t nsigs
= GDB_SIGNAL_LAST
;
8965 unsigned char sigs
[nsigs
] {};
8967 /* Break the command line up into args. */
8969 gdb_argv
built_argv (args
);
8971 /* Walk through the args, looking for signal oursigs, signal names, and
8972 actions. Signal numbers and signal names may be interspersed with
8973 actions, with the actions being performed for all signals cumulatively
8974 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
8976 for (char *arg
: built_argv
)
8978 wordlen
= strlen (arg
);
8979 for (digits
= 0; isdigit (arg
[digits
]); digits
++)
8983 sigfirst
= siglast
= -1;
8985 if (wordlen
>= 1 && !strncmp (arg
, "all", wordlen
))
8987 /* Apply action to all signals except those used by the
8988 debugger. Silently skip those. */
8991 siglast
= nsigs
- 1;
8993 else if (wordlen
>= 1 && !strncmp (arg
, "stop", wordlen
))
8995 SET_SIGS (nsigs
, sigs
, signal_stop
);
8996 SET_SIGS (nsigs
, sigs
, signal_print
);
8998 else if (wordlen
>= 1 && !strncmp (arg
, "ignore", wordlen
))
9000 UNSET_SIGS (nsigs
, sigs
, signal_program
);
9002 else if (wordlen
>= 2 && !strncmp (arg
, "print", wordlen
))
9004 SET_SIGS (nsigs
, sigs
, signal_print
);
9006 else if (wordlen
>= 2 && !strncmp (arg
, "pass", wordlen
))
9008 SET_SIGS (nsigs
, sigs
, signal_program
);
9010 else if (wordlen
>= 3 && !strncmp (arg
, "nostop", wordlen
))
9012 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
9014 else if (wordlen
>= 3 && !strncmp (arg
, "noignore", wordlen
))
9016 SET_SIGS (nsigs
, sigs
, signal_program
);
9018 else if (wordlen
>= 4 && !strncmp (arg
, "noprint", wordlen
))
9020 UNSET_SIGS (nsigs
, sigs
, signal_print
);
9021 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
9023 else if (wordlen
>= 4 && !strncmp (arg
, "nopass", wordlen
))
9025 UNSET_SIGS (nsigs
, sigs
, signal_program
);
9027 else if (digits
> 0)
9029 /* It is numeric. The numeric signal refers to our own
9030 internal signal numbering from target.h, not to host/target
9031 signal number. This is a feature; users really should be
9032 using symbolic names anyway, and the common ones like
9033 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
9035 sigfirst
= siglast
= (int)
9036 gdb_signal_from_command (atoi (arg
));
9037 if (arg
[digits
] == '-')
9040 gdb_signal_from_command (atoi (arg
+ digits
+ 1));
9042 if (sigfirst
> siglast
)
9044 /* Bet he didn't figure we'd think of this case... */
9045 std::swap (sigfirst
, siglast
);
9050 oursig
= gdb_signal_from_name (arg
);
9051 if (oursig
!= GDB_SIGNAL_UNKNOWN
)
9053 sigfirst
= siglast
= (int) oursig
;
9057 /* Not a number and not a recognized flag word => complain. */
9058 error (_("Unrecognized or ambiguous flag word: \"%s\"."), arg
);
9062 /* If any signal numbers or symbol names were found, set flags for
9063 which signals to apply actions to. */
9065 for (int signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
9067 switch ((enum gdb_signal
) signum
)
9069 case GDB_SIGNAL_TRAP
:
9070 case GDB_SIGNAL_INT
:
9071 if (!allsigs
&& !sigs
[signum
])
9073 if (query (_("%s is used by the debugger.\n\
9074 Are you sure you want to change it? "),
9075 gdb_signal_to_name ((enum gdb_signal
) signum
)))
9080 printf_unfiltered (_("Not confirmed, unchanged.\n"));
9084 case GDB_SIGNAL_DEFAULT
:
9085 case GDB_SIGNAL_UNKNOWN
:
9086 /* Make sure that "all" doesn't print these. */
9095 for (int signum
= 0; signum
< nsigs
; signum
++)
9098 signal_cache_update (-1);
9099 target_pass_signals (signal_pass
);
9100 target_program_signals (signal_program
);
9104 /* Show the results. */
9105 sig_print_header ();
9106 for (; signum
< nsigs
; signum
++)
9108 sig_print_info ((enum gdb_signal
) signum
);
9115 /* Complete the "handle" command. */
9118 handle_completer (struct cmd_list_element
*ignore
,
9119 completion_tracker
&tracker
,
9120 const char *text
, const char *word
)
9122 static const char * const keywords
[] =
9136 signal_completer (ignore
, tracker
, text
, word
);
9137 complete_on_enum (tracker
, keywords
, word
, word
);
9141 gdb_signal_from_command (int num
)
9143 if (num
>= 1 && num
<= 15)
9144 return (enum gdb_signal
) num
;
9145 error (_("Only signals 1-15 are valid as numeric signals.\n\
9146 Use \"info signals\" for a list of symbolic signals."));
9149 /* Print current contents of the tables set by the handle command.
9150 It is possible we should just be printing signals actually used
9151 by the current target (but for things to work right when switching
9152 targets, all signals should be in the signal tables). */
9155 info_signals_command (const char *signum_exp
, int from_tty
)
9157 enum gdb_signal oursig
;
9159 sig_print_header ();
9163 /* First see if this is a symbol name. */
9164 oursig
= gdb_signal_from_name (signum_exp
);
9165 if (oursig
== GDB_SIGNAL_UNKNOWN
)
9167 /* No, try numeric. */
9169 gdb_signal_from_command (parse_and_eval_long (signum_exp
));
9171 sig_print_info (oursig
);
9175 printf_filtered ("\n");
9176 /* These ugly casts brought to you by the native VAX compiler. */
9177 for (oursig
= GDB_SIGNAL_FIRST
;
9178 (int) oursig
< (int) GDB_SIGNAL_LAST
;
9179 oursig
= (enum gdb_signal
) ((int) oursig
+ 1))
9183 if (oursig
!= GDB_SIGNAL_UNKNOWN
9184 && oursig
!= GDB_SIGNAL_DEFAULT
&& oursig
!= GDB_SIGNAL_0
)
9185 sig_print_info (oursig
);
9188 printf_filtered (_("\nUse the \"handle\" command "
9189 "to change these tables.\n"));
9192 /* The $_siginfo convenience variable is a bit special. We don't know
9193 for sure the type of the value until we actually have a chance to
9194 fetch the data. The type can change depending on gdbarch, so it is
9195 also dependent on which thread you have selected.
9197 1. making $_siginfo be an internalvar that creates a new value on
9200 2. making the value of $_siginfo be an lval_computed value. */
9202 /* This function implements the lval_computed support for reading a
9206 siginfo_value_read (struct value
*v
)
9208 LONGEST transferred
;
9210 /* If we can access registers, so can we access $_siginfo. Likewise
9212 validate_registers_access ();
9215 target_read (current_inferior ()->top_target (),
9216 TARGET_OBJECT_SIGNAL_INFO
,
9218 value_contents_all_raw (v
),
9220 TYPE_LENGTH (value_type (v
)));
9222 if (transferred
!= TYPE_LENGTH (value_type (v
)))
9223 error (_("Unable to read siginfo"));
9226 /* This function implements the lval_computed support for writing a
9230 siginfo_value_write (struct value
*v
, struct value
*fromval
)
9232 LONGEST transferred
;
9234 /* If we can access registers, so can we access $_siginfo. Likewise
9236 validate_registers_access ();
9238 transferred
= target_write (current_inferior ()->top_target (),
9239 TARGET_OBJECT_SIGNAL_INFO
,
9241 value_contents_all_raw (fromval
),
9243 TYPE_LENGTH (value_type (fromval
)));
9245 if (transferred
!= TYPE_LENGTH (value_type (fromval
)))
9246 error (_("Unable to write siginfo"));
9249 static const struct lval_funcs siginfo_value_funcs
=
9255 /* Return a new value with the correct type for the siginfo object of
9256 the current thread using architecture GDBARCH. Return a void value
9257 if there's no object available. */
9259 static struct value
*
9260 siginfo_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
,
9263 if (target_has_stack ()
9264 && inferior_ptid
!= null_ptid
9265 && gdbarch_get_siginfo_type_p (gdbarch
))
9267 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
9269 return allocate_computed_value (type
, &siginfo_value_funcs
, NULL
);
9272 return allocate_value (builtin_type (gdbarch
)->builtin_void
);
9276 /* infcall_suspend_state contains state about the program itself like its
9277 registers and any signal it received when it last stopped.
9278 This state must be restored regardless of how the inferior function call
9279 ends (either successfully, or after it hits a breakpoint or signal)
9280 if the program is to properly continue where it left off. */
9282 class infcall_suspend_state
9285 /* Capture state from GDBARCH, TP, and REGCACHE that must be restored
9286 once the inferior function call has finished. */
9287 infcall_suspend_state (struct gdbarch
*gdbarch
,
9288 const struct thread_info
*tp
,
9289 struct regcache
*regcache
)
9290 : m_thread_suspend (tp
->suspend
),
9291 m_registers (new readonly_detached_regcache (*regcache
))
9293 gdb::unique_xmalloc_ptr
<gdb_byte
> siginfo_data
;
9295 if (gdbarch_get_siginfo_type_p (gdbarch
))
9297 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
9298 size_t len
= TYPE_LENGTH (type
);
9300 siginfo_data
.reset ((gdb_byte
*) xmalloc (len
));
9302 if (target_read (current_inferior ()->top_target (),
9303 TARGET_OBJECT_SIGNAL_INFO
, NULL
,
9304 siginfo_data
.get (), 0, len
) != len
)
9306 /* Errors ignored. */
9307 siginfo_data
.reset (nullptr);
9313 m_siginfo_gdbarch
= gdbarch
;
9314 m_siginfo_data
= std::move (siginfo_data
);
9318 /* Return a pointer to the stored register state. */
9320 readonly_detached_regcache
*registers () const
9322 return m_registers
.get ();
9325 /* Restores the stored state into GDBARCH, TP, and REGCACHE. */
9327 void restore (struct gdbarch
*gdbarch
,
9328 struct thread_info
*tp
,
9329 struct regcache
*regcache
) const
9331 tp
->suspend
= m_thread_suspend
;
9333 if (m_siginfo_gdbarch
== gdbarch
)
9335 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
9337 /* Errors ignored. */
9338 target_write (current_inferior ()->top_target (),
9339 TARGET_OBJECT_SIGNAL_INFO
, NULL
,
9340 m_siginfo_data
.get (), 0, TYPE_LENGTH (type
));
9343 /* The inferior can be gone if the user types "print exit(0)"
9344 (and perhaps other times). */
9345 if (target_has_execution ())
9346 /* NB: The register write goes through to the target. */
9347 regcache
->restore (registers ());
9351 /* How the current thread stopped before the inferior function call was
9353 struct thread_suspend_state m_thread_suspend
;
9355 /* The registers before the inferior function call was executed. */
9356 std::unique_ptr
<readonly_detached_regcache
> m_registers
;
9358 /* Format of SIGINFO_DATA or NULL if it is not present. */
9359 struct gdbarch
*m_siginfo_gdbarch
= nullptr;
9361 /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
9362 TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the
9363 content would be invalid. */
9364 gdb::unique_xmalloc_ptr
<gdb_byte
> m_siginfo_data
;
9367 infcall_suspend_state_up
9368 save_infcall_suspend_state ()
9370 struct thread_info
*tp
= inferior_thread ();
9371 struct regcache
*regcache
= get_current_regcache ();
9372 struct gdbarch
*gdbarch
= regcache
->arch ();
9374 infcall_suspend_state_up inf_state
9375 (new struct infcall_suspend_state (gdbarch
, tp
, regcache
));
9377 /* Having saved the current state, adjust the thread state, discarding
9378 any stop signal information. The stop signal is not useful when
9379 starting an inferior function call, and run_inferior_call will not use
9380 the signal due to its `proceed' call with GDB_SIGNAL_0. */
9381 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
9386 /* Restore inferior session state to INF_STATE. */
9389 restore_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
9391 struct thread_info
*tp
= inferior_thread ();
9392 struct regcache
*regcache
= get_current_regcache ();
9393 struct gdbarch
*gdbarch
= regcache
->arch ();
9395 inf_state
->restore (gdbarch
, tp
, regcache
);
9396 discard_infcall_suspend_state (inf_state
);
9400 discard_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
9405 readonly_detached_regcache
*
9406 get_infcall_suspend_state_regcache (struct infcall_suspend_state
*inf_state
)
9408 return inf_state
->registers ();
9411 /* infcall_control_state contains state regarding gdb's control of the
9412 inferior itself like stepping control. It also contains session state like
9413 the user's currently selected frame. */
9415 struct infcall_control_state
9417 struct thread_control_state thread_control
;
9418 struct inferior_control_state inferior_control
;
9421 enum stop_stack_kind stop_stack_dummy
= STOP_NONE
;
9422 int stopped_by_random_signal
= 0;
9424 /* ID and level of the selected frame when the inferior function
9426 struct frame_id selected_frame_id
{};
9427 int selected_frame_level
= -1;
9430 /* Save all of the information associated with the inferior<==>gdb
9433 infcall_control_state_up
9434 save_infcall_control_state ()
9436 infcall_control_state_up
inf_status (new struct infcall_control_state
);
9437 struct thread_info
*tp
= inferior_thread ();
9438 struct inferior
*inf
= current_inferior ();
9440 inf_status
->thread_control
= tp
->control
;
9441 inf_status
->inferior_control
= inf
->control
;
9443 tp
->control
.step_resume_breakpoint
= NULL
;
9444 tp
->control
.exception_resume_breakpoint
= NULL
;
9446 /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of
9447 chain. If caller's caller is walking the chain, they'll be happier if we
9448 hand them back the original chain when restore_infcall_control_state is
9450 tp
->control
.stop_bpstat
= bpstat_copy (tp
->control
.stop_bpstat
);
9453 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
9454 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
9456 save_selected_frame (&inf_status
->selected_frame_id
,
9457 &inf_status
->selected_frame_level
);
9462 /* Restore inferior session state to INF_STATUS. */
9465 restore_infcall_control_state (struct infcall_control_state
*inf_status
)
9467 struct thread_info
*tp
= inferior_thread ();
9468 struct inferior
*inf
= current_inferior ();
9470 if (tp
->control
.step_resume_breakpoint
)
9471 tp
->control
.step_resume_breakpoint
->disposition
= disp_del_at_next_stop
;
9473 if (tp
->control
.exception_resume_breakpoint
)
9474 tp
->control
.exception_resume_breakpoint
->disposition
9475 = disp_del_at_next_stop
;
9477 /* Handle the bpstat_copy of the chain. */
9478 bpstat_clear (&tp
->control
.stop_bpstat
);
9480 tp
->control
= inf_status
->thread_control
;
9481 inf
->control
= inf_status
->inferior_control
;
9484 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
9485 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
9487 if (target_has_stack ())
9489 restore_selected_frame (inf_status
->selected_frame_id
,
9490 inf_status
->selected_frame_level
);
9497 discard_infcall_control_state (struct infcall_control_state
*inf_status
)
9499 if (inf_status
->thread_control
.step_resume_breakpoint
)
9500 inf_status
->thread_control
.step_resume_breakpoint
->disposition
9501 = disp_del_at_next_stop
;
9503 if (inf_status
->thread_control
.exception_resume_breakpoint
)
9504 inf_status
->thread_control
.exception_resume_breakpoint
->disposition
9505 = disp_del_at_next_stop
;
9507 /* See save_infcall_control_state for info on stop_bpstat. */
9508 bpstat_clear (&inf_status
->thread_control
.stop_bpstat
);
9516 clear_exit_convenience_vars (void)
9518 clear_internalvar (lookup_internalvar ("_exitsignal"));
9519 clear_internalvar (lookup_internalvar ("_exitcode"));
9523 /* User interface for reverse debugging:
9524 Set exec-direction / show exec-direction commands
9525 (returns error unless target implements to_set_exec_direction method). */
9527 enum exec_direction_kind execution_direction
= EXEC_FORWARD
;
9528 static const char exec_forward
[] = "forward";
9529 static const char exec_reverse
[] = "reverse";
9530 static const char *exec_direction
= exec_forward
;
9531 static const char *const exec_direction_names
[] = {
9538 set_exec_direction_func (const char *args
, int from_tty
,
9539 struct cmd_list_element
*cmd
)
9541 if (target_can_execute_reverse ())
9543 if (!strcmp (exec_direction
, exec_forward
))
9544 execution_direction
= EXEC_FORWARD
;
9545 else if (!strcmp (exec_direction
, exec_reverse
))
9546 execution_direction
= EXEC_REVERSE
;
9550 exec_direction
= exec_forward
;
9551 error (_("Target does not support this operation."));
9556 show_exec_direction_func (struct ui_file
*out
, int from_tty
,
9557 struct cmd_list_element
*cmd
, const char *value
)
9559 switch (execution_direction
) {
9561 fprintf_filtered (out
, _("Forward.\n"));
9564 fprintf_filtered (out
, _("Reverse.\n"));
9567 internal_error (__FILE__
, __LINE__
,
9568 _("bogus execution_direction value: %d"),
9569 (int) execution_direction
);
9574 show_schedule_multiple (struct ui_file
*file
, int from_tty
,
9575 struct cmd_list_element
*c
, const char *value
)
9577 fprintf_filtered (file
, _("Resuming the execution of threads "
9578 "of all processes is %s.\n"), value
);
9581 /* Implementation of `siginfo' variable. */
9583 static const struct internalvar_funcs siginfo_funcs
=
9590 /* Callback for infrun's target events source. This is marked when a
9591 thread has a pending status to process. */
9594 infrun_async_inferior_event_handler (gdb_client_data data
)
9596 clear_async_event_handler (infrun_async_inferior_event_token
);
9597 inferior_event_handler (INF_REG_EVENT
);
9604 /* Verify that when two threads with the same ptid exist (from two different
9605 targets) and one of them changes ptid, we only update inferior_ptid if
9606 it is appropriate. */
9609 infrun_thread_ptid_changed ()
9611 gdbarch
*arch
= current_inferior ()->gdbarch
;
9613 /* The thread which inferior_ptid represents changes ptid. */
9615 scoped_restore_current_pspace_and_thread restore
;
9617 scoped_mock_context
<test_target_ops
> target1 (arch
);
9618 scoped_mock_context
<test_target_ops
> target2 (arch
);
9619 target2
.mock_inferior
.next
= &target1
.mock_inferior
;
9621 ptid_t
old_ptid (111, 222);
9622 ptid_t
new_ptid (111, 333);
9624 target1
.mock_inferior
.pid
= old_ptid
.pid ();
9625 target1
.mock_thread
.ptid
= old_ptid
;
9626 target2
.mock_inferior
.pid
= old_ptid
.pid ();
9627 target2
.mock_thread
.ptid
= old_ptid
;
9629 auto restore_inferior_ptid
= make_scoped_restore (&inferior_ptid
, old_ptid
);
9630 set_current_inferior (&target1
.mock_inferior
);
9632 thread_change_ptid (&target1
.mock_target
, old_ptid
, new_ptid
);
9634 gdb_assert (inferior_ptid
== new_ptid
);
9637 /* A thread with the same ptid as inferior_ptid, but from another target,
9640 scoped_restore_current_pspace_and_thread restore
;
9642 scoped_mock_context
<test_target_ops
> target1 (arch
);
9643 scoped_mock_context
<test_target_ops
> target2 (arch
);
9644 target2
.mock_inferior
.next
= &target1
.mock_inferior
;
9646 ptid_t
old_ptid (111, 222);
9647 ptid_t
new_ptid (111, 333);
9649 target1
.mock_inferior
.pid
= old_ptid
.pid ();
9650 target1
.mock_thread
.ptid
= old_ptid
;
9651 target2
.mock_inferior
.pid
= old_ptid
.pid ();
9652 target2
.mock_thread
.ptid
= old_ptid
;
9654 auto restore_inferior_ptid
= make_scoped_restore (&inferior_ptid
, old_ptid
);
9655 set_current_inferior (&target2
.mock_inferior
);
9657 thread_change_ptid (&target1
.mock_target
, old_ptid
, new_ptid
);
9659 gdb_assert (inferior_ptid
== old_ptid
);
9663 } /* namespace selftests */
9665 #endif /* GDB_SELF_TEST */
9667 void _initialize_infrun ();
9669 _initialize_infrun ()
9671 struct cmd_list_element
*c
;
9673 /* Register extra event sources in the event loop. */
9674 infrun_async_inferior_event_token
9675 = create_async_event_handler (infrun_async_inferior_event_handler
, NULL
,
9678 cmd_list_element
*info_signals_cmd
9679 = add_info ("signals", info_signals_command
, _("\
9680 What debugger does when program gets various signals.\n\
9681 Specify a signal as argument to print info on that signal only."));
9682 add_info_alias ("handle", info_signals_cmd
, 0);
9684 c
= add_com ("handle", class_run
, handle_command
, _("\
9685 Specify how to handle signals.\n\
9686 Usage: handle SIGNAL [ACTIONS]\n\
9687 Args are signals and actions to apply to those signals.\n\
9688 If no actions are specified, the current settings for the specified signals\n\
9689 will be displayed instead.\n\
9691 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
9692 from 1-15 are allowed for compatibility with old versions of GDB.\n\
9693 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
9694 The special arg \"all\" is recognized to mean all signals except those\n\
9695 used by the debugger, typically SIGTRAP and SIGINT.\n\
9697 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
9698 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
9699 Stop means reenter debugger if this signal happens (implies print).\n\
9700 Print means print a message if this signal happens.\n\
9701 Pass means let program see this signal; otherwise program doesn't know.\n\
9702 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
9703 Pass and Stop may be combined.\n\
9705 Multiple signals may be specified. Signal numbers and signal names\n\
9706 may be interspersed with actions, with the actions being performed for\n\
9707 all signals cumulatively specified."));
9708 set_cmd_completer (c
, handle_completer
);
9711 stop_command
= add_cmd ("stop", class_obscure
,
9712 not_just_help_class_command
, _("\
9713 There is no `stop' command, but you can set a hook on `stop'.\n\
9714 This allows you to set a list of commands to be run each time execution\n\
9715 of the program stops."), &cmdlist
);
9717 add_setshow_boolean_cmd
9718 ("infrun", class_maintenance
, &debug_infrun
,
9719 _("Set inferior debugging."),
9720 _("Show inferior debugging."),
9721 _("When non-zero, inferior specific debugging is enabled."),
9722 NULL
, show_debug_infrun
, &setdebuglist
, &showdebuglist
);
9724 add_setshow_boolean_cmd ("non-stop", no_class
,
9726 Set whether gdb controls the inferior in non-stop mode."), _("\
9727 Show whether gdb controls the inferior in non-stop mode."), _("\
9728 When debugging a multi-threaded program and this setting is\n\
9729 off (the default, also called all-stop mode), when one thread stops\n\
9730 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
9731 all other threads in the program while you interact with the thread of\n\
9732 interest. When you continue or step a thread, you can allow the other\n\
9733 threads to run, or have them remain stopped, but while you inspect any\n\
9734 thread's state, all threads stop.\n\
9736 In non-stop mode, when one thread stops, other threads can continue\n\
9737 to run freely. You'll be able to step each thread independently,\n\
9738 leave it stopped or free to run as needed."),
9744 for (size_t i
= 0; i
< GDB_SIGNAL_LAST
; i
++)
9747 signal_print
[i
] = 1;
9748 signal_program
[i
] = 1;
9749 signal_catch
[i
] = 0;
9752 /* Signals caused by debugger's own actions should not be given to
9753 the program afterwards.
9755 Do not deliver GDB_SIGNAL_TRAP by default, except when the user
9756 explicitly specifies that it should be delivered to the target
9757 program. Typically, that would occur when a user is debugging a
9758 target monitor on a simulator: the target monitor sets a
9759 breakpoint; the simulator encounters this breakpoint and halts
9760 the simulation handing control to GDB; GDB, noting that the stop
9761 address doesn't map to any known breakpoint, returns control back
9762 to the simulator; the simulator then delivers the hardware
9763 equivalent of a GDB_SIGNAL_TRAP to the program being
9765 signal_program
[GDB_SIGNAL_TRAP
] = 0;
9766 signal_program
[GDB_SIGNAL_INT
] = 0;
9768 /* Signals that are not errors should not normally enter the debugger. */
9769 signal_stop
[GDB_SIGNAL_ALRM
] = 0;
9770 signal_print
[GDB_SIGNAL_ALRM
] = 0;
9771 signal_stop
[GDB_SIGNAL_VTALRM
] = 0;
9772 signal_print
[GDB_SIGNAL_VTALRM
] = 0;
9773 signal_stop
[GDB_SIGNAL_PROF
] = 0;
9774 signal_print
[GDB_SIGNAL_PROF
] = 0;
9775 signal_stop
[GDB_SIGNAL_CHLD
] = 0;
9776 signal_print
[GDB_SIGNAL_CHLD
] = 0;
9777 signal_stop
[GDB_SIGNAL_IO
] = 0;
9778 signal_print
[GDB_SIGNAL_IO
] = 0;
9779 signal_stop
[GDB_SIGNAL_POLL
] = 0;
9780 signal_print
[GDB_SIGNAL_POLL
] = 0;
9781 signal_stop
[GDB_SIGNAL_URG
] = 0;
9782 signal_print
[GDB_SIGNAL_URG
] = 0;
9783 signal_stop
[GDB_SIGNAL_WINCH
] = 0;
9784 signal_print
[GDB_SIGNAL_WINCH
] = 0;
9785 signal_stop
[GDB_SIGNAL_PRIO
] = 0;
9786 signal_print
[GDB_SIGNAL_PRIO
] = 0;
9788 /* These signals are used internally by user-level thread
9789 implementations. (See signal(5) on Solaris.) Like the above
9790 signals, a healthy program receives and handles them as part of
9791 its normal operation. */
9792 signal_stop
[GDB_SIGNAL_LWP
] = 0;
9793 signal_print
[GDB_SIGNAL_LWP
] = 0;
9794 signal_stop
[GDB_SIGNAL_WAITING
] = 0;
9795 signal_print
[GDB_SIGNAL_WAITING
] = 0;
9796 signal_stop
[GDB_SIGNAL_CANCEL
] = 0;
9797 signal_print
[GDB_SIGNAL_CANCEL
] = 0;
9798 signal_stop
[GDB_SIGNAL_LIBRT
] = 0;
9799 signal_print
[GDB_SIGNAL_LIBRT
] = 0;
9801 /* Update cached state. */
9802 signal_cache_update (-1);
9804 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support
,
9805 &stop_on_solib_events
, _("\
9806 Set stopping for shared library events."), _("\
9807 Show stopping for shared library events."), _("\
9808 If nonzero, gdb will give control to the user when the dynamic linker\n\
9809 notifies gdb of shared library events. The most common event of interest\n\
9810 to the user would be loading/unloading of a new library."),
9811 set_stop_on_solib_events
,
9812 show_stop_on_solib_events
,
9813 &setlist
, &showlist
);
9815 add_setshow_enum_cmd ("follow-fork-mode", class_run
,
9816 follow_fork_mode_kind_names
,
9817 &follow_fork_mode_string
, _("\
9818 Set debugger response to a program call of fork or vfork."), _("\
9819 Show debugger response to a program call of fork or vfork."), _("\
9820 A fork or vfork creates a new process. follow-fork-mode can be:\n\
9821 parent - the original process is debugged after a fork\n\
9822 child - the new process is debugged after a fork\n\
9823 The unfollowed process will continue to run.\n\
9824 By default, the debugger will follow the parent process."),
9826 show_follow_fork_mode_string
,
9827 &setlist
, &showlist
);
9829 add_setshow_enum_cmd ("follow-exec-mode", class_run
,
9830 follow_exec_mode_names
,
9831 &follow_exec_mode_string
, _("\
9832 Set debugger response to a program call of exec."), _("\
9833 Show debugger response to a program call of exec."), _("\
9834 An exec call replaces the program image of a process.\n\
9836 follow-exec-mode can be:\n\
9838 new - the debugger creates a new inferior and rebinds the process\n\
9839 to this new inferior. The program the process was running before\n\
9840 the exec call can be restarted afterwards by restarting the original\n\
9843 same - the debugger keeps the process bound to the same inferior.\n\
9844 The new executable image replaces the previous executable loaded in\n\
9845 the inferior. Restarting the inferior after the exec call restarts\n\
9846 the executable the process was running after the exec call.\n\
9848 By default, the debugger will use the same inferior."),
9850 show_follow_exec_mode_string
,
9851 &setlist
, &showlist
);
9853 add_setshow_enum_cmd ("scheduler-locking", class_run
,
9854 scheduler_enums
, &scheduler_mode
, _("\
9855 Set mode for locking scheduler during execution."), _("\
9856 Show mode for locking scheduler during execution."), _("\
9857 off == no locking (threads may preempt at any time)\n\
9858 on == full locking (no thread except the current thread may run)\n\
9859 This applies to both normal execution and replay mode.\n\
9860 step == scheduler locked during stepping commands (step, next, stepi, nexti).\n\
9861 In this mode, other threads may run during other commands.\n\
9862 This applies to both normal execution and replay mode.\n\
9863 replay == scheduler locked in replay mode and unlocked during normal execution."),
9864 set_schedlock_func
, /* traps on target vector */
9865 show_scheduler_mode
,
9866 &setlist
, &showlist
);
9868 add_setshow_boolean_cmd ("schedule-multiple", class_run
, &sched_multi
, _("\
9869 Set mode for resuming threads of all processes."), _("\
9870 Show mode for resuming threads of all processes."), _("\
9871 When on, execution commands (such as 'continue' or 'next') resume all\n\
9872 threads of all processes. When off (which is the default), execution\n\
9873 commands only resume the threads of the current process. The set of\n\
9874 threads that are resumed is further refined by the scheduler-locking\n\
9875 mode (see help set scheduler-locking)."),
9877 show_schedule_multiple
,
9878 &setlist
, &showlist
);
9880 add_setshow_boolean_cmd ("step-mode", class_run
, &step_stop_if_no_debug
, _("\
9881 Set mode of the step operation."), _("\
9882 Show mode of the step operation."), _("\
9883 When set, doing a step over a function without debug line information\n\
9884 will stop at the first instruction of that function. Otherwise, the\n\
9885 function is skipped and the step command stops at a different source line."),
9887 show_step_stop_if_no_debug
,
9888 &setlist
, &showlist
);
9890 add_setshow_auto_boolean_cmd ("displaced-stepping", class_run
,
9891 &can_use_displaced_stepping
, _("\
9892 Set debugger's willingness to use displaced stepping."), _("\
9893 Show debugger's willingness to use displaced stepping."), _("\
9894 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
9895 supported by the target architecture. If off, gdb will not use displaced\n\
9896 stepping to step over breakpoints, even if such is supported by the target\n\
9897 architecture. If auto (which is the default), gdb will use displaced stepping\n\
9898 if the target architecture supports it and non-stop mode is active, but will not\n\
9899 use it in all-stop mode (see help set non-stop)."),
9901 show_can_use_displaced_stepping
,
9902 &setlist
, &showlist
);
9904 add_setshow_enum_cmd ("exec-direction", class_run
, exec_direction_names
,
9905 &exec_direction
, _("Set direction of execution.\n\
9906 Options are 'forward' or 'reverse'."),
9907 _("Show direction of execution (forward/reverse)."),
9908 _("Tells gdb whether to execute forward or backward."),
9909 set_exec_direction_func
, show_exec_direction_func
,
9910 &setlist
, &showlist
);
9912 /* Set/show detach-on-fork: user-settable mode. */
9914 add_setshow_boolean_cmd ("detach-on-fork", class_run
, &detach_fork
, _("\
9915 Set whether gdb will detach the child of a fork."), _("\
9916 Show whether gdb will detach the child of a fork."), _("\
9917 Tells gdb whether to detach the child of a fork."),
9918 NULL
, NULL
, &setlist
, &showlist
);
9920 /* Set/show disable address space randomization mode. */
9922 add_setshow_boolean_cmd ("disable-randomization", class_support
,
9923 &disable_randomization
, _("\
9924 Set disabling of debuggee's virtual address space randomization."), _("\
9925 Show disabling of debuggee's virtual address space randomization."), _("\
9926 When this mode is on (which is the default), randomization of the virtual\n\
9927 address space is disabled. Standalone programs run with the randomization\n\
9928 enabled by default on some platforms."),
9929 &set_disable_randomization
,
9930 &show_disable_randomization
,
9931 &setlist
, &showlist
);
9933 /* ptid initializations */
9934 inferior_ptid
= null_ptid
;
9935 target_last_wait_ptid
= minus_one_ptid
;
9937 gdb::observers::thread_ptid_changed
.attach (infrun_thread_ptid_changed
,
9939 gdb::observers::thread_stop_requested
.attach (infrun_thread_stop_requested
,
9941 gdb::observers::thread_exit
.attach (infrun_thread_thread_exit
, "infrun");
9942 gdb::observers::inferior_exit
.attach (infrun_inferior_exit
, "infrun");
9943 gdb::observers::inferior_execd
.attach (infrun_inferior_execd
, "infrun");
9945 /* Explicitly create without lookup, since that tries to create a
9946 value with a void typed value, and when we get here, gdbarch
9947 isn't initialized yet. At this point, we're quite sure there
9948 isn't another convenience variable of the same name. */
9949 create_internalvar_type_lazy ("_siginfo", &siginfo_funcs
, NULL
);
9951 add_setshow_boolean_cmd ("observer", no_class
,
9952 &observer_mode_1
, _("\
9953 Set whether gdb controls the inferior in observer mode."), _("\
9954 Show whether gdb controls the inferior in observer mode."), _("\
9955 In observer mode, GDB can get data from the inferior, but not\n\
9956 affect its execution. Registers and memory may not be changed,\n\
9957 breakpoints may not be set, and the program cannot be interrupted\n\
9965 selftests::register_test ("infrun_thread_ptid_changed",
9966 selftests::infrun_thread_ptid_changed
);