1 /* Target-struct-independent code to start (run) and stop an inferior
4 Copyright (C) 1986-2022 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "displaced-stepping.h"
28 #include "breakpoint.h"
32 #include "target-connection.h"
33 #include "gdbthread.h"
40 #include "observable.h"
45 #include "mi/mi-common.h"
46 #include "event-top.h"
48 #include "record-full.h"
49 #include "inline-frame.h"
51 #include "tracepoint.h"
55 #include "completer.h"
56 #include "target-descriptions.h"
57 #include "target-dcache.h"
60 #include "gdbsupport/event-loop.h"
61 #include "thread-fsm.h"
62 #include "gdbsupport/enum-flags.h"
63 #include "progspace-and-thread.h"
64 #include "gdbsupport/gdb_optional.h"
65 #include "arch-utils.h"
66 #include "gdbsupport/scope-exit.h"
67 #include "gdbsupport/forward-scope-exit.h"
68 #include "gdbsupport/gdb_select.h"
69 #include <unordered_map>
70 #include "async-event.h"
71 #include "gdbsupport/selftest.h"
72 #include "scoped-mock-context.h"
73 #include "test-target.h"
74 #include "gdbsupport/common-debug.h"
76 /* Prototypes for local functions */
78 static void sig_print_info (enum gdb_signal
);
80 static void sig_print_header (void);
82 static void follow_inferior_reset_breakpoints (void);
84 static bool currently_stepping (struct thread_info
*tp
);
86 static void insert_hp_step_resume_breakpoint_at_frame (struct frame_info
*);
88 static void insert_step_resume_breakpoint_at_caller (struct frame_info
*);
90 static void insert_longjmp_resume_breakpoint (struct gdbarch
*, CORE_ADDR
);
92 static bool maybe_software_singlestep (struct gdbarch
*gdbarch
, CORE_ADDR pc
);
94 static void resume (gdb_signal sig
);
96 static void wait_for_inferior (inferior
*inf
);
98 static void restart_threads (struct thread_info
*event_thread
,
99 inferior
*inf
= nullptr);
101 static bool start_step_over (void);
103 /* Asynchronous signal handler registered as event loop source for
104 when we have pending events ready to be passed to the core. */
105 static struct async_event_handler
*infrun_async_inferior_event_token
;
107 /* Stores whether infrun_async was previously enabled or disabled.
108 Starts off as -1, indicating "never enabled/disabled". */
109 static int infrun_is_async
= -1;
114 infrun_async (int enable
)
116 if (infrun_is_async
!= enable
)
118 infrun_is_async
= enable
;
120 infrun_debug_printf ("enable=%d", enable
);
123 mark_async_event_handler (infrun_async_inferior_event_token
);
125 clear_async_event_handler (infrun_async_inferior_event_token
);
132 mark_infrun_async_event_handler (void)
134 mark_async_event_handler (infrun_async_inferior_event_token
);
137 /* When set, stop the 'step' command if we enter a function which has
138 no line number information. The normal behavior is that we step
139 over such function. */
140 bool step_stop_if_no_debug
= false;
142 show_step_stop_if_no_debug (struct ui_file
*file
, int from_tty
,
143 struct cmd_list_element
*c
, const char *value
)
145 fprintf_filtered (file
, _("Mode of the step operation is %s.\n"), value
);
148 /* proceed and normal_stop use this to notify the user when the
149 inferior stopped in a different thread than it had been running
152 static ptid_t previous_inferior_ptid
;
154 /* If set (default for legacy reasons), when following a fork, GDB
155 will detach from one of the fork branches, child or parent.
156 Exactly which branch is detached depends on 'set follow-fork-mode'
159 static bool detach_fork
= true;
161 bool debug_infrun
= false;
163 show_debug_infrun (struct ui_file
*file
, int from_tty
,
164 struct cmd_list_element
*c
, const char *value
)
166 fprintf_filtered (file
, _("Inferior debugging is %s.\n"), value
);
169 /* Support for disabling address space randomization. */
171 bool disable_randomization
= true;
174 show_disable_randomization (struct ui_file
*file
, int from_tty
,
175 struct cmd_list_element
*c
, const char *value
)
177 if (target_supports_disable_randomization ())
178 fprintf_filtered (file
,
179 _("Disabling randomization of debuggee's "
180 "virtual address space is %s.\n"),
183 fputs_filtered (_("Disabling randomization of debuggee's "
184 "virtual address space is unsupported on\n"
185 "this platform.\n"), file
);
189 set_disable_randomization (const char *args
, int from_tty
,
190 struct cmd_list_element
*c
)
192 if (!target_supports_disable_randomization ())
193 error (_("Disabling randomization of debuggee's "
194 "virtual address space is unsupported on\n"
198 /* User interface for non-stop mode. */
200 bool non_stop
= false;
201 static bool non_stop_1
= false;
204 set_non_stop (const char *args
, int from_tty
,
205 struct cmd_list_element
*c
)
207 if (target_has_execution ())
209 non_stop_1
= non_stop
;
210 error (_("Cannot change this setting while the inferior is running."));
213 non_stop
= non_stop_1
;
217 show_non_stop (struct ui_file
*file
, int from_tty
,
218 struct cmd_list_element
*c
, const char *value
)
220 fprintf_filtered (file
,
221 _("Controlling the inferior in non-stop mode is %s.\n"),
225 /* "Observer mode" is somewhat like a more extreme version of
226 non-stop, in which all GDB operations that might affect the
227 target's execution have been disabled. */
229 static bool observer_mode
= false;
230 static bool observer_mode_1
= false;
233 set_observer_mode (const char *args
, int from_tty
,
234 struct cmd_list_element
*c
)
236 if (target_has_execution ())
238 observer_mode_1
= observer_mode
;
239 error (_("Cannot change this setting while the inferior is running."));
242 observer_mode
= observer_mode_1
;
244 may_write_registers
= !observer_mode
;
245 may_write_memory
= !observer_mode
;
246 may_insert_breakpoints
= !observer_mode
;
247 may_insert_tracepoints
= !observer_mode
;
248 /* We can insert fast tracepoints in or out of observer mode,
249 but enable them if we're going into this mode. */
251 may_insert_fast_tracepoints
= true;
252 may_stop
= !observer_mode
;
253 update_target_permissions ();
255 /* Going *into* observer mode we must force non-stop, then
256 going out we leave it that way. */
259 pagination_enabled
= 0;
260 non_stop
= non_stop_1
= true;
264 printf_filtered (_("Observer mode is now %s.\n"),
265 (observer_mode
? "on" : "off"));
269 show_observer_mode (struct ui_file
*file
, int from_tty
,
270 struct cmd_list_element
*c
, const char *value
)
272 fprintf_filtered (file
, _("Observer mode is %s.\n"), value
);
275 /* This updates the value of observer mode based on changes in
276 permissions. Note that we are deliberately ignoring the values of
277 may-write-registers and may-write-memory, since the user may have
278 reason to enable these during a session, for instance to turn on a
279 debugging-related global. */
282 update_observer_mode (void)
284 bool newval
= (!may_insert_breakpoints
285 && !may_insert_tracepoints
286 && may_insert_fast_tracepoints
290 /* Let the user know if things change. */
291 if (newval
!= observer_mode
)
292 printf_filtered (_("Observer mode is now %s.\n"),
293 (newval
? "on" : "off"));
295 observer_mode
= observer_mode_1
= newval
;
298 /* Tables of how to react to signals; the user sets them. */
300 static unsigned char signal_stop
[GDB_SIGNAL_LAST
];
301 static unsigned char signal_print
[GDB_SIGNAL_LAST
];
302 static unsigned char signal_program
[GDB_SIGNAL_LAST
];
304 /* Table of signals that are registered with "catch signal". A
305 non-zero entry indicates that the signal is caught by some "catch
307 static unsigned char signal_catch
[GDB_SIGNAL_LAST
];
309 /* Table of signals that the target may silently handle.
310 This is automatically determined from the flags above,
311 and simply cached here. */
312 static unsigned char signal_pass
[GDB_SIGNAL_LAST
];
314 #define SET_SIGS(nsigs,sigs,flags) \
316 int signum = (nsigs); \
317 while (signum-- > 0) \
318 if ((sigs)[signum]) \
319 (flags)[signum] = 1; \
322 #define UNSET_SIGS(nsigs,sigs,flags) \
324 int signum = (nsigs); \
325 while (signum-- > 0) \
326 if ((sigs)[signum]) \
327 (flags)[signum] = 0; \
330 /* Update the target's copy of SIGNAL_PROGRAM. The sole purpose of
331 this function is to avoid exporting `signal_program'. */
334 update_signals_program_target (void)
336 target_program_signals (signal_program
);
339 /* Value to pass to target_resume() to cause all threads to resume. */
341 #define RESUME_ALL minus_one_ptid
343 /* Command list pointer for the "stop" placeholder. */
345 static struct cmd_list_element
*stop_command
;
347 /* Nonzero if we want to give control to the user when we're notified
348 of shared library events by the dynamic linker. */
349 int stop_on_solib_events
;
351 /* Enable or disable optional shared library event breakpoints
352 as appropriate when the above flag is changed. */
355 set_stop_on_solib_events (const char *args
,
356 int from_tty
, struct cmd_list_element
*c
)
358 update_solib_breakpoints ();
362 show_stop_on_solib_events (struct ui_file
*file
, int from_tty
,
363 struct cmd_list_element
*c
, const char *value
)
365 fprintf_filtered (file
, _("Stopping for shared library events is %s.\n"),
369 /* True after stop if current stack frame should be printed. */
371 static bool stop_print_frame
;
373 /* This is a cached copy of the target/ptid/waitstatus of the last
374 event returned by target_wait()/deprecated_target_wait_hook().
375 This information is returned by get_last_target_status(). */
376 static process_stratum_target
*target_last_proc_target
;
377 static ptid_t target_last_wait_ptid
;
378 static struct target_waitstatus target_last_waitstatus
;
380 void init_thread_stepping_state (struct thread_info
*tss
);
382 static const char follow_fork_mode_child
[] = "child";
383 static const char follow_fork_mode_parent
[] = "parent";
385 static const char *const follow_fork_mode_kind_names
[] = {
386 follow_fork_mode_child
,
387 follow_fork_mode_parent
,
391 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
393 show_follow_fork_mode_string (struct ui_file
*file
, int from_tty
,
394 struct cmd_list_element
*c
, const char *value
)
396 fprintf_filtered (file
,
397 _("Debugger response to a program "
398 "call of fork or vfork is \"%s\".\n"),
403 /* Handle changes to the inferior list based on the type of fork,
404 which process is being followed, and whether the other process
405 should be detached. On entry inferior_ptid must be the ptid of
406 the fork parent. At return inferior_ptid is the ptid of the
407 followed inferior. */
410 follow_fork_inferior (bool follow_child
, bool detach_fork
)
413 ptid_t parent_ptid
, child_ptid
;
415 has_vforked
= (inferior_thread ()->pending_follow
.kind
416 == TARGET_WAITKIND_VFORKED
);
417 parent_ptid
= inferior_ptid
;
418 child_ptid
= inferior_thread ()->pending_follow
.value
.related_pid
;
421 && !non_stop
/* Non-stop always resumes both branches. */
422 && current_ui
->prompt_state
== PROMPT_BLOCKED
423 && !(follow_child
|| detach_fork
|| sched_multi
))
425 /* The parent stays blocked inside the vfork syscall until the
426 child execs or exits. If we don't let the child run, then
427 the parent stays blocked. If we're telling the parent to run
428 in the foreground, the user will not be able to ctrl-c to get
429 back the terminal, effectively hanging the debug session. */
430 fprintf_filtered (gdb_stderr
, _("\
431 Can not resume the parent process over vfork in the foreground while\n\
432 holding the child stopped. Try \"set detach-on-fork\" or \
433 \"set schedule-multiple\".\n"));
437 inferior
*parent_inf
= current_inferior ();
438 gdb_assert (parent_inf
->thread_waiting_for_vfork_done
== nullptr);
442 /* Detach new forked process? */
445 /* Before detaching from the child, remove all breakpoints
446 from it. If we forked, then this has already been taken
447 care of by infrun.c. If we vforked however, any
448 breakpoint inserted in the parent is visible in the
449 child, even those added while stopped in a vfork
450 catchpoint. This will remove the breakpoints from the
451 parent also, but they'll be reinserted below. */
454 /* Keep breakpoints list in sync. */
455 remove_breakpoints_inf (current_inferior ());
458 if (print_inferior_events
)
460 /* Ensure that we have a process ptid. */
461 ptid_t process_ptid
= ptid_t (child_ptid
.pid ());
463 target_terminal::ours_for_output ();
464 fprintf_filtered (gdb_stdlog
,
465 _("[Detaching after %s from child %s]\n"),
466 has_vforked
? "vfork" : "fork",
467 target_pid_to_str (process_ptid
).c_str ());
474 /* Add process to GDB's tables. */
475 child_inf
= add_inferior (child_ptid
.pid ());
477 child_inf
->attach_flag
= parent_inf
->attach_flag
;
478 copy_terminal_info (child_inf
, parent_inf
);
479 child_inf
->gdbarch
= parent_inf
->gdbarch
;
480 copy_inferior_target_desc_info (child_inf
, parent_inf
);
482 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
484 set_current_inferior (child_inf
);
485 switch_to_no_thread ();
486 child_inf
->symfile_flags
= SYMFILE_NO_READ
;
487 child_inf
->push_target (parent_inf
->process_target ());
488 thread_info
*child_thr
489 = add_thread_silent (child_inf
->process_target (), child_ptid
);
491 /* If this is a vfork child, then the address-space is
492 shared with the parent. */
495 child_inf
->pspace
= parent_inf
->pspace
;
496 child_inf
->aspace
= parent_inf
->aspace
;
500 /* The parent will be frozen until the child is done
501 with the shared region. Keep track of the
503 child_inf
->vfork_parent
= parent_inf
;
504 child_inf
->pending_detach
= 0;
505 parent_inf
->vfork_child
= child_inf
;
506 parent_inf
->pending_detach
= 0;
508 /* Now that the inferiors and program spaces are all
509 wired up, we can switch to the child thread (which
510 switches inferior and program space too). */
511 switch_to_thread (child_thr
);
515 child_inf
->aspace
= new_address_space ();
516 child_inf
->pspace
= new program_space (child_inf
->aspace
);
517 child_inf
->removable
= 1;
518 set_current_program_space (child_inf
->pspace
);
519 clone_program_space (child_inf
->pspace
, parent_inf
->pspace
);
521 /* solib_create_inferior_hook relies on the current
523 switch_to_thread (child_thr
);
525 /* Let the shared library layer (e.g., solib-svr4) learn
526 about this new process, relocate the cloned exec, pull
527 in shared libraries, and install the solib event
528 breakpoint. If a "cloned-VM" event was propagated
529 better throughout the core, this wouldn't be
531 scoped_restore restore_in_initial_library_scan
532 = make_scoped_restore (&child_inf
->in_initial_library_scan
,
534 solib_create_inferior_hook (0);
540 /* If we detached from the child, then we have to be careful
541 to not insert breakpoints in the parent until the child
542 is done with the shared memory region. However, if we're
543 staying attached to the child, then we can and should
544 insert breakpoints, so that we can debug it. A
545 subsequent child exec or exit is enough to know when does
546 the child stops using the parent's address space. */
547 parent_inf
->thread_waiting_for_vfork_done
548 = detach_fork
? inferior_thread () : nullptr;
549 parent_inf
->pspace
->breakpoints_not_allowed
= detach_fork
;
554 /* Follow the child. */
556 struct program_space
*parent_pspace
;
558 if (print_inferior_events
)
560 std::string parent_pid
= target_pid_to_str (parent_ptid
);
561 std::string child_pid
= target_pid_to_str (child_ptid
);
563 target_terminal::ours_for_output ();
564 fprintf_filtered (gdb_stdlog
,
565 _("[Attaching after %s %s to child %s]\n"),
567 has_vforked
? "vfork" : "fork",
571 /* Add the new inferior first, so that the target_detach below
572 doesn't unpush the target. */
574 child_inf
= add_inferior (child_ptid
.pid ());
576 child_inf
->attach_flag
= parent_inf
->attach_flag
;
577 copy_terminal_info (child_inf
, parent_inf
);
578 child_inf
->gdbarch
= parent_inf
->gdbarch
;
579 copy_inferior_target_desc_info (child_inf
, parent_inf
);
581 parent_pspace
= parent_inf
->pspace
;
583 process_stratum_target
*target
= parent_inf
->process_target ();
586 /* Hold a strong reference to the target while (maybe)
587 detaching the parent. Otherwise detaching could close the
589 auto target_ref
= target_ops_ref::new_reference (target
);
591 /* If we're vforking, we want to hold on to the parent until
592 the child exits or execs. At child exec or exit time we
593 can remove the old breakpoints from the parent and detach
594 or resume debugging it. Otherwise, detach the parent now;
595 we'll want to reuse it's program/address spaces, but we
596 can't set them to the child before removing breakpoints
597 from the parent, otherwise, the breakpoints module could
598 decide to remove breakpoints from the wrong process (since
599 they'd be assigned to the same address space). */
603 gdb_assert (child_inf
->vfork_parent
== NULL
);
604 gdb_assert (parent_inf
->vfork_child
== NULL
);
605 child_inf
->vfork_parent
= parent_inf
;
606 child_inf
->pending_detach
= 0;
607 parent_inf
->vfork_child
= child_inf
;
608 parent_inf
->pending_detach
= detach_fork
;
610 else if (detach_fork
)
612 if (print_inferior_events
)
614 /* Ensure that we have a process ptid. */
615 ptid_t process_ptid
= ptid_t (parent_ptid
.pid ());
617 target_terminal::ours_for_output ();
618 fprintf_filtered (gdb_stdlog
,
619 _("[Detaching after fork from "
621 target_pid_to_str (process_ptid
).c_str ());
624 target_detach (parent_inf
, 0);
628 /* Note that the detach above makes PARENT_INF dangling. */
630 /* Add the child thread to the appropriate lists, and switch
631 to this new thread, before cloning the program space, and
632 informing the solib layer about this new process. */
634 set_current_inferior (child_inf
);
635 child_inf
->push_target (target
);
638 thread_info
*child_thr
= add_thread_silent (target
, child_ptid
);
640 /* If this is a vfork child, then the address-space is shared
641 with the parent. If we detached from the parent, then we can
642 reuse the parent's program/address spaces. */
643 if (has_vforked
|| detach_fork
)
645 child_inf
->pspace
= parent_pspace
;
646 child_inf
->aspace
= child_inf
->pspace
->aspace
;
652 child_inf
->aspace
= new_address_space ();
653 child_inf
->pspace
= new program_space (child_inf
->aspace
);
654 child_inf
->removable
= 1;
655 child_inf
->symfile_flags
= SYMFILE_NO_READ
;
656 set_current_program_space (child_inf
->pspace
);
657 clone_program_space (child_inf
->pspace
, parent_pspace
);
659 /* Let the shared library layer (e.g., solib-svr4) learn
660 about this new process, relocate the cloned exec, pull in
661 shared libraries, and install the solib event breakpoint.
662 If a "cloned-VM" event was propagated better throughout
663 the core, this wouldn't be required. */
664 scoped_restore restore_in_initial_library_scan
665 = make_scoped_restore (&child_inf
->in_initial_library_scan
, true);
666 solib_create_inferior_hook (0);
669 switch_to_thread (child_thr
);
672 target_follow_fork (follow_child
, detach_fork
);
677 /* Tell the target to follow the fork we're stopped at. Returns true
678 if the inferior should be resumed; false, if the target for some
679 reason decided it's best not to resume. */
684 bool follow_child
= (follow_fork_mode_string
== follow_fork_mode_child
);
685 bool should_resume
= true;
686 struct thread_info
*tp
;
688 /* Copy user stepping state to the new inferior thread. FIXME: the
689 followed fork child thread should have a copy of most of the
690 parent thread structure's run control related fields, not just these.
691 Initialized to avoid "may be used uninitialized" warnings from gcc. */
692 struct breakpoint
*step_resume_breakpoint
= NULL
;
693 struct breakpoint
*exception_resume_breakpoint
= NULL
;
694 CORE_ADDR step_range_start
= 0;
695 CORE_ADDR step_range_end
= 0;
696 int current_line
= 0;
697 symtab
*current_symtab
= NULL
;
698 struct frame_id step_frame_id
= { 0 };
699 struct thread_fsm
*thread_fsm
= NULL
;
703 process_stratum_target
*wait_target
;
705 struct target_waitstatus wait_status
;
707 /* Get the last target status returned by target_wait(). */
708 get_last_target_status (&wait_target
, &wait_ptid
, &wait_status
);
710 /* If not stopped at a fork event, then there's nothing else to
712 if (wait_status
.kind
!= TARGET_WAITKIND_FORKED
713 && wait_status
.kind
!= TARGET_WAITKIND_VFORKED
)
716 /* Check if we switched over from WAIT_PTID, since the event was
718 if (wait_ptid
!= minus_one_ptid
719 && (current_inferior ()->process_target () != wait_target
720 || inferior_ptid
!= wait_ptid
))
722 /* We did. Switch back to WAIT_PTID thread, to tell the
723 target to follow it (in either direction). We'll
724 afterwards refuse to resume, and inform the user what
726 thread_info
*wait_thread
= find_thread_ptid (wait_target
, wait_ptid
);
727 switch_to_thread (wait_thread
);
728 should_resume
= false;
732 tp
= inferior_thread ();
734 /* If there were any forks/vforks that were caught and are now to be
735 followed, then do so now. */
736 switch (tp
->pending_follow
.kind
)
738 case TARGET_WAITKIND_FORKED
:
739 case TARGET_WAITKIND_VFORKED
:
741 ptid_t parent
, child
;
743 /* If the user did a next/step, etc, over a fork call,
744 preserve the stepping state in the fork child. */
745 if (follow_child
&& should_resume
)
747 step_resume_breakpoint
= clone_momentary_breakpoint
748 (tp
->control
.step_resume_breakpoint
);
749 step_range_start
= tp
->control
.step_range_start
;
750 step_range_end
= tp
->control
.step_range_end
;
751 current_line
= tp
->current_line
;
752 current_symtab
= tp
->current_symtab
;
753 step_frame_id
= tp
->control
.step_frame_id
;
754 exception_resume_breakpoint
755 = clone_momentary_breakpoint (tp
->control
.exception_resume_breakpoint
);
756 thread_fsm
= tp
->thread_fsm
;
758 /* For now, delete the parent's sr breakpoint, otherwise,
759 parent/child sr breakpoints are considered duplicates,
760 and the child version will not be installed. Remove
761 this when the breakpoints module becomes aware of
762 inferiors and address spaces. */
763 delete_step_resume_breakpoint (tp
);
764 tp
->control
.step_range_start
= 0;
765 tp
->control
.step_range_end
= 0;
766 tp
->control
.step_frame_id
= null_frame_id
;
767 delete_exception_resume_breakpoint (tp
);
768 tp
->thread_fsm
= NULL
;
771 parent
= inferior_ptid
;
772 child
= tp
->pending_follow
.value
.related_pid
;
774 /* If handling a vfork, stop all the inferior's threads, they will be
775 restarted when the vfork shared region is complete. */
776 if (tp
->pending_follow
.kind
== TARGET_WAITKIND_VFORKED
777 && target_is_non_stop_p ())
778 stop_all_threads ("handling vfork", tp
->inf
);
780 process_stratum_target
*parent_targ
= tp
->inf
->process_target ();
781 /* Set up inferior(s) as specified by the caller, and tell the
782 target to do whatever is necessary to follow either parent
784 if (follow_fork_inferior (follow_child
, detach_fork
))
786 /* Target refused to follow, or there's some other reason
787 we shouldn't resume. */
792 /* This pending follow fork event is now handled, one way
793 or another. The previous selected thread may be gone
794 from the lists by now, but if it is still around, need
795 to clear the pending follow request. */
796 tp
= find_thread_ptid (parent_targ
, parent
);
798 tp
->pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
800 /* This makes sure we don't try to apply the "Switched
801 over from WAIT_PID" logic above. */
802 nullify_last_target_wait_ptid ();
804 /* If we followed the child, switch to it... */
807 thread_info
*child_thr
= find_thread_ptid (parent_targ
, child
);
808 switch_to_thread (child_thr
);
810 /* ... and preserve the stepping state, in case the
811 user was stepping over the fork call. */
814 tp
= inferior_thread ();
815 tp
->control
.step_resume_breakpoint
816 = step_resume_breakpoint
;
817 tp
->control
.step_range_start
= step_range_start
;
818 tp
->control
.step_range_end
= step_range_end
;
819 tp
->current_line
= current_line
;
820 tp
->current_symtab
= current_symtab
;
821 tp
->control
.step_frame_id
= step_frame_id
;
822 tp
->control
.exception_resume_breakpoint
823 = exception_resume_breakpoint
;
824 tp
->thread_fsm
= thread_fsm
;
828 /* If we get here, it was because we're trying to
829 resume from a fork catchpoint, but, the user
830 has switched threads away from the thread that
831 forked. In that case, the resume command
832 issued is most likely not applicable to the
833 child, so just warn, and refuse to resume. */
834 warning (_("Not resuming: switched threads "
835 "before following fork child."));
838 /* Reset breakpoints in the child as appropriate. */
839 follow_inferior_reset_breakpoints ();
844 case TARGET_WAITKIND_SPURIOUS
:
845 /* Nothing to follow. */
848 internal_error (__FILE__
, __LINE__
,
849 "Unexpected pending_follow.kind %d\n",
850 tp
->pending_follow
.kind
);
854 return should_resume
;
858 follow_inferior_reset_breakpoints (void)
860 struct thread_info
*tp
= inferior_thread ();
862 /* Was there a step_resume breakpoint? (There was if the user
863 did a "next" at the fork() call.) If so, explicitly reset its
864 thread number. Cloned step_resume breakpoints are disabled on
865 creation, so enable it here now that it is associated with the
868 step_resumes are a form of bp that are made to be per-thread.
869 Since we created the step_resume bp when the parent process
870 was being debugged, and now are switching to the child process,
871 from the breakpoint package's viewpoint, that's a switch of
872 "threads". We must update the bp's notion of which thread
873 it is for, or it'll be ignored when it triggers. */
875 if (tp
->control
.step_resume_breakpoint
)
877 breakpoint_re_set_thread (tp
->control
.step_resume_breakpoint
);
878 tp
->control
.step_resume_breakpoint
->loc
->enabled
= 1;
881 /* Treat exception_resume breakpoints like step_resume breakpoints. */
882 if (tp
->control
.exception_resume_breakpoint
)
884 breakpoint_re_set_thread (tp
->control
.exception_resume_breakpoint
);
885 tp
->control
.exception_resume_breakpoint
->loc
->enabled
= 1;
888 /* Reinsert all breakpoints in the child. The user may have set
889 breakpoints after catching the fork, in which case those
890 were never set in the child, but only in the parent. This makes
891 sure the inserted breakpoints match the breakpoint list. */
893 breakpoint_re_set ();
894 insert_breakpoints ();
897 /* The child has exited or execed: resume threads of the parent the
898 user wanted to be executing. */
901 proceed_after_vfork_done (struct thread_info
*thread
,
904 int pid
= * (int *) arg
;
906 if (thread
->ptid
.pid () == pid
907 && thread
->state
== THREAD_RUNNING
908 && !thread
->executing
909 && !thread
->stop_requested
910 && thread
->suspend
.stop_signal
== GDB_SIGNAL_0
)
912 infrun_debug_printf ("resuming vfork parent thread %s",
913 target_pid_to_str (thread
->ptid
).c_str ());
915 switch_to_thread (thread
);
916 clear_proceed_status (0);
917 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
923 /* Called whenever we notice an exec or exit event, to handle
924 detaching or resuming a vfork parent. */
927 handle_vfork_child_exec_or_exit (int exec
)
929 struct inferior
*inf
= current_inferior ();
931 if (inf
->vfork_parent
)
933 int resume_parent
= -1;
935 /* This exec or exit marks the end of the shared memory region
936 between the parent and the child. Break the bonds. */
937 inferior
*vfork_parent
= inf
->vfork_parent
;
938 inf
->vfork_parent
->vfork_child
= NULL
;
939 inf
->vfork_parent
= NULL
;
941 /* If the user wanted to detach from the parent, now is the
943 if (vfork_parent
->pending_detach
)
945 struct program_space
*pspace
;
946 struct address_space
*aspace
;
948 /* follow-fork child, detach-on-fork on. */
950 vfork_parent
->pending_detach
= 0;
952 scoped_restore_current_pspace_and_thread restore_thread
;
954 /* We're letting loose of the parent. */
955 thread_info
*tp
= any_live_thread_of_inferior (vfork_parent
);
956 switch_to_thread (tp
);
958 /* We're about to detach from the parent, which implicitly
959 removes breakpoints from its address space. There's a
960 catch here: we want to reuse the spaces for the child,
961 but, parent/child are still sharing the pspace at this
962 point, although the exec in reality makes the kernel give
963 the child a fresh set of new pages. The problem here is
964 that the breakpoints module being unaware of this, would
965 likely chose the child process to write to the parent
966 address space. Swapping the child temporarily away from
967 the spaces has the desired effect. Yes, this is "sort
970 pspace
= inf
->pspace
;
971 aspace
= inf
->aspace
;
975 if (print_inferior_events
)
978 = target_pid_to_str (ptid_t (vfork_parent
->pid
));
980 target_terminal::ours_for_output ();
984 fprintf_filtered (gdb_stdlog
,
985 _("[Detaching vfork parent %s "
986 "after child exec]\n"), pidstr
.c_str ());
990 fprintf_filtered (gdb_stdlog
,
991 _("[Detaching vfork parent %s "
992 "after child exit]\n"), pidstr
.c_str ());
996 target_detach (vfork_parent
, 0);
999 inf
->pspace
= pspace
;
1000 inf
->aspace
= aspace
;
1004 /* We're staying attached to the parent, so, really give the
1005 child a new address space. */
1006 inf
->pspace
= new program_space (maybe_new_address_space ());
1007 inf
->aspace
= inf
->pspace
->aspace
;
1009 set_current_program_space (inf
->pspace
);
1011 resume_parent
= vfork_parent
->pid
;
1015 /* If this is a vfork child exiting, then the pspace and
1016 aspaces were shared with the parent. Since we're
1017 reporting the process exit, we'll be mourning all that is
1018 found in the address space, and switching to null_ptid,
1019 preparing to start a new inferior. But, since we don't
1020 want to clobber the parent's address/program spaces, we
1021 go ahead and create a new one for this exiting
1024 /* Switch to no-thread while running clone_program_space, so
1025 that clone_program_space doesn't want to read the
1026 selected frame of a dead process. */
1027 scoped_restore_current_thread restore_thread
;
1028 switch_to_no_thread ();
1030 inf
->pspace
= new program_space (maybe_new_address_space ());
1031 inf
->aspace
= inf
->pspace
->aspace
;
1032 set_current_program_space (inf
->pspace
);
1034 inf
->symfile_flags
= SYMFILE_NO_READ
;
1035 clone_program_space (inf
->pspace
, vfork_parent
->pspace
);
1037 resume_parent
= vfork_parent
->pid
;
1040 gdb_assert (current_program_space
== inf
->pspace
);
1042 if (non_stop
&& resume_parent
!= -1)
1044 /* If the user wanted the parent to be running, let it go
1046 scoped_restore_current_thread restore_thread
;
1048 infrun_debug_printf ("resuming vfork parent process %d",
1051 iterate_over_threads (proceed_after_vfork_done
, &resume_parent
);
1056 /* Handle TARGET_WAITKIND_VFORK_DONE. */
1059 handle_vfork_done (thread_info
*event_thread
)
1061 /* We only care about this event if inferior::thread_waiting_for_vfork_done is
1062 set, that is if we are waiting for a vfork child not under our control
1063 (because we detached it) to exec or exit.
1065 If an inferior has vforked and we are debugging the child, we don't use
1066 the vfork-done event to get notified about the end of the shared address
1067 space window). We rely instead on the child's exec or exit event, and the
1068 inferior::vfork_{parent,child} fields are used instead. See
1069 handle_vfork_child_exec_or_exit for that. */
1070 if (event_thread
->inf
->thread_waiting_for_vfork_done
== nullptr)
1072 infrun_debug_printf ("not waiting for a vfork-done event");
1076 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
1078 /* We stopped all threads (other than the vforking thread) of the inferior in
1079 follow_fork and kept them stopped until now. It should therefore not be
1080 possible for another thread to have reported a vfork during that window.
1081 If THREAD_WAITING_FOR_VFORK_DONE is set, it has to be the same thread whose
1082 vfork-done we are handling right now. */
1083 gdb_assert (event_thread
->inf
->thread_waiting_for_vfork_done
== event_thread
);
1085 event_thread
->inf
->thread_waiting_for_vfork_done
= nullptr;
1086 event_thread
->inf
->pspace
->breakpoints_not_allowed
= 0;
1088 /* On non-stop targets, we stopped all the inferior's threads in follow_fork,
1089 resume them now. On all-stop targets, everything that needs to be resumed
1090 will be when we resume the event thread. */
1091 if (target_is_non_stop_p ())
1093 /* restart_threads and start_step_over may change the current thread, make
1094 sure we leave the event thread as the current thread. */
1095 scoped_restore_current_thread restore_thread
;
1097 insert_breakpoints ();
1098 restart_threads (event_thread
, event_thread
->inf
);
1103 /* Enum strings for "set|show follow-exec-mode". */
1105 static const char follow_exec_mode_new
[] = "new";
1106 static const char follow_exec_mode_same
[] = "same";
1107 static const char *const follow_exec_mode_names
[] =
1109 follow_exec_mode_new
,
1110 follow_exec_mode_same
,
1114 static const char *follow_exec_mode_string
= follow_exec_mode_same
;
1116 show_follow_exec_mode_string (struct ui_file
*file
, int from_tty
,
1117 struct cmd_list_element
*c
, const char *value
)
1119 fprintf_filtered (file
, _("Follow exec mode is \"%s\".\n"), value
);
1122 /* EXEC_FILE_TARGET is assumed to be non-NULL. */
1125 follow_exec (ptid_t ptid
, const char *exec_file_target
)
1127 int pid
= ptid
.pid ();
1128 ptid_t process_ptid
;
1130 /* Switch terminal for any messages produced e.g. by
1131 breakpoint_re_set. */
1132 target_terminal::ours_for_output ();
1134 /* This is an exec event that we actually wish to pay attention to.
1135 Refresh our symbol table to the newly exec'd program, remove any
1136 momentary bp's, etc.
1138 If there are breakpoints, they aren't really inserted now,
1139 since the exec() transformed our inferior into a fresh set
1142 We want to preserve symbolic breakpoints on the list, since
1143 we have hopes that they can be reset after the new a.out's
1144 symbol table is read.
1146 However, any "raw" breakpoints must be removed from the list
1147 (e.g., the solib bp's), since their address is probably invalid
1150 And, we DON'T want to call delete_breakpoints() here, since
1151 that may write the bp's "shadow contents" (the instruction
1152 value that was overwritten with a TRAP instruction). Since
1153 we now have a new a.out, those shadow contents aren't valid. */
1155 mark_breakpoints_out ();
1157 /* The target reports the exec event to the main thread, even if
1158 some other thread does the exec, and even if the main thread was
1159 stopped or already gone. We may still have non-leader threads of
1160 the process on our list. E.g., on targets that don't have thread
1161 exit events (like remote); or on native Linux in non-stop mode if
1162 there were only two threads in the inferior and the non-leader
1163 one is the one that execs (and nothing forces an update of the
1164 thread list up to here). When debugging remotely, it's best to
1165 avoid extra traffic, when possible, so avoid syncing the thread
1166 list with the target, and instead go ahead and delete all threads
1167 of the process but one that reported the event. Note this must
1168 be done before calling update_breakpoints_after_exec, as
1169 otherwise clearing the threads' resources would reference stale
1170 thread breakpoints -- it may have been one of these threads that
1171 stepped across the exec. We could just clear their stepping
1172 states, but as long as we're iterating, might as well delete
1173 them. Deleting them now rather than at the next user-visible
1174 stop provides a nicer sequence of events for user and MI
1176 for (thread_info
*th
: all_threads_safe ())
1177 if (th
->ptid
.pid () == pid
&& th
->ptid
!= ptid
)
1180 /* We also need to clear any left over stale state for the
1181 leader/event thread. E.g., if there was any step-resume
1182 breakpoint or similar, it's gone now. We cannot truly
1183 step-to-next statement through an exec(). */
1184 thread_info
*th
= inferior_thread ();
1185 th
->control
.step_resume_breakpoint
= NULL
;
1186 th
->control
.exception_resume_breakpoint
= NULL
;
1187 th
->control
.single_step_breakpoints
= NULL
;
1188 th
->control
.step_range_start
= 0;
1189 th
->control
.step_range_end
= 0;
1191 /* The user may have had the main thread held stopped in the
1192 previous image (e.g., schedlock on, or non-stop). Release
1194 th
->stop_requested
= 0;
1196 update_breakpoints_after_exec ();
1198 /* What is this a.out's name? */
1199 process_ptid
= ptid_t (pid
);
1200 printf_unfiltered (_("%s is executing new program: %s\n"),
1201 target_pid_to_str (process_ptid
).c_str (),
1204 /* We've followed the inferior through an exec. Therefore, the
1205 inferior has essentially been killed & reborn. */
1207 breakpoint_init_inferior (inf_execd
);
1209 gdb::unique_xmalloc_ptr
<char> exec_file_host
1210 = exec_file_find (exec_file_target
, NULL
);
1212 /* If we were unable to map the executable target pathname onto a host
1213 pathname, tell the user that. Otherwise GDB's subsequent behavior
1214 is confusing. Maybe it would even be better to stop at this point
1215 so that the user can specify a file manually before continuing. */
1216 if (exec_file_host
== NULL
)
1217 warning (_("Could not load symbols for executable %s.\n"
1218 "Do you need \"set sysroot\"?"),
1221 /* Reset the shared library package. This ensures that we get a
1222 shlib event when the child reaches "_start", at which point the
1223 dld will have had a chance to initialize the child. */
1224 /* Also, loading a symbol file below may trigger symbol lookups, and
1225 we don't want those to be satisfied by the libraries of the
1226 previous incarnation of this process. */
1227 no_shared_libraries (NULL
, 0);
1229 struct inferior
*inf
= current_inferior ();
1231 if (follow_exec_mode_string
== follow_exec_mode_new
)
1233 /* The user wants to keep the old inferior and program spaces
1234 around. Create a new fresh one, and switch to it. */
1236 /* Do exit processing for the original inferior before setting the new
1237 inferior's pid. Having two inferiors with the same pid would confuse
1238 find_inferior_p(t)id. Transfer the terminal state and info from the
1239 old to the new inferior. */
1240 inferior
*new_inferior
= add_inferior_with_spaces ();
1242 swap_terminal_info (new_inferior
, inf
);
1243 exit_inferior_silent (inf
);
1245 new_inferior
->pid
= pid
;
1246 target_follow_exec (new_inferior
, ptid
, exec_file_target
);
1248 /* We continue with the new inferior. */
1253 /* The old description may no longer be fit for the new image.
1254 E.g, a 64-bit process exec'ed a 32-bit process. Clear the
1255 old description; we'll read a new one below. No need to do
1256 this on "follow-exec-mode new", as the old inferior stays
1257 around (its description is later cleared/refetched on
1259 target_clear_description ();
1260 target_follow_exec (inf
, ptid
, exec_file_target
);
1263 gdb_assert (current_inferior () == inf
);
1264 gdb_assert (current_program_space
== inf
->pspace
);
1266 /* Attempt to open the exec file. SYMFILE_DEFER_BP_RESET is used
1267 because the proper displacement for a PIE (Position Independent
1268 Executable) main symbol file will only be computed by
1269 solib_create_inferior_hook below. breakpoint_re_set would fail
1270 to insert the breakpoints with the zero displacement. */
1271 try_open_exec_file (exec_file_host
.get (), inf
, SYMFILE_DEFER_BP_RESET
);
1273 /* If the target can specify a description, read it. Must do this
1274 after flipping to the new executable (because the target supplied
1275 description must be compatible with the executable's
1276 architecture, and the old executable may e.g., be 32-bit, while
1277 the new one 64-bit), and before anything involving memory or
1279 target_find_description ();
1281 gdb::observers::inferior_execd
.notify (inf
);
1283 breakpoint_re_set ();
1285 /* Reinsert all breakpoints. (Those which were symbolic have
1286 been reset to the proper address in the new a.out, thanks
1287 to symbol_file_command...). */
1288 insert_breakpoints ();
1290 /* The next resume of this inferior should bring it to the shlib
1291 startup breakpoints. (If the user had also set bp's on
1292 "main" from the old (parent) process, then they'll auto-
1293 matically get reset there in the new process.). */
1296 /* The chain of threads that need to do a step-over operation to get
1297 past e.g., a breakpoint. What technique is used to step over the
1298 breakpoint/watchpoint does not matter -- all threads end up in the
1299 same queue, to maintain rough temporal order of execution, in order
1300 to avoid starvation, otherwise, we could e.g., find ourselves
1301 constantly stepping the same couple threads past their breakpoints
1302 over and over, if the single-step finish fast enough. */
1303 struct thread_info
*global_thread_step_over_chain_head
;
1305 /* Bit flags indicating what the thread needs to step over. */
1307 enum step_over_what_flag
1309 /* Step over a breakpoint. */
1310 STEP_OVER_BREAKPOINT
= 1,
1312 /* Step past a non-continuable watchpoint, in order to let the
1313 instruction execute so we can evaluate the watchpoint
1315 STEP_OVER_WATCHPOINT
= 2
1317 DEF_ENUM_FLAGS_TYPE (enum step_over_what_flag
, step_over_what
);
1319 /* Info about an instruction that is being stepped over. */
1321 struct step_over_info
1323 /* If we're stepping past a breakpoint, this is the address space
1324 and address of the instruction the breakpoint is set at. We'll
1325 skip inserting all breakpoints here. Valid iff ASPACE is
1327 const address_space
*aspace
= nullptr;
1328 CORE_ADDR address
= 0;
1330 /* The instruction being stepped over triggers a nonsteppable
1331 watchpoint. If true, we'll skip inserting watchpoints. */
1332 int nonsteppable_watchpoint_p
= 0;
1334 /* The thread's global number. */
1338 /* The step-over info of the location that is being stepped over.
1340 Note that with async/breakpoint always-inserted mode, a user might
1341 set a new breakpoint/watchpoint/etc. exactly while a breakpoint is
1342 being stepped over. As setting a new breakpoint inserts all
1343 breakpoints, we need to make sure the breakpoint being stepped over
1344 isn't inserted then. We do that by only clearing the step-over
1345 info when the step-over is actually finished (or aborted).
1347 Presently GDB can only step over one breakpoint at any given time.
1348 Given threads that can't run code in the same address space as the
1349 breakpoint's can't really miss the breakpoint, GDB could be taught
1350 to step-over at most one breakpoint per address space (so this info
1351 could move to the address space object if/when GDB is extended).
1352 The set of breakpoints being stepped over will normally be much
1353 smaller than the set of all breakpoints, so a flag in the
1354 breakpoint location structure would be wasteful. A separate list
1355 also saves complexity and run-time, as otherwise we'd have to go
1356 through all breakpoint locations clearing their flag whenever we
1357 start a new sequence. Similar considerations weigh against storing
1358 this info in the thread object. Plus, not all step overs actually
1359 have breakpoint locations -- e.g., stepping past a single-step
1360 breakpoint, or stepping to complete a non-continuable
1362 static struct step_over_info step_over_info
;
1364 /* Record the address of the breakpoint/instruction we're currently
1366 N.B. We record the aspace and address now, instead of say just the thread,
1367 because when we need the info later the thread may be running. */
1370 set_step_over_info (const address_space
*aspace
, CORE_ADDR address
,
1371 int nonsteppable_watchpoint_p
,
1374 step_over_info
.aspace
= aspace
;
1375 step_over_info
.address
= address
;
1376 step_over_info
.nonsteppable_watchpoint_p
= nonsteppable_watchpoint_p
;
1377 step_over_info
.thread
= thread
;
1380 /* Called when we're not longer stepping over a breakpoint / an
1381 instruction, so all breakpoints are free to be (re)inserted. */
1384 clear_step_over_info (void)
1386 infrun_debug_printf ("clearing step over info");
1387 step_over_info
.aspace
= NULL
;
1388 step_over_info
.address
= 0;
1389 step_over_info
.nonsteppable_watchpoint_p
= 0;
1390 step_over_info
.thread
= -1;
1396 stepping_past_instruction_at (struct address_space
*aspace
,
1399 return (step_over_info
.aspace
!= NULL
1400 && breakpoint_address_match (aspace
, address
,
1401 step_over_info
.aspace
,
1402 step_over_info
.address
));
1408 thread_is_stepping_over_breakpoint (int thread
)
1410 return (step_over_info
.thread
!= -1
1411 && thread
== step_over_info
.thread
);
1417 stepping_past_nonsteppable_watchpoint (void)
1419 return step_over_info
.nonsteppable_watchpoint_p
;
1422 /* Returns true if step-over info is valid. */
1425 step_over_info_valid_p (void)
1427 return (step_over_info
.aspace
!= NULL
1428 || stepping_past_nonsteppable_watchpoint ());
1432 /* Displaced stepping. */
1434 /* In non-stop debugging mode, we must take special care to manage
1435 breakpoints properly; in particular, the traditional strategy for
1436 stepping a thread past a breakpoint it has hit is unsuitable.
1437 'Displaced stepping' is a tactic for stepping one thread past a
1438 breakpoint it has hit while ensuring that other threads running
1439 concurrently will hit the breakpoint as they should.
1441 The traditional way to step a thread T off a breakpoint in a
1442 multi-threaded program in all-stop mode is as follows:
1444 a0) Initially, all threads are stopped, and breakpoints are not
1446 a1) We single-step T, leaving breakpoints uninserted.
1447 a2) We insert breakpoints, and resume all threads.
1449 In non-stop debugging, however, this strategy is unsuitable: we
1450 don't want to have to stop all threads in the system in order to
1451 continue or step T past a breakpoint. Instead, we use displaced
1454 n0) Initially, T is stopped, other threads are running, and
1455 breakpoints are inserted.
1456 n1) We copy the instruction "under" the breakpoint to a separate
1457 location, outside the main code stream, making any adjustments
1458 to the instruction, register, and memory state as directed by
1460 n2) We single-step T over the instruction at its new location.
1461 n3) We adjust the resulting register and memory state as directed
1462 by T's architecture. This includes resetting T's PC to point
1463 back into the main instruction stream.
1466 This approach depends on the following gdbarch methods:
1468 - gdbarch_max_insn_length and gdbarch_displaced_step_location
1469 indicate where to copy the instruction, and how much space must
1470 be reserved there. We use these in step n1.
1472 - gdbarch_displaced_step_copy_insn copies a instruction to a new
1473 address, and makes any necessary adjustments to the instruction,
1474 register contents, and memory. We use this in step n1.
1476 - gdbarch_displaced_step_fixup adjusts registers and memory after
1477 we have successfully single-stepped the instruction, to yield the
1478 same effect the instruction would have had if we had executed it
1479 at its original address. We use this in step n3.
1481 The gdbarch_displaced_step_copy_insn and
1482 gdbarch_displaced_step_fixup functions must be written so that
1483 copying an instruction with gdbarch_displaced_step_copy_insn,
1484 single-stepping across the copied instruction, and then applying
1485 gdbarch_displaced_insn_fixup should have the same effects on the
1486 thread's memory and registers as stepping the instruction in place
1487 would have. Exactly which responsibilities fall to the copy and
1488 which fall to the fixup is up to the author of those functions.
1490 See the comments in gdbarch.sh for details.
1492 Note that displaced stepping and software single-step cannot
1493 currently be used in combination, although with some care I think
1494 they could be made to. Software single-step works by placing
1495 breakpoints on all possible subsequent instructions; if the
1496 displaced instruction is a PC-relative jump, those breakpoints
1497 could fall in very strange places --- on pages that aren't
1498 executable, or at addresses that are not proper instruction
1499 boundaries. (We do generally let other threads run while we wait
1500 to hit the software single-step breakpoint, and they might
1501 encounter such a corrupted instruction.) One way to work around
1502 this would be to have gdbarch_displaced_step_copy_insn fully
1503 simulate the effect of PC-relative instructions (and return NULL)
1504 on architectures that use software single-stepping.
1506 In non-stop mode, we can have independent and simultaneous step
1507 requests, so more than one thread may need to simultaneously step
1508 over a breakpoint. The current implementation assumes there is
1509 only one scratch space per process. In this case, we have to
1510 serialize access to the scratch space. If thread A wants to step
1511 over a breakpoint, but we are currently waiting for some other
1512 thread to complete a displaced step, we leave thread A stopped and
1513 place it in the displaced_step_request_queue. Whenever a displaced
1514 step finishes, we pick the next thread in the queue and start a new
1515 displaced step operation on it. See displaced_step_prepare and
1516 displaced_step_finish for details. */
1518 /* Return true if THREAD is doing a displaced step. */
1521 displaced_step_in_progress_thread (thread_info
*thread
)
1523 gdb_assert (thread
!= NULL
);
1525 return thread
->displaced_step_state
.in_progress ();
1528 /* Return true if INF has a thread doing a displaced step. */
1531 displaced_step_in_progress (inferior
*inf
)
1533 return inf
->displaced_step_state
.in_progress_count
> 0;
1536 /* Return true if any thread is doing a displaced step. */
1539 displaced_step_in_progress_any_thread ()
1541 for (inferior
*inf
: all_non_exited_inferiors ())
1543 if (displaced_step_in_progress (inf
))
1551 infrun_inferior_exit (struct inferior
*inf
)
1553 inf
->displaced_step_state
.reset ();
1554 inf
->thread_waiting_for_vfork_done
= nullptr;
1558 infrun_inferior_execd (inferior
*inf
)
1560 /* If some threads where was doing a displaced step in this inferior at the
1561 moment of the exec, they no longer exist. Even if the exec'ing thread
1562 doing a displaced step, we don't want to to any fixup nor restore displaced
1563 stepping buffer bytes. */
1564 inf
->displaced_step_state
.reset ();
1566 for (thread_info
*thread
: inf
->threads ())
1567 thread
->displaced_step_state
.reset ();
1569 /* Since an in-line step is done with everything else stopped, if there was
1570 one in progress at the time of the exec, it must have been the exec'ing
1572 clear_step_over_info ();
1574 inf
->thread_waiting_for_vfork_done
= nullptr;
1577 /* If ON, and the architecture supports it, GDB will use displaced
1578 stepping to step over breakpoints. If OFF, or if the architecture
1579 doesn't support it, GDB will instead use the traditional
1580 hold-and-step approach. If AUTO (which is the default), GDB will
1581 decide which technique to use to step over breakpoints depending on
1582 whether the target works in a non-stop way (see use_displaced_stepping). */
1584 static enum auto_boolean can_use_displaced_stepping
= AUTO_BOOLEAN_AUTO
;
1587 show_can_use_displaced_stepping (struct ui_file
*file
, int from_tty
,
1588 struct cmd_list_element
*c
,
1591 if (can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
)
1592 fprintf_filtered (file
,
1593 _("Debugger's willingness to use displaced stepping "
1594 "to step over breakpoints is %s (currently %s).\n"),
1595 value
, target_is_non_stop_p () ? "on" : "off");
1597 fprintf_filtered (file
,
1598 _("Debugger's willingness to use displaced stepping "
1599 "to step over breakpoints is %s.\n"), value
);
1602 /* Return true if the gdbarch implements the required methods to use
1603 displaced stepping. */
1606 gdbarch_supports_displaced_stepping (gdbarch
*arch
)
1608 /* Only check for the presence of `prepare`. The gdbarch verification ensures
1609 that if `prepare` is provided, so is `finish`. */
1610 return gdbarch_displaced_step_prepare_p (arch
);
1613 /* Return non-zero if displaced stepping can/should be used to step
1614 over breakpoints of thread TP. */
1617 use_displaced_stepping (thread_info
*tp
)
1619 /* If the user disabled it explicitly, don't use displaced stepping. */
1620 if (can_use_displaced_stepping
== AUTO_BOOLEAN_FALSE
)
1623 /* If "auto", only use displaced stepping if the target operates in a non-stop
1625 if (can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
1626 && !target_is_non_stop_p ())
1629 gdbarch
*gdbarch
= get_thread_regcache (tp
)->arch ();
1631 /* If the architecture doesn't implement displaced stepping, don't use
1633 if (!gdbarch_supports_displaced_stepping (gdbarch
))
1636 /* If recording, don't use displaced stepping. */
1637 if (find_record_target () != nullptr)
1640 /* If displaced stepping failed before for this inferior, don't bother trying
1642 if (tp
->inf
->displaced_step_state
.failed_before
)
1648 /* Simple function wrapper around displaced_step_thread_state::reset. */
1651 displaced_step_reset (displaced_step_thread_state
*displaced
)
1653 displaced
->reset ();
1656 /* A cleanup that wraps displaced_step_reset. We use this instead of, say,
1657 SCOPE_EXIT, because it needs to be discardable with "cleanup.release ()". */
1659 using displaced_step_reset_cleanup
= FORWARD_SCOPE_EXIT (displaced_step_reset
);
1664 displaced_step_dump_bytes (const gdb_byte
*buf
, size_t len
)
1668 for (size_t i
= 0; i
< len
; i
++)
1671 ret
+= string_printf ("%02x", buf
[i
]);
1673 ret
+= string_printf (" %02x", buf
[i
]);
1679 /* Prepare to single-step, using displaced stepping.
1681 Note that we cannot use displaced stepping when we have a signal to
1682 deliver. If we have a signal to deliver and an instruction to step
1683 over, then after the step, there will be no indication from the
1684 target whether the thread entered a signal handler or ignored the
1685 signal and stepped over the instruction successfully --- both cases
1686 result in a simple SIGTRAP. In the first case we mustn't do a
1687 fixup, and in the second case we must --- but we can't tell which.
1688 Comments in the code for 'random signals' in handle_inferior_event
1689 explain how we handle this case instead.
1691 Returns DISPLACED_STEP_PREPARE_STATUS_OK if preparing was successful -- this
1692 thread is going to be stepped now; DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
1693 if displaced stepping this thread got queued; or
1694 DISPLACED_STEP_PREPARE_STATUS_CANT if this instruction can't be displaced
1697 static displaced_step_prepare_status
1698 displaced_step_prepare_throw (thread_info
*tp
)
1700 regcache
*regcache
= get_thread_regcache (tp
);
1701 struct gdbarch
*gdbarch
= regcache
->arch ();
1702 displaced_step_thread_state
&disp_step_thread_state
1703 = tp
->displaced_step_state
;
1705 /* We should never reach this function if the architecture does not
1706 support displaced stepping. */
1707 gdb_assert (gdbarch_supports_displaced_stepping (gdbarch
));
1709 /* Nor if the thread isn't meant to step over a breakpoint. */
1710 gdb_assert (tp
->control
.trap_expected
);
1712 /* Disable range stepping while executing in the scratch pad. We
1713 want a single-step even if executing the displaced instruction in
1714 the scratch buffer lands within the stepping range (e.g., a
1716 tp
->control
.may_range_step
= 0;
1718 /* We are about to start a displaced step for this thread. If one is already
1719 in progress, something's wrong. */
1720 gdb_assert (!disp_step_thread_state
.in_progress ());
1722 if (tp
->inf
->displaced_step_state
.unavailable
)
1724 /* The gdbarch tells us it's not worth asking to try a prepare because
1725 it is likely that it will return unavailable, so don't bother asking. */
1727 displaced_debug_printf ("deferring step of %s",
1728 target_pid_to_str (tp
->ptid
).c_str ());
1730 global_thread_step_over_chain_enqueue (tp
);
1731 return DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
;
1734 displaced_debug_printf ("displaced-stepping %s now",
1735 target_pid_to_str (tp
->ptid
).c_str ());
1737 scoped_restore_current_thread restore_thread
;
1739 switch_to_thread (tp
);
1741 CORE_ADDR original_pc
= regcache_read_pc (regcache
);
1742 CORE_ADDR displaced_pc
;
1744 displaced_step_prepare_status status
1745 = gdbarch_displaced_step_prepare (gdbarch
, tp
, displaced_pc
);
1747 if (status
== DISPLACED_STEP_PREPARE_STATUS_CANT
)
1749 displaced_debug_printf ("failed to prepare (%s)",
1750 target_pid_to_str (tp
->ptid
).c_str ());
1752 return DISPLACED_STEP_PREPARE_STATUS_CANT
;
1754 else if (status
== DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
)
1756 /* Not enough displaced stepping resources available, defer this
1757 request by placing it the queue. */
1759 displaced_debug_printf ("not enough resources available, "
1760 "deferring step of %s",
1761 target_pid_to_str (tp
->ptid
).c_str ());
1763 global_thread_step_over_chain_enqueue (tp
);
1765 return DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
;
1768 gdb_assert (status
== DISPLACED_STEP_PREPARE_STATUS_OK
);
1770 /* Save the information we need to fix things up if the step
1772 disp_step_thread_state
.set (gdbarch
);
1774 tp
->inf
->displaced_step_state
.in_progress_count
++;
1776 displaced_debug_printf ("prepared successfully thread=%s, "
1777 "original_pc=%s, displaced_pc=%s",
1778 target_pid_to_str (tp
->ptid
).c_str (),
1779 paddress (gdbarch
, original_pc
),
1780 paddress (gdbarch
, displaced_pc
));
1782 return DISPLACED_STEP_PREPARE_STATUS_OK
;
1785 /* Wrapper for displaced_step_prepare_throw that disabled further
1786 attempts at displaced stepping if we get a memory error. */
1788 static displaced_step_prepare_status
1789 displaced_step_prepare (thread_info
*thread
)
1791 displaced_step_prepare_status status
1792 = DISPLACED_STEP_PREPARE_STATUS_CANT
;
1796 status
= displaced_step_prepare_throw (thread
);
1798 catch (const gdb_exception_error
&ex
)
1800 if (ex
.error
!= MEMORY_ERROR
1801 && ex
.error
!= NOT_SUPPORTED_ERROR
)
1804 infrun_debug_printf ("caught exception, disabling displaced stepping: %s",
1807 /* Be verbose if "set displaced-stepping" is "on", silent if
1809 if (can_use_displaced_stepping
== AUTO_BOOLEAN_TRUE
)
1811 warning (_("disabling displaced stepping: %s"),
1815 /* Disable further displaced stepping attempts. */
1816 thread
->inf
->displaced_step_state
.failed_before
= 1;
1822 /* If we displaced stepped an instruction successfully, adjust registers and
1823 memory to yield the same effect the instruction would have had if we had
1824 executed it at its original address, and return
1825 DISPLACED_STEP_FINISH_STATUS_OK. If the instruction didn't complete,
1826 relocate the PC and return DISPLACED_STEP_FINISH_STATUS_NOT_EXECUTED.
1828 If the thread wasn't displaced stepping, return
1829 DISPLACED_STEP_FINISH_STATUS_OK as well. */
1831 static displaced_step_finish_status
1832 displaced_step_finish (thread_info
*event_thread
, enum gdb_signal signal
)
1834 displaced_step_thread_state
*displaced
= &event_thread
->displaced_step_state
;
1836 /* Was this thread performing a displaced step? */
1837 if (!displaced
->in_progress ())
1838 return DISPLACED_STEP_FINISH_STATUS_OK
;
1840 gdb_assert (event_thread
->inf
->displaced_step_state
.in_progress_count
> 0);
1841 event_thread
->inf
->displaced_step_state
.in_progress_count
--;
1843 /* Fixup may need to read memory/registers. Switch to the thread
1844 that we're fixing up. Also, target_stopped_by_watchpoint checks
1845 the current thread, and displaced_step_restore performs ptid-dependent
1846 memory accesses using current_inferior(). */
1847 switch_to_thread (event_thread
);
1849 displaced_step_reset_cleanup
cleanup (displaced
);
1851 /* Do the fixup, and release the resources acquired to do the displaced
1853 return gdbarch_displaced_step_finish (displaced
->get_original_gdbarch (),
1854 event_thread
, signal
);
1857 /* Data to be passed around while handling an event. This data is
1858 discarded between events. */
1859 struct execution_control_state
1861 process_stratum_target
*target
;
1863 /* The thread that got the event, if this was a thread event; NULL
1865 struct thread_info
*event_thread
;
1867 struct target_waitstatus ws
;
1868 int stop_func_filled_in
;
1869 CORE_ADDR stop_func_start
;
1870 CORE_ADDR stop_func_end
;
1871 const char *stop_func_name
;
1874 /* True if the event thread hit the single-step breakpoint of
1875 another thread. Thus the event doesn't cause a stop, the thread
1876 needs to be single-stepped past the single-step breakpoint before
1877 we can switch back to the original stepping thread. */
1878 int hit_singlestep_breakpoint
;
1881 /* Clear ECS and set it to point at TP. */
1884 reset_ecs (struct execution_control_state
*ecs
, struct thread_info
*tp
)
1886 memset (ecs
, 0, sizeof (*ecs
));
1887 ecs
->event_thread
= tp
;
1888 ecs
->ptid
= tp
->ptid
;
1891 static void keep_going_pass_signal (struct execution_control_state
*ecs
);
1892 static void prepare_to_wait (struct execution_control_state
*ecs
);
1893 static bool keep_going_stepped_thread (struct thread_info
*tp
);
1894 static step_over_what
thread_still_needs_step_over (struct thread_info
*tp
);
1896 /* Are there any pending step-over requests? If so, run all we can
1897 now and return true. Otherwise, return false. */
1900 start_step_over (void)
1902 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
1906 /* Don't start a new step-over if we already have an in-line
1907 step-over operation ongoing. */
1908 if (step_over_info_valid_p ())
1911 /* Steal the global thread step over chain. As we try to initiate displaced
1912 steps, threads will be enqueued in the global chain if no buffers are
1913 available. If we iterated on the global chain directly, we might iterate
1915 thread_info
*threads_to_step
= global_thread_step_over_chain_head
;
1916 global_thread_step_over_chain_head
= NULL
;
1918 infrun_debug_printf ("stealing global queue of threads to step, length = %d",
1919 thread_step_over_chain_length (threads_to_step
));
1921 bool started
= false;
1923 /* On scope exit (whatever the reason, return or exception), if there are
1924 threads left in the THREADS_TO_STEP chain, put back these threads in the
1928 if (threads_to_step
== nullptr)
1929 infrun_debug_printf ("step-over queue now empty");
1932 infrun_debug_printf ("putting back %d threads to step in global queue",
1933 thread_step_over_chain_length (threads_to_step
));
1935 global_thread_step_over_chain_enqueue_chain (threads_to_step
);
1939 for (thread_info
*tp
= threads_to_step
; tp
!= NULL
; tp
= next
)
1941 struct execution_control_state ecss
;
1942 struct execution_control_state
*ecs
= &ecss
;
1943 step_over_what step_what
;
1944 int must_be_in_line
;
1946 gdb_assert (!tp
->stop_requested
);
1948 next
= thread_step_over_chain_next (threads_to_step
, tp
);
1950 if (tp
->inf
->displaced_step_state
.unavailable
)
1952 /* The arch told us to not even try preparing another displaced step
1953 for this inferior. Just leave the thread in THREADS_TO_STEP, it
1954 will get moved to the global chain on scope exit. */
1958 if (tp
->inf
->thread_waiting_for_vfork_done
)
1960 /* When we stop all threads, handling a vfork, any thread in the step
1961 over chain remains there. A user could also try to continue a
1962 thread stopped at a breakpoint while another thread is waiting for
1963 a vfork-done event. In any case, we don't want to start a step
1968 /* Remove thread from the THREADS_TO_STEP chain. If anything goes wrong
1969 while we try to prepare the displaced step, we don't add it back to
1970 the global step over chain. This is to avoid a thread staying in the
1971 step over chain indefinitely if something goes wrong when resuming it
1972 If the error is intermittent and it still needs a step over, it will
1973 get enqueued again when we try to resume it normally. */
1974 thread_step_over_chain_remove (&threads_to_step
, tp
);
1976 step_what
= thread_still_needs_step_over (tp
);
1977 must_be_in_line
= ((step_what
& STEP_OVER_WATCHPOINT
)
1978 || ((step_what
& STEP_OVER_BREAKPOINT
)
1979 && !use_displaced_stepping (tp
)));
1981 /* We currently stop all threads of all processes to step-over
1982 in-line. If we need to start a new in-line step-over, let
1983 any pending displaced steps finish first. */
1984 if (must_be_in_line
&& displaced_step_in_progress_any_thread ())
1986 global_thread_step_over_chain_enqueue (tp
);
1990 if (tp
->control
.trap_expected
1994 internal_error (__FILE__
, __LINE__
,
1995 "[%s] has inconsistent state: "
1996 "trap_expected=%d, resumed=%d, executing=%d\n",
1997 target_pid_to_str (tp
->ptid
).c_str (),
1998 tp
->control
.trap_expected
,
2003 infrun_debug_printf ("resuming [%s] for step-over",
2004 target_pid_to_str (tp
->ptid
).c_str ());
2006 /* keep_going_pass_signal skips the step-over if the breakpoint
2007 is no longer inserted. In all-stop, we want to keep looking
2008 for a thread that needs a step-over instead of resuming TP,
2009 because we wouldn't be able to resume anything else until the
2010 target stops again. In non-stop, the resume always resumes
2011 only TP, so it's OK to let the thread resume freely. */
2012 if (!target_is_non_stop_p () && !step_what
)
2015 switch_to_thread (tp
);
2016 reset_ecs (ecs
, tp
);
2017 keep_going_pass_signal (ecs
);
2019 if (!ecs
->wait_some_more
)
2020 error (_("Command aborted."));
2022 /* If the thread's step over could not be initiated because no buffers
2023 were available, it was re-added to the global step over chain. */
2026 infrun_debug_printf ("[%s] was resumed.",
2027 target_pid_to_str (tp
->ptid
).c_str ());
2028 gdb_assert (!thread_is_in_step_over_chain (tp
));
2032 infrun_debug_printf ("[%s] was NOT resumed.",
2033 target_pid_to_str (tp
->ptid
).c_str ());
2034 gdb_assert (thread_is_in_step_over_chain (tp
));
2037 /* If we started a new in-line step-over, we're done. */
2038 if (step_over_info_valid_p ())
2040 gdb_assert (tp
->control
.trap_expected
);
2045 if (!target_is_non_stop_p ())
2047 /* On all-stop, shouldn't have resumed unless we needed a
2049 gdb_assert (tp
->control
.trap_expected
2050 || tp
->step_after_step_resume_breakpoint
);
2052 /* With remote targets (at least), in all-stop, we can't
2053 issue any further remote commands until the program stops
2059 /* Either the thread no longer needed a step-over, or a new
2060 displaced stepping sequence started. Even in the latter
2061 case, continue looking. Maybe we can also start another
2062 displaced step on a thread of other process. */
2068 /* Update global variables holding ptids to hold NEW_PTID if they were
2069 holding OLD_PTID. */
2071 infrun_thread_ptid_changed (process_stratum_target
*target
,
2072 ptid_t old_ptid
, ptid_t new_ptid
)
2074 if (inferior_ptid
== old_ptid
2075 && current_inferior ()->process_target () == target
)
2076 inferior_ptid
= new_ptid
;
2081 static const char schedlock_off
[] = "off";
2082 static const char schedlock_on
[] = "on";
2083 static const char schedlock_step
[] = "step";
2084 static const char schedlock_replay
[] = "replay";
2085 static const char *const scheduler_enums
[] = {
2092 static const char *scheduler_mode
= schedlock_replay
;
2094 show_scheduler_mode (struct ui_file
*file
, int from_tty
,
2095 struct cmd_list_element
*c
, const char *value
)
2097 fprintf_filtered (file
,
2098 _("Mode for locking scheduler "
2099 "during execution is \"%s\".\n"),
2104 set_schedlock_func (const char *args
, int from_tty
, struct cmd_list_element
*c
)
2106 if (!target_can_lock_scheduler ())
2108 scheduler_mode
= schedlock_off
;
2109 error (_("Target '%s' cannot support this command."),
2110 target_shortname ());
2114 /* True if execution commands resume all threads of all processes by
2115 default; otherwise, resume only threads of the current inferior
2117 bool sched_multi
= false;
2119 /* Try to setup for software single stepping over the specified location.
2120 Return true if target_resume() should use hardware single step.
2122 GDBARCH the current gdbarch.
2123 PC the location to step over. */
2126 maybe_software_singlestep (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
2128 bool hw_step
= true;
2130 if (execution_direction
== EXEC_FORWARD
2131 && gdbarch_software_single_step_p (gdbarch
))
2132 hw_step
= !insert_single_step_breakpoints (gdbarch
);
2140 user_visible_resume_ptid (int step
)
2146 /* With non-stop mode on, threads are always handled
2148 resume_ptid
= inferior_ptid
;
2150 else if ((scheduler_mode
== schedlock_on
)
2151 || (scheduler_mode
== schedlock_step
&& step
))
2153 /* User-settable 'scheduler' mode requires solo thread
2155 resume_ptid
= inferior_ptid
;
2157 else if ((scheduler_mode
== schedlock_replay
)
2158 && target_record_will_replay (minus_one_ptid
, execution_direction
))
2160 /* User-settable 'scheduler' mode requires solo thread resume in replay
2162 resume_ptid
= inferior_ptid
;
2164 else if (!sched_multi
&& target_supports_multi_process ())
2166 /* Resume all threads of the current process (and none of other
2168 resume_ptid
= ptid_t (inferior_ptid
.pid ());
2172 /* Resume all threads of all processes. */
2173 resume_ptid
= RESUME_ALL
;
2181 process_stratum_target
*
2182 user_visible_resume_target (ptid_t resume_ptid
)
2184 return (resume_ptid
== minus_one_ptid
&& sched_multi
2186 : current_inferior ()->process_target ());
2189 /* Return a ptid representing the set of threads that we will resume,
2190 in the perspective of the target, assuming run control handling
2191 does not require leaving some threads stopped (e.g., stepping past
2192 breakpoint). USER_STEP indicates whether we're about to start the
2193 target for a stepping command. */
2196 internal_resume_ptid (int user_step
)
2198 /* In non-stop, we always control threads individually. Note that
2199 the target may always work in non-stop mode even with "set
2200 non-stop off", in which case user_visible_resume_ptid could
2201 return a wildcard ptid. */
2202 if (target_is_non_stop_p ())
2203 return inferior_ptid
;
2205 /* The rest of the function assumes non-stop==off and
2206 target-non-stop==off.
2208 If a thread is waiting for a vfork-done event, it means breakpoints are out
2209 for this inferior (well, program space in fact). We don't want to resume
2210 any thread other than the one waiting for vfork done, otherwise these other
2211 threads could miss breakpoints. So if a thread in the resumption set is
2212 waiting for a vfork-done event, resume only that thread.
2214 The resumption set width depends on whether schedule-multiple is on or off.
2216 Note that if the target_resume interface was more flexible, we could be
2217 smarter here when schedule-multiple is on. For example, imagine 3
2218 inferiors with 2 threads each (1.1, 1.2, 2.1, 2.2, 3.1 and 3.2). Threads
2219 2.1 and 3.2 are both waiting for a vfork-done event. Then we could ask the
2220 target(s) to resume:
2222 - All threads of inferior 1
2226 Since we don't have that flexibility (we can only pass one ptid), just
2227 resume the first thread waiting for a vfork-done event we find (e.g. thread
2231 for (inferior
*inf
: all_non_exited_inferiors ())
2232 if (inf
->thread_waiting_for_vfork_done
!= nullptr)
2233 return inf
->thread_waiting_for_vfork_done
->ptid
;
2235 else if (current_inferior ()->thread_waiting_for_vfork_done
!= nullptr)
2236 return current_inferior ()->thread_waiting_for_vfork_done
->ptid
;
2238 return user_visible_resume_ptid (user_step
);
2241 /* Wrapper for target_resume, that handles infrun-specific
2245 do_target_resume (ptid_t resume_ptid
, bool step
, enum gdb_signal sig
)
2247 struct thread_info
*tp
= inferior_thread ();
2249 gdb_assert (!tp
->stop_requested
);
2251 /* Install inferior's terminal modes. */
2252 target_terminal::inferior ();
2254 /* Avoid confusing the next resume, if the next stop/resume
2255 happens to apply to another thread. */
2256 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2258 /* Advise target which signals may be handled silently.
2260 If we have removed breakpoints because we are stepping over one
2261 in-line (in any thread), we need to receive all signals to avoid
2262 accidentally skipping a breakpoint during execution of a signal
2265 Likewise if we're displaced stepping, otherwise a trap for a
2266 breakpoint in a signal handler might be confused with the
2267 displaced step finishing. We don't make the displaced_step_finish
2268 step distinguish the cases instead, because:
2270 - a backtrace while stopped in the signal handler would show the
2271 scratch pad as frame older than the signal handler, instead of
2272 the real mainline code.
2274 - when the thread is later resumed, the signal handler would
2275 return to the scratch pad area, which would no longer be
2277 if (step_over_info_valid_p ()
2278 || displaced_step_in_progress (tp
->inf
))
2279 target_pass_signals ({});
2281 target_pass_signals (signal_pass
);
2283 infrun_debug_printf ("resume_ptid=%s, step=%d, sig=%s",
2284 resume_ptid
.to_string ().c_str (),
2285 step
, gdb_signal_to_symbol_string (sig
));
2287 target_resume (resume_ptid
, step
, sig
);
2289 if (target_can_async_p ())
2293 /* Resume the inferior. SIG is the signal to give the inferior
2294 (GDB_SIGNAL_0 for none). Note: don't call this directly; instead
2295 call 'resume', which handles exceptions. */
2298 resume_1 (enum gdb_signal sig
)
2300 struct regcache
*regcache
= get_current_regcache ();
2301 struct gdbarch
*gdbarch
= regcache
->arch ();
2302 struct thread_info
*tp
= inferior_thread ();
2303 const address_space
*aspace
= regcache
->aspace ();
2305 /* This represents the user's step vs continue request. When
2306 deciding whether "set scheduler-locking step" applies, it's the
2307 user's intention that counts. */
2308 const int user_step
= tp
->control
.stepping_command
;
2309 /* This represents what we'll actually request the target to do.
2310 This can decay from a step to a continue, if e.g., we need to
2311 implement single-stepping with breakpoints (software
2315 gdb_assert (!tp
->stop_requested
);
2316 gdb_assert (!thread_is_in_step_over_chain (tp
));
2318 if (tp
->suspend
.waitstatus_pending_p
)
2321 ("thread %s has pending wait "
2322 "status %s (currently_stepping=%d).",
2323 target_pid_to_str (tp
->ptid
).c_str (),
2324 target_waitstatus_to_string (&tp
->suspend
.waitstatus
).c_str (),
2325 currently_stepping (tp
));
2327 tp
->inf
->process_target ()->threads_executing
= true;
2330 /* FIXME: What should we do if we are supposed to resume this
2331 thread with a signal? Maybe we should maintain a queue of
2332 pending signals to deliver. */
2333 if (sig
!= GDB_SIGNAL_0
)
2335 warning (_("Couldn't deliver signal %s to %s."),
2336 gdb_signal_to_name (sig
),
2337 target_pid_to_str (tp
->ptid
).c_str ());
2340 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2342 if (target_can_async_p ())
2345 /* Tell the event loop we have an event to process. */
2346 mark_async_event_handler (infrun_async_inferior_event_token
);
2351 tp
->stepped_breakpoint
= 0;
2353 /* Depends on stepped_breakpoint. */
2354 step
= currently_stepping (tp
);
2356 if (current_inferior ()->thread_waiting_for_vfork_done
!= nullptr)
2358 /* Don't try to single-step a vfork parent that is waiting for
2359 the child to get out of the shared memory region (by exec'ing
2360 or exiting). This is particularly important on software
2361 single-step archs, as the child process would trip on the
2362 software single step breakpoint inserted for the parent
2363 process. Since the parent will not actually execute any
2364 instruction until the child is out of the shared region (such
2365 are vfork's semantics), it is safe to simply continue it.
2366 Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for
2367 the parent, and tell it to `keep_going', which automatically
2368 re-sets it stepping. */
2369 infrun_debug_printf ("resume : clear step");
2373 CORE_ADDR pc
= regcache_read_pc (regcache
);
2375 infrun_debug_printf ("step=%d, signal=%s, trap_expected=%d, "
2376 "current thread [%s] at %s",
2377 step
, gdb_signal_to_symbol_string (sig
),
2378 tp
->control
.trap_expected
,
2379 target_pid_to_str (inferior_ptid
).c_str (),
2380 paddress (gdbarch
, pc
));
2382 /* Normally, by the time we reach `resume', the breakpoints are either
2383 removed or inserted, as appropriate. The exception is if we're sitting
2384 at a permanent breakpoint; we need to step over it, but permanent
2385 breakpoints can't be removed. So we have to test for it here. */
2386 if (breakpoint_here_p (aspace
, pc
) == permanent_breakpoint_here
)
2388 if (sig
!= GDB_SIGNAL_0
)
2390 /* We have a signal to pass to the inferior. The resume
2391 may, or may not take us to the signal handler. If this
2392 is a step, we'll need to stop in the signal handler, if
2393 there's one, (if the target supports stepping into
2394 handlers), or in the next mainline instruction, if
2395 there's no handler. If this is a continue, we need to be
2396 sure to run the handler with all breakpoints inserted.
2397 In all cases, set a breakpoint at the current address
2398 (where the handler returns to), and once that breakpoint
2399 is hit, resume skipping the permanent breakpoint. If
2400 that breakpoint isn't hit, then we've stepped into the
2401 signal handler (or hit some other event). We'll delete
2402 the step-resume breakpoint then. */
2404 infrun_debug_printf ("resume: skipping permanent breakpoint, "
2405 "deliver signal first");
2407 clear_step_over_info ();
2408 tp
->control
.trap_expected
= 0;
2410 if (tp
->control
.step_resume_breakpoint
== NULL
)
2412 /* Set a "high-priority" step-resume, as we don't want
2413 user breakpoints at PC to trigger (again) when this
2415 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
2416 gdb_assert (tp
->control
.step_resume_breakpoint
->loc
->permanent
);
2418 tp
->step_after_step_resume_breakpoint
= step
;
2421 insert_breakpoints ();
2425 /* There's no signal to pass, we can go ahead and skip the
2426 permanent breakpoint manually. */
2427 infrun_debug_printf ("skipping permanent breakpoint");
2428 gdbarch_skip_permanent_breakpoint (gdbarch
, regcache
);
2429 /* Update pc to reflect the new address from which we will
2430 execute instructions. */
2431 pc
= regcache_read_pc (regcache
);
2435 /* We've already advanced the PC, so the stepping part
2436 is done. Now we need to arrange for a trap to be
2437 reported to handle_inferior_event. Set a breakpoint
2438 at the current PC, and run to it. Don't update
2439 prev_pc, because if we end in
2440 switch_back_to_stepped_thread, we want the "expected
2441 thread advanced also" branch to be taken. IOW, we
2442 don't want this thread to step further from PC
2444 gdb_assert (!step_over_info_valid_p ());
2445 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
2446 insert_breakpoints ();
2448 resume_ptid
= internal_resume_ptid (user_step
);
2449 do_target_resume (resume_ptid
, false, GDB_SIGNAL_0
);
2456 /* If we have a breakpoint to step over, make sure to do a single
2457 step only. Same if we have software watchpoints. */
2458 if (tp
->control
.trap_expected
|| bpstat_should_step ())
2459 tp
->control
.may_range_step
= 0;
2461 /* If displaced stepping is enabled, step over breakpoints by executing a
2462 copy of the instruction at a different address.
2464 We can't use displaced stepping when we have a signal to deliver;
2465 the comments for displaced_step_prepare explain why. The
2466 comments in the handle_inferior event for dealing with 'random
2467 signals' explain what we do instead.
2469 We can't use displaced stepping when we are waiting for vfork_done
2470 event, displaced stepping breaks the vfork child similarly as single
2471 step software breakpoint. */
2472 if (tp
->control
.trap_expected
2473 && use_displaced_stepping (tp
)
2474 && !step_over_info_valid_p ()
2475 && sig
== GDB_SIGNAL_0
2476 && current_inferior ()->thread_waiting_for_vfork_done
== nullptr)
2478 displaced_step_prepare_status prepare_status
2479 = displaced_step_prepare (tp
);
2481 if (prepare_status
== DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
)
2483 infrun_debug_printf ("Got placed in step-over queue");
2485 tp
->control
.trap_expected
= 0;
2488 else if (prepare_status
== DISPLACED_STEP_PREPARE_STATUS_CANT
)
2490 /* Fallback to stepping over the breakpoint in-line. */
2492 if (target_is_non_stop_p ())
2493 stop_all_threads ("displaced stepping falling back on inline stepping");
2495 set_step_over_info (regcache
->aspace (),
2496 regcache_read_pc (regcache
), 0, tp
->global_num
);
2498 step
= maybe_software_singlestep (gdbarch
, pc
);
2500 insert_breakpoints ();
2502 else if (prepare_status
== DISPLACED_STEP_PREPARE_STATUS_OK
)
2504 /* Update pc to reflect the new address from which we will
2505 execute instructions due to displaced stepping. */
2506 pc
= regcache_read_pc (get_thread_regcache (tp
));
2508 step
= gdbarch_displaced_step_hw_singlestep (gdbarch
);
2511 gdb_assert_not_reached (_("Invalid displaced_step_prepare_status "
2515 /* Do we need to do it the hard way, w/temp breakpoints? */
2517 step
= maybe_software_singlestep (gdbarch
, pc
);
2519 /* Currently, our software single-step implementation leads to different
2520 results than hardware single-stepping in one situation: when stepping
2521 into delivering a signal which has an associated signal handler,
2522 hardware single-step will stop at the first instruction of the handler,
2523 while software single-step will simply skip execution of the handler.
2525 For now, this difference in behavior is accepted since there is no
2526 easy way to actually implement single-stepping into a signal handler
2527 without kernel support.
2529 However, there is one scenario where this difference leads to follow-on
2530 problems: if we're stepping off a breakpoint by removing all breakpoints
2531 and then single-stepping. In this case, the software single-step
2532 behavior means that even if there is a *breakpoint* in the signal
2533 handler, GDB still would not stop.
2535 Fortunately, we can at least fix this particular issue. We detect
2536 here the case where we are about to deliver a signal while software
2537 single-stepping with breakpoints removed. In this situation, we
2538 revert the decisions to remove all breakpoints and insert single-
2539 step breakpoints, and instead we install a step-resume breakpoint
2540 at the current address, deliver the signal without stepping, and
2541 once we arrive back at the step-resume breakpoint, actually step
2542 over the breakpoint we originally wanted to step over. */
2543 if (thread_has_single_step_breakpoints_set (tp
)
2544 && sig
!= GDB_SIGNAL_0
2545 && step_over_info_valid_p ())
2547 /* If we have nested signals or a pending signal is delivered
2548 immediately after a handler returns, might already have
2549 a step-resume breakpoint set on the earlier handler. We cannot
2550 set another step-resume breakpoint; just continue on until the
2551 original breakpoint is hit. */
2552 if (tp
->control
.step_resume_breakpoint
== NULL
)
2554 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
2555 tp
->step_after_step_resume_breakpoint
= 1;
2558 delete_single_step_breakpoints (tp
);
2560 clear_step_over_info ();
2561 tp
->control
.trap_expected
= 0;
2563 insert_breakpoints ();
2566 /* If STEP is set, it's a request to use hardware stepping
2567 facilities. But in that case, we should never
2568 use singlestep breakpoint. */
2569 gdb_assert (!(thread_has_single_step_breakpoints_set (tp
) && step
));
2571 /* Decide the set of threads to ask the target to resume. */
2572 if (tp
->control
.trap_expected
)
2574 /* We're allowing a thread to run past a breakpoint it has
2575 hit, either by single-stepping the thread with the breakpoint
2576 removed, or by displaced stepping, with the breakpoint inserted.
2577 In the former case, we need to single-step only this thread,
2578 and keep others stopped, as they can miss this breakpoint if
2579 allowed to run. That's not really a problem for displaced
2580 stepping, but, we still keep other threads stopped, in case
2581 another thread is also stopped for a breakpoint waiting for
2582 its turn in the displaced stepping queue. */
2583 resume_ptid
= inferior_ptid
;
2586 resume_ptid
= internal_resume_ptid (user_step
);
2588 if (execution_direction
!= EXEC_REVERSE
2589 && step
&& breakpoint_inserted_here_p (aspace
, pc
))
2591 /* There are two cases where we currently need to step a
2592 breakpoint instruction when we have a signal to deliver:
2594 - See handle_signal_stop where we handle random signals that
2595 could take out us out of the stepping range. Normally, in
2596 that case we end up continuing (instead of stepping) over the
2597 signal handler with a breakpoint at PC, but there are cases
2598 where we should _always_ single-step, even if we have a
2599 step-resume breakpoint, like when a software watchpoint is
2600 set. Assuming single-stepping and delivering a signal at the
2601 same time would takes us to the signal handler, then we could
2602 have removed the breakpoint at PC to step over it. However,
2603 some hardware step targets (like e.g., Mac OS) can't step
2604 into signal handlers, and for those, we need to leave the
2605 breakpoint at PC inserted, as otherwise if the handler
2606 recurses and executes PC again, it'll miss the breakpoint.
2607 So we leave the breakpoint inserted anyway, but we need to
2608 record that we tried to step a breakpoint instruction, so
2609 that adjust_pc_after_break doesn't end up confused.
2611 - In non-stop if we insert a breakpoint (e.g., a step-resume)
2612 in one thread after another thread that was stepping had been
2613 momentarily paused for a step-over. When we re-resume the
2614 stepping thread, it may be resumed from that address with a
2615 breakpoint that hasn't trapped yet. Seen with
2616 gdb.threads/non-stop-fair-events.exp, on targets that don't
2617 do displaced stepping. */
2619 infrun_debug_printf ("resume: [%s] stepped breakpoint",
2620 target_pid_to_str (tp
->ptid
).c_str ());
2622 tp
->stepped_breakpoint
= 1;
2624 /* Most targets can step a breakpoint instruction, thus
2625 executing it normally. But if this one cannot, just
2626 continue and we will hit it anyway. */
2627 if (gdbarch_cannot_step_breakpoint (gdbarch
))
2632 && tp
->control
.trap_expected
2633 && use_displaced_stepping (tp
)
2634 && !step_over_info_valid_p ())
2636 struct regcache
*resume_regcache
= get_thread_regcache (tp
);
2637 struct gdbarch
*resume_gdbarch
= resume_regcache
->arch ();
2638 CORE_ADDR actual_pc
= regcache_read_pc (resume_regcache
);
2641 read_memory (actual_pc
, buf
, sizeof (buf
));
2642 displaced_debug_printf ("run %s: %s",
2643 paddress (resume_gdbarch
, actual_pc
),
2644 displaced_step_dump_bytes
2645 (buf
, sizeof (buf
)).c_str ());
2648 if (tp
->control
.may_range_step
)
2650 /* If we're resuming a thread with the PC out of the step
2651 range, then we're doing some nested/finer run control
2652 operation, like stepping the thread out of the dynamic
2653 linker or the displaced stepping scratch pad. We
2654 shouldn't have allowed a range step then. */
2655 gdb_assert (pc_in_thread_step_range (pc
, tp
));
2658 do_target_resume (resume_ptid
, step
, sig
);
2662 /* Resume the inferior. SIG is the signal to give the inferior
2663 (GDB_SIGNAL_0 for none). This is a wrapper around 'resume_1' that
2664 rolls back state on error. */
2667 resume (gdb_signal sig
)
2673 catch (const gdb_exception
&ex
)
2675 /* If resuming is being aborted for any reason, delete any
2676 single-step breakpoint resume_1 may have created, to avoid
2677 confusing the following resumption, and to avoid leaving
2678 single-step breakpoints perturbing other threads, in case
2679 we're running in non-stop mode. */
2680 if (inferior_ptid
!= null_ptid
)
2681 delete_single_step_breakpoints (inferior_thread ());
2691 /* Counter that tracks number of user visible stops. This can be used
2692 to tell whether a command has proceeded the inferior past the
2693 current location. This allows e.g., inferior function calls in
2694 breakpoint commands to not interrupt the command list. When the
2695 call finishes successfully, the inferior is standing at the same
2696 breakpoint as if nothing happened (and so we don't call
2698 static ULONGEST current_stop_id
;
2705 return current_stop_id
;
2708 /* Called when we report a user visible stop. */
2716 /* Clear out all variables saying what to do when inferior is continued.
2717 First do this, then set the ones you want, then call `proceed'. */
2720 clear_proceed_status_thread (struct thread_info
*tp
)
2722 infrun_debug_printf ("%s", target_pid_to_str (tp
->ptid
).c_str ());
2724 /* If we're starting a new sequence, then the previous finished
2725 single-step is no longer relevant. */
2726 if (tp
->suspend
.waitstatus_pending_p
)
2728 if (tp
->suspend
.stop_reason
== TARGET_STOPPED_BY_SINGLE_STEP
)
2730 infrun_debug_printf ("pending event of %s was a finished step. "
2732 target_pid_to_str (tp
->ptid
).c_str ());
2734 tp
->suspend
.waitstatus_pending_p
= 0;
2735 tp
->suspend
.stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
2740 ("thread %s has pending wait status %s (currently_stepping=%d).",
2741 target_pid_to_str (tp
->ptid
).c_str (),
2742 target_waitstatus_to_string (&tp
->suspend
.waitstatus
).c_str (),
2743 currently_stepping (tp
));
2747 /* If this signal should not be seen by program, give it zero.
2748 Used for debugging signals. */
2749 if (!signal_pass_state (tp
->suspend
.stop_signal
))
2750 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2752 delete tp
->thread_fsm
;
2753 tp
->thread_fsm
= NULL
;
2755 tp
->control
.trap_expected
= 0;
2756 tp
->control
.step_range_start
= 0;
2757 tp
->control
.step_range_end
= 0;
2758 tp
->control
.may_range_step
= 0;
2759 tp
->control
.step_frame_id
= null_frame_id
;
2760 tp
->control
.step_stack_frame_id
= null_frame_id
;
2761 tp
->control
.step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
2762 tp
->control
.step_start_function
= NULL
;
2763 tp
->stop_requested
= 0;
2765 tp
->control
.stop_step
= 0;
2767 tp
->control
.proceed_to_finish
= 0;
2769 tp
->control
.stepping_command
= 0;
2771 /* Discard any remaining commands or status from previous stop. */
2772 bpstat_clear (&tp
->control
.stop_bpstat
);
2776 clear_proceed_status (int step
)
2778 /* With scheduler-locking replay, stop replaying other threads if we're
2779 not replaying the user-visible resume ptid.
2781 This is a convenience feature to not require the user to explicitly
2782 stop replaying the other threads. We're assuming that the user's
2783 intent is to resume tracing the recorded process. */
2784 if (!non_stop
&& scheduler_mode
== schedlock_replay
2785 && target_record_is_replaying (minus_one_ptid
)
2786 && !target_record_will_replay (user_visible_resume_ptid (step
),
2787 execution_direction
))
2788 target_record_stop_replaying ();
2790 if (!non_stop
&& inferior_ptid
!= null_ptid
)
2792 ptid_t resume_ptid
= user_visible_resume_ptid (step
);
2793 process_stratum_target
*resume_target
2794 = user_visible_resume_target (resume_ptid
);
2796 /* In all-stop mode, delete the per-thread status of all threads
2797 we're about to resume, implicitly and explicitly. */
2798 for (thread_info
*tp
: all_non_exited_threads (resume_target
, resume_ptid
))
2799 clear_proceed_status_thread (tp
);
2802 if (inferior_ptid
!= null_ptid
)
2804 struct inferior
*inferior
;
2808 /* If in non-stop mode, only delete the per-thread status of
2809 the current thread. */
2810 clear_proceed_status_thread (inferior_thread ());
2813 inferior
= current_inferior ();
2814 inferior
->control
.stop_soon
= NO_STOP_QUIETLY
;
2817 gdb::observers::about_to_proceed
.notify ();
2820 /* Returns true if TP is still stopped at a breakpoint that needs
2821 stepping-over in order to make progress. If the breakpoint is gone
2822 meanwhile, we can skip the whole step-over dance. */
2825 thread_still_needs_step_over_bp (struct thread_info
*tp
)
2827 if (tp
->stepping_over_breakpoint
)
2829 struct regcache
*regcache
= get_thread_regcache (tp
);
2831 if (breakpoint_here_p (regcache
->aspace (),
2832 regcache_read_pc (regcache
))
2833 == ordinary_breakpoint_here
)
2836 tp
->stepping_over_breakpoint
= 0;
2842 /* Check whether thread TP still needs to start a step-over in order
2843 to make progress when resumed. Returns an bitwise or of enum
2844 step_over_what bits, indicating what needs to be stepped over. */
2846 static step_over_what
2847 thread_still_needs_step_over (struct thread_info
*tp
)
2849 step_over_what what
= 0;
2851 if (thread_still_needs_step_over_bp (tp
))
2852 what
|= STEP_OVER_BREAKPOINT
;
2854 if (tp
->stepping_over_watchpoint
2855 && !target_have_steppable_watchpoint ())
2856 what
|= STEP_OVER_WATCHPOINT
;
2861 /* Returns true if scheduler locking applies. STEP indicates whether
2862 we're about to do a step/next-like command to a thread. */
2865 schedlock_applies (struct thread_info
*tp
)
2867 return (scheduler_mode
== schedlock_on
2868 || (scheduler_mode
== schedlock_step
2869 && tp
->control
.stepping_command
)
2870 || (scheduler_mode
== schedlock_replay
2871 && target_record_will_replay (minus_one_ptid
,
2872 execution_direction
)));
2875 /* Set process_stratum_target::COMMIT_RESUMED_STATE in all target
2876 stacks that have threads executing and don't have threads with
2880 maybe_set_commit_resumed_all_targets ()
2882 scoped_restore_current_thread restore_thread
;
2884 for (inferior
*inf
: all_non_exited_inferiors ())
2886 process_stratum_target
*proc_target
= inf
->process_target ();
2888 if (proc_target
->commit_resumed_state
)
2890 /* We already set this in a previous iteration, via another
2891 inferior sharing the process_stratum target. */
2895 /* If the target has no resumed threads, it would be useless to
2896 ask it to commit the resumed threads. */
2897 if (!proc_target
->threads_executing
)
2899 infrun_debug_printf ("not requesting commit-resumed for target "
2900 "%s, no resumed threads",
2901 proc_target
->shortname ());
2905 /* As an optimization, if a thread from this target has some
2906 status to report, handle it before requiring the target to
2907 commit its resumed threads: handling the status might lead to
2908 resuming more threads. */
2909 bool has_thread_with_pending_status
= false;
2910 for (thread_info
*thread
: all_non_exited_threads (proc_target
))
2911 if (thread
->resumed
&& thread
->suspend
.waitstatus_pending_p
)
2913 has_thread_with_pending_status
= true;
2917 if (has_thread_with_pending_status
)
2919 infrun_debug_printf ("not requesting commit-resumed for target %s, a"
2920 " thread has a pending waitstatus",
2921 proc_target
->shortname ());
2925 switch_to_inferior_no_thread (inf
);
2927 if (target_has_pending_events ())
2929 infrun_debug_printf ("not requesting commit-resumed for target %s, "
2930 "target has pending events",
2931 proc_target
->shortname ());
2935 infrun_debug_printf ("enabling commit-resumed for target %s",
2936 proc_target
->shortname ());
2938 proc_target
->commit_resumed_state
= true;
2945 maybe_call_commit_resumed_all_targets ()
2947 scoped_restore_current_thread restore_thread
;
2949 for (inferior
*inf
: all_non_exited_inferiors ())
2951 process_stratum_target
*proc_target
= inf
->process_target ();
2953 if (!proc_target
->commit_resumed_state
)
2956 switch_to_inferior_no_thread (inf
);
2958 infrun_debug_printf ("calling commit_resumed for target %s",
2959 proc_target
->shortname());
2961 target_commit_resumed ();
2965 /* To track nesting of scoped_disable_commit_resumed objects, ensuring
2966 that only the outermost one attempts to re-enable
2968 static bool enable_commit_resumed
= true;
2972 scoped_disable_commit_resumed::scoped_disable_commit_resumed
2973 (const char *reason
)
2974 : m_reason (reason
),
2975 m_prev_enable_commit_resumed (enable_commit_resumed
)
2977 infrun_debug_printf ("reason=%s", m_reason
);
2979 enable_commit_resumed
= false;
2981 for (inferior
*inf
: all_non_exited_inferiors ())
2983 process_stratum_target
*proc_target
= inf
->process_target ();
2985 if (m_prev_enable_commit_resumed
)
2987 /* This is the outermost instance: force all
2988 COMMIT_RESUMED_STATE to false. */
2989 proc_target
->commit_resumed_state
= false;
2993 /* This is not the outermost instance, we expect
2994 COMMIT_RESUMED_STATE to have been cleared by the
2995 outermost instance. */
2996 gdb_assert (!proc_target
->commit_resumed_state
);
3004 scoped_disable_commit_resumed::reset ()
3010 infrun_debug_printf ("reason=%s", m_reason
);
3012 gdb_assert (!enable_commit_resumed
);
3014 enable_commit_resumed
= m_prev_enable_commit_resumed
;
3016 if (m_prev_enable_commit_resumed
)
3018 /* This is the outermost instance, re-enable
3019 COMMIT_RESUMED_STATE on the targets where it's possible. */
3020 maybe_set_commit_resumed_all_targets ();
3024 /* This is not the outermost instance, we expect
3025 COMMIT_RESUMED_STATE to still be false. */
3026 for (inferior
*inf
: all_non_exited_inferiors ())
3028 process_stratum_target
*proc_target
= inf
->process_target ();
3029 gdb_assert (!proc_target
->commit_resumed_state
);
3036 scoped_disable_commit_resumed::~scoped_disable_commit_resumed ()
3044 scoped_disable_commit_resumed::reset_and_commit ()
3047 maybe_call_commit_resumed_all_targets ();
3052 scoped_enable_commit_resumed::scoped_enable_commit_resumed
3053 (const char *reason
)
3054 : m_reason (reason
),
3055 m_prev_enable_commit_resumed (enable_commit_resumed
)
3057 infrun_debug_printf ("reason=%s", m_reason
);
3059 if (!enable_commit_resumed
)
3061 enable_commit_resumed
= true;
3063 /* Re-enable COMMIT_RESUMED_STATE on the targets where it's
3065 maybe_set_commit_resumed_all_targets ();
3067 maybe_call_commit_resumed_all_targets ();
3073 scoped_enable_commit_resumed::~scoped_enable_commit_resumed ()
3075 infrun_debug_printf ("reason=%s", m_reason
);
3077 gdb_assert (enable_commit_resumed
);
3079 enable_commit_resumed
= m_prev_enable_commit_resumed
;
3081 if (!enable_commit_resumed
)
3083 /* Force all COMMIT_RESUMED_STATE back to false. */
3084 for (inferior
*inf
: all_non_exited_inferiors ())
3086 process_stratum_target
*proc_target
= inf
->process_target ();
3087 proc_target
->commit_resumed_state
= false;
3092 /* Check that all the targets we're about to resume are in non-stop
3093 mode. Ideally, we'd only care whether all targets support
3094 target-async, but we're not there yet. E.g., stop_all_threads
3095 doesn't know how to handle all-stop targets. Also, the remote
3096 protocol in all-stop mode is synchronous, irrespective of
3097 target-async, which means that things like a breakpoint re-set
3098 triggered by one target would try to read memory from all targets
3102 check_multi_target_resumption (process_stratum_target
*resume_target
)
3104 if (!non_stop
&& resume_target
== nullptr)
3106 scoped_restore_current_thread restore_thread
;
3108 /* This is used to track whether we're resuming more than one
3110 process_stratum_target
*first_connection
= nullptr;
3112 /* The first inferior we see with a target that does not work in
3113 always-non-stop mode. */
3114 inferior
*first_not_non_stop
= nullptr;
3116 for (inferior
*inf
: all_non_exited_inferiors ())
3118 switch_to_inferior_no_thread (inf
);
3120 if (!target_has_execution ())
3123 process_stratum_target
*proc_target
3124 = current_inferior ()->process_target();
3126 if (!target_is_non_stop_p ())
3127 first_not_non_stop
= inf
;
3129 if (first_connection
== nullptr)
3130 first_connection
= proc_target
;
3131 else if (first_connection
!= proc_target
3132 && first_not_non_stop
!= nullptr)
3134 switch_to_inferior_no_thread (first_not_non_stop
);
3136 proc_target
= current_inferior ()->process_target();
3138 error (_("Connection %d (%s) does not support "
3139 "multi-target resumption."),
3140 proc_target
->connection_number
,
3141 make_target_connection_string (proc_target
).c_str ());
3147 /* Basic routine for continuing the program in various fashions.
3149 ADDR is the address to resume at, or -1 for resume where stopped.
3150 SIGGNAL is the signal to give it, or GDB_SIGNAL_0 for none,
3151 or GDB_SIGNAL_DEFAULT for act according to how it stopped.
3153 You should call clear_proceed_status before calling proceed. */
3156 proceed (CORE_ADDR addr
, enum gdb_signal siggnal
)
3158 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
3160 struct regcache
*regcache
;
3161 struct gdbarch
*gdbarch
;
3163 struct execution_control_state ecss
;
3164 struct execution_control_state
*ecs
= &ecss
;
3167 /* If we're stopped at a fork/vfork, follow the branch set by the
3168 "set follow-fork-mode" command; otherwise, we'll just proceed
3169 resuming the current thread. */
3170 if (!follow_fork ())
3172 /* The target for some reason decided not to resume. */
3174 if (target_can_async_p ())
3175 inferior_event_handler (INF_EXEC_COMPLETE
);
3179 /* We'll update this if & when we switch to a new thread. */
3180 previous_inferior_ptid
= inferior_ptid
;
3182 regcache
= get_current_regcache ();
3183 gdbarch
= regcache
->arch ();
3184 const address_space
*aspace
= regcache
->aspace ();
3186 pc
= regcache_read_pc_protected (regcache
);
3188 thread_info
*cur_thr
= inferior_thread ();
3190 /* Fill in with reasonable starting values. */
3191 init_thread_stepping_state (cur_thr
);
3193 gdb_assert (!thread_is_in_step_over_chain (cur_thr
));
3196 = user_visible_resume_ptid (cur_thr
->control
.stepping_command
);
3197 process_stratum_target
*resume_target
3198 = user_visible_resume_target (resume_ptid
);
3200 check_multi_target_resumption (resume_target
);
3202 if (addr
== (CORE_ADDR
) -1)
3204 if (pc
== cur_thr
->suspend
.stop_pc
3205 && breakpoint_here_p (aspace
, pc
) == ordinary_breakpoint_here
3206 && execution_direction
!= EXEC_REVERSE
)
3207 /* There is a breakpoint at the address we will resume at,
3208 step one instruction before inserting breakpoints so that
3209 we do not stop right away (and report a second hit at this
3212 Note, we don't do this in reverse, because we won't
3213 actually be executing the breakpoint insn anyway.
3214 We'll be (un-)executing the previous instruction. */
3215 cur_thr
->stepping_over_breakpoint
= 1;
3216 else if (gdbarch_single_step_through_delay_p (gdbarch
)
3217 && gdbarch_single_step_through_delay (gdbarch
,
3218 get_current_frame ()))
3219 /* We stepped onto an instruction that needs to be stepped
3220 again before re-inserting the breakpoint, do so. */
3221 cur_thr
->stepping_over_breakpoint
= 1;
3225 regcache_write_pc (regcache
, addr
);
3228 if (siggnal
!= GDB_SIGNAL_DEFAULT
)
3229 cur_thr
->suspend
.stop_signal
= siggnal
;
3231 /* If an exception is thrown from this point on, make sure to
3232 propagate GDB's knowledge of the executing state to the
3233 frontend/user running state. */
3234 scoped_finish_thread_state
finish_state (resume_target
, resume_ptid
);
3236 /* Even if RESUME_PTID is a wildcard, and we end up resuming fewer
3237 threads (e.g., we might need to set threads stepping over
3238 breakpoints first), from the user/frontend's point of view, all
3239 threads in RESUME_PTID are now running. Unless we're calling an
3240 inferior function, as in that case we pretend the inferior
3241 doesn't run at all. */
3242 if (!cur_thr
->control
.in_infcall
)
3243 set_running (resume_target
, resume_ptid
, true);
3245 infrun_debug_printf ("addr=%s, signal=%s", paddress (gdbarch
, addr
),
3246 gdb_signal_to_symbol_string (siggnal
));
3248 annotate_starting ();
3250 /* Make sure that output from GDB appears before output from the
3252 gdb_flush (gdb_stdout
);
3254 /* Since we've marked the inferior running, give it the terminal. A
3255 QUIT/Ctrl-C from here on is forwarded to the target (which can
3256 still detect attempts to unblock a stuck connection with repeated
3257 Ctrl-C from within target_pass_ctrlc). */
3258 target_terminal::inferior ();
3260 /* In a multi-threaded task we may select another thread and
3261 then continue or step.
3263 But if a thread that we're resuming had stopped at a breakpoint,
3264 it will immediately cause another breakpoint stop without any
3265 execution (i.e. it will report a breakpoint hit incorrectly). So
3266 we must step over it first.
3268 Look for threads other than the current (TP) that reported a
3269 breakpoint hit and haven't been resumed yet since. */
3271 /* If scheduler locking applies, we can avoid iterating over all
3273 if (!non_stop
&& !schedlock_applies (cur_thr
))
3275 for (thread_info
*tp
: all_non_exited_threads (resume_target
,
3278 switch_to_thread_no_regs (tp
);
3280 /* Ignore the current thread here. It's handled
3285 if (!thread_still_needs_step_over (tp
))
3288 gdb_assert (!thread_is_in_step_over_chain (tp
));
3290 infrun_debug_printf ("need to step-over [%s] first",
3291 target_pid_to_str (tp
->ptid
).c_str ());
3293 global_thread_step_over_chain_enqueue (tp
);
3296 switch_to_thread (cur_thr
);
3299 /* Enqueue the current thread last, so that we move all other
3300 threads over their breakpoints first. */
3301 if (cur_thr
->stepping_over_breakpoint
)
3302 global_thread_step_over_chain_enqueue (cur_thr
);
3304 /* If the thread isn't started, we'll still need to set its prev_pc,
3305 so that switch_back_to_stepped_thread knows the thread hasn't
3306 advanced. Must do this before resuming any thread, as in
3307 all-stop/remote, once we resume we can't send any other packet
3308 until the target stops again. */
3309 cur_thr
->prev_pc
= regcache_read_pc_protected (regcache
);
3312 scoped_disable_commit_resumed
disable_commit_resumed ("proceeding");
3314 started
= start_step_over ();
3316 if (step_over_info_valid_p ())
3318 /* Either this thread started a new in-line step over, or some
3319 other thread was already doing one. In either case, don't
3320 resume anything else until the step-over is finished. */
3322 else if (started
&& !target_is_non_stop_p ())
3324 /* A new displaced stepping sequence was started. In all-stop,
3325 we can't talk to the target anymore until it next stops. */
3327 else if (!non_stop
&& target_is_non_stop_p ())
3329 INFRUN_SCOPED_DEBUG_START_END
3330 ("resuming threads, all-stop-on-top-of-non-stop");
3332 /* In all-stop, but the target is always in non-stop mode.
3333 Start all other threads that are implicitly resumed too. */
3334 for (thread_info
*tp
: all_non_exited_threads (resume_target
,
3337 switch_to_thread_no_regs (tp
);
3339 if (!tp
->inf
->has_execution ())
3341 infrun_debug_printf ("[%s] target has no execution",
3342 target_pid_to_str (tp
->ptid
).c_str ());
3348 infrun_debug_printf ("[%s] resumed",
3349 target_pid_to_str (tp
->ptid
).c_str ());
3350 gdb_assert (tp
->executing
|| tp
->suspend
.waitstatus_pending_p
);
3354 if (thread_is_in_step_over_chain (tp
))
3356 infrun_debug_printf ("[%s] needs step-over",
3357 target_pid_to_str (tp
->ptid
).c_str ());
3361 /* If a thread of that inferior is waiting for a vfork-done
3362 (for a detached vfork child to exec or exit), breakpoints are
3363 removed. We must not resume any thread of that inferior, other
3364 than the one waiting for the vfork-done. */
3365 if (tp
->inf
->thread_waiting_for_vfork_done
!= nullptr
3366 && tp
!= tp
->inf
->thread_waiting_for_vfork_done
)
3368 infrun_debug_printf ("[%s] another thread of this inferior is "
3369 "waiting for vfork-done",
3370 tp
->ptid
.to_string ().c_str ());
3374 infrun_debug_printf ("resuming %s",
3375 target_pid_to_str (tp
->ptid
).c_str ());
3377 reset_ecs (ecs
, tp
);
3378 switch_to_thread (tp
);
3379 keep_going_pass_signal (ecs
);
3380 if (!ecs
->wait_some_more
)
3381 error (_("Command aborted."));
3384 else if (!cur_thr
->resumed
3385 && !thread_is_in_step_over_chain (cur_thr
)
3386 /* In non-stop, forbid resume a thread if some other thread of
3387 that inferior is waiting for a vfork-done event (this means
3388 breakpoints are out for this inferior). */
3389 && !(non_stop
&& cur_thr
->inf
->thread_waiting_for_vfork_done
))
3391 /* The thread wasn't started, and isn't queued, run it now. */
3392 reset_ecs (ecs
, cur_thr
);
3393 switch_to_thread (cur_thr
);
3394 keep_going_pass_signal (ecs
);
3395 if (!ecs
->wait_some_more
)
3396 error (_("Command aborted."));
3399 disable_commit_resumed
.reset_and_commit ();
3402 finish_state
.release ();
3404 /* If we've switched threads above, switch back to the previously
3405 current thread. We don't want the user to see a different
3407 switch_to_thread (cur_thr
);
3409 /* Tell the event loop to wait for it to stop. If the target
3410 supports asynchronous execution, it'll do this from within
3412 if (!target_can_async_p ())
3413 mark_async_event_handler (infrun_async_inferior_event_token
);
3417 /* Start remote-debugging of a machine over a serial link. */
3420 start_remote (int from_tty
)
3422 inferior
*inf
= current_inferior ();
3423 inf
->control
.stop_soon
= STOP_QUIETLY_REMOTE
;
3425 /* Always go on waiting for the target, regardless of the mode. */
3426 /* FIXME: cagney/1999-09-23: At present it isn't possible to
3427 indicate to wait_for_inferior that a target should timeout if
3428 nothing is returned (instead of just blocking). Because of this,
3429 targets expecting an immediate response need to, internally, set
3430 things up so that the target_wait() is forced to eventually
3432 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
3433 differentiate to its caller what the state of the target is after
3434 the initial open has been performed. Here we're assuming that
3435 the target has stopped. It should be possible to eventually have
3436 target_open() return to the caller an indication that the target
3437 is currently running and GDB state should be set to the same as
3438 for an async run. */
3439 wait_for_inferior (inf
);
3441 /* Now that the inferior has stopped, do any bookkeeping like
3442 loading shared libraries. We want to do this before normal_stop,
3443 so that the displayed frame is up to date. */
3444 post_create_inferior (from_tty
);
3449 /* Initialize static vars when a new inferior begins. */
3452 init_wait_for_inferior (void)
3454 /* These are meaningless until the first time through wait_for_inferior. */
3456 breakpoint_init_inferior (inf_starting
);
3458 clear_proceed_status (0);
3460 nullify_last_target_wait_ptid ();
3462 previous_inferior_ptid
= inferior_ptid
;
3467 static void handle_inferior_event (struct execution_control_state
*ecs
);
3469 static void handle_step_into_function (struct gdbarch
*gdbarch
,
3470 struct execution_control_state
*ecs
);
3471 static void handle_step_into_function_backward (struct gdbarch
*gdbarch
,
3472 struct execution_control_state
*ecs
);
3473 static void handle_signal_stop (struct execution_control_state
*ecs
);
3474 static void check_exception_resume (struct execution_control_state
*,
3475 struct frame_info
*);
3477 static void end_stepping_range (struct execution_control_state
*ecs
);
3478 static void stop_waiting (struct execution_control_state
*ecs
);
3479 static void keep_going (struct execution_control_state
*ecs
);
3480 static void process_event_stop_test (struct execution_control_state
*ecs
);
3481 static bool switch_back_to_stepped_thread (struct execution_control_state
*ecs
);
3483 /* This function is attached as a "thread_stop_requested" observer.
3484 Cleanup local state that assumed the PTID was to be resumed, and
3485 report the stop to the frontend. */
3488 infrun_thread_stop_requested (ptid_t ptid
)
3490 process_stratum_target
*curr_target
= current_inferior ()->process_target ();
3492 /* PTID was requested to stop. If the thread was already stopped,
3493 but the user/frontend doesn't know about that yet (e.g., the
3494 thread had been temporarily paused for some step-over), set up
3495 for reporting the stop now. */
3496 for (thread_info
*tp
: all_threads (curr_target
, ptid
))
3498 if (tp
->state
!= THREAD_RUNNING
)
3503 /* Remove matching threads from the step-over queue, so
3504 start_step_over doesn't try to resume them
3506 if (thread_is_in_step_over_chain (tp
))
3507 global_thread_step_over_chain_remove (tp
);
3509 /* If the thread is stopped, but the user/frontend doesn't
3510 know about that yet, queue a pending event, as if the
3511 thread had just stopped now. Unless the thread already had
3513 if (!tp
->suspend
.waitstatus_pending_p
)
3515 tp
->suspend
.waitstatus_pending_p
= 1;
3516 tp
->suspend
.waitstatus
.kind
= TARGET_WAITKIND_STOPPED
;
3517 tp
->suspend
.waitstatus
.value
.sig
= GDB_SIGNAL_0
;
3520 /* Clear the inline-frame state, since we're re-processing the
3522 clear_inline_frame_state (tp
);
3524 /* If this thread was paused because some other thread was
3525 doing an inline-step over, let that finish first. Once
3526 that happens, we'll restart all threads and consume pending
3527 stop events then. */
3528 if (step_over_info_valid_p ())
3531 /* Otherwise we can process the (new) pending event now. Set
3532 it so this pending event is considered by
3539 infrun_thread_thread_exit (struct thread_info
*tp
, int silent
)
3541 if (target_last_proc_target
== tp
->inf
->process_target ()
3542 && target_last_wait_ptid
== tp
->ptid
)
3543 nullify_last_target_wait_ptid ();
3546 /* Delete the step resume, single-step and longjmp/exception resume
3547 breakpoints of TP. */
3550 delete_thread_infrun_breakpoints (struct thread_info
*tp
)
3552 delete_step_resume_breakpoint (tp
);
3553 delete_exception_resume_breakpoint (tp
);
3554 delete_single_step_breakpoints (tp
);
3557 /* If the target still has execution, call FUNC for each thread that
3558 just stopped. In all-stop, that's all the non-exited threads; in
3559 non-stop, that's the current thread, only. */
3561 typedef void (*for_each_just_stopped_thread_callback_func
)
3562 (struct thread_info
*tp
);
3565 for_each_just_stopped_thread (for_each_just_stopped_thread_callback_func func
)
3567 if (!target_has_execution () || inferior_ptid
== null_ptid
)
3570 if (target_is_non_stop_p ())
3572 /* If in non-stop mode, only the current thread stopped. */
3573 func (inferior_thread ());
3577 /* In all-stop mode, all threads have stopped. */
3578 for (thread_info
*tp
: all_non_exited_threads ())
3583 /* Delete the step resume and longjmp/exception resume breakpoints of
3584 the threads that just stopped. */
3587 delete_just_stopped_threads_infrun_breakpoints (void)
3589 for_each_just_stopped_thread (delete_thread_infrun_breakpoints
);
3592 /* Delete the single-step breakpoints of the threads that just
3596 delete_just_stopped_threads_single_step_breakpoints (void)
3598 for_each_just_stopped_thread (delete_single_step_breakpoints
);
3604 print_target_wait_results (ptid_t waiton_ptid
, ptid_t result_ptid
,
3605 const struct target_waitstatus
*ws
)
3607 infrun_debug_printf ("target_wait (%d.%ld.%ld [%s], status) =",
3611 target_pid_to_str (waiton_ptid
).c_str ());
3612 infrun_debug_printf (" %d.%ld.%ld [%s],",
3616 target_pid_to_str (result_ptid
).c_str ());
3617 infrun_debug_printf (" %s", target_waitstatus_to_string (ws
).c_str ());
3620 /* Select a thread at random, out of those which are resumed and have
3623 static struct thread_info
*
3624 random_pending_event_thread (inferior
*inf
, ptid_t waiton_ptid
)
3628 auto has_event
= [&] (thread_info
*tp
)
3630 return (tp
->ptid
.matches (waiton_ptid
)
3632 && tp
->suspend
.waitstatus_pending_p
);
3635 /* First see how many events we have. Count only resumed threads
3636 that have an event pending. */
3637 for (thread_info
*tp
: inf
->non_exited_threads ())
3641 if (num_events
== 0)
3644 /* Now randomly pick a thread out of those that have had events. */
3645 int random_selector
= (int) ((num_events
* (double) rand ())
3646 / (RAND_MAX
+ 1.0));
3649 infrun_debug_printf ("Found %d events, selecting #%d",
3650 num_events
, random_selector
);
3652 /* Select the Nth thread that has had an event. */
3653 for (thread_info
*tp
: inf
->non_exited_threads ())
3655 if (random_selector
-- == 0)
3658 gdb_assert_not_reached ("event thread not found");
3661 /* Wrapper for target_wait that first checks whether threads have
3662 pending statuses to report before actually asking the target for
3663 more events. INF is the inferior we're using to call target_wait
3667 do_target_wait_1 (inferior
*inf
, ptid_t ptid
,
3668 target_waitstatus
*status
, target_wait_flags options
)
3671 struct thread_info
*tp
;
3673 /* We know that we are looking for an event in the target of inferior
3674 INF, but we don't know which thread the event might come from. As
3675 such we want to make sure that INFERIOR_PTID is reset so that none of
3676 the wait code relies on it - doing so is always a mistake. */
3677 switch_to_inferior_no_thread (inf
);
3679 /* First check if there is a resumed thread with a wait status
3681 if (ptid
== minus_one_ptid
|| ptid
.is_pid ())
3683 tp
= random_pending_event_thread (inf
, ptid
);
3687 infrun_debug_printf ("Waiting for specific thread %s.",
3688 target_pid_to_str (ptid
).c_str ());
3690 /* We have a specific thread to check. */
3691 tp
= find_thread_ptid (inf
, ptid
);
3692 gdb_assert (tp
!= NULL
);
3693 if (!tp
->suspend
.waitstatus_pending_p
)
3698 && (tp
->suspend
.stop_reason
== TARGET_STOPPED_BY_SW_BREAKPOINT
3699 || tp
->suspend
.stop_reason
== TARGET_STOPPED_BY_HW_BREAKPOINT
))
3701 struct regcache
*regcache
= get_thread_regcache (tp
);
3702 struct gdbarch
*gdbarch
= regcache
->arch ();
3706 pc
= regcache_read_pc (regcache
);
3708 if (pc
!= tp
->suspend
.stop_pc
)
3710 infrun_debug_printf ("PC of %s changed. was=%s, now=%s",
3711 target_pid_to_str (tp
->ptid
).c_str (),
3712 paddress (gdbarch
, tp
->suspend
.stop_pc
),
3713 paddress (gdbarch
, pc
));
3716 else if (!breakpoint_inserted_here_p (regcache
->aspace (), pc
))
3718 infrun_debug_printf ("previous breakpoint of %s, at %s gone",
3719 target_pid_to_str (tp
->ptid
).c_str (),
3720 paddress (gdbarch
, pc
));
3727 infrun_debug_printf ("pending event of %s cancelled.",
3728 target_pid_to_str (tp
->ptid
).c_str ());
3730 tp
->suspend
.waitstatus
.kind
= TARGET_WAITKIND_SPURIOUS
;
3731 tp
->suspend
.stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
3737 infrun_debug_printf ("Using pending wait status %s for %s.",
3738 target_waitstatus_to_string
3739 (&tp
->suspend
.waitstatus
).c_str (),
3740 target_pid_to_str (tp
->ptid
).c_str ());
3742 /* Now that we've selected our final event LWP, un-adjust its PC
3743 if it was a software breakpoint (and the target doesn't
3744 always adjust the PC itself). */
3745 if (tp
->suspend
.stop_reason
== TARGET_STOPPED_BY_SW_BREAKPOINT
3746 && !target_supports_stopped_by_sw_breakpoint ())
3748 struct regcache
*regcache
;
3749 struct gdbarch
*gdbarch
;
3752 regcache
= get_thread_regcache (tp
);
3753 gdbarch
= regcache
->arch ();
3755 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
3760 pc
= regcache_read_pc (regcache
);
3761 regcache_write_pc (regcache
, pc
+ decr_pc
);
3765 tp
->suspend
.stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
3766 *status
= tp
->suspend
.waitstatus
;
3767 tp
->suspend
.waitstatus_pending_p
= 0;
3769 /* Wake up the event loop again, until all pending events are
3771 if (target_is_async_p ())
3772 mark_async_event_handler (infrun_async_inferior_event_token
);
3776 /* But if we don't find one, we'll have to wait. */
3778 /* We can't ask a non-async target to do a non-blocking wait, so this will be
3780 if (!target_can_async_p ())
3781 options
&= ~TARGET_WNOHANG
;
3783 if (deprecated_target_wait_hook
)
3784 event_ptid
= deprecated_target_wait_hook (ptid
, status
, options
);
3786 event_ptid
= target_wait (ptid
, status
, options
);
3791 /* Wrapper for target_wait that first checks whether threads have
3792 pending statuses to report before actually asking the target for
3793 more events. Polls for events from all inferiors/targets. */
3796 do_target_wait (execution_control_state
*ecs
, target_wait_flags options
)
3798 int num_inferiors
= 0;
3799 int random_selector
;
3801 /* For fairness, we pick the first inferior/target to poll at random
3802 out of all inferiors that may report events, and then continue
3803 polling the rest of the inferior list starting from that one in a
3804 circular fashion until the whole list is polled once. */
3806 auto inferior_matches
= [] (inferior
*inf
)
3808 return inf
->process_target () != nullptr;
3811 /* First see how many matching inferiors we have. */
3812 for (inferior
*inf
: all_inferiors ())
3813 if (inferior_matches (inf
))
3816 if (num_inferiors
== 0)
3818 ecs
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
3822 /* Now randomly pick an inferior out of those that matched. */
3823 random_selector
= (int)
3824 ((num_inferiors
* (double) rand ()) / (RAND_MAX
+ 1.0));
3826 if (num_inferiors
> 1)
3827 infrun_debug_printf ("Found %d inferiors, starting at #%d",
3828 num_inferiors
, random_selector
);
3830 /* Select the Nth inferior that matched. */
3832 inferior
*selected
= nullptr;
3834 for (inferior
*inf
: all_inferiors ())
3835 if (inferior_matches (inf
))
3836 if (random_selector
-- == 0)
3842 /* Now poll for events out of each of the matching inferior's
3843 targets, starting from the selected one. */
3845 auto do_wait
= [&] (inferior
*inf
)
3847 ecs
->ptid
= do_target_wait_1 (inf
, minus_one_ptid
, &ecs
->ws
, options
);
3848 ecs
->target
= inf
->process_target ();
3849 return (ecs
->ws
.kind
!= TARGET_WAITKIND_IGNORE
);
3852 /* Needed in 'all-stop + target-non-stop' mode, because we end up
3853 here spuriously after the target is all stopped and we've already
3854 reported the stop to the user, polling for events. */
3855 scoped_restore_current_thread restore_thread
;
3857 int inf_num
= selected
->num
;
3858 for (inferior
*inf
= selected
; inf
!= NULL
; inf
= inf
->next
)
3859 if (inferior_matches (inf
))
3863 for (inferior
*inf
= inferior_list
;
3864 inf
!= NULL
&& inf
->num
< inf_num
;
3866 if (inferior_matches (inf
))
3870 ecs
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
3874 /* An event reported by wait_one. */
3876 struct wait_one_event
3878 /* The target the event came out of. */
3879 process_stratum_target
*target
;
3881 /* The PTID the event was for. */
3884 /* The waitstatus. */
3885 target_waitstatus ws
;
3888 static bool handle_one (const wait_one_event
&event
);
3890 /* Prepare and stabilize the inferior for detaching it. E.g.,
3891 detaching while a thread is displaced stepping is a recipe for
3892 crashing it, as nothing would readjust the PC out of the scratch
3896 prepare_for_detach (void)
3898 struct inferior
*inf
= current_inferior ();
3899 ptid_t pid_ptid
= ptid_t (inf
->pid
);
3900 scoped_restore_current_thread restore_thread
;
3902 scoped_restore restore_detaching
= make_scoped_restore (&inf
->detaching
, true);
3904 /* Remove all threads of INF from the global step-over chain. We
3905 want to stop any ongoing step-over, not start any new one. */
3907 for (thread_info
*tp
= global_thread_step_over_chain_head
;
3911 next
= global_thread_step_over_chain_next (tp
);
3913 global_thread_step_over_chain_remove (tp
);
3916 /* If we were already in the middle of an inline step-over, and the
3917 thread stepping belongs to the inferior we're detaching, we need
3918 to restart the threads of other inferiors. */
3919 if (step_over_info
.thread
!= -1)
3921 infrun_debug_printf ("inline step-over in-process while detaching");
3923 thread_info
*thr
= find_thread_global_id (step_over_info
.thread
);
3924 if (thr
->inf
== inf
)
3926 /* Since we removed threads of INF from the step-over chain,
3927 we know this won't start a step-over for INF. */
3928 clear_step_over_info ();
3930 if (target_is_non_stop_p ())
3932 /* Start a new step-over in another thread if there's
3933 one that needs it. */
3936 /* Restart all other threads (except the
3937 previously-stepping thread, since that one is still
3939 if (!step_over_info_valid_p ())
3940 restart_threads (thr
);
3945 if (displaced_step_in_progress (inf
))
3947 infrun_debug_printf ("displaced-stepping in-process while detaching");
3949 /* Stop threads currently displaced stepping, aborting it. */
3951 for (thread_info
*thr
: inf
->non_exited_threads ())
3953 if (thr
->displaced_step_state
.in_progress ())
3957 if (!thr
->stop_requested
)
3959 target_stop (thr
->ptid
);
3960 thr
->stop_requested
= true;
3964 thr
->resumed
= false;
3968 while (displaced_step_in_progress (inf
))
3970 wait_one_event event
;
3972 event
.target
= inf
->process_target ();
3973 event
.ptid
= do_target_wait_1 (inf
, pid_ptid
, &event
.ws
, 0);
3976 print_target_wait_results (pid_ptid
, event
.ptid
, &event
.ws
);
3981 /* It's OK to leave some of the threads of INF stopped, since
3982 they'll be detached shortly. */
3986 /* Wait for control to return from inferior to debugger.
3988 If inferior gets a signal, we may decide to start it up again
3989 instead of returning. That is why there is a loop in this function.
3990 When this function actually returns it means the inferior
3991 should be left stopped and GDB should read more commands. */
3994 wait_for_inferior (inferior
*inf
)
3996 infrun_debug_printf ("wait_for_inferior ()");
3998 SCOPE_EXIT
{ delete_just_stopped_threads_infrun_breakpoints (); };
4000 /* If an error happens while handling the event, propagate GDB's
4001 knowledge of the executing state to the frontend/user running
4003 scoped_finish_thread_state finish_state
4004 (inf
->process_target (), minus_one_ptid
);
4008 struct execution_control_state ecss
;
4009 struct execution_control_state
*ecs
= &ecss
;
4011 memset (ecs
, 0, sizeof (*ecs
));
4013 overlay_cache_invalid
= 1;
4015 /* Flush target cache before starting to handle each event.
4016 Target was running and cache could be stale. This is just a
4017 heuristic. Running threads may modify target memory, but we
4018 don't get any event. */
4019 target_dcache_invalidate ();
4021 ecs
->ptid
= do_target_wait_1 (inf
, minus_one_ptid
, &ecs
->ws
, 0);
4022 ecs
->target
= inf
->process_target ();
4025 print_target_wait_results (minus_one_ptid
, ecs
->ptid
, &ecs
->ws
);
4027 /* Now figure out what to do with the result of the result. */
4028 handle_inferior_event (ecs
);
4030 if (!ecs
->wait_some_more
)
4034 /* No error, don't finish the state yet. */
4035 finish_state
.release ();
4038 /* Cleanup that reinstalls the readline callback handler, if the
4039 target is running in the background. If while handling the target
4040 event something triggered a secondary prompt, like e.g., a
4041 pagination prompt, we'll have removed the callback handler (see
4042 gdb_readline_wrapper_line). Need to do this as we go back to the
4043 event loop, ready to process further input. Note this has no
4044 effect if the handler hasn't actually been removed, because calling
4045 rl_callback_handler_install resets the line buffer, thus losing
4049 reinstall_readline_callback_handler_cleanup ()
4051 struct ui
*ui
= current_ui
;
4055 /* We're not going back to the top level event loop yet. Don't
4056 install the readline callback, as it'd prep the terminal,
4057 readline-style (raw, noecho) (e.g., --batch). We'll install
4058 it the next time the prompt is displayed, when we're ready
4063 if (ui
->command_editing
&& ui
->prompt_state
!= PROMPT_BLOCKED
)
4064 gdb_rl_callback_handler_reinstall ();
4067 /* Clean up the FSMs of threads that are now stopped. In non-stop,
4068 that's just the event thread. In all-stop, that's all threads. */
4071 clean_up_just_stopped_threads_fsms (struct execution_control_state
*ecs
)
4073 if (ecs
->event_thread
!= NULL
4074 && ecs
->event_thread
->thread_fsm
!= NULL
)
4075 ecs
->event_thread
->thread_fsm
->clean_up (ecs
->event_thread
);
4079 for (thread_info
*thr
: all_non_exited_threads ())
4081 if (thr
->thread_fsm
== NULL
)
4083 if (thr
== ecs
->event_thread
)
4086 switch_to_thread (thr
);
4087 thr
->thread_fsm
->clean_up (thr
);
4090 if (ecs
->event_thread
!= NULL
)
4091 switch_to_thread (ecs
->event_thread
);
4095 /* Helper for all_uis_check_sync_execution_done that works on the
4099 check_curr_ui_sync_execution_done (void)
4101 struct ui
*ui
= current_ui
;
4103 if (ui
->prompt_state
== PROMPT_NEEDED
4105 && !gdb_in_secondary_prompt_p (ui
))
4107 target_terminal::ours ();
4108 gdb::observers::sync_execution_done
.notify ();
4109 ui_register_input_event_handler (ui
);
4116 all_uis_check_sync_execution_done (void)
4118 SWITCH_THRU_ALL_UIS ()
4120 check_curr_ui_sync_execution_done ();
4127 all_uis_on_sync_execution_starting (void)
4129 SWITCH_THRU_ALL_UIS ()
4131 if (current_ui
->prompt_state
== PROMPT_NEEDED
)
4132 async_disable_stdin ();
4136 /* Asynchronous version of wait_for_inferior. It is called by the
4137 event loop whenever a change of state is detected on the file
4138 descriptor corresponding to the target. It can be called more than
4139 once to complete a single execution command. In such cases we need
4140 to keep the state in a global variable ECSS. If it is the last time
4141 that this function is called for a single execution command, then
4142 report to the user that the inferior has stopped, and do the
4143 necessary cleanups. */
4146 fetch_inferior_event ()
4148 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
4150 struct execution_control_state ecss
;
4151 struct execution_control_state
*ecs
= &ecss
;
4154 memset (ecs
, 0, sizeof (*ecs
));
4156 /* Events are always processed with the main UI as current UI. This
4157 way, warnings, debug output, etc. are always consistently sent to
4158 the main console. */
4159 scoped_restore save_ui
= make_scoped_restore (¤t_ui
, main_ui
);
4161 /* Temporarily disable pagination. Otherwise, the user would be
4162 given an option to press 'q' to quit, which would cause an early
4163 exit and could leave GDB in a half-baked state. */
4164 scoped_restore save_pagination
4165 = make_scoped_restore (&pagination_enabled
, false);
4167 /* End up with readline processing input, if necessary. */
4169 SCOPE_EXIT
{ reinstall_readline_callback_handler_cleanup (); };
4171 /* We're handling a live event, so make sure we're doing live
4172 debugging. If we're looking at traceframes while the target is
4173 running, we're going to need to get back to that mode after
4174 handling the event. */
4175 gdb::optional
<scoped_restore_current_traceframe
> maybe_restore_traceframe
;
4178 maybe_restore_traceframe
.emplace ();
4179 set_current_traceframe (-1);
4182 /* The user/frontend should not notice a thread switch due to
4183 internal events. Make sure we revert to the user selected
4184 thread and frame after handling the event and running any
4185 breakpoint commands. */
4186 scoped_restore_current_thread restore_thread
;
4188 overlay_cache_invalid
= 1;
4189 /* Flush target cache before starting to handle each event. Target
4190 was running and cache could be stale. This is just a heuristic.
4191 Running threads may modify target memory, but we don't get any
4193 target_dcache_invalidate ();
4195 scoped_restore save_exec_dir
4196 = make_scoped_restore (&execution_direction
,
4197 target_execution_direction ());
4199 /* Allow targets to pause their resumed threads while we handle
4201 scoped_disable_commit_resumed
disable_commit_resumed ("handling event");
4203 if (!do_target_wait (ecs
, TARGET_WNOHANG
))
4205 infrun_debug_printf ("do_target_wait returned no event");
4206 disable_commit_resumed
.reset_and_commit ();
4210 gdb_assert (ecs
->ws
.kind
!= TARGET_WAITKIND_IGNORE
);
4212 /* Switch to the target that generated the event, so we can do
4214 switch_to_target_no_thread (ecs
->target
);
4217 print_target_wait_results (minus_one_ptid
, ecs
->ptid
, &ecs
->ws
);
4219 /* If an error happens while handling the event, propagate GDB's
4220 knowledge of the executing state to the frontend/user running
4222 ptid_t finish_ptid
= !target_is_non_stop_p () ? minus_one_ptid
: ecs
->ptid
;
4223 scoped_finish_thread_state
finish_state (ecs
->target
, finish_ptid
);
4225 /* Get executed before scoped_restore_current_thread above to apply
4226 still for the thread which has thrown the exception. */
4227 auto defer_bpstat_clear
4228 = make_scope_exit (bpstat_clear_actions
);
4229 auto defer_delete_threads
4230 = make_scope_exit (delete_just_stopped_threads_infrun_breakpoints
);
4232 /* Now figure out what to do with the result of the result. */
4233 handle_inferior_event (ecs
);
4235 if (!ecs
->wait_some_more
)
4237 struct inferior
*inf
= find_inferior_ptid (ecs
->target
, ecs
->ptid
);
4238 bool should_stop
= true;
4239 struct thread_info
*thr
= ecs
->event_thread
;
4241 delete_just_stopped_threads_infrun_breakpoints ();
4245 struct thread_fsm
*thread_fsm
= thr
->thread_fsm
;
4247 if (thread_fsm
!= NULL
)
4248 should_stop
= thread_fsm
->should_stop (thr
);
4257 bool should_notify_stop
= true;
4260 clean_up_just_stopped_threads_fsms (ecs
);
4262 if (thr
!= NULL
&& thr
->thread_fsm
!= NULL
)
4263 should_notify_stop
= thr
->thread_fsm
->should_notify_stop ();
4265 if (should_notify_stop
)
4267 /* We may not find an inferior if this was a process exit. */
4268 if (inf
== NULL
|| inf
->control
.stop_soon
== NO_STOP_QUIETLY
)
4269 proceeded
= normal_stop ();
4274 inferior_event_handler (INF_EXEC_COMPLETE
);
4278 /* If we got a TARGET_WAITKIND_NO_RESUMED event, then the
4279 previously selected thread is gone. We have two
4280 choices - switch to no thread selected, or restore the
4281 previously selected thread (now exited). We chose the
4282 later, just because that's what GDB used to do. After
4283 this, "info threads" says "The current thread <Thread
4284 ID 2> has terminated." instead of "No thread
4288 && ecs
->ws
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
4289 restore_thread
.dont_restore ();
4293 defer_delete_threads
.release ();
4294 defer_bpstat_clear
.release ();
4296 /* No error, don't finish the thread states yet. */
4297 finish_state
.release ();
4299 disable_commit_resumed
.reset_and_commit ();
4301 /* This scope is used to ensure that readline callbacks are
4302 reinstalled here. */
4305 /* If a UI was in sync execution mode, and now isn't, restore its
4306 prompt (a synchronous execution command has finished, and we're
4307 ready for input). */
4308 all_uis_check_sync_execution_done ();
4311 && exec_done_display_p
4312 && (inferior_ptid
== null_ptid
4313 || inferior_thread ()->state
!= THREAD_RUNNING
))
4314 printf_unfiltered (_("completed.\n"));
4320 set_step_info (thread_info
*tp
, struct frame_info
*frame
,
4321 struct symtab_and_line sal
)
4323 /* This can be removed once this function no longer implicitly relies on the
4324 inferior_ptid value. */
4325 gdb_assert (inferior_ptid
== tp
->ptid
);
4327 tp
->control
.step_frame_id
= get_frame_id (frame
);
4328 tp
->control
.step_stack_frame_id
= get_stack_frame_id (frame
);
4330 tp
->current_symtab
= sal
.symtab
;
4331 tp
->current_line
= sal
.line
;
4334 /* Clear context switchable stepping state. */
4337 init_thread_stepping_state (struct thread_info
*tss
)
4339 tss
->stepped_breakpoint
= 0;
4340 tss
->stepping_over_breakpoint
= 0;
4341 tss
->stepping_over_watchpoint
= 0;
4342 tss
->step_after_step_resume_breakpoint
= 0;
4348 set_last_target_status (process_stratum_target
*target
, ptid_t ptid
,
4349 target_waitstatus status
)
4351 target_last_proc_target
= target
;
4352 target_last_wait_ptid
= ptid
;
4353 target_last_waitstatus
= status
;
4359 get_last_target_status (process_stratum_target
**target
, ptid_t
*ptid
,
4360 target_waitstatus
*status
)
4362 if (target
!= nullptr)
4363 *target
= target_last_proc_target
;
4364 if (ptid
!= nullptr)
4365 *ptid
= target_last_wait_ptid
;
4366 if (status
!= nullptr)
4367 *status
= target_last_waitstatus
;
4373 nullify_last_target_wait_ptid (void)
4375 target_last_proc_target
= nullptr;
4376 target_last_wait_ptid
= minus_one_ptid
;
4377 target_last_waitstatus
= {};
4380 /* Switch thread contexts. */
4383 context_switch (execution_control_state
*ecs
)
4385 if (ecs
->ptid
!= inferior_ptid
4386 && (inferior_ptid
== null_ptid
4387 || ecs
->event_thread
!= inferior_thread ()))
4389 infrun_debug_printf ("Switching context from %s to %s",
4390 target_pid_to_str (inferior_ptid
).c_str (),
4391 target_pid_to_str (ecs
->ptid
).c_str ());
4394 switch_to_thread (ecs
->event_thread
);
4397 /* If the target can't tell whether we've hit breakpoints
4398 (target_supports_stopped_by_sw_breakpoint), and we got a SIGTRAP,
4399 check whether that could have been caused by a breakpoint. If so,
4400 adjust the PC, per gdbarch_decr_pc_after_break. */
4403 adjust_pc_after_break (struct thread_info
*thread
,
4404 struct target_waitstatus
*ws
)
4406 struct regcache
*regcache
;
4407 struct gdbarch
*gdbarch
;
4408 CORE_ADDR breakpoint_pc
, decr_pc
;
4410 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
4411 we aren't, just return.
4413 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
4414 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
4415 implemented by software breakpoints should be handled through the normal
4418 NOTE drow/2004-01-31: On some targets, breakpoints may generate
4419 different signals (SIGILL or SIGEMT for instance), but it is less
4420 clear where the PC is pointing afterwards. It may not match
4421 gdbarch_decr_pc_after_break. I don't know any specific target that
4422 generates these signals at breakpoints (the code has been in GDB since at
4423 least 1992) so I can not guess how to handle them here.
4425 In earlier versions of GDB, a target with
4426 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
4427 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
4428 target with both of these set in GDB history, and it seems unlikely to be
4429 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
4431 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
)
4434 if (ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
4437 /* In reverse execution, when a breakpoint is hit, the instruction
4438 under it has already been de-executed. The reported PC always
4439 points at the breakpoint address, so adjusting it further would
4440 be wrong. E.g., consider this case on a decr_pc_after_break == 1
4443 B1 0x08000000 : INSN1
4444 B2 0x08000001 : INSN2
4446 PC -> 0x08000003 : INSN4
4448 Say you're stopped at 0x08000003 as above. Reverse continuing
4449 from that point should hit B2 as below. Reading the PC when the
4450 SIGTRAP is reported should read 0x08000001 and INSN2 should have
4451 been de-executed already.
4453 B1 0x08000000 : INSN1
4454 B2 PC -> 0x08000001 : INSN2
4458 We can't apply the same logic as for forward execution, because
4459 we would wrongly adjust the PC to 0x08000000, since there's a
4460 breakpoint at PC - 1. We'd then report a hit on B1, although
4461 INSN1 hadn't been de-executed yet. Doing nothing is the correct
4463 if (execution_direction
== EXEC_REVERSE
)
4466 /* If the target can tell whether the thread hit a SW breakpoint,
4467 trust it. Targets that can tell also adjust the PC
4469 if (target_supports_stopped_by_sw_breakpoint ())
4472 /* Note that relying on whether a breakpoint is planted in memory to
4473 determine this can fail. E.g,. the breakpoint could have been
4474 removed since. Or the thread could have been told to step an
4475 instruction the size of a breakpoint instruction, and only
4476 _after_ was a breakpoint inserted at its address. */
4478 /* If this target does not decrement the PC after breakpoints, then
4479 we have nothing to do. */
4480 regcache
= get_thread_regcache (thread
);
4481 gdbarch
= regcache
->arch ();
4483 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
4487 const address_space
*aspace
= regcache
->aspace ();
4489 /* Find the location where (if we've hit a breakpoint) the
4490 breakpoint would be. */
4491 breakpoint_pc
= regcache_read_pc (regcache
) - decr_pc
;
4493 /* If the target can't tell whether a software breakpoint triggered,
4494 fallback to figuring it out based on breakpoints we think were
4495 inserted in the target, and on whether the thread was stepped or
4498 /* Check whether there actually is a software breakpoint inserted at
4501 If in non-stop mode, a race condition is possible where we've
4502 removed a breakpoint, but stop events for that breakpoint were
4503 already queued and arrive later. To suppress those spurious
4504 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
4505 and retire them after a number of stop events are reported. Note
4506 this is an heuristic and can thus get confused. The real fix is
4507 to get the "stopped by SW BP and needs adjustment" info out of
4508 the target/kernel (and thus never reach here; see above). */
4509 if (software_breakpoint_inserted_here_p (aspace
, breakpoint_pc
)
4510 || (target_is_non_stop_p ()
4511 && moribund_breakpoint_here_p (aspace
, breakpoint_pc
)))
4513 gdb::optional
<scoped_restore_tmpl
<int>> restore_operation_disable
;
4515 if (record_full_is_used ())
4516 restore_operation_disable
.emplace
4517 (record_full_gdb_operation_disable_set ());
4519 /* When using hardware single-step, a SIGTRAP is reported for both
4520 a completed single-step and a software breakpoint. Need to
4521 differentiate between the two, as the latter needs adjusting
4522 but the former does not.
4524 The SIGTRAP can be due to a completed hardware single-step only if
4525 - we didn't insert software single-step breakpoints
4526 - this thread is currently being stepped
4528 If any of these events did not occur, we must have stopped due
4529 to hitting a software breakpoint, and have to back up to the
4532 As a special case, we could have hardware single-stepped a
4533 software breakpoint. In this case (prev_pc == breakpoint_pc),
4534 we also need to back up to the breakpoint address. */
4536 if (thread_has_single_step_breakpoints_set (thread
)
4537 || !currently_stepping (thread
)
4538 || (thread
->stepped_breakpoint
4539 && thread
->prev_pc
== breakpoint_pc
))
4540 regcache_write_pc (regcache
, breakpoint_pc
);
4545 stepped_in_from (struct frame_info
*frame
, struct frame_id step_frame_id
)
4547 for (frame
= get_prev_frame (frame
);
4549 frame
= get_prev_frame (frame
))
4551 if (frame_id_eq (get_frame_id (frame
), step_frame_id
))
4554 if (get_frame_type (frame
) != INLINE_FRAME
)
4561 /* Look for an inline frame that is marked for skip.
4562 If PREV_FRAME is TRUE start at the previous frame,
4563 otherwise start at the current frame. Stop at the
4564 first non-inline frame, or at the frame where the
4568 inline_frame_is_marked_for_skip (bool prev_frame
, struct thread_info
*tp
)
4570 struct frame_info
*frame
= get_current_frame ();
4573 frame
= get_prev_frame (frame
);
4575 for (; frame
!= NULL
; frame
= get_prev_frame (frame
))
4577 const char *fn
= NULL
;
4578 symtab_and_line sal
;
4581 if (frame_id_eq (get_frame_id (frame
), tp
->control
.step_frame_id
))
4583 if (get_frame_type (frame
) != INLINE_FRAME
)
4586 sal
= find_frame_sal (frame
);
4587 sym
= get_frame_function (frame
);
4590 fn
= sym
->print_name ();
4593 && function_name_is_marked_for_skip (fn
, sal
))
4600 /* If the event thread has the stop requested flag set, pretend it
4601 stopped for a GDB_SIGNAL_0 (i.e., as if it stopped due to
4605 handle_stop_requested (struct execution_control_state
*ecs
)
4607 if (ecs
->event_thread
->stop_requested
)
4609 ecs
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
4610 ecs
->ws
.value
.sig
= GDB_SIGNAL_0
;
4611 handle_signal_stop (ecs
);
4617 /* Auxiliary function that handles syscall entry/return events.
4618 It returns true if the inferior should keep going (and GDB
4619 should ignore the event), or false if the event deserves to be
4623 handle_syscall_event (struct execution_control_state
*ecs
)
4625 struct regcache
*regcache
;
4628 context_switch (ecs
);
4630 regcache
= get_thread_regcache (ecs
->event_thread
);
4631 syscall_number
= ecs
->ws
.value
.syscall_number
;
4632 ecs
->event_thread
->suspend
.stop_pc
= regcache_read_pc (regcache
);
4634 if (catch_syscall_enabled () > 0
4635 && catching_syscall_number (syscall_number
) > 0)
4637 infrun_debug_printf ("syscall number=%d", syscall_number
);
4639 ecs
->event_thread
->control
.stop_bpstat
4640 = bpstat_stop_status (regcache
->aspace (),
4641 ecs
->event_thread
->suspend
.stop_pc
,
4642 ecs
->event_thread
, &ecs
->ws
);
4644 if (handle_stop_requested (ecs
))
4647 if (bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
4649 /* Catchpoint hit. */
4654 if (handle_stop_requested (ecs
))
4657 /* If no catchpoint triggered for this, then keep going. */
4663 /* Lazily fill in the execution_control_state's stop_func_* fields. */
4666 fill_in_stop_func (struct gdbarch
*gdbarch
,
4667 struct execution_control_state
*ecs
)
4669 if (!ecs
->stop_func_filled_in
)
4672 const general_symbol_info
*gsi
;
4674 /* Don't care about return value; stop_func_start and stop_func_name
4675 will both be 0 if it doesn't work. */
4676 find_pc_partial_function_sym (ecs
->event_thread
->suspend
.stop_pc
,
4678 &ecs
->stop_func_start
,
4679 &ecs
->stop_func_end
,
4681 ecs
->stop_func_name
= gsi
== nullptr ? nullptr : gsi
->print_name ();
4683 /* The call to find_pc_partial_function, above, will set
4684 stop_func_start and stop_func_end to the start and end
4685 of the range containing the stop pc. If this range
4686 contains the entry pc for the block (which is always the
4687 case for contiguous blocks), advance stop_func_start past
4688 the function's start offset and entrypoint. Note that
4689 stop_func_start is NOT advanced when in a range of a
4690 non-contiguous block that does not contain the entry pc. */
4691 if (block
!= nullptr
4692 && ecs
->stop_func_start
<= BLOCK_ENTRY_PC (block
)
4693 && BLOCK_ENTRY_PC (block
) < ecs
->stop_func_end
)
4695 ecs
->stop_func_start
4696 += gdbarch_deprecated_function_start_offset (gdbarch
);
4698 if (gdbarch_skip_entrypoint_p (gdbarch
))
4699 ecs
->stop_func_start
4700 = gdbarch_skip_entrypoint (gdbarch
, ecs
->stop_func_start
);
4703 ecs
->stop_func_filled_in
= 1;
4708 /* Return the STOP_SOON field of the inferior pointed at by ECS. */
4710 static enum stop_kind
4711 get_inferior_stop_soon (execution_control_state
*ecs
)
4713 struct inferior
*inf
= find_inferior_ptid (ecs
->target
, ecs
->ptid
);
4715 gdb_assert (inf
!= NULL
);
4716 return inf
->control
.stop_soon
;
4719 /* Poll for one event out of the current target. Store the resulting
4720 waitstatus in WS, and return the event ptid. Does not block. */
4723 poll_one_curr_target (struct target_waitstatus
*ws
)
4727 overlay_cache_invalid
= 1;
4729 /* Flush target cache before starting to handle each event.
4730 Target was running and cache could be stale. This is just a
4731 heuristic. Running threads may modify target memory, but we
4732 don't get any event. */
4733 target_dcache_invalidate ();
4735 if (deprecated_target_wait_hook
)
4736 event_ptid
= deprecated_target_wait_hook (minus_one_ptid
, ws
, TARGET_WNOHANG
);
4738 event_ptid
= target_wait (minus_one_ptid
, ws
, TARGET_WNOHANG
);
4741 print_target_wait_results (minus_one_ptid
, event_ptid
, ws
);
4746 /* Wait for one event out of any target. */
4748 static wait_one_event
4753 for (inferior
*inf
: all_inferiors ())
4755 process_stratum_target
*target
= inf
->process_target ();
4757 || !target
->is_async_p ()
4758 || !target
->threads_executing
)
4761 switch_to_inferior_no_thread (inf
);
4763 wait_one_event event
;
4764 event
.target
= target
;
4765 event
.ptid
= poll_one_curr_target (&event
.ws
);
4767 if (event
.ws
.kind
== TARGET_WAITKIND_NO_RESUMED
)
4769 /* If nothing is resumed, remove the target from the
4773 else if (event
.ws
.kind
!= TARGET_WAITKIND_IGNORE
)
4777 /* Block waiting for some event. */
4784 for (inferior
*inf
: all_inferiors ())
4786 process_stratum_target
*target
= inf
->process_target ();
4788 || !target
->is_async_p ()
4789 || !target
->threads_executing
)
4792 int fd
= target
->async_wait_fd ();
4793 FD_SET (fd
, &readfds
);
4800 /* No waitable targets left. All must be stopped. */
4801 return {NULL
, minus_one_ptid
, {TARGET_WAITKIND_NO_RESUMED
}};
4806 int numfds
= interruptible_select (nfds
, &readfds
, 0, NULL
, 0);
4812 perror_with_name ("interruptible_select");
4817 /* Save the thread's event and stop reason to process it later. */
4820 save_waitstatus (struct thread_info
*tp
, const target_waitstatus
*ws
)
4822 infrun_debug_printf ("saving status %s for %d.%ld.%ld",
4823 target_waitstatus_to_string (ws
).c_str (),
4828 /* Record for later. */
4829 tp
->suspend
.waitstatus
= *ws
;
4830 tp
->suspend
.waitstatus_pending_p
= 1;
4832 if (ws
->kind
== TARGET_WAITKIND_STOPPED
4833 && ws
->value
.sig
== GDB_SIGNAL_TRAP
)
4835 struct regcache
*regcache
= get_thread_regcache (tp
);
4836 const address_space
*aspace
= regcache
->aspace ();
4837 CORE_ADDR pc
= regcache_read_pc (regcache
);
4839 adjust_pc_after_break (tp
, &tp
->suspend
.waitstatus
);
4841 scoped_restore_current_thread restore_thread
;
4842 switch_to_thread (tp
);
4844 if (target_stopped_by_watchpoint ())
4846 tp
->suspend
.stop_reason
4847 = TARGET_STOPPED_BY_WATCHPOINT
;
4849 else if (target_supports_stopped_by_sw_breakpoint ()
4850 && target_stopped_by_sw_breakpoint ())
4852 tp
->suspend
.stop_reason
4853 = TARGET_STOPPED_BY_SW_BREAKPOINT
;
4855 else if (target_supports_stopped_by_hw_breakpoint ()
4856 && target_stopped_by_hw_breakpoint ())
4858 tp
->suspend
.stop_reason
4859 = TARGET_STOPPED_BY_HW_BREAKPOINT
;
4861 else if (!target_supports_stopped_by_hw_breakpoint ()
4862 && hardware_breakpoint_inserted_here_p (aspace
,
4865 tp
->suspend
.stop_reason
4866 = TARGET_STOPPED_BY_HW_BREAKPOINT
;
4868 else if (!target_supports_stopped_by_sw_breakpoint ()
4869 && software_breakpoint_inserted_here_p (aspace
,
4872 tp
->suspend
.stop_reason
4873 = TARGET_STOPPED_BY_SW_BREAKPOINT
;
4875 else if (!thread_has_single_step_breakpoints_set (tp
)
4876 && currently_stepping (tp
))
4878 tp
->suspend
.stop_reason
4879 = TARGET_STOPPED_BY_SINGLE_STEP
;
4884 /* Mark the non-executing threads accordingly. In all-stop, all
4885 threads of all processes are stopped when we get any event
4886 reported. In non-stop mode, only the event thread stops. */
4889 mark_non_executing_threads (process_stratum_target
*target
,
4891 struct target_waitstatus ws
)
4895 if (!target_is_non_stop_p ())
4896 mark_ptid
= minus_one_ptid
;
4897 else if (ws
.kind
== TARGET_WAITKIND_SIGNALLED
4898 || ws
.kind
== TARGET_WAITKIND_EXITED
)
4900 /* If we're handling a process exit in non-stop mode, even
4901 though threads haven't been deleted yet, one would think
4902 that there is nothing to do, as threads of the dead process
4903 will be soon deleted, and threads of any other process were
4904 left running. However, on some targets, threads survive a
4905 process exit event. E.g., for the "checkpoint" command,
4906 when the current checkpoint/fork exits, linux-fork.c
4907 automatically switches to another fork from within
4908 target_mourn_inferior, by associating the same
4909 inferior/thread to another fork. We haven't mourned yet at
4910 this point, but we must mark any threads left in the
4911 process as not-executing so that finish_thread_state marks
4912 them stopped (in the user's perspective) if/when we present
4913 the stop to the user. */
4914 mark_ptid
= ptid_t (event_ptid
.pid ());
4917 mark_ptid
= event_ptid
;
4919 set_executing (target
, mark_ptid
, false);
4921 /* Likewise the resumed flag. */
4922 set_resumed (target
, mark_ptid
, false);
4925 /* Handle one event after stopping threads. If the eventing thread
4926 reports back any interesting event, we leave it pending. If the
4927 eventing thread was in the middle of a displaced step, we
4928 cancel/finish it, and unless the thread's inferior is being
4929 detached, put the thread back in the step-over chain. Returns true
4930 if there are no resumed threads left in the target (thus there's no
4931 point in waiting further), false otherwise. */
4934 handle_one (const wait_one_event
&event
)
4937 ("%s %s", target_waitstatus_to_string (&event
.ws
).c_str (),
4938 target_pid_to_str (event
.ptid
).c_str ());
4940 if (event
.ws
.kind
== TARGET_WAITKIND_NO_RESUMED
)
4942 /* All resumed threads exited. */
4945 else if (event
.ws
.kind
== TARGET_WAITKIND_THREAD_EXITED
4946 || event
.ws
.kind
== TARGET_WAITKIND_EXITED
4947 || event
.ws
.kind
== TARGET_WAITKIND_SIGNALLED
)
4949 /* One thread/process exited/signalled. */
4951 thread_info
*t
= nullptr;
4953 /* The target may have reported just a pid. If so, try
4954 the first non-exited thread. */
4955 if (event
.ptid
.is_pid ())
4957 int pid
= event
.ptid
.pid ();
4958 inferior
*inf
= find_inferior_pid (event
.target
, pid
);
4959 for (thread_info
*tp
: inf
->non_exited_threads ())
4965 /* If there is no available thread, the event would
4966 have to be appended to a per-inferior event list,
4967 which does not exist (and if it did, we'd have
4968 to adjust run control command to be able to
4969 resume such an inferior). We assert here instead
4970 of going into an infinite loop. */
4971 gdb_assert (t
!= nullptr);
4974 ("using %s", target_pid_to_str (t
->ptid
).c_str ());
4978 t
= find_thread_ptid (event
.target
, event
.ptid
);
4979 /* Check if this is the first time we see this thread.
4980 Don't bother adding if it individually exited. */
4982 && event
.ws
.kind
!= TARGET_WAITKIND_THREAD_EXITED
)
4983 t
= add_thread (event
.target
, event
.ptid
);
4988 /* Set the threads as non-executing to avoid
4989 another stop attempt on them. */
4990 switch_to_thread_no_regs (t
);
4991 mark_non_executing_threads (event
.target
, event
.ptid
,
4993 save_waitstatus (t
, &event
.ws
);
4994 t
->stop_requested
= false;
4999 thread_info
*t
= find_thread_ptid (event
.target
, event
.ptid
);
5001 t
= add_thread (event
.target
, event
.ptid
);
5003 t
->stop_requested
= 0;
5006 t
->control
.may_range_step
= 0;
5008 /* This may be the first time we see the inferior report
5010 inferior
*inf
= find_inferior_ptid (event
.target
, event
.ptid
);
5011 if (inf
->needs_setup
)
5013 switch_to_thread_no_regs (t
);
5017 if (event
.ws
.kind
== TARGET_WAITKIND_STOPPED
5018 && event
.ws
.value
.sig
== GDB_SIGNAL_0
)
5020 /* We caught the event that we intended to catch, so
5021 there's no event pending. */
5022 t
->suspend
.waitstatus
.kind
= TARGET_WAITKIND_IGNORE
;
5023 t
->suspend
.waitstatus_pending_p
= 0;
5025 if (displaced_step_finish (t
, GDB_SIGNAL_0
)
5026 == DISPLACED_STEP_FINISH_STATUS_NOT_EXECUTED
)
5028 /* Add it back to the step-over queue. */
5030 ("displaced-step of %s canceled",
5031 target_pid_to_str (t
->ptid
).c_str ());
5033 t
->control
.trap_expected
= 0;
5034 if (!t
->inf
->detaching
)
5035 global_thread_step_over_chain_enqueue (t
);
5040 enum gdb_signal sig
;
5041 struct regcache
*regcache
;
5044 ("target_wait %s, saving status for %d.%ld.%ld",
5045 target_waitstatus_to_string (&event
.ws
).c_str (),
5046 t
->ptid
.pid (), t
->ptid
.lwp (), t
->ptid
.tid ());
5048 /* Record for later. */
5049 save_waitstatus (t
, &event
.ws
);
5051 sig
= (event
.ws
.kind
== TARGET_WAITKIND_STOPPED
5052 ? event
.ws
.value
.sig
: GDB_SIGNAL_0
);
5054 if (displaced_step_finish (t
, sig
)
5055 == DISPLACED_STEP_FINISH_STATUS_NOT_EXECUTED
)
5057 /* Add it back to the step-over queue. */
5058 t
->control
.trap_expected
= 0;
5059 if (!t
->inf
->detaching
)
5060 global_thread_step_over_chain_enqueue (t
);
5063 regcache
= get_thread_regcache (t
);
5064 t
->suspend
.stop_pc
= regcache_read_pc (regcache
);
5066 infrun_debug_printf ("saved stop_pc=%s for %s "
5067 "(currently_stepping=%d)",
5068 paddress (target_gdbarch (),
5069 t
->suspend
.stop_pc
),
5070 target_pid_to_str (t
->ptid
).c_str (),
5071 currently_stepping (t
));
5081 stop_all_threads (const char *reason
, inferior
*inf
)
5083 /* We may need multiple passes to discover all threads. */
5087 gdb_assert (exists_non_stop_target ());
5089 INFRUN_SCOPED_DEBUG_START_END ("reason=%s, inf=%d", reason
,
5090 inf
!= nullptr ? inf
->num
: -1);
5092 scoped_restore_current_thread restore_thread
;
5094 /* Enable thread events on relevant targets. */
5095 for (auto *target
: all_non_exited_process_targets ())
5097 if (inf
!= nullptr && inf
->process_target () != target
)
5100 switch_to_target_no_thread (target
);
5101 target_thread_events (true);
5106 /* Disable thread events on relevant targets. */
5107 for (auto *target
: all_non_exited_process_targets ())
5109 if (inf
!= nullptr && inf
->process_target () != target
)
5112 switch_to_target_no_thread (target
);
5113 target_thread_events (false);
5116 /* Use debug_prefixed_printf directly to get a meaningful function
5119 debug_prefixed_printf ("infrun", "stop_all_threads", "done");
5122 /* Request threads to stop, and then wait for the stops. Because
5123 threads we already know about can spawn more threads while we're
5124 trying to stop them, and we only learn about new threads when we
5125 update the thread list, do this in a loop, and keep iterating
5126 until two passes find no threads that need to be stopped. */
5127 for (pass
= 0; pass
< 2; pass
++, iterations
++)
5129 infrun_debug_printf ("pass=%d, iterations=%d", pass
, iterations
);
5132 int waits_needed
= 0;
5134 for (auto *target
: all_non_exited_process_targets ())
5136 if (inf
!= nullptr && inf
->process_target () != target
)
5139 switch_to_target_no_thread (target
);
5140 update_thread_list ();
5143 /* Go through all threads looking for threads that we need
5144 to tell the target to stop. */
5145 for (thread_info
*t
: all_non_exited_threads ())
5147 if (inf
!= nullptr && t
->inf
!= inf
)
5150 /* For a single-target setting with an all-stop target,
5151 we would not even arrive here. For a multi-target
5152 setting, until GDB is able to handle a mixture of
5153 all-stop and non-stop targets, simply skip all-stop
5154 targets' threads. This should be fine due to the
5155 protection of 'check_multi_target_resumption'. */
5157 switch_to_thread_no_regs (t
);
5158 if (!target_is_non_stop_p ())
5163 /* If already stopping, don't request a stop again.
5164 We just haven't seen the notification yet. */
5165 if (!t
->stop_requested
)
5167 infrun_debug_printf (" %s executing, need stop",
5168 target_pid_to_str (t
->ptid
).c_str ());
5169 target_stop (t
->ptid
);
5170 t
->stop_requested
= 1;
5174 infrun_debug_printf (" %s executing, already stopping",
5175 target_pid_to_str (t
->ptid
).c_str ());
5178 if (t
->stop_requested
)
5183 infrun_debug_printf (" %s not executing",
5184 target_pid_to_str (t
->ptid
).c_str ());
5186 /* The thread may be not executing, but still be
5187 resumed with a pending status to process. */
5192 if (waits_needed
== 0)
5195 /* If we find new threads on the second iteration, restart
5196 over. We want to see two iterations in a row with all
5201 for (int i
= 0; i
< waits_needed
; i
++)
5203 wait_one_event event
= wait_one ();
5204 if (handle_one (event
))
5211 /* Handle a TARGET_WAITKIND_NO_RESUMED event. */
5214 handle_no_resumed (struct execution_control_state
*ecs
)
5216 if (target_can_async_p ())
5218 bool any_sync
= false;
5220 for (ui
*ui
: all_uis ())
5222 if (ui
->prompt_state
== PROMPT_BLOCKED
)
5230 /* There were no unwaited-for children left in the target, but,
5231 we're not synchronously waiting for events either. Just
5234 infrun_debug_printf ("TARGET_WAITKIND_NO_RESUMED (ignoring: bg)");
5235 prepare_to_wait (ecs
);
5240 /* Otherwise, if we were running a synchronous execution command, we
5241 may need to cancel it and give the user back the terminal.
5243 In non-stop mode, the target can't tell whether we've already
5244 consumed previous stop events, so it can end up sending us a
5245 no-resumed event like so:
5247 #0 - thread 1 is left stopped
5249 #1 - thread 2 is resumed and hits breakpoint
5250 -> TARGET_WAITKIND_STOPPED
5252 #2 - thread 3 is resumed and exits
5253 this is the last resumed thread, so
5254 -> TARGET_WAITKIND_NO_RESUMED
5256 #3 - gdb processes stop for thread 2 and decides to re-resume
5259 #4 - gdb processes the TARGET_WAITKIND_NO_RESUMED event.
5260 thread 2 is now resumed, so the event should be ignored.
5262 IOW, if the stop for thread 2 doesn't end a foreground command,
5263 then we need to ignore the following TARGET_WAITKIND_NO_RESUMED
5264 event. But it could be that the event meant that thread 2 itself
5265 (or whatever other thread was the last resumed thread) exited.
5267 To address this we refresh the thread list and check whether we
5268 have resumed threads _now_. In the example above, this removes
5269 thread 3 from the thread list. If thread 2 was re-resumed, we
5270 ignore this event. If we find no thread resumed, then we cancel
5271 the synchronous command and show "no unwaited-for " to the
5274 inferior
*curr_inf
= current_inferior ();
5276 scoped_restore_current_thread restore_thread
;
5278 for (auto *target
: all_non_exited_process_targets ())
5280 switch_to_target_no_thread (target
);
5281 update_thread_list ();
5286 - the current target has no thread executing, and
5287 - the current inferior is native, and
5288 - the current inferior is the one which has the terminal, and
5291 then a Ctrl-C from this point on would remain stuck in the
5292 kernel, until a thread resumes and dequeues it. That would
5293 result in the GDB CLI not reacting to Ctrl-C, not able to
5294 interrupt the program. To address this, if the current inferior
5295 no longer has any thread executing, we give the terminal to some
5296 other inferior that has at least one thread executing. */
5297 bool swap_terminal
= true;
5299 /* Whether to ignore this TARGET_WAITKIND_NO_RESUMED event, or
5300 whether to report it to the user. */
5301 bool ignore_event
= false;
5303 for (thread_info
*thread
: all_non_exited_threads ())
5305 if (swap_terminal
&& thread
->executing
)
5307 if (thread
->inf
!= curr_inf
)
5309 target_terminal::ours ();
5311 switch_to_thread (thread
);
5312 target_terminal::inferior ();
5314 swap_terminal
= false;
5318 && (thread
->executing
5319 || thread
->suspend
.waitstatus_pending_p
))
5321 /* Either there were no unwaited-for children left in the
5322 target at some point, but there are now, or some target
5323 other than the eventing one has unwaited-for children
5324 left. Just ignore. */
5325 infrun_debug_printf ("TARGET_WAITKIND_NO_RESUMED "
5326 "(ignoring: found resumed)");
5328 ignore_event
= true;
5331 if (ignore_event
&& !swap_terminal
)
5337 switch_to_inferior_no_thread (curr_inf
);
5338 prepare_to_wait (ecs
);
5342 /* Go ahead and report the event. */
5346 /* Given an execution control state that has been freshly filled in by
5347 an event from the inferior, figure out what it means and take
5350 The alternatives are:
5352 1) stop_waiting and return; to really stop and return to the
5355 2) keep_going and return; to wait for the next event (set
5356 ecs->event_thread->stepping_over_breakpoint to 1 to single step
5360 handle_inferior_event (struct execution_control_state
*ecs
)
5362 /* Make sure that all temporary struct value objects that were
5363 created during the handling of the event get deleted at the
5365 scoped_value_mark free_values
;
5367 infrun_debug_printf ("%s", target_waitstatus_to_string (&ecs
->ws
).c_str ());
5369 if (ecs
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
5371 /* We had an event in the inferior, but we are not interested in
5372 handling it at this level. The lower layers have already
5373 done what needs to be done, if anything.
5375 One of the possible circumstances for this is when the
5376 inferior produces output for the console. The inferior has
5377 not stopped, and we are ignoring the event. Another possible
5378 circumstance is any event which the lower level knows will be
5379 reported multiple times without an intervening resume. */
5380 prepare_to_wait (ecs
);
5384 if (ecs
->ws
.kind
== TARGET_WAITKIND_THREAD_EXITED
)
5386 prepare_to_wait (ecs
);
5390 if (ecs
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
5391 && handle_no_resumed (ecs
))
5394 /* Cache the last target/ptid/waitstatus. */
5395 set_last_target_status (ecs
->target
, ecs
->ptid
, ecs
->ws
);
5397 /* Always clear state belonging to the previous time we stopped. */
5398 stop_stack_dummy
= STOP_NONE
;
5400 if (ecs
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
)
5402 /* No unwaited-for children left. IOW, all resumed children
5404 stop_print_frame
= false;
5409 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
5410 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
)
5412 ecs
->event_thread
= find_thread_ptid (ecs
->target
, ecs
->ptid
);
5413 /* If it's a new thread, add it to the thread database. */
5414 if (ecs
->event_thread
== NULL
)
5415 ecs
->event_thread
= add_thread (ecs
->target
, ecs
->ptid
);
5417 /* Disable range stepping. If the next step request could use a
5418 range, this will be end up re-enabled then. */
5419 ecs
->event_thread
->control
.may_range_step
= 0;
5422 /* Dependent on valid ECS->EVENT_THREAD. */
5423 adjust_pc_after_break (ecs
->event_thread
, &ecs
->ws
);
5425 /* Dependent on the current PC value modified by adjust_pc_after_break. */
5426 reinit_frame_cache ();
5428 breakpoint_retire_moribund ();
5430 /* First, distinguish signals caused by the debugger from signals
5431 that have to do with the program's own actions. Note that
5432 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
5433 on the operating system version. Here we detect when a SIGILL or
5434 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
5435 something similar for SIGSEGV, since a SIGSEGV will be generated
5436 when we're trying to execute a breakpoint instruction on a
5437 non-executable stack. This happens for call dummy breakpoints
5438 for architectures like SPARC that place call dummies on the
5440 if (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
5441 && (ecs
->ws
.value
.sig
== GDB_SIGNAL_ILL
5442 || ecs
->ws
.value
.sig
== GDB_SIGNAL_SEGV
5443 || ecs
->ws
.value
.sig
== GDB_SIGNAL_EMT
))
5445 struct regcache
*regcache
= get_thread_regcache (ecs
->event_thread
);
5447 if (breakpoint_inserted_here_p (regcache
->aspace (),
5448 regcache_read_pc (regcache
)))
5450 infrun_debug_printf ("Treating signal as SIGTRAP");
5451 ecs
->ws
.value
.sig
= GDB_SIGNAL_TRAP
;
5455 mark_non_executing_threads (ecs
->target
, ecs
->ptid
, ecs
->ws
);
5457 switch (ecs
->ws
.kind
)
5459 case TARGET_WAITKIND_LOADED
:
5461 context_switch (ecs
);
5462 /* Ignore gracefully during startup of the inferior, as it might
5463 be the shell which has just loaded some objects, otherwise
5464 add the symbols for the newly loaded objects. Also ignore at
5465 the beginning of an attach or remote session; we will query
5466 the full list of libraries once the connection is
5469 stop_kind stop_soon
= get_inferior_stop_soon (ecs
);
5470 if (stop_soon
== NO_STOP_QUIETLY
)
5472 struct regcache
*regcache
;
5474 regcache
= get_thread_regcache (ecs
->event_thread
);
5476 handle_solib_event ();
5478 ecs
->event_thread
->control
.stop_bpstat
5479 = bpstat_stop_status (regcache
->aspace (),
5480 ecs
->event_thread
->suspend
.stop_pc
,
5481 ecs
->event_thread
, &ecs
->ws
);
5483 if (handle_stop_requested (ecs
))
5486 if (bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
5488 /* A catchpoint triggered. */
5489 process_event_stop_test (ecs
);
5493 /* If requested, stop when the dynamic linker notifies
5494 gdb of events. This allows the user to get control
5495 and place breakpoints in initializer routines for
5496 dynamically loaded objects (among other things). */
5497 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5498 if (stop_on_solib_events
)
5500 /* Make sure we print "Stopped due to solib-event" in
5502 stop_print_frame
= true;
5509 /* If we are skipping through a shell, or through shared library
5510 loading that we aren't interested in, resume the program. If
5511 we're running the program normally, also resume. */
5512 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== NO_STOP_QUIETLY
)
5514 /* Loading of shared libraries might have changed breakpoint
5515 addresses. Make sure new breakpoints are inserted. */
5516 if (stop_soon
== NO_STOP_QUIETLY
)
5517 insert_breakpoints ();
5518 resume (GDB_SIGNAL_0
);
5519 prepare_to_wait (ecs
);
5523 /* But stop if we're attaching or setting up a remote
5525 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
5526 || stop_soon
== STOP_QUIETLY_REMOTE
)
5528 infrun_debug_printf ("quietly stopped");
5533 internal_error (__FILE__
, __LINE__
,
5534 _("unhandled stop_soon: %d"), (int) stop_soon
);
5537 case TARGET_WAITKIND_SPURIOUS
:
5538 if (handle_stop_requested (ecs
))
5540 context_switch (ecs
);
5541 resume (GDB_SIGNAL_0
);
5542 prepare_to_wait (ecs
);
5545 case TARGET_WAITKIND_THREAD_CREATED
:
5546 if (handle_stop_requested (ecs
))
5548 context_switch (ecs
);
5549 if (!switch_back_to_stepped_thread (ecs
))
5553 case TARGET_WAITKIND_EXITED
:
5554 case TARGET_WAITKIND_SIGNALLED
:
5556 /* Depending on the system, ecs->ptid may point to a thread or
5557 to a process. On some targets, target_mourn_inferior may
5558 need to have access to the just-exited thread. That is the
5559 case of GNU/Linux's "checkpoint" support, for example.
5560 Call the switch_to_xxx routine as appropriate. */
5561 thread_info
*thr
= find_thread_ptid (ecs
->target
, ecs
->ptid
);
5563 switch_to_thread (thr
);
5566 inferior
*inf
= find_inferior_ptid (ecs
->target
, ecs
->ptid
);
5567 switch_to_inferior_no_thread (inf
);
5570 handle_vfork_child_exec_or_exit (0);
5571 target_terminal::ours (); /* Must do this before mourn anyway. */
5573 /* Clearing any previous state of convenience variables. */
5574 clear_exit_convenience_vars ();
5576 if (ecs
->ws
.kind
== TARGET_WAITKIND_EXITED
)
5578 /* Record the exit code in the convenience variable $_exitcode, so
5579 that the user can inspect this again later. */
5580 set_internalvar_integer (lookup_internalvar ("_exitcode"),
5581 (LONGEST
) ecs
->ws
.value
.integer
);
5583 /* Also record this in the inferior itself. */
5584 current_inferior ()->has_exit_code
= 1;
5585 current_inferior ()->exit_code
= (LONGEST
) ecs
->ws
.value
.integer
;
5587 /* Support the --return-child-result option. */
5588 return_child_result_value
= ecs
->ws
.value
.integer
;
5590 gdb::observers::exited
.notify (ecs
->ws
.value
.integer
);
5594 struct gdbarch
*gdbarch
= current_inferior ()->gdbarch
;
5596 if (gdbarch_gdb_signal_to_target_p (gdbarch
))
5598 /* Set the value of the internal variable $_exitsignal,
5599 which holds the signal uncaught by the inferior. */
5600 set_internalvar_integer (lookup_internalvar ("_exitsignal"),
5601 gdbarch_gdb_signal_to_target (gdbarch
,
5602 ecs
->ws
.value
.sig
));
5606 /* We don't have access to the target's method used for
5607 converting between signal numbers (GDB's internal
5608 representation <-> target's representation).
5609 Therefore, we cannot do a good job at displaying this
5610 information to the user. It's better to just warn
5611 her about it (if infrun debugging is enabled), and
5613 infrun_debug_printf ("Cannot fill $_exitsignal with the correct "
5617 gdb::observers::signal_exited
.notify (ecs
->ws
.value
.sig
);
5620 gdb_flush (gdb_stdout
);
5621 target_mourn_inferior (inferior_ptid
);
5622 stop_print_frame
= false;
5626 case TARGET_WAITKIND_FORKED
:
5627 case TARGET_WAITKIND_VFORKED
:
5628 /* Check whether the inferior is displaced stepping. */
5630 struct regcache
*regcache
= get_thread_regcache (ecs
->event_thread
);
5631 struct gdbarch
*gdbarch
= regcache
->arch ();
5632 inferior
*parent_inf
= find_inferior_ptid (ecs
->target
, ecs
->ptid
);
5634 /* If this is a fork (child gets its own address space copy)
5635 and some displaced step buffers were in use at the time of
5636 the fork, restore the displaced step buffer bytes in the
5639 Architectures which support displaced stepping and fork
5640 events must supply an implementation of
5641 gdbarch_displaced_step_restore_all_in_ptid. This is not
5642 enforced during gdbarch validation to support architectures
5643 which support displaced stepping but not forks. */
5644 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
5645 && gdbarch_supports_displaced_stepping (gdbarch
))
5646 gdbarch_displaced_step_restore_all_in_ptid
5647 (gdbarch
, parent_inf
, ecs
->ws
.value
.related_pid
);
5649 /* If displaced stepping is supported, and thread ecs->ptid is
5650 displaced stepping. */
5651 if (displaced_step_in_progress_thread (ecs
->event_thread
))
5653 struct regcache
*child_regcache
;
5654 CORE_ADDR parent_pc
;
5656 /* GDB has got TARGET_WAITKIND_FORKED or TARGET_WAITKIND_VFORKED,
5657 indicating that the displaced stepping of syscall instruction
5658 has been done. Perform cleanup for parent process here. Note
5659 that this operation also cleans up the child process for vfork,
5660 because their pages are shared. */
5661 displaced_step_finish (ecs
->event_thread
, GDB_SIGNAL_TRAP
);
5662 /* Start a new step-over in another thread if there's one
5666 /* Since the vfork/fork syscall instruction was executed in the scratchpad,
5667 the child's PC is also within the scratchpad. Set the child's PC
5668 to the parent's PC value, which has already been fixed up.
5669 FIXME: we use the parent's aspace here, although we're touching
5670 the child, because the child hasn't been added to the inferior
5671 list yet at this point. */
5674 = get_thread_arch_aspace_regcache (parent_inf
->process_target (),
5675 ecs
->ws
.value
.related_pid
,
5677 parent_inf
->aspace
);
5678 /* Read PC value of parent process. */
5679 parent_pc
= regcache_read_pc (regcache
);
5681 displaced_debug_printf ("write child pc from %s to %s",
5683 regcache_read_pc (child_regcache
)),
5684 paddress (gdbarch
, parent_pc
));
5686 regcache_write_pc (child_regcache
, parent_pc
);
5690 context_switch (ecs
);
5692 /* Immediately detach breakpoints from the child before there's
5693 any chance of letting the user delete breakpoints from the
5694 breakpoint lists. If we don't do this early, it's easy to
5695 leave left over traps in the child, vis: "break foo; catch
5696 fork; c; <fork>; del; c; <child calls foo>". We only follow
5697 the fork on the last `continue', and by that time the
5698 breakpoint at "foo" is long gone from the breakpoint table.
5699 If we vforked, then we don't need to unpatch here, since both
5700 parent and child are sharing the same memory pages; we'll
5701 need to unpatch at follow/detach time instead to be certain
5702 that new breakpoints added between catchpoint hit time and
5703 vfork follow are detached. */
5704 if (ecs
->ws
.kind
!= TARGET_WAITKIND_VFORKED
)
5706 /* This won't actually modify the breakpoint list, but will
5707 physically remove the breakpoints from the child. */
5708 detach_breakpoints (ecs
->ws
.value
.related_pid
);
5711 delete_just_stopped_threads_single_step_breakpoints ();
5713 /* In case the event is caught by a catchpoint, remember that
5714 the event is to be followed at the next resume of the thread,
5715 and not immediately. */
5716 ecs
->event_thread
->pending_follow
= ecs
->ws
;
5718 ecs
->event_thread
->suspend
.stop_pc
5719 = regcache_read_pc (get_thread_regcache (ecs
->event_thread
));
5721 ecs
->event_thread
->control
.stop_bpstat
5722 = bpstat_stop_status (get_current_regcache ()->aspace (),
5723 ecs
->event_thread
->suspend
.stop_pc
,
5724 ecs
->event_thread
, &ecs
->ws
);
5726 if (handle_stop_requested (ecs
))
5729 /* If no catchpoint triggered for this, then keep going. Note
5730 that we're interested in knowing the bpstat actually causes a
5731 stop, not just if it may explain the signal. Software
5732 watchpoints, for example, always appear in the bpstat. */
5733 if (!bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
5736 = (follow_fork_mode_string
== follow_fork_mode_child
);
5738 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5740 process_stratum_target
*targ
5741 = ecs
->event_thread
->inf
->process_target ();
5743 bool should_resume
= follow_fork ();
5745 /* Note that one of these may be an invalid pointer,
5746 depending on detach_fork. */
5747 thread_info
*parent
= ecs
->event_thread
;
5749 = find_thread_ptid (targ
, ecs
->ws
.value
.related_pid
);
5751 /* At this point, the parent is marked running, and the
5752 child is marked stopped. */
5754 /* If not resuming the parent, mark it stopped. */
5755 if (follow_child
&& !detach_fork
&& !non_stop
&& !sched_multi
)
5756 parent
->set_running (false);
5758 /* If resuming the child, mark it running. */
5759 if (follow_child
|| (!detach_fork
&& (non_stop
|| sched_multi
)))
5760 child
->set_running (true);
5762 /* In non-stop mode, also resume the other branch. */
5763 if (!detach_fork
&& (non_stop
5764 || (sched_multi
&& target_is_non_stop_p ())))
5767 switch_to_thread (parent
);
5769 switch_to_thread (child
);
5771 ecs
->event_thread
= inferior_thread ();
5772 ecs
->ptid
= inferior_ptid
;
5777 switch_to_thread (child
);
5779 switch_to_thread (parent
);
5781 ecs
->event_thread
= inferior_thread ();
5782 ecs
->ptid
= inferior_ptid
;
5786 /* Never call switch_back_to_stepped_thread if we are waiting for
5787 vfork-done (waiting for an external vfork child to exec or
5788 exit). We will resume only the vforking thread for the purpose
5789 of collecting the vfork-done event, and we will restart any
5790 step once the critical shared address space window is done. */
5793 && parent
->inf
->thread_waiting_for_vfork_done
!= nullptr)
5794 || !switch_back_to_stepped_thread (ecs
))
5801 process_event_stop_test (ecs
);
5804 case TARGET_WAITKIND_VFORK_DONE
:
5805 /* Done with the shared memory region. Re-insert breakpoints in
5806 the parent, and keep going. */
5808 context_switch (ecs
);
5810 handle_vfork_done (ecs
->event_thread
);
5811 gdb_assert (inferior_thread () == ecs
->event_thread
);
5813 if (handle_stop_requested (ecs
))
5816 if (!switch_back_to_stepped_thread (ecs
))
5818 gdb_assert (inferior_thread () == ecs
->event_thread
);
5819 /* This also takes care of reinserting breakpoints in the
5820 previously locked inferior. */
5825 case TARGET_WAITKIND_EXECD
:
5827 /* Note we can't read registers yet (the stop_pc), because we
5828 don't yet know the inferior's post-exec architecture.
5829 'stop_pc' is explicitly read below instead. */
5830 switch_to_thread_no_regs (ecs
->event_thread
);
5832 /* Do whatever is necessary to the parent branch of the vfork. */
5833 handle_vfork_child_exec_or_exit (1);
5835 /* This causes the eventpoints and symbol table to be reset.
5836 Must do this now, before trying to determine whether to
5838 follow_exec (inferior_ptid
, ecs
->ws
.value
.execd_pathname
);
5840 /* In follow_exec we may have deleted the original thread and
5841 created a new one. Make sure that the event thread is the
5842 execd thread for that case (this is a nop otherwise). */
5843 ecs
->event_thread
= inferior_thread ();
5845 ecs
->event_thread
->suspend
.stop_pc
5846 = regcache_read_pc (get_thread_regcache (ecs
->event_thread
));
5848 ecs
->event_thread
->control
.stop_bpstat
5849 = bpstat_stop_status (get_current_regcache ()->aspace (),
5850 ecs
->event_thread
->suspend
.stop_pc
,
5851 ecs
->event_thread
, &ecs
->ws
);
5853 /* Note that this may be referenced from inside
5854 bpstat_stop_status above, through inferior_has_execd. */
5855 xfree (ecs
->ws
.value
.execd_pathname
);
5856 ecs
->ws
.value
.execd_pathname
= NULL
;
5858 if (handle_stop_requested (ecs
))
5861 /* If no catchpoint triggered for this, then keep going. */
5862 if (!bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
5864 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5868 process_event_stop_test (ecs
);
5871 /* Be careful not to try to gather much state about a thread
5872 that's in a syscall. It's frequently a losing proposition. */
5873 case TARGET_WAITKIND_SYSCALL_ENTRY
:
5874 /* Getting the current syscall number. */
5875 if (handle_syscall_event (ecs
) == 0)
5876 process_event_stop_test (ecs
);
5879 /* Before examining the threads further, step this thread to
5880 get it entirely out of the syscall. (We get notice of the
5881 event when the thread is just on the verge of exiting a
5882 syscall. Stepping one instruction seems to get it back
5884 case TARGET_WAITKIND_SYSCALL_RETURN
:
5885 if (handle_syscall_event (ecs
) == 0)
5886 process_event_stop_test (ecs
);
5889 case TARGET_WAITKIND_STOPPED
:
5890 handle_signal_stop (ecs
);
5893 case TARGET_WAITKIND_NO_HISTORY
:
5894 /* Reverse execution: target ran out of history info. */
5896 /* Switch to the stopped thread. */
5897 context_switch (ecs
);
5898 infrun_debug_printf ("stopped");
5900 delete_just_stopped_threads_single_step_breakpoints ();
5901 ecs
->event_thread
->suspend
.stop_pc
5902 = regcache_read_pc (get_thread_regcache (inferior_thread ()));
5904 if (handle_stop_requested (ecs
))
5907 gdb::observers::no_history
.notify ();
5913 /* Restart threads back to what they were trying to do back when we
5914 paused them (because of an in-line step-over or vfork, for example).
5915 The EVENT_THREAD thread is ignored (not restarted).
5917 If INF is non-nullptr, only resume threads from INF. */
5920 restart_threads (struct thread_info
*event_thread
, inferior
*inf
)
5922 INFRUN_SCOPED_DEBUG_START_END ("event_thread=%s, inf=%d",
5923 event_thread
->ptid
.to_string ().c_str (),
5924 inf
!= nullptr ? inf
->num
: -1);
5926 /* In case the instruction just stepped spawned a new thread. */
5927 update_thread_list ();
5929 for (thread_info
*tp
: all_non_exited_threads ())
5931 if (inf
!= nullptr && tp
->inf
!= inf
)
5934 if (tp
->inf
->detaching
)
5936 infrun_debug_printf ("restart threads: [%s] inferior detaching",
5937 target_pid_to_str (tp
->ptid
).c_str ());
5941 switch_to_thread_no_regs (tp
);
5943 if (tp
== event_thread
)
5945 infrun_debug_printf ("restart threads: [%s] is event thread",
5946 target_pid_to_str (tp
->ptid
).c_str ());
5950 if (!(tp
->state
== THREAD_RUNNING
|| tp
->control
.in_infcall
))
5952 infrun_debug_printf ("restart threads: [%s] not meant to be running",
5953 target_pid_to_str (tp
->ptid
).c_str ());
5959 infrun_debug_printf ("restart threads: [%s] resumed",
5960 target_pid_to_str (tp
->ptid
).c_str ());
5961 gdb_assert (tp
->executing
|| tp
->suspend
.waitstatus_pending_p
);
5965 if (thread_is_in_step_over_chain (tp
))
5967 infrun_debug_printf ("restart threads: [%s] needs step-over",
5968 target_pid_to_str (tp
->ptid
).c_str ());
5969 gdb_assert (!tp
->resumed
);
5974 if (tp
->suspend
.waitstatus_pending_p
)
5976 infrun_debug_printf ("restart threads: [%s] has pending status",
5977 target_pid_to_str (tp
->ptid
).c_str ());
5982 gdb_assert (!tp
->stop_requested
);
5984 /* If some thread needs to start a step-over at this point, it
5985 should still be in the step-over queue, and thus skipped
5987 if (thread_still_needs_step_over (tp
))
5989 internal_error (__FILE__
, __LINE__
,
5990 "thread [%s] needs a step-over, but not in "
5991 "step-over queue\n",
5992 target_pid_to_str (tp
->ptid
).c_str ());
5995 if (currently_stepping (tp
))
5997 infrun_debug_printf ("restart threads: [%s] was stepping",
5998 target_pid_to_str (tp
->ptid
).c_str ());
5999 keep_going_stepped_thread (tp
);
6003 struct execution_control_state ecss
;
6004 struct execution_control_state
*ecs
= &ecss
;
6006 infrun_debug_printf ("restart threads: [%s] continuing",
6007 target_pid_to_str (tp
->ptid
).c_str ());
6008 reset_ecs (ecs
, tp
);
6009 switch_to_thread (tp
);
6010 keep_going_pass_signal (ecs
);
6015 /* Callback for iterate_over_threads. Find a resumed thread that has
6016 a pending waitstatus. */
6019 resumed_thread_with_pending_status (struct thread_info
*tp
,
6023 && tp
->suspend
.waitstatus_pending_p
);
6026 /* Called when we get an event that may finish an in-line or
6027 out-of-line (displaced stepping) step-over started previously.
6028 Return true if the event is processed and we should go back to the
6029 event loop; false if the caller should continue processing the
6033 finish_step_over (struct execution_control_state
*ecs
)
6035 displaced_step_finish (ecs
->event_thread
,
6036 ecs
->event_thread
->suspend
.stop_signal
);
6038 bool had_step_over_info
= step_over_info_valid_p ();
6040 if (had_step_over_info
)
6042 /* If we're stepping over a breakpoint with all threads locked,
6043 then only the thread that was stepped should be reporting
6045 gdb_assert (ecs
->event_thread
->control
.trap_expected
);
6047 clear_step_over_info ();
6050 if (!target_is_non_stop_p ())
6053 /* Start a new step-over in another thread if there's one that
6057 /* If we were stepping over a breakpoint before, and haven't started
6058 a new in-line step-over sequence, then restart all other threads
6059 (except the event thread). We can't do this in all-stop, as then
6060 e.g., we wouldn't be able to issue any other remote packet until
6061 these other threads stop. */
6062 if (had_step_over_info
&& !step_over_info_valid_p ())
6064 struct thread_info
*pending
;
6066 /* If we only have threads with pending statuses, the restart
6067 below won't restart any thread and so nothing re-inserts the
6068 breakpoint we just stepped over. But we need it inserted
6069 when we later process the pending events, otherwise if
6070 another thread has a pending event for this breakpoint too,
6071 we'd discard its event (because the breakpoint that
6072 originally caused the event was no longer inserted). */
6073 context_switch (ecs
);
6074 insert_breakpoints ();
6076 restart_threads (ecs
->event_thread
);
6078 /* If we have events pending, go through handle_inferior_event
6079 again, picking up a pending event at random. This avoids
6080 thread starvation. */
6082 /* But not if we just stepped over a watchpoint in order to let
6083 the instruction execute so we can evaluate its expression.
6084 The set of watchpoints that triggered is recorded in the
6085 breakpoint objects themselves (see bp->watchpoint_triggered).
6086 If we processed another event first, that other event could
6087 clobber this info. */
6088 if (ecs
->event_thread
->stepping_over_watchpoint
)
6091 pending
= iterate_over_threads (resumed_thread_with_pending_status
,
6093 if (pending
!= NULL
)
6095 struct thread_info
*tp
= ecs
->event_thread
;
6096 struct regcache
*regcache
;
6098 infrun_debug_printf ("found resumed threads with "
6099 "pending events, saving status");
6101 gdb_assert (pending
!= tp
);
6103 /* Record the event thread's event for later. */
6104 save_waitstatus (tp
, &ecs
->ws
);
6105 /* This was cleared early, by handle_inferior_event. Set it
6106 so this pending event is considered by
6110 gdb_assert (!tp
->executing
);
6112 regcache
= get_thread_regcache (tp
);
6113 tp
->suspend
.stop_pc
= regcache_read_pc (regcache
);
6115 infrun_debug_printf ("saved stop_pc=%s for %s "
6116 "(currently_stepping=%d)",
6117 paddress (target_gdbarch (),
6118 tp
->suspend
.stop_pc
),
6119 target_pid_to_str (tp
->ptid
).c_str (),
6120 currently_stepping (tp
));
6122 /* This in-line step-over finished; clear this so we won't
6123 start a new one. This is what handle_signal_stop would
6124 do, if we returned false. */
6125 tp
->stepping_over_breakpoint
= 0;
6127 /* Wake up the event loop again. */
6128 mark_async_event_handler (infrun_async_inferior_event_token
);
6130 prepare_to_wait (ecs
);
6138 /* Come here when the program has stopped with a signal. */
6141 handle_signal_stop (struct execution_control_state
*ecs
)
6143 struct frame_info
*frame
;
6144 struct gdbarch
*gdbarch
;
6145 int stopped_by_watchpoint
;
6146 enum stop_kind stop_soon
;
6149 gdb_assert (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
6151 ecs
->event_thread
->suspend
.stop_signal
= ecs
->ws
.value
.sig
;
6153 /* Do we need to clean up the state of a thread that has
6154 completed a displaced single-step? (Doing so usually affects
6155 the PC, so do it here, before we set stop_pc.) */
6156 if (finish_step_over (ecs
))
6159 /* If we either finished a single-step or hit a breakpoint, but
6160 the user wanted this thread to be stopped, pretend we got a
6161 SIG0 (generic unsignaled stop). */
6162 if (ecs
->event_thread
->stop_requested
6163 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
6164 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
6166 ecs
->event_thread
->suspend
.stop_pc
6167 = regcache_read_pc (get_thread_regcache (ecs
->event_thread
));
6169 context_switch (ecs
);
6171 if (deprecated_context_hook
)
6172 deprecated_context_hook (ecs
->event_thread
->global_num
);
6176 struct regcache
*regcache
= get_thread_regcache (ecs
->event_thread
);
6177 struct gdbarch
*reg_gdbarch
= regcache
->arch ();
6179 infrun_debug_printf ("stop_pc=%s",
6180 paddress (reg_gdbarch
,
6181 ecs
->event_thread
->suspend
.stop_pc
));
6182 if (target_stopped_by_watchpoint ())
6186 infrun_debug_printf ("stopped by watchpoint");
6188 if (target_stopped_data_address (current_inferior ()->top_target (),
6190 infrun_debug_printf ("stopped data address=%s",
6191 paddress (reg_gdbarch
, addr
));
6193 infrun_debug_printf ("(no data address available)");
6197 /* This is originated from start_remote(), start_inferior() and
6198 shared libraries hook functions. */
6199 stop_soon
= get_inferior_stop_soon (ecs
);
6200 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_REMOTE
)
6202 infrun_debug_printf ("quietly stopped");
6203 stop_print_frame
= true;
6208 /* This originates from attach_command(). We need to overwrite
6209 the stop_signal here, because some kernels don't ignore a
6210 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
6211 See more comments in inferior.h. On the other hand, if we
6212 get a non-SIGSTOP, report it to the user - assume the backend
6213 will handle the SIGSTOP if it should show up later.
6215 Also consider that the attach is complete when we see a
6216 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
6217 target extended-remote report it instead of a SIGSTOP
6218 (e.g. gdbserver). We already rely on SIGTRAP being our
6219 signal, so this is no exception.
6221 Also consider that the attach is complete when we see a
6222 GDB_SIGNAL_0. In non-stop mode, GDB will explicitly tell
6223 the target to stop all threads of the inferior, in case the
6224 low level attach operation doesn't stop them implicitly. If
6225 they weren't stopped implicitly, then the stub will report a
6226 GDB_SIGNAL_0, meaning: stopped for no particular reason
6227 other than GDB's request. */
6228 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
6229 && (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_STOP
6230 || ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
6231 || ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_0
))
6233 stop_print_frame
= true;
6235 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
6239 /* At this point, get hold of the now-current thread's frame. */
6240 frame
= get_current_frame ();
6241 gdbarch
= get_frame_arch (frame
);
6243 /* Pull the single step breakpoints out of the target. */
6244 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
6246 struct regcache
*regcache
;
6249 regcache
= get_thread_regcache (ecs
->event_thread
);
6250 const address_space
*aspace
= regcache
->aspace ();
6252 pc
= regcache_read_pc (regcache
);
6254 /* However, before doing so, if this single-step breakpoint was
6255 actually for another thread, set this thread up for moving
6257 if (!thread_has_single_step_breakpoint_here (ecs
->event_thread
,
6260 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
6262 infrun_debug_printf ("[%s] hit another thread's single-step "
6264 target_pid_to_str (ecs
->ptid
).c_str ());
6265 ecs
->hit_singlestep_breakpoint
= 1;
6270 infrun_debug_printf ("[%s] hit its single-step breakpoint",
6271 target_pid_to_str (ecs
->ptid
).c_str ());
6274 delete_just_stopped_threads_single_step_breakpoints ();
6276 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
6277 && ecs
->event_thread
->control
.trap_expected
6278 && ecs
->event_thread
->stepping_over_watchpoint
)
6279 stopped_by_watchpoint
= 0;
6281 stopped_by_watchpoint
= watchpoints_triggered (&ecs
->ws
);
6283 /* If necessary, step over this watchpoint. We'll be back to display
6285 if (stopped_by_watchpoint
6286 && (target_have_steppable_watchpoint ()
6287 || gdbarch_have_nonsteppable_watchpoint (gdbarch
)))
6289 /* At this point, we are stopped at an instruction which has
6290 attempted to write to a piece of memory under control of
6291 a watchpoint. The instruction hasn't actually executed
6292 yet. If we were to evaluate the watchpoint expression
6293 now, we would get the old value, and therefore no change
6294 would seem to have occurred.
6296 In order to make watchpoints work `right', we really need
6297 to complete the memory write, and then evaluate the
6298 watchpoint expression. We do this by single-stepping the
6301 It may not be necessary to disable the watchpoint to step over
6302 it. For example, the PA can (with some kernel cooperation)
6303 single step over a watchpoint without disabling the watchpoint.
6305 It is far more common to need to disable a watchpoint to step
6306 the inferior over it. If we have non-steppable watchpoints,
6307 we must disable the current watchpoint; it's simplest to
6308 disable all watchpoints.
6310 Any breakpoint at PC must also be stepped over -- if there's
6311 one, it will have already triggered before the watchpoint
6312 triggered, and we either already reported it to the user, or
6313 it didn't cause a stop and we called keep_going. In either
6314 case, if there was a breakpoint at PC, we must be trying to
6316 ecs
->event_thread
->stepping_over_watchpoint
= 1;
6321 ecs
->event_thread
->stepping_over_breakpoint
= 0;
6322 ecs
->event_thread
->stepping_over_watchpoint
= 0;
6323 bpstat_clear (&ecs
->event_thread
->control
.stop_bpstat
);
6324 ecs
->event_thread
->control
.stop_step
= 0;
6325 stop_print_frame
= true;
6326 stopped_by_random_signal
= 0;
6327 bpstat stop_chain
= NULL
;
6329 /* Hide inlined functions starting here, unless we just performed stepi or
6330 nexti. After stepi and nexti, always show the innermost frame (not any
6331 inline function call sites). */
6332 if (ecs
->event_thread
->control
.step_range_end
!= 1)
6334 const address_space
*aspace
6335 = get_thread_regcache (ecs
->event_thread
)->aspace ();
6337 /* skip_inline_frames is expensive, so we avoid it if we can
6338 determine that the address is one where functions cannot have
6339 been inlined. This improves performance with inferiors that
6340 load a lot of shared libraries, because the solib event
6341 breakpoint is defined as the address of a function (i.e. not
6342 inline). Note that we have to check the previous PC as well
6343 as the current one to catch cases when we have just
6344 single-stepped off a breakpoint prior to reinstating it.
6345 Note that we're assuming that the code we single-step to is
6346 not inline, but that's not definitive: there's nothing
6347 preventing the event breakpoint function from containing
6348 inlined code, and the single-step ending up there. If the
6349 user had set a breakpoint on that inlined code, the missing
6350 skip_inline_frames call would break things. Fortunately
6351 that's an extremely unlikely scenario. */
6352 if (!pc_at_non_inline_function (aspace
,
6353 ecs
->event_thread
->suspend
.stop_pc
,
6355 && !(ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
6356 && ecs
->event_thread
->control
.trap_expected
6357 && pc_at_non_inline_function (aspace
,
6358 ecs
->event_thread
->prev_pc
,
6361 stop_chain
= build_bpstat_chain (aspace
,
6362 ecs
->event_thread
->suspend
.stop_pc
,
6364 skip_inline_frames (ecs
->event_thread
, stop_chain
);
6366 /* Re-fetch current thread's frame in case that invalidated
6368 frame
= get_current_frame ();
6369 gdbarch
= get_frame_arch (frame
);
6373 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
6374 && ecs
->event_thread
->control
.trap_expected
6375 && gdbarch_single_step_through_delay_p (gdbarch
)
6376 && currently_stepping (ecs
->event_thread
))
6378 /* We're trying to step off a breakpoint. Turns out that we're
6379 also on an instruction that needs to be stepped multiple
6380 times before it's been fully executing. E.g., architectures
6381 with a delay slot. It needs to be stepped twice, once for
6382 the instruction and once for the delay slot. */
6383 int step_through_delay
6384 = gdbarch_single_step_through_delay (gdbarch
, frame
);
6386 if (step_through_delay
)
6387 infrun_debug_printf ("step through delay");
6389 if (ecs
->event_thread
->control
.step_range_end
== 0
6390 && step_through_delay
)
6392 /* The user issued a continue when stopped at a breakpoint.
6393 Set up for another trap and get out of here. */
6394 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6398 else if (step_through_delay
)
6400 /* The user issued a step when stopped at a breakpoint.
6401 Maybe we should stop, maybe we should not - the delay
6402 slot *might* correspond to a line of source. In any
6403 case, don't decide that here, just set
6404 ecs->stepping_over_breakpoint, making sure we
6405 single-step again before breakpoints are re-inserted. */
6406 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6410 /* See if there is a breakpoint/watchpoint/catchpoint/etc. that
6411 handles this event. */
6412 ecs
->event_thread
->control
.stop_bpstat
6413 = bpstat_stop_status (get_current_regcache ()->aspace (),
6414 ecs
->event_thread
->suspend
.stop_pc
,
6415 ecs
->event_thread
, &ecs
->ws
, stop_chain
);
6417 /* Following in case break condition called a
6419 stop_print_frame
= true;
6421 /* This is where we handle "moribund" watchpoints. Unlike
6422 software breakpoints traps, hardware watchpoint traps are
6423 always distinguishable from random traps. If no high-level
6424 watchpoint is associated with the reported stop data address
6425 anymore, then the bpstat does not explain the signal ---
6426 simply make sure to ignore it if `stopped_by_watchpoint' is
6429 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
6430 && !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
6432 && stopped_by_watchpoint
)
6434 infrun_debug_printf ("no user watchpoint explains watchpoint SIGTRAP, "
6438 /* NOTE: cagney/2003-03-29: These checks for a random signal
6439 at one stage in the past included checks for an inferior
6440 function call's call dummy's return breakpoint. The original
6441 comment, that went with the test, read:
6443 ``End of a stack dummy. Some systems (e.g. Sony news) give
6444 another signal besides SIGTRAP, so check here as well as
6447 If someone ever tries to get call dummys on a
6448 non-executable stack to work (where the target would stop
6449 with something like a SIGSEGV), then those tests might need
6450 to be re-instated. Given, however, that the tests were only
6451 enabled when momentary breakpoints were not being used, I
6452 suspect that it won't be the case.
6454 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
6455 be necessary for call dummies on a non-executable stack on
6458 /* See if the breakpoints module can explain the signal. */
6460 = !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
6461 ecs
->event_thread
->suspend
.stop_signal
);
6463 /* Maybe this was a trap for a software breakpoint that has since
6465 if (random_signal
&& target_stopped_by_sw_breakpoint ())
6467 if (gdbarch_program_breakpoint_here_p (gdbarch
,
6468 ecs
->event_thread
->suspend
.stop_pc
))
6470 struct regcache
*regcache
;
6473 /* Re-adjust PC to what the program would see if GDB was not
6475 regcache
= get_thread_regcache (ecs
->event_thread
);
6476 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
6479 gdb::optional
<scoped_restore_tmpl
<int>>
6480 restore_operation_disable
;
6482 if (record_full_is_used ())
6483 restore_operation_disable
.emplace
6484 (record_full_gdb_operation_disable_set ());
6486 regcache_write_pc (regcache
,
6487 ecs
->event_thread
->suspend
.stop_pc
+ decr_pc
);
6492 /* A delayed software breakpoint event. Ignore the trap. */
6493 infrun_debug_printf ("delayed software breakpoint trap, ignoring");
6498 /* Maybe this was a trap for a hardware breakpoint/watchpoint that
6499 has since been removed. */
6500 if (random_signal
&& target_stopped_by_hw_breakpoint ())
6502 /* A delayed hardware breakpoint event. Ignore the trap. */
6503 infrun_debug_printf ("delayed hardware breakpoint/watchpoint "
6508 /* If not, perhaps stepping/nexting can. */
6510 random_signal
= !(ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
6511 && currently_stepping (ecs
->event_thread
));
6513 /* Perhaps the thread hit a single-step breakpoint of _another_
6514 thread. Single-step breakpoints are transparent to the
6515 breakpoints module. */
6517 random_signal
= !ecs
->hit_singlestep_breakpoint
;
6519 /* No? Perhaps we got a moribund watchpoint. */
6521 random_signal
= !stopped_by_watchpoint
;
6523 /* Always stop if the user explicitly requested this thread to
6525 if (ecs
->event_thread
->stop_requested
)
6528 infrun_debug_printf ("user-requested stop");
6531 /* For the program's own signals, act according to
6532 the signal handling tables. */
6536 /* Signal not for debugging purposes. */
6537 enum gdb_signal stop_signal
= ecs
->event_thread
->suspend
.stop_signal
;
6539 infrun_debug_printf ("random signal (%s)",
6540 gdb_signal_to_symbol_string (stop_signal
));
6542 stopped_by_random_signal
= 1;
6544 /* Always stop on signals if we're either just gaining control
6545 of the program, or the user explicitly requested this thread
6546 to remain stopped. */
6547 if (stop_soon
!= NO_STOP_QUIETLY
6548 || ecs
->event_thread
->stop_requested
6549 || signal_stop_state (ecs
->event_thread
->suspend
.stop_signal
))
6555 /* Notify observers the signal has "handle print" set. Note we
6556 returned early above if stopping; normal_stop handles the
6557 printing in that case. */
6558 if (signal_print
[ecs
->event_thread
->suspend
.stop_signal
])
6560 /* The signal table tells us to print about this signal. */
6561 target_terminal::ours_for_output ();
6562 gdb::observers::signal_received
.notify (ecs
->event_thread
->suspend
.stop_signal
);
6563 target_terminal::inferior ();
6566 /* Clear the signal if it should not be passed. */
6567 if (signal_program
[ecs
->event_thread
->suspend
.stop_signal
] == 0)
6568 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
6570 if (ecs
->event_thread
->prev_pc
== ecs
->event_thread
->suspend
.stop_pc
6571 && ecs
->event_thread
->control
.trap_expected
6572 && ecs
->event_thread
->control
.step_resume_breakpoint
== NULL
)
6574 /* We were just starting a new sequence, attempting to
6575 single-step off of a breakpoint and expecting a SIGTRAP.
6576 Instead this signal arrives. This signal will take us out
6577 of the stepping range so GDB needs to remember to, when
6578 the signal handler returns, resume stepping off that
6580 /* To simplify things, "continue" is forced to use the same
6581 code paths as single-step - set a breakpoint at the
6582 signal return address and then, once hit, step off that
6584 infrun_debug_printf ("signal arrived while stepping over breakpoint");
6586 insert_hp_step_resume_breakpoint_at_frame (frame
);
6587 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
6588 /* Reset trap_expected to ensure breakpoints are re-inserted. */
6589 ecs
->event_thread
->control
.trap_expected
= 0;
6591 /* If we were nexting/stepping some other thread, switch to
6592 it, so that we don't continue it, losing control. */
6593 if (!switch_back_to_stepped_thread (ecs
))
6598 if (ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
6599 && (pc_in_thread_step_range (ecs
->event_thread
->suspend
.stop_pc
,
6601 || ecs
->event_thread
->control
.step_range_end
== 1)
6602 && frame_id_eq (get_stack_frame_id (frame
),
6603 ecs
->event_thread
->control
.step_stack_frame_id
)
6604 && ecs
->event_thread
->control
.step_resume_breakpoint
== NULL
)
6606 /* The inferior is about to take a signal that will take it
6607 out of the single step range. Set a breakpoint at the
6608 current PC (which is presumably where the signal handler
6609 will eventually return) and then allow the inferior to
6612 Note that this is only needed for a signal delivered
6613 while in the single-step range. Nested signals aren't a
6614 problem as they eventually all return. */
6615 infrun_debug_printf ("signal may take us out of single-step range");
6617 clear_step_over_info ();
6618 insert_hp_step_resume_breakpoint_at_frame (frame
);
6619 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
6620 /* Reset trap_expected to ensure breakpoints are re-inserted. */
6621 ecs
->event_thread
->control
.trap_expected
= 0;
6626 /* Note: step_resume_breakpoint may be non-NULL. This occurs
6627 when either there's a nested signal, or when there's a
6628 pending signal enabled just as the signal handler returns
6629 (leaving the inferior at the step-resume-breakpoint without
6630 actually executing it). Either way continue until the
6631 breakpoint is really hit. */
6633 if (!switch_back_to_stepped_thread (ecs
))
6635 infrun_debug_printf ("random signal, keep going");
6642 process_event_stop_test (ecs
);
6645 /* Come here when we've got some debug event / signal we can explain
6646 (IOW, not a random signal), and test whether it should cause a
6647 stop, or whether we should resume the inferior (transparently).
6648 E.g., could be a breakpoint whose condition evaluates false; we
6649 could be still stepping within the line; etc. */
6652 process_event_stop_test (struct execution_control_state
*ecs
)
6654 struct symtab_and_line stop_pc_sal
;
6655 struct frame_info
*frame
;
6656 struct gdbarch
*gdbarch
;
6657 CORE_ADDR jmp_buf_pc
;
6658 struct bpstat_what what
;
6660 /* Handle cases caused by hitting a breakpoint. */
6662 frame
= get_current_frame ();
6663 gdbarch
= get_frame_arch (frame
);
6665 what
= bpstat_what (ecs
->event_thread
->control
.stop_bpstat
);
6667 if (what
.call_dummy
)
6669 stop_stack_dummy
= what
.call_dummy
;
6672 /* A few breakpoint types have callbacks associated (e.g.,
6673 bp_jit_event). Run them now. */
6674 bpstat_run_callbacks (ecs
->event_thread
->control
.stop_bpstat
);
6676 /* If we hit an internal event that triggers symbol changes, the
6677 current frame will be invalidated within bpstat_what (e.g., if we
6678 hit an internal solib event). Re-fetch it. */
6679 frame
= get_current_frame ();
6680 gdbarch
= get_frame_arch (frame
);
6682 switch (what
.main_action
)
6684 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
6685 /* If we hit the breakpoint at longjmp while stepping, we
6686 install a momentary breakpoint at the target of the
6689 infrun_debug_printf ("BPSTAT_WHAT_SET_LONGJMP_RESUME");
6691 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6693 if (what
.is_longjmp
)
6695 struct value
*arg_value
;
6697 /* If we set the longjmp breakpoint via a SystemTap probe,
6698 then use it to extract the arguments. The destination PC
6699 is the third argument to the probe. */
6700 arg_value
= probe_safe_evaluate_at_pc (frame
, 2);
6703 jmp_buf_pc
= value_as_address (arg_value
);
6704 jmp_buf_pc
= gdbarch_addr_bits_remove (gdbarch
, jmp_buf_pc
);
6706 else if (!gdbarch_get_longjmp_target_p (gdbarch
)
6707 || !gdbarch_get_longjmp_target (gdbarch
,
6708 frame
, &jmp_buf_pc
))
6710 infrun_debug_printf ("BPSTAT_WHAT_SET_LONGJMP_RESUME "
6711 "(!gdbarch_get_longjmp_target)");
6716 /* Insert a breakpoint at resume address. */
6717 insert_longjmp_resume_breakpoint (gdbarch
, jmp_buf_pc
);
6720 check_exception_resume (ecs
, frame
);
6724 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
6726 struct frame_info
*init_frame
;
6728 /* There are several cases to consider.
6730 1. The initiating frame no longer exists. In this case we
6731 must stop, because the exception or longjmp has gone too
6734 2. The initiating frame exists, and is the same as the
6735 current frame. We stop, because the exception or longjmp
6738 3. The initiating frame exists and is different from the
6739 current frame. This means the exception or longjmp has
6740 been caught beneath the initiating frame, so keep going.
6742 4. longjmp breakpoint has been placed just to protect
6743 against stale dummy frames and user is not interested in
6744 stopping around longjmps. */
6746 infrun_debug_printf ("BPSTAT_WHAT_CLEAR_LONGJMP_RESUME");
6748 gdb_assert (ecs
->event_thread
->control
.exception_resume_breakpoint
6750 delete_exception_resume_breakpoint (ecs
->event_thread
);
6752 if (what
.is_longjmp
)
6754 check_longjmp_breakpoint_for_call_dummy (ecs
->event_thread
);
6756 if (!frame_id_p (ecs
->event_thread
->initiating_frame
))
6764 init_frame
= frame_find_by_id (ecs
->event_thread
->initiating_frame
);
6768 struct frame_id current_id
6769 = get_frame_id (get_current_frame ());
6770 if (frame_id_eq (current_id
,
6771 ecs
->event_thread
->initiating_frame
))
6773 /* Case 2. Fall through. */
6783 /* For Cases 1 and 2, remove the step-resume breakpoint, if it
6785 delete_step_resume_breakpoint (ecs
->event_thread
);
6787 end_stepping_range (ecs
);
6791 case BPSTAT_WHAT_SINGLE
:
6792 infrun_debug_printf ("BPSTAT_WHAT_SINGLE");
6793 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6794 /* Still need to check other stuff, at least the case where we
6795 are stepping and step out of the right range. */
6798 case BPSTAT_WHAT_STEP_RESUME
:
6799 infrun_debug_printf ("BPSTAT_WHAT_STEP_RESUME");
6801 delete_step_resume_breakpoint (ecs
->event_thread
);
6802 if (ecs
->event_thread
->control
.proceed_to_finish
6803 && execution_direction
== EXEC_REVERSE
)
6805 struct thread_info
*tp
= ecs
->event_thread
;
6807 /* We are finishing a function in reverse, and just hit the
6808 step-resume breakpoint at the start address of the
6809 function, and we're almost there -- just need to back up
6810 by one more single-step, which should take us back to the
6812 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
6816 fill_in_stop_func (gdbarch
, ecs
);
6817 if (ecs
->event_thread
->suspend
.stop_pc
== ecs
->stop_func_start
6818 && execution_direction
== EXEC_REVERSE
)
6820 /* We are stepping over a function call in reverse, and just
6821 hit the step-resume breakpoint at the start address of
6822 the function. Go back to single-stepping, which should
6823 take us back to the function call. */
6824 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6830 case BPSTAT_WHAT_STOP_NOISY
:
6831 infrun_debug_printf ("BPSTAT_WHAT_STOP_NOISY");
6832 stop_print_frame
= true;
6834 /* Assume the thread stopped for a breakpoint. We'll still check
6835 whether a/the breakpoint is there when the thread is next
6837 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6842 case BPSTAT_WHAT_STOP_SILENT
:
6843 infrun_debug_printf ("BPSTAT_WHAT_STOP_SILENT");
6844 stop_print_frame
= false;
6846 /* Assume the thread stopped for a breakpoint. We'll still check
6847 whether a/the breakpoint is there when the thread is next
6849 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6853 case BPSTAT_WHAT_HP_STEP_RESUME
:
6854 infrun_debug_printf ("BPSTAT_WHAT_HP_STEP_RESUME");
6856 delete_step_resume_breakpoint (ecs
->event_thread
);
6857 if (ecs
->event_thread
->step_after_step_resume_breakpoint
)
6859 /* Back when the step-resume breakpoint was inserted, we
6860 were trying to single-step off a breakpoint. Go back to
6862 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
6863 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6869 case BPSTAT_WHAT_KEEP_CHECKING
:
6873 /* If we stepped a permanent breakpoint and we had a high priority
6874 step-resume breakpoint for the address we stepped, but we didn't
6875 hit it, then we must have stepped into the signal handler. The
6876 step-resume was only necessary to catch the case of _not_
6877 stepping into the handler, so delete it, and fall through to
6878 checking whether the step finished. */
6879 if (ecs
->event_thread
->stepped_breakpoint
)
6881 struct breakpoint
*sr_bp
6882 = ecs
->event_thread
->control
.step_resume_breakpoint
;
6885 && sr_bp
->loc
->permanent
6886 && sr_bp
->type
== bp_hp_step_resume
6887 && sr_bp
->loc
->address
== ecs
->event_thread
->prev_pc
)
6889 infrun_debug_printf ("stepped permanent breakpoint, stopped in handler");
6890 delete_step_resume_breakpoint (ecs
->event_thread
);
6891 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
6895 /* We come here if we hit a breakpoint but should not stop for it.
6896 Possibly we also were stepping and should stop for that. So fall
6897 through and test for stepping. But, if not stepping, do not
6900 /* In all-stop mode, if we're currently stepping but have stopped in
6901 some other thread, we need to switch back to the stepped thread. */
6902 if (switch_back_to_stepped_thread (ecs
))
6905 if (ecs
->event_thread
->control
.step_resume_breakpoint
)
6907 infrun_debug_printf ("step-resume breakpoint is inserted");
6909 /* Having a step-resume breakpoint overrides anything
6910 else having to do with stepping commands until
6911 that breakpoint is reached. */
6916 if (ecs
->event_thread
->control
.step_range_end
== 0)
6918 infrun_debug_printf ("no stepping, continue");
6919 /* Likewise if we aren't even stepping. */
6924 /* Re-fetch current thread's frame in case the code above caused
6925 the frame cache to be re-initialized, making our FRAME variable
6926 a dangling pointer. */
6927 frame
= get_current_frame ();
6928 gdbarch
= get_frame_arch (frame
);
6929 fill_in_stop_func (gdbarch
, ecs
);
6931 /* If stepping through a line, keep going if still within it.
6933 Note that step_range_end is the address of the first instruction
6934 beyond the step range, and NOT the address of the last instruction
6937 Note also that during reverse execution, we may be stepping
6938 through a function epilogue and therefore must detect when
6939 the current-frame changes in the middle of a line. */
6941 if (pc_in_thread_step_range (ecs
->event_thread
->suspend
.stop_pc
,
6943 && (execution_direction
!= EXEC_REVERSE
6944 || frame_id_eq (get_frame_id (frame
),
6945 ecs
->event_thread
->control
.step_frame_id
)))
6948 ("stepping inside range [%s-%s]",
6949 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_start
),
6950 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_end
));
6952 /* Tentatively re-enable range stepping; `resume' disables it if
6953 necessary (e.g., if we're stepping over a breakpoint or we
6954 have software watchpoints). */
6955 ecs
->event_thread
->control
.may_range_step
= 1;
6957 /* When stepping backward, stop at beginning of line range
6958 (unless it's the function entry point, in which case
6959 keep going back to the call point). */
6960 CORE_ADDR stop_pc
= ecs
->event_thread
->suspend
.stop_pc
;
6961 if (stop_pc
== ecs
->event_thread
->control
.step_range_start
6962 && stop_pc
!= ecs
->stop_func_start
6963 && execution_direction
== EXEC_REVERSE
)
6964 end_stepping_range (ecs
);
6971 /* We stepped out of the stepping range. */
6973 /* If we are stepping at the source level and entered the runtime
6974 loader dynamic symbol resolution code...
6976 EXEC_FORWARD: we keep on single stepping until we exit the run
6977 time loader code and reach the callee's address.
6979 EXEC_REVERSE: we've already executed the callee (backward), and
6980 the runtime loader code is handled just like any other
6981 undebuggable function call. Now we need only keep stepping
6982 backward through the trampoline code, and that's handled further
6983 down, so there is nothing for us to do here. */
6985 if (execution_direction
!= EXEC_REVERSE
6986 && ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
6987 && in_solib_dynsym_resolve_code (ecs
->event_thread
->suspend
.stop_pc
))
6989 CORE_ADDR pc_after_resolver
=
6990 gdbarch_skip_solib_resolver (gdbarch
,
6991 ecs
->event_thread
->suspend
.stop_pc
);
6993 infrun_debug_printf ("stepped into dynsym resolve code");
6995 if (pc_after_resolver
)
6997 /* Set up a step-resume breakpoint at the address
6998 indicated by SKIP_SOLIB_RESOLVER. */
6999 symtab_and_line sr_sal
;
7000 sr_sal
.pc
= pc_after_resolver
;
7001 sr_sal
.pspace
= get_frame_program_space (frame
);
7003 insert_step_resume_breakpoint_at_sal (gdbarch
,
7004 sr_sal
, null_frame_id
);
7011 /* Step through an indirect branch thunk. */
7012 if (ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
7013 && gdbarch_in_indirect_branch_thunk (gdbarch
,
7014 ecs
->event_thread
->suspend
.stop_pc
))
7016 infrun_debug_printf ("stepped into indirect branch thunk");
7021 if (ecs
->event_thread
->control
.step_range_end
!= 1
7022 && (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
7023 || ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
7024 && get_frame_type (frame
) == SIGTRAMP_FRAME
)
7026 infrun_debug_printf ("stepped into signal trampoline");
7027 /* The inferior, while doing a "step" or "next", has ended up in
7028 a signal trampoline (either by a signal being delivered or by
7029 the signal handler returning). Just single-step until the
7030 inferior leaves the trampoline (either by calling the handler
7036 /* If we're in the return path from a shared library trampoline,
7037 we want to proceed through the trampoline when stepping. */
7038 /* macro/2012-04-25: This needs to come before the subroutine
7039 call check below as on some targets return trampolines look
7040 like subroutine calls (MIPS16 return thunks). */
7041 if (gdbarch_in_solib_return_trampoline (gdbarch
,
7042 ecs
->event_thread
->suspend
.stop_pc
,
7043 ecs
->stop_func_name
)
7044 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
7046 /* Determine where this trampoline returns. */
7047 CORE_ADDR stop_pc
= ecs
->event_thread
->suspend
.stop_pc
;
7048 CORE_ADDR real_stop_pc
7049 = gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
7051 infrun_debug_printf ("stepped into solib return tramp");
7053 /* Only proceed through if we know where it's going. */
7056 /* And put the step-breakpoint there and go until there. */
7057 symtab_and_line sr_sal
;
7058 sr_sal
.pc
= real_stop_pc
;
7059 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
7060 sr_sal
.pspace
= get_frame_program_space (frame
);
7062 /* Do not specify what the fp should be when we stop since
7063 on some machines the prologue is where the new fp value
7065 insert_step_resume_breakpoint_at_sal (gdbarch
,
7066 sr_sal
, null_frame_id
);
7068 /* Restart without fiddling with the step ranges or
7075 /* Check for subroutine calls. The check for the current frame
7076 equalling the step ID is not necessary - the check of the
7077 previous frame's ID is sufficient - but it is a common case and
7078 cheaper than checking the previous frame's ID.
7080 NOTE: frame_id_eq will never report two invalid frame IDs as
7081 being equal, so to get into this block, both the current and
7082 previous frame must have valid frame IDs. */
7083 /* The outer_frame_id check is a heuristic to detect stepping
7084 through startup code. If we step over an instruction which
7085 sets the stack pointer from an invalid value to a valid value,
7086 we may detect that as a subroutine call from the mythical
7087 "outermost" function. This could be fixed by marking
7088 outermost frames as !stack_p,code_p,special_p. Then the
7089 initial outermost frame, before sp was valid, would
7090 have code_addr == &_start. See the comment in frame_id_eq
7092 if (!frame_id_eq (get_stack_frame_id (frame
),
7093 ecs
->event_thread
->control
.step_stack_frame_id
)
7094 && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()),
7095 ecs
->event_thread
->control
.step_stack_frame_id
)
7096 && (!frame_id_eq (ecs
->event_thread
->control
.step_stack_frame_id
,
7098 || (ecs
->event_thread
->control
.step_start_function
7099 != find_pc_function (ecs
->event_thread
->suspend
.stop_pc
)))))
7101 CORE_ADDR stop_pc
= ecs
->event_thread
->suspend
.stop_pc
;
7102 CORE_ADDR real_stop_pc
;
7104 infrun_debug_printf ("stepped into subroutine");
7106 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_NONE
)
7108 /* I presume that step_over_calls is only 0 when we're
7109 supposed to be stepping at the assembly language level
7110 ("stepi"). Just stop. */
7111 /* And this works the same backward as frontward. MVS */
7112 end_stepping_range (ecs
);
7116 /* Reverse stepping through solib trampolines. */
7118 if (execution_direction
== EXEC_REVERSE
7119 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
7120 && (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
7121 || (ecs
->stop_func_start
== 0
7122 && in_solib_dynsym_resolve_code (stop_pc
))))
7124 /* Any solib trampoline code can be handled in reverse
7125 by simply continuing to single-step. We have already
7126 executed the solib function (backwards), and a few
7127 steps will take us back through the trampoline to the
7133 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
7135 /* We're doing a "next".
7137 Normal (forward) execution: set a breakpoint at the
7138 callee's return address (the address at which the caller
7141 Reverse (backward) execution. set the step-resume
7142 breakpoint at the start of the function that we just
7143 stepped into (backwards), and continue to there. When we
7144 get there, we'll need to single-step back to the caller. */
7146 if (execution_direction
== EXEC_REVERSE
)
7148 /* If we're already at the start of the function, we've either
7149 just stepped backward into a single instruction function,
7150 or stepped back out of a signal handler to the first instruction
7151 of the function. Just keep going, which will single-step back
7153 if (ecs
->stop_func_start
!= stop_pc
&& ecs
->stop_func_start
!= 0)
7155 /* Normal function call return (static or dynamic). */
7156 symtab_and_line sr_sal
;
7157 sr_sal
.pc
= ecs
->stop_func_start
;
7158 sr_sal
.pspace
= get_frame_program_space (frame
);
7159 insert_step_resume_breakpoint_at_sal (gdbarch
,
7160 sr_sal
, null_frame_id
);
7164 insert_step_resume_breakpoint_at_caller (frame
);
7170 /* If we are in a function call trampoline (a stub between the
7171 calling routine and the real function), locate the real
7172 function. That's what tells us (a) whether we want to step
7173 into it at all, and (b) what prologue we want to run to the
7174 end of, if we do step into it. */
7175 real_stop_pc
= skip_language_trampoline (frame
, stop_pc
);
7176 if (real_stop_pc
== 0)
7177 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
7178 if (real_stop_pc
!= 0)
7179 ecs
->stop_func_start
= real_stop_pc
;
7181 if (real_stop_pc
!= 0 && in_solib_dynsym_resolve_code (real_stop_pc
))
7183 symtab_and_line sr_sal
;
7184 sr_sal
.pc
= ecs
->stop_func_start
;
7185 sr_sal
.pspace
= get_frame_program_space (frame
);
7187 insert_step_resume_breakpoint_at_sal (gdbarch
,
7188 sr_sal
, null_frame_id
);
7193 /* If we have line number information for the function we are
7194 thinking of stepping into and the function isn't on the skip
7197 If there are several symtabs at that PC (e.g. with include
7198 files), just want to know whether *any* of them have line
7199 numbers. find_pc_line handles this. */
7201 struct symtab_and_line tmp_sal
;
7203 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
7204 if (tmp_sal
.line
!= 0
7205 && !function_name_is_marked_for_skip (ecs
->stop_func_name
,
7207 && !inline_frame_is_marked_for_skip (true, ecs
->event_thread
))
7209 if (execution_direction
== EXEC_REVERSE
)
7210 handle_step_into_function_backward (gdbarch
, ecs
);
7212 handle_step_into_function (gdbarch
, ecs
);
7217 /* If we have no line number and the step-stop-if-no-debug is
7218 set, we stop the step so that the user has a chance to switch
7219 in assembly mode. */
7220 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
7221 && step_stop_if_no_debug
)
7223 end_stepping_range (ecs
);
7227 if (execution_direction
== EXEC_REVERSE
)
7229 /* If we're already at the start of the function, we've either just
7230 stepped backward into a single instruction function without line
7231 number info, or stepped back out of a signal handler to the first
7232 instruction of the function without line number info. Just keep
7233 going, which will single-step back to the caller. */
7234 if (ecs
->stop_func_start
!= stop_pc
)
7236 /* Set a breakpoint at callee's start address.
7237 From there we can step once and be back in the caller. */
7238 symtab_and_line sr_sal
;
7239 sr_sal
.pc
= ecs
->stop_func_start
;
7240 sr_sal
.pspace
= get_frame_program_space (frame
);
7241 insert_step_resume_breakpoint_at_sal (gdbarch
,
7242 sr_sal
, null_frame_id
);
7246 /* Set a breakpoint at callee's return address (the address
7247 at which the caller will resume). */
7248 insert_step_resume_breakpoint_at_caller (frame
);
7254 /* Reverse stepping through solib trampolines. */
7256 if (execution_direction
== EXEC_REVERSE
7257 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
7259 CORE_ADDR stop_pc
= ecs
->event_thread
->suspend
.stop_pc
;
7261 if (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
7262 || (ecs
->stop_func_start
== 0
7263 && in_solib_dynsym_resolve_code (stop_pc
)))
7265 /* Any solib trampoline code can be handled in reverse
7266 by simply continuing to single-step. We have already
7267 executed the solib function (backwards), and a few
7268 steps will take us back through the trampoline to the
7273 else if (in_solib_dynsym_resolve_code (stop_pc
))
7275 /* Stepped backward into the solib dynsym resolver.
7276 Set a breakpoint at its start and continue, then
7277 one more step will take us out. */
7278 symtab_and_line sr_sal
;
7279 sr_sal
.pc
= ecs
->stop_func_start
;
7280 sr_sal
.pspace
= get_frame_program_space (frame
);
7281 insert_step_resume_breakpoint_at_sal (gdbarch
,
7282 sr_sal
, null_frame_id
);
7288 /* This always returns the sal for the inner-most frame when we are in a
7289 stack of inlined frames, even if GDB actually believes that it is in a
7290 more outer frame. This is checked for below by calls to
7291 inline_skipped_frames. */
7292 stop_pc_sal
= find_pc_line (ecs
->event_thread
->suspend
.stop_pc
, 0);
7294 /* NOTE: tausq/2004-05-24: This if block used to be done before all
7295 the trampoline processing logic, however, there are some trampolines
7296 that have no names, so we should do trampoline handling first. */
7297 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
7298 && ecs
->stop_func_name
== NULL
7299 && stop_pc_sal
.line
== 0)
7301 infrun_debug_printf ("stepped into undebuggable function");
7303 /* The inferior just stepped into, or returned to, an
7304 undebuggable function (where there is no debugging information
7305 and no line number corresponding to the address where the
7306 inferior stopped). Since we want to skip this kind of code,
7307 we keep going until the inferior returns from this
7308 function - unless the user has asked us not to (via
7309 set step-mode) or we no longer know how to get back
7310 to the call site. */
7311 if (step_stop_if_no_debug
7312 || !frame_id_p (frame_unwind_caller_id (frame
)))
7314 /* If we have no line number and the step-stop-if-no-debug
7315 is set, we stop the step so that the user has a chance to
7316 switch in assembly mode. */
7317 end_stepping_range (ecs
);
7322 /* Set a breakpoint at callee's return address (the address
7323 at which the caller will resume). */
7324 insert_step_resume_breakpoint_at_caller (frame
);
7330 if (ecs
->event_thread
->control
.step_range_end
== 1)
7332 /* It is stepi or nexti. We always want to stop stepping after
7334 infrun_debug_printf ("stepi/nexti");
7335 end_stepping_range (ecs
);
7339 if (stop_pc_sal
.line
== 0)
7341 /* We have no line number information. That means to stop
7342 stepping (does this always happen right after one instruction,
7343 when we do "s" in a function with no line numbers,
7344 or can this happen as a result of a return or longjmp?). */
7345 infrun_debug_printf ("line number info");
7346 end_stepping_range (ecs
);
7350 /* Look for "calls" to inlined functions, part one. If the inline
7351 frame machinery detected some skipped call sites, we have entered
7352 a new inline function. */
7354 if (frame_id_eq (get_frame_id (get_current_frame ()),
7355 ecs
->event_thread
->control
.step_frame_id
)
7356 && inline_skipped_frames (ecs
->event_thread
))
7358 infrun_debug_printf ("stepped into inlined function");
7360 symtab_and_line call_sal
= find_frame_sal (get_current_frame ());
7362 if (ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_ALL
)
7364 /* For "step", we're going to stop. But if the call site
7365 for this inlined function is on the same source line as
7366 we were previously stepping, go down into the function
7367 first. Otherwise stop at the call site. */
7369 if (call_sal
.line
== ecs
->event_thread
->current_line
7370 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
7372 step_into_inline_frame (ecs
->event_thread
);
7373 if (inline_frame_is_marked_for_skip (false, ecs
->event_thread
))
7380 end_stepping_range (ecs
);
7385 /* For "next", we should stop at the call site if it is on a
7386 different source line. Otherwise continue through the
7387 inlined function. */
7388 if (call_sal
.line
== ecs
->event_thread
->current_line
7389 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
7392 end_stepping_range (ecs
);
7397 /* Look for "calls" to inlined functions, part two. If we are still
7398 in the same real function we were stepping through, but we have
7399 to go further up to find the exact frame ID, we are stepping
7400 through a more inlined call beyond its call site. */
7402 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
7403 && !frame_id_eq (get_frame_id (get_current_frame ()),
7404 ecs
->event_thread
->control
.step_frame_id
)
7405 && stepped_in_from (get_current_frame (),
7406 ecs
->event_thread
->control
.step_frame_id
))
7408 infrun_debug_printf ("stepping through inlined function");
7410 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
7411 || inline_frame_is_marked_for_skip (false, ecs
->event_thread
))
7414 end_stepping_range (ecs
);
7418 bool refresh_step_info
= true;
7419 if ((ecs
->event_thread
->suspend
.stop_pc
== stop_pc_sal
.pc
)
7420 && (ecs
->event_thread
->current_line
!= stop_pc_sal
.line
7421 || ecs
->event_thread
->current_symtab
!= stop_pc_sal
.symtab
))
7423 /* We are at a different line. */
7425 if (stop_pc_sal
.is_stmt
)
7427 /* We are at the start of a statement.
7429 So stop. Note that we don't stop if we step into the middle of a
7430 statement. That is said to make things like for (;;) statements
7432 infrun_debug_printf ("stepped to a different line");
7433 end_stepping_range (ecs
);
7436 else if (frame_id_eq (get_frame_id (get_current_frame ()),
7437 ecs
->event_thread
->control
.step_frame_id
))
7439 /* We are not at the start of a statement, and we have not changed
7442 We ignore this line table entry, and continue stepping forward,
7443 looking for a better place to stop. */
7444 refresh_step_info
= false;
7445 infrun_debug_printf ("stepped to a different line, but "
7446 "it's not the start of a statement");
7450 /* We are not the start of a statement, and we have changed frame.
7452 We ignore this line table entry, and continue stepping forward,
7453 looking for a better place to stop. Keep refresh_step_info at
7454 true to note that the frame has changed, but ignore the line
7455 number to make sure we don't ignore a subsequent entry with the
7456 same line number. */
7457 stop_pc_sal
.line
= 0;
7458 infrun_debug_printf ("stepped to a different frame, but "
7459 "it's not the start of a statement");
7463 /* We aren't done stepping.
7465 Optimize by setting the stepping range to the line.
7466 (We might not be in the original line, but if we entered a
7467 new line in mid-statement, we continue stepping. This makes
7468 things like for(;;) statements work better.)
7470 If we entered a SAL that indicates a non-statement line table entry,
7471 then we update the stepping range, but we don't update the step info,
7472 which includes things like the line number we are stepping away from.
7473 This means we will stop when we find a line table entry that is marked
7474 as is-statement, even if it matches the non-statement one we just
7477 ecs
->event_thread
->control
.step_range_start
= stop_pc_sal
.pc
;
7478 ecs
->event_thread
->control
.step_range_end
= stop_pc_sal
.end
;
7479 ecs
->event_thread
->control
.may_range_step
= 1;
7480 if (refresh_step_info
)
7481 set_step_info (ecs
->event_thread
, frame
, stop_pc_sal
);
7483 infrun_debug_printf ("keep going");
7487 static bool restart_stepped_thread (process_stratum_target
*resume_target
,
7488 ptid_t resume_ptid
);
7490 /* In all-stop mode, if we're currently stepping but have stopped in
7491 some other thread, we may need to switch back to the stepped
7492 thread. Returns true we set the inferior running, false if we left
7493 it stopped (and the event needs further processing). */
7496 switch_back_to_stepped_thread (struct execution_control_state
*ecs
)
7498 if (!target_is_non_stop_p ())
7500 /* If any thread is blocked on some internal breakpoint, and we
7501 simply need to step over that breakpoint to get it going
7502 again, do that first. */
7504 /* However, if we see an event for the stepping thread, then we
7505 know all other threads have been moved past their breakpoints
7506 already. Let the caller check whether the step is finished,
7507 etc., before deciding to move it past a breakpoint. */
7508 if (ecs
->event_thread
->control
.step_range_end
!= 0)
7511 /* Check if the current thread is blocked on an incomplete
7512 step-over, interrupted by a random signal. */
7513 if (ecs
->event_thread
->control
.trap_expected
7514 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_TRAP
)
7517 ("need to finish step-over of [%s]",
7518 target_pid_to_str (ecs
->event_thread
->ptid
).c_str ());
7523 /* Check if the current thread is blocked by a single-step
7524 breakpoint of another thread. */
7525 if (ecs
->hit_singlestep_breakpoint
)
7527 infrun_debug_printf ("need to step [%s] over single-step breakpoint",
7528 target_pid_to_str (ecs
->ptid
).c_str ());
7533 /* If this thread needs yet another step-over (e.g., stepping
7534 through a delay slot), do it first before moving on to
7536 if (thread_still_needs_step_over (ecs
->event_thread
))
7539 ("thread [%s] still needs step-over",
7540 target_pid_to_str (ecs
->event_thread
->ptid
).c_str ());
7545 /* If scheduler locking applies even if not stepping, there's no
7546 need to walk over threads. Above we've checked whether the
7547 current thread is stepping. If some other thread not the
7548 event thread is stepping, then it must be that scheduler
7549 locking is not in effect. */
7550 if (schedlock_applies (ecs
->event_thread
))
7553 /* Otherwise, we no longer expect a trap in the current thread.
7554 Clear the trap_expected flag before switching back -- this is
7555 what keep_going does as well, if we call it. */
7556 ecs
->event_thread
->control
.trap_expected
= 0;
7558 /* Likewise, clear the signal if it should not be passed. */
7559 if (!signal_program
[ecs
->event_thread
->suspend
.stop_signal
])
7560 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
7562 if (restart_stepped_thread (ecs
->target
, ecs
->ptid
))
7564 prepare_to_wait (ecs
);
7568 switch_to_thread (ecs
->event_thread
);
7574 /* Look for the thread that was stepping, and resume it.
7575 RESUME_TARGET / RESUME_PTID indicate the set of threads the caller
7576 is resuming. Return true if a thread was started, false
7580 restart_stepped_thread (process_stratum_target
*resume_target
,
7583 /* Do all pending step-overs before actually proceeding with
7585 if (start_step_over ())
7588 for (thread_info
*tp
: all_threads_safe ())
7590 if (tp
->state
== THREAD_EXITED
)
7593 if (tp
->suspend
.waitstatus_pending_p
)
7596 /* Ignore threads of processes the caller is not
7599 && (tp
->inf
->process_target () != resume_target
7600 || tp
->inf
->pid
!= resume_ptid
.pid ()))
7603 if (tp
->control
.trap_expected
)
7605 infrun_debug_printf ("switching back to stepped thread (step-over)");
7607 if (keep_going_stepped_thread (tp
))
7612 for (thread_info
*tp
: all_threads_safe ())
7614 if (tp
->state
== THREAD_EXITED
)
7617 if (tp
->suspend
.waitstatus_pending_p
)
7620 /* Ignore threads of processes the caller is not
7623 && (tp
->inf
->process_target () != resume_target
7624 || tp
->inf
->pid
!= resume_ptid
.pid ()))
7627 /* Did we find the stepping thread? */
7628 if (tp
->control
.step_range_end
)
7630 infrun_debug_printf ("switching back to stepped thread (stepping)");
7632 if (keep_going_stepped_thread (tp
))
7643 restart_after_all_stop_detach (process_stratum_target
*proc_target
)
7645 /* Note we don't check target_is_non_stop_p() here, because the
7646 current inferior may no longer have a process_stratum target
7647 pushed, as we just detached. */
7649 /* See if we have a THREAD_RUNNING thread that need to be
7650 re-resumed. If we have any thread that is already executing,
7651 then we don't need to resume the target -- it is already been
7652 resumed. With the remote target (in all-stop), it's even
7653 impossible to issue another resumption if the target is already
7654 resumed, until the target reports a stop. */
7655 for (thread_info
*thr
: all_threads (proc_target
))
7657 if (thr
->state
!= THREAD_RUNNING
)
7660 /* If we have any thread that is already executing, then we
7661 don't need to resume the target -- it is already been
7666 /* If we have a pending event to process, skip resuming the
7667 target and go straight to processing it. */
7668 if (thr
->resumed
&& thr
->suspend
.waitstatus_pending_p
)
7672 /* Alright, we need to re-resume the target. If a thread was
7673 stepping, we need to restart it stepping. */
7674 if (restart_stepped_thread (proc_target
, minus_one_ptid
))
7677 /* Otherwise, find the first THREAD_RUNNING thread and resume
7679 for (thread_info
*thr
: all_threads (proc_target
))
7681 if (thr
->state
!= THREAD_RUNNING
)
7684 execution_control_state ecs
;
7685 reset_ecs (&ecs
, thr
);
7686 switch_to_thread (thr
);
7692 /* Set a previously stepped thread back to stepping. Returns true on
7693 success, false if the resume is not possible (e.g., the thread
7697 keep_going_stepped_thread (struct thread_info
*tp
)
7699 struct frame_info
*frame
;
7700 struct execution_control_state ecss
;
7701 struct execution_control_state
*ecs
= &ecss
;
7703 /* If the stepping thread exited, then don't try to switch back and
7704 resume it, which could fail in several different ways depending
7705 on the target. Instead, just keep going.
7707 We can find a stepping dead thread in the thread list in two
7710 - The target supports thread exit events, and when the target
7711 tries to delete the thread from the thread list, inferior_ptid
7712 pointed at the exiting thread. In such case, calling
7713 delete_thread does not really remove the thread from the list;
7714 instead, the thread is left listed, with 'exited' state.
7716 - The target's debug interface does not support thread exit
7717 events, and so we have no idea whatsoever if the previously
7718 stepping thread is still alive. For that reason, we need to
7719 synchronously query the target now. */
7721 if (tp
->state
== THREAD_EXITED
|| !target_thread_alive (tp
->ptid
))
7723 infrun_debug_printf ("not resuming previously stepped thread, it has "
7730 infrun_debug_printf ("resuming previously stepped thread");
7732 reset_ecs (ecs
, tp
);
7733 switch_to_thread (tp
);
7735 tp
->suspend
.stop_pc
= regcache_read_pc (get_thread_regcache (tp
));
7736 frame
= get_current_frame ();
7738 /* If the PC of the thread we were trying to single-step has
7739 changed, then that thread has trapped or been signaled, but the
7740 event has not been reported to GDB yet. Re-poll the target
7741 looking for this particular thread's event (i.e. temporarily
7742 enable schedlock) by:
7744 - setting a break at the current PC
7745 - resuming that particular thread, only (by setting trap
7748 This prevents us continuously moving the single-step breakpoint
7749 forward, one instruction at a time, overstepping. */
7751 if (tp
->suspend
.stop_pc
!= tp
->prev_pc
)
7755 infrun_debug_printf ("expected thread advanced also (%s -> %s)",
7756 paddress (target_gdbarch (), tp
->prev_pc
),
7757 paddress (target_gdbarch (), tp
->suspend
.stop_pc
));
7759 /* Clear the info of the previous step-over, as it's no longer
7760 valid (if the thread was trying to step over a breakpoint, it
7761 has already succeeded). It's what keep_going would do too,
7762 if we called it. Do this before trying to insert the sss
7763 breakpoint, otherwise if we were previously trying to step
7764 over this exact address in another thread, the breakpoint is
7766 clear_step_over_info ();
7767 tp
->control
.trap_expected
= 0;
7769 insert_single_step_breakpoint (get_frame_arch (frame
),
7770 get_frame_address_space (frame
),
7771 tp
->suspend
.stop_pc
);
7774 resume_ptid
= internal_resume_ptid (tp
->control
.stepping_command
);
7775 do_target_resume (resume_ptid
, false, GDB_SIGNAL_0
);
7779 infrun_debug_printf ("expected thread still hasn't advanced");
7781 keep_going_pass_signal (ecs
);
7787 /* Is thread TP in the middle of (software or hardware)
7788 single-stepping? (Note the result of this function must never be
7789 passed directly as target_resume's STEP parameter.) */
7792 currently_stepping (struct thread_info
*tp
)
7794 return ((tp
->control
.step_range_end
7795 && tp
->control
.step_resume_breakpoint
== NULL
)
7796 || tp
->control
.trap_expected
7797 || tp
->stepped_breakpoint
7798 || bpstat_should_step ());
7801 /* Inferior has stepped into a subroutine call with source code that
7802 we should not step over. Do step to the first line of code in
7806 handle_step_into_function (struct gdbarch
*gdbarch
,
7807 struct execution_control_state
*ecs
)
7809 fill_in_stop_func (gdbarch
, ecs
);
7811 compunit_symtab
*cust
7812 = find_pc_compunit_symtab (ecs
->event_thread
->suspend
.stop_pc
);
7813 if (cust
!= NULL
&& compunit_language (cust
) != language_asm
)
7814 ecs
->stop_func_start
7815 = gdbarch_skip_prologue_noexcept (gdbarch
, ecs
->stop_func_start
);
7817 symtab_and_line stop_func_sal
= find_pc_line (ecs
->stop_func_start
, 0);
7818 /* Use the step_resume_break to step until the end of the prologue,
7819 even if that involves jumps (as it seems to on the vax under
7821 /* If the prologue ends in the middle of a source line, continue to
7822 the end of that source line (if it is still within the function).
7823 Otherwise, just go to end of prologue. */
7824 if (stop_func_sal
.end
7825 && stop_func_sal
.pc
!= ecs
->stop_func_start
7826 && stop_func_sal
.end
< ecs
->stop_func_end
)
7827 ecs
->stop_func_start
= stop_func_sal
.end
;
7829 /* Architectures which require breakpoint adjustment might not be able
7830 to place a breakpoint at the computed address. If so, the test
7831 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
7832 ecs->stop_func_start to an address at which a breakpoint may be
7833 legitimately placed.
7835 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
7836 made, GDB will enter an infinite loop when stepping through
7837 optimized code consisting of VLIW instructions which contain
7838 subinstructions corresponding to different source lines. On
7839 FR-V, it's not permitted to place a breakpoint on any but the
7840 first subinstruction of a VLIW instruction. When a breakpoint is
7841 set, GDB will adjust the breakpoint address to the beginning of
7842 the VLIW instruction. Thus, we need to make the corresponding
7843 adjustment here when computing the stop address. */
7845 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
7847 ecs
->stop_func_start
7848 = gdbarch_adjust_breakpoint_address (gdbarch
,
7849 ecs
->stop_func_start
);
7852 if (ecs
->stop_func_start
== ecs
->event_thread
->suspend
.stop_pc
)
7854 /* We are already there: stop now. */
7855 end_stepping_range (ecs
);
7860 /* Put the step-breakpoint there and go until there. */
7861 symtab_and_line sr_sal
;
7862 sr_sal
.pc
= ecs
->stop_func_start
;
7863 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
7864 sr_sal
.pspace
= get_frame_program_space (get_current_frame ());
7866 /* Do not specify what the fp should be when we stop since on
7867 some machines the prologue is where the new fp value is
7869 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
, null_frame_id
);
7871 /* And make sure stepping stops right away then. */
7872 ecs
->event_thread
->control
.step_range_end
7873 = ecs
->event_thread
->control
.step_range_start
;
7878 /* Inferior has stepped backward into a subroutine call with source
7879 code that we should not step over. Do step to the beginning of the
7880 last line of code in it. */
7883 handle_step_into_function_backward (struct gdbarch
*gdbarch
,
7884 struct execution_control_state
*ecs
)
7886 struct compunit_symtab
*cust
;
7887 struct symtab_and_line stop_func_sal
;
7889 fill_in_stop_func (gdbarch
, ecs
);
7891 cust
= find_pc_compunit_symtab (ecs
->event_thread
->suspend
.stop_pc
);
7892 if (cust
!= NULL
&& compunit_language (cust
) != language_asm
)
7893 ecs
->stop_func_start
7894 = gdbarch_skip_prologue_noexcept (gdbarch
, ecs
->stop_func_start
);
7896 stop_func_sal
= find_pc_line (ecs
->event_thread
->suspend
.stop_pc
, 0);
7898 /* OK, we're just going to keep stepping here. */
7899 if (stop_func_sal
.pc
== ecs
->event_thread
->suspend
.stop_pc
)
7901 /* We're there already. Just stop stepping now. */
7902 end_stepping_range (ecs
);
7906 /* Else just reset the step range and keep going.
7907 No step-resume breakpoint, they don't work for
7908 epilogues, which can have multiple entry paths. */
7909 ecs
->event_thread
->control
.step_range_start
= stop_func_sal
.pc
;
7910 ecs
->event_thread
->control
.step_range_end
= stop_func_sal
.end
;
7916 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
7917 This is used to both functions and to skip over code. */
7920 insert_step_resume_breakpoint_at_sal_1 (struct gdbarch
*gdbarch
,
7921 struct symtab_and_line sr_sal
,
7922 struct frame_id sr_id
,
7923 enum bptype sr_type
)
7925 /* There should never be more than one step-resume or longjmp-resume
7926 breakpoint per thread, so we should never be setting a new
7927 step_resume_breakpoint when one is already active. */
7928 gdb_assert (inferior_thread ()->control
.step_resume_breakpoint
== NULL
);
7929 gdb_assert (sr_type
== bp_step_resume
|| sr_type
== bp_hp_step_resume
);
7931 infrun_debug_printf ("inserting step-resume breakpoint at %s",
7932 paddress (gdbarch
, sr_sal
.pc
));
7934 inferior_thread ()->control
.step_resume_breakpoint
7935 = set_momentary_breakpoint (gdbarch
, sr_sal
, sr_id
, sr_type
).release ();
7939 insert_step_resume_breakpoint_at_sal (struct gdbarch
*gdbarch
,
7940 struct symtab_and_line sr_sal
,
7941 struct frame_id sr_id
)
7943 insert_step_resume_breakpoint_at_sal_1 (gdbarch
,
7948 /* Insert a "high-priority step-resume breakpoint" at RETURN_FRAME.pc.
7949 This is used to skip a potential signal handler.
7951 This is called with the interrupted function's frame. The signal
7952 handler, when it returns, will resume the interrupted function at
7956 insert_hp_step_resume_breakpoint_at_frame (struct frame_info
*return_frame
)
7958 gdb_assert (return_frame
!= NULL
);
7960 struct gdbarch
*gdbarch
= get_frame_arch (return_frame
);
7962 symtab_and_line sr_sal
;
7963 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
, get_frame_pc (return_frame
));
7964 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
7965 sr_sal
.pspace
= get_frame_program_space (return_frame
);
7967 insert_step_resume_breakpoint_at_sal_1 (gdbarch
, sr_sal
,
7968 get_stack_frame_id (return_frame
),
7972 /* Insert a "step-resume breakpoint" at the previous frame's PC. This
7973 is used to skip a function after stepping into it (for "next" or if
7974 the called function has no debugging information).
7976 The current function has almost always been reached by single
7977 stepping a call or return instruction. NEXT_FRAME belongs to the
7978 current function, and the breakpoint will be set at the caller's
7981 This is a separate function rather than reusing
7982 insert_hp_step_resume_breakpoint_at_frame in order to avoid
7983 get_prev_frame, which may stop prematurely (see the implementation
7984 of frame_unwind_caller_id for an example). */
7987 insert_step_resume_breakpoint_at_caller (struct frame_info
*next_frame
)
7989 /* We shouldn't have gotten here if we don't know where the call site
7991 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame
)));
7993 struct gdbarch
*gdbarch
= frame_unwind_caller_arch (next_frame
);
7995 symtab_and_line sr_sal
;
7996 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
,
7997 frame_unwind_caller_pc (next_frame
));
7998 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
7999 sr_sal
.pspace
= frame_unwind_program_space (next_frame
);
8001 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
,
8002 frame_unwind_caller_id (next_frame
));
8005 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
8006 new breakpoint at the target of a jmp_buf. The handling of
8007 longjmp-resume uses the same mechanisms used for handling
8008 "step-resume" breakpoints. */
8011 insert_longjmp_resume_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
8013 /* There should never be more than one longjmp-resume breakpoint per
8014 thread, so we should never be setting a new
8015 longjmp_resume_breakpoint when one is already active. */
8016 gdb_assert (inferior_thread ()->control
.exception_resume_breakpoint
== NULL
);
8018 infrun_debug_printf ("inserting longjmp-resume breakpoint at %s",
8019 paddress (gdbarch
, pc
));
8021 inferior_thread ()->control
.exception_resume_breakpoint
=
8022 set_momentary_breakpoint_at_pc (gdbarch
, pc
, bp_longjmp_resume
).release ();
8025 /* Insert an exception resume breakpoint. TP is the thread throwing
8026 the exception. The block B is the block of the unwinder debug hook
8027 function. FRAME is the frame corresponding to the call to this
8028 function. SYM is the symbol of the function argument holding the
8029 target PC of the exception. */
8032 insert_exception_resume_breakpoint (struct thread_info
*tp
,
8033 const struct block
*b
,
8034 struct frame_info
*frame
,
8039 struct block_symbol vsym
;
8040 struct value
*value
;
8042 struct breakpoint
*bp
;
8044 vsym
= lookup_symbol_search_name (sym
->search_name (),
8046 value
= read_var_value (vsym
.symbol
, vsym
.block
, frame
);
8047 /* If the value was optimized out, revert to the old behavior. */
8048 if (! value_optimized_out (value
))
8050 handler
= value_as_address (value
);
8052 infrun_debug_printf ("exception resume at %lx",
8053 (unsigned long) handler
);
8055 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
8057 bp_exception_resume
).release ();
8059 /* set_momentary_breakpoint_at_pc invalidates FRAME. */
8062 bp
->thread
= tp
->global_num
;
8063 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
8066 catch (const gdb_exception_error
&e
)
8068 /* We want to ignore errors here. */
8072 /* A helper for check_exception_resume that sets an
8073 exception-breakpoint based on a SystemTap probe. */
8076 insert_exception_resume_from_probe (struct thread_info
*tp
,
8077 const struct bound_probe
*probe
,
8078 struct frame_info
*frame
)
8080 struct value
*arg_value
;
8082 struct breakpoint
*bp
;
8084 arg_value
= probe_safe_evaluate_at_pc (frame
, 1);
8088 handler
= value_as_address (arg_value
);
8090 infrun_debug_printf ("exception resume at %s",
8091 paddress (probe
->objfile
->arch (), handler
));
8093 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
8094 handler
, bp_exception_resume
).release ();
8095 bp
->thread
= tp
->global_num
;
8096 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
8099 /* This is called when an exception has been intercepted. Check to
8100 see whether the exception's destination is of interest, and if so,
8101 set an exception resume breakpoint there. */
8104 check_exception_resume (struct execution_control_state
*ecs
,
8105 struct frame_info
*frame
)
8107 struct bound_probe probe
;
8108 struct symbol
*func
;
8110 /* First see if this exception unwinding breakpoint was set via a
8111 SystemTap probe point. If so, the probe has two arguments: the
8112 CFA and the HANDLER. We ignore the CFA, extract the handler, and
8113 set a breakpoint there. */
8114 probe
= find_probe_by_pc (get_frame_pc (frame
));
8117 insert_exception_resume_from_probe (ecs
->event_thread
, &probe
, frame
);
8121 func
= get_frame_function (frame
);
8127 const struct block
*b
;
8128 struct block_iterator iter
;
8132 /* The exception breakpoint is a thread-specific breakpoint on
8133 the unwinder's debug hook, declared as:
8135 void _Unwind_DebugHook (void *cfa, void *handler);
8137 The CFA argument indicates the frame to which control is
8138 about to be transferred. HANDLER is the destination PC.
8140 We ignore the CFA and set a temporary breakpoint at HANDLER.
8141 This is not extremely efficient but it avoids issues in gdb
8142 with computing the DWARF CFA, and it also works even in weird
8143 cases such as throwing an exception from inside a signal
8146 b
= SYMBOL_BLOCK_VALUE (func
);
8147 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
8149 if (!SYMBOL_IS_ARGUMENT (sym
))
8156 insert_exception_resume_breakpoint (ecs
->event_thread
,
8162 catch (const gdb_exception_error
&e
)
8168 stop_waiting (struct execution_control_state
*ecs
)
8170 infrun_debug_printf ("stop_waiting");
8172 /* Let callers know we don't want to wait for the inferior anymore. */
8173 ecs
->wait_some_more
= 0;
8175 /* If all-stop, but there exists a non-stop target, stop all
8176 threads now that we're presenting the stop to the user. */
8177 if (!non_stop
&& exists_non_stop_target ())
8178 stop_all_threads ("presenting stop to user in all-stop");
8181 /* Like keep_going, but passes the signal to the inferior, even if the
8182 signal is set to nopass. */
8185 keep_going_pass_signal (struct execution_control_state
*ecs
)
8187 gdb_assert (ecs
->event_thread
->ptid
== inferior_ptid
);
8188 gdb_assert (!ecs
->event_thread
->resumed
);
8190 /* Save the pc before execution, to compare with pc after stop. */
8191 ecs
->event_thread
->prev_pc
8192 = regcache_read_pc_protected (get_thread_regcache (ecs
->event_thread
));
8194 if (ecs
->event_thread
->control
.trap_expected
)
8196 struct thread_info
*tp
= ecs
->event_thread
;
8198 infrun_debug_printf ("%s has trap_expected set, "
8199 "resuming to collect trap",
8200 target_pid_to_str (tp
->ptid
).c_str ());
8202 /* We haven't yet gotten our trap, and either: intercepted a
8203 non-signal event (e.g., a fork); or took a signal which we
8204 are supposed to pass through to the inferior. Simply
8206 resume (ecs
->event_thread
->suspend
.stop_signal
);
8208 else if (step_over_info_valid_p ())
8210 /* Another thread is stepping over a breakpoint in-line. If
8211 this thread needs a step-over too, queue the request. In
8212 either case, this resume must be deferred for later. */
8213 struct thread_info
*tp
= ecs
->event_thread
;
8215 if (ecs
->hit_singlestep_breakpoint
8216 || thread_still_needs_step_over (tp
))
8218 infrun_debug_printf ("step-over already in progress: "
8219 "step-over for %s deferred",
8220 target_pid_to_str (tp
->ptid
).c_str ());
8221 global_thread_step_over_chain_enqueue (tp
);
8225 infrun_debug_printf ("step-over in progress: resume of %s deferred",
8226 target_pid_to_str (tp
->ptid
).c_str ());
8231 struct regcache
*regcache
= get_current_regcache ();
8234 step_over_what step_what
;
8236 /* Either the trap was not expected, but we are continuing
8237 anyway (if we got a signal, the user asked it be passed to
8240 We got our expected trap, but decided we should resume from
8243 We're going to run this baby now!
8245 Note that insert_breakpoints won't try to re-insert
8246 already inserted breakpoints. Therefore, we don't
8247 care if breakpoints were already inserted, or not. */
8249 /* If we need to step over a breakpoint, and we're not using
8250 displaced stepping to do so, insert all breakpoints
8251 (watchpoints, etc.) but the one we're stepping over, step one
8252 instruction, and then re-insert the breakpoint when that step
8255 step_what
= thread_still_needs_step_over (ecs
->event_thread
);
8257 remove_bp
= (ecs
->hit_singlestep_breakpoint
8258 || (step_what
& STEP_OVER_BREAKPOINT
));
8259 remove_wps
= (step_what
& STEP_OVER_WATCHPOINT
);
8261 /* We can't use displaced stepping if we need to step past a
8262 watchpoint. The instruction copied to the scratch pad would
8263 still trigger the watchpoint. */
8265 && (remove_wps
|| !use_displaced_stepping (ecs
->event_thread
)))
8267 set_step_over_info (regcache
->aspace (),
8268 regcache_read_pc (regcache
), remove_wps
,
8269 ecs
->event_thread
->global_num
);
8271 else if (remove_wps
)
8272 set_step_over_info (NULL
, 0, remove_wps
, -1);
8274 /* If we now need to do an in-line step-over, we need to stop
8275 all other threads. Note this must be done before
8276 insert_breakpoints below, because that removes the breakpoint
8277 we're about to step over, otherwise other threads could miss
8279 if (step_over_info_valid_p () && target_is_non_stop_p ())
8280 stop_all_threads ("starting in-line step-over");
8282 /* Stop stepping if inserting breakpoints fails. */
8285 insert_breakpoints ();
8287 catch (const gdb_exception_error
&e
)
8289 exception_print (gdb_stderr
, e
);
8291 clear_step_over_info ();
8295 ecs
->event_thread
->control
.trap_expected
= (remove_bp
|| remove_wps
);
8297 resume (ecs
->event_thread
->suspend
.stop_signal
);
8300 prepare_to_wait (ecs
);
8303 /* Called when we should continue running the inferior, because the
8304 current event doesn't cause a user visible stop. This does the
8305 resuming part; waiting for the next event is done elsewhere. */
8308 keep_going (struct execution_control_state
*ecs
)
8310 if (ecs
->event_thread
->control
.trap_expected
8311 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
8312 ecs
->event_thread
->control
.trap_expected
= 0;
8314 if (!signal_program
[ecs
->event_thread
->suspend
.stop_signal
])
8315 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
8316 keep_going_pass_signal (ecs
);
8319 /* This function normally comes after a resume, before
8320 handle_inferior_event exits. It takes care of any last bits of
8321 housekeeping, and sets the all-important wait_some_more flag. */
8324 prepare_to_wait (struct execution_control_state
*ecs
)
8326 infrun_debug_printf ("prepare_to_wait");
8328 ecs
->wait_some_more
= 1;
8330 /* If the target can't async, emulate it by marking the infrun event
8331 handler such that as soon as we get back to the event-loop, we
8332 immediately end up in fetch_inferior_event again calling
8334 if (!target_can_async_p ())
8335 mark_infrun_async_event_handler ();
8338 /* We are done with the step range of a step/next/si/ni command.
8339 Called once for each n of a "step n" operation. */
8342 end_stepping_range (struct execution_control_state
*ecs
)
8344 ecs
->event_thread
->control
.stop_step
= 1;
8348 /* Several print_*_reason functions to print why the inferior has stopped.
8349 We always print something when the inferior exits, or receives a signal.
8350 The rest of the cases are dealt with later on in normal_stop and
8351 print_it_typical. Ideally there should be a call to one of these
8352 print_*_reason functions functions from handle_inferior_event each time
8353 stop_waiting is called.
8355 Note that we don't call these directly, instead we delegate that to
8356 the interpreters, through observers. Interpreters then call these
8357 with whatever uiout is right. */
8360 print_end_stepping_range_reason (struct ui_out
*uiout
)
8362 /* For CLI-like interpreters, print nothing. */
8364 if (uiout
->is_mi_like_p ())
8366 uiout
->field_string ("reason",
8367 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE
));
8372 print_signal_exited_reason (struct ui_out
*uiout
, enum gdb_signal siggnal
)
8374 annotate_signalled ();
8375 if (uiout
->is_mi_like_p ())
8377 ("reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED
));
8378 uiout
->text ("\nProgram terminated with signal ");
8379 annotate_signal_name ();
8380 uiout
->field_string ("signal-name",
8381 gdb_signal_to_name (siggnal
));
8382 annotate_signal_name_end ();
8384 annotate_signal_string ();
8385 uiout
->field_string ("signal-meaning",
8386 gdb_signal_to_string (siggnal
));
8387 annotate_signal_string_end ();
8388 uiout
->text (".\n");
8389 uiout
->text ("The program no longer exists.\n");
8393 print_exited_reason (struct ui_out
*uiout
, int exitstatus
)
8395 struct inferior
*inf
= current_inferior ();
8396 std::string pidstr
= target_pid_to_str (ptid_t (inf
->pid
));
8398 annotate_exited (exitstatus
);
8401 if (uiout
->is_mi_like_p ())
8402 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXITED
));
8403 std::string exit_code_str
8404 = string_printf ("0%o", (unsigned int) exitstatus
);
8405 uiout
->message ("[Inferior %s (%s) exited with code %pF]\n",
8406 plongest (inf
->num
), pidstr
.c_str (),
8407 string_field ("exit-code", exit_code_str
.c_str ()));
8411 if (uiout
->is_mi_like_p ())
8413 ("reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY
));
8414 uiout
->message ("[Inferior %s (%s) exited normally]\n",
8415 plongest (inf
->num
), pidstr
.c_str ());
8420 print_signal_received_reason (struct ui_out
*uiout
, enum gdb_signal siggnal
)
8422 struct thread_info
*thr
= inferior_thread ();
8426 if (uiout
->is_mi_like_p ())
8428 else if (show_thread_that_caused_stop ())
8432 uiout
->text ("\nThread ");
8433 uiout
->field_string ("thread-id", print_thread_id (thr
));
8435 name
= thr
->name
!= NULL
? thr
->name
: target_thread_name (thr
);
8438 uiout
->text (" \"");
8439 uiout
->field_string ("name", name
);
8444 uiout
->text ("\nProgram");
8446 if (siggnal
== GDB_SIGNAL_0
&& !uiout
->is_mi_like_p ())
8447 uiout
->text (" stopped");
8450 uiout
->text (" received signal ");
8451 annotate_signal_name ();
8452 if (uiout
->is_mi_like_p ())
8454 ("reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED
));
8455 uiout
->field_string ("signal-name", gdb_signal_to_name (siggnal
));
8456 annotate_signal_name_end ();
8458 annotate_signal_string ();
8459 uiout
->field_string ("signal-meaning", gdb_signal_to_string (siggnal
));
8461 struct regcache
*regcache
= get_current_regcache ();
8462 struct gdbarch
*gdbarch
= regcache
->arch ();
8463 if (gdbarch_report_signal_info_p (gdbarch
))
8464 gdbarch_report_signal_info (gdbarch
, uiout
, siggnal
);
8466 annotate_signal_string_end ();
8468 uiout
->text (".\n");
8472 print_no_history_reason (struct ui_out
*uiout
)
8474 uiout
->text ("\nNo more reverse-execution history.\n");
8477 /* Print current location without a level number, if we have changed
8478 functions or hit a breakpoint. Print source line if we have one.
8479 bpstat_print contains the logic deciding in detail what to print,
8480 based on the event(s) that just occurred. */
8483 print_stop_location (struct target_waitstatus
*ws
)
8486 enum print_what source_flag
;
8487 int do_frame_printing
= 1;
8488 struct thread_info
*tp
= inferior_thread ();
8490 bpstat_ret
= bpstat_print (tp
->control
.stop_bpstat
, ws
->kind
);
8494 /* FIXME: cagney/2002-12-01: Given that a frame ID does (or
8495 should) carry around the function and does (or should) use
8496 that when doing a frame comparison. */
8497 if (tp
->control
.stop_step
8498 && frame_id_eq (tp
->control
.step_frame_id
,
8499 get_frame_id (get_current_frame ()))
8500 && (tp
->control
.step_start_function
8501 == find_pc_function (tp
->suspend
.stop_pc
)))
8503 /* Finished step, just print source line. */
8504 source_flag
= SRC_LINE
;
8508 /* Print location and source line. */
8509 source_flag
= SRC_AND_LOC
;
8512 case PRINT_SRC_AND_LOC
:
8513 /* Print location and source line. */
8514 source_flag
= SRC_AND_LOC
;
8516 case PRINT_SRC_ONLY
:
8517 source_flag
= SRC_LINE
;
8520 /* Something bogus. */
8521 source_flag
= SRC_LINE
;
8522 do_frame_printing
= 0;
8525 internal_error (__FILE__
, __LINE__
, _("Unknown value."));
8528 /* The behavior of this routine with respect to the source
8530 SRC_LINE: Print only source line
8531 LOCATION: Print only location
8532 SRC_AND_LOC: Print location and source line. */
8533 if (do_frame_printing
)
8534 print_stack_frame (get_selected_frame (NULL
), 0, source_flag
, 1);
8540 print_stop_event (struct ui_out
*uiout
, bool displays
)
8542 struct target_waitstatus last
;
8543 struct thread_info
*tp
;
8545 get_last_target_status (nullptr, nullptr, &last
);
8548 scoped_restore save_uiout
= make_scoped_restore (¤t_uiout
, uiout
);
8550 print_stop_location (&last
);
8552 /* Display the auto-display expressions. */
8557 tp
= inferior_thread ();
8558 if (tp
->thread_fsm
!= NULL
8559 && tp
->thread_fsm
->finished_p ())
8561 struct return_value_info
*rv
;
8563 rv
= tp
->thread_fsm
->return_value ();
8565 print_return_value (uiout
, rv
);
8572 maybe_remove_breakpoints (void)
8574 if (!breakpoints_should_be_inserted_now () && target_has_execution ())
8576 if (remove_breakpoints ())
8578 target_terminal::ours_for_output ();
8579 printf_filtered (_("Cannot remove breakpoints because "
8580 "program is no longer writable.\nFurther "
8581 "execution is probably impossible.\n"));
8586 /* The execution context that just caused a normal stop. */
8592 DISABLE_COPY_AND_ASSIGN (stop_context
);
8594 bool changed () const;
8599 /* The event PTID. */
8603 /* If stopp for a thread event, this is the thread that caused the
8605 thread_info_ref thread
;
8607 /* The inferior that caused the stop. */
8611 /* Initializes a new stop context. If stopped for a thread event, this
8612 takes a strong reference to the thread. */
8614 stop_context::stop_context ()
8616 stop_id
= get_stop_id ();
8617 ptid
= inferior_ptid
;
8618 inf_num
= current_inferior ()->num
;
8620 if (inferior_ptid
!= null_ptid
)
8622 /* Take a strong reference so that the thread can't be deleted
8624 thread
= thread_info_ref::new_reference (inferior_thread ());
8628 /* Return true if the current context no longer matches the saved stop
8632 stop_context::changed () const
8634 if (ptid
!= inferior_ptid
)
8636 if (inf_num
!= current_inferior ()->num
)
8638 if (thread
!= NULL
&& thread
->state
!= THREAD_STOPPED
)
8640 if (get_stop_id () != stop_id
)
8650 struct target_waitstatus last
;
8652 get_last_target_status (nullptr, nullptr, &last
);
8656 /* If an exception is thrown from this point on, make sure to
8657 propagate GDB's knowledge of the executing state to the
8658 frontend/user running state. A QUIT is an easy exception to see
8659 here, so do this before any filtered output. */
8661 ptid_t finish_ptid
= null_ptid
;
8664 finish_ptid
= minus_one_ptid
;
8665 else if (last
.kind
== TARGET_WAITKIND_SIGNALLED
8666 || last
.kind
== TARGET_WAITKIND_EXITED
)
8668 /* On some targets, we may still have live threads in the
8669 inferior when we get a process exit event. E.g., for
8670 "checkpoint", when the current checkpoint/fork exits,
8671 linux-fork.c automatically switches to another fork from
8672 within target_mourn_inferior. */
8673 if (inferior_ptid
!= null_ptid
)
8674 finish_ptid
= ptid_t (inferior_ptid
.pid ());
8676 else if (last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
8677 finish_ptid
= inferior_ptid
;
8679 gdb::optional
<scoped_finish_thread_state
> maybe_finish_thread_state
;
8680 if (finish_ptid
!= null_ptid
)
8682 maybe_finish_thread_state
.emplace
8683 (user_visible_resume_target (finish_ptid
), finish_ptid
);
8686 /* As we're presenting a stop, and potentially removing breakpoints,
8687 update the thread list so we can tell whether there are threads
8688 running on the target. With target remote, for example, we can
8689 only learn about new threads when we explicitly update the thread
8690 list. Do this before notifying the interpreters about signal
8691 stops, end of stepping ranges, etc., so that the "new thread"
8692 output is emitted before e.g., "Program received signal FOO",
8693 instead of after. */
8694 update_thread_list ();
8696 if (last
.kind
== TARGET_WAITKIND_STOPPED
&& stopped_by_random_signal
)
8697 gdb::observers::signal_received
.notify (inferior_thread ()->suspend
.stop_signal
);
8699 /* As with the notification of thread events, we want to delay
8700 notifying the user that we've switched thread context until
8701 the inferior actually stops.
8703 There's no point in saying anything if the inferior has exited.
8704 Note that SIGNALLED here means "exited with a signal", not
8705 "received a signal".
8707 Also skip saying anything in non-stop mode. In that mode, as we
8708 don't want GDB to switch threads behind the user's back, to avoid
8709 races where the user is typing a command to apply to thread x,
8710 but GDB switches to thread y before the user finishes entering
8711 the command, fetch_inferior_event installs a cleanup to restore
8712 the current thread back to the thread the user had selected right
8713 after this event is handled, so we're not really switching, only
8714 informing of a stop. */
8716 && previous_inferior_ptid
!= inferior_ptid
8717 && target_has_execution ()
8718 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
8719 && last
.kind
!= TARGET_WAITKIND_EXITED
8720 && last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
8722 SWITCH_THRU_ALL_UIS ()
8724 target_terminal::ours_for_output ();
8725 printf_filtered (_("[Switching to %s]\n"),
8726 target_pid_to_str (inferior_ptid
).c_str ());
8727 annotate_thread_changed ();
8729 previous_inferior_ptid
= inferior_ptid
;
8732 if (last
.kind
== TARGET_WAITKIND_NO_RESUMED
)
8734 SWITCH_THRU_ALL_UIS ()
8735 if (current_ui
->prompt_state
== PROMPT_BLOCKED
)
8737 target_terminal::ours_for_output ();
8738 printf_filtered (_("No unwaited-for children left.\n"));
8742 /* Note: this depends on the update_thread_list call above. */
8743 maybe_remove_breakpoints ();
8745 /* If an auto-display called a function and that got a signal,
8746 delete that auto-display to avoid an infinite recursion. */
8748 if (stopped_by_random_signal
)
8749 disable_current_display ();
8751 SWITCH_THRU_ALL_UIS ()
8753 async_enable_stdin ();
8756 /* Let the user/frontend see the threads as stopped. */
8757 maybe_finish_thread_state
.reset ();
8759 /* Select innermost stack frame - i.e., current frame is frame 0,
8760 and current location is based on that. Handle the case where the
8761 dummy call is returning after being stopped. E.g. the dummy call
8762 previously hit a breakpoint. (If the dummy call returns
8763 normally, we won't reach here.) Do this before the stop hook is
8764 run, so that it doesn't get to see the temporary dummy frame,
8765 which is not where we'll present the stop. */
8766 if (has_stack_frames ())
8768 if (stop_stack_dummy
== STOP_STACK_DUMMY
)
8770 /* Pop the empty frame that contains the stack dummy. This
8771 also restores inferior state prior to the call (struct
8772 infcall_suspend_state). */
8773 struct frame_info
*frame
= get_current_frame ();
8775 gdb_assert (get_frame_type (frame
) == DUMMY_FRAME
);
8777 /* frame_pop calls reinit_frame_cache as the last thing it
8778 does which means there's now no selected frame. */
8781 select_frame (get_current_frame ());
8783 /* Set the current source location. */
8784 set_current_sal_from_frame (get_current_frame ());
8787 /* Look up the hook_stop and run it (CLI internally handles problem
8788 of stop_command's pre-hook not existing). */
8789 if (stop_command
!= NULL
)
8791 stop_context saved_context
;
8795 execute_cmd_pre_hook (stop_command
);
8797 catch (const gdb_exception
&ex
)
8799 exception_fprintf (gdb_stderr
, ex
,
8800 "Error while running hook_stop:\n");
8803 /* If the stop hook resumes the target, then there's no point in
8804 trying to notify about the previous stop; its context is
8805 gone. Likewise if the command switches thread or inferior --
8806 the observers would print a stop for the wrong
8808 if (saved_context
.changed ())
8812 /* Notify observers about the stop. This is where the interpreters
8813 print the stop event. */
8814 if (inferior_ptid
!= null_ptid
)
8815 gdb::observers::normal_stop
.notify (inferior_thread ()->control
.stop_bpstat
,
8818 gdb::observers::normal_stop
.notify (NULL
, stop_print_frame
);
8820 annotate_stopped ();
8822 if (target_has_execution ())
8824 if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
8825 && last
.kind
!= TARGET_WAITKIND_EXITED
8826 && last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
8827 /* Delete the breakpoint we stopped at, if it wants to be deleted.
8828 Delete any breakpoint that is to be deleted at the next stop. */
8829 breakpoint_auto_delete (inferior_thread ()->control
.stop_bpstat
);
8832 /* Try to get rid of automatically added inferiors that are no
8833 longer needed. Keeping those around slows down things linearly.
8834 Note that this never removes the current inferior. */
8841 signal_stop_state (int signo
)
8843 return signal_stop
[signo
];
8847 signal_print_state (int signo
)
8849 return signal_print
[signo
];
8853 signal_pass_state (int signo
)
8855 return signal_program
[signo
];
8859 signal_cache_update (int signo
)
8863 for (signo
= 0; signo
< (int) GDB_SIGNAL_LAST
; signo
++)
8864 signal_cache_update (signo
);
8869 signal_pass
[signo
] = (signal_stop
[signo
] == 0
8870 && signal_print
[signo
] == 0
8871 && signal_program
[signo
] == 1
8872 && signal_catch
[signo
] == 0);
8876 signal_stop_update (int signo
, int state
)
8878 int ret
= signal_stop
[signo
];
8880 signal_stop
[signo
] = state
;
8881 signal_cache_update (signo
);
8886 signal_print_update (int signo
, int state
)
8888 int ret
= signal_print
[signo
];
8890 signal_print
[signo
] = state
;
8891 signal_cache_update (signo
);
8896 signal_pass_update (int signo
, int state
)
8898 int ret
= signal_program
[signo
];
8900 signal_program
[signo
] = state
;
8901 signal_cache_update (signo
);
8905 /* Update the global 'signal_catch' from INFO and notify the
8909 signal_catch_update (const unsigned int *info
)
8913 for (i
= 0; i
< GDB_SIGNAL_LAST
; ++i
)
8914 signal_catch
[i
] = info
[i
] > 0;
8915 signal_cache_update (-1);
8916 target_pass_signals (signal_pass
);
8920 sig_print_header (void)
8922 printf_filtered (_("Signal Stop\tPrint\tPass "
8923 "to program\tDescription\n"));
8927 sig_print_info (enum gdb_signal oursig
)
8929 const char *name
= gdb_signal_to_name (oursig
);
8930 int name_padding
= 13 - strlen (name
);
8932 if (name_padding
<= 0)
8935 printf_filtered ("%s", name
);
8936 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
8937 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
8938 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
8939 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
8940 printf_filtered ("%s\n", gdb_signal_to_string (oursig
));
8943 /* Specify how various signals in the inferior should be handled. */
8946 handle_command (const char *args
, int from_tty
)
8948 int digits
, wordlen
;
8949 int sigfirst
, siglast
;
8950 enum gdb_signal oursig
;
8955 error_no_arg (_("signal to handle"));
8958 /* Allocate and zero an array of flags for which signals to handle. */
8960 const size_t nsigs
= GDB_SIGNAL_LAST
;
8961 unsigned char sigs
[nsigs
] {};
8963 /* Break the command line up into args. */
8965 gdb_argv
built_argv (args
);
8967 /* Walk through the args, looking for signal oursigs, signal names, and
8968 actions. Signal numbers and signal names may be interspersed with
8969 actions, with the actions being performed for all signals cumulatively
8970 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
8972 for (char *arg
: built_argv
)
8974 wordlen
= strlen (arg
);
8975 for (digits
= 0; isdigit (arg
[digits
]); digits
++)
8979 sigfirst
= siglast
= -1;
8981 if (wordlen
>= 1 && !strncmp (arg
, "all", wordlen
))
8983 /* Apply action to all signals except those used by the
8984 debugger. Silently skip those. */
8987 siglast
= nsigs
- 1;
8989 else if (wordlen
>= 1 && !strncmp (arg
, "stop", wordlen
))
8991 SET_SIGS (nsigs
, sigs
, signal_stop
);
8992 SET_SIGS (nsigs
, sigs
, signal_print
);
8994 else if (wordlen
>= 1 && !strncmp (arg
, "ignore", wordlen
))
8996 UNSET_SIGS (nsigs
, sigs
, signal_program
);
8998 else if (wordlen
>= 2 && !strncmp (arg
, "print", wordlen
))
9000 SET_SIGS (nsigs
, sigs
, signal_print
);
9002 else if (wordlen
>= 2 && !strncmp (arg
, "pass", wordlen
))
9004 SET_SIGS (nsigs
, sigs
, signal_program
);
9006 else if (wordlen
>= 3 && !strncmp (arg
, "nostop", wordlen
))
9008 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
9010 else if (wordlen
>= 3 && !strncmp (arg
, "noignore", wordlen
))
9012 SET_SIGS (nsigs
, sigs
, signal_program
);
9014 else if (wordlen
>= 4 && !strncmp (arg
, "noprint", wordlen
))
9016 UNSET_SIGS (nsigs
, sigs
, signal_print
);
9017 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
9019 else if (wordlen
>= 4 && !strncmp (arg
, "nopass", wordlen
))
9021 UNSET_SIGS (nsigs
, sigs
, signal_program
);
9023 else if (digits
> 0)
9025 /* It is numeric. The numeric signal refers to our own
9026 internal signal numbering from target.h, not to host/target
9027 signal number. This is a feature; users really should be
9028 using symbolic names anyway, and the common ones like
9029 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
9031 sigfirst
= siglast
= (int)
9032 gdb_signal_from_command (atoi (arg
));
9033 if (arg
[digits
] == '-')
9036 gdb_signal_from_command (atoi (arg
+ digits
+ 1));
9038 if (sigfirst
> siglast
)
9040 /* Bet he didn't figure we'd think of this case... */
9041 std::swap (sigfirst
, siglast
);
9046 oursig
= gdb_signal_from_name (arg
);
9047 if (oursig
!= GDB_SIGNAL_UNKNOWN
)
9049 sigfirst
= siglast
= (int) oursig
;
9053 /* Not a number and not a recognized flag word => complain. */
9054 error (_("Unrecognized or ambiguous flag word: \"%s\"."), arg
);
9058 /* If any signal numbers or symbol names were found, set flags for
9059 which signals to apply actions to. */
9061 for (int signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
9063 switch ((enum gdb_signal
) signum
)
9065 case GDB_SIGNAL_TRAP
:
9066 case GDB_SIGNAL_INT
:
9067 if (!allsigs
&& !sigs
[signum
])
9069 if (query (_("%s is used by the debugger.\n\
9070 Are you sure you want to change it? "),
9071 gdb_signal_to_name ((enum gdb_signal
) signum
)))
9076 printf_unfiltered (_("Not confirmed, unchanged.\n"));
9080 case GDB_SIGNAL_DEFAULT
:
9081 case GDB_SIGNAL_UNKNOWN
:
9082 /* Make sure that "all" doesn't print these. */
9091 for (int signum
= 0; signum
< nsigs
; signum
++)
9094 signal_cache_update (-1);
9095 target_pass_signals (signal_pass
);
9096 target_program_signals (signal_program
);
9100 /* Show the results. */
9101 sig_print_header ();
9102 for (; signum
< nsigs
; signum
++)
9104 sig_print_info ((enum gdb_signal
) signum
);
9111 /* Complete the "handle" command. */
9114 handle_completer (struct cmd_list_element
*ignore
,
9115 completion_tracker
&tracker
,
9116 const char *text
, const char *word
)
9118 static const char * const keywords
[] =
9132 signal_completer (ignore
, tracker
, text
, word
);
9133 complete_on_enum (tracker
, keywords
, word
, word
);
9137 gdb_signal_from_command (int num
)
9139 if (num
>= 1 && num
<= 15)
9140 return (enum gdb_signal
) num
;
9141 error (_("Only signals 1-15 are valid as numeric signals.\n\
9142 Use \"info signals\" for a list of symbolic signals."));
9145 /* Print current contents of the tables set by the handle command.
9146 It is possible we should just be printing signals actually used
9147 by the current target (but for things to work right when switching
9148 targets, all signals should be in the signal tables). */
9151 info_signals_command (const char *signum_exp
, int from_tty
)
9153 enum gdb_signal oursig
;
9155 sig_print_header ();
9159 /* First see if this is a symbol name. */
9160 oursig
= gdb_signal_from_name (signum_exp
);
9161 if (oursig
== GDB_SIGNAL_UNKNOWN
)
9163 /* No, try numeric. */
9165 gdb_signal_from_command (parse_and_eval_long (signum_exp
));
9167 sig_print_info (oursig
);
9171 printf_filtered ("\n");
9172 /* These ugly casts brought to you by the native VAX compiler. */
9173 for (oursig
= GDB_SIGNAL_FIRST
;
9174 (int) oursig
< (int) GDB_SIGNAL_LAST
;
9175 oursig
= (enum gdb_signal
) ((int) oursig
+ 1))
9179 if (oursig
!= GDB_SIGNAL_UNKNOWN
9180 && oursig
!= GDB_SIGNAL_DEFAULT
&& oursig
!= GDB_SIGNAL_0
)
9181 sig_print_info (oursig
);
9184 printf_filtered (_("\nUse the \"handle\" command "
9185 "to change these tables.\n"));
9188 /* The $_siginfo convenience variable is a bit special. We don't know
9189 for sure the type of the value until we actually have a chance to
9190 fetch the data. The type can change depending on gdbarch, so it is
9191 also dependent on which thread you have selected.
9193 1. making $_siginfo be an internalvar that creates a new value on
9196 2. making the value of $_siginfo be an lval_computed value. */
9198 /* This function implements the lval_computed support for reading a
9202 siginfo_value_read (struct value
*v
)
9204 LONGEST transferred
;
9206 /* If we can access registers, so can we access $_siginfo. Likewise
9208 validate_registers_access ();
9211 target_read (current_inferior ()->top_target (),
9212 TARGET_OBJECT_SIGNAL_INFO
,
9214 value_contents_all_raw (v
),
9216 TYPE_LENGTH (value_type (v
)));
9218 if (transferred
!= TYPE_LENGTH (value_type (v
)))
9219 error (_("Unable to read siginfo"));
9222 /* This function implements the lval_computed support for writing a
9226 siginfo_value_write (struct value
*v
, struct value
*fromval
)
9228 LONGEST transferred
;
9230 /* If we can access registers, so can we access $_siginfo. Likewise
9232 validate_registers_access ();
9234 transferred
= target_write (current_inferior ()->top_target (),
9235 TARGET_OBJECT_SIGNAL_INFO
,
9237 value_contents_all_raw (fromval
),
9239 TYPE_LENGTH (value_type (fromval
)));
9241 if (transferred
!= TYPE_LENGTH (value_type (fromval
)))
9242 error (_("Unable to write siginfo"));
9245 static const struct lval_funcs siginfo_value_funcs
=
9251 /* Return a new value with the correct type for the siginfo object of
9252 the current thread using architecture GDBARCH. Return a void value
9253 if there's no object available. */
9255 static struct value
*
9256 siginfo_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
,
9259 if (target_has_stack ()
9260 && inferior_ptid
!= null_ptid
9261 && gdbarch_get_siginfo_type_p (gdbarch
))
9263 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
9265 return allocate_computed_value (type
, &siginfo_value_funcs
, NULL
);
9268 return allocate_value (builtin_type (gdbarch
)->builtin_void
);
9272 /* infcall_suspend_state contains state about the program itself like its
9273 registers and any signal it received when it last stopped.
9274 This state must be restored regardless of how the inferior function call
9275 ends (either successfully, or after it hits a breakpoint or signal)
9276 if the program is to properly continue where it left off. */
9278 class infcall_suspend_state
9281 /* Capture state from GDBARCH, TP, and REGCACHE that must be restored
9282 once the inferior function call has finished. */
9283 infcall_suspend_state (struct gdbarch
*gdbarch
,
9284 const struct thread_info
*tp
,
9285 struct regcache
*regcache
)
9286 : m_thread_suspend (tp
->suspend
),
9287 m_registers (new readonly_detached_regcache (*regcache
))
9289 gdb::unique_xmalloc_ptr
<gdb_byte
> siginfo_data
;
9291 if (gdbarch_get_siginfo_type_p (gdbarch
))
9293 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
9294 size_t len
= TYPE_LENGTH (type
);
9296 siginfo_data
.reset ((gdb_byte
*) xmalloc (len
));
9298 if (target_read (current_inferior ()->top_target (),
9299 TARGET_OBJECT_SIGNAL_INFO
, NULL
,
9300 siginfo_data
.get (), 0, len
) != len
)
9302 /* Errors ignored. */
9303 siginfo_data
.reset (nullptr);
9309 m_siginfo_gdbarch
= gdbarch
;
9310 m_siginfo_data
= std::move (siginfo_data
);
9314 /* Return a pointer to the stored register state. */
9316 readonly_detached_regcache
*registers () const
9318 return m_registers
.get ();
9321 /* Restores the stored state into GDBARCH, TP, and REGCACHE. */
9323 void restore (struct gdbarch
*gdbarch
,
9324 struct thread_info
*tp
,
9325 struct regcache
*regcache
) const
9327 tp
->suspend
= m_thread_suspend
;
9329 if (m_siginfo_gdbarch
== gdbarch
)
9331 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
9333 /* Errors ignored. */
9334 target_write (current_inferior ()->top_target (),
9335 TARGET_OBJECT_SIGNAL_INFO
, NULL
,
9336 m_siginfo_data
.get (), 0, TYPE_LENGTH (type
));
9339 /* The inferior can be gone if the user types "print exit(0)"
9340 (and perhaps other times). */
9341 if (target_has_execution ())
9342 /* NB: The register write goes through to the target. */
9343 regcache
->restore (registers ());
9347 /* How the current thread stopped before the inferior function call was
9349 struct thread_suspend_state m_thread_suspend
;
9351 /* The registers before the inferior function call was executed. */
9352 std::unique_ptr
<readonly_detached_regcache
> m_registers
;
9354 /* Format of SIGINFO_DATA or NULL if it is not present. */
9355 struct gdbarch
*m_siginfo_gdbarch
= nullptr;
9357 /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
9358 TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the
9359 content would be invalid. */
9360 gdb::unique_xmalloc_ptr
<gdb_byte
> m_siginfo_data
;
9363 infcall_suspend_state_up
9364 save_infcall_suspend_state ()
9366 struct thread_info
*tp
= inferior_thread ();
9367 struct regcache
*regcache
= get_current_regcache ();
9368 struct gdbarch
*gdbarch
= regcache
->arch ();
9370 infcall_suspend_state_up inf_state
9371 (new struct infcall_suspend_state (gdbarch
, tp
, regcache
));
9373 /* Having saved the current state, adjust the thread state, discarding
9374 any stop signal information. The stop signal is not useful when
9375 starting an inferior function call, and run_inferior_call will not use
9376 the signal due to its `proceed' call with GDB_SIGNAL_0. */
9377 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
9382 /* Restore inferior session state to INF_STATE. */
9385 restore_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
9387 struct thread_info
*tp
= inferior_thread ();
9388 struct regcache
*regcache
= get_current_regcache ();
9389 struct gdbarch
*gdbarch
= regcache
->arch ();
9391 inf_state
->restore (gdbarch
, tp
, regcache
);
9392 discard_infcall_suspend_state (inf_state
);
9396 discard_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
9401 readonly_detached_regcache
*
9402 get_infcall_suspend_state_regcache (struct infcall_suspend_state
*inf_state
)
9404 return inf_state
->registers ();
9407 /* infcall_control_state contains state regarding gdb's control of the
9408 inferior itself like stepping control. It also contains session state like
9409 the user's currently selected frame. */
9411 struct infcall_control_state
9413 struct thread_control_state thread_control
;
9414 struct inferior_control_state inferior_control
;
9417 enum stop_stack_kind stop_stack_dummy
= STOP_NONE
;
9418 int stopped_by_random_signal
= 0;
9420 /* ID and level of the selected frame when the inferior function
9422 struct frame_id selected_frame_id
{};
9423 int selected_frame_level
= -1;
9426 /* Save all of the information associated with the inferior<==>gdb
9429 infcall_control_state_up
9430 save_infcall_control_state ()
9432 infcall_control_state_up
inf_status (new struct infcall_control_state
);
9433 struct thread_info
*tp
= inferior_thread ();
9434 struct inferior
*inf
= current_inferior ();
9436 inf_status
->thread_control
= tp
->control
;
9437 inf_status
->inferior_control
= inf
->control
;
9439 tp
->control
.step_resume_breakpoint
= NULL
;
9440 tp
->control
.exception_resume_breakpoint
= NULL
;
9442 /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of
9443 chain. If caller's caller is walking the chain, they'll be happier if we
9444 hand them back the original chain when restore_infcall_control_state is
9446 tp
->control
.stop_bpstat
= bpstat_copy (tp
->control
.stop_bpstat
);
9449 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
9450 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
9452 save_selected_frame (&inf_status
->selected_frame_id
,
9453 &inf_status
->selected_frame_level
);
9458 /* Restore inferior session state to INF_STATUS. */
9461 restore_infcall_control_state (struct infcall_control_state
*inf_status
)
9463 struct thread_info
*tp
= inferior_thread ();
9464 struct inferior
*inf
= current_inferior ();
9466 if (tp
->control
.step_resume_breakpoint
)
9467 tp
->control
.step_resume_breakpoint
->disposition
= disp_del_at_next_stop
;
9469 if (tp
->control
.exception_resume_breakpoint
)
9470 tp
->control
.exception_resume_breakpoint
->disposition
9471 = disp_del_at_next_stop
;
9473 /* Handle the bpstat_copy of the chain. */
9474 bpstat_clear (&tp
->control
.stop_bpstat
);
9476 tp
->control
= inf_status
->thread_control
;
9477 inf
->control
= inf_status
->inferior_control
;
9480 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
9481 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
9483 if (target_has_stack ())
9485 restore_selected_frame (inf_status
->selected_frame_id
,
9486 inf_status
->selected_frame_level
);
9493 discard_infcall_control_state (struct infcall_control_state
*inf_status
)
9495 if (inf_status
->thread_control
.step_resume_breakpoint
)
9496 inf_status
->thread_control
.step_resume_breakpoint
->disposition
9497 = disp_del_at_next_stop
;
9499 if (inf_status
->thread_control
.exception_resume_breakpoint
)
9500 inf_status
->thread_control
.exception_resume_breakpoint
->disposition
9501 = disp_del_at_next_stop
;
9503 /* See save_infcall_control_state for info on stop_bpstat. */
9504 bpstat_clear (&inf_status
->thread_control
.stop_bpstat
);
9512 clear_exit_convenience_vars (void)
9514 clear_internalvar (lookup_internalvar ("_exitsignal"));
9515 clear_internalvar (lookup_internalvar ("_exitcode"));
9519 /* User interface for reverse debugging:
9520 Set exec-direction / show exec-direction commands
9521 (returns error unless target implements to_set_exec_direction method). */
9523 enum exec_direction_kind execution_direction
= EXEC_FORWARD
;
9524 static const char exec_forward
[] = "forward";
9525 static const char exec_reverse
[] = "reverse";
9526 static const char *exec_direction
= exec_forward
;
9527 static const char *const exec_direction_names
[] = {
9534 set_exec_direction_func (const char *args
, int from_tty
,
9535 struct cmd_list_element
*cmd
)
9537 if (target_can_execute_reverse ())
9539 if (!strcmp (exec_direction
, exec_forward
))
9540 execution_direction
= EXEC_FORWARD
;
9541 else if (!strcmp (exec_direction
, exec_reverse
))
9542 execution_direction
= EXEC_REVERSE
;
9546 exec_direction
= exec_forward
;
9547 error (_("Target does not support this operation."));
9552 show_exec_direction_func (struct ui_file
*out
, int from_tty
,
9553 struct cmd_list_element
*cmd
, const char *value
)
9555 switch (execution_direction
) {
9557 fprintf_filtered (out
, _("Forward.\n"));
9560 fprintf_filtered (out
, _("Reverse.\n"));
9563 internal_error (__FILE__
, __LINE__
,
9564 _("bogus execution_direction value: %d"),
9565 (int) execution_direction
);
9570 show_schedule_multiple (struct ui_file
*file
, int from_tty
,
9571 struct cmd_list_element
*c
, const char *value
)
9573 fprintf_filtered (file
, _("Resuming the execution of threads "
9574 "of all processes is %s.\n"), value
);
9577 /* Implementation of `siginfo' variable. */
9579 static const struct internalvar_funcs siginfo_funcs
=
9586 /* Callback for infrun's target events source. This is marked when a
9587 thread has a pending status to process. */
9590 infrun_async_inferior_event_handler (gdb_client_data data
)
9592 clear_async_event_handler (infrun_async_inferior_event_token
);
9593 inferior_event_handler (INF_REG_EVENT
);
9600 /* Verify that when two threads with the same ptid exist (from two different
9601 targets) and one of them changes ptid, we only update inferior_ptid if
9602 it is appropriate. */
9605 infrun_thread_ptid_changed ()
9607 gdbarch
*arch
= current_inferior ()->gdbarch
;
9609 /* The thread which inferior_ptid represents changes ptid. */
9611 scoped_restore_current_pspace_and_thread restore
;
9613 scoped_mock_context
<test_target_ops
> target1 (arch
);
9614 scoped_mock_context
<test_target_ops
> target2 (arch
);
9615 target2
.mock_inferior
.next
= &target1
.mock_inferior
;
9617 ptid_t
old_ptid (111, 222);
9618 ptid_t
new_ptid (111, 333);
9620 target1
.mock_inferior
.pid
= old_ptid
.pid ();
9621 target1
.mock_thread
.ptid
= old_ptid
;
9622 target2
.mock_inferior
.pid
= old_ptid
.pid ();
9623 target2
.mock_thread
.ptid
= old_ptid
;
9625 auto restore_inferior_ptid
= make_scoped_restore (&inferior_ptid
, old_ptid
);
9626 set_current_inferior (&target1
.mock_inferior
);
9628 thread_change_ptid (&target1
.mock_target
, old_ptid
, new_ptid
);
9630 gdb_assert (inferior_ptid
== new_ptid
);
9633 /* A thread with the same ptid as inferior_ptid, but from another target,
9636 scoped_restore_current_pspace_and_thread restore
;
9638 scoped_mock_context
<test_target_ops
> target1 (arch
);
9639 scoped_mock_context
<test_target_ops
> target2 (arch
);
9640 target2
.mock_inferior
.next
= &target1
.mock_inferior
;
9642 ptid_t
old_ptid (111, 222);
9643 ptid_t
new_ptid (111, 333);
9645 target1
.mock_inferior
.pid
= old_ptid
.pid ();
9646 target1
.mock_thread
.ptid
= old_ptid
;
9647 target2
.mock_inferior
.pid
= old_ptid
.pid ();
9648 target2
.mock_thread
.ptid
= old_ptid
;
9650 auto restore_inferior_ptid
= make_scoped_restore (&inferior_ptid
, old_ptid
);
9651 set_current_inferior (&target2
.mock_inferior
);
9653 thread_change_ptid (&target1
.mock_target
, old_ptid
, new_ptid
);
9655 gdb_assert (inferior_ptid
== old_ptid
);
9659 } /* namespace selftests */
9661 #endif /* GDB_SELF_TEST */
9663 void _initialize_infrun ();
9665 _initialize_infrun ()
9667 struct cmd_list_element
*c
;
9669 /* Register extra event sources in the event loop. */
9670 infrun_async_inferior_event_token
9671 = create_async_event_handler (infrun_async_inferior_event_handler
, NULL
,
9674 cmd_list_element
*info_signals_cmd
9675 = add_info ("signals", info_signals_command
, _("\
9676 What debugger does when program gets various signals.\n\
9677 Specify a signal as argument to print info on that signal only."));
9678 add_info_alias ("handle", info_signals_cmd
, 0);
9680 c
= add_com ("handle", class_run
, handle_command
, _("\
9681 Specify how to handle signals.\n\
9682 Usage: handle SIGNAL [ACTIONS]\n\
9683 Args are signals and actions to apply to those signals.\n\
9684 If no actions are specified, the current settings for the specified signals\n\
9685 will be displayed instead.\n\
9687 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
9688 from 1-15 are allowed for compatibility with old versions of GDB.\n\
9689 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
9690 The special arg \"all\" is recognized to mean all signals except those\n\
9691 used by the debugger, typically SIGTRAP and SIGINT.\n\
9693 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
9694 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
9695 Stop means reenter debugger if this signal happens (implies print).\n\
9696 Print means print a message if this signal happens.\n\
9697 Pass means let program see this signal; otherwise program doesn't know.\n\
9698 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
9699 Pass and Stop may be combined.\n\
9701 Multiple signals may be specified. Signal numbers and signal names\n\
9702 may be interspersed with actions, with the actions being performed for\n\
9703 all signals cumulatively specified."));
9704 set_cmd_completer (c
, handle_completer
);
9707 stop_command
= add_cmd ("stop", class_obscure
,
9708 not_just_help_class_command
, _("\
9709 There is no `stop' command, but you can set a hook on `stop'.\n\
9710 This allows you to set a list of commands to be run each time execution\n\
9711 of the program stops."), &cmdlist
);
9713 add_setshow_boolean_cmd
9714 ("infrun", class_maintenance
, &debug_infrun
,
9715 _("Set inferior debugging."),
9716 _("Show inferior debugging."),
9717 _("When non-zero, inferior specific debugging is enabled."),
9718 NULL
, show_debug_infrun
, &setdebuglist
, &showdebuglist
);
9720 add_setshow_boolean_cmd ("non-stop", no_class
,
9722 Set whether gdb controls the inferior in non-stop mode."), _("\
9723 Show whether gdb controls the inferior in non-stop mode."), _("\
9724 When debugging a multi-threaded program and this setting is\n\
9725 off (the default, also called all-stop mode), when one thread stops\n\
9726 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
9727 all other threads in the program while you interact with the thread of\n\
9728 interest. When you continue or step a thread, you can allow the other\n\
9729 threads to run, or have them remain stopped, but while you inspect any\n\
9730 thread's state, all threads stop.\n\
9732 In non-stop mode, when one thread stops, other threads can continue\n\
9733 to run freely. You'll be able to step each thread independently,\n\
9734 leave it stopped or free to run as needed."),
9740 for (size_t i
= 0; i
< GDB_SIGNAL_LAST
; i
++)
9743 signal_print
[i
] = 1;
9744 signal_program
[i
] = 1;
9745 signal_catch
[i
] = 0;
9748 /* Signals caused by debugger's own actions should not be given to
9749 the program afterwards.
9751 Do not deliver GDB_SIGNAL_TRAP by default, except when the user
9752 explicitly specifies that it should be delivered to the target
9753 program. Typically, that would occur when a user is debugging a
9754 target monitor on a simulator: the target monitor sets a
9755 breakpoint; the simulator encounters this breakpoint and halts
9756 the simulation handing control to GDB; GDB, noting that the stop
9757 address doesn't map to any known breakpoint, returns control back
9758 to the simulator; the simulator then delivers the hardware
9759 equivalent of a GDB_SIGNAL_TRAP to the program being
9761 signal_program
[GDB_SIGNAL_TRAP
] = 0;
9762 signal_program
[GDB_SIGNAL_INT
] = 0;
9764 /* Signals that are not errors should not normally enter the debugger. */
9765 signal_stop
[GDB_SIGNAL_ALRM
] = 0;
9766 signal_print
[GDB_SIGNAL_ALRM
] = 0;
9767 signal_stop
[GDB_SIGNAL_VTALRM
] = 0;
9768 signal_print
[GDB_SIGNAL_VTALRM
] = 0;
9769 signal_stop
[GDB_SIGNAL_PROF
] = 0;
9770 signal_print
[GDB_SIGNAL_PROF
] = 0;
9771 signal_stop
[GDB_SIGNAL_CHLD
] = 0;
9772 signal_print
[GDB_SIGNAL_CHLD
] = 0;
9773 signal_stop
[GDB_SIGNAL_IO
] = 0;
9774 signal_print
[GDB_SIGNAL_IO
] = 0;
9775 signal_stop
[GDB_SIGNAL_POLL
] = 0;
9776 signal_print
[GDB_SIGNAL_POLL
] = 0;
9777 signal_stop
[GDB_SIGNAL_URG
] = 0;
9778 signal_print
[GDB_SIGNAL_URG
] = 0;
9779 signal_stop
[GDB_SIGNAL_WINCH
] = 0;
9780 signal_print
[GDB_SIGNAL_WINCH
] = 0;
9781 signal_stop
[GDB_SIGNAL_PRIO
] = 0;
9782 signal_print
[GDB_SIGNAL_PRIO
] = 0;
9784 /* These signals are used internally by user-level thread
9785 implementations. (See signal(5) on Solaris.) Like the above
9786 signals, a healthy program receives and handles them as part of
9787 its normal operation. */
9788 signal_stop
[GDB_SIGNAL_LWP
] = 0;
9789 signal_print
[GDB_SIGNAL_LWP
] = 0;
9790 signal_stop
[GDB_SIGNAL_WAITING
] = 0;
9791 signal_print
[GDB_SIGNAL_WAITING
] = 0;
9792 signal_stop
[GDB_SIGNAL_CANCEL
] = 0;
9793 signal_print
[GDB_SIGNAL_CANCEL
] = 0;
9794 signal_stop
[GDB_SIGNAL_LIBRT
] = 0;
9795 signal_print
[GDB_SIGNAL_LIBRT
] = 0;
9797 /* Update cached state. */
9798 signal_cache_update (-1);
9800 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support
,
9801 &stop_on_solib_events
, _("\
9802 Set stopping for shared library events."), _("\
9803 Show stopping for shared library events."), _("\
9804 If nonzero, gdb will give control to the user when the dynamic linker\n\
9805 notifies gdb of shared library events. The most common event of interest\n\
9806 to the user would be loading/unloading of a new library."),
9807 set_stop_on_solib_events
,
9808 show_stop_on_solib_events
,
9809 &setlist
, &showlist
);
9811 add_setshow_enum_cmd ("follow-fork-mode", class_run
,
9812 follow_fork_mode_kind_names
,
9813 &follow_fork_mode_string
, _("\
9814 Set debugger response to a program call of fork or vfork."), _("\
9815 Show debugger response to a program call of fork or vfork."), _("\
9816 A fork or vfork creates a new process. follow-fork-mode can be:\n\
9817 parent - the original process is debugged after a fork\n\
9818 child - the new process is debugged after a fork\n\
9819 The unfollowed process will continue to run.\n\
9820 By default, the debugger will follow the parent process."),
9822 show_follow_fork_mode_string
,
9823 &setlist
, &showlist
);
9825 add_setshow_enum_cmd ("follow-exec-mode", class_run
,
9826 follow_exec_mode_names
,
9827 &follow_exec_mode_string
, _("\
9828 Set debugger response to a program call of exec."), _("\
9829 Show debugger response to a program call of exec."), _("\
9830 An exec call replaces the program image of a process.\n\
9832 follow-exec-mode can be:\n\
9834 new - the debugger creates a new inferior and rebinds the process\n\
9835 to this new inferior. The program the process was running before\n\
9836 the exec call can be restarted afterwards by restarting the original\n\
9839 same - the debugger keeps the process bound to the same inferior.\n\
9840 The new executable image replaces the previous executable loaded in\n\
9841 the inferior. Restarting the inferior after the exec call restarts\n\
9842 the executable the process was running after the exec call.\n\
9844 By default, the debugger will use the same inferior."),
9846 show_follow_exec_mode_string
,
9847 &setlist
, &showlist
);
9849 add_setshow_enum_cmd ("scheduler-locking", class_run
,
9850 scheduler_enums
, &scheduler_mode
, _("\
9851 Set mode for locking scheduler during execution."), _("\
9852 Show mode for locking scheduler during execution."), _("\
9853 off == no locking (threads may preempt at any time)\n\
9854 on == full locking (no thread except the current thread may run)\n\
9855 This applies to both normal execution and replay mode.\n\
9856 step == scheduler locked during stepping commands (step, next, stepi, nexti).\n\
9857 In this mode, other threads may run during other commands.\n\
9858 This applies to both normal execution and replay mode.\n\
9859 replay == scheduler locked in replay mode and unlocked during normal execution."),
9860 set_schedlock_func
, /* traps on target vector */
9861 show_scheduler_mode
,
9862 &setlist
, &showlist
);
9864 add_setshow_boolean_cmd ("schedule-multiple", class_run
, &sched_multi
, _("\
9865 Set mode for resuming threads of all processes."), _("\
9866 Show mode for resuming threads of all processes."), _("\
9867 When on, execution commands (such as 'continue' or 'next') resume all\n\
9868 threads of all processes. When off (which is the default), execution\n\
9869 commands only resume the threads of the current process. The set of\n\
9870 threads that are resumed is further refined by the scheduler-locking\n\
9871 mode (see help set scheduler-locking)."),
9873 show_schedule_multiple
,
9874 &setlist
, &showlist
);
9876 add_setshow_boolean_cmd ("step-mode", class_run
, &step_stop_if_no_debug
, _("\
9877 Set mode of the step operation."), _("\
9878 Show mode of the step operation."), _("\
9879 When set, doing a step over a function without debug line information\n\
9880 will stop at the first instruction of that function. Otherwise, the\n\
9881 function is skipped and the step command stops at a different source line."),
9883 show_step_stop_if_no_debug
,
9884 &setlist
, &showlist
);
9886 add_setshow_auto_boolean_cmd ("displaced-stepping", class_run
,
9887 &can_use_displaced_stepping
, _("\
9888 Set debugger's willingness to use displaced stepping."), _("\
9889 Show debugger's willingness to use displaced stepping."), _("\
9890 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
9891 supported by the target architecture. If off, gdb will not use displaced\n\
9892 stepping to step over breakpoints, even if such is supported by the target\n\
9893 architecture. If auto (which is the default), gdb will use displaced stepping\n\
9894 if the target architecture supports it and non-stop mode is active, but will not\n\
9895 use it in all-stop mode (see help set non-stop)."),
9897 show_can_use_displaced_stepping
,
9898 &setlist
, &showlist
);
9900 add_setshow_enum_cmd ("exec-direction", class_run
, exec_direction_names
,
9901 &exec_direction
, _("Set direction of execution.\n\
9902 Options are 'forward' or 'reverse'."),
9903 _("Show direction of execution (forward/reverse)."),
9904 _("Tells gdb whether to execute forward or backward."),
9905 set_exec_direction_func
, show_exec_direction_func
,
9906 &setlist
, &showlist
);
9908 /* Set/show detach-on-fork: user-settable mode. */
9910 add_setshow_boolean_cmd ("detach-on-fork", class_run
, &detach_fork
, _("\
9911 Set whether gdb will detach the child of a fork."), _("\
9912 Show whether gdb will detach the child of a fork."), _("\
9913 Tells gdb whether to detach the child of a fork."),
9914 NULL
, NULL
, &setlist
, &showlist
);
9916 /* Set/show disable address space randomization mode. */
9918 add_setshow_boolean_cmd ("disable-randomization", class_support
,
9919 &disable_randomization
, _("\
9920 Set disabling of debuggee's virtual address space randomization."), _("\
9921 Show disabling of debuggee's virtual address space randomization."), _("\
9922 When this mode is on (which is the default), randomization of the virtual\n\
9923 address space is disabled. Standalone programs run with the randomization\n\
9924 enabled by default on some platforms."),
9925 &set_disable_randomization
,
9926 &show_disable_randomization
,
9927 &setlist
, &showlist
);
9929 /* ptid initializations */
9930 inferior_ptid
= null_ptid
;
9931 target_last_wait_ptid
= minus_one_ptid
;
9933 gdb::observers::thread_ptid_changed
.attach (infrun_thread_ptid_changed
,
9935 gdb::observers::thread_stop_requested
.attach (infrun_thread_stop_requested
,
9937 gdb::observers::thread_exit
.attach (infrun_thread_thread_exit
, "infrun");
9938 gdb::observers::inferior_exit
.attach (infrun_inferior_exit
, "infrun");
9939 gdb::observers::inferior_execd
.attach (infrun_inferior_execd
, "infrun");
9941 /* Explicitly create without lookup, since that tries to create a
9942 value with a void typed value, and when we get here, gdbarch
9943 isn't initialized yet. At this point, we're quite sure there
9944 isn't another convenience variable of the same name. */
9945 create_internalvar_type_lazy ("_siginfo", &siginfo_funcs
, NULL
);
9947 add_setshow_boolean_cmd ("observer", no_class
,
9948 &observer_mode_1
, _("\
9949 Set whether gdb controls the inferior in observer mode."), _("\
9950 Show whether gdb controls the inferior in observer mode."), _("\
9951 In observer mode, GDB can get data from the inferior, but not\n\
9952 affect its execution. Registers and memory may not be changed,\n\
9953 breakpoints may not be set, and the program cannot be interrupted\n\
9961 selftests::register_test ("infrun_thread_ptid_changed",
9962 selftests::infrun_thread_ptid_changed
);