1 /* Target-struct-independent code to start (run) and stop an inferior
4 Copyright (C) 1986-2013 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "gdb_string.h"
27 #include "exceptions.h"
28 #include "breakpoint.h"
32 #include "cli/cli-script.h"
34 #include "gdbthread.h"
46 #include "dictionary.h"
48 #include "gdb_assert.h"
49 #include "mi/mi-common.h"
50 #include "event-top.h"
52 #include "record-full.h"
53 #include "inline-frame.h"
55 #include "tracepoint.h"
56 #include "continuations.h"
61 #include "completer.h"
62 #include "target-descriptions.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 void set_schedlock_func (char *args
, int from_tty
,
83 struct cmd_list_element
*c
);
85 static int currently_stepping (struct thread_info
*tp
);
87 static int currently_stepping_or_nexting_callback (struct thread_info
*tp
,
90 static void xdb_handle_command (char *args
, int from_tty
);
92 static int prepare_to_proceed (int);
94 static void print_exited_reason (int exitstatus
);
96 static void print_signal_exited_reason (enum gdb_signal siggnal
);
98 static void print_no_history_reason (void);
100 static void print_signal_received_reason (enum gdb_signal siggnal
);
102 static void print_end_stepping_range_reason (void);
104 void _initialize_infrun (void);
106 void nullify_last_target_wait_ptid (void);
108 static void insert_hp_step_resume_breakpoint_at_frame (struct frame_info
*);
110 static void insert_step_resume_breakpoint_at_caller (struct frame_info
*);
112 static void insert_longjmp_resume_breakpoint (struct gdbarch
*, CORE_ADDR
);
114 /* When set, stop the 'step' command if we enter a function which has
115 no line number information. The normal behavior is that we step
116 over such function. */
117 int step_stop_if_no_debug
= 0;
119 show_step_stop_if_no_debug (struct ui_file
*file
, int from_tty
,
120 struct cmd_list_element
*c
, const char *value
)
122 fprintf_filtered (file
, _("Mode of the step operation is %s.\n"), value
);
125 /* In asynchronous mode, but simulating synchronous execution. */
127 int sync_execution
= 0;
129 /* wait_for_inferior and normal_stop use this to notify the user
130 when the inferior stopped in a different thread than it had been
133 static ptid_t previous_inferior_ptid
;
135 /* If set (default for legacy reasons), when following a fork, GDB
136 will detach from one of the fork branches, child or parent.
137 Exactly which branch is detached depends on 'set follow-fork-mode'
140 static int detach_fork
= 1;
142 int debug_displaced
= 0;
144 show_debug_displaced (struct ui_file
*file
, int from_tty
,
145 struct cmd_list_element
*c
, const char *value
)
147 fprintf_filtered (file
, _("Displace stepping debugging is %s.\n"), value
);
150 unsigned int debug_infrun
= 0;
152 show_debug_infrun (struct ui_file
*file
, int from_tty
,
153 struct cmd_list_element
*c
, const char *value
)
155 fprintf_filtered (file
, _("Inferior debugging is %s.\n"), value
);
159 /* Support for disabling address space randomization. */
161 int disable_randomization
= 1;
164 show_disable_randomization (struct ui_file
*file
, int from_tty
,
165 struct cmd_list_element
*c
, const char *value
)
167 if (target_supports_disable_randomization ())
168 fprintf_filtered (file
,
169 _("Disabling randomization of debuggee's "
170 "virtual address space is %s.\n"),
173 fputs_filtered (_("Disabling randomization of debuggee's "
174 "virtual address space is unsupported on\n"
175 "this platform.\n"), file
);
179 set_disable_randomization (char *args
, int from_tty
,
180 struct cmd_list_element
*c
)
182 if (!target_supports_disable_randomization ())
183 error (_("Disabling randomization of debuggee's "
184 "virtual address space is unsupported on\n"
188 /* User interface for non-stop mode. */
191 static int non_stop_1
= 0;
194 set_non_stop (char *args
, int from_tty
,
195 struct cmd_list_element
*c
)
197 if (target_has_execution
)
199 non_stop_1
= non_stop
;
200 error (_("Cannot change this setting while the inferior is running."));
203 non_stop
= non_stop_1
;
207 show_non_stop (struct ui_file
*file
, int from_tty
,
208 struct cmd_list_element
*c
, const char *value
)
210 fprintf_filtered (file
,
211 _("Controlling the inferior in non-stop mode is %s.\n"),
215 /* "Observer mode" is somewhat like a more extreme version of
216 non-stop, in which all GDB operations that might affect the
217 target's execution have been disabled. */
219 int observer_mode
= 0;
220 static int observer_mode_1
= 0;
223 set_observer_mode (char *args
, int from_tty
,
224 struct cmd_list_element
*c
)
226 if (target_has_execution
)
228 observer_mode_1
= observer_mode
;
229 error (_("Cannot change this setting while the inferior is running."));
232 observer_mode
= observer_mode_1
;
234 may_write_registers
= !observer_mode
;
235 may_write_memory
= !observer_mode
;
236 may_insert_breakpoints
= !observer_mode
;
237 may_insert_tracepoints
= !observer_mode
;
238 /* We can insert fast tracepoints in or out of observer mode,
239 but enable them if we're going into this mode. */
241 may_insert_fast_tracepoints
= 1;
242 may_stop
= !observer_mode
;
243 update_target_permissions ();
245 /* Going *into* observer mode we must force non-stop, then
246 going out we leave it that way. */
249 target_async_permitted
= 1;
250 pagination_enabled
= 0;
251 non_stop
= non_stop_1
= 1;
255 printf_filtered (_("Observer mode is now %s.\n"),
256 (observer_mode
? "on" : "off"));
260 show_observer_mode (struct ui_file
*file
, int from_tty
,
261 struct cmd_list_element
*c
, const char *value
)
263 fprintf_filtered (file
, _("Observer mode is %s.\n"), value
);
266 /* This updates the value of observer mode based on changes in
267 permissions. Note that we are deliberately ignoring the values of
268 may-write-registers and may-write-memory, since the user may have
269 reason to enable these during a session, for instance to turn on a
270 debugging-related global. */
273 update_observer_mode (void)
277 newval
= (!may_insert_breakpoints
278 && !may_insert_tracepoints
279 && may_insert_fast_tracepoints
283 /* Let the user know if things change. */
284 if (newval
!= observer_mode
)
285 printf_filtered (_("Observer mode is now %s.\n"),
286 (newval
? "on" : "off"));
288 observer_mode
= observer_mode_1
= newval
;
291 /* Tables of how to react to signals; the user sets them. */
293 static unsigned char *signal_stop
;
294 static unsigned char *signal_print
;
295 static unsigned char *signal_program
;
297 /* Table of signals that are registered with "catch signal". A
298 non-zero entry indicates that the signal is caught by some "catch
299 signal" command. This has size GDB_SIGNAL_LAST, to accommodate all
301 static unsigned char *signal_catch
;
303 /* Table of signals that the target may silently handle.
304 This is automatically determined from the flags above,
305 and simply cached here. */
306 static unsigned char *signal_pass
;
308 #define SET_SIGS(nsigs,sigs,flags) \
310 int signum = (nsigs); \
311 while (signum-- > 0) \
312 if ((sigs)[signum]) \
313 (flags)[signum] = 1; \
316 #define UNSET_SIGS(nsigs,sigs,flags) \
318 int signum = (nsigs); \
319 while (signum-- > 0) \
320 if ((sigs)[signum]) \
321 (flags)[signum] = 0; \
324 /* Update the target's copy of SIGNAL_PROGRAM. The sole purpose of
325 this function is to avoid exporting `signal_program'. */
328 update_signals_program_target (void)
330 target_program_signals ((int) GDB_SIGNAL_LAST
, signal_program
);
333 /* Value to pass to target_resume() to cause all threads to resume. */
335 #define RESUME_ALL minus_one_ptid
337 /* Command list pointer for the "stop" placeholder. */
339 static struct cmd_list_element
*stop_command
;
341 /* Function inferior was in as of last step command. */
343 static struct symbol
*step_start_function
;
345 /* Nonzero if we want to give control to the user when we're notified
346 of shared library events by the dynamic linker. */
347 int stop_on_solib_events
;
349 /* Enable or disable optional shared library event breakpoints
350 as appropriate when the above flag is changed. */
353 set_stop_on_solib_events (char *args
, int from_tty
, struct cmd_list_element
*c
)
355 update_solib_breakpoints ();
359 show_stop_on_solib_events (struct ui_file
*file
, int from_tty
,
360 struct cmd_list_element
*c
, const char *value
)
362 fprintf_filtered (file
, _("Stopping for shared library events is %s.\n"),
366 /* Nonzero means expecting a trace trap
367 and should stop the inferior and return silently when it happens. */
371 /* Save register contents here when executing a "finish" command or are
372 about to pop a stack dummy frame, if-and-only-if proceed_to_finish is set.
373 Thus this contains the return value from the called function (assuming
374 values are returned in a register). */
376 struct regcache
*stop_registers
;
378 /* Nonzero after stop if current stack frame should be printed. */
380 static int stop_print_frame
;
382 /* This is a cached copy of the pid/waitstatus of the last event
383 returned by target_wait()/deprecated_target_wait_hook(). This
384 information is returned by get_last_target_status(). */
385 static ptid_t target_last_wait_ptid
;
386 static struct target_waitstatus target_last_waitstatus
;
388 static void context_switch (ptid_t ptid
);
390 void init_thread_stepping_state (struct thread_info
*tss
);
392 static void init_infwait_state (void);
394 static const char follow_fork_mode_child
[] = "child";
395 static const char follow_fork_mode_parent
[] = "parent";
397 static const char *const follow_fork_mode_kind_names
[] = {
398 follow_fork_mode_child
,
399 follow_fork_mode_parent
,
403 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
405 show_follow_fork_mode_string (struct ui_file
*file
, int from_tty
,
406 struct cmd_list_element
*c
, const char *value
)
408 fprintf_filtered (file
,
409 _("Debugger response to a program "
410 "call of fork or vfork is \"%s\".\n"),
415 /* Tell the target to follow the fork we're stopped at. Returns true
416 if the inferior should be resumed; false, if the target for some
417 reason decided it's best not to resume. */
422 int follow_child
= (follow_fork_mode_string
== follow_fork_mode_child
);
423 int should_resume
= 1;
424 struct thread_info
*tp
;
426 /* Copy user stepping state to the new inferior thread. FIXME: the
427 followed fork child thread should have a copy of most of the
428 parent thread structure's run control related fields, not just these.
429 Initialized to avoid "may be used uninitialized" warnings from gcc. */
430 struct breakpoint
*step_resume_breakpoint
= NULL
;
431 struct breakpoint
*exception_resume_breakpoint
= NULL
;
432 CORE_ADDR step_range_start
= 0;
433 CORE_ADDR step_range_end
= 0;
434 struct frame_id step_frame_id
= { 0 };
439 struct target_waitstatus wait_status
;
441 /* Get the last target status returned by target_wait(). */
442 get_last_target_status (&wait_ptid
, &wait_status
);
444 /* If not stopped at a fork event, then there's nothing else to
446 if (wait_status
.kind
!= TARGET_WAITKIND_FORKED
447 && wait_status
.kind
!= TARGET_WAITKIND_VFORKED
)
450 /* Check if we switched over from WAIT_PTID, since the event was
452 if (!ptid_equal (wait_ptid
, minus_one_ptid
)
453 && !ptid_equal (inferior_ptid
, wait_ptid
))
455 /* We did. Switch back to WAIT_PTID thread, to tell the
456 target to follow it (in either direction). We'll
457 afterwards refuse to resume, and inform the user what
459 switch_to_thread (wait_ptid
);
464 tp
= inferior_thread ();
466 /* If there were any forks/vforks that were caught and are now to be
467 followed, then do so now. */
468 switch (tp
->pending_follow
.kind
)
470 case TARGET_WAITKIND_FORKED
:
471 case TARGET_WAITKIND_VFORKED
:
473 ptid_t parent
, child
;
475 /* If the user did a next/step, etc, over a fork call,
476 preserve the stepping state in the fork child. */
477 if (follow_child
&& should_resume
)
479 step_resume_breakpoint
= clone_momentary_breakpoint
480 (tp
->control
.step_resume_breakpoint
);
481 step_range_start
= tp
->control
.step_range_start
;
482 step_range_end
= tp
->control
.step_range_end
;
483 step_frame_id
= tp
->control
.step_frame_id
;
484 exception_resume_breakpoint
485 = clone_momentary_breakpoint (tp
->control
.exception_resume_breakpoint
);
487 /* For now, delete the parent's sr breakpoint, otherwise,
488 parent/child sr breakpoints are considered duplicates,
489 and the child version will not be installed. Remove
490 this when the breakpoints module becomes aware of
491 inferiors and address spaces. */
492 delete_step_resume_breakpoint (tp
);
493 tp
->control
.step_range_start
= 0;
494 tp
->control
.step_range_end
= 0;
495 tp
->control
.step_frame_id
= null_frame_id
;
496 delete_exception_resume_breakpoint (tp
);
499 parent
= inferior_ptid
;
500 child
= tp
->pending_follow
.value
.related_pid
;
502 /* Tell the target to do whatever is necessary to follow
503 either parent or child. */
504 if (target_follow_fork (follow_child
, detach_fork
))
506 /* Target refused to follow, or there's some other reason
507 we shouldn't resume. */
512 /* This pending follow fork event is now handled, one way
513 or another. The previous selected thread may be gone
514 from the lists by now, but if it is still around, need
515 to clear the pending follow request. */
516 tp
= find_thread_ptid (parent
);
518 tp
->pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
520 /* This makes sure we don't try to apply the "Switched
521 over from WAIT_PID" logic above. */
522 nullify_last_target_wait_ptid ();
524 /* If we followed the child, switch to it... */
527 switch_to_thread (child
);
529 /* ... and preserve the stepping state, in case the
530 user was stepping over the fork call. */
533 tp
= inferior_thread ();
534 tp
->control
.step_resume_breakpoint
535 = step_resume_breakpoint
;
536 tp
->control
.step_range_start
= step_range_start
;
537 tp
->control
.step_range_end
= step_range_end
;
538 tp
->control
.step_frame_id
= step_frame_id
;
539 tp
->control
.exception_resume_breakpoint
540 = exception_resume_breakpoint
;
544 /* If we get here, it was because we're trying to
545 resume from a fork catchpoint, but, the user
546 has switched threads away from the thread that
547 forked. In that case, the resume command
548 issued is most likely not applicable to the
549 child, so just warn, and refuse to resume. */
550 warning (_("Not resuming: switched threads "
551 "before following fork child.\n"));
554 /* Reset breakpoints in the child as appropriate. */
555 follow_inferior_reset_breakpoints ();
558 switch_to_thread (parent
);
562 case TARGET_WAITKIND_SPURIOUS
:
563 /* Nothing to follow. */
566 internal_error (__FILE__
, __LINE__
,
567 "Unexpected pending_follow.kind %d\n",
568 tp
->pending_follow
.kind
);
572 return should_resume
;
576 follow_inferior_reset_breakpoints (void)
578 struct thread_info
*tp
= inferior_thread ();
580 /* Was there a step_resume breakpoint? (There was if the user
581 did a "next" at the fork() call.) If so, explicitly reset its
584 step_resumes are a form of bp that are made to be per-thread.
585 Since we created the step_resume bp when the parent process
586 was being debugged, and now are switching to the child process,
587 from the breakpoint package's viewpoint, that's a switch of
588 "threads". We must update the bp's notion of which thread
589 it is for, or it'll be ignored when it triggers. */
591 if (tp
->control
.step_resume_breakpoint
)
592 breakpoint_re_set_thread (tp
->control
.step_resume_breakpoint
);
594 if (tp
->control
.exception_resume_breakpoint
)
595 breakpoint_re_set_thread (tp
->control
.exception_resume_breakpoint
);
597 /* Reinsert all breakpoints in the child. The user may have set
598 breakpoints after catching the fork, in which case those
599 were never set in the child, but only in the parent. This makes
600 sure the inserted breakpoints match the breakpoint list. */
602 breakpoint_re_set ();
603 insert_breakpoints ();
606 /* The child has exited or execed: resume threads of the parent the
607 user wanted to be executing. */
610 proceed_after_vfork_done (struct thread_info
*thread
,
613 int pid
= * (int *) arg
;
615 if (ptid_get_pid (thread
->ptid
) == pid
616 && is_running (thread
->ptid
)
617 && !is_executing (thread
->ptid
)
618 && !thread
->stop_requested
619 && thread
->suspend
.stop_signal
== GDB_SIGNAL_0
)
622 fprintf_unfiltered (gdb_stdlog
,
623 "infrun: resuming vfork parent thread %s\n",
624 target_pid_to_str (thread
->ptid
));
626 switch_to_thread (thread
->ptid
);
627 clear_proceed_status ();
628 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
, 0);
634 /* Called whenever we notice an exec or exit event, to handle
635 detaching or resuming a vfork parent. */
638 handle_vfork_child_exec_or_exit (int exec
)
640 struct inferior
*inf
= current_inferior ();
642 if (inf
->vfork_parent
)
644 int resume_parent
= -1;
646 /* This exec or exit marks the end of the shared memory region
647 between the parent and the child. If the user wanted to
648 detach from the parent, now is the time. */
650 if (inf
->vfork_parent
->pending_detach
)
652 struct thread_info
*tp
;
653 struct cleanup
*old_chain
;
654 struct program_space
*pspace
;
655 struct address_space
*aspace
;
657 /* follow-fork child, detach-on-fork on. */
659 inf
->vfork_parent
->pending_detach
= 0;
663 /* If we're handling a child exit, then inferior_ptid
664 points at the inferior's pid, not to a thread. */
665 old_chain
= save_inferior_ptid ();
666 save_current_program_space ();
667 save_current_inferior ();
670 old_chain
= save_current_space_and_thread ();
672 /* We're letting loose of the parent. */
673 tp
= any_live_thread_of_process (inf
->vfork_parent
->pid
);
674 switch_to_thread (tp
->ptid
);
676 /* We're about to detach from the parent, which implicitly
677 removes breakpoints from its address space. There's a
678 catch here: we want to reuse the spaces for the child,
679 but, parent/child are still sharing the pspace at this
680 point, although the exec in reality makes the kernel give
681 the child a fresh set of new pages. The problem here is
682 that the breakpoints module being unaware of this, would
683 likely chose the child process to write to the parent
684 address space. Swapping the child temporarily away from
685 the spaces has the desired effect. Yes, this is "sort
688 pspace
= inf
->pspace
;
689 aspace
= inf
->aspace
;
693 if (debug_infrun
|| info_verbose
)
695 target_terminal_ours ();
698 fprintf_filtered (gdb_stdlog
,
699 "Detaching vfork parent process "
700 "%d after child exec.\n",
701 inf
->vfork_parent
->pid
);
703 fprintf_filtered (gdb_stdlog
,
704 "Detaching vfork parent process "
705 "%d after child exit.\n",
706 inf
->vfork_parent
->pid
);
709 target_detach (NULL
, 0);
712 inf
->pspace
= pspace
;
713 inf
->aspace
= aspace
;
715 do_cleanups (old_chain
);
719 /* We're staying attached to the parent, so, really give the
720 child a new address space. */
721 inf
->pspace
= add_program_space (maybe_new_address_space ());
722 inf
->aspace
= inf
->pspace
->aspace
;
724 set_current_program_space (inf
->pspace
);
726 resume_parent
= inf
->vfork_parent
->pid
;
728 /* Break the bonds. */
729 inf
->vfork_parent
->vfork_child
= NULL
;
733 struct cleanup
*old_chain
;
734 struct program_space
*pspace
;
736 /* If this is a vfork child exiting, then the pspace and
737 aspaces were shared with the parent. Since we're
738 reporting the process exit, we'll be mourning all that is
739 found in the address space, and switching to null_ptid,
740 preparing to start a new inferior. But, since we don't
741 want to clobber the parent's address/program spaces, we
742 go ahead and create a new one for this exiting
745 /* Switch to null_ptid, so that clone_program_space doesn't want
746 to read the selected frame of a dead process. */
747 old_chain
= save_inferior_ptid ();
748 inferior_ptid
= null_ptid
;
750 /* This inferior is dead, so avoid giving the breakpoints
751 module the option to write through to it (cloning a
752 program space resets breakpoints). */
755 pspace
= add_program_space (maybe_new_address_space ());
756 set_current_program_space (pspace
);
758 inf
->symfile_flags
= SYMFILE_NO_READ
;
759 clone_program_space (pspace
, inf
->vfork_parent
->pspace
);
760 inf
->pspace
= pspace
;
761 inf
->aspace
= pspace
->aspace
;
763 /* Put back inferior_ptid. We'll continue mourning this
765 do_cleanups (old_chain
);
767 resume_parent
= inf
->vfork_parent
->pid
;
768 /* Break the bonds. */
769 inf
->vfork_parent
->vfork_child
= NULL
;
772 inf
->vfork_parent
= NULL
;
774 gdb_assert (current_program_space
== inf
->pspace
);
776 if (non_stop
&& resume_parent
!= -1)
778 /* If the user wanted the parent to be running, let it go
780 struct cleanup
*old_chain
= make_cleanup_restore_current_thread ();
783 fprintf_unfiltered (gdb_stdlog
,
784 "infrun: resuming vfork parent process %d\n",
787 iterate_over_threads (proceed_after_vfork_done
, &resume_parent
);
789 do_cleanups (old_chain
);
794 /* Enum strings for "set|show follow-exec-mode". */
796 static const char follow_exec_mode_new
[] = "new";
797 static const char follow_exec_mode_same
[] = "same";
798 static const char *const follow_exec_mode_names
[] =
800 follow_exec_mode_new
,
801 follow_exec_mode_same
,
805 static const char *follow_exec_mode_string
= follow_exec_mode_same
;
807 show_follow_exec_mode_string (struct ui_file
*file
, int from_tty
,
808 struct cmd_list_element
*c
, const char *value
)
810 fprintf_filtered (file
, _("Follow exec mode is \"%s\".\n"), value
);
813 /* EXECD_PATHNAME is assumed to be non-NULL. */
816 follow_exec (ptid_t pid
, char *execd_pathname
)
818 struct thread_info
*th
= inferior_thread ();
819 struct inferior
*inf
= current_inferior ();
821 /* This is an exec event that we actually wish to pay attention to.
822 Refresh our symbol table to the newly exec'd program, remove any
825 If there are breakpoints, they aren't really inserted now,
826 since the exec() transformed our inferior into a fresh set
829 We want to preserve symbolic breakpoints on the list, since
830 we have hopes that they can be reset after the new a.out's
831 symbol table is read.
833 However, any "raw" breakpoints must be removed from the list
834 (e.g., the solib bp's), since their address is probably invalid
837 And, we DON'T want to call delete_breakpoints() here, since
838 that may write the bp's "shadow contents" (the instruction
839 value that was overwritten witha TRAP instruction). Since
840 we now have a new a.out, those shadow contents aren't valid. */
842 mark_breakpoints_out ();
844 update_breakpoints_after_exec ();
846 /* If there was one, it's gone now. We cannot truly step-to-next
847 statement through an exec(). */
848 th
->control
.step_resume_breakpoint
= NULL
;
849 th
->control
.exception_resume_breakpoint
= NULL
;
850 th
->control
.step_range_start
= 0;
851 th
->control
.step_range_end
= 0;
853 /* The target reports the exec event to the main thread, even if
854 some other thread does the exec, and even if the main thread was
855 already stopped --- if debugging in non-stop mode, it's possible
856 the user had the main thread held stopped in the previous image
857 --- release it now. This is the same behavior as step-over-exec
858 with scheduler-locking on in all-stop mode. */
859 th
->stop_requested
= 0;
861 /* What is this a.out's name? */
862 printf_unfiltered (_("%s is executing new program: %s\n"),
863 target_pid_to_str (inferior_ptid
),
866 /* We've followed the inferior through an exec. Therefore, the
867 inferior has essentially been killed & reborn. */
869 gdb_flush (gdb_stdout
);
871 breakpoint_init_inferior (inf_execd
);
873 if (gdb_sysroot
&& *gdb_sysroot
)
875 char *name
= alloca (strlen (gdb_sysroot
)
876 + strlen (execd_pathname
)
879 strcpy (name
, gdb_sysroot
);
880 strcat (name
, execd_pathname
);
881 execd_pathname
= name
;
884 /* Reset the shared library package. This ensures that we get a
885 shlib event when the child reaches "_start", at which point the
886 dld will have had a chance to initialize the child. */
887 /* Also, loading a symbol file below may trigger symbol lookups, and
888 we don't want those to be satisfied by the libraries of the
889 previous incarnation of this process. */
890 no_shared_libraries (NULL
, 0);
892 if (follow_exec_mode_string
== follow_exec_mode_new
)
894 struct program_space
*pspace
;
896 /* The user wants to keep the old inferior and program spaces
897 around. Create a new fresh one, and switch to it. */
899 inf
= add_inferior (current_inferior ()->pid
);
900 pspace
= add_program_space (maybe_new_address_space ());
901 inf
->pspace
= pspace
;
902 inf
->aspace
= pspace
->aspace
;
904 exit_inferior_num_silent (current_inferior ()->num
);
906 set_current_inferior (inf
);
907 set_current_program_space (pspace
);
911 /* The old description may no longer be fit for the new image.
912 E.g, a 64-bit process exec'ed a 32-bit process. Clear the
913 old description; we'll read a new one below. No need to do
914 this on "follow-exec-mode new", as the old inferior stays
915 around (its description is later cleared/refetched on
917 target_clear_description ();
920 gdb_assert (current_program_space
== inf
->pspace
);
922 /* That a.out is now the one to use. */
923 exec_file_attach (execd_pathname
, 0);
925 /* SYMFILE_DEFER_BP_RESET is used as the proper displacement for PIE
926 (Position Independent Executable) main symbol file will get applied by
927 solib_create_inferior_hook below. breakpoint_re_set would fail to insert
928 the breakpoints with the zero displacement. */
930 symbol_file_add (execd_pathname
,
932 | SYMFILE_MAINLINE
| SYMFILE_DEFER_BP_RESET
),
935 if ((inf
->symfile_flags
& SYMFILE_NO_READ
) == 0)
936 set_initial_language ();
938 /* If the target can specify a description, read it. Must do this
939 after flipping to the new executable (because the target supplied
940 description must be compatible with the executable's
941 architecture, and the old executable may e.g., be 32-bit, while
942 the new one 64-bit), and before anything involving memory or
944 target_find_description ();
946 solib_create_inferior_hook (0);
948 jit_inferior_created_hook ();
950 breakpoint_re_set ();
952 /* Reinsert all breakpoints. (Those which were symbolic have
953 been reset to the proper address in the new a.out, thanks
954 to symbol_file_command...). */
955 insert_breakpoints ();
957 /* The next resume of this inferior should bring it to the shlib
958 startup breakpoints. (If the user had also set bp's on
959 "main" from the old (parent) process, then they'll auto-
960 matically get reset there in the new process.). */
963 /* Non-zero if we just simulating a single-step. This is needed
964 because we cannot remove the breakpoints in the inferior process
965 until after the `wait' in `wait_for_inferior'. */
966 static int singlestep_breakpoints_inserted_p
= 0;
968 /* The thread we inserted single-step breakpoints for. */
969 static ptid_t singlestep_ptid
;
971 /* PC when we started this single-step. */
972 static CORE_ADDR singlestep_pc
;
974 /* If another thread hit the singlestep breakpoint, we save the original
975 thread here so that we can resume single-stepping it later. */
976 static ptid_t saved_singlestep_ptid
;
977 static int stepping_past_singlestep_breakpoint
;
979 /* If not equal to null_ptid, this means that after stepping over breakpoint
980 is finished, we need to switch to deferred_step_ptid, and step it.
982 The use case is when one thread has hit a breakpoint, and then the user
983 has switched to another thread and issued 'step'. We need to step over
984 breakpoint in the thread which hit the breakpoint, but then continue
985 stepping the thread user has selected. */
986 static ptid_t deferred_step_ptid
;
988 /* Displaced stepping. */
990 /* In non-stop debugging mode, we must take special care to manage
991 breakpoints properly; in particular, the traditional strategy for
992 stepping a thread past a breakpoint it has hit is unsuitable.
993 'Displaced stepping' is a tactic for stepping one thread past a
994 breakpoint it has hit while ensuring that other threads running
995 concurrently will hit the breakpoint as they should.
997 The traditional way to step a thread T off a breakpoint in a
998 multi-threaded program in all-stop mode is as follows:
1000 a0) Initially, all threads are stopped, and breakpoints are not
1002 a1) We single-step T, leaving breakpoints uninserted.
1003 a2) We insert breakpoints, and resume all threads.
1005 In non-stop debugging, however, this strategy is unsuitable: we
1006 don't want to have to stop all threads in the system in order to
1007 continue or step T past a breakpoint. Instead, we use displaced
1010 n0) Initially, T is stopped, other threads are running, and
1011 breakpoints are inserted.
1012 n1) We copy the instruction "under" the breakpoint to a separate
1013 location, outside the main code stream, making any adjustments
1014 to the instruction, register, and memory state as directed by
1016 n2) We single-step T over the instruction at its new location.
1017 n3) We adjust the resulting register and memory state as directed
1018 by T's architecture. This includes resetting T's PC to point
1019 back into the main instruction stream.
1022 This approach depends on the following gdbarch methods:
1024 - gdbarch_max_insn_length and gdbarch_displaced_step_location
1025 indicate where to copy the instruction, and how much space must
1026 be reserved there. We use these in step n1.
1028 - gdbarch_displaced_step_copy_insn copies a instruction to a new
1029 address, and makes any necessary adjustments to the instruction,
1030 register contents, and memory. We use this in step n1.
1032 - gdbarch_displaced_step_fixup adjusts registers and memory after
1033 we have successfuly single-stepped the instruction, to yield the
1034 same effect the instruction would have had if we had executed it
1035 at its original address. We use this in step n3.
1037 - gdbarch_displaced_step_free_closure provides cleanup.
1039 The gdbarch_displaced_step_copy_insn and
1040 gdbarch_displaced_step_fixup functions must be written so that
1041 copying an instruction with gdbarch_displaced_step_copy_insn,
1042 single-stepping across the copied instruction, and then applying
1043 gdbarch_displaced_insn_fixup should have the same effects on the
1044 thread's memory and registers as stepping the instruction in place
1045 would have. Exactly which responsibilities fall to the copy and
1046 which fall to the fixup is up to the author of those functions.
1048 See the comments in gdbarch.sh for details.
1050 Note that displaced stepping and software single-step cannot
1051 currently be used in combination, although with some care I think
1052 they could be made to. Software single-step works by placing
1053 breakpoints on all possible subsequent instructions; if the
1054 displaced instruction is a PC-relative jump, those breakpoints
1055 could fall in very strange places --- on pages that aren't
1056 executable, or at addresses that are not proper instruction
1057 boundaries. (We do generally let other threads run while we wait
1058 to hit the software single-step breakpoint, and they might
1059 encounter such a corrupted instruction.) One way to work around
1060 this would be to have gdbarch_displaced_step_copy_insn fully
1061 simulate the effect of PC-relative instructions (and return NULL)
1062 on architectures that use software single-stepping.
1064 In non-stop mode, we can have independent and simultaneous step
1065 requests, so more than one thread may need to simultaneously step
1066 over a breakpoint. The current implementation assumes there is
1067 only one scratch space per process. In this case, we have to
1068 serialize access to the scratch space. If thread A wants to step
1069 over a breakpoint, but we are currently waiting for some other
1070 thread to complete a displaced step, we leave thread A stopped and
1071 place it in the displaced_step_request_queue. Whenever a displaced
1072 step finishes, we pick the next thread in the queue and start a new
1073 displaced step operation on it. See displaced_step_prepare and
1074 displaced_step_fixup for details. */
1076 struct displaced_step_request
1079 struct displaced_step_request
*next
;
1082 /* Per-inferior displaced stepping state. */
1083 struct displaced_step_inferior_state
1085 /* Pointer to next in linked list. */
1086 struct displaced_step_inferior_state
*next
;
1088 /* The process this displaced step state refers to. */
1091 /* A queue of pending displaced stepping requests. One entry per
1092 thread that needs to do a displaced step. */
1093 struct displaced_step_request
*step_request_queue
;
1095 /* If this is not null_ptid, this is the thread carrying out a
1096 displaced single-step in process PID. This thread's state will
1097 require fixing up once it has completed its step. */
1100 /* The architecture the thread had when we stepped it. */
1101 struct gdbarch
*step_gdbarch
;
1103 /* The closure provided gdbarch_displaced_step_copy_insn, to be used
1104 for post-step cleanup. */
1105 struct displaced_step_closure
*step_closure
;
1107 /* The address of the original instruction, and the copy we
1109 CORE_ADDR step_original
, step_copy
;
1111 /* Saved contents of copy area. */
1112 gdb_byte
*step_saved_copy
;
1115 /* The list of states of processes involved in displaced stepping
1117 static struct displaced_step_inferior_state
*displaced_step_inferior_states
;
1119 /* Get the displaced stepping state of process PID. */
1121 static struct displaced_step_inferior_state
*
1122 get_displaced_stepping_state (int pid
)
1124 struct displaced_step_inferior_state
*state
;
1126 for (state
= displaced_step_inferior_states
;
1128 state
= state
->next
)
1129 if (state
->pid
== pid
)
1135 /* Add a new displaced stepping state for process PID to the displaced
1136 stepping state list, or return a pointer to an already existing
1137 entry, if it already exists. Never returns NULL. */
1139 static struct displaced_step_inferior_state
*
1140 add_displaced_stepping_state (int pid
)
1142 struct displaced_step_inferior_state
*state
;
1144 for (state
= displaced_step_inferior_states
;
1146 state
= state
->next
)
1147 if (state
->pid
== pid
)
1150 state
= xcalloc (1, sizeof (*state
));
1152 state
->next
= displaced_step_inferior_states
;
1153 displaced_step_inferior_states
= state
;
1158 /* If inferior is in displaced stepping, and ADDR equals to starting address
1159 of copy area, return corresponding displaced_step_closure. Otherwise,
1162 struct displaced_step_closure
*
1163 get_displaced_step_closure_by_addr (CORE_ADDR addr
)
1165 struct displaced_step_inferior_state
*displaced
1166 = get_displaced_stepping_state (ptid_get_pid (inferior_ptid
));
1168 /* If checking the mode of displaced instruction in copy area. */
1169 if (displaced
&& !ptid_equal (displaced
->step_ptid
, null_ptid
)
1170 && (displaced
->step_copy
== addr
))
1171 return displaced
->step_closure
;
1176 /* Remove the displaced stepping state of process PID. */
1179 remove_displaced_stepping_state (int pid
)
1181 struct displaced_step_inferior_state
*it
, **prev_next_p
;
1183 gdb_assert (pid
!= 0);
1185 it
= displaced_step_inferior_states
;
1186 prev_next_p
= &displaced_step_inferior_states
;
1191 *prev_next_p
= it
->next
;
1196 prev_next_p
= &it
->next
;
1202 infrun_inferior_exit (struct inferior
*inf
)
1204 remove_displaced_stepping_state (inf
->pid
);
1207 /* If ON, and the architecture supports it, GDB will use displaced
1208 stepping to step over breakpoints. If OFF, or if the architecture
1209 doesn't support it, GDB will instead use the traditional
1210 hold-and-step approach. If AUTO (which is the default), GDB will
1211 decide which technique to use to step over breakpoints depending on
1212 which of all-stop or non-stop mode is active --- displaced stepping
1213 in non-stop mode; hold-and-step in all-stop mode. */
1215 static enum auto_boolean can_use_displaced_stepping
= AUTO_BOOLEAN_AUTO
;
1218 show_can_use_displaced_stepping (struct ui_file
*file
, int from_tty
,
1219 struct cmd_list_element
*c
,
1222 if (can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
)
1223 fprintf_filtered (file
,
1224 _("Debugger's willingness to use displaced stepping "
1225 "to step over breakpoints is %s (currently %s).\n"),
1226 value
, non_stop
? "on" : "off");
1228 fprintf_filtered (file
,
1229 _("Debugger's willingness to use displaced stepping "
1230 "to step over breakpoints is %s.\n"), value
);
1233 /* Return non-zero if displaced stepping can/should be used to step
1234 over breakpoints. */
1237 use_displaced_stepping (struct gdbarch
*gdbarch
)
1239 return (((can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
&& non_stop
)
1240 || can_use_displaced_stepping
== AUTO_BOOLEAN_TRUE
)
1241 && gdbarch_displaced_step_copy_insn_p (gdbarch
)
1242 && !RECORD_IS_USED
);
1245 /* Clean out any stray displaced stepping state. */
1247 displaced_step_clear (struct displaced_step_inferior_state
*displaced
)
1249 /* Indicate that there is no cleanup pending. */
1250 displaced
->step_ptid
= null_ptid
;
1252 if (displaced
->step_closure
)
1254 gdbarch_displaced_step_free_closure (displaced
->step_gdbarch
,
1255 displaced
->step_closure
);
1256 displaced
->step_closure
= NULL
;
1261 displaced_step_clear_cleanup (void *arg
)
1263 struct displaced_step_inferior_state
*state
= arg
;
1265 displaced_step_clear (state
);
1268 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */
1270 displaced_step_dump_bytes (struct ui_file
*file
,
1271 const gdb_byte
*buf
,
1276 for (i
= 0; i
< len
; i
++)
1277 fprintf_unfiltered (file
, "%02x ", buf
[i
]);
1278 fputs_unfiltered ("\n", file
);
1281 /* Prepare to single-step, using displaced stepping.
1283 Note that we cannot use displaced stepping when we have a signal to
1284 deliver. If we have a signal to deliver and an instruction to step
1285 over, then after the step, there will be no indication from the
1286 target whether the thread entered a signal handler or ignored the
1287 signal and stepped over the instruction successfully --- both cases
1288 result in a simple SIGTRAP. In the first case we mustn't do a
1289 fixup, and in the second case we must --- but we can't tell which.
1290 Comments in the code for 'random signals' in handle_inferior_event
1291 explain how we handle this case instead.
1293 Returns 1 if preparing was successful -- this thread is going to be
1294 stepped now; or 0 if displaced stepping this thread got queued. */
1296 displaced_step_prepare (ptid_t ptid
)
1298 struct cleanup
*old_cleanups
, *ignore_cleanups
;
1299 struct thread_info
*tp
= find_thread_ptid (ptid
);
1300 struct regcache
*regcache
= get_thread_regcache (ptid
);
1301 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1302 CORE_ADDR original
, copy
;
1304 struct displaced_step_closure
*closure
;
1305 struct displaced_step_inferior_state
*displaced
;
1308 /* We should never reach this function if the architecture does not
1309 support displaced stepping. */
1310 gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch
));
1312 /* Disable range stepping while executing in the scratch pad. We
1313 want a single-step even if executing the displaced instruction in
1314 the scratch buffer lands within the stepping range (e.g., a
1316 tp
->control
.may_range_step
= 0;
1318 /* We have to displaced step one thread at a time, as we only have
1319 access to a single scratch space per inferior. */
1321 displaced
= add_displaced_stepping_state (ptid_get_pid (ptid
));
1323 if (!ptid_equal (displaced
->step_ptid
, null_ptid
))
1325 /* Already waiting for a displaced step to finish. Defer this
1326 request and place in queue. */
1327 struct displaced_step_request
*req
, *new_req
;
1329 if (debug_displaced
)
1330 fprintf_unfiltered (gdb_stdlog
,
1331 "displaced: defering step of %s\n",
1332 target_pid_to_str (ptid
));
1334 new_req
= xmalloc (sizeof (*new_req
));
1335 new_req
->ptid
= ptid
;
1336 new_req
->next
= NULL
;
1338 if (displaced
->step_request_queue
)
1340 for (req
= displaced
->step_request_queue
;
1344 req
->next
= new_req
;
1347 displaced
->step_request_queue
= new_req
;
1353 if (debug_displaced
)
1354 fprintf_unfiltered (gdb_stdlog
,
1355 "displaced: stepping %s now\n",
1356 target_pid_to_str (ptid
));
1359 displaced_step_clear (displaced
);
1361 old_cleanups
= save_inferior_ptid ();
1362 inferior_ptid
= ptid
;
1364 original
= regcache_read_pc (regcache
);
1366 copy
= gdbarch_displaced_step_location (gdbarch
);
1367 len
= gdbarch_max_insn_length (gdbarch
);
1369 /* Save the original contents of the copy area. */
1370 displaced
->step_saved_copy
= xmalloc (len
);
1371 ignore_cleanups
= make_cleanup (free_current_contents
,
1372 &displaced
->step_saved_copy
);
1373 status
= target_read_memory (copy
, displaced
->step_saved_copy
, len
);
1375 throw_error (MEMORY_ERROR
,
1376 _("Error accessing memory address %s (%s) for "
1377 "displaced-stepping scratch space."),
1378 paddress (gdbarch
, copy
), safe_strerror (status
));
1379 if (debug_displaced
)
1381 fprintf_unfiltered (gdb_stdlog
, "displaced: saved %s: ",
1382 paddress (gdbarch
, copy
));
1383 displaced_step_dump_bytes (gdb_stdlog
,
1384 displaced
->step_saved_copy
,
1388 closure
= gdbarch_displaced_step_copy_insn (gdbarch
,
1389 original
, copy
, regcache
);
1391 /* We don't support the fully-simulated case at present. */
1392 gdb_assert (closure
);
1394 /* Save the information we need to fix things up if the step
1396 displaced
->step_ptid
= ptid
;
1397 displaced
->step_gdbarch
= gdbarch
;
1398 displaced
->step_closure
= closure
;
1399 displaced
->step_original
= original
;
1400 displaced
->step_copy
= copy
;
1402 make_cleanup (displaced_step_clear_cleanup
, displaced
);
1404 /* Resume execution at the copy. */
1405 regcache_write_pc (regcache
, copy
);
1407 discard_cleanups (ignore_cleanups
);
1409 do_cleanups (old_cleanups
);
1411 if (debug_displaced
)
1412 fprintf_unfiltered (gdb_stdlog
, "displaced: displaced pc to %s\n",
1413 paddress (gdbarch
, copy
));
1419 write_memory_ptid (ptid_t ptid
, CORE_ADDR memaddr
,
1420 const gdb_byte
*myaddr
, int len
)
1422 struct cleanup
*ptid_cleanup
= save_inferior_ptid ();
1424 inferior_ptid
= ptid
;
1425 write_memory (memaddr
, myaddr
, len
);
1426 do_cleanups (ptid_cleanup
);
1429 /* Restore the contents of the copy area for thread PTID. */
1432 displaced_step_restore (struct displaced_step_inferior_state
*displaced
,
1435 ULONGEST len
= gdbarch_max_insn_length (displaced
->step_gdbarch
);
1437 write_memory_ptid (ptid
, displaced
->step_copy
,
1438 displaced
->step_saved_copy
, len
);
1439 if (debug_displaced
)
1440 fprintf_unfiltered (gdb_stdlog
, "displaced: restored %s %s\n",
1441 target_pid_to_str (ptid
),
1442 paddress (displaced
->step_gdbarch
,
1443 displaced
->step_copy
));
1447 displaced_step_fixup (ptid_t event_ptid
, enum gdb_signal signal
)
1449 struct cleanup
*old_cleanups
;
1450 struct displaced_step_inferior_state
*displaced
1451 = get_displaced_stepping_state (ptid_get_pid (event_ptid
));
1453 /* Was any thread of this process doing a displaced step? */
1454 if (displaced
== NULL
)
1457 /* Was this event for the pid we displaced? */
1458 if (ptid_equal (displaced
->step_ptid
, null_ptid
)
1459 || ! ptid_equal (displaced
->step_ptid
, event_ptid
))
1462 old_cleanups
= make_cleanup (displaced_step_clear_cleanup
, displaced
);
1464 displaced_step_restore (displaced
, displaced
->step_ptid
);
1466 /* Did the instruction complete successfully? */
1467 if (signal
== GDB_SIGNAL_TRAP
)
1469 /* Fix up the resulting state. */
1470 gdbarch_displaced_step_fixup (displaced
->step_gdbarch
,
1471 displaced
->step_closure
,
1472 displaced
->step_original
,
1473 displaced
->step_copy
,
1474 get_thread_regcache (displaced
->step_ptid
));
1478 /* Since the instruction didn't complete, all we can do is
1480 struct regcache
*regcache
= get_thread_regcache (event_ptid
);
1481 CORE_ADDR pc
= regcache_read_pc (regcache
);
1483 pc
= displaced
->step_original
+ (pc
- displaced
->step_copy
);
1484 regcache_write_pc (regcache
, pc
);
1487 do_cleanups (old_cleanups
);
1489 displaced
->step_ptid
= null_ptid
;
1491 /* Are there any pending displaced stepping requests? If so, run
1492 one now. Leave the state object around, since we're likely to
1493 need it again soon. */
1494 while (displaced
->step_request_queue
)
1496 struct displaced_step_request
*head
;
1498 struct regcache
*regcache
;
1499 struct gdbarch
*gdbarch
;
1500 CORE_ADDR actual_pc
;
1501 struct address_space
*aspace
;
1503 head
= displaced
->step_request_queue
;
1505 displaced
->step_request_queue
= head
->next
;
1508 context_switch (ptid
);
1510 regcache
= get_thread_regcache (ptid
);
1511 actual_pc
= regcache_read_pc (regcache
);
1512 aspace
= get_regcache_aspace (regcache
);
1514 if (breakpoint_here_p (aspace
, actual_pc
))
1516 if (debug_displaced
)
1517 fprintf_unfiltered (gdb_stdlog
,
1518 "displaced: stepping queued %s now\n",
1519 target_pid_to_str (ptid
));
1521 displaced_step_prepare (ptid
);
1523 gdbarch
= get_regcache_arch (regcache
);
1525 if (debug_displaced
)
1527 CORE_ADDR actual_pc
= regcache_read_pc (regcache
);
1530 fprintf_unfiltered (gdb_stdlog
, "displaced: run %s: ",
1531 paddress (gdbarch
, actual_pc
));
1532 read_memory (actual_pc
, buf
, sizeof (buf
));
1533 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
1536 if (gdbarch_displaced_step_hw_singlestep (gdbarch
,
1537 displaced
->step_closure
))
1538 target_resume (ptid
, 1, GDB_SIGNAL_0
);
1540 target_resume (ptid
, 0, GDB_SIGNAL_0
);
1542 /* Done, we're stepping a thread. */
1548 struct thread_info
*tp
= inferior_thread ();
1550 /* The breakpoint we were sitting under has since been
1552 tp
->control
.trap_expected
= 0;
1554 /* Go back to what we were trying to do. */
1555 step
= currently_stepping (tp
);
1557 if (debug_displaced
)
1558 fprintf_unfiltered (gdb_stdlog
,
1559 "displaced: breakpoint is gone: %s, step(%d)\n",
1560 target_pid_to_str (tp
->ptid
), step
);
1562 target_resume (ptid
, step
, GDB_SIGNAL_0
);
1563 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
1565 /* This request was discarded. See if there's any other
1566 thread waiting for its turn. */
1571 /* Update global variables holding ptids to hold NEW_PTID if they were
1572 holding OLD_PTID. */
1574 infrun_thread_ptid_changed (ptid_t old_ptid
, ptid_t new_ptid
)
1576 struct displaced_step_request
*it
;
1577 struct displaced_step_inferior_state
*displaced
;
1579 if (ptid_equal (inferior_ptid
, old_ptid
))
1580 inferior_ptid
= new_ptid
;
1582 if (ptid_equal (singlestep_ptid
, old_ptid
))
1583 singlestep_ptid
= new_ptid
;
1585 if (ptid_equal (deferred_step_ptid
, old_ptid
))
1586 deferred_step_ptid
= new_ptid
;
1588 for (displaced
= displaced_step_inferior_states
;
1590 displaced
= displaced
->next
)
1592 if (ptid_equal (displaced
->step_ptid
, old_ptid
))
1593 displaced
->step_ptid
= new_ptid
;
1595 for (it
= displaced
->step_request_queue
; it
; it
= it
->next
)
1596 if (ptid_equal (it
->ptid
, old_ptid
))
1597 it
->ptid
= new_ptid
;
1604 /* Things to clean up if we QUIT out of resume (). */
1606 resume_cleanups (void *ignore
)
1611 static const char schedlock_off
[] = "off";
1612 static const char schedlock_on
[] = "on";
1613 static const char schedlock_step
[] = "step";
1614 static const char *const scheduler_enums
[] = {
1620 static const char *scheduler_mode
= schedlock_off
;
1622 show_scheduler_mode (struct ui_file
*file
, int from_tty
,
1623 struct cmd_list_element
*c
, const char *value
)
1625 fprintf_filtered (file
,
1626 _("Mode for locking scheduler "
1627 "during execution is \"%s\".\n"),
1632 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
1634 if (!target_can_lock_scheduler
)
1636 scheduler_mode
= schedlock_off
;
1637 error (_("Target '%s' cannot support this command."), target_shortname
);
1641 /* True if execution commands resume all threads of all processes by
1642 default; otherwise, resume only threads of the current inferior
1644 int sched_multi
= 0;
1646 /* Try to setup for software single stepping over the specified location.
1647 Return 1 if target_resume() should use hardware single step.
1649 GDBARCH the current gdbarch.
1650 PC the location to step over. */
1653 maybe_software_singlestep (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
1657 if (execution_direction
== EXEC_FORWARD
1658 && gdbarch_software_single_step_p (gdbarch
)
1659 && gdbarch_software_single_step (gdbarch
, get_current_frame ()))
1662 /* Do not pull these breakpoints until after a `wait' in
1663 `wait_for_inferior'. */
1664 singlestep_breakpoints_inserted_p
= 1;
1665 singlestep_ptid
= inferior_ptid
;
1671 /* Return a ptid representing the set of threads that we will proceed,
1672 in the perspective of the user/frontend. We may actually resume
1673 fewer threads at first, e.g., if a thread is stopped at a
1674 breakpoint that needs stepping-off, but that should not be visible
1675 to the user/frontend, and neither should the frontend/user be
1676 allowed to proceed any of the threads that happen to be stopped for
1677 internal run control handling, if a previous command wanted them
1681 user_visible_resume_ptid (int step
)
1683 /* By default, resume all threads of all processes. */
1684 ptid_t resume_ptid
= RESUME_ALL
;
1686 /* Maybe resume only all threads of the current process. */
1687 if (!sched_multi
&& target_supports_multi_process ())
1689 resume_ptid
= pid_to_ptid (ptid_get_pid (inferior_ptid
));
1692 /* Maybe resume a single thread after all. */
1695 /* With non-stop mode on, threads are always handled
1697 resume_ptid
= inferior_ptid
;
1699 else if ((scheduler_mode
== schedlock_on
)
1700 || (scheduler_mode
== schedlock_step
1701 && (step
|| singlestep_breakpoints_inserted_p
)))
1703 /* User-settable 'scheduler' mode requires solo thread resume. */
1704 resume_ptid
= inferior_ptid
;
1710 /* Resume the inferior, but allow a QUIT. This is useful if the user
1711 wants to interrupt some lengthy single-stepping operation
1712 (for child processes, the SIGINT goes to the inferior, and so
1713 we get a SIGINT random_signal, but for remote debugging and perhaps
1714 other targets, that's not true).
1716 STEP nonzero if we should step (zero to continue instead).
1717 SIG is the signal to give the inferior (zero for none). */
1719 resume (int step
, enum gdb_signal sig
)
1721 int should_resume
= 1;
1722 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
1723 struct regcache
*regcache
= get_current_regcache ();
1724 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1725 struct thread_info
*tp
= inferior_thread ();
1726 CORE_ADDR pc
= regcache_read_pc (regcache
);
1727 struct address_space
*aspace
= get_regcache_aspace (regcache
);
1731 if (current_inferior ()->waiting_for_vfork_done
)
1733 /* Don't try to single-step a vfork parent that is waiting for
1734 the child to get out of the shared memory region (by exec'ing
1735 or exiting). This is particularly important on software
1736 single-step archs, as the child process would trip on the
1737 software single step breakpoint inserted for the parent
1738 process. Since the parent will not actually execute any
1739 instruction until the child is out of the shared region (such
1740 are vfork's semantics), it is safe to simply continue it.
1741 Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for
1742 the parent, and tell it to `keep_going', which automatically
1743 re-sets it stepping. */
1745 fprintf_unfiltered (gdb_stdlog
,
1746 "infrun: resume : clear step\n");
1751 fprintf_unfiltered (gdb_stdlog
,
1752 "infrun: resume (step=%d, signal=%d), "
1753 "trap_expected=%d, current thread [%s] at %s\n",
1754 step
, sig
, tp
->control
.trap_expected
,
1755 target_pid_to_str (inferior_ptid
),
1756 paddress (gdbarch
, pc
));
1758 /* Normally, by the time we reach `resume', the breakpoints are either
1759 removed or inserted, as appropriate. The exception is if we're sitting
1760 at a permanent breakpoint; we need to step over it, but permanent
1761 breakpoints can't be removed. So we have to test for it here. */
1762 if (breakpoint_here_p (aspace
, pc
) == permanent_breakpoint_here
)
1764 if (gdbarch_skip_permanent_breakpoint_p (gdbarch
))
1765 gdbarch_skip_permanent_breakpoint (gdbarch
, regcache
);
1768 The program is stopped at a permanent breakpoint, but GDB does not know\n\
1769 how to step past a permanent breakpoint on this architecture. Try using\n\
1770 a command like `return' or `jump' to continue execution."));
1773 /* If we have a breakpoint to step over, make sure to do a single
1774 step only. Same if we have software watchpoints. */
1775 if (tp
->control
.trap_expected
|| bpstat_should_step ())
1776 tp
->control
.may_range_step
= 0;
1778 /* If enabled, step over breakpoints by executing a copy of the
1779 instruction at a different address.
1781 We can't use displaced stepping when we have a signal to deliver;
1782 the comments for displaced_step_prepare explain why. The
1783 comments in the handle_inferior event for dealing with 'random
1784 signals' explain what we do instead.
1786 We can't use displaced stepping when we are waiting for vfork_done
1787 event, displaced stepping breaks the vfork child similarly as single
1788 step software breakpoint. */
1789 if (use_displaced_stepping (gdbarch
)
1790 && (tp
->control
.trap_expected
1791 || (step
&& gdbarch_software_single_step_p (gdbarch
)))
1792 && sig
== GDB_SIGNAL_0
1793 && !current_inferior ()->waiting_for_vfork_done
)
1795 struct displaced_step_inferior_state
*displaced
;
1797 if (!displaced_step_prepare (inferior_ptid
))
1799 /* Got placed in displaced stepping queue. Will be resumed
1800 later when all the currently queued displaced stepping
1801 requests finish. The thread is not executing at this point,
1802 and the call to set_executing will be made later. But we
1803 need to call set_running here, since from frontend point of view,
1804 the thread is running. */
1805 set_running (inferior_ptid
, 1);
1806 discard_cleanups (old_cleanups
);
1810 /* Update pc to reflect the new address from which we will execute
1811 instructions due to displaced stepping. */
1812 pc
= regcache_read_pc (get_thread_regcache (inferior_ptid
));
1814 displaced
= get_displaced_stepping_state (ptid_get_pid (inferior_ptid
));
1815 step
= gdbarch_displaced_step_hw_singlestep (gdbarch
,
1816 displaced
->step_closure
);
1819 /* Do we need to do it the hard way, w/temp breakpoints? */
1821 step
= maybe_software_singlestep (gdbarch
, pc
);
1823 /* Currently, our software single-step implementation leads to different
1824 results than hardware single-stepping in one situation: when stepping
1825 into delivering a signal which has an associated signal handler,
1826 hardware single-step will stop at the first instruction of the handler,
1827 while software single-step will simply skip execution of the handler.
1829 For now, this difference in behavior is accepted since there is no
1830 easy way to actually implement single-stepping into a signal handler
1831 without kernel support.
1833 However, there is one scenario where this difference leads to follow-on
1834 problems: if we're stepping off a breakpoint by removing all breakpoints
1835 and then single-stepping. In this case, the software single-step
1836 behavior means that even if there is a *breakpoint* in the signal
1837 handler, GDB still would not stop.
1839 Fortunately, we can at least fix this particular issue. We detect
1840 here the case where we are about to deliver a signal while software
1841 single-stepping with breakpoints removed. In this situation, we
1842 revert the decisions to remove all breakpoints and insert single-
1843 step breakpoints, and instead we install a step-resume breakpoint
1844 at the current address, deliver the signal without stepping, and
1845 once we arrive back at the step-resume breakpoint, actually step
1846 over the breakpoint we originally wanted to step over. */
1847 if (singlestep_breakpoints_inserted_p
1848 && tp
->control
.trap_expected
&& sig
!= GDB_SIGNAL_0
)
1850 /* If we have nested signals or a pending signal is delivered
1851 immediately after a handler returns, might might already have
1852 a step-resume breakpoint set on the earlier handler. We cannot
1853 set another step-resume breakpoint; just continue on until the
1854 original breakpoint is hit. */
1855 if (tp
->control
.step_resume_breakpoint
== NULL
)
1857 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
1858 tp
->step_after_step_resume_breakpoint
= 1;
1861 remove_single_step_breakpoints ();
1862 singlestep_breakpoints_inserted_p
= 0;
1864 insert_breakpoints ();
1865 tp
->control
.trap_expected
= 0;
1872 /* If STEP is set, it's a request to use hardware stepping
1873 facilities. But in that case, we should never
1874 use singlestep breakpoint. */
1875 gdb_assert (!(singlestep_breakpoints_inserted_p
&& step
));
1877 /* Decide the set of threads to ask the target to resume. Start
1878 by assuming everything will be resumed, than narrow the set
1879 by applying increasingly restricting conditions. */
1880 resume_ptid
= user_visible_resume_ptid (step
);
1882 /* Maybe resume a single thread after all. */
1883 if (singlestep_breakpoints_inserted_p
1884 && stepping_past_singlestep_breakpoint
)
1886 /* The situation here is as follows. In thread T1 we wanted to
1887 single-step. Lacking hardware single-stepping we've
1888 set breakpoint at the PC of the next instruction -- call it
1889 P. After resuming, we've hit that breakpoint in thread T2.
1890 Now we've removed original breakpoint, inserted breakpoint
1891 at P+1, and try to step to advance T2 past breakpoint.
1892 We need to step only T2, as if T1 is allowed to freely run,
1893 it can run past P, and if other threads are allowed to run,
1894 they can hit breakpoint at P+1, and nested hits of single-step
1895 breakpoints is not something we'd want -- that's complicated
1896 to support, and has no value. */
1897 resume_ptid
= inferior_ptid
;
1899 else if ((step
|| singlestep_breakpoints_inserted_p
)
1900 && tp
->control
.trap_expected
)
1902 /* We're allowing a thread to run past a breakpoint it has
1903 hit, by single-stepping the thread with the breakpoint
1904 removed. In which case, we need to single-step only this
1905 thread, and keep others stopped, as they can miss this
1906 breakpoint if allowed to run.
1908 The current code actually removes all breakpoints when
1909 doing this, not just the one being stepped over, so if we
1910 let other threads run, we can actually miss any
1911 breakpoint, not just the one at PC. */
1912 resume_ptid
= inferior_ptid
;
1915 if (gdbarch_cannot_step_breakpoint (gdbarch
))
1917 /* Most targets can step a breakpoint instruction, thus
1918 executing it normally. But if this one cannot, just
1919 continue and we will hit it anyway. */
1920 if (step
&& breakpoint_inserted_here_p (aspace
, pc
))
1925 && use_displaced_stepping (gdbarch
)
1926 && tp
->control
.trap_expected
)
1928 struct regcache
*resume_regcache
= get_thread_regcache (resume_ptid
);
1929 struct gdbarch
*resume_gdbarch
= get_regcache_arch (resume_regcache
);
1930 CORE_ADDR actual_pc
= regcache_read_pc (resume_regcache
);
1933 fprintf_unfiltered (gdb_stdlog
, "displaced: run %s: ",
1934 paddress (resume_gdbarch
, actual_pc
));
1935 read_memory (actual_pc
, buf
, sizeof (buf
));
1936 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
1939 if (tp
->control
.may_range_step
)
1941 /* If we're resuming a thread with the PC out of the step
1942 range, then we're doing some nested/finer run control
1943 operation, like stepping the thread out of the dynamic
1944 linker or the displaced stepping scratch pad. We
1945 shouldn't have allowed a range step then. */
1946 gdb_assert (pc_in_thread_step_range (pc
, tp
));
1949 /* Install inferior's terminal modes. */
1950 target_terminal_inferior ();
1952 /* Avoid confusing the next resume, if the next stop/resume
1953 happens to apply to another thread. */
1954 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
1956 /* Advise target which signals may be handled silently. If we have
1957 removed breakpoints because we are stepping over one (which can
1958 happen only if we are not using displaced stepping), we need to
1959 receive all signals to avoid accidentally skipping a breakpoint
1960 during execution of a signal handler. */
1961 if ((step
|| singlestep_breakpoints_inserted_p
)
1962 && tp
->control
.trap_expected
1963 && !use_displaced_stepping (gdbarch
))
1964 target_pass_signals (0, NULL
);
1966 target_pass_signals ((int) GDB_SIGNAL_LAST
, signal_pass
);
1968 target_resume (resume_ptid
, step
, sig
);
1971 discard_cleanups (old_cleanups
);
1976 /* Clear out all variables saying what to do when inferior is continued.
1977 First do this, then set the ones you want, then call `proceed'. */
1980 clear_proceed_status_thread (struct thread_info
*tp
)
1983 fprintf_unfiltered (gdb_stdlog
,
1984 "infrun: clear_proceed_status_thread (%s)\n",
1985 target_pid_to_str (tp
->ptid
));
1987 tp
->control
.trap_expected
= 0;
1988 tp
->control
.step_range_start
= 0;
1989 tp
->control
.step_range_end
= 0;
1990 tp
->control
.may_range_step
= 0;
1991 tp
->control
.step_frame_id
= null_frame_id
;
1992 tp
->control
.step_stack_frame_id
= null_frame_id
;
1993 tp
->control
.step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
1994 tp
->stop_requested
= 0;
1996 tp
->control
.stop_step
= 0;
1998 tp
->control
.proceed_to_finish
= 0;
2000 /* Discard any remaining commands or status from previous stop. */
2001 bpstat_clear (&tp
->control
.stop_bpstat
);
2005 clear_proceed_status_callback (struct thread_info
*tp
, void *data
)
2007 if (is_exited (tp
->ptid
))
2010 clear_proceed_status_thread (tp
);
2015 clear_proceed_status (void)
2019 /* In all-stop mode, delete the per-thread status of all
2020 threads, even if inferior_ptid is null_ptid, there may be
2021 threads on the list. E.g., we may be launching a new
2022 process, while selecting the executable. */
2023 iterate_over_threads (clear_proceed_status_callback
, NULL
);
2026 if (!ptid_equal (inferior_ptid
, null_ptid
))
2028 struct inferior
*inferior
;
2032 /* If in non-stop mode, only delete the per-thread status of
2033 the current thread. */
2034 clear_proceed_status_thread (inferior_thread ());
2037 inferior
= current_inferior ();
2038 inferior
->control
.stop_soon
= NO_STOP_QUIETLY
;
2041 stop_after_trap
= 0;
2043 observer_notify_about_to_proceed ();
2047 regcache_xfree (stop_registers
);
2048 stop_registers
= NULL
;
2052 /* Check the current thread against the thread that reported the most recent
2053 event. If a step-over is required return TRUE and set the current thread
2054 to the old thread. Otherwise return FALSE.
2056 This should be suitable for any targets that support threads. */
2059 prepare_to_proceed (int step
)
2062 struct target_waitstatus wait_status
;
2063 int schedlock_enabled
;
2065 /* With non-stop mode on, threads are always handled individually. */
2066 gdb_assert (! non_stop
);
2068 /* Get the last target status returned by target_wait(). */
2069 get_last_target_status (&wait_ptid
, &wait_status
);
2071 /* Make sure we were stopped at a breakpoint. */
2072 if (wait_status
.kind
!= TARGET_WAITKIND_STOPPED
2073 || (wait_status
.value
.sig
!= GDB_SIGNAL_TRAP
2074 && wait_status
.value
.sig
!= GDB_SIGNAL_ILL
2075 && wait_status
.value
.sig
!= GDB_SIGNAL_SEGV
2076 && wait_status
.value
.sig
!= GDB_SIGNAL_EMT
))
2081 schedlock_enabled
= (scheduler_mode
== schedlock_on
2082 || (scheduler_mode
== schedlock_step
2085 /* Don't switch over to WAIT_PTID if scheduler locking is on. */
2086 if (schedlock_enabled
)
2089 /* Don't switch over if we're about to resume some other process
2090 other than WAIT_PTID's, and schedule-multiple is off. */
2092 && ptid_get_pid (wait_ptid
) != ptid_get_pid (inferior_ptid
))
2095 /* Switched over from WAIT_PID. */
2096 if (!ptid_equal (wait_ptid
, minus_one_ptid
)
2097 && !ptid_equal (inferior_ptid
, wait_ptid
))
2099 struct regcache
*regcache
= get_thread_regcache (wait_ptid
);
2101 if (breakpoint_here_p (get_regcache_aspace (regcache
),
2102 regcache_read_pc (regcache
)))
2104 /* If stepping, remember current thread to switch back to. */
2106 deferred_step_ptid
= inferior_ptid
;
2108 /* Switch back to WAIT_PID thread. */
2109 switch_to_thread (wait_ptid
);
2112 fprintf_unfiltered (gdb_stdlog
,
2113 "infrun: prepare_to_proceed (step=%d), "
2114 "switched to [%s]\n",
2115 step
, target_pid_to_str (inferior_ptid
));
2117 /* We return 1 to indicate that there is a breakpoint here,
2118 so we need to step over it before continuing to avoid
2119 hitting it straight away. */
2127 /* Basic routine for continuing the program in various fashions.
2129 ADDR is the address to resume at, or -1 for resume where stopped.
2130 SIGGNAL is the signal to give it, or 0 for none,
2131 or -1 for act according to how it stopped.
2132 STEP is nonzero if should trap after one instruction.
2133 -1 means return after that and print nothing.
2134 You should probably set various step_... variables
2135 before calling here, if you are stepping.
2137 You should call clear_proceed_status before calling proceed. */
2140 proceed (CORE_ADDR addr
, enum gdb_signal siggnal
, int step
)
2142 struct regcache
*regcache
;
2143 struct gdbarch
*gdbarch
;
2144 struct thread_info
*tp
;
2146 struct address_space
*aspace
;
2147 /* GDB may force the inferior to step due to various reasons. */
2150 /* If we're stopped at a fork/vfork, follow the branch set by the
2151 "set follow-fork-mode" command; otherwise, we'll just proceed
2152 resuming the current thread. */
2153 if (!follow_fork ())
2155 /* The target for some reason decided not to resume. */
2157 if (target_can_async_p ())
2158 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
2162 /* We'll update this if & when we switch to a new thread. */
2163 previous_inferior_ptid
= inferior_ptid
;
2165 regcache
= get_current_regcache ();
2166 gdbarch
= get_regcache_arch (regcache
);
2167 aspace
= get_regcache_aspace (regcache
);
2168 pc
= regcache_read_pc (regcache
);
2171 step_start_function
= find_pc_function (pc
);
2173 stop_after_trap
= 1;
2175 if (addr
== (CORE_ADDR
) -1)
2177 if (pc
== stop_pc
&& breakpoint_here_p (aspace
, pc
)
2178 && execution_direction
!= EXEC_REVERSE
)
2179 /* There is a breakpoint at the address we will resume at,
2180 step one instruction before inserting breakpoints so that
2181 we do not stop right away (and report a second hit at this
2184 Note, we don't do this in reverse, because we won't
2185 actually be executing the breakpoint insn anyway.
2186 We'll be (un-)executing the previous instruction. */
2189 else if (gdbarch_single_step_through_delay_p (gdbarch
)
2190 && gdbarch_single_step_through_delay (gdbarch
,
2191 get_current_frame ()))
2192 /* We stepped onto an instruction that needs to be stepped
2193 again before re-inserting the breakpoint, do so. */
2198 regcache_write_pc (regcache
, addr
);
2202 fprintf_unfiltered (gdb_stdlog
,
2203 "infrun: proceed (addr=%s, signal=%d, step=%d)\n",
2204 paddress (gdbarch
, addr
), siggnal
, step
);
2207 /* In non-stop, each thread is handled individually. The context
2208 must already be set to the right thread here. */
2212 /* In a multi-threaded task we may select another thread and
2213 then continue or step.
2215 But if the old thread was stopped at a breakpoint, it will
2216 immediately cause another breakpoint stop without any
2217 execution (i.e. it will report a breakpoint hit incorrectly).
2218 So we must step over it first.
2220 prepare_to_proceed checks the current thread against the
2221 thread that reported the most recent event. If a step-over
2222 is required it returns TRUE and sets the current thread to
2224 if (prepare_to_proceed (step
))
2228 /* prepare_to_proceed may change the current thread. */
2229 tp
= inferior_thread ();
2233 tp
->control
.trap_expected
= 1;
2234 /* If displaced stepping is enabled, we can step over the
2235 breakpoint without hitting it, so leave all breakpoints
2236 inserted. Otherwise we need to disable all breakpoints, step
2237 one instruction, and then re-add them when that step is
2239 if (!use_displaced_stepping (gdbarch
))
2240 remove_breakpoints ();
2243 /* We can insert breakpoints if we're not trying to step over one,
2244 or if we are stepping over one but we're using displaced stepping
2246 if (! tp
->control
.trap_expected
|| use_displaced_stepping (gdbarch
))
2247 insert_breakpoints ();
2251 /* Pass the last stop signal to the thread we're resuming,
2252 irrespective of whether the current thread is the thread that
2253 got the last event or not. This was historically GDB's
2254 behaviour before keeping a stop_signal per thread. */
2256 struct thread_info
*last_thread
;
2258 struct target_waitstatus last_status
;
2260 get_last_target_status (&last_ptid
, &last_status
);
2261 if (!ptid_equal (inferior_ptid
, last_ptid
)
2262 && !ptid_equal (last_ptid
, null_ptid
)
2263 && !ptid_equal (last_ptid
, minus_one_ptid
))
2265 last_thread
= find_thread_ptid (last_ptid
);
2268 tp
->suspend
.stop_signal
= last_thread
->suspend
.stop_signal
;
2269 last_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2274 if (siggnal
!= GDB_SIGNAL_DEFAULT
)
2275 tp
->suspend
.stop_signal
= siggnal
;
2276 /* If this signal should not be seen by program,
2277 give it zero. Used for debugging signals. */
2278 else if (!signal_program
[tp
->suspend
.stop_signal
])
2279 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2281 annotate_starting ();
2283 /* Make sure that output from GDB appears before output from the
2285 gdb_flush (gdb_stdout
);
2287 /* Refresh prev_pc value just prior to resuming. This used to be
2288 done in stop_stepping, however, setting prev_pc there did not handle
2289 scenarios such as inferior function calls or returning from
2290 a function via the return command. In those cases, the prev_pc
2291 value was not set properly for subsequent commands. The prev_pc value
2292 is used to initialize the starting line number in the ecs. With an
2293 invalid value, the gdb next command ends up stopping at the position
2294 represented by the next line table entry past our start position.
2295 On platforms that generate one line table entry per line, this
2296 is not a problem. However, on the ia64, the compiler generates
2297 extraneous line table entries that do not increase the line number.
2298 When we issue the gdb next command on the ia64 after an inferior call
2299 or a return command, we often end up a few instructions forward, still
2300 within the original line we started.
2302 An attempt was made to refresh the prev_pc at the same time the
2303 execution_control_state is initialized (for instance, just before
2304 waiting for an inferior event). But this approach did not work
2305 because of platforms that use ptrace, where the pc register cannot
2306 be read unless the inferior is stopped. At that point, we are not
2307 guaranteed the inferior is stopped and so the regcache_read_pc() call
2308 can fail. Setting the prev_pc value here ensures the value is updated
2309 correctly when the inferior is stopped. */
2310 tp
->prev_pc
= regcache_read_pc (get_current_regcache ());
2312 /* Fill in with reasonable starting values. */
2313 init_thread_stepping_state (tp
);
2315 /* Reset to normal state. */
2316 init_infwait_state ();
2318 /* Resume inferior. */
2319 resume (force_step
|| step
|| bpstat_should_step (),
2320 tp
->suspend
.stop_signal
);
2322 /* Wait for it to stop (if not standalone)
2323 and in any case decode why it stopped, and act accordingly. */
2324 /* Do this only if we are not using the event loop, or if the target
2325 does not support asynchronous execution. */
2326 if (!target_can_async_p ())
2328 wait_for_inferior ();
2334 /* Start remote-debugging of a machine over a serial link. */
2337 start_remote (int from_tty
)
2339 struct inferior
*inferior
;
2341 inferior
= current_inferior ();
2342 inferior
->control
.stop_soon
= STOP_QUIETLY_REMOTE
;
2344 /* Always go on waiting for the target, regardless of the mode. */
2345 /* FIXME: cagney/1999-09-23: At present it isn't possible to
2346 indicate to wait_for_inferior that a target should timeout if
2347 nothing is returned (instead of just blocking). Because of this,
2348 targets expecting an immediate response need to, internally, set
2349 things up so that the target_wait() is forced to eventually
2351 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
2352 differentiate to its caller what the state of the target is after
2353 the initial open has been performed. Here we're assuming that
2354 the target has stopped. It should be possible to eventually have
2355 target_open() return to the caller an indication that the target
2356 is currently running and GDB state should be set to the same as
2357 for an async run. */
2358 wait_for_inferior ();
2360 /* Now that the inferior has stopped, do any bookkeeping like
2361 loading shared libraries. We want to do this before normal_stop,
2362 so that the displayed frame is up to date. */
2363 post_create_inferior (¤t_target
, from_tty
);
2368 /* Initialize static vars when a new inferior begins. */
2371 init_wait_for_inferior (void)
2373 /* These are meaningless until the first time through wait_for_inferior. */
2375 breakpoint_init_inferior (inf_starting
);
2377 clear_proceed_status ();
2379 stepping_past_singlestep_breakpoint
= 0;
2380 deferred_step_ptid
= null_ptid
;
2382 target_last_wait_ptid
= minus_one_ptid
;
2384 previous_inferior_ptid
= inferior_ptid
;
2385 init_infwait_state ();
2387 /* Discard any skipped inlined frames. */
2388 clear_inline_frame_state (minus_one_ptid
);
2392 /* This enum encodes possible reasons for doing a target_wait, so that
2393 wfi can call target_wait in one place. (Ultimately the call will be
2394 moved out of the infinite loop entirely.) */
2398 infwait_normal_state
,
2399 infwait_thread_hop_state
,
2400 infwait_step_watch_state
,
2401 infwait_nonstep_watch_state
2404 /* The PTID we'll do a target_wait on.*/
2407 /* Current inferior wait state. */
2408 static enum infwait_states infwait_state
;
2410 /* Data to be passed around while handling an event. This data is
2411 discarded between events. */
2412 struct execution_control_state
2415 /* The thread that got the event, if this was a thread event; NULL
2417 struct thread_info
*event_thread
;
2419 struct target_waitstatus ws
;
2421 int stop_func_filled_in
;
2422 CORE_ADDR stop_func_start
;
2423 CORE_ADDR stop_func_end
;
2424 const char *stop_func_name
;
2428 static void handle_inferior_event (struct execution_control_state
*ecs
);
2430 static void handle_step_into_function (struct gdbarch
*gdbarch
,
2431 struct execution_control_state
*ecs
);
2432 static void handle_step_into_function_backward (struct gdbarch
*gdbarch
,
2433 struct execution_control_state
*ecs
);
2434 static void check_exception_resume (struct execution_control_state
*,
2435 struct frame_info
*);
2437 static void stop_stepping (struct execution_control_state
*ecs
);
2438 static void prepare_to_wait (struct execution_control_state
*ecs
);
2439 static void keep_going (struct execution_control_state
*ecs
);
2441 /* Callback for iterate over threads. If the thread is stopped, but
2442 the user/frontend doesn't know about that yet, go through
2443 normal_stop, as if the thread had just stopped now. ARG points at
2444 a ptid. If PTID is MINUS_ONE_PTID, applies to all threads. If
2445 ptid_is_pid(PTID) is true, applies to all threads of the process
2446 pointed at by PTID. Otherwise, apply only to the thread pointed by
2450 infrun_thread_stop_requested_callback (struct thread_info
*info
, void *arg
)
2452 ptid_t ptid
= * (ptid_t
*) arg
;
2454 if ((ptid_equal (info
->ptid
, ptid
)
2455 || ptid_equal (minus_one_ptid
, ptid
)
2456 || (ptid_is_pid (ptid
)
2457 && ptid_get_pid (ptid
) == ptid_get_pid (info
->ptid
)))
2458 && is_running (info
->ptid
)
2459 && !is_executing (info
->ptid
))
2461 struct cleanup
*old_chain
;
2462 struct execution_control_state ecss
;
2463 struct execution_control_state
*ecs
= &ecss
;
2465 memset (ecs
, 0, sizeof (*ecs
));
2467 old_chain
= make_cleanup_restore_current_thread ();
2469 /* Go through handle_inferior_event/normal_stop, so we always
2470 have consistent output as if the stop event had been
2472 ecs
->ptid
= info
->ptid
;
2473 ecs
->event_thread
= find_thread_ptid (info
->ptid
);
2474 ecs
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
2475 ecs
->ws
.value
.sig
= GDB_SIGNAL_0
;
2477 handle_inferior_event (ecs
);
2479 if (!ecs
->wait_some_more
)
2481 struct thread_info
*tp
;
2485 /* Finish off the continuations. */
2486 tp
= inferior_thread ();
2487 do_all_intermediate_continuations_thread (tp
, 1);
2488 do_all_continuations_thread (tp
, 1);
2491 do_cleanups (old_chain
);
2497 /* This function is attached as a "thread_stop_requested" observer.
2498 Cleanup local state that assumed the PTID was to be resumed, and
2499 report the stop to the frontend. */
2502 infrun_thread_stop_requested (ptid_t ptid
)
2504 struct displaced_step_inferior_state
*displaced
;
2506 /* PTID was requested to stop. Remove it from the displaced
2507 stepping queue, so we don't try to resume it automatically. */
2509 for (displaced
= displaced_step_inferior_states
;
2511 displaced
= displaced
->next
)
2513 struct displaced_step_request
*it
, **prev_next_p
;
2515 it
= displaced
->step_request_queue
;
2516 prev_next_p
= &displaced
->step_request_queue
;
2519 if (ptid_match (it
->ptid
, ptid
))
2521 *prev_next_p
= it
->next
;
2527 prev_next_p
= &it
->next
;
2534 iterate_over_threads (infrun_thread_stop_requested_callback
, &ptid
);
2538 infrun_thread_thread_exit (struct thread_info
*tp
, int silent
)
2540 if (ptid_equal (target_last_wait_ptid
, tp
->ptid
))
2541 nullify_last_target_wait_ptid ();
2544 /* Callback for iterate_over_threads. */
2547 delete_step_resume_breakpoint_callback (struct thread_info
*info
, void *data
)
2549 if (is_exited (info
->ptid
))
2552 delete_step_resume_breakpoint (info
);
2553 delete_exception_resume_breakpoint (info
);
2557 /* In all-stop, delete the step resume breakpoint of any thread that
2558 had one. In non-stop, delete the step resume breakpoint of the
2559 thread that just stopped. */
2562 delete_step_thread_step_resume_breakpoint (void)
2564 if (!target_has_execution
2565 || ptid_equal (inferior_ptid
, null_ptid
))
2566 /* If the inferior has exited, we have already deleted the step
2567 resume breakpoints out of GDB's lists. */
2572 /* If in non-stop mode, only delete the step-resume or
2573 longjmp-resume breakpoint of the thread that just stopped
2575 struct thread_info
*tp
= inferior_thread ();
2577 delete_step_resume_breakpoint (tp
);
2578 delete_exception_resume_breakpoint (tp
);
2581 /* In all-stop mode, delete all step-resume and longjmp-resume
2582 breakpoints of any thread that had them. */
2583 iterate_over_threads (delete_step_resume_breakpoint_callback
, NULL
);
2586 /* A cleanup wrapper. */
2589 delete_step_thread_step_resume_breakpoint_cleanup (void *arg
)
2591 delete_step_thread_step_resume_breakpoint ();
2594 /* Pretty print the results of target_wait, for debugging purposes. */
2597 print_target_wait_results (ptid_t waiton_ptid
, ptid_t result_ptid
,
2598 const struct target_waitstatus
*ws
)
2600 char *status_string
= target_waitstatus_to_string (ws
);
2601 struct ui_file
*tmp_stream
= mem_fileopen ();
2604 /* The text is split over several lines because it was getting too long.
2605 Call fprintf_unfiltered (gdb_stdlog) once so that the text is still
2606 output as a unit; we want only one timestamp printed if debug_timestamp
2609 fprintf_unfiltered (tmp_stream
,
2610 "infrun: target_wait (%d", PIDGET (waiton_ptid
));
2611 if (PIDGET (waiton_ptid
) != -1)
2612 fprintf_unfiltered (tmp_stream
,
2613 " [%s]", target_pid_to_str (waiton_ptid
));
2614 fprintf_unfiltered (tmp_stream
, ", status) =\n");
2615 fprintf_unfiltered (tmp_stream
,
2616 "infrun: %d [%s],\n",
2617 PIDGET (result_ptid
), target_pid_to_str (result_ptid
));
2618 fprintf_unfiltered (tmp_stream
,
2622 text
= ui_file_xstrdup (tmp_stream
, NULL
);
2624 /* This uses %s in part to handle %'s in the text, but also to avoid
2625 a gcc error: the format attribute requires a string literal. */
2626 fprintf_unfiltered (gdb_stdlog
, "%s", text
);
2628 xfree (status_string
);
2630 ui_file_delete (tmp_stream
);
2633 /* Prepare and stabilize the inferior for detaching it. E.g.,
2634 detaching while a thread is displaced stepping is a recipe for
2635 crashing it, as nothing would readjust the PC out of the scratch
2639 prepare_for_detach (void)
2641 struct inferior
*inf
= current_inferior ();
2642 ptid_t pid_ptid
= pid_to_ptid (inf
->pid
);
2643 struct cleanup
*old_chain_1
;
2644 struct displaced_step_inferior_state
*displaced
;
2646 displaced
= get_displaced_stepping_state (inf
->pid
);
2648 /* Is any thread of this process displaced stepping? If not,
2649 there's nothing else to do. */
2650 if (displaced
== NULL
|| ptid_equal (displaced
->step_ptid
, null_ptid
))
2654 fprintf_unfiltered (gdb_stdlog
,
2655 "displaced-stepping in-process while detaching");
2657 old_chain_1
= make_cleanup_restore_integer (&inf
->detaching
);
2660 while (!ptid_equal (displaced
->step_ptid
, null_ptid
))
2662 struct cleanup
*old_chain_2
;
2663 struct execution_control_state ecss
;
2664 struct execution_control_state
*ecs
;
2667 memset (ecs
, 0, sizeof (*ecs
));
2669 overlay_cache_invalid
= 1;
2671 if (deprecated_target_wait_hook
)
2672 ecs
->ptid
= deprecated_target_wait_hook (pid_ptid
, &ecs
->ws
, 0);
2674 ecs
->ptid
= target_wait (pid_ptid
, &ecs
->ws
, 0);
2677 print_target_wait_results (pid_ptid
, ecs
->ptid
, &ecs
->ws
);
2679 /* If an error happens while handling the event, propagate GDB's
2680 knowledge of the executing state to the frontend/user running
2682 old_chain_2
= make_cleanup (finish_thread_state_cleanup
,
2685 /* Now figure out what to do with the result of the result. */
2686 handle_inferior_event (ecs
);
2688 /* No error, don't finish the state yet. */
2689 discard_cleanups (old_chain_2
);
2691 /* Breakpoints and watchpoints are not installed on the target
2692 at this point, and signals are passed directly to the
2693 inferior, so this must mean the process is gone. */
2694 if (!ecs
->wait_some_more
)
2696 discard_cleanups (old_chain_1
);
2697 error (_("Program exited while detaching"));
2701 discard_cleanups (old_chain_1
);
2704 /* Wait for control to return from inferior to debugger.
2706 If inferior gets a signal, we may decide to start it up again
2707 instead of returning. That is why there is a loop in this function.
2708 When this function actually returns it means the inferior
2709 should be left stopped and GDB should read more commands. */
2712 wait_for_inferior (void)
2714 struct cleanup
*old_cleanups
;
2718 (gdb_stdlog
, "infrun: wait_for_inferior ()\n");
2721 make_cleanup (delete_step_thread_step_resume_breakpoint_cleanup
, NULL
);
2725 struct execution_control_state ecss
;
2726 struct execution_control_state
*ecs
= &ecss
;
2727 struct cleanup
*old_chain
;
2729 memset (ecs
, 0, sizeof (*ecs
));
2731 overlay_cache_invalid
= 1;
2733 if (deprecated_target_wait_hook
)
2734 ecs
->ptid
= deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
, 0);
2736 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
, 0);
2739 print_target_wait_results (waiton_ptid
, ecs
->ptid
, &ecs
->ws
);
2741 /* If an error happens while handling the event, propagate GDB's
2742 knowledge of the executing state to the frontend/user running
2744 old_chain
= make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
2746 /* Now figure out what to do with the result of the result. */
2747 handle_inferior_event (ecs
);
2749 /* No error, don't finish the state yet. */
2750 discard_cleanups (old_chain
);
2752 if (!ecs
->wait_some_more
)
2756 do_cleanups (old_cleanups
);
2759 /* Asynchronous version of wait_for_inferior. It is called by the
2760 event loop whenever a change of state is detected on the file
2761 descriptor corresponding to the target. It can be called more than
2762 once to complete a single execution command. In such cases we need
2763 to keep the state in a global variable ECSS. If it is the last time
2764 that this function is called for a single execution command, then
2765 report to the user that the inferior has stopped, and do the
2766 necessary cleanups. */
2769 fetch_inferior_event (void *client_data
)
2771 struct execution_control_state ecss
;
2772 struct execution_control_state
*ecs
= &ecss
;
2773 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
2774 struct cleanup
*ts_old_chain
;
2775 int was_sync
= sync_execution
;
2778 memset (ecs
, 0, sizeof (*ecs
));
2780 /* We're handling a live event, so make sure we're doing live
2781 debugging. If we're looking at traceframes while the target is
2782 running, we're going to need to get back to that mode after
2783 handling the event. */
2786 make_cleanup_restore_current_traceframe ();
2787 set_current_traceframe (-1);
2791 /* In non-stop mode, the user/frontend should not notice a thread
2792 switch due to internal events. Make sure we reverse to the
2793 user selected thread and frame after handling the event and
2794 running any breakpoint commands. */
2795 make_cleanup_restore_current_thread ();
2797 overlay_cache_invalid
= 1;
2799 make_cleanup_restore_integer (&execution_direction
);
2800 execution_direction
= target_execution_direction ();
2802 if (deprecated_target_wait_hook
)
2804 deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
, TARGET_WNOHANG
);
2806 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
, TARGET_WNOHANG
);
2809 print_target_wait_results (waiton_ptid
, ecs
->ptid
, &ecs
->ws
);
2811 /* If an error happens while handling the event, propagate GDB's
2812 knowledge of the executing state to the frontend/user running
2815 ts_old_chain
= make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
2817 ts_old_chain
= make_cleanup (finish_thread_state_cleanup
, &ecs
->ptid
);
2819 /* Get executed before make_cleanup_restore_current_thread above to apply
2820 still for the thread which has thrown the exception. */
2821 make_bpstat_clear_actions_cleanup ();
2823 /* Now figure out what to do with the result of the result. */
2824 handle_inferior_event (ecs
);
2826 if (!ecs
->wait_some_more
)
2828 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ecs
->ptid
));
2830 delete_step_thread_step_resume_breakpoint ();
2832 /* We may not find an inferior if this was a process exit. */
2833 if (inf
== NULL
|| inf
->control
.stop_soon
== NO_STOP_QUIETLY
)
2836 if (target_has_execution
2837 && ecs
->ws
.kind
!= TARGET_WAITKIND_NO_RESUMED
2838 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
2839 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
2840 && ecs
->event_thread
->step_multi
2841 && ecs
->event_thread
->control
.stop_step
)
2842 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
2845 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
2850 /* No error, don't finish the thread states yet. */
2851 discard_cleanups (ts_old_chain
);
2853 /* Revert thread and frame. */
2854 do_cleanups (old_chain
);
2856 /* If the inferior was in sync execution mode, and now isn't,
2857 restore the prompt (a synchronous execution command has finished,
2858 and we're ready for input). */
2859 if (interpreter_async
&& was_sync
&& !sync_execution
)
2860 display_gdb_prompt (0);
2864 && exec_done_display_p
2865 && (ptid_equal (inferior_ptid
, null_ptid
)
2866 || !is_running (inferior_ptid
)))
2867 printf_unfiltered (_("completed.\n"));
2870 /* Record the frame and location we're currently stepping through. */
2872 set_step_info (struct frame_info
*frame
, struct symtab_and_line sal
)
2874 struct thread_info
*tp
= inferior_thread ();
2876 tp
->control
.step_frame_id
= get_frame_id (frame
);
2877 tp
->control
.step_stack_frame_id
= get_stack_frame_id (frame
);
2879 tp
->current_symtab
= sal
.symtab
;
2880 tp
->current_line
= sal
.line
;
2883 /* Clear context switchable stepping state. */
2886 init_thread_stepping_state (struct thread_info
*tss
)
2888 tss
->stepping_over_breakpoint
= 0;
2889 tss
->step_after_step_resume_breakpoint
= 0;
2892 /* Return the cached copy of the last pid/waitstatus returned by
2893 target_wait()/deprecated_target_wait_hook(). The data is actually
2894 cached by handle_inferior_event(), which gets called immediately
2895 after target_wait()/deprecated_target_wait_hook(). */
2898 get_last_target_status (ptid_t
*ptidp
, struct target_waitstatus
*status
)
2900 *ptidp
= target_last_wait_ptid
;
2901 *status
= target_last_waitstatus
;
2905 nullify_last_target_wait_ptid (void)
2907 target_last_wait_ptid
= minus_one_ptid
;
2910 /* Switch thread contexts. */
2913 context_switch (ptid_t ptid
)
2915 if (debug_infrun
&& !ptid_equal (ptid
, inferior_ptid
))
2917 fprintf_unfiltered (gdb_stdlog
, "infrun: Switching context from %s ",
2918 target_pid_to_str (inferior_ptid
));
2919 fprintf_unfiltered (gdb_stdlog
, "to %s\n",
2920 target_pid_to_str (ptid
));
2923 switch_to_thread (ptid
);
2927 adjust_pc_after_break (struct execution_control_state
*ecs
)
2929 struct regcache
*regcache
;
2930 struct gdbarch
*gdbarch
;
2931 struct address_space
*aspace
;
2932 CORE_ADDR breakpoint_pc
;
2934 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
2935 we aren't, just return.
2937 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
2938 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
2939 implemented by software breakpoints should be handled through the normal
2942 NOTE drow/2004-01-31: On some targets, breakpoints may generate
2943 different signals (SIGILL or SIGEMT for instance), but it is less
2944 clear where the PC is pointing afterwards. It may not match
2945 gdbarch_decr_pc_after_break. I don't know any specific target that
2946 generates these signals at breakpoints (the code has been in GDB since at
2947 least 1992) so I can not guess how to handle them here.
2949 In earlier versions of GDB, a target with
2950 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
2951 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
2952 target with both of these set in GDB history, and it seems unlikely to be
2953 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
2955 if (ecs
->ws
.kind
!= TARGET_WAITKIND_STOPPED
)
2958 if (ecs
->ws
.value
.sig
!= GDB_SIGNAL_TRAP
)
2961 /* In reverse execution, when a breakpoint is hit, the instruction
2962 under it has already been de-executed. The reported PC always
2963 points at the breakpoint address, so adjusting it further would
2964 be wrong. E.g., consider this case on a decr_pc_after_break == 1
2967 B1 0x08000000 : INSN1
2968 B2 0x08000001 : INSN2
2970 PC -> 0x08000003 : INSN4
2972 Say you're stopped at 0x08000003 as above. Reverse continuing
2973 from that point should hit B2 as below. Reading the PC when the
2974 SIGTRAP is reported should read 0x08000001 and INSN2 should have
2975 been de-executed already.
2977 B1 0x08000000 : INSN1
2978 B2 PC -> 0x08000001 : INSN2
2982 We can't apply the same logic as for forward execution, because
2983 we would wrongly adjust the PC to 0x08000000, since there's a
2984 breakpoint at PC - 1. We'd then report a hit on B1, although
2985 INSN1 hadn't been de-executed yet. Doing nothing is the correct
2987 if (execution_direction
== EXEC_REVERSE
)
2990 /* If this target does not decrement the PC after breakpoints, then
2991 we have nothing to do. */
2992 regcache
= get_thread_regcache (ecs
->ptid
);
2993 gdbarch
= get_regcache_arch (regcache
);
2994 if (gdbarch_decr_pc_after_break (gdbarch
) == 0)
2997 aspace
= get_regcache_aspace (regcache
);
2999 /* Find the location where (if we've hit a breakpoint) the
3000 breakpoint would be. */
3001 breakpoint_pc
= regcache_read_pc (regcache
)
3002 - gdbarch_decr_pc_after_break (gdbarch
);
3004 /* Check whether there actually is a software breakpoint inserted at
3007 If in non-stop mode, a race condition is possible where we've
3008 removed a breakpoint, but stop events for that breakpoint were
3009 already queued and arrive later. To suppress those spurious
3010 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
3011 and retire them after a number of stop events are reported. */
3012 if (software_breakpoint_inserted_here_p (aspace
, breakpoint_pc
)
3013 || (non_stop
&& moribund_breakpoint_here_p (aspace
, breakpoint_pc
)))
3015 struct cleanup
*old_cleanups
= make_cleanup (null_cleanup
, NULL
);
3018 record_full_gdb_operation_disable_set ();
3020 /* When using hardware single-step, a SIGTRAP is reported for both
3021 a completed single-step and a software breakpoint. Need to
3022 differentiate between the two, as the latter needs adjusting
3023 but the former does not.
3025 The SIGTRAP can be due to a completed hardware single-step only if
3026 - we didn't insert software single-step breakpoints
3027 - the thread to be examined is still the current thread
3028 - this thread is currently being stepped
3030 If any of these events did not occur, we must have stopped due
3031 to hitting a software breakpoint, and have to back up to the
3034 As a special case, we could have hardware single-stepped a
3035 software breakpoint. In this case (prev_pc == breakpoint_pc),
3036 we also need to back up to the breakpoint address. */
3038 if (singlestep_breakpoints_inserted_p
3039 || !ptid_equal (ecs
->ptid
, inferior_ptid
)
3040 || !currently_stepping (ecs
->event_thread
)
3041 || ecs
->event_thread
->prev_pc
== breakpoint_pc
)
3042 regcache_write_pc (regcache
, breakpoint_pc
);
3044 do_cleanups (old_cleanups
);
3049 init_infwait_state (void)
3051 waiton_ptid
= pid_to_ptid (-1);
3052 infwait_state
= infwait_normal_state
;
3056 stepped_in_from (struct frame_info
*frame
, struct frame_id step_frame_id
)
3058 for (frame
= get_prev_frame (frame
);
3060 frame
= get_prev_frame (frame
))
3062 if (frame_id_eq (get_frame_id (frame
), step_frame_id
))
3064 if (get_frame_type (frame
) != INLINE_FRAME
)
3071 /* Auxiliary function that handles syscall entry/return events.
3072 It returns 1 if the inferior should keep going (and GDB
3073 should ignore the event), or 0 if the event deserves to be
3077 handle_syscall_event (struct execution_control_state
*ecs
)
3079 struct regcache
*regcache
;
3082 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3083 context_switch (ecs
->ptid
);
3085 regcache
= get_thread_regcache (ecs
->ptid
);
3086 syscall_number
= ecs
->ws
.value
.syscall_number
;
3087 stop_pc
= regcache_read_pc (regcache
);
3089 if (catch_syscall_enabled () > 0
3090 && catching_syscall_number (syscall_number
) > 0)
3092 enum bpstat_signal_value sval
;
3095 fprintf_unfiltered (gdb_stdlog
, "infrun: syscall number = '%d'\n",
3098 ecs
->event_thread
->control
.stop_bpstat
3099 = bpstat_stop_status (get_regcache_aspace (regcache
),
3100 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3102 sval
= bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
3104 ecs
->random_signal
= sval
== BPSTAT_SIGNAL_NO
;
3106 if (!ecs
->random_signal
)
3108 /* Catchpoint hit. */
3109 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_TRAP
;
3114 /* If no catchpoint triggered for this, then keep going. */
3115 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3120 /* Clear the supplied execution_control_state's stop_func_* fields. */
3123 clear_stop_func (struct execution_control_state
*ecs
)
3125 ecs
->stop_func_filled_in
= 0;
3126 ecs
->stop_func_start
= 0;
3127 ecs
->stop_func_end
= 0;
3128 ecs
->stop_func_name
= NULL
;
3131 /* Lazily fill in the execution_control_state's stop_func_* fields. */
3134 fill_in_stop_func (struct gdbarch
*gdbarch
,
3135 struct execution_control_state
*ecs
)
3137 if (!ecs
->stop_func_filled_in
)
3139 /* Don't care about return value; stop_func_start and stop_func_name
3140 will both be 0 if it doesn't work. */
3141 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
3142 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
3143 ecs
->stop_func_start
3144 += gdbarch_deprecated_function_start_offset (gdbarch
);
3146 ecs
->stop_func_filled_in
= 1;
3150 /* Given an execution control state that has been freshly filled in
3151 by an event from the inferior, figure out what it means and take
3152 appropriate action. */
3155 handle_inferior_event (struct execution_control_state
*ecs
)
3157 struct frame_info
*frame
;
3158 struct gdbarch
*gdbarch
;
3159 int stopped_by_watchpoint
;
3160 int stepped_after_stopped_by_watchpoint
= 0;
3161 struct symtab_and_line stop_pc_sal
;
3162 enum stop_kind stop_soon
;
3164 if (ecs
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
3166 /* We had an event in the inferior, but we are not interested in
3167 handling it at this level. The lower layers have already
3168 done what needs to be done, if anything.
3170 One of the possible circumstances for this is when the
3171 inferior produces output for the console. The inferior has
3172 not stopped, and we are ignoring the event. Another possible
3173 circumstance is any event which the lower level knows will be
3174 reported multiple times without an intervening resume. */
3176 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_IGNORE\n");
3177 prepare_to_wait (ecs
);
3181 if (ecs
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
3182 && target_can_async_p () && !sync_execution
)
3184 /* There were no unwaited-for children left in the target, but,
3185 we're not synchronously waiting for events either. Just
3186 ignore. Otherwise, if we were running a synchronous
3187 execution command, we need to cancel it and give the user
3188 back the terminal. */
3190 fprintf_unfiltered (gdb_stdlog
,
3191 "infrun: TARGET_WAITKIND_NO_RESUMED (ignoring)\n");
3192 prepare_to_wait (ecs
);
3196 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
3197 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
3198 && ecs
->ws
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
3200 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ecs
->ptid
));
3203 stop_soon
= inf
->control
.stop_soon
;
3206 stop_soon
= NO_STOP_QUIETLY
;
3208 /* Cache the last pid/waitstatus. */
3209 target_last_wait_ptid
= ecs
->ptid
;
3210 target_last_waitstatus
= ecs
->ws
;
3212 /* Always clear state belonging to the previous time we stopped. */
3213 stop_stack_dummy
= STOP_NONE
;
3215 if (ecs
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
)
3217 /* No unwaited-for children left. IOW, all resumed children
3220 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_NO_RESUMED\n");
3222 stop_print_frame
= 0;
3223 stop_stepping (ecs
);
3227 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
3228 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
)
3230 ecs
->event_thread
= find_thread_ptid (ecs
->ptid
);
3231 /* If it's a new thread, add it to the thread database. */
3232 if (ecs
->event_thread
== NULL
)
3233 ecs
->event_thread
= add_thread (ecs
->ptid
);
3235 /* Disable range stepping. If the next step request could use a
3236 range, this will be end up re-enabled then. */
3237 ecs
->event_thread
->control
.may_range_step
= 0;
3240 /* Dependent on valid ECS->EVENT_THREAD. */
3241 adjust_pc_after_break (ecs
);
3243 /* Dependent on the current PC value modified by adjust_pc_after_break. */
3244 reinit_frame_cache ();
3246 breakpoint_retire_moribund ();
3248 /* First, distinguish signals caused by the debugger from signals
3249 that have to do with the program's own actions. Note that
3250 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
3251 on the operating system version. Here we detect when a SIGILL or
3252 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
3253 something similar for SIGSEGV, since a SIGSEGV will be generated
3254 when we're trying to execute a breakpoint instruction on a
3255 non-executable stack. This happens for call dummy breakpoints
3256 for architectures like SPARC that place call dummies on the
3258 if (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
3259 && (ecs
->ws
.value
.sig
== GDB_SIGNAL_ILL
3260 || ecs
->ws
.value
.sig
== GDB_SIGNAL_SEGV
3261 || ecs
->ws
.value
.sig
== GDB_SIGNAL_EMT
))
3263 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3265 if (breakpoint_inserted_here_p (get_regcache_aspace (regcache
),
3266 regcache_read_pc (regcache
)))
3269 fprintf_unfiltered (gdb_stdlog
,
3270 "infrun: Treating signal as SIGTRAP\n");
3271 ecs
->ws
.value
.sig
= GDB_SIGNAL_TRAP
;
3275 /* Mark the non-executing threads accordingly. In all-stop, all
3276 threads of all processes are stopped when we get any event
3277 reported. In non-stop mode, only the event thread stops. If
3278 we're handling a process exit in non-stop mode, there's nothing
3279 to do, as threads of the dead process are gone, and threads of
3280 any other process were left running. */
3282 set_executing (minus_one_ptid
, 0);
3283 else if (ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
3284 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
)
3285 set_executing (ecs
->ptid
, 0);
3287 switch (infwait_state
)
3289 case infwait_thread_hop_state
:
3291 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_thread_hop_state\n");
3294 case infwait_normal_state
:
3296 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_normal_state\n");
3299 case infwait_step_watch_state
:
3301 fprintf_unfiltered (gdb_stdlog
,
3302 "infrun: infwait_step_watch_state\n");
3304 stepped_after_stopped_by_watchpoint
= 1;
3307 case infwait_nonstep_watch_state
:
3309 fprintf_unfiltered (gdb_stdlog
,
3310 "infrun: infwait_nonstep_watch_state\n");
3311 insert_breakpoints ();
3313 /* FIXME-maybe: is this cleaner than setting a flag? Does it
3314 handle things like signals arriving and other things happening
3315 in combination correctly? */
3316 stepped_after_stopped_by_watchpoint
= 1;
3320 internal_error (__FILE__
, __LINE__
, _("bad switch"));
3323 infwait_state
= infwait_normal_state
;
3324 waiton_ptid
= pid_to_ptid (-1);
3326 switch (ecs
->ws
.kind
)
3328 case TARGET_WAITKIND_LOADED
:
3330 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_LOADED\n");
3331 /* Ignore gracefully during startup of the inferior, as it might
3332 be the shell which has just loaded some objects, otherwise
3333 add the symbols for the newly loaded objects. Also ignore at
3334 the beginning of an attach or remote session; we will query
3335 the full list of libraries once the connection is
3337 if (stop_soon
== NO_STOP_QUIETLY
)
3339 struct regcache
*regcache
;
3340 enum bpstat_signal_value sval
;
3342 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3343 context_switch (ecs
->ptid
);
3344 regcache
= get_thread_regcache (ecs
->ptid
);
3346 handle_solib_event ();
3348 ecs
->event_thread
->control
.stop_bpstat
3349 = bpstat_stop_status (get_regcache_aspace (regcache
),
3350 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3353 = bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
3355 ecs
->random_signal
= sval
== BPSTAT_SIGNAL_NO
;
3357 if (!ecs
->random_signal
)
3359 /* A catchpoint triggered. */
3360 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_TRAP
;
3361 goto process_event_stop_test
;
3364 /* If requested, stop when the dynamic linker notifies
3365 gdb of events. This allows the user to get control
3366 and place breakpoints in initializer routines for
3367 dynamically loaded objects (among other things). */
3368 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3369 if (stop_on_solib_events
)
3371 /* Make sure we print "Stopped due to solib-event" in
3373 stop_print_frame
= 1;
3375 stop_stepping (ecs
);
3380 /* If we are skipping through a shell, or through shared library
3381 loading that we aren't interested in, resume the program. If
3382 we're running the program normally, also resume. But stop if
3383 we're attaching or setting up a remote connection. */
3384 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== NO_STOP_QUIETLY
)
3386 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3387 context_switch (ecs
->ptid
);
3389 /* Loading of shared libraries might have changed breakpoint
3390 addresses. Make sure new breakpoints are inserted. */
3391 if (stop_soon
== NO_STOP_QUIETLY
3392 && !breakpoints_always_inserted_mode ())
3393 insert_breakpoints ();
3394 resume (0, GDB_SIGNAL_0
);
3395 prepare_to_wait (ecs
);
3401 case TARGET_WAITKIND_SPURIOUS
:
3403 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SPURIOUS\n");
3404 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3405 context_switch (ecs
->ptid
);
3406 resume (0, GDB_SIGNAL_0
);
3407 prepare_to_wait (ecs
);
3410 case TARGET_WAITKIND_EXITED
:
3411 case TARGET_WAITKIND_SIGNALLED
:
3414 if (ecs
->ws
.kind
== TARGET_WAITKIND_EXITED
)
3415 fprintf_unfiltered (gdb_stdlog
,
3416 "infrun: TARGET_WAITKIND_EXITED\n");
3418 fprintf_unfiltered (gdb_stdlog
,
3419 "infrun: TARGET_WAITKIND_SIGNALLED\n");
3422 inferior_ptid
= ecs
->ptid
;
3423 set_current_inferior (find_inferior_pid (ptid_get_pid (ecs
->ptid
)));
3424 set_current_program_space (current_inferior ()->pspace
);
3425 handle_vfork_child_exec_or_exit (0);
3426 target_terminal_ours (); /* Must do this before mourn anyway. */
3428 if (ecs
->ws
.kind
== TARGET_WAITKIND_EXITED
)
3430 /* Record the exit code in the convenience variable $_exitcode, so
3431 that the user can inspect this again later. */
3432 set_internalvar_integer (lookup_internalvar ("_exitcode"),
3433 (LONGEST
) ecs
->ws
.value
.integer
);
3435 /* Also record this in the inferior itself. */
3436 current_inferior ()->has_exit_code
= 1;
3437 current_inferior ()->exit_code
= (LONGEST
) ecs
->ws
.value
.integer
;
3439 print_exited_reason (ecs
->ws
.value
.integer
);
3442 print_signal_exited_reason (ecs
->ws
.value
.sig
);
3444 gdb_flush (gdb_stdout
);
3445 target_mourn_inferior ();
3446 singlestep_breakpoints_inserted_p
= 0;
3447 cancel_single_step_breakpoints ();
3448 stop_print_frame
= 0;
3449 stop_stepping (ecs
);
3452 /* The following are the only cases in which we keep going;
3453 the above cases end in a continue or goto. */
3454 case TARGET_WAITKIND_FORKED
:
3455 case TARGET_WAITKIND_VFORKED
:
3458 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
3459 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_FORKED\n");
3461 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_VFORKED\n");
3464 /* Check whether the inferior is displaced stepping. */
3466 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3467 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3468 struct displaced_step_inferior_state
*displaced
3469 = get_displaced_stepping_state (ptid_get_pid (ecs
->ptid
));
3471 /* If checking displaced stepping is supported, and thread
3472 ecs->ptid is displaced stepping. */
3473 if (displaced
&& ptid_equal (displaced
->step_ptid
, ecs
->ptid
))
3475 struct inferior
*parent_inf
3476 = find_inferior_pid (ptid_get_pid (ecs
->ptid
));
3477 struct regcache
*child_regcache
;
3478 CORE_ADDR parent_pc
;
3480 /* GDB has got TARGET_WAITKIND_FORKED or TARGET_WAITKIND_VFORKED,
3481 indicating that the displaced stepping of syscall instruction
3482 has been done. Perform cleanup for parent process here. Note
3483 that this operation also cleans up the child process for vfork,
3484 because their pages are shared. */
3485 displaced_step_fixup (ecs
->ptid
, GDB_SIGNAL_TRAP
);
3487 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
3489 /* Restore scratch pad for child process. */
3490 displaced_step_restore (displaced
, ecs
->ws
.value
.related_pid
);
3493 /* Since the vfork/fork syscall instruction was executed in the scratchpad,
3494 the child's PC is also within the scratchpad. Set the child's PC
3495 to the parent's PC value, which has already been fixed up.
3496 FIXME: we use the parent's aspace here, although we're touching
3497 the child, because the child hasn't been added to the inferior
3498 list yet at this point. */
3501 = get_thread_arch_aspace_regcache (ecs
->ws
.value
.related_pid
,
3503 parent_inf
->aspace
);
3504 /* Read PC value of parent process. */
3505 parent_pc
= regcache_read_pc (regcache
);
3507 if (debug_displaced
)
3508 fprintf_unfiltered (gdb_stdlog
,
3509 "displaced: write child pc from %s to %s\n",
3511 regcache_read_pc (child_regcache
)),
3512 paddress (gdbarch
, parent_pc
));
3514 regcache_write_pc (child_regcache
, parent_pc
);
3518 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3519 context_switch (ecs
->ptid
);
3521 /* Immediately detach breakpoints from the child before there's
3522 any chance of letting the user delete breakpoints from the
3523 breakpoint lists. If we don't do this early, it's easy to
3524 leave left over traps in the child, vis: "break foo; catch
3525 fork; c; <fork>; del; c; <child calls foo>". We only follow
3526 the fork on the last `continue', and by that time the
3527 breakpoint at "foo" is long gone from the breakpoint table.
3528 If we vforked, then we don't need to unpatch here, since both
3529 parent and child are sharing the same memory pages; we'll
3530 need to unpatch at follow/detach time instead to be certain
3531 that new breakpoints added between catchpoint hit time and
3532 vfork follow are detached. */
3533 if (ecs
->ws
.kind
!= TARGET_WAITKIND_VFORKED
)
3535 /* This won't actually modify the breakpoint list, but will
3536 physically remove the breakpoints from the child. */
3537 detach_breakpoints (ecs
->ws
.value
.related_pid
);
3540 if (singlestep_breakpoints_inserted_p
)
3542 /* Pull the single step breakpoints out of the target. */
3543 remove_single_step_breakpoints ();
3544 singlestep_breakpoints_inserted_p
= 0;
3547 /* In case the event is caught by a catchpoint, remember that
3548 the event is to be followed at the next resume of the thread,
3549 and not immediately. */
3550 ecs
->event_thread
->pending_follow
= ecs
->ws
;
3552 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3554 ecs
->event_thread
->control
.stop_bpstat
3555 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3556 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3558 /* Note that we're interested in knowing the bpstat actually
3559 causes a stop, not just if it may explain the signal.
3560 Software watchpoints, for example, always appear in the
3563 = !bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
);
3565 /* If no catchpoint triggered for this, then keep going. */
3566 if (ecs
->random_signal
)
3572 = (follow_fork_mode_string
== follow_fork_mode_child
);
3574 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3576 should_resume
= follow_fork ();
3579 child
= ecs
->ws
.value
.related_pid
;
3581 /* In non-stop mode, also resume the other branch. */
3582 if (non_stop
&& !detach_fork
)
3585 switch_to_thread (parent
);
3587 switch_to_thread (child
);
3589 ecs
->event_thread
= inferior_thread ();
3590 ecs
->ptid
= inferior_ptid
;
3595 switch_to_thread (child
);
3597 switch_to_thread (parent
);
3599 ecs
->event_thread
= inferior_thread ();
3600 ecs
->ptid
= inferior_ptid
;
3605 stop_stepping (ecs
);
3608 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_TRAP
;
3609 goto process_event_stop_test
;
3611 case TARGET_WAITKIND_VFORK_DONE
:
3612 /* Done with the shared memory region. Re-insert breakpoints in
3613 the parent, and keep going. */
3616 fprintf_unfiltered (gdb_stdlog
,
3617 "infrun: TARGET_WAITKIND_VFORK_DONE\n");
3619 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3620 context_switch (ecs
->ptid
);
3622 current_inferior ()->waiting_for_vfork_done
= 0;
3623 current_inferior ()->pspace
->breakpoints_not_allowed
= 0;
3624 /* This also takes care of reinserting breakpoints in the
3625 previously locked inferior. */
3629 case TARGET_WAITKIND_EXECD
:
3631 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_EXECD\n");
3633 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3634 context_switch (ecs
->ptid
);
3636 singlestep_breakpoints_inserted_p
= 0;
3637 cancel_single_step_breakpoints ();
3639 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3641 /* Do whatever is necessary to the parent branch of the vfork. */
3642 handle_vfork_child_exec_or_exit (1);
3644 /* This causes the eventpoints and symbol table to be reset.
3645 Must do this now, before trying to determine whether to
3647 follow_exec (inferior_ptid
, ecs
->ws
.value
.execd_pathname
);
3649 ecs
->event_thread
->control
.stop_bpstat
3650 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3651 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3653 = (bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
3655 == BPSTAT_SIGNAL_NO
);
3657 /* Note that this may be referenced from inside
3658 bpstat_stop_status above, through inferior_has_execd. */
3659 xfree (ecs
->ws
.value
.execd_pathname
);
3660 ecs
->ws
.value
.execd_pathname
= NULL
;
3662 /* If no catchpoint triggered for this, then keep going. */
3663 if (ecs
->random_signal
)
3665 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3669 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_TRAP
;
3670 goto process_event_stop_test
;
3672 /* Be careful not to try to gather much state about a thread
3673 that's in a syscall. It's frequently a losing proposition. */
3674 case TARGET_WAITKIND_SYSCALL_ENTRY
:
3676 fprintf_unfiltered (gdb_stdlog
,
3677 "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
3678 /* Getting the current syscall number. */
3679 if (handle_syscall_event (ecs
) != 0)
3681 goto process_event_stop_test
;
3683 /* Before examining the threads further, step this thread to
3684 get it entirely out of the syscall. (We get notice of the
3685 event when the thread is just on the verge of exiting a
3686 syscall. Stepping one instruction seems to get it back
3688 case TARGET_WAITKIND_SYSCALL_RETURN
:
3690 fprintf_unfiltered (gdb_stdlog
,
3691 "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
3692 if (handle_syscall_event (ecs
) != 0)
3694 goto process_event_stop_test
;
3696 case TARGET_WAITKIND_STOPPED
:
3698 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_STOPPED\n");
3699 ecs
->event_thread
->suspend
.stop_signal
= ecs
->ws
.value
.sig
;
3702 case TARGET_WAITKIND_NO_HISTORY
:
3704 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_NO_HISTORY\n");
3705 /* Reverse execution: target ran out of history info. */
3707 /* Pull the single step breakpoints out of the target. */
3708 if (singlestep_breakpoints_inserted_p
)
3710 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3711 context_switch (ecs
->ptid
);
3712 remove_single_step_breakpoints ();
3713 singlestep_breakpoints_inserted_p
= 0;
3715 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3716 print_no_history_reason ();
3717 stop_stepping (ecs
);
3721 if (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
)
3723 /* Do we need to clean up the state of a thread that has
3724 completed a displaced single-step? (Doing so usually affects
3725 the PC, so do it here, before we set stop_pc.) */
3726 displaced_step_fixup (ecs
->ptid
,
3727 ecs
->event_thread
->suspend
.stop_signal
);
3729 /* If we either finished a single-step or hit a breakpoint, but
3730 the user wanted this thread to be stopped, pretend we got a
3731 SIG0 (generic unsignaled stop). */
3733 if (ecs
->event_thread
->stop_requested
3734 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
3735 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3738 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3742 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3743 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3744 struct cleanup
*old_chain
= save_inferior_ptid ();
3746 inferior_ptid
= ecs
->ptid
;
3748 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_pc = %s\n",
3749 paddress (gdbarch
, stop_pc
));
3750 if (target_stopped_by_watchpoint ())
3754 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped by watchpoint\n");
3756 if (target_stopped_data_address (¤t_target
, &addr
))
3757 fprintf_unfiltered (gdb_stdlog
,
3758 "infrun: stopped data address = %s\n",
3759 paddress (gdbarch
, addr
));
3761 fprintf_unfiltered (gdb_stdlog
,
3762 "infrun: (no data address available)\n");
3765 do_cleanups (old_chain
);
3768 if (stepping_past_singlestep_breakpoint
)
3770 gdb_assert (singlestep_breakpoints_inserted_p
);
3771 gdb_assert (ptid_equal (singlestep_ptid
, ecs
->ptid
));
3772 gdb_assert (!ptid_equal (singlestep_ptid
, saved_singlestep_ptid
));
3774 stepping_past_singlestep_breakpoint
= 0;
3776 /* We've either finished single-stepping past the single-step
3777 breakpoint, or stopped for some other reason. It would be nice if
3778 we could tell, but we can't reliably. */
3779 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
3782 fprintf_unfiltered (gdb_stdlog
,
3783 "infrun: stepping_past_"
3784 "singlestep_breakpoint\n");
3785 /* Pull the single step breakpoints out of the target. */
3786 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3787 context_switch (ecs
->ptid
);
3788 remove_single_step_breakpoints ();
3789 singlestep_breakpoints_inserted_p
= 0;
3791 ecs
->random_signal
= 0;
3792 ecs
->event_thread
->control
.trap_expected
= 0;
3794 context_switch (saved_singlestep_ptid
);
3795 if (deprecated_context_hook
)
3796 deprecated_context_hook (pid_to_thread_id (saved_singlestep_ptid
));
3798 resume (1, GDB_SIGNAL_0
);
3799 prepare_to_wait (ecs
);
3804 if (!ptid_equal (deferred_step_ptid
, null_ptid
))
3806 /* In non-stop mode, there's never a deferred_step_ptid set. */
3807 gdb_assert (!non_stop
);
3809 /* If we stopped for some other reason than single-stepping, ignore
3810 the fact that we were supposed to switch back. */
3811 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
3814 fprintf_unfiltered (gdb_stdlog
,
3815 "infrun: handling deferred step\n");
3817 /* Pull the single step breakpoints out of the target. */
3818 if (singlestep_breakpoints_inserted_p
)
3820 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3821 context_switch (ecs
->ptid
);
3822 remove_single_step_breakpoints ();
3823 singlestep_breakpoints_inserted_p
= 0;
3826 ecs
->event_thread
->control
.trap_expected
= 0;
3828 context_switch (deferred_step_ptid
);
3829 deferred_step_ptid
= null_ptid
;
3830 /* Suppress spurious "Switching to ..." message. */
3831 previous_inferior_ptid
= inferior_ptid
;
3833 resume (1, GDB_SIGNAL_0
);
3834 prepare_to_wait (ecs
);
3838 deferred_step_ptid
= null_ptid
;
3841 /* See if a thread hit a thread-specific breakpoint that was meant for
3842 another thread. If so, then step that thread past the breakpoint,
3845 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
3847 int thread_hop_needed
= 0;
3848 struct address_space
*aspace
=
3849 get_regcache_aspace (get_thread_regcache (ecs
->ptid
));
3851 /* Check if a regular breakpoint has been hit before checking
3852 for a potential single step breakpoint. Otherwise, GDB will
3853 not see this breakpoint hit when stepping onto breakpoints. */
3854 if (regular_breakpoint_inserted_here_p (aspace
, stop_pc
))
3856 ecs
->random_signal
= 0;
3857 if (!breakpoint_thread_match (aspace
, stop_pc
, ecs
->ptid
))
3858 thread_hop_needed
= 1;
3860 else if (singlestep_breakpoints_inserted_p
)
3862 /* We have not context switched yet, so this should be true
3863 no matter which thread hit the singlestep breakpoint. */
3864 gdb_assert (ptid_equal (inferior_ptid
, singlestep_ptid
));
3866 fprintf_unfiltered (gdb_stdlog
, "infrun: software single step "
3868 target_pid_to_str (ecs
->ptid
));
3870 ecs
->random_signal
= 0;
3871 /* The call to in_thread_list is necessary because PTIDs sometimes
3872 change when we go from single-threaded to multi-threaded. If
3873 the singlestep_ptid is still in the list, assume that it is
3874 really different from ecs->ptid. */
3875 if (!ptid_equal (singlestep_ptid
, ecs
->ptid
)
3876 && in_thread_list (singlestep_ptid
))
3878 /* If the PC of the thread we were trying to single-step
3879 has changed, discard this event (which we were going
3880 to ignore anyway), and pretend we saw that thread
3881 trap. This prevents us continuously moving the
3882 single-step breakpoint forward, one instruction at a
3883 time. If the PC has changed, then the thread we were
3884 trying to single-step has trapped or been signalled,
3885 but the event has not been reported to GDB yet.
3887 There might be some cases where this loses signal
3888 information, if a signal has arrived at exactly the
3889 same time that the PC changed, but this is the best
3890 we can do with the information available. Perhaps we
3891 should arrange to report all events for all threads
3892 when they stop, or to re-poll the remote looking for
3893 this particular thread (i.e. temporarily enable
3896 CORE_ADDR new_singlestep_pc
3897 = regcache_read_pc (get_thread_regcache (singlestep_ptid
));
3899 if (new_singlestep_pc
!= singlestep_pc
)
3901 enum gdb_signal stop_signal
;
3904 fprintf_unfiltered (gdb_stdlog
, "infrun: unexpected thread,"
3905 " but expected thread advanced also\n");
3907 /* The current context still belongs to
3908 singlestep_ptid. Don't swap here, since that's
3909 the context we want to use. Just fudge our
3910 state and continue. */
3911 stop_signal
= ecs
->event_thread
->suspend
.stop_signal
;
3912 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3913 ecs
->ptid
= singlestep_ptid
;
3914 ecs
->event_thread
= find_thread_ptid (ecs
->ptid
);
3915 ecs
->event_thread
->suspend
.stop_signal
= stop_signal
;
3916 stop_pc
= new_singlestep_pc
;
3921 fprintf_unfiltered (gdb_stdlog
,
3922 "infrun: unexpected thread\n");
3924 thread_hop_needed
= 1;
3925 stepping_past_singlestep_breakpoint
= 1;
3926 saved_singlestep_ptid
= singlestep_ptid
;
3931 if (thread_hop_needed
)
3933 struct regcache
*thread_regcache
;
3934 int remove_status
= 0;
3937 fprintf_unfiltered (gdb_stdlog
, "infrun: thread_hop_needed\n");
3939 /* Switch context before touching inferior memory, the
3940 previous thread may have exited. */
3941 if (!ptid_equal (inferior_ptid
, ecs
->ptid
))
3942 context_switch (ecs
->ptid
);
3944 /* Saw a breakpoint, but it was hit by the wrong thread.
3947 if (singlestep_breakpoints_inserted_p
)
3949 /* Pull the single step breakpoints out of the target. */
3950 remove_single_step_breakpoints ();
3951 singlestep_breakpoints_inserted_p
= 0;
3954 /* If the arch can displace step, don't remove the
3956 thread_regcache
= get_thread_regcache (ecs
->ptid
);
3957 if (!use_displaced_stepping (get_regcache_arch (thread_regcache
)))
3958 remove_status
= remove_breakpoints ();
3960 /* Did we fail to remove breakpoints? If so, try
3961 to set the PC past the bp. (There's at least
3962 one situation in which we can fail to remove
3963 the bp's: On HP-UX's that use ttrace, we can't
3964 change the address space of a vforking child
3965 process until the child exits (well, okay, not
3966 then either :-) or execs. */
3967 if (remove_status
!= 0)
3968 error (_("Cannot step over breakpoint hit in wrong thread"));
3973 /* Only need to require the next event from this
3974 thread in all-stop mode. */
3975 waiton_ptid
= ecs
->ptid
;
3976 infwait_state
= infwait_thread_hop_state
;
3979 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3984 else if (singlestep_breakpoints_inserted_p
)
3986 ecs
->random_signal
= 0;
3990 ecs
->random_signal
= 1;
3992 /* See if something interesting happened to the non-current thread. If
3993 so, then switch to that thread. */
3994 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3997 fprintf_unfiltered (gdb_stdlog
, "infrun: context switch\n");
3999 context_switch (ecs
->ptid
);
4001 if (deprecated_context_hook
)
4002 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
4005 /* At this point, get hold of the now-current thread's frame. */
4006 frame
= get_current_frame ();
4007 gdbarch
= get_frame_arch (frame
);
4009 if (singlestep_breakpoints_inserted_p
)
4011 /* Pull the single step breakpoints out of the target. */
4012 remove_single_step_breakpoints ();
4013 singlestep_breakpoints_inserted_p
= 0;
4016 if (stepped_after_stopped_by_watchpoint
)
4017 stopped_by_watchpoint
= 0;
4019 stopped_by_watchpoint
= watchpoints_triggered (&ecs
->ws
);
4021 /* If necessary, step over this watchpoint. We'll be back to display
4023 if (stopped_by_watchpoint
4024 && (target_have_steppable_watchpoint
4025 || gdbarch_have_nonsteppable_watchpoint (gdbarch
)))
4027 /* At this point, we are stopped at an instruction which has
4028 attempted to write to a piece of memory under control of
4029 a watchpoint. The instruction hasn't actually executed
4030 yet. If we were to evaluate the watchpoint expression
4031 now, we would get the old value, and therefore no change
4032 would seem to have occurred.
4034 In order to make watchpoints work `right', we really need
4035 to complete the memory write, and then evaluate the
4036 watchpoint expression. We do this by single-stepping the
4039 It may not be necessary to disable the watchpoint to stop over
4040 it. For example, the PA can (with some kernel cooperation)
4041 single step over a watchpoint without disabling the watchpoint.
4043 It is far more common to need to disable a watchpoint to step
4044 the inferior over it. If we have non-steppable watchpoints,
4045 we must disable the current watchpoint; it's simplest to
4046 disable all watchpoints and breakpoints. */
4049 if (!target_have_steppable_watchpoint
)
4051 remove_breakpoints ();
4052 /* See comment in resume why we need to stop bypassing signals
4053 while breakpoints have been removed. */
4054 target_pass_signals (0, NULL
);
4057 hw_step
= maybe_software_singlestep (gdbarch
, stop_pc
);
4058 target_resume (ecs
->ptid
, hw_step
, GDB_SIGNAL_0
);
4059 waiton_ptid
= ecs
->ptid
;
4060 if (target_have_steppable_watchpoint
)
4061 infwait_state
= infwait_step_watch_state
;
4063 infwait_state
= infwait_nonstep_watch_state
;
4064 prepare_to_wait (ecs
);
4068 clear_stop_func (ecs
);
4069 ecs
->event_thread
->stepping_over_breakpoint
= 0;
4070 bpstat_clear (&ecs
->event_thread
->control
.stop_bpstat
);
4071 ecs
->event_thread
->control
.stop_step
= 0;
4072 stop_print_frame
= 1;
4073 ecs
->random_signal
= 0;
4074 stopped_by_random_signal
= 0;
4076 /* Hide inlined functions starting here, unless we just performed stepi or
4077 nexti. After stepi and nexti, always show the innermost frame (not any
4078 inline function call sites). */
4079 if (ecs
->event_thread
->control
.step_range_end
!= 1)
4081 struct address_space
*aspace
=
4082 get_regcache_aspace (get_thread_regcache (ecs
->ptid
));
4084 /* skip_inline_frames is expensive, so we avoid it if we can
4085 determine that the address is one where functions cannot have
4086 been inlined. This improves performance with inferiors that
4087 load a lot of shared libraries, because the solib event
4088 breakpoint is defined as the address of a function (i.e. not
4089 inline). Note that we have to check the previous PC as well
4090 as the current one to catch cases when we have just
4091 single-stepped off a breakpoint prior to reinstating it.
4092 Note that we're assuming that the code we single-step to is
4093 not inline, but that's not definitive: there's nothing
4094 preventing the event breakpoint function from containing
4095 inlined code, and the single-step ending up there. If the
4096 user had set a breakpoint on that inlined code, the missing
4097 skip_inline_frames call would break things. Fortunately
4098 that's an extremely unlikely scenario. */
4099 if (!pc_at_non_inline_function (aspace
, stop_pc
, &ecs
->ws
)
4100 && !(ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4101 && ecs
->event_thread
->control
.trap_expected
4102 && pc_at_non_inline_function (aspace
,
4103 ecs
->event_thread
->prev_pc
,
4106 skip_inline_frames (ecs
->ptid
);
4108 /* Re-fetch current thread's frame in case that invalidated
4110 frame
= get_current_frame ();
4111 gdbarch
= get_frame_arch (frame
);
4115 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4116 && ecs
->event_thread
->control
.trap_expected
4117 && gdbarch_single_step_through_delay_p (gdbarch
)
4118 && currently_stepping (ecs
->event_thread
))
4120 /* We're trying to step off a breakpoint. Turns out that we're
4121 also on an instruction that needs to be stepped multiple
4122 times before it's been fully executing. E.g., architectures
4123 with a delay slot. It needs to be stepped twice, once for
4124 the instruction and once for the delay slot. */
4125 int step_through_delay
4126 = gdbarch_single_step_through_delay (gdbarch
, frame
);
4128 if (debug_infrun
&& step_through_delay
)
4129 fprintf_unfiltered (gdb_stdlog
, "infrun: step through delay\n");
4130 if (ecs
->event_thread
->control
.step_range_end
== 0
4131 && step_through_delay
)
4133 /* The user issued a continue when stopped at a breakpoint.
4134 Set up for another trap and get out of here. */
4135 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4139 else if (step_through_delay
)
4141 /* The user issued a step when stopped at a breakpoint.
4142 Maybe we should stop, maybe we should not - the delay
4143 slot *might* correspond to a line of source. In any
4144 case, don't decide that here, just set
4145 ecs->stepping_over_breakpoint, making sure we
4146 single-step again before breakpoints are re-inserted. */
4147 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4151 /* Look at the cause of the stop, and decide what to do.
4152 The alternatives are:
4153 1) stop_stepping and return; to really stop and return to the debugger,
4154 2) keep_going and return to start up again
4155 (set ecs->event_thread->stepping_over_breakpoint to 1 to single step once)
4156 3) set ecs->random_signal to 1, and the decision between 1 and 2
4157 will be made according to the signal handling tables. */
4159 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4163 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped\n");
4164 stop_print_frame
= 0;
4165 stop_stepping (ecs
);
4169 /* This is originated from start_remote(), start_inferior() and
4170 shared libraries hook functions. */
4171 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_REMOTE
)
4174 fprintf_unfiltered (gdb_stdlog
, "infrun: quietly stopped\n");
4175 stop_stepping (ecs
);
4179 /* This originates from attach_command(). We need to overwrite
4180 the stop_signal here, because some kernels don't ignore a
4181 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
4182 See more comments in inferior.h. On the other hand, if we
4183 get a non-SIGSTOP, report it to the user - assume the backend
4184 will handle the SIGSTOP if it should show up later.
4186 Also consider that the attach is complete when we see a
4187 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
4188 target extended-remote report it instead of a SIGSTOP
4189 (e.g. gdbserver). We already rely on SIGTRAP being our
4190 signal, so this is no exception.
4192 Also consider that the attach is complete when we see a
4193 GDB_SIGNAL_0. In non-stop mode, GDB will explicitly tell
4194 the target to stop all threads of the inferior, in case the
4195 low level attach operation doesn't stop them implicitly. If
4196 they weren't stopped implicitly, then the stub will report a
4197 GDB_SIGNAL_0, meaning: stopped for no particular reason
4198 other than GDB's request. */
4199 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
4200 && (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_STOP
4201 || ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4202 || ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_0
))
4204 stop_stepping (ecs
);
4205 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4209 /* See if there is a breakpoint/watchpoint/catchpoint/etc. that
4210 handles this event. */
4211 ecs
->event_thread
->control
.stop_bpstat
4212 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
4213 stop_pc
, ecs
->ptid
, &ecs
->ws
);
4215 /* Following in case break condition called a
4217 stop_print_frame
= 1;
4219 /* This is where we handle "moribund" watchpoints. Unlike
4220 software breakpoints traps, hardware watchpoint traps are
4221 always distinguishable from random traps. If no high-level
4222 watchpoint is associated with the reported stop data address
4223 anymore, then the bpstat does not explain the signal ---
4224 simply make sure to ignore it if `stopped_by_watchpoint' is
4228 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4229 && (bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
4231 == BPSTAT_SIGNAL_NO
)
4232 && stopped_by_watchpoint
)
4233 fprintf_unfiltered (gdb_stdlog
,
4234 "infrun: no user watchpoint explains "
4235 "watchpoint SIGTRAP, ignoring\n");
4237 /* NOTE: cagney/2003-03-29: These two checks for a random signal
4238 at one stage in the past included checks for an inferior
4239 function call's call dummy's return breakpoint. The original
4240 comment, that went with the test, read:
4242 ``End of a stack dummy. Some systems (e.g. Sony news) give
4243 another signal besides SIGTRAP, so check here as well as
4246 If someone ever tries to get call dummys on a
4247 non-executable stack to work (where the target would stop
4248 with something like a SIGSEGV), then those tests might need
4249 to be re-instated. Given, however, that the tests were only
4250 enabled when momentary breakpoints were not being used, I
4251 suspect that it won't be the case.
4253 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
4254 be necessary for call dummies on a non-executable stack on
4257 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
4259 = !((bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
4261 != BPSTAT_SIGNAL_NO
)
4262 || stopped_by_watchpoint
4263 || ecs
->event_thread
->control
.trap_expected
4264 || (ecs
->event_thread
->control
.step_range_end
4265 && (ecs
->event_thread
->control
.step_resume_breakpoint
4269 enum bpstat_signal_value sval
;
4271 sval
= bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
4272 ecs
->event_thread
->suspend
.stop_signal
);
4273 ecs
->random_signal
= (sval
== BPSTAT_SIGNAL_NO
);
4275 if (sval
== BPSTAT_SIGNAL_HIDE
)
4276 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_TRAP
;
4279 process_event_stop_test
:
4281 /* Re-fetch current thread's frame in case we did a
4282 "goto process_event_stop_test" above. */
4283 frame
= get_current_frame ();
4284 gdbarch
= get_frame_arch (frame
);
4286 /* For the program's own signals, act according to
4287 the signal handling tables. */
4289 if (ecs
->random_signal
)
4291 /* Signal not for debugging purposes. */
4293 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ecs
->ptid
));
4296 fprintf_unfiltered (gdb_stdlog
, "infrun: random signal %d\n",
4297 ecs
->event_thread
->suspend
.stop_signal
);
4299 stopped_by_random_signal
= 1;
4301 if (signal_print
[ecs
->event_thread
->suspend
.stop_signal
])
4304 target_terminal_ours_for_output ();
4305 print_signal_received_reason
4306 (ecs
->event_thread
->suspend
.stop_signal
);
4308 /* Always stop on signals if we're either just gaining control
4309 of the program, or the user explicitly requested this thread
4310 to remain stopped. */
4311 if (stop_soon
!= NO_STOP_QUIETLY
4312 || ecs
->event_thread
->stop_requested
4314 && signal_stop_state (ecs
->event_thread
->suspend
.stop_signal
)))
4316 stop_stepping (ecs
);
4319 /* If not going to stop, give terminal back
4320 if we took it away. */
4322 target_terminal_inferior ();
4324 /* Clear the signal if it should not be passed. */
4325 if (signal_program
[ecs
->event_thread
->suspend
.stop_signal
] == 0)
4326 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4328 if (ecs
->event_thread
->prev_pc
== stop_pc
4329 && ecs
->event_thread
->control
.trap_expected
4330 && ecs
->event_thread
->control
.step_resume_breakpoint
== NULL
)
4332 /* We were just starting a new sequence, attempting to
4333 single-step off of a breakpoint and expecting a SIGTRAP.
4334 Instead this signal arrives. This signal will take us out
4335 of the stepping range so GDB needs to remember to, when
4336 the signal handler returns, resume stepping off that
4338 /* To simplify things, "continue" is forced to use the same
4339 code paths as single-step - set a breakpoint at the
4340 signal return address and then, once hit, step off that
4343 fprintf_unfiltered (gdb_stdlog
,
4344 "infrun: signal arrived while stepping over "
4347 insert_hp_step_resume_breakpoint_at_frame (frame
);
4348 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
4349 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4350 ecs
->event_thread
->control
.trap_expected
= 0;
4355 if (ecs
->event_thread
->control
.step_range_end
!= 0
4356 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
4357 && pc_in_thread_step_range (stop_pc
, ecs
->event_thread
)
4358 && frame_id_eq (get_stack_frame_id (frame
),
4359 ecs
->event_thread
->control
.step_stack_frame_id
)
4360 && ecs
->event_thread
->control
.step_resume_breakpoint
== NULL
)
4362 /* The inferior is about to take a signal that will take it
4363 out of the single step range. Set a breakpoint at the
4364 current PC (which is presumably where the signal handler
4365 will eventually return) and then allow the inferior to
4368 Note that this is only needed for a signal delivered
4369 while in the single-step range. Nested signals aren't a
4370 problem as they eventually all return. */
4372 fprintf_unfiltered (gdb_stdlog
,
4373 "infrun: signal may take us out of "
4374 "single-step range\n");
4376 insert_hp_step_resume_breakpoint_at_frame (frame
);
4377 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4378 ecs
->event_thread
->control
.trap_expected
= 0;
4383 /* Note: step_resume_breakpoint may be non-NULL. This occures
4384 when either there's a nested signal, or when there's a
4385 pending signal enabled just as the signal handler returns
4386 (leaving the inferior at the step-resume-breakpoint without
4387 actually executing it). Either way continue until the
4388 breakpoint is really hit. */
4392 /* Handle cases caused by hitting a breakpoint. */
4394 CORE_ADDR jmp_buf_pc
;
4395 struct bpstat_what what
;
4397 what
= bpstat_what (ecs
->event_thread
->control
.stop_bpstat
);
4399 if (what
.call_dummy
)
4401 stop_stack_dummy
= what
.call_dummy
;
4404 /* If we hit an internal event that triggers symbol changes, the
4405 current frame will be invalidated within bpstat_what (e.g.,
4406 if we hit an internal solib event). Re-fetch it. */
4407 frame
= get_current_frame ();
4408 gdbarch
= get_frame_arch (frame
);
4410 switch (what
.main_action
)
4412 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
4413 /* If we hit the breakpoint at longjmp while stepping, we
4414 install a momentary breakpoint at the target of the
4418 fprintf_unfiltered (gdb_stdlog
,
4419 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
4421 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4423 if (what
.is_longjmp
)
4425 struct value
*arg_value
;
4427 /* If we set the longjmp breakpoint via a SystemTap
4428 probe, then use it to extract the arguments. The
4429 destination PC is the third argument to the
4431 arg_value
= probe_safe_evaluate_at_pc (frame
, 2);
4433 jmp_buf_pc
= value_as_address (arg_value
);
4434 else if (!gdbarch_get_longjmp_target_p (gdbarch
)
4435 || !gdbarch_get_longjmp_target (gdbarch
,
4436 frame
, &jmp_buf_pc
))
4439 fprintf_unfiltered (gdb_stdlog
,
4440 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME "
4441 "(!gdbarch_get_longjmp_target)\n");
4446 /* Insert a breakpoint at resume address. */
4447 insert_longjmp_resume_breakpoint (gdbarch
, jmp_buf_pc
);
4450 check_exception_resume (ecs
, frame
);
4454 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
4456 struct frame_info
*init_frame
;
4458 /* There are several cases to consider.
4460 1. The initiating frame no longer exists. In this case
4461 we must stop, because the exception or longjmp has gone
4464 2. The initiating frame exists, and is the same as the
4465 current frame. We stop, because the exception or
4466 longjmp has been caught.
4468 3. The initiating frame exists and is different from
4469 the current frame. This means the exception or longjmp
4470 has been caught beneath the initiating frame, so keep
4473 4. longjmp breakpoint has been placed just to protect
4474 against stale dummy frames and user is not interested
4475 in stopping around longjmps. */
4478 fprintf_unfiltered (gdb_stdlog
,
4479 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
4481 gdb_assert (ecs
->event_thread
->control
.exception_resume_breakpoint
4483 delete_exception_resume_breakpoint (ecs
->event_thread
);
4485 if (what
.is_longjmp
)
4487 check_longjmp_breakpoint_for_call_dummy (ecs
->event_thread
->num
);
4489 if (!frame_id_p (ecs
->event_thread
->initiating_frame
))
4497 init_frame
= frame_find_by_id (ecs
->event_thread
->initiating_frame
);
4501 struct frame_id current_id
4502 = get_frame_id (get_current_frame ());
4503 if (frame_id_eq (current_id
,
4504 ecs
->event_thread
->initiating_frame
))
4506 /* Case 2. Fall through. */
4516 /* For Cases 1 and 2, remove the step-resume breakpoint,
4518 delete_step_resume_breakpoint (ecs
->event_thread
);
4520 ecs
->event_thread
->control
.stop_step
= 1;
4521 print_end_stepping_range_reason ();
4522 stop_stepping (ecs
);
4526 case BPSTAT_WHAT_SINGLE
:
4528 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_SINGLE\n");
4529 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4530 /* Still need to check other stuff, at least the case where
4531 we are stepping and step out of the right range. */
4534 case BPSTAT_WHAT_STEP_RESUME
:
4536 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
4538 delete_step_resume_breakpoint (ecs
->event_thread
);
4539 if (ecs
->event_thread
->control
.proceed_to_finish
4540 && execution_direction
== EXEC_REVERSE
)
4542 struct thread_info
*tp
= ecs
->event_thread
;
4544 /* We are finishing a function in reverse, and just hit
4545 the step-resume breakpoint at the start address of
4546 the function, and we're almost there -- just need to
4547 back up by one more single-step, which should take us
4548 back to the function call. */
4549 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
4553 fill_in_stop_func (gdbarch
, ecs
);
4554 if (stop_pc
== ecs
->stop_func_start
4555 && execution_direction
== EXEC_REVERSE
)
4557 /* We are stepping over a function call in reverse, and
4558 just hit the step-resume breakpoint at the start
4559 address of the function. Go back to single-stepping,
4560 which should take us back to the function call. */
4561 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4567 case BPSTAT_WHAT_STOP_NOISY
:
4569 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
4570 stop_print_frame
= 1;
4572 /* We are about to nuke the step_resume_breakpointt via the
4573 cleanup chain, so no need to worry about it here. */
4575 stop_stepping (ecs
);
4578 case BPSTAT_WHAT_STOP_SILENT
:
4580 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
4581 stop_print_frame
= 0;
4583 /* We are about to nuke the step_resume_breakpoin via the
4584 cleanup chain, so no need to worry about it here. */
4586 stop_stepping (ecs
);
4589 case BPSTAT_WHAT_HP_STEP_RESUME
:
4591 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_HP_STEP_RESUME\n");
4593 delete_step_resume_breakpoint (ecs
->event_thread
);
4594 if (ecs
->event_thread
->step_after_step_resume_breakpoint
)
4596 /* Back when the step-resume breakpoint was inserted, we
4597 were trying to single-step off a breakpoint. Go back
4599 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
4600 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4606 case BPSTAT_WHAT_KEEP_CHECKING
:
4611 /* We come here if we hit a breakpoint but should not
4612 stop for it. Possibly we also were stepping
4613 and should stop for that. So fall through and
4614 test for stepping. But, if not stepping,
4617 /* In all-stop mode, if we're currently stepping but have stopped in
4618 some other thread, we need to switch back to the stepped thread. */
4621 struct thread_info
*tp
;
4623 tp
= iterate_over_threads (currently_stepping_or_nexting_callback
,
4627 /* However, if the current thread is blocked on some internal
4628 breakpoint, and we simply need to step over that breakpoint
4629 to get it going again, do that first. */
4630 if ((ecs
->event_thread
->control
.trap_expected
4631 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_TRAP
)
4632 || ecs
->event_thread
->stepping_over_breakpoint
)
4638 /* If the stepping thread exited, then don't try to switch
4639 back and resume it, which could fail in several different
4640 ways depending on the target. Instead, just keep going.
4642 We can find a stepping dead thread in the thread list in
4645 - The target supports thread exit events, and when the
4646 target tries to delete the thread from the thread list,
4647 inferior_ptid pointed at the exiting thread. In such
4648 case, calling delete_thread does not really remove the
4649 thread from the list; instead, the thread is left listed,
4650 with 'exited' state.
4652 - The target's debug interface does not support thread
4653 exit events, and so we have no idea whatsoever if the
4654 previously stepping thread is still alive. For that
4655 reason, we need to synchronously query the target
4657 if (is_exited (tp
->ptid
)
4658 || !target_thread_alive (tp
->ptid
))
4661 fprintf_unfiltered (gdb_stdlog
,
4662 "infrun: not switching back to "
4663 "stepped thread, it has vanished\n");
4665 delete_thread (tp
->ptid
);
4670 /* Otherwise, we no longer expect a trap in the current thread.
4671 Clear the trap_expected flag before switching back -- this is
4672 what keep_going would do as well, if we called it. */
4673 ecs
->event_thread
->control
.trap_expected
= 0;
4676 fprintf_unfiltered (gdb_stdlog
,
4677 "infrun: switching back to stepped thread\n");
4679 ecs
->event_thread
= tp
;
4680 ecs
->ptid
= tp
->ptid
;
4681 context_switch (ecs
->ptid
);
4687 if (ecs
->event_thread
->control
.step_resume_breakpoint
)
4690 fprintf_unfiltered (gdb_stdlog
,
4691 "infrun: step-resume breakpoint is inserted\n");
4693 /* Having a step-resume breakpoint overrides anything
4694 else having to do with stepping commands until
4695 that breakpoint is reached. */
4700 if (ecs
->event_thread
->control
.step_range_end
== 0)
4703 fprintf_unfiltered (gdb_stdlog
, "infrun: no stepping, continue\n");
4704 /* Likewise if we aren't even stepping. */
4709 /* Re-fetch current thread's frame in case the code above caused
4710 the frame cache to be re-initialized, making our FRAME variable
4711 a dangling pointer. */
4712 frame
= get_current_frame ();
4713 gdbarch
= get_frame_arch (frame
);
4714 fill_in_stop_func (gdbarch
, ecs
);
4716 /* If stepping through a line, keep going if still within it.
4718 Note that step_range_end is the address of the first instruction
4719 beyond the step range, and NOT the address of the last instruction
4722 Note also that during reverse execution, we may be stepping
4723 through a function epilogue and therefore must detect when
4724 the current-frame changes in the middle of a line. */
4726 if (pc_in_thread_step_range (stop_pc
, ecs
->event_thread
)
4727 && (execution_direction
!= EXEC_REVERSE
4728 || frame_id_eq (get_frame_id (frame
),
4729 ecs
->event_thread
->control
.step_frame_id
)))
4733 (gdb_stdlog
, "infrun: stepping inside range [%s-%s]\n",
4734 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_start
),
4735 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_end
));
4737 /* Tentatively re-enable range stepping; `resume' disables it if
4738 necessary (e.g., if we're stepping over a breakpoint or we
4739 have software watchpoints). */
4740 ecs
->event_thread
->control
.may_range_step
= 1;
4742 /* When stepping backward, stop at beginning of line range
4743 (unless it's the function entry point, in which case
4744 keep going back to the call point). */
4745 if (stop_pc
== ecs
->event_thread
->control
.step_range_start
4746 && stop_pc
!= ecs
->stop_func_start
4747 && execution_direction
== EXEC_REVERSE
)
4749 ecs
->event_thread
->control
.stop_step
= 1;
4750 print_end_stepping_range_reason ();
4751 stop_stepping (ecs
);
4759 /* We stepped out of the stepping range. */
4761 /* If we are stepping at the source level and entered the runtime
4762 loader dynamic symbol resolution code...
4764 EXEC_FORWARD: we keep on single stepping until we exit the run
4765 time loader code and reach the callee's address.
4767 EXEC_REVERSE: we've already executed the callee (backward), and
4768 the runtime loader code is handled just like any other
4769 undebuggable function call. Now we need only keep stepping
4770 backward through the trampoline code, and that's handled further
4771 down, so there is nothing for us to do here. */
4773 if (execution_direction
!= EXEC_REVERSE
4774 && ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
4775 && in_solib_dynsym_resolve_code (stop_pc
))
4777 CORE_ADDR pc_after_resolver
=
4778 gdbarch_skip_solib_resolver (gdbarch
, stop_pc
);
4781 fprintf_unfiltered (gdb_stdlog
,
4782 "infrun: stepped into dynsym resolve code\n");
4784 if (pc_after_resolver
)
4786 /* Set up a step-resume breakpoint at the address
4787 indicated by SKIP_SOLIB_RESOLVER. */
4788 struct symtab_and_line sr_sal
;
4791 sr_sal
.pc
= pc_after_resolver
;
4792 sr_sal
.pspace
= get_frame_program_space (frame
);
4794 insert_step_resume_breakpoint_at_sal (gdbarch
,
4795 sr_sal
, null_frame_id
);
4802 if (ecs
->event_thread
->control
.step_range_end
!= 1
4803 && (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
4804 || ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
4805 && get_frame_type (frame
) == SIGTRAMP_FRAME
)
4808 fprintf_unfiltered (gdb_stdlog
,
4809 "infrun: stepped into signal trampoline\n");
4810 /* The inferior, while doing a "step" or "next", has ended up in
4811 a signal trampoline (either by a signal being delivered or by
4812 the signal handler returning). Just single-step until the
4813 inferior leaves the trampoline (either by calling the handler
4819 /* If we're in the return path from a shared library trampoline,
4820 we want to proceed through the trampoline when stepping. */
4821 /* macro/2012-04-25: This needs to come before the subroutine
4822 call check below as on some targets return trampolines look
4823 like subroutine calls (MIPS16 return thunks). */
4824 if (gdbarch_in_solib_return_trampoline (gdbarch
,
4825 stop_pc
, ecs
->stop_func_name
)
4826 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
4828 /* Determine where this trampoline returns. */
4829 CORE_ADDR real_stop_pc
;
4831 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
4834 fprintf_unfiltered (gdb_stdlog
,
4835 "infrun: stepped into solib return tramp\n");
4837 /* Only proceed through if we know where it's going. */
4840 /* And put the step-breakpoint there and go until there. */
4841 struct symtab_and_line sr_sal
;
4843 init_sal (&sr_sal
); /* initialize to zeroes */
4844 sr_sal
.pc
= real_stop_pc
;
4845 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
4846 sr_sal
.pspace
= get_frame_program_space (frame
);
4848 /* Do not specify what the fp should be when we stop since
4849 on some machines the prologue is where the new fp value
4851 insert_step_resume_breakpoint_at_sal (gdbarch
,
4852 sr_sal
, null_frame_id
);
4854 /* Restart without fiddling with the step ranges or
4861 /* Check for subroutine calls. The check for the current frame
4862 equalling the step ID is not necessary - the check of the
4863 previous frame's ID is sufficient - but it is a common case and
4864 cheaper than checking the previous frame's ID.
4866 NOTE: frame_id_eq will never report two invalid frame IDs as
4867 being equal, so to get into this block, both the current and
4868 previous frame must have valid frame IDs. */
4869 /* The outer_frame_id check is a heuristic to detect stepping
4870 through startup code. If we step over an instruction which
4871 sets the stack pointer from an invalid value to a valid value,
4872 we may detect that as a subroutine call from the mythical
4873 "outermost" function. This could be fixed by marking
4874 outermost frames as !stack_p,code_p,special_p. Then the
4875 initial outermost frame, before sp was valid, would
4876 have code_addr == &_start. See the comment in frame_id_eq
4878 if (!frame_id_eq (get_stack_frame_id (frame
),
4879 ecs
->event_thread
->control
.step_stack_frame_id
)
4880 && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()),
4881 ecs
->event_thread
->control
.step_stack_frame_id
)
4882 && (!frame_id_eq (ecs
->event_thread
->control
.step_stack_frame_id
,
4884 || step_start_function
!= find_pc_function (stop_pc
))))
4886 CORE_ADDR real_stop_pc
;
4889 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into subroutine\n");
4891 if ((ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_NONE
)
4892 || ((ecs
->event_thread
->control
.step_range_end
== 1)
4893 && in_prologue (gdbarch
, ecs
->event_thread
->prev_pc
,
4894 ecs
->stop_func_start
)))
4896 /* I presume that step_over_calls is only 0 when we're
4897 supposed to be stepping at the assembly language level
4898 ("stepi"). Just stop. */
4899 /* Also, maybe we just did a "nexti" inside a prolog, so we
4900 thought it was a subroutine call but it was not. Stop as
4902 /* And this works the same backward as frontward. MVS */
4903 ecs
->event_thread
->control
.stop_step
= 1;
4904 print_end_stepping_range_reason ();
4905 stop_stepping (ecs
);
4909 /* Reverse stepping through solib trampolines. */
4911 if (execution_direction
== EXEC_REVERSE
4912 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
4913 && (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
4914 || (ecs
->stop_func_start
== 0
4915 && in_solib_dynsym_resolve_code (stop_pc
))))
4917 /* Any solib trampoline code can be handled in reverse
4918 by simply continuing to single-step. We have already
4919 executed the solib function (backwards), and a few
4920 steps will take us back through the trampoline to the
4926 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
4928 /* We're doing a "next".
4930 Normal (forward) execution: set a breakpoint at the
4931 callee's return address (the address at which the caller
4934 Reverse (backward) execution. set the step-resume
4935 breakpoint at the start of the function that we just
4936 stepped into (backwards), and continue to there. When we
4937 get there, we'll need to single-step back to the caller. */
4939 if (execution_direction
== EXEC_REVERSE
)
4941 /* If we're already at the start of the function, we've either
4942 just stepped backward into a single instruction function,
4943 or stepped back out of a signal handler to the first instruction
4944 of the function. Just keep going, which will single-step back
4946 if (ecs
->stop_func_start
!= stop_pc
)
4948 struct symtab_and_line sr_sal
;
4950 /* Normal function call return (static or dynamic). */
4952 sr_sal
.pc
= ecs
->stop_func_start
;
4953 sr_sal
.pspace
= get_frame_program_space (frame
);
4954 insert_step_resume_breakpoint_at_sal (gdbarch
,
4955 sr_sal
, null_frame_id
);
4959 insert_step_resume_breakpoint_at_caller (frame
);
4965 /* If we are in a function call trampoline (a stub between the
4966 calling routine and the real function), locate the real
4967 function. That's what tells us (a) whether we want to step
4968 into it at all, and (b) what prologue we want to run to the
4969 end of, if we do step into it. */
4970 real_stop_pc
= skip_language_trampoline (frame
, stop_pc
);
4971 if (real_stop_pc
== 0)
4972 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
4973 if (real_stop_pc
!= 0)
4974 ecs
->stop_func_start
= real_stop_pc
;
4976 if (real_stop_pc
!= 0 && in_solib_dynsym_resolve_code (real_stop_pc
))
4978 struct symtab_and_line sr_sal
;
4981 sr_sal
.pc
= ecs
->stop_func_start
;
4982 sr_sal
.pspace
= get_frame_program_space (frame
);
4984 insert_step_resume_breakpoint_at_sal (gdbarch
,
4985 sr_sal
, null_frame_id
);
4990 /* If we have line number information for the function we are
4991 thinking of stepping into and the function isn't on the skip
4994 If there are several symtabs at that PC (e.g. with include
4995 files), just want to know whether *any* of them have line
4996 numbers. find_pc_line handles this. */
4998 struct symtab_and_line tmp_sal
;
5000 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
5001 if (tmp_sal
.line
!= 0
5002 && !function_name_is_marked_for_skip (ecs
->stop_func_name
,
5005 if (execution_direction
== EXEC_REVERSE
)
5006 handle_step_into_function_backward (gdbarch
, ecs
);
5008 handle_step_into_function (gdbarch
, ecs
);
5013 /* If we have no line number and the step-stop-if-no-debug is
5014 set, we stop the step so that the user has a chance to switch
5015 in assembly mode. */
5016 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
5017 && step_stop_if_no_debug
)
5019 ecs
->event_thread
->control
.stop_step
= 1;
5020 print_end_stepping_range_reason ();
5021 stop_stepping (ecs
);
5025 if (execution_direction
== EXEC_REVERSE
)
5027 /* If we're already at the start of the function, we've either just
5028 stepped backward into a single instruction function without line
5029 number info, or stepped back out of a signal handler to the first
5030 instruction of the function without line number info. Just keep
5031 going, which will single-step back to the caller. */
5032 if (ecs
->stop_func_start
!= stop_pc
)
5034 /* Set a breakpoint at callee's start address.
5035 From there we can step once and be back in the caller. */
5036 struct symtab_and_line sr_sal
;
5039 sr_sal
.pc
= ecs
->stop_func_start
;
5040 sr_sal
.pspace
= get_frame_program_space (frame
);
5041 insert_step_resume_breakpoint_at_sal (gdbarch
,
5042 sr_sal
, null_frame_id
);
5046 /* Set a breakpoint at callee's return address (the address
5047 at which the caller will resume). */
5048 insert_step_resume_breakpoint_at_caller (frame
);
5054 /* Reverse stepping through solib trampolines. */
5056 if (execution_direction
== EXEC_REVERSE
5057 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
5059 if (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
5060 || (ecs
->stop_func_start
== 0
5061 && in_solib_dynsym_resolve_code (stop_pc
)))
5063 /* Any solib trampoline code can be handled in reverse
5064 by simply continuing to single-step. We have already
5065 executed the solib function (backwards), and a few
5066 steps will take us back through the trampoline to the
5071 else if (in_solib_dynsym_resolve_code (stop_pc
))
5073 /* Stepped backward into the solib dynsym resolver.
5074 Set a breakpoint at its start and continue, then
5075 one more step will take us out. */
5076 struct symtab_and_line sr_sal
;
5079 sr_sal
.pc
= ecs
->stop_func_start
;
5080 sr_sal
.pspace
= get_frame_program_space (frame
);
5081 insert_step_resume_breakpoint_at_sal (gdbarch
,
5082 sr_sal
, null_frame_id
);
5088 stop_pc_sal
= find_pc_line (stop_pc
, 0);
5090 /* NOTE: tausq/2004-05-24: This if block used to be done before all
5091 the trampoline processing logic, however, there are some trampolines
5092 that have no names, so we should do trampoline handling first. */
5093 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
5094 && ecs
->stop_func_name
== NULL
5095 && stop_pc_sal
.line
== 0)
5098 fprintf_unfiltered (gdb_stdlog
,
5099 "infrun: stepped into undebuggable function\n");
5101 /* The inferior just stepped into, or returned to, an
5102 undebuggable function (where there is no debugging information
5103 and no line number corresponding to the address where the
5104 inferior stopped). Since we want to skip this kind of code,
5105 we keep going until the inferior returns from this
5106 function - unless the user has asked us not to (via
5107 set step-mode) or we no longer know how to get back
5108 to the call site. */
5109 if (step_stop_if_no_debug
5110 || !frame_id_p (frame_unwind_caller_id (frame
)))
5112 /* If we have no line number and the step-stop-if-no-debug
5113 is set, we stop the step so that the user has a chance to
5114 switch in assembly mode. */
5115 ecs
->event_thread
->control
.stop_step
= 1;
5116 print_end_stepping_range_reason ();
5117 stop_stepping (ecs
);
5122 /* Set a breakpoint at callee's return address (the address
5123 at which the caller will resume). */
5124 insert_step_resume_breakpoint_at_caller (frame
);
5130 if (ecs
->event_thread
->control
.step_range_end
== 1)
5132 /* It is stepi or nexti. We always want to stop stepping after
5135 fprintf_unfiltered (gdb_stdlog
, "infrun: stepi/nexti\n");
5136 ecs
->event_thread
->control
.stop_step
= 1;
5137 print_end_stepping_range_reason ();
5138 stop_stepping (ecs
);
5142 if (stop_pc_sal
.line
== 0)
5144 /* We have no line number information. That means to stop
5145 stepping (does this always happen right after one instruction,
5146 when we do "s" in a function with no line numbers,
5147 or can this happen as a result of a return or longjmp?). */
5149 fprintf_unfiltered (gdb_stdlog
, "infrun: no line number info\n");
5150 ecs
->event_thread
->control
.stop_step
= 1;
5151 print_end_stepping_range_reason ();
5152 stop_stepping (ecs
);
5156 /* Look for "calls" to inlined functions, part one. If the inline
5157 frame machinery detected some skipped call sites, we have entered
5158 a new inline function. */
5160 if (frame_id_eq (get_frame_id (get_current_frame ()),
5161 ecs
->event_thread
->control
.step_frame_id
)
5162 && inline_skipped_frames (ecs
->ptid
))
5164 struct symtab_and_line call_sal
;
5167 fprintf_unfiltered (gdb_stdlog
,
5168 "infrun: stepped into inlined function\n");
5170 find_frame_sal (get_current_frame (), &call_sal
);
5172 if (ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_ALL
)
5174 /* For "step", we're going to stop. But if the call site
5175 for this inlined function is on the same source line as
5176 we were previously stepping, go down into the function
5177 first. Otherwise stop at the call site. */
5179 if (call_sal
.line
== ecs
->event_thread
->current_line
5180 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
5181 step_into_inline_frame (ecs
->ptid
);
5183 ecs
->event_thread
->control
.stop_step
= 1;
5184 print_end_stepping_range_reason ();
5185 stop_stepping (ecs
);
5190 /* For "next", we should stop at the call site if it is on a
5191 different source line. Otherwise continue through the
5192 inlined function. */
5193 if (call_sal
.line
== ecs
->event_thread
->current_line
5194 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
5198 ecs
->event_thread
->control
.stop_step
= 1;
5199 print_end_stepping_range_reason ();
5200 stop_stepping (ecs
);
5206 /* Look for "calls" to inlined functions, part two. If we are still
5207 in the same real function we were stepping through, but we have
5208 to go further up to find the exact frame ID, we are stepping
5209 through a more inlined call beyond its call site. */
5211 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
5212 && !frame_id_eq (get_frame_id (get_current_frame ()),
5213 ecs
->event_thread
->control
.step_frame_id
)
5214 && stepped_in_from (get_current_frame (),
5215 ecs
->event_thread
->control
.step_frame_id
))
5218 fprintf_unfiltered (gdb_stdlog
,
5219 "infrun: stepping through inlined function\n");
5221 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
5225 ecs
->event_thread
->control
.stop_step
= 1;
5226 print_end_stepping_range_reason ();
5227 stop_stepping (ecs
);
5232 if ((stop_pc
== stop_pc_sal
.pc
)
5233 && (ecs
->event_thread
->current_line
!= stop_pc_sal
.line
5234 || ecs
->event_thread
->current_symtab
!= stop_pc_sal
.symtab
))
5236 /* We are at the start of a different line. So stop. Note that
5237 we don't stop if we step into the middle of a different line.
5238 That is said to make things like for (;;) statements work
5241 fprintf_unfiltered (gdb_stdlog
,
5242 "infrun: stepped to a different line\n");
5243 ecs
->event_thread
->control
.stop_step
= 1;
5244 print_end_stepping_range_reason ();
5245 stop_stepping (ecs
);
5249 /* We aren't done stepping.
5251 Optimize by setting the stepping range to the line.
5252 (We might not be in the original line, but if we entered a
5253 new line in mid-statement, we continue stepping. This makes
5254 things like for(;;) statements work better.) */
5256 ecs
->event_thread
->control
.step_range_start
= stop_pc_sal
.pc
;
5257 ecs
->event_thread
->control
.step_range_end
= stop_pc_sal
.end
;
5258 ecs
->event_thread
->control
.may_range_step
= 1;
5259 set_step_info (frame
, stop_pc_sal
);
5262 fprintf_unfiltered (gdb_stdlog
, "infrun: keep going\n");
5266 /* Is thread TP in the middle of single-stepping? */
5269 currently_stepping (struct thread_info
*tp
)
5271 return ((tp
->control
.step_range_end
5272 && tp
->control
.step_resume_breakpoint
== NULL
)
5273 || tp
->control
.trap_expected
5274 || bpstat_should_step ());
5277 /* Returns true if any thread *but* the one passed in "data" is in the
5278 middle of stepping or of handling a "next". */
5281 currently_stepping_or_nexting_callback (struct thread_info
*tp
, void *data
)
5286 return (tp
->control
.step_range_end
5287 || tp
->control
.trap_expected
);
5290 /* Inferior has stepped into a subroutine call with source code that
5291 we should not step over. Do step to the first line of code in
5295 handle_step_into_function (struct gdbarch
*gdbarch
,
5296 struct execution_control_state
*ecs
)
5299 struct symtab_and_line stop_func_sal
, sr_sal
;
5301 fill_in_stop_func (gdbarch
, ecs
);
5303 s
= find_pc_symtab (stop_pc
);
5304 if (s
&& s
->language
!= language_asm
)
5305 ecs
->stop_func_start
= gdbarch_skip_prologue (gdbarch
,
5306 ecs
->stop_func_start
);
5308 stop_func_sal
= find_pc_line (ecs
->stop_func_start
, 0);
5309 /* Use the step_resume_break to step until the end of the prologue,
5310 even if that involves jumps (as it seems to on the vax under
5312 /* If the prologue ends in the middle of a source line, continue to
5313 the end of that source line (if it is still within the function).
5314 Otherwise, just go to end of prologue. */
5315 if (stop_func_sal
.end
5316 && stop_func_sal
.pc
!= ecs
->stop_func_start
5317 && stop_func_sal
.end
< ecs
->stop_func_end
)
5318 ecs
->stop_func_start
= stop_func_sal
.end
;
5320 /* Architectures which require breakpoint adjustment might not be able
5321 to place a breakpoint at the computed address. If so, the test
5322 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
5323 ecs->stop_func_start to an address at which a breakpoint may be
5324 legitimately placed.
5326 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
5327 made, GDB will enter an infinite loop when stepping through
5328 optimized code consisting of VLIW instructions which contain
5329 subinstructions corresponding to different source lines. On
5330 FR-V, it's not permitted to place a breakpoint on any but the
5331 first subinstruction of a VLIW instruction. When a breakpoint is
5332 set, GDB will adjust the breakpoint address to the beginning of
5333 the VLIW instruction. Thus, we need to make the corresponding
5334 adjustment here when computing the stop address. */
5336 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
5338 ecs
->stop_func_start
5339 = gdbarch_adjust_breakpoint_address (gdbarch
,
5340 ecs
->stop_func_start
);
5343 if (ecs
->stop_func_start
== stop_pc
)
5345 /* We are already there: stop now. */
5346 ecs
->event_thread
->control
.stop_step
= 1;
5347 print_end_stepping_range_reason ();
5348 stop_stepping (ecs
);
5353 /* Put the step-breakpoint there and go until there. */
5354 init_sal (&sr_sal
); /* initialize to zeroes */
5355 sr_sal
.pc
= ecs
->stop_func_start
;
5356 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
5357 sr_sal
.pspace
= get_frame_program_space (get_current_frame ());
5359 /* Do not specify what the fp should be when we stop since on
5360 some machines the prologue is where the new fp value is
5362 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
, null_frame_id
);
5364 /* And make sure stepping stops right away then. */
5365 ecs
->event_thread
->control
.step_range_end
5366 = ecs
->event_thread
->control
.step_range_start
;
5371 /* Inferior has stepped backward into a subroutine call with source
5372 code that we should not step over. Do step to the beginning of the
5373 last line of code in it. */
5376 handle_step_into_function_backward (struct gdbarch
*gdbarch
,
5377 struct execution_control_state
*ecs
)
5380 struct symtab_and_line stop_func_sal
;
5382 fill_in_stop_func (gdbarch
, ecs
);
5384 s
= find_pc_symtab (stop_pc
);
5385 if (s
&& s
->language
!= language_asm
)
5386 ecs
->stop_func_start
= gdbarch_skip_prologue (gdbarch
,
5387 ecs
->stop_func_start
);
5389 stop_func_sal
= find_pc_line (stop_pc
, 0);
5391 /* OK, we're just going to keep stepping here. */
5392 if (stop_func_sal
.pc
== stop_pc
)
5394 /* We're there already. Just stop stepping now. */
5395 ecs
->event_thread
->control
.stop_step
= 1;
5396 print_end_stepping_range_reason ();
5397 stop_stepping (ecs
);
5401 /* Else just reset the step range and keep going.
5402 No step-resume breakpoint, they don't work for
5403 epilogues, which can have multiple entry paths. */
5404 ecs
->event_thread
->control
.step_range_start
= stop_func_sal
.pc
;
5405 ecs
->event_thread
->control
.step_range_end
= stop_func_sal
.end
;
5411 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
5412 This is used to both functions and to skip over code. */
5415 insert_step_resume_breakpoint_at_sal_1 (struct gdbarch
*gdbarch
,
5416 struct symtab_and_line sr_sal
,
5417 struct frame_id sr_id
,
5418 enum bptype sr_type
)
5420 /* There should never be more than one step-resume or longjmp-resume
5421 breakpoint per thread, so we should never be setting a new
5422 step_resume_breakpoint when one is already active. */
5423 gdb_assert (inferior_thread ()->control
.step_resume_breakpoint
== NULL
);
5424 gdb_assert (sr_type
== bp_step_resume
|| sr_type
== bp_hp_step_resume
);
5427 fprintf_unfiltered (gdb_stdlog
,
5428 "infrun: inserting step-resume breakpoint at %s\n",
5429 paddress (gdbarch
, sr_sal
.pc
));
5431 inferior_thread ()->control
.step_resume_breakpoint
5432 = set_momentary_breakpoint (gdbarch
, sr_sal
, sr_id
, sr_type
);
5436 insert_step_resume_breakpoint_at_sal (struct gdbarch
*gdbarch
,
5437 struct symtab_and_line sr_sal
,
5438 struct frame_id sr_id
)
5440 insert_step_resume_breakpoint_at_sal_1 (gdbarch
,
5445 /* Insert a "high-priority step-resume breakpoint" at RETURN_FRAME.pc.
5446 This is used to skip a potential signal handler.
5448 This is called with the interrupted function's frame. The signal
5449 handler, when it returns, will resume the interrupted function at
5453 insert_hp_step_resume_breakpoint_at_frame (struct frame_info
*return_frame
)
5455 struct symtab_and_line sr_sal
;
5456 struct gdbarch
*gdbarch
;
5458 gdb_assert (return_frame
!= NULL
);
5459 init_sal (&sr_sal
); /* initialize to zeros */
5461 gdbarch
= get_frame_arch (return_frame
);
5462 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
, get_frame_pc (return_frame
));
5463 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
5464 sr_sal
.pspace
= get_frame_program_space (return_frame
);
5466 insert_step_resume_breakpoint_at_sal_1 (gdbarch
, sr_sal
,
5467 get_stack_frame_id (return_frame
),
5471 /* Insert a "step-resume breakpoint" at the previous frame's PC. This
5472 is used to skip a function after stepping into it (for "next" or if
5473 the called function has no debugging information).
5475 The current function has almost always been reached by single
5476 stepping a call or return instruction. NEXT_FRAME belongs to the
5477 current function, and the breakpoint will be set at the caller's
5480 This is a separate function rather than reusing
5481 insert_hp_step_resume_breakpoint_at_frame in order to avoid
5482 get_prev_frame, which may stop prematurely (see the implementation
5483 of frame_unwind_caller_id for an example). */
5486 insert_step_resume_breakpoint_at_caller (struct frame_info
*next_frame
)
5488 struct symtab_and_line sr_sal
;
5489 struct gdbarch
*gdbarch
;
5491 /* We shouldn't have gotten here if we don't know where the call site
5493 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame
)));
5495 init_sal (&sr_sal
); /* initialize to zeros */
5497 gdbarch
= frame_unwind_caller_arch (next_frame
);
5498 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
,
5499 frame_unwind_caller_pc (next_frame
));
5500 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
5501 sr_sal
.pspace
= frame_unwind_program_space (next_frame
);
5503 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
,
5504 frame_unwind_caller_id (next_frame
));
5507 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
5508 new breakpoint at the target of a jmp_buf. The handling of
5509 longjmp-resume uses the same mechanisms used for handling
5510 "step-resume" breakpoints. */
5513 insert_longjmp_resume_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
5515 /* There should never be more than one longjmp-resume breakpoint per
5516 thread, so we should never be setting a new
5517 longjmp_resume_breakpoint when one is already active. */
5518 gdb_assert (inferior_thread ()->control
.exception_resume_breakpoint
== NULL
);
5521 fprintf_unfiltered (gdb_stdlog
,
5522 "infrun: inserting longjmp-resume breakpoint at %s\n",
5523 paddress (gdbarch
, pc
));
5525 inferior_thread ()->control
.exception_resume_breakpoint
=
5526 set_momentary_breakpoint_at_pc (gdbarch
, pc
, bp_longjmp_resume
);
5529 /* Insert an exception resume breakpoint. TP is the thread throwing
5530 the exception. The block B is the block of the unwinder debug hook
5531 function. FRAME is the frame corresponding to the call to this
5532 function. SYM is the symbol of the function argument holding the
5533 target PC of the exception. */
5536 insert_exception_resume_breakpoint (struct thread_info
*tp
,
5538 struct frame_info
*frame
,
5541 volatile struct gdb_exception e
;
5543 /* We want to ignore errors here. */
5544 TRY_CATCH (e
, RETURN_MASK_ERROR
)
5546 struct symbol
*vsym
;
5547 struct value
*value
;
5549 struct breakpoint
*bp
;
5551 vsym
= lookup_symbol (SYMBOL_LINKAGE_NAME (sym
), b
, VAR_DOMAIN
, NULL
);
5552 value
= read_var_value (vsym
, frame
);
5553 /* If the value was optimized out, revert to the old behavior. */
5554 if (! value_optimized_out (value
))
5556 handler
= value_as_address (value
);
5559 fprintf_unfiltered (gdb_stdlog
,
5560 "infrun: exception resume at %lx\n",
5561 (unsigned long) handler
);
5563 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
5564 handler
, bp_exception_resume
);
5566 /* set_momentary_breakpoint_at_pc invalidates FRAME. */
5569 bp
->thread
= tp
->num
;
5570 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
5575 /* A helper for check_exception_resume that sets an
5576 exception-breakpoint based on a SystemTap probe. */
5579 insert_exception_resume_from_probe (struct thread_info
*tp
,
5580 const struct probe
*probe
,
5581 struct frame_info
*frame
)
5583 struct value
*arg_value
;
5585 struct breakpoint
*bp
;
5587 arg_value
= probe_safe_evaluate_at_pc (frame
, 1);
5591 handler
= value_as_address (arg_value
);
5594 fprintf_unfiltered (gdb_stdlog
,
5595 "infrun: exception resume at %s\n",
5596 paddress (get_objfile_arch (probe
->objfile
),
5599 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
5600 handler
, bp_exception_resume
);
5601 bp
->thread
= tp
->num
;
5602 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
5605 /* This is called when an exception has been intercepted. Check to
5606 see whether the exception's destination is of interest, and if so,
5607 set an exception resume breakpoint there. */
5610 check_exception_resume (struct execution_control_state
*ecs
,
5611 struct frame_info
*frame
)
5613 volatile struct gdb_exception e
;
5614 const struct probe
*probe
;
5615 struct symbol
*func
;
5617 /* First see if this exception unwinding breakpoint was set via a
5618 SystemTap probe point. If so, the probe has two arguments: the
5619 CFA and the HANDLER. We ignore the CFA, extract the handler, and
5620 set a breakpoint there. */
5621 probe
= find_probe_by_pc (get_frame_pc (frame
));
5624 insert_exception_resume_from_probe (ecs
->event_thread
, probe
, frame
);
5628 func
= get_frame_function (frame
);
5632 TRY_CATCH (e
, RETURN_MASK_ERROR
)
5635 struct block_iterator iter
;
5639 /* The exception breakpoint is a thread-specific breakpoint on
5640 the unwinder's debug hook, declared as:
5642 void _Unwind_DebugHook (void *cfa, void *handler);
5644 The CFA argument indicates the frame to which control is
5645 about to be transferred. HANDLER is the destination PC.
5647 We ignore the CFA and set a temporary breakpoint at HANDLER.
5648 This is not extremely efficient but it avoids issues in gdb
5649 with computing the DWARF CFA, and it also works even in weird
5650 cases such as throwing an exception from inside a signal
5653 b
= SYMBOL_BLOCK_VALUE (func
);
5654 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
5656 if (!SYMBOL_IS_ARGUMENT (sym
))
5663 insert_exception_resume_breakpoint (ecs
->event_thread
,
5672 stop_stepping (struct execution_control_state
*ecs
)
5675 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_stepping\n");
5677 /* Let callers know we don't want to wait for the inferior anymore. */
5678 ecs
->wait_some_more
= 0;
5681 /* This function handles various cases where we need to continue
5682 waiting for the inferior. */
5683 /* (Used to be the keep_going: label in the old wait_for_inferior). */
5686 keep_going (struct execution_control_state
*ecs
)
5688 /* Make sure normal_stop is called if we get a QUIT handled before
5690 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
5692 /* Save the pc before execution, to compare with pc after stop. */
5693 ecs
->event_thread
->prev_pc
5694 = regcache_read_pc (get_thread_regcache (ecs
->ptid
));
5696 /* If we did not do break;, it means we should keep running the
5697 inferior and not return to debugger. */
5699 if (ecs
->event_thread
->control
.trap_expected
5700 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_TRAP
)
5702 /* We took a signal (which we are supposed to pass through to
5703 the inferior, else we'd not get here) and we haven't yet
5704 gotten our trap. Simply continue. */
5706 discard_cleanups (old_cleanups
);
5707 resume (currently_stepping (ecs
->event_thread
),
5708 ecs
->event_thread
->suspend
.stop_signal
);
5712 /* Either the trap was not expected, but we are continuing
5713 anyway (the user asked that this signal be passed to the
5716 The signal was SIGTRAP, e.g. it was our signal, but we
5717 decided we should resume from it.
5719 We're going to run this baby now!
5721 Note that insert_breakpoints won't try to re-insert
5722 already inserted breakpoints. Therefore, we don't
5723 care if breakpoints were already inserted, or not. */
5725 if (ecs
->event_thread
->stepping_over_breakpoint
)
5727 struct regcache
*thread_regcache
= get_thread_regcache (ecs
->ptid
);
5729 if (!use_displaced_stepping (get_regcache_arch (thread_regcache
)))
5730 /* Since we can't do a displaced step, we have to remove
5731 the breakpoint while we step it. To keep things
5732 simple, we remove them all. */
5733 remove_breakpoints ();
5737 volatile struct gdb_exception e
;
5739 /* Stop stepping when inserting breakpoints
5741 TRY_CATCH (e
, RETURN_MASK_ERROR
)
5743 insert_breakpoints ();
5747 exception_print (gdb_stderr
, e
);
5748 stop_stepping (ecs
);
5753 ecs
->event_thread
->control
.trap_expected
5754 = ecs
->event_thread
->stepping_over_breakpoint
;
5756 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
5757 specifies that such a signal should be delivered to the
5760 Typically, this would occure when a user is debugging a
5761 target monitor on a simulator: the target monitor sets a
5762 breakpoint; the simulator encounters this break-point and
5763 halts the simulation handing control to GDB; GDB, noteing
5764 that the break-point isn't valid, returns control back to the
5765 simulator; the simulator then delivers the hardware
5766 equivalent of a SIGNAL_TRAP to the program being debugged. */
5768 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
5769 && !signal_program
[ecs
->event_thread
->suspend
.stop_signal
])
5770 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5772 discard_cleanups (old_cleanups
);
5773 resume (currently_stepping (ecs
->event_thread
),
5774 ecs
->event_thread
->suspend
.stop_signal
);
5777 prepare_to_wait (ecs
);
5780 /* This function normally comes after a resume, before
5781 handle_inferior_event exits. It takes care of any last bits of
5782 housekeeping, and sets the all-important wait_some_more flag. */
5785 prepare_to_wait (struct execution_control_state
*ecs
)
5788 fprintf_unfiltered (gdb_stdlog
, "infrun: prepare_to_wait\n");
5790 /* This is the old end of the while loop. Let everybody know we
5791 want to wait for the inferior some more and get called again
5793 ecs
->wait_some_more
= 1;
5796 /* Several print_*_reason functions to print why the inferior has stopped.
5797 We always print something when the inferior exits, or receives a signal.
5798 The rest of the cases are dealt with later on in normal_stop and
5799 print_it_typical. Ideally there should be a call to one of these
5800 print_*_reason functions functions from handle_inferior_event each time
5801 stop_stepping is called. */
5803 /* Print why the inferior has stopped.
5804 We are done with a step/next/si/ni command, print why the inferior has
5805 stopped. For now print nothing. Print a message only if not in the middle
5806 of doing a "step n" operation for n > 1. */
5809 print_end_stepping_range_reason (void)
5811 if ((!inferior_thread ()->step_multi
5812 || !inferior_thread ()->control
.stop_step
)
5813 && ui_out_is_mi_like_p (current_uiout
))
5814 ui_out_field_string (current_uiout
, "reason",
5815 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE
));
5818 /* The inferior was terminated by a signal, print why it stopped. */
5821 print_signal_exited_reason (enum gdb_signal siggnal
)
5823 struct ui_out
*uiout
= current_uiout
;
5825 annotate_signalled ();
5826 if (ui_out_is_mi_like_p (uiout
))
5828 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED
));
5829 ui_out_text (uiout
, "\nProgram terminated with signal ");
5830 annotate_signal_name ();
5831 ui_out_field_string (uiout
, "signal-name",
5832 gdb_signal_to_name (siggnal
));
5833 annotate_signal_name_end ();
5834 ui_out_text (uiout
, ", ");
5835 annotate_signal_string ();
5836 ui_out_field_string (uiout
, "signal-meaning",
5837 gdb_signal_to_string (siggnal
));
5838 annotate_signal_string_end ();
5839 ui_out_text (uiout
, ".\n");
5840 ui_out_text (uiout
, "The program no longer exists.\n");
5843 /* The inferior program is finished, print why it stopped. */
5846 print_exited_reason (int exitstatus
)
5848 struct inferior
*inf
= current_inferior ();
5849 const char *pidstr
= target_pid_to_str (pid_to_ptid (inf
->pid
));
5850 struct ui_out
*uiout
= current_uiout
;
5852 annotate_exited (exitstatus
);
5855 if (ui_out_is_mi_like_p (uiout
))
5856 ui_out_field_string (uiout
, "reason",
5857 async_reason_lookup (EXEC_ASYNC_EXITED
));
5858 ui_out_text (uiout
, "[Inferior ");
5859 ui_out_text (uiout
, plongest (inf
->num
));
5860 ui_out_text (uiout
, " (");
5861 ui_out_text (uiout
, pidstr
);
5862 ui_out_text (uiout
, ") exited with code ");
5863 ui_out_field_fmt (uiout
, "exit-code", "0%o", (unsigned int) exitstatus
);
5864 ui_out_text (uiout
, "]\n");
5868 if (ui_out_is_mi_like_p (uiout
))
5870 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY
));
5871 ui_out_text (uiout
, "[Inferior ");
5872 ui_out_text (uiout
, plongest (inf
->num
));
5873 ui_out_text (uiout
, " (");
5874 ui_out_text (uiout
, pidstr
);
5875 ui_out_text (uiout
, ") exited normally]\n");
5877 /* Support the --return-child-result option. */
5878 return_child_result_value
= exitstatus
;
5881 /* Signal received, print why the inferior has stopped. The signal table
5882 tells us to print about it. */
5885 print_signal_received_reason (enum gdb_signal siggnal
)
5887 struct ui_out
*uiout
= current_uiout
;
5891 if (siggnal
== GDB_SIGNAL_0
&& !ui_out_is_mi_like_p (uiout
))
5893 struct thread_info
*t
= inferior_thread ();
5895 ui_out_text (uiout
, "\n[");
5896 ui_out_field_string (uiout
, "thread-name",
5897 target_pid_to_str (t
->ptid
));
5898 ui_out_field_fmt (uiout
, "thread-id", "] #%d", t
->num
);
5899 ui_out_text (uiout
, " stopped");
5903 ui_out_text (uiout
, "\nProgram received signal ");
5904 annotate_signal_name ();
5905 if (ui_out_is_mi_like_p (uiout
))
5907 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED
));
5908 ui_out_field_string (uiout
, "signal-name",
5909 gdb_signal_to_name (siggnal
));
5910 annotate_signal_name_end ();
5911 ui_out_text (uiout
, ", ");
5912 annotate_signal_string ();
5913 ui_out_field_string (uiout
, "signal-meaning",
5914 gdb_signal_to_string (siggnal
));
5915 annotate_signal_string_end ();
5917 ui_out_text (uiout
, ".\n");
5920 /* Reverse execution: target ran out of history info, print why the inferior
5924 print_no_history_reason (void)
5926 ui_out_text (current_uiout
, "\nNo more reverse-execution history.\n");
5929 /* Here to return control to GDB when the inferior stops for real.
5930 Print appropriate messages, remove breakpoints, give terminal our modes.
5932 STOP_PRINT_FRAME nonzero means print the executing frame
5933 (pc, function, args, file, line number and line text).
5934 BREAKPOINTS_FAILED nonzero means stop was due to error
5935 attempting to insert breakpoints. */
5940 struct target_waitstatus last
;
5942 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
5944 get_last_target_status (&last_ptid
, &last
);
5946 /* If an exception is thrown from this point on, make sure to
5947 propagate GDB's knowledge of the executing state to the
5948 frontend/user running state. A QUIT is an easy exception to see
5949 here, so do this before any filtered output. */
5951 make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
5952 else if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
5953 && last
.kind
!= TARGET_WAITKIND_EXITED
5954 && last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
5955 make_cleanup (finish_thread_state_cleanup
, &inferior_ptid
);
5957 /* In non-stop mode, we don't want GDB to switch threads behind the
5958 user's back, to avoid races where the user is typing a command to
5959 apply to thread x, but GDB switches to thread y before the user
5960 finishes entering the command. */
5962 /* As with the notification of thread events, we want to delay
5963 notifying the user that we've switched thread context until
5964 the inferior actually stops.
5966 There's no point in saying anything if the inferior has exited.
5967 Note that SIGNALLED here means "exited with a signal", not
5968 "received a signal". */
5970 && !ptid_equal (previous_inferior_ptid
, inferior_ptid
)
5971 && target_has_execution
5972 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
5973 && last
.kind
!= TARGET_WAITKIND_EXITED
5974 && last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
5976 target_terminal_ours_for_output ();
5977 printf_filtered (_("[Switching to %s]\n"),
5978 target_pid_to_str (inferior_ptid
));
5979 annotate_thread_changed ();
5980 previous_inferior_ptid
= inferior_ptid
;
5983 if (last
.kind
== TARGET_WAITKIND_NO_RESUMED
)
5985 gdb_assert (sync_execution
|| !target_can_async_p ());
5987 target_terminal_ours_for_output ();
5988 printf_filtered (_("No unwaited-for children left.\n"));
5991 if (!breakpoints_always_inserted_mode () && target_has_execution
)
5993 if (remove_breakpoints ())
5995 target_terminal_ours_for_output ();
5996 printf_filtered (_("Cannot remove breakpoints because "
5997 "program is no longer writable.\nFurther "
5998 "execution is probably impossible.\n"));
6002 /* If an auto-display called a function and that got a signal,
6003 delete that auto-display to avoid an infinite recursion. */
6005 if (stopped_by_random_signal
)
6006 disable_current_display ();
6008 /* Don't print a message if in the middle of doing a "step n"
6009 operation for n > 1 */
6010 if (target_has_execution
6011 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
6012 && last
.kind
!= TARGET_WAITKIND_EXITED
6013 && inferior_thread ()->step_multi
6014 && inferior_thread ()->control
.stop_step
)
6017 target_terminal_ours ();
6018 async_enable_stdin ();
6020 /* Set the current source location. This will also happen if we
6021 display the frame below, but the current SAL will be incorrect
6022 during a user hook-stop function. */
6023 if (has_stack_frames () && !stop_stack_dummy
)
6024 set_current_sal_from_frame (get_current_frame (), 1);
6026 /* Let the user/frontend see the threads as stopped. */
6027 do_cleanups (old_chain
);
6029 /* Look up the hook_stop and run it (CLI internally handles problem
6030 of stop_command's pre-hook not existing). */
6032 catch_errors (hook_stop_stub
, stop_command
,
6033 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
6035 if (!has_stack_frames ())
6038 if (last
.kind
== TARGET_WAITKIND_SIGNALLED
6039 || last
.kind
== TARGET_WAITKIND_EXITED
)
6042 /* Select innermost stack frame - i.e., current frame is frame 0,
6043 and current location is based on that.
6044 Don't do this on return from a stack dummy routine,
6045 or if the program has exited. */
6047 if (!stop_stack_dummy
)
6049 select_frame (get_current_frame ());
6051 /* Print current location without a level number, if
6052 we have changed functions or hit a breakpoint.
6053 Print source line if we have one.
6054 bpstat_print() contains the logic deciding in detail
6055 what to print, based on the event(s) that just occurred. */
6057 /* If --batch-silent is enabled then there's no need to print the current
6058 source location, and to try risks causing an error message about
6059 missing source files. */
6060 if (stop_print_frame
&& !batch_silent
)
6064 int do_frame_printing
= 1;
6065 struct thread_info
*tp
= inferior_thread ();
6067 bpstat_ret
= bpstat_print (tp
->control
.stop_bpstat
, last
.kind
);
6071 /* FIXME: cagney/2002-12-01: Given that a frame ID does
6072 (or should) carry around the function and does (or
6073 should) use that when doing a frame comparison. */
6074 if (tp
->control
.stop_step
6075 && frame_id_eq (tp
->control
.step_frame_id
,
6076 get_frame_id (get_current_frame ()))
6077 && step_start_function
== find_pc_function (stop_pc
))
6078 source_flag
= SRC_LINE
; /* Finished step, just
6079 print source line. */
6081 source_flag
= SRC_AND_LOC
; /* Print location and
6084 case PRINT_SRC_AND_LOC
:
6085 source_flag
= SRC_AND_LOC
; /* Print location and
6088 case PRINT_SRC_ONLY
:
6089 source_flag
= SRC_LINE
;
6092 source_flag
= SRC_LINE
; /* something bogus */
6093 do_frame_printing
= 0;
6096 internal_error (__FILE__
, __LINE__
, _("Unknown value."));
6099 /* The behavior of this routine with respect to the source
6101 SRC_LINE: Print only source line
6102 LOCATION: Print only location
6103 SRC_AND_LOC: Print location and source line. */
6104 if (do_frame_printing
)
6105 print_stack_frame (get_selected_frame (NULL
), 0, source_flag
, 1);
6107 /* Display the auto-display expressions. */
6112 /* Save the function value return registers, if we care.
6113 We might be about to restore their previous contents. */
6114 if (inferior_thread ()->control
.proceed_to_finish
6115 && execution_direction
!= EXEC_REVERSE
)
6117 /* This should not be necessary. */
6119 regcache_xfree (stop_registers
);
6121 /* NB: The copy goes through to the target picking up the value of
6122 all the registers. */
6123 stop_registers
= regcache_dup (get_current_regcache ());
6126 if (stop_stack_dummy
== STOP_STACK_DUMMY
)
6128 /* Pop the empty frame that contains the stack dummy.
6129 This also restores inferior state prior to the call
6130 (struct infcall_suspend_state). */
6131 struct frame_info
*frame
= get_current_frame ();
6133 gdb_assert (get_frame_type (frame
) == DUMMY_FRAME
);
6135 /* frame_pop() calls reinit_frame_cache as the last thing it
6136 does which means there's currently no selected frame. We
6137 don't need to re-establish a selected frame if the dummy call
6138 returns normally, that will be done by
6139 restore_infcall_control_state. However, we do have to handle
6140 the case where the dummy call is returning after being
6141 stopped (e.g. the dummy call previously hit a breakpoint).
6142 We can't know which case we have so just always re-establish
6143 a selected frame here. */
6144 select_frame (get_current_frame ());
6148 annotate_stopped ();
6150 /* Suppress the stop observer if we're in the middle of:
6152 - a step n (n > 1), as there still more steps to be done.
6154 - a "finish" command, as the observer will be called in
6155 finish_command_continuation, so it can include the inferior
6156 function's return value.
6158 - calling an inferior function, as we pretend we inferior didn't
6159 run at all. The return value of the call is handled by the
6160 expression evaluator, through call_function_by_hand. */
6162 if (!target_has_execution
6163 || last
.kind
== TARGET_WAITKIND_SIGNALLED
6164 || last
.kind
== TARGET_WAITKIND_EXITED
6165 || last
.kind
== TARGET_WAITKIND_NO_RESUMED
6166 || (!(inferior_thread ()->step_multi
6167 && inferior_thread ()->control
.stop_step
)
6168 && !(inferior_thread ()->control
.stop_bpstat
6169 && inferior_thread ()->control
.proceed_to_finish
)
6170 && !inferior_thread ()->control
.in_infcall
))
6172 if (!ptid_equal (inferior_ptid
, null_ptid
))
6173 observer_notify_normal_stop (inferior_thread ()->control
.stop_bpstat
,
6176 observer_notify_normal_stop (NULL
, stop_print_frame
);
6179 if (target_has_execution
)
6181 if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
6182 && last
.kind
!= TARGET_WAITKIND_EXITED
)
6183 /* Delete the breakpoint we stopped at, if it wants to be deleted.
6184 Delete any breakpoint that is to be deleted at the next stop. */
6185 breakpoint_auto_delete (inferior_thread ()->control
.stop_bpstat
);
6188 /* Try to get rid of automatically added inferiors that are no
6189 longer needed. Keeping those around slows down things linearly.
6190 Note that this never removes the current inferior. */
6195 hook_stop_stub (void *cmd
)
6197 execute_cmd_pre_hook ((struct cmd_list_element
*) cmd
);
6202 signal_stop_state (int signo
)
6204 return signal_stop
[signo
];
6208 signal_print_state (int signo
)
6210 return signal_print
[signo
];
6214 signal_pass_state (int signo
)
6216 return signal_program
[signo
];
6220 signal_cache_update (int signo
)
6224 for (signo
= 0; signo
< (int) GDB_SIGNAL_LAST
; signo
++)
6225 signal_cache_update (signo
);
6230 signal_pass
[signo
] = (signal_stop
[signo
] == 0
6231 && signal_print
[signo
] == 0
6232 && signal_program
[signo
] == 1
6233 && signal_catch
[signo
] == 0);
6237 signal_stop_update (int signo
, int state
)
6239 int ret
= signal_stop
[signo
];
6241 signal_stop
[signo
] = state
;
6242 signal_cache_update (signo
);
6247 signal_print_update (int signo
, int state
)
6249 int ret
= signal_print
[signo
];
6251 signal_print
[signo
] = state
;
6252 signal_cache_update (signo
);
6257 signal_pass_update (int signo
, int state
)
6259 int ret
= signal_program
[signo
];
6261 signal_program
[signo
] = state
;
6262 signal_cache_update (signo
);
6266 /* Update the global 'signal_catch' from INFO and notify the
6270 signal_catch_update (const unsigned int *info
)
6274 for (i
= 0; i
< GDB_SIGNAL_LAST
; ++i
)
6275 signal_catch
[i
] = info
[i
] > 0;
6276 signal_cache_update (-1);
6277 target_pass_signals ((int) GDB_SIGNAL_LAST
, signal_pass
);
6281 sig_print_header (void)
6283 printf_filtered (_("Signal Stop\tPrint\tPass "
6284 "to program\tDescription\n"));
6288 sig_print_info (enum gdb_signal oursig
)
6290 const char *name
= gdb_signal_to_name (oursig
);
6291 int name_padding
= 13 - strlen (name
);
6293 if (name_padding
<= 0)
6296 printf_filtered ("%s", name
);
6297 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
6298 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
6299 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
6300 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
6301 printf_filtered ("%s\n", gdb_signal_to_string (oursig
));
6304 /* Specify how various signals in the inferior should be handled. */
6307 handle_command (char *args
, int from_tty
)
6310 int digits
, wordlen
;
6311 int sigfirst
, signum
, siglast
;
6312 enum gdb_signal oursig
;
6315 unsigned char *sigs
;
6316 struct cleanup
*old_chain
;
6320 error_no_arg (_("signal to handle"));
6323 /* Allocate and zero an array of flags for which signals to handle. */
6325 nsigs
= (int) GDB_SIGNAL_LAST
;
6326 sigs
= (unsigned char *) alloca (nsigs
);
6327 memset (sigs
, 0, nsigs
);
6329 /* Break the command line up into args. */
6331 argv
= gdb_buildargv (args
);
6332 old_chain
= make_cleanup_freeargv (argv
);
6334 /* Walk through the args, looking for signal oursigs, signal names, and
6335 actions. Signal numbers and signal names may be interspersed with
6336 actions, with the actions being performed for all signals cumulatively
6337 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
6339 while (*argv
!= NULL
)
6341 wordlen
= strlen (*argv
);
6342 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
6346 sigfirst
= siglast
= -1;
6348 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
6350 /* Apply action to all signals except those used by the
6351 debugger. Silently skip those. */
6354 siglast
= nsigs
- 1;
6356 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
6358 SET_SIGS (nsigs
, sigs
, signal_stop
);
6359 SET_SIGS (nsigs
, sigs
, signal_print
);
6361 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
6363 UNSET_SIGS (nsigs
, sigs
, signal_program
);
6365 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
6367 SET_SIGS (nsigs
, sigs
, signal_print
);
6369 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
6371 SET_SIGS (nsigs
, sigs
, signal_program
);
6373 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
6375 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
6377 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
6379 SET_SIGS (nsigs
, sigs
, signal_program
);
6381 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
6383 UNSET_SIGS (nsigs
, sigs
, signal_print
);
6384 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
6386 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
6388 UNSET_SIGS (nsigs
, sigs
, signal_program
);
6390 else if (digits
> 0)
6392 /* It is numeric. The numeric signal refers to our own
6393 internal signal numbering from target.h, not to host/target
6394 signal number. This is a feature; users really should be
6395 using symbolic names anyway, and the common ones like
6396 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
6398 sigfirst
= siglast
= (int)
6399 gdb_signal_from_command (atoi (*argv
));
6400 if ((*argv
)[digits
] == '-')
6403 gdb_signal_from_command (atoi ((*argv
) + digits
+ 1));
6405 if (sigfirst
> siglast
)
6407 /* Bet he didn't figure we'd think of this case... */
6415 oursig
= gdb_signal_from_name (*argv
);
6416 if (oursig
!= GDB_SIGNAL_UNKNOWN
)
6418 sigfirst
= siglast
= (int) oursig
;
6422 /* Not a number and not a recognized flag word => complain. */
6423 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv
);
6427 /* If any signal numbers or symbol names were found, set flags for
6428 which signals to apply actions to. */
6430 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
6432 switch ((enum gdb_signal
) signum
)
6434 case GDB_SIGNAL_TRAP
:
6435 case GDB_SIGNAL_INT
:
6436 if (!allsigs
&& !sigs
[signum
])
6438 if (query (_("%s is used by the debugger.\n\
6439 Are you sure you want to change it? "),
6440 gdb_signal_to_name ((enum gdb_signal
) signum
)))
6446 printf_unfiltered (_("Not confirmed, unchanged.\n"));
6447 gdb_flush (gdb_stdout
);
6452 case GDB_SIGNAL_DEFAULT
:
6453 case GDB_SIGNAL_UNKNOWN
:
6454 /* Make sure that "all" doesn't print these. */
6465 for (signum
= 0; signum
< nsigs
; signum
++)
6468 signal_cache_update (-1);
6469 target_pass_signals ((int) GDB_SIGNAL_LAST
, signal_pass
);
6470 target_program_signals ((int) GDB_SIGNAL_LAST
, signal_program
);
6474 /* Show the results. */
6475 sig_print_header ();
6476 for (; signum
< nsigs
; signum
++)
6478 sig_print_info (signum
);
6484 do_cleanups (old_chain
);
6487 /* Complete the "handle" command. */
6489 static VEC (char_ptr
) *
6490 handle_completer (struct cmd_list_element
*ignore
,
6491 const char *text
, const char *word
)
6493 VEC (char_ptr
) *vec_signals
, *vec_keywords
, *return_val
;
6494 static const char * const keywords
[] =
6508 vec_signals
= signal_completer (ignore
, text
, word
);
6509 vec_keywords
= complete_on_enum (keywords
, word
, word
);
6511 return_val
= VEC_merge (char_ptr
, vec_signals
, vec_keywords
);
6512 VEC_free (char_ptr
, vec_signals
);
6513 VEC_free (char_ptr
, vec_keywords
);
6518 xdb_handle_command (char *args
, int from_tty
)
6521 struct cleanup
*old_chain
;
6524 error_no_arg (_("xdb command"));
6526 /* Break the command line up into args. */
6528 argv
= gdb_buildargv (args
);
6529 old_chain
= make_cleanup_freeargv (argv
);
6530 if (argv
[1] != (char *) NULL
)
6535 bufLen
= strlen (argv
[0]) + 20;
6536 argBuf
= (char *) xmalloc (bufLen
);
6540 enum gdb_signal oursig
;
6542 oursig
= gdb_signal_from_name (argv
[0]);
6543 memset (argBuf
, 0, bufLen
);
6544 if (strcmp (argv
[1], "Q") == 0)
6545 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
6548 if (strcmp (argv
[1], "s") == 0)
6550 if (!signal_stop
[oursig
])
6551 sprintf (argBuf
, "%s %s", argv
[0], "stop");
6553 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
6555 else if (strcmp (argv
[1], "i") == 0)
6557 if (!signal_program
[oursig
])
6558 sprintf (argBuf
, "%s %s", argv
[0], "pass");
6560 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
6562 else if (strcmp (argv
[1], "r") == 0)
6564 if (!signal_print
[oursig
])
6565 sprintf (argBuf
, "%s %s", argv
[0], "print");
6567 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
6573 handle_command (argBuf
, from_tty
);
6575 printf_filtered (_("Invalid signal handling flag.\n"));
6580 do_cleanups (old_chain
);
6584 gdb_signal_from_command (int num
)
6586 if (num
>= 1 && num
<= 15)
6587 return (enum gdb_signal
) num
;
6588 error (_("Only signals 1-15 are valid as numeric signals.\n\
6589 Use \"info signals\" for a list of symbolic signals."));
6592 /* Print current contents of the tables set by the handle command.
6593 It is possible we should just be printing signals actually used
6594 by the current target (but for things to work right when switching
6595 targets, all signals should be in the signal tables). */
6598 signals_info (char *signum_exp
, int from_tty
)
6600 enum gdb_signal oursig
;
6602 sig_print_header ();
6606 /* First see if this is a symbol name. */
6607 oursig
= gdb_signal_from_name (signum_exp
);
6608 if (oursig
== GDB_SIGNAL_UNKNOWN
)
6610 /* No, try numeric. */
6612 gdb_signal_from_command (parse_and_eval_long (signum_exp
));
6614 sig_print_info (oursig
);
6618 printf_filtered ("\n");
6619 /* These ugly casts brought to you by the native VAX compiler. */
6620 for (oursig
= GDB_SIGNAL_FIRST
;
6621 (int) oursig
< (int) GDB_SIGNAL_LAST
;
6622 oursig
= (enum gdb_signal
) ((int) oursig
+ 1))
6626 if (oursig
!= GDB_SIGNAL_UNKNOWN
6627 && oursig
!= GDB_SIGNAL_DEFAULT
&& oursig
!= GDB_SIGNAL_0
)
6628 sig_print_info (oursig
);
6631 printf_filtered (_("\nUse the \"handle\" command "
6632 "to change these tables.\n"));
6635 /* Check if it makes sense to read $_siginfo from the current thread
6636 at this point. If not, throw an error. */
6639 validate_siginfo_access (void)
6641 /* No current inferior, no siginfo. */
6642 if (ptid_equal (inferior_ptid
, null_ptid
))
6643 error (_("No thread selected."));
6645 /* Don't try to read from a dead thread. */
6646 if (is_exited (inferior_ptid
))
6647 error (_("The current thread has terminated"));
6649 /* ... or from a spinning thread. */
6650 if (is_running (inferior_ptid
))
6651 error (_("Selected thread is running."));
6654 /* The $_siginfo convenience variable is a bit special. We don't know
6655 for sure the type of the value until we actually have a chance to
6656 fetch the data. The type can change depending on gdbarch, so it is
6657 also dependent on which thread you have selected.
6659 1. making $_siginfo be an internalvar that creates a new value on
6662 2. making the value of $_siginfo be an lval_computed value. */
6664 /* This function implements the lval_computed support for reading a
6668 siginfo_value_read (struct value
*v
)
6670 LONGEST transferred
;
6672 validate_siginfo_access ();
6675 target_read (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
,
6677 value_contents_all_raw (v
),
6679 TYPE_LENGTH (value_type (v
)));
6681 if (transferred
!= TYPE_LENGTH (value_type (v
)))
6682 error (_("Unable to read siginfo"));
6685 /* This function implements the lval_computed support for writing a
6689 siginfo_value_write (struct value
*v
, struct value
*fromval
)
6691 LONGEST transferred
;
6693 validate_siginfo_access ();
6695 transferred
= target_write (¤t_target
,
6696 TARGET_OBJECT_SIGNAL_INFO
,
6698 value_contents_all_raw (fromval
),
6700 TYPE_LENGTH (value_type (fromval
)));
6702 if (transferred
!= TYPE_LENGTH (value_type (fromval
)))
6703 error (_("Unable to write siginfo"));
6706 static const struct lval_funcs siginfo_value_funcs
=
6712 /* Return a new value with the correct type for the siginfo object of
6713 the current thread using architecture GDBARCH. Return a void value
6714 if there's no object available. */
6716 static struct value
*
6717 siginfo_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
,
6720 if (target_has_stack
6721 && !ptid_equal (inferior_ptid
, null_ptid
)
6722 && gdbarch_get_siginfo_type_p (gdbarch
))
6724 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
6726 return allocate_computed_value (type
, &siginfo_value_funcs
, NULL
);
6729 return allocate_value (builtin_type (gdbarch
)->builtin_void
);
6733 /* infcall_suspend_state contains state about the program itself like its
6734 registers and any signal it received when it last stopped.
6735 This state must be restored regardless of how the inferior function call
6736 ends (either successfully, or after it hits a breakpoint or signal)
6737 if the program is to properly continue where it left off. */
6739 struct infcall_suspend_state
6741 struct thread_suspend_state thread_suspend
;
6742 #if 0 /* Currently unused and empty structures are not valid C. */
6743 struct inferior_suspend_state inferior_suspend
;
6748 struct regcache
*registers
;
6750 /* Format of SIGINFO_DATA or NULL if it is not present. */
6751 struct gdbarch
*siginfo_gdbarch
;
6753 /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
6754 TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the
6755 content would be invalid. */
6756 gdb_byte
*siginfo_data
;
6759 struct infcall_suspend_state
*
6760 save_infcall_suspend_state (void)
6762 struct infcall_suspend_state
*inf_state
;
6763 struct thread_info
*tp
= inferior_thread ();
6765 struct inferior
*inf
= current_inferior ();
6767 struct regcache
*regcache
= get_current_regcache ();
6768 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6769 gdb_byte
*siginfo_data
= NULL
;
6771 if (gdbarch_get_siginfo_type_p (gdbarch
))
6773 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
6774 size_t len
= TYPE_LENGTH (type
);
6775 struct cleanup
*back_to
;
6777 siginfo_data
= xmalloc (len
);
6778 back_to
= make_cleanup (xfree
, siginfo_data
);
6780 if (target_read (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
, NULL
,
6781 siginfo_data
, 0, len
) == len
)
6782 discard_cleanups (back_to
);
6785 /* Errors ignored. */
6786 do_cleanups (back_to
);
6787 siginfo_data
= NULL
;
6791 inf_state
= XZALLOC (struct infcall_suspend_state
);
6795 inf_state
->siginfo_gdbarch
= gdbarch
;
6796 inf_state
->siginfo_data
= siginfo_data
;
6799 inf_state
->thread_suspend
= tp
->suspend
;
6800 #if 0 /* Currently unused and empty structures are not valid C. */
6801 inf_state
->inferior_suspend
= inf
->suspend
;
6804 /* run_inferior_call will not use the signal due to its `proceed' call with
6805 GDB_SIGNAL_0 anyway. */
6806 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
6808 inf_state
->stop_pc
= stop_pc
;
6810 inf_state
->registers
= regcache_dup (regcache
);
6815 /* Restore inferior session state to INF_STATE. */
6818 restore_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
6820 struct thread_info
*tp
= inferior_thread ();
6822 struct inferior
*inf
= current_inferior ();
6824 struct regcache
*regcache
= get_current_regcache ();
6825 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6827 tp
->suspend
= inf_state
->thread_suspend
;
6828 #if 0 /* Currently unused and empty structures are not valid C. */
6829 inf
->suspend
= inf_state
->inferior_suspend
;
6832 stop_pc
= inf_state
->stop_pc
;
6834 if (inf_state
->siginfo_gdbarch
== gdbarch
)
6836 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
6838 /* Errors ignored. */
6839 target_write (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
, NULL
,
6840 inf_state
->siginfo_data
, 0, TYPE_LENGTH (type
));
6843 /* The inferior can be gone if the user types "print exit(0)"
6844 (and perhaps other times). */
6845 if (target_has_execution
)
6846 /* NB: The register write goes through to the target. */
6847 regcache_cpy (regcache
, inf_state
->registers
);
6849 discard_infcall_suspend_state (inf_state
);
6853 do_restore_infcall_suspend_state_cleanup (void *state
)
6855 restore_infcall_suspend_state (state
);
6859 make_cleanup_restore_infcall_suspend_state
6860 (struct infcall_suspend_state
*inf_state
)
6862 return make_cleanup (do_restore_infcall_suspend_state_cleanup
, inf_state
);
6866 discard_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
6868 regcache_xfree (inf_state
->registers
);
6869 xfree (inf_state
->siginfo_data
);
6874 get_infcall_suspend_state_regcache (struct infcall_suspend_state
*inf_state
)
6876 return inf_state
->registers
;
6879 /* infcall_control_state contains state regarding gdb's control of the
6880 inferior itself like stepping control. It also contains session state like
6881 the user's currently selected frame. */
6883 struct infcall_control_state
6885 struct thread_control_state thread_control
;
6886 struct inferior_control_state inferior_control
;
6889 enum stop_stack_kind stop_stack_dummy
;
6890 int stopped_by_random_signal
;
6891 int stop_after_trap
;
6893 /* ID if the selected frame when the inferior function call was made. */
6894 struct frame_id selected_frame_id
;
6897 /* Save all of the information associated with the inferior<==>gdb
6900 struct infcall_control_state
*
6901 save_infcall_control_state (void)
6903 struct infcall_control_state
*inf_status
= xmalloc (sizeof (*inf_status
));
6904 struct thread_info
*tp
= inferior_thread ();
6905 struct inferior
*inf
= current_inferior ();
6907 inf_status
->thread_control
= tp
->control
;
6908 inf_status
->inferior_control
= inf
->control
;
6910 tp
->control
.step_resume_breakpoint
= NULL
;
6911 tp
->control
.exception_resume_breakpoint
= NULL
;
6913 /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of
6914 chain. If caller's caller is walking the chain, they'll be happier if we
6915 hand them back the original chain when restore_infcall_control_state is
6917 tp
->control
.stop_bpstat
= bpstat_copy (tp
->control
.stop_bpstat
);
6920 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
6921 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
6922 inf_status
->stop_after_trap
= stop_after_trap
;
6924 inf_status
->selected_frame_id
= get_frame_id (get_selected_frame (NULL
));
6930 restore_selected_frame (void *args
)
6932 struct frame_id
*fid
= (struct frame_id
*) args
;
6933 struct frame_info
*frame
;
6935 frame
= frame_find_by_id (*fid
);
6937 /* If inf_status->selected_frame_id is NULL, there was no previously
6941 warning (_("Unable to restore previously selected frame."));
6945 select_frame (frame
);
6950 /* Restore inferior session state to INF_STATUS. */
6953 restore_infcall_control_state (struct infcall_control_state
*inf_status
)
6955 struct thread_info
*tp
= inferior_thread ();
6956 struct inferior
*inf
= current_inferior ();
6958 if (tp
->control
.step_resume_breakpoint
)
6959 tp
->control
.step_resume_breakpoint
->disposition
= disp_del_at_next_stop
;
6961 if (tp
->control
.exception_resume_breakpoint
)
6962 tp
->control
.exception_resume_breakpoint
->disposition
6963 = disp_del_at_next_stop
;
6965 /* Handle the bpstat_copy of the chain. */
6966 bpstat_clear (&tp
->control
.stop_bpstat
);
6968 tp
->control
= inf_status
->thread_control
;
6969 inf
->control
= inf_status
->inferior_control
;
6972 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
6973 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
6974 stop_after_trap
= inf_status
->stop_after_trap
;
6976 if (target_has_stack
)
6978 /* The point of catch_errors is that if the stack is clobbered,
6979 walking the stack might encounter a garbage pointer and
6980 error() trying to dereference it. */
6982 (restore_selected_frame
, &inf_status
->selected_frame_id
,
6983 "Unable to restore previously selected frame:\n",
6984 RETURN_MASK_ERROR
) == 0)
6985 /* Error in restoring the selected frame. Select the innermost
6987 select_frame (get_current_frame ());
6994 do_restore_infcall_control_state_cleanup (void *sts
)
6996 restore_infcall_control_state (sts
);
7000 make_cleanup_restore_infcall_control_state
7001 (struct infcall_control_state
*inf_status
)
7003 return make_cleanup (do_restore_infcall_control_state_cleanup
, inf_status
);
7007 discard_infcall_control_state (struct infcall_control_state
*inf_status
)
7009 if (inf_status
->thread_control
.step_resume_breakpoint
)
7010 inf_status
->thread_control
.step_resume_breakpoint
->disposition
7011 = disp_del_at_next_stop
;
7013 if (inf_status
->thread_control
.exception_resume_breakpoint
)
7014 inf_status
->thread_control
.exception_resume_breakpoint
->disposition
7015 = disp_del_at_next_stop
;
7017 /* See save_infcall_control_state for info on stop_bpstat. */
7018 bpstat_clear (&inf_status
->thread_control
.stop_bpstat
);
7024 ptid_match (ptid_t ptid
, ptid_t filter
)
7026 if (ptid_equal (filter
, minus_one_ptid
))
7028 if (ptid_is_pid (filter
)
7029 && ptid_get_pid (ptid
) == ptid_get_pid (filter
))
7031 else if (ptid_equal (ptid
, filter
))
7037 /* restore_inferior_ptid() will be used by the cleanup machinery
7038 to restore the inferior_ptid value saved in a call to
7039 save_inferior_ptid(). */
7042 restore_inferior_ptid (void *arg
)
7044 ptid_t
*saved_ptid_ptr
= arg
;
7046 inferior_ptid
= *saved_ptid_ptr
;
7050 /* Save the value of inferior_ptid so that it may be restored by a
7051 later call to do_cleanups(). Returns the struct cleanup pointer
7052 needed for later doing the cleanup. */
7055 save_inferior_ptid (void)
7057 ptid_t
*saved_ptid_ptr
;
7059 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
7060 *saved_ptid_ptr
= inferior_ptid
;
7061 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
7065 /* User interface for reverse debugging:
7066 Set exec-direction / show exec-direction commands
7067 (returns error unless target implements to_set_exec_direction method). */
7069 int execution_direction
= EXEC_FORWARD
;
7070 static const char exec_forward
[] = "forward";
7071 static const char exec_reverse
[] = "reverse";
7072 static const char *exec_direction
= exec_forward
;
7073 static const char *const exec_direction_names
[] = {
7080 set_exec_direction_func (char *args
, int from_tty
,
7081 struct cmd_list_element
*cmd
)
7083 if (target_can_execute_reverse
)
7085 if (!strcmp (exec_direction
, exec_forward
))
7086 execution_direction
= EXEC_FORWARD
;
7087 else if (!strcmp (exec_direction
, exec_reverse
))
7088 execution_direction
= EXEC_REVERSE
;
7092 exec_direction
= exec_forward
;
7093 error (_("Target does not support this operation."));
7098 show_exec_direction_func (struct ui_file
*out
, int from_tty
,
7099 struct cmd_list_element
*cmd
, const char *value
)
7101 switch (execution_direction
) {
7103 fprintf_filtered (out
, _("Forward.\n"));
7106 fprintf_filtered (out
, _("Reverse.\n"));
7109 internal_error (__FILE__
, __LINE__
,
7110 _("bogus execution_direction value: %d"),
7111 (int) execution_direction
);
7116 show_schedule_multiple (struct ui_file
*file
, int from_tty
,
7117 struct cmd_list_element
*c
, const char *value
)
7119 fprintf_filtered (file
, _("Resuming the execution of threads "
7120 "of all processes is %s.\n"), value
);
7123 /* Implementation of `siginfo' variable. */
7125 static const struct internalvar_funcs siginfo_funcs
=
7133 _initialize_infrun (void)
7137 struct cmd_list_element
*c
;
7139 add_info ("signals", signals_info
, _("\
7140 What debugger does when program gets various signals.\n\
7141 Specify a signal as argument to print info on that signal only."));
7142 add_info_alias ("handle", "signals", 0);
7144 c
= add_com ("handle", class_run
, handle_command
, _("\
7145 Specify how to handle signals.\n\
7146 Usage: handle SIGNAL [ACTIONS]\n\
7147 Args are signals and actions to apply to those signals.\n\
7148 If no actions are specified, the current settings for the specified signals\n\
7149 will be displayed instead.\n\
7151 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
7152 from 1-15 are allowed for compatibility with old versions of GDB.\n\
7153 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
7154 The special arg \"all\" is recognized to mean all signals except those\n\
7155 used by the debugger, typically SIGTRAP and SIGINT.\n\
7157 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
7158 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
7159 Stop means reenter debugger if this signal happens (implies print).\n\
7160 Print means print a message if this signal happens.\n\
7161 Pass means let program see this signal; otherwise program doesn't know.\n\
7162 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
7163 Pass and Stop may be combined.\n\
7165 Multiple signals may be specified. Signal numbers and signal names\n\
7166 may be interspersed with actions, with the actions being performed for\n\
7167 all signals cumulatively specified."));
7168 set_cmd_completer (c
, handle_completer
);
7172 add_com ("lz", class_info
, signals_info
, _("\
7173 What debugger does when program gets various signals.\n\
7174 Specify a signal as argument to print info on that signal only."));
7175 add_com ("z", class_run
, xdb_handle_command
, _("\
7176 Specify how to handle a signal.\n\
7177 Args are signals and actions to apply to those signals.\n\
7178 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
7179 from 1-15 are allowed for compatibility with old versions of GDB.\n\
7180 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
7181 The special arg \"all\" is recognized to mean all signals except those\n\
7182 used by the debugger, typically SIGTRAP and SIGINT.\n\
7183 Recognized actions include \"s\" (toggles between stop and nostop),\n\
7184 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
7185 nopass), \"Q\" (noprint)\n\
7186 Stop means reenter debugger if this signal happens (implies print).\n\
7187 Print means print a message if this signal happens.\n\
7188 Pass means let program see this signal; otherwise program doesn't know.\n\
7189 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
7190 Pass and Stop may be combined."));
7194 stop_command
= add_cmd ("stop", class_obscure
,
7195 not_just_help_class_command
, _("\
7196 There is no `stop' command, but you can set a hook on `stop'.\n\
7197 This allows you to set a list of commands to be run each time execution\n\
7198 of the program stops."), &cmdlist
);
7200 add_setshow_zuinteger_cmd ("infrun", class_maintenance
, &debug_infrun
, _("\
7201 Set inferior debugging."), _("\
7202 Show inferior debugging."), _("\
7203 When non-zero, inferior specific debugging is enabled."),
7206 &setdebuglist
, &showdebuglist
);
7208 add_setshow_boolean_cmd ("displaced", class_maintenance
,
7209 &debug_displaced
, _("\
7210 Set displaced stepping debugging."), _("\
7211 Show displaced stepping debugging."), _("\
7212 When non-zero, displaced stepping specific debugging is enabled."),
7214 show_debug_displaced
,
7215 &setdebuglist
, &showdebuglist
);
7217 add_setshow_boolean_cmd ("non-stop", no_class
,
7219 Set whether gdb controls the inferior in non-stop mode."), _("\
7220 Show whether gdb controls the inferior in non-stop mode."), _("\
7221 When debugging a multi-threaded program and this setting is\n\
7222 off (the default, also called all-stop mode), when one thread stops\n\
7223 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
7224 all other threads in the program while you interact with the thread of\n\
7225 interest. When you continue or step a thread, you can allow the other\n\
7226 threads to run, or have them remain stopped, but while you inspect any\n\
7227 thread's state, all threads stop.\n\
7229 In non-stop mode, when one thread stops, other threads can continue\n\
7230 to run freely. You'll be able to step each thread independently,\n\
7231 leave it stopped or free to run as needed."),
7237 numsigs
= (int) GDB_SIGNAL_LAST
;
7238 signal_stop
= (unsigned char *) xmalloc (sizeof (signal_stop
[0]) * numsigs
);
7239 signal_print
= (unsigned char *)
7240 xmalloc (sizeof (signal_print
[0]) * numsigs
);
7241 signal_program
= (unsigned char *)
7242 xmalloc (sizeof (signal_program
[0]) * numsigs
);
7243 signal_catch
= (unsigned char *)
7244 xmalloc (sizeof (signal_catch
[0]) * numsigs
);
7245 signal_pass
= (unsigned char *)
7246 xmalloc (sizeof (signal_program
[0]) * numsigs
);
7247 for (i
= 0; i
< numsigs
; i
++)
7250 signal_print
[i
] = 1;
7251 signal_program
[i
] = 1;
7252 signal_catch
[i
] = 0;
7255 /* Signals caused by debugger's own actions
7256 should not be given to the program afterwards. */
7257 signal_program
[GDB_SIGNAL_TRAP
] = 0;
7258 signal_program
[GDB_SIGNAL_INT
] = 0;
7260 /* Signals that are not errors should not normally enter the debugger. */
7261 signal_stop
[GDB_SIGNAL_ALRM
] = 0;
7262 signal_print
[GDB_SIGNAL_ALRM
] = 0;
7263 signal_stop
[GDB_SIGNAL_VTALRM
] = 0;
7264 signal_print
[GDB_SIGNAL_VTALRM
] = 0;
7265 signal_stop
[GDB_SIGNAL_PROF
] = 0;
7266 signal_print
[GDB_SIGNAL_PROF
] = 0;
7267 signal_stop
[GDB_SIGNAL_CHLD
] = 0;
7268 signal_print
[GDB_SIGNAL_CHLD
] = 0;
7269 signal_stop
[GDB_SIGNAL_IO
] = 0;
7270 signal_print
[GDB_SIGNAL_IO
] = 0;
7271 signal_stop
[GDB_SIGNAL_POLL
] = 0;
7272 signal_print
[GDB_SIGNAL_POLL
] = 0;
7273 signal_stop
[GDB_SIGNAL_URG
] = 0;
7274 signal_print
[GDB_SIGNAL_URG
] = 0;
7275 signal_stop
[GDB_SIGNAL_WINCH
] = 0;
7276 signal_print
[GDB_SIGNAL_WINCH
] = 0;
7277 signal_stop
[GDB_SIGNAL_PRIO
] = 0;
7278 signal_print
[GDB_SIGNAL_PRIO
] = 0;
7280 /* These signals are used internally by user-level thread
7281 implementations. (See signal(5) on Solaris.) Like the above
7282 signals, a healthy program receives and handles them as part of
7283 its normal operation. */
7284 signal_stop
[GDB_SIGNAL_LWP
] = 0;
7285 signal_print
[GDB_SIGNAL_LWP
] = 0;
7286 signal_stop
[GDB_SIGNAL_WAITING
] = 0;
7287 signal_print
[GDB_SIGNAL_WAITING
] = 0;
7288 signal_stop
[GDB_SIGNAL_CANCEL
] = 0;
7289 signal_print
[GDB_SIGNAL_CANCEL
] = 0;
7291 /* Update cached state. */
7292 signal_cache_update (-1);
7294 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support
,
7295 &stop_on_solib_events
, _("\
7296 Set stopping for shared library events."), _("\
7297 Show stopping for shared library events."), _("\
7298 If nonzero, gdb will give control to the user when the dynamic linker\n\
7299 notifies gdb of shared library events. The most common event of interest\n\
7300 to the user would be loading/unloading of a new library."),
7301 set_stop_on_solib_events
,
7302 show_stop_on_solib_events
,
7303 &setlist
, &showlist
);
7305 add_setshow_enum_cmd ("follow-fork-mode", class_run
,
7306 follow_fork_mode_kind_names
,
7307 &follow_fork_mode_string
, _("\
7308 Set debugger response to a program call of fork or vfork."), _("\
7309 Show debugger response to a program call of fork or vfork."), _("\
7310 A fork or vfork creates a new process. follow-fork-mode can be:\n\
7311 parent - the original process is debugged after a fork\n\
7312 child - the new process is debugged after a fork\n\
7313 The unfollowed process will continue to run.\n\
7314 By default, the debugger will follow the parent process."),
7316 show_follow_fork_mode_string
,
7317 &setlist
, &showlist
);
7319 add_setshow_enum_cmd ("follow-exec-mode", class_run
,
7320 follow_exec_mode_names
,
7321 &follow_exec_mode_string
, _("\
7322 Set debugger response to a program call of exec."), _("\
7323 Show debugger response to a program call of exec."), _("\
7324 An exec call replaces the program image of a process.\n\
7326 follow-exec-mode can be:\n\
7328 new - the debugger creates a new inferior and rebinds the process\n\
7329 to this new inferior. The program the process was running before\n\
7330 the exec call can be restarted afterwards by restarting the original\n\
7333 same - the debugger keeps the process bound to the same inferior.\n\
7334 The new executable image replaces the previous executable loaded in\n\
7335 the inferior. Restarting the inferior after the exec call restarts\n\
7336 the executable the process was running after the exec call.\n\
7338 By default, the debugger will use the same inferior."),
7340 show_follow_exec_mode_string
,
7341 &setlist
, &showlist
);
7343 add_setshow_enum_cmd ("scheduler-locking", class_run
,
7344 scheduler_enums
, &scheduler_mode
, _("\
7345 Set mode for locking scheduler during execution."), _("\
7346 Show mode for locking scheduler during execution."), _("\
7347 off == no locking (threads may preempt at any time)\n\
7348 on == full locking (no thread except the current thread may run)\n\
7349 step == scheduler locked during every single-step operation.\n\
7350 In this mode, no other thread may run during a step command.\n\
7351 Other threads may run while stepping over a function call ('next')."),
7352 set_schedlock_func
, /* traps on target vector */
7353 show_scheduler_mode
,
7354 &setlist
, &showlist
);
7356 add_setshow_boolean_cmd ("schedule-multiple", class_run
, &sched_multi
, _("\
7357 Set mode for resuming threads of all processes."), _("\
7358 Show mode for resuming threads of all processes."), _("\
7359 When on, execution commands (such as 'continue' or 'next') resume all\n\
7360 threads of all processes. When off (which is the default), execution\n\
7361 commands only resume the threads of the current process. The set of\n\
7362 threads that are resumed is further refined by the scheduler-locking\n\
7363 mode (see help set scheduler-locking)."),
7365 show_schedule_multiple
,
7366 &setlist
, &showlist
);
7368 add_setshow_boolean_cmd ("step-mode", class_run
, &step_stop_if_no_debug
, _("\
7369 Set mode of the step operation."), _("\
7370 Show mode of the step operation."), _("\
7371 When set, doing a step over a function without debug line information\n\
7372 will stop at the first instruction of that function. Otherwise, the\n\
7373 function is skipped and the step command stops at a different source line."),
7375 show_step_stop_if_no_debug
,
7376 &setlist
, &showlist
);
7378 add_setshow_auto_boolean_cmd ("displaced-stepping", class_run
,
7379 &can_use_displaced_stepping
, _("\
7380 Set debugger's willingness to use displaced stepping."), _("\
7381 Show debugger's willingness to use displaced stepping."), _("\
7382 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
7383 supported by the target architecture. If off, gdb will not use displaced\n\
7384 stepping to step over breakpoints, even if such is supported by the target\n\
7385 architecture. If auto (which is the default), gdb will use displaced stepping\n\
7386 if the target architecture supports it and non-stop mode is active, but will not\n\
7387 use it in all-stop mode (see help set non-stop)."),
7389 show_can_use_displaced_stepping
,
7390 &setlist
, &showlist
);
7392 add_setshow_enum_cmd ("exec-direction", class_run
, exec_direction_names
,
7393 &exec_direction
, _("Set direction of execution.\n\
7394 Options are 'forward' or 'reverse'."),
7395 _("Show direction of execution (forward/reverse)."),
7396 _("Tells gdb whether to execute forward or backward."),
7397 set_exec_direction_func
, show_exec_direction_func
,
7398 &setlist
, &showlist
);
7400 /* Set/show detach-on-fork: user-settable mode. */
7402 add_setshow_boolean_cmd ("detach-on-fork", class_run
, &detach_fork
, _("\
7403 Set whether gdb will detach the child of a fork."), _("\
7404 Show whether gdb will detach the child of a fork."), _("\
7405 Tells gdb whether to detach the child of a fork."),
7406 NULL
, NULL
, &setlist
, &showlist
);
7408 /* Set/show disable address space randomization mode. */
7410 add_setshow_boolean_cmd ("disable-randomization", class_support
,
7411 &disable_randomization
, _("\
7412 Set disabling of debuggee's virtual address space randomization."), _("\
7413 Show disabling of debuggee's virtual address space randomization."), _("\
7414 When this mode is on (which is the default), randomization of the virtual\n\
7415 address space is disabled. Standalone programs run with the randomization\n\
7416 enabled by default on some platforms."),
7417 &set_disable_randomization
,
7418 &show_disable_randomization
,
7419 &setlist
, &showlist
);
7421 /* ptid initializations */
7422 inferior_ptid
= null_ptid
;
7423 target_last_wait_ptid
= minus_one_ptid
;
7425 observer_attach_thread_ptid_changed (infrun_thread_ptid_changed
);
7426 observer_attach_thread_stop_requested (infrun_thread_stop_requested
);
7427 observer_attach_thread_exit (infrun_thread_thread_exit
);
7428 observer_attach_inferior_exit (infrun_inferior_exit
);
7430 /* Explicitly create without lookup, since that tries to create a
7431 value with a void typed value, and when we get here, gdbarch
7432 isn't initialized yet. At this point, we're quite sure there
7433 isn't another convenience variable of the same name. */
7434 create_internalvar_type_lazy ("_siginfo", &siginfo_funcs
, NULL
);
7436 add_setshow_boolean_cmd ("observer", no_class
,
7437 &observer_mode_1
, _("\
7438 Set whether gdb controls the inferior in observer mode."), _("\
7439 Show whether gdb controls the inferior in observer mode."), _("\
7440 In observer mode, GDB can get data from the inferior, but not\n\
7441 affect its execution. Registers and memory may not be changed,\n\
7442 breakpoints may not be set, and the program cannot be interrupted\n\