1 /* Target-struct-independent code to start (run) and stop an inferior
4 Copyright (C) 1986-2020 Free Software Foundation, Inc.
5 Copyright (C) 2019-2020 Advanced Micro Devices, Inc. All rights reserved.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "displaced-stepping.h"
29 #include "breakpoint.h"
33 #include "gdbthread.h"
41 #include "observable.h"
46 #include "mi/mi-common.h"
47 #include "event-top.h"
49 #include "record-full.h"
50 #include "inline-frame.h"
52 #include "tracepoint.h"
56 #include "completer.h"
57 #include "target-descriptions.h"
58 #include "target-dcache.h"
61 #include "event-loop.h"
62 #include "thread-fsm.h"
63 #include "gdbsupport/enum-flags.h"
64 #include "progspace-and-thread.h"
65 #include "gdbsupport/gdb_optional.h"
66 #include "arch-utils.h"
67 #include "gdbsupport/scope-exit.h"
68 #include "gdbsupport/forward-scope-exit.h"
70 /* Prototypes for local functions */
72 static void sig_print_info (enum gdb_signal
);
74 static void sig_print_header (void);
76 static int follow_fork (void);
78 static int follow_fork_inferior (int follow_child
, int detach_fork
);
80 static void follow_inferior_reset_breakpoints (void);
82 static int currently_stepping (struct thread_info
*tp
);
84 void nullify_last_target_wait_ptid (void);
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 int maybe_software_singlestep (struct gdbarch
*gdbarch
, CORE_ADDR pc
);
94 static void resume (gdb_signal sig
);
96 /* Asynchronous signal handler registered as event loop source for
97 when we have pending events ready to be passed to the core. */
98 static struct async_event_handler
*infrun_async_inferior_event_token
;
100 /* Stores whether infrun_async was previously enabled or disabled.
101 Starts off as -1, indicating "never enabled/disabled". */
102 static int infrun_is_async
= -1;
107 infrun_async (int enable
)
109 if (infrun_is_async
!= enable
)
111 infrun_is_async
= enable
;
114 fprintf_unfiltered (gdb_stdlog
,
115 "infrun: infrun_async(%d)\n",
119 mark_async_event_handler (infrun_async_inferior_event_token
);
121 clear_async_event_handler (infrun_async_inferior_event_token
);
128 mark_infrun_async_event_handler (void)
130 mark_async_event_handler (infrun_async_inferior_event_token
);
133 /* When set, stop the 'step' command if we enter a function which has
134 no line number information. The normal behavior is that we step
135 over such function. */
136 bool step_stop_if_no_debug
= false;
138 show_step_stop_if_no_debug (struct ui_file
*file
, int from_tty
,
139 struct cmd_list_element
*c
, const char *value
)
141 fprintf_filtered (file
, _("Mode of the step operation is %s.\n"), value
);
144 /* proceed and normal_stop use this to notify the user when the
145 inferior stopped in a different thread than it had been running
148 static ptid_t previous_inferior_ptid
;
150 /* If set (default for legacy reasons), when following a fork, GDB
151 will detach from one of the fork branches, child or parent.
152 Exactly which branch is detached depends on 'set follow-fork-mode'
155 static bool detach_fork
= true;
157 bool debug_displaced
= false;
159 show_debug_displaced (struct ui_file
*file
, int from_tty
,
160 struct cmd_list_element
*c
, const char *value
)
162 fprintf_filtered (file
, _("Displace stepping debugging is %s.\n"), value
);
165 unsigned int debug_infrun
= 0;
167 show_debug_infrun (struct ui_file
*file
, int from_tty
,
168 struct cmd_list_element
*c
, const char *value
)
170 fprintf_filtered (file
, _("Inferior debugging is %s.\n"), value
);
174 /* Support for disabling address space randomization. */
176 bool disable_randomization
= true;
179 show_disable_randomization (struct ui_file
*file
, int from_tty
,
180 struct cmd_list_element
*c
, const char *value
)
182 if (target_supports_disable_randomization ())
183 fprintf_filtered (file
,
184 _("Disabling randomization of debuggee's "
185 "virtual address space is %s.\n"),
188 fputs_filtered (_("Disabling randomization of debuggee's "
189 "virtual address space is unsupported on\n"
190 "this platform.\n"), file
);
194 set_disable_randomization (const char *args
, int from_tty
,
195 struct cmd_list_element
*c
)
197 if (!target_supports_disable_randomization ())
198 error (_("Disabling randomization of debuggee's "
199 "virtual address space is unsupported on\n"
203 /* User interface for non-stop mode. */
205 bool non_stop
= false;
206 static bool non_stop_1
= false;
209 set_non_stop (const char *args
, int from_tty
,
210 struct cmd_list_element
*c
)
212 if (target_has_execution
)
214 non_stop_1
= non_stop
;
215 error (_("Cannot change this setting while the inferior is running."));
218 non_stop
= non_stop_1
;
222 show_non_stop (struct ui_file
*file
, int from_tty
,
223 struct cmd_list_element
*c
, const char *value
)
225 fprintf_filtered (file
,
226 _("Controlling the inferior in non-stop mode is %s.\n"),
230 /* "Observer mode" is somewhat like a more extreme version of
231 non-stop, in which all GDB operations that might affect the
232 target's execution have been disabled. */
234 bool observer_mode
= false;
235 static bool observer_mode_1
= false;
238 set_observer_mode (const char *args
, int from_tty
,
239 struct cmd_list_element
*c
)
241 if (target_has_execution
)
243 observer_mode_1
= observer_mode
;
244 error (_("Cannot change this setting while the inferior is running."));
247 observer_mode
= observer_mode_1
;
249 may_write_registers
= !observer_mode
;
250 may_write_memory
= !observer_mode
;
251 may_insert_breakpoints
= !observer_mode
;
252 may_insert_tracepoints
= !observer_mode
;
253 /* We can insert fast tracepoints in or out of observer mode,
254 but enable them if we're going into this mode. */
256 may_insert_fast_tracepoints
= true;
257 may_stop
= !observer_mode
;
258 update_target_permissions ();
260 /* Going *into* observer mode we must force non-stop, then
261 going out we leave it that way. */
264 pagination_enabled
= 0;
265 non_stop
= non_stop_1
= true;
269 printf_filtered (_("Observer mode is now %s.\n"),
270 (observer_mode
? "on" : "off"));
274 show_observer_mode (struct ui_file
*file
, int from_tty
,
275 struct cmd_list_element
*c
, const char *value
)
277 fprintf_filtered (file
, _("Observer mode is %s.\n"), value
);
280 /* This updates the value of observer mode based on changes in
281 permissions. Note that we are deliberately ignoring the values of
282 may-write-registers and may-write-memory, since the user may have
283 reason to enable these during a session, for instance to turn on a
284 debugging-related global. */
287 update_observer_mode (void)
289 bool newval
= (!may_insert_breakpoints
290 && !may_insert_tracepoints
291 && may_insert_fast_tracepoints
295 /* Let the user know if things change. */
296 if (newval
!= observer_mode
)
297 printf_filtered (_("Observer mode is now %s.\n"),
298 (newval
? "on" : "off"));
300 observer_mode
= observer_mode_1
= newval
;
303 /* Tables of how to react to signals; the user sets them. */
305 static unsigned char signal_stop
[GDB_SIGNAL_LAST
];
306 static unsigned char signal_print
[GDB_SIGNAL_LAST
];
307 static unsigned char signal_program
[GDB_SIGNAL_LAST
];
309 /* Table of signals that are registered with "catch signal". A
310 non-zero entry indicates that the signal is caught by some "catch
312 static unsigned char signal_catch
[GDB_SIGNAL_LAST
];
314 /* Table of signals that the target may silently handle.
315 This is automatically determined from the flags above,
316 and simply cached here. */
317 static unsigned char signal_pass
[GDB_SIGNAL_LAST
];
319 #define SET_SIGS(nsigs,sigs,flags) \
321 int signum = (nsigs); \
322 while (signum-- > 0) \
323 if ((sigs)[signum]) \
324 (flags)[signum] = 1; \
327 #define UNSET_SIGS(nsigs,sigs,flags) \
329 int signum = (nsigs); \
330 while (signum-- > 0) \
331 if ((sigs)[signum]) \
332 (flags)[signum] = 0; \
335 /* Update the target's copy of SIGNAL_PROGRAM. The sole purpose of
336 this function is to avoid exporting `signal_program'. */
339 update_signals_program_target (void)
341 target_program_signals (signal_program
);
344 /* Value to pass to target_resume() to cause all threads to resume. */
346 #define RESUME_ALL minus_one_ptid
348 /* Command list pointer for the "stop" placeholder. */
350 static struct cmd_list_element
*stop_command
;
352 /* Nonzero if we want to give control to the user when we're notified
353 of shared library events by the dynamic linker. */
354 int stop_on_solib_events
;
356 /* Enable or disable optional shared library event breakpoints
357 as appropriate when the above flag is changed. */
360 set_stop_on_solib_events (const char *args
,
361 int from_tty
, struct cmd_list_element
*c
)
363 update_solib_breakpoints ();
367 show_stop_on_solib_events (struct ui_file
*file
, int from_tty
,
368 struct cmd_list_element
*c
, const char *value
)
370 fprintf_filtered (file
, _("Stopping for shared library events is %s.\n"),
374 /* Nonzero after stop if current stack frame should be printed. */
376 static int stop_print_frame
;
378 /* This is a cached copy of the pid/waitstatus of the last event
379 returned by target_wait()/deprecated_target_wait_hook(). This
380 information is returned by get_last_target_status(). */
381 static ptid_t target_last_wait_ptid
;
382 static struct target_waitstatus target_last_waitstatus
;
384 void init_thread_stepping_state (struct thread_info
*tss
);
386 static const char follow_fork_mode_child
[] = "child";
387 static const char follow_fork_mode_parent
[] = "parent";
389 static const char *const follow_fork_mode_kind_names
[] = {
390 follow_fork_mode_child
,
391 follow_fork_mode_parent
,
395 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
397 show_follow_fork_mode_string (struct ui_file
*file
, int from_tty
,
398 struct cmd_list_element
*c
, const char *value
)
400 fprintf_filtered (file
,
401 _("Debugger response to a program "
402 "call of fork or vfork is \"%s\".\n"),
407 /* Handle changes to the inferior list based on the type of fork,
408 which process is being followed, and whether the other process
409 should be detached. On entry inferior_ptid must be the ptid of
410 the fork parent. At return inferior_ptid is the ptid of the
411 followed inferior. */
414 follow_fork_inferior (int follow_child
, int detach_fork
)
417 ptid_t parent_ptid
, child_ptid
;
419 has_vforked
= (inferior_thread ()->pending_follow
.kind
420 == TARGET_WAITKIND_VFORKED
);
421 parent_ptid
= inferior_ptid
;
422 child_ptid
= inferior_thread ()->pending_follow
.value
.related_pid
;
425 && !non_stop
/* Non-stop always resumes both branches. */
426 && current_ui
->prompt_state
== PROMPT_BLOCKED
427 && !(follow_child
|| detach_fork
|| sched_multi
))
429 /* The parent stays blocked inside the vfork syscall until the
430 child execs or exits. If we don't let the child run, then
431 the parent stays blocked. If we're telling the parent to run
432 in the foreground, the user will not be able to ctrl-c to get
433 back the terminal, effectively hanging the debug session. */
434 fprintf_filtered (gdb_stderr
, _("\
435 Can not resume the parent process over vfork in the foreground while\n\
436 holding the child stopped. Try \"set detach-on-fork\" or \
437 \"set schedule-multiple\".\n"));
443 /* Detach new forked process? */
446 /* Before detaching from the child, remove all breakpoints
447 from it. If we forked, then this has already been taken
448 care of by infrun.c. If we vforked however, any
449 breakpoint inserted in the parent is visible in the
450 child, even those added while stopped in a vfork
451 catchpoint. This will remove the breakpoints from the
452 parent also, but they'll be reinserted below. */
455 /* Keep breakpoints list in sync. */
456 remove_breakpoints_inf (current_inferior ());
459 if (print_inferior_events
)
461 /* Ensure that we have a process ptid. */
462 ptid_t process_ptid
= ptid_t (child_ptid
.pid ());
464 target_terminal::ours_for_output ();
465 fprintf_filtered (gdb_stdlog
,
466 _("[Detaching after %s from child %s]\n"),
467 has_vforked
? "vfork" : "fork",
468 target_pid_to_str (process_ptid
).c_str ());
473 struct inferior
*parent_inf
, *child_inf
;
475 /* Add process to GDB's tables. */
476 child_inf
= add_inferior (child_ptid
.pid ());
478 parent_inf
= current_inferior ();
479 child_inf
->attach_flag
= parent_inf
->attach_flag
;
480 copy_terminal_info (child_inf
, parent_inf
);
481 child_inf
->gdbarch
= parent_inf
->gdbarch
;
482 copy_inferior_target_desc_info (child_inf
, parent_inf
);
484 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
486 inferior_ptid
= child_ptid
;
487 add_thread_silent (inferior_ptid
);
488 set_current_inferior (child_inf
);
489 child_inf
->symfile_flags
= SYMFILE_NO_READ
;
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
;
498 /* The parent will be frozen until the child is done
499 with the shared region. Keep track of the
501 child_inf
->vfork_parent
= parent_inf
;
502 child_inf
->pending_detach
= 0;
503 parent_inf
->vfork_child
= child_inf
;
504 parent_inf
->pending_detach
= 0;
508 child_inf
->aspace
= new_address_space ();
509 child_inf
->pspace
= new program_space (child_inf
->aspace
);
510 child_inf
->removable
= 1;
511 set_current_program_space (child_inf
->pspace
);
512 clone_program_space (child_inf
->pspace
, parent_inf
->pspace
);
514 /* Let the shared library layer (e.g., solib-svr4) learn
515 about this new process, relocate the cloned exec, pull
516 in shared libraries, and install the solib event
517 breakpoint. If a "cloned-VM" event was propagated
518 better throughout the core, this wouldn't be
520 solib_create_inferior_hook (0);
526 struct inferior
*parent_inf
;
528 parent_inf
= current_inferior ();
530 /* If we detached from the child, then we have to be careful
531 to not insert breakpoints in the parent until the child
532 is done with the shared memory region. However, if we're
533 staying attached to the child, then we can and should
534 insert breakpoints, so that we can debug it. A
535 subsequent child exec or exit is enough to know when does
536 the child stops using the parent's address space. */
537 parent_inf
->waiting_for_vfork_done
= detach_fork
;
538 parent_inf
->pspace
->breakpoints_not_allowed
= detach_fork
;
543 /* Follow the child. */
544 struct inferior
*parent_inf
, *child_inf
;
545 struct program_space
*parent_pspace
;
547 if (print_inferior_events
)
549 std::string parent_pid
= target_pid_to_str (parent_ptid
);
550 std::string child_pid
= target_pid_to_str (child_ptid
);
552 target_terminal::ours_for_output ();
553 fprintf_filtered (gdb_stdlog
,
554 _("[Attaching after %s %s to child %s]\n"),
556 has_vforked
? "vfork" : "fork",
560 /* Add the new inferior first, so that the target_detach below
561 doesn't unpush the target. */
563 child_inf
= add_inferior (child_ptid
.pid ());
565 parent_inf
= current_inferior ();
566 child_inf
->attach_flag
= parent_inf
->attach_flag
;
567 copy_terminal_info (child_inf
, parent_inf
);
568 child_inf
->gdbarch
= parent_inf
->gdbarch
;
569 copy_inferior_target_desc_info (child_inf
, parent_inf
);
571 parent_pspace
= parent_inf
->pspace
;
573 /* If we're vforking, we want to hold on to the parent until the
574 child exits or execs. At child exec or exit time we can
575 remove the old breakpoints from the parent and detach or
576 resume debugging it. Otherwise, detach the parent now; we'll
577 want to reuse it's program/address spaces, but we can't set
578 them to the child before removing breakpoints from the
579 parent, otherwise, the breakpoints module could decide to
580 remove breakpoints from the wrong process (since they'd be
581 assigned to the same address space). */
585 gdb_assert (child_inf
->vfork_parent
== NULL
);
586 gdb_assert (parent_inf
->vfork_child
== NULL
);
587 child_inf
->vfork_parent
= parent_inf
;
588 child_inf
->pending_detach
= 0;
589 parent_inf
->vfork_child
= child_inf
;
590 parent_inf
->pending_detach
= detach_fork
;
591 parent_inf
->waiting_for_vfork_done
= 0;
593 else if (detach_fork
)
595 if (print_inferior_events
)
597 /* Ensure that we have a process ptid. */
598 ptid_t process_ptid
= ptid_t (parent_ptid
.pid ());
600 target_terminal::ours_for_output ();
601 fprintf_filtered (gdb_stdlog
,
602 _("[Detaching after fork from "
604 target_pid_to_str (process_ptid
).c_str ());
607 target_detach (parent_inf
, 0);
610 /* Note that the detach above makes PARENT_INF dangling. */
612 /* Add the child thread to the appropriate lists, and switch to
613 this new thread, before cloning the program space, and
614 informing the solib layer about this new process. */
616 inferior_ptid
= child_ptid
;
617 add_thread_silent (inferior_ptid
);
618 set_current_inferior (child_inf
);
620 /* If this is a vfork child, then the address-space is shared
621 with the parent. If we detached from the parent, then we can
622 reuse the parent's program/address spaces. */
623 if (has_vforked
|| detach_fork
)
625 child_inf
->pspace
= parent_pspace
;
626 child_inf
->aspace
= child_inf
->pspace
->aspace
;
630 child_inf
->aspace
= new_address_space ();
631 child_inf
->pspace
= new program_space (child_inf
->aspace
);
632 child_inf
->removable
= 1;
633 child_inf
->symfile_flags
= SYMFILE_NO_READ
;
634 set_current_program_space (child_inf
->pspace
);
635 clone_program_space (child_inf
->pspace
, parent_pspace
);
637 /* Let the shared library layer (e.g., solib-svr4) learn
638 about this new process, relocate the cloned exec, pull in
639 shared libraries, and install the solib event breakpoint.
640 If a "cloned-VM" event was propagated better throughout
641 the core, this wouldn't be required. */
642 solib_create_inferior_hook (0);
646 return target_follow_fork (follow_child
, detach_fork
);
649 /* Tell the target to follow the fork we're stopped at. Returns true
650 if the inferior should be resumed; false, if the target for some
651 reason decided it's best not to resume. */
656 int follow_child
= (follow_fork_mode_string
== follow_fork_mode_child
);
657 int should_resume
= 1;
658 struct thread_info
*tp
;
660 /* Copy user stepping state to the new inferior thread. FIXME: the
661 followed fork child thread should have a copy of most of the
662 parent thread structure's run control related fields, not just these.
663 Initialized to avoid "may be used uninitialized" warnings from gcc. */
664 struct breakpoint
*step_resume_breakpoint
= NULL
;
665 struct breakpoint
*exception_resume_breakpoint
= NULL
;
666 CORE_ADDR step_range_start
= 0;
667 CORE_ADDR step_range_end
= 0;
668 struct frame_id step_frame_id
= { 0 };
669 struct thread_fsm
*thread_fsm
= NULL
;
674 struct target_waitstatus wait_status
;
676 /* Get the last target status returned by target_wait(). */
677 get_last_target_status (&wait_ptid
, &wait_status
);
679 /* If not stopped at a fork event, then there's nothing else to
681 if (wait_status
.kind
!= TARGET_WAITKIND_FORKED
682 && wait_status
.kind
!= TARGET_WAITKIND_VFORKED
)
685 /* Check if we switched over from WAIT_PTID, since the event was
687 if (wait_ptid
!= minus_one_ptid
688 && inferior_ptid
!= wait_ptid
)
690 /* We did. Switch back to WAIT_PTID thread, to tell the
691 target to follow it (in either direction). We'll
692 afterwards refuse to resume, and inform the user what
694 thread_info
*wait_thread
695 = find_thread_ptid (wait_ptid
);
696 switch_to_thread (wait_thread
);
701 tp
= inferior_thread ();
703 /* If there were any forks/vforks that were caught and are now to be
704 followed, then do so now. */
705 switch (tp
->pending_follow
.kind
)
707 case TARGET_WAITKIND_FORKED
:
708 case TARGET_WAITKIND_VFORKED
:
710 ptid_t parent
, child
;
712 /* If the user did a next/step, etc, over a fork call,
713 preserve the stepping state in the fork child. */
714 if (follow_child
&& should_resume
)
716 step_resume_breakpoint
= clone_momentary_breakpoint
717 (tp
->control
.step_resume_breakpoint
);
718 step_range_start
= tp
->control
.step_range_start
;
719 step_range_end
= tp
->control
.step_range_end
;
720 step_frame_id
= tp
->control
.step_frame_id
;
721 exception_resume_breakpoint
722 = clone_momentary_breakpoint (tp
->control
.exception_resume_breakpoint
);
723 thread_fsm
= tp
->thread_fsm
;
725 /* For now, delete the parent's sr breakpoint, otherwise,
726 parent/child sr breakpoints are considered duplicates,
727 and the child version will not be installed. Remove
728 this when the breakpoints module becomes aware of
729 inferiors and address spaces. */
730 delete_step_resume_breakpoint (tp
);
731 tp
->control
.step_range_start
= 0;
732 tp
->control
.step_range_end
= 0;
733 tp
->control
.step_frame_id
= null_frame_id
;
734 delete_exception_resume_breakpoint (tp
);
735 tp
->thread_fsm
= NULL
;
738 parent
= inferior_ptid
;
739 child
= tp
->pending_follow
.value
.related_pid
;
741 /* Set up inferior(s) as specified by the caller, and tell the
742 target to do whatever is necessary to follow either parent
744 if (follow_fork_inferior (follow_child
, detach_fork
))
746 /* Target refused to follow, or there's some other reason
747 we shouldn't resume. */
752 /* This pending follow fork event is now handled, one way
753 or another. The previous selected thread may be gone
754 from the lists by now, but if it is still around, need
755 to clear the pending follow request. */
756 tp
= find_thread_ptid (parent
);
758 tp
->pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
760 /* This makes sure we don't try to apply the "Switched
761 over from WAIT_PID" logic above. */
762 nullify_last_target_wait_ptid ();
764 /* If we followed the child, switch to it... */
767 thread_info
*child_thr
= find_thread_ptid (child
);
768 switch_to_thread (child_thr
);
770 /* ... and preserve the stepping state, in case the
771 user was stepping over the fork call. */
774 tp
= inferior_thread ();
775 tp
->control
.step_resume_breakpoint
776 = step_resume_breakpoint
;
777 tp
->control
.step_range_start
= step_range_start
;
778 tp
->control
.step_range_end
= step_range_end
;
779 tp
->control
.step_frame_id
= step_frame_id
;
780 tp
->control
.exception_resume_breakpoint
781 = exception_resume_breakpoint
;
782 tp
->thread_fsm
= thread_fsm
;
786 /* If we get here, it was because we're trying to
787 resume from a fork catchpoint, but, the user
788 has switched threads away from the thread that
789 forked. In that case, the resume command
790 issued is most likely not applicable to the
791 child, so just warn, and refuse to resume. */
792 warning (_("Not resuming: switched threads "
793 "before following fork child."));
796 /* Reset breakpoints in the child as appropriate. */
797 follow_inferior_reset_breakpoints ();
802 case TARGET_WAITKIND_SPURIOUS
:
803 /* Nothing to follow. */
806 internal_error (__FILE__
, __LINE__
,
807 "Unexpected pending_follow.kind %d\n",
808 tp
->pending_follow
.kind
);
812 return should_resume
;
816 follow_inferior_reset_breakpoints (void)
818 struct thread_info
*tp
= inferior_thread ();
820 /* Was there a step_resume breakpoint? (There was if the user
821 did a "next" at the fork() call.) If so, explicitly reset its
822 thread number. Cloned step_resume breakpoints are disabled on
823 creation, so enable it here now that it is associated with the
826 step_resumes are a form of bp that are made to be per-thread.
827 Since we created the step_resume bp when the parent process
828 was being debugged, and now are switching to the child process,
829 from the breakpoint package's viewpoint, that's a switch of
830 "threads". We must update the bp's notion of which thread
831 it is for, or it'll be ignored when it triggers. */
833 if (tp
->control
.step_resume_breakpoint
)
835 breakpoint_re_set_thread (tp
->control
.step_resume_breakpoint
);
836 tp
->control
.step_resume_breakpoint
->loc
->enabled
= 1;
839 /* Treat exception_resume breakpoints like step_resume breakpoints. */
840 if (tp
->control
.exception_resume_breakpoint
)
842 breakpoint_re_set_thread (tp
->control
.exception_resume_breakpoint
);
843 tp
->control
.exception_resume_breakpoint
->loc
->enabled
= 1;
846 /* Reinsert all breakpoints in the child. The user may have set
847 breakpoints after catching the fork, in which case those
848 were never set in the child, but only in the parent. This makes
849 sure the inserted breakpoints match the breakpoint list. */
851 breakpoint_re_set ();
852 insert_breakpoints ();
855 /* The child has exited or execed: resume threads of the parent the
856 user wanted to be executing. */
859 proceed_after_vfork_done (struct thread_info
*thread
,
862 int pid
= * (int *) arg
;
864 if (thread
->ptid
.pid () == pid
865 && thread
->state
== THREAD_RUNNING
866 && !thread
->executing
867 && !thread
->stop_requested
868 && thread
->suspend
.stop_signal
== GDB_SIGNAL_0
)
871 fprintf_unfiltered (gdb_stdlog
,
872 "infrun: resuming vfork parent thread %s\n",
873 target_pid_to_str (thread
->ptid
).c_str ());
875 switch_to_thread (thread
);
876 clear_proceed_status (0);
877 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
883 /* Save/restore inferior_ptid, current program space and current
884 inferior. Only use this if the current context points at an exited
885 inferior (and therefore there's no current thread to save). */
886 class scoped_restore_exited_inferior
889 scoped_restore_exited_inferior ()
890 : m_saved_ptid (&inferior_ptid
)
894 scoped_restore_tmpl
<ptid_t
> m_saved_ptid
;
895 scoped_restore_current_program_space m_pspace
;
896 scoped_restore_current_inferior m_inferior
;
899 /* Called whenever we notice an exec or exit event, to handle
900 detaching or resuming a vfork parent. */
903 handle_vfork_child_exec_or_exit (int exec
)
905 struct inferior
*inf
= current_inferior ();
907 if (inf
->vfork_parent
)
909 int resume_parent
= -1;
911 /* This exec or exit marks the end of the shared memory region
912 between the parent and the child. Break the bonds. */
913 inferior
*vfork_parent
= inf
->vfork_parent
;
914 inf
->vfork_parent
->vfork_child
= NULL
;
915 inf
->vfork_parent
= NULL
;
917 /* If the user wanted to detach from the parent, now is the
919 if (vfork_parent
->pending_detach
)
921 struct thread_info
*tp
;
922 struct program_space
*pspace
;
923 struct address_space
*aspace
;
925 /* follow-fork child, detach-on-fork on. */
927 vfork_parent
->pending_detach
= 0;
929 gdb::optional
<scoped_restore_exited_inferior
>
930 maybe_restore_inferior
;
931 gdb::optional
<scoped_restore_current_pspace_and_thread
>
932 maybe_restore_thread
;
934 /* If we're handling a child exit, then inferior_ptid points
935 at the inferior's pid, not to a thread. */
937 maybe_restore_inferior
.emplace ();
939 maybe_restore_thread
.emplace ();
941 /* We're letting loose of the parent. */
942 tp
= any_live_thread_of_inferior (vfork_parent
);
943 switch_to_thread (tp
);
945 /* We're about to detach from the parent, which implicitly
946 removes breakpoints from its address space. There's a
947 catch here: we want to reuse the spaces for the child,
948 but, parent/child are still sharing the pspace at this
949 point, although the exec in reality makes the kernel give
950 the child a fresh set of new pages. The problem here is
951 that the breakpoints module being unaware of this, would
952 likely chose the child process to write to the parent
953 address space. Swapping the child temporarily away from
954 the spaces has the desired effect. Yes, this is "sort
957 pspace
= inf
->pspace
;
958 aspace
= inf
->aspace
;
962 if (print_inferior_events
)
965 = target_pid_to_str (ptid_t (vfork_parent
->pid
));
967 target_terminal::ours_for_output ();
971 fprintf_filtered (gdb_stdlog
,
972 _("[Detaching vfork parent %s "
973 "after child exec]\n"), pidstr
.c_str ());
977 fprintf_filtered (gdb_stdlog
,
978 _("[Detaching vfork parent %s "
979 "after child exit]\n"), pidstr
.c_str ());
983 target_detach (vfork_parent
, 0);
986 inf
->pspace
= pspace
;
987 inf
->aspace
= aspace
;
991 /* We're staying attached to the parent, so, really give the
992 child a new address space. */
993 inf
->pspace
= new program_space (maybe_new_address_space ());
994 inf
->aspace
= inf
->pspace
->aspace
;
996 set_current_program_space (inf
->pspace
);
998 resume_parent
= vfork_parent
->pid
;
1002 struct program_space
*pspace
;
1004 /* If this is a vfork child exiting, then the pspace and
1005 aspaces were shared with the parent. Since we're
1006 reporting the process exit, we'll be mourning all that is
1007 found in the address space, and switching to null_ptid,
1008 preparing to start a new inferior. But, since we don't
1009 want to clobber the parent's address/program spaces, we
1010 go ahead and create a new one for this exiting
1013 /* Switch to null_ptid while running clone_program_space, so
1014 that clone_program_space doesn't want to read the
1015 selected frame of a dead process. */
1016 scoped_restore restore_ptid
1017 = make_scoped_restore (&inferior_ptid
, null_ptid
);
1019 /* This inferior is dead, so avoid giving the breakpoints
1020 module the option to write through to it (cloning a
1021 program space resets breakpoints). */
1024 pspace
= new program_space (maybe_new_address_space ());
1025 set_current_program_space (pspace
);
1027 inf
->symfile_flags
= SYMFILE_NO_READ
;
1028 clone_program_space (pspace
, vfork_parent
->pspace
);
1029 inf
->pspace
= pspace
;
1030 inf
->aspace
= pspace
->aspace
;
1032 resume_parent
= vfork_parent
->pid
;
1035 gdb_assert (current_program_space
== inf
->pspace
);
1037 if (non_stop
&& resume_parent
!= -1)
1039 /* If the user wanted the parent to be running, let it go
1041 scoped_restore_current_thread restore_thread
;
1044 fprintf_unfiltered (gdb_stdlog
,
1045 "infrun: resuming vfork parent process %d\n",
1048 iterate_over_threads (proceed_after_vfork_done
, &resume_parent
);
1053 /* Enum strings for "set|show follow-exec-mode". */
1055 static const char follow_exec_mode_new
[] = "new";
1056 static const char follow_exec_mode_same
[] = "same";
1057 static const char *const follow_exec_mode_names
[] =
1059 follow_exec_mode_new
,
1060 follow_exec_mode_same
,
1064 static const char *follow_exec_mode_string
= follow_exec_mode_same
;
1066 show_follow_exec_mode_string (struct ui_file
*file
, int from_tty
,
1067 struct cmd_list_element
*c
, const char *value
)
1069 fprintf_filtered (file
, _("Follow exec mode is \"%s\".\n"), value
);
1072 /* EXEC_FILE_TARGET is assumed to be non-NULL. */
1075 follow_exec (ptid_t ptid
, const char *exec_file_target
)
1077 struct inferior
*inf
= current_inferior ();
1078 int pid
= ptid
.pid ();
1079 ptid_t process_ptid
;
1081 /* Switch terminal for any messages produced e.g. by
1082 breakpoint_re_set. */
1083 target_terminal::ours_for_output ();
1085 /* This is an exec event that we actually wish to pay attention to.
1086 Refresh our symbol table to the newly exec'd program, remove any
1087 momentary bp's, etc.
1089 If there are breakpoints, they aren't really inserted now,
1090 since the exec() transformed our inferior into a fresh set
1093 We want to preserve symbolic breakpoints on the list, since
1094 we have hopes that they can be reset after the new a.out's
1095 symbol table is read.
1097 However, any "raw" breakpoints must be removed from the list
1098 (e.g., the solib bp's), since their address is probably invalid
1101 And, we DON'T want to call delete_breakpoints() here, since
1102 that may write the bp's "shadow contents" (the instruction
1103 value that was overwritten with a TRAP instruction). Since
1104 we now have a new a.out, those shadow contents aren't valid. */
1106 mark_breakpoints_out ();
1108 /* The target reports the exec event to the main thread, even if
1109 some other thread does the exec, and even if the main thread was
1110 stopped or already gone. We may still have non-leader threads of
1111 the process on our list. E.g., on targets that don't have thread
1112 exit events (like remote); or on native Linux in non-stop mode if
1113 there were only two threads in the inferior and the non-leader
1114 one is the one that execs (and nothing forces an update of the
1115 thread list up to here). When debugging remotely, it's best to
1116 avoid extra traffic, when possible, so avoid syncing the thread
1117 list with the target, and instead go ahead and delete all threads
1118 of the process but one that reported the event. Note this must
1119 be done before calling update_breakpoints_after_exec, as
1120 otherwise clearing the threads' resources would reference stale
1121 thread breakpoints -- it may have been one of these threads that
1122 stepped across the exec. We could just clear their stepping
1123 states, but as long as we're iterating, might as well delete
1124 them. Deleting them now rather than at the next user-visible
1125 stop provides a nicer sequence of events for user and MI
1127 for (thread_info
*th
: all_threads_safe ())
1128 if (th
->ptid
.pid () == pid
&& th
->ptid
!= ptid
)
1131 /* We also need to clear any left over stale state for the
1132 leader/event thread. E.g., if there was any step-resume
1133 breakpoint or similar, it's gone now. We cannot truly
1134 step-to-next statement through an exec(). */
1135 thread_info
*th
= inferior_thread ();
1136 th
->control
.step_resume_breakpoint
= NULL
;
1137 th
->control
.exception_resume_breakpoint
= NULL
;
1138 th
->control
.single_step_breakpoints
= NULL
;
1139 th
->control
.step_range_start
= 0;
1140 th
->control
.step_range_end
= 0;
1142 /* The user may have had the main thread held stopped in the
1143 previous image (e.g., schedlock on, or non-stop). Release
1145 th
->stop_requested
= 0;
1147 update_breakpoints_after_exec ();
1149 /* What is this a.out's name? */
1150 process_ptid
= ptid_t (pid
);
1151 printf_unfiltered (_("%s is executing new program: %s\n"),
1152 target_pid_to_str (process_ptid
).c_str (),
1155 /* We've followed the inferior through an exec. Therefore, the
1156 inferior has essentially been killed & reborn. */
1158 breakpoint_init_inferior (inf_execd
);
1160 gdb::unique_xmalloc_ptr
<char> exec_file_host
1161 = exec_file_find (exec_file_target
, NULL
);
1163 /* If we were unable to map the executable target pathname onto a host
1164 pathname, tell the user that. Otherwise GDB's subsequent behavior
1165 is confusing. Maybe it would even be better to stop at this point
1166 so that the user can specify a file manually before continuing. */
1167 if (exec_file_host
== NULL
)
1168 warning (_("Could not load symbols for executable %s.\n"
1169 "Do you need \"set sysroot\"?"),
1172 /* Reset the shared library package. This ensures that we get a
1173 shlib event when the child reaches "_start", at which point the
1174 dld will have had a chance to initialize the child. */
1175 /* Also, loading a symbol file below may trigger symbol lookups, and
1176 we don't want those to be satisfied by the libraries of the
1177 previous incarnation of this process. */
1178 no_shared_libraries (NULL
, 0);
1180 if (follow_exec_mode_string
== follow_exec_mode_new
)
1182 /* The user wants to keep the old inferior and program spaces
1183 around. Create a new fresh one, and switch to it. */
1185 /* Do exit processing for the original inferior before setting the new
1186 inferior's pid. Having two inferiors with the same pid would confuse
1187 find_inferior_p(t)id. Transfer the terminal state and info from the
1188 old to the new inferior. */
1189 inf
= add_inferior_with_spaces ();
1190 swap_terminal_info (inf
, current_inferior ());
1191 exit_inferior_silent (current_inferior ());
1194 target_follow_exec (inf
, exec_file_target
);
1196 set_current_inferior (inf
);
1197 set_current_program_space (inf
->pspace
);
1202 /* The old description may no longer be fit for the new image.
1203 E.g, a 64-bit process exec'ed a 32-bit process. Clear the
1204 old description; we'll read a new one below. No need to do
1205 this on "follow-exec-mode new", as the old inferior stays
1206 around (its description is later cleared/refetched on
1208 target_clear_description ();
1211 gdb_assert (current_program_space
== inf
->pspace
);
1213 /* Attempt to open the exec file. SYMFILE_DEFER_BP_RESET is used
1214 because the proper displacement for a PIE (Position Independent
1215 Executable) main symbol file will only be computed by
1216 solib_create_inferior_hook below. breakpoint_re_set would fail
1217 to insert the breakpoints with the zero displacement. */
1218 try_open_exec_file (exec_file_host
.get (), inf
, SYMFILE_DEFER_BP_RESET
);
1220 /* If the target can specify a description, read it. Must do this
1221 after flipping to the new executable (because the target supplied
1222 description must be compatible with the executable's
1223 architecture, and the old executable may e.g., be 32-bit, while
1224 the new one 64-bit), and before anything involving memory or
1226 target_find_description ();
1228 solib_create_inferior_hook (0);
1230 jit_inferior_created_hook ();
1232 breakpoint_re_set ();
1234 /* Reinsert all breakpoints. (Those which were symbolic have
1235 been reset to the proper address in the new a.out, thanks
1236 to symbol_file_command...). */
1237 insert_breakpoints ();
1239 /* The next resume of this inferior should bring it to the shlib
1240 startup breakpoints. (If the user had also set bp's on
1241 "main" from the old (parent) process, then they'll auto-
1242 matically get reset there in the new process.). */
1245 /* The queue of threads that need to do a step-over operation to get
1246 past e.g., a breakpoint. What technique is used to step over the
1247 breakpoint/watchpoint does not matter -- all threads end up in the
1248 same queue, to maintain rough temporal order of execution, in order
1249 to avoid starvation, otherwise, we could e.g., find ourselves
1250 constantly stepping the same couple threads past their breakpoints
1251 over and over, if the single-step finish fast enough. */
1252 struct thread_info
*global_thread_step_over_chain_head
;
1254 /* Bit flags indicating what the thread needs to step over. */
1256 enum step_over_what_flag
1258 /* Step over a breakpoint. */
1259 STEP_OVER_BREAKPOINT
= 1,
1261 /* Step past a non-continuable watchpoint, in order to let the
1262 instruction execute so we can evaluate the watchpoint
1264 STEP_OVER_WATCHPOINT
= 2
1266 DEF_ENUM_FLAGS_TYPE (enum step_over_what_flag
, step_over_what
);
1268 /* Info about an instruction that is being stepped over. */
1270 struct step_over_info
1272 /* If we're stepping past a breakpoint, this is the address space
1273 and address of the instruction the breakpoint is set at. We'll
1274 skip inserting all breakpoints here. Valid iff ASPACE is
1276 const address_space
*aspace
;
1279 /* The instruction being stepped over triggers a nonsteppable
1280 watchpoint. If true, we'll skip inserting watchpoints. */
1281 int nonsteppable_watchpoint_p
;
1283 /* The thread's global number. */
1287 /* The step-over info of the location that is being stepped over.
1289 Note that with async/breakpoint always-inserted mode, a user might
1290 set a new breakpoint/watchpoint/etc. exactly while a breakpoint is
1291 being stepped over. As setting a new breakpoint inserts all
1292 breakpoints, we need to make sure the breakpoint being stepped over
1293 isn't inserted then. We do that by only clearing the step-over
1294 info when the step-over is actually finished (or aborted).
1296 Presently GDB can only step over one breakpoint at any given time.
1297 Given threads that can't run code in the same address space as the
1298 breakpoint's can't really miss the breakpoint, GDB could be taught
1299 to step-over at most one breakpoint per address space (so this info
1300 could move to the address space object if/when GDB is extended).
1301 The set of breakpoints being stepped over will normally be much
1302 smaller than the set of all breakpoints, so a flag in the
1303 breakpoint location structure would be wasteful. A separate list
1304 also saves complexity and run-time, as otherwise we'd have to go
1305 through all breakpoint locations clearing their flag whenever we
1306 start a new sequence. Similar considerations weigh against storing
1307 this info in the thread object. Plus, not all step overs actually
1308 have breakpoint locations -- e.g., stepping past a single-step
1309 breakpoint, or stepping to complete a non-continuable
1311 static struct step_over_info step_over_info
;
1313 /* Record the address of the breakpoint/instruction we're currently
1315 N.B. We record the aspace and address now, instead of say just the thread,
1316 because when we need the info later the thread may be running. */
1319 set_step_over_info (const address_space
*aspace
, CORE_ADDR address
,
1320 int nonsteppable_watchpoint_p
,
1323 step_over_info
.aspace
= aspace
;
1324 step_over_info
.address
= address
;
1325 step_over_info
.nonsteppable_watchpoint_p
= nonsteppable_watchpoint_p
;
1326 step_over_info
.thread
= thread
;
1329 /* Called when we're not longer stepping over a breakpoint / an
1330 instruction, so all breakpoints are free to be (re)inserted. */
1333 clear_step_over_info (void)
1336 fprintf_unfiltered (gdb_stdlog
,
1337 "infrun: clear_step_over_info\n");
1338 step_over_info
.aspace
= NULL
;
1339 step_over_info
.address
= 0;
1340 step_over_info
.nonsteppable_watchpoint_p
= 0;
1341 step_over_info
.thread
= -1;
1347 stepping_past_instruction_at (struct address_space
*aspace
,
1350 return (step_over_info
.aspace
!= NULL
1351 && breakpoint_address_match (aspace
, address
,
1352 step_over_info
.aspace
,
1353 step_over_info
.address
));
1359 thread_is_stepping_over_breakpoint (int thread
)
1361 return (step_over_info
.thread
!= -1
1362 && thread
== step_over_info
.thread
);
1368 stepping_past_nonsteppable_watchpoint (void)
1370 return step_over_info
.nonsteppable_watchpoint_p
;
1373 /* Returns true if step-over info is valid. */
1376 step_over_info_valid_p (void)
1378 return (step_over_info
.aspace
!= NULL
1379 || stepping_past_nonsteppable_watchpoint ());
1383 /* Displaced stepping. */
1385 /* In non-stop debugging mode, we must take special care to manage
1386 breakpoints properly; in particular, the traditional strategy for
1387 stepping a thread past a breakpoint it has hit is unsuitable.
1388 'Displaced stepping' is a tactic for stepping one thread past a
1389 breakpoint it has hit while ensuring that other threads running
1390 concurrently will hit the breakpoint as they should.
1392 The traditional way to step a thread T off a breakpoint in a
1393 multi-threaded program in all-stop mode is as follows:
1395 a0) Initially, all threads are stopped, and breakpoints are not
1397 a1) We single-step T, leaving breakpoints uninserted.
1398 a2) We insert breakpoints, and resume all threads.
1400 In non-stop debugging, however, this strategy is unsuitable: we
1401 don't want to have to stop all threads in the system in order to
1402 continue or step T past a breakpoint. Instead, we use displaced
1405 n0) Initially, T is stopped, other threads are running, and
1406 breakpoints are inserted.
1407 n1) We copy the instruction "under" the breakpoint to a separate
1408 location, outside the main code stream, making any adjustments
1409 to the instruction, register, and memory state as directed by
1411 n2) We single-step T over the instruction at its new location.
1412 n3) We adjust the resulting register and memory state as directed
1413 by T's architecture. This includes resetting T's PC to point
1414 back into the main instruction stream.
1417 This approach depends on the following gdbarch methods:
1419 - gdbarch_max_insn_length and gdbarch_displaced_step_location
1420 indicate where to copy the instruction, and how much space must
1421 be reserved there. We use these in step n1.
1423 - gdbarch_displaced_step_copy_insn copies a instruction to a new
1424 address, and makes any necessary adjustments to the instruction,
1425 register contents, and memory. We use this in step n1.
1427 - gdbarch_displaced_step_fixup adjusts registers and memory after
1428 we have successfully single-stepped the instruction, to yield the
1429 same effect the instruction would have had if we had executed it
1430 at its original address. We use this in step n3.
1432 The gdbarch_displaced_step_copy_insn and
1433 gdbarch_displaced_step_fixup functions must be written so that
1434 copying an instruction with gdbarch_displaced_step_copy_insn,
1435 single-stepping across the copied instruction, and then applying
1436 gdbarch_displaced_insn_fixup should have the same effects on the
1437 thread's memory and registers as stepping the instruction in place
1438 would have. Exactly which responsibilities fall to the copy and
1439 which fall to the fixup is up to the author of those functions.
1441 See the comments in gdbarch.sh for details.
1443 Note that displaced stepping and software single-step cannot
1444 currently be used in combination, although with some care I think
1445 they could be made to. Software single-step works by placing
1446 breakpoints on all possible subsequent instructions; if the
1447 displaced instruction is a PC-relative jump, those breakpoints
1448 could fall in very strange places --- on pages that aren't
1449 executable, or at addresses that are not proper instruction
1450 boundaries. (We do generally let other threads run while we wait
1451 to hit the software single-step breakpoint, and they might
1452 encounter such a corrupted instruction.) One way to work around
1453 this would be to have gdbarch_displaced_step_copy_insn fully
1454 simulate the effect of PC-relative instructions (and return NULL)
1455 on architectures that use software single-stepping.
1457 In non-stop mode, we can have independent and simultaneous step
1458 requests, so more than one thread may need to simultaneously step
1459 over a breakpoint. The current implementation assumes there is
1460 only one scratch space per process. In this case, we have to
1461 serialize access to the scratch space. If thread A wants to step
1462 over a breakpoint, but we are currently waiting for some other
1463 thread to complete a displaced step, we leave thread A stopped and
1464 place it in the displaced_step_request_queue. Whenever a displaced
1465 step finishes, we pick the next thread in the queue and start a new
1466 displaced step operation on it. See displaced_step_prepare and
1467 displaced_step_fixup for details. */
1469 /* Get the displaced stepping state of inferior INF. */
1471 static displaced_step_inferior_state
*
1472 get_displaced_stepping_state (inferior
*inf
)
1474 return &inf
->displaced_step_state
;
1477 /* Get the displaced stepping state of thread THREAD. */
1479 static displaced_step_thread_state
*
1480 get_displaced_stepping_state (thread_info
*thread
)
1482 return &thread
->displaced_step_state
;
1485 /* Return true if the given thread is doing a displaced step. */
1488 displaced_step_in_progress (thread_info
*thread
)
1490 gdb_assert (thread
!= NULL
);
1492 return get_displaced_stepping_state (thread
)->in_progress ();
1495 /* Return true if any thread of this inferior is doing a displaced step. */
1498 displaced_step_in_progress (inferior
*inf
)
1500 for (thread_info
*thread
: inf
->non_exited_threads ())
1502 if (displaced_step_in_progress (thread
))
1509 /* Return true if any thread is doing a displaced step. */
1512 displaced_step_in_progress_any_thread ()
1514 for (thread_info
*thread
: all_non_exited_threads ())
1516 if (displaced_step_in_progress (thread
))
1523 /* If inferior is in displaced stepping, and ADDR equals to starting address
1524 of copy area, return corresponding displaced_step_copy_insn_closure. Otherwise,
1527 struct displaced_step_copy_insn_closure
*
1528 get_displaced_step_copy_insn_closure_by_addr (CORE_ADDR addr
)
1530 // FIXME: implement me (only needed on ARM).
1531 // displaced_step_inferior_state *displaced
1532 // = get_displaced_stepping_state (current_inferior ());
1534 // /* If checking the mode of displaced instruction in copy area. */
1535 // if (displaced->step_thread != nullptr
1536 // && displaced->step_copy == addr)
1537 // return displaced->step_closure.get ();
1543 infrun_inferior_exit (struct inferior
*inf
)
1545 inf
->displaced_step_state
.reset ();
1548 /* If ON, and the architecture supports it, GDB will use displaced
1549 stepping to step over breakpoints. If OFF, or if the architecture
1550 doesn't support it, GDB will instead use the traditional
1551 hold-and-step approach. If AUTO (which is the default), GDB will
1552 decide which technique to use to step over breakpoints depending on
1553 whether the target works in a non-stop way (see use_displaced_stepping). */
1555 static enum auto_boolean can_use_displaced_stepping
= AUTO_BOOLEAN_AUTO
;
1558 show_can_use_displaced_stepping (struct ui_file
*file
, int from_tty
,
1559 struct cmd_list_element
*c
,
1562 if (can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
)
1563 fprintf_filtered (file
,
1564 _("Debugger's willingness to use displaced stepping "
1565 "to step over breakpoints is %s (currently %s).\n"),
1566 value
, target_is_non_stop_p () ? "on" : "off");
1568 fprintf_filtered (file
,
1569 _("Debugger's willingness to use displaced stepping "
1570 "to step over breakpoints is %s.\n"), value
);
1573 /* Return true if the gdbarch implements the required methods to use
1574 displaced stepping. */
1577 gdbarch_supports_displaced_stepping (gdbarch
*arch
)
1579 /* Only check for the presence of copy_insn. Other required methods
1580 are checked by the gdbarch validation to be provided if copy_insn is
1582 return gdbarch_displaced_step_copy_insn_p (arch
);
1585 /* Return non-zero if displaced stepping can/should be used to step
1586 over breakpoints of thread TP. */
1589 use_displaced_stepping (thread_info
*tp
)
1591 /* If the user disabled it explicitly, don't use displaced stepping. */
1592 if (can_use_displaced_stepping
== AUTO_BOOLEAN_FALSE
)
1595 /* If "auto", only use displaced stepping if the target operates in a non-stop
1597 if (can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
1598 && !target_is_non_stop_p ())
1601 gdbarch
*gdbarch
= get_thread_regcache (tp
)->arch ();
1603 /* If the architecture doesn't implement displaced stepping, don't use
1605 if (!gdbarch_supports_displaced_stepping (gdbarch
))
1608 /* If recording, don't use displaced stepping. */
1609 if (find_record_target () != nullptr)
1612 displaced_step_inferior_state
*displaced_state
1613 = get_displaced_stepping_state (tp
->inf
);
1615 /* If displaced stepping failed before for this inferior, don't bother trying
1617 if (displaced_state
->failed_before
)
1623 /* Simple function wrapper around displaced_step_thread_state::reset. */
1626 displaced_step_reset (displaced_step_thread_state
*displaced
)
1628 displaced
->reset ();
1631 /* A cleanup that wraps displaced_step_reset. We use this instead of, say,
1632 SCOPE_EXIT, because it needs to be discardable with "cleanup.release ()". */
1634 using displaced_step_reset_cleanup
= FORWARD_SCOPE_EXIT (displaced_step_reset
);
1636 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */
1638 displaced_step_dump_bytes (struct ui_file
*file
,
1639 const gdb_byte
*buf
,
1644 for (i
= 0; i
< len
; i
++)
1645 fprintf_unfiltered (file
, "%02x ", buf
[i
]);
1646 fputs_unfiltered ("\n", file
);
1649 /* Prepare to single-step, using displaced stepping.
1651 Note that we cannot use displaced stepping when we have a signal to
1652 deliver. If we have a signal to deliver and an instruction to step
1653 over, then after the step, there will be no indication from the
1654 target whether the thread entered a signal handler or ignored the
1655 signal and stepped over the instruction successfully --- both cases
1656 result in a simple SIGTRAP. In the first case we mustn't do a
1657 fixup, and in the second case we must --- but we can't tell which.
1658 Comments in the code for 'random signals' in handle_inferior_event
1659 explain how we handle this case instead.
1661 Returns 1 if preparing was successful -- this thread is going to be
1662 stepped now; 0 if displaced stepping this thread got queued; or -1
1663 if this instruction can't be displaced stepped. */
1665 static displaced_step_prepare_status
1666 displaced_step_prepare_throw (thread_info
*tp
)
1668 regcache
*regcache
= get_thread_regcache (tp
);
1669 struct gdbarch
*gdbarch
= regcache
->arch ();
1670 displaced_step_thread_state
*thread_disp_step_state
1671 = get_displaced_stepping_state (tp
);
1673 /* We should never reach this function if the architecture does not
1674 support displaced stepping. */
1675 gdb_assert (gdbarch_supports_displaced_stepping (gdbarch
));
1677 /* Nor if the thread isn't meant to step over a breakpoint. */
1678 gdb_assert (tp
->control
.trap_expected
);
1680 /* Disable range stepping while executing in the scratch pad. We
1681 want a single-step even if executing the displaced instruction in
1682 the scratch buffer lands within the stepping range (e.g., a
1684 tp
->control
.may_range_step
= 0;
1686 /* We are about to start a displaced step for this thread, if one is already
1687 in progress, we goofed up somewhere. */
1688 gdb_assert (!thread_disp_step_state
->in_progress ());
1690 scoped_restore_current_thread restore_thread
;
1692 switch_to_thread (tp
);
1694 CORE_ADDR original_pc
= regcache_read_pc (regcache
);
1696 displaced_step_prepare_status status
=
1697 gdbarch_displaced_step_prepare (gdbarch
, tp
);
1699 if (status
== DISPLACED_STEP_PREPARE_STATUS_ERROR
)
1701 if (debug_displaced
)
1702 fprintf_unfiltered (gdb_stdlog
,
1703 "displaced: failed to prepare (%s)",
1704 target_pid_to_str (tp
->ptid
).c_str ());
1706 return DISPLACED_STEP_PREPARE_STATUS_ERROR
;
1708 else if (status
== DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
)
1710 /* Not enough displaced stepping resources available, defer this
1711 request by placing it the queue. */
1713 if (debug_displaced
)
1714 fprintf_unfiltered (gdb_stdlog
,
1715 "displaced: not enough resources available, "
1716 "deferring step of %s\n",
1717 target_pid_to_str (tp
->ptid
).c_str ());
1719 global_thread_step_over_chain_enqueue (tp
);
1721 return DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
;
1724 gdb_assert (status
== DISPLACED_STEP_PREPARE_STATUS_OK
);
1726 // FIXME: Should probably replicated in the arch implementation now.
1728 // if (breakpoint_in_range_p (aspace, copy, len))
1730 // /* There's a breakpoint set in the scratch pad location range
1731 // (which is usually around the entry point). We'd either
1732 // install it before resuming, which would overwrite/corrupt the
1733 // scratch pad, or if it was already inserted, this displaced
1734 // step would overwrite it. The latter is OK in the sense that
1735 // we already assume that no thread is going to execute the code
1736 // in the scratch pad range (after initial startup) anyway, but
1737 // the former is unacceptable. Simply punt and fallback to
1738 // stepping over this breakpoint in-line. */
1739 // if (debug_displaced)
1741 // fprintf_unfiltered (gdb_stdlog,
1742 // "displaced: breakpoint set in scratch pad. "
1743 // "Stepping over breakpoint in-line instead.\n");
1746 // gdb_assert (false);
1747 // gdbarch_displaced_step_release_location (gdbarch, copy);
1752 /* Save the information we need to fix things up if the step
1754 thread_disp_step_state
->set (gdbarch
);
1756 // FIXME: get it from _prepare?
1757 CORE_ADDR displaced_pc
= 0;
1759 if (debug_displaced
)
1760 fprintf_unfiltered (gdb_stdlog
,
1761 "displaced: prepared successfully thread=%s, "
1762 "original_pc=%s, displaced_pc=%s\n",
1763 target_pid_to_str (tp
->ptid
).c_str (),
1764 paddress (gdbarch
, original_pc
),
1765 paddress (gdbarch
, displaced_pc
));
1767 return DISPLACED_STEP_PREPARE_STATUS_OK
;
1770 /* Wrapper for displaced_step_prepare_throw that disabled further
1771 attempts at displaced stepping if we get a memory error. */
1773 static displaced_step_prepare_status
1774 displaced_step_prepare (thread_info
*thread
)
1776 displaced_step_prepare_status status
1777 = DISPLACED_STEP_PREPARE_STATUS_ERROR
;
1781 status
= displaced_step_prepare_throw (thread
);
1783 catch (const gdb_exception_error
&ex
)
1785 struct displaced_step_inferior_state
*displaced_state
;
1787 if (ex
.error
!= MEMORY_ERROR
1788 && ex
.error
!= NOT_SUPPORTED_ERROR
)
1793 fprintf_unfiltered (gdb_stdlog
,
1794 "infrun: disabling displaced stepping: %s\n",
1798 /* Be verbose if "set displaced-stepping" is "on", silent if
1800 if (can_use_displaced_stepping
== AUTO_BOOLEAN_TRUE
)
1802 warning (_("disabling displaced stepping: %s"),
1806 /* Disable further displaced stepping attempts. */
1808 = get_displaced_stepping_state (thread
->inf
);
1809 displaced_state
->failed_before
= 1;
1815 /* If we displaced stepped an instruction successfully, adjust
1816 registers and memory to yield the same effect the instruction would
1817 have had if we had executed it at its original address, and return
1818 1. If the instruction didn't complete, relocate the PC and return
1819 -1. If the thread wasn't displaced stepping, return 0. */
1822 displaced_step_finish (thread_info
*event_thread
, enum gdb_signal signal
)
1824 displaced_step_thread_state
*displaced
1825 = get_displaced_stepping_state (event_thread
);
1827 /* Was this thread performing a displaced step? */
1828 if (!displaced
->in_progress ())
1831 displaced_step_reset_cleanup
cleanup (displaced
);
1833 /* Fixup may need to read memory/registers. Switch to the thread
1834 that we're fixing up. Also, target_stopped_by_watchpoint checks
1835 the current thread, and displaced_step_restore performs ptid-dependent
1836 memory accesses using current_inferior() and current_top_target(). */
1837 switch_to_thread (event_thread
);
1839 /* Do the fixup, and release the resources acquired to do the displaced
1841 displaced_step_finish_status finish_status
=
1842 gdbarch_displaced_step_finish (displaced
->get_original_gdbarch (),
1843 event_thread
, signal
);
1845 if (finish_status
== DISPLACED_STEP_FINISH_STATUS_OK
)
1851 /* Data to be passed around while handling an event. This data is
1852 discarded between events. */
1853 struct execution_control_state
1856 /* The thread that got the event, if this was a thread event; NULL
1858 struct thread_info
*event_thread
;
1860 struct target_waitstatus ws
;
1861 int stop_func_filled_in
;
1862 CORE_ADDR stop_func_start
;
1863 CORE_ADDR stop_func_end
;
1864 const char *stop_func_name
;
1867 /* True if the event thread hit the single-step breakpoint of
1868 another thread. Thus the event doesn't cause a stop, the thread
1869 needs to be single-stepped past the single-step breakpoint before
1870 we can switch back to the original stepping thread. */
1871 int hit_singlestep_breakpoint
;
1874 /* Clear ECS and set it to point at TP. */
1877 reset_ecs (struct execution_control_state
*ecs
, struct thread_info
*tp
)
1879 memset (ecs
, 0, sizeof (*ecs
));
1880 ecs
->event_thread
= tp
;
1881 ecs
->ptid
= tp
->ptid
;
1884 static void keep_going_pass_signal (struct execution_control_state
*ecs
);
1885 static void prepare_to_wait (struct execution_control_state
*ecs
);
1886 static int keep_going_stepped_thread (struct thread_info
*tp
);
1887 static step_over_what
thread_still_needs_step_over (struct thread_info
*tp
);
1889 /* Are there any pending step-over requests? If so, run all we can
1890 now and return true. Otherwise, return false. */
1893 start_step_over (void)
1895 struct thread_info
*tp
, *next
;
1898 /* Don't start a new step-over if we already have an in-line
1899 step-over operation ongoing. */
1900 if (step_over_info_valid_p ())
1903 /* Steal the global thread step over chain. */
1904 thread_info
*threads_to_step
= global_thread_step_over_chain_head
;
1905 global_thread_step_over_chain_head
= NULL
;
1908 fprintf_unfiltered (gdb_stdlog
,
1909 "infrun: stealing list of %d threads to step from global queue\n",
1910 thread_step_over_chain_length (threads_to_step
));
1912 for (tp
= threads_to_step
; tp
!= NULL
; tp
= next
)
1914 struct execution_control_state ecss
;
1915 struct execution_control_state
*ecs
= &ecss
;
1916 step_over_what step_what
;
1917 int must_be_in_line
;
1919 gdb_assert (!tp
->stop_requested
);
1921 next
= thread_step_over_chain_next (threads_to_step
, tp
);
1923 step_what
= thread_still_needs_step_over (tp
);
1924 must_be_in_line
= ((step_what
& STEP_OVER_WATCHPOINT
)
1925 || ((step_what
& STEP_OVER_BREAKPOINT
)
1926 && !use_displaced_stepping (tp
)));
1928 /* We currently stop all threads of all processes to step-over
1929 in-line. If we need to start a new in-line step-over, let
1930 any pending displaced steps finish first. */
1931 if (must_be_in_line
&& displaced_step_in_progress_any_thread ())
1934 thread_step_over_chain_remove (&threads_to_step
, tp
);
1936 if (tp
->control
.trap_expected
1940 internal_error (__FILE__
, __LINE__
,
1941 "[%s] has inconsistent state: "
1942 "trap_expected=%d, resumed=%d, executing=%d\n",
1943 target_pid_to_str (tp
->ptid
).c_str (),
1944 tp
->control
.trap_expected
,
1950 fprintf_unfiltered (gdb_stdlog
,
1951 "infrun: resuming [%s] for step-over\n",
1952 target_pid_to_str (tp
->ptid
).c_str ());
1954 /* keep_going_pass_signal skips the step-over if the breakpoint
1955 is no longer inserted. In all-stop, we want to keep looking
1956 for a thread that needs a step-over instead of resuming TP,
1957 because we wouldn't be able to resume anything else until the
1958 target stops again. In non-stop, the resume always resumes
1959 only TP, so it's OK to let the thread resume freely. */
1960 if (!target_is_non_stop_p () && !step_what
)
1963 switch_to_thread (tp
);
1964 reset_ecs (ecs
, tp
);
1965 keep_going_pass_signal (ecs
);
1967 if (!ecs
->wait_some_more
)
1968 error (_("Command aborted."));
1970 /* If the thread's step over could not be initiated, it was re-added
1971 to the global step over chain. */
1975 fprintf_unfiltered (gdb_stdlog
, "infrun: start_step_over: [%s] was resumed.\n",
1976 target_pid_to_str (tp
->ptid
).c_str ());
1977 gdb_assert (!thread_is_in_step_over_chain (tp
));
1982 fprintf_unfiltered (gdb_stdlog
, "infrun: start_step_over: [%s] was NOT resumed.\n",
1983 target_pid_to_str (tp
->ptid
).c_str ());
1984 gdb_assert (thread_is_in_step_over_chain (tp
));
1988 /* If we started a new in-line step-over, we're done. */
1989 if (step_over_info_valid_p ())
1991 gdb_assert (tp
->control
.trap_expected
);
1996 if (!target_is_non_stop_p ())
1998 /* On all-stop, shouldn't have resumed unless we needed a
2000 gdb_assert (tp
->control
.trap_expected
2001 || tp
->step_after_step_resume_breakpoint
);
2003 /* With remote targets (at least), in all-stop, we can't
2004 issue any further remote commands until the program stops
2010 /* Either the thread no longer needed a step-over, or a new
2011 displaced stepping sequence started. Even in the latter
2012 case, continue looking. Maybe we can also start another
2013 displaced step on a thread of other process. */
2016 /* If there are threads left in the THREADS_TO_STEP list, but we have
2017 detected that we can't start anything more, put back these threads
2018 in the global list. */
2019 if (threads_to_step
== NULL
)
2022 fprintf_unfiltered (gdb_stdlog
,
2023 "infrun: step-over queue now empty\n");
2028 fprintf_unfiltered (gdb_stdlog
,
2029 "infrun: putting back %d threads to step in global queue\n",
2030 thread_step_over_chain_length (threads_to_step
));
2031 while (threads_to_step
!= nullptr)
2033 thread_info
*thread
= threads_to_step
;
2035 /* Remove from that list. */
2036 thread_step_over_chain_remove (&threads_to_step
, thread
);
2038 /* Add to global list. */
2039 global_thread_step_over_chain_enqueue (thread
);
2047 /* Update global variables holding ptids to hold NEW_PTID if they were
2048 holding OLD_PTID. */
2050 infrun_thread_ptid_changed (ptid_t old_ptid
, ptid_t new_ptid
)
2052 if (inferior_ptid
== old_ptid
)
2053 inferior_ptid
= new_ptid
;
2058 static const char schedlock_off
[] = "off";
2059 static const char schedlock_on
[] = "on";
2060 static const char schedlock_step
[] = "step";
2061 static const char schedlock_replay
[] = "replay";
2062 static const char *const scheduler_enums
[] = {
2069 static const char *scheduler_mode
= schedlock_replay
;
2071 show_scheduler_mode (struct ui_file
*file
, int from_tty
,
2072 struct cmd_list_element
*c
, const char *value
)
2074 fprintf_filtered (file
,
2075 _("Mode for locking scheduler "
2076 "during execution is \"%s\".\n"),
2081 set_schedlock_func (const char *args
, int from_tty
, struct cmd_list_element
*c
)
2083 if (!target_can_lock_scheduler
)
2085 scheduler_mode
= schedlock_off
;
2086 error (_("Target '%s' cannot support this command."), target_shortname
);
2090 /* True if execution commands resume all threads of all processes by
2091 default; otherwise, resume only threads of the current inferior
2093 bool sched_multi
= false;
2095 /* Try to setup for software single stepping over the specified location.
2096 Return 1 if target_resume() should use hardware single step.
2098 GDBARCH the current gdbarch.
2099 PC the location to step over. */
2102 maybe_software_singlestep (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
2106 if (execution_direction
== EXEC_FORWARD
2107 && gdbarch_software_single_step_p (gdbarch
))
2108 hw_step
= !insert_single_step_breakpoints (gdbarch
);
2116 user_visible_resume_ptid (int step
)
2122 /* With non-stop mode on, threads are always handled
2124 resume_ptid
= inferior_ptid
;
2126 else if ((scheduler_mode
== schedlock_on
)
2127 || (scheduler_mode
== schedlock_step
&& step
))
2129 /* User-settable 'scheduler' mode requires solo thread
2131 resume_ptid
= inferior_ptid
;
2133 else if ((scheduler_mode
== schedlock_replay
)
2134 && target_record_will_replay (minus_one_ptid
, execution_direction
))
2136 /* User-settable 'scheduler' mode requires solo thread resume in replay
2138 resume_ptid
= inferior_ptid
;
2140 else if (!sched_multi
&& target_supports_multi_process ())
2142 /* Resume all threads of the current process (and none of other
2144 resume_ptid
= ptid_t (inferior_ptid
.pid ());
2148 /* Resume all threads of all processes. */
2149 resume_ptid
= RESUME_ALL
;
2155 /* Return a ptid representing the set of threads that we will resume,
2156 in the perspective of the target, assuming run control handling
2157 does not require leaving some threads stopped (e.g., stepping past
2158 breakpoint). USER_STEP indicates whether we're about to start the
2159 target for a stepping command. */
2162 internal_resume_ptid (int user_step
)
2164 /* In non-stop, we always control threads individually. Note that
2165 the target may always work in non-stop mode even with "set
2166 non-stop off", in which case user_visible_resume_ptid could
2167 return a wildcard ptid. */
2168 if (target_is_non_stop_p ())
2169 return inferior_ptid
;
2171 return user_visible_resume_ptid (user_step
);
2174 /* Wrapper for target_resume, that handles infrun-specific
2178 do_target_resume (ptid_t resume_ptid
, int step
, enum gdb_signal sig
)
2180 struct thread_info
*tp
= inferior_thread ();
2182 gdb_assert (!tp
->stop_requested
);
2184 /* Install inferior's terminal modes. */
2185 target_terminal::inferior ();
2187 /* Avoid confusing the next resume, if the next stop/resume
2188 happens to apply to another thread. */
2189 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2191 /* Advise target which signals may be handled silently.
2193 If we have removed breakpoints because we are stepping over one
2194 in-line (in any thread), we need to receive all signals to avoid
2195 accidentally skipping a breakpoint during execution of a signal
2198 Likewise if we're displaced stepping, otherwise a trap for a
2199 breakpoint in a signal handler might be confused with the
2200 displaced step finishing. We don't make the displaced_step_fixup
2201 step distinguish the cases instead, because:
2203 - a backtrace while stopped in the signal handler would show the
2204 scratch pad as frame older than the signal handler, instead of
2205 the real mainline code.
2207 - when the thread is later resumed, the signal handler would
2208 return to the scratch pad area, which would no longer be
2210 if (step_over_info_valid_p ()
2211 || displaced_step_in_progress (tp
->inf
))
2212 target_pass_signals ({});
2214 target_pass_signals (signal_pass
);
2216 target_resume (resume_ptid
, step
, sig
);
2218 target_commit_resume ();
2221 /* Resume the inferior. SIG is the signal to give the inferior
2222 (GDB_SIGNAL_0 for none). Note: don't call this directly; instead
2223 call 'resume', which handles exceptions. */
2226 resume_1 (enum gdb_signal sig
)
2228 struct regcache
*regcache
= get_current_regcache ();
2229 struct gdbarch
*gdbarch
= regcache
->arch ();
2230 struct thread_info
*tp
= inferior_thread ();
2231 CORE_ADDR pc
= regcache_read_pc (regcache
);
2232 const address_space
*aspace
= regcache
->aspace ();
2234 /* This represents the user's step vs continue request. When
2235 deciding whether "set scheduler-locking step" applies, it's the
2236 user's intention that counts. */
2237 const int user_step
= tp
->control
.stepping_command
;
2238 /* This represents what we'll actually request the target to do.
2239 This can decay from a step to a continue, if e.g., we need to
2240 implement single-stepping with breakpoints (software
2244 gdb_assert (!tp
->stop_requested
);
2245 gdb_assert (!thread_is_in_step_over_chain (tp
));
2247 if (tp
->suspend
.waitstatus_pending_p
)
2252 = target_waitstatus_to_string (&tp
->suspend
.waitstatus
);
2254 fprintf_unfiltered (gdb_stdlog
,
2255 "infrun: resume: thread %s has pending wait "
2256 "status %s (currently_stepping=%d).\n",
2257 target_pid_to_str (tp
->ptid
).c_str (),
2259 currently_stepping (tp
));
2264 /* FIXME: What should we do if we are supposed to resume this
2265 thread with a signal? Maybe we should maintain a queue of
2266 pending signals to deliver. */
2267 if (sig
!= GDB_SIGNAL_0
)
2269 warning (_("Couldn't deliver signal %s to %s."),
2270 gdb_signal_to_name (sig
),
2271 target_pid_to_str (tp
->ptid
).c_str ());
2274 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2276 if (target_can_async_p ())
2279 /* Tell the event loop we have an event to process. */
2280 mark_async_event_handler (infrun_async_inferior_event_token
);
2285 tp
->stepped_breakpoint
= 0;
2287 /* Depends on stepped_breakpoint. */
2288 step
= currently_stepping (tp
);
2290 if (current_inferior ()->waiting_for_vfork_done
)
2292 /* Don't try to single-step a vfork parent that is waiting for
2293 the child to get out of the shared memory region (by exec'ing
2294 or exiting). This is particularly important on software
2295 single-step archs, as the child process would trip on the
2296 software single step breakpoint inserted for the parent
2297 process. Since the parent will not actually execute any
2298 instruction until the child is out of the shared region (such
2299 are vfork's semantics), it is safe to simply continue it.
2300 Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for
2301 the parent, and tell it to `keep_going', which automatically
2302 re-sets it stepping. */
2304 fprintf_unfiltered (gdb_stdlog
,
2305 "infrun: resume : clear step\n");
2310 fprintf_unfiltered (gdb_stdlog
,
2311 "infrun: resume (step=%d, signal=%s), "
2312 "trap_expected=%d, current thread [%s] at %s\n",
2313 step
, gdb_signal_to_symbol_string (sig
),
2314 tp
->control
.trap_expected
,
2315 target_pid_to_str (inferior_ptid
).c_str (),
2316 paddress (gdbarch
, pc
));
2318 /* Normally, by the time we reach `resume', the breakpoints are either
2319 removed or inserted, as appropriate. The exception is if we're sitting
2320 at a permanent breakpoint; we need to step over it, but permanent
2321 breakpoints can't be removed. So we have to test for it here. */
2322 if (breakpoint_here_p (aspace
, pc
) == permanent_breakpoint_here
)
2324 if (sig
!= GDB_SIGNAL_0
)
2326 /* We have a signal to pass to the inferior. The resume
2327 may, or may not take us to the signal handler. If this
2328 is a step, we'll need to stop in the signal handler, if
2329 there's one, (if the target supports stepping into
2330 handlers), or in the next mainline instruction, if
2331 there's no handler. If this is a continue, we need to be
2332 sure to run the handler with all breakpoints inserted.
2333 In all cases, set a breakpoint at the current address
2334 (where the handler returns to), and once that breakpoint
2335 is hit, resume skipping the permanent breakpoint. If
2336 that breakpoint isn't hit, then we've stepped into the
2337 signal handler (or hit some other event). We'll delete
2338 the step-resume breakpoint then. */
2341 fprintf_unfiltered (gdb_stdlog
,
2342 "infrun: resume: skipping permanent breakpoint, "
2343 "deliver signal first\n");
2345 clear_step_over_info ();
2346 tp
->control
.trap_expected
= 0;
2348 if (tp
->control
.step_resume_breakpoint
== NULL
)
2350 /* Set a "high-priority" step-resume, as we don't want
2351 user breakpoints at PC to trigger (again) when this
2353 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
2354 gdb_assert (tp
->control
.step_resume_breakpoint
->loc
->permanent
);
2356 tp
->step_after_step_resume_breakpoint
= step
;
2359 insert_breakpoints ();
2363 /* There's no signal to pass, we can go ahead and skip the
2364 permanent breakpoint manually. */
2366 fprintf_unfiltered (gdb_stdlog
,
2367 "infrun: resume: skipping permanent breakpoint\n");
2368 gdbarch_skip_permanent_breakpoint (gdbarch
, regcache
);
2369 /* Update pc to reflect the new address from which we will
2370 execute instructions. */
2371 pc
= regcache_read_pc (regcache
);
2375 /* We've already advanced the PC, so the stepping part
2376 is done. Now we need to arrange for a trap to be
2377 reported to handle_inferior_event. Set a breakpoint
2378 at the current PC, and run to it. Don't update
2379 prev_pc, because if we end in
2380 switch_back_to_stepped_thread, we want the "expected
2381 thread advanced also" branch to be taken. IOW, we
2382 don't want this thread to step further from PC
2384 gdb_assert (!step_over_info_valid_p ());
2385 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
2386 insert_breakpoints ();
2388 resume_ptid
= internal_resume_ptid (user_step
);
2389 do_target_resume (resume_ptid
, 0, GDB_SIGNAL_0
);
2396 /* If we have a breakpoint to step over, make sure to do a single
2397 step only. Same if we have software watchpoints. */
2398 if (tp
->control
.trap_expected
|| bpstat_should_step ())
2399 tp
->control
.may_range_step
= 0;
2401 /* If enabled, step over breakpoints by executing a copy of the
2402 instruction at a different address.
2404 We can't use displaced stepping when we have a signal to deliver;
2405 the comments for displaced_step_prepare explain why. The
2406 comments in the handle_inferior event for dealing with 'random
2407 signals' explain what we do instead.
2409 We can't use displaced stepping when we are waiting for vfork_done
2410 event, displaced stepping breaks the vfork child similarly as single
2411 step software breakpoint. */
2412 if (tp
->control
.trap_expected
2413 && use_displaced_stepping (tp
)
2414 && !step_over_info_valid_p ()
2415 && sig
== GDB_SIGNAL_0
2416 && !current_inferior ()->waiting_for_vfork_done
)
2418 displaced_step_prepare_status prepare_status
2419 = displaced_step_prepare (tp
);
2421 if (prepare_status
== DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
)
2424 fprintf_unfiltered (gdb_stdlog
,
2425 "Got placed in step-over queue\n");
2427 tp
->control
.trap_expected
= 0;
2430 else if (prepare_status
== DISPLACED_STEP_PREPARE_STATUS_ERROR
)
2432 /* Fallback to stepping over the breakpoint in-line. */
2434 if (target_is_non_stop_p ())
2435 stop_all_threads ();
2437 set_step_over_info (regcache
->aspace (),
2438 regcache_read_pc (regcache
), 0, tp
->global_num
);
2440 step
= maybe_software_singlestep (gdbarch
, pc
);
2442 insert_breakpoints ();
2444 else if (prepare_status
== DISPLACED_STEP_PREPARE_STATUS_OK
)
2446 step
= gdbarch_displaced_step_hw_singlestep (gdbarch
, NULL
);
2449 gdb_assert_not_reached ("invalid displaced_step_prepare_status value");
2452 /* Do we need to do it the hard way, w/temp breakpoints? */
2454 step
= maybe_software_singlestep (gdbarch
, pc
);
2456 /* Currently, our software single-step implementation leads to different
2457 results than hardware single-stepping in one situation: when stepping
2458 into delivering a signal which has an associated signal handler,
2459 hardware single-step will stop at the first instruction of the handler,
2460 while software single-step will simply skip execution of the handler.
2462 For now, this difference in behavior is accepted since there is no
2463 easy way to actually implement single-stepping into a signal handler
2464 without kernel support.
2466 However, there is one scenario where this difference leads to follow-on
2467 problems: if we're stepping off a breakpoint by removing all breakpoints
2468 and then single-stepping. In this case, the software single-step
2469 behavior means that even if there is a *breakpoint* in the signal
2470 handler, GDB still would not stop.
2472 Fortunately, we can at least fix this particular issue. We detect
2473 here the case where we are about to deliver a signal while software
2474 single-stepping with breakpoints removed. In this situation, we
2475 revert the decisions to remove all breakpoints and insert single-
2476 step breakpoints, and instead we install a step-resume breakpoint
2477 at the current address, deliver the signal without stepping, and
2478 once we arrive back at the step-resume breakpoint, actually step
2479 over the breakpoint we originally wanted to step over. */
2480 if (thread_has_single_step_breakpoints_set (tp
)
2481 && sig
!= GDB_SIGNAL_0
2482 && step_over_info_valid_p ())
2484 /* If we have nested signals or a pending signal is delivered
2485 immediately after a handler returns, might might already have
2486 a step-resume breakpoint set on the earlier handler. We cannot
2487 set another step-resume breakpoint; just continue on until the
2488 original breakpoint is hit. */
2489 if (tp
->control
.step_resume_breakpoint
== NULL
)
2491 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
2492 tp
->step_after_step_resume_breakpoint
= 1;
2495 delete_single_step_breakpoints (tp
);
2497 clear_step_over_info ();
2498 tp
->control
.trap_expected
= 0;
2500 insert_breakpoints ();
2503 /* If STEP is set, it's a request to use hardware stepping
2504 facilities. But in that case, we should never
2505 use singlestep breakpoint. */
2506 gdb_assert (!(thread_has_single_step_breakpoints_set (tp
) && step
));
2508 /* Decide the set of threads to ask the target to resume. */
2509 if (tp
->control
.trap_expected
)
2511 /* We're allowing a thread to run past a breakpoint it has
2512 hit, either by single-stepping the thread with the breakpoint
2513 removed, or by displaced stepping, with the breakpoint inserted.
2514 In the former case, we need to single-step only this thread,
2515 and keep others stopped, as they can miss this breakpoint if
2516 allowed to run. That's not really a problem for displaced
2517 stepping, but, we still keep other threads stopped, in case
2518 another thread is also stopped for a breakpoint waiting for
2519 its turn in the displaced stepping queue. */
2520 resume_ptid
= inferior_ptid
;
2523 resume_ptid
= internal_resume_ptid (user_step
);
2525 if (execution_direction
!= EXEC_REVERSE
2526 && step
&& breakpoint_inserted_here_p (aspace
, pc
))
2528 /* There are two cases where we currently need to step a
2529 breakpoint instruction when we have a signal to deliver:
2531 - See handle_signal_stop where we handle random signals that
2532 could take out us out of the stepping range. Normally, in
2533 that case we end up continuing (instead of stepping) over the
2534 signal handler with a breakpoint at PC, but there are cases
2535 where we should _always_ single-step, even if we have a
2536 step-resume breakpoint, like when a software watchpoint is
2537 set. Assuming single-stepping and delivering a signal at the
2538 same time would takes us to the signal handler, then we could
2539 have removed the breakpoint at PC to step over it. However,
2540 some hardware step targets (like e.g., Mac OS) can't step
2541 into signal handlers, and for those, we need to leave the
2542 breakpoint at PC inserted, as otherwise if the handler
2543 recurses and executes PC again, it'll miss the breakpoint.
2544 So we leave the breakpoint inserted anyway, but we need to
2545 record that we tried to step a breakpoint instruction, so
2546 that adjust_pc_after_break doesn't end up confused.
2548 - In non-stop if we insert a breakpoint (e.g., a step-resume)
2549 in one thread after another thread that was stepping had been
2550 momentarily paused for a step-over. When we re-resume the
2551 stepping thread, it may be resumed from that address with a
2552 breakpoint that hasn't trapped yet. Seen with
2553 gdb.threads/non-stop-fair-events.exp, on targets that don't
2554 do displaced stepping. */
2557 fprintf_unfiltered (gdb_stdlog
,
2558 "infrun: resume: [%s] stepped breakpoint\n",
2559 target_pid_to_str (tp
->ptid
).c_str ());
2561 tp
->stepped_breakpoint
= 1;
2563 /* Most targets can step a breakpoint instruction, thus
2564 executing it normally. But if this one cannot, just
2565 continue and we will hit it anyway. */
2566 if (gdbarch_cannot_step_breakpoint (gdbarch
))
2571 && tp
->control
.trap_expected
2572 && use_displaced_stepping (tp
)
2573 && !step_over_info_valid_p ())
2575 struct regcache
*resume_regcache
= get_thread_regcache (tp
);
2576 struct gdbarch
*resume_gdbarch
= resume_regcache
->arch ();
2577 CORE_ADDR actual_pc
= regcache_read_pc (resume_regcache
);
2580 fprintf_unfiltered (gdb_stdlog
, "displaced: run %s: ",
2581 paddress (resume_gdbarch
, actual_pc
));
2582 read_memory (actual_pc
, buf
, sizeof (buf
));
2583 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
2586 if (tp
->control
.may_range_step
)
2588 /* If we're resuming a thread with the PC out of the step
2589 range, then we're doing some nested/finer run control
2590 operation, like stepping the thread out of the dynamic
2591 linker or the displaced stepping scratch pad. We
2592 shouldn't have allowed a range step then. */
2593 gdb_assert (pc_in_thread_step_range (pc
, tp
));
2596 do_target_resume (resume_ptid
, step
, sig
);
2600 /* Resume the inferior. SIG is the signal to give the inferior
2601 (GDB_SIGNAL_0 for none). This is a wrapper around 'resume_1' that
2602 rolls back state on error. */
2605 resume (gdb_signal sig
)
2611 catch (const gdb_exception
&ex
)
2613 /* If resuming is being aborted for any reason, delete any
2614 single-step breakpoint resume_1 may have created, to avoid
2615 confusing the following resumption, and to avoid leaving
2616 single-step breakpoints perturbing other threads, in case
2617 we're running in non-stop mode. */
2618 if (inferior_ptid
!= null_ptid
)
2619 delete_single_step_breakpoints (inferior_thread ());
2629 /* Counter that tracks number of user visible stops. This can be used
2630 to tell whether a command has proceeded the inferior past the
2631 current location. This allows e.g., inferior function calls in
2632 breakpoint commands to not interrupt the command list. When the
2633 call finishes successfully, the inferior is standing at the same
2634 breakpoint as if nothing happened (and so we don't call
2636 static ULONGEST current_stop_id
;
2643 return current_stop_id
;
2646 /* Called when we report a user visible stop. */
2654 /* Clear out all variables saying what to do when inferior is continued.
2655 First do this, then set the ones you want, then call `proceed'. */
2658 clear_proceed_status_thread (struct thread_info
*tp
)
2661 fprintf_unfiltered (gdb_stdlog
,
2662 "infrun: clear_proceed_status_thread (%s)\n",
2663 target_pid_to_str (tp
->ptid
).c_str ());
2665 /* If we're starting a new sequence, then the previous finished
2666 single-step is no longer relevant. */
2667 if (tp
->suspend
.waitstatus_pending_p
)
2669 if (tp
->suspend
.stop_reason
== TARGET_STOPPED_BY_SINGLE_STEP
)
2672 fprintf_unfiltered (gdb_stdlog
,
2673 "infrun: clear_proceed_status: pending "
2674 "event of %s was a finished step. "
2676 target_pid_to_str (tp
->ptid
).c_str ());
2678 tp
->suspend
.waitstatus_pending_p
= 0;
2679 tp
->suspend
.stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
2681 else if (debug_infrun
)
2684 = target_waitstatus_to_string (&tp
->suspend
.waitstatus
);
2686 fprintf_unfiltered (gdb_stdlog
,
2687 "infrun: clear_proceed_status_thread: thread %s "
2688 "has pending wait status %s "
2689 "(currently_stepping=%d).\n",
2690 target_pid_to_str (tp
->ptid
).c_str (),
2692 currently_stepping (tp
));
2696 /* If this signal should not be seen by program, give it zero.
2697 Used for debugging signals. */
2698 if (!signal_pass_state (tp
->suspend
.stop_signal
))
2699 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2701 delete tp
->thread_fsm
;
2702 tp
->thread_fsm
= NULL
;
2704 tp
->control
.trap_expected
= 0;
2705 tp
->control
.step_range_start
= 0;
2706 tp
->control
.step_range_end
= 0;
2707 tp
->control
.may_range_step
= 0;
2708 tp
->control
.step_frame_id
= null_frame_id
;
2709 tp
->control
.step_stack_frame_id
= null_frame_id
;
2710 tp
->control
.step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
2711 tp
->control
.step_start_function
= NULL
;
2712 tp
->stop_requested
= 0;
2714 tp
->control
.stop_step
= 0;
2716 tp
->control
.proceed_to_finish
= 0;
2718 tp
->control
.stepping_command
= 0;
2720 /* Discard any remaining commands or status from previous stop. */
2721 bpstat_clear (&tp
->control
.stop_bpstat
);
2725 clear_proceed_status (int step
)
2727 /* With scheduler-locking replay, stop replaying other threads if we're
2728 not replaying the user-visible resume ptid.
2730 This is a convenience feature to not require the user to explicitly
2731 stop replaying the other threads. We're assuming that the user's
2732 intent is to resume tracing the recorded process. */
2733 if (!non_stop
&& scheduler_mode
== schedlock_replay
2734 && target_record_is_replaying (minus_one_ptid
)
2735 && !target_record_will_replay (user_visible_resume_ptid (step
),
2736 execution_direction
))
2737 target_record_stop_replaying ();
2739 if (!non_stop
&& inferior_ptid
!= null_ptid
)
2741 ptid_t resume_ptid
= user_visible_resume_ptid (step
);
2743 /* In all-stop mode, delete the per-thread status of all threads
2744 we're about to resume, implicitly and explicitly. */
2745 for (thread_info
*tp
: all_non_exited_threads (resume_ptid
))
2746 clear_proceed_status_thread (tp
);
2749 if (inferior_ptid
!= null_ptid
)
2751 struct inferior
*inferior
;
2755 /* If in non-stop mode, only delete the per-thread status of
2756 the current thread. */
2757 clear_proceed_status_thread (inferior_thread ());
2760 inferior
= current_inferior ();
2761 inferior
->control
.stop_soon
= NO_STOP_QUIETLY
;
2764 gdb::observers::about_to_proceed
.notify ();
2767 /* Returns true if TP is still stopped at a breakpoint that needs
2768 stepping-over in order to make progress. If the breakpoint is gone
2769 meanwhile, we can skip the whole step-over dance. */
2772 thread_still_needs_step_over_bp (struct thread_info
*tp
)
2774 if (tp
->stepping_over_breakpoint
)
2776 struct regcache
*regcache
= get_thread_regcache (tp
);
2778 if (breakpoint_here_p (regcache
->aspace (),
2779 regcache_read_pc (regcache
))
2780 == ordinary_breakpoint_here
)
2783 tp
->stepping_over_breakpoint
= 0;
2789 /* Check whether thread TP still needs to start a step-over in order
2790 to make progress when resumed. Returns an bitwise or of enum
2791 step_over_what bits, indicating what needs to be stepped over. */
2793 static step_over_what
2794 thread_still_needs_step_over (struct thread_info
*tp
)
2796 step_over_what what
= 0;
2798 if (thread_still_needs_step_over_bp (tp
))
2799 what
|= STEP_OVER_BREAKPOINT
;
2801 if (tp
->stepping_over_watchpoint
2802 && !target_have_steppable_watchpoint
)
2803 what
|= STEP_OVER_WATCHPOINT
;
2808 /* Returns true if scheduler locking applies. STEP indicates whether
2809 we're about to do a step/next-like command to a thread. */
2812 schedlock_applies (struct thread_info
*tp
)
2814 return (scheduler_mode
== schedlock_on
2815 || (scheduler_mode
== schedlock_step
2816 && tp
->control
.stepping_command
)
2817 || (scheduler_mode
== schedlock_replay
2818 && target_record_will_replay (minus_one_ptid
,
2819 execution_direction
)));
2822 /* Basic routine for continuing the program in various fashions.
2824 ADDR is the address to resume at, or -1 for resume where stopped.
2825 SIGGNAL is the signal to give it, or GDB_SIGNAL_0 for none,
2826 or GDB_SIGNAL_DEFAULT for act according to how it stopped.
2828 You should call clear_proceed_status before calling proceed. */
2831 proceed (CORE_ADDR addr
, enum gdb_signal siggnal
)
2833 struct regcache
*regcache
;
2834 struct gdbarch
*gdbarch
;
2837 struct execution_control_state ecss
;
2838 struct execution_control_state
*ecs
= &ecss
;
2841 /* If we're stopped at a fork/vfork, follow the branch set by the
2842 "set follow-fork-mode" command; otherwise, we'll just proceed
2843 resuming the current thread. */
2844 if (!follow_fork ())
2846 /* The target for some reason decided not to resume. */
2848 if (target_can_async_p ())
2849 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
2853 /* We'll update this if & when we switch to a new thread. */
2854 previous_inferior_ptid
= inferior_ptid
;
2856 regcache
= get_current_regcache ();
2857 gdbarch
= regcache
->arch ();
2858 const address_space
*aspace
= regcache
->aspace ();
2860 pc
= regcache_read_pc (regcache
);
2861 thread_info
*cur_thr
= inferior_thread ();
2863 /* Fill in with reasonable starting values. */
2864 init_thread_stepping_state (cur_thr
);
2866 gdb_assert (!thread_is_in_step_over_chain (cur_thr
));
2868 if (addr
== (CORE_ADDR
) -1)
2870 if (pc
== cur_thr
->suspend
.stop_pc
2871 && breakpoint_here_p (aspace
, pc
) == ordinary_breakpoint_here
2872 && execution_direction
!= EXEC_REVERSE
)
2873 /* There is a breakpoint at the address we will resume at,
2874 step one instruction before inserting breakpoints so that
2875 we do not stop right away (and report a second hit at this
2878 Note, we don't do this in reverse, because we won't
2879 actually be executing the breakpoint insn anyway.
2880 We'll be (un-)executing the previous instruction. */
2881 cur_thr
->stepping_over_breakpoint
= 1;
2882 else if (gdbarch_single_step_through_delay_p (gdbarch
)
2883 && gdbarch_single_step_through_delay (gdbarch
,
2884 get_current_frame ()))
2885 /* We stepped onto an instruction that needs to be stepped
2886 again before re-inserting the breakpoint, do so. */
2887 cur_thr
->stepping_over_breakpoint
= 1;
2891 regcache_write_pc (regcache
, addr
);
2894 if (siggnal
!= GDB_SIGNAL_DEFAULT
)
2895 cur_thr
->suspend
.stop_signal
= siggnal
;
2897 resume_ptid
= user_visible_resume_ptid (cur_thr
->control
.stepping_command
);
2899 /* If an exception is thrown from this point on, make sure to
2900 propagate GDB's knowledge of the executing state to the
2901 frontend/user running state. */
2902 scoped_finish_thread_state
finish_state (resume_ptid
);
2904 /* Even if RESUME_PTID is a wildcard, and we end up resuming fewer
2905 threads (e.g., we might need to set threads stepping over
2906 breakpoints first), from the user/frontend's point of view, all
2907 threads in RESUME_PTID are now running. Unless we're calling an
2908 inferior function, as in that case we pretend the inferior
2909 doesn't run at all. */
2910 if (!cur_thr
->control
.in_infcall
)
2911 set_running (resume_ptid
, 1);
2914 fprintf_unfiltered (gdb_stdlog
,
2915 "infrun: proceed (addr=%s, signal=%s)\n",
2916 paddress (gdbarch
, addr
),
2917 gdb_signal_to_symbol_string (siggnal
));
2919 annotate_starting ();
2921 /* Make sure that output from GDB appears before output from the
2923 gdb_flush (gdb_stdout
);
2925 /* Since we've marked the inferior running, give it the terminal. A
2926 QUIT/Ctrl-C from here on is forwarded to the target (which can
2927 still detect attempts to unblock a stuck connection with repeated
2928 Ctrl-C from within target_pass_ctrlc). */
2929 target_terminal::inferior ();
2931 /* In a multi-threaded task we may select another thread and
2932 then continue or step.
2934 But if a thread that we're resuming had stopped at a breakpoint,
2935 it will immediately cause another breakpoint stop without any
2936 execution (i.e. it will report a breakpoint hit incorrectly). So
2937 we must step over it first.
2939 Look for threads other than the current (TP) that reported a
2940 breakpoint hit and haven't been resumed yet since. */
2942 /* If scheduler locking applies, we can avoid iterating over all
2944 if (!non_stop
&& !schedlock_applies (cur_thr
))
2946 for (thread_info
*tp
: all_non_exited_threads (resume_ptid
))
2948 /* Ignore the current thread here. It's handled
2953 if (!thread_still_needs_step_over (tp
))
2956 gdb_assert (!thread_is_in_step_over_chain (tp
));
2959 fprintf_unfiltered (gdb_stdlog
,
2960 "infrun: need to step-over [%s] first\n",
2961 target_pid_to_str (tp
->ptid
).c_str ());
2963 global_thread_step_over_chain_enqueue (tp
);
2967 /* Enqueue the current thread last, so that we move all other
2968 threads over their breakpoints first. */
2969 if (cur_thr
->stepping_over_breakpoint
)
2970 global_thread_step_over_chain_enqueue (cur_thr
);
2972 /* If the thread isn't started, we'll still need to set its prev_pc,
2973 so that switch_back_to_stepped_thread knows the thread hasn't
2974 advanced. Must do this before resuming any thread, as in
2975 all-stop/remote, once we resume we can't send any other packet
2976 until the target stops again. */
2977 cur_thr
->prev_pc
= regcache_read_pc (regcache
);
2980 scoped_restore save_defer_tc
= make_scoped_defer_target_commit_resume ();
2982 started
= start_step_over ();
2984 if (step_over_info_valid_p ())
2986 /* Either this thread started a new in-line step over, or some
2987 other thread was already doing one. In either case, don't
2988 resume anything else until the step-over is finished. */
2990 else if (started
&& !target_is_non_stop_p ())
2992 /* A new displaced stepping sequence was started. In all-stop,
2993 we can't talk to the target anymore until it next stops. */
2995 else if (!non_stop
&& target_is_non_stop_p ())
2997 /* In all-stop, but the target is always in non-stop mode.
2998 Start all other threads that are implicitly resumed too. */
2999 for (thread_info
*tp
: all_non_exited_threads (resume_ptid
))
3004 fprintf_unfiltered (gdb_stdlog
,
3005 "infrun: proceed: [%s] resumed\n",
3006 target_pid_to_str (tp
->ptid
).c_str ());
3007 gdb_assert (tp
->executing
|| tp
->suspend
.waitstatus_pending_p
);
3011 if (thread_is_in_step_over_chain (tp
))
3014 fprintf_unfiltered (gdb_stdlog
,
3015 "infrun: proceed: [%s] needs step-over\n",
3016 target_pid_to_str (tp
->ptid
).c_str ());
3021 fprintf_unfiltered (gdb_stdlog
,
3022 "infrun: proceed: resuming %s\n",
3023 target_pid_to_str (tp
->ptid
).c_str ());
3025 reset_ecs (ecs
, tp
);
3026 switch_to_thread (tp
);
3027 keep_going_pass_signal (ecs
);
3028 if (!ecs
->wait_some_more
)
3029 error (_("Command aborted."));
3032 else if (!cur_thr
->resumed
&& !thread_is_in_step_over_chain (cur_thr
))
3034 /* The thread wasn't started, and isn't queued, run it now. */
3035 reset_ecs (ecs
, cur_thr
);
3036 switch_to_thread (cur_thr
);
3037 keep_going_pass_signal (ecs
);
3038 if (!ecs
->wait_some_more
)
3039 error (_("Command aborted."));
3043 target_commit_resume ();
3045 finish_state
.release ();
3047 /* Tell the event loop to wait for it to stop. If the target
3048 supports asynchronous execution, it'll do this from within
3050 if (!target_can_async_p ())
3051 mark_async_event_handler (infrun_async_inferior_event_token
);
3055 /* Start remote-debugging of a machine over a serial link. */
3058 start_remote (int from_tty
)
3060 struct inferior
*inferior
;
3062 inferior
= current_inferior ();
3063 inferior
->control
.stop_soon
= STOP_QUIETLY_REMOTE
;
3065 /* Always go on waiting for the target, regardless of the mode. */
3066 /* FIXME: cagney/1999-09-23: At present it isn't possible to
3067 indicate to wait_for_inferior that a target should timeout if
3068 nothing is returned (instead of just blocking). Because of this,
3069 targets expecting an immediate response need to, internally, set
3070 things up so that the target_wait() is forced to eventually
3072 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
3073 differentiate to its caller what the state of the target is after
3074 the initial open has been performed. Here we're assuming that
3075 the target has stopped. It should be possible to eventually have
3076 target_open() return to the caller an indication that the target
3077 is currently running and GDB state should be set to the same as
3078 for an async run. */
3079 wait_for_inferior ();
3081 /* Now that the inferior has stopped, do any bookkeeping like
3082 loading shared libraries. We want to do this before normal_stop,
3083 so that the displayed frame is up to date. */
3084 post_create_inferior (current_top_target (), from_tty
);
3089 /* Initialize static vars when a new inferior begins. */
3092 init_wait_for_inferior (void)
3094 /* These are meaningless until the first time through wait_for_inferior. */
3096 breakpoint_init_inferior (inf_starting
);
3098 clear_proceed_status (0);
3100 target_last_wait_ptid
= minus_one_ptid
;
3102 previous_inferior_ptid
= inferior_ptid
;
3107 static void handle_inferior_event (struct execution_control_state
*ecs
);
3109 static void handle_step_into_function (struct gdbarch
*gdbarch
,
3110 struct execution_control_state
*ecs
);
3111 static void handle_step_into_function_backward (struct gdbarch
*gdbarch
,
3112 struct execution_control_state
*ecs
);
3113 static void handle_signal_stop (struct execution_control_state
*ecs
);
3114 static void check_exception_resume (struct execution_control_state
*,
3115 struct frame_info
*);
3117 static void end_stepping_range (struct execution_control_state
*ecs
);
3118 static void stop_waiting (struct execution_control_state
*ecs
);
3119 static void keep_going (struct execution_control_state
*ecs
);
3120 static void process_event_stop_test (struct execution_control_state
*ecs
);
3121 static int switch_back_to_stepped_thread (struct execution_control_state
*ecs
);
3123 /* This function is attached as a "thread_stop_requested" observer.
3124 Cleanup local state that assumed the PTID was to be resumed, and
3125 report the stop to the frontend. */
3128 infrun_thread_stop_requested (ptid_t ptid
)
3130 /* PTID was requested to stop. If the thread was already stopped,
3131 but the user/frontend doesn't know about that yet (e.g., the
3132 thread had been temporarily paused for some step-over), set up
3133 for reporting the stop now. */
3134 for (thread_info
*tp
: all_threads (ptid
))
3136 if (tp
->state
!= THREAD_RUNNING
)
3141 /* Remove matching threads from the step-over queue, so
3142 start_step_over doesn't try to resume them
3144 if (thread_is_in_step_over_chain (tp
))
3145 global_thread_step_over_chain_remove (tp
);
3147 /* If the thread is stopped, but the user/frontend doesn't
3148 know about that yet, queue a pending event, as if the
3149 thread had just stopped now. Unless the thread already had
3151 if (!tp
->suspend
.waitstatus_pending_p
)
3153 tp
->suspend
.waitstatus_pending_p
= 1;
3154 tp
->suspend
.waitstatus
.kind
= TARGET_WAITKIND_STOPPED
;
3155 tp
->suspend
.waitstatus
.value
.sig
= GDB_SIGNAL_0
;
3158 /* Clear the inline-frame state, since we're re-processing the
3160 clear_inline_frame_state (tp
->ptid
);
3162 /* If this thread was paused because some other thread was
3163 doing an inline-step over, let that finish first. Once
3164 that happens, we'll restart all threads and consume pending
3165 stop events then. */
3166 if (step_over_info_valid_p ())
3169 /* Otherwise we can process the (new) pending event now. Set
3170 it so this pending event is considered by
3177 infrun_thread_thread_exit (struct thread_info
*tp
, int silent
)
3179 if (target_last_wait_ptid
== tp
->ptid
)
3180 nullify_last_target_wait_ptid ();
3183 /* Delete the step resume, single-step and longjmp/exception resume
3184 breakpoints of TP. */
3187 delete_thread_infrun_breakpoints (struct thread_info
*tp
)
3189 delete_step_resume_breakpoint (tp
);
3190 delete_exception_resume_breakpoint (tp
);
3191 delete_single_step_breakpoints (tp
);
3194 /* If the target still has execution, call FUNC for each thread that
3195 just stopped. In all-stop, that's all the non-exited threads; in
3196 non-stop, that's the current thread, only. */
3198 typedef void (*for_each_just_stopped_thread_callback_func
)
3199 (struct thread_info
*tp
);
3202 for_each_just_stopped_thread (for_each_just_stopped_thread_callback_func func
)
3204 if (!target_has_execution
|| inferior_ptid
== null_ptid
)
3207 if (target_is_non_stop_p ())
3209 /* If in non-stop mode, only the current thread stopped. */
3210 func (inferior_thread ());
3214 /* In all-stop mode, all threads have stopped. */
3215 for (thread_info
*tp
: all_non_exited_threads ())
3220 /* Delete the step resume and longjmp/exception resume breakpoints of
3221 the threads that just stopped. */
3224 delete_just_stopped_threads_infrun_breakpoints (void)
3226 for_each_just_stopped_thread (delete_thread_infrun_breakpoints
);
3229 /* Delete the single-step breakpoints of the threads that just
3233 delete_just_stopped_threads_single_step_breakpoints (void)
3235 for_each_just_stopped_thread (delete_single_step_breakpoints
);
3241 print_target_wait_results (ptid_t waiton_ptid
, ptid_t result_ptid
,
3242 const struct target_waitstatus
*ws
)
3244 std::string status_string
= target_waitstatus_to_string (ws
);
3247 /* The text is split over several lines because it was getting too long.
3248 Call fprintf_unfiltered (gdb_stdlog) once so that the text is still
3249 output as a unit; we want only one timestamp printed if debug_timestamp
3252 stb
.printf ("infrun: target_wait (%d.%ld.%ld",
3255 waiton_ptid
.tid ());
3256 if (waiton_ptid
.pid () != -1)
3257 stb
.printf (" [%s]", target_pid_to_str (waiton_ptid
).c_str ());
3258 stb
.printf (", status) =\n");
3259 stb
.printf ("infrun: %d.%ld.%ld [%s],\n",
3263 target_pid_to_str (result_ptid
).c_str ());
3264 stb
.printf ("infrun: %s\n", status_string
.c_str ());
3266 /* This uses %s in part to handle %'s in the text, but also to avoid
3267 a gcc error: the format attribute requires a string literal. */
3268 fprintf_unfiltered (gdb_stdlog
, "%s", stb
.c_str ());
3271 /* Select a thread at random, out of those which are resumed and have
3274 static struct thread_info
*
3275 random_pending_event_thread (ptid_t waiton_ptid
)
3279 auto has_event
= [] (thread_info
*tp
)
3282 && tp
->suspend
.waitstatus_pending_p
);
3285 /* First see how many events we have. Count only resumed threads
3286 that have an event pending. */
3287 for (thread_info
*tp
: all_non_exited_threads (waiton_ptid
))
3291 if (num_events
== 0)
3294 /* Now randomly pick a thread out of those that have had events. */
3295 int random_selector
= (int) ((num_events
* (double) rand ())
3296 / (RAND_MAX
+ 1.0));
3298 if (debug_infrun
&& num_events
> 1)
3299 fprintf_unfiltered (gdb_stdlog
,
3300 "infrun: Found %d events, selecting #%d\n",
3301 num_events
, random_selector
);
3303 /* Select the Nth thread that has had an event. */
3304 for (thread_info
*tp
: all_non_exited_threads (waiton_ptid
))
3306 if (random_selector
-- == 0)
3309 gdb_assert_not_reached ("event thread not found");
3312 /* Wrapper for target_wait that first checks whether threads have
3313 pending statuses to report before actually asking the target for
3317 do_target_wait (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
3320 struct thread_info
*tp
;
3322 /* First check if there is a resumed thread with a wait status
3324 if (ptid
== minus_one_ptid
|| ptid
.is_pid ())
3326 tp
= random_pending_event_thread (ptid
);
3331 fprintf_unfiltered (gdb_stdlog
,
3332 "infrun: Waiting for specific thread %s.\n",
3333 target_pid_to_str (ptid
).c_str ());
3335 /* We have a specific thread to check. */
3336 tp
= find_thread_ptid (ptid
);
3337 gdb_assert (tp
!= NULL
);
3338 if (!tp
->suspend
.waitstatus_pending_p
)
3343 && (tp
->suspend
.stop_reason
== TARGET_STOPPED_BY_SW_BREAKPOINT
3344 || tp
->suspend
.stop_reason
== TARGET_STOPPED_BY_HW_BREAKPOINT
))
3346 struct regcache
*regcache
= get_thread_regcache (tp
);
3347 struct gdbarch
*gdbarch
= regcache
->arch ();
3351 pc
= regcache_read_pc (regcache
);
3353 if (pc
!= tp
->suspend
.stop_pc
)
3356 fprintf_unfiltered (gdb_stdlog
,
3357 "infrun: PC of %s changed. was=%s, now=%s\n",
3358 target_pid_to_str (tp
->ptid
).c_str (),
3359 paddress (gdbarch
, tp
->suspend
.stop_pc
),
3360 paddress (gdbarch
, pc
));
3363 else if (!breakpoint_inserted_here_p (regcache
->aspace (), pc
))
3366 fprintf_unfiltered (gdb_stdlog
,
3367 "infrun: previous breakpoint of %s, at %s gone\n",
3368 target_pid_to_str (tp
->ptid
).c_str (),
3369 paddress (gdbarch
, pc
));
3377 fprintf_unfiltered (gdb_stdlog
,
3378 "infrun: pending event of %s cancelled.\n",
3379 target_pid_to_str (tp
->ptid
).c_str ());
3381 tp
->suspend
.waitstatus
.kind
= TARGET_WAITKIND_SPURIOUS
;
3382 tp
->suspend
.stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
3391 = target_waitstatus_to_string (&tp
->suspend
.waitstatus
);
3393 fprintf_unfiltered (gdb_stdlog
,
3394 "infrun: Using pending wait status %s for %s.\n",
3396 target_pid_to_str (tp
->ptid
).c_str ());
3399 /* Now that we've selected our final event LWP, un-adjust its PC
3400 if it was a software breakpoint (and the target doesn't
3401 always adjust the PC itself). */
3402 if (tp
->suspend
.stop_reason
== TARGET_STOPPED_BY_SW_BREAKPOINT
3403 && !target_supports_stopped_by_sw_breakpoint ())
3405 struct regcache
*regcache
;
3406 struct gdbarch
*gdbarch
;
3409 regcache
= get_thread_regcache (tp
);
3410 gdbarch
= regcache
->arch ();
3412 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
3417 pc
= regcache_read_pc (regcache
);
3418 regcache_write_pc (regcache
, pc
+ decr_pc
);
3422 tp
->suspend
.stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
3423 *status
= tp
->suspend
.waitstatus
;
3424 tp
->suspend
.waitstatus_pending_p
= 0;
3426 /* Wake up the event loop again, until all pending events are
3428 if (target_is_async_p ())
3429 mark_async_event_handler (infrun_async_inferior_event_token
);
3433 /* But if we don't find one, we'll have to wait. */
3435 if (deprecated_target_wait_hook
)
3436 event_ptid
= deprecated_target_wait_hook (ptid
, status
, options
);
3438 event_ptid
= target_wait (ptid
, status
, options
);
3443 /* Prepare and stabilize the inferior for detaching it. E.g.,
3444 detaching while a thread is displaced stepping is a recipe for
3445 crashing it, as nothing would readjust the PC out of the scratch
3449 prepare_for_detach (void)
3451 struct inferior
*inf
= current_inferior ();
3452 ptid_t pid_ptid
= ptid_t (inf
->pid
);
3454 // displaced_step_inferior_state *displaced = get_displaced_stepping_state (inf);
3456 /* Is any thread of this process displaced stepping? If not,
3457 there's nothing else to do. */
3458 if (displaced_step_in_progress (inf
))
3462 fprintf_unfiltered (gdb_stdlog
,
3463 "displaced-stepping in-process while detaching");
3465 scoped_restore restore_detaching
= make_scoped_restore (&inf
->detaching
, true);
3470 struct execution_control_state ecss
;
3471 struct execution_control_state
*ecs
;
3474 memset (ecs
, 0, sizeof (*ecs
));
3476 overlay_cache_invalid
= 1;
3477 /* Flush target cache before starting to handle each event.
3478 Target was running and cache could be stale. This is just a
3479 heuristic. Running threads may modify target memory, but we
3480 don't get any event. */
3481 target_dcache_invalidate ();
3483 ecs
->ptid
= do_target_wait (pid_ptid
, &ecs
->ws
, 0);
3486 print_target_wait_results (pid_ptid
, ecs
->ptid
, &ecs
->ws
);
3488 /* If an error happens while handling the event, propagate GDB's
3489 knowledge of the executing state to the frontend/user running
3491 scoped_finish_thread_state
finish_state (minus_one_ptid
);
3493 /* Now figure out what to do with the result of the result. */
3494 handle_inferior_event (ecs
);
3496 /* No error, don't finish the state yet. */
3497 finish_state
.release ();
3499 /* Breakpoints and watchpoints are not installed on the target
3500 at this point, and signals are passed directly to the
3501 inferior, so this must mean the process is gone. */
3502 if (!ecs
->wait_some_more
)
3504 restore_detaching
.release ();
3505 error (_("Program exited while detaching"));
3509 restore_detaching
.release ();
3512 /* Wait for control to return from inferior to debugger.
3514 If inferior gets a signal, we may decide to start it up again
3515 instead of returning. That is why there is a loop in this function.
3516 When this function actually returns it means the inferior
3517 should be left stopped and GDB should read more commands. */
3520 wait_for_inferior (void)
3524 (gdb_stdlog
, "infrun: wait_for_inferior ()\n");
3526 SCOPE_EXIT
{ delete_just_stopped_threads_infrun_breakpoints (); };
3528 /* If an error happens while handling the event, propagate GDB's
3529 knowledge of the executing state to the frontend/user running
3531 scoped_finish_thread_state
finish_state (minus_one_ptid
);
3535 struct execution_control_state ecss
;
3536 struct execution_control_state
*ecs
= &ecss
;
3537 ptid_t waiton_ptid
= minus_one_ptid
;
3539 memset (ecs
, 0, sizeof (*ecs
));
3541 overlay_cache_invalid
= 1;
3543 /* Flush target cache before starting to handle each event.
3544 Target was running and cache could be stale. This is just a
3545 heuristic. Running threads may modify target memory, but we
3546 don't get any event. */
3547 target_dcache_invalidate ();
3549 ecs
->ptid
= do_target_wait (waiton_ptid
, &ecs
->ws
, 0);
3552 print_target_wait_results (waiton_ptid
, ecs
->ptid
, &ecs
->ws
);
3554 /* Now figure out what to do with the result of the result. */
3555 handle_inferior_event (ecs
);
3557 if (!ecs
->wait_some_more
)
3561 /* No error, don't finish the state yet. */
3562 finish_state
.release ();
3565 /* Cleanup that reinstalls the readline callback handler, if the
3566 target is running in the background. If while handling the target
3567 event something triggered a secondary prompt, like e.g., a
3568 pagination prompt, we'll have removed the callback handler (see
3569 gdb_readline_wrapper_line). Need to do this as we go back to the
3570 event loop, ready to process further input. Note this has no
3571 effect if the handler hasn't actually been removed, because calling
3572 rl_callback_handler_install resets the line buffer, thus losing
3576 reinstall_readline_callback_handler_cleanup ()
3578 struct ui
*ui
= current_ui
;
3582 /* We're not going back to the top level event loop yet. Don't
3583 install the readline callback, as it'd prep the terminal,
3584 readline-style (raw, noecho) (e.g., --batch). We'll install
3585 it the next time the prompt is displayed, when we're ready
3590 if (ui
->command_editing
&& ui
->prompt_state
!= PROMPT_BLOCKED
)
3591 gdb_rl_callback_handler_reinstall ();
3594 /* Clean up the FSMs of threads that are now stopped. In non-stop,
3595 that's just the event thread. In all-stop, that's all threads. */
3598 clean_up_just_stopped_threads_fsms (struct execution_control_state
*ecs
)
3600 if (ecs
->event_thread
!= NULL
3601 && ecs
->event_thread
->thread_fsm
!= NULL
)
3602 ecs
->event_thread
->thread_fsm
->clean_up (ecs
->event_thread
);
3606 for (thread_info
*thr
: all_non_exited_threads ())
3608 if (thr
->thread_fsm
== NULL
)
3610 if (thr
== ecs
->event_thread
)
3613 switch_to_thread (thr
);
3614 thr
->thread_fsm
->clean_up (thr
);
3617 if (ecs
->event_thread
!= NULL
)
3618 switch_to_thread (ecs
->event_thread
);
3622 /* Helper for all_uis_check_sync_execution_done that works on the
3626 check_curr_ui_sync_execution_done (void)
3628 struct ui
*ui
= current_ui
;
3630 if (ui
->prompt_state
== PROMPT_NEEDED
3632 && !gdb_in_secondary_prompt_p (ui
))
3634 target_terminal::ours ();
3635 gdb::observers::sync_execution_done
.notify ();
3636 ui_register_input_event_handler (ui
);
3643 all_uis_check_sync_execution_done (void)
3645 SWITCH_THRU_ALL_UIS ()
3647 check_curr_ui_sync_execution_done ();
3654 all_uis_on_sync_execution_starting (void)
3656 SWITCH_THRU_ALL_UIS ()
3658 if (current_ui
->prompt_state
== PROMPT_NEEDED
)
3659 async_disable_stdin ();
3663 /* Asynchronous version of wait_for_inferior. It is called by the
3664 event loop whenever a change of state is detected on the file
3665 descriptor corresponding to the target. It can be called more than
3666 once to complete a single execution command. In such cases we need
3667 to keep the state in a global variable ECSS. If it is the last time
3668 that this function is called for a single execution command, then
3669 report to the user that the inferior has stopped, and do the
3670 necessary cleanups. */
3673 fetch_inferior_event (void *client_data
)
3675 struct execution_control_state ecss
;
3676 struct execution_control_state
*ecs
= &ecss
;
3678 ptid_t waiton_ptid
= minus_one_ptid
;
3680 memset (ecs
, 0, sizeof (*ecs
));
3682 /* Events are always processed with the main UI as current UI. This
3683 way, warnings, debug output, etc. are always consistently sent to
3684 the main console. */
3685 scoped_restore save_ui
= make_scoped_restore (¤t_ui
, main_ui
);
3687 /* End up with readline processing input, if necessary. */
3689 SCOPE_EXIT
{ reinstall_readline_callback_handler_cleanup (); };
3691 /* We're handling a live event, so make sure we're doing live
3692 debugging. If we're looking at traceframes while the target is
3693 running, we're going to need to get back to that mode after
3694 handling the event. */
3695 gdb::optional
<scoped_restore_current_traceframe
> maybe_restore_traceframe
;
3698 maybe_restore_traceframe
.emplace ();
3699 set_current_traceframe (-1);
3702 gdb::optional
<scoped_restore_current_thread
> maybe_restore_thread
;
3705 /* In non-stop mode, the user/frontend should not notice a thread
3706 switch due to internal events. Make sure we reverse to the
3707 user selected thread and frame after handling the event and
3708 running any breakpoint commands. */
3709 maybe_restore_thread
.emplace ();
3711 overlay_cache_invalid
= 1;
3712 /* Flush target cache before starting to handle each event. Target
3713 was running and cache could be stale. This is just a heuristic.
3714 Running threads may modify target memory, but we don't get any
3716 target_dcache_invalidate ();
3718 scoped_restore save_exec_dir
3719 = make_scoped_restore (&execution_direction
,
3720 target_execution_direction ());
3722 ecs
->ptid
= do_target_wait (waiton_ptid
, &ecs
->ws
,
3723 target_can_async_p () ? TARGET_WNOHANG
: 0);
3726 print_target_wait_results (waiton_ptid
, ecs
->ptid
, &ecs
->ws
);
3728 /* If an error happens while handling the event, propagate GDB's
3729 knowledge of the executing state to the frontend/user running
3731 ptid_t finish_ptid
= !target_is_non_stop_p () ? minus_one_ptid
: ecs
->ptid
;
3732 scoped_finish_thread_state
finish_state (finish_ptid
);
3734 /* Get executed before scoped_restore_current_thread above to apply
3735 still for the thread which has thrown the exception. */
3736 auto defer_bpstat_clear
3737 = make_scope_exit (bpstat_clear_actions
);
3738 auto defer_delete_threads
3739 = make_scope_exit (delete_just_stopped_threads_infrun_breakpoints
);
3741 /* Now figure out what to do with the result of the result. */
3742 handle_inferior_event (ecs
);
3744 if (!ecs
->wait_some_more
)
3746 struct inferior
*inf
= find_inferior_ptid (ecs
->ptid
);
3747 int should_stop
= 1;
3748 struct thread_info
*thr
= ecs
->event_thread
;
3750 delete_just_stopped_threads_infrun_breakpoints ();
3754 struct thread_fsm
*thread_fsm
= thr
->thread_fsm
;
3756 if (thread_fsm
!= NULL
)
3757 should_stop
= thread_fsm
->should_stop (thr
);
3766 bool should_notify_stop
= true;
3769 clean_up_just_stopped_threads_fsms (ecs
);
3771 if (thr
!= NULL
&& thr
->thread_fsm
!= NULL
)
3772 should_notify_stop
= thr
->thread_fsm
->should_notify_stop ();
3774 if (should_notify_stop
)
3776 /* We may not find an inferior if this was a process exit. */
3777 if (inf
== NULL
|| inf
->control
.stop_soon
== NO_STOP_QUIETLY
)
3778 proceeded
= normal_stop ();
3783 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
3789 defer_delete_threads
.release ();
3790 defer_bpstat_clear
.release ();
3792 /* No error, don't finish the thread states yet. */
3793 finish_state
.release ();
3795 /* This scope is used to ensure that readline callbacks are
3796 reinstalled here. */
3799 /* If a UI was in sync execution mode, and now isn't, restore its
3800 prompt (a synchronous execution command has finished, and we're
3801 ready for input). */
3802 all_uis_check_sync_execution_done ();
3805 && exec_done_display_p
3806 && (inferior_ptid
== null_ptid
3807 || inferior_thread ()->state
!= THREAD_RUNNING
))
3808 printf_unfiltered (_("completed.\n"));
3811 /* Record the frame and location we're currently stepping through. */
3813 set_step_info (struct frame_info
*frame
, struct symtab_and_line sal
)
3815 struct thread_info
*tp
= inferior_thread ();
3817 tp
->control
.step_frame_id
= get_frame_id (frame
);
3818 tp
->control
.step_stack_frame_id
= get_stack_frame_id (frame
);
3820 tp
->current_symtab
= sal
.symtab
;
3821 tp
->current_line
= sal
.line
;
3824 /* Clear context switchable stepping state. */
3827 init_thread_stepping_state (struct thread_info
*tss
)
3829 tss
->stepped_breakpoint
= 0;
3830 tss
->stepping_over_breakpoint
= 0;
3831 tss
->stepping_over_watchpoint
= 0;
3832 tss
->step_after_step_resume_breakpoint
= 0;
3835 /* Set the cached copy of the last ptid/waitstatus. */
3838 set_last_target_status (ptid_t ptid
, struct target_waitstatus status
)
3840 target_last_wait_ptid
= ptid
;
3841 target_last_waitstatus
= status
;
3844 /* Return the cached copy of the last pid/waitstatus returned by
3845 target_wait()/deprecated_target_wait_hook(). The data is actually
3846 cached by handle_inferior_event(), which gets called immediately
3847 after target_wait()/deprecated_target_wait_hook(). */
3850 get_last_target_status (ptid_t
*ptidp
, struct target_waitstatus
*status
)
3852 *ptidp
= target_last_wait_ptid
;
3853 *status
= target_last_waitstatus
;
3857 nullify_last_target_wait_ptid (void)
3859 target_last_wait_ptid
= minus_one_ptid
;
3862 /* Switch thread contexts. */
3865 context_switch (execution_control_state
*ecs
)
3868 && ecs
->ptid
!= inferior_ptid
3869 && ecs
->event_thread
!= inferior_thread ())
3871 fprintf_unfiltered (gdb_stdlog
, "infrun: Switching context from %s ",
3872 target_pid_to_str (inferior_ptid
).c_str ());
3873 fprintf_unfiltered (gdb_stdlog
, "to %s\n",
3874 target_pid_to_str (ecs
->ptid
).c_str ());
3877 switch_to_thread (ecs
->event_thread
);
3880 /* If the target can't tell whether we've hit breakpoints
3881 (target_supports_stopped_by_sw_breakpoint), and we got a SIGTRAP,
3882 check whether that could have been caused by a breakpoint. If so,
3883 adjust the PC, per gdbarch_decr_pc_after_break. */
3886 adjust_pc_after_break (struct thread_info
*thread
,
3887 struct target_waitstatus
*ws
)
3889 struct regcache
*regcache
;
3890 struct gdbarch
*gdbarch
;
3891 CORE_ADDR breakpoint_pc
, decr_pc
;
3893 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
3894 we aren't, just return.
3896 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
3897 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
3898 implemented by software breakpoints should be handled through the normal
3901 NOTE drow/2004-01-31: On some targets, breakpoints may generate
3902 different signals (SIGILL or SIGEMT for instance), but it is less
3903 clear where the PC is pointing afterwards. It may not match
3904 gdbarch_decr_pc_after_break. I don't know any specific target that
3905 generates these signals at breakpoints (the code has been in GDB since at
3906 least 1992) so I can not guess how to handle them here.
3908 In earlier versions of GDB, a target with
3909 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
3910 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
3911 target with both of these set in GDB history, and it seems unlikely to be
3912 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
3914 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
)
3917 if (ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
3920 /* In reverse execution, when a breakpoint is hit, the instruction
3921 under it has already been de-executed. The reported PC always
3922 points at the breakpoint address, so adjusting it further would
3923 be wrong. E.g., consider this case on a decr_pc_after_break == 1
3926 B1 0x08000000 : INSN1
3927 B2 0x08000001 : INSN2
3929 PC -> 0x08000003 : INSN4
3931 Say you're stopped at 0x08000003 as above. Reverse continuing
3932 from that point should hit B2 as below. Reading the PC when the
3933 SIGTRAP is reported should read 0x08000001 and INSN2 should have
3934 been de-executed already.
3936 B1 0x08000000 : INSN1
3937 B2 PC -> 0x08000001 : INSN2
3941 We can't apply the same logic as for forward execution, because
3942 we would wrongly adjust the PC to 0x08000000, since there's a
3943 breakpoint at PC - 1. We'd then report a hit on B1, although
3944 INSN1 hadn't been de-executed yet. Doing nothing is the correct
3946 if (execution_direction
== EXEC_REVERSE
)
3949 /* If the target can tell whether the thread hit a SW breakpoint,
3950 trust it. Targets that can tell also adjust the PC
3952 if (target_supports_stopped_by_sw_breakpoint ())
3955 /* Note that relying on whether a breakpoint is planted in memory to
3956 determine this can fail. E.g,. the breakpoint could have been
3957 removed since. Or the thread could have been told to step an
3958 instruction the size of a breakpoint instruction, and only
3959 _after_ was a breakpoint inserted at its address. */
3961 /* If this target does not decrement the PC after breakpoints, then
3962 we have nothing to do. */
3963 regcache
= get_thread_regcache (thread
);
3964 gdbarch
= regcache
->arch ();
3966 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
3970 const address_space
*aspace
= regcache
->aspace ();
3972 /* Find the location where (if we've hit a breakpoint) the
3973 breakpoint would be. */
3974 breakpoint_pc
= regcache_read_pc (regcache
) - decr_pc
;
3976 /* If the target can't tell whether a software breakpoint triggered,
3977 fallback to figuring it out based on breakpoints we think were
3978 inserted in the target, and on whether the thread was stepped or
3981 /* Check whether there actually is a software breakpoint inserted at
3984 If in non-stop mode, a race condition is possible where we've
3985 removed a breakpoint, but stop events for that breakpoint were
3986 already queued and arrive later. To suppress those spurious
3987 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
3988 and retire them after a number of stop events are reported. Note
3989 this is an heuristic and can thus get confused. The real fix is
3990 to get the "stopped by SW BP and needs adjustment" info out of
3991 the target/kernel (and thus never reach here; see above). */
3992 if (software_breakpoint_inserted_here_p (aspace
, breakpoint_pc
)
3993 || (target_is_non_stop_p ()
3994 && moribund_breakpoint_here_p (aspace
, breakpoint_pc
)))
3996 gdb::optional
<scoped_restore_tmpl
<int>> restore_operation_disable
;
3998 if (record_full_is_used ())
3999 restore_operation_disable
.emplace
4000 (record_full_gdb_operation_disable_set ());
4002 /* When using hardware single-step, a SIGTRAP is reported for both
4003 a completed single-step and a software breakpoint. Need to
4004 differentiate between the two, as the latter needs adjusting
4005 but the former does not.
4007 The SIGTRAP can be due to a completed hardware single-step only if
4008 - we didn't insert software single-step breakpoints
4009 - this thread is currently being stepped
4011 If any of these events did not occur, we must have stopped due
4012 to hitting a software breakpoint, and have to back up to the
4015 As a special case, we could have hardware single-stepped a
4016 software breakpoint. In this case (prev_pc == breakpoint_pc),
4017 we also need to back up to the breakpoint address. */
4019 if (thread_has_single_step_breakpoints_set (thread
)
4020 || !currently_stepping (thread
)
4021 || (thread
->stepped_breakpoint
4022 && thread
->prev_pc
== breakpoint_pc
))
4023 regcache_write_pc (regcache
, breakpoint_pc
);
4028 stepped_in_from (struct frame_info
*frame
, struct frame_id step_frame_id
)
4030 for (frame
= get_prev_frame (frame
);
4032 frame
= get_prev_frame (frame
))
4034 if (frame_id_eq (get_frame_id (frame
), step_frame_id
))
4036 if (get_frame_type (frame
) != INLINE_FRAME
)
4043 /* If the event thread has the stop requested flag set, pretend it
4044 stopped for a GDB_SIGNAL_0 (i.e., as if it stopped due to
4048 handle_stop_requested (struct execution_control_state
*ecs
)
4050 if (ecs
->event_thread
->stop_requested
)
4052 ecs
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
4053 ecs
->ws
.value
.sig
= GDB_SIGNAL_0
;
4054 handle_signal_stop (ecs
);
4060 /* Auxiliary function that handles syscall entry/return events.
4061 It returns 1 if the inferior should keep going (and GDB
4062 should ignore the event), or 0 if the event deserves to be
4066 handle_syscall_event (struct execution_control_state
*ecs
)
4068 struct regcache
*regcache
;
4071 context_switch (ecs
);
4073 regcache
= get_thread_regcache (ecs
->event_thread
);
4074 syscall_number
= ecs
->ws
.value
.syscall_number
;
4075 ecs
->event_thread
->suspend
.stop_pc
= regcache_read_pc (regcache
);
4077 if (catch_syscall_enabled () > 0
4078 && catching_syscall_number (syscall_number
) > 0)
4081 fprintf_unfiltered (gdb_stdlog
, "infrun: syscall number = '%d'\n",
4084 ecs
->event_thread
->control
.stop_bpstat
4085 = bpstat_stop_status (regcache
->aspace (),
4086 ecs
->event_thread
->suspend
.stop_pc
,
4087 ecs
->event_thread
, &ecs
->ws
);
4089 if (handle_stop_requested (ecs
))
4092 if (bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
4094 /* Catchpoint hit. */
4099 if (handle_stop_requested (ecs
))
4102 /* If no catchpoint triggered for this, then keep going. */
4107 /* Lazily fill in the execution_control_state's stop_func_* fields. */
4110 fill_in_stop_func (struct gdbarch
*gdbarch
,
4111 struct execution_control_state
*ecs
)
4113 if (!ecs
->stop_func_filled_in
)
4117 /* Don't care about return value; stop_func_start and stop_func_name
4118 will both be 0 if it doesn't work. */
4119 find_pc_partial_function (ecs
->event_thread
->suspend
.stop_pc
,
4120 &ecs
->stop_func_name
,
4121 &ecs
->stop_func_start
,
4122 &ecs
->stop_func_end
,
4125 /* The call to find_pc_partial_function, above, will set
4126 stop_func_start and stop_func_end to the start and end
4127 of the range containing the stop pc. If this range
4128 contains the entry pc for the block (which is always the
4129 case for contiguous blocks), advance stop_func_start past
4130 the function's start offset and entrypoint. Note that
4131 stop_func_start is NOT advanced when in a range of a
4132 non-contiguous block that does not contain the entry pc. */
4133 if (block
!= nullptr
4134 && ecs
->stop_func_start
<= BLOCK_ENTRY_PC (block
)
4135 && BLOCK_ENTRY_PC (block
) < ecs
->stop_func_end
)
4137 ecs
->stop_func_start
4138 += gdbarch_deprecated_function_start_offset (gdbarch
);
4140 if (gdbarch_skip_entrypoint_p (gdbarch
))
4141 ecs
->stop_func_start
4142 = gdbarch_skip_entrypoint (gdbarch
, ecs
->stop_func_start
);
4145 ecs
->stop_func_filled_in
= 1;
4150 /* Return the STOP_SOON field of the inferior pointed at by ECS. */
4152 static enum stop_kind
4153 get_inferior_stop_soon (execution_control_state
*ecs
)
4155 struct inferior
*inf
= find_inferior_ptid (ecs
->ptid
);
4157 gdb_assert (inf
!= NULL
);
4158 return inf
->control
.stop_soon
;
4161 /* Wait for one event. Store the resulting waitstatus in WS, and
4162 return the event ptid. */
4165 wait_one (struct target_waitstatus
*ws
)
4168 ptid_t wait_ptid
= minus_one_ptid
;
4170 overlay_cache_invalid
= 1;
4172 /* Flush target cache before starting to handle each event.
4173 Target was running and cache could be stale. This is just a
4174 heuristic. Running threads may modify target memory, but we
4175 don't get any event. */
4176 target_dcache_invalidate ();
4178 if (deprecated_target_wait_hook
)
4179 event_ptid
= deprecated_target_wait_hook (wait_ptid
, ws
, 0);
4181 event_ptid
= target_wait (wait_ptid
, ws
, 0);
4184 print_target_wait_results (wait_ptid
, event_ptid
, ws
);
4189 /* Generate a wrapper for target_stopped_by_REASON that works on PTID
4190 instead of the current thread. */
4191 #define THREAD_STOPPED_BY(REASON) \
4193 thread_stopped_by_ ## REASON (ptid_t ptid) \
4195 scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); \
4196 inferior_ptid = ptid; \
4198 return target_stopped_by_ ## REASON (); \
4201 /* Generate thread_stopped_by_watchpoint. */
4202 THREAD_STOPPED_BY (watchpoint
)
4203 /* Generate thread_stopped_by_sw_breakpoint. */
4204 THREAD_STOPPED_BY (sw_breakpoint
)
4205 /* Generate thread_stopped_by_hw_breakpoint. */
4206 THREAD_STOPPED_BY (hw_breakpoint
)
4208 /* Save the thread's event and stop reason to process it later. */
4211 save_waitstatus (struct thread_info
*tp
, struct target_waitstatus
*ws
)
4215 std::string statstr
= target_waitstatus_to_string (ws
);
4217 fprintf_unfiltered (gdb_stdlog
,
4218 "infrun: saving status %s for %d.%ld.%ld\n",
4225 /* Record for later. */
4226 tp
->suspend
.waitstatus
= *ws
;
4227 tp
->suspend
.waitstatus_pending_p
= 1;
4229 struct regcache
*regcache
= get_thread_regcache (tp
);
4230 const address_space
*aspace
= regcache
->aspace ();
4232 if (ws
->kind
== TARGET_WAITKIND_STOPPED
4233 && ws
->value
.sig
== GDB_SIGNAL_TRAP
)
4235 CORE_ADDR pc
= regcache_read_pc (regcache
);
4237 adjust_pc_after_break (tp
, &tp
->suspend
.waitstatus
);
4239 if (thread_stopped_by_watchpoint (tp
->ptid
))
4241 tp
->suspend
.stop_reason
4242 = TARGET_STOPPED_BY_WATCHPOINT
;
4244 else if (target_supports_stopped_by_sw_breakpoint ()
4245 && thread_stopped_by_sw_breakpoint (tp
->ptid
))
4247 tp
->suspend
.stop_reason
4248 = TARGET_STOPPED_BY_SW_BREAKPOINT
;
4250 else if (target_supports_stopped_by_hw_breakpoint ()
4251 && thread_stopped_by_hw_breakpoint (tp
->ptid
))
4253 tp
->suspend
.stop_reason
4254 = TARGET_STOPPED_BY_HW_BREAKPOINT
;
4256 else if (!target_supports_stopped_by_hw_breakpoint ()
4257 && hardware_breakpoint_inserted_here_p (aspace
,
4260 tp
->suspend
.stop_reason
4261 = TARGET_STOPPED_BY_HW_BREAKPOINT
;
4263 else if (!target_supports_stopped_by_sw_breakpoint ()
4264 && software_breakpoint_inserted_here_p (aspace
,
4267 tp
->suspend
.stop_reason
4268 = TARGET_STOPPED_BY_SW_BREAKPOINT
;
4270 else if (!thread_has_single_step_breakpoints_set (tp
)
4271 && currently_stepping (tp
))
4273 tp
->suspend
.stop_reason
4274 = TARGET_STOPPED_BY_SINGLE_STEP
;
4282 stop_all_threads (void)
4284 /* We may need multiple passes to discover all threads. */
4288 gdb_assert (target_is_non_stop_p ());
4291 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_all_threads\n");
4293 scoped_restore_current_thread restore_thread
;
4295 target_thread_events (1);
4296 SCOPE_EXIT
{ target_thread_events (0); };
4298 /* Request threads to stop, and then wait for the stops. Because
4299 threads we already know about can spawn more threads while we're
4300 trying to stop them, and we only learn about new threads when we
4301 update the thread list, do this in a loop, and keep iterating
4302 until two passes find no threads that need to be stopped. */
4303 for (pass
= 0; pass
< 2; pass
++, iterations
++)
4306 fprintf_unfiltered (gdb_stdlog
,
4307 "infrun: stop_all_threads, pass=%d, "
4308 "iterations=%d\n", pass
, iterations
);
4312 struct target_waitstatus ws
;
4315 update_thread_list ();
4317 /* Go through all threads looking for threads that we need
4318 to tell the target to stop. */
4319 for (thread_info
*t
: all_non_exited_threads ())
4323 /* If already stopping, don't request a stop again.
4324 We just haven't seen the notification yet. */
4325 if (!t
->stop_requested
)
4328 fprintf_unfiltered (gdb_stdlog
,
4329 "infrun: %s executing, "
4331 target_pid_to_str (t
->ptid
).c_str ());
4332 target_stop (t
->ptid
);
4333 t
->stop_requested
= 1;
4338 fprintf_unfiltered (gdb_stdlog
,
4339 "infrun: %s executing, "
4340 "already stopping\n",
4341 target_pid_to_str (t
->ptid
).c_str ());
4344 if (t
->stop_requested
)
4350 fprintf_unfiltered (gdb_stdlog
,
4351 "infrun: %s not executing\n",
4352 target_pid_to_str (t
->ptid
).c_str ());
4354 /* The thread may be not executing, but still be
4355 resumed with a pending status to process. */
4363 /* If we find new threads on the second iteration, restart
4364 over. We want to see two iterations in a row with all
4369 event_ptid
= wait_one (&ws
);
4372 fprintf_unfiltered (gdb_stdlog
,
4373 "infrun: stop_all_threads %s %s\n",
4374 target_waitstatus_to_string (&ws
).c_str (),
4375 target_pid_to_str (event_ptid
).c_str ());
4378 if (ws
.kind
== TARGET_WAITKIND_NO_RESUMED
4379 || ws
.kind
== TARGET_WAITKIND_THREAD_EXITED
4380 || ws
.kind
== TARGET_WAITKIND_EXITED
4381 || ws
.kind
== TARGET_WAITKIND_SIGNALLED
)
4383 /* All resumed threads exited
4384 or one thread/process exited/signalled. */
4388 thread_info
*t
= find_thread_ptid (event_ptid
);
4390 t
= add_thread (event_ptid
);
4392 t
->stop_requested
= 0;
4395 t
->control
.may_range_step
= 0;
4397 /* This may be the first time we see the inferior report
4399 inferior
*inf
= find_inferior_ptid (event_ptid
);
4400 if (inf
->needs_setup
)
4402 switch_to_thread_no_regs (t
);
4406 if (ws
.kind
== TARGET_WAITKIND_STOPPED
4407 && ws
.value
.sig
== GDB_SIGNAL_0
)
4409 /* We caught the event that we intended to catch, so
4410 there's no event pending. */
4411 t
->suspend
.waitstatus
.kind
= TARGET_WAITKIND_IGNORE
;
4412 t
->suspend
.waitstatus_pending_p
= 0;
4414 if (displaced_step_finish (t
, GDB_SIGNAL_0
) < 0)
4416 /* Add it back to the step-over queue. */
4419 fprintf_unfiltered (gdb_stdlog
,
4420 "infrun: displaced-step of %s "
4421 "canceled: adding back to the "
4422 "step-over queue\n",
4423 target_pid_to_str (t
->ptid
).c_str ());
4425 t
->control
.trap_expected
= 0;
4426 global_thread_step_over_chain_enqueue (t
);
4431 enum gdb_signal sig
;
4432 struct regcache
*regcache
;
4436 std::string statstr
= target_waitstatus_to_string (&ws
);
4438 fprintf_unfiltered (gdb_stdlog
,
4439 "infrun: target_wait %s, saving "
4440 "status for %d.%ld.%ld\n",
4447 /* Record for later. */
4448 save_waitstatus (t
, &ws
);
4450 sig
= (ws
.kind
== TARGET_WAITKIND_STOPPED
4451 ? ws
.value
.sig
: GDB_SIGNAL_0
);
4453 if (displaced_step_finish (t
, sig
) < 0)
4455 /* Add it back to the step-over queue. */
4456 t
->control
.trap_expected
= 0;
4457 global_thread_step_over_chain_enqueue (t
);
4460 regcache
= get_thread_regcache (t
);
4461 t
->suspend
.stop_pc
= regcache_read_pc (regcache
);
4465 fprintf_unfiltered (gdb_stdlog
,
4466 "infrun: saved stop_pc=%s for %s "
4467 "(currently_stepping=%d)\n",
4468 paddress (target_gdbarch (),
4469 t
->suspend
.stop_pc
),
4470 target_pid_to_str (t
->ptid
).c_str (),
4471 currently_stepping (t
));
4479 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_all_threads done\n");
4482 /* Handle a TARGET_WAITKIND_NO_RESUMED event. */
4485 handle_no_resumed (struct execution_control_state
*ecs
)
4487 if (target_can_async_p ())
4494 if (ui
->prompt_state
== PROMPT_BLOCKED
)
4502 /* There were no unwaited-for children left in the target, but,
4503 we're not synchronously waiting for events either. Just
4507 fprintf_unfiltered (gdb_stdlog
,
4508 "infrun: TARGET_WAITKIND_NO_RESUMED "
4509 "(ignoring: bg)\n");
4510 prepare_to_wait (ecs
);
4515 /* Otherwise, if we were running a synchronous execution command, we
4516 may need to cancel it and give the user back the terminal.
4518 In non-stop mode, the target can't tell whether we've already
4519 consumed previous stop events, so it can end up sending us a
4520 no-resumed event like so:
4522 #0 - thread 1 is left stopped
4524 #1 - thread 2 is resumed and hits breakpoint
4525 -> TARGET_WAITKIND_STOPPED
4527 #2 - thread 3 is resumed and exits
4528 this is the last resumed thread, so
4529 -> TARGET_WAITKIND_NO_RESUMED
4531 #3 - gdb processes stop for thread 2 and decides to re-resume
4534 #4 - gdb processes the TARGET_WAITKIND_NO_RESUMED event.
4535 thread 2 is now resumed, so the event should be ignored.
4537 IOW, if the stop for thread 2 doesn't end a foreground command,
4538 then we need to ignore the following TARGET_WAITKIND_NO_RESUMED
4539 event. But it could be that the event meant that thread 2 itself
4540 (or whatever other thread was the last resumed thread) exited.
4542 To address this we refresh the thread list and check whether we
4543 have resumed threads _now_. In the example above, this removes
4544 thread 3 from the thread list. If thread 2 was re-resumed, we
4545 ignore this event. If we find no thread resumed, then we cancel
4546 the synchronous command show "no unwaited-for " to the user. */
4547 update_thread_list ();
4549 for (thread_info
*thread
: all_non_exited_threads ())
4551 if (thread
->executing
4552 || thread
->suspend
.waitstatus_pending_p
)
4554 /* There were no unwaited-for children left in the target at
4555 some point, but there are now. Just ignore. */
4557 fprintf_unfiltered (gdb_stdlog
,
4558 "infrun: TARGET_WAITKIND_NO_RESUMED "
4559 "(ignoring: found resumed)\n");
4560 prepare_to_wait (ecs
);
4565 /* Note however that we may find no resumed thread because the whole
4566 process exited meanwhile (thus updating the thread list results
4567 in an empty thread list). In this case we know we'll be getting
4568 a process exit event shortly. */
4569 for (inferior
*inf
: all_inferiors ())
4574 thread_info
*thread
= any_live_thread_of_inferior (inf
);
4578 fprintf_unfiltered (gdb_stdlog
,
4579 "infrun: TARGET_WAITKIND_NO_RESUMED "
4580 "(expect process exit)\n");
4581 prepare_to_wait (ecs
);
4586 /* Go ahead and report the event. */
4590 /* Given an execution control state that has been freshly filled in by
4591 an event from the inferior, figure out what it means and take
4594 The alternatives are:
4596 1) stop_waiting and return; to really stop and return to the
4599 2) keep_going and return; to wait for the next event (set
4600 ecs->event_thread->stepping_over_breakpoint to 1 to single step
4604 handle_inferior_event (struct execution_control_state
*ecs
)
4606 /* Make sure that all temporary struct value objects that were
4607 created during the handling of the event get deleted at the
4609 scoped_value_mark free_values
;
4611 enum stop_kind stop_soon
;
4614 fprintf_unfiltered (gdb_stdlog
, "infrun: handle_inferior_event %s\n",
4615 target_waitstatus_to_string (&ecs
->ws
).c_str ());
4617 if (ecs
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
4619 /* We had an event in the inferior, but we are not interested in
4620 handling it at this level. The lower layers have already
4621 done what needs to be done, if anything.
4623 One of the possible circumstances for this is when the
4624 inferior produces output for the console. The inferior has
4625 not stopped, and we are ignoring the event. Another possible
4626 circumstance is any event which the lower level knows will be
4627 reported multiple times without an intervening resume. */
4628 prepare_to_wait (ecs
);
4632 if (ecs
->ws
.kind
== TARGET_WAITKIND_THREAD_EXITED
)
4634 prepare_to_wait (ecs
);
4638 if (ecs
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
4639 && handle_no_resumed (ecs
))
4642 /* Cache the last pid/waitstatus. */
4643 set_last_target_status (ecs
->ptid
, ecs
->ws
);
4645 /* Always clear state belonging to the previous time we stopped. */
4646 stop_stack_dummy
= STOP_NONE
;
4648 if (ecs
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
)
4650 /* No unwaited-for children left. IOW, all resumed children
4652 stop_print_frame
= 0;
4657 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
4658 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
)
4660 ecs
->event_thread
= find_thread_ptid (ecs
->ptid
);
4661 /* If it's a new thread, add it to the thread database. */
4662 if (ecs
->event_thread
== NULL
)
4663 ecs
->event_thread
= add_thread (ecs
->ptid
);
4665 /* Disable range stepping. If the next step request could use a
4666 range, this will be end up re-enabled then. */
4667 ecs
->event_thread
->control
.may_range_step
= 0;
4670 /* Dependent on valid ECS->EVENT_THREAD. */
4671 adjust_pc_after_break (ecs
->event_thread
, &ecs
->ws
);
4673 /* Dependent on the current PC value modified by adjust_pc_after_break. */
4674 reinit_frame_cache ();
4676 breakpoint_retire_moribund ();
4678 /* First, distinguish signals caused by the debugger from signals
4679 that have to do with the program's own actions. Note that
4680 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
4681 on the operating system version. Here we detect when a SIGILL or
4682 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
4683 something similar for SIGSEGV, since a SIGSEGV will be generated
4684 when we're trying to execute a breakpoint instruction on a
4685 non-executable stack. This happens for call dummy breakpoints
4686 for architectures like SPARC that place call dummies on the
4688 if (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
4689 && (ecs
->ws
.value
.sig
== GDB_SIGNAL_ILL
4690 || ecs
->ws
.value
.sig
== GDB_SIGNAL_SEGV
4691 || ecs
->ws
.value
.sig
== GDB_SIGNAL_EMT
))
4693 struct regcache
*regcache
= get_thread_regcache (ecs
->event_thread
);
4695 if (breakpoint_inserted_here_p (regcache
->aspace (),
4696 regcache_read_pc (regcache
)))
4699 fprintf_unfiltered (gdb_stdlog
,
4700 "infrun: Treating signal as SIGTRAP\n");
4701 ecs
->ws
.value
.sig
= GDB_SIGNAL_TRAP
;
4705 /* Mark the non-executing threads accordingly. In all-stop, all
4706 threads of all processes are stopped when we get any event
4707 reported. In non-stop mode, only the event thread stops. */
4711 if (!target_is_non_stop_p ())
4712 mark_ptid
= minus_one_ptid
;
4713 else if (ecs
->ws
.kind
== TARGET_WAITKIND_SIGNALLED
4714 || ecs
->ws
.kind
== TARGET_WAITKIND_EXITED
)
4716 /* If we're handling a process exit in non-stop mode, even
4717 though threads haven't been deleted yet, one would think
4718 that there is nothing to do, as threads of the dead process
4719 will be soon deleted, and threads of any other process were
4720 left running. However, on some targets, threads survive a
4721 process exit event. E.g., for the "checkpoint" command,
4722 when the current checkpoint/fork exits, linux-fork.c
4723 automatically switches to another fork from within
4724 target_mourn_inferior, by associating the same
4725 inferior/thread to another fork. We haven't mourned yet at
4726 this point, but we must mark any threads left in the
4727 process as not-executing so that finish_thread_state marks
4728 them stopped (in the user's perspective) if/when we present
4729 the stop to the user. */
4730 mark_ptid
= ptid_t (ecs
->ptid
.pid ());
4733 mark_ptid
= ecs
->ptid
;
4735 set_executing (mark_ptid
, 0);
4737 /* Likewise the resumed flag. */
4738 set_resumed (mark_ptid
, 0);
4741 switch (ecs
->ws
.kind
)
4743 case TARGET_WAITKIND_LOADED
:
4744 context_switch (ecs
);
4745 /* Ignore gracefully during startup of the inferior, as it might
4746 be the shell which has just loaded some objects, otherwise
4747 add the symbols for the newly loaded objects. Also ignore at
4748 the beginning of an attach or remote session; we will query
4749 the full list of libraries once the connection is
4752 stop_soon
= get_inferior_stop_soon (ecs
);
4753 if (stop_soon
== NO_STOP_QUIETLY
)
4755 struct regcache
*regcache
;
4757 regcache
= get_thread_regcache (ecs
->event_thread
);
4759 handle_solib_event ();
4761 ecs
->event_thread
->control
.stop_bpstat
4762 = bpstat_stop_status (regcache
->aspace (),
4763 ecs
->event_thread
->suspend
.stop_pc
,
4764 ecs
->event_thread
, &ecs
->ws
);
4766 if (handle_stop_requested (ecs
))
4769 if (bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
4771 /* A catchpoint triggered. */
4772 process_event_stop_test (ecs
);
4776 /* If requested, stop when the dynamic linker notifies
4777 gdb of events. This allows the user to get control
4778 and place breakpoints in initializer routines for
4779 dynamically loaded objects (among other things). */
4780 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4781 if (stop_on_solib_events
)
4783 /* Make sure we print "Stopped due to solib-event" in
4785 stop_print_frame
= 1;
4792 /* If we are skipping through a shell, or through shared library
4793 loading that we aren't interested in, resume the program. If
4794 we're running the program normally, also resume. */
4795 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== NO_STOP_QUIETLY
)
4797 /* Loading of shared libraries might have changed breakpoint
4798 addresses. Make sure new breakpoints are inserted. */
4799 if (stop_soon
== NO_STOP_QUIETLY
)
4800 insert_breakpoints ();
4801 resume (GDB_SIGNAL_0
);
4802 prepare_to_wait (ecs
);
4806 /* But stop if we're attaching or setting up a remote
4808 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
4809 || stop_soon
== STOP_QUIETLY_REMOTE
)
4812 fprintf_unfiltered (gdb_stdlog
, "infrun: quietly stopped\n");
4817 internal_error (__FILE__
, __LINE__
,
4818 _("unhandled stop_soon: %d"), (int) stop_soon
);
4820 case TARGET_WAITKIND_SPURIOUS
:
4821 if (handle_stop_requested (ecs
))
4823 context_switch (ecs
);
4824 resume (GDB_SIGNAL_0
);
4825 prepare_to_wait (ecs
);
4828 case TARGET_WAITKIND_THREAD_CREATED
:
4829 if (handle_stop_requested (ecs
))
4831 context_switch (ecs
);
4832 if (!switch_back_to_stepped_thread (ecs
))
4836 case TARGET_WAITKIND_EXITED
:
4837 case TARGET_WAITKIND_SIGNALLED
:
4838 inferior_ptid
= ecs
->ptid
;
4839 set_current_inferior (find_inferior_ptid (ecs
->ptid
));
4840 set_current_program_space (current_inferior ()->pspace
);
4841 handle_vfork_child_exec_or_exit (0);
4842 target_terminal::ours (); /* Must do this before mourn anyway. */
4844 /* Clearing any previous state of convenience variables. */
4845 clear_exit_convenience_vars ();
4847 if (ecs
->ws
.kind
== TARGET_WAITKIND_EXITED
)
4849 /* Record the exit code in the convenience variable $_exitcode, so
4850 that the user can inspect this again later. */
4851 set_internalvar_integer (lookup_internalvar ("_exitcode"),
4852 (LONGEST
) ecs
->ws
.value
.integer
);
4854 /* Also record this in the inferior itself. */
4855 current_inferior ()->has_exit_code
= 1;
4856 current_inferior ()->exit_code
= (LONGEST
) ecs
->ws
.value
.integer
;
4858 /* Support the --return-child-result option. */
4859 return_child_result_value
= ecs
->ws
.value
.integer
;
4861 gdb::observers::exited
.notify (ecs
->ws
.value
.integer
);
4865 struct gdbarch
*gdbarch
= current_inferior ()->gdbarch
;
4867 if (gdbarch_gdb_signal_to_target_p (gdbarch
))
4869 /* Set the value of the internal variable $_exitsignal,
4870 which holds the signal uncaught by the inferior. */
4871 set_internalvar_integer (lookup_internalvar ("_exitsignal"),
4872 gdbarch_gdb_signal_to_target (gdbarch
,
4873 ecs
->ws
.value
.sig
));
4877 /* We don't have access to the target's method used for
4878 converting between signal numbers (GDB's internal
4879 representation <-> target's representation).
4880 Therefore, we cannot do a good job at displaying this
4881 information to the user. It's better to just warn
4882 her about it (if infrun debugging is enabled), and
4885 fprintf_filtered (gdb_stdlog
, _("\
4886 Cannot fill $_exitsignal with the correct signal number.\n"));
4889 gdb::observers::signal_exited
.notify (ecs
->ws
.value
.sig
);
4892 gdb_flush (gdb_stdout
);
4893 target_mourn_inferior (inferior_ptid
);
4894 stop_print_frame
= 0;
4898 /* The following are the only cases in which we keep going;
4899 the above cases end in a continue or goto. */
4900 case TARGET_WAITKIND_FORKED
:
4901 case TARGET_WAITKIND_VFORKED
:
4902 /* Check whether the inferior is displaced stepping. */
4904 struct regcache
*regcache
= get_thread_regcache (ecs
->event_thread
);
4905 struct gdbarch
*gdbarch
= regcache
->arch ();
4907 /* If checking displaced stepping is supported, and thread
4908 ecs->ptid is displaced stepping. */
4909 if (displaced_step_in_progress (ecs
->event_thread
))
4911 struct inferior
*parent_inf
4912 = find_inferior_ptid (ecs
->ptid
);
4913 struct regcache
*child_regcache
;
4914 CORE_ADDR parent_pc
;
4916 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
4918 // struct displaced_step_inferior_state *displaced
4919 // = get_displaced_stepping_state (parent_inf);
4921 /* Restore scratch pad for child process. */
4922 //displaced_step_restore (displaced, ecs->ws.value.related_pid);
4923 // FIXME: we should restore all the buffers that were currently in use
4926 /* GDB has got TARGET_WAITKIND_FORKED or TARGET_WAITKIND_VFORKED,
4927 indicating that the displaced stepping of syscall instruction
4928 has been done. Perform cleanup for parent process here. Note
4929 that this operation also cleans up the child process for vfork,
4930 because their pages are shared. */
4931 displaced_step_finish (ecs
->event_thread
, GDB_SIGNAL_TRAP
);
4932 /* Start a new step-over in another thread if there's one
4936 /* Since the vfork/fork syscall instruction was executed in the scratchpad,
4937 the child's PC is also within the scratchpad. Set the child's PC
4938 to the parent's PC value, which has already been fixed up.
4939 FIXME: we use the parent's aspace here, although we're touching
4940 the child, because the child hasn't been added to the inferior
4941 list yet at this point. */
4944 = get_thread_arch_aspace_regcache (ecs
->ws
.value
.related_pid
,
4946 parent_inf
->aspace
);
4947 /* Read PC value of parent process. */
4948 parent_pc
= regcache_read_pc (regcache
);
4950 if (debug_displaced
)
4951 fprintf_unfiltered (gdb_stdlog
,
4952 "displaced: write child pc from %s to %s\n",
4954 regcache_read_pc (child_regcache
)),
4955 paddress (gdbarch
, parent_pc
));
4957 regcache_write_pc (child_regcache
, parent_pc
);
4961 context_switch (ecs
);
4963 /* Immediately detach breakpoints from the child before there's
4964 any chance of letting the user delete breakpoints from the
4965 breakpoint lists. If we don't do this early, it's easy to
4966 leave left over traps in the child, vis: "break foo; catch
4967 fork; c; <fork>; del; c; <child calls foo>". We only follow
4968 the fork on the last `continue', and by that time the
4969 breakpoint at "foo" is long gone from the breakpoint table.
4970 If we vforked, then we don't need to unpatch here, since both
4971 parent and child are sharing the same memory pages; we'll
4972 need to unpatch at follow/detach time instead to be certain
4973 that new breakpoints added between catchpoint hit time and
4974 vfork follow are detached. */
4975 if (ecs
->ws
.kind
!= TARGET_WAITKIND_VFORKED
)
4977 /* This won't actually modify the breakpoint list, but will
4978 physically remove the breakpoints from the child. */
4979 detach_breakpoints (ecs
->ws
.value
.related_pid
);
4982 delete_just_stopped_threads_single_step_breakpoints ();
4984 /* In case the event is caught by a catchpoint, remember that
4985 the event is to be followed at the next resume of the thread,
4986 and not immediately. */
4987 ecs
->event_thread
->pending_follow
= ecs
->ws
;
4989 ecs
->event_thread
->suspend
.stop_pc
4990 = regcache_read_pc (get_thread_regcache (ecs
->event_thread
));
4992 ecs
->event_thread
->control
.stop_bpstat
4993 = bpstat_stop_status (get_current_regcache ()->aspace (),
4994 ecs
->event_thread
->suspend
.stop_pc
,
4995 ecs
->event_thread
, &ecs
->ws
);
4997 if (handle_stop_requested (ecs
))
5000 /* If no catchpoint triggered for this, then keep going. Note
5001 that we're interested in knowing the bpstat actually causes a
5002 stop, not just if it may explain the signal. Software
5003 watchpoints, for example, always appear in the bpstat. */
5004 if (!bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
5008 = (follow_fork_mode_string
== follow_fork_mode_child
);
5010 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5012 should_resume
= follow_fork ();
5014 thread_info
*parent
= ecs
->event_thread
;
5015 thread_info
*child
= find_thread_ptid (ecs
->ws
.value
.related_pid
);
5017 /* At this point, the parent is marked running, and the
5018 child is marked stopped. */
5020 /* If not resuming the parent, mark it stopped. */
5021 if (follow_child
&& !detach_fork
&& !non_stop
&& !sched_multi
)
5022 parent
->set_running (false);
5024 /* If resuming the child, mark it running. */
5025 if (follow_child
|| (!detach_fork
&& (non_stop
|| sched_multi
)))
5026 child
->set_running (true);
5028 /* In non-stop mode, also resume the other branch. */
5029 if (!detach_fork
&& (non_stop
5030 || (sched_multi
&& target_is_non_stop_p ())))
5033 switch_to_thread (parent
);
5035 switch_to_thread (child
);
5037 ecs
->event_thread
= inferior_thread ();
5038 ecs
->ptid
= inferior_ptid
;
5043 switch_to_thread (child
);
5045 switch_to_thread (parent
);
5047 ecs
->event_thread
= inferior_thread ();
5048 ecs
->ptid
= inferior_ptid
;
5056 process_event_stop_test (ecs
);
5059 case TARGET_WAITKIND_VFORK_DONE
:
5060 /* Done with the shared memory region. Re-insert breakpoints in
5061 the parent, and keep going. */
5063 context_switch (ecs
);
5065 current_inferior ()->waiting_for_vfork_done
= 0;
5066 current_inferior ()->pspace
->breakpoints_not_allowed
= 0;
5068 if (handle_stop_requested (ecs
))
5071 /* This also takes care of reinserting breakpoints in the
5072 previously locked inferior. */
5076 case TARGET_WAITKIND_EXECD
:
5078 /* Note we can't read registers yet (the stop_pc), because we
5079 don't yet know the inferior's post-exec architecture.
5080 'stop_pc' is explicitly read below instead. */
5081 switch_to_thread_no_regs (ecs
->event_thread
);
5083 /* Do whatever is necessary to the parent branch of the vfork. */
5084 handle_vfork_child_exec_or_exit (1);
5086 /* This causes the eventpoints and symbol table to be reset.
5087 Must do this now, before trying to determine whether to
5089 follow_exec (inferior_ptid
, ecs
->ws
.value
.execd_pathname
);
5091 /* In follow_exec we may have deleted the original thread and
5092 created a new one. Make sure that the event thread is the
5093 execd thread for that case (this is a nop otherwise). */
5094 ecs
->event_thread
= inferior_thread ();
5096 ecs
->event_thread
->suspend
.stop_pc
5097 = regcache_read_pc (get_thread_regcache (ecs
->event_thread
));
5099 ecs
->event_thread
->control
.stop_bpstat
5100 = bpstat_stop_status (get_current_regcache ()->aspace (),
5101 ecs
->event_thread
->suspend
.stop_pc
,
5102 ecs
->event_thread
, &ecs
->ws
);
5104 /* Note that this may be referenced from inside
5105 bpstat_stop_status above, through inferior_has_execd. */
5106 xfree (ecs
->ws
.value
.execd_pathname
);
5107 ecs
->ws
.value
.execd_pathname
= NULL
;
5109 if (handle_stop_requested (ecs
))
5112 /* If no catchpoint triggered for this, then keep going. */
5113 if (!bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
5115 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5119 process_event_stop_test (ecs
);
5122 /* Be careful not to try to gather much state about a thread
5123 that's in a syscall. It's frequently a losing proposition. */
5124 case TARGET_WAITKIND_SYSCALL_ENTRY
:
5125 /* Getting the current syscall number. */
5126 if (handle_syscall_event (ecs
) == 0)
5127 process_event_stop_test (ecs
);
5130 /* Before examining the threads further, step this thread to
5131 get it entirely out of the syscall. (We get notice of the
5132 event when the thread is just on the verge of exiting a
5133 syscall. Stepping one instruction seems to get it back
5135 case TARGET_WAITKIND_SYSCALL_RETURN
:
5136 if (handle_syscall_event (ecs
) == 0)
5137 process_event_stop_test (ecs
);
5140 case TARGET_WAITKIND_STOPPED
:
5141 handle_signal_stop (ecs
);
5144 case TARGET_WAITKIND_NO_HISTORY
:
5145 /* Reverse execution: target ran out of history info. */
5147 /* Switch to the stopped thread. */
5148 context_switch (ecs
);
5150 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped\n");
5152 delete_just_stopped_threads_single_step_breakpoints ();
5153 ecs
->event_thread
->suspend
.stop_pc
5154 = regcache_read_pc (get_thread_regcache (inferior_thread ()));
5156 if (handle_stop_requested (ecs
))
5159 gdb::observers::no_history
.notify ();
5165 /* Restart threads back to what they were trying to do back when we
5166 paused them for an in-line step-over. The EVENT_THREAD thread is
5170 restart_threads (struct thread_info
*event_thread
)
5172 /* In case the instruction just stepped spawned a new thread. */
5173 update_thread_list ();
5175 for (thread_info
*tp
: all_non_exited_threads ())
5177 if (tp
== event_thread
)
5180 fprintf_unfiltered (gdb_stdlog
,
5181 "infrun: restart threads: "
5182 "[%s] is event thread\n",
5183 target_pid_to_str (tp
->ptid
).c_str ());
5187 if (!(tp
->state
== THREAD_RUNNING
|| tp
->control
.in_infcall
))
5190 fprintf_unfiltered (gdb_stdlog
,
5191 "infrun: restart threads: "
5192 "[%s] not meant to be running\n",
5193 target_pid_to_str (tp
->ptid
).c_str ());
5200 fprintf_unfiltered (gdb_stdlog
,
5201 "infrun: restart threads: [%s] resumed\n",
5202 target_pid_to_str (tp
->ptid
).c_str ());
5203 gdb_assert (tp
->executing
|| tp
->suspend
.waitstatus_pending_p
);
5207 if (thread_is_in_step_over_chain (tp
))
5210 fprintf_unfiltered (gdb_stdlog
,
5211 "infrun: restart threads: "
5212 "[%s] needs step-over\n",
5213 target_pid_to_str (tp
->ptid
).c_str ());
5214 gdb_assert (!tp
->resumed
);
5219 if (tp
->suspend
.waitstatus_pending_p
)
5222 fprintf_unfiltered (gdb_stdlog
,
5223 "infrun: restart threads: "
5224 "[%s] has pending status\n",
5225 target_pid_to_str (tp
->ptid
).c_str ());
5230 gdb_assert (!tp
->stop_requested
);
5232 /* If some thread needs to start a step-over at this point, it
5233 should still be in the step-over queue, and thus skipped
5235 if (thread_still_needs_step_over (tp
))
5237 internal_error (__FILE__
, __LINE__
,
5238 "thread [%s] needs a step-over, but not in "
5239 "step-over queue\n",
5240 target_pid_to_str (tp
->ptid
).c_str ());
5243 if (currently_stepping (tp
))
5246 fprintf_unfiltered (gdb_stdlog
,
5247 "infrun: restart threads: [%s] was stepping\n",
5248 target_pid_to_str (tp
->ptid
).c_str ());
5249 keep_going_stepped_thread (tp
);
5253 struct execution_control_state ecss
;
5254 struct execution_control_state
*ecs
= &ecss
;
5257 fprintf_unfiltered (gdb_stdlog
,
5258 "infrun: restart threads: [%s] continuing\n",
5259 target_pid_to_str (tp
->ptid
).c_str ());
5260 reset_ecs (ecs
, tp
);
5261 switch_to_thread (tp
);
5262 keep_going_pass_signal (ecs
);
5267 /* Callback for iterate_over_threads. Find a resumed thread that has
5268 a pending waitstatus. */
5271 resumed_thread_with_pending_status (struct thread_info
*tp
,
5275 && tp
->suspend
.waitstatus_pending_p
);
5278 /* Called when we get an event that may finish an in-line or
5279 out-of-line (displaced stepping) step-over started previously.
5280 Return true if the event is processed and we should go back to the
5281 event loop; false if the caller should continue processing the
5285 finish_step_over (struct execution_control_state
*ecs
)
5287 int had_step_over_info
;
5289 displaced_step_finish (ecs
->event_thread
,
5290 ecs
->event_thread
->suspend
.stop_signal
);
5292 had_step_over_info
= step_over_info_valid_p ();
5294 if (had_step_over_info
)
5296 /* If we're stepping over a breakpoint with all threads locked,
5297 then only the thread that was stepped should be reporting
5299 gdb_assert (ecs
->event_thread
->control
.trap_expected
);
5301 clear_step_over_info ();
5304 if (!target_is_non_stop_p ())
5307 /* Start a new step-over in another thread if there's one that
5311 /* If we were stepping over a breakpoint before, and haven't started
5312 a new in-line step-over sequence, then restart all other threads
5313 (except the event thread). We can't do this in all-stop, as then
5314 e.g., we wouldn't be able to issue any other remote packet until
5315 these other threads stop. */
5316 if (had_step_over_info
&& !step_over_info_valid_p ())
5318 struct thread_info
*pending
;
5320 /* If we only have threads with pending statuses, the restart
5321 below won't restart any thread and so nothing re-inserts the
5322 breakpoint we just stepped over. But we need it inserted
5323 when we later process the pending events, otherwise if
5324 another thread has a pending event for this breakpoint too,
5325 we'd discard its event (because the breakpoint that
5326 originally caused the event was no longer inserted). */
5327 context_switch (ecs
);
5328 insert_breakpoints ();
5331 scoped_restore save_defer_tc
5332 = make_scoped_defer_target_commit_resume ();
5333 restart_threads (ecs
->event_thread
);
5335 target_commit_resume ();
5337 /* If we have events pending, go through handle_inferior_event
5338 again, picking up a pending event at random. This avoids
5339 thread starvation. */
5341 /* But not if we just stepped over a watchpoint in order to let
5342 the instruction execute so we can evaluate its expression.
5343 The set of watchpoints that triggered is recorded in the
5344 breakpoint objects themselves (see bp->watchpoint_triggered).
5345 If we processed another event first, that other event could
5346 clobber this info. */
5347 if (ecs
->event_thread
->stepping_over_watchpoint
)
5350 pending
= iterate_over_threads (resumed_thread_with_pending_status
,
5352 if (pending
!= NULL
)
5354 struct thread_info
*tp
= ecs
->event_thread
;
5355 struct regcache
*regcache
;
5359 fprintf_unfiltered (gdb_stdlog
,
5360 "infrun: found resumed threads with "
5361 "pending events, saving status\n");
5364 gdb_assert (pending
!= tp
);
5366 /* Record the event thread's event for later. */
5367 save_waitstatus (tp
, &ecs
->ws
);
5368 /* This was cleared early, by handle_inferior_event. Set it
5369 so this pending event is considered by
5373 gdb_assert (!tp
->executing
);
5375 regcache
= get_thread_regcache (tp
);
5376 tp
->suspend
.stop_pc
= regcache_read_pc (regcache
);
5380 fprintf_unfiltered (gdb_stdlog
,
5381 "infrun: saved stop_pc=%s for %s "
5382 "(currently_stepping=%d)\n",
5383 paddress (target_gdbarch (),
5384 tp
->suspend
.stop_pc
),
5385 target_pid_to_str (tp
->ptid
).c_str (),
5386 currently_stepping (tp
));
5389 /* This in-line step-over finished; clear this so we won't
5390 start a new one. This is what handle_signal_stop would
5391 do, if we returned false. */
5392 tp
->stepping_over_breakpoint
= 0;
5394 /* Wake up the event loop again. */
5395 mark_async_event_handler (infrun_async_inferior_event_token
);
5397 prepare_to_wait (ecs
);
5405 /* Come here when the program has stopped with a signal. */
5408 handle_signal_stop (struct execution_control_state
*ecs
)
5410 struct frame_info
*frame
;
5411 struct gdbarch
*gdbarch
;
5412 int stopped_by_watchpoint
;
5413 enum stop_kind stop_soon
;
5416 gdb_assert (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
5418 ecs
->event_thread
->suspend
.stop_signal
= ecs
->ws
.value
.sig
;
5420 /* Do we need to clean up the state of a thread that has
5421 completed a displaced single-step? (Doing so usually affects
5422 the PC, so do it here, before we set stop_pc.) */
5423 if (finish_step_over (ecs
))
5426 /* If we either finished a single-step or hit a breakpoint, but
5427 the user wanted this thread to be stopped, pretend we got a
5428 SIG0 (generic unsignaled stop). */
5429 if (ecs
->event_thread
->stop_requested
5430 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
5431 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5433 ecs
->event_thread
->suspend
.stop_pc
5434 = regcache_read_pc (get_thread_regcache (ecs
->event_thread
));
5438 struct regcache
*regcache
= get_thread_regcache (ecs
->event_thread
);
5439 struct gdbarch
*reg_gdbarch
= regcache
->arch ();
5440 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
5442 inferior_ptid
= ecs
->ptid
;
5444 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_pc = %s\n",
5445 paddress (reg_gdbarch
,
5446 ecs
->event_thread
->suspend
.stop_pc
));
5447 if (target_stopped_by_watchpoint ())
5451 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped by watchpoint\n");
5453 if (target_stopped_data_address (current_top_target (), &addr
))
5454 fprintf_unfiltered (gdb_stdlog
,
5455 "infrun: stopped data address = %s\n",
5456 paddress (reg_gdbarch
, addr
));
5458 fprintf_unfiltered (gdb_stdlog
,
5459 "infrun: (no data address available)\n");
5463 /* This is originated from start_remote(), start_inferior() and
5464 shared libraries hook functions. */
5465 stop_soon
= get_inferior_stop_soon (ecs
);
5466 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_REMOTE
)
5468 context_switch (ecs
);
5470 fprintf_unfiltered (gdb_stdlog
, "infrun: quietly stopped\n");
5471 stop_print_frame
= 1;
5476 /* This originates from attach_command(). We need to overwrite
5477 the stop_signal here, because some kernels don't ignore a
5478 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
5479 See more comments in inferior.h. On the other hand, if we
5480 get a non-SIGSTOP, report it to the user - assume the backend
5481 will handle the SIGSTOP if it should show up later.
5483 Also consider that the attach is complete when we see a
5484 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
5485 target extended-remote report it instead of a SIGSTOP
5486 (e.g. gdbserver). We already rely on SIGTRAP being our
5487 signal, so this is no exception.
5489 Also consider that the attach is complete when we see a
5490 GDB_SIGNAL_0. In non-stop mode, GDB will explicitly tell
5491 the target to stop all threads of the inferior, in case the
5492 low level attach operation doesn't stop them implicitly. If
5493 they weren't stopped implicitly, then the stub will report a
5494 GDB_SIGNAL_0, meaning: stopped for no particular reason
5495 other than GDB's request. */
5496 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
5497 && (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_STOP
5498 || ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
5499 || ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_0
))
5501 stop_print_frame
= 1;
5503 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5507 /* See if something interesting happened to the non-current thread. If
5508 so, then switch to that thread. */
5509 if (ecs
->ptid
!= inferior_ptid
)
5512 fprintf_unfiltered (gdb_stdlog
, "infrun: context switch\n");
5514 context_switch (ecs
);
5516 if (deprecated_context_hook
)
5517 deprecated_context_hook (ecs
->event_thread
->global_num
);
5520 /* At this point, get hold of the now-current thread's frame. */
5521 frame
= get_current_frame ();
5522 gdbarch
= get_frame_arch (frame
);
5524 /* Pull the single step breakpoints out of the target. */
5525 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
5527 struct regcache
*regcache
;
5530 regcache
= get_thread_regcache (ecs
->event_thread
);
5531 const address_space
*aspace
= regcache
->aspace ();
5533 pc
= regcache_read_pc (regcache
);
5535 /* However, before doing so, if this single-step breakpoint was
5536 actually for another thread, set this thread up for moving
5538 if (!thread_has_single_step_breakpoint_here (ecs
->event_thread
,
5541 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
5545 fprintf_unfiltered (gdb_stdlog
,
5546 "infrun: [%s] hit another thread's "
5547 "single-step breakpoint\n",
5548 target_pid_to_str (ecs
->ptid
).c_str ());
5550 ecs
->hit_singlestep_breakpoint
= 1;
5557 fprintf_unfiltered (gdb_stdlog
,
5558 "infrun: [%s] hit its "
5559 "single-step breakpoint\n",
5560 target_pid_to_str (ecs
->ptid
).c_str ());
5564 delete_just_stopped_threads_single_step_breakpoints ();
5566 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
5567 && ecs
->event_thread
->control
.trap_expected
5568 && ecs
->event_thread
->stepping_over_watchpoint
)
5569 stopped_by_watchpoint
= 0;
5571 stopped_by_watchpoint
= watchpoints_triggered (&ecs
->ws
);
5573 /* If necessary, step over this watchpoint. We'll be back to display
5575 if (stopped_by_watchpoint
5576 && (target_have_steppable_watchpoint
5577 || gdbarch_have_nonsteppable_watchpoint (gdbarch
)))
5579 /* At this point, we are stopped at an instruction which has
5580 attempted to write to a piece of memory under control of
5581 a watchpoint. The instruction hasn't actually executed
5582 yet. If we were to evaluate the watchpoint expression
5583 now, we would get the old value, and therefore no change
5584 would seem to have occurred.
5586 In order to make watchpoints work `right', we really need
5587 to complete the memory write, and then evaluate the
5588 watchpoint expression. We do this by single-stepping the
5591 It may not be necessary to disable the watchpoint to step over
5592 it. For example, the PA can (with some kernel cooperation)
5593 single step over a watchpoint without disabling the watchpoint.
5595 It is far more common to need to disable a watchpoint to step
5596 the inferior over it. If we have non-steppable watchpoints,
5597 we must disable the current watchpoint; it's simplest to
5598 disable all watchpoints.
5600 Any breakpoint at PC must also be stepped over -- if there's
5601 one, it will have already triggered before the watchpoint
5602 triggered, and we either already reported it to the user, or
5603 it didn't cause a stop and we called keep_going. In either
5604 case, if there was a breakpoint at PC, we must be trying to
5606 ecs
->event_thread
->stepping_over_watchpoint
= 1;
5611 ecs
->event_thread
->stepping_over_breakpoint
= 0;
5612 ecs
->event_thread
->stepping_over_watchpoint
= 0;
5613 bpstat_clear (&ecs
->event_thread
->control
.stop_bpstat
);
5614 ecs
->event_thread
->control
.stop_step
= 0;
5615 stop_print_frame
= 1;
5616 stopped_by_random_signal
= 0;
5617 bpstat stop_chain
= NULL
;
5619 /* Hide inlined functions starting here, unless we just performed stepi or
5620 nexti. After stepi and nexti, always show the innermost frame (not any
5621 inline function call sites). */
5622 if (ecs
->event_thread
->control
.step_range_end
!= 1)
5624 const address_space
*aspace
5625 = get_thread_regcache (ecs
->event_thread
)->aspace ();
5627 /* skip_inline_frames is expensive, so we avoid it if we can
5628 determine that the address is one where functions cannot have
5629 been inlined. This improves performance with inferiors that
5630 load a lot of shared libraries, because the solib event
5631 breakpoint is defined as the address of a function (i.e. not
5632 inline). Note that we have to check the previous PC as well
5633 as the current one to catch cases when we have just
5634 single-stepped off a breakpoint prior to reinstating it.
5635 Note that we're assuming that the code we single-step to is
5636 not inline, but that's not definitive: there's nothing
5637 preventing the event breakpoint function from containing
5638 inlined code, and the single-step ending up there. If the
5639 user had set a breakpoint on that inlined code, the missing
5640 skip_inline_frames call would break things. Fortunately
5641 that's an extremely unlikely scenario. */
5642 if (!pc_at_non_inline_function (aspace
,
5643 ecs
->event_thread
->suspend
.stop_pc
,
5645 && !(ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
5646 && ecs
->event_thread
->control
.trap_expected
5647 && pc_at_non_inline_function (aspace
,
5648 ecs
->event_thread
->prev_pc
,
5651 stop_chain
= build_bpstat_chain (aspace
,
5652 ecs
->event_thread
->suspend
.stop_pc
,
5654 skip_inline_frames (ecs
->event_thread
, stop_chain
);
5656 /* Re-fetch current thread's frame in case that invalidated
5658 frame
= get_current_frame ();
5659 gdbarch
= get_frame_arch (frame
);
5663 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
5664 && ecs
->event_thread
->control
.trap_expected
5665 && gdbarch_single_step_through_delay_p (gdbarch
)
5666 && currently_stepping (ecs
->event_thread
))
5668 /* We're trying to step off a breakpoint. Turns out that we're
5669 also on an instruction that needs to be stepped multiple
5670 times before it's been fully executing. E.g., architectures
5671 with a delay slot. It needs to be stepped twice, once for
5672 the instruction and once for the delay slot. */
5673 int step_through_delay
5674 = gdbarch_single_step_through_delay (gdbarch
, frame
);
5676 if (debug_infrun
&& step_through_delay
)
5677 fprintf_unfiltered (gdb_stdlog
, "infrun: step through delay\n");
5678 if (ecs
->event_thread
->control
.step_range_end
== 0
5679 && step_through_delay
)
5681 /* The user issued a continue when stopped at a breakpoint.
5682 Set up for another trap and get out of here. */
5683 ecs
->event_thread
->stepping_over_breakpoint
= 1;
5687 else if (step_through_delay
)
5689 /* The user issued a step when stopped at a breakpoint.
5690 Maybe we should stop, maybe we should not - the delay
5691 slot *might* correspond to a line of source. In any
5692 case, don't decide that here, just set
5693 ecs->stepping_over_breakpoint, making sure we
5694 single-step again before breakpoints are re-inserted. */
5695 ecs
->event_thread
->stepping_over_breakpoint
= 1;
5699 /* See if there is a breakpoint/watchpoint/catchpoint/etc. that
5700 handles this event. */
5701 ecs
->event_thread
->control
.stop_bpstat
5702 = bpstat_stop_status (get_current_regcache ()->aspace (),
5703 ecs
->event_thread
->suspend
.stop_pc
,
5704 ecs
->event_thread
, &ecs
->ws
, stop_chain
);
5706 /* Following in case break condition called a
5708 stop_print_frame
= 1;
5710 /* This is where we handle "moribund" watchpoints. Unlike
5711 software breakpoints traps, hardware watchpoint traps are
5712 always distinguishable from random traps. If no high-level
5713 watchpoint is associated with the reported stop data address
5714 anymore, then the bpstat does not explain the signal ---
5715 simply make sure to ignore it if `stopped_by_watchpoint' is
5719 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
5720 && !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
5722 && stopped_by_watchpoint
)
5723 fprintf_unfiltered (gdb_stdlog
,
5724 "infrun: no user watchpoint explains "
5725 "watchpoint SIGTRAP, ignoring\n");
5727 /* NOTE: cagney/2003-03-29: These checks for a random signal
5728 at one stage in the past included checks for an inferior
5729 function call's call dummy's return breakpoint. The original
5730 comment, that went with the test, read:
5732 ``End of a stack dummy. Some systems (e.g. Sony news) give
5733 another signal besides SIGTRAP, so check here as well as
5736 If someone ever tries to get call dummys on a
5737 non-executable stack to work (where the target would stop
5738 with something like a SIGSEGV), then those tests might need
5739 to be re-instated. Given, however, that the tests were only
5740 enabled when momentary breakpoints were not being used, I
5741 suspect that it won't be the case.
5743 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
5744 be necessary for call dummies on a non-executable stack on
5747 /* See if the breakpoints module can explain the signal. */
5749 = !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
5750 ecs
->event_thread
->suspend
.stop_signal
);
5752 /* Maybe this was a trap for a software breakpoint that has since
5754 if (random_signal
&& target_stopped_by_sw_breakpoint ())
5756 if (program_breakpoint_here_p (gdbarch
,
5757 ecs
->event_thread
->suspend
.stop_pc
))
5759 struct regcache
*regcache
;
5762 /* Re-adjust PC to what the program would see if GDB was not
5764 regcache
= get_thread_regcache (ecs
->event_thread
);
5765 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
5768 gdb::optional
<scoped_restore_tmpl
<int>>
5769 restore_operation_disable
;
5771 if (record_full_is_used ())
5772 restore_operation_disable
.emplace
5773 (record_full_gdb_operation_disable_set ());
5775 regcache_write_pc (regcache
,
5776 ecs
->event_thread
->suspend
.stop_pc
+ decr_pc
);
5781 /* A delayed software breakpoint event. Ignore the trap. */
5783 fprintf_unfiltered (gdb_stdlog
,
5784 "infrun: delayed software breakpoint "
5785 "trap, ignoring\n");
5790 /* Maybe this was a trap for a hardware breakpoint/watchpoint that
5791 has since been removed. */
5792 if (random_signal
&& target_stopped_by_hw_breakpoint ())
5794 /* A delayed hardware breakpoint event. Ignore the trap. */
5796 fprintf_unfiltered (gdb_stdlog
,
5797 "infrun: delayed hardware breakpoint/watchpoint "
5798 "trap, ignoring\n");
5802 /* If not, perhaps stepping/nexting can. */
5804 random_signal
= !(ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
5805 && currently_stepping (ecs
->event_thread
));
5807 /* Perhaps the thread hit a single-step breakpoint of _another_
5808 thread. Single-step breakpoints are transparent to the
5809 breakpoints module. */
5811 random_signal
= !ecs
->hit_singlestep_breakpoint
;
5813 /* No? Perhaps we got a moribund watchpoint. */
5815 random_signal
= !stopped_by_watchpoint
;
5817 /* Always stop if the user explicitly requested this thread to
5819 if (ecs
->event_thread
->stop_requested
)
5823 fprintf_unfiltered (gdb_stdlog
, "infrun: user-requested stop\n");
5826 /* For the program's own signals, act according to
5827 the signal handling tables. */
5831 /* Signal not for debugging purposes. */
5832 struct inferior
*inf
= find_inferior_ptid (ecs
->ptid
);
5833 enum gdb_signal stop_signal
= ecs
->event_thread
->suspend
.stop_signal
;
5836 fprintf_unfiltered (gdb_stdlog
, "infrun: random signal (%s)\n",
5837 gdb_signal_to_symbol_string (stop_signal
));
5839 stopped_by_random_signal
= 1;
5841 /* Always stop on signals if we're either just gaining control
5842 of the program, or the user explicitly requested this thread
5843 to remain stopped. */
5844 if (stop_soon
!= NO_STOP_QUIETLY
5845 || ecs
->event_thread
->stop_requested
5847 && signal_stop_state (ecs
->event_thread
->suspend
.stop_signal
)))
5853 /* Notify observers the signal has "handle print" set. Note we
5854 returned early above if stopping; normal_stop handles the
5855 printing in that case. */
5856 if (signal_print
[ecs
->event_thread
->suspend
.stop_signal
])
5858 /* The signal table tells us to print about this signal. */
5859 target_terminal::ours_for_output ();
5860 gdb::observers::signal_received
.notify (ecs
->event_thread
->suspend
.stop_signal
);
5861 target_terminal::inferior ();
5864 /* Clear the signal if it should not be passed. */
5865 if (signal_program
[ecs
->event_thread
->suspend
.stop_signal
] == 0)
5866 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5868 if (ecs
->event_thread
->prev_pc
== ecs
->event_thread
->suspend
.stop_pc
5869 && ecs
->event_thread
->control
.trap_expected
5870 && ecs
->event_thread
->control
.step_resume_breakpoint
== NULL
)
5872 /* We were just starting a new sequence, attempting to
5873 single-step off of a breakpoint and expecting a SIGTRAP.
5874 Instead this signal arrives. This signal will take us out
5875 of the stepping range so GDB needs to remember to, when
5876 the signal handler returns, resume stepping off that
5878 /* To simplify things, "continue" is forced to use the same
5879 code paths as single-step - set a breakpoint at the
5880 signal return address and then, once hit, step off that
5883 fprintf_unfiltered (gdb_stdlog
,
5884 "infrun: signal arrived while stepping over "
5887 insert_hp_step_resume_breakpoint_at_frame (frame
);
5888 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
5889 /* Reset trap_expected to ensure breakpoints are re-inserted. */
5890 ecs
->event_thread
->control
.trap_expected
= 0;
5892 /* If we were nexting/stepping some other thread, switch to
5893 it, so that we don't continue it, losing control. */
5894 if (!switch_back_to_stepped_thread (ecs
))
5899 if (ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
5900 && (pc_in_thread_step_range (ecs
->event_thread
->suspend
.stop_pc
,
5902 || ecs
->event_thread
->control
.step_range_end
== 1)
5903 && frame_id_eq (get_stack_frame_id (frame
),
5904 ecs
->event_thread
->control
.step_stack_frame_id
)
5905 && ecs
->event_thread
->control
.step_resume_breakpoint
== NULL
)
5907 /* The inferior is about to take a signal that will take it
5908 out of the single step range. Set a breakpoint at the
5909 current PC (which is presumably where the signal handler
5910 will eventually return) and then allow the inferior to
5913 Note that this is only needed for a signal delivered
5914 while in the single-step range. Nested signals aren't a
5915 problem as they eventually all return. */
5917 fprintf_unfiltered (gdb_stdlog
,
5918 "infrun: signal may take us out of "
5919 "single-step range\n");
5921 clear_step_over_info ();
5922 insert_hp_step_resume_breakpoint_at_frame (frame
);
5923 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
5924 /* Reset trap_expected to ensure breakpoints are re-inserted. */
5925 ecs
->event_thread
->control
.trap_expected
= 0;
5930 /* Note: step_resume_breakpoint may be non-NULL. This occurs
5931 when either there's a nested signal, or when there's a
5932 pending signal enabled just as the signal handler returns
5933 (leaving the inferior at the step-resume-breakpoint without
5934 actually executing it). Either way continue until the
5935 breakpoint is really hit. */
5937 if (!switch_back_to_stepped_thread (ecs
))
5940 fprintf_unfiltered (gdb_stdlog
,
5941 "infrun: random signal, keep going\n");
5948 process_event_stop_test (ecs
);
5951 /* Come here when we've got some debug event / signal we can explain
5952 (IOW, not a random signal), and test whether it should cause a
5953 stop, or whether we should resume the inferior (transparently).
5954 E.g., could be a breakpoint whose condition evaluates false; we
5955 could be still stepping within the line; etc. */
5958 process_event_stop_test (struct execution_control_state
*ecs
)
5960 struct symtab_and_line stop_pc_sal
;
5961 struct frame_info
*frame
;
5962 struct gdbarch
*gdbarch
;
5963 CORE_ADDR jmp_buf_pc
;
5964 struct bpstat_what what
;
5966 /* Handle cases caused by hitting a breakpoint. */
5968 frame
= get_current_frame ();
5969 gdbarch
= get_frame_arch (frame
);
5971 what
= bpstat_what (ecs
->event_thread
->control
.stop_bpstat
);
5973 if (what
.call_dummy
)
5975 stop_stack_dummy
= what
.call_dummy
;
5978 /* A few breakpoint types have callbacks associated (e.g.,
5979 bp_jit_event). Run them now. */
5980 bpstat_run_callbacks (ecs
->event_thread
->control
.stop_bpstat
);
5982 /* If we hit an internal event that triggers symbol changes, the
5983 current frame will be invalidated within bpstat_what (e.g., if we
5984 hit an internal solib event). Re-fetch it. */
5985 frame
= get_current_frame ();
5986 gdbarch
= get_frame_arch (frame
);
5988 switch (what
.main_action
)
5990 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
5991 /* If we hit the breakpoint at longjmp while stepping, we
5992 install a momentary breakpoint at the target of the
5996 fprintf_unfiltered (gdb_stdlog
,
5997 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
5999 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6001 if (what
.is_longjmp
)
6003 struct value
*arg_value
;
6005 /* If we set the longjmp breakpoint via a SystemTap probe,
6006 then use it to extract the arguments. The destination PC
6007 is the third argument to the probe. */
6008 arg_value
= probe_safe_evaluate_at_pc (frame
, 2);
6011 jmp_buf_pc
= value_as_address (arg_value
);
6012 jmp_buf_pc
= gdbarch_addr_bits_remove (gdbarch
, jmp_buf_pc
);
6014 else if (!gdbarch_get_longjmp_target_p (gdbarch
)
6015 || !gdbarch_get_longjmp_target (gdbarch
,
6016 frame
, &jmp_buf_pc
))
6019 fprintf_unfiltered (gdb_stdlog
,
6020 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME "
6021 "(!gdbarch_get_longjmp_target)\n");
6026 /* Insert a breakpoint at resume address. */
6027 insert_longjmp_resume_breakpoint (gdbarch
, jmp_buf_pc
);
6030 check_exception_resume (ecs
, frame
);
6034 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
6036 struct frame_info
*init_frame
;
6038 /* There are several cases to consider.
6040 1. The initiating frame no longer exists. In this case we
6041 must stop, because the exception or longjmp has gone too
6044 2. The initiating frame exists, and is the same as the
6045 current frame. We stop, because the exception or longjmp
6048 3. The initiating frame exists and is different from the
6049 current frame. This means the exception or longjmp has
6050 been caught beneath the initiating frame, so keep going.
6052 4. longjmp breakpoint has been placed just to protect
6053 against stale dummy frames and user is not interested in
6054 stopping around longjmps. */
6057 fprintf_unfiltered (gdb_stdlog
,
6058 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
6060 gdb_assert (ecs
->event_thread
->control
.exception_resume_breakpoint
6062 delete_exception_resume_breakpoint (ecs
->event_thread
);
6064 if (what
.is_longjmp
)
6066 check_longjmp_breakpoint_for_call_dummy (ecs
->event_thread
);
6068 if (!frame_id_p (ecs
->event_thread
->initiating_frame
))
6076 init_frame
= frame_find_by_id (ecs
->event_thread
->initiating_frame
);
6080 struct frame_id current_id
6081 = get_frame_id (get_current_frame ());
6082 if (frame_id_eq (current_id
,
6083 ecs
->event_thread
->initiating_frame
))
6085 /* Case 2. Fall through. */
6095 /* For Cases 1 and 2, remove the step-resume breakpoint, if it
6097 delete_step_resume_breakpoint (ecs
->event_thread
);
6099 end_stepping_range (ecs
);
6103 case BPSTAT_WHAT_SINGLE
:
6105 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_SINGLE\n");
6106 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6107 /* Still need to check other stuff, at least the case where we
6108 are stepping and step out of the right range. */
6111 case BPSTAT_WHAT_STEP_RESUME
:
6113 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
6115 delete_step_resume_breakpoint (ecs
->event_thread
);
6116 if (ecs
->event_thread
->control
.proceed_to_finish
6117 && execution_direction
== EXEC_REVERSE
)
6119 struct thread_info
*tp
= ecs
->event_thread
;
6121 /* We are finishing a function in reverse, and just hit the
6122 step-resume breakpoint at the start address of the
6123 function, and we're almost there -- just need to back up
6124 by one more single-step, which should take us back to the
6126 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
6130 fill_in_stop_func (gdbarch
, ecs
);
6131 if (ecs
->event_thread
->suspend
.stop_pc
== ecs
->stop_func_start
6132 && execution_direction
== EXEC_REVERSE
)
6134 /* We are stepping over a function call in reverse, and just
6135 hit the step-resume breakpoint at the start address of
6136 the function. Go back to single-stepping, which should
6137 take us back to the function call. */
6138 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6144 case BPSTAT_WHAT_STOP_NOISY
:
6146 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
6147 stop_print_frame
= 1;
6149 /* Assume the thread stopped for a breapoint. We'll still check
6150 whether a/the breakpoint is there when the thread is next
6152 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6157 case BPSTAT_WHAT_STOP_SILENT
:
6159 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
6160 stop_print_frame
= 0;
6162 /* Assume the thread stopped for a breapoint. We'll still check
6163 whether a/the breakpoint is there when the thread is next
6165 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6169 case BPSTAT_WHAT_HP_STEP_RESUME
:
6171 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_HP_STEP_RESUME\n");
6173 delete_step_resume_breakpoint (ecs
->event_thread
);
6174 if (ecs
->event_thread
->step_after_step_resume_breakpoint
)
6176 /* Back when the step-resume breakpoint was inserted, we
6177 were trying to single-step off a breakpoint. Go back to
6179 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
6180 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6186 case BPSTAT_WHAT_KEEP_CHECKING
:
6190 /* If we stepped a permanent breakpoint and we had a high priority
6191 step-resume breakpoint for the address we stepped, but we didn't
6192 hit it, then we must have stepped into the signal handler. The
6193 step-resume was only necessary to catch the case of _not_
6194 stepping into the handler, so delete it, and fall through to
6195 checking whether the step finished. */
6196 if (ecs
->event_thread
->stepped_breakpoint
)
6198 struct breakpoint
*sr_bp
6199 = ecs
->event_thread
->control
.step_resume_breakpoint
;
6202 && sr_bp
->loc
->permanent
6203 && sr_bp
->type
== bp_hp_step_resume
6204 && sr_bp
->loc
->address
== ecs
->event_thread
->prev_pc
)
6207 fprintf_unfiltered (gdb_stdlog
,
6208 "infrun: stepped permanent breakpoint, stopped in "
6210 delete_step_resume_breakpoint (ecs
->event_thread
);
6211 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
6215 /* We come here if we hit a breakpoint but should not stop for it.
6216 Possibly we also were stepping and should stop for that. So fall
6217 through and test for stepping. But, if not stepping, do not
6220 /* In all-stop mode, if we're currently stepping but have stopped in
6221 some other thread, we need to switch back to the stepped thread. */
6222 if (switch_back_to_stepped_thread (ecs
))
6225 if (ecs
->event_thread
->control
.step_resume_breakpoint
)
6228 fprintf_unfiltered (gdb_stdlog
,
6229 "infrun: step-resume breakpoint is inserted\n");
6231 /* Having a step-resume breakpoint overrides anything
6232 else having to do with stepping commands until
6233 that breakpoint is reached. */
6238 if (ecs
->event_thread
->control
.step_range_end
== 0)
6241 fprintf_unfiltered (gdb_stdlog
, "infrun: no stepping, continue\n");
6242 /* Likewise if we aren't even stepping. */
6247 /* Re-fetch current thread's frame in case the code above caused
6248 the frame cache to be re-initialized, making our FRAME variable
6249 a dangling pointer. */
6250 frame
= get_current_frame ();
6251 gdbarch
= get_frame_arch (frame
);
6252 fill_in_stop_func (gdbarch
, ecs
);
6254 /* If stepping through a line, keep going if still within it.
6256 Note that step_range_end is the address of the first instruction
6257 beyond the step range, and NOT the address of the last instruction
6260 Note also that during reverse execution, we may be stepping
6261 through a function epilogue and therefore must detect when
6262 the current-frame changes in the middle of a line. */
6264 if (pc_in_thread_step_range (ecs
->event_thread
->suspend
.stop_pc
,
6266 && (execution_direction
!= EXEC_REVERSE
6267 || frame_id_eq (get_frame_id (frame
),
6268 ecs
->event_thread
->control
.step_frame_id
)))
6272 (gdb_stdlog
, "infrun: stepping inside range [%s-%s]\n",
6273 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_start
),
6274 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_end
));
6276 /* Tentatively re-enable range stepping; `resume' disables it if
6277 necessary (e.g., if we're stepping over a breakpoint or we
6278 have software watchpoints). */
6279 ecs
->event_thread
->control
.may_range_step
= 1;
6281 /* When stepping backward, stop at beginning of line range
6282 (unless it's the function entry point, in which case
6283 keep going back to the call point). */
6284 CORE_ADDR stop_pc
= ecs
->event_thread
->suspend
.stop_pc
;
6285 if (stop_pc
== ecs
->event_thread
->control
.step_range_start
6286 && stop_pc
!= ecs
->stop_func_start
6287 && execution_direction
== EXEC_REVERSE
)
6288 end_stepping_range (ecs
);
6295 /* We stepped out of the stepping range. */
6297 /* If we are stepping at the source level and entered the runtime
6298 loader dynamic symbol resolution code...
6300 EXEC_FORWARD: we keep on single stepping until we exit the run
6301 time loader code and reach the callee's address.
6303 EXEC_REVERSE: we've already executed the callee (backward), and
6304 the runtime loader code is handled just like any other
6305 undebuggable function call. Now we need only keep stepping
6306 backward through the trampoline code, and that's handled further
6307 down, so there is nothing for us to do here. */
6309 if (execution_direction
!= EXEC_REVERSE
6310 && ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
6311 && in_solib_dynsym_resolve_code (ecs
->event_thread
->suspend
.stop_pc
))
6313 CORE_ADDR pc_after_resolver
=
6314 gdbarch_skip_solib_resolver (gdbarch
,
6315 ecs
->event_thread
->suspend
.stop_pc
);
6318 fprintf_unfiltered (gdb_stdlog
,
6319 "infrun: stepped into dynsym resolve code\n");
6321 if (pc_after_resolver
)
6323 /* Set up a step-resume breakpoint at the address
6324 indicated by SKIP_SOLIB_RESOLVER. */
6325 symtab_and_line sr_sal
;
6326 sr_sal
.pc
= pc_after_resolver
;
6327 sr_sal
.pspace
= get_frame_program_space (frame
);
6329 insert_step_resume_breakpoint_at_sal (gdbarch
,
6330 sr_sal
, null_frame_id
);
6337 /* Step through an indirect branch thunk. */
6338 if (ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
6339 && gdbarch_in_indirect_branch_thunk (gdbarch
,
6340 ecs
->event_thread
->suspend
.stop_pc
))
6343 fprintf_unfiltered (gdb_stdlog
,
6344 "infrun: stepped into indirect branch thunk\n");
6349 if (ecs
->event_thread
->control
.step_range_end
!= 1
6350 && (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
6351 || ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
6352 && get_frame_type (frame
) == SIGTRAMP_FRAME
)
6355 fprintf_unfiltered (gdb_stdlog
,
6356 "infrun: stepped into signal trampoline\n");
6357 /* The inferior, while doing a "step" or "next", has ended up in
6358 a signal trampoline (either by a signal being delivered or by
6359 the signal handler returning). Just single-step until the
6360 inferior leaves the trampoline (either by calling the handler
6366 /* If we're in the return path from a shared library trampoline,
6367 we want to proceed through the trampoline when stepping. */
6368 /* macro/2012-04-25: This needs to come before the subroutine
6369 call check below as on some targets return trampolines look
6370 like subroutine calls (MIPS16 return thunks). */
6371 if (gdbarch_in_solib_return_trampoline (gdbarch
,
6372 ecs
->event_thread
->suspend
.stop_pc
,
6373 ecs
->stop_func_name
)
6374 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
6376 /* Determine where this trampoline returns. */
6377 CORE_ADDR stop_pc
= ecs
->event_thread
->suspend
.stop_pc
;
6378 CORE_ADDR real_stop_pc
6379 = gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
6382 fprintf_unfiltered (gdb_stdlog
,
6383 "infrun: stepped into solib return tramp\n");
6385 /* Only proceed through if we know where it's going. */
6388 /* And put the step-breakpoint there and go until there. */
6389 symtab_and_line sr_sal
;
6390 sr_sal
.pc
= real_stop_pc
;
6391 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
6392 sr_sal
.pspace
= get_frame_program_space (frame
);
6394 /* Do not specify what the fp should be when we stop since
6395 on some machines the prologue is where the new fp value
6397 insert_step_resume_breakpoint_at_sal (gdbarch
,
6398 sr_sal
, null_frame_id
);
6400 /* Restart without fiddling with the step ranges or
6407 /* Check for subroutine calls. The check for the current frame
6408 equalling the step ID is not necessary - the check of the
6409 previous frame's ID is sufficient - but it is a common case and
6410 cheaper than checking the previous frame's ID.
6412 NOTE: frame_id_eq will never report two invalid frame IDs as
6413 being equal, so to get into this block, both the current and
6414 previous frame must have valid frame IDs. */
6415 /* The outer_frame_id check is a heuristic to detect stepping
6416 through startup code. If we step over an instruction which
6417 sets the stack pointer from an invalid value to a valid value,
6418 we may detect that as a subroutine call from the mythical
6419 "outermost" function. This could be fixed by marking
6420 outermost frames as !stack_p,code_p,special_p. Then the
6421 initial outermost frame, before sp was valid, would
6422 have code_addr == &_start. See the comment in frame_id_eq
6424 if (!frame_id_eq (get_stack_frame_id (frame
),
6425 ecs
->event_thread
->control
.step_stack_frame_id
)
6426 && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()),
6427 ecs
->event_thread
->control
.step_stack_frame_id
)
6428 && (!frame_id_eq (ecs
->event_thread
->control
.step_stack_frame_id
,
6430 || (ecs
->event_thread
->control
.step_start_function
6431 != find_pc_function (ecs
->event_thread
->suspend
.stop_pc
)))))
6433 CORE_ADDR stop_pc
= ecs
->event_thread
->suspend
.stop_pc
;
6434 CORE_ADDR real_stop_pc
;
6437 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into subroutine\n");
6439 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_NONE
)
6441 /* I presume that step_over_calls is only 0 when we're
6442 supposed to be stepping at the assembly language level
6443 ("stepi"). Just stop. */
6444 /* And this works the same backward as frontward. MVS */
6445 end_stepping_range (ecs
);
6449 /* Reverse stepping through solib trampolines. */
6451 if (execution_direction
== EXEC_REVERSE
6452 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
6453 && (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
6454 || (ecs
->stop_func_start
== 0
6455 && in_solib_dynsym_resolve_code (stop_pc
))))
6457 /* Any solib trampoline code can be handled in reverse
6458 by simply continuing to single-step. We have already
6459 executed the solib function (backwards), and a few
6460 steps will take us back through the trampoline to the
6466 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
6468 /* We're doing a "next".
6470 Normal (forward) execution: set a breakpoint at the
6471 callee's return address (the address at which the caller
6474 Reverse (backward) execution. set the step-resume
6475 breakpoint at the start of the function that we just
6476 stepped into (backwards), and continue to there. When we
6477 get there, we'll need to single-step back to the caller. */
6479 if (execution_direction
== EXEC_REVERSE
)
6481 /* If we're already at the start of the function, we've either
6482 just stepped backward into a single instruction function,
6483 or stepped back out of a signal handler to the first instruction
6484 of the function. Just keep going, which will single-step back
6486 if (ecs
->stop_func_start
!= stop_pc
&& ecs
->stop_func_start
!= 0)
6488 /* Normal function call return (static or dynamic). */
6489 symtab_and_line sr_sal
;
6490 sr_sal
.pc
= ecs
->stop_func_start
;
6491 sr_sal
.pspace
= get_frame_program_space (frame
);
6492 insert_step_resume_breakpoint_at_sal (gdbarch
,
6493 sr_sal
, null_frame_id
);
6497 insert_step_resume_breakpoint_at_caller (frame
);
6503 /* If we are in a function call trampoline (a stub between the
6504 calling routine and the real function), locate the real
6505 function. That's what tells us (a) whether we want to step
6506 into it at all, and (b) what prologue we want to run to the
6507 end of, if we do step into it. */
6508 real_stop_pc
= skip_language_trampoline (frame
, stop_pc
);
6509 if (real_stop_pc
== 0)
6510 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
6511 if (real_stop_pc
!= 0)
6512 ecs
->stop_func_start
= real_stop_pc
;
6514 if (real_stop_pc
!= 0 && in_solib_dynsym_resolve_code (real_stop_pc
))
6516 symtab_and_line sr_sal
;
6517 sr_sal
.pc
= ecs
->stop_func_start
;
6518 sr_sal
.pspace
= get_frame_program_space (frame
);
6520 insert_step_resume_breakpoint_at_sal (gdbarch
,
6521 sr_sal
, null_frame_id
);
6526 /* If we have line number information for the function we are
6527 thinking of stepping into and the function isn't on the skip
6530 If there are several symtabs at that PC (e.g. with include
6531 files), just want to know whether *any* of them have line
6532 numbers. find_pc_line handles this. */
6534 struct symtab_and_line tmp_sal
;
6536 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
6537 if (tmp_sal
.line
!= 0
6538 && !function_name_is_marked_for_skip (ecs
->stop_func_name
,
6541 if (execution_direction
== EXEC_REVERSE
)
6542 handle_step_into_function_backward (gdbarch
, ecs
);
6544 handle_step_into_function (gdbarch
, ecs
);
6549 /* If we have no line number and the step-stop-if-no-debug is
6550 set, we stop the step so that the user has a chance to switch
6551 in assembly mode. */
6552 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
6553 && step_stop_if_no_debug
)
6555 end_stepping_range (ecs
);
6559 if (execution_direction
== EXEC_REVERSE
)
6561 /* If we're already at the start of the function, we've either just
6562 stepped backward into a single instruction function without line
6563 number info, or stepped back out of a signal handler to the first
6564 instruction of the function without line number info. Just keep
6565 going, which will single-step back to the caller. */
6566 if (ecs
->stop_func_start
!= stop_pc
)
6568 /* Set a breakpoint at callee's start address.
6569 From there we can step once and be back in the caller. */
6570 symtab_and_line sr_sal
;
6571 sr_sal
.pc
= ecs
->stop_func_start
;
6572 sr_sal
.pspace
= get_frame_program_space (frame
);
6573 insert_step_resume_breakpoint_at_sal (gdbarch
,
6574 sr_sal
, null_frame_id
);
6578 /* Set a breakpoint at callee's return address (the address
6579 at which the caller will resume). */
6580 insert_step_resume_breakpoint_at_caller (frame
);
6586 /* Reverse stepping through solib trampolines. */
6588 if (execution_direction
== EXEC_REVERSE
6589 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
6591 CORE_ADDR stop_pc
= ecs
->event_thread
->suspend
.stop_pc
;
6593 if (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
6594 || (ecs
->stop_func_start
== 0
6595 && in_solib_dynsym_resolve_code (stop_pc
)))
6597 /* Any solib trampoline code can be handled in reverse
6598 by simply continuing to single-step. We have already
6599 executed the solib function (backwards), and a few
6600 steps will take us back through the trampoline to the
6605 else if (in_solib_dynsym_resolve_code (stop_pc
))
6607 /* Stepped backward into the solib dynsym resolver.
6608 Set a breakpoint at its start and continue, then
6609 one more step will take us out. */
6610 symtab_and_line sr_sal
;
6611 sr_sal
.pc
= ecs
->stop_func_start
;
6612 sr_sal
.pspace
= get_frame_program_space (frame
);
6613 insert_step_resume_breakpoint_at_sal (gdbarch
,
6614 sr_sal
, null_frame_id
);
6620 stop_pc_sal
= find_pc_line (ecs
->event_thread
->suspend
.stop_pc
, 0);
6622 /* NOTE: tausq/2004-05-24: This if block used to be done before all
6623 the trampoline processing logic, however, there are some trampolines
6624 that have no names, so we should do trampoline handling first. */
6625 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
6626 && ecs
->stop_func_name
== NULL
6627 && stop_pc_sal
.line
== 0)
6630 fprintf_unfiltered (gdb_stdlog
,
6631 "infrun: stepped into undebuggable function\n");
6633 /* The inferior just stepped into, or returned to, an
6634 undebuggable function (where there is no debugging information
6635 and no line number corresponding to the address where the
6636 inferior stopped). Since we want to skip this kind of code,
6637 we keep going until the inferior returns from this
6638 function - unless the user has asked us not to (via
6639 set step-mode) or we no longer know how to get back
6640 to the call site. */
6641 if (step_stop_if_no_debug
6642 || !frame_id_p (frame_unwind_caller_id (frame
)))
6644 /* If we have no line number and the step-stop-if-no-debug
6645 is set, we stop the step so that the user has a chance to
6646 switch in assembly mode. */
6647 end_stepping_range (ecs
);
6652 /* Set a breakpoint at callee's return address (the address
6653 at which the caller will resume). */
6654 insert_step_resume_breakpoint_at_caller (frame
);
6660 if (ecs
->event_thread
->control
.step_range_end
== 1)
6662 /* It is stepi or nexti. We always want to stop stepping after
6665 fprintf_unfiltered (gdb_stdlog
, "infrun: stepi/nexti\n");
6666 end_stepping_range (ecs
);
6670 if (stop_pc_sal
.line
== 0)
6672 /* We have no line number information. That means to stop
6673 stepping (does this always happen right after one instruction,
6674 when we do "s" in a function with no line numbers,
6675 or can this happen as a result of a return or longjmp?). */
6677 fprintf_unfiltered (gdb_stdlog
, "infrun: no line number info\n");
6678 end_stepping_range (ecs
);
6682 /* Look for "calls" to inlined functions, part one. If the inline
6683 frame machinery detected some skipped call sites, we have entered
6684 a new inline function. */
6686 if (frame_id_eq (get_frame_id (get_current_frame ()),
6687 ecs
->event_thread
->control
.step_frame_id
)
6688 && inline_skipped_frames (ecs
->event_thread
))
6691 fprintf_unfiltered (gdb_stdlog
,
6692 "infrun: stepped into inlined function\n");
6694 symtab_and_line call_sal
= find_frame_sal (get_current_frame ());
6696 if (ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_ALL
)
6698 /* For "step", we're going to stop. But if the call site
6699 for this inlined function is on the same source line as
6700 we were previously stepping, go down into the function
6701 first. Otherwise stop at the call site. */
6703 if (call_sal
.line
== ecs
->event_thread
->current_line
6704 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
6705 step_into_inline_frame (ecs
->event_thread
);
6707 end_stepping_range (ecs
);
6712 /* For "next", we should stop at the call site if it is on a
6713 different source line. Otherwise continue through the
6714 inlined function. */
6715 if (call_sal
.line
== ecs
->event_thread
->current_line
6716 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
6719 end_stepping_range (ecs
);
6724 /* Look for "calls" to inlined functions, part two. If we are still
6725 in the same real function we were stepping through, but we have
6726 to go further up to find the exact frame ID, we are stepping
6727 through a more inlined call beyond its call site. */
6729 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
6730 && !frame_id_eq (get_frame_id (get_current_frame ()),
6731 ecs
->event_thread
->control
.step_frame_id
)
6732 && stepped_in_from (get_current_frame (),
6733 ecs
->event_thread
->control
.step_frame_id
))
6736 fprintf_unfiltered (gdb_stdlog
,
6737 "infrun: stepping through inlined function\n");
6739 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
6742 end_stepping_range (ecs
);
6746 if ((ecs
->event_thread
->suspend
.stop_pc
== stop_pc_sal
.pc
)
6747 && (ecs
->event_thread
->current_line
!= stop_pc_sal
.line
6748 || ecs
->event_thread
->current_symtab
!= stop_pc_sal
.symtab
))
6750 /* We are at the start of a different line. So stop. Note that
6751 we don't stop if we step into the middle of a different line.
6752 That is said to make things like for (;;) statements work
6755 fprintf_unfiltered (gdb_stdlog
,
6756 "infrun: stepped to a different line\n");
6757 end_stepping_range (ecs
);
6761 /* We aren't done stepping.
6763 Optimize by setting the stepping range to the line.
6764 (We might not be in the original line, but if we entered a
6765 new line in mid-statement, we continue stepping. This makes
6766 things like for(;;) statements work better.) */
6768 ecs
->event_thread
->control
.step_range_start
= stop_pc_sal
.pc
;
6769 ecs
->event_thread
->control
.step_range_end
= stop_pc_sal
.end
;
6770 ecs
->event_thread
->control
.may_range_step
= 1;
6771 set_step_info (frame
, stop_pc_sal
);
6774 fprintf_unfiltered (gdb_stdlog
, "infrun: keep going\n");
6778 /* In all-stop mode, if we're currently stepping but have stopped in
6779 some other thread, we may need to switch back to the stepped
6780 thread. Returns true we set the inferior running, false if we left
6781 it stopped (and the event needs further processing). */
6784 switch_back_to_stepped_thread (struct execution_control_state
*ecs
)
6786 if (!target_is_non_stop_p ())
6788 struct thread_info
*stepping_thread
;
6790 /* If any thread is blocked on some internal breakpoint, and we
6791 simply need to step over that breakpoint to get it going
6792 again, do that first. */
6794 /* However, if we see an event for the stepping thread, then we
6795 know all other threads have been moved past their breakpoints
6796 already. Let the caller check whether the step is finished,
6797 etc., before deciding to move it past a breakpoint. */
6798 if (ecs
->event_thread
->control
.step_range_end
!= 0)
6801 /* Check if the current thread is blocked on an incomplete
6802 step-over, interrupted by a random signal. */
6803 if (ecs
->event_thread
->control
.trap_expected
6804 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_TRAP
)
6808 fprintf_unfiltered (gdb_stdlog
,
6809 "infrun: need to finish step-over of [%s]\n",
6810 target_pid_to_str (ecs
->event_thread
->ptid
).c_str ());
6816 /* Check if the current thread is blocked by a single-step
6817 breakpoint of another thread. */
6818 if (ecs
->hit_singlestep_breakpoint
)
6822 fprintf_unfiltered (gdb_stdlog
,
6823 "infrun: need to step [%s] over single-step "
6825 target_pid_to_str (ecs
->ptid
).c_str ());
6831 /* If this thread needs yet another step-over (e.g., stepping
6832 through a delay slot), do it first before moving on to
6834 if (thread_still_needs_step_over (ecs
->event_thread
))
6838 fprintf_unfiltered (gdb_stdlog
,
6839 "infrun: thread [%s] still needs step-over\n",
6840 target_pid_to_str (ecs
->event_thread
->ptid
).c_str ());
6846 /* If scheduler locking applies even if not stepping, there's no
6847 need to walk over threads. Above we've checked whether the
6848 current thread is stepping. If some other thread not the
6849 event thread is stepping, then it must be that scheduler
6850 locking is not in effect. */
6851 if (schedlock_applies (ecs
->event_thread
))
6854 /* Otherwise, we no longer expect a trap in the current thread.
6855 Clear the trap_expected flag before switching back -- this is
6856 what keep_going does as well, if we call it. */
6857 ecs
->event_thread
->control
.trap_expected
= 0;
6859 /* Likewise, clear the signal if it should not be passed. */
6860 if (!signal_program
[ecs
->event_thread
->suspend
.stop_signal
])
6861 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
6863 /* Do all pending step-overs before actually proceeding with
6865 if (start_step_over ())
6867 prepare_to_wait (ecs
);
6871 /* Look for the stepping/nexting thread. */
6872 stepping_thread
= NULL
;
6874 for (thread_info
*tp
: all_non_exited_threads ())
6876 /* Ignore threads of processes the caller is not
6879 && tp
->ptid
.pid () != ecs
->ptid
.pid ())
6882 /* When stepping over a breakpoint, we lock all threads
6883 except the one that needs to move past the breakpoint.
6884 If a non-event thread has this set, the "incomplete
6885 step-over" check above should have caught it earlier. */
6886 if (tp
->control
.trap_expected
)
6888 internal_error (__FILE__
, __LINE__
,
6889 "[%s] has inconsistent state: "
6890 "trap_expected=%d\n",
6891 target_pid_to_str (tp
->ptid
).c_str (),
6892 tp
->control
.trap_expected
);
6895 /* Did we find the stepping thread? */
6896 if (tp
->control
.step_range_end
)
6898 /* Yep. There should only one though. */
6899 gdb_assert (stepping_thread
== NULL
);
6901 /* The event thread is handled at the top, before we
6903 gdb_assert (tp
!= ecs
->event_thread
);
6905 /* If some thread other than the event thread is
6906 stepping, then scheduler locking can't be in effect,
6907 otherwise we wouldn't have resumed the current event
6908 thread in the first place. */
6909 gdb_assert (!schedlock_applies (tp
));
6911 stepping_thread
= tp
;
6915 if (stepping_thread
!= NULL
)
6918 fprintf_unfiltered (gdb_stdlog
,
6919 "infrun: switching back to stepped thread\n");
6921 if (keep_going_stepped_thread (stepping_thread
))
6923 prepare_to_wait (ecs
);
6932 /* Set a previously stepped thread back to stepping. Returns true on
6933 success, false if the resume is not possible (e.g., the thread
6937 keep_going_stepped_thread (struct thread_info
*tp
)
6939 struct frame_info
*frame
;
6940 struct execution_control_state ecss
;
6941 struct execution_control_state
*ecs
= &ecss
;
6943 /* If the stepping thread exited, then don't try to switch back and
6944 resume it, which could fail in several different ways depending
6945 on the target. Instead, just keep going.
6947 We can find a stepping dead thread in the thread list in two
6950 - The target supports thread exit events, and when the target
6951 tries to delete the thread from the thread list, inferior_ptid
6952 pointed at the exiting thread. In such case, calling
6953 delete_thread does not really remove the thread from the list;
6954 instead, the thread is left listed, with 'exited' state.
6956 - The target's debug interface does not support thread exit
6957 events, and so we have no idea whatsoever if the previously
6958 stepping thread is still alive. For that reason, we need to
6959 synchronously query the target now. */
6961 if (tp
->state
== THREAD_EXITED
|| !target_thread_alive (tp
->ptid
))
6964 fprintf_unfiltered (gdb_stdlog
,
6965 "infrun: not resuming previously "
6966 "stepped thread, it has vanished\n");
6973 fprintf_unfiltered (gdb_stdlog
,
6974 "infrun: resuming previously stepped thread\n");
6976 reset_ecs (ecs
, tp
);
6977 switch_to_thread (tp
);
6979 tp
->suspend
.stop_pc
= regcache_read_pc (get_thread_regcache (tp
));
6980 frame
= get_current_frame ();
6982 /* If the PC of the thread we were trying to single-step has
6983 changed, then that thread has trapped or been signaled, but the
6984 event has not been reported to GDB yet. Re-poll the target
6985 looking for this particular thread's event (i.e. temporarily
6986 enable schedlock) by:
6988 - setting a break at the current PC
6989 - resuming that particular thread, only (by setting trap
6992 This prevents us continuously moving the single-step breakpoint
6993 forward, one instruction at a time, overstepping. */
6995 if (tp
->suspend
.stop_pc
!= tp
->prev_pc
)
7000 fprintf_unfiltered (gdb_stdlog
,
7001 "infrun: expected thread advanced also (%s -> %s)\n",
7002 paddress (target_gdbarch (), tp
->prev_pc
),
7003 paddress (target_gdbarch (), tp
->suspend
.stop_pc
));
7005 /* Clear the info of the previous step-over, as it's no longer
7006 valid (if the thread was trying to step over a breakpoint, it
7007 has already succeeded). It's what keep_going would do too,
7008 if we called it. Do this before trying to insert the sss
7009 breakpoint, otherwise if we were previously trying to step
7010 over this exact address in another thread, the breakpoint is
7012 clear_step_over_info ();
7013 tp
->control
.trap_expected
= 0;
7015 insert_single_step_breakpoint (get_frame_arch (frame
),
7016 get_frame_address_space (frame
),
7017 tp
->suspend
.stop_pc
);
7020 resume_ptid
= internal_resume_ptid (tp
->control
.stepping_command
);
7021 do_target_resume (resume_ptid
, 0, GDB_SIGNAL_0
);
7026 fprintf_unfiltered (gdb_stdlog
,
7027 "infrun: expected thread still hasn't advanced\n");
7029 keep_going_pass_signal (ecs
);
7034 /* Is thread TP in the middle of (software or hardware)
7035 single-stepping? (Note the result of this function must never be
7036 passed directly as target_resume's STEP parameter.) */
7039 currently_stepping (struct thread_info
*tp
)
7041 return ((tp
->control
.step_range_end
7042 && tp
->control
.step_resume_breakpoint
== NULL
)
7043 || tp
->control
.trap_expected
7044 || tp
->stepped_breakpoint
7045 || bpstat_should_step ());
7048 /* Inferior has stepped into a subroutine call with source code that
7049 we should not step over. Do step to the first line of code in
7053 handle_step_into_function (struct gdbarch
*gdbarch
,
7054 struct execution_control_state
*ecs
)
7056 fill_in_stop_func (gdbarch
, ecs
);
7058 compunit_symtab
*cust
7059 = find_pc_compunit_symtab (ecs
->event_thread
->suspend
.stop_pc
);
7060 if (cust
!= NULL
&& compunit_language (cust
) != language_asm
)
7061 ecs
->stop_func_start
7062 = gdbarch_skip_prologue_noexcept (gdbarch
, ecs
->stop_func_start
);
7064 symtab_and_line stop_func_sal
= find_pc_line (ecs
->stop_func_start
, 0);
7065 /* Use the step_resume_break to step until the end of the prologue,
7066 even if that involves jumps (as it seems to on the vax under
7068 /* If the prologue ends in the middle of a source line, continue to
7069 the end of that source line (if it is still within the function).
7070 Otherwise, just go to end of prologue. */
7071 if (stop_func_sal
.end
7072 && stop_func_sal
.pc
!= ecs
->stop_func_start
7073 && stop_func_sal
.end
< ecs
->stop_func_end
)
7074 ecs
->stop_func_start
= stop_func_sal
.end
;
7076 /* Architectures which require breakpoint adjustment might not be able
7077 to place a breakpoint at the computed address. If so, the test
7078 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
7079 ecs->stop_func_start to an address at which a breakpoint may be
7080 legitimately placed.
7082 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
7083 made, GDB will enter an infinite loop when stepping through
7084 optimized code consisting of VLIW instructions which contain
7085 subinstructions corresponding to different source lines. On
7086 FR-V, it's not permitted to place a breakpoint on any but the
7087 first subinstruction of a VLIW instruction. When a breakpoint is
7088 set, GDB will adjust the breakpoint address to the beginning of
7089 the VLIW instruction. Thus, we need to make the corresponding
7090 adjustment here when computing the stop address. */
7092 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
7094 ecs
->stop_func_start
7095 = gdbarch_adjust_breakpoint_address (gdbarch
,
7096 ecs
->stop_func_start
);
7099 if (ecs
->stop_func_start
== ecs
->event_thread
->suspend
.stop_pc
)
7101 /* We are already there: stop now. */
7102 end_stepping_range (ecs
);
7107 /* Put the step-breakpoint there and go until there. */
7108 symtab_and_line sr_sal
;
7109 sr_sal
.pc
= ecs
->stop_func_start
;
7110 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
7111 sr_sal
.pspace
= get_frame_program_space (get_current_frame ());
7113 /* Do not specify what the fp should be when we stop since on
7114 some machines the prologue is where the new fp value is
7116 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
, null_frame_id
);
7118 /* And make sure stepping stops right away then. */
7119 ecs
->event_thread
->control
.step_range_end
7120 = ecs
->event_thread
->control
.step_range_start
;
7125 /* Inferior has stepped backward into a subroutine call with source
7126 code that we should not step over. Do step to the beginning of the
7127 last line of code in it. */
7130 handle_step_into_function_backward (struct gdbarch
*gdbarch
,
7131 struct execution_control_state
*ecs
)
7133 struct compunit_symtab
*cust
;
7134 struct symtab_and_line stop_func_sal
;
7136 fill_in_stop_func (gdbarch
, ecs
);
7138 cust
= find_pc_compunit_symtab (ecs
->event_thread
->suspend
.stop_pc
);
7139 if (cust
!= NULL
&& compunit_language (cust
) != language_asm
)
7140 ecs
->stop_func_start
7141 = gdbarch_skip_prologue_noexcept (gdbarch
, ecs
->stop_func_start
);
7143 stop_func_sal
= find_pc_line (ecs
->event_thread
->suspend
.stop_pc
, 0);
7145 /* OK, we're just going to keep stepping here. */
7146 if (stop_func_sal
.pc
== ecs
->event_thread
->suspend
.stop_pc
)
7148 /* We're there already. Just stop stepping now. */
7149 end_stepping_range (ecs
);
7153 /* Else just reset the step range and keep going.
7154 No step-resume breakpoint, they don't work for
7155 epilogues, which can have multiple entry paths. */
7156 ecs
->event_thread
->control
.step_range_start
= stop_func_sal
.pc
;
7157 ecs
->event_thread
->control
.step_range_end
= stop_func_sal
.end
;
7163 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
7164 This is used to both functions and to skip over code. */
7167 insert_step_resume_breakpoint_at_sal_1 (struct gdbarch
*gdbarch
,
7168 struct symtab_and_line sr_sal
,
7169 struct frame_id sr_id
,
7170 enum bptype sr_type
)
7172 /* There should never be more than one step-resume or longjmp-resume
7173 breakpoint per thread, so we should never be setting a new
7174 step_resume_breakpoint when one is already active. */
7175 gdb_assert (inferior_thread ()->control
.step_resume_breakpoint
== NULL
);
7176 gdb_assert (sr_type
== bp_step_resume
|| sr_type
== bp_hp_step_resume
);
7179 fprintf_unfiltered (gdb_stdlog
,
7180 "infrun: inserting step-resume breakpoint at %s\n",
7181 paddress (gdbarch
, sr_sal
.pc
));
7183 inferior_thread ()->control
.step_resume_breakpoint
7184 = set_momentary_breakpoint (gdbarch
, sr_sal
, sr_id
, sr_type
).release ();
7188 insert_step_resume_breakpoint_at_sal (struct gdbarch
*gdbarch
,
7189 struct symtab_and_line sr_sal
,
7190 struct frame_id sr_id
)
7192 insert_step_resume_breakpoint_at_sal_1 (gdbarch
,
7197 /* Insert a "high-priority step-resume breakpoint" at RETURN_FRAME.pc.
7198 This is used to skip a potential signal handler.
7200 This is called with the interrupted function's frame. The signal
7201 handler, when it returns, will resume the interrupted function at
7205 insert_hp_step_resume_breakpoint_at_frame (struct frame_info
*return_frame
)
7207 gdb_assert (return_frame
!= NULL
);
7209 struct gdbarch
*gdbarch
= get_frame_arch (return_frame
);
7211 symtab_and_line sr_sal
;
7212 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
, get_frame_pc (return_frame
));
7213 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
7214 sr_sal
.pspace
= get_frame_program_space (return_frame
);
7216 insert_step_resume_breakpoint_at_sal_1 (gdbarch
, sr_sal
,
7217 get_stack_frame_id (return_frame
),
7221 /* Insert a "step-resume breakpoint" at the previous frame's PC. This
7222 is used to skip a function after stepping into it (for "next" or if
7223 the called function has no debugging information).
7225 The current function has almost always been reached by single
7226 stepping a call or return instruction. NEXT_FRAME belongs to the
7227 current function, and the breakpoint will be set at the caller's
7230 This is a separate function rather than reusing
7231 insert_hp_step_resume_breakpoint_at_frame in order to avoid
7232 get_prev_frame, which may stop prematurely (see the implementation
7233 of frame_unwind_caller_id for an example). */
7236 insert_step_resume_breakpoint_at_caller (struct frame_info
*next_frame
)
7238 /* We shouldn't have gotten here if we don't know where the call site
7240 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame
)));
7242 struct gdbarch
*gdbarch
= frame_unwind_caller_arch (next_frame
);
7244 symtab_and_line sr_sal
;
7245 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
,
7246 frame_unwind_caller_pc (next_frame
));
7247 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
7248 sr_sal
.pspace
= frame_unwind_program_space (next_frame
);
7250 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
,
7251 frame_unwind_caller_id (next_frame
));
7254 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
7255 new breakpoint at the target of a jmp_buf. The handling of
7256 longjmp-resume uses the same mechanisms used for handling
7257 "step-resume" breakpoints. */
7260 insert_longjmp_resume_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
7262 /* There should never be more than one longjmp-resume breakpoint per
7263 thread, so we should never be setting a new
7264 longjmp_resume_breakpoint when one is already active. */
7265 gdb_assert (inferior_thread ()->control
.exception_resume_breakpoint
== NULL
);
7268 fprintf_unfiltered (gdb_stdlog
,
7269 "infrun: inserting longjmp-resume breakpoint at %s\n",
7270 paddress (gdbarch
, pc
));
7272 inferior_thread ()->control
.exception_resume_breakpoint
=
7273 set_momentary_breakpoint_at_pc (gdbarch
, pc
, bp_longjmp_resume
).release ();
7276 /* Insert an exception resume breakpoint. TP is the thread throwing
7277 the exception. The block B is the block of the unwinder debug hook
7278 function. FRAME is the frame corresponding to the call to this
7279 function. SYM is the symbol of the function argument holding the
7280 target PC of the exception. */
7283 insert_exception_resume_breakpoint (struct thread_info
*tp
,
7284 const struct block
*b
,
7285 struct frame_info
*frame
,
7290 struct block_symbol vsym
;
7291 struct value
*value
;
7293 struct breakpoint
*bp
;
7295 vsym
= lookup_symbol_search_name (sym
->search_name (),
7297 value
= read_var_value (vsym
.symbol
, vsym
.block
, frame
);
7298 /* If the value was optimized out, revert to the old behavior. */
7299 if (! value_optimized_out (value
))
7301 handler
= value_as_address (value
);
7304 fprintf_unfiltered (gdb_stdlog
,
7305 "infrun: exception resume at %lx\n",
7306 (unsigned long) handler
);
7308 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
7310 bp_exception_resume
).release ();
7312 /* set_momentary_breakpoint_at_pc invalidates FRAME. */
7315 bp
->thread
= tp
->global_num
;
7316 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
7319 catch (const gdb_exception_error
&e
)
7321 /* We want to ignore errors here. */
7325 /* A helper for check_exception_resume that sets an
7326 exception-breakpoint based on a SystemTap probe. */
7329 insert_exception_resume_from_probe (struct thread_info
*tp
,
7330 const struct bound_probe
*probe
,
7331 struct frame_info
*frame
)
7333 struct value
*arg_value
;
7335 struct breakpoint
*bp
;
7337 arg_value
= probe_safe_evaluate_at_pc (frame
, 1);
7341 handler
= value_as_address (arg_value
);
7344 fprintf_unfiltered (gdb_stdlog
,
7345 "infrun: exception resume at %s\n",
7346 paddress (get_objfile_arch (probe
->objfile
),
7349 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
7350 handler
, bp_exception_resume
).release ();
7351 bp
->thread
= tp
->global_num
;
7352 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
7355 /* This is called when an exception has been intercepted. Check to
7356 see whether the exception's destination is of interest, and if so,
7357 set an exception resume breakpoint there. */
7360 check_exception_resume (struct execution_control_state
*ecs
,
7361 struct frame_info
*frame
)
7363 struct bound_probe probe
;
7364 struct symbol
*func
;
7366 /* First see if this exception unwinding breakpoint was set via a
7367 SystemTap probe point. If so, the probe has two arguments: the
7368 CFA and the HANDLER. We ignore the CFA, extract the handler, and
7369 set a breakpoint there. */
7370 probe
= find_probe_by_pc (get_frame_pc (frame
));
7373 insert_exception_resume_from_probe (ecs
->event_thread
, &probe
, frame
);
7377 func
= get_frame_function (frame
);
7383 const struct block
*b
;
7384 struct block_iterator iter
;
7388 /* The exception breakpoint is a thread-specific breakpoint on
7389 the unwinder's debug hook, declared as:
7391 void _Unwind_DebugHook (void *cfa, void *handler);
7393 The CFA argument indicates the frame to which control is
7394 about to be transferred. HANDLER is the destination PC.
7396 We ignore the CFA and set a temporary breakpoint at HANDLER.
7397 This is not extremely efficient but it avoids issues in gdb
7398 with computing the DWARF CFA, and it also works even in weird
7399 cases such as throwing an exception from inside a signal
7402 b
= SYMBOL_BLOCK_VALUE (func
);
7403 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
7405 if (!SYMBOL_IS_ARGUMENT (sym
))
7412 insert_exception_resume_breakpoint (ecs
->event_thread
,
7418 catch (const gdb_exception_error
&e
)
7424 stop_waiting (struct execution_control_state
*ecs
)
7427 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_waiting\n");
7429 /* Let callers know we don't want to wait for the inferior anymore. */
7430 ecs
->wait_some_more
= 0;
7432 /* If all-stop, but the target is always in non-stop mode, stop all
7433 threads now that we're presenting the stop to the user. */
7434 if (!non_stop
&& target_is_non_stop_p ())
7435 stop_all_threads ();
7438 /* Like keep_going, but passes the signal to the inferior, even if the
7439 signal is set to nopass. */
7442 keep_going_pass_signal (struct execution_control_state
*ecs
)
7444 gdb_assert (ecs
->event_thread
->ptid
== inferior_ptid
);
7445 gdb_assert (!ecs
->event_thread
->resumed
);
7447 /* Save the pc before execution, to compare with pc after stop. */
7448 ecs
->event_thread
->prev_pc
7449 = regcache_read_pc (get_thread_regcache (ecs
->event_thread
));
7451 if (ecs
->event_thread
->control
.trap_expected
)
7453 struct thread_info
*tp
= ecs
->event_thread
;
7456 fprintf_unfiltered (gdb_stdlog
,
7457 "infrun: %s has trap_expected set, "
7458 "resuming to collect trap\n",
7459 target_pid_to_str (tp
->ptid
).c_str ());
7461 /* We haven't yet gotten our trap, and either: intercepted a
7462 non-signal event (e.g., a fork); or took a signal which we
7463 are supposed to pass through to the inferior. Simply
7465 resume (ecs
->event_thread
->suspend
.stop_signal
);
7467 else if (step_over_info_valid_p ())
7469 /* Another thread is stepping over a breakpoint in-line. If
7470 this thread needs a step-over too, queue the request. In
7471 either case, this resume must be deferred for later. */
7472 struct thread_info
*tp
= ecs
->event_thread
;
7474 if (ecs
->hit_singlestep_breakpoint
7475 || thread_still_needs_step_over (tp
))
7478 fprintf_unfiltered (gdb_stdlog
,
7479 "infrun: step-over already in progress: "
7480 "step-over for %s deferred\n",
7481 target_pid_to_str (tp
->ptid
).c_str ());
7482 global_thread_step_over_chain_enqueue (tp
);
7487 fprintf_unfiltered (gdb_stdlog
,
7488 "infrun: step-over in progress: "
7489 "resume of %s deferred\n",
7490 target_pid_to_str (tp
->ptid
).c_str ());
7495 struct regcache
*regcache
= get_current_regcache ();
7498 step_over_what step_what
;
7500 /* Either the trap was not expected, but we are continuing
7501 anyway (if we got a signal, the user asked it be passed to
7504 We got our expected trap, but decided we should resume from
7507 We're going to run this baby now!
7509 Note that insert_breakpoints won't try to re-insert
7510 already inserted breakpoints. Therefore, we don't
7511 care if breakpoints were already inserted, or not. */
7513 /* If we need to step over a breakpoint, and we're not using
7514 displaced stepping to do so, insert all breakpoints
7515 (watchpoints, etc.) but the one we're stepping over, step one
7516 instruction, and then re-insert the breakpoint when that step
7519 step_what
= thread_still_needs_step_over (ecs
->event_thread
);
7521 remove_bp
= (ecs
->hit_singlestep_breakpoint
7522 || (step_what
& STEP_OVER_BREAKPOINT
));
7523 remove_wps
= (step_what
& STEP_OVER_WATCHPOINT
);
7525 /* We can't use displaced stepping if we need to step past a
7526 watchpoint. The instruction copied to the scratch pad would
7527 still trigger the watchpoint. */
7529 && (remove_wps
|| !use_displaced_stepping (ecs
->event_thread
)))
7531 set_step_over_info (regcache
->aspace (),
7532 regcache_read_pc (regcache
), remove_wps
,
7533 ecs
->event_thread
->global_num
);
7535 else if (remove_wps
)
7536 set_step_over_info (NULL
, 0, remove_wps
, -1);
7538 /* If we now need to do an in-line step-over, we need to stop
7539 all other threads. Note this must be done before
7540 insert_breakpoints below, because that removes the breakpoint
7541 we're about to step over, otherwise other threads could miss
7543 if (step_over_info_valid_p () && target_is_non_stop_p ())
7544 stop_all_threads ();
7546 /* Stop stepping if inserting breakpoints fails. */
7549 insert_breakpoints ();
7551 catch (const gdb_exception_error
&e
)
7553 exception_print (gdb_stderr
, e
);
7555 clear_step_over_info ();
7559 ecs
->event_thread
->control
.trap_expected
= (remove_bp
|| remove_wps
);
7561 resume (ecs
->event_thread
->suspend
.stop_signal
);
7564 prepare_to_wait (ecs
);
7567 /* Called when we should continue running the inferior, because the
7568 current event doesn't cause a user visible stop. This does the
7569 resuming part; waiting for the next event is done elsewhere. */
7572 keep_going (struct execution_control_state
*ecs
)
7574 if (ecs
->event_thread
->control
.trap_expected
7575 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
7576 ecs
->event_thread
->control
.trap_expected
= 0;
7578 if (!signal_program
[ecs
->event_thread
->suspend
.stop_signal
])
7579 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
7580 keep_going_pass_signal (ecs
);
7583 /* This function normally comes after a resume, before
7584 handle_inferior_event exits. It takes care of any last bits of
7585 housekeeping, and sets the all-important wait_some_more flag. */
7588 prepare_to_wait (struct execution_control_state
*ecs
)
7591 fprintf_unfiltered (gdb_stdlog
, "infrun: prepare_to_wait\n");
7593 ecs
->wait_some_more
= 1;
7595 if (!target_is_async_p ())
7596 mark_infrun_async_event_handler ();
7599 /* We are done with the step range of a step/next/si/ni command.
7600 Called once for each n of a "step n" operation. */
7603 end_stepping_range (struct execution_control_state
*ecs
)
7605 ecs
->event_thread
->control
.stop_step
= 1;
7609 /* Several print_*_reason functions to print why the inferior has stopped.
7610 We always print something when the inferior exits, or receives a signal.
7611 The rest of the cases are dealt with later on in normal_stop and
7612 print_it_typical. Ideally there should be a call to one of these
7613 print_*_reason functions functions from handle_inferior_event each time
7614 stop_waiting is called.
7616 Note that we don't call these directly, instead we delegate that to
7617 the interpreters, through observers. Interpreters then call these
7618 with whatever uiout is right. */
7621 print_end_stepping_range_reason (struct ui_out
*uiout
)
7623 /* For CLI-like interpreters, print nothing. */
7625 if (uiout
->is_mi_like_p ())
7627 uiout
->field_string ("reason",
7628 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE
));
7633 print_signal_exited_reason (struct ui_out
*uiout
, enum gdb_signal siggnal
)
7635 annotate_signalled ();
7636 if (uiout
->is_mi_like_p ())
7638 ("reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED
));
7639 uiout
->text ("\nProgram terminated with signal ");
7640 annotate_signal_name ();
7641 uiout
->field_string ("signal-name",
7642 gdb_signal_to_name (siggnal
));
7643 annotate_signal_name_end ();
7645 annotate_signal_string ();
7646 uiout
->field_string ("signal-meaning",
7647 gdb_signal_to_string (siggnal
));
7648 annotate_signal_string_end ();
7649 uiout
->text (".\n");
7650 uiout
->text ("The program no longer exists.\n");
7654 print_exited_reason (struct ui_out
*uiout
, int exitstatus
)
7656 struct inferior
*inf
= current_inferior ();
7657 std::string pidstr
= target_pid_to_str (ptid_t (inf
->pid
));
7659 annotate_exited (exitstatus
);
7662 if (uiout
->is_mi_like_p ())
7663 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXITED
));
7664 std::string exit_code_str
7665 = string_printf ("0%o", (unsigned int) exitstatus
);
7666 uiout
->message ("[Inferior %s (%s) exited with code %pF]\n",
7667 plongest (inf
->num
), pidstr
.c_str (),
7668 string_field ("exit-code", exit_code_str
.c_str ()));
7672 if (uiout
->is_mi_like_p ())
7674 ("reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY
));
7675 uiout
->message ("[Inferior %s (%s) exited normally]\n",
7676 plongest (inf
->num
), pidstr
.c_str ());
7680 /* Some targets/architectures can do extra processing/display of
7681 segmentation faults. E.g., Intel MPX boundary faults.
7682 Call the architecture dependent function to handle the fault. */
7685 handle_segmentation_fault (struct ui_out
*uiout
)
7687 struct regcache
*regcache
= get_current_regcache ();
7688 struct gdbarch
*gdbarch
= regcache
->arch ();
7690 if (gdbarch_handle_segmentation_fault_p (gdbarch
))
7691 gdbarch_handle_segmentation_fault (gdbarch
, uiout
);
7695 print_signal_received_reason (struct ui_out
*uiout
, enum gdb_signal siggnal
)
7697 struct thread_info
*thr
= inferior_thread ();
7701 if (uiout
->is_mi_like_p ())
7703 else if (show_thread_that_caused_stop ())
7707 uiout
->text ("\nThread ");
7708 uiout
->field_string ("thread-id", print_thread_id (thr
));
7710 name
= thr
->name
!= NULL
? thr
->name
: target_thread_name (thr
);
7713 uiout
->text (" \"");
7714 uiout
->field_string ("name", name
);
7719 uiout
->text ("\nProgram");
7721 if (siggnal
== GDB_SIGNAL_0
&& !uiout
->is_mi_like_p ())
7722 uiout
->text (" stopped");
7725 uiout
->text (" received signal ");
7726 annotate_signal_name ();
7727 if (uiout
->is_mi_like_p ())
7729 ("reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED
));
7730 uiout
->field_string ("signal-name", gdb_signal_to_name (siggnal
));
7731 annotate_signal_name_end ();
7733 annotate_signal_string ();
7734 uiout
->field_string ("signal-meaning", gdb_signal_to_string (siggnal
));
7736 if (siggnal
== GDB_SIGNAL_SEGV
)
7737 handle_segmentation_fault (uiout
);
7739 annotate_signal_string_end ();
7741 uiout
->text (".\n");
7745 print_no_history_reason (struct ui_out
*uiout
)
7747 uiout
->text ("\nNo more reverse-execution history.\n");
7750 /* Print current location without a level number, if we have changed
7751 functions or hit a breakpoint. Print source line if we have one.
7752 bpstat_print contains the logic deciding in detail what to print,
7753 based on the event(s) that just occurred. */
7756 print_stop_location (struct target_waitstatus
*ws
)
7759 enum print_what source_flag
;
7760 int do_frame_printing
= 1;
7761 struct thread_info
*tp
= inferior_thread ();
7763 bpstat_ret
= bpstat_print (tp
->control
.stop_bpstat
, ws
->kind
);
7767 /* FIXME: cagney/2002-12-01: Given that a frame ID does (or
7768 should) carry around the function and does (or should) use
7769 that when doing a frame comparison. */
7770 if (tp
->control
.stop_step
7771 && frame_id_eq (tp
->control
.step_frame_id
,
7772 get_frame_id (get_current_frame ()))
7773 && (tp
->control
.step_start_function
7774 == find_pc_function (tp
->suspend
.stop_pc
)))
7776 /* Finished step, just print source line. */
7777 source_flag
= SRC_LINE
;
7781 /* Print location and source line. */
7782 source_flag
= SRC_AND_LOC
;
7785 case PRINT_SRC_AND_LOC
:
7786 /* Print location and source line. */
7787 source_flag
= SRC_AND_LOC
;
7789 case PRINT_SRC_ONLY
:
7790 source_flag
= SRC_LINE
;
7793 /* Something bogus. */
7794 source_flag
= SRC_LINE
;
7795 do_frame_printing
= 0;
7798 internal_error (__FILE__
, __LINE__
, _("Unknown value."));
7801 /* The behavior of this routine with respect to the source
7803 SRC_LINE: Print only source line
7804 LOCATION: Print only location
7805 SRC_AND_LOC: Print location and source line. */
7806 if (do_frame_printing
)
7807 print_stack_frame (get_selected_frame (NULL
), 0, source_flag
, 1);
7813 print_stop_event (struct ui_out
*uiout
, bool displays
)
7815 struct target_waitstatus last
;
7817 struct thread_info
*tp
;
7819 get_last_target_status (&last_ptid
, &last
);
7822 scoped_restore save_uiout
= make_scoped_restore (¤t_uiout
, uiout
);
7824 print_stop_location (&last
);
7826 /* Display the auto-display expressions. */
7831 tp
= inferior_thread ();
7832 if (tp
->thread_fsm
!= NULL
7833 && tp
->thread_fsm
->finished_p ())
7835 struct return_value_info
*rv
;
7837 rv
= tp
->thread_fsm
->return_value ();
7839 print_return_value (uiout
, rv
);
7846 maybe_remove_breakpoints (void)
7848 if (!breakpoints_should_be_inserted_now () && target_has_execution
)
7850 if (remove_breakpoints ())
7852 target_terminal::ours_for_output ();
7853 printf_filtered (_("Cannot remove breakpoints because "
7854 "program is no longer writable.\nFurther "
7855 "execution is probably impossible.\n"));
7860 /* The execution context that just caused a normal stop. */
7867 DISABLE_COPY_AND_ASSIGN (stop_context
);
7869 bool changed () const;
7874 /* The event PTID. */
7878 /* If stopp for a thread event, this is the thread that caused the
7880 struct thread_info
*thread
;
7882 /* The inferior that caused the stop. */
7886 /* Initializes a new stop context. If stopped for a thread event, this
7887 takes a strong reference to the thread. */
7889 stop_context::stop_context ()
7891 stop_id
= get_stop_id ();
7892 ptid
= inferior_ptid
;
7893 inf_num
= current_inferior ()->num
;
7895 if (inferior_ptid
!= null_ptid
)
7897 /* Take a strong reference so that the thread can't be deleted
7899 thread
= inferior_thread ();
7906 /* Release a stop context previously created with save_stop_context.
7907 Releases the strong reference to the thread as well. */
7909 stop_context::~stop_context ()
7915 /* Return true if the current context no longer matches the saved stop
7919 stop_context::changed () const
7921 if (ptid
!= inferior_ptid
)
7923 if (inf_num
!= current_inferior ()->num
)
7925 if (thread
!= NULL
&& thread
->state
!= THREAD_STOPPED
)
7927 if (get_stop_id () != stop_id
)
7937 struct target_waitstatus last
;
7940 get_last_target_status (&last_ptid
, &last
);
7944 /* If an exception is thrown from this point on, make sure to
7945 propagate GDB's knowledge of the executing state to the
7946 frontend/user running state. A QUIT is an easy exception to see
7947 here, so do this before any filtered output. */
7949 gdb::optional
<scoped_finish_thread_state
> maybe_finish_thread_state
;
7952 maybe_finish_thread_state
.emplace (minus_one_ptid
);
7953 else if (last
.kind
== TARGET_WAITKIND_SIGNALLED
7954 || last
.kind
== TARGET_WAITKIND_EXITED
)
7956 /* On some targets, we may still have live threads in the
7957 inferior when we get a process exit event. E.g., for
7958 "checkpoint", when the current checkpoint/fork exits,
7959 linux-fork.c automatically switches to another fork from
7960 within target_mourn_inferior. */
7961 if (inferior_ptid
!= null_ptid
)
7962 maybe_finish_thread_state
.emplace (ptid_t (inferior_ptid
.pid ()));
7964 else if (last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
7965 maybe_finish_thread_state
.emplace (inferior_ptid
);
7967 /* As we're presenting a stop, and potentially removing breakpoints,
7968 update the thread list so we can tell whether there are threads
7969 running on the target. With target remote, for example, we can
7970 only learn about new threads when we explicitly update the thread
7971 list. Do this before notifying the interpreters about signal
7972 stops, end of stepping ranges, etc., so that the "new thread"
7973 output is emitted before e.g., "Program received signal FOO",
7974 instead of after. */
7975 update_thread_list ();
7977 if (last
.kind
== TARGET_WAITKIND_STOPPED
&& stopped_by_random_signal
)
7978 gdb::observers::signal_received
.notify (inferior_thread ()->suspend
.stop_signal
);
7980 /* As with the notification of thread events, we want to delay
7981 notifying the user that we've switched thread context until
7982 the inferior actually stops.
7984 There's no point in saying anything if the inferior has exited.
7985 Note that SIGNALLED here means "exited with a signal", not
7986 "received a signal".
7988 Also skip saying anything in non-stop mode. In that mode, as we
7989 don't want GDB to switch threads behind the user's back, to avoid
7990 races where the user is typing a command to apply to thread x,
7991 but GDB switches to thread y before the user finishes entering
7992 the command, fetch_inferior_event installs a cleanup to restore
7993 the current thread back to the thread the user had selected right
7994 after this event is handled, so we're not really switching, only
7995 informing of a stop. */
7997 && previous_inferior_ptid
!= inferior_ptid
7998 && target_has_execution
7999 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
8000 && last
.kind
!= TARGET_WAITKIND_EXITED
8001 && last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
8003 SWITCH_THRU_ALL_UIS ()
8005 target_terminal::ours_for_output ();
8006 printf_filtered (_("[Switching to %s]\n"),
8007 target_pid_to_str (inferior_ptid
).c_str ());
8008 annotate_thread_changed ();
8010 previous_inferior_ptid
= inferior_ptid
;
8013 if (last
.kind
== TARGET_WAITKIND_NO_RESUMED
)
8015 SWITCH_THRU_ALL_UIS ()
8016 if (current_ui
->prompt_state
== PROMPT_BLOCKED
)
8018 target_terminal::ours_for_output ();
8019 printf_filtered (_("No unwaited-for children left.\n"));
8023 /* Note: this depends on the update_thread_list call above. */
8024 maybe_remove_breakpoints ();
8026 /* If an auto-display called a function and that got a signal,
8027 delete that auto-display to avoid an infinite recursion. */
8029 if (stopped_by_random_signal
)
8030 disable_current_display ();
8032 SWITCH_THRU_ALL_UIS ()
8034 async_enable_stdin ();
8037 /* Let the user/frontend see the threads as stopped. */
8038 maybe_finish_thread_state
.reset ();
8040 /* Select innermost stack frame - i.e., current frame is frame 0,
8041 and current location is based on that. Handle the case where the
8042 dummy call is returning after being stopped. E.g. the dummy call
8043 previously hit a breakpoint. (If the dummy call returns
8044 normally, we won't reach here.) Do this before the stop hook is
8045 run, so that it doesn't get to see the temporary dummy frame,
8046 which is not where we'll present the stop. */
8047 if (has_stack_frames ())
8049 if (stop_stack_dummy
== STOP_STACK_DUMMY
)
8051 /* Pop the empty frame that contains the stack dummy. This
8052 also restores inferior state prior to the call (struct
8053 infcall_suspend_state). */
8054 struct frame_info
*frame
= get_current_frame ();
8056 gdb_assert (get_frame_type (frame
) == DUMMY_FRAME
);
8058 /* frame_pop calls reinit_frame_cache as the last thing it
8059 does which means there's now no selected frame. */
8062 select_frame (get_current_frame ());
8064 /* Set the current source location. */
8065 set_current_sal_from_frame (get_current_frame ());
8068 /* Look up the hook_stop and run it (CLI internally handles problem
8069 of stop_command's pre-hook not existing). */
8070 if (stop_command
!= NULL
)
8072 stop_context saved_context
;
8076 execute_cmd_pre_hook (stop_command
);
8078 catch (const gdb_exception
&ex
)
8080 exception_fprintf (gdb_stderr
, ex
,
8081 "Error while running hook_stop:\n");
8084 /* If the stop hook resumes the target, then there's no point in
8085 trying to notify about the previous stop; its context is
8086 gone. Likewise if the command switches thread or inferior --
8087 the observers would print a stop for the wrong
8089 if (saved_context
.changed ())
8093 /* Notify observers about the stop. This is where the interpreters
8094 print the stop event. */
8095 if (inferior_ptid
!= null_ptid
)
8096 gdb::observers::normal_stop
.notify (inferior_thread ()->control
.stop_bpstat
,
8099 gdb::observers::normal_stop
.notify (NULL
, stop_print_frame
);
8101 annotate_stopped ();
8103 if (target_has_execution
)
8105 if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
8106 && last
.kind
!= TARGET_WAITKIND_EXITED
8107 && last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
8108 /* Delete the breakpoint we stopped at, if it wants to be deleted.
8109 Delete any breakpoint that is to be deleted at the next stop. */
8110 breakpoint_auto_delete (inferior_thread ()->control
.stop_bpstat
);
8113 /* Try to get rid of automatically added inferiors that are no
8114 longer needed. Keeping those around slows down things linearly.
8115 Note that this never removes the current inferior. */
8122 signal_stop_state (int signo
)
8124 return signal_stop
[signo
];
8128 signal_print_state (int signo
)
8130 return signal_print
[signo
];
8134 signal_pass_state (int signo
)
8136 return signal_program
[signo
];
8140 signal_cache_update (int signo
)
8144 for (signo
= 0; signo
< (int) GDB_SIGNAL_LAST
; signo
++)
8145 signal_cache_update (signo
);
8150 signal_pass
[signo
] = (signal_stop
[signo
] == 0
8151 && signal_print
[signo
] == 0
8152 && signal_program
[signo
] == 1
8153 && signal_catch
[signo
] == 0);
8157 signal_stop_update (int signo
, int state
)
8159 int ret
= signal_stop
[signo
];
8161 signal_stop
[signo
] = state
;
8162 signal_cache_update (signo
);
8167 signal_print_update (int signo
, int state
)
8169 int ret
= signal_print
[signo
];
8171 signal_print
[signo
] = state
;
8172 signal_cache_update (signo
);
8177 signal_pass_update (int signo
, int state
)
8179 int ret
= signal_program
[signo
];
8181 signal_program
[signo
] = state
;
8182 signal_cache_update (signo
);
8186 /* Update the global 'signal_catch' from INFO and notify the
8190 signal_catch_update (const unsigned int *info
)
8194 for (i
= 0; i
< GDB_SIGNAL_LAST
; ++i
)
8195 signal_catch
[i
] = info
[i
] > 0;
8196 signal_cache_update (-1);
8197 target_pass_signals (signal_pass
);
8201 sig_print_header (void)
8203 printf_filtered (_("Signal Stop\tPrint\tPass "
8204 "to program\tDescription\n"));
8208 sig_print_info (enum gdb_signal oursig
)
8210 const char *name
= gdb_signal_to_name (oursig
);
8211 int name_padding
= 13 - strlen (name
);
8213 if (name_padding
<= 0)
8216 printf_filtered ("%s", name
);
8217 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
8218 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
8219 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
8220 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
8221 printf_filtered ("%s\n", gdb_signal_to_string (oursig
));
8224 /* Specify how various signals in the inferior should be handled. */
8227 handle_command (const char *args
, int from_tty
)
8229 int digits
, wordlen
;
8230 int sigfirst
, siglast
;
8231 enum gdb_signal oursig
;
8236 error_no_arg (_("signal to handle"));
8239 /* Allocate and zero an array of flags for which signals to handle. */
8241 const size_t nsigs
= GDB_SIGNAL_LAST
;
8242 unsigned char sigs
[nsigs
] {};
8244 /* Break the command line up into args. */
8246 gdb_argv
built_argv (args
);
8248 /* Walk through the args, looking for signal oursigs, signal names, and
8249 actions. Signal numbers and signal names may be interspersed with
8250 actions, with the actions being performed for all signals cumulatively
8251 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
8253 for (char *arg
: built_argv
)
8255 wordlen
= strlen (arg
);
8256 for (digits
= 0; isdigit (arg
[digits
]); digits
++)
8260 sigfirst
= siglast
= -1;
8262 if (wordlen
>= 1 && !strncmp (arg
, "all", wordlen
))
8264 /* Apply action to all signals except those used by the
8265 debugger. Silently skip those. */
8268 siglast
= nsigs
- 1;
8270 else if (wordlen
>= 1 && !strncmp (arg
, "stop", wordlen
))
8272 SET_SIGS (nsigs
, sigs
, signal_stop
);
8273 SET_SIGS (nsigs
, sigs
, signal_print
);
8275 else if (wordlen
>= 1 && !strncmp (arg
, "ignore", wordlen
))
8277 UNSET_SIGS (nsigs
, sigs
, signal_program
);
8279 else if (wordlen
>= 2 && !strncmp (arg
, "print", wordlen
))
8281 SET_SIGS (nsigs
, sigs
, signal_print
);
8283 else if (wordlen
>= 2 && !strncmp (arg
, "pass", wordlen
))
8285 SET_SIGS (nsigs
, sigs
, signal_program
);
8287 else if (wordlen
>= 3 && !strncmp (arg
, "nostop", wordlen
))
8289 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
8291 else if (wordlen
>= 3 && !strncmp (arg
, "noignore", wordlen
))
8293 SET_SIGS (nsigs
, sigs
, signal_program
);
8295 else if (wordlen
>= 4 && !strncmp (arg
, "noprint", wordlen
))
8297 UNSET_SIGS (nsigs
, sigs
, signal_print
);
8298 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
8300 else if (wordlen
>= 4 && !strncmp (arg
, "nopass", wordlen
))
8302 UNSET_SIGS (nsigs
, sigs
, signal_program
);
8304 else if (digits
> 0)
8306 /* It is numeric. The numeric signal refers to our own
8307 internal signal numbering from target.h, not to host/target
8308 signal number. This is a feature; users really should be
8309 using symbolic names anyway, and the common ones like
8310 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
8312 sigfirst
= siglast
= (int)
8313 gdb_signal_from_command (atoi (arg
));
8314 if (arg
[digits
] == '-')
8317 gdb_signal_from_command (atoi (arg
+ digits
+ 1));
8319 if (sigfirst
> siglast
)
8321 /* Bet he didn't figure we'd think of this case... */
8322 std::swap (sigfirst
, siglast
);
8327 oursig
= gdb_signal_from_name (arg
);
8328 if (oursig
!= GDB_SIGNAL_UNKNOWN
)
8330 sigfirst
= siglast
= (int) oursig
;
8334 /* Not a number and not a recognized flag word => complain. */
8335 error (_("Unrecognized or ambiguous flag word: \"%s\"."), arg
);
8339 /* If any signal numbers or symbol names were found, set flags for
8340 which signals to apply actions to. */
8342 for (int signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
8344 switch ((enum gdb_signal
) signum
)
8346 case GDB_SIGNAL_TRAP
:
8347 case GDB_SIGNAL_INT
:
8348 if (!allsigs
&& !sigs
[signum
])
8350 if (query (_("%s is used by the debugger.\n\
8351 Are you sure you want to change it? "),
8352 gdb_signal_to_name ((enum gdb_signal
) signum
)))
8357 printf_unfiltered (_("Not confirmed, unchanged.\n"));
8361 case GDB_SIGNAL_DEFAULT
:
8362 case GDB_SIGNAL_UNKNOWN
:
8363 /* Make sure that "all" doesn't print these. */
8372 for (int signum
= 0; signum
< nsigs
; signum
++)
8375 signal_cache_update (-1);
8376 target_pass_signals (signal_pass
);
8377 target_program_signals (signal_program
);
8381 /* Show the results. */
8382 sig_print_header ();
8383 for (; signum
< nsigs
; signum
++)
8385 sig_print_info ((enum gdb_signal
) signum
);
8392 /* Complete the "handle" command. */
8395 handle_completer (struct cmd_list_element
*ignore
,
8396 completion_tracker
&tracker
,
8397 const char *text
, const char *word
)
8399 static const char * const keywords
[] =
8413 signal_completer (ignore
, tracker
, text
, word
);
8414 complete_on_enum (tracker
, keywords
, word
, word
);
8418 gdb_signal_from_command (int num
)
8420 if (num
>= 1 && num
<= 15)
8421 return (enum gdb_signal
) num
;
8422 error (_("Only signals 1-15 are valid as numeric signals.\n\
8423 Use \"info signals\" for a list of symbolic signals."));
8426 /* Print current contents of the tables set by the handle command.
8427 It is possible we should just be printing signals actually used
8428 by the current target (but for things to work right when switching
8429 targets, all signals should be in the signal tables). */
8432 info_signals_command (const char *signum_exp
, int from_tty
)
8434 enum gdb_signal oursig
;
8436 sig_print_header ();
8440 /* First see if this is a symbol name. */
8441 oursig
= gdb_signal_from_name (signum_exp
);
8442 if (oursig
== GDB_SIGNAL_UNKNOWN
)
8444 /* No, try numeric. */
8446 gdb_signal_from_command (parse_and_eval_long (signum_exp
));
8448 sig_print_info (oursig
);
8452 printf_filtered ("\n");
8453 /* These ugly casts brought to you by the native VAX compiler. */
8454 for (oursig
= GDB_SIGNAL_FIRST
;
8455 (int) oursig
< (int) GDB_SIGNAL_LAST
;
8456 oursig
= (enum gdb_signal
) ((int) oursig
+ 1))
8460 if (oursig
!= GDB_SIGNAL_UNKNOWN
8461 && oursig
!= GDB_SIGNAL_DEFAULT
&& oursig
!= GDB_SIGNAL_0
)
8462 sig_print_info (oursig
);
8465 printf_filtered (_("\nUse the \"handle\" command "
8466 "to change these tables.\n"));
8469 /* The $_siginfo convenience variable is a bit special. We don't know
8470 for sure the type of the value until we actually have a chance to
8471 fetch the data. The type can change depending on gdbarch, so it is
8472 also dependent on which thread you have selected.
8474 1. making $_siginfo be an internalvar that creates a new value on
8477 2. making the value of $_siginfo be an lval_computed value. */
8479 /* This function implements the lval_computed support for reading a
8483 siginfo_value_read (struct value
*v
)
8485 LONGEST transferred
;
8487 /* If we can access registers, so can we access $_siginfo. Likewise
8489 validate_registers_access ();
8492 target_read (current_top_target (), TARGET_OBJECT_SIGNAL_INFO
,
8494 value_contents_all_raw (v
),
8496 TYPE_LENGTH (value_type (v
)));
8498 if (transferred
!= TYPE_LENGTH (value_type (v
)))
8499 error (_("Unable to read siginfo"));
8502 /* This function implements the lval_computed support for writing a
8506 siginfo_value_write (struct value
*v
, struct value
*fromval
)
8508 LONGEST transferred
;
8510 /* If we can access registers, so can we access $_siginfo. Likewise
8512 validate_registers_access ();
8514 transferred
= target_write (current_top_target (),
8515 TARGET_OBJECT_SIGNAL_INFO
,
8517 value_contents_all_raw (fromval
),
8519 TYPE_LENGTH (value_type (fromval
)));
8521 if (transferred
!= TYPE_LENGTH (value_type (fromval
)))
8522 error (_("Unable to write siginfo"));
8525 static const struct lval_funcs siginfo_value_funcs
=
8531 /* Return a new value with the correct type for the siginfo object of
8532 the current thread using architecture GDBARCH. Return a void value
8533 if there's no object available. */
8535 static struct value
*
8536 siginfo_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
,
8539 if (target_has_stack
8540 && inferior_ptid
!= null_ptid
8541 && gdbarch_get_siginfo_type_p (gdbarch
))
8543 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
8545 return allocate_computed_value (type
, &siginfo_value_funcs
, NULL
);
8548 return allocate_value (builtin_type (gdbarch
)->builtin_void
);
8552 /* infcall_suspend_state contains state about the program itself like its
8553 registers and any signal it received when it last stopped.
8554 This state must be restored regardless of how the inferior function call
8555 ends (either successfully, or after it hits a breakpoint or signal)
8556 if the program is to properly continue where it left off. */
8558 class infcall_suspend_state
8561 /* Capture state from GDBARCH, TP, and REGCACHE that must be restored
8562 once the inferior function call has finished. */
8563 infcall_suspend_state (struct gdbarch
*gdbarch
,
8564 const struct thread_info
*tp
,
8565 struct regcache
*regcache
)
8566 : m_thread_suspend (tp
->suspend
),
8567 m_registers (new readonly_detached_regcache (*regcache
))
8569 gdb::unique_xmalloc_ptr
<gdb_byte
> siginfo_data
;
8571 if (gdbarch_get_siginfo_type_p (gdbarch
))
8573 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
8574 size_t len
= TYPE_LENGTH (type
);
8576 siginfo_data
.reset ((gdb_byte
*) xmalloc (len
));
8578 if (target_read (current_top_target (), TARGET_OBJECT_SIGNAL_INFO
, NULL
,
8579 siginfo_data
.get (), 0, len
) != len
)
8581 /* Errors ignored. */
8582 siginfo_data
.reset (nullptr);
8588 m_siginfo_gdbarch
= gdbarch
;
8589 m_siginfo_data
= std::move (siginfo_data
);
8593 /* Return a pointer to the stored register state. */
8595 readonly_detached_regcache
*registers () const
8597 return m_registers
.get ();
8600 /* Restores the stored state into GDBARCH, TP, and REGCACHE. */
8602 void restore (struct gdbarch
*gdbarch
,
8603 struct thread_info
*tp
,
8604 struct regcache
*regcache
) const
8606 tp
->suspend
= m_thread_suspend
;
8608 if (m_siginfo_gdbarch
== gdbarch
)
8610 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
8612 /* Errors ignored. */
8613 target_write (current_top_target (), TARGET_OBJECT_SIGNAL_INFO
, NULL
,
8614 m_siginfo_data
.get (), 0, TYPE_LENGTH (type
));
8617 /* The inferior can be gone if the user types "print exit(0)"
8618 (and perhaps other times). */
8619 if (target_has_execution
)
8620 /* NB: The register write goes through to the target. */
8621 regcache
->restore (registers ());
8625 /* How the current thread stopped before the inferior function call was
8627 struct thread_suspend_state m_thread_suspend
;
8629 /* The registers before the inferior function call was executed. */
8630 std::unique_ptr
<readonly_detached_regcache
> m_registers
;
8632 /* Format of SIGINFO_DATA or NULL if it is not present. */
8633 struct gdbarch
*m_siginfo_gdbarch
= nullptr;
8635 /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
8636 TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the
8637 content would be invalid. */
8638 gdb::unique_xmalloc_ptr
<gdb_byte
> m_siginfo_data
;
8641 infcall_suspend_state_up
8642 save_infcall_suspend_state ()
8644 struct thread_info
*tp
= inferior_thread ();
8645 struct regcache
*regcache
= get_current_regcache ();
8646 struct gdbarch
*gdbarch
= regcache
->arch ();
8648 infcall_suspend_state_up inf_state
8649 (new struct infcall_suspend_state (gdbarch
, tp
, regcache
));
8651 /* Having saved the current state, adjust the thread state, discarding
8652 any stop signal information. The stop signal is not useful when
8653 starting an inferior function call, and run_inferior_call will not use
8654 the signal due to its `proceed' call with GDB_SIGNAL_0. */
8655 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
8660 /* Restore inferior session state to INF_STATE. */
8663 restore_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
8665 struct thread_info
*tp
= inferior_thread ();
8666 struct regcache
*regcache
= get_current_regcache ();
8667 struct gdbarch
*gdbarch
= regcache
->arch ();
8669 inf_state
->restore (gdbarch
, tp
, regcache
);
8670 discard_infcall_suspend_state (inf_state
);
8674 discard_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
8679 readonly_detached_regcache
*
8680 get_infcall_suspend_state_regcache (struct infcall_suspend_state
*inf_state
)
8682 return inf_state
->registers ();
8685 /* infcall_control_state contains state regarding gdb's control of the
8686 inferior itself like stepping control. It also contains session state like
8687 the user's currently selected frame. */
8689 struct infcall_control_state
8691 struct thread_control_state thread_control
;
8692 struct inferior_control_state inferior_control
;
8695 enum stop_stack_kind stop_stack_dummy
= STOP_NONE
;
8696 int stopped_by_random_signal
= 0;
8698 /* ID if the selected frame when the inferior function call was made. */
8699 struct frame_id selected_frame_id
{};
8702 /* Save all of the information associated with the inferior<==>gdb
8705 infcall_control_state_up
8706 save_infcall_control_state ()
8708 infcall_control_state_up
inf_status (new struct infcall_control_state
);
8709 struct thread_info
*tp
= inferior_thread ();
8710 struct inferior
*inf
= current_inferior ();
8712 inf_status
->thread_control
= tp
->control
;
8713 inf_status
->inferior_control
= inf
->control
;
8715 tp
->control
.step_resume_breakpoint
= NULL
;
8716 tp
->control
.exception_resume_breakpoint
= NULL
;
8718 /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of
8719 chain. If caller's caller is walking the chain, they'll be happier if we
8720 hand them back the original chain when restore_infcall_control_state is
8722 tp
->control
.stop_bpstat
= bpstat_copy (tp
->control
.stop_bpstat
);
8725 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
8726 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
8728 inf_status
->selected_frame_id
= get_frame_id (get_selected_frame (NULL
));
8734 restore_selected_frame (const frame_id
&fid
)
8736 frame_info
*frame
= frame_find_by_id (fid
);
8738 /* If inf_status->selected_frame_id is NULL, there was no previously
8742 warning (_("Unable to restore previously selected frame."));
8746 select_frame (frame
);
8749 /* Restore inferior session state to INF_STATUS. */
8752 restore_infcall_control_state (struct infcall_control_state
*inf_status
)
8754 struct thread_info
*tp
= inferior_thread ();
8755 struct inferior
*inf
= current_inferior ();
8757 if (tp
->control
.step_resume_breakpoint
)
8758 tp
->control
.step_resume_breakpoint
->disposition
= disp_del_at_next_stop
;
8760 if (tp
->control
.exception_resume_breakpoint
)
8761 tp
->control
.exception_resume_breakpoint
->disposition
8762 = disp_del_at_next_stop
;
8764 /* Handle the bpstat_copy of the chain. */
8765 bpstat_clear (&tp
->control
.stop_bpstat
);
8767 tp
->control
= inf_status
->thread_control
;
8768 inf
->control
= inf_status
->inferior_control
;
8771 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
8772 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
8774 if (target_has_stack
)
8776 /* The point of the try/catch is that if the stack is clobbered,
8777 walking the stack might encounter a garbage pointer and
8778 error() trying to dereference it. */
8781 restore_selected_frame (inf_status
->selected_frame_id
);
8783 catch (const gdb_exception_error
&ex
)
8785 exception_fprintf (gdb_stderr
, ex
,
8786 "Unable to restore previously selected frame:\n");
8787 /* Error in restoring the selected frame. Select the
8789 select_frame (get_current_frame ());
8797 discard_infcall_control_state (struct infcall_control_state
*inf_status
)
8799 if (inf_status
->thread_control
.step_resume_breakpoint
)
8800 inf_status
->thread_control
.step_resume_breakpoint
->disposition
8801 = disp_del_at_next_stop
;
8803 if (inf_status
->thread_control
.exception_resume_breakpoint
)
8804 inf_status
->thread_control
.exception_resume_breakpoint
->disposition
8805 = disp_del_at_next_stop
;
8807 /* See save_infcall_control_state for info on stop_bpstat. */
8808 bpstat_clear (&inf_status
->thread_control
.stop_bpstat
);
8816 clear_exit_convenience_vars (void)
8818 clear_internalvar (lookup_internalvar ("_exitsignal"));
8819 clear_internalvar (lookup_internalvar ("_exitcode"));
8823 /* User interface for reverse debugging:
8824 Set exec-direction / show exec-direction commands
8825 (returns error unless target implements to_set_exec_direction method). */
8827 enum exec_direction_kind execution_direction
= EXEC_FORWARD
;
8828 static const char exec_forward
[] = "forward";
8829 static const char exec_reverse
[] = "reverse";
8830 static const char *exec_direction
= exec_forward
;
8831 static const char *const exec_direction_names
[] = {
8838 set_exec_direction_func (const char *args
, int from_tty
,
8839 struct cmd_list_element
*cmd
)
8841 if (target_can_execute_reverse
)
8843 if (!strcmp (exec_direction
, exec_forward
))
8844 execution_direction
= EXEC_FORWARD
;
8845 else if (!strcmp (exec_direction
, exec_reverse
))
8846 execution_direction
= EXEC_REVERSE
;
8850 exec_direction
= exec_forward
;
8851 error (_("Target does not support this operation."));
8856 show_exec_direction_func (struct ui_file
*out
, int from_tty
,
8857 struct cmd_list_element
*cmd
, const char *value
)
8859 switch (execution_direction
) {
8861 fprintf_filtered (out
, _("Forward.\n"));
8864 fprintf_filtered (out
, _("Reverse.\n"));
8867 internal_error (__FILE__
, __LINE__
,
8868 _("bogus execution_direction value: %d"),
8869 (int) execution_direction
);
8874 show_schedule_multiple (struct ui_file
*file
, int from_tty
,
8875 struct cmd_list_element
*c
, const char *value
)
8877 fprintf_filtered (file
, _("Resuming the execution of threads "
8878 "of all processes is %s.\n"), value
);
8881 /* Implementation of `siginfo' variable. */
8883 static const struct internalvar_funcs siginfo_funcs
=
8890 /* Callback for infrun's target events source. This is marked when a
8891 thread has a pending status to process. */
8894 infrun_async_inferior_event_handler (gdb_client_data data
)
8896 inferior_event_handler (INF_REG_EVENT
, NULL
);
8900 _initialize_infrun (void)
8902 struct cmd_list_element
*c
;
8904 /* Register extra event sources in the event loop. */
8905 infrun_async_inferior_event_token
8906 = create_async_event_handler (infrun_async_inferior_event_handler
, NULL
);
8908 add_info ("signals", info_signals_command
, _("\
8909 What debugger does when program gets various signals.\n\
8910 Specify a signal as argument to print info on that signal only."));
8911 add_info_alias ("handle", "signals", 0);
8913 c
= add_com ("handle", class_run
, handle_command
, _("\
8914 Specify how to handle signals.\n\
8915 Usage: handle SIGNAL [ACTIONS]\n\
8916 Args are signals and actions to apply to those signals.\n\
8917 If no actions are specified, the current settings for the specified signals\n\
8918 will be displayed instead.\n\
8920 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
8921 from 1-15 are allowed for compatibility with old versions of GDB.\n\
8922 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
8923 The special arg \"all\" is recognized to mean all signals except those\n\
8924 used by the debugger, typically SIGTRAP and SIGINT.\n\
8926 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
8927 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
8928 Stop means reenter debugger if this signal happens (implies print).\n\
8929 Print means print a message if this signal happens.\n\
8930 Pass means let program see this signal; otherwise program doesn't know.\n\
8931 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
8932 Pass and Stop may be combined.\n\
8934 Multiple signals may be specified. Signal numbers and signal names\n\
8935 may be interspersed with actions, with the actions being performed for\n\
8936 all signals cumulatively specified."));
8937 set_cmd_completer (c
, handle_completer
);
8940 stop_command
= add_cmd ("stop", class_obscure
,
8941 not_just_help_class_command
, _("\
8942 There is no `stop' command, but you can set a hook on `stop'.\n\
8943 This allows you to set a list of commands to be run each time execution\n\
8944 of the program stops."), &cmdlist
);
8946 add_setshow_zuinteger_cmd ("infrun", class_maintenance
, &debug_infrun
, _("\
8947 Set inferior debugging."), _("\
8948 Show inferior debugging."), _("\
8949 When non-zero, inferior specific debugging is enabled."),
8952 &setdebuglist
, &showdebuglist
);
8954 add_setshow_boolean_cmd ("displaced", class_maintenance
,
8955 &debug_displaced
, _("\
8956 Set displaced stepping debugging."), _("\
8957 Show displaced stepping debugging."), _("\
8958 When non-zero, displaced stepping specific debugging is enabled."),
8960 show_debug_displaced
,
8961 &setdebuglist
, &showdebuglist
);
8963 add_setshow_boolean_cmd ("non-stop", no_class
,
8965 Set whether gdb controls the inferior in non-stop mode."), _("\
8966 Show whether gdb controls the inferior in non-stop mode."), _("\
8967 When debugging a multi-threaded program and this setting is\n\
8968 off (the default, also called all-stop mode), when one thread stops\n\
8969 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
8970 all other threads in the program while you interact with the thread of\n\
8971 interest. When you continue or step a thread, you can allow the other\n\
8972 threads to run, or have them remain stopped, but while you inspect any\n\
8973 thread's state, all threads stop.\n\
8975 In non-stop mode, when one thread stops, other threads can continue\n\
8976 to run freely. You'll be able to step each thread independently,\n\
8977 leave it stopped or free to run as needed."),
8983 for (size_t i
= 0; i
< GDB_SIGNAL_LAST
; i
++)
8986 signal_print
[i
] = 1;
8987 signal_program
[i
] = 1;
8988 signal_catch
[i
] = 0;
8991 /* Signals caused by debugger's own actions should not be given to
8992 the program afterwards.
8994 Do not deliver GDB_SIGNAL_TRAP by default, except when the user
8995 explicitly specifies that it should be delivered to the target
8996 program. Typically, that would occur when a user is debugging a
8997 target monitor on a simulator: the target monitor sets a
8998 breakpoint; the simulator encounters this breakpoint and halts
8999 the simulation handing control to GDB; GDB, noting that the stop
9000 address doesn't map to any known breakpoint, returns control back
9001 to the simulator; the simulator then delivers the hardware
9002 equivalent of a GDB_SIGNAL_TRAP to the program being
9004 signal_program
[GDB_SIGNAL_TRAP
] = 0;
9005 signal_program
[GDB_SIGNAL_INT
] = 0;
9007 /* Signals that are not errors should not normally enter the debugger. */
9008 signal_stop
[GDB_SIGNAL_ALRM
] = 0;
9009 signal_print
[GDB_SIGNAL_ALRM
] = 0;
9010 signal_stop
[GDB_SIGNAL_VTALRM
] = 0;
9011 signal_print
[GDB_SIGNAL_VTALRM
] = 0;
9012 signal_stop
[GDB_SIGNAL_PROF
] = 0;
9013 signal_print
[GDB_SIGNAL_PROF
] = 0;
9014 signal_stop
[GDB_SIGNAL_CHLD
] = 0;
9015 signal_print
[GDB_SIGNAL_CHLD
] = 0;
9016 signal_stop
[GDB_SIGNAL_IO
] = 0;
9017 signal_print
[GDB_SIGNAL_IO
] = 0;
9018 signal_stop
[GDB_SIGNAL_POLL
] = 0;
9019 signal_print
[GDB_SIGNAL_POLL
] = 0;
9020 signal_stop
[GDB_SIGNAL_URG
] = 0;
9021 signal_print
[GDB_SIGNAL_URG
] = 0;
9022 signal_stop
[GDB_SIGNAL_WINCH
] = 0;
9023 signal_print
[GDB_SIGNAL_WINCH
] = 0;
9024 signal_stop
[GDB_SIGNAL_PRIO
] = 0;
9025 signal_print
[GDB_SIGNAL_PRIO
] = 0;
9027 /* These signals are used internally by user-level thread
9028 implementations. (See signal(5) on Solaris.) Like the above
9029 signals, a healthy program receives and handles them as part of
9030 its normal operation. */
9031 signal_stop
[GDB_SIGNAL_LWP
] = 0;
9032 signal_print
[GDB_SIGNAL_LWP
] = 0;
9033 signal_stop
[GDB_SIGNAL_WAITING
] = 0;
9034 signal_print
[GDB_SIGNAL_WAITING
] = 0;
9035 signal_stop
[GDB_SIGNAL_CANCEL
] = 0;
9036 signal_print
[GDB_SIGNAL_CANCEL
] = 0;
9037 signal_stop
[GDB_SIGNAL_LIBRT
] = 0;
9038 signal_print
[GDB_SIGNAL_LIBRT
] = 0;
9040 /* Update cached state. */
9041 signal_cache_update (-1);
9043 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support
,
9044 &stop_on_solib_events
, _("\
9045 Set stopping for shared library events."), _("\
9046 Show stopping for shared library events."), _("\
9047 If nonzero, gdb will give control to the user when the dynamic linker\n\
9048 notifies gdb of shared library events. The most common event of interest\n\
9049 to the user would be loading/unloading of a new library."),
9050 set_stop_on_solib_events
,
9051 show_stop_on_solib_events
,
9052 &setlist
, &showlist
);
9054 add_setshow_enum_cmd ("follow-fork-mode", class_run
,
9055 follow_fork_mode_kind_names
,
9056 &follow_fork_mode_string
, _("\
9057 Set debugger response to a program call of fork or vfork."), _("\
9058 Show debugger response to a program call of fork or vfork."), _("\
9059 A fork or vfork creates a new process. follow-fork-mode can be:\n\
9060 parent - the original process is debugged after a fork\n\
9061 child - the new process is debugged after a fork\n\
9062 The unfollowed process will continue to run.\n\
9063 By default, the debugger will follow the parent process."),
9065 show_follow_fork_mode_string
,
9066 &setlist
, &showlist
);
9068 add_setshow_enum_cmd ("follow-exec-mode", class_run
,
9069 follow_exec_mode_names
,
9070 &follow_exec_mode_string
, _("\
9071 Set debugger response to a program call of exec."), _("\
9072 Show debugger response to a program call of exec."), _("\
9073 An exec call replaces the program image of a process.\n\
9075 follow-exec-mode can be:\n\
9077 new - the debugger creates a new inferior and rebinds the process\n\
9078 to this new inferior. The program the process was running before\n\
9079 the exec call can be restarted afterwards by restarting the original\n\
9082 same - the debugger keeps the process bound to the same inferior.\n\
9083 The new executable image replaces the previous executable loaded in\n\
9084 the inferior. Restarting the inferior after the exec call restarts\n\
9085 the executable the process was running after the exec call.\n\
9087 By default, the debugger will use the same inferior."),
9089 show_follow_exec_mode_string
,
9090 &setlist
, &showlist
);
9092 add_setshow_enum_cmd ("scheduler-locking", class_run
,
9093 scheduler_enums
, &scheduler_mode
, _("\
9094 Set mode for locking scheduler during execution."), _("\
9095 Show mode for locking scheduler during execution."), _("\
9096 off == no locking (threads may preempt at any time)\n\
9097 on == full locking (no thread except the current thread may run)\n\
9098 This applies to both normal execution and replay mode.\n\
9099 step == scheduler locked during stepping commands (step, next, stepi, nexti).\n\
9100 In this mode, other threads may run during other commands.\n\
9101 This applies to both normal execution and replay mode.\n\
9102 replay == scheduler locked in replay mode and unlocked during normal execution."),
9103 set_schedlock_func
, /* traps on target vector */
9104 show_scheduler_mode
,
9105 &setlist
, &showlist
);
9107 add_setshow_boolean_cmd ("schedule-multiple", class_run
, &sched_multi
, _("\
9108 Set mode for resuming threads of all processes."), _("\
9109 Show mode for resuming threads of all processes."), _("\
9110 When on, execution commands (such as 'continue' or 'next') resume all\n\
9111 threads of all processes. When off (which is the default), execution\n\
9112 commands only resume the threads of the current process. The set of\n\
9113 threads that are resumed is further refined by the scheduler-locking\n\
9114 mode (see help set scheduler-locking)."),
9116 show_schedule_multiple
,
9117 &setlist
, &showlist
);
9119 add_setshow_boolean_cmd ("step-mode", class_run
, &step_stop_if_no_debug
, _("\
9120 Set mode of the step operation."), _("\
9121 Show mode of the step operation."), _("\
9122 When set, doing a step over a function without debug line information\n\
9123 will stop at the first instruction of that function. Otherwise, the\n\
9124 function is skipped and the step command stops at a different source line."),
9126 show_step_stop_if_no_debug
,
9127 &setlist
, &showlist
);
9129 add_setshow_auto_boolean_cmd ("displaced-stepping", class_run
,
9130 &can_use_displaced_stepping
, _("\
9131 Set debugger's willingness to use displaced stepping."), _("\
9132 Show debugger's willingness to use displaced stepping."), _("\
9133 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
9134 supported by the target architecture. If off, gdb will not use displaced\n\
9135 stepping to step over breakpoints, even if such is supported by the target\n\
9136 architecture. If auto (which is the default), gdb will use displaced stepping\n\
9137 if the target architecture supports it and non-stop mode is active, but will not\n\
9138 use it in all-stop mode (see help set non-stop)."),
9140 show_can_use_displaced_stepping
,
9141 &setlist
, &showlist
);
9143 add_setshow_enum_cmd ("exec-direction", class_run
, exec_direction_names
,
9144 &exec_direction
, _("Set direction of execution.\n\
9145 Options are 'forward' or 'reverse'."),
9146 _("Show direction of execution (forward/reverse)."),
9147 _("Tells gdb whether to execute forward or backward."),
9148 set_exec_direction_func
, show_exec_direction_func
,
9149 &setlist
, &showlist
);
9151 /* Set/show detach-on-fork: user-settable mode. */
9153 add_setshow_boolean_cmd ("detach-on-fork", class_run
, &detach_fork
, _("\
9154 Set whether gdb will detach the child of a fork."), _("\
9155 Show whether gdb will detach the child of a fork."), _("\
9156 Tells gdb whether to detach the child of a fork."),
9157 NULL
, NULL
, &setlist
, &showlist
);
9159 /* Set/show disable address space randomization mode. */
9161 add_setshow_boolean_cmd ("disable-randomization", class_support
,
9162 &disable_randomization
, _("\
9163 Set disabling of debuggee's virtual address space randomization."), _("\
9164 Show disabling of debuggee's virtual address space randomization."), _("\
9165 When this mode is on (which is the default), randomization of the virtual\n\
9166 address space is disabled. Standalone programs run with the randomization\n\
9167 enabled by default on some platforms."),
9168 &set_disable_randomization
,
9169 &show_disable_randomization
,
9170 &setlist
, &showlist
);
9172 /* ptid initializations */
9173 inferior_ptid
= null_ptid
;
9174 target_last_wait_ptid
= minus_one_ptid
;
9176 gdb::observers::thread_ptid_changed
.attach (infrun_thread_ptid_changed
);
9177 gdb::observers::thread_stop_requested
.attach (infrun_thread_stop_requested
);
9178 gdb::observers::thread_exit
.attach (infrun_thread_thread_exit
);
9179 gdb::observers::inferior_exit
.attach (infrun_inferior_exit
);
9181 /* Explicitly create without lookup, since that tries to create a
9182 value with a void typed value, and when we get here, gdbarch
9183 isn't initialized yet. At this point, we're quite sure there
9184 isn't another convenience variable of the same name. */
9185 create_internalvar_type_lazy ("_siginfo", &siginfo_funcs
, NULL
);
9187 add_setshow_boolean_cmd ("observer", no_class
,
9188 &observer_mode_1
, _("\
9189 Set whether gdb controls the inferior in observer mode."), _("\
9190 Show whether gdb controls the inferior in observer mode."), _("\
9191 In observer mode, GDB can get data from the inferior, but not\n\
9192 affect its execution. Registers and memory may not be changed,\n\
9193 breakpoints may not be set, and the program cannot be interrupted\n\