1 /* Target-struct-independent code to start (run) and stop an inferior
4 Copyright (C) 1986-2015 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 #include "breakpoint.h"
31 #include "cli/cli-script.h"
33 #include "gdbthread.h"
45 #include "dictionary.h"
47 #include "mi/mi-common.h"
48 #include "event-top.h"
50 #include "record-full.h"
51 #include "inline-frame.h"
53 #include "tracepoint.h"
54 #include "continuations.h"
59 #include "completer.h"
60 #include "target-descriptions.h"
61 #include "target-dcache.h"
64 /* Prototypes for local functions */
66 static void signals_info (char *, int);
68 static void handle_command (char *, int);
70 static void sig_print_info (enum gdb_signal
);
72 static void sig_print_header (void);
74 static void resume_cleanups (void *);
76 static int hook_stop_stub (void *);
78 static int restore_selected_frame (void *);
80 static int follow_fork (void);
82 static int follow_fork_inferior (int follow_child
, int detach_fork
);
84 static void follow_inferior_reset_breakpoints (void);
86 static void set_schedlock_func (char *args
, int from_tty
,
87 struct cmd_list_element
*c
);
89 static int currently_stepping (struct thread_info
*tp
);
91 static void xdb_handle_command (char *args
, int from_tty
);
93 void _initialize_infrun (void);
95 void nullify_last_target_wait_ptid (void);
97 static void insert_hp_step_resume_breakpoint_at_frame (struct frame_info
*);
99 static void insert_step_resume_breakpoint_at_caller (struct frame_info
*);
101 static void insert_longjmp_resume_breakpoint (struct gdbarch
*, CORE_ADDR
);
103 /* When set, stop the 'step' command if we enter a function which has
104 no line number information. The normal behavior is that we step
105 over such function. */
106 int step_stop_if_no_debug
= 0;
108 show_step_stop_if_no_debug (struct ui_file
*file
, int from_tty
,
109 struct cmd_list_element
*c
, const char *value
)
111 fprintf_filtered (file
, _("Mode of the step operation is %s.\n"), value
);
114 /* In asynchronous mode, but simulating synchronous execution. */
116 int sync_execution
= 0;
118 /* proceed and normal_stop use this to notify the user when the
119 inferior stopped in a different thread than it had been running
122 static ptid_t previous_inferior_ptid
;
124 /* If set (default for legacy reasons), when following a fork, GDB
125 will detach from one of the fork branches, child or parent.
126 Exactly which branch is detached depends on 'set follow-fork-mode'
129 static int detach_fork
= 1;
131 int debug_displaced
= 0;
133 show_debug_displaced (struct ui_file
*file
, int from_tty
,
134 struct cmd_list_element
*c
, const char *value
)
136 fprintf_filtered (file
, _("Displace stepping debugging is %s.\n"), value
);
139 unsigned int debug_infrun
= 0;
141 show_debug_infrun (struct ui_file
*file
, int from_tty
,
142 struct cmd_list_element
*c
, const char *value
)
144 fprintf_filtered (file
, _("Inferior debugging is %s.\n"), value
);
148 /* Support for disabling address space randomization. */
150 int disable_randomization
= 1;
153 show_disable_randomization (struct ui_file
*file
, int from_tty
,
154 struct cmd_list_element
*c
, const char *value
)
156 if (target_supports_disable_randomization ())
157 fprintf_filtered (file
,
158 _("Disabling randomization of debuggee's "
159 "virtual address space is %s.\n"),
162 fputs_filtered (_("Disabling randomization of debuggee's "
163 "virtual address space is unsupported on\n"
164 "this platform.\n"), file
);
168 set_disable_randomization (char *args
, int from_tty
,
169 struct cmd_list_element
*c
)
171 if (!target_supports_disable_randomization ())
172 error (_("Disabling randomization of debuggee's "
173 "virtual address space is unsupported on\n"
177 /* User interface for non-stop mode. */
180 static int non_stop_1
= 0;
183 set_non_stop (char *args
, int from_tty
,
184 struct cmd_list_element
*c
)
186 if (target_has_execution
)
188 non_stop_1
= non_stop
;
189 error (_("Cannot change this setting while the inferior is running."));
192 non_stop
= non_stop_1
;
196 show_non_stop (struct ui_file
*file
, int from_tty
,
197 struct cmd_list_element
*c
, const char *value
)
199 fprintf_filtered (file
,
200 _("Controlling the inferior in non-stop mode is %s.\n"),
204 /* "Observer mode" is somewhat like a more extreme version of
205 non-stop, in which all GDB operations that might affect the
206 target's execution have been disabled. */
208 int observer_mode
= 0;
209 static int observer_mode_1
= 0;
212 set_observer_mode (char *args
, int from_tty
,
213 struct cmd_list_element
*c
)
215 if (target_has_execution
)
217 observer_mode_1
= observer_mode
;
218 error (_("Cannot change this setting while the inferior is running."));
221 observer_mode
= observer_mode_1
;
223 may_write_registers
= !observer_mode
;
224 may_write_memory
= !observer_mode
;
225 may_insert_breakpoints
= !observer_mode
;
226 may_insert_tracepoints
= !observer_mode
;
227 /* We can insert fast tracepoints in or out of observer mode,
228 but enable them if we're going into this mode. */
230 may_insert_fast_tracepoints
= 1;
231 may_stop
= !observer_mode
;
232 update_target_permissions ();
234 /* Going *into* observer mode we must force non-stop, then
235 going out we leave it that way. */
238 pagination_enabled
= 0;
239 non_stop
= non_stop_1
= 1;
243 printf_filtered (_("Observer mode is now %s.\n"),
244 (observer_mode
? "on" : "off"));
248 show_observer_mode (struct ui_file
*file
, int from_tty
,
249 struct cmd_list_element
*c
, const char *value
)
251 fprintf_filtered (file
, _("Observer mode is %s.\n"), value
);
254 /* This updates the value of observer mode based on changes in
255 permissions. Note that we are deliberately ignoring the values of
256 may-write-registers and may-write-memory, since the user may have
257 reason to enable these during a session, for instance to turn on a
258 debugging-related global. */
261 update_observer_mode (void)
265 newval
= (!may_insert_breakpoints
266 && !may_insert_tracepoints
267 && may_insert_fast_tracepoints
271 /* Let the user know if things change. */
272 if (newval
!= observer_mode
)
273 printf_filtered (_("Observer mode is now %s.\n"),
274 (newval
? "on" : "off"));
276 observer_mode
= observer_mode_1
= newval
;
279 /* Tables of how to react to signals; the user sets them. */
281 static unsigned char *signal_stop
;
282 static unsigned char *signal_print
;
283 static unsigned char *signal_program
;
285 /* Table of signals that are registered with "catch signal". A
286 non-zero entry indicates that the signal is caught by some "catch
287 signal" command. This has size GDB_SIGNAL_LAST, to accommodate all
289 static unsigned char *signal_catch
;
291 /* Table of signals that the target may silently handle.
292 This is automatically determined from the flags above,
293 and simply cached here. */
294 static unsigned char *signal_pass
;
296 #define SET_SIGS(nsigs,sigs,flags) \
298 int signum = (nsigs); \
299 while (signum-- > 0) \
300 if ((sigs)[signum]) \
301 (flags)[signum] = 1; \
304 #define UNSET_SIGS(nsigs,sigs,flags) \
306 int signum = (nsigs); \
307 while (signum-- > 0) \
308 if ((sigs)[signum]) \
309 (flags)[signum] = 0; \
312 /* Update the target's copy of SIGNAL_PROGRAM. The sole purpose of
313 this function is to avoid exporting `signal_program'. */
316 update_signals_program_target (void)
318 target_program_signals ((int) GDB_SIGNAL_LAST
, signal_program
);
321 /* Value to pass to target_resume() to cause all threads to resume. */
323 #define RESUME_ALL minus_one_ptid
325 /* Command list pointer for the "stop" placeholder. */
327 static struct cmd_list_element
*stop_command
;
329 /* Function inferior was in as of last step command. */
331 static struct symbol
*step_start_function
;
333 /* Nonzero if we want to give control to the user when we're notified
334 of shared library events by the dynamic linker. */
335 int stop_on_solib_events
;
337 /* Enable or disable optional shared library event breakpoints
338 as appropriate when the above flag is changed. */
341 set_stop_on_solib_events (char *args
, int from_tty
, struct cmd_list_element
*c
)
343 update_solib_breakpoints ();
347 show_stop_on_solib_events (struct ui_file
*file
, int from_tty
,
348 struct cmd_list_element
*c
, const char *value
)
350 fprintf_filtered (file
, _("Stopping for shared library events is %s.\n"),
354 /* Nonzero means expecting a trace trap
355 and should stop the inferior and return silently when it happens. */
359 /* Save register contents here when executing a "finish" command or are
360 about to pop a stack dummy frame, if-and-only-if proceed_to_finish is set.
361 Thus this contains the return value from the called function (assuming
362 values are returned in a register). */
364 struct regcache
*stop_registers
;
366 /* Nonzero after stop if current stack frame should be printed. */
368 static int stop_print_frame
;
370 /* This is a cached copy of the pid/waitstatus of the last event
371 returned by target_wait()/deprecated_target_wait_hook(). This
372 information is returned by get_last_target_status(). */
373 static ptid_t target_last_wait_ptid
;
374 static struct target_waitstatus target_last_waitstatus
;
376 static void context_switch (ptid_t ptid
);
378 void init_thread_stepping_state (struct thread_info
*tss
);
380 static const char follow_fork_mode_child
[] = "child";
381 static const char follow_fork_mode_parent
[] = "parent";
383 static const char *const follow_fork_mode_kind_names
[] = {
384 follow_fork_mode_child
,
385 follow_fork_mode_parent
,
389 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
391 show_follow_fork_mode_string (struct ui_file
*file
, int from_tty
,
392 struct cmd_list_element
*c
, const char *value
)
394 fprintf_filtered (file
,
395 _("Debugger response to a program "
396 "call of fork or vfork is \"%s\".\n"),
401 /* Handle changes to the inferior list based on the type of fork,
402 which process is being followed, and whether the other process
403 should be detached. On entry inferior_ptid must be the ptid of
404 the fork parent. At return inferior_ptid is the ptid of the
405 followed inferior. */
408 follow_fork_inferior (int follow_child
, int detach_fork
)
411 ptid_t parent_ptid
, child_ptid
;
413 has_vforked
= (inferior_thread ()->pending_follow
.kind
414 == TARGET_WAITKIND_VFORKED
);
415 parent_ptid
= inferior_ptid
;
416 child_ptid
= inferior_thread ()->pending_follow
.value
.related_pid
;
419 && !non_stop
/* Non-stop always resumes both branches. */
420 && (!target_is_async_p () || sync_execution
)
421 && !(follow_child
|| detach_fork
|| sched_multi
))
423 /* The parent stays blocked inside the vfork syscall until the
424 child execs or exits. If we don't let the child run, then
425 the parent stays blocked. If we're telling the parent to run
426 in the foreground, the user will not be able to ctrl-c to get
427 back the terminal, effectively hanging the debug session. */
428 fprintf_filtered (gdb_stderr
, _("\
429 Can not resume the parent process over vfork in the foreground while\n\
430 holding the child stopped. Try \"set detach-on-fork\" or \
431 \"set schedule-multiple\".\n"));
432 /* FIXME output string > 80 columns. */
438 /* Detach new forked process? */
441 struct cleanup
*old_chain
;
443 /* Before detaching from the child, remove all breakpoints
444 from it. If we forked, then this has already been taken
445 care of by infrun.c. If we vforked however, any
446 breakpoint inserted in the parent is visible in the
447 child, even those added while stopped in a vfork
448 catchpoint. This will remove the breakpoints from the
449 parent also, but they'll be reinserted below. */
452 /* Keep breakpoints list in sync. */
453 remove_breakpoints_pid (ptid_get_pid (inferior_ptid
));
456 if (info_verbose
|| debug_infrun
)
458 target_terminal_ours_for_output ();
459 fprintf_filtered (gdb_stdlog
,
460 _("Detaching after %s from child %s.\n"),
461 has_vforked
? "vfork" : "fork",
462 target_pid_to_str (child_ptid
));
467 struct inferior
*parent_inf
, *child_inf
;
468 struct cleanup
*old_chain
;
470 /* Add process to GDB's tables. */
471 child_inf
= add_inferior (ptid_get_pid (child_ptid
));
473 parent_inf
= current_inferior ();
474 child_inf
->attach_flag
= parent_inf
->attach_flag
;
475 copy_terminal_info (child_inf
, parent_inf
);
476 child_inf
->gdbarch
= parent_inf
->gdbarch
;
477 copy_inferior_target_desc_info (child_inf
, parent_inf
);
479 old_chain
= save_inferior_ptid ();
480 save_current_program_space ();
482 inferior_ptid
= child_ptid
;
483 add_thread (inferior_ptid
);
484 child_inf
->symfile_flags
= SYMFILE_NO_READ
;
486 /* If this is a vfork child, then the address-space is
487 shared with the parent. */
490 child_inf
->pspace
= parent_inf
->pspace
;
491 child_inf
->aspace
= parent_inf
->aspace
;
493 /* The parent will be frozen until the child is done
494 with the shared region. Keep track of the
496 child_inf
->vfork_parent
= parent_inf
;
497 child_inf
->pending_detach
= 0;
498 parent_inf
->vfork_child
= child_inf
;
499 parent_inf
->pending_detach
= 0;
503 child_inf
->aspace
= new_address_space ();
504 child_inf
->pspace
= add_program_space (child_inf
->aspace
);
505 child_inf
->removable
= 1;
506 set_current_program_space (child_inf
->pspace
);
507 clone_program_space (child_inf
->pspace
, parent_inf
->pspace
);
509 /* Let the shared library layer (e.g., solib-svr4) learn
510 about this new process, relocate the cloned exec, pull
511 in shared libraries, and install the solib event
512 breakpoint. If a "cloned-VM" event was propagated
513 better throughout the core, this wouldn't be
515 solib_create_inferior_hook (0);
518 do_cleanups (old_chain
);
523 struct inferior
*parent_inf
;
525 parent_inf
= current_inferior ();
527 /* If we detached from the child, then we have to be careful
528 to not insert breakpoints in the parent until the child
529 is done with the shared memory region. However, if we're
530 staying attached to the child, then we can and should
531 insert breakpoints, so that we can debug it. A
532 subsequent child exec or exit is enough to know when does
533 the child stops using the parent's address space. */
534 parent_inf
->waiting_for_vfork_done
= detach_fork
;
535 parent_inf
->pspace
->breakpoints_not_allowed
= detach_fork
;
540 /* Follow the child. */
541 struct inferior
*parent_inf
, *child_inf
;
542 struct program_space
*parent_pspace
;
544 if (info_verbose
|| debug_infrun
)
546 target_terminal_ours_for_output ();
547 fprintf_filtered (gdb_stdlog
,
548 _("Attaching after %s %s to child %s.\n"),
549 target_pid_to_str (parent_ptid
),
550 has_vforked
? "vfork" : "fork",
551 target_pid_to_str (child_ptid
));
554 /* Add the new inferior first, so that the target_detach below
555 doesn't unpush the target. */
557 child_inf
= add_inferior (ptid_get_pid (child_ptid
));
559 parent_inf
= current_inferior ();
560 child_inf
->attach_flag
= parent_inf
->attach_flag
;
561 copy_terminal_info (child_inf
, parent_inf
);
562 child_inf
->gdbarch
= parent_inf
->gdbarch
;
563 copy_inferior_target_desc_info (child_inf
, parent_inf
);
565 parent_pspace
= parent_inf
->pspace
;
567 /* If we're vforking, we want to hold on to the parent until the
568 child exits or execs. At child exec or exit time we can
569 remove the old breakpoints from the parent and detach or
570 resume debugging it. Otherwise, detach the parent now; we'll
571 want to reuse it's program/address spaces, but we can't set
572 them to the child before removing breakpoints from the
573 parent, otherwise, the breakpoints module could decide to
574 remove breakpoints from the wrong process (since they'd be
575 assigned to the same address space). */
579 gdb_assert (child_inf
->vfork_parent
== NULL
);
580 gdb_assert (parent_inf
->vfork_child
== NULL
);
581 child_inf
->vfork_parent
= parent_inf
;
582 child_inf
->pending_detach
= 0;
583 parent_inf
->vfork_child
= child_inf
;
584 parent_inf
->pending_detach
= detach_fork
;
585 parent_inf
->waiting_for_vfork_done
= 0;
587 else if (detach_fork
)
589 if (info_verbose
|| debug_infrun
)
591 target_terminal_ours_for_output ();
592 fprintf_filtered (gdb_stdlog
,
593 _("Detaching after fork from "
595 target_pid_to_str (child_ptid
));
598 target_detach (NULL
, 0);
601 /* Note that the detach above makes PARENT_INF dangling. */
603 /* Add the child thread to the appropriate lists, and switch to
604 this new thread, before cloning the program space, and
605 informing the solib layer about this new process. */
607 inferior_ptid
= child_ptid
;
608 add_thread (inferior_ptid
);
610 /* If this is a vfork child, then the address-space is shared
611 with the parent. If we detached from the parent, then we can
612 reuse the parent's program/address spaces. */
613 if (has_vforked
|| detach_fork
)
615 child_inf
->pspace
= parent_pspace
;
616 child_inf
->aspace
= child_inf
->pspace
->aspace
;
620 child_inf
->aspace
= new_address_space ();
621 child_inf
->pspace
= add_program_space (child_inf
->aspace
);
622 child_inf
->removable
= 1;
623 child_inf
->symfile_flags
= SYMFILE_NO_READ
;
624 set_current_program_space (child_inf
->pspace
);
625 clone_program_space (child_inf
->pspace
, parent_pspace
);
627 /* Let the shared library layer (e.g., solib-svr4) learn
628 about this new process, relocate the cloned exec, pull in
629 shared libraries, and install the solib event breakpoint.
630 If a "cloned-VM" event was propagated better throughout
631 the core, this wouldn't be required. */
632 solib_create_inferior_hook (0);
636 return target_follow_fork (follow_child
, detach_fork
);
639 /* Tell the target to follow the fork we're stopped at. Returns true
640 if the inferior should be resumed; false, if the target for some
641 reason decided it's best not to resume. */
646 int follow_child
= (follow_fork_mode_string
== follow_fork_mode_child
);
647 int should_resume
= 1;
648 struct thread_info
*tp
;
650 /* Copy user stepping state to the new inferior thread. FIXME: the
651 followed fork child thread should have a copy of most of the
652 parent thread structure's run control related fields, not just these.
653 Initialized to avoid "may be used uninitialized" warnings from gcc. */
654 struct breakpoint
*step_resume_breakpoint
= NULL
;
655 struct breakpoint
*exception_resume_breakpoint
= NULL
;
656 CORE_ADDR step_range_start
= 0;
657 CORE_ADDR step_range_end
= 0;
658 struct frame_id step_frame_id
= { 0 };
659 struct interp
*command_interp
= NULL
;
664 struct target_waitstatus wait_status
;
666 /* Get the last target status returned by target_wait(). */
667 get_last_target_status (&wait_ptid
, &wait_status
);
669 /* If not stopped at a fork event, then there's nothing else to
671 if (wait_status
.kind
!= TARGET_WAITKIND_FORKED
672 && wait_status
.kind
!= TARGET_WAITKIND_VFORKED
)
675 /* Check if we switched over from WAIT_PTID, since the event was
677 if (!ptid_equal (wait_ptid
, minus_one_ptid
)
678 && !ptid_equal (inferior_ptid
, wait_ptid
))
680 /* We did. Switch back to WAIT_PTID thread, to tell the
681 target to follow it (in either direction). We'll
682 afterwards refuse to resume, and inform the user what
684 switch_to_thread (wait_ptid
);
689 tp
= inferior_thread ();
691 /* If there were any forks/vforks that were caught and are now to be
692 followed, then do so now. */
693 switch (tp
->pending_follow
.kind
)
695 case TARGET_WAITKIND_FORKED
:
696 case TARGET_WAITKIND_VFORKED
:
698 ptid_t parent
, child
;
700 /* If the user did a next/step, etc, over a fork call,
701 preserve the stepping state in the fork child. */
702 if (follow_child
&& should_resume
)
704 step_resume_breakpoint
= clone_momentary_breakpoint
705 (tp
->control
.step_resume_breakpoint
);
706 step_range_start
= tp
->control
.step_range_start
;
707 step_range_end
= tp
->control
.step_range_end
;
708 step_frame_id
= tp
->control
.step_frame_id
;
709 exception_resume_breakpoint
710 = clone_momentary_breakpoint (tp
->control
.exception_resume_breakpoint
);
711 command_interp
= tp
->control
.command_interp
;
713 /* For now, delete the parent's sr breakpoint, otherwise,
714 parent/child sr breakpoints are considered duplicates,
715 and the child version will not be installed. Remove
716 this when the breakpoints module becomes aware of
717 inferiors and address spaces. */
718 delete_step_resume_breakpoint (tp
);
719 tp
->control
.step_range_start
= 0;
720 tp
->control
.step_range_end
= 0;
721 tp
->control
.step_frame_id
= null_frame_id
;
722 delete_exception_resume_breakpoint (tp
);
723 tp
->control
.command_interp
= NULL
;
726 parent
= inferior_ptid
;
727 child
= tp
->pending_follow
.value
.related_pid
;
729 /* Set up inferior(s) as specified by the caller, and tell the
730 target to do whatever is necessary to follow either parent
732 if (follow_fork_inferior (follow_child
, detach_fork
))
734 /* Target refused to follow, or there's some other reason
735 we shouldn't resume. */
740 /* This pending follow fork event is now handled, one way
741 or another. The previous selected thread may be gone
742 from the lists by now, but if it is still around, need
743 to clear the pending follow request. */
744 tp
= find_thread_ptid (parent
);
746 tp
->pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
748 /* This makes sure we don't try to apply the "Switched
749 over from WAIT_PID" logic above. */
750 nullify_last_target_wait_ptid ();
752 /* If we followed the child, switch to it... */
755 switch_to_thread (child
);
757 /* ... and preserve the stepping state, in case the
758 user was stepping over the fork call. */
761 tp
= inferior_thread ();
762 tp
->control
.step_resume_breakpoint
763 = step_resume_breakpoint
;
764 tp
->control
.step_range_start
= step_range_start
;
765 tp
->control
.step_range_end
= step_range_end
;
766 tp
->control
.step_frame_id
= step_frame_id
;
767 tp
->control
.exception_resume_breakpoint
768 = exception_resume_breakpoint
;
769 tp
->control
.command_interp
= command_interp
;
773 /* If we get here, it was because we're trying to
774 resume from a fork catchpoint, but, the user
775 has switched threads away from the thread that
776 forked. In that case, the resume command
777 issued is most likely not applicable to the
778 child, so just warn, and refuse to resume. */
779 warning (_("Not resuming: switched threads "
780 "before following fork child.\n"));
783 /* Reset breakpoints in the child as appropriate. */
784 follow_inferior_reset_breakpoints ();
787 switch_to_thread (parent
);
791 case TARGET_WAITKIND_SPURIOUS
:
792 /* Nothing to follow. */
795 internal_error (__FILE__
, __LINE__
,
796 "Unexpected pending_follow.kind %d\n",
797 tp
->pending_follow
.kind
);
801 return should_resume
;
805 follow_inferior_reset_breakpoints (void)
807 struct thread_info
*tp
= inferior_thread ();
809 /* Was there a step_resume breakpoint? (There was if the user
810 did a "next" at the fork() call.) If so, explicitly reset its
811 thread number. Cloned step_resume breakpoints are disabled on
812 creation, so enable it here now that it is associated with the
815 step_resumes are a form of bp that are made to be per-thread.
816 Since we created the step_resume bp when the parent process
817 was being debugged, and now are switching to the child process,
818 from the breakpoint package's viewpoint, that's a switch of
819 "threads". We must update the bp's notion of which thread
820 it is for, or it'll be ignored when it triggers. */
822 if (tp
->control
.step_resume_breakpoint
)
824 breakpoint_re_set_thread (tp
->control
.step_resume_breakpoint
);
825 tp
->control
.step_resume_breakpoint
->loc
->enabled
= 1;
828 /* Treat exception_resume breakpoints like step_resume breakpoints. */
829 if (tp
->control
.exception_resume_breakpoint
)
831 breakpoint_re_set_thread (tp
->control
.exception_resume_breakpoint
);
832 tp
->control
.exception_resume_breakpoint
->loc
->enabled
= 1;
835 /* Reinsert all breakpoints in the child. The user may have set
836 breakpoints after catching the fork, in which case those
837 were never set in the child, but only in the parent. This makes
838 sure the inserted breakpoints match the breakpoint list. */
840 breakpoint_re_set ();
841 insert_breakpoints ();
844 /* The child has exited or execed: resume threads of the parent the
845 user wanted to be executing. */
848 proceed_after_vfork_done (struct thread_info
*thread
,
851 int pid
= * (int *) arg
;
853 if (ptid_get_pid (thread
->ptid
) == pid
854 && is_running (thread
->ptid
)
855 && !is_executing (thread
->ptid
)
856 && !thread
->stop_requested
857 && thread
->suspend
.stop_signal
== GDB_SIGNAL_0
)
860 fprintf_unfiltered (gdb_stdlog
,
861 "infrun: resuming vfork parent thread %s\n",
862 target_pid_to_str (thread
->ptid
));
864 switch_to_thread (thread
->ptid
);
865 clear_proceed_status (0);
866 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
, 0);
872 /* Called whenever we notice an exec or exit event, to handle
873 detaching or resuming a vfork parent. */
876 handle_vfork_child_exec_or_exit (int exec
)
878 struct inferior
*inf
= current_inferior ();
880 if (inf
->vfork_parent
)
882 int resume_parent
= -1;
884 /* This exec or exit marks the end of the shared memory region
885 between the parent and the child. If the user wanted to
886 detach from the parent, now is the time. */
888 if (inf
->vfork_parent
->pending_detach
)
890 struct thread_info
*tp
;
891 struct cleanup
*old_chain
;
892 struct program_space
*pspace
;
893 struct address_space
*aspace
;
895 /* follow-fork child, detach-on-fork on. */
897 inf
->vfork_parent
->pending_detach
= 0;
901 /* If we're handling a child exit, then inferior_ptid
902 points at the inferior's pid, not to a thread. */
903 old_chain
= save_inferior_ptid ();
904 save_current_program_space ();
905 save_current_inferior ();
908 old_chain
= save_current_space_and_thread ();
910 /* We're letting loose of the parent. */
911 tp
= any_live_thread_of_process (inf
->vfork_parent
->pid
);
912 switch_to_thread (tp
->ptid
);
914 /* We're about to detach from the parent, which implicitly
915 removes breakpoints from its address space. There's a
916 catch here: we want to reuse the spaces for the child,
917 but, parent/child are still sharing the pspace at this
918 point, although the exec in reality makes the kernel give
919 the child a fresh set of new pages. The problem here is
920 that the breakpoints module being unaware of this, would
921 likely chose the child process to write to the parent
922 address space. Swapping the child temporarily away from
923 the spaces has the desired effect. Yes, this is "sort
926 pspace
= inf
->pspace
;
927 aspace
= inf
->aspace
;
931 if (debug_infrun
|| info_verbose
)
933 target_terminal_ours_for_output ();
937 fprintf_filtered (gdb_stdlog
,
938 _("Detaching vfork parent process "
939 "%d after child exec.\n"),
940 inf
->vfork_parent
->pid
);
944 fprintf_filtered (gdb_stdlog
,
945 _("Detaching vfork parent process "
946 "%d after child exit.\n"),
947 inf
->vfork_parent
->pid
);
951 target_detach (NULL
, 0);
954 inf
->pspace
= pspace
;
955 inf
->aspace
= aspace
;
957 do_cleanups (old_chain
);
961 /* We're staying attached to the parent, so, really give the
962 child a new address space. */
963 inf
->pspace
= add_program_space (maybe_new_address_space ());
964 inf
->aspace
= inf
->pspace
->aspace
;
966 set_current_program_space (inf
->pspace
);
968 resume_parent
= inf
->vfork_parent
->pid
;
970 /* Break the bonds. */
971 inf
->vfork_parent
->vfork_child
= NULL
;
975 struct cleanup
*old_chain
;
976 struct program_space
*pspace
;
978 /* If this is a vfork child exiting, then the pspace and
979 aspaces were shared with the parent. Since we're
980 reporting the process exit, we'll be mourning all that is
981 found in the address space, and switching to null_ptid,
982 preparing to start a new inferior. But, since we don't
983 want to clobber the parent's address/program spaces, we
984 go ahead and create a new one for this exiting
987 /* Switch to null_ptid, so that clone_program_space doesn't want
988 to read the selected frame of a dead process. */
989 old_chain
= save_inferior_ptid ();
990 inferior_ptid
= null_ptid
;
992 /* This inferior is dead, so avoid giving the breakpoints
993 module the option to write through to it (cloning a
994 program space resets breakpoints). */
997 pspace
= add_program_space (maybe_new_address_space ());
998 set_current_program_space (pspace
);
1000 inf
->symfile_flags
= SYMFILE_NO_READ
;
1001 clone_program_space (pspace
, inf
->vfork_parent
->pspace
);
1002 inf
->pspace
= pspace
;
1003 inf
->aspace
= pspace
->aspace
;
1005 /* Put back inferior_ptid. We'll continue mourning this
1007 do_cleanups (old_chain
);
1009 resume_parent
= inf
->vfork_parent
->pid
;
1010 /* Break the bonds. */
1011 inf
->vfork_parent
->vfork_child
= NULL
;
1014 inf
->vfork_parent
= NULL
;
1016 gdb_assert (current_program_space
== inf
->pspace
);
1018 if (non_stop
&& resume_parent
!= -1)
1020 /* If the user wanted the parent to be running, let it go
1022 struct cleanup
*old_chain
= make_cleanup_restore_current_thread ();
1025 fprintf_unfiltered (gdb_stdlog
,
1026 "infrun: resuming vfork parent process %d\n",
1029 iterate_over_threads (proceed_after_vfork_done
, &resume_parent
);
1031 do_cleanups (old_chain
);
1036 /* Enum strings for "set|show follow-exec-mode". */
1038 static const char follow_exec_mode_new
[] = "new";
1039 static const char follow_exec_mode_same
[] = "same";
1040 static const char *const follow_exec_mode_names
[] =
1042 follow_exec_mode_new
,
1043 follow_exec_mode_same
,
1047 static const char *follow_exec_mode_string
= follow_exec_mode_same
;
1049 show_follow_exec_mode_string (struct ui_file
*file
, int from_tty
,
1050 struct cmd_list_element
*c
, const char *value
)
1052 fprintf_filtered (file
, _("Follow exec mode is \"%s\".\n"), value
);
1055 /* EXECD_PATHNAME is assumed to be non-NULL. */
1058 follow_exec (ptid_t ptid
, char *execd_pathname
)
1060 struct thread_info
*th
, *tmp
;
1061 struct inferior
*inf
= current_inferior ();
1062 int pid
= ptid_get_pid (ptid
);
1064 /* This is an exec event that we actually wish to pay attention to.
1065 Refresh our symbol table to the newly exec'd program, remove any
1066 momentary bp's, etc.
1068 If there are breakpoints, they aren't really inserted now,
1069 since the exec() transformed our inferior into a fresh set
1072 We want to preserve symbolic breakpoints on the list, since
1073 we have hopes that they can be reset after the new a.out's
1074 symbol table is read.
1076 However, any "raw" breakpoints must be removed from the list
1077 (e.g., the solib bp's), since their address is probably invalid
1080 And, we DON'T want to call delete_breakpoints() here, since
1081 that may write the bp's "shadow contents" (the instruction
1082 value that was overwritten witha TRAP instruction). Since
1083 we now have a new a.out, those shadow contents aren't valid. */
1085 mark_breakpoints_out ();
1087 /* The target reports the exec event to the main thread, even if
1088 some other thread does the exec, and even if the main thread was
1089 stopped or already gone. We may still have non-leader threads of
1090 the process on our list. E.g., on targets that don't have thread
1091 exit events (like remote); or on native Linux in non-stop mode if
1092 there were only two threads in the inferior and the non-leader
1093 one is the one that execs (and nothing forces an update of the
1094 thread list up to here). When debugging remotely, it's best to
1095 avoid extra traffic, when possible, so avoid syncing the thread
1096 list with the target, and instead go ahead and delete all threads
1097 of the process but one that reported the event. Note this must
1098 be done before calling update_breakpoints_after_exec, as
1099 otherwise clearing the threads' resources would reference stale
1100 thread breakpoints -- it may have been one of these threads that
1101 stepped across the exec. We could just clear their stepping
1102 states, but as long as we're iterating, might as well delete
1103 them. Deleting them now rather than at the next user-visible
1104 stop provides a nicer sequence of events for user and MI
1106 ALL_NON_EXITED_THREADS_SAFE (th
, tmp
)
1107 if (ptid_get_pid (th
->ptid
) == pid
&& !ptid_equal (th
->ptid
, ptid
))
1108 delete_thread (th
->ptid
);
1110 /* We also need to clear any left over stale state for the
1111 leader/event thread. E.g., if there was any step-resume
1112 breakpoint or similar, it's gone now. We cannot truly
1113 step-to-next statement through an exec(). */
1114 th
= inferior_thread ();
1115 th
->control
.step_resume_breakpoint
= NULL
;
1116 th
->control
.exception_resume_breakpoint
= NULL
;
1117 th
->control
.single_step_breakpoints
= NULL
;
1118 th
->control
.step_range_start
= 0;
1119 th
->control
.step_range_end
= 0;
1121 /* The user may have had the main thread held stopped in the
1122 previous image (e.g., schedlock on, or non-stop). Release
1124 th
->stop_requested
= 0;
1126 update_breakpoints_after_exec ();
1128 /* What is this a.out's name? */
1129 printf_unfiltered (_("%s is executing new program: %s\n"),
1130 target_pid_to_str (inferior_ptid
),
1133 /* We've followed the inferior through an exec. Therefore, the
1134 inferior has essentially been killed & reborn. */
1136 gdb_flush (gdb_stdout
);
1138 breakpoint_init_inferior (inf_execd
);
1140 if (gdb_sysroot
&& *gdb_sysroot
)
1142 char *name
= alloca (strlen (gdb_sysroot
)
1143 + strlen (execd_pathname
)
1146 strcpy (name
, gdb_sysroot
);
1147 strcat (name
, execd_pathname
);
1148 execd_pathname
= name
;
1151 /* Reset the shared library package. This ensures that we get a
1152 shlib event when the child reaches "_start", at which point the
1153 dld will have had a chance to initialize the child. */
1154 /* Also, loading a symbol file below may trigger symbol lookups, and
1155 we don't want those to be satisfied by the libraries of the
1156 previous incarnation of this process. */
1157 no_shared_libraries (NULL
, 0);
1159 if (follow_exec_mode_string
== follow_exec_mode_new
)
1161 struct program_space
*pspace
;
1163 /* The user wants to keep the old inferior and program spaces
1164 around. Create a new fresh one, and switch to it. */
1166 inf
= add_inferior (current_inferior ()->pid
);
1167 pspace
= add_program_space (maybe_new_address_space ());
1168 inf
->pspace
= pspace
;
1169 inf
->aspace
= pspace
->aspace
;
1171 exit_inferior_num_silent (current_inferior ()->num
);
1173 set_current_inferior (inf
);
1174 set_current_program_space (pspace
);
1178 /* The old description may no longer be fit for the new image.
1179 E.g, a 64-bit process exec'ed a 32-bit process. Clear the
1180 old description; we'll read a new one below. No need to do
1181 this on "follow-exec-mode new", as the old inferior stays
1182 around (its description is later cleared/refetched on
1184 target_clear_description ();
1187 gdb_assert (current_program_space
== inf
->pspace
);
1189 /* That a.out is now the one to use. */
1190 exec_file_attach (execd_pathname
, 0);
1192 /* SYMFILE_DEFER_BP_RESET is used as the proper displacement for PIE
1193 (Position Independent Executable) main symbol file will get applied by
1194 solib_create_inferior_hook below. breakpoint_re_set would fail to insert
1195 the breakpoints with the zero displacement. */
1197 symbol_file_add (execd_pathname
,
1199 | SYMFILE_MAINLINE
| SYMFILE_DEFER_BP_RESET
),
1202 if ((inf
->symfile_flags
& SYMFILE_NO_READ
) == 0)
1203 set_initial_language ();
1205 /* If the target can specify a description, read it. Must do this
1206 after flipping to the new executable (because the target supplied
1207 description must be compatible with the executable's
1208 architecture, and the old executable may e.g., be 32-bit, while
1209 the new one 64-bit), and before anything involving memory or
1211 target_find_description ();
1213 solib_create_inferior_hook (0);
1215 jit_inferior_created_hook ();
1217 breakpoint_re_set ();
1219 /* Reinsert all breakpoints. (Those which were symbolic have
1220 been reset to the proper address in the new a.out, thanks
1221 to symbol_file_command...). */
1222 insert_breakpoints ();
1224 /* The next resume of this inferior should bring it to the shlib
1225 startup breakpoints. (If the user had also set bp's on
1226 "main" from the old (parent) process, then they'll auto-
1227 matically get reset there in the new process.). */
1230 /* Info about an instruction that is being stepped over. */
1232 struct step_over_info
1234 /* If we're stepping past a breakpoint, this is the address space
1235 and address of the instruction the breakpoint is set at. We'll
1236 skip inserting all breakpoints here. Valid iff ASPACE is
1238 struct address_space
*aspace
;
1241 /* The instruction being stepped over triggers a nonsteppable
1242 watchpoint. If true, we'll skip inserting watchpoints. */
1243 int nonsteppable_watchpoint_p
;
1246 /* The step-over info of the location that is being stepped over.
1248 Note that with async/breakpoint always-inserted mode, a user might
1249 set a new breakpoint/watchpoint/etc. exactly while a breakpoint is
1250 being stepped over. As setting a new breakpoint inserts all
1251 breakpoints, we need to make sure the breakpoint being stepped over
1252 isn't inserted then. We do that by only clearing the step-over
1253 info when the step-over is actually finished (or aborted).
1255 Presently GDB can only step over one breakpoint at any given time.
1256 Given threads that can't run code in the same address space as the
1257 breakpoint's can't really miss the breakpoint, GDB could be taught
1258 to step-over at most one breakpoint per address space (so this info
1259 could move to the address space object if/when GDB is extended).
1260 The set of breakpoints being stepped over will normally be much
1261 smaller than the set of all breakpoints, so a flag in the
1262 breakpoint location structure would be wasteful. A separate list
1263 also saves complexity and run-time, as otherwise we'd have to go
1264 through all breakpoint locations clearing their flag whenever we
1265 start a new sequence. Similar considerations weigh against storing
1266 this info in the thread object. Plus, not all step overs actually
1267 have breakpoint locations -- e.g., stepping past a single-step
1268 breakpoint, or stepping to complete a non-continuable
1270 static struct step_over_info step_over_info
;
1272 /* Record the address of the breakpoint/instruction we're currently
1276 set_step_over_info (struct address_space
*aspace
, CORE_ADDR address
,
1277 int nonsteppable_watchpoint_p
)
1279 step_over_info
.aspace
= aspace
;
1280 step_over_info
.address
= address
;
1281 step_over_info
.nonsteppable_watchpoint_p
= nonsteppable_watchpoint_p
;
1284 /* Called when we're not longer stepping over a breakpoint / an
1285 instruction, so all breakpoints are free to be (re)inserted. */
1288 clear_step_over_info (void)
1290 step_over_info
.aspace
= NULL
;
1291 step_over_info
.address
= 0;
1292 step_over_info
.nonsteppable_watchpoint_p
= 0;
1298 stepping_past_instruction_at (struct address_space
*aspace
,
1301 return (step_over_info
.aspace
!= NULL
1302 && breakpoint_address_match (aspace
, address
,
1303 step_over_info
.aspace
,
1304 step_over_info
.address
));
1310 stepping_past_nonsteppable_watchpoint (void)
1312 return step_over_info
.nonsteppable_watchpoint_p
;
1315 /* Returns true if step-over info is valid. */
1318 step_over_info_valid_p (void)
1320 return (step_over_info
.aspace
!= NULL
1321 || stepping_past_nonsteppable_watchpoint ());
1325 /* Displaced stepping. */
1327 /* In non-stop debugging mode, we must take special care to manage
1328 breakpoints properly; in particular, the traditional strategy for
1329 stepping a thread past a breakpoint it has hit is unsuitable.
1330 'Displaced stepping' is a tactic for stepping one thread past a
1331 breakpoint it has hit while ensuring that other threads running
1332 concurrently will hit the breakpoint as they should.
1334 The traditional way to step a thread T off a breakpoint in a
1335 multi-threaded program in all-stop mode is as follows:
1337 a0) Initially, all threads are stopped, and breakpoints are not
1339 a1) We single-step T, leaving breakpoints uninserted.
1340 a2) We insert breakpoints, and resume all threads.
1342 In non-stop debugging, however, this strategy is unsuitable: we
1343 don't want to have to stop all threads in the system in order to
1344 continue or step T past a breakpoint. Instead, we use displaced
1347 n0) Initially, T is stopped, other threads are running, and
1348 breakpoints are inserted.
1349 n1) We copy the instruction "under" the breakpoint to a separate
1350 location, outside the main code stream, making any adjustments
1351 to the instruction, register, and memory state as directed by
1353 n2) We single-step T over the instruction at its new location.
1354 n3) We adjust the resulting register and memory state as directed
1355 by T's architecture. This includes resetting T's PC to point
1356 back into the main instruction stream.
1359 This approach depends on the following gdbarch methods:
1361 - gdbarch_max_insn_length and gdbarch_displaced_step_location
1362 indicate where to copy the instruction, and how much space must
1363 be reserved there. We use these in step n1.
1365 - gdbarch_displaced_step_copy_insn copies a instruction to a new
1366 address, and makes any necessary adjustments to the instruction,
1367 register contents, and memory. We use this in step n1.
1369 - gdbarch_displaced_step_fixup adjusts registers and memory after
1370 we have successfuly single-stepped the instruction, to yield the
1371 same effect the instruction would have had if we had executed it
1372 at its original address. We use this in step n3.
1374 - gdbarch_displaced_step_free_closure provides cleanup.
1376 The gdbarch_displaced_step_copy_insn and
1377 gdbarch_displaced_step_fixup functions must be written so that
1378 copying an instruction with gdbarch_displaced_step_copy_insn,
1379 single-stepping across the copied instruction, and then applying
1380 gdbarch_displaced_insn_fixup should have the same effects on the
1381 thread's memory and registers as stepping the instruction in place
1382 would have. Exactly which responsibilities fall to the copy and
1383 which fall to the fixup is up to the author of those functions.
1385 See the comments in gdbarch.sh for details.
1387 Note that displaced stepping and software single-step cannot
1388 currently be used in combination, although with some care I think
1389 they could be made to. Software single-step works by placing
1390 breakpoints on all possible subsequent instructions; if the
1391 displaced instruction is a PC-relative jump, those breakpoints
1392 could fall in very strange places --- on pages that aren't
1393 executable, or at addresses that are not proper instruction
1394 boundaries. (We do generally let other threads run while we wait
1395 to hit the software single-step breakpoint, and they might
1396 encounter such a corrupted instruction.) One way to work around
1397 this would be to have gdbarch_displaced_step_copy_insn fully
1398 simulate the effect of PC-relative instructions (and return NULL)
1399 on architectures that use software single-stepping.
1401 In non-stop mode, we can have independent and simultaneous step
1402 requests, so more than one thread may need to simultaneously step
1403 over a breakpoint. The current implementation assumes there is
1404 only one scratch space per process. In this case, we have to
1405 serialize access to the scratch space. If thread A wants to step
1406 over a breakpoint, but we are currently waiting for some other
1407 thread to complete a displaced step, we leave thread A stopped and
1408 place it in the displaced_step_request_queue. Whenever a displaced
1409 step finishes, we pick the next thread in the queue and start a new
1410 displaced step operation on it. See displaced_step_prepare and
1411 displaced_step_fixup for details. */
1413 struct displaced_step_request
1416 struct displaced_step_request
*next
;
1419 /* Per-inferior displaced stepping state. */
1420 struct displaced_step_inferior_state
1422 /* Pointer to next in linked list. */
1423 struct displaced_step_inferior_state
*next
;
1425 /* The process this displaced step state refers to. */
1428 /* A queue of pending displaced stepping requests. One entry per
1429 thread that needs to do a displaced step. */
1430 struct displaced_step_request
*step_request_queue
;
1432 /* If this is not null_ptid, this is the thread carrying out a
1433 displaced single-step in process PID. This thread's state will
1434 require fixing up once it has completed its step. */
1437 /* The architecture the thread had when we stepped it. */
1438 struct gdbarch
*step_gdbarch
;
1440 /* The closure provided gdbarch_displaced_step_copy_insn, to be used
1441 for post-step cleanup. */
1442 struct displaced_step_closure
*step_closure
;
1444 /* The address of the original instruction, and the copy we
1446 CORE_ADDR step_original
, step_copy
;
1448 /* Saved contents of copy area. */
1449 gdb_byte
*step_saved_copy
;
1452 /* The list of states of processes involved in displaced stepping
1454 static struct displaced_step_inferior_state
*displaced_step_inferior_states
;
1456 /* Get the displaced stepping state of process PID. */
1458 static struct displaced_step_inferior_state
*
1459 get_displaced_stepping_state (int pid
)
1461 struct displaced_step_inferior_state
*state
;
1463 for (state
= displaced_step_inferior_states
;
1465 state
= state
->next
)
1466 if (state
->pid
== pid
)
1472 /* Add a new displaced stepping state for process PID to the displaced
1473 stepping state list, or return a pointer to an already existing
1474 entry, if it already exists. Never returns NULL. */
1476 static struct displaced_step_inferior_state
*
1477 add_displaced_stepping_state (int pid
)
1479 struct displaced_step_inferior_state
*state
;
1481 for (state
= displaced_step_inferior_states
;
1483 state
= state
->next
)
1484 if (state
->pid
== pid
)
1487 state
= xcalloc (1, sizeof (*state
));
1489 state
->next
= displaced_step_inferior_states
;
1490 displaced_step_inferior_states
= state
;
1495 /* If inferior is in displaced stepping, and ADDR equals to starting address
1496 of copy area, return corresponding displaced_step_closure. Otherwise,
1499 struct displaced_step_closure
*
1500 get_displaced_step_closure_by_addr (CORE_ADDR addr
)
1502 struct displaced_step_inferior_state
*displaced
1503 = get_displaced_stepping_state (ptid_get_pid (inferior_ptid
));
1505 /* If checking the mode of displaced instruction in copy area. */
1506 if (displaced
&& !ptid_equal (displaced
->step_ptid
, null_ptid
)
1507 && (displaced
->step_copy
== addr
))
1508 return displaced
->step_closure
;
1513 /* Remove the displaced stepping state of process PID. */
1516 remove_displaced_stepping_state (int pid
)
1518 struct displaced_step_inferior_state
*it
, **prev_next_p
;
1520 gdb_assert (pid
!= 0);
1522 it
= displaced_step_inferior_states
;
1523 prev_next_p
= &displaced_step_inferior_states
;
1528 *prev_next_p
= it
->next
;
1533 prev_next_p
= &it
->next
;
1539 infrun_inferior_exit (struct inferior
*inf
)
1541 remove_displaced_stepping_state (inf
->pid
);
1544 /* If ON, and the architecture supports it, GDB will use displaced
1545 stepping to step over breakpoints. If OFF, or if the architecture
1546 doesn't support it, GDB will instead use the traditional
1547 hold-and-step approach. If AUTO (which is the default), GDB will
1548 decide which technique to use to step over breakpoints depending on
1549 which of all-stop or non-stop mode is active --- displaced stepping
1550 in non-stop mode; hold-and-step in all-stop mode. */
1552 static enum auto_boolean can_use_displaced_stepping
= AUTO_BOOLEAN_AUTO
;
1555 show_can_use_displaced_stepping (struct ui_file
*file
, int from_tty
,
1556 struct cmd_list_element
*c
,
1559 if (can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
)
1560 fprintf_filtered (file
,
1561 _("Debugger's willingness to use displaced stepping "
1562 "to step over breakpoints is %s (currently %s).\n"),
1563 value
, non_stop
? "on" : "off");
1565 fprintf_filtered (file
,
1566 _("Debugger's willingness to use displaced stepping "
1567 "to step over breakpoints is %s.\n"), value
);
1570 /* Return non-zero if displaced stepping can/should be used to step
1571 over breakpoints. */
1574 use_displaced_stepping (struct gdbarch
*gdbarch
)
1576 return (((can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
&& non_stop
)
1577 || can_use_displaced_stepping
== AUTO_BOOLEAN_TRUE
)
1578 && gdbarch_displaced_step_copy_insn_p (gdbarch
)
1579 && find_record_target () == NULL
);
1582 /* Clean out any stray displaced stepping state. */
1584 displaced_step_clear (struct displaced_step_inferior_state
*displaced
)
1586 /* Indicate that there is no cleanup pending. */
1587 displaced
->step_ptid
= null_ptid
;
1589 if (displaced
->step_closure
)
1591 gdbarch_displaced_step_free_closure (displaced
->step_gdbarch
,
1592 displaced
->step_closure
);
1593 displaced
->step_closure
= NULL
;
1598 displaced_step_clear_cleanup (void *arg
)
1600 struct displaced_step_inferior_state
*state
= arg
;
1602 displaced_step_clear (state
);
1605 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */
1607 displaced_step_dump_bytes (struct ui_file
*file
,
1608 const gdb_byte
*buf
,
1613 for (i
= 0; i
< len
; i
++)
1614 fprintf_unfiltered (file
, "%02x ", buf
[i
]);
1615 fputs_unfiltered ("\n", file
);
1618 /* Prepare to single-step, using displaced stepping.
1620 Note that we cannot use displaced stepping when we have a signal to
1621 deliver. If we have a signal to deliver and an instruction to step
1622 over, then after the step, there will be no indication from the
1623 target whether the thread entered a signal handler or ignored the
1624 signal and stepped over the instruction successfully --- both cases
1625 result in a simple SIGTRAP. In the first case we mustn't do a
1626 fixup, and in the second case we must --- but we can't tell which.
1627 Comments in the code for 'random signals' in handle_inferior_event
1628 explain how we handle this case instead.
1630 Returns 1 if preparing was successful -- this thread is going to be
1631 stepped now; or 0 if displaced stepping this thread got queued. */
1633 displaced_step_prepare (ptid_t ptid
)
1635 struct cleanup
*old_cleanups
, *ignore_cleanups
;
1636 struct thread_info
*tp
= find_thread_ptid (ptid
);
1637 struct regcache
*regcache
= get_thread_regcache (ptid
);
1638 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1639 CORE_ADDR original
, copy
;
1641 struct displaced_step_closure
*closure
;
1642 struct displaced_step_inferior_state
*displaced
;
1645 /* We should never reach this function if the architecture does not
1646 support displaced stepping. */
1647 gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch
));
1649 /* Disable range stepping while executing in the scratch pad. We
1650 want a single-step even if executing the displaced instruction in
1651 the scratch buffer lands within the stepping range (e.g., a
1653 tp
->control
.may_range_step
= 0;
1655 /* We have to displaced step one thread at a time, as we only have
1656 access to a single scratch space per inferior. */
1658 displaced
= add_displaced_stepping_state (ptid_get_pid (ptid
));
1660 if (!ptid_equal (displaced
->step_ptid
, null_ptid
))
1662 /* Already waiting for a displaced step to finish. Defer this
1663 request and place in queue. */
1664 struct displaced_step_request
*req
, *new_req
;
1666 if (debug_displaced
)
1667 fprintf_unfiltered (gdb_stdlog
,
1668 "displaced: defering step of %s\n",
1669 target_pid_to_str (ptid
));
1671 new_req
= xmalloc (sizeof (*new_req
));
1672 new_req
->ptid
= ptid
;
1673 new_req
->next
= NULL
;
1675 if (displaced
->step_request_queue
)
1677 for (req
= displaced
->step_request_queue
;
1681 req
->next
= new_req
;
1684 displaced
->step_request_queue
= new_req
;
1690 if (debug_displaced
)
1691 fprintf_unfiltered (gdb_stdlog
,
1692 "displaced: stepping %s now\n",
1693 target_pid_to_str (ptid
));
1696 displaced_step_clear (displaced
);
1698 old_cleanups
= save_inferior_ptid ();
1699 inferior_ptid
= ptid
;
1701 original
= regcache_read_pc (regcache
);
1703 copy
= gdbarch_displaced_step_location (gdbarch
);
1704 len
= gdbarch_max_insn_length (gdbarch
);
1706 /* Save the original contents of the copy area. */
1707 displaced
->step_saved_copy
= xmalloc (len
);
1708 ignore_cleanups
= make_cleanup (free_current_contents
,
1709 &displaced
->step_saved_copy
);
1710 status
= target_read_memory (copy
, displaced
->step_saved_copy
, len
);
1712 throw_error (MEMORY_ERROR
,
1713 _("Error accessing memory address %s (%s) for "
1714 "displaced-stepping scratch space."),
1715 paddress (gdbarch
, copy
), safe_strerror (status
));
1716 if (debug_displaced
)
1718 fprintf_unfiltered (gdb_stdlog
, "displaced: saved %s: ",
1719 paddress (gdbarch
, copy
));
1720 displaced_step_dump_bytes (gdb_stdlog
,
1721 displaced
->step_saved_copy
,
1725 closure
= gdbarch_displaced_step_copy_insn (gdbarch
,
1726 original
, copy
, regcache
);
1728 /* We don't support the fully-simulated case at present. */
1729 gdb_assert (closure
);
1731 /* Save the information we need to fix things up if the step
1733 displaced
->step_ptid
= ptid
;
1734 displaced
->step_gdbarch
= gdbarch
;
1735 displaced
->step_closure
= closure
;
1736 displaced
->step_original
= original
;
1737 displaced
->step_copy
= copy
;
1739 make_cleanup (displaced_step_clear_cleanup
, displaced
);
1741 /* Resume execution at the copy. */
1742 regcache_write_pc (regcache
, copy
);
1744 discard_cleanups (ignore_cleanups
);
1746 do_cleanups (old_cleanups
);
1748 if (debug_displaced
)
1749 fprintf_unfiltered (gdb_stdlog
, "displaced: displaced pc to %s\n",
1750 paddress (gdbarch
, copy
));
1756 write_memory_ptid (ptid_t ptid
, CORE_ADDR memaddr
,
1757 const gdb_byte
*myaddr
, int len
)
1759 struct cleanup
*ptid_cleanup
= save_inferior_ptid ();
1761 inferior_ptid
= ptid
;
1762 write_memory (memaddr
, myaddr
, len
);
1763 do_cleanups (ptid_cleanup
);
1766 /* Restore the contents of the copy area for thread PTID. */
1769 displaced_step_restore (struct displaced_step_inferior_state
*displaced
,
1772 ULONGEST len
= gdbarch_max_insn_length (displaced
->step_gdbarch
);
1774 write_memory_ptid (ptid
, displaced
->step_copy
,
1775 displaced
->step_saved_copy
, len
);
1776 if (debug_displaced
)
1777 fprintf_unfiltered (gdb_stdlog
, "displaced: restored %s %s\n",
1778 target_pid_to_str (ptid
),
1779 paddress (displaced
->step_gdbarch
,
1780 displaced
->step_copy
));
1784 displaced_step_fixup (ptid_t event_ptid
, enum gdb_signal signal
)
1786 struct cleanup
*old_cleanups
;
1787 struct displaced_step_inferior_state
*displaced
1788 = get_displaced_stepping_state (ptid_get_pid (event_ptid
));
1790 /* Was any thread of this process doing a displaced step? */
1791 if (displaced
== NULL
)
1794 /* Was this event for the pid we displaced? */
1795 if (ptid_equal (displaced
->step_ptid
, null_ptid
)
1796 || ! ptid_equal (displaced
->step_ptid
, event_ptid
))
1799 old_cleanups
= make_cleanup (displaced_step_clear_cleanup
, displaced
);
1801 displaced_step_restore (displaced
, displaced
->step_ptid
);
1803 /* Did the instruction complete successfully? */
1804 if (signal
== GDB_SIGNAL_TRAP
)
1806 /* Fixup may need to read memory/registers. Switch to the
1807 thread that we're fixing up. */
1808 switch_to_thread (event_ptid
);
1810 /* Fix up the resulting state. */
1811 gdbarch_displaced_step_fixup (displaced
->step_gdbarch
,
1812 displaced
->step_closure
,
1813 displaced
->step_original
,
1814 displaced
->step_copy
,
1815 get_thread_regcache (displaced
->step_ptid
));
1819 /* Since the instruction didn't complete, all we can do is
1821 struct regcache
*regcache
= get_thread_regcache (event_ptid
);
1822 CORE_ADDR pc
= regcache_read_pc (regcache
);
1824 pc
= displaced
->step_original
+ (pc
- displaced
->step_copy
);
1825 regcache_write_pc (regcache
, pc
);
1828 do_cleanups (old_cleanups
);
1830 displaced
->step_ptid
= null_ptid
;
1832 /* Are there any pending displaced stepping requests? If so, run
1833 one now. Leave the state object around, since we're likely to
1834 need it again soon. */
1835 while (displaced
->step_request_queue
)
1837 struct displaced_step_request
*head
;
1839 struct regcache
*regcache
;
1840 struct gdbarch
*gdbarch
;
1841 CORE_ADDR actual_pc
;
1842 struct address_space
*aspace
;
1844 head
= displaced
->step_request_queue
;
1846 displaced
->step_request_queue
= head
->next
;
1849 context_switch (ptid
);
1851 regcache
= get_thread_regcache (ptid
);
1852 actual_pc
= regcache_read_pc (regcache
);
1853 aspace
= get_regcache_aspace (regcache
);
1855 if (breakpoint_here_p (aspace
, actual_pc
))
1857 if (debug_displaced
)
1858 fprintf_unfiltered (gdb_stdlog
,
1859 "displaced: stepping queued %s now\n",
1860 target_pid_to_str (ptid
));
1862 displaced_step_prepare (ptid
);
1864 gdbarch
= get_regcache_arch (regcache
);
1866 if (debug_displaced
)
1868 CORE_ADDR actual_pc
= regcache_read_pc (regcache
);
1871 fprintf_unfiltered (gdb_stdlog
, "displaced: run %s: ",
1872 paddress (gdbarch
, actual_pc
));
1873 read_memory (actual_pc
, buf
, sizeof (buf
));
1874 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
1877 if (gdbarch_displaced_step_hw_singlestep (gdbarch
,
1878 displaced
->step_closure
))
1879 target_resume (ptid
, 1, GDB_SIGNAL_0
);
1881 target_resume (ptid
, 0, GDB_SIGNAL_0
);
1883 /* Done, we're stepping a thread. */
1889 struct thread_info
*tp
= inferior_thread ();
1891 /* The breakpoint we were sitting under has since been
1893 tp
->control
.trap_expected
= 0;
1895 /* Go back to what we were trying to do. */
1896 step
= currently_stepping (tp
);
1898 if (debug_displaced
)
1899 fprintf_unfiltered (gdb_stdlog
,
1900 "displaced: breakpoint is gone: %s, step(%d)\n",
1901 target_pid_to_str (tp
->ptid
), step
);
1903 target_resume (ptid
, step
, GDB_SIGNAL_0
);
1904 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
1906 /* This request was discarded. See if there's any other
1907 thread waiting for its turn. */
1912 /* Update global variables holding ptids to hold NEW_PTID if they were
1913 holding OLD_PTID. */
1915 infrun_thread_ptid_changed (ptid_t old_ptid
, ptid_t new_ptid
)
1917 struct displaced_step_request
*it
;
1918 struct displaced_step_inferior_state
*displaced
;
1920 if (ptid_equal (inferior_ptid
, old_ptid
))
1921 inferior_ptid
= new_ptid
;
1923 for (displaced
= displaced_step_inferior_states
;
1925 displaced
= displaced
->next
)
1927 if (ptid_equal (displaced
->step_ptid
, old_ptid
))
1928 displaced
->step_ptid
= new_ptid
;
1930 for (it
= displaced
->step_request_queue
; it
; it
= it
->next
)
1931 if (ptid_equal (it
->ptid
, old_ptid
))
1932 it
->ptid
= new_ptid
;
1939 /* Things to clean up if we QUIT out of resume (). */
1941 resume_cleanups (void *ignore
)
1943 if (!ptid_equal (inferior_ptid
, null_ptid
))
1944 delete_single_step_breakpoints (inferior_thread ());
1949 static const char schedlock_off
[] = "off";
1950 static const char schedlock_on
[] = "on";
1951 static const char schedlock_step
[] = "step";
1952 static const char *const scheduler_enums
[] = {
1958 static const char *scheduler_mode
= schedlock_off
;
1960 show_scheduler_mode (struct ui_file
*file
, int from_tty
,
1961 struct cmd_list_element
*c
, const char *value
)
1963 fprintf_filtered (file
,
1964 _("Mode for locking scheduler "
1965 "during execution is \"%s\".\n"),
1970 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
1972 if (!target_can_lock_scheduler
)
1974 scheduler_mode
= schedlock_off
;
1975 error (_("Target '%s' cannot support this command."), target_shortname
);
1979 /* True if execution commands resume all threads of all processes by
1980 default; otherwise, resume only threads of the current inferior
1982 int sched_multi
= 0;
1984 /* Try to setup for software single stepping over the specified location.
1985 Return 1 if target_resume() should use hardware single step.
1987 GDBARCH the current gdbarch.
1988 PC the location to step over. */
1991 maybe_software_singlestep (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
1995 if (execution_direction
== EXEC_FORWARD
1996 && gdbarch_software_single_step_p (gdbarch
)
1997 && gdbarch_software_single_step (gdbarch
, get_current_frame ()))
2005 user_visible_resume_ptid (int step
)
2007 /* By default, resume all threads of all processes. */
2008 ptid_t resume_ptid
= RESUME_ALL
;
2010 /* Maybe resume only all threads of the current process. */
2011 if (!sched_multi
&& target_supports_multi_process ())
2013 resume_ptid
= pid_to_ptid (ptid_get_pid (inferior_ptid
));
2016 /* Maybe resume a single thread after all. */
2019 /* With non-stop mode on, threads are always handled
2021 resume_ptid
= inferior_ptid
;
2023 else if ((scheduler_mode
== schedlock_on
)
2024 || (scheduler_mode
== schedlock_step
&& step
))
2026 /* User-settable 'scheduler' mode requires solo thread resume. */
2027 resume_ptid
= inferior_ptid
;
2030 /* We may actually resume fewer threads at first, e.g., if a thread
2031 is stopped at a breakpoint that needs stepping-off, but that
2032 should not be visible to the user/frontend, and neither should
2033 the frontend/user be allowed to proceed any of the threads that
2034 happen to be stopped for internal run control handling, if a
2035 previous command wanted them resumed. */
2039 /* Resume the inferior, but allow a QUIT. This is useful if the user
2040 wants to interrupt some lengthy single-stepping operation
2041 (for child processes, the SIGINT goes to the inferior, and so
2042 we get a SIGINT random_signal, but for remote debugging and perhaps
2043 other targets, that's not true).
2045 STEP nonzero if we should step (zero to continue instead).
2046 SIG is the signal to give the inferior (zero for none). */
2048 resume (int step
, enum gdb_signal sig
)
2050 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
2051 struct regcache
*regcache
= get_current_regcache ();
2052 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
2053 struct thread_info
*tp
= inferior_thread ();
2054 CORE_ADDR pc
= regcache_read_pc (regcache
);
2055 struct address_space
*aspace
= get_regcache_aspace (regcache
);
2057 /* From here on, this represents the caller's step vs continue
2058 request, while STEP represents what we'll actually request the
2059 target to do. STEP can decay from a step to a continue, if e.g.,
2060 we need to implement single-stepping with breakpoints (software
2061 single-step). When deciding whether "set scheduler-locking step"
2062 applies, it's the callers intention that counts. */
2063 const int entry_step
= step
;
2065 tp
->stepped_breakpoint
= 0;
2069 if (current_inferior ()->waiting_for_vfork_done
)
2071 /* Don't try to single-step a vfork parent that is waiting for
2072 the child to get out of the shared memory region (by exec'ing
2073 or exiting). This is particularly important on software
2074 single-step archs, as the child process would trip on the
2075 software single step breakpoint inserted for the parent
2076 process. Since the parent will not actually execute any
2077 instruction until the child is out of the shared region (such
2078 are vfork's semantics), it is safe to simply continue it.
2079 Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for
2080 the parent, and tell it to `keep_going', which automatically
2081 re-sets it stepping. */
2083 fprintf_unfiltered (gdb_stdlog
,
2084 "infrun: resume : clear step\n");
2089 fprintf_unfiltered (gdb_stdlog
,
2090 "infrun: resume (step=%d, signal=%s), "
2091 "trap_expected=%d, current thread [%s] at %s\n",
2092 step
, gdb_signal_to_symbol_string (sig
),
2093 tp
->control
.trap_expected
,
2094 target_pid_to_str (inferior_ptid
),
2095 paddress (gdbarch
, pc
));
2097 /* Normally, by the time we reach `resume', the breakpoints are either
2098 removed or inserted, as appropriate. The exception is if we're sitting
2099 at a permanent breakpoint; we need to step over it, but permanent
2100 breakpoints can't be removed. So we have to test for it here. */
2101 if (breakpoint_here_p (aspace
, pc
) == permanent_breakpoint_here
)
2103 if (sig
!= GDB_SIGNAL_0
)
2105 /* We have a signal to pass to the inferior. The resume
2106 may, or may not take us to the signal handler. If this
2107 is a step, we'll need to stop in the signal handler, if
2108 there's one, (if the target supports stepping into
2109 handlers), or in the next mainline instruction, if
2110 there's no handler. If this is a continue, we need to be
2111 sure to run the handler with all breakpoints inserted.
2112 In all cases, set a breakpoint at the current address
2113 (where the handler returns to), and once that breakpoint
2114 is hit, resume skipping the permanent breakpoint. If
2115 that breakpoint isn't hit, then we've stepped into the
2116 signal handler (or hit some other event). We'll delete
2117 the step-resume breakpoint then. */
2120 fprintf_unfiltered (gdb_stdlog
,
2121 "infrun: resume: skipping permanent breakpoint, "
2122 "deliver signal first\n");
2124 clear_step_over_info ();
2125 tp
->control
.trap_expected
= 0;
2127 if (tp
->control
.step_resume_breakpoint
== NULL
)
2129 /* Set a "high-priority" step-resume, as we don't want
2130 user breakpoints at PC to trigger (again) when this
2132 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
2133 gdb_assert (tp
->control
.step_resume_breakpoint
->loc
->permanent
);
2135 tp
->step_after_step_resume_breakpoint
= step
;
2138 insert_breakpoints ();
2142 /* There's no signal to pass, we can go ahead and skip the
2143 permanent breakpoint manually. */
2145 fprintf_unfiltered (gdb_stdlog
,
2146 "infrun: resume: skipping permanent breakpoint\n");
2147 gdbarch_skip_permanent_breakpoint (gdbarch
, regcache
);
2148 /* Update pc to reflect the new address from which we will
2149 execute instructions. */
2150 pc
= regcache_read_pc (regcache
);
2154 /* We've already advanced the PC, so the stepping part
2155 is done. Now we need to arrange for a trap to be
2156 reported to handle_inferior_event. Set a breakpoint
2157 at the current PC, and run to it. Don't update
2158 prev_pc, because if we end in
2159 switch_back_to_stepping, we want the "expected thread
2160 advanced also" branch to be taken. IOW, we don't
2161 want this thread to step further from PC
2163 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
2164 insert_breakpoints ();
2166 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2167 /* We're continuing with all breakpoints inserted. It's
2168 safe to let the target bypass signals. */
2169 target_pass_signals ((int) GDB_SIGNAL_LAST
, signal_pass
);
2170 /* ... and safe to let other threads run, according to
2172 resume_ptid
= user_visible_resume_ptid (entry_step
);
2173 target_resume (resume_ptid
, 0, GDB_SIGNAL_0
);
2174 discard_cleanups (old_cleanups
);
2180 /* If we have a breakpoint to step over, make sure to do a single
2181 step only. Same if we have software watchpoints. */
2182 if (tp
->control
.trap_expected
|| bpstat_should_step ())
2183 tp
->control
.may_range_step
= 0;
2185 /* If enabled, step over breakpoints by executing a copy of the
2186 instruction at a different address.
2188 We can't use displaced stepping when we have a signal to deliver;
2189 the comments for displaced_step_prepare explain why. The
2190 comments in the handle_inferior event for dealing with 'random
2191 signals' explain what we do instead.
2193 We can't use displaced stepping when we are waiting for vfork_done
2194 event, displaced stepping breaks the vfork child similarly as single
2195 step software breakpoint. */
2196 if (use_displaced_stepping (gdbarch
)
2197 && tp
->control
.trap_expected
2198 && sig
== GDB_SIGNAL_0
2199 && !current_inferior ()->waiting_for_vfork_done
)
2201 struct displaced_step_inferior_state
*displaced
;
2203 if (!displaced_step_prepare (inferior_ptid
))
2205 /* Got placed in displaced stepping queue. Will be resumed
2206 later when all the currently queued displaced stepping
2207 requests finish. The thread is not executing at this
2208 point, and the call to set_executing will be made later.
2209 But we need to call set_running here, since from the
2210 user/frontend's point of view, threads were set running.
2211 Unless we're calling an inferior function, as in that
2212 case we pretend the inferior doesn't run at all. */
2213 if (!tp
->control
.in_infcall
)
2214 set_running (user_visible_resume_ptid (entry_step
), 1);
2215 discard_cleanups (old_cleanups
);
2219 /* Update pc to reflect the new address from which we will execute
2220 instructions due to displaced stepping. */
2221 pc
= regcache_read_pc (get_thread_regcache (inferior_ptid
));
2223 displaced
= get_displaced_stepping_state (ptid_get_pid (inferior_ptid
));
2224 step
= gdbarch_displaced_step_hw_singlestep (gdbarch
,
2225 displaced
->step_closure
);
2228 /* Do we need to do it the hard way, w/temp breakpoints? */
2230 step
= maybe_software_singlestep (gdbarch
, pc
);
2232 /* Currently, our software single-step implementation leads to different
2233 results than hardware single-stepping in one situation: when stepping
2234 into delivering a signal which has an associated signal handler,
2235 hardware single-step will stop at the first instruction of the handler,
2236 while software single-step will simply skip execution of the handler.
2238 For now, this difference in behavior is accepted since there is no
2239 easy way to actually implement single-stepping into a signal handler
2240 without kernel support.
2242 However, there is one scenario where this difference leads to follow-on
2243 problems: if we're stepping off a breakpoint by removing all breakpoints
2244 and then single-stepping. In this case, the software single-step
2245 behavior means that even if there is a *breakpoint* in the signal
2246 handler, GDB still would not stop.
2248 Fortunately, we can at least fix this particular issue. We detect
2249 here the case where we are about to deliver a signal while software
2250 single-stepping with breakpoints removed. In this situation, we
2251 revert the decisions to remove all breakpoints and insert single-
2252 step breakpoints, and instead we install a step-resume breakpoint
2253 at the current address, deliver the signal without stepping, and
2254 once we arrive back at the step-resume breakpoint, actually step
2255 over the breakpoint we originally wanted to step over. */
2256 if (thread_has_single_step_breakpoints_set (tp
)
2257 && sig
!= GDB_SIGNAL_0
2258 && step_over_info_valid_p ())
2260 /* If we have nested signals or a pending signal is delivered
2261 immediately after a handler returns, might might already have
2262 a step-resume breakpoint set on the earlier handler. We cannot
2263 set another step-resume breakpoint; just continue on until the
2264 original breakpoint is hit. */
2265 if (tp
->control
.step_resume_breakpoint
== NULL
)
2267 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
2268 tp
->step_after_step_resume_breakpoint
= 1;
2271 delete_single_step_breakpoints (tp
);
2273 clear_step_over_info ();
2274 tp
->control
.trap_expected
= 0;
2276 insert_breakpoints ();
2279 /* If STEP is set, it's a request to use hardware stepping
2280 facilities. But in that case, we should never
2281 use singlestep breakpoint. */
2282 gdb_assert (!(thread_has_single_step_breakpoints_set (tp
) && step
));
2284 /* Decide the set of threads to ask the target to resume. Start
2285 by assuming everything will be resumed, than narrow the set
2286 by applying increasingly restricting conditions. */
2287 resume_ptid
= user_visible_resume_ptid (entry_step
);
2289 /* Even if RESUME_PTID is a wildcard, and we end up resuming less
2290 (e.g., we might need to step over a breakpoint), from the
2291 user/frontend's point of view, all threads in RESUME_PTID are now
2292 running. Unless we're calling an inferior function, as in that
2293 case pretend we inferior doesn't run at all. */
2294 if (!tp
->control
.in_infcall
)
2295 set_running (resume_ptid
, 1);
2297 /* Maybe resume a single thread after all. */
2298 if ((step
|| thread_has_single_step_breakpoints_set (tp
))
2299 && tp
->control
.trap_expected
)
2301 /* We're allowing a thread to run past a breakpoint it has
2302 hit, by single-stepping the thread with the breakpoint
2303 removed. In which case, we need to single-step only this
2304 thread, and keep others stopped, as they can miss this
2305 breakpoint if allowed to run. */
2306 resume_ptid
= inferior_ptid
;
2309 if (execution_direction
!= EXEC_REVERSE
2310 && step
&& breakpoint_inserted_here_p (aspace
, pc
))
2312 /* The only case we currently need to step a breakpoint
2313 instruction is when we have a signal to deliver. See
2314 handle_signal_stop where we handle random signals that could
2315 take out us out of the stepping range. Normally, in that
2316 case we end up continuing (instead of stepping) over the
2317 signal handler with a breakpoint at PC, but there are cases
2318 where we should _always_ single-step, even if we have a
2319 step-resume breakpoint, like when a software watchpoint is
2320 set. Assuming single-stepping and delivering a signal at the
2321 same time would takes us to the signal handler, then we could
2322 have removed the breakpoint at PC to step over it. However,
2323 some hardware step targets (like e.g., Mac OS) can't step
2324 into signal handlers, and for those, we need to leave the
2325 breakpoint at PC inserted, as otherwise if the handler
2326 recurses and executes PC again, it'll miss the breakpoint.
2327 So we leave the breakpoint inserted anyway, but we need to
2328 record that we tried to step a breakpoint instruction, so
2329 that adjust_pc_after_break doesn't end up confused. */
2330 gdb_assert (sig
!= GDB_SIGNAL_0
);
2332 tp
->stepped_breakpoint
= 1;
2334 /* Most targets can step a breakpoint instruction, thus
2335 executing it normally. But if this one cannot, just
2336 continue and we will hit it anyway. */
2337 if (gdbarch_cannot_step_breakpoint (gdbarch
))
2342 && use_displaced_stepping (gdbarch
)
2343 && tp
->control
.trap_expected
)
2345 struct regcache
*resume_regcache
= get_thread_regcache (resume_ptid
);
2346 struct gdbarch
*resume_gdbarch
= get_regcache_arch (resume_regcache
);
2347 CORE_ADDR actual_pc
= regcache_read_pc (resume_regcache
);
2350 fprintf_unfiltered (gdb_stdlog
, "displaced: run %s: ",
2351 paddress (resume_gdbarch
, actual_pc
));
2352 read_memory (actual_pc
, buf
, sizeof (buf
));
2353 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
2356 if (tp
->control
.may_range_step
)
2358 /* If we're resuming a thread with the PC out of the step
2359 range, then we're doing some nested/finer run control
2360 operation, like stepping the thread out of the dynamic
2361 linker or the displaced stepping scratch pad. We
2362 shouldn't have allowed a range step then. */
2363 gdb_assert (pc_in_thread_step_range (pc
, tp
));
2366 /* Install inferior's terminal modes. */
2367 target_terminal_inferior ();
2369 /* Avoid confusing the next resume, if the next stop/resume
2370 happens to apply to another thread. */
2371 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2373 /* Advise target which signals may be handled silently. If we have
2374 removed breakpoints because we are stepping over one (in any
2375 thread), we need to receive all signals to avoid accidentally
2376 skipping a breakpoint during execution of a signal handler. */
2377 if (step_over_info_valid_p ())
2378 target_pass_signals (0, NULL
);
2380 target_pass_signals ((int) GDB_SIGNAL_LAST
, signal_pass
);
2382 target_resume (resume_ptid
, step
, sig
);
2384 discard_cleanups (old_cleanups
);
2389 /* Clear out all variables saying what to do when inferior is continued.
2390 First do this, then set the ones you want, then call `proceed'. */
2393 clear_proceed_status_thread (struct thread_info
*tp
)
2396 fprintf_unfiltered (gdb_stdlog
,
2397 "infrun: clear_proceed_status_thread (%s)\n",
2398 target_pid_to_str (tp
->ptid
));
2400 /* If this signal should not be seen by program, give it zero.
2401 Used for debugging signals. */
2402 if (!signal_pass_state (tp
->suspend
.stop_signal
))
2403 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2405 tp
->control
.trap_expected
= 0;
2406 tp
->control
.step_range_start
= 0;
2407 tp
->control
.step_range_end
= 0;
2408 tp
->control
.may_range_step
= 0;
2409 tp
->control
.step_frame_id
= null_frame_id
;
2410 tp
->control
.step_stack_frame_id
= null_frame_id
;
2411 tp
->control
.step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
2412 tp
->stop_requested
= 0;
2414 tp
->control
.stop_step
= 0;
2416 tp
->control
.proceed_to_finish
= 0;
2418 tp
->control
.command_interp
= NULL
;
2420 /* Discard any remaining commands or status from previous stop. */
2421 bpstat_clear (&tp
->control
.stop_bpstat
);
2425 clear_proceed_status (int step
)
2429 struct thread_info
*tp
;
2432 resume_ptid
= user_visible_resume_ptid (step
);
2434 /* In all-stop mode, delete the per-thread status of all threads
2435 we're about to resume, implicitly and explicitly. */
2436 ALL_NON_EXITED_THREADS (tp
)
2438 if (!ptid_match (tp
->ptid
, resume_ptid
))
2440 clear_proceed_status_thread (tp
);
2444 if (!ptid_equal (inferior_ptid
, null_ptid
))
2446 struct inferior
*inferior
;
2450 /* If in non-stop mode, only delete the per-thread status of
2451 the current thread. */
2452 clear_proceed_status_thread (inferior_thread ());
2455 inferior
= current_inferior ();
2456 inferior
->control
.stop_soon
= NO_STOP_QUIETLY
;
2459 stop_after_trap
= 0;
2461 clear_step_over_info ();
2463 observer_notify_about_to_proceed ();
2467 regcache_xfree (stop_registers
);
2468 stop_registers
= NULL
;
2472 /* Returns true if TP is still stopped at a breakpoint that needs
2473 stepping-over in order to make progress. If the breakpoint is gone
2474 meanwhile, we can skip the whole step-over dance. */
2477 thread_still_needs_step_over (struct thread_info
*tp
)
2479 if (tp
->stepping_over_breakpoint
)
2481 struct regcache
*regcache
= get_thread_regcache (tp
->ptid
);
2483 if (breakpoint_here_p (get_regcache_aspace (regcache
),
2484 regcache_read_pc (regcache
))
2485 == ordinary_breakpoint_here
)
2488 tp
->stepping_over_breakpoint
= 0;
2494 /* Returns true if scheduler locking applies. STEP indicates whether
2495 we're about to do a step/next-like command to a thread. */
2498 schedlock_applies (int step
)
2500 return (scheduler_mode
== schedlock_on
2501 || (scheduler_mode
== schedlock_step
2505 /* Look a thread other than EXCEPT that has previously reported a
2506 breakpoint event, and thus needs a step-over in order to make
2507 progress. Returns NULL is none is found. STEP indicates whether
2508 we're about to step the current thread, in order to decide whether
2509 "set scheduler-locking step" applies. */
2511 static struct thread_info
*
2512 find_thread_needs_step_over (int step
, struct thread_info
*except
)
2514 struct thread_info
*tp
, *current
;
2516 /* With non-stop mode on, threads are always handled individually. */
2517 gdb_assert (! non_stop
);
2519 current
= inferior_thread ();
2521 /* If scheduler locking applies, we can avoid iterating over all
2523 if (schedlock_applies (step
))
2525 if (except
!= current
2526 && thread_still_needs_step_over (current
))
2532 ALL_NON_EXITED_THREADS (tp
)
2534 /* Ignore the EXCEPT thread. */
2537 /* Ignore threads of processes we're not resuming. */
2539 && ptid_get_pid (tp
->ptid
) != ptid_get_pid (inferior_ptid
))
2542 if (thread_still_needs_step_over (tp
))
2549 /* Basic routine for continuing the program in various fashions.
2551 ADDR is the address to resume at, or -1 for resume where stopped.
2552 SIGGNAL is the signal to give it, or 0 for none,
2553 or -1 for act according to how it stopped.
2554 STEP is nonzero if should trap after one instruction.
2555 -1 means return after that and print nothing.
2556 You should probably set various step_... variables
2557 before calling here, if you are stepping.
2559 You should call clear_proceed_status before calling proceed. */
2562 proceed (CORE_ADDR addr
, enum gdb_signal siggnal
, int step
)
2564 struct regcache
*regcache
;
2565 struct gdbarch
*gdbarch
;
2566 struct thread_info
*tp
;
2568 struct address_space
*aspace
;
2570 /* If we're stopped at a fork/vfork, follow the branch set by the
2571 "set follow-fork-mode" command; otherwise, we'll just proceed
2572 resuming the current thread. */
2573 if (!follow_fork ())
2575 /* The target for some reason decided not to resume. */
2577 if (target_can_async_p ())
2578 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
2582 /* We'll update this if & when we switch to a new thread. */
2583 previous_inferior_ptid
= inferior_ptid
;
2585 regcache
= get_current_regcache ();
2586 gdbarch
= get_regcache_arch (regcache
);
2587 aspace
= get_regcache_aspace (regcache
);
2588 pc
= regcache_read_pc (regcache
);
2589 tp
= inferior_thread ();
2592 step_start_function
= find_pc_function (pc
);
2594 stop_after_trap
= 1;
2596 /* Fill in with reasonable starting values. */
2597 init_thread_stepping_state (tp
);
2599 if (addr
== (CORE_ADDR
) -1)
2602 && breakpoint_here_p (aspace
, pc
) == ordinary_breakpoint_here
2603 && execution_direction
!= EXEC_REVERSE
)
2604 /* There is a breakpoint at the address we will resume at,
2605 step one instruction before inserting breakpoints so that
2606 we do not stop right away (and report a second hit at this
2609 Note, we don't do this in reverse, because we won't
2610 actually be executing the breakpoint insn anyway.
2611 We'll be (un-)executing the previous instruction. */
2612 tp
->stepping_over_breakpoint
= 1;
2613 else if (gdbarch_single_step_through_delay_p (gdbarch
)
2614 && gdbarch_single_step_through_delay (gdbarch
,
2615 get_current_frame ()))
2616 /* We stepped onto an instruction that needs to be stepped
2617 again before re-inserting the breakpoint, do so. */
2618 tp
->stepping_over_breakpoint
= 1;
2622 regcache_write_pc (regcache
, addr
);
2625 if (siggnal
!= GDB_SIGNAL_DEFAULT
)
2626 tp
->suspend
.stop_signal
= siggnal
;
2628 /* Record the interpreter that issued the execution command that
2629 caused this thread to resume. If the top level interpreter is
2630 MI/async, and the execution command was a CLI command
2631 (next/step/etc.), we'll want to print stop event output to the MI
2632 console channel (the stepped-to line, etc.), as if the user
2633 entered the execution command on a real GDB console. */
2634 inferior_thread ()->control
.command_interp
= command_interp ();
2637 fprintf_unfiltered (gdb_stdlog
,
2638 "infrun: proceed (addr=%s, signal=%s, step=%d)\n",
2639 paddress (gdbarch
, addr
),
2640 gdb_signal_to_symbol_string (siggnal
), step
);
2643 /* In non-stop, each thread is handled individually. The context
2644 must already be set to the right thread here. */
2648 struct thread_info
*step_over
;
2650 /* In a multi-threaded task we may select another thread and
2651 then continue or step.
2653 But if the old thread was stopped at a breakpoint, it will
2654 immediately cause another breakpoint stop without any
2655 execution (i.e. it will report a breakpoint hit incorrectly).
2656 So we must step over it first.
2658 Look for a thread other than the current (TP) that reported a
2659 breakpoint hit and hasn't been resumed yet since. */
2660 step_over
= find_thread_needs_step_over (step
, tp
);
2661 if (step_over
!= NULL
)
2664 fprintf_unfiltered (gdb_stdlog
,
2665 "infrun: need to step-over [%s] first\n",
2666 target_pid_to_str (step_over
->ptid
));
2668 /* Store the prev_pc for the stepping thread too, needed by
2669 switch_back_to_stepping thread. */
2670 tp
->prev_pc
= regcache_read_pc (get_current_regcache ());
2671 switch_to_thread (step_over
->ptid
);
2676 /* If we need to step over a breakpoint, and we're not using
2677 displaced stepping to do so, insert all breakpoints (watchpoints,
2678 etc.) but the one we're stepping over, step one instruction, and
2679 then re-insert the breakpoint when that step is finished. */
2680 if (tp
->stepping_over_breakpoint
&& !use_displaced_stepping (gdbarch
))
2682 struct regcache
*regcache
= get_current_regcache ();
2684 set_step_over_info (get_regcache_aspace (regcache
),
2685 regcache_read_pc (regcache
), 0);
2688 clear_step_over_info ();
2690 insert_breakpoints ();
2692 tp
->control
.trap_expected
= tp
->stepping_over_breakpoint
;
2694 annotate_starting ();
2696 /* Make sure that output from GDB appears before output from the
2698 gdb_flush (gdb_stdout
);
2700 /* Refresh prev_pc value just prior to resuming. This used to be
2701 done in stop_waiting, however, setting prev_pc there did not handle
2702 scenarios such as inferior function calls or returning from
2703 a function via the return command. In those cases, the prev_pc
2704 value was not set properly for subsequent commands. The prev_pc value
2705 is used to initialize the starting line number in the ecs. With an
2706 invalid value, the gdb next command ends up stopping at the position
2707 represented by the next line table entry past our start position.
2708 On platforms that generate one line table entry per line, this
2709 is not a problem. However, on the ia64, the compiler generates
2710 extraneous line table entries that do not increase the line number.
2711 When we issue the gdb next command on the ia64 after an inferior call
2712 or a return command, we often end up a few instructions forward, still
2713 within the original line we started.
2715 An attempt was made to refresh the prev_pc at the same time the
2716 execution_control_state is initialized (for instance, just before
2717 waiting for an inferior event). But this approach did not work
2718 because of platforms that use ptrace, where the pc register cannot
2719 be read unless the inferior is stopped. At that point, we are not
2720 guaranteed the inferior is stopped and so the regcache_read_pc() call
2721 can fail. Setting the prev_pc value here ensures the value is updated
2722 correctly when the inferior is stopped. */
2723 tp
->prev_pc
= regcache_read_pc (get_current_regcache ());
2725 /* Resume inferior. */
2726 resume (tp
->control
.trap_expected
|| step
|| bpstat_should_step (),
2727 tp
->suspend
.stop_signal
);
2729 /* Wait for it to stop (if not standalone)
2730 and in any case decode why it stopped, and act accordingly. */
2731 /* Do this only if we are not using the event loop, or if the target
2732 does not support asynchronous execution. */
2733 if (!target_can_async_p ())
2735 wait_for_inferior ();
2741 /* Start remote-debugging of a machine over a serial link. */
2744 start_remote (int from_tty
)
2746 struct inferior
*inferior
;
2748 inferior
= current_inferior ();
2749 inferior
->control
.stop_soon
= STOP_QUIETLY_REMOTE
;
2751 /* Always go on waiting for the target, regardless of the mode. */
2752 /* FIXME: cagney/1999-09-23: At present it isn't possible to
2753 indicate to wait_for_inferior that a target should timeout if
2754 nothing is returned (instead of just blocking). Because of this,
2755 targets expecting an immediate response need to, internally, set
2756 things up so that the target_wait() is forced to eventually
2758 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
2759 differentiate to its caller what the state of the target is after
2760 the initial open has been performed. Here we're assuming that
2761 the target has stopped. It should be possible to eventually have
2762 target_open() return to the caller an indication that the target
2763 is currently running and GDB state should be set to the same as
2764 for an async run. */
2765 wait_for_inferior ();
2767 /* Now that the inferior has stopped, do any bookkeeping like
2768 loading shared libraries. We want to do this before normal_stop,
2769 so that the displayed frame is up to date. */
2770 post_create_inferior (¤t_target
, from_tty
);
2775 /* Initialize static vars when a new inferior begins. */
2778 init_wait_for_inferior (void)
2780 /* These are meaningless until the first time through wait_for_inferior. */
2782 breakpoint_init_inferior (inf_starting
);
2784 clear_proceed_status (0);
2786 target_last_wait_ptid
= minus_one_ptid
;
2788 previous_inferior_ptid
= inferior_ptid
;
2790 /* Discard any skipped inlined frames. */
2791 clear_inline_frame_state (minus_one_ptid
);
2795 /* Data to be passed around while handling an event. This data is
2796 discarded between events. */
2797 struct execution_control_state
2800 /* The thread that got the event, if this was a thread event; NULL
2802 struct thread_info
*event_thread
;
2804 struct target_waitstatus ws
;
2805 int stop_func_filled_in
;
2806 CORE_ADDR stop_func_start
;
2807 CORE_ADDR stop_func_end
;
2808 const char *stop_func_name
;
2811 /* True if the event thread hit the single-step breakpoint of
2812 another thread. Thus the event doesn't cause a stop, the thread
2813 needs to be single-stepped past the single-step breakpoint before
2814 we can switch back to the original stepping thread. */
2815 int hit_singlestep_breakpoint
;
2818 static void handle_inferior_event (struct execution_control_state
*ecs
);
2820 static void handle_step_into_function (struct gdbarch
*gdbarch
,
2821 struct execution_control_state
*ecs
);
2822 static void handle_step_into_function_backward (struct gdbarch
*gdbarch
,
2823 struct execution_control_state
*ecs
);
2824 static void handle_signal_stop (struct execution_control_state
*ecs
);
2825 static void check_exception_resume (struct execution_control_state
*,
2826 struct frame_info
*);
2828 static void end_stepping_range (struct execution_control_state
*ecs
);
2829 static void stop_waiting (struct execution_control_state
*ecs
);
2830 static void prepare_to_wait (struct execution_control_state
*ecs
);
2831 static void keep_going (struct execution_control_state
*ecs
);
2832 static void process_event_stop_test (struct execution_control_state
*ecs
);
2833 static int switch_back_to_stepped_thread (struct execution_control_state
*ecs
);
2835 /* Callback for iterate over threads. If the thread is stopped, but
2836 the user/frontend doesn't know about that yet, go through
2837 normal_stop, as if the thread had just stopped now. ARG points at
2838 a ptid. If PTID is MINUS_ONE_PTID, applies to all threads. If
2839 ptid_is_pid(PTID) is true, applies to all threads of the process
2840 pointed at by PTID. Otherwise, apply only to the thread pointed by
2844 infrun_thread_stop_requested_callback (struct thread_info
*info
, void *arg
)
2846 ptid_t ptid
= * (ptid_t
*) arg
;
2848 if ((ptid_equal (info
->ptid
, ptid
)
2849 || ptid_equal (minus_one_ptid
, ptid
)
2850 || (ptid_is_pid (ptid
)
2851 && ptid_get_pid (ptid
) == ptid_get_pid (info
->ptid
)))
2852 && is_running (info
->ptid
)
2853 && !is_executing (info
->ptid
))
2855 struct cleanup
*old_chain
;
2856 struct execution_control_state ecss
;
2857 struct execution_control_state
*ecs
= &ecss
;
2859 memset (ecs
, 0, sizeof (*ecs
));
2861 old_chain
= make_cleanup_restore_current_thread ();
2863 overlay_cache_invalid
= 1;
2864 /* Flush target cache before starting to handle each event.
2865 Target was running and cache could be stale. This is just a
2866 heuristic. Running threads may modify target memory, but we
2867 don't get any event. */
2868 target_dcache_invalidate ();
2870 /* Go through handle_inferior_event/normal_stop, so we always
2871 have consistent output as if the stop event had been
2873 ecs
->ptid
= info
->ptid
;
2874 ecs
->event_thread
= find_thread_ptid (info
->ptid
);
2875 ecs
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
2876 ecs
->ws
.value
.sig
= GDB_SIGNAL_0
;
2878 handle_inferior_event (ecs
);
2880 if (!ecs
->wait_some_more
)
2882 struct thread_info
*tp
;
2886 /* Finish off the continuations. */
2887 tp
= inferior_thread ();
2888 do_all_intermediate_continuations_thread (tp
, 1);
2889 do_all_continuations_thread (tp
, 1);
2892 do_cleanups (old_chain
);
2898 /* This function is attached as a "thread_stop_requested" observer.
2899 Cleanup local state that assumed the PTID was to be resumed, and
2900 report the stop to the frontend. */
2903 infrun_thread_stop_requested (ptid_t ptid
)
2905 struct displaced_step_inferior_state
*displaced
;
2907 /* PTID was requested to stop. Remove it from the displaced
2908 stepping queue, so we don't try to resume it automatically. */
2910 for (displaced
= displaced_step_inferior_states
;
2912 displaced
= displaced
->next
)
2914 struct displaced_step_request
*it
, **prev_next_p
;
2916 it
= displaced
->step_request_queue
;
2917 prev_next_p
= &displaced
->step_request_queue
;
2920 if (ptid_match (it
->ptid
, ptid
))
2922 *prev_next_p
= it
->next
;
2928 prev_next_p
= &it
->next
;
2935 iterate_over_threads (infrun_thread_stop_requested_callback
, &ptid
);
2939 infrun_thread_thread_exit (struct thread_info
*tp
, int silent
)
2941 if (ptid_equal (target_last_wait_ptid
, tp
->ptid
))
2942 nullify_last_target_wait_ptid ();
2945 /* Delete the step resume, single-step and longjmp/exception resume
2946 breakpoints of TP. */
2949 delete_thread_infrun_breakpoints (struct thread_info
*tp
)
2951 delete_step_resume_breakpoint (tp
);
2952 delete_exception_resume_breakpoint (tp
);
2953 delete_single_step_breakpoints (tp
);
2956 /* If the target still has execution, call FUNC for each thread that
2957 just stopped. In all-stop, that's all the non-exited threads; in
2958 non-stop, that's the current thread, only. */
2960 typedef void (*for_each_just_stopped_thread_callback_func
)
2961 (struct thread_info
*tp
);
2964 for_each_just_stopped_thread (for_each_just_stopped_thread_callback_func func
)
2966 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
2971 /* If in non-stop mode, only the current thread stopped. */
2972 func (inferior_thread ());
2976 struct thread_info
*tp
;
2978 /* In all-stop mode, all threads have stopped. */
2979 ALL_NON_EXITED_THREADS (tp
)
2986 /* Delete the step resume and longjmp/exception resume breakpoints of
2987 the threads that just stopped. */
2990 delete_just_stopped_threads_infrun_breakpoints (void)
2992 for_each_just_stopped_thread (delete_thread_infrun_breakpoints
);
2995 /* Delete the single-step breakpoints of the threads that just
2999 delete_just_stopped_threads_single_step_breakpoints (void)
3001 for_each_just_stopped_thread (delete_single_step_breakpoints
);
3004 /* A cleanup wrapper. */
3007 delete_just_stopped_threads_infrun_breakpoints_cleanup (void *arg
)
3009 delete_just_stopped_threads_infrun_breakpoints ();
3012 /* Pretty print the results of target_wait, for debugging purposes. */
3015 print_target_wait_results (ptid_t waiton_ptid
, ptid_t result_ptid
,
3016 const struct target_waitstatus
*ws
)
3018 char *status_string
= target_waitstatus_to_string (ws
);
3019 struct ui_file
*tmp_stream
= mem_fileopen ();
3022 /* The text is split over several lines because it was getting too long.
3023 Call fprintf_unfiltered (gdb_stdlog) once so that the text is still
3024 output as a unit; we want only one timestamp printed if debug_timestamp
3027 fprintf_unfiltered (tmp_stream
,
3028 "infrun: target_wait (%d", ptid_get_pid (waiton_ptid
));
3029 if (ptid_get_pid (waiton_ptid
) != -1)
3030 fprintf_unfiltered (tmp_stream
,
3031 " [%s]", target_pid_to_str (waiton_ptid
));
3032 fprintf_unfiltered (tmp_stream
, ", status) =\n");
3033 fprintf_unfiltered (tmp_stream
,
3034 "infrun: %d [%s],\n",
3035 ptid_get_pid (result_ptid
),
3036 target_pid_to_str (result_ptid
));
3037 fprintf_unfiltered (tmp_stream
,
3041 text
= ui_file_xstrdup (tmp_stream
, NULL
);
3043 /* This uses %s in part to handle %'s in the text, but also to avoid
3044 a gcc error: the format attribute requires a string literal. */
3045 fprintf_unfiltered (gdb_stdlog
, "%s", text
);
3047 xfree (status_string
);
3049 ui_file_delete (tmp_stream
);
3052 /* Prepare and stabilize the inferior for detaching it. E.g.,
3053 detaching while a thread is displaced stepping is a recipe for
3054 crashing it, as nothing would readjust the PC out of the scratch
3058 prepare_for_detach (void)
3060 struct inferior
*inf
= current_inferior ();
3061 ptid_t pid_ptid
= pid_to_ptid (inf
->pid
);
3062 struct cleanup
*old_chain_1
;
3063 struct displaced_step_inferior_state
*displaced
;
3065 displaced
= get_displaced_stepping_state (inf
->pid
);
3067 /* Is any thread of this process displaced stepping? If not,
3068 there's nothing else to do. */
3069 if (displaced
== NULL
|| ptid_equal (displaced
->step_ptid
, null_ptid
))
3073 fprintf_unfiltered (gdb_stdlog
,
3074 "displaced-stepping in-process while detaching");
3076 old_chain_1
= make_cleanup_restore_integer (&inf
->detaching
);
3079 while (!ptid_equal (displaced
->step_ptid
, null_ptid
))
3081 struct cleanup
*old_chain_2
;
3082 struct execution_control_state ecss
;
3083 struct execution_control_state
*ecs
;
3086 memset (ecs
, 0, sizeof (*ecs
));
3088 overlay_cache_invalid
= 1;
3089 /* Flush target cache before starting to handle each event.
3090 Target was running and cache could be stale. This is just a
3091 heuristic. Running threads may modify target memory, but we
3092 don't get any event. */
3093 target_dcache_invalidate ();
3095 if (deprecated_target_wait_hook
)
3096 ecs
->ptid
= deprecated_target_wait_hook (pid_ptid
, &ecs
->ws
, 0);
3098 ecs
->ptid
= target_wait (pid_ptid
, &ecs
->ws
, 0);
3101 print_target_wait_results (pid_ptid
, ecs
->ptid
, &ecs
->ws
);
3103 /* If an error happens while handling the event, propagate GDB's
3104 knowledge of the executing state to the frontend/user running
3106 old_chain_2
= make_cleanup (finish_thread_state_cleanup
,
3109 /* Now figure out what to do with the result of the result. */
3110 handle_inferior_event (ecs
);
3112 /* No error, don't finish the state yet. */
3113 discard_cleanups (old_chain_2
);
3115 /* Breakpoints and watchpoints are not installed on the target
3116 at this point, and signals are passed directly to the
3117 inferior, so this must mean the process is gone. */
3118 if (!ecs
->wait_some_more
)
3120 discard_cleanups (old_chain_1
);
3121 error (_("Program exited while detaching"));
3125 discard_cleanups (old_chain_1
);
3128 /* Wait for control to return from inferior to debugger.
3130 If inferior gets a signal, we may decide to start it up again
3131 instead of returning. That is why there is a loop in this function.
3132 When this function actually returns it means the inferior
3133 should be left stopped and GDB should read more commands. */
3136 wait_for_inferior (void)
3138 struct cleanup
*old_cleanups
;
3142 (gdb_stdlog
, "infrun: wait_for_inferior ()\n");
3145 = make_cleanup (delete_just_stopped_threads_infrun_breakpoints_cleanup
,
3150 struct execution_control_state ecss
;
3151 struct execution_control_state
*ecs
= &ecss
;
3152 struct cleanup
*old_chain
;
3153 ptid_t waiton_ptid
= minus_one_ptid
;
3155 memset (ecs
, 0, sizeof (*ecs
));
3157 overlay_cache_invalid
= 1;
3159 /* Flush target cache before starting to handle each event.
3160 Target was running and cache could be stale. This is just a
3161 heuristic. Running threads may modify target memory, but we
3162 don't get any event. */
3163 target_dcache_invalidate ();
3165 if (deprecated_target_wait_hook
)
3166 ecs
->ptid
= deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
, 0);
3168 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
, 0);
3171 print_target_wait_results (waiton_ptid
, ecs
->ptid
, &ecs
->ws
);
3173 /* If an error happens while handling the event, propagate GDB's
3174 knowledge of the executing state to the frontend/user running
3176 old_chain
= make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
3178 /* Now figure out what to do with the result of the result. */
3179 handle_inferior_event (ecs
);
3181 /* No error, don't finish the state yet. */
3182 discard_cleanups (old_chain
);
3184 if (!ecs
->wait_some_more
)
3188 do_cleanups (old_cleanups
);
3191 /* Cleanup that reinstalls the readline callback handler, if the
3192 target is running in the background. If while handling the target
3193 event something triggered a secondary prompt, like e.g., a
3194 pagination prompt, we'll have removed the callback handler (see
3195 gdb_readline_wrapper_line). Need to do this as we go back to the
3196 event loop, ready to process further input. Note this has no
3197 effect if the handler hasn't actually been removed, because calling
3198 rl_callback_handler_install resets the line buffer, thus losing
3202 reinstall_readline_callback_handler_cleanup (void *arg
)
3204 if (!interpreter_async
)
3206 /* We're not going back to the top level event loop yet. Don't
3207 install the readline callback, as it'd prep the terminal,
3208 readline-style (raw, noecho) (e.g., --batch). We'll install
3209 it the next time the prompt is displayed, when we're ready
3214 if (async_command_editing_p
&& !sync_execution
)
3215 gdb_rl_callback_handler_reinstall ();
3218 /* Asynchronous version of wait_for_inferior. It is called by the
3219 event loop whenever a change of state is detected on the file
3220 descriptor corresponding to the target. It can be called more than
3221 once to complete a single execution command. In such cases we need
3222 to keep the state in a global variable ECSS. If it is the last time
3223 that this function is called for a single execution command, then
3224 report to the user that the inferior has stopped, and do the
3225 necessary cleanups. */
3228 fetch_inferior_event (void *client_data
)
3230 struct execution_control_state ecss
;
3231 struct execution_control_state
*ecs
= &ecss
;
3232 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
3233 struct cleanup
*ts_old_chain
;
3234 int was_sync
= sync_execution
;
3236 ptid_t waiton_ptid
= minus_one_ptid
;
3238 memset (ecs
, 0, sizeof (*ecs
));
3240 /* End up with readline processing input, if necessary. */
3241 make_cleanup (reinstall_readline_callback_handler_cleanup
, NULL
);
3243 /* We're handling a live event, so make sure we're doing live
3244 debugging. If we're looking at traceframes while the target is
3245 running, we're going to need to get back to that mode after
3246 handling the event. */
3249 make_cleanup_restore_current_traceframe ();
3250 set_current_traceframe (-1);
3254 /* In non-stop mode, the user/frontend should not notice a thread
3255 switch due to internal events. Make sure we reverse to the
3256 user selected thread and frame after handling the event and
3257 running any breakpoint commands. */
3258 make_cleanup_restore_current_thread ();
3260 overlay_cache_invalid
= 1;
3261 /* Flush target cache before starting to handle each event. Target
3262 was running and cache could be stale. This is just a heuristic.
3263 Running threads may modify target memory, but we don't get any
3265 target_dcache_invalidate ();
3267 make_cleanup_restore_integer (&execution_direction
);
3268 execution_direction
= target_execution_direction ();
3270 if (deprecated_target_wait_hook
)
3272 deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
, TARGET_WNOHANG
);
3274 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
, TARGET_WNOHANG
);
3277 print_target_wait_results (waiton_ptid
, ecs
->ptid
, &ecs
->ws
);
3279 /* If an error happens while handling the event, propagate GDB's
3280 knowledge of the executing state to the frontend/user running
3283 ts_old_chain
= make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
3285 ts_old_chain
= make_cleanup (finish_thread_state_cleanup
, &ecs
->ptid
);
3287 /* Get executed before make_cleanup_restore_current_thread above to apply
3288 still for the thread which has thrown the exception. */
3289 make_bpstat_clear_actions_cleanup ();
3291 make_cleanup (delete_just_stopped_threads_infrun_breakpoints_cleanup
, NULL
);
3293 /* Now figure out what to do with the result of the result. */
3294 handle_inferior_event (ecs
);
3296 if (!ecs
->wait_some_more
)
3298 struct inferior
*inf
= find_inferior_ptid (ecs
->ptid
);
3300 delete_just_stopped_threads_infrun_breakpoints ();
3302 /* We may not find an inferior if this was a process exit. */
3303 if (inf
== NULL
|| inf
->control
.stop_soon
== NO_STOP_QUIETLY
)
3306 if (target_has_execution
3307 && ecs
->ws
.kind
!= TARGET_WAITKIND_NO_RESUMED
3308 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
3309 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
3310 && ecs
->event_thread
->step_multi
3311 && ecs
->event_thread
->control
.stop_step
)
3312 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
3315 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
3320 /* No error, don't finish the thread states yet. */
3321 discard_cleanups (ts_old_chain
);
3323 /* Revert thread and frame. */
3324 do_cleanups (old_chain
);
3326 /* If the inferior was in sync execution mode, and now isn't,
3327 restore the prompt (a synchronous execution command has finished,
3328 and we're ready for input). */
3329 if (interpreter_async
&& was_sync
&& !sync_execution
)
3330 observer_notify_sync_execution_done ();
3334 && exec_done_display_p
3335 && (ptid_equal (inferior_ptid
, null_ptid
)
3336 || !is_running (inferior_ptid
)))
3337 printf_unfiltered (_("completed.\n"));
3340 /* Record the frame and location we're currently stepping through. */
3342 set_step_info (struct frame_info
*frame
, struct symtab_and_line sal
)
3344 struct thread_info
*tp
= inferior_thread ();
3346 tp
->control
.step_frame_id
= get_frame_id (frame
);
3347 tp
->control
.step_stack_frame_id
= get_stack_frame_id (frame
);
3349 tp
->current_symtab
= sal
.symtab
;
3350 tp
->current_line
= sal
.line
;
3353 /* Clear context switchable stepping state. */
3356 init_thread_stepping_state (struct thread_info
*tss
)
3358 tss
->stepped_breakpoint
= 0;
3359 tss
->stepping_over_breakpoint
= 0;
3360 tss
->stepping_over_watchpoint
= 0;
3361 tss
->step_after_step_resume_breakpoint
= 0;
3364 /* Set the cached copy of the last ptid/waitstatus. */
3367 set_last_target_status (ptid_t ptid
, struct target_waitstatus status
)
3369 target_last_wait_ptid
= ptid
;
3370 target_last_waitstatus
= status
;
3373 /* Return the cached copy of the last pid/waitstatus returned by
3374 target_wait()/deprecated_target_wait_hook(). The data is actually
3375 cached by handle_inferior_event(), which gets called immediately
3376 after target_wait()/deprecated_target_wait_hook(). */
3379 get_last_target_status (ptid_t
*ptidp
, struct target_waitstatus
*status
)
3381 *ptidp
= target_last_wait_ptid
;
3382 *status
= target_last_waitstatus
;
3386 nullify_last_target_wait_ptid (void)
3388 target_last_wait_ptid
= minus_one_ptid
;
3391 /* Switch thread contexts. */
3394 context_switch (ptid_t ptid
)
3396 if (debug_infrun
&& !ptid_equal (ptid
, inferior_ptid
))
3398 fprintf_unfiltered (gdb_stdlog
, "infrun: Switching context from %s ",
3399 target_pid_to_str (inferior_ptid
));
3400 fprintf_unfiltered (gdb_stdlog
, "to %s\n",
3401 target_pid_to_str (ptid
));
3404 switch_to_thread (ptid
);
3408 adjust_pc_after_break (struct execution_control_state
*ecs
)
3410 struct regcache
*regcache
;
3411 struct gdbarch
*gdbarch
;
3412 struct address_space
*aspace
;
3413 CORE_ADDR breakpoint_pc
, decr_pc
;
3415 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
3416 we aren't, just return.
3418 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
3419 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
3420 implemented by software breakpoints should be handled through the normal
3423 NOTE drow/2004-01-31: On some targets, breakpoints may generate
3424 different signals (SIGILL or SIGEMT for instance), but it is less
3425 clear where the PC is pointing afterwards. It may not match
3426 gdbarch_decr_pc_after_break. I don't know any specific target that
3427 generates these signals at breakpoints (the code has been in GDB since at
3428 least 1992) so I can not guess how to handle them here.
3430 In earlier versions of GDB, a target with
3431 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
3432 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
3433 target with both of these set in GDB history, and it seems unlikely to be
3434 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
3436 if (ecs
->ws
.kind
!= TARGET_WAITKIND_STOPPED
)
3439 if (ecs
->ws
.value
.sig
!= GDB_SIGNAL_TRAP
)
3442 /* In reverse execution, when a breakpoint is hit, the instruction
3443 under it has already been de-executed. The reported PC always
3444 points at the breakpoint address, so adjusting it further would
3445 be wrong. E.g., consider this case on a decr_pc_after_break == 1
3448 B1 0x08000000 : INSN1
3449 B2 0x08000001 : INSN2
3451 PC -> 0x08000003 : INSN4
3453 Say you're stopped at 0x08000003 as above. Reverse continuing
3454 from that point should hit B2 as below. Reading the PC when the
3455 SIGTRAP is reported should read 0x08000001 and INSN2 should have
3456 been de-executed already.
3458 B1 0x08000000 : INSN1
3459 B2 PC -> 0x08000001 : INSN2
3463 We can't apply the same logic as for forward execution, because
3464 we would wrongly adjust the PC to 0x08000000, since there's a
3465 breakpoint at PC - 1. We'd then report a hit on B1, although
3466 INSN1 hadn't been de-executed yet. Doing nothing is the correct
3468 if (execution_direction
== EXEC_REVERSE
)
3471 /* If the target can tell whether the thread hit a SW breakpoint,
3472 trust it. Targets that can tell also adjust the PC
3474 if (target_supports_stopped_by_sw_breakpoint ())
3477 /* Note that relying on whether a breakpoint is planted in memory to
3478 determine this can fail. E.g,. the breakpoint could have been
3479 removed since. Or the thread could have been told to step an
3480 instruction the size of a breakpoint instruction, and only
3481 _after_ was a breakpoint inserted at its address. */
3483 /* If this target does not decrement the PC after breakpoints, then
3484 we have nothing to do. */
3485 regcache
= get_thread_regcache (ecs
->ptid
);
3486 gdbarch
= get_regcache_arch (regcache
);
3488 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
3492 aspace
= get_regcache_aspace (regcache
);
3494 /* Find the location where (if we've hit a breakpoint) the
3495 breakpoint would be. */
3496 breakpoint_pc
= regcache_read_pc (regcache
) - decr_pc
;
3498 /* If the target can't tell whether a software breakpoint triggered,
3499 fallback to figuring it out based on breakpoints we think were
3500 inserted in the target, and on whether the thread was stepped or
3503 /* Check whether there actually is a software breakpoint inserted at
3506 If in non-stop mode, a race condition is possible where we've
3507 removed a breakpoint, but stop events for that breakpoint were
3508 already queued and arrive later. To suppress those spurious
3509 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
3510 and retire them after a number of stop events are reported. Note
3511 this is an heuristic and can thus get confused. The real fix is
3512 to get the "stopped by SW BP and needs adjustment" info out of
3513 the target/kernel (and thus never reach here; see above). */
3514 if (software_breakpoint_inserted_here_p (aspace
, breakpoint_pc
)
3515 || (non_stop
&& moribund_breakpoint_here_p (aspace
, breakpoint_pc
)))
3517 struct cleanup
*old_cleanups
= make_cleanup (null_cleanup
, NULL
);
3519 if (record_full_is_used ())
3520 record_full_gdb_operation_disable_set ();
3522 /* When using hardware single-step, a SIGTRAP is reported for both
3523 a completed single-step and a software breakpoint. Need to
3524 differentiate between the two, as the latter needs adjusting
3525 but the former does not.
3527 The SIGTRAP can be due to a completed hardware single-step only if
3528 - we didn't insert software single-step breakpoints
3529 - this thread is currently being stepped
3531 If any of these events did not occur, we must have stopped due
3532 to hitting a software breakpoint, and have to back up to the
3535 As a special case, we could have hardware single-stepped a
3536 software breakpoint. In this case (prev_pc == breakpoint_pc),
3537 we also need to back up to the breakpoint address. */
3539 if (thread_has_single_step_breakpoints_set (ecs
->event_thread
)
3540 || !currently_stepping (ecs
->event_thread
)
3541 || (ecs
->event_thread
->stepped_breakpoint
3542 && ecs
->event_thread
->prev_pc
== breakpoint_pc
))
3543 regcache_write_pc (regcache
, breakpoint_pc
);
3545 do_cleanups (old_cleanups
);
3550 stepped_in_from (struct frame_info
*frame
, struct frame_id step_frame_id
)
3552 for (frame
= get_prev_frame (frame
);
3554 frame
= get_prev_frame (frame
))
3556 if (frame_id_eq (get_frame_id (frame
), step_frame_id
))
3558 if (get_frame_type (frame
) != INLINE_FRAME
)
3565 /* Auxiliary function that handles syscall entry/return events.
3566 It returns 1 if the inferior should keep going (and GDB
3567 should ignore the event), or 0 if the event deserves to be
3571 handle_syscall_event (struct execution_control_state
*ecs
)
3573 struct regcache
*regcache
;
3576 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3577 context_switch (ecs
->ptid
);
3579 regcache
= get_thread_regcache (ecs
->ptid
);
3580 syscall_number
= ecs
->ws
.value
.syscall_number
;
3581 stop_pc
= regcache_read_pc (regcache
);
3583 if (catch_syscall_enabled () > 0
3584 && catching_syscall_number (syscall_number
) > 0)
3587 fprintf_unfiltered (gdb_stdlog
, "infrun: syscall number = '%d'\n",
3590 ecs
->event_thread
->control
.stop_bpstat
3591 = bpstat_stop_status (get_regcache_aspace (regcache
),
3592 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3594 if (bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
3596 /* Catchpoint hit. */
3601 /* If no catchpoint triggered for this, then keep going. */
3606 /* Lazily fill in the execution_control_state's stop_func_* fields. */
3609 fill_in_stop_func (struct gdbarch
*gdbarch
,
3610 struct execution_control_state
*ecs
)
3612 if (!ecs
->stop_func_filled_in
)
3614 /* Don't care about return value; stop_func_start and stop_func_name
3615 will both be 0 if it doesn't work. */
3616 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
3617 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
3618 ecs
->stop_func_start
3619 += gdbarch_deprecated_function_start_offset (gdbarch
);
3621 if (gdbarch_skip_entrypoint_p (gdbarch
))
3622 ecs
->stop_func_start
= gdbarch_skip_entrypoint (gdbarch
,
3623 ecs
->stop_func_start
);
3625 ecs
->stop_func_filled_in
= 1;
3630 /* Return the STOP_SOON field of the inferior pointed at by PTID. */
3632 static enum stop_kind
3633 get_inferior_stop_soon (ptid_t ptid
)
3635 struct inferior
*inf
= find_inferior_ptid (ptid
);
3637 gdb_assert (inf
!= NULL
);
3638 return inf
->control
.stop_soon
;
3641 /* Given an execution control state that has been freshly filled in by
3642 an event from the inferior, figure out what it means and take
3645 The alternatives are:
3647 1) stop_waiting and return; to really stop and return to the
3650 2) keep_going and return; to wait for the next event (set
3651 ecs->event_thread->stepping_over_breakpoint to 1 to single step
3655 handle_inferior_event (struct execution_control_state
*ecs
)
3657 enum stop_kind stop_soon
;
3659 if (ecs
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
3661 /* We had an event in the inferior, but we are not interested in
3662 handling it at this level. The lower layers have already
3663 done what needs to be done, if anything.
3665 One of the possible circumstances for this is when the
3666 inferior produces output for the console. The inferior has
3667 not stopped, and we are ignoring the event. Another possible
3668 circumstance is any event which the lower level knows will be
3669 reported multiple times without an intervening resume. */
3671 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_IGNORE\n");
3672 prepare_to_wait (ecs
);
3676 if (ecs
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
3677 && target_can_async_p () && !sync_execution
)
3679 /* There were no unwaited-for children left in the target, but,
3680 we're not synchronously waiting for events either. Just
3681 ignore. Otherwise, if we were running a synchronous
3682 execution command, we need to cancel it and give the user
3683 back the terminal. */
3685 fprintf_unfiltered (gdb_stdlog
,
3686 "infrun: TARGET_WAITKIND_NO_RESUMED (ignoring)\n");
3687 prepare_to_wait (ecs
);
3691 /* Cache the last pid/waitstatus. */
3692 set_last_target_status (ecs
->ptid
, ecs
->ws
);
3694 /* Always clear state belonging to the previous time we stopped. */
3695 stop_stack_dummy
= STOP_NONE
;
3697 if (ecs
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
)
3699 /* No unwaited-for children left. IOW, all resumed children
3702 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_NO_RESUMED\n");
3704 stop_print_frame
= 0;
3709 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
3710 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
)
3712 ecs
->event_thread
= find_thread_ptid (ecs
->ptid
);
3713 /* If it's a new thread, add it to the thread database. */
3714 if (ecs
->event_thread
== NULL
)
3715 ecs
->event_thread
= add_thread (ecs
->ptid
);
3717 /* Disable range stepping. If the next step request could use a
3718 range, this will be end up re-enabled then. */
3719 ecs
->event_thread
->control
.may_range_step
= 0;
3722 /* Dependent on valid ECS->EVENT_THREAD. */
3723 adjust_pc_after_break (ecs
);
3725 /* Dependent on the current PC value modified by adjust_pc_after_break. */
3726 reinit_frame_cache ();
3728 breakpoint_retire_moribund ();
3730 /* First, distinguish signals caused by the debugger from signals
3731 that have to do with the program's own actions. Note that
3732 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
3733 on the operating system version. Here we detect when a SIGILL or
3734 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
3735 something similar for SIGSEGV, since a SIGSEGV will be generated
3736 when we're trying to execute a breakpoint instruction on a
3737 non-executable stack. This happens for call dummy breakpoints
3738 for architectures like SPARC that place call dummies on the
3740 if (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
3741 && (ecs
->ws
.value
.sig
== GDB_SIGNAL_ILL
3742 || ecs
->ws
.value
.sig
== GDB_SIGNAL_SEGV
3743 || ecs
->ws
.value
.sig
== GDB_SIGNAL_EMT
))
3745 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3747 if (breakpoint_inserted_here_p (get_regcache_aspace (regcache
),
3748 regcache_read_pc (regcache
)))
3751 fprintf_unfiltered (gdb_stdlog
,
3752 "infrun: Treating signal as SIGTRAP\n");
3753 ecs
->ws
.value
.sig
= GDB_SIGNAL_TRAP
;
3757 /* Mark the non-executing threads accordingly. In all-stop, all
3758 threads of all processes are stopped when we get any event
3759 reported. In non-stop mode, only the event thread stops. If
3760 we're handling a process exit in non-stop mode, there's nothing
3761 to do, as threads of the dead process are gone, and threads of
3762 any other process were left running. */
3764 set_executing (minus_one_ptid
, 0);
3765 else if (ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
3766 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
)
3767 set_executing (ecs
->ptid
, 0);
3769 switch (ecs
->ws
.kind
)
3771 case TARGET_WAITKIND_LOADED
:
3773 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_LOADED\n");
3774 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3775 context_switch (ecs
->ptid
);
3776 /* Ignore gracefully during startup of the inferior, as it might
3777 be the shell which has just loaded some objects, otherwise
3778 add the symbols for the newly loaded objects. Also ignore at
3779 the beginning of an attach or remote session; we will query
3780 the full list of libraries once the connection is
3783 stop_soon
= get_inferior_stop_soon (ecs
->ptid
);
3784 if (stop_soon
== NO_STOP_QUIETLY
)
3786 struct regcache
*regcache
;
3788 regcache
= get_thread_regcache (ecs
->ptid
);
3790 handle_solib_event ();
3792 ecs
->event_thread
->control
.stop_bpstat
3793 = bpstat_stop_status (get_regcache_aspace (regcache
),
3794 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3796 if (bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
3798 /* A catchpoint triggered. */
3799 process_event_stop_test (ecs
);
3803 /* If requested, stop when the dynamic linker notifies
3804 gdb of events. This allows the user to get control
3805 and place breakpoints in initializer routines for
3806 dynamically loaded objects (among other things). */
3807 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3808 if (stop_on_solib_events
)
3810 /* Make sure we print "Stopped due to solib-event" in
3812 stop_print_frame
= 1;
3819 /* If we are skipping through a shell, or through shared library
3820 loading that we aren't interested in, resume the program. If
3821 we're running the program normally, also resume. */
3822 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== NO_STOP_QUIETLY
)
3824 /* Loading of shared libraries might have changed breakpoint
3825 addresses. Make sure new breakpoints are inserted. */
3826 if (stop_soon
== NO_STOP_QUIETLY
)
3827 insert_breakpoints ();
3828 resume (0, GDB_SIGNAL_0
);
3829 prepare_to_wait (ecs
);
3833 /* But stop if we're attaching or setting up a remote
3835 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
3836 || stop_soon
== STOP_QUIETLY_REMOTE
)
3839 fprintf_unfiltered (gdb_stdlog
, "infrun: quietly stopped\n");
3844 internal_error (__FILE__
, __LINE__
,
3845 _("unhandled stop_soon: %d"), (int) stop_soon
);
3847 case TARGET_WAITKIND_SPURIOUS
:
3849 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SPURIOUS\n");
3850 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3851 context_switch (ecs
->ptid
);
3852 resume (0, GDB_SIGNAL_0
);
3853 prepare_to_wait (ecs
);
3856 case TARGET_WAITKIND_EXITED
:
3857 case TARGET_WAITKIND_SIGNALLED
:
3860 if (ecs
->ws
.kind
== TARGET_WAITKIND_EXITED
)
3861 fprintf_unfiltered (gdb_stdlog
,
3862 "infrun: TARGET_WAITKIND_EXITED\n");
3864 fprintf_unfiltered (gdb_stdlog
,
3865 "infrun: TARGET_WAITKIND_SIGNALLED\n");
3868 inferior_ptid
= ecs
->ptid
;
3869 set_current_inferior (find_inferior_ptid (ecs
->ptid
));
3870 set_current_program_space (current_inferior ()->pspace
);
3871 handle_vfork_child_exec_or_exit (0);
3872 target_terminal_ours (); /* Must do this before mourn anyway. */
3874 /* Clearing any previous state of convenience variables. */
3875 clear_exit_convenience_vars ();
3877 if (ecs
->ws
.kind
== TARGET_WAITKIND_EXITED
)
3879 /* Record the exit code in the convenience variable $_exitcode, so
3880 that the user can inspect this again later. */
3881 set_internalvar_integer (lookup_internalvar ("_exitcode"),
3882 (LONGEST
) ecs
->ws
.value
.integer
);
3884 /* Also record this in the inferior itself. */
3885 current_inferior ()->has_exit_code
= 1;
3886 current_inferior ()->exit_code
= (LONGEST
) ecs
->ws
.value
.integer
;
3888 /* Support the --return-child-result option. */
3889 return_child_result_value
= ecs
->ws
.value
.integer
;
3891 observer_notify_exited (ecs
->ws
.value
.integer
);
3895 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3896 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3898 if (gdbarch_gdb_signal_to_target_p (gdbarch
))
3900 /* Set the value of the internal variable $_exitsignal,
3901 which holds the signal uncaught by the inferior. */
3902 set_internalvar_integer (lookup_internalvar ("_exitsignal"),
3903 gdbarch_gdb_signal_to_target (gdbarch
,
3904 ecs
->ws
.value
.sig
));
3908 /* We don't have access to the target's method used for
3909 converting between signal numbers (GDB's internal
3910 representation <-> target's representation).
3911 Therefore, we cannot do a good job at displaying this
3912 information to the user. It's better to just warn
3913 her about it (if infrun debugging is enabled), and
3916 fprintf_filtered (gdb_stdlog
, _("\
3917 Cannot fill $_exitsignal with the correct signal number.\n"));
3920 observer_notify_signal_exited (ecs
->ws
.value
.sig
);
3923 gdb_flush (gdb_stdout
);
3924 target_mourn_inferior ();
3925 stop_print_frame
= 0;
3929 /* The following are the only cases in which we keep going;
3930 the above cases end in a continue or goto. */
3931 case TARGET_WAITKIND_FORKED
:
3932 case TARGET_WAITKIND_VFORKED
:
3935 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
3936 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_FORKED\n");
3938 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_VFORKED\n");
3941 /* Check whether the inferior is displaced stepping. */
3943 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3944 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3945 struct displaced_step_inferior_state
*displaced
3946 = get_displaced_stepping_state (ptid_get_pid (ecs
->ptid
));
3948 /* If checking displaced stepping is supported, and thread
3949 ecs->ptid is displaced stepping. */
3950 if (displaced
&& ptid_equal (displaced
->step_ptid
, ecs
->ptid
))
3952 struct inferior
*parent_inf
3953 = find_inferior_ptid (ecs
->ptid
);
3954 struct regcache
*child_regcache
;
3955 CORE_ADDR parent_pc
;
3957 /* GDB has got TARGET_WAITKIND_FORKED or TARGET_WAITKIND_VFORKED,
3958 indicating that the displaced stepping of syscall instruction
3959 has been done. Perform cleanup for parent process here. Note
3960 that this operation also cleans up the child process for vfork,
3961 because their pages are shared. */
3962 displaced_step_fixup (ecs
->ptid
, GDB_SIGNAL_TRAP
);
3964 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
3966 /* Restore scratch pad for child process. */
3967 displaced_step_restore (displaced
, ecs
->ws
.value
.related_pid
);
3970 /* Since the vfork/fork syscall instruction was executed in the scratchpad,
3971 the child's PC is also within the scratchpad. Set the child's PC
3972 to the parent's PC value, which has already been fixed up.
3973 FIXME: we use the parent's aspace here, although we're touching
3974 the child, because the child hasn't been added to the inferior
3975 list yet at this point. */
3978 = get_thread_arch_aspace_regcache (ecs
->ws
.value
.related_pid
,
3980 parent_inf
->aspace
);
3981 /* Read PC value of parent process. */
3982 parent_pc
= regcache_read_pc (regcache
);
3984 if (debug_displaced
)
3985 fprintf_unfiltered (gdb_stdlog
,
3986 "displaced: write child pc from %s to %s\n",
3988 regcache_read_pc (child_regcache
)),
3989 paddress (gdbarch
, parent_pc
));
3991 regcache_write_pc (child_regcache
, parent_pc
);
3995 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3996 context_switch (ecs
->ptid
);
3998 /* Immediately detach breakpoints from the child before there's
3999 any chance of letting the user delete breakpoints from the
4000 breakpoint lists. If we don't do this early, it's easy to
4001 leave left over traps in the child, vis: "break foo; catch
4002 fork; c; <fork>; del; c; <child calls foo>". We only follow
4003 the fork on the last `continue', and by that time the
4004 breakpoint at "foo" is long gone from the breakpoint table.
4005 If we vforked, then we don't need to unpatch here, since both
4006 parent and child are sharing the same memory pages; we'll
4007 need to unpatch at follow/detach time instead to be certain
4008 that new breakpoints added between catchpoint hit time and
4009 vfork follow are detached. */
4010 if (ecs
->ws
.kind
!= TARGET_WAITKIND_VFORKED
)
4012 /* This won't actually modify the breakpoint list, but will
4013 physically remove the breakpoints from the child. */
4014 detach_breakpoints (ecs
->ws
.value
.related_pid
);
4017 delete_just_stopped_threads_single_step_breakpoints ();
4019 /* In case the event is caught by a catchpoint, remember that
4020 the event is to be followed at the next resume of the thread,
4021 and not immediately. */
4022 ecs
->event_thread
->pending_follow
= ecs
->ws
;
4024 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
4026 ecs
->event_thread
->control
.stop_bpstat
4027 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
4028 stop_pc
, ecs
->ptid
, &ecs
->ws
);
4030 /* If no catchpoint triggered for this, then keep going. Note
4031 that we're interested in knowing the bpstat actually causes a
4032 stop, not just if it may explain the signal. Software
4033 watchpoints, for example, always appear in the bpstat. */
4034 if (!bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
4040 = (follow_fork_mode_string
== follow_fork_mode_child
);
4042 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4044 should_resume
= follow_fork ();
4047 child
= ecs
->ws
.value
.related_pid
;
4049 /* In non-stop mode, also resume the other branch. */
4050 if (non_stop
&& !detach_fork
)
4053 switch_to_thread (parent
);
4055 switch_to_thread (child
);
4057 ecs
->event_thread
= inferior_thread ();
4058 ecs
->ptid
= inferior_ptid
;
4063 switch_to_thread (child
);
4065 switch_to_thread (parent
);
4067 ecs
->event_thread
= inferior_thread ();
4068 ecs
->ptid
= inferior_ptid
;
4076 process_event_stop_test (ecs
);
4079 case TARGET_WAITKIND_VFORK_DONE
:
4080 /* Done with the shared memory region. Re-insert breakpoints in
4081 the parent, and keep going. */
4084 fprintf_unfiltered (gdb_stdlog
,
4085 "infrun: TARGET_WAITKIND_VFORK_DONE\n");
4087 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
4088 context_switch (ecs
->ptid
);
4090 current_inferior ()->waiting_for_vfork_done
= 0;
4091 current_inferior ()->pspace
->breakpoints_not_allowed
= 0;
4092 /* This also takes care of reinserting breakpoints in the
4093 previously locked inferior. */
4097 case TARGET_WAITKIND_EXECD
:
4099 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_EXECD\n");
4101 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
4102 context_switch (ecs
->ptid
);
4104 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
4106 /* Do whatever is necessary to the parent branch of the vfork. */
4107 handle_vfork_child_exec_or_exit (1);
4109 /* This causes the eventpoints and symbol table to be reset.
4110 Must do this now, before trying to determine whether to
4112 follow_exec (inferior_ptid
, ecs
->ws
.value
.execd_pathname
);
4114 ecs
->event_thread
->control
.stop_bpstat
4115 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
4116 stop_pc
, ecs
->ptid
, &ecs
->ws
);
4118 /* Note that this may be referenced from inside
4119 bpstat_stop_status above, through inferior_has_execd. */
4120 xfree (ecs
->ws
.value
.execd_pathname
);
4121 ecs
->ws
.value
.execd_pathname
= NULL
;
4123 /* If no catchpoint triggered for this, then keep going. */
4124 if (!bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
4126 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4130 process_event_stop_test (ecs
);
4133 /* Be careful not to try to gather much state about a thread
4134 that's in a syscall. It's frequently a losing proposition. */
4135 case TARGET_WAITKIND_SYSCALL_ENTRY
:
4137 fprintf_unfiltered (gdb_stdlog
,
4138 "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
4139 /* Getting the current syscall number. */
4140 if (handle_syscall_event (ecs
) == 0)
4141 process_event_stop_test (ecs
);
4144 /* Before examining the threads further, step this thread to
4145 get it entirely out of the syscall. (We get notice of the
4146 event when the thread is just on the verge of exiting a
4147 syscall. Stepping one instruction seems to get it back
4149 case TARGET_WAITKIND_SYSCALL_RETURN
:
4151 fprintf_unfiltered (gdb_stdlog
,
4152 "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
4153 if (handle_syscall_event (ecs
) == 0)
4154 process_event_stop_test (ecs
);
4157 case TARGET_WAITKIND_STOPPED
:
4159 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_STOPPED\n");
4160 ecs
->event_thread
->suspend
.stop_signal
= ecs
->ws
.value
.sig
;
4161 handle_signal_stop (ecs
);
4164 case TARGET_WAITKIND_NO_HISTORY
:
4166 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_NO_HISTORY\n");
4167 /* Reverse execution: target ran out of history info. */
4169 delete_just_stopped_threads_single_step_breakpoints ();
4170 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
4171 observer_notify_no_history ();
4177 /* Come here when the program has stopped with a signal. */
4180 handle_signal_stop (struct execution_control_state
*ecs
)
4182 struct frame_info
*frame
;
4183 struct gdbarch
*gdbarch
;
4184 int stopped_by_watchpoint
;
4185 enum stop_kind stop_soon
;
4188 gdb_assert (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
4190 /* Do we need to clean up the state of a thread that has
4191 completed a displaced single-step? (Doing so usually affects
4192 the PC, so do it here, before we set stop_pc.) */
4193 displaced_step_fixup (ecs
->ptid
,
4194 ecs
->event_thread
->suspend
.stop_signal
);
4196 /* If we either finished a single-step or hit a breakpoint, but
4197 the user wanted this thread to be stopped, pretend we got a
4198 SIG0 (generic unsignaled stop). */
4199 if (ecs
->event_thread
->stop_requested
4200 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
4201 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4203 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
4207 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
4208 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
4209 struct cleanup
*old_chain
= save_inferior_ptid ();
4211 inferior_ptid
= ecs
->ptid
;
4213 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_pc = %s\n",
4214 paddress (gdbarch
, stop_pc
));
4215 if (target_stopped_by_watchpoint ())
4219 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped by watchpoint\n");
4221 if (target_stopped_data_address (¤t_target
, &addr
))
4222 fprintf_unfiltered (gdb_stdlog
,
4223 "infrun: stopped data address = %s\n",
4224 paddress (gdbarch
, addr
));
4226 fprintf_unfiltered (gdb_stdlog
,
4227 "infrun: (no data address available)\n");
4230 do_cleanups (old_chain
);
4233 /* This is originated from start_remote(), start_inferior() and
4234 shared libraries hook functions. */
4235 stop_soon
= get_inferior_stop_soon (ecs
->ptid
);
4236 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_REMOTE
)
4238 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
4239 context_switch (ecs
->ptid
);
4241 fprintf_unfiltered (gdb_stdlog
, "infrun: quietly stopped\n");
4242 stop_print_frame
= 1;
4247 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4250 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
4251 context_switch (ecs
->ptid
);
4253 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped\n");
4254 stop_print_frame
= 0;
4259 /* This originates from attach_command(). We need to overwrite
4260 the stop_signal here, because some kernels don't ignore a
4261 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
4262 See more comments in inferior.h. On the other hand, if we
4263 get a non-SIGSTOP, report it to the user - assume the backend
4264 will handle the SIGSTOP if it should show up later.
4266 Also consider that the attach is complete when we see a
4267 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
4268 target extended-remote report it instead of a SIGSTOP
4269 (e.g. gdbserver). We already rely on SIGTRAP being our
4270 signal, so this is no exception.
4272 Also consider that the attach is complete when we see a
4273 GDB_SIGNAL_0. In non-stop mode, GDB will explicitly tell
4274 the target to stop all threads of the inferior, in case the
4275 low level attach operation doesn't stop them implicitly. If
4276 they weren't stopped implicitly, then the stub will report a
4277 GDB_SIGNAL_0, meaning: stopped for no particular reason
4278 other than GDB's request. */
4279 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
4280 && (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_STOP
4281 || ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4282 || ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_0
))
4284 stop_print_frame
= 1;
4286 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4290 /* See if something interesting happened to the non-current thread. If
4291 so, then switch to that thread. */
4292 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
4295 fprintf_unfiltered (gdb_stdlog
, "infrun: context switch\n");
4297 context_switch (ecs
->ptid
);
4299 if (deprecated_context_hook
)
4300 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
4303 /* At this point, get hold of the now-current thread's frame. */
4304 frame
= get_current_frame ();
4305 gdbarch
= get_frame_arch (frame
);
4307 /* Pull the single step breakpoints out of the target. */
4308 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
4310 struct regcache
*regcache
;
4311 struct address_space
*aspace
;
4314 regcache
= get_thread_regcache (ecs
->ptid
);
4315 aspace
= get_regcache_aspace (regcache
);
4316 pc
= regcache_read_pc (regcache
);
4318 /* However, before doing so, if this single-step breakpoint was
4319 actually for another thread, set this thread up for moving
4321 if (!thread_has_single_step_breakpoint_here (ecs
->event_thread
,
4324 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
4328 fprintf_unfiltered (gdb_stdlog
,
4329 "infrun: [%s] hit another thread's "
4330 "single-step breakpoint\n",
4331 target_pid_to_str (ecs
->ptid
));
4333 ecs
->hit_singlestep_breakpoint
= 1;
4340 fprintf_unfiltered (gdb_stdlog
,
4341 "infrun: [%s] hit its "
4342 "single-step breakpoint\n",
4343 target_pid_to_str (ecs
->ptid
));
4347 delete_just_stopped_threads_single_step_breakpoints ();
4349 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4350 && ecs
->event_thread
->control
.trap_expected
4351 && ecs
->event_thread
->stepping_over_watchpoint
)
4352 stopped_by_watchpoint
= 0;
4354 stopped_by_watchpoint
= watchpoints_triggered (&ecs
->ws
);
4356 /* If necessary, step over this watchpoint. We'll be back to display
4358 if (stopped_by_watchpoint
4359 && (target_have_steppable_watchpoint
4360 || gdbarch_have_nonsteppable_watchpoint (gdbarch
)))
4362 /* At this point, we are stopped at an instruction which has
4363 attempted to write to a piece of memory under control of
4364 a watchpoint. The instruction hasn't actually executed
4365 yet. If we were to evaluate the watchpoint expression
4366 now, we would get the old value, and therefore no change
4367 would seem to have occurred.
4369 In order to make watchpoints work `right', we really need
4370 to complete the memory write, and then evaluate the
4371 watchpoint expression. We do this by single-stepping the
4374 It may not be necessary to disable the watchpoint to step over
4375 it. For example, the PA can (with some kernel cooperation)
4376 single step over a watchpoint without disabling the watchpoint.
4378 It is far more common to need to disable a watchpoint to step
4379 the inferior over it. If we have non-steppable watchpoints,
4380 we must disable the current watchpoint; it's simplest to
4381 disable all watchpoints.
4383 Any breakpoint at PC must also be stepped over -- if there's
4384 one, it will have already triggered before the watchpoint
4385 triggered, and we either already reported it to the user, or
4386 it didn't cause a stop and we called keep_going. In either
4387 case, if there was a breakpoint at PC, we must be trying to
4389 ecs
->event_thread
->stepping_over_watchpoint
= 1;
4394 ecs
->event_thread
->stepping_over_breakpoint
= 0;
4395 ecs
->event_thread
->stepping_over_watchpoint
= 0;
4396 bpstat_clear (&ecs
->event_thread
->control
.stop_bpstat
);
4397 ecs
->event_thread
->control
.stop_step
= 0;
4398 stop_print_frame
= 1;
4399 stopped_by_random_signal
= 0;
4401 /* Hide inlined functions starting here, unless we just performed stepi or
4402 nexti. After stepi and nexti, always show the innermost frame (not any
4403 inline function call sites). */
4404 if (ecs
->event_thread
->control
.step_range_end
!= 1)
4406 struct address_space
*aspace
=
4407 get_regcache_aspace (get_thread_regcache (ecs
->ptid
));
4409 /* skip_inline_frames is expensive, so we avoid it if we can
4410 determine that the address is one where functions cannot have
4411 been inlined. This improves performance with inferiors that
4412 load a lot of shared libraries, because the solib event
4413 breakpoint is defined as the address of a function (i.e. not
4414 inline). Note that we have to check the previous PC as well
4415 as the current one to catch cases when we have just
4416 single-stepped off a breakpoint prior to reinstating it.
4417 Note that we're assuming that the code we single-step to is
4418 not inline, but that's not definitive: there's nothing
4419 preventing the event breakpoint function from containing
4420 inlined code, and the single-step ending up there. If the
4421 user had set a breakpoint on that inlined code, the missing
4422 skip_inline_frames call would break things. Fortunately
4423 that's an extremely unlikely scenario. */
4424 if (!pc_at_non_inline_function (aspace
, stop_pc
, &ecs
->ws
)
4425 && !(ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4426 && ecs
->event_thread
->control
.trap_expected
4427 && pc_at_non_inline_function (aspace
,
4428 ecs
->event_thread
->prev_pc
,
4431 skip_inline_frames (ecs
->ptid
);
4433 /* Re-fetch current thread's frame in case that invalidated
4435 frame
= get_current_frame ();
4436 gdbarch
= get_frame_arch (frame
);
4440 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4441 && ecs
->event_thread
->control
.trap_expected
4442 && gdbarch_single_step_through_delay_p (gdbarch
)
4443 && currently_stepping (ecs
->event_thread
))
4445 /* We're trying to step off a breakpoint. Turns out that we're
4446 also on an instruction that needs to be stepped multiple
4447 times before it's been fully executing. E.g., architectures
4448 with a delay slot. It needs to be stepped twice, once for
4449 the instruction and once for the delay slot. */
4450 int step_through_delay
4451 = gdbarch_single_step_through_delay (gdbarch
, frame
);
4453 if (debug_infrun
&& step_through_delay
)
4454 fprintf_unfiltered (gdb_stdlog
, "infrun: step through delay\n");
4455 if (ecs
->event_thread
->control
.step_range_end
== 0
4456 && step_through_delay
)
4458 /* The user issued a continue when stopped at a breakpoint.
4459 Set up for another trap and get out of here. */
4460 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4464 else if (step_through_delay
)
4466 /* The user issued a step when stopped at a breakpoint.
4467 Maybe we should stop, maybe we should not - the delay
4468 slot *might* correspond to a line of source. In any
4469 case, don't decide that here, just set
4470 ecs->stepping_over_breakpoint, making sure we
4471 single-step again before breakpoints are re-inserted. */
4472 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4476 /* See if there is a breakpoint/watchpoint/catchpoint/etc. that
4477 handles this event. */
4478 ecs
->event_thread
->control
.stop_bpstat
4479 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
4480 stop_pc
, ecs
->ptid
, &ecs
->ws
);
4482 /* Following in case break condition called a
4484 stop_print_frame
= 1;
4486 /* This is where we handle "moribund" watchpoints. Unlike
4487 software breakpoints traps, hardware watchpoint traps are
4488 always distinguishable from random traps. If no high-level
4489 watchpoint is associated with the reported stop data address
4490 anymore, then the bpstat does not explain the signal ---
4491 simply make sure to ignore it if `stopped_by_watchpoint' is
4495 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4496 && !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
4498 && stopped_by_watchpoint
)
4499 fprintf_unfiltered (gdb_stdlog
,
4500 "infrun: no user watchpoint explains "
4501 "watchpoint SIGTRAP, ignoring\n");
4503 /* NOTE: cagney/2003-03-29: These checks for a random signal
4504 at one stage in the past included checks for an inferior
4505 function call's call dummy's return breakpoint. The original
4506 comment, that went with the test, read:
4508 ``End of a stack dummy. Some systems (e.g. Sony news) give
4509 another signal besides SIGTRAP, so check here as well as
4512 If someone ever tries to get call dummys on a
4513 non-executable stack to work (where the target would stop
4514 with something like a SIGSEGV), then those tests might need
4515 to be re-instated. Given, however, that the tests were only
4516 enabled when momentary breakpoints were not being used, I
4517 suspect that it won't be the case.
4519 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
4520 be necessary for call dummies on a non-executable stack on
4523 /* See if the breakpoints module can explain the signal. */
4525 = !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
4526 ecs
->event_thread
->suspend
.stop_signal
);
4528 /* Maybe this was a trap for a software breakpoint that has since
4530 if (random_signal
&& target_stopped_by_sw_breakpoint ())
4532 if (program_breakpoint_here_p (gdbarch
, stop_pc
))
4534 struct regcache
*regcache
;
4537 /* Re-adjust PC to what the program would see if GDB was not
4539 regcache
= get_thread_regcache (ecs
->event_thread
->ptid
);
4540 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
4543 struct cleanup
*old_cleanups
= make_cleanup (null_cleanup
, NULL
);
4545 if (record_full_is_used ())
4546 record_full_gdb_operation_disable_set ();
4548 regcache_write_pc (regcache
, stop_pc
+ decr_pc
);
4550 do_cleanups (old_cleanups
);
4555 /* A delayed software breakpoint event. Ignore the trap. */
4557 fprintf_unfiltered (gdb_stdlog
,
4558 "infrun: delayed software breakpoint "
4559 "trap, ignoring\n");
4564 /* Maybe this was a trap for a hardware breakpoint/watchpoint that
4565 has since been removed. */
4566 if (random_signal
&& target_stopped_by_hw_breakpoint ())
4568 /* A delayed hardware breakpoint event. Ignore the trap. */
4570 fprintf_unfiltered (gdb_stdlog
,
4571 "infrun: delayed hardware breakpoint/watchpoint "
4572 "trap, ignoring\n");
4576 /* If not, perhaps stepping/nexting can. */
4578 random_signal
= !(ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4579 && currently_stepping (ecs
->event_thread
));
4581 /* Perhaps the thread hit a single-step breakpoint of _another_
4582 thread. Single-step breakpoints are transparent to the
4583 breakpoints module. */
4585 random_signal
= !ecs
->hit_singlestep_breakpoint
;
4587 /* No? Perhaps we got a moribund watchpoint. */
4589 random_signal
= !stopped_by_watchpoint
;
4591 /* For the program's own signals, act according to
4592 the signal handling tables. */
4596 /* Signal not for debugging purposes. */
4597 struct inferior
*inf
= find_inferior_ptid (ecs
->ptid
);
4598 enum gdb_signal stop_signal
= ecs
->event_thread
->suspend
.stop_signal
;
4601 fprintf_unfiltered (gdb_stdlog
, "infrun: random signal (%s)\n",
4602 gdb_signal_to_symbol_string (stop_signal
));
4604 stopped_by_random_signal
= 1;
4606 /* Always stop on signals if we're either just gaining control
4607 of the program, or the user explicitly requested this thread
4608 to remain stopped. */
4609 if (stop_soon
!= NO_STOP_QUIETLY
4610 || ecs
->event_thread
->stop_requested
4612 && signal_stop_state (ecs
->event_thread
->suspend
.stop_signal
)))
4618 /* Notify observers the signal has "handle print" set. Note we
4619 returned early above if stopping; normal_stop handles the
4620 printing in that case. */
4621 if (signal_print
[ecs
->event_thread
->suspend
.stop_signal
])
4623 /* The signal table tells us to print about this signal. */
4624 target_terminal_ours_for_output ();
4625 observer_notify_signal_received (ecs
->event_thread
->suspend
.stop_signal
);
4626 target_terminal_inferior ();
4629 /* Clear the signal if it should not be passed. */
4630 if (signal_program
[ecs
->event_thread
->suspend
.stop_signal
] == 0)
4631 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4633 if (ecs
->event_thread
->prev_pc
== stop_pc
4634 && ecs
->event_thread
->control
.trap_expected
4635 && ecs
->event_thread
->control
.step_resume_breakpoint
== NULL
)
4637 /* We were just starting a new sequence, attempting to
4638 single-step off of a breakpoint and expecting a SIGTRAP.
4639 Instead this signal arrives. This signal will take us out
4640 of the stepping range so GDB needs to remember to, when
4641 the signal handler returns, resume stepping off that
4643 /* To simplify things, "continue" is forced to use the same
4644 code paths as single-step - set a breakpoint at the
4645 signal return address and then, once hit, step off that
4648 fprintf_unfiltered (gdb_stdlog
,
4649 "infrun: signal arrived while stepping over "
4652 insert_hp_step_resume_breakpoint_at_frame (frame
);
4653 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
4654 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4655 ecs
->event_thread
->control
.trap_expected
= 0;
4657 /* If we were nexting/stepping some other thread, switch to
4658 it, so that we don't continue it, losing control. */
4659 if (!switch_back_to_stepped_thread (ecs
))
4664 if (ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
4665 && (pc_in_thread_step_range (stop_pc
, ecs
->event_thread
)
4666 || ecs
->event_thread
->control
.step_range_end
== 1)
4667 && frame_id_eq (get_stack_frame_id (frame
),
4668 ecs
->event_thread
->control
.step_stack_frame_id
)
4669 && ecs
->event_thread
->control
.step_resume_breakpoint
== NULL
)
4671 /* The inferior is about to take a signal that will take it
4672 out of the single step range. Set a breakpoint at the
4673 current PC (which is presumably where the signal handler
4674 will eventually return) and then allow the inferior to
4677 Note that this is only needed for a signal delivered
4678 while in the single-step range. Nested signals aren't a
4679 problem as they eventually all return. */
4681 fprintf_unfiltered (gdb_stdlog
,
4682 "infrun: signal may take us out of "
4683 "single-step range\n");
4685 insert_hp_step_resume_breakpoint_at_frame (frame
);
4686 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
4687 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4688 ecs
->event_thread
->control
.trap_expected
= 0;
4693 /* Note: step_resume_breakpoint may be non-NULL. This occures
4694 when either there's a nested signal, or when there's a
4695 pending signal enabled just as the signal handler returns
4696 (leaving the inferior at the step-resume-breakpoint without
4697 actually executing it). Either way continue until the
4698 breakpoint is really hit. */
4700 if (!switch_back_to_stepped_thread (ecs
))
4703 fprintf_unfiltered (gdb_stdlog
,
4704 "infrun: random signal, keep going\n");
4711 process_event_stop_test (ecs
);
4714 /* Come here when we've got some debug event / signal we can explain
4715 (IOW, not a random signal), and test whether it should cause a
4716 stop, or whether we should resume the inferior (transparently).
4717 E.g., could be a breakpoint whose condition evaluates false; we
4718 could be still stepping within the line; etc. */
4721 process_event_stop_test (struct execution_control_state
*ecs
)
4723 struct symtab_and_line stop_pc_sal
;
4724 struct frame_info
*frame
;
4725 struct gdbarch
*gdbarch
;
4726 CORE_ADDR jmp_buf_pc
;
4727 struct bpstat_what what
;
4729 /* Handle cases caused by hitting a breakpoint. */
4731 frame
= get_current_frame ();
4732 gdbarch
= get_frame_arch (frame
);
4734 what
= bpstat_what (ecs
->event_thread
->control
.stop_bpstat
);
4736 if (what
.call_dummy
)
4738 stop_stack_dummy
= what
.call_dummy
;
4741 /* If we hit an internal event that triggers symbol changes, the
4742 current frame will be invalidated within bpstat_what (e.g., if we
4743 hit an internal solib event). Re-fetch it. */
4744 frame
= get_current_frame ();
4745 gdbarch
= get_frame_arch (frame
);
4747 switch (what
.main_action
)
4749 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
4750 /* If we hit the breakpoint at longjmp while stepping, we
4751 install a momentary breakpoint at the target of the
4755 fprintf_unfiltered (gdb_stdlog
,
4756 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
4758 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4760 if (what
.is_longjmp
)
4762 struct value
*arg_value
;
4764 /* If we set the longjmp breakpoint via a SystemTap probe,
4765 then use it to extract the arguments. The destination PC
4766 is the third argument to the probe. */
4767 arg_value
= probe_safe_evaluate_at_pc (frame
, 2);
4770 jmp_buf_pc
= value_as_address (arg_value
);
4771 jmp_buf_pc
= gdbarch_addr_bits_remove (gdbarch
, jmp_buf_pc
);
4773 else if (!gdbarch_get_longjmp_target_p (gdbarch
)
4774 || !gdbarch_get_longjmp_target (gdbarch
,
4775 frame
, &jmp_buf_pc
))
4778 fprintf_unfiltered (gdb_stdlog
,
4779 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME "
4780 "(!gdbarch_get_longjmp_target)\n");
4785 /* Insert a breakpoint at resume address. */
4786 insert_longjmp_resume_breakpoint (gdbarch
, jmp_buf_pc
);
4789 check_exception_resume (ecs
, frame
);
4793 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
4795 struct frame_info
*init_frame
;
4797 /* There are several cases to consider.
4799 1. The initiating frame no longer exists. In this case we
4800 must stop, because the exception or longjmp has gone too
4803 2. The initiating frame exists, and is the same as the
4804 current frame. We stop, because the exception or longjmp
4807 3. The initiating frame exists and is different from the
4808 current frame. This means the exception or longjmp has
4809 been caught beneath the initiating frame, so keep going.
4811 4. longjmp breakpoint has been placed just to protect
4812 against stale dummy frames and user is not interested in
4813 stopping around longjmps. */
4816 fprintf_unfiltered (gdb_stdlog
,
4817 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
4819 gdb_assert (ecs
->event_thread
->control
.exception_resume_breakpoint
4821 delete_exception_resume_breakpoint (ecs
->event_thread
);
4823 if (what
.is_longjmp
)
4825 check_longjmp_breakpoint_for_call_dummy (ecs
->event_thread
);
4827 if (!frame_id_p (ecs
->event_thread
->initiating_frame
))
4835 init_frame
= frame_find_by_id (ecs
->event_thread
->initiating_frame
);
4839 struct frame_id current_id
4840 = get_frame_id (get_current_frame ());
4841 if (frame_id_eq (current_id
,
4842 ecs
->event_thread
->initiating_frame
))
4844 /* Case 2. Fall through. */
4854 /* For Cases 1 and 2, remove the step-resume breakpoint, if it
4856 delete_step_resume_breakpoint (ecs
->event_thread
);
4858 end_stepping_range (ecs
);
4862 case BPSTAT_WHAT_SINGLE
:
4864 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_SINGLE\n");
4865 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4866 /* Still need to check other stuff, at least the case where we
4867 are stepping and step out of the right range. */
4870 case BPSTAT_WHAT_STEP_RESUME
:
4872 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
4874 delete_step_resume_breakpoint (ecs
->event_thread
);
4875 if (ecs
->event_thread
->control
.proceed_to_finish
4876 && execution_direction
== EXEC_REVERSE
)
4878 struct thread_info
*tp
= ecs
->event_thread
;
4880 /* We are finishing a function in reverse, and just hit the
4881 step-resume breakpoint at the start address of the
4882 function, and we're almost there -- just need to back up
4883 by one more single-step, which should take us back to the
4885 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
4889 fill_in_stop_func (gdbarch
, ecs
);
4890 if (stop_pc
== ecs
->stop_func_start
4891 && execution_direction
== EXEC_REVERSE
)
4893 /* We are stepping over a function call in reverse, and just
4894 hit the step-resume breakpoint at the start address of
4895 the function. Go back to single-stepping, which should
4896 take us back to the function call. */
4897 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4903 case BPSTAT_WHAT_STOP_NOISY
:
4905 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
4906 stop_print_frame
= 1;
4908 /* Assume the thread stopped for a breapoint. We'll still check
4909 whether a/the breakpoint is there when the thread is next
4911 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4916 case BPSTAT_WHAT_STOP_SILENT
:
4918 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
4919 stop_print_frame
= 0;
4921 /* Assume the thread stopped for a breapoint. We'll still check
4922 whether a/the breakpoint is there when the thread is next
4924 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4928 case BPSTAT_WHAT_HP_STEP_RESUME
:
4930 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_HP_STEP_RESUME\n");
4932 delete_step_resume_breakpoint (ecs
->event_thread
);
4933 if (ecs
->event_thread
->step_after_step_resume_breakpoint
)
4935 /* Back when the step-resume breakpoint was inserted, we
4936 were trying to single-step off a breakpoint. Go back to
4938 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
4939 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4945 case BPSTAT_WHAT_KEEP_CHECKING
:
4949 /* If we stepped a permanent breakpoint and we had a high priority
4950 step-resume breakpoint for the address we stepped, but we didn't
4951 hit it, then we must have stepped into the signal handler. The
4952 step-resume was only necessary to catch the case of _not_
4953 stepping into the handler, so delete it, and fall through to
4954 checking whether the step finished. */
4955 if (ecs
->event_thread
->stepped_breakpoint
)
4957 struct breakpoint
*sr_bp
4958 = ecs
->event_thread
->control
.step_resume_breakpoint
;
4960 if (sr_bp
->loc
->permanent
4961 && sr_bp
->type
== bp_hp_step_resume
4962 && sr_bp
->loc
->address
== ecs
->event_thread
->prev_pc
)
4965 fprintf_unfiltered (gdb_stdlog
,
4966 "infrun: stepped permanent breakpoint, stopped in "
4968 delete_step_resume_breakpoint (ecs
->event_thread
);
4969 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
4973 /* We come here if we hit a breakpoint but should not stop for it.
4974 Possibly we also were stepping and should stop for that. So fall
4975 through and test for stepping. But, if not stepping, do not
4978 /* In all-stop mode, if we're currently stepping but have stopped in
4979 some other thread, we need to switch back to the stepped thread. */
4980 if (switch_back_to_stepped_thread (ecs
))
4983 if (ecs
->event_thread
->control
.step_resume_breakpoint
)
4986 fprintf_unfiltered (gdb_stdlog
,
4987 "infrun: step-resume breakpoint is inserted\n");
4989 /* Having a step-resume breakpoint overrides anything
4990 else having to do with stepping commands until
4991 that breakpoint is reached. */
4996 if (ecs
->event_thread
->control
.step_range_end
== 0)
4999 fprintf_unfiltered (gdb_stdlog
, "infrun: no stepping, continue\n");
5000 /* Likewise if we aren't even stepping. */
5005 /* Re-fetch current thread's frame in case the code above caused
5006 the frame cache to be re-initialized, making our FRAME variable
5007 a dangling pointer. */
5008 frame
= get_current_frame ();
5009 gdbarch
= get_frame_arch (frame
);
5010 fill_in_stop_func (gdbarch
, ecs
);
5012 /* If stepping through a line, keep going if still within it.
5014 Note that step_range_end is the address of the first instruction
5015 beyond the step range, and NOT the address of the last instruction
5018 Note also that during reverse execution, we may be stepping
5019 through a function epilogue and therefore must detect when
5020 the current-frame changes in the middle of a line. */
5022 if (pc_in_thread_step_range (stop_pc
, ecs
->event_thread
)
5023 && (execution_direction
!= EXEC_REVERSE
5024 || frame_id_eq (get_frame_id (frame
),
5025 ecs
->event_thread
->control
.step_frame_id
)))
5029 (gdb_stdlog
, "infrun: stepping inside range [%s-%s]\n",
5030 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_start
),
5031 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_end
));
5033 /* Tentatively re-enable range stepping; `resume' disables it if
5034 necessary (e.g., if we're stepping over a breakpoint or we
5035 have software watchpoints). */
5036 ecs
->event_thread
->control
.may_range_step
= 1;
5038 /* When stepping backward, stop at beginning of line range
5039 (unless it's the function entry point, in which case
5040 keep going back to the call point). */
5041 if (stop_pc
== ecs
->event_thread
->control
.step_range_start
5042 && stop_pc
!= ecs
->stop_func_start
5043 && execution_direction
== EXEC_REVERSE
)
5044 end_stepping_range (ecs
);
5051 /* We stepped out of the stepping range. */
5053 /* If we are stepping at the source level and entered the runtime
5054 loader dynamic symbol resolution code...
5056 EXEC_FORWARD: we keep on single stepping until we exit the run
5057 time loader code and reach the callee's address.
5059 EXEC_REVERSE: we've already executed the callee (backward), and
5060 the runtime loader code is handled just like any other
5061 undebuggable function call. Now we need only keep stepping
5062 backward through the trampoline code, and that's handled further
5063 down, so there is nothing for us to do here. */
5065 if (execution_direction
!= EXEC_REVERSE
5066 && ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
5067 && in_solib_dynsym_resolve_code (stop_pc
))
5069 CORE_ADDR pc_after_resolver
=
5070 gdbarch_skip_solib_resolver (gdbarch
, stop_pc
);
5073 fprintf_unfiltered (gdb_stdlog
,
5074 "infrun: stepped into dynsym resolve code\n");
5076 if (pc_after_resolver
)
5078 /* Set up a step-resume breakpoint at the address
5079 indicated by SKIP_SOLIB_RESOLVER. */
5080 struct symtab_and_line sr_sal
;
5083 sr_sal
.pc
= pc_after_resolver
;
5084 sr_sal
.pspace
= get_frame_program_space (frame
);
5086 insert_step_resume_breakpoint_at_sal (gdbarch
,
5087 sr_sal
, null_frame_id
);
5094 if (ecs
->event_thread
->control
.step_range_end
!= 1
5095 && (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
5096 || ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
5097 && get_frame_type (frame
) == SIGTRAMP_FRAME
)
5100 fprintf_unfiltered (gdb_stdlog
,
5101 "infrun: stepped into signal trampoline\n");
5102 /* The inferior, while doing a "step" or "next", has ended up in
5103 a signal trampoline (either by a signal being delivered or by
5104 the signal handler returning). Just single-step until the
5105 inferior leaves the trampoline (either by calling the handler
5111 /* If we're in the return path from a shared library trampoline,
5112 we want to proceed through the trampoline when stepping. */
5113 /* macro/2012-04-25: This needs to come before the subroutine
5114 call check below as on some targets return trampolines look
5115 like subroutine calls (MIPS16 return thunks). */
5116 if (gdbarch_in_solib_return_trampoline (gdbarch
,
5117 stop_pc
, ecs
->stop_func_name
)
5118 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
5120 /* Determine where this trampoline returns. */
5121 CORE_ADDR real_stop_pc
;
5123 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
5126 fprintf_unfiltered (gdb_stdlog
,
5127 "infrun: stepped into solib return tramp\n");
5129 /* Only proceed through if we know where it's going. */
5132 /* And put the step-breakpoint there and go until there. */
5133 struct symtab_and_line sr_sal
;
5135 init_sal (&sr_sal
); /* initialize to zeroes */
5136 sr_sal
.pc
= real_stop_pc
;
5137 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
5138 sr_sal
.pspace
= get_frame_program_space (frame
);
5140 /* Do not specify what the fp should be when we stop since
5141 on some machines the prologue is where the new fp value
5143 insert_step_resume_breakpoint_at_sal (gdbarch
,
5144 sr_sal
, null_frame_id
);
5146 /* Restart without fiddling with the step ranges or
5153 /* Check for subroutine calls. The check for the current frame
5154 equalling the step ID is not necessary - the check of the
5155 previous frame's ID is sufficient - but it is a common case and
5156 cheaper than checking the previous frame's ID.
5158 NOTE: frame_id_eq will never report two invalid frame IDs as
5159 being equal, so to get into this block, both the current and
5160 previous frame must have valid frame IDs. */
5161 /* The outer_frame_id check is a heuristic to detect stepping
5162 through startup code. If we step over an instruction which
5163 sets the stack pointer from an invalid value to a valid value,
5164 we may detect that as a subroutine call from the mythical
5165 "outermost" function. This could be fixed by marking
5166 outermost frames as !stack_p,code_p,special_p. Then the
5167 initial outermost frame, before sp was valid, would
5168 have code_addr == &_start. See the comment in frame_id_eq
5170 if (!frame_id_eq (get_stack_frame_id (frame
),
5171 ecs
->event_thread
->control
.step_stack_frame_id
)
5172 && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()),
5173 ecs
->event_thread
->control
.step_stack_frame_id
)
5174 && (!frame_id_eq (ecs
->event_thread
->control
.step_stack_frame_id
,
5176 || step_start_function
!= find_pc_function (stop_pc
))))
5178 CORE_ADDR real_stop_pc
;
5181 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into subroutine\n");
5183 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_NONE
)
5185 /* I presume that step_over_calls is only 0 when we're
5186 supposed to be stepping at the assembly language level
5187 ("stepi"). Just stop. */
5188 /* And this works the same backward as frontward. MVS */
5189 end_stepping_range (ecs
);
5193 /* Reverse stepping through solib trampolines. */
5195 if (execution_direction
== EXEC_REVERSE
5196 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
5197 && (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
5198 || (ecs
->stop_func_start
== 0
5199 && in_solib_dynsym_resolve_code (stop_pc
))))
5201 /* Any solib trampoline code can be handled in reverse
5202 by simply continuing to single-step. We have already
5203 executed the solib function (backwards), and a few
5204 steps will take us back through the trampoline to the
5210 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
5212 /* We're doing a "next".
5214 Normal (forward) execution: set a breakpoint at the
5215 callee's return address (the address at which the caller
5218 Reverse (backward) execution. set the step-resume
5219 breakpoint at the start of the function that we just
5220 stepped into (backwards), and continue to there. When we
5221 get there, we'll need to single-step back to the caller. */
5223 if (execution_direction
== EXEC_REVERSE
)
5225 /* If we're already at the start of the function, we've either
5226 just stepped backward into a single instruction function,
5227 or stepped back out of a signal handler to the first instruction
5228 of the function. Just keep going, which will single-step back
5230 if (ecs
->stop_func_start
!= stop_pc
&& ecs
->stop_func_start
!= 0)
5232 struct symtab_and_line sr_sal
;
5234 /* Normal function call return (static or dynamic). */
5236 sr_sal
.pc
= ecs
->stop_func_start
;
5237 sr_sal
.pspace
= get_frame_program_space (frame
);
5238 insert_step_resume_breakpoint_at_sal (gdbarch
,
5239 sr_sal
, null_frame_id
);
5243 insert_step_resume_breakpoint_at_caller (frame
);
5249 /* If we are in a function call trampoline (a stub between the
5250 calling routine and the real function), locate the real
5251 function. That's what tells us (a) whether we want to step
5252 into it at all, and (b) what prologue we want to run to the
5253 end of, if we do step into it. */
5254 real_stop_pc
= skip_language_trampoline (frame
, stop_pc
);
5255 if (real_stop_pc
== 0)
5256 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
5257 if (real_stop_pc
!= 0)
5258 ecs
->stop_func_start
= real_stop_pc
;
5260 if (real_stop_pc
!= 0 && in_solib_dynsym_resolve_code (real_stop_pc
))
5262 struct symtab_and_line sr_sal
;
5265 sr_sal
.pc
= ecs
->stop_func_start
;
5266 sr_sal
.pspace
= get_frame_program_space (frame
);
5268 insert_step_resume_breakpoint_at_sal (gdbarch
,
5269 sr_sal
, null_frame_id
);
5274 /* If we have line number information for the function we are
5275 thinking of stepping into and the function isn't on the skip
5278 If there are several symtabs at that PC (e.g. with include
5279 files), just want to know whether *any* of them have line
5280 numbers. find_pc_line handles this. */
5282 struct symtab_and_line tmp_sal
;
5284 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
5285 if (tmp_sal
.line
!= 0
5286 && !function_name_is_marked_for_skip (ecs
->stop_func_name
,
5289 if (execution_direction
== EXEC_REVERSE
)
5290 handle_step_into_function_backward (gdbarch
, ecs
);
5292 handle_step_into_function (gdbarch
, ecs
);
5297 /* If we have no line number and the step-stop-if-no-debug is
5298 set, we stop the step so that the user has a chance to switch
5299 in assembly mode. */
5300 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
5301 && step_stop_if_no_debug
)
5303 end_stepping_range (ecs
);
5307 if (execution_direction
== EXEC_REVERSE
)
5309 /* If we're already at the start of the function, we've either just
5310 stepped backward into a single instruction function without line
5311 number info, or stepped back out of a signal handler to the first
5312 instruction of the function without line number info. Just keep
5313 going, which will single-step back to the caller. */
5314 if (ecs
->stop_func_start
!= stop_pc
)
5316 /* Set a breakpoint at callee's start address.
5317 From there we can step once and be back in the caller. */
5318 struct symtab_and_line sr_sal
;
5321 sr_sal
.pc
= ecs
->stop_func_start
;
5322 sr_sal
.pspace
= get_frame_program_space (frame
);
5323 insert_step_resume_breakpoint_at_sal (gdbarch
,
5324 sr_sal
, null_frame_id
);
5328 /* Set a breakpoint at callee's return address (the address
5329 at which the caller will resume). */
5330 insert_step_resume_breakpoint_at_caller (frame
);
5336 /* Reverse stepping through solib trampolines. */
5338 if (execution_direction
== EXEC_REVERSE
5339 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
5341 if (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
5342 || (ecs
->stop_func_start
== 0
5343 && in_solib_dynsym_resolve_code (stop_pc
)))
5345 /* Any solib trampoline code can be handled in reverse
5346 by simply continuing to single-step. We have already
5347 executed the solib function (backwards), and a few
5348 steps will take us back through the trampoline to the
5353 else if (in_solib_dynsym_resolve_code (stop_pc
))
5355 /* Stepped backward into the solib dynsym resolver.
5356 Set a breakpoint at its start and continue, then
5357 one more step will take us out. */
5358 struct symtab_and_line sr_sal
;
5361 sr_sal
.pc
= ecs
->stop_func_start
;
5362 sr_sal
.pspace
= get_frame_program_space (frame
);
5363 insert_step_resume_breakpoint_at_sal (gdbarch
,
5364 sr_sal
, null_frame_id
);
5370 stop_pc_sal
= find_pc_line (stop_pc
, 0);
5372 /* NOTE: tausq/2004-05-24: This if block used to be done before all
5373 the trampoline processing logic, however, there are some trampolines
5374 that have no names, so we should do trampoline handling first. */
5375 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
5376 && ecs
->stop_func_name
== NULL
5377 && stop_pc_sal
.line
== 0)
5380 fprintf_unfiltered (gdb_stdlog
,
5381 "infrun: stepped into undebuggable function\n");
5383 /* The inferior just stepped into, or returned to, an
5384 undebuggable function (where there is no debugging information
5385 and no line number corresponding to the address where the
5386 inferior stopped). Since we want to skip this kind of code,
5387 we keep going until the inferior returns from this
5388 function - unless the user has asked us not to (via
5389 set step-mode) or we no longer know how to get back
5390 to the call site. */
5391 if (step_stop_if_no_debug
5392 || !frame_id_p (frame_unwind_caller_id (frame
)))
5394 /* If we have no line number and the step-stop-if-no-debug
5395 is set, we stop the step so that the user has a chance to
5396 switch in assembly mode. */
5397 end_stepping_range (ecs
);
5402 /* Set a breakpoint at callee's return address (the address
5403 at which the caller will resume). */
5404 insert_step_resume_breakpoint_at_caller (frame
);
5410 if (ecs
->event_thread
->control
.step_range_end
== 1)
5412 /* It is stepi or nexti. We always want to stop stepping after
5415 fprintf_unfiltered (gdb_stdlog
, "infrun: stepi/nexti\n");
5416 end_stepping_range (ecs
);
5420 if (stop_pc_sal
.line
== 0)
5422 /* We have no line number information. That means to stop
5423 stepping (does this always happen right after one instruction,
5424 when we do "s" in a function with no line numbers,
5425 or can this happen as a result of a return or longjmp?). */
5427 fprintf_unfiltered (gdb_stdlog
, "infrun: no line number info\n");
5428 end_stepping_range (ecs
);
5432 /* Look for "calls" to inlined functions, part one. If the inline
5433 frame machinery detected some skipped call sites, we have entered
5434 a new inline function. */
5436 if (frame_id_eq (get_frame_id (get_current_frame ()),
5437 ecs
->event_thread
->control
.step_frame_id
)
5438 && inline_skipped_frames (ecs
->ptid
))
5440 struct symtab_and_line call_sal
;
5443 fprintf_unfiltered (gdb_stdlog
,
5444 "infrun: stepped into inlined function\n");
5446 find_frame_sal (get_current_frame (), &call_sal
);
5448 if (ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_ALL
)
5450 /* For "step", we're going to stop. But if the call site
5451 for this inlined function is on the same source line as
5452 we were previously stepping, go down into the function
5453 first. Otherwise stop at the call site. */
5455 if (call_sal
.line
== ecs
->event_thread
->current_line
5456 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
5457 step_into_inline_frame (ecs
->ptid
);
5459 end_stepping_range (ecs
);
5464 /* For "next", we should stop at the call site if it is on a
5465 different source line. Otherwise continue through the
5466 inlined function. */
5467 if (call_sal
.line
== ecs
->event_thread
->current_line
5468 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
5471 end_stepping_range (ecs
);
5476 /* Look for "calls" to inlined functions, part two. If we are still
5477 in the same real function we were stepping through, but we have
5478 to go further up to find the exact frame ID, we are stepping
5479 through a more inlined call beyond its call site. */
5481 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
5482 && !frame_id_eq (get_frame_id (get_current_frame ()),
5483 ecs
->event_thread
->control
.step_frame_id
)
5484 && stepped_in_from (get_current_frame (),
5485 ecs
->event_thread
->control
.step_frame_id
))
5488 fprintf_unfiltered (gdb_stdlog
,
5489 "infrun: stepping through inlined function\n");
5491 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
5494 end_stepping_range (ecs
);
5498 if ((stop_pc
== stop_pc_sal
.pc
)
5499 && (ecs
->event_thread
->current_line
!= stop_pc_sal
.line
5500 || ecs
->event_thread
->current_symtab
!= stop_pc_sal
.symtab
))
5502 /* We are at the start of a different line. So stop. Note that
5503 we don't stop if we step into the middle of a different line.
5504 That is said to make things like for (;;) statements work
5507 fprintf_unfiltered (gdb_stdlog
,
5508 "infrun: stepped to a different line\n");
5509 end_stepping_range (ecs
);
5513 /* We aren't done stepping.
5515 Optimize by setting the stepping range to the line.
5516 (We might not be in the original line, but if we entered a
5517 new line in mid-statement, we continue stepping. This makes
5518 things like for(;;) statements work better.) */
5520 ecs
->event_thread
->control
.step_range_start
= stop_pc_sal
.pc
;
5521 ecs
->event_thread
->control
.step_range_end
= stop_pc_sal
.end
;
5522 ecs
->event_thread
->control
.may_range_step
= 1;
5523 set_step_info (frame
, stop_pc_sal
);
5526 fprintf_unfiltered (gdb_stdlog
, "infrun: keep going\n");
5530 /* In all-stop mode, if we're currently stepping but have stopped in
5531 some other thread, we may need to switch back to the stepped
5532 thread. Returns true we set the inferior running, false if we left
5533 it stopped (and the event needs further processing). */
5536 switch_back_to_stepped_thread (struct execution_control_state
*ecs
)
5540 struct thread_info
*tp
;
5541 struct thread_info
*stepping_thread
;
5542 struct thread_info
*step_over
;
5544 /* If any thread is blocked on some internal breakpoint, and we
5545 simply need to step over that breakpoint to get it going
5546 again, do that first. */
5548 /* However, if we see an event for the stepping thread, then we
5549 know all other threads have been moved past their breakpoints
5550 already. Let the caller check whether the step is finished,
5551 etc., before deciding to move it past a breakpoint. */
5552 if (ecs
->event_thread
->control
.step_range_end
!= 0)
5555 /* Check if the current thread is blocked on an incomplete
5556 step-over, interrupted by a random signal. */
5557 if (ecs
->event_thread
->control
.trap_expected
5558 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_TRAP
)
5562 fprintf_unfiltered (gdb_stdlog
,
5563 "infrun: need to finish step-over of [%s]\n",
5564 target_pid_to_str (ecs
->event_thread
->ptid
));
5570 /* Check if the current thread is blocked by a single-step
5571 breakpoint of another thread. */
5572 if (ecs
->hit_singlestep_breakpoint
)
5576 fprintf_unfiltered (gdb_stdlog
,
5577 "infrun: need to step [%s] over single-step "
5579 target_pid_to_str (ecs
->ptid
));
5585 /* Otherwise, we no longer expect a trap in the current thread.
5586 Clear the trap_expected flag before switching back -- this is
5587 what keep_going does as well, if we call it. */
5588 ecs
->event_thread
->control
.trap_expected
= 0;
5590 /* Likewise, clear the signal if it should not be passed. */
5591 if (!signal_program
[ecs
->event_thread
->suspend
.stop_signal
])
5592 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5594 /* If scheduler locking applies even if not stepping, there's no
5595 need to walk over threads. Above we've checked whether the
5596 current thread is stepping. If some other thread not the
5597 event thread is stepping, then it must be that scheduler
5598 locking is not in effect. */
5599 if (schedlock_applies (0))
5602 /* Look for the stepping/nexting thread, and check if any other
5603 thread other than the stepping thread needs to start a
5604 step-over. Do all step-overs before actually proceeding with
5606 stepping_thread
= NULL
;
5608 ALL_NON_EXITED_THREADS (tp
)
5610 /* Ignore threads of processes we're not resuming. */
5612 && ptid_get_pid (tp
->ptid
) != ptid_get_pid (inferior_ptid
))
5615 /* When stepping over a breakpoint, we lock all threads
5616 except the one that needs to move past the breakpoint.
5617 If a non-event thread has this set, the "incomplete
5618 step-over" check above should have caught it earlier. */
5619 gdb_assert (!tp
->control
.trap_expected
);
5621 /* Did we find the stepping thread? */
5622 if (tp
->control
.step_range_end
)
5624 /* Yep. There should only one though. */
5625 gdb_assert (stepping_thread
== NULL
);
5627 /* The event thread is handled at the top, before we
5629 gdb_assert (tp
!= ecs
->event_thread
);
5631 /* If some thread other than the event thread is
5632 stepping, then scheduler locking can't be in effect,
5633 otherwise we wouldn't have resumed the current event
5634 thread in the first place. */
5635 gdb_assert (!schedlock_applies (currently_stepping (tp
)));
5637 stepping_thread
= tp
;
5639 else if (thread_still_needs_step_over (tp
))
5643 /* At the top we've returned early if the event thread
5644 is stepping. If some other thread not the event
5645 thread is stepping, then scheduler locking can't be
5646 in effect, and we can resume this thread. No need to
5647 keep looking for the stepping thread then. */
5652 if (step_over
!= NULL
)
5657 fprintf_unfiltered (gdb_stdlog
,
5658 "infrun: need to step-over [%s]\n",
5659 target_pid_to_str (tp
->ptid
));
5662 /* Only the stepping thread should have this set. */
5663 gdb_assert (tp
->control
.step_range_end
== 0);
5665 ecs
->ptid
= tp
->ptid
;
5666 ecs
->event_thread
= tp
;
5667 switch_to_thread (ecs
->ptid
);
5672 if (stepping_thread
!= NULL
)
5674 struct frame_info
*frame
;
5675 struct gdbarch
*gdbarch
;
5677 tp
= stepping_thread
;
5679 /* If the stepping thread exited, then don't try to switch
5680 back and resume it, which could fail in several different
5681 ways depending on the target. Instead, just keep going.
5683 We can find a stepping dead thread in the thread list in
5686 - The target supports thread exit events, and when the
5687 target tries to delete the thread from the thread list,
5688 inferior_ptid pointed at the exiting thread. In such
5689 case, calling delete_thread does not really remove the
5690 thread from the list; instead, the thread is left listed,
5691 with 'exited' state.
5693 - The target's debug interface does not support thread
5694 exit events, and so we have no idea whatsoever if the
5695 previously stepping thread is still alive. For that
5696 reason, we need to synchronously query the target
5698 if (is_exited (tp
->ptid
)
5699 || !target_thread_alive (tp
->ptid
))
5702 fprintf_unfiltered (gdb_stdlog
,
5703 "infrun: not switching back to "
5704 "stepped thread, it has vanished\n");
5706 delete_thread (tp
->ptid
);
5712 fprintf_unfiltered (gdb_stdlog
,
5713 "infrun: switching back to stepped thread\n");
5715 ecs
->event_thread
= tp
;
5716 ecs
->ptid
= tp
->ptid
;
5717 context_switch (ecs
->ptid
);
5719 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
5720 frame
= get_current_frame ();
5721 gdbarch
= get_frame_arch (frame
);
5723 /* If the PC of the thread we were trying to single-step has
5724 changed, then that thread has trapped or been signaled,
5725 but the event has not been reported to GDB yet. Re-poll
5726 the target looking for this particular thread's event
5727 (i.e. temporarily enable schedlock) by:
5729 - setting a break at the current PC
5730 - resuming that particular thread, only (by setting
5733 This prevents us continuously moving the single-step
5734 breakpoint forward, one instruction at a time,
5737 if (stop_pc
!= tp
->prev_pc
)
5740 fprintf_unfiltered (gdb_stdlog
,
5741 "infrun: expected thread advanced also\n");
5743 /* Clear the info of the previous step-over, as it's no
5744 longer valid. It's what keep_going would do too, if
5745 we called it. Must do this before trying to insert
5746 the sss breakpoint, otherwise if we were previously
5747 trying to step over this exact address in another
5748 thread, the breakpoint ends up not installed. */
5749 clear_step_over_info ();
5751 insert_single_step_breakpoint (get_frame_arch (frame
),
5752 get_frame_address_space (frame
),
5754 ecs
->event_thread
->control
.trap_expected
= 1;
5756 resume (0, GDB_SIGNAL_0
);
5757 prepare_to_wait (ecs
);
5762 fprintf_unfiltered (gdb_stdlog
,
5763 "infrun: expected thread still "
5764 "hasn't advanced\n");
5774 /* Is thread TP in the middle of single-stepping? */
5777 currently_stepping (struct thread_info
*tp
)
5779 return ((tp
->control
.step_range_end
5780 && tp
->control
.step_resume_breakpoint
== NULL
)
5781 || tp
->control
.trap_expected
5782 || tp
->stepped_breakpoint
5783 || bpstat_should_step ());
5786 /* Inferior has stepped into a subroutine call with source code that
5787 we should not step over. Do step to the first line of code in
5791 handle_step_into_function (struct gdbarch
*gdbarch
,
5792 struct execution_control_state
*ecs
)
5794 struct compunit_symtab
*cust
;
5795 struct symtab_and_line stop_func_sal
, sr_sal
;
5797 fill_in_stop_func (gdbarch
, ecs
);
5799 cust
= find_pc_compunit_symtab (stop_pc
);
5800 if (cust
!= NULL
&& compunit_language (cust
) != language_asm
)
5801 ecs
->stop_func_start
= gdbarch_skip_prologue (gdbarch
,
5802 ecs
->stop_func_start
);
5804 stop_func_sal
= find_pc_line (ecs
->stop_func_start
, 0);
5805 /* Use the step_resume_break to step until the end of the prologue,
5806 even if that involves jumps (as it seems to on the vax under
5808 /* If the prologue ends in the middle of a source line, continue to
5809 the end of that source line (if it is still within the function).
5810 Otherwise, just go to end of prologue. */
5811 if (stop_func_sal
.end
5812 && stop_func_sal
.pc
!= ecs
->stop_func_start
5813 && stop_func_sal
.end
< ecs
->stop_func_end
)
5814 ecs
->stop_func_start
= stop_func_sal
.end
;
5816 /* Architectures which require breakpoint adjustment might not be able
5817 to place a breakpoint at the computed address. If so, the test
5818 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
5819 ecs->stop_func_start to an address at which a breakpoint may be
5820 legitimately placed.
5822 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
5823 made, GDB will enter an infinite loop when stepping through
5824 optimized code consisting of VLIW instructions which contain
5825 subinstructions corresponding to different source lines. On
5826 FR-V, it's not permitted to place a breakpoint on any but the
5827 first subinstruction of a VLIW instruction. When a breakpoint is
5828 set, GDB will adjust the breakpoint address to the beginning of
5829 the VLIW instruction. Thus, we need to make the corresponding
5830 adjustment here when computing the stop address. */
5832 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
5834 ecs
->stop_func_start
5835 = gdbarch_adjust_breakpoint_address (gdbarch
,
5836 ecs
->stop_func_start
);
5839 if (ecs
->stop_func_start
== stop_pc
)
5841 /* We are already there: stop now. */
5842 end_stepping_range (ecs
);
5847 /* Put the step-breakpoint there and go until there. */
5848 init_sal (&sr_sal
); /* initialize to zeroes */
5849 sr_sal
.pc
= ecs
->stop_func_start
;
5850 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
5851 sr_sal
.pspace
= get_frame_program_space (get_current_frame ());
5853 /* Do not specify what the fp should be when we stop since on
5854 some machines the prologue is where the new fp value is
5856 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
, null_frame_id
);
5858 /* And make sure stepping stops right away then. */
5859 ecs
->event_thread
->control
.step_range_end
5860 = ecs
->event_thread
->control
.step_range_start
;
5865 /* Inferior has stepped backward into a subroutine call with source
5866 code that we should not step over. Do step to the beginning of the
5867 last line of code in it. */
5870 handle_step_into_function_backward (struct gdbarch
*gdbarch
,
5871 struct execution_control_state
*ecs
)
5873 struct compunit_symtab
*cust
;
5874 struct symtab_and_line stop_func_sal
;
5876 fill_in_stop_func (gdbarch
, ecs
);
5878 cust
= find_pc_compunit_symtab (stop_pc
);
5879 if (cust
!= NULL
&& compunit_language (cust
) != language_asm
)
5880 ecs
->stop_func_start
= gdbarch_skip_prologue (gdbarch
,
5881 ecs
->stop_func_start
);
5883 stop_func_sal
= find_pc_line (stop_pc
, 0);
5885 /* OK, we're just going to keep stepping here. */
5886 if (stop_func_sal
.pc
== stop_pc
)
5888 /* We're there already. Just stop stepping now. */
5889 end_stepping_range (ecs
);
5893 /* Else just reset the step range and keep going.
5894 No step-resume breakpoint, they don't work for
5895 epilogues, which can have multiple entry paths. */
5896 ecs
->event_thread
->control
.step_range_start
= stop_func_sal
.pc
;
5897 ecs
->event_thread
->control
.step_range_end
= stop_func_sal
.end
;
5903 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
5904 This is used to both functions and to skip over code. */
5907 insert_step_resume_breakpoint_at_sal_1 (struct gdbarch
*gdbarch
,
5908 struct symtab_and_line sr_sal
,
5909 struct frame_id sr_id
,
5910 enum bptype sr_type
)
5912 /* There should never be more than one step-resume or longjmp-resume
5913 breakpoint per thread, so we should never be setting a new
5914 step_resume_breakpoint when one is already active. */
5915 gdb_assert (inferior_thread ()->control
.step_resume_breakpoint
== NULL
);
5916 gdb_assert (sr_type
== bp_step_resume
|| sr_type
== bp_hp_step_resume
);
5919 fprintf_unfiltered (gdb_stdlog
,
5920 "infrun: inserting step-resume breakpoint at %s\n",
5921 paddress (gdbarch
, sr_sal
.pc
));
5923 inferior_thread ()->control
.step_resume_breakpoint
5924 = set_momentary_breakpoint (gdbarch
, sr_sal
, sr_id
, sr_type
);
5928 insert_step_resume_breakpoint_at_sal (struct gdbarch
*gdbarch
,
5929 struct symtab_and_line sr_sal
,
5930 struct frame_id sr_id
)
5932 insert_step_resume_breakpoint_at_sal_1 (gdbarch
,
5937 /* Insert a "high-priority step-resume breakpoint" at RETURN_FRAME.pc.
5938 This is used to skip a potential signal handler.
5940 This is called with the interrupted function's frame. The signal
5941 handler, when it returns, will resume the interrupted function at
5945 insert_hp_step_resume_breakpoint_at_frame (struct frame_info
*return_frame
)
5947 struct symtab_and_line sr_sal
;
5948 struct gdbarch
*gdbarch
;
5950 gdb_assert (return_frame
!= NULL
);
5951 init_sal (&sr_sal
); /* initialize to zeros */
5953 gdbarch
= get_frame_arch (return_frame
);
5954 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
, get_frame_pc (return_frame
));
5955 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
5956 sr_sal
.pspace
= get_frame_program_space (return_frame
);
5958 insert_step_resume_breakpoint_at_sal_1 (gdbarch
, sr_sal
,
5959 get_stack_frame_id (return_frame
),
5963 /* Insert a "step-resume breakpoint" at the previous frame's PC. This
5964 is used to skip a function after stepping into it (for "next" or if
5965 the called function has no debugging information).
5967 The current function has almost always been reached by single
5968 stepping a call or return instruction. NEXT_FRAME belongs to the
5969 current function, and the breakpoint will be set at the caller's
5972 This is a separate function rather than reusing
5973 insert_hp_step_resume_breakpoint_at_frame in order to avoid
5974 get_prev_frame, which may stop prematurely (see the implementation
5975 of frame_unwind_caller_id for an example). */
5978 insert_step_resume_breakpoint_at_caller (struct frame_info
*next_frame
)
5980 struct symtab_and_line sr_sal
;
5981 struct gdbarch
*gdbarch
;
5983 /* We shouldn't have gotten here if we don't know where the call site
5985 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame
)));
5987 init_sal (&sr_sal
); /* initialize to zeros */
5989 gdbarch
= frame_unwind_caller_arch (next_frame
);
5990 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
,
5991 frame_unwind_caller_pc (next_frame
));
5992 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
5993 sr_sal
.pspace
= frame_unwind_program_space (next_frame
);
5995 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
,
5996 frame_unwind_caller_id (next_frame
));
5999 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
6000 new breakpoint at the target of a jmp_buf. The handling of
6001 longjmp-resume uses the same mechanisms used for handling
6002 "step-resume" breakpoints. */
6005 insert_longjmp_resume_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
6007 /* There should never be more than one longjmp-resume breakpoint per
6008 thread, so we should never be setting a new
6009 longjmp_resume_breakpoint when one is already active. */
6010 gdb_assert (inferior_thread ()->control
.exception_resume_breakpoint
== NULL
);
6013 fprintf_unfiltered (gdb_stdlog
,
6014 "infrun: inserting longjmp-resume breakpoint at %s\n",
6015 paddress (gdbarch
, pc
));
6017 inferior_thread ()->control
.exception_resume_breakpoint
=
6018 set_momentary_breakpoint_at_pc (gdbarch
, pc
, bp_longjmp_resume
);
6021 /* Insert an exception resume breakpoint. TP is the thread throwing
6022 the exception. The block B is the block of the unwinder debug hook
6023 function. FRAME is the frame corresponding to the call to this
6024 function. SYM is the symbol of the function argument holding the
6025 target PC of the exception. */
6028 insert_exception_resume_breakpoint (struct thread_info
*tp
,
6029 const struct block
*b
,
6030 struct frame_info
*frame
,
6035 struct symbol
*vsym
;
6036 struct value
*value
;
6038 struct breakpoint
*bp
;
6040 vsym
= lookup_symbol (SYMBOL_LINKAGE_NAME (sym
), b
, VAR_DOMAIN
, NULL
);
6041 value
= read_var_value (vsym
, frame
);
6042 /* If the value was optimized out, revert to the old behavior. */
6043 if (! value_optimized_out (value
))
6045 handler
= value_as_address (value
);
6048 fprintf_unfiltered (gdb_stdlog
,
6049 "infrun: exception resume at %lx\n",
6050 (unsigned long) handler
);
6052 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
6053 handler
, bp_exception_resume
);
6055 /* set_momentary_breakpoint_at_pc invalidates FRAME. */
6058 bp
->thread
= tp
->num
;
6059 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
6062 CATCH (e
, RETURN_MASK_ERROR
)
6064 /* We want to ignore errors here. */
6069 /* A helper for check_exception_resume that sets an
6070 exception-breakpoint based on a SystemTap probe. */
6073 insert_exception_resume_from_probe (struct thread_info
*tp
,
6074 const struct bound_probe
*probe
,
6075 struct frame_info
*frame
)
6077 struct value
*arg_value
;
6079 struct breakpoint
*bp
;
6081 arg_value
= probe_safe_evaluate_at_pc (frame
, 1);
6085 handler
= value_as_address (arg_value
);
6088 fprintf_unfiltered (gdb_stdlog
,
6089 "infrun: exception resume at %s\n",
6090 paddress (get_objfile_arch (probe
->objfile
),
6093 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
6094 handler
, bp_exception_resume
);
6095 bp
->thread
= tp
->num
;
6096 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
6099 /* This is called when an exception has been intercepted. Check to
6100 see whether the exception's destination is of interest, and if so,
6101 set an exception resume breakpoint there. */
6104 check_exception_resume (struct execution_control_state
*ecs
,
6105 struct frame_info
*frame
)
6107 struct bound_probe probe
;
6108 struct symbol
*func
;
6110 /* First see if this exception unwinding breakpoint was set via a
6111 SystemTap probe point. If so, the probe has two arguments: the
6112 CFA and the HANDLER. We ignore the CFA, extract the handler, and
6113 set a breakpoint there. */
6114 probe
= find_probe_by_pc (get_frame_pc (frame
));
6117 insert_exception_resume_from_probe (ecs
->event_thread
, &probe
, frame
);
6121 func
= get_frame_function (frame
);
6127 const struct block
*b
;
6128 struct block_iterator iter
;
6132 /* The exception breakpoint is a thread-specific breakpoint on
6133 the unwinder's debug hook, declared as:
6135 void _Unwind_DebugHook (void *cfa, void *handler);
6137 The CFA argument indicates the frame to which control is
6138 about to be transferred. HANDLER is the destination PC.
6140 We ignore the CFA and set a temporary breakpoint at HANDLER.
6141 This is not extremely efficient but it avoids issues in gdb
6142 with computing the DWARF CFA, and it also works even in weird
6143 cases such as throwing an exception from inside a signal
6146 b
= SYMBOL_BLOCK_VALUE (func
);
6147 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
6149 if (!SYMBOL_IS_ARGUMENT (sym
))
6156 insert_exception_resume_breakpoint (ecs
->event_thread
,
6162 CATCH (e
, RETURN_MASK_ERROR
)
6169 stop_waiting (struct execution_control_state
*ecs
)
6172 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_waiting\n");
6174 clear_step_over_info ();
6176 /* Let callers know we don't want to wait for the inferior anymore. */
6177 ecs
->wait_some_more
= 0;
6180 /* Called when we should continue running the inferior, because the
6181 current event doesn't cause a user visible stop. This does the
6182 resuming part; waiting for the next event is done elsewhere. */
6185 keep_going (struct execution_control_state
*ecs
)
6187 /* Make sure normal_stop is called if we get a QUIT handled before
6189 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
6191 /* Save the pc before execution, to compare with pc after stop. */
6192 ecs
->event_thread
->prev_pc
6193 = regcache_read_pc (get_thread_regcache (ecs
->ptid
));
6195 if (ecs
->event_thread
->control
.trap_expected
6196 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_TRAP
)
6198 /* We haven't yet gotten our trap, and either: intercepted a
6199 non-signal event (e.g., a fork); or took a signal which we
6200 are supposed to pass through to the inferior. Simply
6202 discard_cleanups (old_cleanups
);
6203 resume (currently_stepping (ecs
->event_thread
),
6204 ecs
->event_thread
->suspend
.stop_signal
);
6208 struct regcache
*regcache
= get_current_regcache ();
6212 /* Either the trap was not expected, but we are continuing
6213 anyway (if we got a signal, the user asked it be passed to
6216 We got our expected trap, but decided we should resume from
6219 We're going to run this baby now!
6221 Note that insert_breakpoints won't try to re-insert
6222 already inserted breakpoints. Therefore, we don't
6223 care if breakpoints were already inserted, or not. */
6225 /* If we need to step over a breakpoint, and we're not using
6226 displaced stepping to do so, insert all breakpoints
6227 (watchpoints, etc.) but the one we're stepping over, step one
6228 instruction, and then re-insert the breakpoint when that step
6231 remove_bp
= (ecs
->hit_singlestep_breakpoint
6232 || thread_still_needs_step_over (ecs
->event_thread
));
6233 remove_wps
= (ecs
->event_thread
->stepping_over_watchpoint
6234 && !target_have_steppable_watchpoint
);
6236 if (remove_bp
&& !use_displaced_stepping (get_regcache_arch (regcache
)))
6238 set_step_over_info (get_regcache_aspace (regcache
),
6239 regcache_read_pc (regcache
), remove_wps
);
6241 else if (remove_wps
)
6242 set_step_over_info (NULL
, 0, remove_wps
);
6244 clear_step_over_info ();
6246 /* Stop stepping if inserting breakpoints fails. */
6249 insert_breakpoints ();
6251 CATCH (e
, RETURN_MASK_ERROR
)
6253 exception_print (gdb_stderr
, e
);
6259 ecs
->event_thread
->control
.trap_expected
= (remove_bp
|| remove_wps
);
6261 /* Do not deliver GDB_SIGNAL_TRAP (except when the user
6262 explicitly specifies that such a signal should be delivered
6263 to the target program). Typically, that would occur when a
6264 user is debugging a target monitor on a simulator: the target
6265 monitor sets a breakpoint; the simulator encounters this
6266 breakpoint and halts the simulation handing control to GDB;
6267 GDB, noting that the stop address doesn't map to any known
6268 breakpoint, returns control back to the simulator; the
6269 simulator then delivers the hardware equivalent of a
6270 GDB_SIGNAL_TRAP to the program being debugged. */
6271 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
6272 && !signal_program
[ecs
->event_thread
->suspend
.stop_signal
])
6273 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
6275 discard_cleanups (old_cleanups
);
6276 resume (currently_stepping (ecs
->event_thread
),
6277 ecs
->event_thread
->suspend
.stop_signal
);
6280 prepare_to_wait (ecs
);
6283 /* This function normally comes after a resume, before
6284 handle_inferior_event exits. It takes care of any last bits of
6285 housekeeping, and sets the all-important wait_some_more flag. */
6288 prepare_to_wait (struct execution_control_state
*ecs
)
6291 fprintf_unfiltered (gdb_stdlog
, "infrun: prepare_to_wait\n");
6293 /* This is the old end of the while loop. Let everybody know we
6294 want to wait for the inferior some more and get called again
6296 ecs
->wait_some_more
= 1;
6299 /* We are done with the step range of a step/next/si/ni command.
6300 Called once for each n of a "step n" operation. */
6303 end_stepping_range (struct execution_control_state
*ecs
)
6305 ecs
->event_thread
->control
.stop_step
= 1;
6309 /* Several print_*_reason functions to print why the inferior has stopped.
6310 We always print something when the inferior exits, or receives a signal.
6311 The rest of the cases are dealt with later on in normal_stop and
6312 print_it_typical. Ideally there should be a call to one of these
6313 print_*_reason functions functions from handle_inferior_event each time
6314 stop_waiting is called.
6316 Note that we don't call these directly, instead we delegate that to
6317 the interpreters, through observers. Interpreters then call these
6318 with whatever uiout is right. */
6321 print_end_stepping_range_reason (struct ui_out
*uiout
)
6323 /* For CLI-like interpreters, print nothing. */
6325 if (ui_out_is_mi_like_p (uiout
))
6327 ui_out_field_string (uiout
, "reason",
6328 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE
));
6333 print_signal_exited_reason (struct ui_out
*uiout
, enum gdb_signal siggnal
)
6335 annotate_signalled ();
6336 if (ui_out_is_mi_like_p (uiout
))
6338 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED
));
6339 ui_out_text (uiout
, "\nProgram terminated with signal ");
6340 annotate_signal_name ();
6341 ui_out_field_string (uiout
, "signal-name",
6342 gdb_signal_to_name (siggnal
));
6343 annotate_signal_name_end ();
6344 ui_out_text (uiout
, ", ");
6345 annotate_signal_string ();
6346 ui_out_field_string (uiout
, "signal-meaning",
6347 gdb_signal_to_string (siggnal
));
6348 annotate_signal_string_end ();
6349 ui_out_text (uiout
, ".\n");
6350 ui_out_text (uiout
, "The program no longer exists.\n");
6354 print_exited_reason (struct ui_out
*uiout
, int exitstatus
)
6356 struct inferior
*inf
= current_inferior ();
6357 const char *pidstr
= target_pid_to_str (pid_to_ptid (inf
->pid
));
6359 annotate_exited (exitstatus
);
6362 if (ui_out_is_mi_like_p (uiout
))
6363 ui_out_field_string (uiout
, "reason",
6364 async_reason_lookup (EXEC_ASYNC_EXITED
));
6365 ui_out_text (uiout
, "[Inferior ");
6366 ui_out_text (uiout
, plongest (inf
->num
));
6367 ui_out_text (uiout
, " (");
6368 ui_out_text (uiout
, pidstr
);
6369 ui_out_text (uiout
, ") exited with code ");
6370 ui_out_field_fmt (uiout
, "exit-code", "0%o", (unsigned int) exitstatus
);
6371 ui_out_text (uiout
, "]\n");
6375 if (ui_out_is_mi_like_p (uiout
))
6377 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY
));
6378 ui_out_text (uiout
, "[Inferior ");
6379 ui_out_text (uiout
, plongest (inf
->num
));
6380 ui_out_text (uiout
, " (");
6381 ui_out_text (uiout
, pidstr
);
6382 ui_out_text (uiout
, ") exited normally]\n");
6387 print_signal_received_reason (struct ui_out
*uiout
, enum gdb_signal siggnal
)
6391 if (siggnal
== GDB_SIGNAL_0
&& !ui_out_is_mi_like_p (uiout
))
6393 struct thread_info
*t
= inferior_thread ();
6395 ui_out_text (uiout
, "\n[");
6396 ui_out_field_string (uiout
, "thread-name",
6397 target_pid_to_str (t
->ptid
));
6398 ui_out_field_fmt (uiout
, "thread-id", "] #%d", t
->num
);
6399 ui_out_text (uiout
, " stopped");
6403 ui_out_text (uiout
, "\nProgram received signal ");
6404 annotate_signal_name ();
6405 if (ui_out_is_mi_like_p (uiout
))
6407 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED
));
6408 ui_out_field_string (uiout
, "signal-name",
6409 gdb_signal_to_name (siggnal
));
6410 annotate_signal_name_end ();
6411 ui_out_text (uiout
, ", ");
6412 annotate_signal_string ();
6413 ui_out_field_string (uiout
, "signal-meaning",
6414 gdb_signal_to_string (siggnal
));
6415 annotate_signal_string_end ();
6417 ui_out_text (uiout
, ".\n");
6421 print_no_history_reason (struct ui_out
*uiout
)
6423 ui_out_text (uiout
, "\nNo more reverse-execution history.\n");
6426 /* Print current location without a level number, if we have changed
6427 functions or hit a breakpoint. Print source line if we have one.
6428 bpstat_print contains the logic deciding in detail what to print,
6429 based on the event(s) that just occurred. */
6432 print_stop_event (struct target_waitstatus
*ws
)
6436 int do_frame_printing
= 1;
6437 struct thread_info
*tp
= inferior_thread ();
6439 bpstat_ret
= bpstat_print (tp
->control
.stop_bpstat
, ws
->kind
);
6443 /* FIXME: cagney/2002-12-01: Given that a frame ID does (or
6444 should) carry around the function and does (or should) use
6445 that when doing a frame comparison. */
6446 if (tp
->control
.stop_step
6447 && frame_id_eq (tp
->control
.step_frame_id
,
6448 get_frame_id (get_current_frame ()))
6449 && step_start_function
== find_pc_function (stop_pc
))
6451 /* Finished step, just print source line. */
6452 source_flag
= SRC_LINE
;
6456 /* Print location and source line. */
6457 source_flag
= SRC_AND_LOC
;
6460 case PRINT_SRC_AND_LOC
:
6461 /* Print location and source line. */
6462 source_flag
= SRC_AND_LOC
;
6464 case PRINT_SRC_ONLY
:
6465 source_flag
= SRC_LINE
;
6468 /* Something bogus. */
6469 source_flag
= SRC_LINE
;
6470 do_frame_printing
= 0;
6473 internal_error (__FILE__
, __LINE__
, _("Unknown value."));
6476 /* The behavior of this routine with respect to the source
6478 SRC_LINE: Print only source line
6479 LOCATION: Print only location
6480 SRC_AND_LOC: Print location and source line. */
6481 if (do_frame_printing
)
6482 print_stack_frame (get_selected_frame (NULL
), 0, source_flag
, 1);
6484 /* Display the auto-display expressions. */
6488 /* Here to return control to GDB when the inferior stops for real.
6489 Print appropriate messages, remove breakpoints, give terminal our modes.
6491 STOP_PRINT_FRAME nonzero means print the executing frame
6492 (pc, function, args, file, line number and line text).
6493 BREAKPOINTS_FAILED nonzero means stop was due to error
6494 attempting to insert breakpoints. */
6499 struct target_waitstatus last
;
6501 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
6503 get_last_target_status (&last_ptid
, &last
);
6505 /* If an exception is thrown from this point on, make sure to
6506 propagate GDB's knowledge of the executing state to the
6507 frontend/user running state. A QUIT is an easy exception to see
6508 here, so do this before any filtered output. */
6510 make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
6511 else if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
6512 && last
.kind
!= TARGET_WAITKIND_EXITED
6513 && last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
6514 make_cleanup (finish_thread_state_cleanup
, &inferior_ptid
);
6516 /* As we're presenting a stop, and potentially removing breakpoints,
6517 update the thread list so we can tell whether there are threads
6518 running on the target. With target remote, for example, we can
6519 only learn about new threads when we explicitly update the thread
6520 list. Do this before notifying the interpreters about signal
6521 stops, end of stepping ranges, etc., so that the "new thread"
6522 output is emitted before e.g., "Program received signal FOO",
6523 instead of after. */
6524 update_thread_list ();
6526 if (last
.kind
== TARGET_WAITKIND_STOPPED
&& stopped_by_random_signal
)
6527 observer_notify_signal_received (inferior_thread ()->suspend
.stop_signal
);
6529 /* As with the notification of thread events, we want to delay
6530 notifying the user that we've switched thread context until
6531 the inferior actually stops.
6533 There's no point in saying anything if the inferior has exited.
6534 Note that SIGNALLED here means "exited with a signal", not
6535 "received a signal".
6537 Also skip saying anything in non-stop mode. In that mode, as we
6538 don't want GDB to switch threads behind the user's back, to avoid
6539 races where the user is typing a command to apply to thread x,
6540 but GDB switches to thread y before the user finishes entering
6541 the command, fetch_inferior_event installs a cleanup to restore
6542 the current thread back to the thread the user had selected right
6543 after this event is handled, so we're not really switching, only
6544 informing of a stop. */
6546 && !ptid_equal (previous_inferior_ptid
, inferior_ptid
)
6547 && target_has_execution
6548 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
6549 && last
.kind
!= TARGET_WAITKIND_EXITED
6550 && last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
6552 target_terminal_ours_for_output ();
6553 printf_filtered (_("[Switching to %s]\n"),
6554 target_pid_to_str (inferior_ptid
));
6555 annotate_thread_changed ();
6556 previous_inferior_ptid
= inferior_ptid
;
6559 if (last
.kind
== TARGET_WAITKIND_NO_RESUMED
)
6561 gdb_assert (sync_execution
|| !target_can_async_p ());
6563 target_terminal_ours_for_output ();
6564 printf_filtered (_("No unwaited-for children left.\n"));
6567 /* Note: this depends on the update_thread_list call above. */
6568 if (!breakpoints_should_be_inserted_now () && target_has_execution
)
6570 if (remove_breakpoints ())
6572 target_terminal_ours_for_output ();
6573 printf_filtered (_("Cannot remove breakpoints because "
6574 "program is no longer writable.\nFurther "
6575 "execution is probably impossible.\n"));
6579 /* If an auto-display called a function and that got a signal,
6580 delete that auto-display to avoid an infinite recursion. */
6582 if (stopped_by_random_signal
)
6583 disable_current_display ();
6585 /* Notify observers if we finished a "step"-like command, etc. */
6586 if (target_has_execution
6587 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
6588 && last
.kind
!= TARGET_WAITKIND_EXITED
6589 && inferior_thread ()->control
.stop_step
)
6591 /* But not if in the middle of doing a "step n" operation for
6593 if (inferior_thread ()->step_multi
)
6596 observer_notify_end_stepping_range ();
6599 target_terminal_ours ();
6600 async_enable_stdin ();
6602 /* Set the current source location. This will also happen if we
6603 display the frame below, but the current SAL will be incorrect
6604 during a user hook-stop function. */
6605 if (has_stack_frames () && !stop_stack_dummy
)
6606 set_current_sal_from_frame (get_current_frame ());
6608 /* Let the user/frontend see the threads as stopped, but do nothing
6609 if the thread was running an infcall. We may be e.g., evaluating
6610 a breakpoint condition. In that case, the thread had state
6611 THREAD_RUNNING before the infcall, and shall remain set to
6612 running, all without informing the user/frontend about state
6613 transition changes. If this is actually a call command, then the
6614 thread was originally already stopped, so there's no state to
6616 if (target_has_execution
&& inferior_thread ()->control
.in_infcall
)
6617 discard_cleanups (old_chain
);
6619 do_cleanups (old_chain
);
6621 /* Look up the hook_stop and run it (CLI internally handles problem
6622 of stop_command's pre-hook not existing). */
6624 catch_errors (hook_stop_stub
, stop_command
,
6625 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
6627 if (!has_stack_frames ())
6630 if (last
.kind
== TARGET_WAITKIND_SIGNALLED
6631 || last
.kind
== TARGET_WAITKIND_EXITED
)
6634 /* Select innermost stack frame - i.e., current frame is frame 0,
6635 and current location is based on that.
6636 Don't do this on return from a stack dummy routine,
6637 or if the program has exited. */
6639 if (!stop_stack_dummy
)
6641 select_frame (get_current_frame ());
6643 /* If --batch-silent is enabled then there's no need to print the current
6644 source location, and to try risks causing an error message about
6645 missing source files. */
6646 if (stop_print_frame
&& !batch_silent
)
6647 print_stop_event (&last
);
6650 /* Save the function value return registers, if we care.
6651 We might be about to restore their previous contents. */
6652 if (inferior_thread ()->control
.proceed_to_finish
6653 && execution_direction
!= EXEC_REVERSE
)
6655 /* This should not be necessary. */
6657 regcache_xfree (stop_registers
);
6659 /* NB: The copy goes through to the target picking up the value of
6660 all the registers. */
6661 stop_registers
= regcache_dup (get_current_regcache ());
6664 if (stop_stack_dummy
== STOP_STACK_DUMMY
)
6666 /* Pop the empty frame that contains the stack dummy.
6667 This also restores inferior state prior to the call
6668 (struct infcall_suspend_state). */
6669 struct frame_info
*frame
= get_current_frame ();
6671 gdb_assert (get_frame_type (frame
) == DUMMY_FRAME
);
6673 /* frame_pop() calls reinit_frame_cache as the last thing it
6674 does which means there's currently no selected frame. We
6675 don't need to re-establish a selected frame if the dummy call
6676 returns normally, that will be done by
6677 restore_infcall_control_state. However, we do have to handle
6678 the case where the dummy call is returning after being
6679 stopped (e.g. the dummy call previously hit a breakpoint).
6680 We can't know which case we have so just always re-establish
6681 a selected frame here. */
6682 select_frame (get_current_frame ());
6686 annotate_stopped ();
6688 /* Suppress the stop observer if we're in the middle of:
6690 - a step n (n > 1), as there still more steps to be done.
6692 - a "finish" command, as the observer will be called in
6693 finish_command_continuation, so it can include the inferior
6694 function's return value.
6696 - calling an inferior function, as we pretend we inferior didn't
6697 run at all. The return value of the call is handled by the
6698 expression evaluator, through call_function_by_hand. */
6700 if (!target_has_execution
6701 || last
.kind
== TARGET_WAITKIND_SIGNALLED
6702 || last
.kind
== TARGET_WAITKIND_EXITED
6703 || last
.kind
== TARGET_WAITKIND_NO_RESUMED
6704 || (!(inferior_thread ()->step_multi
6705 && inferior_thread ()->control
.stop_step
)
6706 && !(inferior_thread ()->control
.stop_bpstat
6707 && inferior_thread ()->control
.proceed_to_finish
)
6708 && !inferior_thread ()->control
.in_infcall
))
6710 if (!ptid_equal (inferior_ptid
, null_ptid
))
6711 observer_notify_normal_stop (inferior_thread ()->control
.stop_bpstat
,
6714 observer_notify_normal_stop (NULL
, stop_print_frame
);
6717 if (target_has_execution
)
6719 if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
6720 && last
.kind
!= TARGET_WAITKIND_EXITED
)
6721 /* Delete the breakpoint we stopped at, if it wants to be deleted.
6722 Delete any breakpoint that is to be deleted at the next stop. */
6723 breakpoint_auto_delete (inferior_thread ()->control
.stop_bpstat
);
6726 /* Try to get rid of automatically added inferiors that are no
6727 longer needed. Keeping those around slows down things linearly.
6728 Note that this never removes the current inferior. */
6733 hook_stop_stub (void *cmd
)
6735 execute_cmd_pre_hook ((struct cmd_list_element
*) cmd
);
6740 signal_stop_state (int signo
)
6742 return signal_stop
[signo
];
6746 signal_print_state (int signo
)
6748 return signal_print
[signo
];
6752 signal_pass_state (int signo
)
6754 return signal_program
[signo
];
6758 signal_cache_update (int signo
)
6762 for (signo
= 0; signo
< (int) GDB_SIGNAL_LAST
; signo
++)
6763 signal_cache_update (signo
);
6768 signal_pass
[signo
] = (signal_stop
[signo
] == 0
6769 && signal_print
[signo
] == 0
6770 && signal_program
[signo
] == 1
6771 && signal_catch
[signo
] == 0);
6775 signal_stop_update (int signo
, int state
)
6777 int ret
= signal_stop
[signo
];
6779 signal_stop
[signo
] = state
;
6780 signal_cache_update (signo
);
6785 signal_print_update (int signo
, int state
)
6787 int ret
= signal_print
[signo
];
6789 signal_print
[signo
] = state
;
6790 signal_cache_update (signo
);
6795 signal_pass_update (int signo
, int state
)
6797 int ret
= signal_program
[signo
];
6799 signal_program
[signo
] = state
;
6800 signal_cache_update (signo
);
6804 /* Update the global 'signal_catch' from INFO and notify the
6808 signal_catch_update (const unsigned int *info
)
6812 for (i
= 0; i
< GDB_SIGNAL_LAST
; ++i
)
6813 signal_catch
[i
] = info
[i
] > 0;
6814 signal_cache_update (-1);
6815 target_pass_signals ((int) GDB_SIGNAL_LAST
, signal_pass
);
6819 sig_print_header (void)
6821 printf_filtered (_("Signal Stop\tPrint\tPass "
6822 "to program\tDescription\n"));
6826 sig_print_info (enum gdb_signal oursig
)
6828 const char *name
= gdb_signal_to_name (oursig
);
6829 int name_padding
= 13 - strlen (name
);
6831 if (name_padding
<= 0)
6834 printf_filtered ("%s", name
);
6835 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
6836 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
6837 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
6838 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
6839 printf_filtered ("%s\n", gdb_signal_to_string (oursig
));
6842 /* Specify how various signals in the inferior should be handled. */
6845 handle_command (char *args
, int from_tty
)
6848 int digits
, wordlen
;
6849 int sigfirst
, signum
, siglast
;
6850 enum gdb_signal oursig
;
6853 unsigned char *sigs
;
6854 struct cleanup
*old_chain
;
6858 error_no_arg (_("signal to handle"));
6861 /* Allocate and zero an array of flags for which signals to handle. */
6863 nsigs
= (int) GDB_SIGNAL_LAST
;
6864 sigs
= (unsigned char *) alloca (nsigs
);
6865 memset (sigs
, 0, nsigs
);
6867 /* Break the command line up into args. */
6869 argv
= gdb_buildargv (args
);
6870 old_chain
= make_cleanup_freeargv (argv
);
6872 /* Walk through the args, looking for signal oursigs, signal names, and
6873 actions. Signal numbers and signal names may be interspersed with
6874 actions, with the actions being performed for all signals cumulatively
6875 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
6877 while (*argv
!= NULL
)
6879 wordlen
= strlen (*argv
);
6880 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
6884 sigfirst
= siglast
= -1;
6886 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
6888 /* Apply action to all signals except those used by the
6889 debugger. Silently skip those. */
6892 siglast
= nsigs
- 1;
6894 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
6896 SET_SIGS (nsigs
, sigs
, signal_stop
);
6897 SET_SIGS (nsigs
, sigs
, signal_print
);
6899 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
6901 UNSET_SIGS (nsigs
, sigs
, signal_program
);
6903 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
6905 SET_SIGS (nsigs
, sigs
, signal_print
);
6907 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
6909 SET_SIGS (nsigs
, sigs
, signal_program
);
6911 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
6913 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
6915 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
6917 SET_SIGS (nsigs
, sigs
, signal_program
);
6919 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
6921 UNSET_SIGS (nsigs
, sigs
, signal_print
);
6922 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
6924 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
6926 UNSET_SIGS (nsigs
, sigs
, signal_program
);
6928 else if (digits
> 0)
6930 /* It is numeric. The numeric signal refers to our own
6931 internal signal numbering from target.h, not to host/target
6932 signal number. This is a feature; users really should be
6933 using symbolic names anyway, and the common ones like
6934 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
6936 sigfirst
= siglast
= (int)
6937 gdb_signal_from_command (atoi (*argv
));
6938 if ((*argv
)[digits
] == '-')
6941 gdb_signal_from_command (atoi ((*argv
) + digits
+ 1));
6943 if (sigfirst
> siglast
)
6945 /* Bet he didn't figure we'd think of this case... */
6953 oursig
= gdb_signal_from_name (*argv
);
6954 if (oursig
!= GDB_SIGNAL_UNKNOWN
)
6956 sigfirst
= siglast
= (int) oursig
;
6960 /* Not a number and not a recognized flag word => complain. */
6961 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv
);
6965 /* If any signal numbers or symbol names were found, set flags for
6966 which signals to apply actions to. */
6968 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
6970 switch ((enum gdb_signal
) signum
)
6972 case GDB_SIGNAL_TRAP
:
6973 case GDB_SIGNAL_INT
:
6974 if (!allsigs
&& !sigs
[signum
])
6976 if (query (_("%s is used by the debugger.\n\
6977 Are you sure you want to change it? "),
6978 gdb_signal_to_name ((enum gdb_signal
) signum
)))
6984 printf_unfiltered (_("Not confirmed, unchanged.\n"));
6985 gdb_flush (gdb_stdout
);
6990 case GDB_SIGNAL_DEFAULT
:
6991 case GDB_SIGNAL_UNKNOWN
:
6992 /* Make sure that "all" doesn't print these. */
7003 for (signum
= 0; signum
< nsigs
; signum
++)
7006 signal_cache_update (-1);
7007 target_pass_signals ((int) GDB_SIGNAL_LAST
, signal_pass
);
7008 target_program_signals ((int) GDB_SIGNAL_LAST
, signal_program
);
7012 /* Show the results. */
7013 sig_print_header ();
7014 for (; signum
< nsigs
; signum
++)
7016 sig_print_info (signum
);
7022 do_cleanups (old_chain
);
7025 /* Complete the "handle" command. */
7027 static VEC (char_ptr
) *
7028 handle_completer (struct cmd_list_element
*ignore
,
7029 const char *text
, const char *word
)
7031 VEC (char_ptr
) *vec_signals
, *vec_keywords
, *return_val
;
7032 static const char * const keywords
[] =
7046 vec_signals
= signal_completer (ignore
, text
, word
);
7047 vec_keywords
= complete_on_enum (keywords
, word
, word
);
7049 return_val
= VEC_merge (char_ptr
, vec_signals
, vec_keywords
);
7050 VEC_free (char_ptr
, vec_signals
);
7051 VEC_free (char_ptr
, vec_keywords
);
7056 xdb_handle_command (char *args
, int from_tty
)
7059 struct cleanup
*old_chain
;
7062 error_no_arg (_("xdb command"));
7064 /* Break the command line up into args. */
7066 argv
= gdb_buildargv (args
);
7067 old_chain
= make_cleanup_freeargv (argv
);
7068 if (argv
[1] != (char *) NULL
)
7073 bufLen
= strlen (argv
[0]) + 20;
7074 argBuf
= (char *) xmalloc (bufLen
);
7078 enum gdb_signal oursig
;
7080 oursig
= gdb_signal_from_name (argv
[0]);
7081 memset (argBuf
, 0, bufLen
);
7082 if (strcmp (argv
[1], "Q") == 0)
7083 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
7086 if (strcmp (argv
[1], "s") == 0)
7088 if (!signal_stop
[oursig
])
7089 sprintf (argBuf
, "%s %s", argv
[0], "stop");
7091 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
7093 else if (strcmp (argv
[1], "i") == 0)
7095 if (!signal_program
[oursig
])
7096 sprintf (argBuf
, "%s %s", argv
[0], "pass");
7098 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
7100 else if (strcmp (argv
[1], "r") == 0)
7102 if (!signal_print
[oursig
])
7103 sprintf (argBuf
, "%s %s", argv
[0], "print");
7105 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
7111 handle_command (argBuf
, from_tty
);
7113 printf_filtered (_("Invalid signal handling flag.\n"));
7118 do_cleanups (old_chain
);
7122 gdb_signal_from_command (int num
)
7124 if (num
>= 1 && num
<= 15)
7125 return (enum gdb_signal
) num
;
7126 error (_("Only signals 1-15 are valid as numeric signals.\n\
7127 Use \"info signals\" for a list of symbolic signals."));
7130 /* Print current contents of the tables set by the handle command.
7131 It is possible we should just be printing signals actually used
7132 by the current target (but for things to work right when switching
7133 targets, all signals should be in the signal tables). */
7136 signals_info (char *signum_exp
, int from_tty
)
7138 enum gdb_signal oursig
;
7140 sig_print_header ();
7144 /* First see if this is a symbol name. */
7145 oursig
= gdb_signal_from_name (signum_exp
);
7146 if (oursig
== GDB_SIGNAL_UNKNOWN
)
7148 /* No, try numeric. */
7150 gdb_signal_from_command (parse_and_eval_long (signum_exp
));
7152 sig_print_info (oursig
);
7156 printf_filtered ("\n");
7157 /* These ugly casts brought to you by the native VAX compiler. */
7158 for (oursig
= GDB_SIGNAL_FIRST
;
7159 (int) oursig
< (int) GDB_SIGNAL_LAST
;
7160 oursig
= (enum gdb_signal
) ((int) oursig
+ 1))
7164 if (oursig
!= GDB_SIGNAL_UNKNOWN
7165 && oursig
!= GDB_SIGNAL_DEFAULT
&& oursig
!= GDB_SIGNAL_0
)
7166 sig_print_info (oursig
);
7169 printf_filtered (_("\nUse the \"handle\" command "
7170 "to change these tables.\n"));
7173 /* Check if it makes sense to read $_siginfo from the current thread
7174 at this point. If not, throw an error. */
7177 validate_siginfo_access (void)
7179 /* No current inferior, no siginfo. */
7180 if (ptid_equal (inferior_ptid
, null_ptid
))
7181 error (_("No thread selected."));
7183 /* Don't try to read from a dead thread. */
7184 if (is_exited (inferior_ptid
))
7185 error (_("The current thread has terminated"));
7187 /* ... or from a spinning thread. */
7188 if (is_running (inferior_ptid
))
7189 error (_("Selected thread is running."));
7192 /* The $_siginfo convenience variable is a bit special. We don't know
7193 for sure the type of the value until we actually have a chance to
7194 fetch the data. The type can change depending on gdbarch, so it is
7195 also dependent on which thread you have selected.
7197 1. making $_siginfo be an internalvar that creates a new value on
7200 2. making the value of $_siginfo be an lval_computed value. */
7202 /* This function implements the lval_computed support for reading a
7206 siginfo_value_read (struct value
*v
)
7208 LONGEST transferred
;
7210 validate_siginfo_access ();
7213 target_read (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
,
7215 value_contents_all_raw (v
),
7217 TYPE_LENGTH (value_type (v
)));
7219 if (transferred
!= TYPE_LENGTH (value_type (v
)))
7220 error (_("Unable to read siginfo"));
7223 /* This function implements the lval_computed support for writing a
7227 siginfo_value_write (struct value
*v
, struct value
*fromval
)
7229 LONGEST transferred
;
7231 validate_siginfo_access ();
7233 transferred
= target_write (¤t_target
,
7234 TARGET_OBJECT_SIGNAL_INFO
,
7236 value_contents_all_raw (fromval
),
7238 TYPE_LENGTH (value_type (fromval
)));
7240 if (transferred
!= TYPE_LENGTH (value_type (fromval
)))
7241 error (_("Unable to write siginfo"));
7244 static const struct lval_funcs siginfo_value_funcs
=
7250 /* Return a new value with the correct type for the siginfo object of
7251 the current thread using architecture GDBARCH. Return a void value
7252 if there's no object available. */
7254 static struct value
*
7255 siginfo_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
,
7258 if (target_has_stack
7259 && !ptid_equal (inferior_ptid
, null_ptid
)
7260 && gdbarch_get_siginfo_type_p (gdbarch
))
7262 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
7264 return allocate_computed_value (type
, &siginfo_value_funcs
, NULL
);
7267 return allocate_value (builtin_type (gdbarch
)->builtin_void
);
7271 /* infcall_suspend_state contains state about the program itself like its
7272 registers and any signal it received when it last stopped.
7273 This state must be restored regardless of how the inferior function call
7274 ends (either successfully, or after it hits a breakpoint or signal)
7275 if the program is to properly continue where it left off. */
7277 struct infcall_suspend_state
7279 struct thread_suspend_state thread_suspend
;
7280 #if 0 /* Currently unused and empty structures are not valid C. */
7281 struct inferior_suspend_state inferior_suspend
;
7286 struct regcache
*registers
;
7288 /* Format of SIGINFO_DATA or NULL if it is not present. */
7289 struct gdbarch
*siginfo_gdbarch
;
7291 /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
7292 TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the
7293 content would be invalid. */
7294 gdb_byte
*siginfo_data
;
7297 struct infcall_suspend_state
*
7298 save_infcall_suspend_state (void)
7300 struct infcall_suspend_state
*inf_state
;
7301 struct thread_info
*tp
= inferior_thread ();
7303 struct inferior
*inf
= current_inferior ();
7305 struct regcache
*regcache
= get_current_regcache ();
7306 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
7307 gdb_byte
*siginfo_data
= NULL
;
7309 if (gdbarch_get_siginfo_type_p (gdbarch
))
7311 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
7312 size_t len
= TYPE_LENGTH (type
);
7313 struct cleanup
*back_to
;
7315 siginfo_data
= xmalloc (len
);
7316 back_to
= make_cleanup (xfree
, siginfo_data
);
7318 if (target_read (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
, NULL
,
7319 siginfo_data
, 0, len
) == len
)
7320 discard_cleanups (back_to
);
7323 /* Errors ignored. */
7324 do_cleanups (back_to
);
7325 siginfo_data
= NULL
;
7329 inf_state
= XCNEW (struct infcall_suspend_state
);
7333 inf_state
->siginfo_gdbarch
= gdbarch
;
7334 inf_state
->siginfo_data
= siginfo_data
;
7337 inf_state
->thread_suspend
= tp
->suspend
;
7338 #if 0 /* Currently unused and empty structures are not valid C. */
7339 inf_state
->inferior_suspend
= inf
->suspend
;
7342 /* run_inferior_call will not use the signal due to its `proceed' call with
7343 GDB_SIGNAL_0 anyway. */
7344 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
7346 inf_state
->stop_pc
= stop_pc
;
7348 inf_state
->registers
= regcache_dup (regcache
);
7353 /* Restore inferior session state to INF_STATE. */
7356 restore_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
7358 struct thread_info
*tp
= inferior_thread ();
7360 struct inferior
*inf
= current_inferior ();
7362 struct regcache
*regcache
= get_current_regcache ();
7363 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
7365 tp
->suspend
= inf_state
->thread_suspend
;
7366 #if 0 /* Currently unused and empty structures are not valid C. */
7367 inf
->suspend
= inf_state
->inferior_suspend
;
7370 stop_pc
= inf_state
->stop_pc
;
7372 if (inf_state
->siginfo_gdbarch
== gdbarch
)
7374 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
7376 /* Errors ignored. */
7377 target_write (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
, NULL
,
7378 inf_state
->siginfo_data
, 0, TYPE_LENGTH (type
));
7381 /* The inferior can be gone if the user types "print exit(0)"
7382 (and perhaps other times). */
7383 if (target_has_execution
)
7384 /* NB: The register write goes through to the target. */
7385 regcache_cpy (regcache
, inf_state
->registers
);
7387 discard_infcall_suspend_state (inf_state
);
7391 do_restore_infcall_suspend_state_cleanup (void *state
)
7393 restore_infcall_suspend_state (state
);
7397 make_cleanup_restore_infcall_suspend_state
7398 (struct infcall_suspend_state
*inf_state
)
7400 return make_cleanup (do_restore_infcall_suspend_state_cleanup
, inf_state
);
7404 discard_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
7406 regcache_xfree (inf_state
->registers
);
7407 xfree (inf_state
->siginfo_data
);
7412 get_infcall_suspend_state_regcache (struct infcall_suspend_state
*inf_state
)
7414 return inf_state
->registers
;
7417 /* infcall_control_state contains state regarding gdb's control of the
7418 inferior itself like stepping control. It also contains session state like
7419 the user's currently selected frame. */
7421 struct infcall_control_state
7423 struct thread_control_state thread_control
;
7424 struct inferior_control_state inferior_control
;
7427 enum stop_stack_kind stop_stack_dummy
;
7428 int stopped_by_random_signal
;
7429 int stop_after_trap
;
7431 /* ID if the selected frame when the inferior function call was made. */
7432 struct frame_id selected_frame_id
;
7435 /* Save all of the information associated with the inferior<==>gdb
7438 struct infcall_control_state
*
7439 save_infcall_control_state (void)
7441 struct infcall_control_state
*inf_status
= xmalloc (sizeof (*inf_status
));
7442 struct thread_info
*tp
= inferior_thread ();
7443 struct inferior
*inf
= current_inferior ();
7445 inf_status
->thread_control
= tp
->control
;
7446 inf_status
->inferior_control
= inf
->control
;
7448 tp
->control
.step_resume_breakpoint
= NULL
;
7449 tp
->control
.exception_resume_breakpoint
= NULL
;
7451 /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of
7452 chain. If caller's caller is walking the chain, they'll be happier if we
7453 hand them back the original chain when restore_infcall_control_state is
7455 tp
->control
.stop_bpstat
= bpstat_copy (tp
->control
.stop_bpstat
);
7458 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
7459 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
7460 inf_status
->stop_after_trap
= stop_after_trap
;
7462 inf_status
->selected_frame_id
= get_frame_id (get_selected_frame (NULL
));
7468 restore_selected_frame (void *args
)
7470 struct frame_id
*fid
= (struct frame_id
*) args
;
7471 struct frame_info
*frame
;
7473 frame
= frame_find_by_id (*fid
);
7475 /* If inf_status->selected_frame_id is NULL, there was no previously
7479 warning (_("Unable to restore previously selected frame."));
7483 select_frame (frame
);
7488 /* Restore inferior session state to INF_STATUS. */
7491 restore_infcall_control_state (struct infcall_control_state
*inf_status
)
7493 struct thread_info
*tp
= inferior_thread ();
7494 struct inferior
*inf
= current_inferior ();
7496 if (tp
->control
.step_resume_breakpoint
)
7497 tp
->control
.step_resume_breakpoint
->disposition
= disp_del_at_next_stop
;
7499 if (tp
->control
.exception_resume_breakpoint
)
7500 tp
->control
.exception_resume_breakpoint
->disposition
7501 = disp_del_at_next_stop
;
7503 /* Handle the bpstat_copy of the chain. */
7504 bpstat_clear (&tp
->control
.stop_bpstat
);
7506 tp
->control
= inf_status
->thread_control
;
7507 inf
->control
= inf_status
->inferior_control
;
7510 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
7511 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
7512 stop_after_trap
= inf_status
->stop_after_trap
;
7514 if (target_has_stack
)
7516 /* The point of catch_errors is that if the stack is clobbered,
7517 walking the stack might encounter a garbage pointer and
7518 error() trying to dereference it. */
7520 (restore_selected_frame
, &inf_status
->selected_frame_id
,
7521 "Unable to restore previously selected frame:\n",
7522 RETURN_MASK_ERROR
) == 0)
7523 /* Error in restoring the selected frame. Select the innermost
7525 select_frame (get_current_frame ());
7532 do_restore_infcall_control_state_cleanup (void *sts
)
7534 restore_infcall_control_state (sts
);
7538 make_cleanup_restore_infcall_control_state
7539 (struct infcall_control_state
*inf_status
)
7541 return make_cleanup (do_restore_infcall_control_state_cleanup
, inf_status
);
7545 discard_infcall_control_state (struct infcall_control_state
*inf_status
)
7547 if (inf_status
->thread_control
.step_resume_breakpoint
)
7548 inf_status
->thread_control
.step_resume_breakpoint
->disposition
7549 = disp_del_at_next_stop
;
7551 if (inf_status
->thread_control
.exception_resume_breakpoint
)
7552 inf_status
->thread_control
.exception_resume_breakpoint
->disposition
7553 = disp_del_at_next_stop
;
7555 /* See save_infcall_control_state for info on stop_bpstat. */
7556 bpstat_clear (&inf_status
->thread_control
.stop_bpstat
);
7561 /* restore_inferior_ptid() will be used by the cleanup machinery
7562 to restore the inferior_ptid value saved in a call to
7563 save_inferior_ptid(). */
7566 restore_inferior_ptid (void *arg
)
7568 ptid_t
*saved_ptid_ptr
= arg
;
7570 inferior_ptid
= *saved_ptid_ptr
;
7574 /* Save the value of inferior_ptid so that it may be restored by a
7575 later call to do_cleanups(). Returns the struct cleanup pointer
7576 needed for later doing the cleanup. */
7579 save_inferior_ptid (void)
7581 ptid_t
*saved_ptid_ptr
;
7583 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
7584 *saved_ptid_ptr
= inferior_ptid
;
7585 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
7591 clear_exit_convenience_vars (void)
7593 clear_internalvar (lookup_internalvar ("_exitsignal"));
7594 clear_internalvar (lookup_internalvar ("_exitcode"));
7598 /* User interface for reverse debugging:
7599 Set exec-direction / show exec-direction commands
7600 (returns error unless target implements to_set_exec_direction method). */
7602 int execution_direction
= EXEC_FORWARD
;
7603 static const char exec_forward
[] = "forward";
7604 static const char exec_reverse
[] = "reverse";
7605 static const char *exec_direction
= exec_forward
;
7606 static const char *const exec_direction_names
[] = {
7613 set_exec_direction_func (char *args
, int from_tty
,
7614 struct cmd_list_element
*cmd
)
7616 if (target_can_execute_reverse
)
7618 if (!strcmp (exec_direction
, exec_forward
))
7619 execution_direction
= EXEC_FORWARD
;
7620 else if (!strcmp (exec_direction
, exec_reverse
))
7621 execution_direction
= EXEC_REVERSE
;
7625 exec_direction
= exec_forward
;
7626 error (_("Target does not support this operation."));
7631 show_exec_direction_func (struct ui_file
*out
, int from_tty
,
7632 struct cmd_list_element
*cmd
, const char *value
)
7634 switch (execution_direction
) {
7636 fprintf_filtered (out
, _("Forward.\n"));
7639 fprintf_filtered (out
, _("Reverse.\n"));
7642 internal_error (__FILE__
, __LINE__
,
7643 _("bogus execution_direction value: %d"),
7644 (int) execution_direction
);
7649 show_schedule_multiple (struct ui_file
*file
, int from_tty
,
7650 struct cmd_list_element
*c
, const char *value
)
7652 fprintf_filtered (file
, _("Resuming the execution of threads "
7653 "of all processes is %s.\n"), value
);
7656 /* Implementation of `siginfo' variable. */
7658 static const struct internalvar_funcs siginfo_funcs
=
7666 _initialize_infrun (void)
7670 struct cmd_list_element
*c
;
7672 add_info ("signals", signals_info
, _("\
7673 What debugger does when program gets various signals.\n\
7674 Specify a signal as argument to print info on that signal only."));
7675 add_info_alias ("handle", "signals", 0);
7677 c
= add_com ("handle", class_run
, handle_command
, _("\
7678 Specify how to handle signals.\n\
7679 Usage: handle SIGNAL [ACTIONS]\n\
7680 Args are signals and actions to apply to those signals.\n\
7681 If no actions are specified, the current settings for the specified signals\n\
7682 will be displayed instead.\n\
7684 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
7685 from 1-15 are allowed for compatibility with old versions of GDB.\n\
7686 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
7687 The special arg \"all\" is recognized to mean all signals except those\n\
7688 used by the debugger, typically SIGTRAP and SIGINT.\n\
7690 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
7691 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
7692 Stop means reenter debugger if this signal happens (implies print).\n\
7693 Print means print a message if this signal happens.\n\
7694 Pass means let program see this signal; otherwise program doesn't know.\n\
7695 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
7696 Pass and Stop may be combined.\n\
7698 Multiple signals may be specified. Signal numbers and signal names\n\
7699 may be interspersed with actions, with the actions being performed for\n\
7700 all signals cumulatively specified."));
7701 set_cmd_completer (c
, handle_completer
);
7705 add_com ("lz", class_info
, signals_info
, _("\
7706 What debugger does when program gets various signals.\n\
7707 Specify a signal as argument to print info on that signal only."));
7708 add_com ("z", class_run
, xdb_handle_command
, _("\
7709 Specify how to handle a signal.\n\
7710 Args are signals and actions to apply to those signals.\n\
7711 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
7712 from 1-15 are allowed for compatibility with old versions of GDB.\n\
7713 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
7714 The special arg \"all\" is recognized to mean all signals except those\n\
7715 used by the debugger, typically SIGTRAP and SIGINT.\n\
7716 Recognized actions include \"s\" (toggles between stop and nostop),\n\
7717 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
7718 nopass), \"Q\" (noprint)\n\
7719 Stop means reenter debugger if this signal happens (implies print).\n\
7720 Print means print a message if this signal happens.\n\
7721 Pass means let program see this signal; otherwise program doesn't know.\n\
7722 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
7723 Pass and Stop may be combined."));
7727 stop_command
= add_cmd ("stop", class_obscure
,
7728 not_just_help_class_command
, _("\
7729 There is no `stop' command, but you can set a hook on `stop'.\n\
7730 This allows you to set a list of commands to be run each time execution\n\
7731 of the program stops."), &cmdlist
);
7733 add_setshow_zuinteger_cmd ("infrun", class_maintenance
, &debug_infrun
, _("\
7734 Set inferior debugging."), _("\
7735 Show inferior debugging."), _("\
7736 When non-zero, inferior specific debugging is enabled."),
7739 &setdebuglist
, &showdebuglist
);
7741 add_setshow_boolean_cmd ("displaced", class_maintenance
,
7742 &debug_displaced
, _("\
7743 Set displaced stepping debugging."), _("\
7744 Show displaced stepping debugging."), _("\
7745 When non-zero, displaced stepping specific debugging is enabled."),
7747 show_debug_displaced
,
7748 &setdebuglist
, &showdebuglist
);
7750 add_setshow_boolean_cmd ("non-stop", no_class
,
7752 Set whether gdb controls the inferior in non-stop mode."), _("\
7753 Show whether gdb controls the inferior in non-stop mode."), _("\
7754 When debugging a multi-threaded program and this setting is\n\
7755 off (the default, also called all-stop mode), when one thread stops\n\
7756 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
7757 all other threads in the program while you interact with the thread of\n\
7758 interest. When you continue or step a thread, you can allow the other\n\
7759 threads to run, or have them remain stopped, but while you inspect any\n\
7760 thread's state, all threads stop.\n\
7762 In non-stop mode, when one thread stops, other threads can continue\n\
7763 to run freely. You'll be able to step each thread independently,\n\
7764 leave it stopped or free to run as needed."),
7770 numsigs
= (int) GDB_SIGNAL_LAST
;
7771 signal_stop
= (unsigned char *) xmalloc (sizeof (signal_stop
[0]) * numsigs
);
7772 signal_print
= (unsigned char *)
7773 xmalloc (sizeof (signal_print
[0]) * numsigs
);
7774 signal_program
= (unsigned char *)
7775 xmalloc (sizeof (signal_program
[0]) * numsigs
);
7776 signal_catch
= (unsigned char *)
7777 xmalloc (sizeof (signal_catch
[0]) * numsigs
);
7778 signal_pass
= (unsigned char *)
7779 xmalloc (sizeof (signal_pass
[0]) * numsigs
);
7780 for (i
= 0; i
< numsigs
; i
++)
7783 signal_print
[i
] = 1;
7784 signal_program
[i
] = 1;
7785 signal_catch
[i
] = 0;
7788 /* Signals caused by debugger's own actions
7789 should not be given to the program afterwards. */
7790 signal_program
[GDB_SIGNAL_TRAP
] = 0;
7791 signal_program
[GDB_SIGNAL_INT
] = 0;
7793 /* Signals that are not errors should not normally enter the debugger. */
7794 signal_stop
[GDB_SIGNAL_ALRM
] = 0;
7795 signal_print
[GDB_SIGNAL_ALRM
] = 0;
7796 signal_stop
[GDB_SIGNAL_VTALRM
] = 0;
7797 signal_print
[GDB_SIGNAL_VTALRM
] = 0;
7798 signal_stop
[GDB_SIGNAL_PROF
] = 0;
7799 signal_print
[GDB_SIGNAL_PROF
] = 0;
7800 signal_stop
[GDB_SIGNAL_CHLD
] = 0;
7801 signal_print
[GDB_SIGNAL_CHLD
] = 0;
7802 signal_stop
[GDB_SIGNAL_IO
] = 0;
7803 signal_print
[GDB_SIGNAL_IO
] = 0;
7804 signal_stop
[GDB_SIGNAL_POLL
] = 0;
7805 signal_print
[GDB_SIGNAL_POLL
] = 0;
7806 signal_stop
[GDB_SIGNAL_URG
] = 0;
7807 signal_print
[GDB_SIGNAL_URG
] = 0;
7808 signal_stop
[GDB_SIGNAL_WINCH
] = 0;
7809 signal_print
[GDB_SIGNAL_WINCH
] = 0;
7810 signal_stop
[GDB_SIGNAL_PRIO
] = 0;
7811 signal_print
[GDB_SIGNAL_PRIO
] = 0;
7813 /* These signals are used internally by user-level thread
7814 implementations. (See signal(5) on Solaris.) Like the above
7815 signals, a healthy program receives and handles them as part of
7816 its normal operation. */
7817 signal_stop
[GDB_SIGNAL_LWP
] = 0;
7818 signal_print
[GDB_SIGNAL_LWP
] = 0;
7819 signal_stop
[GDB_SIGNAL_WAITING
] = 0;
7820 signal_print
[GDB_SIGNAL_WAITING
] = 0;
7821 signal_stop
[GDB_SIGNAL_CANCEL
] = 0;
7822 signal_print
[GDB_SIGNAL_CANCEL
] = 0;
7824 /* Update cached state. */
7825 signal_cache_update (-1);
7827 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support
,
7828 &stop_on_solib_events
, _("\
7829 Set stopping for shared library events."), _("\
7830 Show stopping for shared library events."), _("\
7831 If nonzero, gdb will give control to the user when the dynamic linker\n\
7832 notifies gdb of shared library events. The most common event of interest\n\
7833 to the user would be loading/unloading of a new library."),
7834 set_stop_on_solib_events
,
7835 show_stop_on_solib_events
,
7836 &setlist
, &showlist
);
7838 add_setshow_enum_cmd ("follow-fork-mode", class_run
,
7839 follow_fork_mode_kind_names
,
7840 &follow_fork_mode_string
, _("\
7841 Set debugger response to a program call of fork or vfork."), _("\
7842 Show debugger response to a program call of fork or vfork."), _("\
7843 A fork or vfork creates a new process. follow-fork-mode can be:\n\
7844 parent - the original process is debugged after a fork\n\
7845 child - the new process is debugged after a fork\n\
7846 The unfollowed process will continue to run.\n\
7847 By default, the debugger will follow the parent process."),
7849 show_follow_fork_mode_string
,
7850 &setlist
, &showlist
);
7852 add_setshow_enum_cmd ("follow-exec-mode", class_run
,
7853 follow_exec_mode_names
,
7854 &follow_exec_mode_string
, _("\
7855 Set debugger response to a program call of exec."), _("\
7856 Show debugger response to a program call of exec."), _("\
7857 An exec call replaces the program image of a process.\n\
7859 follow-exec-mode can be:\n\
7861 new - the debugger creates a new inferior and rebinds the process\n\
7862 to this new inferior. The program the process was running before\n\
7863 the exec call can be restarted afterwards by restarting the original\n\
7866 same - the debugger keeps the process bound to the same inferior.\n\
7867 The new executable image replaces the previous executable loaded in\n\
7868 the inferior. Restarting the inferior after the exec call restarts\n\
7869 the executable the process was running after the exec call.\n\
7871 By default, the debugger will use the same inferior."),
7873 show_follow_exec_mode_string
,
7874 &setlist
, &showlist
);
7876 add_setshow_enum_cmd ("scheduler-locking", class_run
,
7877 scheduler_enums
, &scheduler_mode
, _("\
7878 Set mode for locking scheduler during execution."), _("\
7879 Show mode for locking scheduler during execution."), _("\
7880 off == no locking (threads may preempt at any time)\n\
7881 on == full locking (no thread except the current thread may run)\n\
7882 step == scheduler locked during every single-step operation.\n\
7883 In this mode, no other thread may run during a step command.\n\
7884 Other threads may run while stepping over a function call ('next')."),
7885 set_schedlock_func
, /* traps on target vector */
7886 show_scheduler_mode
,
7887 &setlist
, &showlist
);
7889 add_setshow_boolean_cmd ("schedule-multiple", class_run
, &sched_multi
, _("\
7890 Set mode for resuming threads of all processes."), _("\
7891 Show mode for resuming threads of all processes."), _("\
7892 When on, execution commands (such as 'continue' or 'next') resume all\n\
7893 threads of all processes. When off (which is the default), execution\n\
7894 commands only resume the threads of the current process. The set of\n\
7895 threads that are resumed is further refined by the scheduler-locking\n\
7896 mode (see help set scheduler-locking)."),
7898 show_schedule_multiple
,
7899 &setlist
, &showlist
);
7901 add_setshow_boolean_cmd ("step-mode", class_run
, &step_stop_if_no_debug
, _("\
7902 Set mode of the step operation."), _("\
7903 Show mode of the step operation."), _("\
7904 When set, doing a step over a function without debug line information\n\
7905 will stop at the first instruction of that function. Otherwise, the\n\
7906 function is skipped and the step command stops at a different source line."),
7908 show_step_stop_if_no_debug
,
7909 &setlist
, &showlist
);
7911 add_setshow_auto_boolean_cmd ("displaced-stepping", class_run
,
7912 &can_use_displaced_stepping
, _("\
7913 Set debugger's willingness to use displaced stepping."), _("\
7914 Show debugger's willingness to use displaced stepping."), _("\
7915 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
7916 supported by the target architecture. If off, gdb will not use displaced\n\
7917 stepping to step over breakpoints, even if such is supported by the target\n\
7918 architecture. If auto (which is the default), gdb will use displaced stepping\n\
7919 if the target architecture supports it and non-stop mode is active, but will not\n\
7920 use it in all-stop mode (see help set non-stop)."),
7922 show_can_use_displaced_stepping
,
7923 &setlist
, &showlist
);
7925 add_setshow_enum_cmd ("exec-direction", class_run
, exec_direction_names
,
7926 &exec_direction
, _("Set direction of execution.\n\
7927 Options are 'forward' or 'reverse'."),
7928 _("Show direction of execution (forward/reverse)."),
7929 _("Tells gdb whether to execute forward or backward."),
7930 set_exec_direction_func
, show_exec_direction_func
,
7931 &setlist
, &showlist
);
7933 /* Set/show detach-on-fork: user-settable mode. */
7935 add_setshow_boolean_cmd ("detach-on-fork", class_run
, &detach_fork
, _("\
7936 Set whether gdb will detach the child of a fork."), _("\
7937 Show whether gdb will detach the child of a fork."), _("\
7938 Tells gdb whether to detach the child of a fork."),
7939 NULL
, NULL
, &setlist
, &showlist
);
7941 /* Set/show disable address space randomization mode. */
7943 add_setshow_boolean_cmd ("disable-randomization", class_support
,
7944 &disable_randomization
, _("\
7945 Set disabling of debuggee's virtual address space randomization."), _("\
7946 Show disabling of debuggee's virtual address space randomization."), _("\
7947 When this mode is on (which is the default), randomization of the virtual\n\
7948 address space is disabled. Standalone programs run with the randomization\n\
7949 enabled by default on some platforms."),
7950 &set_disable_randomization
,
7951 &show_disable_randomization
,
7952 &setlist
, &showlist
);
7954 /* ptid initializations */
7955 inferior_ptid
= null_ptid
;
7956 target_last_wait_ptid
= minus_one_ptid
;
7958 observer_attach_thread_ptid_changed (infrun_thread_ptid_changed
);
7959 observer_attach_thread_stop_requested (infrun_thread_stop_requested
);
7960 observer_attach_thread_exit (infrun_thread_thread_exit
);
7961 observer_attach_inferior_exit (infrun_inferior_exit
);
7963 /* Explicitly create without lookup, since that tries to create a
7964 value with a void typed value, and when we get here, gdbarch
7965 isn't initialized yet. At this point, we're quite sure there
7966 isn't another convenience variable of the same name. */
7967 create_internalvar_type_lazy ("_siginfo", &siginfo_funcs
, NULL
);
7969 add_setshow_boolean_cmd ("observer", no_class
,
7970 &observer_mode_1
, _("\
7971 Set whether gdb controls the inferior in observer mode."), _("\
7972 Show whether gdb controls the inferior in observer mode."), _("\
7973 In observer mode, GDB can get data from the inferior, but not\n\
7974 affect its execution. Registers and memory may not be changed,\n\
7975 breakpoints may not be set, and the program cannot be interrupted\n\