1 /* Target-struct-independent code to start (run) and stop an inferior
4 Copyright (C) 1986-2021 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "displaced-stepping.h"
28 #include "breakpoint.h"
32 #include "target-connection.h"
33 #include "gdbthread.h"
40 #include "observable.h"
45 #include "mi/mi-common.h"
46 #include "event-top.h"
48 #include "record-full.h"
49 #include "inline-frame.h"
51 #include "tracepoint.h"
55 #include "completer.h"
56 #include "target-descriptions.h"
57 #include "target-dcache.h"
60 #include "gdbsupport/event-loop.h"
61 #include "thread-fsm.h"
62 #include "gdbsupport/enum-flags.h"
63 #include "progspace-and-thread.h"
64 #include "gdbsupport/gdb_optional.h"
65 #include "arch-utils.h"
66 #include "gdbsupport/scope-exit.h"
67 #include "gdbsupport/forward-scope-exit.h"
68 #include "gdbsupport/gdb_select.h"
69 #include <unordered_map>
70 #include "async-event.h"
71 #include "gdbsupport/selftest.h"
72 #include "scoped-mock-context.h"
73 #include "test-target.h"
74 #include "gdbsupport/common-debug.h"
76 /* Prototypes for local functions */
78 static void sig_print_info (enum gdb_signal
);
80 static void sig_print_header (void);
82 static void follow_inferior_reset_breakpoints (void);
84 static bool currently_stepping (struct thread_info
*tp
);
86 static void insert_hp_step_resume_breakpoint_at_frame (struct frame_info
*);
88 static void insert_step_resume_breakpoint_at_caller (struct frame_info
*);
90 static void insert_longjmp_resume_breakpoint (struct gdbarch
*, CORE_ADDR
);
92 static bool maybe_software_singlestep (struct gdbarch
*gdbarch
, 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
, inferior
*inf
);
100 static bool start_step_over (void);
102 static bool step_over_info_valid_p (void);
104 /* Asynchronous signal handler registered as event loop source for
105 when we have pending events ready to be passed to the core. */
106 static struct async_event_handler
*infrun_async_inferior_event_token
;
108 /* Stores whether infrun_async was previously enabled or disabled.
109 Starts off as -1, indicating "never enabled/disabled". */
110 static int infrun_is_async
= -1;
115 infrun_async (int enable
)
117 if (infrun_is_async
!= enable
)
119 infrun_is_async
= enable
;
121 infrun_debug_printf ("enable=%d", enable
);
124 mark_async_event_handler (infrun_async_inferior_event_token
);
126 clear_async_event_handler (infrun_async_inferior_event_token
);
133 mark_infrun_async_event_handler (void)
135 mark_async_event_handler (infrun_async_inferior_event_token
);
138 /* When set, stop the 'step' command if we enter a function which has
139 no line number information. The normal behavior is that we step
140 over such function. */
141 bool step_stop_if_no_debug
= false;
143 show_step_stop_if_no_debug (struct ui_file
*file
, int from_tty
,
144 struct cmd_list_element
*c
, const char *value
)
146 fprintf_filtered (file
, _("Mode of the step operation is %s.\n"), value
);
149 /* proceed and normal_stop use this to notify the user when the
150 inferior stopped in a different thread than it had been running
153 static ptid_t previous_inferior_ptid
;
155 /* If set (default for legacy reasons), when following a fork, GDB
156 will detach from one of the fork branches, child or parent.
157 Exactly which branch is detached depends on 'set follow-fork-mode'
160 static bool detach_fork
= true;
162 bool debug_infrun
= false;
164 show_debug_infrun (struct ui_file
*file
, int from_tty
,
165 struct cmd_list_element
*c
, const char *value
)
167 fprintf_filtered (file
, _("Inferior debugging is %s.\n"), value
);
170 /* Support for disabling address space randomization. */
172 bool disable_randomization
= true;
175 show_disable_randomization (struct ui_file
*file
, int from_tty
,
176 struct cmd_list_element
*c
, const char *value
)
178 if (target_supports_disable_randomization ())
179 fprintf_filtered (file
,
180 _("Disabling randomization of debuggee's "
181 "virtual address space is %s.\n"),
184 fputs_filtered (_("Disabling randomization of debuggee's "
185 "virtual address space is unsupported on\n"
186 "this platform.\n"), file
);
190 set_disable_randomization (const char *args
, int from_tty
,
191 struct cmd_list_element
*c
)
193 if (!target_supports_disable_randomization ())
194 error (_("Disabling randomization of debuggee's "
195 "virtual address space is unsupported on\n"
199 /* User interface for non-stop mode. */
201 bool non_stop
= false;
202 static bool non_stop_1
= false;
205 set_non_stop (const char *args
, int from_tty
,
206 struct cmd_list_element
*c
)
208 if (target_has_execution ())
210 non_stop_1
= non_stop
;
211 error (_("Cannot change this setting while the inferior is running."));
214 non_stop
= non_stop_1
;
218 show_non_stop (struct ui_file
*file
, int from_tty
,
219 struct cmd_list_element
*c
, const char *value
)
221 fprintf_filtered (file
,
222 _("Controlling the inferior in non-stop mode is %s.\n"),
226 /* "Observer mode" is somewhat like a more extreme version of
227 non-stop, in which all GDB operations that might affect the
228 target's execution have been disabled. */
230 static bool observer_mode
= false;
231 static bool observer_mode_1
= false;
234 set_observer_mode (const char *args
, int from_tty
,
235 struct cmd_list_element
*c
)
237 if (target_has_execution ())
239 observer_mode_1
= observer_mode
;
240 error (_("Cannot change this setting while the inferior is running."));
243 observer_mode
= observer_mode_1
;
245 may_write_registers
= !observer_mode
;
246 may_write_memory
= !observer_mode
;
247 may_insert_breakpoints
= !observer_mode
;
248 may_insert_tracepoints
= !observer_mode
;
249 /* We can insert fast tracepoints in or out of observer mode,
250 but enable them if we're going into this mode. */
252 may_insert_fast_tracepoints
= true;
253 may_stop
= !observer_mode
;
254 update_target_permissions ();
256 /* Going *into* observer mode we must force non-stop, then
257 going out we leave it that way. */
260 pagination_enabled
= 0;
261 non_stop
= non_stop_1
= true;
265 printf_filtered (_("Observer mode is now %s.\n"),
266 (observer_mode
? "on" : "off"));
270 show_observer_mode (struct ui_file
*file
, int from_tty
,
271 struct cmd_list_element
*c
, const char *value
)
273 fprintf_filtered (file
, _("Observer mode is %s.\n"), value
);
276 /* This updates the value of observer mode based on changes in
277 permissions. Note that we are deliberately ignoring the values of
278 may-write-registers and may-write-memory, since the user may have
279 reason to enable these during a session, for instance to turn on a
280 debugging-related global. */
283 update_observer_mode (void)
285 bool newval
= (!may_insert_breakpoints
286 && !may_insert_tracepoints
287 && may_insert_fast_tracepoints
291 /* Let the user know if things change. */
292 if (newval
!= observer_mode
)
293 printf_filtered (_("Observer mode is now %s.\n"),
294 (newval
? "on" : "off"));
296 observer_mode
= observer_mode_1
= newval
;
299 /* Tables of how to react to signals; the user sets them. */
301 static unsigned char signal_stop
[GDB_SIGNAL_LAST
];
302 static unsigned char signal_print
[GDB_SIGNAL_LAST
];
303 static unsigned char signal_program
[GDB_SIGNAL_LAST
];
305 /* Table of signals that are registered with "catch signal". A
306 non-zero entry indicates that the signal is caught by some "catch
308 static unsigned char signal_catch
[GDB_SIGNAL_LAST
];
310 /* Table of signals that the target may silently handle.
311 This is automatically determined from the flags above,
312 and simply cached here. */
313 static unsigned char signal_pass
[GDB_SIGNAL_LAST
];
315 #define SET_SIGS(nsigs,sigs,flags) \
317 int signum = (nsigs); \
318 while (signum-- > 0) \
319 if ((sigs)[signum]) \
320 (flags)[signum] = 1; \
323 #define UNSET_SIGS(nsigs,sigs,flags) \
325 int signum = (nsigs); \
326 while (signum-- > 0) \
327 if ((sigs)[signum]) \
328 (flags)[signum] = 0; \
331 /* Update the target's copy of SIGNAL_PROGRAM. The sole purpose of
332 this function is to avoid exporting `signal_program'. */
335 update_signals_program_target (void)
337 target_program_signals (signal_program
);
340 /* Value to pass to target_resume() to cause all threads to resume. */
342 #define RESUME_ALL minus_one_ptid
344 /* Command list pointer for the "stop" placeholder. */
346 static struct cmd_list_element
*stop_command
;
348 /* Nonzero if we want to give control to the user when we're notified
349 of shared library events by the dynamic linker. */
350 int stop_on_solib_events
;
352 /* Enable or disable optional shared library event breakpoints
353 as appropriate when the above flag is changed. */
356 set_stop_on_solib_events (const char *args
,
357 int from_tty
, struct cmd_list_element
*c
)
359 update_solib_breakpoints ();
363 show_stop_on_solib_events (struct ui_file
*file
, int from_tty
,
364 struct cmd_list_element
*c
, const char *value
)
366 fprintf_filtered (file
, _("Stopping for shared library events is %s.\n"),
370 /* True after stop if current stack frame should be printed. */
372 static bool stop_print_frame
;
374 /* This is a cached copy of the target/ptid/waitstatus of the last
375 event returned by target_wait()/deprecated_target_wait_hook().
376 This information is returned by get_last_target_status(). */
377 static process_stratum_target
*target_last_proc_target
;
378 static ptid_t target_last_wait_ptid
;
379 static struct target_waitstatus target_last_waitstatus
;
381 void init_thread_stepping_state (struct thread_info
*tss
);
383 static const char follow_fork_mode_child
[] = "child";
384 static const char follow_fork_mode_parent
[] = "parent";
386 static const char *const follow_fork_mode_kind_names
[] = {
387 follow_fork_mode_child
,
388 follow_fork_mode_parent
,
392 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
394 show_follow_fork_mode_string (struct ui_file
*file
, int from_tty
,
395 struct cmd_list_element
*c
, const char *value
)
397 fprintf_filtered (file
,
398 _("Debugger response to a program "
399 "call of fork or vfork is \"%s\".\n"),
404 /* Handle changes to the inferior list based on the type of fork,
405 which process is being followed, and whether the other process
406 should be detached. On entry inferior_ptid must be the ptid of
407 the fork parent. At return inferior_ptid is the ptid of the
408 followed inferior. */
411 follow_fork_inferior (bool follow_child
, bool detach_fork
)
414 ptid_t parent_ptid
, child_ptid
;
416 has_vforked
= (inferior_thread ()->pending_follow
.kind
417 == TARGET_WAITKIND_VFORKED
);
418 parent_ptid
= inferior_ptid
;
419 child_ptid
= inferior_thread ()->pending_follow
.value
.related_pid
;
422 && !non_stop
/* Non-stop always resumes both branches. */
423 && current_ui
->prompt_state
== PROMPT_BLOCKED
424 && !(follow_child
|| detach_fork
|| sched_multi
))
426 /* The parent stays blocked inside the vfork syscall until the
427 child execs or exits. If we don't let the child run, then
428 the parent stays blocked. If we're telling the parent to run
429 in the foreground, the user will not be able to ctrl-c to get
430 back the terminal, effectively hanging the debug session. */
431 fprintf_filtered (gdb_stderr
, _("\
432 Can not resume the parent process over vfork in the foreground while\n\
433 holding the child stopped. Try \"set detach-on-fork\" or \
434 \"set schedule-multiple\".\n"));
440 /* Detach new forked process? */
443 /* Before detaching from the child, remove all breakpoints
444 from it. If we forked, then this has already been taken
445 care of by infrun.c. If we vforked however, any
446 breakpoint inserted in the parent is visible in the
447 child, even those added while stopped in a vfork
448 catchpoint. This will remove the breakpoints from the
449 parent also, but they'll be reinserted below. */
452 /* Keep breakpoints list in sync. */
453 remove_breakpoints_inf (current_inferior ());
456 if (print_inferior_events
)
458 /* Ensure that we have a process ptid. */
459 ptid_t process_ptid
= ptid_t (child_ptid
.pid ());
461 target_terminal::ours_for_output ();
462 fprintf_filtered (gdb_stdlog
,
463 _("[Detaching after %s from child %s]\n"),
464 has_vforked
? "vfork" : "fork",
465 target_pid_to_str (process_ptid
).c_str ());
470 struct inferior
*parent_inf
, *child_inf
;
472 /* Add process to GDB's tables. */
473 child_inf
= add_inferior (child_ptid
.pid ());
475 parent_inf
= current_inferior ();
476 child_inf
->attach_flag
= parent_inf
->attach_flag
;
477 copy_terminal_info (child_inf
, parent_inf
);
478 child_inf
->gdbarch
= parent_inf
->gdbarch
;
479 copy_inferior_target_desc_info (child_inf
, parent_inf
);
481 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
483 set_current_inferior (child_inf
);
484 switch_to_no_thread ();
485 child_inf
->symfile_flags
= SYMFILE_NO_READ
;
486 child_inf
->push_target (parent_inf
->process_target ());
487 thread_info
*child_thr
488 = add_thread_silent (child_inf
->process_target (), child_ptid
);
490 /* If this is a vfork child, then the address-space is
491 shared with the parent. */
494 child_inf
->pspace
= parent_inf
->pspace
;
495 child_inf
->aspace
= parent_inf
->aspace
;
499 /* The parent will be frozen until the child is done
500 with the shared region. Keep track of the
502 child_inf
->vfork_parent
= parent_inf
;
503 child_inf
->pending_detach
= 0;
504 parent_inf
->vfork_child
= child_inf
;
505 parent_inf
->pending_detach
= 0;
507 /* Now that the inferiors and program spaces are all
508 wired up, we can switch to the child thread (which
509 switches inferior and program space too). */
510 switch_to_thread (child_thr
);
514 child_inf
->aspace
= new_address_space ();
515 child_inf
->pspace
= new program_space (child_inf
->aspace
);
516 child_inf
->removable
= 1;
517 set_current_program_space (child_inf
->pspace
);
518 clone_program_space (child_inf
->pspace
, parent_inf
->pspace
);
520 /* solib_create_inferior_hook relies on the current
522 switch_to_thread (child_thr
);
524 /* Let the shared library layer (e.g., solib-svr4) learn
525 about this new process, relocate the cloned exec, pull
526 in shared libraries, and install the solib event
527 breakpoint. If a "cloned-VM" event was propagated
528 better throughout the core, this wouldn't be
530 scoped_restore restore_in_initial_library_scan
531 = make_scoped_restore (&child_inf
->in_initial_library_scan
,
533 solib_create_inferior_hook (0);
539 struct inferior
*parent_inf
;
541 parent_inf
= current_inferior ();
543 /* If we detached from the child, then we have to be careful
544 to not insert breakpoints in the parent until the child
545 is done with the shared memory region. However, if we're
546 staying attached to the child, then we can and should
547 insert breakpoints, so that we can debug it. A
548 subsequent child exec or exit is enough to know when does
549 the child stops using the parent's address space. */
550 gdb_assert (parent_inf
->thread_waiting_for_vfork_done
== nullptr);
551 parent_inf
->thread_waiting_for_vfork_done
552 = detach_fork
? inferior_thread () : nullptr;
553 parent_inf
->pspace
->breakpoints_not_allowed
= detach_fork
;
558 /* Follow the child. */
559 struct inferior
*parent_inf
, *child_inf
;
560 struct program_space
*parent_pspace
;
562 if (print_inferior_events
)
564 std::string parent_pid
= target_pid_to_str (parent_ptid
);
565 std::string child_pid
= target_pid_to_str (child_ptid
);
567 target_terminal::ours_for_output ();
568 fprintf_filtered (gdb_stdlog
,
569 _("[Attaching after %s %s to child %s]\n"),
571 has_vforked
? "vfork" : "fork",
575 /* Add the new inferior first, so that the target_detach below
576 doesn't unpush the target. */
578 child_inf
= add_inferior (child_ptid
.pid ());
580 parent_inf
= current_inferior ();
581 child_inf
->attach_flag
= parent_inf
->attach_flag
;
582 copy_terminal_info (child_inf
, parent_inf
);
583 child_inf
->gdbarch
= parent_inf
->gdbarch
;
584 copy_inferior_target_desc_info (child_inf
, parent_inf
);
586 parent_pspace
= parent_inf
->pspace
;
588 process_stratum_target
*target
= parent_inf
->process_target ();
591 /* Hold a strong reference to the target while (maybe)
592 detaching the parent. Otherwise detaching could close the
594 auto target_ref
= target_ops_ref::new_reference (target
);
596 /* If we're vforking, we want to hold on to the parent until
597 the child exits or execs. At child exec or exit time we
598 can remove the old breakpoints from the parent and detach
599 or resume debugging it. Otherwise, detach the parent now;
600 we'll want to reuse it's program/address spaces, but we
601 can't set them to the child before removing breakpoints
602 from the parent, otherwise, the breakpoints module could
603 decide to remove breakpoints from the wrong process (since
604 they'd be assigned to the same address space). */
608 gdb_assert (child_inf
->vfork_parent
== NULL
);
609 gdb_assert (parent_inf
->vfork_child
== NULL
);
610 child_inf
->vfork_parent
= parent_inf
;
611 child_inf
->pending_detach
= 0;
612 parent_inf
->vfork_child
= child_inf
;
613 parent_inf
->pending_detach
= detach_fork
;
614 parent_inf
->thread_waiting_for_vfork_done
= nullptr;
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 (tp
->pending_follow
.kind
== TARGET_WAITKIND_VFORKED
781 && target_is_non_stop_p ())
782 stop_all_threads ("handling vfork", tp
->inf
);
784 process_stratum_target
*parent_targ
= tp
->inf
->process_target ();
785 /* Set up inferior(s) as specified by the caller, and tell the
786 target to do whatever is necessary to follow either parent
788 if (follow_fork_inferior (follow_child
, detach_fork
))
790 /* Target refused to follow, or there's some other reason
791 we shouldn't resume. */
796 /* This pending follow fork event is now handled, one way
797 or another. The previous selected thread may be gone
798 from the lists by now, but if it is still around, need
799 to clear the pending follow request. */
800 tp
= find_thread_ptid (parent_targ
, parent
);
802 tp
->pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
804 /* This makes sure we don't try to apply the "Switched
805 over from WAIT_PID" logic above. */
806 nullify_last_target_wait_ptid ();
808 /* If we followed the child, switch to it... */
811 thread_info
*child_thr
= find_thread_ptid (parent_targ
, child
);
812 switch_to_thread (child_thr
);
814 /* ... and preserve the stepping state, in case the
815 user was stepping over the fork call. */
818 tp
= inferior_thread ();
819 tp
->control
.step_resume_breakpoint
820 = step_resume_breakpoint
;
821 tp
->control
.step_range_start
= step_range_start
;
822 tp
->control
.step_range_end
= step_range_end
;
823 tp
->current_line
= current_line
;
824 tp
->current_symtab
= current_symtab
;
825 tp
->control
.step_frame_id
= step_frame_id
;
826 tp
->control
.exception_resume_breakpoint
827 = exception_resume_breakpoint
;
828 tp
->thread_fsm
= thread_fsm
;
832 /* If we get here, it was because we're trying to
833 resume from a fork catchpoint, but, the user
834 has switched threads away from the thread that
835 forked. In that case, the resume command
836 issued is most likely not applicable to the
837 child, so just warn, and refuse to resume. */
838 warning (_("Not resuming: switched threads "
839 "before following fork child."));
842 /* Reset breakpoints in the child as appropriate. */
843 follow_inferior_reset_breakpoints ();
848 case TARGET_WAITKIND_SPURIOUS
:
849 /* Nothing to follow. */
852 internal_error (__FILE__
, __LINE__
,
853 "Unexpected pending_follow.kind %d\n",
854 tp
->pending_follow
.kind
);
858 return should_resume
;
862 follow_inferior_reset_breakpoints (void)
864 struct thread_info
*tp
= inferior_thread ();
866 /* Was there a step_resume breakpoint? (There was if the user
867 did a "next" at the fork() call.) If so, explicitly reset its
868 thread number. Cloned step_resume breakpoints are disabled on
869 creation, so enable it here now that it is associated with the
872 step_resumes are a form of bp that are made to be per-thread.
873 Since we created the step_resume bp when the parent process
874 was being debugged, and now are switching to the child process,
875 from the breakpoint package's viewpoint, that's a switch of
876 "threads". We must update the bp's notion of which thread
877 it is for, or it'll be ignored when it triggers. */
879 if (tp
->control
.step_resume_breakpoint
)
881 breakpoint_re_set_thread (tp
->control
.step_resume_breakpoint
);
882 tp
->control
.step_resume_breakpoint
->loc
->enabled
= 1;
885 /* Treat exception_resume breakpoints like step_resume breakpoints. */
886 if (tp
->control
.exception_resume_breakpoint
)
888 breakpoint_re_set_thread (tp
->control
.exception_resume_breakpoint
);
889 tp
->control
.exception_resume_breakpoint
->loc
->enabled
= 1;
892 /* Reinsert all breakpoints in the child. The user may have set
893 breakpoints after catching the fork, in which case those
894 were never set in the child, but only in the parent. This makes
895 sure the inserted breakpoints match the breakpoint list. */
897 breakpoint_re_set ();
898 insert_breakpoints ();
901 /* The child has exited or execed: resume threads of the parent the
902 user wanted to be executing. */
905 proceed_after_vfork_done (struct thread_info
*thread
,
908 int pid
= * (int *) arg
;
910 if (thread
->ptid
.pid () == pid
911 && thread
->state
== THREAD_RUNNING
912 && !thread
->executing
913 && !thread
->stop_requested
914 && thread
->suspend
.stop_signal
== GDB_SIGNAL_0
)
916 infrun_debug_printf ("resuming vfork parent thread %s",
917 target_pid_to_str (thread
->ptid
).c_str ());
919 switch_to_thread (thread
);
920 clear_proceed_status (0);
921 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
927 /* Called whenever we notice an exec or exit event, to handle
928 detaching or resuming a vfork parent. */
931 handle_vfork_child_exec_or_exit (int exec
)
933 struct inferior
*inf
= current_inferior ();
935 if (inf
->vfork_parent
)
937 int resume_parent
= -1;
939 /* This exec or exit marks the end of the shared memory region
940 between the parent and the child. Break the bonds. */
941 inferior
*vfork_parent
= inf
->vfork_parent
;
942 inf
->vfork_parent
->vfork_child
= NULL
;
943 inf
->vfork_parent
= NULL
;
945 /* If the user wanted to detach from the parent, now is the
947 if (vfork_parent
->pending_detach
)
949 struct program_space
*pspace
;
950 struct address_space
*aspace
;
952 /* follow-fork child, detach-on-fork on. */
954 vfork_parent
->pending_detach
= 0;
956 scoped_restore_current_pspace_and_thread restore_thread
;
958 /* We're letting loose of the parent. */
959 thread_info
*tp
= any_live_thread_of_inferior (vfork_parent
);
960 switch_to_thread (tp
);
962 /* We're about to detach from the parent, which implicitly
963 removes breakpoints from its address space. There's a
964 catch here: we want to reuse the spaces for the child,
965 but, parent/child are still sharing the pspace at this
966 point, although the exec in reality makes the kernel give
967 the child a fresh set of new pages. The problem here is
968 that the breakpoints module being unaware of this, would
969 likely chose the child process to write to the parent
970 address space. Swapping the child temporarily away from
971 the spaces has the desired effect. Yes, this is "sort
974 pspace
= inf
->pspace
;
975 aspace
= inf
->aspace
;
979 if (print_inferior_events
)
982 = target_pid_to_str (ptid_t (vfork_parent
->pid
));
984 target_terminal::ours_for_output ();
988 fprintf_filtered (gdb_stdlog
,
989 _("[Detaching vfork parent %s "
990 "after child exec]\n"), pidstr
.c_str ());
994 fprintf_filtered (gdb_stdlog
,
995 _("[Detaching vfork parent %s "
996 "after child exit]\n"), pidstr
.c_str ());
1000 target_detach (vfork_parent
, 0);
1003 inf
->pspace
= pspace
;
1004 inf
->aspace
= aspace
;
1008 /* We're staying attached to the parent, so, really give the
1009 child a new address space. */
1010 inf
->pspace
= new program_space (maybe_new_address_space ());
1011 inf
->aspace
= inf
->pspace
->aspace
;
1013 set_current_program_space (inf
->pspace
);
1015 resume_parent
= vfork_parent
->pid
;
1019 /* If this is a vfork child exiting, then the pspace and
1020 aspaces were shared with the parent. Since we're
1021 reporting the process exit, we'll be mourning all that is
1022 found in the address space, and switching to null_ptid,
1023 preparing to start a new inferior. But, since we don't
1024 want to clobber the parent's address/program spaces, we
1025 go ahead and create a new one for this exiting
1028 /* Switch to no-thread while running clone_program_space, so
1029 that clone_program_space doesn't want to read the
1030 selected frame of a dead process. */
1031 scoped_restore_current_thread restore_thread
;
1032 switch_to_no_thread ();
1034 inf
->pspace
= new program_space (maybe_new_address_space ());
1035 inf
->aspace
= inf
->pspace
->aspace
;
1036 set_current_program_space (inf
->pspace
);
1038 inf
->symfile_flags
= SYMFILE_NO_READ
;
1039 clone_program_space (inf
->pspace
, vfork_parent
->pspace
);
1041 resume_parent
= vfork_parent
->pid
;
1044 gdb_assert (current_program_space
== inf
->pspace
);
1046 if (non_stop
&& resume_parent
!= -1)
1048 /* If the user wanted the parent to be running, let it go
1050 scoped_restore_current_thread restore_thread
;
1052 infrun_debug_printf ("resuming vfork parent process %d",
1055 iterate_over_threads (proceed_after_vfork_done
, &resume_parent
);
1061 handle_vfork_done (thread_info
*event_thread
)
1063 if (event_thread
->inf
->thread_waiting_for_vfork_done
== nullptr)
1066 gdb_assert (event_thread
->inf
->thread_waiting_for_vfork_done
== event_thread
);
1067 event_thread
->inf
->thread_waiting_for_vfork_done
= nullptr;
1068 current_inferior ()->pspace
->breakpoints_not_allowed
= 0;
1070 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
1072 if (target_is_non_stop_p ())
1074 scoped_restore_current_thread restore_thread
;
1076 insert_breakpoints ();
1077 restart_threads (event_thread
, event_thread
->inf
);
1082 /* Enum strings for "set|show follow-exec-mode". */
1084 static const char follow_exec_mode_new
[] = "new";
1085 static const char follow_exec_mode_same
[] = "same";
1086 static const char *const follow_exec_mode_names
[] =
1088 follow_exec_mode_new
,
1089 follow_exec_mode_same
,
1093 static const char *follow_exec_mode_string
= follow_exec_mode_same
;
1095 show_follow_exec_mode_string (struct ui_file
*file
, int from_tty
,
1096 struct cmd_list_element
*c
, const char *value
)
1098 fprintf_filtered (file
, _("Follow exec mode is \"%s\".\n"), value
);
1101 /* EXEC_FILE_TARGET is assumed to be non-NULL. */
1104 follow_exec (ptid_t ptid
, const char *exec_file_target
)
1106 int pid
= ptid
.pid ();
1107 ptid_t process_ptid
;
1109 /* Switch terminal for any messages produced e.g. by
1110 breakpoint_re_set. */
1111 target_terminal::ours_for_output ();
1113 /* This is an exec event that we actually wish to pay attention to.
1114 Refresh our symbol table to the newly exec'd program, remove any
1115 momentary bp's, etc.
1117 If there are breakpoints, they aren't really inserted now,
1118 since the exec() transformed our inferior into a fresh set
1121 We want to preserve symbolic breakpoints on the list, since
1122 we have hopes that they can be reset after the new a.out's
1123 symbol table is read.
1125 However, any "raw" breakpoints must be removed from the list
1126 (e.g., the solib bp's), since their address is probably invalid
1129 And, we DON'T want to call delete_breakpoints() here, since
1130 that may write the bp's "shadow contents" (the instruction
1131 value that was overwritten with a TRAP instruction). Since
1132 we now have a new a.out, those shadow contents aren't valid. */
1134 mark_breakpoints_out ();
1136 /* The target reports the exec event to the main thread, even if
1137 some other thread does the exec, and even if the main thread was
1138 stopped or already gone. We may still have non-leader threads of
1139 the process on our list. E.g., on targets that don't have thread
1140 exit events (like remote); or on native Linux in non-stop mode if
1141 there were only two threads in the inferior and the non-leader
1142 one is the one that execs (and nothing forces an update of the
1143 thread list up to here). When debugging remotely, it's best to
1144 avoid extra traffic, when possible, so avoid syncing the thread
1145 list with the target, and instead go ahead and delete all threads
1146 of the process but one that reported the event. Note this must
1147 be done before calling update_breakpoints_after_exec, as
1148 otherwise clearing the threads' resources would reference stale
1149 thread breakpoints -- it may have been one of these threads that
1150 stepped across the exec. We could just clear their stepping
1151 states, but as long as we're iterating, might as well delete
1152 them. Deleting them now rather than at the next user-visible
1153 stop provides a nicer sequence of events for user and MI
1155 for (thread_info
*th
: all_threads_safe ())
1156 if (th
->ptid
.pid () == pid
&& th
->ptid
!= ptid
)
1159 /* We also need to clear any left over stale state for the
1160 leader/event thread. E.g., if there was any step-resume
1161 breakpoint or similar, it's gone now. We cannot truly
1162 step-to-next statement through an exec(). */
1163 thread_info
*th
= inferior_thread ();
1164 th
->control
.step_resume_breakpoint
= NULL
;
1165 th
->control
.exception_resume_breakpoint
= NULL
;
1166 th
->control
.single_step_breakpoints
= NULL
;
1167 th
->control
.step_range_start
= 0;
1168 th
->control
.step_range_end
= 0;
1170 /* The user may have had the main thread held stopped in the
1171 previous image (e.g., schedlock on, or non-stop). Release
1173 th
->stop_requested
= 0;
1175 update_breakpoints_after_exec ();
1177 /* What is this a.out's name? */
1178 process_ptid
= ptid_t (pid
);
1179 printf_unfiltered (_("%s is executing new program: %s\n"),
1180 target_pid_to_str (process_ptid
).c_str (),
1183 /* We've followed the inferior through an exec. Therefore, the
1184 inferior has essentially been killed & reborn. */
1186 breakpoint_init_inferior (inf_execd
);
1188 gdb::unique_xmalloc_ptr
<char> exec_file_host
1189 = exec_file_find (exec_file_target
, NULL
);
1191 /* If we were unable to map the executable target pathname onto a host
1192 pathname, tell the user that. Otherwise GDB's subsequent behavior
1193 is confusing. Maybe it would even be better to stop at this point
1194 so that the user can specify a file manually before continuing. */
1195 if (exec_file_host
== NULL
)
1196 warning (_("Could not load symbols for executable %s.\n"
1197 "Do you need \"set sysroot\"?"),
1200 /* Reset the shared library package. This ensures that we get a
1201 shlib event when the child reaches "_start", at which point the
1202 dld will have had a chance to initialize the child. */
1203 /* Also, loading a symbol file below may trigger symbol lookups, and
1204 we don't want those to be satisfied by the libraries of the
1205 previous incarnation of this process. */
1206 no_shared_libraries (NULL
, 0);
1208 struct inferior
*inf
= current_inferior ();
1210 if (follow_exec_mode_string
== follow_exec_mode_new
)
1212 /* The user wants to keep the old inferior and program spaces
1213 around. Create a new fresh one, and switch to it. */
1215 /* Do exit processing for the original inferior before setting the new
1216 inferior's pid. Having two inferiors with the same pid would confuse
1217 find_inferior_p(t)id. Transfer the terminal state and info from the
1218 old to the new inferior. */
1219 inferior
*new_inferior
= add_inferior_with_spaces ();
1221 swap_terminal_info (new_inferior
, inf
);
1222 exit_inferior_silent (inf
);
1224 new_inferior
->pid
= pid
;
1225 target_follow_exec (new_inferior
, ptid
, exec_file_target
);
1227 /* We continue with the new inferior. */
1232 /* The old description may no longer be fit for the new image.
1233 E.g, a 64-bit process exec'ed a 32-bit process. Clear the
1234 old description; we'll read a new one below. No need to do
1235 this on "follow-exec-mode new", as the old inferior stays
1236 around (its description is later cleared/refetched on
1238 target_clear_description ();
1239 target_follow_exec (inf
, ptid
, exec_file_target
);
1242 gdb_assert (current_inferior () == inf
);
1243 gdb_assert (current_program_space
== inf
->pspace
);
1245 /* Attempt to open the exec file. SYMFILE_DEFER_BP_RESET is used
1246 because the proper displacement for a PIE (Position Independent
1247 Executable) main symbol file will only be computed by
1248 solib_create_inferior_hook below. breakpoint_re_set would fail
1249 to insert the breakpoints with the zero displacement. */
1250 try_open_exec_file (exec_file_host
.get (), inf
, SYMFILE_DEFER_BP_RESET
);
1252 /* If the target can specify a description, read it. Must do this
1253 after flipping to the new executable (because the target supplied
1254 description must be compatible with the executable's
1255 architecture, and the old executable may e.g., be 32-bit, while
1256 the new one 64-bit), and before anything involving memory or
1258 target_find_description ();
1260 gdb::observers::inferior_execd
.notify (inf
);
1262 breakpoint_re_set ();
1264 /* Reinsert all breakpoints. (Those which were symbolic have
1265 been reset to the proper address in the new a.out, thanks
1266 to symbol_file_command...). */
1267 insert_breakpoints ();
1269 /* The next resume of this inferior should bring it to the shlib
1270 startup breakpoints. (If the user had also set bp's on
1271 "main" from the old (parent) process, then they'll auto-
1272 matically get reset there in the new process.). */
1275 /* The chain of threads that need to do a step-over operation to get
1276 past e.g., a breakpoint. What technique is used to step over the
1277 breakpoint/watchpoint does not matter -- all threads end up in the
1278 same queue, to maintain rough temporal order of execution, in order
1279 to avoid starvation, otherwise, we could e.g., find ourselves
1280 constantly stepping the same couple threads past their breakpoints
1281 over and over, if the single-step finish fast enough. */
1282 struct thread_info
*global_thread_step_over_chain_head
;
1284 /* Bit flags indicating what the thread needs to step over. */
1286 enum step_over_what_flag
1288 /* Step over a breakpoint. */
1289 STEP_OVER_BREAKPOINT
= 1,
1291 /* Step past a non-continuable watchpoint, in order to let the
1292 instruction execute so we can evaluate the watchpoint
1294 STEP_OVER_WATCHPOINT
= 2
1296 DEF_ENUM_FLAGS_TYPE (enum step_over_what_flag
, step_over_what
);
1298 /* Info about an instruction that is being stepped over. */
1300 struct step_over_info
1302 /* If we're stepping past a breakpoint, this is the address space
1303 and address of the instruction the breakpoint is set at. We'll
1304 skip inserting all breakpoints here. Valid iff ASPACE is
1306 const address_space
*aspace
= nullptr;
1307 CORE_ADDR address
= 0;
1309 /* The instruction being stepped over triggers a nonsteppable
1310 watchpoint. If true, we'll skip inserting watchpoints. */
1311 int nonsteppable_watchpoint_p
= 0;
1313 /* The thread's global number. */
1317 /* The step-over info of the location that is being stepped over.
1319 Note that with async/breakpoint always-inserted mode, a user might
1320 set a new breakpoint/watchpoint/etc. exactly while a breakpoint is
1321 being stepped over. As setting a new breakpoint inserts all
1322 breakpoints, we need to make sure the breakpoint being stepped over
1323 isn't inserted then. We do that by only clearing the step-over
1324 info when the step-over is actually finished (or aborted).
1326 Presently GDB can only step over one breakpoint at any given time.
1327 Given threads that can't run code in the same address space as the
1328 breakpoint's can't really miss the breakpoint, GDB could be taught
1329 to step-over at most one breakpoint per address space (so this info
1330 could move to the address space object if/when GDB is extended).
1331 The set of breakpoints being stepped over will normally be much
1332 smaller than the set of all breakpoints, so a flag in the
1333 breakpoint location structure would be wasteful. A separate list
1334 also saves complexity and run-time, as otherwise we'd have to go
1335 through all breakpoint locations clearing their flag whenever we
1336 start a new sequence. Similar considerations weigh against storing
1337 this info in the thread object. Plus, not all step overs actually
1338 have breakpoint locations -- e.g., stepping past a single-step
1339 breakpoint, or stepping to complete a non-continuable
1341 static struct step_over_info step_over_info
;
1343 /* Record the address of the breakpoint/instruction we're currently
1345 N.B. We record the aspace and address now, instead of say just the thread,
1346 because when we need the info later the thread may be running. */
1349 set_step_over_info (const address_space
*aspace
, CORE_ADDR address
,
1350 int nonsteppable_watchpoint_p
,
1353 step_over_info
.aspace
= aspace
;
1354 step_over_info
.address
= address
;
1355 step_over_info
.nonsteppable_watchpoint_p
= nonsteppable_watchpoint_p
;
1356 step_over_info
.thread
= thread
;
1359 /* Called when we're not longer stepping over a breakpoint / an
1360 instruction, so all breakpoints are free to be (re)inserted. */
1363 clear_step_over_info (void)
1365 infrun_debug_printf ("clearing step over info");
1366 step_over_info
.aspace
= NULL
;
1367 step_over_info
.address
= 0;
1368 step_over_info
.nonsteppable_watchpoint_p
= 0;
1369 step_over_info
.thread
= -1;
1375 stepping_past_instruction_at (struct address_space
*aspace
,
1378 return (step_over_info
.aspace
!= NULL
1379 && breakpoint_address_match (aspace
, address
,
1380 step_over_info
.aspace
,
1381 step_over_info
.address
));
1387 thread_is_stepping_over_breakpoint (int thread
)
1389 return (step_over_info
.thread
!= -1
1390 && thread
== step_over_info
.thread
);
1396 stepping_past_nonsteppable_watchpoint (void)
1398 return step_over_info
.nonsteppable_watchpoint_p
;
1401 /* Returns true if step-over info is valid. */
1404 step_over_info_valid_p (void)
1406 return (step_over_info
.aspace
!= NULL
1407 || stepping_past_nonsteppable_watchpoint ());
1410 /* Displaced stepping. */
1412 /* In non-stop debugging mode, we must take special care to manage
1413 breakpoints properly; in particular, the traditional strategy for
1414 stepping a thread past a breakpoint it has hit is unsuitable.
1415 'Displaced stepping' is a tactic for stepping one thread past a
1416 breakpoint it has hit while ensuring that other threads running
1417 concurrently will hit the breakpoint as they should.
1419 The traditional way to step a thread T off a breakpoint in a
1420 multi-threaded program in all-stop mode is as follows:
1422 a0) Initially, all threads are stopped, and breakpoints are not
1424 a1) We single-step T, leaving breakpoints uninserted.
1425 a2) We insert breakpoints, and resume all threads.
1427 In non-stop debugging, however, this strategy is unsuitable: we
1428 don't want to have to stop all threads in the system in order to
1429 continue or step T past a breakpoint. Instead, we use displaced
1432 n0) Initially, T is stopped, other threads are running, and
1433 breakpoints are inserted.
1434 n1) We copy the instruction "under" the breakpoint to a separate
1435 location, outside the main code stream, making any adjustments
1436 to the instruction, register, and memory state as directed by
1438 n2) We single-step T over the instruction at its new location.
1439 n3) We adjust the resulting register and memory state as directed
1440 by T's architecture. This includes resetting T's PC to point
1441 back into the main instruction stream.
1444 This approach depends on the following gdbarch methods:
1446 - gdbarch_max_insn_length and gdbarch_displaced_step_location
1447 indicate where to copy the instruction, and how much space must
1448 be reserved there. We use these in step n1.
1450 - gdbarch_displaced_step_copy_insn copies a instruction to a new
1451 address, and makes any necessary adjustments to the instruction,
1452 register contents, and memory. We use this in step n1.
1454 - gdbarch_displaced_step_fixup adjusts registers and memory after
1455 we have successfully single-stepped the instruction, to yield the
1456 same effect the instruction would have had if we had executed it
1457 at its original address. We use this in step n3.
1459 The gdbarch_displaced_step_copy_insn and
1460 gdbarch_displaced_step_fixup functions must be written so that
1461 copying an instruction with gdbarch_displaced_step_copy_insn,
1462 single-stepping across the copied instruction, and then applying
1463 gdbarch_displaced_insn_fixup should have the same effects on the
1464 thread's memory and registers as stepping the instruction in place
1465 would have. Exactly which responsibilities fall to the copy and
1466 which fall to the fixup is up to the author of those functions.
1468 See the comments in gdbarch.sh for details.
1470 Note that displaced stepping and software single-step cannot
1471 currently be used in combination, although with some care I think
1472 they could be made to. Software single-step works by placing
1473 breakpoints on all possible subsequent instructions; if the
1474 displaced instruction is a PC-relative jump, those breakpoints
1475 could fall in very strange places --- on pages that aren't
1476 executable, or at addresses that are not proper instruction
1477 boundaries. (We do generally let other threads run while we wait
1478 to hit the software single-step breakpoint, and they might
1479 encounter such a corrupted instruction.) One way to work around
1480 this would be to have gdbarch_displaced_step_copy_insn fully
1481 simulate the effect of PC-relative instructions (and return NULL)
1482 on architectures that use software single-stepping.
1484 In non-stop mode, we can have independent and simultaneous step
1485 requests, so more than one thread may need to simultaneously step
1486 over a breakpoint. The current implementation assumes there is
1487 only one scratch space per process. In this case, we have to
1488 serialize access to the scratch space. If thread A wants to step
1489 over a breakpoint, but we are currently waiting for some other
1490 thread to complete a displaced step, we leave thread A stopped and
1491 place it in the displaced_step_request_queue. Whenever a displaced
1492 step finishes, we pick the next thread in the queue and start a new
1493 displaced step operation on it. See displaced_step_prepare and
1494 displaced_step_finish for details. */
1496 /* Return true if THREAD is doing a displaced step. */
1499 displaced_step_in_progress_thread (thread_info
*thread
)
1501 gdb_assert (thread
!= NULL
);
1503 return thread
->displaced_step_state
.in_progress ();
1506 /* Return true if INF has a thread doing a displaced step. */
1509 displaced_step_in_progress (inferior
*inf
)
1511 return inf
->displaced_step_state
.in_progress_count
> 0;
1514 /* Return true if any thread is doing a displaced step. */
1517 displaced_step_in_progress_any_thread ()
1519 for (inferior
*inf
: all_non_exited_inferiors ())
1521 if (displaced_step_in_progress (inf
))
1529 infrun_inferior_exit (struct inferior
*inf
)
1531 inf
->displaced_step_state
.reset ();
1535 infrun_inferior_execd (inferior
*inf
)
1537 /* If some threads where was doing a displaced step in this inferior at the
1538 moment of the exec, they no longer exist. Even if the exec'ing thread
1539 doing a displaced step, we don't want to to any fixup nor restore displaced
1540 stepping buffer bytes. */
1541 inf
->displaced_step_state
.reset ();
1543 for (thread_info
*thread
: inf
->threads ())
1544 thread
->displaced_step_state
.reset ();
1546 /* Since an in-line step is done with everything else stopped, if there was
1547 one in progress at the time of the exec, it must have been the exec'ing
1549 clear_step_over_info ();
1552 /* If ON, and the architecture supports it, GDB will use displaced
1553 stepping to step over breakpoints. If OFF, or if the architecture
1554 doesn't support it, GDB will instead use the traditional
1555 hold-and-step approach. If AUTO (which is the default), GDB will
1556 decide which technique to use to step over breakpoints depending on
1557 whether the target works in a non-stop way (see use_displaced_stepping). */
1559 static enum auto_boolean can_use_displaced_stepping
= AUTO_BOOLEAN_AUTO
;
1562 show_can_use_displaced_stepping (struct ui_file
*file
, int from_tty
,
1563 struct cmd_list_element
*c
,
1566 if (can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
)
1567 fprintf_filtered (file
,
1568 _("Debugger's willingness to use displaced stepping "
1569 "to step over breakpoints is %s (currently %s).\n"),
1570 value
, target_is_non_stop_p () ? "on" : "off");
1572 fprintf_filtered (file
,
1573 _("Debugger's willingness to use displaced stepping "
1574 "to step over breakpoints is %s.\n"), value
);
1577 /* Return true if the gdbarch implements the required methods to use
1578 displaced stepping. */
1581 gdbarch_supports_displaced_stepping (gdbarch
*arch
)
1583 /* Only check for the presence of `prepare`. The gdbarch verification ensures
1584 that if `prepare` is provided, so is `finish`. */
1585 return gdbarch_displaced_step_prepare_p (arch
);
1588 /* Return non-zero if displaced stepping can/should be used to step
1589 over breakpoints of thread TP. */
1592 use_displaced_stepping (thread_info
*tp
)
1594 /* If the user disabled it explicitly, don't use displaced stepping. */
1595 if (can_use_displaced_stepping
== AUTO_BOOLEAN_FALSE
)
1598 /* If "auto", only use displaced stepping if the target operates in a non-stop
1600 if (can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
1601 && !target_is_non_stop_p ())
1604 gdbarch
*gdbarch
= get_thread_regcache (tp
)->arch ();
1606 /* If the architecture doesn't implement displaced stepping, don't use
1608 if (!gdbarch_supports_displaced_stepping (gdbarch
))
1611 /* If recording, don't use displaced stepping. */
1612 if (find_record_target () != nullptr)
1615 /* If displaced stepping failed before for this inferior, don't bother trying
1617 if (tp
->inf
->displaced_step_state
.failed_before
)
1623 /* Simple function wrapper around displaced_step_thread_state::reset. */
1626 displaced_step_reset (displaced_step_thread_state
*displaced
)
1628 displaced
->reset ();
1631 /* A cleanup that wraps displaced_step_reset. We use this instead of, say,
1632 SCOPE_EXIT, because it needs to be discardable with "cleanup.release ()". */
1634 using displaced_step_reset_cleanup
= FORWARD_SCOPE_EXIT (displaced_step_reset
);
1639 displaced_step_dump_bytes (const gdb_byte
*buf
, size_t len
)
1643 for (size_t i
= 0; i
< len
; i
++)
1646 ret
+= string_printf ("%02x", buf
[i
]);
1648 ret
+= string_printf (" %02x", buf
[i
]);
1654 /* Prepare to single-step, using displaced stepping.
1656 Note that we cannot use displaced stepping when we have a signal to
1657 deliver. If we have a signal to deliver and an instruction to step
1658 over, then after the step, there will be no indication from the
1659 target whether the thread entered a signal handler or ignored the
1660 signal and stepped over the instruction successfully --- both cases
1661 result in a simple SIGTRAP. In the first case we mustn't do a
1662 fixup, and in the second case we must --- but we can't tell which.
1663 Comments in the code for 'random signals' in handle_inferior_event
1664 explain how we handle this case instead.
1666 Returns DISPLACED_STEP_PREPARE_STATUS_OK if preparing was successful -- this
1667 thread is going to be stepped now; DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
1668 if displaced stepping this thread got queued; or
1669 DISPLACED_STEP_PREPARE_STATUS_CANT if this instruction can't be displaced
1672 static displaced_step_prepare_status
1673 displaced_step_prepare_throw (thread_info
*tp
)
1675 regcache
*regcache
= get_thread_regcache (tp
);
1676 struct gdbarch
*gdbarch
= regcache
->arch ();
1677 displaced_step_thread_state
&disp_step_thread_state
1678 = tp
->displaced_step_state
;
1680 /* We should never reach this function if the architecture does not
1681 support displaced stepping. */
1682 gdb_assert (gdbarch_supports_displaced_stepping (gdbarch
));
1684 /* Nor if the thread isn't meant to step over a breakpoint. */
1685 gdb_assert (tp
->control
.trap_expected
);
1687 /* Disable range stepping while executing in the scratch pad. We
1688 want a single-step even if executing the displaced instruction in
1689 the scratch buffer lands within the stepping range (e.g., a
1691 tp
->control
.may_range_step
= 0;
1693 /* We are about to start a displaced step for this thread. If one is already
1694 in progress, something's wrong. */
1695 gdb_assert (!disp_step_thread_state
.in_progress ());
1697 if (tp
->inf
->displaced_step_state
.unavailable
)
1699 /* The gdbarch tells us it's not worth asking to try a prepare because
1700 it is likely that it will return unavailable, so don't bother asking. */
1702 displaced_debug_printf ("deferring step of %s",
1703 target_pid_to_str (tp
->ptid
).c_str ());
1705 global_thread_step_over_chain_enqueue (tp
);
1706 return DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
;
1709 displaced_debug_printf ("displaced-stepping %s now",
1710 target_pid_to_str (tp
->ptid
).c_str ());
1712 scoped_restore_current_thread restore_thread
;
1714 switch_to_thread (tp
);
1716 CORE_ADDR original_pc
= regcache_read_pc (regcache
);
1717 CORE_ADDR displaced_pc
;
1719 displaced_step_prepare_status status
1720 = gdbarch_displaced_step_prepare (gdbarch
, tp
, displaced_pc
);
1722 if (status
== DISPLACED_STEP_PREPARE_STATUS_CANT
)
1724 displaced_debug_printf ("failed to prepare (%s)",
1725 target_pid_to_str (tp
->ptid
).c_str ());
1727 return DISPLACED_STEP_PREPARE_STATUS_CANT
;
1729 else if (status
== DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
)
1731 /* Not enough displaced stepping resources available, defer this
1732 request by placing it the queue. */
1734 displaced_debug_printf ("not enough resources available, "
1735 "deferring step of %s",
1736 target_pid_to_str (tp
->ptid
).c_str ());
1738 global_thread_step_over_chain_enqueue (tp
);
1740 return DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
;
1743 gdb_assert (status
== DISPLACED_STEP_PREPARE_STATUS_OK
);
1745 /* Save the information we need to fix things up if the step
1747 disp_step_thread_state
.set (gdbarch
);
1749 tp
->inf
->displaced_step_state
.in_progress_count
++;
1751 displaced_debug_printf ("prepared successfully thread=%s, "
1752 "original_pc=%s, displaced_pc=%s",
1753 target_pid_to_str (tp
->ptid
).c_str (),
1754 paddress (gdbarch
, original_pc
),
1755 paddress (gdbarch
, displaced_pc
));
1757 return DISPLACED_STEP_PREPARE_STATUS_OK
;
1760 /* Wrapper for displaced_step_prepare_throw that disabled further
1761 attempts at displaced stepping if we get a memory error. */
1763 static displaced_step_prepare_status
1764 displaced_step_prepare (thread_info
*thread
)
1766 displaced_step_prepare_status status
1767 = DISPLACED_STEP_PREPARE_STATUS_CANT
;
1771 status
= displaced_step_prepare_throw (thread
);
1773 catch (const gdb_exception_error
&ex
)
1775 if (ex
.error
!= MEMORY_ERROR
1776 && ex
.error
!= NOT_SUPPORTED_ERROR
)
1779 infrun_debug_printf ("caught exception, disabling displaced stepping: %s",
1782 /* Be verbose if "set displaced-stepping" is "on", silent if
1784 if (can_use_displaced_stepping
== AUTO_BOOLEAN_TRUE
)
1786 warning (_("disabling displaced stepping: %s"),
1790 /* Disable further displaced stepping attempts. */
1791 thread
->inf
->displaced_step_state
.failed_before
= 1;
1797 /* If we displaced stepped an instruction successfully, adjust registers and
1798 memory to yield the same effect the instruction would have had if we had
1799 executed it at its original address, and return
1800 DISPLACED_STEP_FINISH_STATUS_OK. If the instruction didn't complete,
1801 relocate the PC and return DISPLACED_STEP_FINISH_STATUS_NOT_EXECUTED.
1803 If the thread wasn't displaced stepping, return
1804 DISPLACED_STEP_FINISH_STATUS_OK as well. */
1806 static displaced_step_finish_status
1807 displaced_step_finish (thread_info
*event_thread
, enum gdb_signal signal
)
1809 displaced_step_thread_state
*displaced
= &event_thread
->displaced_step_state
;
1811 /* Was this thread performing a displaced step? */
1812 if (!displaced
->in_progress ())
1813 return DISPLACED_STEP_FINISH_STATUS_OK
;
1815 gdb_assert (event_thread
->inf
->displaced_step_state
.in_progress_count
> 0);
1816 event_thread
->inf
->displaced_step_state
.in_progress_count
--;
1818 /* Fixup may need to read memory/registers. Switch to the thread
1819 that we're fixing up. Also, target_stopped_by_watchpoint checks
1820 the current thread, and displaced_step_restore performs ptid-dependent
1821 memory accesses using current_inferior(). */
1822 switch_to_thread (event_thread
);
1824 displaced_step_reset_cleanup
cleanup (displaced
);
1826 /* Do the fixup, and release the resources acquired to do the displaced
1828 return gdbarch_displaced_step_finish (displaced
->get_original_gdbarch (),
1829 event_thread
, signal
);
1832 /* Data to be passed around while handling an event. This data is
1833 discarded between events. */
1834 struct execution_control_state
1836 process_stratum_target
*target
;
1838 /* The thread that got the event, if this was a thread event; NULL
1840 struct thread_info
*event_thread
;
1842 struct target_waitstatus ws
;
1843 int stop_func_filled_in
;
1844 CORE_ADDR stop_func_start
;
1845 CORE_ADDR stop_func_end
;
1846 const char *stop_func_name
;
1849 /* True if the event thread hit the single-step breakpoint of
1850 another thread. Thus the event doesn't cause a stop, the thread
1851 needs to be single-stepped past the single-step breakpoint before
1852 we can switch back to the original stepping thread. */
1853 int hit_singlestep_breakpoint
;
1856 /* Clear ECS and set it to point at TP. */
1859 reset_ecs (struct execution_control_state
*ecs
, struct thread_info
*tp
)
1861 memset (ecs
, 0, sizeof (*ecs
));
1862 ecs
->event_thread
= tp
;
1863 ecs
->ptid
= tp
->ptid
;
1866 static void keep_going_pass_signal (struct execution_control_state
*ecs
);
1867 static void prepare_to_wait (struct execution_control_state
*ecs
);
1868 static bool keep_going_stepped_thread (struct thread_info
*tp
);
1869 static step_over_what
thread_still_needs_step_over (struct thread_info
*tp
);
1871 /* Are there any pending step-over requests? If so, run all we can
1872 now and return true. Otherwise, return false. */
1875 start_step_over (void)
1877 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
1881 /* Don't start a new step-over if we already have an in-line
1882 step-over operation ongoing. */
1883 if (step_over_info_valid_p ())
1886 /* Steal the global thread step over chain. As we try to initiate displaced
1887 steps, threads will be enqueued in the global chain if no buffers are
1888 available. If we iterated on the global chain directly, we might iterate
1890 thread_info
*threads_to_step
= global_thread_step_over_chain_head
;
1891 global_thread_step_over_chain_head
= NULL
;
1893 infrun_debug_printf ("stealing global queue of threads to step, length = %d",
1894 thread_step_over_chain_length (threads_to_step
));
1896 bool started
= false;
1898 /* On scope exit (whatever the reason, return or exception), if there are
1899 threads left in the THREADS_TO_STEP chain, put back these threads in the
1903 if (threads_to_step
== nullptr)
1904 infrun_debug_printf ("step-over queue now empty");
1907 infrun_debug_printf ("putting back %d threads to step in global queue",
1908 thread_step_over_chain_length (threads_to_step
));
1910 global_thread_step_over_chain_enqueue_chain (threads_to_step
);
1914 for (thread_info
*tp
= threads_to_step
; tp
!= NULL
; tp
= next
)
1916 struct execution_control_state ecss
;
1917 struct execution_control_state
*ecs
= &ecss
;
1918 step_over_what step_what
;
1919 int must_be_in_line
;
1921 gdb_assert (!tp
->stop_requested
);
1923 next
= thread_step_over_chain_next (threads_to_step
, tp
);
1925 if (tp
->inf
->displaced_step_state
.unavailable
)
1927 /* The arch told us to not even try preparing another displaced step
1928 for this inferior. Just leave the thread in THREADS_TO_STEP, it
1929 will get moved to the global chain on scope exit. */
1933 if (tp
->inf
->thread_waiting_for_vfork_done
)
1939 /* Remove thread from the THREADS_TO_STEP chain. If anything goes wrong
1940 while we try to prepare the displaced step, we don't add it back to
1941 the global step over chain. This is to avoid a thread staying in the
1942 step over chain indefinitely if something goes wrong when resuming it
1943 If the error is intermittent and it still needs a step over, it will
1944 get enqueued again when we try to resume it normally. */
1945 thread_step_over_chain_remove (&threads_to_step
, tp
);
1947 step_what
= thread_still_needs_step_over (tp
);
1948 must_be_in_line
= ((step_what
& STEP_OVER_WATCHPOINT
)
1949 || ((step_what
& STEP_OVER_BREAKPOINT
)
1950 && !use_displaced_stepping (tp
)));
1952 /* We currently stop all threads of all processes to step-over
1953 in-line. If we need to start a new in-line step-over, let
1954 any pending displaced steps finish first. */
1955 if (must_be_in_line
&& displaced_step_in_progress_any_thread ())
1957 global_thread_step_over_chain_enqueue (tp
);
1961 if (tp
->control
.trap_expected
1965 internal_error (__FILE__
, __LINE__
,
1966 "[%s] has inconsistent state: "
1967 "trap_expected=%d, resumed=%d, executing=%d\n",
1968 target_pid_to_str (tp
->ptid
).c_str (),
1969 tp
->control
.trap_expected
,
1974 infrun_debug_printf ("resuming [%s] for step-over",
1975 target_pid_to_str (tp
->ptid
).c_str ());
1977 /* keep_going_pass_signal skips the step-over if the breakpoint
1978 is no longer inserted. In all-stop, we want to keep looking
1979 for a thread that needs a step-over instead of resuming TP,
1980 because we wouldn't be able to resume anything else until the
1981 target stops again. In non-stop, the resume always resumes
1982 only TP, so it's OK to let the thread resume freely. */
1983 if (!target_is_non_stop_p () && !step_what
)
1986 switch_to_thread (tp
);
1987 reset_ecs (ecs
, tp
);
1988 keep_going_pass_signal (ecs
);
1990 if (!ecs
->wait_some_more
)
1991 error (_("Command aborted."));
1993 /* If the thread's step over could not be initiated because no buffers
1994 were available, it was re-added to the global step over chain. */
1997 infrun_debug_printf ("[%s] was resumed.",
1998 target_pid_to_str (tp
->ptid
).c_str ());
1999 gdb_assert (!thread_is_in_step_over_chain (tp
));
2003 infrun_debug_printf ("[%s] was NOT resumed.",
2004 target_pid_to_str (tp
->ptid
).c_str ());
2005 gdb_assert (thread_is_in_step_over_chain (tp
));
2008 /* If we started a new in-line step-over, we're done. */
2009 if (step_over_info_valid_p ())
2011 gdb_assert (tp
->control
.trap_expected
);
2016 if (!target_is_non_stop_p ())
2018 /* On all-stop, shouldn't have resumed unless we needed a
2020 gdb_assert (tp
->control
.trap_expected
2021 || tp
->step_after_step_resume_breakpoint
);
2023 /* With remote targets (at least), in all-stop, we can't
2024 issue any further remote commands until the program stops
2030 /* Either the thread no longer needed a step-over, or a new
2031 displaced stepping sequence started. Even in the latter
2032 case, continue looking. Maybe we can also start another
2033 displaced step on a thread of other process. */
2039 /* Update global variables holding ptids to hold NEW_PTID if they were
2040 holding OLD_PTID. */
2042 infrun_thread_ptid_changed (process_stratum_target
*target
,
2043 ptid_t old_ptid
, ptid_t new_ptid
)
2045 if (inferior_ptid
== old_ptid
2046 && current_inferior ()->process_target () == target
)
2047 inferior_ptid
= new_ptid
;
2052 static const char schedlock_off
[] = "off";
2053 static const char schedlock_on
[] = "on";
2054 static const char schedlock_step
[] = "step";
2055 static const char schedlock_replay
[] = "replay";
2056 static const char *const scheduler_enums
[] = {
2063 static const char *scheduler_mode
= schedlock_replay
;
2065 show_scheduler_mode (struct ui_file
*file
, int from_tty
,
2066 struct cmd_list_element
*c
, const char *value
)
2068 fprintf_filtered (file
,
2069 _("Mode for locking scheduler "
2070 "during execution is \"%s\".\n"),
2075 set_schedlock_func (const char *args
, int from_tty
, struct cmd_list_element
*c
)
2077 if (!target_can_lock_scheduler ())
2079 scheduler_mode
= schedlock_off
;
2080 error (_("Target '%s' cannot support this command."),
2081 target_shortname ());
2085 /* True if execution commands resume all threads of all processes by
2086 default; otherwise, resume only threads of the current inferior
2088 bool sched_multi
= false;
2090 /* Try to setup for software single stepping over the specified location.
2091 Return true if target_resume() should use hardware single step.
2093 GDBARCH the current gdbarch.
2094 PC the location to step over. */
2097 maybe_software_singlestep (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
2099 bool hw_step
= true;
2101 if (execution_direction
== EXEC_FORWARD
2102 && gdbarch_software_single_step_p (gdbarch
))
2103 hw_step
= !insert_single_step_breakpoints (gdbarch
);
2111 user_visible_resume_ptid (int step
)
2117 /* With non-stop mode on, threads are always handled
2119 resume_ptid
= inferior_ptid
;
2121 else if ((scheduler_mode
== schedlock_on
)
2122 || (scheduler_mode
== schedlock_step
&& step
))
2124 /* User-settable 'scheduler' mode requires solo thread
2126 resume_ptid
= inferior_ptid
;
2128 else if ((scheduler_mode
== schedlock_replay
)
2129 && target_record_will_replay (minus_one_ptid
, execution_direction
))
2131 /* User-settable 'scheduler' mode requires solo thread resume in replay
2133 resume_ptid
= inferior_ptid
;
2135 else if (!sched_multi
&& target_supports_multi_process ())
2137 /* Resume all threads of the current process (and none of other
2139 resume_ptid
= ptid_t (inferior_ptid
.pid ());
2143 /* Resume all threads of all processes. */
2144 resume_ptid
= RESUME_ALL
;
2152 process_stratum_target
*
2153 user_visible_resume_target (ptid_t resume_ptid
)
2155 return (resume_ptid
== minus_one_ptid
&& sched_multi
2157 : current_inferior ()->process_target ());
2160 /* Return a ptid representing the set of threads that we will resume,
2161 in the perspective of the target, assuming run control handling
2162 does not require leaving some threads stopped (e.g., stepping past
2163 breakpoint). USER_STEP indicates whether we're about to start the
2164 target for a stepping command. */
2167 internal_resume_ptid (int user_step
)
2169 /* In non-stop, we always control threads individually. Note that
2170 the target may always work in non-stop mode even with "set
2171 non-stop off", in which case user_visible_resume_ptid could
2172 return a wildcard ptid. */
2173 if (target_is_non_stop_p ())
2174 return inferior_ptid
;
2176 /* The rest of the function assumes non-stop==off and
2177 target-non-stop==off. */
2179 /* If a thread in the resumption set is waiting for a vfork-done event (the
2180 vfork child is not under GDB's control), resume just that thread.
2182 If the target_resume interface was more flexible, we could be smarter
2183 here when schedule-multiple is on . For example, imagine 3 inferiors with
2184 2 threads each (1.1, 1.2, 2.1, 2.2, 3.1 and 3.2). Threads 2.1 and 3.2 are
2185 both waiting for a vfork-done event. Then we could ask the target(s) to
2188 - All threads of inferior 1
2192 Since we don't have that flexibility, just resume the first thread waiting
2193 for a vfork-done event we find (e.g. thread 2.1). */
2196 for (inferior
*inf
: all_non_exited_inferiors ())
2197 if (inf
->thread_waiting_for_vfork_done
!= nullptr)
2198 return inf
->thread_waiting_for_vfork_done
->ptid
;
2200 else if (current_inferior ()->thread_waiting_for_vfork_done
!= nullptr)
2201 return current_inferior ()->thread_waiting_for_vfork_done
->ptid
;
2203 /* If an inferior (so, under GDB's control) is a vfork child of another
2204 continue just that inferior. */
2207 for (inferior
*inf
: all_non_exited_inferiors ())
2208 if (inf
->vfork_parent
!= nullptr)
2209 return ptid_t (inf
->pid
);
2211 else if (current_inferior ()->vfork_parent
!= nullptr)
2212 return ptid_t (current_inferior ()->pid
);
2214 return user_visible_resume_ptid (user_step
);
2217 /* Wrapper for target_resume, that handles infrun-specific
2221 do_target_resume (ptid_t resume_ptid
, bool step
, enum gdb_signal sig
)
2223 struct thread_info
*tp
= inferior_thread ();
2225 gdb_assert (!tp
->stop_requested
);
2227 /* Install inferior's terminal modes. */
2228 target_terminal::inferior ();
2230 /* Avoid confusing the next resume, if the next stop/resume
2231 happens to apply to another thread. */
2232 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2234 /* Advise target which signals may be handled silently.
2236 If we have removed breakpoints because we are stepping over one
2237 in-line (in any thread), we need to receive all signals to avoid
2238 accidentally skipping a breakpoint during execution of a signal
2241 Likewise if we're displaced stepping, otherwise a trap for a
2242 breakpoint in a signal handler might be confused with the
2243 displaced step finishing. We don't make the displaced_step_finish
2244 step distinguish the cases instead, because:
2246 - a backtrace while stopped in the signal handler would show the
2247 scratch pad as frame older than the signal handler, instead of
2248 the real mainline code.
2250 - when the thread is later resumed, the signal handler would
2251 return to the scratch pad area, which would no longer be
2253 if (step_over_info_valid_p ()
2254 || displaced_step_in_progress (tp
->inf
))
2255 target_pass_signals ({});
2257 target_pass_signals (signal_pass
);
2259 infrun_debug_printf ("resume_ptid=%s, step=%d, sig=%s",
2260 resume_ptid
.to_string ().c_str (),
2261 step
, gdb_signal_to_symbol_string (sig
));
2262 target_resume (resume_ptid
, step
, sig
);
2264 if (target_can_async_p ())
2268 /* Resume the inferior. SIG is the signal to give the inferior
2269 (GDB_SIGNAL_0 for none). Note: don't call this directly; instead
2270 call 'resume', which handles exceptions. */
2273 resume_1 (enum gdb_signal sig
)
2275 struct regcache
*regcache
= get_current_regcache ();
2276 struct gdbarch
*gdbarch
= regcache
->arch ();
2277 struct thread_info
*tp
= inferior_thread ();
2278 const address_space
*aspace
= regcache
->aspace ();
2279 /* This represents the user's step vs continue request. When
2280 deciding whether "set scheduler-locking step" applies, it's the
2281 user's intention that counts. */
2282 const int user_step
= tp
->control
.stepping_command
;
2283 /* This represents what we'll actually request the target to do.
2284 This can decay from a step to a continue, if e.g., we need to
2285 implement single-stepping with breakpoints (software
2289 gdb_assert (!tp
->stop_requested
);
2290 gdb_assert (!thread_is_in_step_over_chain (tp
));
2291 gdb_assert (tp
->inf
->thread_waiting_for_vfork_done
== nullptr
2292 || tp
->inf
->thread_waiting_for_vfork_done
== tp
);
2294 if (tp
->suspend
.waitstatus_pending_p
)
2297 ("thread %s has pending wait "
2298 "status %s (currently_stepping=%d).",
2299 target_pid_to_str (tp
->ptid
).c_str (),
2300 target_waitstatus_to_string (&tp
->suspend
.waitstatus
).c_str (),
2301 currently_stepping (tp
));
2303 tp
->inf
->process_target ()->threads_executing
= true;
2306 /* FIXME: What should we do if we are supposed to resume this
2307 thread with a signal? Maybe we should maintain a queue of
2308 pending signals to deliver. */
2309 if (sig
!= GDB_SIGNAL_0
)
2311 warning (_("Couldn't deliver signal %s to %s."),
2312 gdb_signal_to_name (sig
),
2313 target_pid_to_str (tp
->ptid
).c_str ());
2316 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2318 if (target_can_async_p ())
2321 /* Tell the event loop we have an event to process. */
2322 mark_async_event_handler (infrun_async_inferior_event_token
);
2327 tp
->stepped_breakpoint
= 0;
2329 /* Depends on stepped_breakpoint. */
2330 step
= currently_stepping (tp
);
2332 if (current_inferior ()->thread_waiting_for_vfork_done
!= nullptr)
2334 /* Don't try to single-step a vfork parent that is waiting for
2335 the child to get out of the shared memory region (by exec'ing
2336 or exiting). This is particularly important on software
2337 single-step archs, as the child process would trip on the
2338 software single step breakpoint inserted for the parent
2339 process. Since the parent will not actually execute any
2340 instruction until the child is out of the shared region (such
2341 are vfork's semantics), it is safe to simply continue it.
2342 Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for
2343 the parent, and tell it to `keep_going', which automatically
2344 re-sets it stepping. */
2345 infrun_debug_printf ("resume : clear step");
2349 CORE_ADDR pc
= regcache_read_pc (regcache
);
2351 infrun_debug_printf ("step=%d, signal=%s, trap_expected=%d, "
2352 "current thread [%s] at %s",
2353 step
, gdb_signal_to_symbol_string (sig
),
2354 tp
->control
.trap_expected
,
2355 target_pid_to_str (inferior_ptid
).c_str (),
2356 paddress (gdbarch
, pc
));
2358 /* Normally, by the time we reach `resume', the breakpoints are either
2359 removed or inserted, as appropriate. The exception is if we're sitting
2360 at a permanent breakpoint; we need to step over it, but permanent
2361 breakpoints can't be removed. So we have to test for it here. */
2362 if (breakpoint_here_p (aspace
, pc
) == permanent_breakpoint_here
)
2364 if (sig
!= GDB_SIGNAL_0
)
2366 /* We have a signal to pass to the inferior. The resume
2367 may, or may not take us to the signal handler. If this
2368 is a step, we'll need to stop in the signal handler, if
2369 there's one, (if the target supports stepping into
2370 handlers), or in the next mainline instruction, if
2371 there's no handler. If this is a continue, we need to be
2372 sure to run the handler with all breakpoints inserted.
2373 In all cases, set a breakpoint at the current address
2374 (where the handler returns to), and once that breakpoint
2375 is hit, resume skipping the permanent breakpoint. If
2376 that breakpoint isn't hit, then we've stepped into the
2377 signal handler (or hit some other event). We'll delete
2378 the step-resume breakpoint then. */
2380 infrun_debug_printf ("resume: skipping permanent breakpoint, "
2381 "deliver signal first");
2383 clear_step_over_info ();
2384 tp
->control
.trap_expected
= 0;
2386 if (tp
->control
.step_resume_breakpoint
== NULL
)
2388 /* Set a "high-priority" step-resume, as we don't want
2389 user breakpoints at PC to trigger (again) when this
2391 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
2392 gdb_assert (tp
->control
.step_resume_breakpoint
->loc
->permanent
);
2394 tp
->step_after_step_resume_breakpoint
= step
;
2397 insert_breakpoints ();
2401 /* There's no signal to pass, we can go ahead and skip the
2402 permanent breakpoint manually. */
2403 infrun_debug_printf ("skipping permanent breakpoint");
2404 gdbarch_skip_permanent_breakpoint (gdbarch
, regcache
);
2405 /* Update pc to reflect the new address from which we will
2406 execute instructions. */
2407 pc
= regcache_read_pc (regcache
);
2411 /* We've already advanced the PC, so the stepping part
2412 is done. Now we need to arrange for a trap to be
2413 reported to handle_inferior_event. Set a breakpoint
2414 at the current PC, and run to it. Don't update
2415 prev_pc, because if we end in
2416 switch_back_to_stepped_thread, we want the "expected
2417 thread advanced also" branch to be taken. IOW, we
2418 don't want this thread to step further from PC
2420 gdb_assert (!step_over_info_valid_p ());
2421 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
2422 insert_breakpoints ();
2424 ptid_t resume_ptid
= internal_resume_ptid (user_step
);
2425 do_target_resume (resume_ptid
, false, GDB_SIGNAL_0
);
2432 /* If we have a breakpoint to step over, make sure to do a single
2433 step only. Same if we have software watchpoints. */
2434 if (tp
->control
.trap_expected
|| bpstat_should_step ())
2435 tp
->control
.may_range_step
= 0;
2437 /* If displaced stepping is enabled, step over breakpoints by executing a
2438 copy of the instruction at a different address.
2440 We can't use displaced stepping when we have a signal to deliver;
2441 the comments for displaced_step_prepare explain why. The
2442 comments in the handle_inferior event for dealing with 'random
2443 signals' explain what we do instead.
2445 We can't use displaced stepping when we are waiting for vfork_done
2446 event, displaced stepping breaks the vfork child similarly as single
2447 step software breakpoint. */
2448 if (tp
->control
.trap_expected
2449 && use_displaced_stepping (tp
)
2450 && !step_over_info_valid_p ()
2451 && sig
== GDB_SIGNAL_0
2452 && current_inferior ()->thread_waiting_for_vfork_done
== nullptr)
2454 displaced_step_prepare_status prepare_status
2455 = displaced_step_prepare (tp
);
2457 if (prepare_status
== DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
)
2459 infrun_debug_printf ("Got placed in step-over queue");
2461 tp
->control
.trap_expected
= 0;
2464 else if (prepare_status
== DISPLACED_STEP_PREPARE_STATUS_CANT
)
2466 /* Fallback to stepping over the breakpoint in-line. */
2468 if (target_is_non_stop_p ())
2469 stop_all_threads ("displaced stepping falling back on inline stepping");
2471 set_step_over_info (regcache
->aspace (),
2472 regcache_read_pc (regcache
), 0, tp
->global_num
);
2474 step
= maybe_software_singlestep (gdbarch
, pc
);
2476 insert_breakpoints ();
2478 else if (prepare_status
== DISPLACED_STEP_PREPARE_STATUS_OK
)
2480 /* Update pc to reflect the new address from which we will
2481 execute instructions due to displaced stepping. */
2482 pc
= regcache_read_pc (get_thread_regcache (tp
));
2484 step
= gdbarch_displaced_step_hw_singlestep (gdbarch
);
2487 gdb_assert_not_reached (_("Invalid displaced_step_prepare_status "
2491 /* Do we need to do it the hard way, w/temp breakpoints? */
2493 step
= maybe_software_singlestep (gdbarch
, pc
);
2495 /* Currently, our software single-step implementation leads to different
2496 results than hardware single-stepping in one situation: when stepping
2497 into delivering a signal which has an associated signal handler,
2498 hardware single-step will stop at the first instruction of the handler,
2499 while software single-step will simply skip execution of the handler.
2501 For now, this difference in behavior is accepted since there is no
2502 easy way to actually implement single-stepping into a signal handler
2503 without kernel support.
2505 However, there is one scenario where this difference leads to follow-on
2506 problems: if we're stepping off a breakpoint by removing all breakpoints
2507 and then single-stepping. In this case, the software single-step
2508 behavior means that even if there is a *breakpoint* in the signal
2509 handler, GDB still would not stop.
2511 Fortunately, we can at least fix this particular issue. We detect
2512 here the case where we are about to deliver a signal while software
2513 single-stepping with breakpoints removed. In this situation, we
2514 revert the decisions to remove all breakpoints and insert single-
2515 step breakpoints, and instead we install a step-resume breakpoint
2516 at the current address, deliver the signal without stepping, and
2517 once we arrive back at the step-resume breakpoint, actually step
2518 over the breakpoint we originally wanted to step over. */
2519 if (thread_has_single_step_breakpoints_set (tp
)
2520 && sig
!= GDB_SIGNAL_0
2521 && step_over_info_valid_p ())
2523 /* If we have nested signals or a pending signal is delivered
2524 immediately after a handler returns, might already have
2525 a step-resume breakpoint set on the earlier handler. We cannot
2526 set another step-resume breakpoint; just continue on until the
2527 original breakpoint is hit. */
2528 if (tp
->control
.step_resume_breakpoint
== NULL
)
2530 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
2531 tp
->step_after_step_resume_breakpoint
= 1;
2534 delete_single_step_breakpoints (tp
);
2536 clear_step_over_info ();
2537 tp
->control
.trap_expected
= 0;
2539 insert_breakpoints ();
2542 /* If STEP is set, it's a request to use hardware stepping
2543 facilities. But in that case, we should never
2544 use singlestep breakpoint. */
2545 gdb_assert (!(thread_has_single_step_breakpoints_set (tp
) && step
));
2547 /* Decide the set of threads to ask the target to resume. */
2549 if (tp
->control
.trap_expected
)
2551 /* We're allowing a thread to run past a breakpoint it has
2552 hit, either by single-stepping the thread with the breakpoint
2553 removed, or by displaced stepping, with the breakpoint inserted.
2554 In the former case, we need to single-step only this thread,
2555 and keep others stopped, as they can miss this breakpoint if
2556 allowed to run. That's not really a problem for displaced
2557 stepping, but, we still keep other threads stopped, in case
2558 another thread is also stopped for a breakpoint waiting for
2559 its turn in the displaced stepping queue. */
2560 resume_ptid
= inferior_ptid
;
2563 resume_ptid
= internal_resume_ptid (user_step
);
2565 if (execution_direction
!= EXEC_REVERSE
2566 && step
&& breakpoint_inserted_here_p (aspace
, pc
))
2568 /* There are two cases where we currently need to step a
2569 breakpoint instruction when we have a signal to deliver:
2571 - See handle_signal_stop where we handle random signals that
2572 could take out us out of the stepping range. Normally, in
2573 that case we end up continuing (instead of stepping) over the
2574 signal handler with a breakpoint at PC, but there are cases
2575 where we should _always_ single-step, even if we have a
2576 step-resume breakpoint, like when a software watchpoint is
2577 set. Assuming single-stepping and delivering a signal at the
2578 same time would takes us to the signal handler, then we could
2579 have removed the breakpoint at PC to step over it. However,
2580 some hardware step targets (like e.g., Mac OS) can't step
2581 into signal handlers, and for those, we need to leave the
2582 breakpoint at PC inserted, as otherwise if the handler
2583 recurses and executes PC again, it'll miss the breakpoint.
2584 So we leave the breakpoint inserted anyway, but we need to
2585 record that we tried to step a breakpoint instruction, so
2586 that adjust_pc_after_break doesn't end up confused.
2588 - In non-stop if we insert a breakpoint (e.g., a step-resume)
2589 in one thread after another thread that was stepping had been
2590 momentarily paused for a step-over. When we re-resume the
2591 stepping thread, it may be resumed from that address with a
2592 breakpoint that hasn't trapped yet. Seen with
2593 gdb.threads/non-stop-fair-events.exp, on targets that don't
2594 do displaced stepping. */
2596 infrun_debug_printf ("resume: [%s] stepped breakpoint",
2597 target_pid_to_str (tp
->ptid
).c_str ());
2599 tp
->stepped_breakpoint
= 1;
2601 /* Most targets can step a breakpoint instruction, thus
2602 executing it normally. But if this one cannot, just
2603 continue and we will hit it anyway. */
2604 if (gdbarch_cannot_step_breakpoint (gdbarch
))
2609 && tp
->control
.trap_expected
2610 && use_displaced_stepping (tp
)
2611 && !step_over_info_valid_p ())
2613 struct regcache
*resume_regcache
= get_thread_regcache (tp
);
2614 struct gdbarch
*resume_gdbarch
= resume_regcache
->arch ();
2615 CORE_ADDR actual_pc
= regcache_read_pc (resume_regcache
);
2618 read_memory (actual_pc
, buf
, sizeof (buf
));
2619 displaced_debug_printf ("run %s: %s",
2620 paddress (resume_gdbarch
, actual_pc
),
2621 displaced_step_dump_bytes
2622 (buf
, sizeof (buf
)).c_str ());
2625 if (tp
->control
.may_range_step
)
2627 /* If we're resuming a thread with the PC out of the step
2628 range, then we're doing some nested/finer run control
2629 operation, like stepping the thread out of the dynamic
2630 linker or the displaced stepping scratch pad. We
2631 shouldn't have allowed a range step then. */
2632 gdb_assert (pc_in_thread_step_range (pc
, tp
));
2635 do_target_resume (resume_ptid
, step
, sig
);
2639 /* Resume the inferior. SIG is the signal to give the inferior
2640 (GDB_SIGNAL_0 for none). This is a wrapper around 'resume_1' that
2641 rolls back state on error. */
2644 resume (gdb_signal sig
)
2650 catch (const gdb_exception
&ex
)
2652 /* If resuming is being aborted for any reason, delete any
2653 single-step breakpoint resume_1 may have created, to avoid
2654 confusing the following resumption, and to avoid leaving
2655 single-step breakpoints perturbing other threads, in case
2656 we're running in non-stop mode. */
2657 if (inferior_ptid
!= null_ptid
)
2658 delete_single_step_breakpoints (inferior_thread ());
2668 /* Counter that tracks number of user visible stops. This can be used
2669 to tell whether a command has proceeded the inferior past the
2670 current location. This allows e.g., inferior function calls in
2671 breakpoint commands to not interrupt the command list. When the
2672 call finishes successfully, the inferior is standing at the same
2673 breakpoint as if nothing happened (and so we don't call
2675 static ULONGEST current_stop_id
;
2682 return current_stop_id
;
2685 /* Called when we report a user visible stop. */
2693 /* Clear out all variables saying what to do when inferior is continued.
2694 First do this, then set the ones you want, then call `proceed'. */
2697 clear_proceed_status_thread (struct thread_info
*tp
)
2699 infrun_debug_printf ("%s", target_pid_to_str (tp
->ptid
).c_str ());
2701 /* If we're starting a new sequence, then the previous finished
2702 single-step is no longer relevant. */
2703 if (tp
->suspend
.waitstatus_pending_p
)
2705 if (tp
->suspend
.stop_reason
== TARGET_STOPPED_BY_SINGLE_STEP
)
2707 infrun_debug_printf ("pending event of %s was a finished step. "
2709 target_pid_to_str (tp
->ptid
).c_str ());
2711 tp
->suspend
.waitstatus_pending_p
= 0;
2712 tp
->suspend
.stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
2717 ("thread %s has pending wait status %s (currently_stepping=%d).",
2718 target_pid_to_str (tp
->ptid
).c_str (),
2719 target_waitstatus_to_string (&tp
->suspend
.waitstatus
).c_str (),
2720 currently_stepping (tp
));
2724 /* If this signal should not be seen by program, give it zero.
2725 Used for debugging signals. */
2726 if (!signal_pass_state (tp
->suspend
.stop_signal
))
2727 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2729 delete tp
->thread_fsm
;
2730 tp
->thread_fsm
= NULL
;
2732 tp
->control
.trap_expected
= 0;
2733 tp
->control
.step_range_start
= 0;
2734 tp
->control
.step_range_end
= 0;
2735 tp
->control
.may_range_step
= 0;
2736 tp
->control
.step_frame_id
= null_frame_id
;
2737 tp
->control
.step_stack_frame_id
= null_frame_id
;
2738 tp
->control
.step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
2739 tp
->control
.step_start_function
= NULL
;
2740 tp
->stop_requested
= 0;
2742 tp
->control
.stop_step
= 0;
2744 tp
->control
.proceed_to_finish
= 0;
2746 tp
->control
.stepping_command
= 0;
2748 /* Discard any remaining commands or status from previous stop. */
2749 bpstat_clear (&tp
->control
.stop_bpstat
);
2753 clear_proceed_status (int step
)
2755 /* With scheduler-locking replay, stop replaying other threads if we're
2756 not replaying the user-visible resume ptid.
2758 This is a convenience feature to not require the user to explicitly
2759 stop replaying the other threads. We're assuming that the user's
2760 intent is to resume tracing the recorded process. */
2761 if (!non_stop
&& scheduler_mode
== schedlock_replay
2762 && target_record_is_replaying (minus_one_ptid
)
2763 && !target_record_will_replay (user_visible_resume_ptid (step
),
2764 execution_direction
))
2765 target_record_stop_replaying ();
2767 if (!non_stop
&& inferior_ptid
!= null_ptid
)
2769 ptid_t resume_ptid
= user_visible_resume_ptid (step
);
2770 process_stratum_target
*resume_target
2771 = user_visible_resume_target (resume_ptid
);
2773 /* In all-stop mode, delete the per-thread status of all threads
2774 we're about to resume, implicitly and explicitly. */
2775 for (thread_info
*tp
: all_non_exited_threads (resume_target
, resume_ptid
))
2776 clear_proceed_status_thread (tp
);
2779 if (inferior_ptid
!= null_ptid
)
2781 struct inferior
*inferior
;
2785 /* If in non-stop mode, only delete the per-thread status of
2786 the current thread. */
2787 clear_proceed_status_thread (inferior_thread ());
2790 inferior
= current_inferior ();
2791 inferior
->control
.stop_soon
= NO_STOP_QUIETLY
;
2794 gdb::observers::about_to_proceed
.notify ();
2797 /* Returns true if TP is still stopped at a breakpoint that needs
2798 stepping-over in order to make progress. If the breakpoint is gone
2799 meanwhile, we can skip the whole step-over dance. */
2802 thread_still_needs_step_over_bp (struct thread_info
*tp
)
2804 if (tp
->stepping_over_breakpoint
)
2806 struct regcache
*regcache
= get_thread_regcache (tp
);
2808 if (breakpoint_here_p (regcache
->aspace (),
2809 regcache_read_pc (regcache
))
2810 == ordinary_breakpoint_here
)
2813 tp
->stepping_over_breakpoint
= 0;
2819 /* Check whether thread TP still needs to start a step-over in order
2820 to make progress when resumed. Returns an bitwise or of enum
2821 step_over_what bits, indicating what needs to be stepped over. */
2823 static step_over_what
2824 thread_still_needs_step_over (struct thread_info
*tp
)
2826 step_over_what what
= 0;
2828 if (thread_still_needs_step_over_bp (tp
))
2829 what
|= STEP_OVER_BREAKPOINT
;
2831 if (tp
->stepping_over_watchpoint
2832 && !target_have_steppable_watchpoint ())
2833 what
|= STEP_OVER_WATCHPOINT
;
2838 /* Returns true if scheduler locking applies. STEP indicates whether
2839 we're about to do a step/next-like command to a thread. */
2842 schedlock_applies (struct thread_info
*tp
)
2844 return (scheduler_mode
== schedlock_on
2845 || (scheduler_mode
== schedlock_step
2846 && tp
->control
.stepping_command
)
2847 || (scheduler_mode
== schedlock_replay
2848 && target_record_will_replay (minus_one_ptid
,
2849 execution_direction
)));
2852 /* Set process_stratum_target::COMMIT_RESUMED_STATE in all target
2853 stacks that have threads executing and don't have threads with
2857 maybe_set_commit_resumed_all_targets ()
2859 scoped_restore_current_thread restore_thread
;
2861 for (inferior
*inf
: all_non_exited_inferiors ())
2863 process_stratum_target
*proc_target
= inf
->process_target ();
2865 if (proc_target
->commit_resumed_state
)
2867 /* We already set this in a previous iteration, via another
2868 inferior sharing the process_stratum target. */
2872 /* If the target has no resumed threads, it would be useless to
2873 ask it to commit the resumed threads. */
2874 if (!proc_target
->threads_executing
)
2876 infrun_debug_printf ("not requesting commit-resumed for target "
2877 "%s, no resumed threads",
2878 proc_target
->shortname ());
2882 /* As an optimization, if a thread from this target has some
2883 status to report, handle it before requiring the target to
2884 commit its resumed threads: handling the status might lead to
2885 resuming more threads. */
2886 bool has_thread_with_pending_status
= false;
2887 for (thread_info
*thread
: all_non_exited_threads (proc_target
))
2888 if (thread
->resumed
&& thread
->suspend
.waitstatus_pending_p
)
2890 has_thread_with_pending_status
= true;
2894 if (has_thread_with_pending_status
)
2896 infrun_debug_printf ("not requesting commit-resumed for target %s, a"
2897 " thread has a pending waitstatus",
2898 proc_target
->shortname ());
2902 switch_to_inferior_no_thread (inf
);
2904 if (target_has_pending_events ())
2906 infrun_debug_printf ("not requesting commit-resumed for target %s, "
2907 "target has pending events",
2908 proc_target
->shortname ());
2912 infrun_debug_printf ("enabling commit-resumed for target %s",
2913 proc_target
->shortname ());
2915 proc_target
->commit_resumed_state
= true;
2922 maybe_call_commit_resumed_all_targets ()
2924 scoped_restore_current_thread restore_thread
;
2926 for (inferior
*inf
: all_non_exited_inferiors ())
2928 process_stratum_target
*proc_target
= inf
->process_target ();
2930 if (!proc_target
->commit_resumed_state
)
2933 switch_to_inferior_no_thread (inf
);
2935 infrun_debug_printf ("calling commit_resumed for target %s",
2936 proc_target
->shortname());
2938 target_commit_resumed ();
2942 /* To track nesting of scoped_disable_commit_resumed objects, ensuring
2943 that only the outermost one attempts to re-enable
2945 static bool enable_commit_resumed
= true;
2949 scoped_disable_commit_resumed::scoped_disable_commit_resumed
2950 (const char *reason
)
2951 : m_reason (reason
),
2952 m_prev_enable_commit_resumed (enable_commit_resumed
)
2954 infrun_debug_printf ("reason=%s", m_reason
);
2956 enable_commit_resumed
= false;
2958 for (inferior
*inf
: all_non_exited_inferiors ())
2960 process_stratum_target
*proc_target
= inf
->process_target ();
2962 if (m_prev_enable_commit_resumed
)
2964 /* This is the outermost instance: force all
2965 COMMIT_RESUMED_STATE to false. */
2966 proc_target
->commit_resumed_state
= false;
2970 /* This is not the outermost instance, we expect
2971 COMMIT_RESUMED_STATE to have been cleared by the
2972 outermost instance. */
2973 gdb_assert (!proc_target
->commit_resumed_state
);
2981 scoped_disable_commit_resumed::reset ()
2987 infrun_debug_printf ("reason=%s", m_reason
);
2989 gdb_assert (!enable_commit_resumed
);
2991 enable_commit_resumed
= m_prev_enable_commit_resumed
;
2993 if (m_prev_enable_commit_resumed
)
2995 /* This is the outermost instance, re-enable
2996 COMMIT_RESUMED_STATE on the targets where it's possible. */
2997 maybe_set_commit_resumed_all_targets ();
3001 /* This is not the outermost instance, we expect
3002 COMMIT_RESUMED_STATE to still be false. */
3003 for (inferior
*inf
: all_non_exited_inferiors ())
3005 process_stratum_target
*proc_target
= inf
->process_target ();
3006 gdb_assert (!proc_target
->commit_resumed_state
);
3013 scoped_disable_commit_resumed::~scoped_disable_commit_resumed ()
3021 scoped_disable_commit_resumed::reset_and_commit ()
3024 maybe_call_commit_resumed_all_targets ();
3029 scoped_enable_commit_resumed::scoped_enable_commit_resumed
3030 (const char *reason
)
3031 : m_reason (reason
),
3032 m_prev_enable_commit_resumed (enable_commit_resumed
)
3034 infrun_debug_printf ("reason=%s", m_reason
);
3036 if (!enable_commit_resumed
)
3038 enable_commit_resumed
= true;
3040 /* Re-enable COMMIT_RESUMED_STATE on the targets where it's
3042 maybe_set_commit_resumed_all_targets ();
3044 maybe_call_commit_resumed_all_targets ();
3050 scoped_enable_commit_resumed::~scoped_enable_commit_resumed ()
3052 infrun_debug_printf ("reason=%s", m_reason
);
3054 gdb_assert (enable_commit_resumed
);
3056 enable_commit_resumed
= m_prev_enable_commit_resumed
;
3058 if (!enable_commit_resumed
)
3060 /* Force all COMMIT_RESUMED_STATE back to false. */
3061 for (inferior
*inf
: all_non_exited_inferiors ())
3063 process_stratum_target
*proc_target
= inf
->process_target ();
3064 proc_target
->commit_resumed_state
= false;
3069 /* Check that all the targets we're about to resume are in non-stop
3070 mode. Ideally, we'd only care whether all targets support
3071 target-async, but we're not there yet. E.g., stop_all_threads
3072 doesn't know how to handle all-stop targets. Also, the remote
3073 protocol in all-stop mode is synchronous, irrespective of
3074 target-async, which means that things like a breakpoint re-set
3075 triggered by one target would try to read memory from all targets
3079 check_multi_target_resumption (process_stratum_target
*resume_target
)
3081 if (!non_stop
&& resume_target
== nullptr)
3083 scoped_restore_current_thread restore_thread
;
3085 /* This is used to track whether we're resuming more than one
3087 process_stratum_target
*first_connection
= nullptr;
3089 /* The first inferior we see with a target that does not work in
3090 always-non-stop mode. */
3091 inferior
*first_not_non_stop
= nullptr;
3093 for (inferior
*inf
: all_non_exited_inferiors ())
3095 switch_to_inferior_no_thread (inf
);
3097 if (!target_has_execution ())
3100 process_stratum_target
*proc_target
3101 = current_inferior ()->process_target();
3103 if (!target_is_non_stop_p ())
3104 first_not_non_stop
= inf
;
3106 if (first_connection
== nullptr)
3107 first_connection
= proc_target
;
3108 else if (first_connection
!= proc_target
3109 && first_not_non_stop
!= nullptr)
3111 switch_to_inferior_no_thread (first_not_non_stop
);
3113 proc_target
= current_inferior ()->process_target();
3115 error (_("Connection %d (%s) does not support "
3116 "multi-target resumption."),
3117 proc_target
->connection_number
,
3118 make_target_connection_string (proc_target
).c_str ());
3124 /* Basic routine for continuing the program in various fashions.
3126 ADDR is the address to resume at, or -1 for resume where stopped.
3127 SIGGNAL is the signal to give it, or GDB_SIGNAL_0 for none,
3128 or GDB_SIGNAL_DEFAULT for act according to how it stopped.
3130 You should call clear_proceed_status before calling proceed. */
3133 proceed (CORE_ADDR addr
, enum gdb_signal siggnal
)
3135 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
3137 struct regcache
*regcache
;
3138 struct gdbarch
*gdbarch
;
3140 struct execution_control_state ecss
;
3141 struct execution_control_state
*ecs
= &ecss
;
3143 /* If we're stopped at a fork/vfork, follow the branch set by the
3144 "set follow-fork-mode" command; otherwise, we'll just proceed
3145 resuming the current thread. */
3146 if (!follow_fork ())
3148 /* The target for some reason decided not to resume. */
3150 if (target_can_async_p ())
3151 inferior_event_handler (INF_EXEC_COMPLETE
);
3155 /* We'll update this if & when we switch to a new thread. */
3156 previous_inferior_ptid
= inferior_ptid
;
3158 regcache
= get_current_regcache ();
3159 gdbarch
= regcache
->arch ();
3160 const address_space
*aspace
= regcache
->aspace ();
3162 pc
= regcache_read_pc_protected (regcache
);
3164 thread_info
*cur_thr
= inferior_thread ();
3166 /* Fill in with reasonable starting values. */
3167 init_thread_stepping_state (cur_thr
);
3169 gdb_assert (!thread_is_in_step_over_chain (cur_thr
));
3172 = user_visible_resume_ptid (cur_thr
->control
.stepping_command
);
3173 process_stratum_target
*resume_target
3174 = user_visible_resume_target (resume_ptid
);
3176 check_multi_target_resumption (resume_target
);
3178 if (addr
== (CORE_ADDR
) -1)
3180 if (pc
== cur_thr
->suspend
.stop_pc
3181 && breakpoint_here_p (aspace
, pc
) == ordinary_breakpoint_here
3182 && execution_direction
!= EXEC_REVERSE
)
3183 /* There is a breakpoint at the address we will resume at,
3184 step one instruction before inserting breakpoints so that
3185 we do not stop right away (and report a second hit at this
3188 Note, we don't do this in reverse, because we won't
3189 actually be executing the breakpoint insn anyway.
3190 We'll be (un-)executing the previous instruction. */
3191 cur_thr
->stepping_over_breakpoint
= 1;
3192 else if (gdbarch_single_step_through_delay_p (gdbarch
)
3193 && gdbarch_single_step_through_delay (gdbarch
,
3194 get_current_frame ()))
3195 /* We stepped onto an instruction that needs to be stepped
3196 again before re-inserting the breakpoint, do so. */
3197 cur_thr
->stepping_over_breakpoint
= 1;
3201 regcache_write_pc (regcache
, addr
);
3204 if (siggnal
!= GDB_SIGNAL_DEFAULT
)
3205 cur_thr
->suspend
.stop_signal
= siggnal
;
3207 /* If an exception is thrown from this point on, make sure to
3208 propagate GDB's knowledge of the executing state to the
3209 frontend/user running state. */
3210 scoped_finish_thread_state
finish_state (resume_target
, resume_ptid
);
3212 /* Even if RESUME_PTID is a wildcard, and we end up resuming fewer
3213 threads (e.g., we might need to set threads stepping over
3214 breakpoints first), from the user/frontend's point of view, all
3215 threads in RESUME_PTID are now running. Unless we're calling an
3216 inferior function, as in that case we pretend the inferior
3217 doesn't run at all. */
3218 if (!cur_thr
->control
.in_infcall
)
3219 set_running (resume_target
, resume_ptid
, true);
3221 infrun_debug_printf ("addr=%s, signal=%s", paddress (gdbarch
, addr
),
3222 gdb_signal_to_symbol_string (siggnal
));
3224 annotate_starting ();
3226 /* Make sure that output from GDB appears before output from the
3228 gdb_flush (gdb_stdout
);
3230 /* Since we've marked the inferior running, give it the terminal. A
3231 QUIT/Ctrl-C from here on is forwarded to the target (which can
3232 still detect attempts to unblock a stuck connection with repeated
3233 Ctrl-C from within target_pass_ctrlc). */
3234 target_terminal::inferior ();
3236 /* In a multi-threaded task we may select another thread and
3237 then continue or step.
3239 But if a thread that we're resuming had stopped at a breakpoint,
3240 it will immediately cause another breakpoint stop without any
3241 execution (i.e. it will report a breakpoint hit incorrectly). So
3242 we must step over it first.
3244 Look for threads other than the current (TP) that reported a
3245 breakpoint hit and haven't been resumed yet since. */
3247 /* If scheduler locking applies, we can avoid iterating over all
3249 if (!non_stop
&& !schedlock_applies (cur_thr
))
3251 for (thread_info
*tp
: all_non_exited_threads (resume_target
,
3254 switch_to_thread_no_regs (tp
);
3256 /* Ignore the current thread here. It's handled
3261 if (!thread_still_needs_step_over (tp
))
3264 gdb_assert (!thread_is_in_step_over_chain (tp
));
3266 infrun_debug_printf ("need to step-over [%s] first",
3267 target_pid_to_str (tp
->ptid
).c_str ());
3269 global_thread_step_over_chain_enqueue (tp
);
3272 switch_to_thread (cur_thr
);
3275 /* Enqueue the current thread last, so that we move all other
3276 threads over their breakpoints first. */
3277 if (cur_thr
->stepping_over_breakpoint
)
3278 global_thread_step_over_chain_enqueue (cur_thr
);
3280 /* If the thread isn't started, we'll still need to set its prev_pc,
3281 so that switch_back_to_stepped_thread knows the thread hasn't
3282 advanced. Must do this before resuming any thread, as in
3283 all-stop/remote, once we resume we can't send any other packet
3284 until the target stops again. */
3285 cur_thr
->prev_pc
= regcache_read_pc_protected (regcache
);
3288 scoped_disable_commit_resumed
disable_commit_resumed ("proceeding");
3290 bool displaced_step_started
= start_step_over ();
3292 if (step_over_info_valid_p ())
3294 /* Either this thread started a new in-line step over, or some
3295 other thread was already doing one. In either case, don't
3296 resume anything else until the step-over is finished. */
3298 else if (displaced_step_started
&& !target_is_non_stop_p ())
3300 /* A new displaced stepping sequence was started. In all-stop,
3301 we can't talk to the target anymore until it next stops. */
3303 else if (!non_stop
&& target_is_non_stop_p ())
3305 INFRUN_SCOPED_DEBUG_START_END
3306 ("resuming threads, all-stop-on-top-of-non-stop");
3308 /* In all-stop, but the target is always in non-stop mode.
3309 Start all other threads that are implicitly resumed too. */
3310 for (thread_info
*tp
: all_non_exited_threads (resume_target
,
3313 switch_to_thread_no_regs (tp
);
3315 if (!tp
->inf
->has_execution ())
3317 infrun_debug_printf ("[%s] target has no execution",
3318 target_pid_to_str (tp
->ptid
).c_str ());
3324 infrun_debug_printf ("[%s] resumed",
3325 target_pid_to_str (tp
->ptid
).c_str ());
3326 gdb_assert (tp
->executing
|| tp
->suspend
.waitstatus_pending_p
);
3330 if (thread_is_in_step_over_chain (tp
))
3332 infrun_debug_printf ("[%s] needs step-over",
3333 target_pid_to_str (tp
->ptid
).c_str ());
3337 if (tp
->inf
->thread_waiting_for_vfork_done
!= nullptr
3338 && tp
!= tp
->inf
->thread_waiting_for_vfork_done
)
3340 infrun_debug_printf ("[%s] a thread of this inferior is waiting for vfork-done",
3341 tp
->ptid
.to_string ().c_str ());
3345 //if (tp->inf->pending_detach)
3347 //infrun_debug_printf ("[%s] inferior pending detach",
3348 // tp->ptid.to_string ().c_str ());
3352 infrun_debug_printf ("resuming %s",
3353 target_pid_to_str (tp
->ptid
).c_str ());
3355 reset_ecs (ecs
, tp
);
3356 switch_to_thread (tp
);
3357 keep_going_pass_signal (ecs
);
3358 if (!ecs
->wait_some_more
)
3359 error (_("Command aborted."));
3362 else if (!cur_thr
->resumed
3363 && !thread_is_in_step_over_chain (cur_thr
)
3364 && !(non_stop
&& cur_thr
->inf
->thread_waiting_for_vfork_done
))
3366 /* The thread wasn't started, and isn't queued, run it now. */
3367 reset_ecs (ecs
, cur_thr
);
3368 switch_to_thread (cur_thr
);
3369 keep_going_pass_signal (ecs
);
3370 if (!ecs
->wait_some_more
)
3371 error (_("Command aborted."));
3374 disable_commit_resumed
.reset_and_commit ();
3377 finish_state
.release ();
3379 /* If we've switched threads above, switch back to the previously
3380 current thread. We don't want the user to see a different
3382 switch_to_thread (cur_thr
);
3384 /* Tell the event loop to wait for it to stop. If the target
3385 supports asynchronous execution, it'll do this from within
3387 if (!target_can_async_p ())
3388 mark_async_event_handler (infrun_async_inferior_event_token
);
3392 /* Start remote-debugging of a machine over a serial link. */
3395 start_remote (int from_tty
)
3397 inferior
*inf
= current_inferior ();
3398 inf
->control
.stop_soon
= STOP_QUIETLY_REMOTE
;
3400 /* Always go on waiting for the target, regardless of the mode. */
3401 /* FIXME: cagney/1999-09-23: At present it isn't possible to
3402 indicate to wait_for_inferior that a target should timeout if
3403 nothing is returned (instead of just blocking). Because of this,
3404 targets expecting an immediate response need to, internally, set
3405 things up so that the target_wait() is forced to eventually
3407 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
3408 differentiate to its caller what the state of the target is after
3409 the initial open has been performed. Here we're assuming that
3410 the target has stopped. It should be possible to eventually have
3411 target_open() return to the caller an indication that the target
3412 is currently running and GDB state should be set to the same as
3413 for an async run. */
3414 wait_for_inferior (inf
);
3416 /* Now that the inferior has stopped, do any bookkeeping like
3417 loading shared libraries. We want to do this before normal_stop,
3418 so that the displayed frame is up to date. */
3419 post_create_inferior (from_tty
);
3424 /* Initialize static vars when a new inferior begins. */
3427 init_wait_for_inferior (void)
3429 /* These are meaningless until the first time through wait_for_inferior. */
3431 breakpoint_init_inferior (inf_starting
);
3433 clear_proceed_status (0);
3435 nullify_last_target_wait_ptid ();
3437 previous_inferior_ptid
= inferior_ptid
;
3442 static void handle_inferior_event (struct execution_control_state
*ecs
);
3444 static void handle_step_into_function (struct gdbarch
*gdbarch
,
3445 struct execution_control_state
*ecs
);
3446 static void handle_step_into_function_backward (struct gdbarch
*gdbarch
,
3447 struct execution_control_state
*ecs
);
3448 static void handle_signal_stop (struct execution_control_state
*ecs
);
3449 static void check_exception_resume (struct execution_control_state
*,
3450 struct frame_info
*);
3452 static void end_stepping_range (struct execution_control_state
*ecs
);
3453 static void stop_waiting (struct execution_control_state
*ecs
);
3454 static void keep_going (struct execution_control_state
*ecs
);
3455 static void process_event_stop_test (struct execution_control_state
*ecs
);
3456 static bool switch_back_to_stepped_thread (struct execution_control_state
*ecs
);
3458 /* This function is attached as a "thread_stop_requested" observer.
3459 Cleanup local state that assumed the PTID was to be resumed, and
3460 report the stop to the frontend. */
3463 infrun_thread_stop_requested (ptid_t ptid
)
3465 process_stratum_target
*curr_target
= current_inferior ()->process_target ();
3467 /* PTID was requested to stop. If the thread was already stopped,
3468 but the user/frontend doesn't know about that yet (e.g., the
3469 thread had been temporarily paused for some step-over), set up
3470 for reporting the stop now. */
3471 for (thread_info
*tp
: all_threads (curr_target
, ptid
))
3473 if (tp
->state
!= THREAD_RUNNING
)
3478 /* Remove matching threads from the step-over queue, so
3479 start_step_over doesn't try to resume them
3481 if (thread_is_in_step_over_chain (tp
))
3482 global_thread_step_over_chain_remove (tp
);
3484 /* If the thread is stopped, but the user/frontend doesn't
3485 know about that yet, queue a pending event, as if the
3486 thread had just stopped now. Unless the thread already had
3488 if (!tp
->suspend
.waitstatus_pending_p
)
3490 tp
->suspend
.waitstatus_pending_p
= 1;
3491 tp
->suspend
.waitstatus
.kind
= TARGET_WAITKIND_STOPPED
;
3492 tp
->suspend
.waitstatus
.value
.sig
= GDB_SIGNAL_0
;
3495 /* Clear the inline-frame state, since we're re-processing the
3497 clear_inline_frame_state (tp
);
3499 /* If this thread was paused because some other thread was
3500 doing an inline-step over, let that finish first. Once
3501 that happens, we'll restart all threads and consume pending
3502 stop events then. */
3503 if (step_over_info_valid_p ())
3506 /* Otherwise we can process the (new) pending event now. Set
3507 it so this pending event is considered by
3514 infrun_thread_thread_exit (struct thread_info
*tp
, int silent
)
3516 if (target_last_proc_target
== tp
->inf
->process_target ()
3517 && target_last_wait_ptid
== tp
->ptid
)
3518 nullify_last_target_wait_ptid ();
3521 /* Delete the step resume, single-step and longjmp/exception resume
3522 breakpoints of TP. */
3525 delete_thread_infrun_breakpoints (struct thread_info
*tp
)
3527 delete_step_resume_breakpoint (tp
);
3528 delete_exception_resume_breakpoint (tp
);
3529 delete_single_step_breakpoints (tp
);
3532 /* If the target still has execution, call FUNC for each thread that
3533 just stopped. In all-stop, that's all the non-exited threads; in
3534 non-stop, that's the current thread, only. */
3536 typedef void (*for_each_just_stopped_thread_callback_func
)
3537 (struct thread_info
*tp
);
3540 for_each_just_stopped_thread (for_each_just_stopped_thread_callback_func func
)
3542 if (!target_has_execution () || inferior_ptid
== null_ptid
)
3545 if (target_is_non_stop_p ())
3547 /* If in non-stop mode, only the current thread stopped. */
3548 func (inferior_thread ());
3552 /* In all-stop mode, all threads have stopped. */
3553 for (thread_info
*tp
: all_non_exited_threads ())
3558 /* Delete the step resume and longjmp/exception resume breakpoints of
3559 the threads that just stopped. */
3562 delete_just_stopped_threads_infrun_breakpoints (void)
3564 for_each_just_stopped_thread (delete_thread_infrun_breakpoints
);
3567 /* Delete the single-step breakpoints of the threads that just
3571 delete_just_stopped_threads_single_step_breakpoints (void)
3573 for_each_just_stopped_thread (delete_single_step_breakpoints
);
3579 print_target_wait_results (ptid_t waiton_ptid
, ptid_t result_ptid
,
3580 const struct target_waitstatus
*ws
)
3582 infrun_debug_printf ("target_wait (%d.%ld.%ld [%s], status) =",
3586 target_pid_to_str (waiton_ptid
).c_str ());
3587 infrun_debug_printf (" %d.%ld.%ld [%s],",
3591 target_pid_to_str (result_ptid
).c_str ());
3592 infrun_debug_printf (" %s", target_waitstatus_to_string (ws
).c_str ());
3595 /* Select a thread at random, out of those which are resumed and have
3598 static struct thread_info
*
3599 random_pending_event_thread (inferior
*inf
, ptid_t waiton_ptid
)
3603 auto has_event
= [&] (thread_info
*tp
)
3605 return (tp
->ptid
.matches (waiton_ptid
)
3607 && tp
->suspend
.waitstatus_pending_p
);
3610 /* First see how many events we have. Count only resumed threads
3611 that have an event pending. */
3612 for (thread_info
*tp
: inf
->non_exited_threads ())
3616 if (num_events
== 0)
3619 /* Now randomly pick a thread out of those that have had events. */
3620 int random_selector
= (int) ((num_events
* (double) rand ())
3621 / (RAND_MAX
+ 1.0));
3624 infrun_debug_printf ("Found %d events, selecting #%d",
3625 num_events
, random_selector
);
3627 /* Select the Nth thread that has had an event. */
3628 for (thread_info
*tp
: inf
->non_exited_threads ())
3630 if (random_selector
-- == 0)
3633 gdb_assert_not_reached ("event thread not found");
3636 /* Wrapper for target_wait that first checks whether threads have
3637 pending statuses to report before actually asking the target for
3638 more events. INF is the inferior we're using to call target_wait
3642 do_target_wait_1 (inferior
*inf
, ptid_t ptid
,
3643 target_waitstatus
*status
, target_wait_flags options
)
3646 struct thread_info
*tp
;
3648 /* We know that we are looking for an event in the target of inferior
3649 INF, but we don't know which thread the event might come from. As
3650 such we want to make sure that INFERIOR_PTID is reset so that none of
3651 the wait code relies on it - doing so is always a mistake. */
3652 switch_to_inferior_no_thread (inf
);
3654 /* First check if there is a resumed thread with a wait status
3656 if (ptid
== minus_one_ptid
|| ptid
.is_pid ())
3658 tp
= random_pending_event_thread (inf
, ptid
);
3662 infrun_debug_printf ("Waiting for specific thread %s.",
3663 target_pid_to_str (ptid
).c_str ());
3665 /* We have a specific thread to check. */
3666 tp
= find_thread_ptid (inf
, ptid
);
3667 gdb_assert (tp
!= NULL
);
3668 if (!tp
->suspend
.waitstatus_pending_p
)
3673 && (tp
->suspend
.stop_reason
== TARGET_STOPPED_BY_SW_BREAKPOINT
3674 || tp
->suspend
.stop_reason
== TARGET_STOPPED_BY_HW_BREAKPOINT
))
3676 struct regcache
*regcache
= get_thread_regcache (tp
);
3677 struct gdbarch
*gdbarch
= regcache
->arch ();
3681 pc
= regcache_read_pc (regcache
);
3683 if (pc
!= tp
->suspend
.stop_pc
)
3685 infrun_debug_printf ("PC of %s changed. was=%s, now=%s",
3686 target_pid_to_str (tp
->ptid
).c_str (),
3687 paddress (gdbarch
, tp
->suspend
.stop_pc
),
3688 paddress (gdbarch
, pc
));
3691 else if (!breakpoint_inserted_here_p (regcache
->aspace (), pc
))
3693 infrun_debug_printf ("previous breakpoint of %s, at %s gone",
3694 target_pid_to_str (tp
->ptid
).c_str (),
3695 paddress (gdbarch
, pc
));
3702 infrun_debug_printf ("pending event of %s cancelled.",
3703 target_pid_to_str (tp
->ptid
).c_str ());
3705 tp
->suspend
.waitstatus
.kind
= TARGET_WAITKIND_SPURIOUS
;
3706 tp
->suspend
.stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
3712 infrun_debug_printf ("Using pending wait status %s for %s.",
3713 target_waitstatus_to_string
3714 (&tp
->suspend
.waitstatus
).c_str (),
3715 target_pid_to_str (tp
->ptid
).c_str ());
3717 /* Now that we've selected our final event LWP, un-adjust its PC
3718 if it was a software breakpoint (and the target doesn't
3719 always adjust the PC itself). */
3720 if (tp
->suspend
.stop_reason
== TARGET_STOPPED_BY_SW_BREAKPOINT
3721 && !target_supports_stopped_by_sw_breakpoint ())
3723 struct regcache
*regcache
;
3724 struct gdbarch
*gdbarch
;
3727 regcache
= get_thread_regcache (tp
);
3728 gdbarch
= regcache
->arch ();
3730 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
3735 pc
= regcache_read_pc (regcache
);
3736 regcache_write_pc (regcache
, pc
+ decr_pc
);
3740 tp
->suspend
.stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
3741 *status
= tp
->suspend
.waitstatus
;
3742 tp
->suspend
.waitstatus_pending_p
= 0;
3744 /* Wake up the event loop again, until all pending events are
3746 if (target_is_async_p ())
3747 mark_async_event_handler (infrun_async_inferior_event_token
);
3751 /* But if we don't find one, we'll have to wait. */
3753 /* We can't ask a non-async target to do a non-blocking wait, so this will be
3755 if (!target_can_async_p ())
3756 options
&= ~TARGET_WNOHANG
;
3758 if (deprecated_target_wait_hook
)
3759 event_ptid
= deprecated_target_wait_hook (ptid
, status
, options
);
3761 event_ptid
= target_wait (ptid
, status
, options
);
3766 /* Wrapper for target_wait that first checks whether threads have
3767 pending statuses to report before actually asking the target for
3768 more events. Polls for events from all inferiors/targets. */
3771 do_target_wait (execution_control_state
*ecs
, target_wait_flags options
)
3773 int num_inferiors
= 0;
3774 int random_selector
;
3776 /* For fairness, we pick the first inferior/target to poll at random
3777 out of all inferiors that may report events, and then continue
3778 polling the rest of the inferior list starting from that one in a
3779 circular fashion until the whole list is polled once. */
3781 auto inferior_matches
= [] (inferior
*inf
)
3783 return inf
->process_target () != nullptr;
3786 /* First see how many matching inferiors we have. */
3787 for (inferior
*inf
: all_inferiors ())
3788 if (inferior_matches (inf
))
3791 if (num_inferiors
== 0)
3793 ecs
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
3797 /* Now randomly pick an inferior out of those that matched. */
3798 random_selector
= (int)
3799 ((num_inferiors
* (double) rand ()) / (RAND_MAX
+ 1.0));
3801 if (num_inferiors
> 1)
3802 infrun_debug_printf ("Found %d inferiors, starting at #%d",
3803 num_inferiors
, random_selector
);
3805 /* Select the Nth inferior that matched. */
3807 inferior
*selected
= nullptr;
3809 for (inferior
*inf
: all_inferiors ())
3810 if (inferior_matches (inf
))
3811 if (random_selector
-- == 0)
3817 /* Now poll for events out of each of the matching inferior's
3818 targets, starting from the selected one. */
3820 auto do_wait
= [&] (inferior
*inf
)
3822 ecs
->ptid
= do_target_wait_1 (inf
, minus_one_ptid
, &ecs
->ws
, options
);
3823 ecs
->target
= inf
->process_target ();
3824 return (ecs
->ws
.kind
!= TARGET_WAITKIND_IGNORE
);
3827 /* Needed in 'all-stop + target-non-stop' mode, because we end up
3828 here spuriously after the target is all stopped and we've already
3829 reported the stop to the user, polling for events. */
3830 scoped_restore_current_thread restore_thread
;
3832 int inf_num
= selected
->num
;
3833 for (inferior
*inf
= selected
; inf
!= NULL
; inf
= inf
->next
)
3834 if (inferior_matches (inf
))
3838 for (inferior
*inf
= inferior_list
;
3839 inf
!= NULL
&& inf
->num
< inf_num
;
3841 if (inferior_matches (inf
))
3845 ecs
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
3849 /* An event reported by wait_one. */
3851 struct wait_one_event
3853 /* The target the event came out of. */
3854 process_stratum_target
*target
;
3856 /* The PTID the event was for. */
3859 /* The waitstatus. */
3860 target_waitstatus ws
;
3863 static bool handle_one (const wait_one_event
&event
);
3865 /* Prepare and stabilize the inferior for detaching it. E.g.,
3866 detaching while a thread is displaced stepping is a recipe for
3867 crashing it, as nothing would readjust the PC out of the scratch
3871 prepare_for_detach (void)
3873 struct inferior
*inf
= current_inferior ();
3874 ptid_t pid_ptid
= ptid_t (inf
->pid
);
3875 scoped_restore_current_thread restore_thread
;
3877 scoped_restore restore_detaching
= make_scoped_restore (&inf
->detaching
, true);
3879 /* Remove all threads of INF from the global step-over chain. We
3880 want to stop any ongoing step-over, not start any new one. */
3882 for (thread_info
*tp
= global_thread_step_over_chain_head
;
3886 next
= global_thread_step_over_chain_next (tp
);
3888 global_thread_step_over_chain_remove (tp
);
3891 /* If we were already in the middle of an inline step-over, and the
3892 thread stepping belongs to the inferior we're detaching, we need
3893 to restart the threads of other inferiors. */
3894 if (step_over_info
.thread
!= -1)
3896 infrun_debug_printf ("inline step-over in-process while detaching");
3898 thread_info
*thr
= find_thread_global_id (step_over_info
.thread
);
3899 if (thr
->inf
== inf
)
3901 /* Since we removed threads of INF from the step-over chain,
3902 we know this won't start a step-over for INF. */
3903 clear_step_over_info ();
3905 if (target_is_non_stop_p ())
3907 /* Start a new step-over in another thread if there's
3908 one that needs it. */
3911 /* Restart all other threads (except the
3912 previously-stepping thread, since that one is still
3914 if (!step_over_info_valid_p ())
3915 restart_threads (thr
, nullptr);
3920 if (displaced_step_in_progress (inf
))
3922 infrun_debug_printf ("displaced-stepping in-process while detaching");
3924 /* Stop threads currently displaced stepping, aborting it. */
3926 for (thread_info
*thr
: inf
->non_exited_threads ())
3928 if (thr
->displaced_step_state
.in_progress ())
3932 if (!thr
->stop_requested
)
3934 target_stop (thr
->ptid
);
3935 thr
->stop_requested
= true;
3939 thr
->resumed
= false;
3943 while (displaced_step_in_progress (inf
))
3945 wait_one_event event
;
3947 event
.target
= inf
->process_target ();
3948 event
.ptid
= do_target_wait_1 (inf
, pid_ptid
, &event
.ws
, 0);
3951 print_target_wait_results (pid_ptid
, event
.ptid
, &event
.ws
);
3956 /* It's OK to leave some of the threads of INF stopped, since
3957 they'll be detached shortly. */
3961 /* Wait for control to return from inferior to debugger.
3963 If inferior gets a signal, we may decide to start it up again
3964 instead of returning. That is why there is a loop in this function.
3965 When this function actually returns it means the inferior
3966 should be left stopped and GDB should read more commands. */
3969 wait_for_inferior (inferior
*inf
)
3971 infrun_debug_printf ("wait_for_inferior ()");
3973 SCOPE_EXIT
{ delete_just_stopped_threads_infrun_breakpoints (); };
3975 /* If an error happens while handling the event, propagate GDB's
3976 knowledge of the executing state to the frontend/user running
3978 scoped_finish_thread_state finish_state
3979 (inf
->process_target (), minus_one_ptid
);
3983 struct execution_control_state ecss
;
3984 struct execution_control_state
*ecs
= &ecss
;
3986 memset (ecs
, 0, sizeof (*ecs
));
3988 overlay_cache_invalid
= 1;
3990 /* Flush target cache before starting to handle each event.
3991 Target was running and cache could be stale. This is just a
3992 heuristic. Running threads may modify target memory, but we
3993 don't get any event. */
3994 target_dcache_invalidate ();
3996 ecs
->ptid
= do_target_wait_1 (inf
, minus_one_ptid
, &ecs
->ws
, 0);
3997 ecs
->target
= inf
->process_target ();
4000 print_target_wait_results (minus_one_ptid
, ecs
->ptid
, &ecs
->ws
);
4002 /* Now figure out what to do with the result of the result. */
4003 handle_inferior_event (ecs
);
4005 if (!ecs
->wait_some_more
)
4009 /* No error, don't finish the state yet. */
4010 finish_state
.release ();
4013 /* Cleanup that reinstalls the readline callback handler, if the
4014 target is running in the background. If while handling the target
4015 event something triggered a secondary prompt, like e.g., a
4016 pagination prompt, we'll have removed the callback handler (see
4017 gdb_readline_wrapper_line). Need to do this as we go back to the
4018 event loop, ready to process further input. Note this has no
4019 effect if the handler hasn't actually been removed, because calling
4020 rl_callback_handler_install resets the line buffer, thus losing
4024 reinstall_readline_callback_handler_cleanup ()
4026 struct ui
*ui
= current_ui
;
4030 /* We're not going back to the top level event loop yet. Don't
4031 install the readline callback, as it'd prep the terminal,
4032 readline-style (raw, noecho) (e.g., --batch). We'll install
4033 it the next time the prompt is displayed, when we're ready
4038 if (ui
->command_editing
&& ui
->prompt_state
!= PROMPT_BLOCKED
)
4039 gdb_rl_callback_handler_reinstall ();
4042 /* Clean up the FSMs of threads that are now stopped. In non-stop,
4043 that's just the event thread. In all-stop, that's all threads. */
4046 clean_up_just_stopped_threads_fsms (struct execution_control_state
*ecs
)
4048 if (ecs
->event_thread
!= NULL
4049 && ecs
->event_thread
->thread_fsm
!= NULL
)
4050 ecs
->event_thread
->thread_fsm
->clean_up (ecs
->event_thread
);
4054 for (thread_info
*thr
: all_non_exited_threads ())
4056 if (thr
->thread_fsm
== NULL
)
4058 if (thr
== ecs
->event_thread
)
4061 switch_to_thread (thr
);
4062 thr
->thread_fsm
->clean_up (thr
);
4065 if (ecs
->event_thread
!= NULL
)
4066 switch_to_thread (ecs
->event_thread
);
4070 /* Helper for all_uis_check_sync_execution_done that works on the
4074 check_curr_ui_sync_execution_done (void)
4076 struct ui
*ui
= current_ui
;
4078 if (ui
->prompt_state
== PROMPT_NEEDED
4080 && !gdb_in_secondary_prompt_p (ui
))
4082 target_terminal::ours ();
4083 gdb::observers::sync_execution_done
.notify ();
4084 ui_register_input_event_handler (ui
);
4091 all_uis_check_sync_execution_done (void)
4093 SWITCH_THRU_ALL_UIS ()
4095 check_curr_ui_sync_execution_done ();
4102 all_uis_on_sync_execution_starting (void)
4104 SWITCH_THRU_ALL_UIS ()
4106 if (current_ui
->prompt_state
== PROMPT_NEEDED
)
4107 async_disable_stdin ();
4111 /* Asynchronous version of wait_for_inferior. It is called by the
4112 event loop whenever a change of state is detected on the file
4113 descriptor corresponding to the target. It can be called more than
4114 once to complete a single execution command. In such cases we need
4115 to keep the state in a global variable ECSS. If it is the last time
4116 that this function is called for a single execution command, then
4117 report to the user that the inferior has stopped, and do the
4118 necessary cleanups. */
4121 fetch_inferior_event ()
4123 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
4125 struct execution_control_state ecss
;
4126 struct execution_control_state
*ecs
= &ecss
;
4129 memset (ecs
, 0, sizeof (*ecs
));
4131 /* Events are always processed with the main UI as current UI. This
4132 way, warnings, debug output, etc. are always consistently sent to
4133 the main console. */
4134 scoped_restore save_ui
= make_scoped_restore (¤t_ui
, main_ui
);
4136 /* Temporarily disable pagination. Otherwise, the user would be
4137 given an option to press 'q' to quit, which would cause an early
4138 exit and could leave GDB in a half-baked state. */
4139 scoped_restore save_pagination
4140 = make_scoped_restore (&pagination_enabled
, false);
4142 /* End up with readline processing input, if necessary. */
4144 SCOPE_EXIT
{ reinstall_readline_callback_handler_cleanup (); };
4146 /* We're handling a live event, so make sure we're doing live
4147 debugging. If we're looking at traceframes while the target is
4148 running, we're going to need to get back to that mode after
4149 handling the event. */
4150 gdb::optional
<scoped_restore_current_traceframe
> maybe_restore_traceframe
;
4153 maybe_restore_traceframe
.emplace ();
4154 set_current_traceframe (-1);
4157 /* The user/frontend should not notice a thread switch due to
4158 internal events. Make sure we revert to the user selected
4159 thread and frame after handling the event and running any
4160 breakpoint commands. */
4161 scoped_restore_current_thread restore_thread
;
4163 overlay_cache_invalid
= 1;
4164 /* Flush target cache before starting to handle each event. Target
4165 was running and cache could be stale. This is just a heuristic.
4166 Running threads may modify target memory, but we don't get any
4168 target_dcache_invalidate ();
4170 scoped_restore save_exec_dir
4171 = make_scoped_restore (&execution_direction
,
4172 target_execution_direction ());
4174 /* Allow targets to pause their resumed threads while we handle
4176 scoped_disable_commit_resumed
disable_commit_resumed ("handling event");
4178 if (!do_target_wait (ecs
, TARGET_WNOHANG
))
4180 infrun_debug_printf ("do_target_wait returned no event");
4181 disable_commit_resumed
.reset_and_commit ();
4185 gdb_assert (ecs
->ws
.kind
!= TARGET_WAITKIND_IGNORE
);
4187 /* Switch to the target that generated the event, so we can do
4189 switch_to_target_no_thread (ecs
->target
);
4192 print_target_wait_results (minus_one_ptid
, ecs
->ptid
, &ecs
->ws
);
4194 /* If an error happens while handling the event, propagate GDB's
4195 knowledge of the executing state to the frontend/user running
4197 ptid_t finish_ptid
= !target_is_non_stop_p () ? minus_one_ptid
: ecs
->ptid
;
4198 scoped_finish_thread_state
finish_state (ecs
->target
, finish_ptid
);
4200 /* Get executed before scoped_restore_current_thread above to apply
4201 still for the thread which has thrown the exception. */
4202 auto defer_bpstat_clear
4203 = make_scope_exit (bpstat_clear_actions
);
4204 auto defer_delete_threads
4205 = make_scope_exit (delete_just_stopped_threads_infrun_breakpoints
);
4207 /* Now figure out what to do with the result of the result. */
4208 handle_inferior_event (ecs
);
4210 if (!ecs
->wait_some_more
)
4212 struct inferior
*inf
= find_inferior_ptid (ecs
->target
, ecs
->ptid
);
4213 bool should_stop
= true;
4214 struct thread_info
*thr
= ecs
->event_thread
;
4216 delete_just_stopped_threads_infrun_breakpoints ();
4220 struct thread_fsm
*thread_fsm
= thr
->thread_fsm
;
4222 if (thread_fsm
!= NULL
)
4223 should_stop
= thread_fsm
->should_stop (thr
);
4232 bool should_notify_stop
= true;
4235 clean_up_just_stopped_threads_fsms (ecs
);
4237 if (thr
!= NULL
&& thr
->thread_fsm
!= NULL
)
4238 should_notify_stop
= thr
->thread_fsm
->should_notify_stop ();
4240 if (should_notify_stop
)
4242 /* We may not find an inferior if this was a process exit. */
4243 if (inf
== NULL
|| inf
->control
.stop_soon
== NO_STOP_QUIETLY
)
4244 proceeded
= normal_stop ();
4249 inferior_event_handler (INF_EXEC_COMPLETE
);
4253 /* If we got a TARGET_WAITKIND_NO_RESUMED event, then the
4254 previously selected thread is gone. We have two
4255 choices - switch to no thread selected, or restore the
4256 previously selected thread (now exited). We chose the
4257 later, just because that's what GDB used to do. After
4258 this, "info threads" says "The current thread <Thread
4259 ID 2> has terminated." instead of "No thread
4263 && ecs
->ws
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
4264 restore_thread
.dont_restore ();
4268 defer_delete_threads
.release ();
4269 defer_bpstat_clear
.release ();
4271 /* No error, don't finish the thread states yet. */
4272 finish_state
.release ();
4274 disable_commit_resumed
.reset_and_commit ();
4276 /* This scope is used to ensure that readline callbacks are
4277 reinstalled here. */
4280 /* If a UI was in sync execution mode, and now isn't, restore its
4281 prompt (a synchronous execution command has finished, and we're
4282 ready for input). */
4283 all_uis_check_sync_execution_done ();
4286 && exec_done_display_p
4287 && (inferior_ptid
== null_ptid
4288 || inferior_thread ()->state
!= THREAD_RUNNING
))
4289 printf_unfiltered (_("completed.\n"));
4295 set_step_info (thread_info
*tp
, struct frame_info
*frame
,
4296 struct symtab_and_line sal
)
4298 /* This can be removed once this function no longer implicitly relies on the
4299 inferior_ptid value. */
4300 gdb_assert (inferior_ptid
== tp
->ptid
);
4302 tp
->control
.step_frame_id
= get_frame_id (frame
);
4303 tp
->control
.step_stack_frame_id
= get_stack_frame_id (frame
);
4305 tp
->current_symtab
= sal
.symtab
;
4306 tp
->current_line
= sal
.line
;
4309 /* Clear context switchable stepping state. */
4312 init_thread_stepping_state (struct thread_info
*tss
)
4314 tss
->stepped_breakpoint
= 0;
4315 tss
->stepping_over_breakpoint
= 0;
4316 tss
->stepping_over_watchpoint
= 0;
4317 tss
->step_after_step_resume_breakpoint
= 0;
4323 set_last_target_status (process_stratum_target
*target
, ptid_t ptid
,
4324 target_waitstatus status
)
4326 target_last_proc_target
= target
;
4327 target_last_wait_ptid
= ptid
;
4328 target_last_waitstatus
= status
;
4334 get_last_target_status (process_stratum_target
**target
, ptid_t
*ptid
,
4335 target_waitstatus
*status
)
4337 if (target
!= nullptr)
4338 *target
= target_last_proc_target
;
4339 if (ptid
!= nullptr)
4340 *ptid
= target_last_wait_ptid
;
4341 if (status
!= nullptr)
4342 *status
= target_last_waitstatus
;
4348 nullify_last_target_wait_ptid (void)
4350 target_last_proc_target
= nullptr;
4351 target_last_wait_ptid
= minus_one_ptid
;
4352 target_last_waitstatus
= {};
4355 /* Switch thread contexts. */
4358 context_switch (execution_control_state
*ecs
)
4360 if (ecs
->ptid
!= inferior_ptid
4361 && (inferior_ptid
== null_ptid
4362 || ecs
->event_thread
!= inferior_thread ()))
4364 infrun_debug_printf ("Switching context from %s to %s",
4365 target_pid_to_str (inferior_ptid
).c_str (),
4366 target_pid_to_str (ecs
->ptid
).c_str ());
4369 switch_to_thread (ecs
->event_thread
);
4372 /* If the target can't tell whether we've hit breakpoints
4373 (target_supports_stopped_by_sw_breakpoint), and we got a SIGTRAP,
4374 check whether that could have been caused by a breakpoint. If so,
4375 adjust the PC, per gdbarch_decr_pc_after_break. */
4378 adjust_pc_after_break (struct thread_info
*thread
,
4379 struct target_waitstatus
*ws
)
4381 struct regcache
*regcache
;
4382 struct gdbarch
*gdbarch
;
4383 CORE_ADDR breakpoint_pc
, decr_pc
;
4385 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
4386 we aren't, just return.
4388 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
4389 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
4390 implemented by software breakpoints should be handled through the normal
4393 NOTE drow/2004-01-31: On some targets, breakpoints may generate
4394 different signals (SIGILL or SIGEMT for instance), but it is less
4395 clear where the PC is pointing afterwards. It may not match
4396 gdbarch_decr_pc_after_break. I don't know any specific target that
4397 generates these signals at breakpoints (the code has been in GDB since at
4398 least 1992) so I can not guess how to handle them here.
4400 In earlier versions of GDB, a target with
4401 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
4402 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
4403 target with both of these set in GDB history, and it seems unlikely to be
4404 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
4406 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
)
4409 if (ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
4412 /* In reverse execution, when a breakpoint is hit, the instruction
4413 under it has already been de-executed. The reported PC always
4414 points at the breakpoint address, so adjusting it further would
4415 be wrong. E.g., consider this case on a decr_pc_after_break == 1
4418 B1 0x08000000 : INSN1
4419 B2 0x08000001 : INSN2
4421 PC -> 0x08000003 : INSN4
4423 Say you're stopped at 0x08000003 as above. Reverse continuing
4424 from that point should hit B2 as below. Reading the PC when the
4425 SIGTRAP is reported should read 0x08000001 and INSN2 should have
4426 been de-executed already.
4428 B1 0x08000000 : INSN1
4429 B2 PC -> 0x08000001 : INSN2
4433 We can't apply the same logic as for forward execution, because
4434 we would wrongly adjust the PC to 0x08000000, since there's a
4435 breakpoint at PC - 1. We'd then report a hit on B1, although
4436 INSN1 hadn't been de-executed yet. Doing nothing is the correct
4438 if (execution_direction
== EXEC_REVERSE
)
4441 /* If the target can tell whether the thread hit a SW breakpoint,
4442 trust it. Targets that can tell also adjust the PC
4444 if (target_supports_stopped_by_sw_breakpoint ())
4447 /* Note that relying on whether a breakpoint is planted in memory to
4448 determine this can fail. E.g,. the breakpoint could have been
4449 removed since. Or the thread could have been told to step an
4450 instruction the size of a breakpoint instruction, and only
4451 _after_ was a breakpoint inserted at its address. */
4453 /* If this target does not decrement the PC after breakpoints, then
4454 we have nothing to do. */
4455 regcache
= get_thread_regcache (thread
);
4456 gdbarch
= regcache
->arch ();
4458 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
4462 const address_space
*aspace
= regcache
->aspace ();
4464 /* Find the location where (if we've hit a breakpoint) the
4465 breakpoint would be. */
4466 breakpoint_pc
= regcache_read_pc (regcache
) - decr_pc
;
4468 /* If the target can't tell whether a software breakpoint triggered,
4469 fallback to figuring it out based on breakpoints we think were
4470 inserted in the target, and on whether the thread was stepped or
4473 /* Check whether there actually is a software breakpoint inserted at
4476 If in non-stop mode, a race condition is possible where we've
4477 removed a breakpoint, but stop events for that breakpoint were
4478 already queued and arrive later. To suppress those spurious
4479 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
4480 and retire them after a number of stop events are reported. Note
4481 this is an heuristic and can thus get confused. The real fix is
4482 to get the "stopped by SW BP and needs adjustment" info out of
4483 the target/kernel (and thus never reach here; see above). */
4484 if (software_breakpoint_inserted_here_p (aspace
, breakpoint_pc
)
4485 || (target_is_non_stop_p ()
4486 && moribund_breakpoint_here_p (aspace
, breakpoint_pc
)))
4488 gdb::optional
<scoped_restore_tmpl
<int>> restore_operation_disable
;
4490 if (record_full_is_used ())
4491 restore_operation_disable
.emplace
4492 (record_full_gdb_operation_disable_set ());
4494 /* When using hardware single-step, a SIGTRAP is reported for both
4495 a completed single-step and a software breakpoint. Need to
4496 differentiate between the two, as the latter needs adjusting
4497 but the former does not.
4499 The SIGTRAP can be due to a completed hardware single-step only if
4500 - we didn't insert software single-step breakpoints
4501 - this thread is currently being stepped
4503 If any of these events did not occur, we must have stopped due
4504 to hitting a software breakpoint, and have to back up to the
4507 As a special case, we could have hardware single-stepped a
4508 software breakpoint. In this case (prev_pc == breakpoint_pc),
4509 we also need to back up to the breakpoint address. */
4511 if (thread_has_single_step_breakpoints_set (thread
)
4512 || !currently_stepping (thread
)
4513 || (thread
->stepped_breakpoint
4514 && thread
->prev_pc
== breakpoint_pc
))
4515 regcache_write_pc (regcache
, breakpoint_pc
);
4520 stepped_in_from (struct frame_info
*frame
, struct frame_id step_frame_id
)
4522 for (frame
= get_prev_frame (frame
);
4524 frame
= get_prev_frame (frame
))
4526 if (frame_id_eq (get_frame_id (frame
), step_frame_id
))
4529 if (get_frame_type (frame
) != INLINE_FRAME
)
4536 /* Look for an inline frame that is marked for skip.
4537 If PREV_FRAME is TRUE start at the previous frame,
4538 otherwise start at the current frame. Stop at the
4539 first non-inline frame, or at the frame where the
4543 inline_frame_is_marked_for_skip (bool prev_frame
, struct thread_info
*tp
)
4545 struct frame_info
*frame
= get_current_frame ();
4548 frame
= get_prev_frame (frame
);
4550 for (; frame
!= NULL
; frame
= get_prev_frame (frame
))
4552 const char *fn
= NULL
;
4553 symtab_and_line sal
;
4556 if (frame_id_eq (get_frame_id (frame
), tp
->control
.step_frame_id
))
4558 if (get_frame_type (frame
) != INLINE_FRAME
)
4561 sal
= find_frame_sal (frame
);
4562 sym
= get_frame_function (frame
);
4565 fn
= sym
->print_name ();
4568 && function_name_is_marked_for_skip (fn
, sal
))
4575 /* If the event thread has the stop requested flag set, pretend it
4576 stopped for a GDB_SIGNAL_0 (i.e., as if it stopped due to
4580 handle_stop_requested (struct execution_control_state
*ecs
)
4582 if (ecs
->event_thread
->stop_requested
)
4584 ecs
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
4585 ecs
->ws
.value
.sig
= GDB_SIGNAL_0
;
4586 handle_signal_stop (ecs
);
4592 /* Auxiliary function that handles syscall entry/return events.
4593 It returns true if the inferior should keep going (and GDB
4594 should ignore the event), or false if the event deserves to be
4598 handle_syscall_event (struct execution_control_state
*ecs
)
4600 struct regcache
*regcache
;
4603 context_switch (ecs
);
4605 regcache
= get_thread_regcache (ecs
->event_thread
);
4606 syscall_number
= ecs
->ws
.value
.syscall_number
;
4607 ecs
->event_thread
->suspend
.stop_pc
= regcache_read_pc (regcache
);
4609 if (catch_syscall_enabled () > 0
4610 && catching_syscall_number (syscall_number
) > 0)
4612 infrun_debug_printf ("syscall number=%d", syscall_number
);
4614 ecs
->event_thread
->control
.stop_bpstat
4615 = bpstat_stop_status (regcache
->aspace (),
4616 ecs
->event_thread
->suspend
.stop_pc
,
4617 ecs
->event_thread
, &ecs
->ws
);
4619 if (handle_stop_requested (ecs
))
4622 if (bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
4624 /* Catchpoint hit. */
4629 if (handle_stop_requested (ecs
))
4632 /* If no catchpoint triggered for this, then keep going. */
4638 /* Lazily fill in the execution_control_state's stop_func_* fields. */
4641 fill_in_stop_func (struct gdbarch
*gdbarch
,
4642 struct execution_control_state
*ecs
)
4644 if (!ecs
->stop_func_filled_in
)
4647 const general_symbol_info
*gsi
;
4649 /* Don't care about return value; stop_func_start and stop_func_name
4650 will both be 0 if it doesn't work. */
4651 find_pc_partial_function_sym (ecs
->event_thread
->suspend
.stop_pc
,
4653 &ecs
->stop_func_start
,
4654 &ecs
->stop_func_end
,
4656 ecs
->stop_func_name
= gsi
== nullptr ? nullptr : gsi
->print_name ();
4658 /* The call to find_pc_partial_function, above, will set
4659 stop_func_start and stop_func_end to the start and end
4660 of the range containing the stop pc. If this range
4661 contains the entry pc for the block (which is always the
4662 case for contiguous blocks), advance stop_func_start past
4663 the function's start offset and entrypoint. Note that
4664 stop_func_start is NOT advanced when in a range of a
4665 non-contiguous block that does not contain the entry pc. */
4666 if (block
!= nullptr
4667 && ecs
->stop_func_start
<= BLOCK_ENTRY_PC (block
)
4668 && BLOCK_ENTRY_PC (block
) < ecs
->stop_func_end
)
4670 ecs
->stop_func_start
4671 += gdbarch_deprecated_function_start_offset (gdbarch
);
4673 if (gdbarch_skip_entrypoint_p (gdbarch
))
4674 ecs
->stop_func_start
4675 = gdbarch_skip_entrypoint (gdbarch
, ecs
->stop_func_start
);
4678 ecs
->stop_func_filled_in
= 1;
4683 /* Return the STOP_SOON field of the inferior pointed at by ECS. */
4685 static enum stop_kind
4686 get_inferior_stop_soon (execution_control_state
*ecs
)
4688 struct inferior
*inf
= find_inferior_ptid (ecs
->target
, ecs
->ptid
);
4690 gdb_assert (inf
!= NULL
);
4691 return inf
->control
.stop_soon
;
4694 /* Poll for one event out of the current target. Store the resulting
4695 waitstatus in WS, and return the event ptid. Does not block. */
4698 poll_one_curr_target (struct target_waitstatus
*ws
)
4702 overlay_cache_invalid
= 1;
4704 /* Flush target cache before starting to handle each event.
4705 Target was running and cache could be stale. This is just a
4706 heuristic. Running threads may modify target memory, but we
4707 don't get any event. */
4708 target_dcache_invalidate ();
4710 if (deprecated_target_wait_hook
)
4711 event_ptid
= deprecated_target_wait_hook (minus_one_ptid
, ws
, TARGET_WNOHANG
);
4713 event_ptid
= target_wait (minus_one_ptid
, ws
, TARGET_WNOHANG
);
4716 print_target_wait_results (minus_one_ptid
, event_ptid
, ws
);
4721 /* Wait for one event out of any target. */
4723 static wait_one_event
4728 for (inferior
*inf
: all_inferiors ())
4730 process_stratum_target
*target
= inf
->process_target ();
4732 || !target
->is_async_p ()
4733 || !target
->threads_executing
)
4736 switch_to_inferior_no_thread (inf
);
4738 wait_one_event event
;
4739 event
.target
= target
;
4740 event
.ptid
= poll_one_curr_target (&event
.ws
);
4742 if (event
.ws
.kind
== TARGET_WAITKIND_NO_RESUMED
)
4744 /* If nothing is resumed, remove the target from the
4748 else if (event
.ws
.kind
!= TARGET_WAITKIND_IGNORE
)
4752 /* Block waiting for some 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 int fd
= target
->async_wait_fd ();
4768 FD_SET (fd
, &readfds
);
4775 /* No waitable targets left. All must be stopped. */
4776 return {NULL
, minus_one_ptid
, {TARGET_WAITKIND_NO_RESUMED
}};
4781 int numfds
= interruptible_select (nfds
, &readfds
, 0, NULL
, 0);
4787 perror_with_name ("interruptible_select");
4792 /* Save the thread's event and stop reason to process it later. */
4795 save_waitstatus (struct thread_info
*tp
, const target_waitstatus
*ws
)
4797 infrun_debug_printf ("saving status %s for %d.%ld.%ld",
4798 target_waitstatus_to_string (ws
).c_str (),
4803 /* Record for later. */
4804 tp
->suspend
.waitstatus
= *ws
;
4805 tp
->suspend
.waitstatus_pending_p
= 1;
4807 if (ws
->kind
== TARGET_WAITKIND_STOPPED
4808 && ws
->value
.sig
== GDB_SIGNAL_TRAP
)
4810 struct regcache
*regcache
= get_thread_regcache (tp
);
4811 const address_space
*aspace
= regcache
->aspace ();
4812 CORE_ADDR pc
= regcache_read_pc (regcache
);
4814 adjust_pc_after_break (tp
, &tp
->suspend
.waitstatus
);
4816 scoped_restore_current_thread restore_thread
;
4817 switch_to_thread (tp
);
4819 if (target_stopped_by_watchpoint ())
4821 tp
->suspend
.stop_reason
4822 = TARGET_STOPPED_BY_WATCHPOINT
;
4824 else if (target_supports_stopped_by_sw_breakpoint ()
4825 && target_stopped_by_sw_breakpoint ())
4827 tp
->suspend
.stop_reason
4828 = TARGET_STOPPED_BY_SW_BREAKPOINT
;
4830 else if (target_supports_stopped_by_hw_breakpoint ()
4831 && target_stopped_by_hw_breakpoint ())
4833 tp
->suspend
.stop_reason
4834 = TARGET_STOPPED_BY_HW_BREAKPOINT
;
4836 else if (!target_supports_stopped_by_hw_breakpoint ()
4837 && hardware_breakpoint_inserted_here_p (aspace
,
4840 tp
->suspend
.stop_reason
4841 = TARGET_STOPPED_BY_HW_BREAKPOINT
;
4843 else if (!target_supports_stopped_by_sw_breakpoint ()
4844 && software_breakpoint_inserted_here_p (aspace
,
4847 tp
->suspend
.stop_reason
4848 = TARGET_STOPPED_BY_SW_BREAKPOINT
;
4850 else if (!thread_has_single_step_breakpoints_set (tp
)
4851 && currently_stepping (tp
))
4853 tp
->suspend
.stop_reason
4854 = TARGET_STOPPED_BY_SINGLE_STEP
;
4859 /* Mark the non-executing threads accordingly. In all-stop, all
4860 threads of all processes are stopped when we get any event
4861 reported. In non-stop mode, only the event thread stops. */
4864 mark_non_executing_threads (process_stratum_target
*target
,
4866 struct target_waitstatus ws
)
4870 if (!target_is_non_stop_p ())
4871 mark_ptid
= minus_one_ptid
;
4872 else if (ws
.kind
== TARGET_WAITKIND_SIGNALLED
4873 || ws
.kind
== TARGET_WAITKIND_EXITED
)
4875 /* If we're handling a process exit in non-stop mode, even
4876 though threads haven't been deleted yet, one would think
4877 that there is nothing to do, as threads of the dead process
4878 will be soon deleted, and threads of any other process were
4879 left running. However, on some targets, threads survive a
4880 process exit event. E.g., for the "checkpoint" command,
4881 when the current checkpoint/fork exits, linux-fork.c
4882 automatically switches to another fork from within
4883 target_mourn_inferior, by associating the same
4884 inferior/thread to another fork. We haven't mourned yet at
4885 this point, but we must mark any threads left in the
4886 process as not-executing so that finish_thread_state marks
4887 them stopped (in the user's perspective) if/when we present
4888 the stop to the user. */
4889 mark_ptid
= ptid_t (event_ptid
.pid ());
4892 mark_ptid
= event_ptid
;
4894 set_executing (target
, mark_ptid
, false);
4896 /* Likewise the resumed flag. */
4897 set_resumed (target
, mark_ptid
, false);
4900 /* Handle one event after stopping threads. If the eventing thread
4901 reports back any interesting event, we leave it pending. If the
4902 eventing thread was in the middle of a displaced step, we
4903 cancel/finish it, and unless the thread's inferior is being
4904 detached, put the thread back in the step-over chain. Returns true
4905 if there are no resumed threads left in the target (thus there's no
4906 point in waiting further), false otherwise. */
4909 handle_one (const wait_one_event
&event
)
4912 ("%s %s", target_waitstatus_to_string (&event
.ws
).c_str (),
4913 target_pid_to_str (event
.ptid
).c_str ());
4915 if (event
.ws
.kind
== TARGET_WAITKIND_NO_RESUMED
)
4917 /* All resumed threads exited. */
4920 else if (event
.ws
.kind
== TARGET_WAITKIND_THREAD_EXITED
4921 || event
.ws
.kind
== TARGET_WAITKIND_EXITED
4922 || event
.ws
.kind
== TARGET_WAITKIND_SIGNALLED
)
4924 /* One thread/process exited/signalled. */
4926 thread_info
*t
= nullptr;
4928 /* The target may have reported just a pid. If so, try
4929 the first non-exited thread. */
4930 if (event
.ptid
.is_pid ())
4932 int pid
= event
.ptid
.pid ();
4933 inferior
*inf
= find_inferior_pid (event
.target
, pid
);
4934 for (thread_info
*tp
: inf
->non_exited_threads ())
4940 /* If there is no available thread, the event would
4941 have to be appended to a per-inferior event list,
4942 which does not exist (and if it did, we'd have
4943 to adjust run control command to be able to
4944 resume such an inferior). We assert here instead
4945 of going into an infinite loop. */
4946 gdb_assert (t
!= nullptr);
4949 ("using %s", target_pid_to_str (t
->ptid
).c_str ());
4953 t
= find_thread_ptid (event
.target
, event
.ptid
);
4954 /* Check if this is the first time we see this thread.
4955 Don't bother adding if it individually exited. */
4957 && event
.ws
.kind
!= TARGET_WAITKIND_THREAD_EXITED
)
4958 t
= add_thread (event
.target
, event
.ptid
);
4963 /* Set the threads as non-executing to avoid
4964 another stop attempt on them. */
4965 switch_to_thread_no_regs (t
);
4966 mark_non_executing_threads (event
.target
, event
.ptid
,
4968 save_waitstatus (t
, &event
.ws
);
4969 t
->stop_requested
= false;
4974 thread_info
*t
= find_thread_ptid (event
.target
, event
.ptid
);
4976 t
= add_thread (event
.target
, event
.ptid
);
4978 t
->stop_requested
= 0;
4981 t
->control
.may_range_step
= 0;
4983 /* This may be the first time we see the inferior report
4985 inferior
*inf
= find_inferior_ptid (event
.target
, event
.ptid
);
4986 if (inf
->needs_setup
)
4988 switch_to_thread_no_regs (t
);
4992 if (event
.ws
.kind
== TARGET_WAITKIND_STOPPED
4993 && event
.ws
.value
.sig
== GDB_SIGNAL_0
)
4995 /* We caught the event that we intended to catch, so
4996 there's no event pending. */
4997 t
->suspend
.waitstatus
.kind
= TARGET_WAITKIND_IGNORE
;
4998 t
->suspend
.waitstatus_pending_p
= 0;
5000 if (displaced_step_finish (t
, GDB_SIGNAL_0
)
5001 == DISPLACED_STEP_FINISH_STATUS_NOT_EXECUTED
)
5003 /* Add it back to the step-over queue. */
5005 ("displaced-step of %s canceled",
5006 target_pid_to_str (t
->ptid
).c_str ());
5008 t
->control
.trap_expected
= 0;
5009 if (!t
->inf
->detaching
)
5010 global_thread_step_over_chain_enqueue (t
);
5015 enum gdb_signal sig
;
5016 struct regcache
*regcache
;
5019 ("target_wait %s, saving status for %d.%ld.%ld",
5020 target_waitstatus_to_string (&event
.ws
).c_str (),
5021 t
->ptid
.pid (), t
->ptid
.lwp (), t
->ptid
.tid ());
5023 /* Record for later. */
5024 save_waitstatus (t
, &event
.ws
);
5026 sig
= (event
.ws
.kind
== TARGET_WAITKIND_STOPPED
5027 ? event
.ws
.value
.sig
: GDB_SIGNAL_0
);
5029 if (displaced_step_finish (t
, sig
)
5030 == DISPLACED_STEP_FINISH_STATUS_NOT_EXECUTED
)
5032 /* Add it back to the step-over queue. */
5033 t
->control
.trap_expected
= 0;
5034 if (!t
->inf
->detaching
)
5035 global_thread_step_over_chain_enqueue (t
);
5038 regcache
= get_thread_regcache (t
);
5039 t
->suspend
.stop_pc
= regcache_read_pc (regcache
);
5041 infrun_debug_printf ("saved stop_pc=%s for %s "
5042 "(currently_stepping=%d)",
5043 paddress (target_gdbarch (),
5044 t
->suspend
.stop_pc
),
5045 target_pid_to_str (t
->ptid
).c_str (),
5046 currently_stepping (t
));
5056 stop_all_threads (const char *reason
, inferior
*inf
)
5058 /* We may need multiple passes to discover all threads. */
5062 gdb_assert (exists_non_stop_target ());
5064 INFRUN_SCOPED_DEBUG_START_END ("reason=%s, inf=%d", reason
, inf
!= nullptr ? inf
->num
: -1);
5066 scoped_restore_current_thread restore_thread
;
5068 /* Enable thread events of all targets. */
5069 for (auto *target
: all_non_exited_process_targets ())
5071 if (inf
!= nullptr && inf
->process_target () != target
)
5074 switch_to_target_no_thread (target
);
5075 target_thread_events (true);
5080 /* Disable thread events of all targets. */
5081 for (auto *target
: all_non_exited_process_targets ())
5083 if (inf
!= nullptr && inf
->process_target () != target
)
5086 switch_to_target_no_thread (target
);
5087 target_thread_events (false);
5090 /* Use debug_prefixed_printf directly to get a meaningful function
5093 debug_prefixed_printf ("infrun", "stop_all_threads", "done");
5096 /* Request threads to stop, and then wait for the stops. Because
5097 threads we already know about can spawn more threads while we're
5098 trying to stop them, and we only learn about new threads when we
5099 update the thread list, do this in a loop, and keep iterating
5100 until two passes find no threads that need to be stopped. */
5101 for (pass
= 0; pass
< 2; pass
++, iterations
++)
5103 infrun_debug_printf ("pass=%d, iterations=%d", pass
, iterations
);
5106 int waits_needed
= 0;
5108 for (auto *target
: all_non_exited_process_targets ())
5110 if (inf
!= nullptr && inf
->process_target () != target
)
5113 switch_to_target_no_thread (target
);
5114 update_thread_list ();
5117 /* Go through all threads looking for threads that we need
5118 to tell the target to stop. */
5119 for (thread_info
*t
: all_non_exited_threads ())
5121 if (inf
!= nullptr && t
->inf
!= inf
)
5124 /* For a single-target setting with an all-stop target,
5125 we would not even arrive here. For a multi-target
5126 setting, until GDB is able to handle a mixture of
5127 all-stop and non-stop targets, simply skip all-stop
5128 targets' threads. This should be fine due to the
5129 protection of 'check_multi_target_resumption'. */
5131 switch_to_thread_no_regs (t
);
5132 if (!target_is_non_stop_p ())
5137 /* If already stopping, don't request a stop again.
5138 We just haven't seen the notification yet. */
5139 if (!t
->stop_requested
)
5141 infrun_debug_printf (" %s executing, need stop",
5142 target_pid_to_str (t
->ptid
).c_str ());
5143 target_stop (t
->ptid
);
5144 t
->stop_requested
= 1;
5148 infrun_debug_printf (" %s executing, already stopping",
5149 target_pid_to_str (t
->ptid
).c_str ());
5152 if (t
->stop_requested
)
5157 infrun_debug_printf (" %s not executing",
5158 target_pid_to_str (t
->ptid
).c_str ());
5160 /* The thread may be not executing, but still be
5161 resumed with a pending status to process. */
5166 if (waits_needed
== 0)
5169 /* If we find new threads on the second iteration, restart
5170 over. We want to see two iterations in a row with all
5175 for (int i
= 0; i
< waits_needed
; i
++)
5177 wait_one_event event
= wait_one ();
5178 if (handle_one (event
))
5185 /* Handle a TARGET_WAITKIND_NO_RESUMED event. */
5188 handle_no_resumed (struct execution_control_state
*ecs
)
5190 if (target_can_async_p ())
5192 bool any_sync
= false;
5194 for (ui
*ui
: all_uis ())
5196 if (ui
->prompt_state
== PROMPT_BLOCKED
)
5204 /* There were no unwaited-for children left in the target, but,
5205 we're not synchronously waiting for events either. Just
5208 infrun_debug_printf ("TARGET_WAITKIND_NO_RESUMED (ignoring: bg)");
5209 prepare_to_wait (ecs
);
5214 /* Otherwise, if we were running a synchronous execution command, we
5215 may need to cancel it and give the user back the terminal.
5217 In non-stop mode, the target can't tell whether we've already
5218 consumed previous stop events, so it can end up sending us a
5219 no-resumed event like so:
5221 #0 - thread 1 is left stopped
5223 #1 - thread 2 is resumed and hits breakpoint
5224 -> TARGET_WAITKIND_STOPPED
5226 #2 - thread 3 is resumed and exits
5227 this is the last resumed thread, so
5228 -> TARGET_WAITKIND_NO_RESUMED
5230 #3 - gdb processes stop for thread 2 and decides to re-resume
5233 #4 - gdb processes the TARGET_WAITKIND_NO_RESUMED event.
5234 thread 2 is now resumed, so the event should be ignored.
5236 IOW, if the stop for thread 2 doesn't end a foreground command,
5237 then we need to ignore the following TARGET_WAITKIND_NO_RESUMED
5238 event. But it could be that the event meant that thread 2 itself
5239 (or whatever other thread was the last resumed thread) exited.
5241 To address this we refresh the thread list and check whether we
5242 have resumed threads _now_. In the example above, this removes
5243 thread 3 from the thread list. If thread 2 was re-resumed, we
5244 ignore this event. If we find no thread resumed, then we cancel
5245 the synchronous command and show "no unwaited-for " to the
5248 inferior
*curr_inf
= current_inferior ();
5250 scoped_restore_current_thread restore_thread
;
5252 for (auto *target
: all_non_exited_process_targets ())
5254 switch_to_target_no_thread (target
);
5255 update_thread_list ();
5260 - the current target has no thread executing, and
5261 - the current inferior is native, and
5262 - the current inferior is the one which has the terminal, and
5265 then a Ctrl-C from this point on would remain stuck in the
5266 kernel, until a thread resumes and dequeues it. That would
5267 result in the GDB CLI not reacting to Ctrl-C, not able to
5268 interrupt the program. To address this, if the current inferior
5269 no longer has any thread executing, we give the terminal to some
5270 other inferior that has at least one thread executing. */
5271 bool swap_terminal
= true;
5273 /* Whether to ignore this TARGET_WAITKIND_NO_RESUMED event, or
5274 whether to report it to the user. */
5275 bool ignore_event
= false;
5277 for (thread_info
*thread
: all_non_exited_threads ())
5279 if (swap_terminal
&& thread
->executing
)
5281 if (thread
->inf
!= curr_inf
)
5283 target_terminal::ours ();
5285 switch_to_thread (thread
);
5286 target_terminal::inferior ();
5288 swap_terminal
= false;
5292 && (thread
->executing
5293 || thread
->suspend
.waitstatus_pending_p
))
5295 /* Either there were no unwaited-for children left in the
5296 target at some point, but there are now, or some target
5297 other than the eventing one has unwaited-for children
5298 left. Just ignore. */
5299 infrun_debug_printf ("TARGET_WAITKIND_NO_RESUMED "
5300 "(ignoring: found resumed)");
5302 ignore_event
= true;
5305 if (ignore_event
&& !swap_terminal
)
5311 switch_to_inferior_no_thread (curr_inf
);
5312 prepare_to_wait (ecs
);
5316 /* Go ahead and report the event. */
5320 /* Given an execution control state that has been freshly filled in by
5321 an event from the inferior, figure out what it means and take
5324 The alternatives are:
5326 1) stop_waiting and return; to really stop and return to the
5329 2) keep_going and return; to wait for the next event (set
5330 ecs->event_thread->stepping_over_breakpoint to 1 to single step
5334 handle_inferior_event (struct execution_control_state
*ecs
)
5336 /* Make sure that all temporary struct value objects that were
5337 created during the handling of the event get deleted at the
5339 scoped_value_mark free_values
;
5341 infrun_debug_printf ("%s", target_waitstatus_to_string (&ecs
->ws
).c_str ());
5343 if (ecs
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
5345 /* We had an event in the inferior, but we are not interested in
5346 handling it at this level. The lower layers have already
5347 done what needs to be done, if anything.
5349 One of the possible circumstances for this is when the
5350 inferior produces output for the console. The inferior has
5351 not stopped, and we are ignoring the event. Another possible
5352 circumstance is any event which the lower level knows will be
5353 reported multiple times without an intervening resume. */
5354 prepare_to_wait (ecs
);
5358 if (ecs
->ws
.kind
== TARGET_WAITKIND_THREAD_EXITED
)
5360 prepare_to_wait (ecs
);
5364 if (ecs
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
5365 && handle_no_resumed (ecs
))
5368 /* Cache the last target/ptid/waitstatus. */
5369 set_last_target_status (ecs
->target
, ecs
->ptid
, ecs
->ws
);
5371 /* Always clear state belonging to the previous time we stopped. */
5372 stop_stack_dummy
= STOP_NONE
;
5374 if (ecs
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
)
5376 /* No unwaited-for children left. IOW, all resumed children
5378 stop_print_frame
= false;
5383 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
5384 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
)
5386 ecs
->event_thread
= find_thread_ptid (ecs
->target
, ecs
->ptid
);
5387 /* If it's a new thread, add it to the thread database. */
5388 if (ecs
->event_thread
== NULL
)
5389 ecs
->event_thread
= add_thread (ecs
->target
, ecs
->ptid
);
5391 /* Disable range stepping. If the next step request could use a
5392 range, this will be end up re-enabled then. */
5393 ecs
->event_thread
->control
.may_range_step
= 0;
5396 /* Dependent on valid ECS->EVENT_THREAD. */
5397 adjust_pc_after_break (ecs
->event_thread
, &ecs
->ws
);
5399 /* Dependent on the current PC value modified by adjust_pc_after_break. */
5400 reinit_frame_cache ();
5402 breakpoint_retire_moribund ();
5404 /* First, distinguish signals caused by the debugger from signals
5405 that have to do with the program's own actions. Note that
5406 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
5407 on the operating system version. Here we detect when a SIGILL or
5408 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
5409 something similar for SIGSEGV, since a SIGSEGV will be generated
5410 when we're trying to execute a breakpoint instruction on a
5411 non-executable stack. This happens for call dummy breakpoints
5412 for architectures like SPARC that place call dummies on the
5414 if (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
5415 && (ecs
->ws
.value
.sig
== GDB_SIGNAL_ILL
5416 || ecs
->ws
.value
.sig
== GDB_SIGNAL_SEGV
5417 || ecs
->ws
.value
.sig
== GDB_SIGNAL_EMT
))
5419 struct regcache
*regcache
= get_thread_regcache (ecs
->event_thread
);
5421 if (breakpoint_inserted_here_p (regcache
->aspace (),
5422 regcache_read_pc (regcache
)))
5424 infrun_debug_printf ("Treating signal as SIGTRAP");
5425 ecs
->ws
.value
.sig
= GDB_SIGNAL_TRAP
;
5429 mark_non_executing_threads (ecs
->target
, ecs
->ptid
, ecs
->ws
);
5431 switch (ecs
->ws
.kind
)
5433 case TARGET_WAITKIND_LOADED
:
5435 context_switch (ecs
);
5436 /* Ignore gracefully during startup of the inferior, as it might
5437 be the shell which has just loaded some objects, otherwise
5438 add the symbols for the newly loaded objects. Also ignore at
5439 the beginning of an attach or remote session; we will query
5440 the full list of libraries once the connection is
5443 stop_kind stop_soon
= get_inferior_stop_soon (ecs
);
5444 if (stop_soon
== NO_STOP_QUIETLY
)
5446 struct regcache
*regcache
;
5448 regcache
= get_thread_regcache (ecs
->event_thread
);
5450 handle_solib_event ();
5452 ecs
->event_thread
->control
.stop_bpstat
5453 = bpstat_stop_status (regcache
->aspace (),
5454 ecs
->event_thread
->suspend
.stop_pc
,
5455 ecs
->event_thread
, &ecs
->ws
);
5457 if (handle_stop_requested (ecs
))
5460 if (bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
5462 /* A catchpoint triggered. */
5463 process_event_stop_test (ecs
);
5467 /* If requested, stop when the dynamic linker notifies
5468 gdb of events. This allows the user to get control
5469 and place breakpoints in initializer routines for
5470 dynamically loaded objects (among other things). */
5471 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5472 if (stop_on_solib_events
)
5474 /* Make sure we print "Stopped due to solib-event" in
5476 stop_print_frame
= true;
5483 /* If we are skipping through a shell, or through shared library
5484 loading that we aren't interested in, resume the program. If
5485 we're running the program normally, also resume. */
5486 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== NO_STOP_QUIETLY
)
5488 /* Loading of shared libraries might have changed breakpoint
5489 addresses. Make sure new breakpoints are inserted. */
5490 if (stop_soon
== NO_STOP_QUIETLY
)
5491 insert_breakpoints ();
5492 resume (GDB_SIGNAL_0
);
5493 prepare_to_wait (ecs
);
5497 /* But stop if we're attaching or setting up a remote
5499 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
5500 || stop_soon
== STOP_QUIETLY_REMOTE
)
5502 infrun_debug_printf ("quietly stopped");
5507 internal_error (__FILE__
, __LINE__
,
5508 _("unhandled stop_soon: %d"), (int) stop_soon
);
5511 case TARGET_WAITKIND_SPURIOUS
:
5512 if (handle_stop_requested (ecs
))
5514 context_switch (ecs
);
5515 resume (GDB_SIGNAL_0
);
5516 prepare_to_wait (ecs
);
5519 case TARGET_WAITKIND_THREAD_CREATED
:
5520 if (handle_stop_requested (ecs
))
5522 context_switch (ecs
);
5523 if (!switch_back_to_stepped_thread (ecs
))
5527 case TARGET_WAITKIND_EXITED
:
5528 case TARGET_WAITKIND_SIGNALLED
:
5530 /* Depending on the system, ecs->ptid may point to a thread or
5531 to a process. On some targets, target_mourn_inferior may
5532 need to have access to the just-exited thread. That is the
5533 case of GNU/Linux's "checkpoint" support, for example.
5534 Call the switch_to_xxx routine as appropriate. */
5535 thread_info
*thr
= find_thread_ptid (ecs
->target
, ecs
->ptid
);
5537 switch_to_thread (thr
);
5540 inferior
*inf
= find_inferior_ptid (ecs
->target
, ecs
->ptid
);
5541 switch_to_inferior_no_thread (inf
);
5544 handle_vfork_child_exec_or_exit (0);
5545 target_terminal::ours (); /* Must do this before mourn anyway. */
5547 /* Clearing any previous state of convenience variables. */
5548 clear_exit_convenience_vars ();
5550 if (ecs
->ws
.kind
== TARGET_WAITKIND_EXITED
)
5552 /* Record the exit code in the convenience variable $_exitcode, so
5553 that the user can inspect this again later. */
5554 set_internalvar_integer (lookup_internalvar ("_exitcode"),
5555 (LONGEST
) ecs
->ws
.value
.integer
);
5557 /* Also record this in the inferior itself. */
5558 current_inferior ()->has_exit_code
= 1;
5559 current_inferior ()->exit_code
= (LONGEST
) ecs
->ws
.value
.integer
;
5561 /* Support the --return-child-result option. */
5562 return_child_result_value
= ecs
->ws
.value
.integer
;
5564 gdb::observers::exited
.notify (ecs
->ws
.value
.integer
);
5568 struct gdbarch
*gdbarch
= current_inferior ()->gdbarch
;
5570 if (gdbarch_gdb_signal_to_target_p (gdbarch
))
5572 /* Set the value of the internal variable $_exitsignal,
5573 which holds the signal uncaught by the inferior. */
5574 set_internalvar_integer (lookup_internalvar ("_exitsignal"),
5575 gdbarch_gdb_signal_to_target (gdbarch
,
5576 ecs
->ws
.value
.sig
));
5580 /* We don't have access to the target's method used for
5581 converting between signal numbers (GDB's internal
5582 representation <-> target's representation).
5583 Therefore, we cannot do a good job at displaying this
5584 information to the user. It's better to just warn
5585 her about it (if infrun debugging is enabled), and
5587 infrun_debug_printf ("Cannot fill $_exitsignal with the correct "
5591 gdb::observers::signal_exited
.notify (ecs
->ws
.value
.sig
);
5594 gdb_flush (gdb_stdout
);
5595 target_mourn_inferior (inferior_ptid
);
5596 stop_print_frame
= false;
5600 case TARGET_WAITKIND_FORKED
:
5601 case TARGET_WAITKIND_VFORKED
:
5602 /* Check whether the inferior is displaced stepping. */
5604 struct regcache
*regcache
= get_thread_regcache (ecs
->event_thread
);
5605 struct gdbarch
*gdbarch
= regcache
->arch ();
5606 inferior
*parent_inf
= find_inferior_ptid (ecs
->target
, ecs
->ptid
);
5608 /* If this is a fork (child gets its own address space copy)
5609 and some displaced step buffers were in use at the time of
5610 the fork, restore the displaced step buffer bytes in the
5613 Architectures which support displaced stepping and fork
5614 events must supply an implementation of
5615 gdbarch_displaced_step_restore_all_in_ptid. This is not
5616 enforced during gdbarch validation to support architectures
5617 which support displaced stepping but not forks. */
5618 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
5619 && gdbarch_supports_displaced_stepping (gdbarch
))
5620 gdbarch_displaced_step_restore_all_in_ptid
5621 (gdbarch
, parent_inf
, ecs
->ws
.value
.related_pid
);
5623 /* If displaced stepping is supported, and thread ecs->ptid is
5624 displaced stepping. */
5625 if (displaced_step_in_progress_thread (ecs
->event_thread
))
5627 struct regcache
*child_regcache
;
5628 CORE_ADDR parent_pc
;
5630 /* GDB has got TARGET_WAITKIND_FORKED or TARGET_WAITKIND_VFORKED,
5631 indicating that the displaced stepping of syscall instruction
5632 has been done. Perform cleanup for parent process here. Note
5633 that this operation also cleans up the child process for vfork,
5634 because their pages are shared. */
5635 displaced_step_finish (ecs
->event_thread
, GDB_SIGNAL_TRAP
);
5636 /* Start a new step-over in another thread if there's one
5640 /* Since the vfork/fork syscall instruction was executed in the scratchpad,
5641 the child's PC is also within the scratchpad. Set the child's PC
5642 to the parent's PC value, which has already been fixed up.
5643 FIXME: we use the parent's aspace here, although we're touching
5644 the child, because the child hasn't been added to the inferior
5645 list yet at this point. */
5648 = get_thread_arch_aspace_regcache (parent_inf
->process_target (),
5649 ecs
->ws
.value
.related_pid
,
5651 parent_inf
->aspace
);
5652 /* Read PC value of parent process. */
5653 parent_pc
= regcache_read_pc (regcache
);
5655 displaced_debug_printf ("write child pc from %s to %s",
5657 regcache_read_pc (child_regcache
)),
5658 paddress (gdbarch
, parent_pc
));
5660 regcache_write_pc (child_regcache
, parent_pc
);
5664 context_switch (ecs
);
5666 /* Immediately detach breakpoints from the child before there's
5667 any chance of letting the user delete breakpoints from the
5668 breakpoint lists. If we don't do this early, it's easy to
5669 leave left over traps in the child, vis: "break foo; catch
5670 fork; c; <fork>; del; c; <child calls foo>". We only follow
5671 the fork on the last `continue', and by that time the
5672 breakpoint at "foo" is long gone from the breakpoint table.
5673 If we vforked, then we don't need to unpatch here, since both
5674 parent and child are sharing the same memory pages; we'll
5675 need to unpatch at follow/detach time instead to be certain
5676 that new breakpoints added between catchpoint hit time and
5677 vfork follow are detached. */
5678 if (ecs
->ws
.kind
!= TARGET_WAITKIND_VFORKED
)
5680 /* This won't actually modify the breakpoint list, but will
5681 physically remove the breakpoints from the child. */
5682 detach_breakpoints (ecs
->ws
.value
.related_pid
);
5685 delete_just_stopped_threads_single_step_breakpoints ();
5687 /* In case the event is caught by a catchpoint, remember that
5688 the event is to be followed at the next resume of the thread,
5689 and not immediately. */
5690 ecs
->event_thread
->pending_follow
= ecs
->ws
;
5692 ecs
->event_thread
->suspend
.stop_pc
5693 = regcache_read_pc (get_thread_regcache (ecs
->event_thread
));
5695 ecs
->event_thread
->control
.stop_bpstat
5696 = bpstat_stop_status (get_current_regcache ()->aspace (),
5697 ecs
->event_thread
->suspend
.stop_pc
,
5698 ecs
->event_thread
, &ecs
->ws
);
5700 if (handle_stop_requested (ecs
))
5703 /* If no catchpoint triggered for this, then keep going. Note
5704 that we're interested in knowing the bpstat actually causes a
5705 stop, not just if it may explain the signal. Software
5706 watchpoints, for example, always appear in the bpstat. */
5707 if (!bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
5710 = (follow_fork_mode_string
== follow_fork_mode_child
);
5712 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5714 process_stratum_target
*targ
5715 = ecs
->event_thread
->inf
->process_target ();
5717 bool should_resume
= follow_fork ();
5719 /* Note that one of these may be an invalid pointer,
5720 depending on detach_fork. */
5721 thread_info
*parent
= ecs
->event_thread
;
5723 = find_thread_ptid (targ
, ecs
->ws
.value
.related_pid
);
5725 /* At this point, the parent is marked running, and the
5726 child is marked stopped. */
5728 /* If not resuming the parent, mark it stopped. */
5729 if (follow_child
&& !detach_fork
&& !non_stop
&& !sched_multi
)
5730 parent
->set_running (false);
5732 /* If resuming the child, mark it running. */
5733 if (follow_child
|| (!detach_fork
&& (non_stop
|| sched_multi
)))
5734 child
->set_running (true);
5736 /* In non-stop mode, also resume the other branch. */
5738 && (non_stop
|| (sched_multi
&& target_is_non_stop_p ())))
5741 switch_to_thread (parent
);
5743 switch_to_thread (child
);
5745 ecs
->event_thread
= inferior_thread ();
5746 ecs
->ptid
= inferior_ptid
;
5747 if (current_inferior ()->vfork_child
== nullptr)
5752 switch_to_thread (child
);
5754 switch_to_thread (parent
);
5756 ecs
->event_thread
= inferior_thread ();
5757 ecs
->ptid
= inferior_ptid
;
5761 if (ecs
->ws
.kind
== TARGET_WAITKIND_VFORKED
)
5763 if (current_inferior ()->vfork_child
!= nullptr
5764 && target_is_non_stop_p ())
5765 prepare_to_wait (ecs
);
5770 if (!switch_back_to_stepped_thread (ecs
))
5777 process_event_stop_test (ecs
);
5780 case TARGET_WAITKIND_VFORK_DONE
:
5781 /* Done with the shared memory region. Re-insert breakpoints in
5782 the parent, and keep going. */
5784 context_switch (ecs
);
5786 handle_vfork_done (ecs
->event_thread
);
5788 gdb_assert (inferior_thread () == ecs
->event_thread
);
5790 if (handle_stop_requested (ecs
))
5793 /* This also takes care of reinserting breakpoints in the
5794 previously locked inferior. */
5795 if (!switch_back_to_stepped_thread (ecs
))
5797 gdb_assert (inferior_thread () == ecs
->event_thread
);
5802 case TARGET_WAITKIND_EXECD
:
5804 /* Note we can't read registers yet (the stop_pc), because we
5805 don't yet know the inferior's post-exec architecture.
5806 'stop_pc' is explicitly read below instead. */
5807 switch_to_thread_no_regs (ecs
->event_thread
);
5809 /* Do whatever is necessary to the parent branch of the vfork. */
5810 handle_vfork_child_exec_or_exit (1);
5812 /* This causes the eventpoints and symbol table to be reset.
5813 Must do this now, before trying to determine whether to
5815 follow_exec (inferior_ptid
, ecs
->ws
.value
.execd_pathname
);
5817 /* In follow_exec we may have deleted the original thread and
5818 created a new one. Make sure that the event thread is the
5819 execd thread for that case (this is a nop otherwise). */
5820 ecs
->event_thread
= inferior_thread ();
5822 ecs
->event_thread
->suspend
.stop_pc
5823 = regcache_read_pc (get_thread_regcache (ecs
->event_thread
));
5825 ecs
->event_thread
->control
.stop_bpstat
5826 = bpstat_stop_status (get_current_regcache ()->aspace (),
5827 ecs
->event_thread
->suspend
.stop_pc
,
5828 ecs
->event_thread
, &ecs
->ws
);
5830 /* Note that this may be referenced from inside
5831 bpstat_stop_status above, through inferior_has_execd. */
5832 xfree (ecs
->ws
.value
.execd_pathname
);
5833 ecs
->ws
.value
.execd_pathname
= NULL
;
5835 if (handle_stop_requested (ecs
))
5838 /* If no catchpoint triggered for this, then keep going. */
5839 if (!bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
5841 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5845 process_event_stop_test (ecs
);
5848 /* Be careful not to try to gather much state about a thread
5849 that's in a syscall. It's frequently a losing proposition. */
5850 case TARGET_WAITKIND_SYSCALL_ENTRY
:
5851 /* Getting the current syscall number. */
5852 if (handle_syscall_event (ecs
) == 0)
5853 process_event_stop_test (ecs
);
5856 /* Before examining the threads further, step this thread to
5857 get it entirely out of the syscall. (We get notice of the
5858 event when the thread is just on the verge of exiting a
5859 syscall. Stepping one instruction seems to get it back
5861 case TARGET_WAITKIND_SYSCALL_RETURN
:
5862 if (handle_syscall_event (ecs
) == 0)
5863 process_event_stop_test (ecs
);
5866 case TARGET_WAITKIND_STOPPED
:
5867 handle_signal_stop (ecs
);
5870 case TARGET_WAITKIND_NO_HISTORY
:
5871 /* Reverse execution: target ran out of history info. */
5873 /* Switch to the stopped thread. */
5874 context_switch (ecs
);
5875 infrun_debug_printf ("stopped");
5877 delete_just_stopped_threads_single_step_breakpoints ();
5878 ecs
->event_thread
->suspend
.stop_pc
5879 = regcache_read_pc (get_thread_regcache (inferior_thread ()));
5881 if (handle_stop_requested (ecs
))
5884 gdb::observers::no_history
.notify ();
5890 /* Restart threads back to what they were trying to do back when we
5891 paused them for an in-line step-over. The EVENT_THREAD thread is
5895 restart_threads (struct thread_info
*event_thread
, inferior
*inf
)
5897 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
5899 gdb_assert (target_is_non_stop_p ());
5901 scoped_restore_current_thread restore_thread
;
5903 /* In case the instruction just stepped spawned a new thread. */
5904 update_thread_list ();
5906 for (thread_info
*tp
: all_non_exited_threads ())
5908 if (inf
!= nullptr && tp
->inf
!= inf
)
5911 if (tp
->inf
->detaching
)
5913 infrun_debug_printf ("restart threads: [%s] inferior detaching",
5914 target_pid_to_str (tp
->ptid
).c_str ());
5918 switch_to_thread_no_regs (tp
);
5920 if (tp
== event_thread
)
5922 infrun_debug_printf ("restart threads: [%s] is event thread",
5923 target_pid_to_str (tp
->ptid
).c_str ());
5927 if (!(tp
->state
== THREAD_RUNNING
|| tp
->control
.in_infcall
))
5929 infrun_debug_printf ("restart threads: [%s] not meant to be running",
5930 target_pid_to_str (tp
->ptid
).c_str ());
5936 infrun_debug_printf ("restart threads: [%s] resumed",
5937 target_pid_to_str (tp
->ptid
).c_str ());
5938 gdb_assert (tp
->executing
|| tp
->suspend
.waitstatus_pending_p
);
5942 if (thread_is_in_step_over_chain (tp
))
5944 infrun_debug_printf ("restart threads: [%s] needs step-over",
5945 target_pid_to_str (tp
->ptid
).c_str ());
5946 gdb_assert (!tp
->resumed
);
5951 if (tp
->suspend
.waitstatus_pending_p
)
5953 infrun_debug_printf ("restart threads: [%s] has pending status",
5954 target_pid_to_str (tp
->ptid
).c_str ());
5959 gdb_assert (!tp
->stop_requested
);
5961 /* If some thread needs to start a step-over at this point, it
5962 should still be in the step-over queue, and thus skipped
5964 if (thread_still_needs_step_over (tp
))
5966 internal_error (__FILE__
, __LINE__
,
5967 "thread [%s] needs a step-over, but not in "
5968 "step-over queue\n",
5969 target_pid_to_str (tp
->ptid
).c_str ());
5972 if (currently_stepping (tp
))
5974 infrun_debug_printf ("restart threads: [%s] was stepping",
5975 target_pid_to_str (tp
->ptid
).c_str ());
5976 keep_going_stepped_thread (tp
);
5980 struct execution_control_state ecss
;
5981 struct execution_control_state
*ecs
= &ecss
;
5983 infrun_debug_printf ("restart threads: [%s] continuing",
5984 target_pid_to_str (tp
->ptid
).c_str ());
5985 reset_ecs (ecs
, tp
);
5986 switch_to_thread (tp
);
5987 keep_going_pass_signal (ecs
);
5992 /* Callback for iterate_over_threads. Find a resumed thread that has
5993 a pending waitstatus. */
5996 resumed_thread_with_pending_status (struct thread_info
*tp
,
6000 && tp
->suspend
.waitstatus_pending_p
);
6003 /* Called when we get an event that may finish an in-line or
6004 out-of-line (displaced stepping) step-over started previously.
6005 Return true if the event is processed and we should go back to the
6006 event loop; false if the caller should continue processing the
6010 finish_step_over (struct execution_control_state
*ecs
)
6012 displaced_step_finish (ecs
->event_thread
,
6013 ecs
->event_thread
->suspend
.stop_signal
);
6015 bool had_step_over_info
= step_over_info_valid_p ();
6017 if (had_step_over_info
)
6019 /* If we're stepping over a breakpoint with all threads locked,
6020 then only the thread that was stepped should be reporting
6022 gdb_assert (ecs
->event_thread
->control
.trap_expected
);
6024 clear_step_over_info ();
6027 if (!target_is_non_stop_p ())
6030 /* Start a new step-over in another thread if there's one that
6034 /* If we were stepping over a breakpoint before, and haven't started
6035 a new in-line step-over sequence, then restart all other threads
6036 (except the event thread). We can't do this in all-stop, as then
6037 e.g., we wouldn't be able to issue any other remote packet until
6038 these other threads stop. */
6039 if (had_step_over_info
&& !step_over_info_valid_p ())
6041 struct thread_info
*pending
;
6043 /* If we only have threads with pending statuses, the restart
6044 below won't restart any thread and so nothing re-inserts the
6045 breakpoint we just stepped over. But we need it inserted
6046 when we later process the pending events, otherwise if
6047 another thread has a pending event for this breakpoint too,
6048 we'd discard its event (because the breakpoint that
6049 originally caused the event was no longer inserted). */
6050 context_switch (ecs
);
6051 insert_breakpoints ();
6053 restart_threads (ecs
->event_thread
, nullptr);
6055 /* If we have events pending, go through handle_inferior_event
6056 again, picking up a pending event at random. This avoids
6057 thread starvation. */
6059 /* But not if we just stepped over a watchpoint in order to let
6060 the instruction execute so we can evaluate its expression.
6061 The set of watchpoints that triggered is recorded in the
6062 breakpoint objects themselves (see bp->watchpoint_triggered).
6063 If we processed another event first, that other event could
6064 clobber this info. */
6065 if (ecs
->event_thread
->stepping_over_watchpoint
)
6068 pending
= iterate_over_threads (resumed_thread_with_pending_status
,
6070 if (pending
!= NULL
)
6072 struct thread_info
*tp
= ecs
->event_thread
;
6073 struct regcache
*regcache
;
6075 infrun_debug_printf ("found resumed threads with "
6076 "pending events, saving status");
6078 gdb_assert (pending
!= tp
);
6080 /* Record the event thread's event for later. */
6081 save_waitstatus (tp
, &ecs
->ws
);
6082 /* This was cleared early, by handle_inferior_event. Set it
6083 so this pending event is considered by
6087 gdb_assert (!tp
->executing
);
6089 regcache
= get_thread_regcache (tp
);
6090 tp
->suspend
.stop_pc
= regcache_read_pc (regcache
);
6092 infrun_debug_printf ("saved stop_pc=%s for %s "
6093 "(currently_stepping=%d)",
6094 paddress (target_gdbarch (),
6095 tp
->suspend
.stop_pc
),
6096 target_pid_to_str (tp
->ptid
).c_str (),
6097 currently_stepping (tp
));
6099 /* This in-line step-over finished; clear this so we won't
6100 start a new one. This is what handle_signal_stop would
6101 do, if we returned false. */
6102 tp
->stepping_over_breakpoint
= 0;
6104 /* Wake up the event loop again. */
6105 mark_async_event_handler (infrun_async_inferior_event_token
);
6107 prepare_to_wait (ecs
);
6115 /* Come here when the program has stopped with a signal. */
6118 handle_signal_stop (struct execution_control_state
*ecs
)
6120 struct frame_info
*frame
;
6121 struct gdbarch
*gdbarch
;
6122 int stopped_by_watchpoint
;
6123 enum stop_kind stop_soon
;
6126 gdb_assert (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
6128 ecs
->event_thread
->suspend
.stop_signal
= ecs
->ws
.value
.sig
;
6130 /* Do we need to clean up the state of a thread that has
6131 completed a displaced single-step? (Doing so usually affects
6132 the PC, so do it here, before we set stop_pc.) */
6133 if (finish_step_over (ecs
))
6136 /* If we either finished a single-step or hit a breakpoint, but
6137 the user wanted this thread to be stopped, pretend we got a
6138 SIG0 (generic unsignaled stop). */
6139 if (ecs
->event_thread
->stop_requested
6140 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
6141 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
6143 ecs
->event_thread
->suspend
.stop_pc
6144 = regcache_read_pc (get_thread_regcache (ecs
->event_thread
));
6146 context_switch (ecs
);
6148 if (deprecated_context_hook
)
6149 deprecated_context_hook (ecs
->event_thread
->global_num
);
6153 struct regcache
*regcache
= get_thread_regcache (ecs
->event_thread
);
6154 struct gdbarch
*reg_gdbarch
= regcache
->arch ();
6156 infrun_debug_printf ("stop_pc=%s",
6157 paddress (reg_gdbarch
,
6158 ecs
->event_thread
->suspend
.stop_pc
));
6159 if (target_stopped_by_watchpoint ())
6163 infrun_debug_printf ("stopped by watchpoint");
6165 if (target_stopped_data_address (current_inferior ()->top_target (),
6167 infrun_debug_printf ("stopped data address=%s",
6168 paddress (reg_gdbarch
, addr
));
6170 infrun_debug_printf ("(no data address available)");
6174 /* This is originated from start_remote(), start_inferior() and
6175 shared libraries hook functions. */
6176 stop_soon
= get_inferior_stop_soon (ecs
);
6177 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_REMOTE
)
6179 infrun_debug_printf ("quietly stopped");
6180 stop_print_frame
= true;
6185 /* This originates from attach_command(). We need to overwrite
6186 the stop_signal here, because some kernels don't ignore a
6187 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
6188 See more comments in inferior.h. On the other hand, if we
6189 get a non-SIGSTOP, report it to the user - assume the backend
6190 will handle the SIGSTOP if it should show up later.
6192 Also consider that the attach is complete when we see a
6193 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
6194 target extended-remote report it instead of a SIGSTOP
6195 (e.g. gdbserver). We already rely on SIGTRAP being our
6196 signal, so this is no exception.
6198 Also consider that the attach is complete when we see a
6199 GDB_SIGNAL_0. In non-stop mode, GDB will explicitly tell
6200 the target to stop all threads of the inferior, in case the
6201 low level attach operation doesn't stop them implicitly. If
6202 they weren't stopped implicitly, then the stub will report a
6203 GDB_SIGNAL_0, meaning: stopped for no particular reason
6204 other than GDB's request. */
6205 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
6206 && (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_STOP
6207 || ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
6208 || ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_0
))
6210 stop_print_frame
= true;
6212 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
6216 /* At this point, get hold of the now-current thread's frame. */
6217 frame
= get_current_frame ();
6218 gdbarch
= get_frame_arch (frame
);
6220 /* Pull the single step breakpoints out of the target. */
6221 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
6223 struct regcache
*regcache
;
6226 regcache
= get_thread_regcache (ecs
->event_thread
);
6227 const address_space
*aspace
= regcache
->aspace ();
6229 pc
= regcache_read_pc (regcache
);
6231 /* However, before doing so, if this single-step breakpoint was
6232 actually for another thread, set this thread up for moving
6234 if (!thread_has_single_step_breakpoint_here (ecs
->event_thread
,
6237 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
6239 infrun_debug_printf ("[%s] hit another thread's single-step "
6241 target_pid_to_str (ecs
->ptid
).c_str ());
6242 ecs
->hit_singlestep_breakpoint
= 1;
6247 infrun_debug_printf ("[%s] hit its single-step breakpoint",
6248 target_pid_to_str (ecs
->ptid
).c_str ());
6251 delete_just_stopped_threads_single_step_breakpoints ();
6253 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
6254 && ecs
->event_thread
->control
.trap_expected
6255 && ecs
->event_thread
->stepping_over_watchpoint
)
6256 stopped_by_watchpoint
= 0;
6258 stopped_by_watchpoint
= watchpoints_triggered (&ecs
->ws
);
6260 /* If necessary, step over this watchpoint. We'll be back to display
6262 if (stopped_by_watchpoint
6263 && (target_have_steppable_watchpoint ()
6264 || gdbarch_have_nonsteppable_watchpoint (gdbarch
)))
6266 /* At this point, we are stopped at an instruction which has
6267 attempted to write to a piece of memory under control of
6268 a watchpoint. The instruction hasn't actually executed
6269 yet. If we were to evaluate the watchpoint expression
6270 now, we would get the old value, and therefore no change
6271 would seem to have occurred.
6273 In order to make watchpoints work `right', we really need
6274 to complete the memory write, and then evaluate the
6275 watchpoint expression. We do this by single-stepping the
6278 It may not be necessary to disable the watchpoint to step over
6279 it. For example, the PA can (with some kernel cooperation)
6280 single step over a watchpoint without disabling the watchpoint.
6282 It is far more common to need to disable a watchpoint to step
6283 the inferior over it. If we have non-steppable watchpoints,
6284 we must disable the current watchpoint; it's simplest to
6285 disable all watchpoints.
6287 Any breakpoint at PC must also be stepped over -- if there's
6288 one, it will have already triggered before the watchpoint
6289 triggered, and we either already reported it to the user, or
6290 it didn't cause a stop and we called keep_going. In either
6291 case, if there was a breakpoint at PC, we must be trying to
6293 ecs
->event_thread
->stepping_over_watchpoint
= 1;
6298 ecs
->event_thread
->stepping_over_breakpoint
= 0;
6299 ecs
->event_thread
->stepping_over_watchpoint
= 0;
6300 bpstat_clear (&ecs
->event_thread
->control
.stop_bpstat
);
6301 ecs
->event_thread
->control
.stop_step
= 0;
6302 stop_print_frame
= true;
6303 stopped_by_random_signal
= 0;
6304 bpstat stop_chain
= NULL
;
6306 /* Hide inlined functions starting here, unless we just performed stepi or
6307 nexti. After stepi and nexti, always show the innermost frame (not any
6308 inline function call sites). */
6309 if (ecs
->event_thread
->control
.step_range_end
!= 1)
6311 const address_space
*aspace
6312 = get_thread_regcache (ecs
->event_thread
)->aspace ();
6314 /* skip_inline_frames is expensive, so we avoid it if we can
6315 determine that the address is one where functions cannot have
6316 been inlined. This improves performance with inferiors that
6317 load a lot of shared libraries, because the solib event
6318 breakpoint is defined as the address of a function (i.e. not
6319 inline). Note that we have to check the previous PC as well
6320 as the current one to catch cases when we have just
6321 single-stepped off a breakpoint prior to reinstating it.
6322 Note that we're assuming that the code we single-step to is
6323 not inline, but that's not definitive: there's nothing
6324 preventing the event breakpoint function from containing
6325 inlined code, and the single-step ending up there. If the
6326 user had set a breakpoint on that inlined code, the missing
6327 skip_inline_frames call would break things. Fortunately
6328 that's an extremely unlikely scenario. */
6329 if (!pc_at_non_inline_function (aspace
,
6330 ecs
->event_thread
->suspend
.stop_pc
,
6332 && !(ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
6333 && ecs
->event_thread
->control
.trap_expected
6334 && pc_at_non_inline_function (aspace
,
6335 ecs
->event_thread
->prev_pc
,
6338 stop_chain
= build_bpstat_chain (aspace
,
6339 ecs
->event_thread
->suspend
.stop_pc
,
6341 skip_inline_frames (ecs
->event_thread
, stop_chain
);
6343 /* Re-fetch current thread's frame in case that invalidated
6345 frame
= get_current_frame ();
6346 gdbarch
= get_frame_arch (frame
);
6350 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
6351 && ecs
->event_thread
->control
.trap_expected
6352 && gdbarch_single_step_through_delay_p (gdbarch
)
6353 && currently_stepping (ecs
->event_thread
))
6355 /* We're trying to step off a breakpoint. Turns out that we're
6356 also on an instruction that needs to be stepped multiple
6357 times before it's been fully executing. E.g., architectures
6358 with a delay slot. It needs to be stepped twice, once for
6359 the instruction and once for the delay slot. */
6360 int step_through_delay
6361 = gdbarch_single_step_through_delay (gdbarch
, frame
);
6363 if (step_through_delay
)
6364 infrun_debug_printf ("step through delay");
6366 if (ecs
->event_thread
->control
.step_range_end
== 0
6367 && step_through_delay
)
6369 /* The user issued a continue when stopped at a breakpoint.
6370 Set up for another trap and get out of here. */
6371 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6375 else if (step_through_delay
)
6377 /* The user issued a step when stopped at a breakpoint.
6378 Maybe we should stop, maybe we should not - the delay
6379 slot *might* correspond to a line of source. In any
6380 case, don't decide that here, just set
6381 ecs->stepping_over_breakpoint, making sure we
6382 single-step again before breakpoints are re-inserted. */
6383 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6387 /* See if there is a breakpoint/watchpoint/catchpoint/etc. that
6388 handles this event. */
6389 ecs
->event_thread
->control
.stop_bpstat
6390 = bpstat_stop_status (get_current_regcache ()->aspace (),
6391 ecs
->event_thread
->suspend
.stop_pc
,
6392 ecs
->event_thread
, &ecs
->ws
, stop_chain
);
6394 /* Following in case break condition called a
6396 stop_print_frame
= true;
6398 /* This is where we handle "moribund" watchpoints. Unlike
6399 software breakpoints traps, hardware watchpoint traps are
6400 always distinguishable from random traps. If no high-level
6401 watchpoint is associated with the reported stop data address
6402 anymore, then the bpstat does not explain the signal ---
6403 simply make sure to ignore it if `stopped_by_watchpoint' is
6406 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
6407 && !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
6409 && stopped_by_watchpoint
)
6411 infrun_debug_printf ("no user watchpoint explains watchpoint SIGTRAP, "
6415 /* NOTE: cagney/2003-03-29: These checks for a random signal
6416 at one stage in the past included checks for an inferior
6417 function call's call dummy's return breakpoint. The original
6418 comment, that went with the test, read:
6420 ``End of a stack dummy. Some systems (e.g. Sony news) give
6421 another signal besides SIGTRAP, so check here as well as
6424 If someone ever tries to get call dummys on a
6425 non-executable stack to work (where the target would stop
6426 with something like a SIGSEGV), then those tests might need
6427 to be re-instated. Given, however, that the tests were only
6428 enabled when momentary breakpoints were not being used, I
6429 suspect that it won't be the case.
6431 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
6432 be necessary for call dummies on a non-executable stack on
6435 /* See if the breakpoints module can explain the signal. */
6437 = !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
6438 ecs
->event_thread
->suspend
.stop_signal
);
6440 /* Maybe this was a trap for a software breakpoint that has since
6442 if (random_signal
&& target_stopped_by_sw_breakpoint ())
6444 if (gdbarch_program_breakpoint_here_p (gdbarch
,
6445 ecs
->event_thread
->suspend
.stop_pc
))
6447 struct regcache
*regcache
;
6450 /* Re-adjust PC to what the program would see if GDB was not
6452 regcache
= get_thread_regcache (ecs
->event_thread
);
6453 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
6456 gdb::optional
<scoped_restore_tmpl
<int>>
6457 restore_operation_disable
;
6459 if (record_full_is_used ())
6460 restore_operation_disable
.emplace
6461 (record_full_gdb_operation_disable_set ());
6463 regcache_write_pc (regcache
,
6464 ecs
->event_thread
->suspend
.stop_pc
+ decr_pc
);
6469 /* A delayed software breakpoint event. Ignore the trap. */
6470 infrun_debug_printf ("delayed software breakpoint trap, ignoring");
6475 /* Maybe this was a trap for a hardware breakpoint/watchpoint that
6476 has since been removed. */
6477 if (random_signal
&& target_stopped_by_hw_breakpoint ())
6479 /* A delayed hardware breakpoint event. Ignore the trap. */
6480 infrun_debug_printf ("delayed hardware breakpoint/watchpoint "
6485 /* If not, perhaps stepping/nexting can. */
6487 random_signal
= !(ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
6488 && currently_stepping (ecs
->event_thread
));
6490 /* Perhaps the thread hit a single-step breakpoint of _another_
6491 thread. Single-step breakpoints are transparent to the
6492 breakpoints module. */
6494 random_signal
= !ecs
->hit_singlestep_breakpoint
;
6496 /* No? Perhaps we got a moribund watchpoint. */
6498 random_signal
= !stopped_by_watchpoint
;
6500 /* Always stop if the user explicitly requested this thread to
6502 if (ecs
->event_thread
->stop_requested
)
6505 infrun_debug_printf ("user-requested stop");
6508 /* For the program's own signals, act according to
6509 the signal handling tables. */
6513 /* Signal not for debugging purposes. */
6514 enum gdb_signal stop_signal
= ecs
->event_thread
->suspend
.stop_signal
;
6516 infrun_debug_printf ("random signal (%s)",
6517 gdb_signal_to_symbol_string (stop_signal
));
6519 stopped_by_random_signal
= 1;
6521 /* Always stop on signals if we're either just gaining control
6522 of the program, or the user explicitly requested this thread
6523 to remain stopped. */
6524 if (stop_soon
!= NO_STOP_QUIETLY
6525 || ecs
->event_thread
->stop_requested
6526 || signal_stop_state (ecs
->event_thread
->suspend
.stop_signal
))
6532 /* Notify observers the signal has "handle print" set. Note we
6533 returned early above if stopping; normal_stop handles the
6534 printing in that case. */
6535 if (signal_print
[ecs
->event_thread
->suspend
.stop_signal
])
6537 /* The signal table tells us to print about this signal. */
6538 target_terminal::ours_for_output ();
6539 gdb::observers::signal_received
.notify (ecs
->event_thread
->suspend
.stop_signal
);
6540 target_terminal::inferior ();
6543 /* Clear the signal if it should not be passed. */
6544 if (signal_program
[ecs
->event_thread
->suspend
.stop_signal
] == 0)
6545 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
6547 if (ecs
->event_thread
->prev_pc
== ecs
->event_thread
->suspend
.stop_pc
6548 && ecs
->event_thread
->control
.trap_expected
6549 && ecs
->event_thread
->control
.step_resume_breakpoint
== NULL
)
6551 /* We were just starting a new sequence, attempting to
6552 single-step off of a breakpoint and expecting a SIGTRAP.
6553 Instead this signal arrives. This signal will take us out
6554 of the stepping range so GDB needs to remember to, when
6555 the signal handler returns, resume stepping off that
6557 /* To simplify things, "continue" is forced to use the same
6558 code paths as single-step - set a breakpoint at the
6559 signal return address and then, once hit, step off that
6561 infrun_debug_printf ("signal arrived while stepping over breakpoint");
6563 insert_hp_step_resume_breakpoint_at_frame (frame
);
6564 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
6565 /* Reset trap_expected to ensure breakpoints are re-inserted. */
6566 ecs
->event_thread
->control
.trap_expected
= 0;
6568 /* If we were nexting/stepping some other thread, switch to
6569 it, so that we don't continue it, losing control. */
6570 if (!switch_back_to_stepped_thread (ecs
))
6575 if (ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
6576 && (pc_in_thread_step_range (ecs
->event_thread
->suspend
.stop_pc
,
6578 || ecs
->event_thread
->control
.step_range_end
== 1)
6579 && frame_id_eq (get_stack_frame_id (frame
),
6580 ecs
->event_thread
->control
.step_stack_frame_id
)
6581 && ecs
->event_thread
->control
.step_resume_breakpoint
== NULL
)
6583 /* The inferior is about to take a signal that will take it
6584 out of the single step range. Set a breakpoint at the
6585 current PC (which is presumably where the signal handler
6586 will eventually return) and then allow the inferior to
6589 Note that this is only needed for a signal delivered
6590 while in the single-step range. Nested signals aren't a
6591 problem as they eventually all return. */
6592 infrun_debug_printf ("signal may take us out of single-step range");
6594 clear_step_over_info ();
6595 insert_hp_step_resume_breakpoint_at_frame (frame
);
6596 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
6597 /* Reset trap_expected to ensure breakpoints are re-inserted. */
6598 ecs
->event_thread
->control
.trap_expected
= 0;
6603 /* Note: step_resume_breakpoint may be non-NULL. This occurs
6604 when either there's a nested signal, or when there's a
6605 pending signal enabled just as the signal handler returns
6606 (leaving the inferior at the step-resume-breakpoint without
6607 actually executing it). Either way continue until the
6608 breakpoint is really hit. */
6610 if (!switch_back_to_stepped_thread (ecs
))
6612 infrun_debug_printf ("random signal, keep going");
6619 process_event_stop_test (ecs
);
6622 /* Come here when we've got some debug event / signal we can explain
6623 (IOW, not a random signal), and test whether it should cause a
6624 stop, or whether we should resume the inferior (transparently).
6625 E.g., could be a breakpoint whose condition evaluates false; we
6626 could be still stepping within the line; etc. */
6629 process_event_stop_test (struct execution_control_state
*ecs
)
6631 struct symtab_and_line stop_pc_sal
;
6632 struct frame_info
*frame
;
6633 struct gdbarch
*gdbarch
;
6634 CORE_ADDR jmp_buf_pc
;
6635 struct bpstat_what what
;
6637 /* Handle cases caused by hitting a breakpoint. */
6639 frame
= get_current_frame ();
6640 gdbarch
= get_frame_arch (frame
);
6642 what
= bpstat_what (ecs
->event_thread
->control
.stop_bpstat
);
6644 if (what
.call_dummy
)
6646 stop_stack_dummy
= what
.call_dummy
;
6649 /* A few breakpoint types have callbacks associated (e.g.,
6650 bp_jit_event). Run them now. */
6651 bpstat_run_callbacks (ecs
->event_thread
->control
.stop_bpstat
);
6653 /* If we hit an internal event that triggers symbol changes, the
6654 current frame will be invalidated within bpstat_what (e.g., if we
6655 hit an internal solib event). Re-fetch it. */
6656 frame
= get_current_frame ();
6657 gdbarch
= get_frame_arch (frame
);
6659 switch (what
.main_action
)
6661 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
6662 /* If we hit the breakpoint at longjmp while stepping, we
6663 install a momentary breakpoint at the target of the
6666 infrun_debug_printf ("BPSTAT_WHAT_SET_LONGJMP_RESUME");
6668 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6670 if (what
.is_longjmp
)
6672 struct value
*arg_value
;
6674 /* If we set the longjmp breakpoint via a SystemTap probe,
6675 then use it to extract the arguments. The destination PC
6676 is the third argument to the probe. */
6677 arg_value
= probe_safe_evaluate_at_pc (frame
, 2);
6680 jmp_buf_pc
= value_as_address (arg_value
);
6681 jmp_buf_pc
= gdbarch_addr_bits_remove (gdbarch
, jmp_buf_pc
);
6683 else if (!gdbarch_get_longjmp_target_p (gdbarch
)
6684 || !gdbarch_get_longjmp_target (gdbarch
,
6685 frame
, &jmp_buf_pc
))
6687 infrun_debug_printf ("BPSTAT_WHAT_SET_LONGJMP_RESUME "
6688 "(!gdbarch_get_longjmp_target)");
6693 /* Insert a breakpoint at resume address. */
6694 insert_longjmp_resume_breakpoint (gdbarch
, jmp_buf_pc
);
6697 check_exception_resume (ecs
, frame
);
6701 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
6703 struct frame_info
*init_frame
;
6705 /* There are several cases to consider.
6707 1. The initiating frame no longer exists. In this case we
6708 must stop, because the exception or longjmp has gone too
6711 2. The initiating frame exists, and is the same as the
6712 current frame. We stop, because the exception or longjmp
6715 3. The initiating frame exists and is different from the
6716 current frame. This means the exception or longjmp has
6717 been caught beneath the initiating frame, so keep going.
6719 4. longjmp breakpoint has been placed just to protect
6720 against stale dummy frames and user is not interested in
6721 stopping around longjmps. */
6723 infrun_debug_printf ("BPSTAT_WHAT_CLEAR_LONGJMP_RESUME");
6725 gdb_assert (ecs
->event_thread
->control
.exception_resume_breakpoint
6727 delete_exception_resume_breakpoint (ecs
->event_thread
);
6729 if (what
.is_longjmp
)
6731 check_longjmp_breakpoint_for_call_dummy (ecs
->event_thread
);
6733 if (!frame_id_p (ecs
->event_thread
->initiating_frame
))
6741 init_frame
= frame_find_by_id (ecs
->event_thread
->initiating_frame
);
6745 struct frame_id current_id
6746 = get_frame_id (get_current_frame ());
6747 if (frame_id_eq (current_id
,
6748 ecs
->event_thread
->initiating_frame
))
6750 /* Case 2. Fall through. */
6760 /* For Cases 1 and 2, remove the step-resume breakpoint, if it
6762 delete_step_resume_breakpoint (ecs
->event_thread
);
6764 end_stepping_range (ecs
);
6768 case BPSTAT_WHAT_SINGLE
:
6769 infrun_debug_printf ("BPSTAT_WHAT_SINGLE");
6770 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6771 /* Still need to check other stuff, at least the case where we
6772 are stepping and step out of the right range. */
6775 case BPSTAT_WHAT_STEP_RESUME
:
6776 infrun_debug_printf ("BPSTAT_WHAT_STEP_RESUME");
6778 delete_step_resume_breakpoint (ecs
->event_thread
);
6779 if (ecs
->event_thread
->control
.proceed_to_finish
6780 && execution_direction
== EXEC_REVERSE
)
6782 struct thread_info
*tp
= ecs
->event_thread
;
6784 /* We are finishing a function in reverse, and just hit the
6785 step-resume breakpoint at the start address of the
6786 function, and we're almost there -- just need to back up
6787 by one more single-step, which should take us back to the
6789 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
6793 fill_in_stop_func (gdbarch
, ecs
);
6794 if (ecs
->event_thread
->suspend
.stop_pc
== ecs
->stop_func_start
6795 && execution_direction
== EXEC_REVERSE
)
6797 /* We are stepping over a function call in reverse, and just
6798 hit the step-resume breakpoint at the start address of
6799 the function. Go back to single-stepping, which should
6800 take us back to the function call. */
6801 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6807 case BPSTAT_WHAT_STOP_NOISY
:
6808 infrun_debug_printf ("BPSTAT_WHAT_STOP_NOISY");
6809 stop_print_frame
= true;
6811 /* Assume the thread stopped for a breakpoint. We'll still check
6812 whether a/the breakpoint is there when the thread is next
6814 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6819 case BPSTAT_WHAT_STOP_SILENT
:
6820 infrun_debug_printf ("BPSTAT_WHAT_STOP_SILENT");
6821 stop_print_frame
= false;
6823 /* Assume the thread stopped for a breakpoint. We'll still check
6824 whether a/the breakpoint is there when the thread is next
6826 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6830 case BPSTAT_WHAT_HP_STEP_RESUME
:
6831 infrun_debug_printf ("BPSTAT_WHAT_HP_STEP_RESUME");
6833 delete_step_resume_breakpoint (ecs
->event_thread
);
6834 if (ecs
->event_thread
->step_after_step_resume_breakpoint
)
6836 /* Back when the step-resume breakpoint was inserted, we
6837 were trying to single-step off a breakpoint. Go back to
6839 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
6840 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6846 case BPSTAT_WHAT_KEEP_CHECKING
:
6850 /* If we stepped a permanent breakpoint and we had a high priority
6851 step-resume breakpoint for the address we stepped, but we didn't
6852 hit it, then we must have stepped into the signal handler. The
6853 step-resume was only necessary to catch the case of _not_
6854 stepping into the handler, so delete it, and fall through to
6855 checking whether the step finished. */
6856 if (ecs
->event_thread
->stepped_breakpoint
)
6858 struct breakpoint
*sr_bp
6859 = ecs
->event_thread
->control
.step_resume_breakpoint
;
6862 && sr_bp
->loc
->permanent
6863 && sr_bp
->type
== bp_hp_step_resume
6864 && sr_bp
->loc
->address
== ecs
->event_thread
->prev_pc
)
6866 infrun_debug_printf ("stepped permanent breakpoint, stopped in handler");
6867 delete_step_resume_breakpoint (ecs
->event_thread
);
6868 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
6872 /* We come here if we hit a breakpoint but should not stop for it.
6873 Possibly we also were stepping and should stop for that. So fall
6874 through and test for stepping. But, if not stepping, do not
6877 /* In all-stop mode, if we're currently stepping but have stopped in
6878 some other thread, we need to switch back to the stepped thread. */
6879 if (switch_back_to_stepped_thread (ecs
))
6882 if (ecs
->event_thread
->control
.step_resume_breakpoint
)
6884 infrun_debug_printf ("step-resume breakpoint is inserted");
6886 /* Having a step-resume breakpoint overrides anything
6887 else having to do with stepping commands until
6888 that breakpoint is reached. */
6893 if (ecs
->event_thread
->control
.step_range_end
== 0)
6895 infrun_debug_printf ("no stepping, continue");
6896 /* Likewise if we aren't even stepping. */
6901 /* Re-fetch current thread's frame in case the code above caused
6902 the frame cache to be re-initialized, making our FRAME variable
6903 a dangling pointer. */
6904 frame
= get_current_frame ();
6905 gdbarch
= get_frame_arch (frame
);
6906 fill_in_stop_func (gdbarch
, ecs
);
6908 /* If stepping through a line, keep going if still within it.
6910 Note that step_range_end is the address of the first instruction
6911 beyond the step range, and NOT the address of the last instruction
6914 Note also that during reverse execution, we may be stepping
6915 through a function epilogue and therefore must detect when
6916 the current-frame changes in the middle of a line. */
6918 if (pc_in_thread_step_range (ecs
->event_thread
->suspend
.stop_pc
,
6920 && (execution_direction
!= EXEC_REVERSE
6921 || frame_id_eq (get_frame_id (frame
),
6922 ecs
->event_thread
->control
.step_frame_id
)))
6925 ("stepping inside range [%s-%s]",
6926 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_start
),
6927 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_end
));
6929 /* Tentatively re-enable range stepping; `resume' disables it if
6930 necessary (e.g., if we're stepping over a breakpoint or we
6931 have software watchpoints). */
6932 ecs
->event_thread
->control
.may_range_step
= 1;
6934 /* When stepping backward, stop at beginning of line range
6935 (unless it's the function entry point, in which case
6936 keep going back to the call point). */
6937 CORE_ADDR stop_pc
= ecs
->event_thread
->suspend
.stop_pc
;
6938 if (stop_pc
== ecs
->event_thread
->control
.step_range_start
6939 && stop_pc
!= ecs
->stop_func_start
6940 && execution_direction
== EXEC_REVERSE
)
6941 end_stepping_range (ecs
);
6948 /* We stepped out of the stepping range. */
6950 /* If we are stepping at the source level and entered the runtime
6951 loader dynamic symbol resolution code...
6953 EXEC_FORWARD: we keep on single stepping until we exit the run
6954 time loader code and reach the callee's address.
6956 EXEC_REVERSE: we've already executed the callee (backward), and
6957 the runtime loader code is handled just like any other
6958 undebuggable function call. Now we need only keep stepping
6959 backward through the trampoline code, and that's handled further
6960 down, so there is nothing for us to do here. */
6962 if (execution_direction
!= EXEC_REVERSE
6963 && ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
6964 && in_solib_dynsym_resolve_code (ecs
->event_thread
->suspend
.stop_pc
))
6966 CORE_ADDR pc_after_resolver
=
6967 gdbarch_skip_solib_resolver (gdbarch
,
6968 ecs
->event_thread
->suspend
.stop_pc
);
6970 infrun_debug_printf ("stepped into dynsym resolve code");
6972 if (pc_after_resolver
)
6974 /* Set up a step-resume breakpoint at the address
6975 indicated by SKIP_SOLIB_RESOLVER. */
6976 symtab_and_line sr_sal
;
6977 sr_sal
.pc
= pc_after_resolver
;
6978 sr_sal
.pspace
= get_frame_program_space (frame
);
6980 insert_step_resume_breakpoint_at_sal (gdbarch
,
6981 sr_sal
, null_frame_id
);
6988 /* Step through an indirect branch thunk. */
6989 if (ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
6990 && gdbarch_in_indirect_branch_thunk (gdbarch
,
6991 ecs
->event_thread
->suspend
.stop_pc
))
6993 infrun_debug_printf ("stepped into indirect branch thunk");
6998 if (ecs
->event_thread
->control
.step_range_end
!= 1
6999 && (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
7000 || ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
7001 && get_frame_type (frame
) == SIGTRAMP_FRAME
)
7003 infrun_debug_printf ("stepped into signal trampoline");
7004 /* The inferior, while doing a "step" or "next", has ended up in
7005 a signal trampoline (either by a signal being delivered or by
7006 the signal handler returning). Just single-step until the
7007 inferior leaves the trampoline (either by calling the handler
7013 /* If we're in the return path from a shared library trampoline,
7014 we want to proceed through the trampoline when stepping. */
7015 /* macro/2012-04-25: This needs to come before the subroutine
7016 call check below as on some targets return trampolines look
7017 like subroutine calls (MIPS16 return thunks). */
7018 if (gdbarch_in_solib_return_trampoline (gdbarch
,
7019 ecs
->event_thread
->suspend
.stop_pc
,
7020 ecs
->stop_func_name
)
7021 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
7023 /* Determine where this trampoline returns. */
7024 CORE_ADDR stop_pc
= ecs
->event_thread
->suspend
.stop_pc
;
7025 CORE_ADDR real_stop_pc
7026 = gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
7028 infrun_debug_printf ("stepped into solib return tramp");
7030 /* Only proceed through if we know where it's going. */
7033 /* And put the step-breakpoint there and go until there. */
7034 symtab_and_line sr_sal
;
7035 sr_sal
.pc
= real_stop_pc
;
7036 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
7037 sr_sal
.pspace
= get_frame_program_space (frame
);
7039 /* Do not specify what the fp should be when we stop since
7040 on some machines the prologue is where the new fp value
7042 insert_step_resume_breakpoint_at_sal (gdbarch
,
7043 sr_sal
, null_frame_id
);
7045 /* Restart without fiddling with the step ranges or
7052 /* Check for subroutine calls. The check for the current frame
7053 equalling the step ID is not necessary - the check of the
7054 previous frame's ID is sufficient - but it is a common case and
7055 cheaper than checking the previous frame's ID.
7057 NOTE: frame_id_eq will never report two invalid frame IDs as
7058 being equal, so to get into this block, both the current and
7059 previous frame must have valid frame IDs. */
7060 /* The outer_frame_id check is a heuristic to detect stepping
7061 through startup code. If we step over an instruction which
7062 sets the stack pointer from an invalid value to a valid value,
7063 we may detect that as a subroutine call from the mythical
7064 "outermost" function. This could be fixed by marking
7065 outermost frames as !stack_p,code_p,special_p. Then the
7066 initial outermost frame, before sp was valid, would
7067 have code_addr == &_start. See the comment in frame_id_eq
7069 if (!frame_id_eq (get_stack_frame_id (frame
),
7070 ecs
->event_thread
->control
.step_stack_frame_id
)
7071 && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()),
7072 ecs
->event_thread
->control
.step_stack_frame_id
)
7073 && (!frame_id_eq (ecs
->event_thread
->control
.step_stack_frame_id
,
7075 || (ecs
->event_thread
->control
.step_start_function
7076 != find_pc_function (ecs
->event_thread
->suspend
.stop_pc
)))))
7078 CORE_ADDR stop_pc
= ecs
->event_thread
->suspend
.stop_pc
;
7079 CORE_ADDR real_stop_pc
;
7081 infrun_debug_printf ("stepped into subroutine");
7083 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_NONE
)
7085 /* I presume that step_over_calls is only 0 when we're
7086 supposed to be stepping at the assembly language level
7087 ("stepi"). Just stop. */
7088 /* And this works the same backward as frontward. MVS */
7089 end_stepping_range (ecs
);
7093 /* Reverse stepping through solib trampolines. */
7095 if (execution_direction
== EXEC_REVERSE
7096 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
7097 && (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
7098 || (ecs
->stop_func_start
== 0
7099 && in_solib_dynsym_resolve_code (stop_pc
))))
7101 /* Any solib trampoline code can be handled in reverse
7102 by simply continuing to single-step. We have already
7103 executed the solib function (backwards), and a few
7104 steps will take us back through the trampoline to the
7110 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
7112 /* We're doing a "next".
7114 Normal (forward) execution: set a breakpoint at the
7115 callee's return address (the address at which the caller
7118 Reverse (backward) execution. set the step-resume
7119 breakpoint at the start of the function that we just
7120 stepped into (backwards), and continue to there. When we
7121 get there, we'll need to single-step back to the caller. */
7123 if (execution_direction
== EXEC_REVERSE
)
7125 /* If we're already at the start of the function, we've either
7126 just stepped backward into a single instruction function,
7127 or stepped back out of a signal handler to the first instruction
7128 of the function. Just keep going, which will single-step back
7130 if (ecs
->stop_func_start
!= stop_pc
&& ecs
->stop_func_start
!= 0)
7132 /* Normal function call return (static or dynamic). */
7133 symtab_and_line sr_sal
;
7134 sr_sal
.pc
= ecs
->stop_func_start
;
7135 sr_sal
.pspace
= get_frame_program_space (frame
);
7136 insert_step_resume_breakpoint_at_sal (gdbarch
,
7137 sr_sal
, null_frame_id
);
7141 insert_step_resume_breakpoint_at_caller (frame
);
7147 /* If we are in a function call trampoline (a stub between the
7148 calling routine and the real function), locate the real
7149 function. That's what tells us (a) whether we want to step
7150 into it at all, and (b) what prologue we want to run to the
7151 end of, if we do step into it. */
7152 real_stop_pc
= skip_language_trampoline (frame
, stop_pc
);
7153 if (real_stop_pc
== 0)
7154 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
7155 if (real_stop_pc
!= 0)
7156 ecs
->stop_func_start
= real_stop_pc
;
7158 if (real_stop_pc
!= 0 && in_solib_dynsym_resolve_code (real_stop_pc
))
7160 symtab_and_line sr_sal
;
7161 sr_sal
.pc
= ecs
->stop_func_start
;
7162 sr_sal
.pspace
= get_frame_program_space (frame
);
7164 insert_step_resume_breakpoint_at_sal (gdbarch
,
7165 sr_sal
, null_frame_id
);
7170 /* If we have line number information for the function we are
7171 thinking of stepping into and the function isn't on the skip
7174 If there are several symtabs at that PC (e.g. with include
7175 files), just want to know whether *any* of them have line
7176 numbers. find_pc_line handles this. */
7178 struct symtab_and_line tmp_sal
;
7180 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
7181 if (tmp_sal
.line
!= 0
7182 && !function_name_is_marked_for_skip (ecs
->stop_func_name
,
7184 && !inline_frame_is_marked_for_skip (true, ecs
->event_thread
))
7186 if (execution_direction
== EXEC_REVERSE
)
7187 handle_step_into_function_backward (gdbarch
, ecs
);
7189 handle_step_into_function (gdbarch
, ecs
);
7194 /* If we have no line number and the step-stop-if-no-debug is
7195 set, we stop the step so that the user has a chance to switch
7196 in assembly mode. */
7197 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
7198 && step_stop_if_no_debug
)
7200 end_stepping_range (ecs
);
7204 if (execution_direction
== EXEC_REVERSE
)
7206 /* If we're already at the start of the function, we've either just
7207 stepped backward into a single instruction function without line
7208 number info, or stepped back out of a signal handler to the first
7209 instruction of the function without line number info. Just keep
7210 going, which will single-step back to the caller. */
7211 if (ecs
->stop_func_start
!= stop_pc
)
7213 /* Set a breakpoint at callee's start address.
7214 From there we can step once and be back in the caller. */
7215 symtab_and_line sr_sal
;
7216 sr_sal
.pc
= ecs
->stop_func_start
;
7217 sr_sal
.pspace
= get_frame_program_space (frame
);
7218 insert_step_resume_breakpoint_at_sal (gdbarch
,
7219 sr_sal
, null_frame_id
);
7223 /* Set a breakpoint at callee's return address (the address
7224 at which the caller will resume). */
7225 insert_step_resume_breakpoint_at_caller (frame
);
7231 /* Reverse stepping through solib trampolines. */
7233 if (execution_direction
== EXEC_REVERSE
7234 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
7236 CORE_ADDR stop_pc
= ecs
->event_thread
->suspend
.stop_pc
;
7238 if (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
7239 || (ecs
->stop_func_start
== 0
7240 && in_solib_dynsym_resolve_code (stop_pc
)))
7242 /* Any solib trampoline code can be handled in reverse
7243 by simply continuing to single-step. We have already
7244 executed the solib function (backwards), and a few
7245 steps will take us back through the trampoline to the
7250 else if (in_solib_dynsym_resolve_code (stop_pc
))
7252 /* Stepped backward into the solib dynsym resolver.
7253 Set a breakpoint at its start and continue, then
7254 one more step will take us out. */
7255 symtab_and_line sr_sal
;
7256 sr_sal
.pc
= ecs
->stop_func_start
;
7257 sr_sal
.pspace
= get_frame_program_space (frame
);
7258 insert_step_resume_breakpoint_at_sal (gdbarch
,
7259 sr_sal
, null_frame_id
);
7265 /* This always returns the sal for the inner-most frame when we are in a
7266 stack of inlined frames, even if GDB actually believes that it is in a
7267 more outer frame. This is checked for below by calls to
7268 inline_skipped_frames. */
7269 stop_pc_sal
= find_pc_line (ecs
->event_thread
->suspend
.stop_pc
, 0);
7271 /* NOTE: tausq/2004-05-24: This if block used to be done before all
7272 the trampoline processing logic, however, there are some trampolines
7273 that have no names, so we should do trampoline handling first. */
7274 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
7275 && ecs
->stop_func_name
== NULL
7276 && stop_pc_sal
.line
== 0)
7278 infrun_debug_printf ("stepped into undebuggable function");
7280 /* The inferior just stepped into, or returned to, an
7281 undebuggable function (where there is no debugging information
7282 and no line number corresponding to the address where the
7283 inferior stopped). Since we want to skip this kind of code,
7284 we keep going until the inferior returns from this
7285 function - unless the user has asked us not to (via
7286 set step-mode) or we no longer know how to get back
7287 to the call site. */
7288 if (step_stop_if_no_debug
7289 || !frame_id_p (frame_unwind_caller_id (frame
)))
7291 /* If we have no line number and the step-stop-if-no-debug
7292 is set, we stop the step so that the user has a chance to
7293 switch in assembly mode. */
7294 end_stepping_range (ecs
);
7299 /* Set a breakpoint at callee's return address (the address
7300 at which the caller will resume). */
7301 insert_step_resume_breakpoint_at_caller (frame
);
7307 if (ecs
->event_thread
->control
.step_range_end
== 1)
7309 /* It is stepi or nexti. We always want to stop stepping after
7311 infrun_debug_printf ("stepi/nexti");
7312 end_stepping_range (ecs
);
7316 if (stop_pc_sal
.line
== 0)
7318 /* We have no line number information. That means to stop
7319 stepping (does this always happen right after one instruction,
7320 when we do "s" in a function with no line numbers,
7321 or can this happen as a result of a return or longjmp?). */
7322 infrun_debug_printf ("line number info");
7323 end_stepping_range (ecs
);
7327 /* Look for "calls" to inlined functions, part one. If the inline
7328 frame machinery detected some skipped call sites, we have entered
7329 a new inline function. */
7331 if (frame_id_eq (get_frame_id (get_current_frame ()),
7332 ecs
->event_thread
->control
.step_frame_id
)
7333 && inline_skipped_frames (ecs
->event_thread
))
7335 infrun_debug_printf ("stepped into inlined function");
7337 symtab_and_line call_sal
= find_frame_sal (get_current_frame ());
7339 if (ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_ALL
)
7341 /* For "step", we're going to stop. But if the call site
7342 for this inlined function is on the same source line as
7343 we were previously stepping, go down into the function
7344 first. Otherwise stop at the call site. */
7346 if (call_sal
.line
== ecs
->event_thread
->current_line
7347 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
7349 step_into_inline_frame (ecs
->event_thread
);
7350 if (inline_frame_is_marked_for_skip (false, ecs
->event_thread
))
7357 end_stepping_range (ecs
);
7362 /* For "next", we should stop at the call site if it is on a
7363 different source line. Otherwise continue through the
7364 inlined function. */
7365 if (call_sal
.line
== ecs
->event_thread
->current_line
7366 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
7369 end_stepping_range (ecs
);
7374 /* Look for "calls" to inlined functions, part two. If we are still
7375 in the same real function we were stepping through, but we have
7376 to go further up to find the exact frame ID, we are stepping
7377 through a more inlined call beyond its call site. */
7379 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
7380 && !frame_id_eq (get_frame_id (get_current_frame ()),
7381 ecs
->event_thread
->control
.step_frame_id
)
7382 && stepped_in_from (get_current_frame (),
7383 ecs
->event_thread
->control
.step_frame_id
))
7385 infrun_debug_printf ("stepping through inlined function");
7387 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
7388 || inline_frame_is_marked_for_skip (false, ecs
->event_thread
))
7391 end_stepping_range (ecs
);
7395 bool refresh_step_info
= true;
7396 if ((ecs
->event_thread
->suspend
.stop_pc
== stop_pc_sal
.pc
)
7397 && (ecs
->event_thread
->current_line
!= stop_pc_sal
.line
7398 || ecs
->event_thread
->current_symtab
!= stop_pc_sal
.symtab
))
7400 /* We are at a different line. */
7402 if (stop_pc_sal
.is_stmt
)
7404 /* We are at the start of a statement.
7406 So stop. Note that we don't stop if we step into the middle of a
7407 statement. That is said to make things like for (;;) statements
7409 infrun_debug_printf ("stepped to a different line");
7410 end_stepping_range (ecs
);
7413 else if (frame_id_eq (get_frame_id (get_current_frame ()),
7414 ecs
->event_thread
->control
.step_frame_id
))
7416 /* We are not at the start of a statement, and we have not changed
7419 We ignore this line table entry, and continue stepping forward,
7420 looking for a better place to stop. */
7421 refresh_step_info
= false;
7422 infrun_debug_printf ("stepped to a different line, but "
7423 "it's not the start of a statement");
7427 /* We are not the start of a statement, and we have changed frame.
7429 We ignore this line table entry, and continue stepping forward,
7430 looking for a better place to stop. Keep refresh_step_info at
7431 true to note that the frame has changed, but ignore the line
7432 number to make sure we don't ignore a subsequent entry with the
7433 same line number. */
7434 stop_pc_sal
.line
= 0;
7435 infrun_debug_printf ("stepped to a different frame, but "
7436 "it's not the start of a statement");
7440 /* We aren't done stepping.
7442 Optimize by setting the stepping range to the line.
7443 (We might not be in the original line, but if we entered a
7444 new line in mid-statement, we continue stepping. This makes
7445 things like for(;;) statements work better.)
7447 If we entered a SAL that indicates a non-statement line table entry,
7448 then we update the stepping range, but we don't update the step info,
7449 which includes things like the line number we are stepping away from.
7450 This means we will stop when we find a line table entry that is marked
7451 as is-statement, even if it matches the non-statement one we just
7454 ecs
->event_thread
->control
.step_range_start
= stop_pc_sal
.pc
;
7455 ecs
->event_thread
->control
.step_range_end
= stop_pc_sal
.end
;
7456 ecs
->event_thread
->control
.may_range_step
= 1;
7457 if (refresh_step_info
)
7458 set_step_info (ecs
->event_thread
, frame
, stop_pc_sal
);
7460 infrun_debug_printf ("keep going");
7464 static bool restart_stepped_thread (process_stratum_target
*resume_target
,
7465 ptid_t resume_ptid
);
7467 /* In all-stop mode, if we're currently stepping but have stopped in
7468 some other thread, we may need to switch back to the stepped
7469 thread. Returns true we set the inferior running, false if we left
7470 it stopped (and the event needs further processing). */
7473 switch_back_to_stepped_thread (struct execution_control_state
*ecs
)
7475 if (!target_is_non_stop_p ())
7477 /* If any thread is blocked on some internal breakpoint, and we
7478 simply need to step over that breakpoint to get it going
7479 again, do that first. */
7481 /* However, if we see an event for the stepping thread, then we
7482 know all other threads have been moved past their breakpoints
7483 already. Let the caller check whether the step is finished,
7484 etc., before deciding to move it past a breakpoint. */
7485 if (ecs
->event_thread
->control
.step_range_end
!= 0)
7488 /* Check if the current thread is blocked on an incomplete
7489 step-over, interrupted by a random signal. */
7490 if (ecs
->event_thread
->control
.trap_expected
7491 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_TRAP
)
7494 ("need to finish step-over of [%s]",
7495 target_pid_to_str (ecs
->event_thread
->ptid
).c_str ());
7500 /* Check if the current thread is blocked by a single-step
7501 breakpoint of another thread. */
7502 if (ecs
->hit_singlestep_breakpoint
)
7504 infrun_debug_printf ("need to step [%s] over single-step breakpoint",
7505 target_pid_to_str (ecs
->ptid
).c_str ());
7510 /* If this thread needs yet another step-over (e.g., stepping
7511 through a delay slot), do it first before moving on to
7513 if (thread_still_needs_step_over (ecs
->event_thread
))
7516 ("thread [%s] still needs step-over",
7517 target_pid_to_str (ecs
->event_thread
->ptid
).c_str ());
7522 /* If scheduler locking applies even if not stepping, there's no
7523 need to walk over threads. Above we've checked whether the
7524 current thread is stepping. If some other thread not the
7525 event thread is stepping, then it must be that scheduler
7526 locking is not in effect. */
7527 if (schedlock_applies (ecs
->event_thread
))
7530 /* Otherwise, we no longer expect a trap in the current thread.
7531 Clear the trap_expected flag before switching back -- this is
7532 what keep_going does as well, if we call it. */
7533 ecs
->event_thread
->control
.trap_expected
= 0;
7535 /* Likewise, clear the signal if it should not be passed. */
7536 if (!signal_program
[ecs
->event_thread
->suspend
.stop_signal
])
7537 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
7539 if (restart_stepped_thread (ecs
->target
, ecs
->ptid
))
7541 prepare_to_wait (ecs
);
7545 switch_to_thread (ecs
->event_thread
);
7551 /* Look for the thread that was stepping, and resume it.
7552 RESUME_TARGET / RESUME_PTID indicate the set of threads the caller
7553 is resuming. Return true if a thread was started, false
7557 restart_stepped_thread (process_stratum_target
*resume_target
,
7560 /* Do all pending step-overs before actually proceeding with
7562 if (start_step_over ())
7565 for (thread_info
*tp
: all_threads_safe ())
7567 if (tp
->state
== THREAD_EXITED
)
7570 if (tp
->suspend
.waitstatus_pending_p
)
7573 /* Ignore threads of processes the caller is not
7576 && (tp
->inf
->process_target () != resume_target
7577 || tp
->inf
->pid
!= resume_ptid
.pid ()))
7580 if (tp
->control
.trap_expected
)
7582 infrun_debug_printf ("switching back to stepped thread (step-over)");
7584 if (keep_going_stepped_thread (tp
))
7589 for (thread_info
*tp
: all_threads_safe ())
7591 if (tp
->state
== THREAD_EXITED
)
7594 if (tp
->suspend
.waitstatus_pending_p
)
7597 /* Ignore threads of processes the caller is not
7600 && (tp
->inf
->process_target () != resume_target
7601 || tp
->inf
->pid
!= resume_ptid
.pid ()))
7604 /* Did we find the stepping thread? */
7605 if (tp
->control
.step_range_end
)
7607 infrun_debug_printf ("switching back to stepped thread (stepping)");
7609 if (keep_going_stepped_thread (tp
))
7620 restart_after_all_stop_detach (process_stratum_target
*proc_target
)
7622 /* Note we don't check target_is_non_stop_p() here, because the
7623 current inferior may no longer have a process_stratum target
7624 pushed, as we just detached. */
7626 /* See if we have a THREAD_RUNNING thread that need to be
7627 re-resumed. If we have any thread that is already executing,
7628 then we don't need to resume the target -- it is already been
7629 resumed. With the remote target (in all-stop), it's even
7630 impossible to issue another resumption if the target is already
7631 resumed, until the target reports a stop. */
7632 for (thread_info
*thr
: all_threads (proc_target
))
7634 if (thr
->state
!= THREAD_RUNNING
)
7637 /* If we have any thread that is already executing, then we
7638 don't need to resume the target -- it is already been
7643 /* If we have a pending event to process, skip resuming the
7644 target and go straight to processing it. */
7645 if (thr
->resumed
&& thr
->suspend
.waitstatus_pending_p
)
7649 /* Alright, we need to re-resume the target. If a thread was
7650 stepping, we need to restart it stepping. */
7651 if (restart_stepped_thread (proc_target
, minus_one_ptid
))
7654 /* Otherwise, find the first THREAD_RUNNING thread and resume
7656 for (thread_info
*thr
: all_threads (proc_target
))
7658 if (thr
->state
!= THREAD_RUNNING
)
7661 execution_control_state ecs
;
7662 reset_ecs (&ecs
, thr
);
7663 switch_to_thread (thr
);
7669 /* Set a previously stepped thread back to stepping. Returns true on
7670 success, false if the resume is not possible (e.g., the thread
7674 keep_going_stepped_thread (struct thread_info
*tp
)
7676 struct frame_info
*frame
;
7677 struct execution_control_state ecss
;
7678 struct execution_control_state
*ecs
= &ecss
;
7680 /* If the stepping thread exited, then don't try to switch back and
7681 resume it, which could fail in several different ways depending
7682 on the target. Instead, just keep going.
7684 We can find a stepping dead thread in the thread list in two
7687 - The target supports thread exit events, and when the target
7688 tries to delete the thread from the thread list, inferior_ptid
7689 pointed at the exiting thread. In such case, calling
7690 delete_thread does not really remove the thread from the list;
7691 instead, the thread is left listed, with 'exited' state.
7693 - The target's debug interface does not support thread exit
7694 events, and so we have no idea whatsoever if the previously
7695 stepping thread is still alive. For that reason, we need to
7696 synchronously query the target now. */
7698 if (tp
->state
== THREAD_EXITED
|| !target_thread_alive (tp
->ptid
))
7700 infrun_debug_printf ("not resuming previously stepped thread, it has "
7707 infrun_debug_printf ("resuming previously stepped thread");
7709 reset_ecs (ecs
, tp
);
7710 switch_to_thread (tp
);
7712 tp
->suspend
.stop_pc
= regcache_read_pc (get_thread_regcache (tp
));
7713 frame
= get_current_frame ();
7715 /* If the PC of the thread we were trying to single-step has
7716 changed, then that thread has trapped or been signaled, but the
7717 event has not been reported to GDB yet. Re-poll the target
7718 looking for this particular thread's event (i.e. temporarily
7719 enable schedlock) by:
7721 - setting a break at the current PC
7722 - resuming that particular thread, only (by setting trap
7725 This prevents us continuously moving the single-step breakpoint
7726 forward, one instruction at a time, overstepping. */
7728 if (tp
->suspend
.stop_pc
!= tp
->prev_pc
)
7732 infrun_debug_printf ("expected thread advanced also (%s -> %s)",
7733 paddress (target_gdbarch (), tp
->prev_pc
),
7734 paddress (target_gdbarch (), tp
->suspend
.stop_pc
));
7736 /* Clear the info of the previous step-over, as it's no longer
7737 valid (if the thread was trying to step over a breakpoint, it
7738 has already succeeded). It's what keep_going would do too,
7739 if we called it. Do this before trying to insert the sss
7740 breakpoint, otherwise if we were previously trying to step
7741 over this exact address in another thread, the breakpoint is
7743 clear_step_over_info ();
7744 tp
->control
.trap_expected
= 0;
7746 insert_single_step_breakpoint (get_frame_arch (frame
),
7747 get_frame_address_space (frame
),
7748 tp
->suspend
.stop_pc
);
7751 resume_ptid
= internal_resume_ptid (tp
->control
.stepping_command
);
7752 do_target_resume (resume_ptid
, false, GDB_SIGNAL_0
);
7756 infrun_debug_printf ("expected thread still hasn't advanced");
7758 keep_going_pass_signal (ecs
);
7764 /* Is thread TP in the middle of (software or hardware)
7765 single-stepping? (Note the result of this function must never be
7766 passed directly as target_resume's STEP parameter.) */
7769 currently_stepping (struct thread_info
*tp
)
7771 return ((tp
->control
.step_range_end
7772 && tp
->control
.step_resume_breakpoint
== NULL
)
7773 || tp
->control
.trap_expected
7774 || tp
->stepped_breakpoint
7775 || bpstat_should_step ());
7778 /* Inferior has stepped into a subroutine call with source code that
7779 we should not step over. Do step to the first line of code in
7783 handle_step_into_function (struct gdbarch
*gdbarch
,
7784 struct execution_control_state
*ecs
)
7786 fill_in_stop_func (gdbarch
, ecs
);
7788 compunit_symtab
*cust
7789 = find_pc_compunit_symtab (ecs
->event_thread
->suspend
.stop_pc
);
7790 if (cust
!= NULL
&& compunit_language (cust
) != language_asm
)
7791 ecs
->stop_func_start
7792 = gdbarch_skip_prologue_noexcept (gdbarch
, ecs
->stop_func_start
);
7794 symtab_and_line stop_func_sal
= find_pc_line (ecs
->stop_func_start
, 0);
7795 /* Use the step_resume_break to step until the end of the prologue,
7796 even if that involves jumps (as it seems to on the vax under
7798 /* If the prologue ends in the middle of a source line, continue to
7799 the end of that source line (if it is still within the function).
7800 Otherwise, just go to end of prologue. */
7801 if (stop_func_sal
.end
7802 && stop_func_sal
.pc
!= ecs
->stop_func_start
7803 && stop_func_sal
.end
< ecs
->stop_func_end
)
7804 ecs
->stop_func_start
= stop_func_sal
.end
;
7806 /* Architectures which require breakpoint adjustment might not be able
7807 to place a breakpoint at the computed address. If so, the test
7808 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
7809 ecs->stop_func_start to an address at which a breakpoint may be
7810 legitimately placed.
7812 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
7813 made, GDB will enter an infinite loop when stepping through
7814 optimized code consisting of VLIW instructions which contain
7815 subinstructions corresponding to different source lines. On
7816 FR-V, it's not permitted to place a breakpoint on any but the
7817 first subinstruction of a VLIW instruction. When a breakpoint is
7818 set, GDB will adjust the breakpoint address to the beginning of
7819 the VLIW instruction. Thus, we need to make the corresponding
7820 adjustment here when computing the stop address. */
7822 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
7824 ecs
->stop_func_start
7825 = gdbarch_adjust_breakpoint_address (gdbarch
,
7826 ecs
->stop_func_start
);
7829 if (ecs
->stop_func_start
== ecs
->event_thread
->suspend
.stop_pc
)
7831 /* We are already there: stop now. */
7832 end_stepping_range (ecs
);
7837 /* Put the step-breakpoint there and go until there. */
7838 symtab_and_line sr_sal
;
7839 sr_sal
.pc
= ecs
->stop_func_start
;
7840 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
7841 sr_sal
.pspace
= get_frame_program_space (get_current_frame ());
7843 /* Do not specify what the fp should be when we stop since on
7844 some machines the prologue is where the new fp value is
7846 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
, null_frame_id
);
7848 /* And make sure stepping stops right away then. */
7849 ecs
->event_thread
->control
.step_range_end
7850 = ecs
->event_thread
->control
.step_range_start
;
7855 /* Inferior has stepped backward into a subroutine call with source
7856 code that we should not step over. Do step to the beginning of the
7857 last line of code in it. */
7860 handle_step_into_function_backward (struct gdbarch
*gdbarch
,
7861 struct execution_control_state
*ecs
)
7863 struct compunit_symtab
*cust
;
7864 struct symtab_and_line stop_func_sal
;
7866 fill_in_stop_func (gdbarch
, ecs
);
7868 cust
= find_pc_compunit_symtab (ecs
->event_thread
->suspend
.stop_pc
);
7869 if (cust
!= NULL
&& compunit_language (cust
) != language_asm
)
7870 ecs
->stop_func_start
7871 = gdbarch_skip_prologue_noexcept (gdbarch
, ecs
->stop_func_start
);
7873 stop_func_sal
= find_pc_line (ecs
->event_thread
->suspend
.stop_pc
, 0);
7875 /* OK, we're just going to keep stepping here. */
7876 if (stop_func_sal
.pc
== ecs
->event_thread
->suspend
.stop_pc
)
7878 /* We're there already. Just stop stepping now. */
7879 end_stepping_range (ecs
);
7883 /* Else just reset the step range and keep going.
7884 No step-resume breakpoint, they don't work for
7885 epilogues, which can have multiple entry paths. */
7886 ecs
->event_thread
->control
.step_range_start
= stop_func_sal
.pc
;
7887 ecs
->event_thread
->control
.step_range_end
= stop_func_sal
.end
;
7893 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
7894 This is used to both functions and to skip over code. */
7897 insert_step_resume_breakpoint_at_sal_1 (struct gdbarch
*gdbarch
,
7898 struct symtab_and_line sr_sal
,
7899 struct frame_id sr_id
,
7900 enum bptype sr_type
)
7902 /* There should never be more than one step-resume or longjmp-resume
7903 breakpoint per thread, so we should never be setting a new
7904 step_resume_breakpoint when one is already active. */
7905 gdb_assert (inferior_thread ()->control
.step_resume_breakpoint
== NULL
);
7906 gdb_assert (sr_type
== bp_step_resume
|| sr_type
== bp_hp_step_resume
);
7908 infrun_debug_printf ("inserting step-resume breakpoint at %s",
7909 paddress (gdbarch
, sr_sal
.pc
));
7911 inferior_thread ()->control
.step_resume_breakpoint
7912 = set_momentary_breakpoint (gdbarch
, sr_sal
, sr_id
, sr_type
).release ();
7916 insert_step_resume_breakpoint_at_sal (struct gdbarch
*gdbarch
,
7917 struct symtab_and_line sr_sal
,
7918 struct frame_id sr_id
)
7920 insert_step_resume_breakpoint_at_sal_1 (gdbarch
,
7925 /* Insert a "high-priority step-resume breakpoint" at RETURN_FRAME.pc.
7926 This is used to skip a potential signal handler.
7928 This is called with the interrupted function's frame. The signal
7929 handler, when it returns, will resume the interrupted function at
7933 insert_hp_step_resume_breakpoint_at_frame (struct frame_info
*return_frame
)
7935 gdb_assert (return_frame
!= NULL
);
7937 struct gdbarch
*gdbarch
= get_frame_arch (return_frame
);
7939 symtab_and_line sr_sal
;
7940 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
, get_frame_pc (return_frame
));
7941 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
7942 sr_sal
.pspace
= get_frame_program_space (return_frame
);
7944 insert_step_resume_breakpoint_at_sal_1 (gdbarch
, sr_sal
,
7945 get_stack_frame_id (return_frame
),
7949 /* Insert a "step-resume breakpoint" at the previous frame's PC. This
7950 is used to skip a function after stepping into it (for "next" or if
7951 the called function has no debugging information).
7953 The current function has almost always been reached by single
7954 stepping a call or return instruction. NEXT_FRAME belongs to the
7955 current function, and the breakpoint will be set at the caller's
7958 This is a separate function rather than reusing
7959 insert_hp_step_resume_breakpoint_at_frame in order to avoid
7960 get_prev_frame, which may stop prematurely (see the implementation
7961 of frame_unwind_caller_id for an example). */
7964 insert_step_resume_breakpoint_at_caller (struct frame_info
*next_frame
)
7966 /* We shouldn't have gotten here if we don't know where the call site
7968 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame
)));
7970 struct gdbarch
*gdbarch
= frame_unwind_caller_arch (next_frame
);
7972 symtab_and_line sr_sal
;
7973 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
,
7974 frame_unwind_caller_pc (next_frame
));
7975 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
7976 sr_sal
.pspace
= frame_unwind_program_space (next_frame
);
7978 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
,
7979 frame_unwind_caller_id (next_frame
));
7982 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
7983 new breakpoint at the target of a jmp_buf. The handling of
7984 longjmp-resume uses the same mechanisms used for handling
7985 "step-resume" breakpoints. */
7988 insert_longjmp_resume_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
7990 /* There should never be more than one longjmp-resume breakpoint per
7991 thread, so we should never be setting a new
7992 longjmp_resume_breakpoint when one is already active. */
7993 gdb_assert (inferior_thread ()->control
.exception_resume_breakpoint
== NULL
);
7995 infrun_debug_printf ("inserting longjmp-resume breakpoint at %s",
7996 paddress (gdbarch
, pc
));
7998 inferior_thread ()->control
.exception_resume_breakpoint
=
7999 set_momentary_breakpoint_at_pc (gdbarch
, pc
, bp_longjmp_resume
).release ();
8002 /* Insert an exception resume breakpoint. TP is the thread throwing
8003 the exception. The block B is the block of the unwinder debug hook
8004 function. FRAME is the frame corresponding to the call to this
8005 function. SYM is the symbol of the function argument holding the
8006 target PC of the exception. */
8009 insert_exception_resume_breakpoint (struct thread_info
*tp
,
8010 const struct block
*b
,
8011 struct frame_info
*frame
,
8016 struct block_symbol vsym
;
8017 struct value
*value
;
8019 struct breakpoint
*bp
;
8021 vsym
= lookup_symbol_search_name (sym
->search_name (),
8023 value
= read_var_value (vsym
.symbol
, vsym
.block
, frame
);
8024 /* If the value was optimized out, revert to the old behavior. */
8025 if (! value_optimized_out (value
))
8027 handler
= value_as_address (value
);
8029 infrun_debug_printf ("exception resume at %lx",
8030 (unsigned long) handler
);
8032 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
8034 bp_exception_resume
).release ();
8036 /* set_momentary_breakpoint_at_pc invalidates FRAME. */
8039 bp
->thread
= tp
->global_num
;
8040 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
8043 catch (const gdb_exception_error
&e
)
8045 /* We want to ignore errors here. */
8049 /* A helper for check_exception_resume that sets an
8050 exception-breakpoint based on a SystemTap probe. */
8053 insert_exception_resume_from_probe (struct thread_info
*tp
,
8054 const struct bound_probe
*probe
,
8055 struct frame_info
*frame
)
8057 struct value
*arg_value
;
8059 struct breakpoint
*bp
;
8061 arg_value
= probe_safe_evaluate_at_pc (frame
, 1);
8065 handler
= value_as_address (arg_value
);
8067 infrun_debug_printf ("exception resume at %s",
8068 paddress (probe
->objfile
->arch (), handler
));
8070 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
8071 handler
, bp_exception_resume
).release ();
8072 bp
->thread
= tp
->global_num
;
8073 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
8076 /* This is called when an exception has been intercepted. Check to
8077 see whether the exception's destination is of interest, and if so,
8078 set an exception resume breakpoint there. */
8081 check_exception_resume (struct execution_control_state
*ecs
,
8082 struct frame_info
*frame
)
8084 struct bound_probe probe
;
8085 struct symbol
*func
;
8087 /* First see if this exception unwinding breakpoint was set via a
8088 SystemTap probe point. If so, the probe has two arguments: the
8089 CFA and the HANDLER. We ignore the CFA, extract the handler, and
8090 set a breakpoint there. */
8091 probe
= find_probe_by_pc (get_frame_pc (frame
));
8094 insert_exception_resume_from_probe (ecs
->event_thread
, &probe
, frame
);
8098 func
= get_frame_function (frame
);
8104 const struct block
*b
;
8105 struct block_iterator iter
;
8109 /* The exception breakpoint is a thread-specific breakpoint on
8110 the unwinder's debug hook, declared as:
8112 void _Unwind_DebugHook (void *cfa, void *handler);
8114 The CFA argument indicates the frame to which control is
8115 about to be transferred. HANDLER is the destination PC.
8117 We ignore the CFA and set a temporary breakpoint at HANDLER.
8118 This is not extremely efficient but it avoids issues in gdb
8119 with computing the DWARF CFA, and it also works even in weird
8120 cases such as throwing an exception from inside a signal
8123 b
= SYMBOL_BLOCK_VALUE (func
);
8124 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
8126 if (!SYMBOL_IS_ARGUMENT (sym
))
8133 insert_exception_resume_breakpoint (ecs
->event_thread
,
8139 catch (const gdb_exception_error
&e
)
8145 stop_waiting (struct execution_control_state
*ecs
)
8147 infrun_debug_printf ("stop_waiting");
8149 /* Let callers know we don't want to wait for the inferior anymore. */
8150 ecs
->wait_some_more
= 0;
8152 /* If all-stop, but there exists a non-stop target, stop all
8153 threads now that we're presenting the stop to the user. */
8154 if (!non_stop
&& exists_non_stop_target ())
8155 stop_all_threads ("presenting stop to user in all-stop");
8158 /* Like keep_going, but passes the signal to the inferior, even if the
8159 signal is set to nopass. */
8162 keep_going_pass_signal (struct execution_control_state
*ecs
)
8164 gdb_assert (ecs
->event_thread
->ptid
== inferior_ptid
);
8165 gdb_assert (!ecs
->event_thread
->resumed
);
8167 /* Save the pc before execution, to compare with pc after stop. */
8168 ecs
->event_thread
->prev_pc
8169 = regcache_read_pc_protected (get_thread_regcache (ecs
->event_thread
));
8171 if (ecs
->event_thread
->control
.trap_expected
)
8173 struct thread_info
*tp
= ecs
->event_thread
;
8175 infrun_debug_printf ("%s has trap_expected set, "
8176 "resuming to collect trap",
8177 target_pid_to_str (tp
->ptid
).c_str ());
8179 /* We haven't yet gotten our trap, and either: intercepted a
8180 non-signal event (e.g., a fork); or took a signal which we
8181 are supposed to pass through to the inferior. Simply
8183 resume (ecs
->event_thread
->suspend
.stop_signal
);
8185 else if (step_over_info_valid_p ())
8187 /* Another thread is stepping over a breakpoint in-line. If
8188 this thread needs a step-over too, queue the request. In
8189 either case, this resume must be deferred for later. */
8190 struct thread_info
*tp
= ecs
->event_thread
;
8192 if (ecs
->hit_singlestep_breakpoint
8193 || thread_still_needs_step_over (tp
))
8195 infrun_debug_printf ("step-over already in progress: "
8196 "step-over for %s deferred",
8197 target_pid_to_str (tp
->ptid
).c_str ());
8198 global_thread_step_over_chain_enqueue (tp
);
8202 infrun_debug_printf ("step-over in progress: resume of %s deferred",
8203 target_pid_to_str (tp
->ptid
).c_str ());
8208 struct regcache
*regcache
= get_current_regcache ();
8211 step_over_what step_what
;
8213 /* Either the trap was not expected, but we are continuing
8214 anyway (if we got a signal, the user asked it be passed to
8217 We got our expected trap, but decided we should resume from
8220 We're going to run this baby now!
8222 Note that insert_breakpoints won't try to re-insert
8223 already inserted breakpoints. Therefore, we don't
8224 care if breakpoints were already inserted, or not. */
8226 /* If we need to step over a breakpoint, and we're not using
8227 displaced stepping to do so, insert all breakpoints
8228 (watchpoints, etc.) but the one we're stepping over, step one
8229 instruction, and then re-insert the breakpoint when that step
8232 step_what
= thread_still_needs_step_over (ecs
->event_thread
);
8234 remove_bp
= (ecs
->hit_singlestep_breakpoint
8235 || (step_what
& STEP_OVER_BREAKPOINT
));
8236 remove_wps
= (step_what
& STEP_OVER_WATCHPOINT
);
8238 /* We can't use displaced stepping if we need to step past a
8239 watchpoint. The instruction copied to the scratch pad would
8240 still trigger the watchpoint. */
8242 && (remove_wps
|| !use_displaced_stepping (ecs
->event_thread
)))
8244 set_step_over_info (regcache
->aspace (),
8245 regcache_read_pc (regcache
), remove_wps
,
8246 ecs
->event_thread
->global_num
);
8248 else if (remove_wps
)
8249 set_step_over_info (NULL
, 0, remove_wps
, -1);
8251 /* If we now need to do an in-line step-over, we need to stop
8252 all other threads. Note this must be done before
8253 insert_breakpoints below, because that removes the breakpoint
8254 we're about to step over, otherwise other threads could miss
8256 if (step_over_info_valid_p () && target_is_non_stop_p ())
8257 stop_all_threads ("starting in-line step-over");
8259 /* Stop stepping if inserting breakpoints fails. */
8262 insert_breakpoints ();
8264 catch (const gdb_exception_error
&e
)
8266 exception_print (gdb_stderr
, e
);
8268 clear_step_over_info ();
8272 ecs
->event_thread
->control
.trap_expected
= (remove_bp
|| remove_wps
);
8274 resume (ecs
->event_thread
->suspend
.stop_signal
);
8277 prepare_to_wait (ecs
);
8280 /* Called when we should continue running the inferior, because the
8281 current event doesn't cause a user visible stop. This does the
8282 resuming part; waiting for the next event is done elsewhere. */
8285 keep_going (struct execution_control_state
*ecs
)
8287 if (ecs
->event_thread
->control
.trap_expected
8288 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
8289 ecs
->event_thread
->control
.trap_expected
= 0;
8291 if (!signal_program
[ecs
->event_thread
->suspend
.stop_signal
])
8292 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
8293 keep_going_pass_signal (ecs
);
8296 /* This function normally comes after a resume, before
8297 handle_inferior_event exits. It takes care of any last bits of
8298 housekeeping, and sets the all-important wait_some_more flag. */
8301 prepare_to_wait (struct execution_control_state
*ecs
)
8303 infrun_debug_printf ("prepare_to_wait");
8305 ecs
->wait_some_more
= 1;
8307 /* If the target can't async, emulate it by marking the infrun event
8308 handler such that as soon as we get back to the event-loop, we
8309 immediately end up in fetch_inferior_event again calling
8311 if (!target_can_async_p ())
8312 mark_infrun_async_event_handler ();
8315 /* We are done with the step range of a step/next/si/ni command.
8316 Called once for each n of a "step n" operation. */
8319 end_stepping_range (struct execution_control_state
*ecs
)
8321 ecs
->event_thread
->control
.stop_step
= 1;
8325 /* Several print_*_reason functions to print why the inferior has stopped.
8326 We always print something when the inferior exits, or receives a signal.
8327 The rest of the cases are dealt with later on in normal_stop and
8328 print_it_typical. Ideally there should be a call to one of these
8329 print_*_reason functions functions from handle_inferior_event each time
8330 stop_waiting is called.
8332 Note that we don't call these directly, instead we delegate that to
8333 the interpreters, through observers. Interpreters then call these
8334 with whatever uiout is right. */
8337 print_end_stepping_range_reason (struct ui_out
*uiout
)
8339 /* For CLI-like interpreters, print nothing. */
8341 if (uiout
->is_mi_like_p ())
8343 uiout
->field_string ("reason",
8344 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE
));
8349 print_signal_exited_reason (struct ui_out
*uiout
, enum gdb_signal siggnal
)
8351 annotate_signalled ();
8352 if (uiout
->is_mi_like_p ())
8354 ("reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED
));
8355 uiout
->text ("\nProgram terminated with signal ");
8356 annotate_signal_name ();
8357 uiout
->field_string ("signal-name",
8358 gdb_signal_to_name (siggnal
));
8359 annotate_signal_name_end ();
8361 annotate_signal_string ();
8362 uiout
->field_string ("signal-meaning",
8363 gdb_signal_to_string (siggnal
));
8364 annotate_signal_string_end ();
8365 uiout
->text (".\n");
8366 uiout
->text ("The program no longer exists.\n");
8370 print_exited_reason (struct ui_out
*uiout
, int exitstatus
)
8372 struct inferior
*inf
= current_inferior ();
8373 std::string pidstr
= target_pid_to_str (ptid_t (inf
->pid
));
8375 annotate_exited (exitstatus
);
8378 if (uiout
->is_mi_like_p ())
8379 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXITED
));
8380 std::string exit_code_str
8381 = string_printf ("0%o", (unsigned int) exitstatus
);
8382 uiout
->message ("[Inferior %s (%s) exited with code %pF]\n",
8383 plongest (inf
->num
), pidstr
.c_str (),
8384 string_field ("exit-code", exit_code_str
.c_str ()));
8388 if (uiout
->is_mi_like_p ())
8390 ("reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY
));
8391 uiout
->message ("[Inferior %s (%s) exited normally]\n",
8392 plongest (inf
->num
), pidstr
.c_str ());
8397 print_signal_received_reason (struct ui_out
*uiout
, enum gdb_signal siggnal
)
8399 struct thread_info
*thr
= inferior_thread ();
8403 if (uiout
->is_mi_like_p ())
8405 else if (show_thread_that_caused_stop ())
8409 uiout
->text ("\nThread ");
8410 uiout
->field_string ("thread-id", print_thread_id (thr
));
8412 name
= thr
->name
!= NULL
? thr
->name
: target_thread_name (thr
);
8415 uiout
->text (" \"");
8416 uiout
->field_string ("name", name
);
8421 uiout
->text ("\nProgram");
8423 if (siggnal
== GDB_SIGNAL_0
&& !uiout
->is_mi_like_p ())
8424 uiout
->text (" stopped");
8427 uiout
->text (" received signal ");
8428 annotate_signal_name ();
8429 if (uiout
->is_mi_like_p ())
8431 ("reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED
));
8432 uiout
->field_string ("signal-name", gdb_signal_to_name (siggnal
));
8433 annotate_signal_name_end ();
8435 annotate_signal_string ();
8436 uiout
->field_string ("signal-meaning", gdb_signal_to_string (siggnal
));
8438 struct regcache
*regcache
= get_current_regcache ();
8439 struct gdbarch
*gdbarch
= regcache
->arch ();
8440 if (gdbarch_report_signal_info_p (gdbarch
))
8441 gdbarch_report_signal_info (gdbarch
, uiout
, siggnal
);
8443 annotate_signal_string_end ();
8445 uiout
->text (".\n");
8449 print_no_history_reason (struct ui_out
*uiout
)
8451 uiout
->text ("\nNo more reverse-execution history.\n");
8454 /* Print current location without a level number, if we have changed
8455 functions or hit a breakpoint. Print source line if we have one.
8456 bpstat_print contains the logic deciding in detail what to print,
8457 based on the event(s) that just occurred. */
8460 print_stop_location (struct target_waitstatus
*ws
)
8463 enum print_what source_flag
;
8464 int do_frame_printing
= 1;
8465 struct thread_info
*tp
= inferior_thread ();
8467 bpstat_ret
= bpstat_print (tp
->control
.stop_bpstat
, ws
->kind
);
8471 /* FIXME: cagney/2002-12-01: Given that a frame ID does (or
8472 should) carry around the function and does (or should) use
8473 that when doing a frame comparison. */
8474 if (tp
->control
.stop_step
8475 && frame_id_eq (tp
->control
.step_frame_id
,
8476 get_frame_id (get_current_frame ()))
8477 && (tp
->control
.step_start_function
8478 == find_pc_function (tp
->suspend
.stop_pc
)))
8480 /* Finished step, just print source line. */
8481 source_flag
= SRC_LINE
;
8485 /* Print location and source line. */
8486 source_flag
= SRC_AND_LOC
;
8489 case PRINT_SRC_AND_LOC
:
8490 /* Print location and source line. */
8491 source_flag
= SRC_AND_LOC
;
8493 case PRINT_SRC_ONLY
:
8494 source_flag
= SRC_LINE
;
8497 /* Something bogus. */
8498 source_flag
= SRC_LINE
;
8499 do_frame_printing
= 0;
8502 internal_error (__FILE__
, __LINE__
, _("Unknown value."));
8505 /* The behavior of this routine with respect to the source
8507 SRC_LINE: Print only source line
8508 LOCATION: Print only location
8509 SRC_AND_LOC: Print location and source line. */
8510 if (do_frame_printing
)
8511 print_stack_frame (get_selected_frame (NULL
), 0, source_flag
, 1);
8517 print_stop_event (struct ui_out
*uiout
, bool displays
)
8519 struct target_waitstatus last
;
8520 struct thread_info
*tp
;
8522 get_last_target_status (nullptr, nullptr, &last
);
8525 scoped_restore save_uiout
= make_scoped_restore (¤t_uiout
, uiout
);
8527 print_stop_location (&last
);
8529 /* Display the auto-display expressions. */
8534 tp
= inferior_thread ();
8535 if (tp
->thread_fsm
!= NULL
8536 && tp
->thread_fsm
->finished_p ())
8538 struct return_value_info
*rv
;
8540 rv
= tp
->thread_fsm
->return_value ();
8542 print_return_value (uiout
, rv
);
8549 maybe_remove_breakpoints (void)
8551 if (!breakpoints_should_be_inserted_now () && target_has_execution ())
8553 if (remove_breakpoints ())
8555 target_terminal::ours_for_output ();
8556 printf_filtered (_("Cannot remove breakpoints because "
8557 "program is no longer writable.\nFurther "
8558 "execution is probably impossible.\n"));
8563 /* The execution context that just caused a normal stop. */
8569 DISABLE_COPY_AND_ASSIGN (stop_context
);
8571 bool changed () const;
8576 /* The event PTID. */
8580 /* If stopp for a thread event, this is the thread that caused the
8582 thread_info_ref thread
;
8584 /* The inferior that caused the stop. */
8588 /* Initializes a new stop context. If stopped for a thread event, this
8589 takes a strong reference to the thread. */
8591 stop_context::stop_context ()
8593 stop_id
= get_stop_id ();
8594 ptid
= inferior_ptid
;
8595 inf_num
= current_inferior ()->num
;
8597 if (inferior_ptid
!= null_ptid
)
8599 /* Take a strong reference so that the thread can't be deleted
8601 thread
= thread_info_ref::new_reference (inferior_thread ());
8605 /* Return true if the current context no longer matches the saved stop
8609 stop_context::changed () const
8611 if (ptid
!= inferior_ptid
)
8613 if (inf_num
!= current_inferior ()->num
)
8615 if (thread
!= NULL
&& thread
->state
!= THREAD_STOPPED
)
8617 if (get_stop_id () != stop_id
)
8627 struct target_waitstatus last
;
8629 get_last_target_status (nullptr, nullptr, &last
);
8633 /* If an exception is thrown from this point on, make sure to
8634 propagate GDB's knowledge of the executing state to the
8635 frontend/user running state. A QUIT is an easy exception to see
8636 here, so do this before any filtered output. */
8638 ptid_t finish_ptid
= null_ptid
;
8641 finish_ptid
= minus_one_ptid
;
8642 else if (last
.kind
== TARGET_WAITKIND_SIGNALLED
8643 || last
.kind
== TARGET_WAITKIND_EXITED
)
8645 /* On some targets, we may still have live threads in the
8646 inferior when we get a process exit event. E.g., for
8647 "checkpoint", when the current checkpoint/fork exits,
8648 linux-fork.c automatically switches to another fork from
8649 within target_mourn_inferior. */
8650 if (inferior_ptid
!= null_ptid
)
8651 finish_ptid
= ptid_t (inferior_ptid
.pid ());
8653 else if (last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
8654 finish_ptid
= inferior_ptid
;
8656 gdb::optional
<scoped_finish_thread_state
> maybe_finish_thread_state
;
8657 if (finish_ptid
!= null_ptid
)
8659 maybe_finish_thread_state
.emplace
8660 (user_visible_resume_target (finish_ptid
), finish_ptid
);
8663 /* As we're presenting a stop, and potentially removing breakpoints,
8664 update the thread list so we can tell whether there are threads
8665 running on the target. With target remote, for example, we can
8666 only learn about new threads when we explicitly update the thread
8667 list. Do this before notifying the interpreters about signal
8668 stops, end of stepping ranges, etc., so that the "new thread"
8669 output is emitted before e.g., "Program received signal FOO",
8670 instead of after. */
8671 update_thread_list ();
8673 if (last
.kind
== TARGET_WAITKIND_STOPPED
&& stopped_by_random_signal
)
8674 gdb::observers::signal_received
.notify (inferior_thread ()->suspend
.stop_signal
);
8676 /* As with the notification of thread events, we want to delay
8677 notifying the user that we've switched thread context until
8678 the inferior actually stops.
8680 There's no point in saying anything if the inferior has exited.
8681 Note that SIGNALLED here means "exited with a signal", not
8682 "received a signal".
8684 Also skip saying anything in non-stop mode. In that mode, as we
8685 don't want GDB to switch threads behind the user's back, to avoid
8686 races where the user is typing a command to apply to thread x,
8687 but GDB switches to thread y before the user finishes entering
8688 the command, fetch_inferior_event installs a cleanup to restore
8689 the current thread back to the thread the user had selected right
8690 after this event is handled, so we're not really switching, only
8691 informing of a stop. */
8693 && previous_inferior_ptid
!= inferior_ptid
8694 && target_has_execution ()
8695 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
8696 && last
.kind
!= TARGET_WAITKIND_EXITED
8697 && last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
8699 SWITCH_THRU_ALL_UIS ()
8701 target_terminal::ours_for_output ();
8702 printf_filtered (_("[Switching to %s]\n"),
8703 target_pid_to_str (inferior_ptid
).c_str ());
8704 annotate_thread_changed ();
8706 previous_inferior_ptid
= inferior_ptid
;
8709 if (last
.kind
== TARGET_WAITKIND_NO_RESUMED
)
8711 SWITCH_THRU_ALL_UIS ()
8712 if (current_ui
->prompt_state
== PROMPT_BLOCKED
)
8714 target_terminal::ours_for_output ();
8715 printf_filtered (_("No unwaited-for children left.\n"));
8719 /* Note: this depends on the update_thread_list call above. */
8720 maybe_remove_breakpoints ();
8722 /* If an auto-display called a function and that got a signal,
8723 delete that auto-display to avoid an infinite recursion. */
8725 if (stopped_by_random_signal
)
8726 disable_current_display ();
8728 SWITCH_THRU_ALL_UIS ()
8730 async_enable_stdin ();
8733 /* Let the user/frontend see the threads as stopped. */
8734 maybe_finish_thread_state
.reset ();
8736 /* Select innermost stack frame - i.e., current frame is frame 0,
8737 and current location is based on that. Handle the case where the
8738 dummy call is returning after being stopped. E.g. the dummy call
8739 previously hit a breakpoint. (If the dummy call returns
8740 normally, we won't reach here.) Do this before the stop hook is
8741 run, so that it doesn't get to see the temporary dummy frame,
8742 which is not where we'll present the stop. */
8743 if (has_stack_frames ())
8745 if (stop_stack_dummy
== STOP_STACK_DUMMY
)
8747 /* Pop the empty frame that contains the stack dummy. This
8748 also restores inferior state prior to the call (struct
8749 infcall_suspend_state). */
8750 struct frame_info
*frame
= get_current_frame ();
8752 gdb_assert (get_frame_type (frame
) == DUMMY_FRAME
);
8754 /* frame_pop calls reinit_frame_cache as the last thing it
8755 does which means there's now no selected frame. */
8758 select_frame (get_current_frame ());
8760 /* Set the current source location. */
8761 set_current_sal_from_frame (get_current_frame ());
8764 /* Look up the hook_stop and run it (CLI internally handles problem
8765 of stop_command's pre-hook not existing). */
8766 if (stop_command
!= NULL
)
8768 stop_context saved_context
;
8772 execute_cmd_pre_hook (stop_command
);
8774 catch (const gdb_exception
&ex
)
8776 exception_fprintf (gdb_stderr
, ex
,
8777 "Error while running hook_stop:\n");
8780 /* If the stop hook resumes the target, then there's no point in
8781 trying to notify about the previous stop; its context is
8782 gone. Likewise if the command switches thread or inferior --
8783 the observers would print a stop for the wrong
8785 if (saved_context
.changed ())
8789 /* Notify observers about the stop. This is where the interpreters
8790 print the stop event. */
8791 if (inferior_ptid
!= null_ptid
)
8792 gdb::observers::normal_stop
.notify (inferior_thread ()->control
.stop_bpstat
,
8795 gdb::observers::normal_stop
.notify (NULL
, stop_print_frame
);
8797 annotate_stopped ();
8799 if (target_has_execution ())
8801 if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
8802 && last
.kind
!= TARGET_WAITKIND_EXITED
8803 && last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
8804 /* Delete the breakpoint we stopped at, if it wants to be deleted.
8805 Delete any breakpoint that is to be deleted at the next stop. */
8806 breakpoint_auto_delete (inferior_thread ()->control
.stop_bpstat
);
8809 /* Try to get rid of automatically added inferiors that are no
8810 longer needed. Keeping those around slows down things linearly.
8811 Note that this never removes the current inferior. */
8818 signal_stop_state (int signo
)
8820 return signal_stop
[signo
];
8824 signal_print_state (int signo
)
8826 return signal_print
[signo
];
8830 signal_pass_state (int signo
)
8832 return signal_program
[signo
];
8836 signal_cache_update (int signo
)
8840 for (signo
= 0; signo
< (int) GDB_SIGNAL_LAST
; signo
++)
8841 signal_cache_update (signo
);
8846 signal_pass
[signo
] = (signal_stop
[signo
] == 0
8847 && signal_print
[signo
] == 0
8848 && signal_program
[signo
] == 1
8849 && signal_catch
[signo
] == 0);
8853 signal_stop_update (int signo
, int state
)
8855 int ret
= signal_stop
[signo
];
8857 signal_stop
[signo
] = state
;
8858 signal_cache_update (signo
);
8863 signal_print_update (int signo
, int state
)
8865 int ret
= signal_print
[signo
];
8867 signal_print
[signo
] = state
;
8868 signal_cache_update (signo
);
8873 signal_pass_update (int signo
, int state
)
8875 int ret
= signal_program
[signo
];
8877 signal_program
[signo
] = state
;
8878 signal_cache_update (signo
);
8882 /* Update the global 'signal_catch' from INFO and notify the
8886 signal_catch_update (const unsigned int *info
)
8890 for (i
= 0; i
< GDB_SIGNAL_LAST
; ++i
)
8891 signal_catch
[i
] = info
[i
] > 0;
8892 signal_cache_update (-1);
8893 target_pass_signals (signal_pass
);
8897 sig_print_header (void)
8899 printf_filtered (_("Signal Stop\tPrint\tPass "
8900 "to program\tDescription\n"));
8904 sig_print_info (enum gdb_signal oursig
)
8906 const char *name
= gdb_signal_to_name (oursig
);
8907 int name_padding
= 13 - strlen (name
);
8909 if (name_padding
<= 0)
8912 printf_filtered ("%s", name
);
8913 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
8914 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
8915 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
8916 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
8917 printf_filtered ("%s\n", gdb_signal_to_string (oursig
));
8920 /* Specify how various signals in the inferior should be handled. */
8923 handle_command (const char *args
, int from_tty
)
8925 int digits
, wordlen
;
8926 int sigfirst
, siglast
;
8927 enum gdb_signal oursig
;
8932 error_no_arg (_("signal to handle"));
8935 /* Allocate and zero an array of flags for which signals to handle. */
8937 const size_t nsigs
= GDB_SIGNAL_LAST
;
8938 unsigned char sigs
[nsigs
] {};
8940 /* Break the command line up into args. */
8942 gdb_argv
built_argv (args
);
8944 /* Walk through the args, looking for signal oursigs, signal names, and
8945 actions. Signal numbers and signal names may be interspersed with
8946 actions, with the actions being performed for all signals cumulatively
8947 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
8949 for (char *arg
: built_argv
)
8951 wordlen
= strlen (arg
);
8952 for (digits
= 0; isdigit (arg
[digits
]); digits
++)
8956 sigfirst
= siglast
= -1;
8958 if (wordlen
>= 1 && !strncmp (arg
, "all", wordlen
))
8960 /* Apply action to all signals except those used by the
8961 debugger. Silently skip those. */
8964 siglast
= nsigs
- 1;
8966 else if (wordlen
>= 1 && !strncmp (arg
, "stop", wordlen
))
8968 SET_SIGS (nsigs
, sigs
, signal_stop
);
8969 SET_SIGS (nsigs
, sigs
, signal_print
);
8971 else if (wordlen
>= 1 && !strncmp (arg
, "ignore", wordlen
))
8973 UNSET_SIGS (nsigs
, sigs
, signal_program
);
8975 else if (wordlen
>= 2 && !strncmp (arg
, "print", wordlen
))
8977 SET_SIGS (nsigs
, sigs
, signal_print
);
8979 else if (wordlen
>= 2 && !strncmp (arg
, "pass", wordlen
))
8981 SET_SIGS (nsigs
, sigs
, signal_program
);
8983 else if (wordlen
>= 3 && !strncmp (arg
, "nostop", wordlen
))
8985 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
8987 else if (wordlen
>= 3 && !strncmp (arg
, "noignore", wordlen
))
8989 SET_SIGS (nsigs
, sigs
, signal_program
);
8991 else if (wordlen
>= 4 && !strncmp (arg
, "noprint", wordlen
))
8993 UNSET_SIGS (nsigs
, sigs
, signal_print
);
8994 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
8996 else if (wordlen
>= 4 && !strncmp (arg
, "nopass", wordlen
))
8998 UNSET_SIGS (nsigs
, sigs
, signal_program
);
9000 else if (digits
> 0)
9002 /* It is numeric. The numeric signal refers to our own
9003 internal signal numbering from target.h, not to host/target
9004 signal number. This is a feature; users really should be
9005 using symbolic names anyway, and the common ones like
9006 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
9008 sigfirst
= siglast
= (int)
9009 gdb_signal_from_command (atoi (arg
));
9010 if (arg
[digits
] == '-')
9013 gdb_signal_from_command (atoi (arg
+ digits
+ 1));
9015 if (sigfirst
> siglast
)
9017 /* Bet he didn't figure we'd think of this case... */
9018 std::swap (sigfirst
, siglast
);
9023 oursig
= gdb_signal_from_name (arg
);
9024 if (oursig
!= GDB_SIGNAL_UNKNOWN
)
9026 sigfirst
= siglast
= (int) oursig
;
9030 /* Not a number and not a recognized flag word => complain. */
9031 error (_("Unrecognized or ambiguous flag word: \"%s\"."), arg
);
9035 /* If any signal numbers or symbol names were found, set flags for
9036 which signals to apply actions to. */
9038 for (int signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
9040 switch ((enum gdb_signal
) signum
)
9042 case GDB_SIGNAL_TRAP
:
9043 case GDB_SIGNAL_INT
:
9044 if (!allsigs
&& !sigs
[signum
])
9046 if (query (_("%s is used by the debugger.\n\
9047 Are you sure you want to change it? "),
9048 gdb_signal_to_name ((enum gdb_signal
) signum
)))
9053 printf_unfiltered (_("Not confirmed, unchanged.\n"));
9057 case GDB_SIGNAL_DEFAULT
:
9058 case GDB_SIGNAL_UNKNOWN
:
9059 /* Make sure that "all" doesn't print these. */
9068 for (int signum
= 0; signum
< nsigs
; signum
++)
9071 signal_cache_update (-1);
9072 target_pass_signals (signal_pass
);
9073 target_program_signals (signal_program
);
9077 /* Show the results. */
9078 sig_print_header ();
9079 for (; signum
< nsigs
; signum
++)
9081 sig_print_info ((enum gdb_signal
) signum
);
9088 /* Complete the "handle" command. */
9091 handle_completer (struct cmd_list_element
*ignore
,
9092 completion_tracker
&tracker
,
9093 const char *text
, const char *word
)
9095 static const char * const keywords
[] =
9109 signal_completer (ignore
, tracker
, text
, word
);
9110 complete_on_enum (tracker
, keywords
, word
, word
);
9114 gdb_signal_from_command (int num
)
9116 if (num
>= 1 && num
<= 15)
9117 return (enum gdb_signal
) num
;
9118 error (_("Only signals 1-15 are valid as numeric signals.\n\
9119 Use \"info signals\" for a list of symbolic signals."));
9122 /* Print current contents of the tables set by the handle command.
9123 It is possible we should just be printing signals actually used
9124 by the current target (but for things to work right when switching
9125 targets, all signals should be in the signal tables). */
9128 info_signals_command (const char *signum_exp
, int from_tty
)
9130 enum gdb_signal oursig
;
9132 sig_print_header ();
9136 /* First see if this is a symbol name. */
9137 oursig
= gdb_signal_from_name (signum_exp
);
9138 if (oursig
== GDB_SIGNAL_UNKNOWN
)
9140 /* No, try numeric. */
9142 gdb_signal_from_command (parse_and_eval_long (signum_exp
));
9144 sig_print_info (oursig
);
9148 printf_filtered ("\n");
9149 /* These ugly casts brought to you by the native VAX compiler. */
9150 for (oursig
= GDB_SIGNAL_FIRST
;
9151 (int) oursig
< (int) GDB_SIGNAL_LAST
;
9152 oursig
= (enum gdb_signal
) ((int) oursig
+ 1))
9156 if (oursig
!= GDB_SIGNAL_UNKNOWN
9157 && oursig
!= GDB_SIGNAL_DEFAULT
&& oursig
!= GDB_SIGNAL_0
)
9158 sig_print_info (oursig
);
9161 printf_filtered (_("\nUse the \"handle\" command "
9162 "to change these tables.\n"));
9165 /* The $_siginfo convenience variable is a bit special. We don't know
9166 for sure the type of the value until we actually have a chance to
9167 fetch the data. The type can change depending on gdbarch, so it is
9168 also dependent on which thread you have selected.
9170 1. making $_siginfo be an internalvar that creates a new value on
9173 2. making the value of $_siginfo be an lval_computed value. */
9175 /* This function implements the lval_computed support for reading a
9179 siginfo_value_read (struct value
*v
)
9181 LONGEST transferred
;
9183 /* If we can access registers, so can we access $_siginfo. Likewise
9185 validate_registers_access ();
9188 target_read (current_inferior ()->top_target (),
9189 TARGET_OBJECT_SIGNAL_INFO
,
9191 value_contents_all_raw (v
),
9193 TYPE_LENGTH (value_type (v
)));
9195 if (transferred
!= TYPE_LENGTH (value_type (v
)))
9196 error (_("Unable to read siginfo"));
9199 /* This function implements the lval_computed support for writing a
9203 siginfo_value_write (struct value
*v
, struct value
*fromval
)
9205 LONGEST transferred
;
9207 /* If we can access registers, so can we access $_siginfo. Likewise
9209 validate_registers_access ();
9211 transferred
= target_write (current_inferior ()->top_target (),
9212 TARGET_OBJECT_SIGNAL_INFO
,
9214 value_contents_all_raw (fromval
),
9216 TYPE_LENGTH (value_type (fromval
)));
9218 if (transferred
!= TYPE_LENGTH (value_type (fromval
)))
9219 error (_("Unable to write siginfo"));
9222 static const struct lval_funcs siginfo_value_funcs
=
9228 /* Return a new value with the correct type for the siginfo object of
9229 the current thread using architecture GDBARCH. Return a void value
9230 if there's no object available. */
9232 static struct value
*
9233 siginfo_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
,
9236 if (target_has_stack ()
9237 && inferior_ptid
!= null_ptid
9238 && gdbarch_get_siginfo_type_p (gdbarch
))
9240 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
9242 return allocate_computed_value (type
, &siginfo_value_funcs
, NULL
);
9245 return allocate_value (builtin_type (gdbarch
)->builtin_void
);
9249 /* infcall_suspend_state contains state about the program itself like its
9250 registers and any signal it received when it last stopped.
9251 This state must be restored regardless of how the inferior function call
9252 ends (either successfully, or after it hits a breakpoint or signal)
9253 if the program is to properly continue where it left off. */
9255 class infcall_suspend_state
9258 /* Capture state from GDBARCH, TP, and REGCACHE that must be restored
9259 once the inferior function call has finished. */
9260 infcall_suspend_state (struct gdbarch
*gdbarch
,
9261 const struct thread_info
*tp
,
9262 struct regcache
*regcache
)
9263 : m_thread_suspend (tp
->suspend
),
9264 m_registers (new readonly_detached_regcache (*regcache
))
9266 gdb::unique_xmalloc_ptr
<gdb_byte
> siginfo_data
;
9268 if (gdbarch_get_siginfo_type_p (gdbarch
))
9270 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
9271 size_t len
= TYPE_LENGTH (type
);
9273 siginfo_data
.reset ((gdb_byte
*) xmalloc (len
));
9275 if (target_read (current_inferior ()->top_target (),
9276 TARGET_OBJECT_SIGNAL_INFO
, NULL
,
9277 siginfo_data
.get (), 0, len
) != len
)
9279 /* Errors ignored. */
9280 siginfo_data
.reset (nullptr);
9286 m_siginfo_gdbarch
= gdbarch
;
9287 m_siginfo_data
= std::move (siginfo_data
);
9291 /* Return a pointer to the stored register state. */
9293 readonly_detached_regcache
*registers () const
9295 return m_registers
.get ();
9298 /* Restores the stored state into GDBARCH, TP, and REGCACHE. */
9300 void restore (struct gdbarch
*gdbarch
,
9301 struct thread_info
*tp
,
9302 struct regcache
*regcache
) const
9304 tp
->suspend
= m_thread_suspend
;
9306 if (m_siginfo_gdbarch
== gdbarch
)
9308 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
9310 /* Errors ignored. */
9311 target_write (current_inferior ()->top_target (),
9312 TARGET_OBJECT_SIGNAL_INFO
, NULL
,
9313 m_siginfo_data
.get (), 0, TYPE_LENGTH (type
));
9316 /* The inferior can be gone if the user types "print exit(0)"
9317 (and perhaps other times). */
9318 if (target_has_execution ())
9319 /* NB: The register write goes through to the target. */
9320 regcache
->restore (registers ());
9324 /* How the current thread stopped before the inferior function call was
9326 struct thread_suspend_state m_thread_suspend
;
9328 /* The registers before the inferior function call was executed. */
9329 std::unique_ptr
<readonly_detached_regcache
> m_registers
;
9331 /* Format of SIGINFO_DATA or NULL if it is not present. */
9332 struct gdbarch
*m_siginfo_gdbarch
= nullptr;
9334 /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
9335 TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the
9336 content would be invalid. */
9337 gdb::unique_xmalloc_ptr
<gdb_byte
> m_siginfo_data
;
9340 infcall_suspend_state_up
9341 save_infcall_suspend_state ()
9343 struct thread_info
*tp
= inferior_thread ();
9344 struct regcache
*regcache
= get_current_regcache ();
9345 struct gdbarch
*gdbarch
= regcache
->arch ();
9347 infcall_suspend_state_up inf_state
9348 (new struct infcall_suspend_state (gdbarch
, tp
, regcache
));
9350 /* Having saved the current state, adjust the thread state, discarding
9351 any stop signal information. The stop signal is not useful when
9352 starting an inferior function call, and run_inferior_call will not use
9353 the signal due to its `proceed' call with GDB_SIGNAL_0. */
9354 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
9359 /* Restore inferior session state to INF_STATE. */
9362 restore_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
9364 struct thread_info
*tp
= inferior_thread ();
9365 struct regcache
*regcache
= get_current_regcache ();
9366 struct gdbarch
*gdbarch
= regcache
->arch ();
9368 inf_state
->restore (gdbarch
, tp
, regcache
);
9369 discard_infcall_suspend_state (inf_state
);
9373 discard_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
9378 readonly_detached_regcache
*
9379 get_infcall_suspend_state_regcache (struct infcall_suspend_state
*inf_state
)
9381 return inf_state
->registers ();
9384 /* infcall_control_state contains state regarding gdb's control of the
9385 inferior itself like stepping control. It also contains session state like
9386 the user's currently selected frame. */
9388 struct infcall_control_state
9390 struct thread_control_state thread_control
;
9391 struct inferior_control_state inferior_control
;
9394 enum stop_stack_kind stop_stack_dummy
= STOP_NONE
;
9395 int stopped_by_random_signal
= 0;
9397 /* ID and level of the selected frame when the inferior function
9399 struct frame_id selected_frame_id
{};
9400 int selected_frame_level
= -1;
9403 /* Save all of the information associated with the inferior<==>gdb
9406 infcall_control_state_up
9407 save_infcall_control_state ()
9409 infcall_control_state_up
inf_status (new struct infcall_control_state
);
9410 struct thread_info
*tp
= inferior_thread ();
9411 struct inferior
*inf
= current_inferior ();
9413 inf_status
->thread_control
= tp
->control
;
9414 inf_status
->inferior_control
= inf
->control
;
9416 tp
->control
.step_resume_breakpoint
= NULL
;
9417 tp
->control
.exception_resume_breakpoint
= NULL
;
9419 /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of
9420 chain. If caller's caller is walking the chain, they'll be happier if we
9421 hand them back the original chain when restore_infcall_control_state is
9423 tp
->control
.stop_bpstat
= bpstat_copy (tp
->control
.stop_bpstat
);
9426 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
9427 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
9429 save_selected_frame (&inf_status
->selected_frame_id
,
9430 &inf_status
->selected_frame_level
);
9435 /* Restore inferior session state to INF_STATUS. */
9438 restore_infcall_control_state (struct infcall_control_state
*inf_status
)
9440 struct thread_info
*tp
= inferior_thread ();
9441 struct inferior
*inf
= current_inferior ();
9443 if (tp
->control
.step_resume_breakpoint
)
9444 tp
->control
.step_resume_breakpoint
->disposition
= disp_del_at_next_stop
;
9446 if (tp
->control
.exception_resume_breakpoint
)
9447 tp
->control
.exception_resume_breakpoint
->disposition
9448 = disp_del_at_next_stop
;
9450 /* Handle the bpstat_copy of the chain. */
9451 bpstat_clear (&tp
->control
.stop_bpstat
);
9453 tp
->control
= inf_status
->thread_control
;
9454 inf
->control
= inf_status
->inferior_control
;
9457 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
9458 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
9460 if (target_has_stack ())
9462 restore_selected_frame (inf_status
->selected_frame_id
,
9463 inf_status
->selected_frame_level
);
9470 discard_infcall_control_state (struct infcall_control_state
*inf_status
)
9472 if (inf_status
->thread_control
.step_resume_breakpoint
)
9473 inf_status
->thread_control
.step_resume_breakpoint
->disposition
9474 = disp_del_at_next_stop
;
9476 if (inf_status
->thread_control
.exception_resume_breakpoint
)
9477 inf_status
->thread_control
.exception_resume_breakpoint
->disposition
9478 = disp_del_at_next_stop
;
9480 /* See save_infcall_control_state for info on stop_bpstat. */
9481 bpstat_clear (&inf_status
->thread_control
.stop_bpstat
);
9489 clear_exit_convenience_vars (void)
9491 clear_internalvar (lookup_internalvar ("_exitsignal"));
9492 clear_internalvar (lookup_internalvar ("_exitcode"));
9496 /* User interface for reverse debugging:
9497 Set exec-direction / show exec-direction commands
9498 (returns error unless target implements to_set_exec_direction method). */
9500 enum exec_direction_kind execution_direction
= EXEC_FORWARD
;
9501 static const char exec_forward
[] = "forward";
9502 static const char exec_reverse
[] = "reverse";
9503 static const char *exec_direction
= exec_forward
;
9504 static const char *const exec_direction_names
[] = {
9511 set_exec_direction_func (const char *args
, int from_tty
,
9512 struct cmd_list_element
*cmd
)
9514 if (target_can_execute_reverse ())
9516 if (!strcmp (exec_direction
, exec_forward
))
9517 execution_direction
= EXEC_FORWARD
;
9518 else if (!strcmp (exec_direction
, exec_reverse
))
9519 execution_direction
= EXEC_REVERSE
;
9523 exec_direction
= exec_forward
;
9524 error (_("Target does not support this operation."));
9529 show_exec_direction_func (struct ui_file
*out
, int from_tty
,
9530 struct cmd_list_element
*cmd
, const char *value
)
9532 switch (execution_direction
) {
9534 fprintf_filtered (out
, _("Forward.\n"));
9537 fprintf_filtered (out
, _("Reverse.\n"));
9540 internal_error (__FILE__
, __LINE__
,
9541 _("bogus execution_direction value: %d"),
9542 (int) execution_direction
);
9547 show_schedule_multiple (struct ui_file
*file
, int from_tty
,
9548 struct cmd_list_element
*c
, const char *value
)
9550 fprintf_filtered (file
, _("Resuming the execution of threads "
9551 "of all processes is %s.\n"), value
);
9554 /* Implementation of `siginfo' variable. */
9556 static const struct internalvar_funcs siginfo_funcs
=
9563 /* Callback for infrun's target events source. This is marked when a
9564 thread has a pending status to process. */
9567 infrun_async_inferior_event_handler (gdb_client_data data
)
9569 clear_async_event_handler (infrun_async_inferior_event_token
);
9570 inferior_event_handler (INF_REG_EVENT
);
9577 /* Verify that when two threads with the same ptid exist (from two different
9578 targets) and one of them changes ptid, we only update inferior_ptid if
9579 it is appropriate. */
9582 infrun_thread_ptid_changed ()
9584 gdbarch
*arch
= current_inferior ()->gdbarch
;
9586 /* The thread which inferior_ptid represents changes ptid. */
9588 scoped_restore_current_pspace_and_thread restore
;
9590 scoped_mock_context
<test_target_ops
> target1 (arch
);
9591 scoped_mock_context
<test_target_ops
> target2 (arch
);
9592 target2
.mock_inferior
.next
= &target1
.mock_inferior
;
9594 ptid_t
old_ptid (111, 222);
9595 ptid_t
new_ptid (111, 333);
9597 target1
.mock_inferior
.pid
= old_ptid
.pid ();
9598 target1
.mock_thread
.ptid
= old_ptid
;
9599 target2
.mock_inferior
.pid
= old_ptid
.pid ();
9600 target2
.mock_thread
.ptid
= old_ptid
;
9602 auto restore_inferior_ptid
= make_scoped_restore (&inferior_ptid
, old_ptid
);
9603 set_current_inferior (&target1
.mock_inferior
);
9605 thread_change_ptid (&target1
.mock_target
, old_ptid
, new_ptid
);
9607 gdb_assert (inferior_ptid
== new_ptid
);
9610 /* A thread with the same ptid as inferior_ptid, but from another target,
9613 scoped_restore_current_pspace_and_thread restore
;
9615 scoped_mock_context
<test_target_ops
> target1 (arch
);
9616 scoped_mock_context
<test_target_ops
> target2 (arch
);
9617 target2
.mock_inferior
.next
= &target1
.mock_inferior
;
9619 ptid_t
old_ptid (111, 222);
9620 ptid_t
new_ptid (111, 333);
9622 target1
.mock_inferior
.pid
= old_ptid
.pid ();
9623 target1
.mock_thread
.ptid
= old_ptid
;
9624 target2
.mock_inferior
.pid
= old_ptid
.pid ();
9625 target2
.mock_thread
.ptid
= old_ptid
;
9627 auto restore_inferior_ptid
= make_scoped_restore (&inferior_ptid
, old_ptid
);
9628 set_current_inferior (&target2
.mock_inferior
);
9630 thread_change_ptid (&target1
.mock_target
, old_ptid
, new_ptid
);
9632 gdb_assert (inferior_ptid
== old_ptid
);
9636 } /* namespace selftests */
9638 #endif /* GDB_SELF_TEST */
9640 void _initialize_infrun ();
9642 _initialize_infrun ()
9644 struct cmd_list_element
*c
;
9646 /* Register extra event sources in the event loop. */
9647 infrun_async_inferior_event_token
9648 = create_async_event_handler (infrun_async_inferior_event_handler
, NULL
,
9651 cmd_list_element
*info_signals_cmd
9652 = add_info ("signals", info_signals_command
, _("\
9653 What debugger does when program gets various signals.\n\
9654 Specify a signal as argument to print info on that signal only."));
9655 add_info_alias ("handle", info_signals_cmd
, 0);
9657 c
= add_com ("handle", class_run
, handle_command
, _("\
9658 Specify how to handle signals.\n\
9659 Usage: handle SIGNAL [ACTIONS]\n\
9660 Args are signals and actions to apply to those signals.\n\
9661 If no actions are specified, the current settings for the specified signals\n\
9662 will be displayed instead.\n\
9664 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
9665 from 1-15 are allowed for compatibility with old versions of GDB.\n\
9666 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
9667 The special arg \"all\" is recognized to mean all signals except those\n\
9668 used by the debugger, typically SIGTRAP and SIGINT.\n\
9670 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
9671 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
9672 Stop means reenter debugger if this signal happens (implies print).\n\
9673 Print means print a message if this signal happens.\n\
9674 Pass means let program see this signal; otherwise program doesn't know.\n\
9675 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
9676 Pass and Stop may be combined.\n\
9678 Multiple signals may be specified. Signal numbers and signal names\n\
9679 may be interspersed with actions, with the actions being performed for\n\
9680 all signals cumulatively specified."));
9681 set_cmd_completer (c
, handle_completer
);
9684 stop_command
= add_cmd ("stop", class_obscure
,
9685 not_just_help_class_command
, _("\
9686 There is no `stop' command, but you can set a hook on `stop'.\n\
9687 This allows you to set a list of commands to be run each time execution\n\
9688 of the program stops."), &cmdlist
);
9690 add_setshow_boolean_cmd
9691 ("infrun", class_maintenance
, &debug_infrun
,
9692 _("Set inferior debugging."),
9693 _("Show inferior debugging."),
9694 _("When non-zero, inferior specific debugging is enabled."),
9695 NULL
, show_debug_infrun
, &setdebuglist
, &showdebuglist
);
9697 add_setshow_boolean_cmd ("non-stop", no_class
,
9699 Set whether gdb controls the inferior in non-stop mode."), _("\
9700 Show whether gdb controls the inferior in non-stop mode."), _("\
9701 When debugging a multi-threaded program and this setting is\n\
9702 off (the default, also called all-stop mode), when one thread stops\n\
9703 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
9704 all other threads in the program while you interact with the thread of\n\
9705 interest. When you continue or step a thread, you can allow the other\n\
9706 threads to run, or have them remain stopped, but while you inspect any\n\
9707 thread's state, all threads stop.\n\
9709 In non-stop mode, when one thread stops, other threads can continue\n\
9710 to run freely. You'll be able to step each thread independently,\n\
9711 leave it stopped or free to run as needed."),
9717 for (size_t i
= 0; i
< GDB_SIGNAL_LAST
; i
++)
9720 signal_print
[i
] = 1;
9721 signal_program
[i
] = 1;
9722 signal_catch
[i
] = 0;
9725 /* Signals caused by debugger's own actions should not be given to
9726 the program afterwards.
9728 Do not deliver GDB_SIGNAL_TRAP by default, except when the user
9729 explicitly specifies that it should be delivered to the target
9730 program. Typically, that would occur when a user is debugging a
9731 target monitor on a simulator: the target monitor sets a
9732 breakpoint; the simulator encounters this breakpoint and halts
9733 the simulation handing control to GDB; GDB, noting that the stop
9734 address doesn't map to any known breakpoint, returns control back
9735 to the simulator; the simulator then delivers the hardware
9736 equivalent of a GDB_SIGNAL_TRAP to the program being
9738 signal_program
[GDB_SIGNAL_TRAP
] = 0;
9739 signal_program
[GDB_SIGNAL_INT
] = 0;
9741 /* Signals that are not errors should not normally enter the debugger. */
9742 signal_stop
[GDB_SIGNAL_ALRM
] = 0;
9743 signal_print
[GDB_SIGNAL_ALRM
] = 0;
9744 signal_stop
[GDB_SIGNAL_VTALRM
] = 0;
9745 signal_print
[GDB_SIGNAL_VTALRM
] = 0;
9746 signal_stop
[GDB_SIGNAL_PROF
] = 0;
9747 signal_print
[GDB_SIGNAL_PROF
] = 0;
9748 signal_stop
[GDB_SIGNAL_CHLD
] = 0;
9749 signal_print
[GDB_SIGNAL_CHLD
] = 0;
9750 signal_stop
[GDB_SIGNAL_IO
] = 0;
9751 signal_print
[GDB_SIGNAL_IO
] = 0;
9752 signal_stop
[GDB_SIGNAL_POLL
] = 0;
9753 signal_print
[GDB_SIGNAL_POLL
] = 0;
9754 signal_stop
[GDB_SIGNAL_URG
] = 0;
9755 signal_print
[GDB_SIGNAL_URG
] = 0;
9756 signal_stop
[GDB_SIGNAL_WINCH
] = 0;
9757 signal_print
[GDB_SIGNAL_WINCH
] = 0;
9758 signal_stop
[GDB_SIGNAL_PRIO
] = 0;
9759 signal_print
[GDB_SIGNAL_PRIO
] = 0;
9761 /* These signals are used internally by user-level thread
9762 implementations. (See signal(5) on Solaris.) Like the above
9763 signals, a healthy program receives and handles them as part of
9764 its normal operation. */
9765 signal_stop
[GDB_SIGNAL_LWP
] = 0;
9766 signal_print
[GDB_SIGNAL_LWP
] = 0;
9767 signal_stop
[GDB_SIGNAL_WAITING
] = 0;
9768 signal_print
[GDB_SIGNAL_WAITING
] = 0;
9769 signal_stop
[GDB_SIGNAL_CANCEL
] = 0;
9770 signal_print
[GDB_SIGNAL_CANCEL
] = 0;
9771 signal_stop
[GDB_SIGNAL_LIBRT
] = 0;
9772 signal_print
[GDB_SIGNAL_LIBRT
] = 0;
9774 /* Update cached state. */
9775 signal_cache_update (-1);
9777 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support
,
9778 &stop_on_solib_events
, _("\
9779 Set stopping for shared library events."), _("\
9780 Show stopping for shared library events."), _("\
9781 If nonzero, gdb will give control to the user when the dynamic linker\n\
9782 notifies gdb of shared library events. The most common event of interest\n\
9783 to the user would be loading/unloading of a new library."),
9784 set_stop_on_solib_events
,
9785 show_stop_on_solib_events
,
9786 &setlist
, &showlist
);
9788 add_setshow_enum_cmd ("follow-fork-mode", class_run
,
9789 follow_fork_mode_kind_names
,
9790 &follow_fork_mode_string
, _("\
9791 Set debugger response to a program call of fork or vfork."), _("\
9792 Show debugger response to a program call of fork or vfork."), _("\
9793 A fork or vfork creates a new process. follow-fork-mode can be:\n\
9794 parent - the original process is debugged after a fork\n\
9795 child - the new process is debugged after a fork\n\
9796 The unfollowed process will continue to run.\n\
9797 By default, the debugger will follow the parent process."),
9799 show_follow_fork_mode_string
,
9800 &setlist
, &showlist
);
9802 add_setshow_enum_cmd ("follow-exec-mode", class_run
,
9803 follow_exec_mode_names
,
9804 &follow_exec_mode_string
, _("\
9805 Set debugger response to a program call of exec."), _("\
9806 Show debugger response to a program call of exec."), _("\
9807 An exec call replaces the program image of a process.\n\
9809 follow-exec-mode can be:\n\
9811 new - the debugger creates a new inferior and rebinds the process\n\
9812 to this new inferior. The program the process was running before\n\
9813 the exec call can be restarted afterwards by restarting the original\n\
9816 same - the debugger keeps the process bound to the same inferior.\n\
9817 The new executable image replaces the previous executable loaded in\n\
9818 the inferior. Restarting the inferior after the exec call restarts\n\
9819 the executable the process was running after the exec call.\n\
9821 By default, the debugger will use the same inferior."),
9823 show_follow_exec_mode_string
,
9824 &setlist
, &showlist
);
9826 add_setshow_enum_cmd ("scheduler-locking", class_run
,
9827 scheduler_enums
, &scheduler_mode
, _("\
9828 Set mode for locking scheduler during execution."), _("\
9829 Show mode for locking scheduler during execution."), _("\
9830 off == no locking (threads may preempt at any time)\n\
9831 on == full locking (no thread except the current thread may run)\n\
9832 This applies to both normal execution and replay mode.\n\
9833 step == scheduler locked during stepping commands (step, next, stepi, nexti).\n\
9834 In this mode, other threads may run during other commands.\n\
9835 This applies to both normal execution and replay mode.\n\
9836 replay == scheduler locked in replay mode and unlocked during normal execution."),
9837 set_schedlock_func
, /* traps on target vector */
9838 show_scheduler_mode
,
9839 &setlist
, &showlist
);
9841 add_setshow_boolean_cmd ("schedule-multiple", class_run
, &sched_multi
, _("\
9842 Set mode for resuming threads of all processes."), _("\
9843 Show mode for resuming threads of all processes."), _("\
9844 When on, execution commands (such as 'continue' or 'next') resume all\n\
9845 threads of all processes. When off (which is the default), execution\n\
9846 commands only resume the threads of the current process. The set of\n\
9847 threads that are resumed is further refined by the scheduler-locking\n\
9848 mode (see help set scheduler-locking)."),
9850 show_schedule_multiple
,
9851 &setlist
, &showlist
);
9853 add_setshow_boolean_cmd ("step-mode", class_run
, &step_stop_if_no_debug
, _("\
9854 Set mode of the step operation."), _("\
9855 Show mode of the step operation."), _("\
9856 When set, doing a step over a function without debug line information\n\
9857 will stop at the first instruction of that function. Otherwise, the\n\
9858 function is skipped and the step command stops at a different source line."),
9860 show_step_stop_if_no_debug
,
9861 &setlist
, &showlist
);
9863 add_setshow_auto_boolean_cmd ("displaced-stepping", class_run
,
9864 &can_use_displaced_stepping
, _("\
9865 Set debugger's willingness to use displaced stepping."), _("\
9866 Show debugger's willingness to use displaced stepping."), _("\
9867 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
9868 supported by the target architecture. If off, gdb will not use displaced\n\
9869 stepping to step over breakpoints, even if such is supported by the target\n\
9870 architecture. If auto (which is the default), gdb will use displaced stepping\n\
9871 if the target architecture supports it and non-stop mode is active, but will not\n\
9872 use it in all-stop mode (see help set non-stop)."),
9874 show_can_use_displaced_stepping
,
9875 &setlist
, &showlist
);
9877 add_setshow_enum_cmd ("exec-direction", class_run
, exec_direction_names
,
9878 &exec_direction
, _("Set direction of execution.\n\
9879 Options are 'forward' or 'reverse'."),
9880 _("Show direction of execution (forward/reverse)."),
9881 _("Tells gdb whether to execute forward or backward."),
9882 set_exec_direction_func
, show_exec_direction_func
,
9883 &setlist
, &showlist
);
9885 /* Set/show detach-on-fork: user-settable mode. */
9887 add_setshow_boolean_cmd ("detach-on-fork", class_run
, &detach_fork
, _("\
9888 Set whether gdb will detach the child of a fork."), _("\
9889 Show whether gdb will detach the child of a fork."), _("\
9890 Tells gdb whether to detach the child of a fork."),
9891 NULL
, NULL
, &setlist
, &showlist
);
9893 /* Set/show disable address space randomization mode. */
9895 add_setshow_boolean_cmd ("disable-randomization", class_support
,
9896 &disable_randomization
, _("\
9897 Set disabling of debuggee's virtual address space randomization."), _("\
9898 Show disabling of debuggee's virtual address space randomization."), _("\
9899 When this mode is on (which is the default), randomization of the virtual\n\
9900 address space is disabled. Standalone programs run with the randomization\n\
9901 enabled by default on some platforms."),
9902 &set_disable_randomization
,
9903 &show_disable_randomization
,
9904 &setlist
, &showlist
);
9906 /* ptid initializations */
9907 inferior_ptid
= null_ptid
;
9908 target_last_wait_ptid
= minus_one_ptid
;
9910 gdb::observers::thread_ptid_changed
.attach (infrun_thread_ptid_changed
,
9912 gdb::observers::thread_stop_requested
.attach (infrun_thread_stop_requested
,
9914 gdb::observers::thread_exit
.attach (infrun_thread_thread_exit
, "infrun");
9915 gdb::observers::inferior_exit
.attach (infrun_inferior_exit
, "infrun");
9916 gdb::observers::inferior_execd
.attach (infrun_inferior_execd
, "infrun");
9918 /* Explicitly create without lookup, since that tries to create a
9919 value with a void typed value, and when we get here, gdbarch
9920 isn't initialized yet. At this point, we're quite sure there
9921 isn't another convenience variable of the same name. */
9922 create_internalvar_type_lazy ("_siginfo", &siginfo_funcs
, NULL
);
9924 add_setshow_boolean_cmd ("observer", no_class
,
9925 &observer_mode_1
, _("\
9926 Set whether gdb controls the inferior in observer mode."), _("\
9927 Show whether gdb controls the inferior in observer mode."), _("\
9928 In observer mode, GDB can get data from the inferior, but not\n\
9929 affect its execution. Registers and memory may not be changed,\n\
9930 breakpoints may not be set, and the program cannot be interrupted\n\
9938 selftests::register_test ("infrun_thread_ptid_changed",
9939 selftests::infrun_thread_ptid_changed
);