1 /* Target-struct-independent code to start (run) and stop an inferior
4 Copyright (C) 1986-2014 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 #include "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"
63 #include "target-dcache.h"
65 /* Prototypes for local functions */
67 static void signals_info (char *, int);
69 static void handle_command (char *, int);
71 static void sig_print_info (enum gdb_signal
);
73 static void sig_print_header (void);
75 static void resume_cleanups (void *);
77 static int hook_stop_stub (void *);
79 static int restore_selected_frame (void *);
81 static int follow_fork (void);
83 static void set_schedlock_func (char *args
, int from_tty
,
84 struct cmd_list_element
*c
);
86 static int currently_stepping (struct thread_info
*tp
);
88 static void xdb_handle_command (char *args
, int from_tty
);
90 static void print_exited_reason (int exitstatus
);
92 static void print_signal_exited_reason (enum gdb_signal siggnal
);
94 static void print_no_history_reason (void);
96 static void print_signal_received_reason (enum gdb_signal siggnal
);
98 static void print_end_stepping_range_reason (void);
100 void _initialize_infrun (void);
102 void nullify_last_target_wait_ptid (void);
104 static void insert_hp_step_resume_breakpoint_at_frame (struct frame_info
*);
106 static void insert_step_resume_breakpoint_at_caller (struct frame_info
*);
108 static void insert_longjmp_resume_breakpoint (struct gdbarch
*, CORE_ADDR
);
110 /* When set, stop the 'step' command if we enter a function which has
111 no line number information. The normal behavior is that we step
112 over such function. */
113 int step_stop_if_no_debug
= 0;
115 show_step_stop_if_no_debug (struct ui_file
*file
, int from_tty
,
116 struct cmd_list_element
*c
, const char *value
)
118 fprintf_filtered (file
, _("Mode of the step operation is %s.\n"), value
);
121 /* In asynchronous mode, but simulating synchronous execution. */
123 int sync_execution
= 0;
125 /* proceed and normal_stop use this to notify the user when the
126 inferior stopped in a different thread than it had been running
129 static ptid_t previous_inferior_ptid
;
131 /* If set (default for legacy reasons), when following a fork, GDB
132 will detach from one of the fork branches, child or parent.
133 Exactly which branch is detached depends on 'set follow-fork-mode'
136 static int detach_fork
= 1;
138 int debug_displaced
= 0;
140 show_debug_displaced (struct ui_file
*file
, int from_tty
,
141 struct cmd_list_element
*c
, const char *value
)
143 fprintf_filtered (file
, _("Displace stepping debugging is %s.\n"), value
);
146 unsigned int debug_infrun
= 0;
148 show_debug_infrun (struct ui_file
*file
, int from_tty
,
149 struct cmd_list_element
*c
, const char *value
)
151 fprintf_filtered (file
, _("Inferior debugging is %s.\n"), value
);
155 /* Support for disabling address space randomization. */
157 int disable_randomization
= 1;
160 show_disable_randomization (struct ui_file
*file
, int from_tty
,
161 struct cmd_list_element
*c
, const char *value
)
163 if (target_supports_disable_randomization ())
164 fprintf_filtered (file
,
165 _("Disabling randomization of debuggee's "
166 "virtual address space is %s.\n"),
169 fputs_filtered (_("Disabling randomization of debuggee's "
170 "virtual address space is unsupported on\n"
171 "this platform.\n"), file
);
175 set_disable_randomization (char *args
, int from_tty
,
176 struct cmd_list_element
*c
)
178 if (!target_supports_disable_randomization ())
179 error (_("Disabling randomization of debuggee's "
180 "virtual address space is unsupported on\n"
184 /* User interface for non-stop mode. */
187 static int non_stop_1
= 0;
190 set_non_stop (char *args
, int from_tty
,
191 struct cmd_list_element
*c
)
193 if (target_has_execution
)
195 non_stop_1
= non_stop
;
196 error (_("Cannot change this setting while the inferior is running."));
199 non_stop
= non_stop_1
;
203 show_non_stop (struct ui_file
*file
, int from_tty
,
204 struct cmd_list_element
*c
, const char *value
)
206 fprintf_filtered (file
,
207 _("Controlling the inferior in non-stop mode is %s.\n"),
211 /* "Observer mode" is somewhat like a more extreme version of
212 non-stop, in which all GDB operations that might affect the
213 target's execution have been disabled. */
215 int observer_mode
= 0;
216 static int observer_mode_1
= 0;
219 set_observer_mode (char *args
, int from_tty
,
220 struct cmd_list_element
*c
)
222 if (target_has_execution
)
224 observer_mode_1
= observer_mode
;
225 error (_("Cannot change this setting while the inferior is running."));
228 observer_mode
= observer_mode_1
;
230 may_write_registers
= !observer_mode
;
231 may_write_memory
= !observer_mode
;
232 may_insert_breakpoints
= !observer_mode
;
233 may_insert_tracepoints
= !observer_mode
;
234 /* We can insert fast tracepoints in or out of observer mode,
235 but enable them if we're going into this mode. */
237 may_insert_fast_tracepoints
= 1;
238 may_stop
= !observer_mode
;
239 update_target_permissions ();
241 /* Going *into* observer mode we must force non-stop, then
242 going out we leave it that way. */
245 target_async_permitted
= 1;
246 pagination_enabled
= 0;
247 non_stop
= non_stop_1
= 1;
251 printf_filtered (_("Observer mode is now %s.\n"),
252 (observer_mode
? "on" : "off"));
256 show_observer_mode (struct ui_file
*file
, int from_tty
,
257 struct cmd_list_element
*c
, const char *value
)
259 fprintf_filtered (file
, _("Observer mode is %s.\n"), value
);
262 /* This updates the value of observer mode based on changes in
263 permissions. Note that we are deliberately ignoring the values of
264 may-write-registers and may-write-memory, since the user may have
265 reason to enable these during a session, for instance to turn on a
266 debugging-related global. */
269 update_observer_mode (void)
273 newval
= (!may_insert_breakpoints
274 && !may_insert_tracepoints
275 && may_insert_fast_tracepoints
279 /* Let the user know if things change. */
280 if (newval
!= observer_mode
)
281 printf_filtered (_("Observer mode is now %s.\n"),
282 (newval
? "on" : "off"));
284 observer_mode
= observer_mode_1
= newval
;
287 /* Tables of how to react to signals; the user sets them. */
289 static unsigned char *signal_stop
;
290 static unsigned char *signal_print
;
291 static unsigned char *signal_program
;
293 /* Table of signals that are registered with "catch signal". A
294 non-zero entry indicates that the signal is caught by some "catch
295 signal" command. This has size GDB_SIGNAL_LAST, to accommodate all
297 static unsigned char *signal_catch
;
299 /* Table of signals that the target may silently handle.
300 This is automatically determined from the flags above,
301 and simply cached here. */
302 static unsigned char *signal_pass
;
304 #define SET_SIGS(nsigs,sigs,flags) \
306 int signum = (nsigs); \
307 while (signum-- > 0) \
308 if ((sigs)[signum]) \
309 (flags)[signum] = 1; \
312 #define UNSET_SIGS(nsigs,sigs,flags) \
314 int signum = (nsigs); \
315 while (signum-- > 0) \
316 if ((sigs)[signum]) \
317 (flags)[signum] = 0; \
320 /* Update the target's copy of SIGNAL_PROGRAM. The sole purpose of
321 this function is to avoid exporting `signal_program'. */
324 update_signals_program_target (void)
326 target_program_signals ((int) GDB_SIGNAL_LAST
, signal_program
);
329 /* Value to pass to target_resume() to cause all threads to resume. */
331 #define RESUME_ALL minus_one_ptid
333 /* Command list pointer for the "stop" placeholder. */
335 static struct cmd_list_element
*stop_command
;
337 /* Function inferior was in as of last step command. */
339 static struct symbol
*step_start_function
;
341 /* Nonzero if we want to give control to the user when we're notified
342 of shared library events by the dynamic linker. */
343 int stop_on_solib_events
;
345 /* Enable or disable optional shared library event breakpoints
346 as appropriate when the above flag is changed. */
349 set_stop_on_solib_events (char *args
, int from_tty
, struct cmd_list_element
*c
)
351 update_solib_breakpoints ();
355 show_stop_on_solib_events (struct ui_file
*file
, int from_tty
,
356 struct cmd_list_element
*c
, const char *value
)
358 fprintf_filtered (file
, _("Stopping for shared library events is %s.\n"),
362 /* Nonzero means expecting a trace trap
363 and should stop the inferior and return silently when it happens. */
367 /* Save register contents here when executing a "finish" command or are
368 about to pop a stack dummy frame, if-and-only-if proceed_to_finish is set.
369 Thus this contains the return value from the called function (assuming
370 values are returned in a register). */
372 struct regcache
*stop_registers
;
374 /* Nonzero after stop if current stack frame should be printed. */
376 static int stop_print_frame
;
378 /* This is a cached copy of the pid/waitstatus of the last event
379 returned by target_wait()/deprecated_target_wait_hook(). This
380 information is returned by get_last_target_status(). */
381 static ptid_t target_last_wait_ptid
;
382 static struct target_waitstatus target_last_waitstatus
;
384 static void context_switch (ptid_t ptid
);
386 void init_thread_stepping_state (struct thread_info
*tss
);
388 static void init_infwait_state (void);
390 static const char follow_fork_mode_child
[] = "child";
391 static const char follow_fork_mode_parent
[] = "parent";
393 static const char *const follow_fork_mode_kind_names
[] = {
394 follow_fork_mode_child
,
395 follow_fork_mode_parent
,
399 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
401 show_follow_fork_mode_string (struct ui_file
*file
, int from_tty
,
402 struct cmd_list_element
*c
, const char *value
)
404 fprintf_filtered (file
,
405 _("Debugger response to a program "
406 "call of fork or vfork is \"%s\".\n"),
411 /* Tell the target to follow the fork we're stopped at. Returns true
412 if the inferior should be resumed; false, if the target for some
413 reason decided it's best not to resume. */
418 int follow_child
= (follow_fork_mode_string
== follow_fork_mode_child
);
419 int should_resume
= 1;
420 struct thread_info
*tp
;
422 /* Copy user stepping state to the new inferior thread. FIXME: the
423 followed fork child thread should have a copy of most of the
424 parent thread structure's run control related fields, not just these.
425 Initialized to avoid "may be used uninitialized" warnings from gcc. */
426 struct breakpoint
*step_resume_breakpoint
= NULL
;
427 struct breakpoint
*exception_resume_breakpoint
= NULL
;
428 CORE_ADDR step_range_start
= 0;
429 CORE_ADDR step_range_end
= 0;
430 struct frame_id step_frame_id
= { 0 };
431 struct interp
*command_interp
= NULL
;
436 struct target_waitstatus wait_status
;
438 /* Get the last target status returned by target_wait(). */
439 get_last_target_status (&wait_ptid
, &wait_status
);
441 /* If not stopped at a fork event, then there's nothing else to
443 if (wait_status
.kind
!= TARGET_WAITKIND_FORKED
444 && wait_status
.kind
!= TARGET_WAITKIND_VFORKED
)
447 /* Check if we switched over from WAIT_PTID, since the event was
449 if (!ptid_equal (wait_ptid
, minus_one_ptid
)
450 && !ptid_equal (inferior_ptid
, wait_ptid
))
452 /* We did. Switch back to WAIT_PTID thread, to tell the
453 target to follow it (in either direction). We'll
454 afterwards refuse to resume, and inform the user what
456 switch_to_thread (wait_ptid
);
461 tp
= inferior_thread ();
463 /* If there were any forks/vforks that were caught and are now to be
464 followed, then do so now. */
465 switch (tp
->pending_follow
.kind
)
467 case TARGET_WAITKIND_FORKED
:
468 case TARGET_WAITKIND_VFORKED
:
470 ptid_t parent
, child
;
472 /* If the user did a next/step, etc, over a fork call,
473 preserve the stepping state in the fork child. */
474 if (follow_child
&& should_resume
)
476 step_resume_breakpoint
= clone_momentary_breakpoint
477 (tp
->control
.step_resume_breakpoint
);
478 step_range_start
= tp
->control
.step_range_start
;
479 step_range_end
= tp
->control
.step_range_end
;
480 step_frame_id
= tp
->control
.step_frame_id
;
481 exception_resume_breakpoint
482 = clone_momentary_breakpoint (tp
->control
.exception_resume_breakpoint
);
483 command_interp
= tp
->control
.command_interp
;
485 /* For now, delete the parent's sr breakpoint, otherwise,
486 parent/child sr breakpoints are considered duplicates,
487 and the child version will not be installed. Remove
488 this when the breakpoints module becomes aware of
489 inferiors and address spaces. */
490 delete_step_resume_breakpoint (tp
);
491 tp
->control
.step_range_start
= 0;
492 tp
->control
.step_range_end
= 0;
493 tp
->control
.step_frame_id
= null_frame_id
;
494 delete_exception_resume_breakpoint (tp
);
495 tp
->control
.command_interp
= NULL
;
498 parent
= inferior_ptid
;
499 child
= tp
->pending_follow
.value
.related_pid
;
501 /* Tell the target to do whatever is necessary to follow
502 either parent or child. */
503 if (target_follow_fork (follow_child
, detach_fork
))
505 /* Target refused to follow, or there's some other reason
506 we shouldn't resume. */
511 /* This pending follow fork event is now handled, one way
512 or another. The previous selected thread may be gone
513 from the lists by now, but if it is still around, need
514 to clear the pending follow request. */
515 tp
= find_thread_ptid (parent
);
517 tp
->pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
519 /* This makes sure we don't try to apply the "Switched
520 over from WAIT_PID" logic above. */
521 nullify_last_target_wait_ptid ();
523 /* If we followed the child, switch to it... */
526 switch_to_thread (child
);
528 /* ... and preserve the stepping state, in case the
529 user was stepping over the fork call. */
532 tp
= inferior_thread ();
533 tp
->control
.step_resume_breakpoint
534 = step_resume_breakpoint
;
535 tp
->control
.step_range_start
= step_range_start
;
536 tp
->control
.step_range_end
= step_range_end
;
537 tp
->control
.step_frame_id
= step_frame_id
;
538 tp
->control
.exception_resume_breakpoint
539 = exception_resume_breakpoint
;
540 tp
->control
.command_interp
= command_interp
;
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 /* Info about an instruction that is being stepped over. Invalid if
977 struct step_over_info
979 /* The instruction's address space. */
980 struct address_space
*aspace
;
982 /* The instruction's address. */
986 /* The step-over info of the location that is being stepped over.
988 Note that with async/breakpoint always-inserted mode, a user might
989 set a new breakpoint/watchpoint/etc. exactly while a breakpoint is
990 being stepped over. As setting a new breakpoint inserts all
991 breakpoints, we need to make sure the breakpoint being stepped over
992 isn't inserted then. We do that by only clearing the step-over
993 info when the step-over is actually finished (or aborted).
995 Presently GDB can only step over one breakpoint at any given time.
996 Given threads that can't run code in the same address space as the
997 breakpoint's can't really miss the breakpoint, GDB could be taught
998 to step-over at most one breakpoint per address space (so this info
999 could move to the address space object if/when GDB is extended).
1000 The set of breakpoints being stepped over will normally be much
1001 smaller than the set of all breakpoints, so a flag in the
1002 breakpoint location structure would be wasteful. A separate list
1003 also saves complexity and run-time, as otherwise we'd have to go
1004 through all breakpoint locations clearing their flag whenever we
1005 start a new sequence. Similar considerations weigh against storing
1006 this info in the thread object. Plus, not all step overs actually
1007 have breakpoint locations -- e.g., stepping past a single-step
1008 breakpoint, or stepping to complete a non-continuable
1010 static struct step_over_info step_over_info
;
1012 /* Record the address of the breakpoint/instruction we're currently
1016 set_step_over_info (struct address_space
*aspace
, CORE_ADDR address
)
1018 step_over_info
.aspace
= aspace
;
1019 step_over_info
.address
= address
;
1022 /* Called when we're not longer stepping over a breakpoint / an
1023 instruction, so all breakpoints are free to be (re)inserted. */
1026 clear_step_over_info (void)
1028 step_over_info
.aspace
= NULL
;
1029 step_over_info
.address
= 0;
1032 /* See inferior.h. */
1035 stepping_past_instruction_at (struct address_space
*aspace
,
1038 return (step_over_info
.aspace
!= NULL
1039 && breakpoint_address_match (aspace
, address
,
1040 step_over_info
.aspace
,
1041 step_over_info
.address
));
1045 /* Displaced stepping. */
1047 /* In non-stop debugging mode, we must take special care to manage
1048 breakpoints properly; in particular, the traditional strategy for
1049 stepping a thread past a breakpoint it has hit is unsuitable.
1050 'Displaced stepping' is a tactic for stepping one thread past a
1051 breakpoint it has hit while ensuring that other threads running
1052 concurrently will hit the breakpoint as they should.
1054 The traditional way to step a thread T off a breakpoint in a
1055 multi-threaded program in all-stop mode is as follows:
1057 a0) Initially, all threads are stopped, and breakpoints are not
1059 a1) We single-step T, leaving breakpoints uninserted.
1060 a2) We insert breakpoints, and resume all threads.
1062 In non-stop debugging, however, this strategy is unsuitable: we
1063 don't want to have to stop all threads in the system in order to
1064 continue or step T past a breakpoint. Instead, we use displaced
1067 n0) Initially, T is stopped, other threads are running, and
1068 breakpoints are inserted.
1069 n1) We copy the instruction "under" the breakpoint to a separate
1070 location, outside the main code stream, making any adjustments
1071 to the instruction, register, and memory state as directed by
1073 n2) We single-step T over the instruction at its new location.
1074 n3) We adjust the resulting register and memory state as directed
1075 by T's architecture. This includes resetting T's PC to point
1076 back into the main instruction stream.
1079 This approach depends on the following gdbarch methods:
1081 - gdbarch_max_insn_length and gdbarch_displaced_step_location
1082 indicate where to copy the instruction, and how much space must
1083 be reserved there. We use these in step n1.
1085 - gdbarch_displaced_step_copy_insn copies a instruction to a new
1086 address, and makes any necessary adjustments to the instruction,
1087 register contents, and memory. We use this in step n1.
1089 - gdbarch_displaced_step_fixup adjusts registers and memory after
1090 we have successfuly single-stepped the instruction, to yield the
1091 same effect the instruction would have had if we had executed it
1092 at its original address. We use this in step n3.
1094 - gdbarch_displaced_step_free_closure provides cleanup.
1096 The gdbarch_displaced_step_copy_insn and
1097 gdbarch_displaced_step_fixup functions must be written so that
1098 copying an instruction with gdbarch_displaced_step_copy_insn,
1099 single-stepping across the copied instruction, and then applying
1100 gdbarch_displaced_insn_fixup should have the same effects on the
1101 thread's memory and registers as stepping the instruction in place
1102 would have. Exactly which responsibilities fall to the copy and
1103 which fall to the fixup is up to the author of those functions.
1105 See the comments in gdbarch.sh for details.
1107 Note that displaced stepping and software single-step cannot
1108 currently be used in combination, although with some care I think
1109 they could be made to. Software single-step works by placing
1110 breakpoints on all possible subsequent instructions; if the
1111 displaced instruction is a PC-relative jump, those breakpoints
1112 could fall in very strange places --- on pages that aren't
1113 executable, or at addresses that are not proper instruction
1114 boundaries. (We do generally let other threads run while we wait
1115 to hit the software single-step breakpoint, and they might
1116 encounter such a corrupted instruction.) One way to work around
1117 this would be to have gdbarch_displaced_step_copy_insn fully
1118 simulate the effect of PC-relative instructions (and return NULL)
1119 on architectures that use software single-stepping.
1121 In non-stop mode, we can have independent and simultaneous step
1122 requests, so more than one thread may need to simultaneously step
1123 over a breakpoint. The current implementation assumes there is
1124 only one scratch space per process. In this case, we have to
1125 serialize access to the scratch space. If thread A wants to step
1126 over a breakpoint, but we are currently waiting for some other
1127 thread to complete a displaced step, we leave thread A stopped and
1128 place it in the displaced_step_request_queue. Whenever a displaced
1129 step finishes, we pick the next thread in the queue and start a new
1130 displaced step operation on it. See displaced_step_prepare and
1131 displaced_step_fixup for details. */
1133 struct displaced_step_request
1136 struct displaced_step_request
*next
;
1139 /* Per-inferior displaced stepping state. */
1140 struct displaced_step_inferior_state
1142 /* Pointer to next in linked list. */
1143 struct displaced_step_inferior_state
*next
;
1145 /* The process this displaced step state refers to. */
1148 /* A queue of pending displaced stepping requests. One entry per
1149 thread that needs to do a displaced step. */
1150 struct displaced_step_request
*step_request_queue
;
1152 /* If this is not null_ptid, this is the thread carrying out a
1153 displaced single-step in process PID. This thread's state will
1154 require fixing up once it has completed its step. */
1157 /* The architecture the thread had when we stepped it. */
1158 struct gdbarch
*step_gdbarch
;
1160 /* The closure provided gdbarch_displaced_step_copy_insn, to be used
1161 for post-step cleanup. */
1162 struct displaced_step_closure
*step_closure
;
1164 /* The address of the original instruction, and the copy we
1166 CORE_ADDR step_original
, step_copy
;
1168 /* Saved contents of copy area. */
1169 gdb_byte
*step_saved_copy
;
1172 /* The list of states of processes involved in displaced stepping
1174 static struct displaced_step_inferior_state
*displaced_step_inferior_states
;
1176 /* Get the displaced stepping state of process PID. */
1178 static struct displaced_step_inferior_state
*
1179 get_displaced_stepping_state (int pid
)
1181 struct displaced_step_inferior_state
*state
;
1183 for (state
= displaced_step_inferior_states
;
1185 state
= state
->next
)
1186 if (state
->pid
== pid
)
1192 /* Add a new displaced stepping state for process PID to the displaced
1193 stepping state list, or return a pointer to an already existing
1194 entry, if it already exists. Never returns NULL. */
1196 static struct displaced_step_inferior_state
*
1197 add_displaced_stepping_state (int pid
)
1199 struct displaced_step_inferior_state
*state
;
1201 for (state
= displaced_step_inferior_states
;
1203 state
= state
->next
)
1204 if (state
->pid
== pid
)
1207 state
= xcalloc (1, sizeof (*state
));
1209 state
->next
= displaced_step_inferior_states
;
1210 displaced_step_inferior_states
= state
;
1215 /* If inferior is in displaced stepping, and ADDR equals to starting address
1216 of copy area, return corresponding displaced_step_closure. Otherwise,
1219 struct displaced_step_closure
*
1220 get_displaced_step_closure_by_addr (CORE_ADDR addr
)
1222 struct displaced_step_inferior_state
*displaced
1223 = get_displaced_stepping_state (ptid_get_pid (inferior_ptid
));
1225 /* If checking the mode of displaced instruction in copy area. */
1226 if (displaced
&& !ptid_equal (displaced
->step_ptid
, null_ptid
)
1227 && (displaced
->step_copy
== addr
))
1228 return displaced
->step_closure
;
1233 /* Remove the displaced stepping state of process PID. */
1236 remove_displaced_stepping_state (int pid
)
1238 struct displaced_step_inferior_state
*it
, **prev_next_p
;
1240 gdb_assert (pid
!= 0);
1242 it
= displaced_step_inferior_states
;
1243 prev_next_p
= &displaced_step_inferior_states
;
1248 *prev_next_p
= it
->next
;
1253 prev_next_p
= &it
->next
;
1259 infrun_inferior_exit (struct inferior
*inf
)
1261 remove_displaced_stepping_state (inf
->pid
);
1264 /* If ON, and the architecture supports it, GDB will use displaced
1265 stepping to step over breakpoints. If OFF, or if the architecture
1266 doesn't support it, GDB will instead use the traditional
1267 hold-and-step approach. If AUTO (which is the default), GDB will
1268 decide which technique to use to step over breakpoints depending on
1269 which of all-stop or non-stop mode is active --- displaced stepping
1270 in non-stop mode; hold-and-step in all-stop mode. */
1272 static enum auto_boolean can_use_displaced_stepping
= AUTO_BOOLEAN_AUTO
;
1275 show_can_use_displaced_stepping (struct ui_file
*file
, int from_tty
,
1276 struct cmd_list_element
*c
,
1279 if (can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
)
1280 fprintf_filtered (file
,
1281 _("Debugger's willingness to use displaced stepping "
1282 "to step over breakpoints is %s (currently %s).\n"),
1283 value
, non_stop
? "on" : "off");
1285 fprintf_filtered (file
,
1286 _("Debugger's willingness to use displaced stepping "
1287 "to step over breakpoints is %s.\n"), value
);
1290 /* Return non-zero if displaced stepping can/should be used to step
1291 over breakpoints. */
1294 use_displaced_stepping (struct gdbarch
*gdbarch
)
1296 return (((can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
&& non_stop
)
1297 || can_use_displaced_stepping
== AUTO_BOOLEAN_TRUE
)
1298 && gdbarch_displaced_step_copy_insn_p (gdbarch
)
1299 && find_record_target () == NULL
);
1302 /* Clean out any stray displaced stepping state. */
1304 displaced_step_clear (struct displaced_step_inferior_state
*displaced
)
1306 /* Indicate that there is no cleanup pending. */
1307 displaced
->step_ptid
= null_ptid
;
1309 if (displaced
->step_closure
)
1311 gdbarch_displaced_step_free_closure (displaced
->step_gdbarch
,
1312 displaced
->step_closure
);
1313 displaced
->step_closure
= NULL
;
1318 displaced_step_clear_cleanup (void *arg
)
1320 struct displaced_step_inferior_state
*state
= arg
;
1322 displaced_step_clear (state
);
1325 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */
1327 displaced_step_dump_bytes (struct ui_file
*file
,
1328 const gdb_byte
*buf
,
1333 for (i
= 0; i
< len
; i
++)
1334 fprintf_unfiltered (file
, "%02x ", buf
[i
]);
1335 fputs_unfiltered ("\n", file
);
1338 /* Prepare to single-step, using displaced stepping.
1340 Note that we cannot use displaced stepping when we have a signal to
1341 deliver. If we have a signal to deliver and an instruction to step
1342 over, then after the step, there will be no indication from the
1343 target whether the thread entered a signal handler or ignored the
1344 signal and stepped over the instruction successfully --- both cases
1345 result in a simple SIGTRAP. In the first case we mustn't do a
1346 fixup, and in the second case we must --- but we can't tell which.
1347 Comments in the code for 'random signals' in handle_inferior_event
1348 explain how we handle this case instead.
1350 Returns 1 if preparing was successful -- this thread is going to be
1351 stepped now; or 0 if displaced stepping this thread got queued. */
1353 displaced_step_prepare (ptid_t ptid
)
1355 struct cleanup
*old_cleanups
, *ignore_cleanups
;
1356 struct thread_info
*tp
= find_thread_ptid (ptid
);
1357 struct regcache
*regcache
= get_thread_regcache (ptid
);
1358 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1359 CORE_ADDR original
, copy
;
1361 struct displaced_step_closure
*closure
;
1362 struct displaced_step_inferior_state
*displaced
;
1365 /* We should never reach this function if the architecture does not
1366 support displaced stepping. */
1367 gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch
));
1369 /* Disable range stepping while executing in the scratch pad. We
1370 want a single-step even if executing the displaced instruction in
1371 the scratch buffer lands within the stepping range (e.g., a
1373 tp
->control
.may_range_step
= 0;
1375 /* We have to displaced step one thread at a time, as we only have
1376 access to a single scratch space per inferior. */
1378 displaced
= add_displaced_stepping_state (ptid_get_pid (ptid
));
1380 if (!ptid_equal (displaced
->step_ptid
, null_ptid
))
1382 /* Already waiting for a displaced step to finish. Defer this
1383 request and place in queue. */
1384 struct displaced_step_request
*req
, *new_req
;
1386 if (debug_displaced
)
1387 fprintf_unfiltered (gdb_stdlog
,
1388 "displaced: defering step of %s\n",
1389 target_pid_to_str (ptid
));
1391 new_req
= xmalloc (sizeof (*new_req
));
1392 new_req
->ptid
= ptid
;
1393 new_req
->next
= NULL
;
1395 if (displaced
->step_request_queue
)
1397 for (req
= displaced
->step_request_queue
;
1401 req
->next
= new_req
;
1404 displaced
->step_request_queue
= new_req
;
1410 if (debug_displaced
)
1411 fprintf_unfiltered (gdb_stdlog
,
1412 "displaced: stepping %s now\n",
1413 target_pid_to_str (ptid
));
1416 displaced_step_clear (displaced
);
1418 old_cleanups
= save_inferior_ptid ();
1419 inferior_ptid
= ptid
;
1421 original
= regcache_read_pc (regcache
);
1423 copy
= gdbarch_displaced_step_location (gdbarch
);
1424 len
= gdbarch_max_insn_length (gdbarch
);
1426 /* Save the original contents of the copy area. */
1427 displaced
->step_saved_copy
= xmalloc (len
);
1428 ignore_cleanups
= make_cleanup (free_current_contents
,
1429 &displaced
->step_saved_copy
);
1430 status
= target_read_memory (copy
, displaced
->step_saved_copy
, len
);
1432 throw_error (MEMORY_ERROR
,
1433 _("Error accessing memory address %s (%s) for "
1434 "displaced-stepping scratch space."),
1435 paddress (gdbarch
, copy
), safe_strerror (status
));
1436 if (debug_displaced
)
1438 fprintf_unfiltered (gdb_stdlog
, "displaced: saved %s: ",
1439 paddress (gdbarch
, copy
));
1440 displaced_step_dump_bytes (gdb_stdlog
,
1441 displaced
->step_saved_copy
,
1445 closure
= gdbarch_displaced_step_copy_insn (gdbarch
,
1446 original
, copy
, regcache
);
1448 /* We don't support the fully-simulated case at present. */
1449 gdb_assert (closure
);
1451 /* Save the information we need to fix things up if the step
1453 displaced
->step_ptid
= ptid
;
1454 displaced
->step_gdbarch
= gdbarch
;
1455 displaced
->step_closure
= closure
;
1456 displaced
->step_original
= original
;
1457 displaced
->step_copy
= copy
;
1459 make_cleanup (displaced_step_clear_cleanup
, displaced
);
1461 /* Resume execution at the copy. */
1462 regcache_write_pc (regcache
, copy
);
1464 discard_cleanups (ignore_cleanups
);
1466 do_cleanups (old_cleanups
);
1468 if (debug_displaced
)
1469 fprintf_unfiltered (gdb_stdlog
, "displaced: displaced pc to %s\n",
1470 paddress (gdbarch
, copy
));
1476 write_memory_ptid (ptid_t ptid
, CORE_ADDR memaddr
,
1477 const gdb_byte
*myaddr
, int len
)
1479 struct cleanup
*ptid_cleanup
= save_inferior_ptid ();
1481 inferior_ptid
= ptid
;
1482 write_memory (memaddr
, myaddr
, len
);
1483 do_cleanups (ptid_cleanup
);
1486 /* Restore the contents of the copy area for thread PTID. */
1489 displaced_step_restore (struct displaced_step_inferior_state
*displaced
,
1492 ULONGEST len
= gdbarch_max_insn_length (displaced
->step_gdbarch
);
1494 write_memory_ptid (ptid
, displaced
->step_copy
,
1495 displaced
->step_saved_copy
, len
);
1496 if (debug_displaced
)
1497 fprintf_unfiltered (gdb_stdlog
, "displaced: restored %s %s\n",
1498 target_pid_to_str (ptid
),
1499 paddress (displaced
->step_gdbarch
,
1500 displaced
->step_copy
));
1504 displaced_step_fixup (ptid_t event_ptid
, enum gdb_signal signal
)
1506 struct cleanup
*old_cleanups
;
1507 struct displaced_step_inferior_state
*displaced
1508 = get_displaced_stepping_state (ptid_get_pid (event_ptid
));
1510 /* Was any thread of this process doing a displaced step? */
1511 if (displaced
== NULL
)
1514 /* Was this event for the pid we displaced? */
1515 if (ptid_equal (displaced
->step_ptid
, null_ptid
)
1516 || ! ptid_equal (displaced
->step_ptid
, event_ptid
))
1519 old_cleanups
= make_cleanup (displaced_step_clear_cleanup
, displaced
);
1521 displaced_step_restore (displaced
, displaced
->step_ptid
);
1523 /* Did the instruction complete successfully? */
1524 if (signal
== GDB_SIGNAL_TRAP
)
1526 /* Fix up the resulting state. */
1527 gdbarch_displaced_step_fixup (displaced
->step_gdbarch
,
1528 displaced
->step_closure
,
1529 displaced
->step_original
,
1530 displaced
->step_copy
,
1531 get_thread_regcache (displaced
->step_ptid
));
1535 /* Since the instruction didn't complete, all we can do is
1537 struct regcache
*regcache
= get_thread_regcache (event_ptid
);
1538 CORE_ADDR pc
= regcache_read_pc (regcache
);
1540 pc
= displaced
->step_original
+ (pc
- displaced
->step_copy
);
1541 regcache_write_pc (regcache
, pc
);
1544 do_cleanups (old_cleanups
);
1546 displaced
->step_ptid
= null_ptid
;
1548 /* Are there any pending displaced stepping requests? If so, run
1549 one now. Leave the state object around, since we're likely to
1550 need it again soon. */
1551 while (displaced
->step_request_queue
)
1553 struct displaced_step_request
*head
;
1555 struct regcache
*regcache
;
1556 struct gdbarch
*gdbarch
;
1557 CORE_ADDR actual_pc
;
1558 struct address_space
*aspace
;
1560 head
= displaced
->step_request_queue
;
1562 displaced
->step_request_queue
= head
->next
;
1565 context_switch (ptid
);
1567 regcache
= get_thread_regcache (ptid
);
1568 actual_pc
= regcache_read_pc (regcache
);
1569 aspace
= get_regcache_aspace (regcache
);
1571 if (breakpoint_here_p (aspace
, actual_pc
))
1573 if (debug_displaced
)
1574 fprintf_unfiltered (gdb_stdlog
,
1575 "displaced: stepping queued %s now\n",
1576 target_pid_to_str (ptid
));
1578 displaced_step_prepare (ptid
);
1580 gdbarch
= get_regcache_arch (regcache
);
1582 if (debug_displaced
)
1584 CORE_ADDR actual_pc
= regcache_read_pc (regcache
);
1587 fprintf_unfiltered (gdb_stdlog
, "displaced: run %s: ",
1588 paddress (gdbarch
, actual_pc
));
1589 read_memory (actual_pc
, buf
, sizeof (buf
));
1590 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
1593 if (gdbarch_displaced_step_hw_singlestep (gdbarch
,
1594 displaced
->step_closure
))
1595 target_resume (ptid
, 1, GDB_SIGNAL_0
);
1597 target_resume (ptid
, 0, GDB_SIGNAL_0
);
1599 /* Done, we're stepping a thread. */
1605 struct thread_info
*tp
= inferior_thread ();
1607 /* The breakpoint we were sitting under has since been
1609 tp
->control
.trap_expected
= 0;
1611 /* Go back to what we were trying to do. */
1612 step
= currently_stepping (tp
);
1614 if (debug_displaced
)
1615 fprintf_unfiltered (gdb_stdlog
,
1616 "displaced: breakpoint is gone: %s, step(%d)\n",
1617 target_pid_to_str (tp
->ptid
), step
);
1619 target_resume (ptid
, step
, GDB_SIGNAL_0
);
1620 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
1622 /* This request was discarded. See if there's any other
1623 thread waiting for its turn. */
1628 /* Update global variables holding ptids to hold NEW_PTID if they were
1629 holding OLD_PTID. */
1631 infrun_thread_ptid_changed (ptid_t old_ptid
, ptid_t new_ptid
)
1633 struct displaced_step_request
*it
;
1634 struct displaced_step_inferior_state
*displaced
;
1636 if (ptid_equal (inferior_ptid
, old_ptid
))
1637 inferior_ptid
= new_ptid
;
1639 if (ptid_equal (singlestep_ptid
, old_ptid
))
1640 singlestep_ptid
= new_ptid
;
1642 for (displaced
= displaced_step_inferior_states
;
1644 displaced
= displaced
->next
)
1646 if (ptid_equal (displaced
->step_ptid
, old_ptid
))
1647 displaced
->step_ptid
= new_ptid
;
1649 for (it
= displaced
->step_request_queue
; it
; it
= it
->next
)
1650 if (ptid_equal (it
->ptid
, old_ptid
))
1651 it
->ptid
= new_ptid
;
1658 /* Things to clean up if we QUIT out of resume (). */
1660 resume_cleanups (void *ignore
)
1665 static const char schedlock_off
[] = "off";
1666 static const char schedlock_on
[] = "on";
1667 static const char schedlock_step
[] = "step";
1668 static const char *const scheduler_enums
[] = {
1674 static const char *scheduler_mode
= schedlock_off
;
1676 show_scheduler_mode (struct ui_file
*file
, int from_tty
,
1677 struct cmd_list_element
*c
, const char *value
)
1679 fprintf_filtered (file
,
1680 _("Mode for locking scheduler "
1681 "during execution is \"%s\".\n"),
1686 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
1688 if (!target_can_lock_scheduler
)
1690 scheduler_mode
= schedlock_off
;
1691 error (_("Target '%s' cannot support this command."), target_shortname
);
1695 /* True if execution commands resume all threads of all processes by
1696 default; otherwise, resume only threads of the current inferior
1698 int sched_multi
= 0;
1700 /* Try to setup for software single stepping over the specified location.
1701 Return 1 if target_resume() should use hardware single step.
1703 GDBARCH the current gdbarch.
1704 PC the location to step over. */
1707 maybe_software_singlestep (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
1711 if (execution_direction
== EXEC_FORWARD
1712 && gdbarch_software_single_step_p (gdbarch
)
1713 && gdbarch_software_single_step (gdbarch
, get_current_frame ()))
1716 /* Do not pull these breakpoints until after a `wait' in
1717 `wait_for_inferior'. */
1718 singlestep_breakpoints_inserted_p
= 1;
1719 singlestep_ptid
= inferior_ptid
;
1725 /* Return a ptid representing the set of threads that we will proceed,
1726 in the perspective of the user/frontend. We may actually resume
1727 fewer threads at first, e.g., if a thread is stopped at a
1728 breakpoint that needs stepping-off, but that should not be visible
1729 to the user/frontend, and neither should the frontend/user be
1730 allowed to proceed any of the threads that happen to be stopped for
1731 internal run control handling, if a previous command wanted them
1735 user_visible_resume_ptid (int step
)
1737 /* By default, resume all threads of all processes. */
1738 ptid_t resume_ptid
= RESUME_ALL
;
1740 /* Maybe resume only all threads of the current process. */
1741 if (!sched_multi
&& target_supports_multi_process ())
1743 resume_ptid
= pid_to_ptid (ptid_get_pid (inferior_ptid
));
1746 /* Maybe resume a single thread after all. */
1749 /* With non-stop mode on, threads are always handled
1751 resume_ptid
= inferior_ptid
;
1753 else if ((scheduler_mode
== schedlock_on
)
1754 || (scheduler_mode
== schedlock_step
1755 && (step
|| singlestep_breakpoints_inserted_p
)))
1757 /* User-settable 'scheduler' mode requires solo thread resume. */
1758 resume_ptid
= inferior_ptid
;
1764 /* Resume the inferior, but allow a QUIT. This is useful if the user
1765 wants to interrupt some lengthy single-stepping operation
1766 (for child processes, the SIGINT goes to the inferior, and so
1767 we get a SIGINT random_signal, but for remote debugging and perhaps
1768 other targets, that's not true).
1770 STEP nonzero if we should step (zero to continue instead).
1771 SIG is the signal to give the inferior (zero for none). */
1773 resume (int step
, enum gdb_signal sig
)
1775 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
1776 struct regcache
*regcache
= get_current_regcache ();
1777 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1778 struct thread_info
*tp
= inferior_thread ();
1779 CORE_ADDR pc
= regcache_read_pc (regcache
);
1780 struct address_space
*aspace
= get_regcache_aspace (regcache
);
1785 if (current_inferior ()->waiting_for_vfork_done
)
1787 /* Don't try to single-step a vfork parent that is waiting for
1788 the child to get out of the shared memory region (by exec'ing
1789 or exiting). This is particularly important on software
1790 single-step archs, as the child process would trip on the
1791 software single step breakpoint inserted for the parent
1792 process. Since the parent will not actually execute any
1793 instruction until the child is out of the shared region (such
1794 are vfork's semantics), it is safe to simply continue it.
1795 Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for
1796 the parent, and tell it to `keep_going', which automatically
1797 re-sets it stepping. */
1799 fprintf_unfiltered (gdb_stdlog
,
1800 "infrun: resume : clear step\n");
1805 fprintf_unfiltered (gdb_stdlog
,
1806 "infrun: resume (step=%d, signal=%s), "
1807 "trap_expected=%d, current thread [%s] at %s\n",
1808 step
, gdb_signal_to_symbol_string (sig
),
1809 tp
->control
.trap_expected
,
1810 target_pid_to_str (inferior_ptid
),
1811 paddress (gdbarch
, pc
));
1813 /* Normally, by the time we reach `resume', the breakpoints are either
1814 removed or inserted, as appropriate. The exception is if we're sitting
1815 at a permanent breakpoint; we need to step over it, but permanent
1816 breakpoints can't be removed. So we have to test for it here. */
1817 if (breakpoint_here_p (aspace
, pc
) == permanent_breakpoint_here
)
1819 if (gdbarch_skip_permanent_breakpoint_p (gdbarch
))
1820 gdbarch_skip_permanent_breakpoint (gdbarch
, regcache
);
1823 The program is stopped at a permanent breakpoint, but GDB does not know\n\
1824 how to step past a permanent breakpoint on this architecture. Try using\n\
1825 a command like `return' or `jump' to continue execution."));
1828 /* If we have a breakpoint to step over, make sure to do a single
1829 step only. Same if we have software watchpoints. */
1830 if (tp
->control
.trap_expected
|| bpstat_should_step ())
1831 tp
->control
.may_range_step
= 0;
1833 /* If enabled, step over breakpoints by executing a copy of the
1834 instruction at a different address.
1836 We can't use displaced stepping when we have a signal to deliver;
1837 the comments for displaced_step_prepare explain why. The
1838 comments in the handle_inferior event for dealing with 'random
1839 signals' explain what we do instead.
1841 We can't use displaced stepping when we are waiting for vfork_done
1842 event, displaced stepping breaks the vfork child similarly as single
1843 step software breakpoint. */
1844 if (use_displaced_stepping (gdbarch
)
1845 && (tp
->control
.trap_expected
1846 || (step
&& gdbarch_software_single_step_p (gdbarch
)))
1847 && sig
== GDB_SIGNAL_0
1848 && !current_inferior ()->waiting_for_vfork_done
)
1850 struct displaced_step_inferior_state
*displaced
;
1852 if (!displaced_step_prepare (inferior_ptid
))
1854 /* Got placed in displaced stepping queue. Will be resumed
1855 later when all the currently queued displaced stepping
1856 requests finish. The thread is not executing at this point,
1857 and the call to set_executing will be made later. But we
1858 need to call set_running here, since from frontend point of view,
1859 the thread is running. */
1860 set_running (inferior_ptid
, 1);
1861 discard_cleanups (old_cleanups
);
1865 /* Update pc to reflect the new address from which we will execute
1866 instructions due to displaced stepping. */
1867 pc
= regcache_read_pc (get_thread_regcache (inferior_ptid
));
1869 displaced
= get_displaced_stepping_state (ptid_get_pid (inferior_ptid
));
1870 step
= gdbarch_displaced_step_hw_singlestep (gdbarch
,
1871 displaced
->step_closure
);
1874 /* Do we need to do it the hard way, w/temp breakpoints? */
1876 step
= maybe_software_singlestep (gdbarch
, pc
);
1878 /* Currently, our software single-step implementation leads to different
1879 results than hardware single-stepping in one situation: when stepping
1880 into delivering a signal which has an associated signal handler,
1881 hardware single-step will stop at the first instruction of the handler,
1882 while software single-step will simply skip execution of the handler.
1884 For now, this difference in behavior is accepted since there is no
1885 easy way to actually implement single-stepping into a signal handler
1886 without kernel support.
1888 However, there is one scenario where this difference leads to follow-on
1889 problems: if we're stepping off a breakpoint by removing all breakpoints
1890 and then single-stepping. In this case, the software single-step
1891 behavior means that even if there is a *breakpoint* in the signal
1892 handler, GDB still would not stop.
1894 Fortunately, we can at least fix this particular issue. We detect
1895 here the case where we are about to deliver a signal while software
1896 single-stepping with breakpoints removed. In this situation, we
1897 revert the decisions to remove all breakpoints and insert single-
1898 step breakpoints, and instead we install a step-resume breakpoint
1899 at the current address, deliver the signal without stepping, and
1900 once we arrive back at the step-resume breakpoint, actually step
1901 over the breakpoint we originally wanted to step over. */
1902 if (singlestep_breakpoints_inserted_p
1903 && tp
->control
.trap_expected
&& sig
!= GDB_SIGNAL_0
)
1905 /* If we have nested signals or a pending signal is delivered
1906 immediately after a handler returns, might might already have
1907 a step-resume breakpoint set on the earlier handler. We cannot
1908 set another step-resume breakpoint; just continue on until the
1909 original breakpoint is hit. */
1910 if (tp
->control
.step_resume_breakpoint
== NULL
)
1912 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
1913 tp
->step_after_step_resume_breakpoint
= 1;
1916 remove_single_step_breakpoints ();
1917 singlestep_breakpoints_inserted_p
= 0;
1919 clear_step_over_info ();
1920 tp
->control
.trap_expected
= 0;
1922 insert_breakpoints ();
1925 /* If STEP is set, it's a request to use hardware stepping
1926 facilities. But in that case, we should never
1927 use singlestep breakpoint. */
1928 gdb_assert (!(singlestep_breakpoints_inserted_p
&& step
));
1930 /* Decide the set of threads to ask the target to resume. Start
1931 by assuming everything will be resumed, than narrow the set
1932 by applying increasingly restricting conditions. */
1933 resume_ptid
= user_visible_resume_ptid (step
);
1935 /* Maybe resume a single thread after all. */
1936 if ((step
|| singlestep_breakpoints_inserted_p
)
1937 && tp
->control
.trap_expected
)
1939 /* We're allowing a thread to run past a breakpoint it has
1940 hit, by single-stepping the thread with the breakpoint
1941 removed. In which case, we need to single-step only this
1942 thread, and keep others stopped, as they can miss this
1943 breakpoint if allowed to run. */
1944 resume_ptid
= inferior_ptid
;
1947 if (gdbarch_cannot_step_breakpoint (gdbarch
))
1949 /* Most targets can step a breakpoint instruction, thus
1950 executing it normally. But if this one cannot, just
1951 continue and we will hit it anyway. */
1952 if (step
&& breakpoint_inserted_here_p (aspace
, pc
))
1957 && use_displaced_stepping (gdbarch
)
1958 && tp
->control
.trap_expected
)
1960 struct regcache
*resume_regcache
= get_thread_regcache (resume_ptid
);
1961 struct gdbarch
*resume_gdbarch
= get_regcache_arch (resume_regcache
);
1962 CORE_ADDR actual_pc
= regcache_read_pc (resume_regcache
);
1965 fprintf_unfiltered (gdb_stdlog
, "displaced: run %s: ",
1966 paddress (resume_gdbarch
, actual_pc
));
1967 read_memory (actual_pc
, buf
, sizeof (buf
));
1968 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
1971 if (tp
->control
.may_range_step
)
1973 /* If we're resuming a thread with the PC out of the step
1974 range, then we're doing some nested/finer run control
1975 operation, like stepping the thread out of the dynamic
1976 linker or the displaced stepping scratch pad. We
1977 shouldn't have allowed a range step then. */
1978 gdb_assert (pc_in_thread_step_range (pc
, tp
));
1981 /* Install inferior's terminal modes. */
1982 target_terminal_inferior ();
1984 /* Avoid confusing the next resume, if the next stop/resume
1985 happens to apply to another thread. */
1986 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
1988 /* Advise target which signals may be handled silently. If we have
1989 removed breakpoints because we are stepping over one (which can
1990 happen only if we are not using displaced stepping), we need to
1991 receive all signals to avoid accidentally skipping a breakpoint
1992 during execution of a signal handler. */
1993 if ((step
|| singlestep_breakpoints_inserted_p
)
1994 && tp
->control
.trap_expected
1995 && !use_displaced_stepping (gdbarch
))
1996 target_pass_signals (0, NULL
);
1998 target_pass_signals ((int) GDB_SIGNAL_LAST
, signal_pass
);
2000 target_resume (resume_ptid
, step
, sig
);
2002 discard_cleanups (old_cleanups
);
2007 /* Clear out all variables saying what to do when inferior is continued.
2008 First do this, then set the ones you want, then call `proceed'. */
2011 clear_proceed_status_thread (struct thread_info
*tp
)
2014 fprintf_unfiltered (gdb_stdlog
,
2015 "infrun: clear_proceed_status_thread (%s)\n",
2016 target_pid_to_str (tp
->ptid
));
2018 tp
->control
.trap_expected
= 0;
2019 tp
->control
.step_range_start
= 0;
2020 tp
->control
.step_range_end
= 0;
2021 tp
->control
.may_range_step
= 0;
2022 tp
->control
.step_frame_id
= null_frame_id
;
2023 tp
->control
.step_stack_frame_id
= null_frame_id
;
2024 tp
->control
.step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
2025 tp
->stop_requested
= 0;
2027 tp
->control
.stop_step
= 0;
2029 tp
->control
.proceed_to_finish
= 0;
2031 tp
->control
.command_interp
= NULL
;
2033 /* Discard any remaining commands or status from previous stop. */
2034 bpstat_clear (&tp
->control
.stop_bpstat
);
2038 clear_proceed_status_callback (struct thread_info
*tp
, void *data
)
2040 if (is_exited (tp
->ptid
))
2043 clear_proceed_status_thread (tp
);
2048 clear_proceed_status (void)
2052 /* In all-stop mode, delete the per-thread status of all
2053 threads, even if inferior_ptid is null_ptid, there may be
2054 threads on the list. E.g., we may be launching a new
2055 process, while selecting the executable. */
2056 iterate_over_threads (clear_proceed_status_callback
, NULL
);
2059 if (!ptid_equal (inferior_ptid
, null_ptid
))
2061 struct inferior
*inferior
;
2065 /* If in non-stop mode, only delete the per-thread status of
2066 the current thread. */
2067 clear_proceed_status_thread (inferior_thread ());
2070 inferior
= current_inferior ();
2071 inferior
->control
.stop_soon
= NO_STOP_QUIETLY
;
2074 stop_after_trap
= 0;
2076 clear_step_over_info ();
2078 observer_notify_about_to_proceed ();
2082 regcache_xfree (stop_registers
);
2083 stop_registers
= NULL
;
2087 /* Returns true if TP is still stopped at a breakpoint that needs
2088 stepping-over in order to make progress. If the breakpoint is gone
2089 meanwhile, we can skip the whole step-over dance. */
2092 thread_still_needs_step_over (struct thread_info
*tp
)
2094 if (tp
->stepping_over_breakpoint
)
2096 struct regcache
*regcache
= get_thread_regcache (tp
->ptid
);
2098 if (breakpoint_here_p (get_regcache_aspace (regcache
),
2099 regcache_read_pc (regcache
)))
2102 tp
->stepping_over_breakpoint
= 0;
2108 /* Returns true if scheduler locking applies. STEP indicates whether
2109 we're about to do a step/next-like command to a thread. */
2112 schedlock_applies (int step
)
2114 return (scheduler_mode
== schedlock_on
2115 || (scheduler_mode
== schedlock_step
2119 /* Look a thread other than EXCEPT that has previously reported a
2120 breakpoint event, and thus needs a step-over in order to make
2121 progress. Returns NULL is none is found. STEP indicates whether
2122 we're about to step the current thread, in order to decide whether
2123 "set scheduler-locking step" applies. */
2125 static struct thread_info
*
2126 find_thread_needs_step_over (int step
, struct thread_info
*except
)
2128 struct thread_info
*tp
, *current
;
2130 /* With non-stop mode on, threads are always handled individually. */
2131 gdb_assert (! non_stop
);
2133 current
= inferior_thread ();
2135 /* If scheduler locking applies, we can avoid iterating over all
2137 if (schedlock_applies (step
))
2139 if (except
!= current
2140 && thread_still_needs_step_over (current
))
2148 /* Ignore the EXCEPT thread. */
2151 /* Ignore threads of processes we're not resuming. */
2153 && ptid_get_pid (tp
->ptid
) != ptid_get_pid (inferior_ptid
))
2156 if (thread_still_needs_step_over (tp
))
2163 /* Basic routine for continuing the program in various fashions.
2165 ADDR is the address to resume at, or -1 for resume where stopped.
2166 SIGGNAL is the signal to give it, or 0 for none,
2167 or -1 for act according to how it stopped.
2168 STEP is nonzero if should trap after one instruction.
2169 -1 means return after that and print nothing.
2170 You should probably set various step_... variables
2171 before calling here, if you are stepping.
2173 You should call clear_proceed_status before calling proceed. */
2176 proceed (CORE_ADDR addr
, enum gdb_signal siggnal
, int step
)
2178 struct regcache
*regcache
;
2179 struct gdbarch
*gdbarch
;
2180 struct thread_info
*tp
;
2182 struct address_space
*aspace
;
2184 /* If we're stopped at a fork/vfork, follow the branch set by the
2185 "set follow-fork-mode" command; otherwise, we'll just proceed
2186 resuming the current thread. */
2187 if (!follow_fork ())
2189 /* The target for some reason decided not to resume. */
2191 if (target_can_async_p ())
2192 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
2196 /* We'll update this if & when we switch to a new thread. */
2197 previous_inferior_ptid
= inferior_ptid
;
2199 regcache
= get_current_regcache ();
2200 gdbarch
= get_regcache_arch (regcache
);
2201 aspace
= get_regcache_aspace (regcache
);
2202 pc
= regcache_read_pc (regcache
);
2203 tp
= inferior_thread ();
2206 step_start_function
= find_pc_function (pc
);
2208 stop_after_trap
= 1;
2210 /* Fill in with reasonable starting values. */
2211 init_thread_stepping_state (tp
);
2213 if (addr
== (CORE_ADDR
) -1)
2215 if (pc
== stop_pc
&& breakpoint_here_p (aspace
, pc
)
2216 && execution_direction
!= EXEC_REVERSE
)
2217 /* There is a breakpoint at the address we will resume at,
2218 step one instruction before inserting breakpoints so that
2219 we do not stop right away (and report a second hit at this
2222 Note, we don't do this in reverse, because we won't
2223 actually be executing the breakpoint insn anyway.
2224 We'll be (un-)executing the previous instruction. */
2225 tp
->stepping_over_breakpoint
= 1;
2226 else if (gdbarch_single_step_through_delay_p (gdbarch
)
2227 && gdbarch_single_step_through_delay (gdbarch
,
2228 get_current_frame ()))
2229 /* We stepped onto an instruction that needs to be stepped
2230 again before re-inserting the breakpoint, do so. */
2231 tp
->stepping_over_breakpoint
= 1;
2235 regcache_write_pc (regcache
, addr
);
2238 /* Record the interpreter that issued the execution command that
2239 caused this thread to resume. If the top level interpreter is
2240 MI/async, and the execution command was a CLI command
2241 (next/step/etc.), we'll want to print stop event output to the MI
2242 console channel (the stepped-to line, etc.), as if the user
2243 entered the execution command on a real GDB console. */
2244 inferior_thread ()->control
.command_interp
= command_interp ();
2247 fprintf_unfiltered (gdb_stdlog
,
2248 "infrun: proceed (addr=%s, signal=%s, step=%d)\n",
2249 paddress (gdbarch
, addr
),
2250 gdb_signal_to_symbol_string (siggnal
), step
);
2253 /* In non-stop, each thread is handled individually. The context
2254 must already be set to the right thread here. */
2258 struct thread_info
*step_over
;
2260 /* In a multi-threaded task we may select another thread and
2261 then continue or step.
2263 But if the old thread was stopped at a breakpoint, it will
2264 immediately cause another breakpoint stop without any
2265 execution (i.e. it will report a breakpoint hit incorrectly).
2266 So we must step over it first.
2268 Look for a thread other than the current (TP) that reported a
2269 breakpoint hit and hasn't been resumed yet since. */
2270 step_over
= find_thread_needs_step_over (step
, tp
);
2271 if (step_over
!= NULL
)
2274 fprintf_unfiltered (gdb_stdlog
,
2275 "infrun: need to step-over [%s] first\n",
2276 target_pid_to_str (step_over
->ptid
));
2278 /* Store the prev_pc for the stepping thread too, needed by
2279 switch_back_to_stepping thread. */
2280 tp
->prev_pc
= regcache_read_pc (get_current_regcache ());
2281 switch_to_thread (step_over
->ptid
);
2286 /* If we need to step over a breakpoint, and we're not using
2287 displaced stepping to do so, insert all breakpoints (watchpoints,
2288 etc.) but the one we're stepping over, step one instruction, and
2289 then re-insert the breakpoint when that step is finished. */
2290 if (tp
->stepping_over_breakpoint
&& !use_displaced_stepping (gdbarch
))
2292 struct regcache
*regcache
= get_current_regcache ();
2294 set_step_over_info (get_regcache_aspace (regcache
),
2295 regcache_read_pc (regcache
));
2298 clear_step_over_info ();
2300 insert_breakpoints ();
2302 tp
->control
.trap_expected
= tp
->stepping_over_breakpoint
;
2306 /* Pass the last stop signal to the thread we're resuming,
2307 irrespective of whether the current thread is the thread that
2308 got the last event or not. This was historically GDB's
2309 behaviour before keeping a stop_signal per thread. */
2311 struct thread_info
*last_thread
;
2313 struct target_waitstatus last_status
;
2315 get_last_target_status (&last_ptid
, &last_status
);
2316 if (!ptid_equal (inferior_ptid
, last_ptid
)
2317 && !ptid_equal (last_ptid
, null_ptid
)
2318 && !ptid_equal (last_ptid
, minus_one_ptid
))
2320 last_thread
= find_thread_ptid (last_ptid
);
2323 tp
->suspend
.stop_signal
= last_thread
->suspend
.stop_signal
;
2324 last_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2329 if (siggnal
!= GDB_SIGNAL_DEFAULT
)
2330 tp
->suspend
.stop_signal
= siggnal
;
2331 /* If this signal should not be seen by program,
2332 give it zero. Used for debugging signals. */
2333 else if (!signal_program
[tp
->suspend
.stop_signal
])
2334 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2336 annotate_starting ();
2338 /* Make sure that output from GDB appears before output from the
2340 gdb_flush (gdb_stdout
);
2342 /* Refresh prev_pc value just prior to resuming. This used to be
2343 done in stop_stepping, however, setting prev_pc there did not handle
2344 scenarios such as inferior function calls or returning from
2345 a function via the return command. In those cases, the prev_pc
2346 value was not set properly for subsequent commands. The prev_pc value
2347 is used to initialize the starting line number in the ecs. With an
2348 invalid value, the gdb next command ends up stopping at the position
2349 represented by the next line table entry past our start position.
2350 On platforms that generate one line table entry per line, this
2351 is not a problem. However, on the ia64, the compiler generates
2352 extraneous line table entries that do not increase the line number.
2353 When we issue the gdb next command on the ia64 after an inferior call
2354 or a return command, we often end up a few instructions forward, still
2355 within the original line we started.
2357 An attempt was made to refresh the prev_pc at the same time the
2358 execution_control_state is initialized (for instance, just before
2359 waiting for an inferior event). But this approach did not work
2360 because of platforms that use ptrace, where the pc register cannot
2361 be read unless the inferior is stopped. At that point, we are not
2362 guaranteed the inferior is stopped and so the regcache_read_pc() call
2363 can fail. Setting the prev_pc value here ensures the value is updated
2364 correctly when the inferior is stopped. */
2365 tp
->prev_pc
= regcache_read_pc (get_current_regcache ());
2367 /* Reset to normal state. */
2368 init_infwait_state ();
2370 /* Resume inferior. */
2371 resume (tp
->control
.trap_expected
|| step
|| bpstat_should_step (),
2372 tp
->suspend
.stop_signal
);
2374 /* Wait for it to stop (if not standalone)
2375 and in any case decode why it stopped, and act accordingly. */
2376 /* Do this only if we are not using the event loop, or if the target
2377 does not support asynchronous execution. */
2378 if (!target_can_async_p ())
2380 wait_for_inferior ();
2386 /* Start remote-debugging of a machine over a serial link. */
2389 start_remote (int from_tty
)
2391 struct inferior
*inferior
;
2393 inferior
= current_inferior ();
2394 inferior
->control
.stop_soon
= STOP_QUIETLY_REMOTE
;
2396 /* Always go on waiting for the target, regardless of the mode. */
2397 /* FIXME: cagney/1999-09-23: At present it isn't possible to
2398 indicate to wait_for_inferior that a target should timeout if
2399 nothing is returned (instead of just blocking). Because of this,
2400 targets expecting an immediate response need to, internally, set
2401 things up so that the target_wait() is forced to eventually
2403 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
2404 differentiate to its caller what the state of the target is after
2405 the initial open has been performed. Here we're assuming that
2406 the target has stopped. It should be possible to eventually have
2407 target_open() return to the caller an indication that the target
2408 is currently running and GDB state should be set to the same as
2409 for an async run. */
2410 wait_for_inferior ();
2412 /* Now that the inferior has stopped, do any bookkeeping like
2413 loading shared libraries. We want to do this before normal_stop,
2414 so that the displayed frame is up to date. */
2415 post_create_inferior (¤t_target
, from_tty
);
2420 /* Initialize static vars when a new inferior begins. */
2423 init_wait_for_inferior (void)
2425 /* These are meaningless until the first time through wait_for_inferior. */
2427 breakpoint_init_inferior (inf_starting
);
2429 clear_proceed_status ();
2431 target_last_wait_ptid
= minus_one_ptid
;
2433 previous_inferior_ptid
= inferior_ptid
;
2434 init_infwait_state ();
2436 /* Discard any skipped inlined frames. */
2437 clear_inline_frame_state (minus_one_ptid
);
2439 singlestep_ptid
= null_ptid
;
2444 /* This enum encodes possible reasons for doing a target_wait, so that
2445 wfi can call target_wait in one place. (Ultimately the call will be
2446 moved out of the infinite loop entirely.) */
2450 infwait_normal_state
,
2451 infwait_step_watch_state
,
2452 infwait_nonstep_watch_state
2455 /* The PTID we'll do a target_wait on.*/
2458 /* Current inferior wait state. */
2459 static enum infwait_states infwait_state
;
2461 /* Data to be passed around while handling an event. This data is
2462 discarded between events. */
2463 struct execution_control_state
2466 /* The thread that got the event, if this was a thread event; NULL
2468 struct thread_info
*event_thread
;
2470 struct target_waitstatus ws
;
2471 int stop_func_filled_in
;
2472 CORE_ADDR stop_func_start
;
2473 CORE_ADDR stop_func_end
;
2474 const char *stop_func_name
;
2477 /* We were in infwait_step_watch_state or
2478 infwait_nonstep_watch_state state, and the thread reported an
2480 int stepped_after_stopped_by_watchpoint
;
2482 /* True if the event thread hit the single-step breakpoint of
2483 another thread. Thus the event doesn't cause a stop, the thread
2484 needs to be single-stepped past the single-step breakpoint before
2485 we can switch back to the original stepping thread. */
2486 int hit_singlestep_breakpoint
;
2489 static void handle_inferior_event (struct execution_control_state
*ecs
);
2491 static void handle_step_into_function (struct gdbarch
*gdbarch
,
2492 struct execution_control_state
*ecs
);
2493 static void handle_step_into_function_backward (struct gdbarch
*gdbarch
,
2494 struct execution_control_state
*ecs
);
2495 static void handle_signal_stop (struct execution_control_state
*ecs
);
2496 static void check_exception_resume (struct execution_control_state
*,
2497 struct frame_info
*);
2499 static void stop_stepping (struct execution_control_state
*ecs
);
2500 static void prepare_to_wait (struct execution_control_state
*ecs
);
2501 static void keep_going (struct execution_control_state
*ecs
);
2502 static void process_event_stop_test (struct execution_control_state
*ecs
);
2503 static int switch_back_to_stepped_thread (struct execution_control_state
*ecs
);
2505 /* Callback for iterate over threads. If the thread is stopped, but
2506 the user/frontend doesn't know about that yet, go through
2507 normal_stop, as if the thread had just stopped now. ARG points at
2508 a ptid. If PTID is MINUS_ONE_PTID, applies to all threads. If
2509 ptid_is_pid(PTID) is true, applies to all threads of the process
2510 pointed at by PTID. Otherwise, apply only to the thread pointed by
2514 infrun_thread_stop_requested_callback (struct thread_info
*info
, void *arg
)
2516 ptid_t ptid
= * (ptid_t
*) arg
;
2518 if ((ptid_equal (info
->ptid
, ptid
)
2519 || ptid_equal (minus_one_ptid
, ptid
)
2520 || (ptid_is_pid (ptid
)
2521 && ptid_get_pid (ptid
) == ptid_get_pid (info
->ptid
)))
2522 && is_running (info
->ptid
)
2523 && !is_executing (info
->ptid
))
2525 struct cleanup
*old_chain
;
2526 struct execution_control_state ecss
;
2527 struct execution_control_state
*ecs
= &ecss
;
2529 memset (ecs
, 0, sizeof (*ecs
));
2531 old_chain
= make_cleanup_restore_current_thread ();
2533 overlay_cache_invalid
= 1;
2534 /* Flush target cache before starting to handle each event.
2535 Target was running and cache could be stale. This is just a
2536 heuristic. Running threads may modify target memory, but we
2537 don't get any event. */
2538 target_dcache_invalidate ();
2540 /* Go through handle_inferior_event/normal_stop, so we always
2541 have consistent output as if the stop event had been
2543 ecs
->ptid
= info
->ptid
;
2544 ecs
->event_thread
= find_thread_ptid (info
->ptid
);
2545 ecs
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
2546 ecs
->ws
.value
.sig
= GDB_SIGNAL_0
;
2548 handle_inferior_event (ecs
);
2550 if (!ecs
->wait_some_more
)
2552 struct thread_info
*tp
;
2556 /* Finish off the continuations. */
2557 tp
= inferior_thread ();
2558 do_all_intermediate_continuations_thread (tp
, 1);
2559 do_all_continuations_thread (tp
, 1);
2562 do_cleanups (old_chain
);
2568 /* This function is attached as a "thread_stop_requested" observer.
2569 Cleanup local state that assumed the PTID was to be resumed, and
2570 report the stop to the frontend. */
2573 infrun_thread_stop_requested (ptid_t ptid
)
2575 struct displaced_step_inferior_state
*displaced
;
2577 /* PTID was requested to stop. Remove it from the displaced
2578 stepping queue, so we don't try to resume it automatically. */
2580 for (displaced
= displaced_step_inferior_states
;
2582 displaced
= displaced
->next
)
2584 struct displaced_step_request
*it
, **prev_next_p
;
2586 it
= displaced
->step_request_queue
;
2587 prev_next_p
= &displaced
->step_request_queue
;
2590 if (ptid_match (it
->ptid
, ptid
))
2592 *prev_next_p
= it
->next
;
2598 prev_next_p
= &it
->next
;
2605 iterate_over_threads (infrun_thread_stop_requested_callback
, &ptid
);
2609 infrun_thread_thread_exit (struct thread_info
*tp
, int silent
)
2611 if (ptid_equal (target_last_wait_ptid
, tp
->ptid
))
2612 nullify_last_target_wait_ptid ();
2615 /* Callback for iterate_over_threads. */
2618 delete_step_resume_breakpoint_callback (struct thread_info
*info
, void *data
)
2620 if (is_exited (info
->ptid
))
2623 delete_step_resume_breakpoint (info
);
2624 delete_exception_resume_breakpoint (info
);
2628 /* In all-stop, delete the step resume breakpoint of any thread that
2629 had one. In non-stop, delete the step resume breakpoint of the
2630 thread that just stopped. */
2633 delete_step_thread_step_resume_breakpoint (void)
2635 if (!target_has_execution
2636 || ptid_equal (inferior_ptid
, null_ptid
))
2637 /* If the inferior has exited, we have already deleted the step
2638 resume breakpoints out of GDB's lists. */
2643 /* If in non-stop mode, only delete the step-resume or
2644 longjmp-resume breakpoint of the thread that just stopped
2646 struct thread_info
*tp
= inferior_thread ();
2648 delete_step_resume_breakpoint (tp
);
2649 delete_exception_resume_breakpoint (tp
);
2652 /* In all-stop mode, delete all step-resume and longjmp-resume
2653 breakpoints of any thread that had them. */
2654 iterate_over_threads (delete_step_resume_breakpoint_callback
, NULL
);
2657 /* A cleanup wrapper. */
2660 delete_step_thread_step_resume_breakpoint_cleanup (void *arg
)
2662 delete_step_thread_step_resume_breakpoint ();
2665 /* Pretty print the results of target_wait, for debugging purposes. */
2668 print_target_wait_results (ptid_t waiton_ptid
, ptid_t result_ptid
,
2669 const struct target_waitstatus
*ws
)
2671 char *status_string
= target_waitstatus_to_string (ws
);
2672 struct ui_file
*tmp_stream
= mem_fileopen ();
2675 /* The text is split over several lines because it was getting too long.
2676 Call fprintf_unfiltered (gdb_stdlog) once so that the text is still
2677 output as a unit; we want only one timestamp printed if debug_timestamp
2680 fprintf_unfiltered (tmp_stream
,
2681 "infrun: target_wait (%d", ptid_get_pid (waiton_ptid
));
2682 if (ptid_get_pid (waiton_ptid
) != -1)
2683 fprintf_unfiltered (tmp_stream
,
2684 " [%s]", target_pid_to_str (waiton_ptid
));
2685 fprintf_unfiltered (tmp_stream
, ", status) =\n");
2686 fprintf_unfiltered (tmp_stream
,
2687 "infrun: %d [%s],\n",
2688 ptid_get_pid (result_ptid
),
2689 target_pid_to_str (result_ptid
));
2690 fprintf_unfiltered (tmp_stream
,
2694 text
= ui_file_xstrdup (tmp_stream
, NULL
);
2696 /* This uses %s in part to handle %'s in the text, but also to avoid
2697 a gcc error: the format attribute requires a string literal. */
2698 fprintf_unfiltered (gdb_stdlog
, "%s", text
);
2700 xfree (status_string
);
2702 ui_file_delete (tmp_stream
);
2705 /* Prepare and stabilize the inferior for detaching it. E.g.,
2706 detaching while a thread is displaced stepping is a recipe for
2707 crashing it, as nothing would readjust the PC out of the scratch
2711 prepare_for_detach (void)
2713 struct inferior
*inf
= current_inferior ();
2714 ptid_t pid_ptid
= pid_to_ptid (inf
->pid
);
2715 struct cleanup
*old_chain_1
;
2716 struct displaced_step_inferior_state
*displaced
;
2718 displaced
= get_displaced_stepping_state (inf
->pid
);
2720 /* Is any thread of this process displaced stepping? If not,
2721 there's nothing else to do. */
2722 if (displaced
== NULL
|| ptid_equal (displaced
->step_ptid
, null_ptid
))
2726 fprintf_unfiltered (gdb_stdlog
,
2727 "displaced-stepping in-process while detaching");
2729 old_chain_1
= make_cleanup_restore_integer (&inf
->detaching
);
2732 while (!ptid_equal (displaced
->step_ptid
, null_ptid
))
2734 struct cleanup
*old_chain_2
;
2735 struct execution_control_state ecss
;
2736 struct execution_control_state
*ecs
;
2739 memset (ecs
, 0, sizeof (*ecs
));
2741 overlay_cache_invalid
= 1;
2742 /* Flush target cache before starting to handle each event.
2743 Target was running and cache could be stale. This is just a
2744 heuristic. Running threads may modify target memory, but we
2745 don't get any event. */
2746 target_dcache_invalidate ();
2748 if (deprecated_target_wait_hook
)
2749 ecs
->ptid
= deprecated_target_wait_hook (pid_ptid
, &ecs
->ws
, 0);
2751 ecs
->ptid
= target_wait (pid_ptid
, &ecs
->ws
, 0);
2754 print_target_wait_results (pid_ptid
, ecs
->ptid
, &ecs
->ws
);
2756 /* If an error happens while handling the event, propagate GDB's
2757 knowledge of the executing state to the frontend/user running
2759 old_chain_2
= make_cleanup (finish_thread_state_cleanup
,
2762 /* Now figure out what to do with the result of the result. */
2763 handle_inferior_event (ecs
);
2765 /* No error, don't finish the state yet. */
2766 discard_cleanups (old_chain_2
);
2768 /* Breakpoints and watchpoints are not installed on the target
2769 at this point, and signals are passed directly to the
2770 inferior, so this must mean the process is gone. */
2771 if (!ecs
->wait_some_more
)
2773 discard_cleanups (old_chain_1
);
2774 error (_("Program exited while detaching"));
2778 discard_cleanups (old_chain_1
);
2781 /* Wait for control to return from inferior to debugger.
2783 If inferior gets a signal, we may decide to start it up again
2784 instead of returning. That is why there is a loop in this function.
2785 When this function actually returns it means the inferior
2786 should be left stopped and GDB should read more commands. */
2789 wait_for_inferior (void)
2791 struct cleanup
*old_cleanups
;
2795 (gdb_stdlog
, "infrun: wait_for_inferior ()\n");
2798 make_cleanup (delete_step_thread_step_resume_breakpoint_cleanup
, NULL
);
2802 struct execution_control_state ecss
;
2803 struct execution_control_state
*ecs
= &ecss
;
2804 struct cleanup
*old_chain
;
2806 memset (ecs
, 0, sizeof (*ecs
));
2808 overlay_cache_invalid
= 1;
2810 /* Flush target cache before starting to handle each event.
2811 Target was running and cache could be stale. This is just a
2812 heuristic. Running threads may modify target memory, but we
2813 don't get any event. */
2814 target_dcache_invalidate ();
2816 if (deprecated_target_wait_hook
)
2817 ecs
->ptid
= deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
, 0);
2819 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
, 0);
2822 print_target_wait_results (waiton_ptid
, ecs
->ptid
, &ecs
->ws
);
2824 /* If an error happens while handling the event, propagate GDB's
2825 knowledge of the executing state to the frontend/user running
2827 old_chain
= make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
2829 /* Now figure out what to do with the result of the result. */
2830 handle_inferior_event (ecs
);
2832 /* No error, don't finish the state yet. */
2833 discard_cleanups (old_chain
);
2835 if (!ecs
->wait_some_more
)
2839 do_cleanups (old_cleanups
);
2842 /* Asynchronous version of wait_for_inferior. It is called by the
2843 event loop whenever a change of state is detected on the file
2844 descriptor corresponding to the target. It can be called more than
2845 once to complete a single execution command. In such cases we need
2846 to keep the state in a global variable ECSS. If it is the last time
2847 that this function is called for a single execution command, then
2848 report to the user that the inferior has stopped, and do the
2849 necessary cleanups. */
2852 fetch_inferior_event (void *client_data
)
2854 struct execution_control_state ecss
;
2855 struct execution_control_state
*ecs
= &ecss
;
2856 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
2857 struct cleanup
*ts_old_chain
;
2858 int was_sync
= sync_execution
;
2861 memset (ecs
, 0, sizeof (*ecs
));
2863 /* We're handling a live event, so make sure we're doing live
2864 debugging. If we're looking at traceframes while the target is
2865 running, we're going to need to get back to that mode after
2866 handling the event. */
2869 make_cleanup_restore_current_traceframe ();
2870 set_current_traceframe (-1);
2874 /* In non-stop mode, the user/frontend should not notice a thread
2875 switch due to internal events. Make sure we reverse to the
2876 user selected thread and frame after handling the event and
2877 running any breakpoint commands. */
2878 make_cleanup_restore_current_thread ();
2880 overlay_cache_invalid
= 1;
2881 /* Flush target cache before starting to handle each event. Target
2882 was running and cache could be stale. This is just a heuristic.
2883 Running threads may modify target memory, but we don't get any
2885 target_dcache_invalidate ();
2887 make_cleanup_restore_integer (&execution_direction
);
2888 execution_direction
= target_execution_direction ();
2890 if (deprecated_target_wait_hook
)
2892 deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
, TARGET_WNOHANG
);
2894 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
, TARGET_WNOHANG
);
2897 print_target_wait_results (waiton_ptid
, ecs
->ptid
, &ecs
->ws
);
2899 /* If an error happens while handling the event, propagate GDB's
2900 knowledge of the executing state to the frontend/user running
2903 ts_old_chain
= make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
2905 ts_old_chain
= make_cleanup (finish_thread_state_cleanup
, &ecs
->ptid
);
2907 /* Get executed before make_cleanup_restore_current_thread above to apply
2908 still for the thread which has thrown the exception. */
2909 make_bpstat_clear_actions_cleanup ();
2911 /* Now figure out what to do with the result of the result. */
2912 handle_inferior_event (ecs
);
2914 if (!ecs
->wait_some_more
)
2916 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ecs
->ptid
));
2918 delete_step_thread_step_resume_breakpoint ();
2920 /* We may not find an inferior if this was a process exit. */
2921 if (inf
== NULL
|| inf
->control
.stop_soon
== NO_STOP_QUIETLY
)
2924 if (target_has_execution
2925 && ecs
->ws
.kind
!= TARGET_WAITKIND_NO_RESUMED
2926 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
2927 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
2928 && ecs
->event_thread
->step_multi
2929 && ecs
->event_thread
->control
.stop_step
)
2930 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
2933 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
2938 /* No error, don't finish the thread states yet. */
2939 discard_cleanups (ts_old_chain
);
2941 /* Revert thread and frame. */
2942 do_cleanups (old_chain
);
2944 /* If the inferior was in sync execution mode, and now isn't,
2945 restore the prompt (a synchronous execution command has finished,
2946 and we're ready for input). */
2947 if (interpreter_async
&& was_sync
&& !sync_execution
)
2948 display_gdb_prompt (0);
2952 && exec_done_display_p
2953 && (ptid_equal (inferior_ptid
, null_ptid
)
2954 || !is_running (inferior_ptid
)))
2955 printf_unfiltered (_("completed.\n"));
2958 /* Record the frame and location we're currently stepping through. */
2960 set_step_info (struct frame_info
*frame
, struct symtab_and_line sal
)
2962 struct thread_info
*tp
= inferior_thread ();
2964 tp
->control
.step_frame_id
= get_frame_id (frame
);
2965 tp
->control
.step_stack_frame_id
= get_stack_frame_id (frame
);
2967 tp
->current_symtab
= sal
.symtab
;
2968 tp
->current_line
= sal
.line
;
2971 /* Clear context switchable stepping state. */
2974 init_thread_stepping_state (struct thread_info
*tss
)
2976 tss
->stepping_over_breakpoint
= 0;
2977 tss
->step_after_step_resume_breakpoint
= 0;
2980 /* Set the cached copy of the last ptid/waitstatus. */
2983 set_last_target_status (ptid_t ptid
, struct target_waitstatus status
)
2985 target_last_wait_ptid
= ptid
;
2986 target_last_waitstatus
= status
;
2989 /* Return the cached copy of the last pid/waitstatus returned by
2990 target_wait()/deprecated_target_wait_hook(). The data is actually
2991 cached by handle_inferior_event(), which gets called immediately
2992 after target_wait()/deprecated_target_wait_hook(). */
2995 get_last_target_status (ptid_t
*ptidp
, struct target_waitstatus
*status
)
2997 *ptidp
= target_last_wait_ptid
;
2998 *status
= target_last_waitstatus
;
3002 nullify_last_target_wait_ptid (void)
3004 target_last_wait_ptid
= minus_one_ptid
;
3007 /* Switch thread contexts. */
3010 context_switch (ptid_t ptid
)
3012 if (debug_infrun
&& !ptid_equal (ptid
, inferior_ptid
))
3014 fprintf_unfiltered (gdb_stdlog
, "infrun: Switching context from %s ",
3015 target_pid_to_str (inferior_ptid
));
3016 fprintf_unfiltered (gdb_stdlog
, "to %s\n",
3017 target_pid_to_str (ptid
));
3020 switch_to_thread (ptid
);
3024 adjust_pc_after_break (struct execution_control_state
*ecs
)
3026 struct regcache
*regcache
;
3027 struct gdbarch
*gdbarch
;
3028 struct address_space
*aspace
;
3029 CORE_ADDR breakpoint_pc
, decr_pc
;
3031 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
3032 we aren't, just return.
3034 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
3035 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
3036 implemented by software breakpoints should be handled through the normal
3039 NOTE drow/2004-01-31: On some targets, breakpoints may generate
3040 different signals (SIGILL or SIGEMT for instance), but it is less
3041 clear where the PC is pointing afterwards. It may not match
3042 gdbarch_decr_pc_after_break. I don't know any specific target that
3043 generates these signals at breakpoints (the code has been in GDB since at
3044 least 1992) so I can not guess how to handle them here.
3046 In earlier versions of GDB, a target with
3047 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
3048 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
3049 target with both of these set in GDB history, and it seems unlikely to be
3050 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
3052 if (ecs
->ws
.kind
!= TARGET_WAITKIND_STOPPED
)
3055 if (ecs
->ws
.value
.sig
!= GDB_SIGNAL_TRAP
)
3058 /* In reverse execution, when a breakpoint is hit, the instruction
3059 under it has already been de-executed. The reported PC always
3060 points at the breakpoint address, so adjusting it further would
3061 be wrong. E.g., consider this case on a decr_pc_after_break == 1
3064 B1 0x08000000 : INSN1
3065 B2 0x08000001 : INSN2
3067 PC -> 0x08000003 : INSN4
3069 Say you're stopped at 0x08000003 as above. Reverse continuing
3070 from that point should hit B2 as below. Reading the PC when the
3071 SIGTRAP is reported should read 0x08000001 and INSN2 should have
3072 been de-executed already.
3074 B1 0x08000000 : INSN1
3075 B2 PC -> 0x08000001 : INSN2
3079 We can't apply the same logic as for forward execution, because
3080 we would wrongly adjust the PC to 0x08000000, since there's a
3081 breakpoint at PC - 1. We'd then report a hit on B1, although
3082 INSN1 hadn't been de-executed yet. Doing nothing is the correct
3084 if (execution_direction
== EXEC_REVERSE
)
3087 /* If this target does not decrement the PC after breakpoints, then
3088 we have nothing to do. */
3089 regcache
= get_thread_regcache (ecs
->ptid
);
3090 gdbarch
= get_regcache_arch (regcache
);
3092 decr_pc
= target_decr_pc_after_break (gdbarch
);
3096 aspace
= get_regcache_aspace (regcache
);
3098 /* Find the location where (if we've hit a breakpoint) the
3099 breakpoint would be. */
3100 breakpoint_pc
= regcache_read_pc (regcache
) - decr_pc
;
3102 /* Check whether there actually is a software breakpoint inserted at
3105 If in non-stop mode, a race condition is possible where we've
3106 removed a breakpoint, but stop events for that breakpoint were
3107 already queued and arrive later. To suppress those spurious
3108 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
3109 and retire them after a number of stop events are reported. */
3110 if (software_breakpoint_inserted_here_p (aspace
, breakpoint_pc
)
3111 || (non_stop
&& moribund_breakpoint_here_p (aspace
, breakpoint_pc
)))
3113 struct cleanup
*old_cleanups
= make_cleanup (null_cleanup
, NULL
);
3115 if (record_full_is_used ())
3116 record_full_gdb_operation_disable_set ();
3118 /* When using hardware single-step, a SIGTRAP is reported for both
3119 a completed single-step and a software breakpoint. Need to
3120 differentiate between the two, as the latter needs adjusting
3121 but the former does not.
3123 The SIGTRAP can be due to a completed hardware single-step only if
3124 - we didn't insert software single-step breakpoints
3125 - the thread to be examined is still the current thread
3126 - this thread is currently being stepped
3128 If any of these events did not occur, we must have stopped due
3129 to hitting a software breakpoint, and have to back up to the
3132 As a special case, we could have hardware single-stepped a
3133 software breakpoint. In this case (prev_pc == breakpoint_pc),
3134 we also need to back up to the breakpoint address. */
3136 if (singlestep_breakpoints_inserted_p
3137 || !ptid_equal (ecs
->ptid
, inferior_ptid
)
3138 || !currently_stepping (ecs
->event_thread
)
3139 || ecs
->event_thread
->prev_pc
== breakpoint_pc
)
3140 regcache_write_pc (regcache
, breakpoint_pc
);
3142 do_cleanups (old_cleanups
);
3147 init_infwait_state (void)
3149 waiton_ptid
= pid_to_ptid (-1);
3150 infwait_state
= infwait_normal_state
;
3154 stepped_in_from (struct frame_info
*frame
, struct frame_id step_frame_id
)
3156 for (frame
= get_prev_frame (frame
);
3158 frame
= get_prev_frame (frame
))
3160 if (frame_id_eq (get_frame_id (frame
), step_frame_id
))
3162 if (get_frame_type (frame
) != INLINE_FRAME
)
3169 /* Auxiliary function that handles syscall entry/return events.
3170 It returns 1 if the inferior should keep going (and GDB
3171 should ignore the event), or 0 if the event deserves to be
3175 handle_syscall_event (struct execution_control_state
*ecs
)
3177 struct regcache
*regcache
;
3180 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3181 context_switch (ecs
->ptid
);
3183 regcache
= get_thread_regcache (ecs
->ptid
);
3184 syscall_number
= ecs
->ws
.value
.syscall_number
;
3185 stop_pc
= regcache_read_pc (regcache
);
3187 if (catch_syscall_enabled () > 0
3188 && catching_syscall_number (syscall_number
) > 0)
3191 fprintf_unfiltered (gdb_stdlog
, "infrun: syscall number = '%d'\n",
3194 ecs
->event_thread
->control
.stop_bpstat
3195 = bpstat_stop_status (get_regcache_aspace (regcache
),
3196 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3198 if (bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
3200 /* Catchpoint hit. */
3205 /* If no catchpoint triggered for this, then keep going. */
3210 /* Lazily fill in the execution_control_state's stop_func_* fields. */
3213 fill_in_stop_func (struct gdbarch
*gdbarch
,
3214 struct execution_control_state
*ecs
)
3216 if (!ecs
->stop_func_filled_in
)
3218 /* Don't care about return value; stop_func_start and stop_func_name
3219 will both be 0 if it doesn't work. */
3220 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
3221 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
3222 ecs
->stop_func_start
3223 += gdbarch_deprecated_function_start_offset (gdbarch
);
3225 if (gdbarch_skip_entrypoint_p (gdbarch
))
3226 ecs
->stop_func_start
= gdbarch_skip_entrypoint (gdbarch
,
3227 ecs
->stop_func_start
);
3229 ecs
->stop_func_filled_in
= 1;
3234 /* Return the STOP_SOON field of the inferior pointed at by PTID. */
3236 static enum stop_kind
3237 get_inferior_stop_soon (ptid_t ptid
)
3239 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ptid
));
3241 gdb_assert (inf
!= NULL
);
3242 return inf
->control
.stop_soon
;
3245 /* Given an execution control state that has been freshly filled in by
3246 an event from the inferior, figure out what it means and take
3249 The alternatives are:
3251 1) stop_stepping and return; to really stop and return to the
3254 2) keep_going and return; to wait for the next event (set
3255 ecs->event_thread->stepping_over_breakpoint to 1 to single step
3259 handle_inferior_event (struct execution_control_state
*ecs
)
3261 enum stop_kind stop_soon
;
3263 if (ecs
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
3265 /* We had an event in the inferior, but we are not interested in
3266 handling it at this level. The lower layers have already
3267 done what needs to be done, if anything.
3269 One of the possible circumstances for this is when the
3270 inferior produces output for the console. The inferior has
3271 not stopped, and we are ignoring the event. Another possible
3272 circumstance is any event which the lower level knows will be
3273 reported multiple times without an intervening resume. */
3275 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_IGNORE\n");
3276 prepare_to_wait (ecs
);
3280 if (ecs
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
3281 && target_can_async_p () && !sync_execution
)
3283 /* There were no unwaited-for children left in the target, but,
3284 we're not synchronously waiting for events either. Just
3285 ignore. Otherwise, if we were running a synchronous
3286 execution command, we need to cancel it and give the user
3287 back the terminal. */
3289 fprintf_unfiltered (gdb_stdlog
,
3290 "infrun: TARGET_WAITKIND_NO_RESUMED (ignoring)\n");
3291 prepare_to_wait (ecs
);
3295 /* Cache the last pid/waitstatus. */
3296 set_last_target_status (ecs
->ptid
, ecs
->ws
);
3298 /* Always clear state belonging to the previous time we stopped. */
3299 stop_stack_dummy
= STOP_NONE
;
3301 if (ecs
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
)
3303 /* No unwaited-for children left. IOW, all resumed children
3306 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_NO_RESUMED\n");
3308 stop_print_frame
= 0;
3309 stop_stepping (ecs
);
3313 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
3314 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
)
3316 ecs
->event_thread
= find_thread_ptid (ecs
->ptid
);
3317 /* If it's a new thread, add it to the thread database. */
3318 if (ecs
->event_thread
== NULL
)
3319 ecs
->event_thread
= add_thread (ecs
->ptid
);
3321 /* Disable range stepping. If the next step request could use a
3322 range, this will be end up re-enabled then. */
3323 ecs
->event_thread
->control
.may_range_step
= 0;
3326 /* Dependent on valid ECS->EVENT_THREAD. */
3327 adjust_pc_after_break (ecs
);
3329 /* Dependent on the current PC value modified by adjust_pc_after_break. */
3330 reinit_frame_cache ();
3332 breakpoint_retire_moribund ();
3334 /* First, distinguish signals caused by the debugger from signals
3335 that have to do with the program's own actions. Note that
3336 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
3337 on the operating system version. Here we detect when a SIGILL or
3338 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
3339 something similar for SIGSEGV, since a SIGSEGV will be generated
3340 when we're trying to execute a breakpoint instruction on a
3341 non-executable stack. This happens for call dummy breakpoints
3342 for architectures like SPARC that place call dummies on the
3344 if (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
3345 && (ecs
->ws
.value
.sig
== GDB_SIGNAL_ILL
3346 || ecs
->ws
.value
.sig
== GDB_SIGNAL_SEGV
3347 || ecs
->ws
.value
.sig
== GDB_SIGNAL_EMT
))
3349 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3351 if (breakpoint_inserted_here_p (get_regcache_aspace (regcache
),
3352 regcache_read_pc (regcache
)))
3355 fprintf_unfiltered (gdb_stdlog
,
3356 "infrun: Treating signal as SIGTRAP\n");
3357 ecs
->ws
.value
.sig
= GDB_SIGNAL_TRAP
;
3361 /* Mark the non-executing threads accordingly. In all-stop, all
3362 threads of all processes are stopped when we get any event
3363 reported. In non-stop mode, only the event thread stops. If
3364 we're handling a process exit in non-stop mode, there's nothing
3365 to do, as threads of the dead process are gone, and threads of
3366 any other process were left running. */
3368 set_executing (minus_one_ptid
, 0);
3369 else if (ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
3370 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
)
3371 set_executing (ecs
->ptid
, 0);
3373 switch (infwait_state
)
3375 case infwait_normal_state
:
3377 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_normal_state\n");
3380 case infwait_step_watch_state
:
3382 fprintf_unfiltered (gdb_stdlog
,
3383 "infrun: infwait_step_watch_state\n");
3385 ecs
->stepped_after_stopped_by_watchpoint
= 1;
3388 case infwait_nonstep_watch_state
:
3390 fprintf_unfiltered (gdb_stdlog
,
3391 "infrun: infwait_nonstep_watch_state\n");
3392 insert_breakpoints ();
3394 /* FIXME-maybe: is this cleaner than setting a flag? Does it
3395 handle things like signals arriving and other things happening
3396 in combination correctly? */
3397 ecs
->stepped_after_stopped_by_watchpoint
= 1;
3401 internal_error (__FILE__
, __LINE__
, _("bad switch"));
3404 infwait_state
= infwait_normal_state
;
3405 waiton_ptid
= pid_to_ptid (-1);
3407 switch (ecs
->ws
.kind
)
3409 case TARGET_WAITKIND_LOADED
:
3411 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_LOADED\n");
3412 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3413 context_switch (ecs
->ptid
);
3414 /* Ignore gracefully during startup of the inferior, as it might
3415 be the shell which has just loaded some objects, otherwise
3416 add the symbols for the newly loaded objects. Also ignore at
3417 the beginning of an attach or remote session; we will query
3418 the full list of libraries once the connection is
3421 stop_soon
= get_inferior_stop_soon (ecs
->ptid
);
3422 if (stop_soon
== NO_STOP_QUIETLY
)
3424 struct regcache
*regcache
;
3426 regcache
= get_thread_regcache (ecs
->ptid
);
3428 handle_solib_event ();
3430 ecs
->event_thread
->control
.stop_bpstat
3431 = bpstat_stop_status (get_regcache_aspace (regcache
),
3432 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3434 if (bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
3436 /* A catchpoint triggered. */
3437 process_event_stop_test (ecs
);
3441 /* If requested, stop when the dynamic linker notifies
3442 gdb of events. This allows the user to get control
3443 and place breakpoints in initializer routines for
3444 dynamically loaded objects (among other things). */
3445 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3446 if (stop_on_solib_events
)
3448 /* Make sure we print "Stopped due to solib-event" in
3450 stop_print_frame
= 1;
3452 stop_stepping (ecs
);
3457 /* If we are skipping through a shell, or through shared library
3458 loading that we aren't interested in, resume the program. If
3459 we're running the program normally, also resume. */
3460 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== NO_STOP_QUIETLY
)
3462 /* Loading of shared libraries might have changed breakpoint
3463 addresses. Make sure new breakpoints are inserted. */
3464 if (stop_soon
== NO_STOP_QUIETLY
3465 && !breakpoints_always_inserted_mode ())
3466 insert_breakpoints ();
3467 resume (0, GDB_SIGNAL_0
);
3468 prepare_to_wait (ecs
);
3472 /* But stop if we're attaching or setting up a remote
3474 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
3475 || stop_soon
== STOP_QUIETLY_REMOTE
)
3478 fprintf_unfiltered (gdb_stdlog
, "infrun: quietly stopped\n");
3479 stop_stepping (ecs
);
3483 internal_error (__FILE__
, __LINE__
,
3484 _("unhandled stop_soon: %d"), (int) stop_soon
);
3486 case TARGET_WAITKIND_SPURIOUS
:
3488 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SPURIOUS\n");
3489 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3490 context_switch (ecs
->ptid
);
3491 resume (0, GDB_SIGNAL_0
);
3492 prepare_to_wait (ecs
);
3495 case TARGET_WAITKIND_EXITED
:
3496 case TARGET_WAITKIND_SIGNALLED
:
3499 if (ecs
->ws
.kind
== TARGET_WAITKIND_EXITED
)
3500 fprintf_unfiltered (gdb_stdlog
,
3501 "infrun: TARGET_WAITKIND_EXITED\n");
3503 fprintf_unfiltered (gdb_stdlog
,
3504 "infrun: TARGET_WAITKIND_SIGNALLED\n");
3507 inferior_ptid
= ecs
->ptid
;
3508 set_current_inferior (find_inferior_pid (ptid_get_pid (ecs
->ptid
)));
3509 set_current_program_space (current_inferior ()->pspace
);
3510 handle_vfork_child_exec_or_exit (0);
3511 target_terminal_ours (); /* Must do this before mourn anyway. */
3513 /* Clearing any previous state of convenience variables. */
3514 clear_exit_convenience_vars ();
3516 if (ecs
->ws
.kind
== TARGET_WAITKIND_EXITED
)
3518 /* Record the exit code in the convenience variable $_exitcode, so
3519 that the user can inspect this again later. */
3520 set_internalvar_integer (lookup_internalvar ("_exitcode"),
3521 (LONGEST
) ecs
->ws
.value
.integer
);
3523 /* Also record this in the inferior itself. */
3524 current_inferior ()->has_exit_code
= 1;
3525 current_inferior ()->exit_code
= (LONGEST
) ecs
->ws
.value
.integer
;
3527 /* Support the --return-child-result option. */
3528 return_child_result_value
= ecs
->ws
.value
.integer
;
3530 print_exited_reason (ecs
->ws
.value
.integer
);
3534 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3535 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3537 if (gdbarch_gdb_signal_to_target_p (gdbarch
))
3539 /* Set the value of the internal variable $_exitsignal,
3540 which holds the signal uncaught by the inferior. */
3541 set_internalvar_integer (lookup_internalvar ("_exitsignal"),
3542 gdbarch_gdb_signal_to_target (gdbarch
,
3543 ecs
->ws
.value
.sig
));
3547 /* We don't have access to the target's method used for
3548 converting between signal numbers (GDB's internal
3549 representation <-> target's representation).
3550 Therefore, we cannot do a good job at displaying this
3551 information to the user. It's better to just warn
3552 her about it (if infrun debugging is enabled), and
3555 fprintf_filtered (gdb_stdlog
, _("\
3556 Cannot fill $_exitsignal with the correct signal number.\n"));
3559 print_signal_exited_reason (ecs
->ws
.value
.sig
);
3562 gdb_flush (gdb_stdout
);
3563 target_mourn_inferior ();
3564 singlestep_breakpoints_inserted_p
= 0;
3565 cancel_single_step_breakpoints ();
3566 stop_print_frame
= 0;
3567 stop_stepping (ecs
);
3570 /* The following are the only cases in which we keep going;
3571 the above cases end in a continue or goto. */
3572 case TARGET_WAITKIND_FORKED
:
3573 case TARGET_WAITKIND_VFORKED
:
3576 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
3577 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_FORKED\n");
3579 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_VFORKED\n");
3582 /* Check whether the inferior is displaced stepping. */
3584 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3585 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3586 struct displaced_step_inferior_state
*displaced
3587 = get_displaced_stepping_state (ptid_get_pid (ecs
->ptid
));
3589 /* If checking displaced stepping is supported, and thread
3590 ecs->ptid is displaced stepping. */
3591 if (displaced
&& ptid_equal (displaced
->step_ptid
, ecs
->ptid
))
3593 struct inferior
*parent_inf
3594 = find_inferior_pid (ptid_get_pid (ecs
->ptid
));
3595 struct regcache
*child_regcache
;
3596 CORE_ADDR parent_pc
;
3598 /* GDB has got TARGET_WAITKIND_FORKED or TARGET_WAITKIND_VFORKED,
3599 indicating that the displaced stepping of syscall instruction
3600 has been done. Perform cleanup for parent process here. Note
3601 that this operation also cleans up the child process for vfork,
3602 because their pages are shared. */
3603 displaced_step_fixup (ecs
->ptid
, GDB_SIGNAL_TRAP
);
3605 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
3607 /* Restore scratch pad for child process. */
3608 displaced_step_restore (displaced
, ecs
->ws
.value
.related_pid
);
3611 /* Since the vfork/fork syscall instruction was executed in the scratchpad,
3612 the child's PC is also within the scratchpad. Set the child's PC
3613 to the parent's PC value, which has already been fixed up.
3614 FIXME: we use the parent's aspace here, although we're touching
3615 the child, because the child hasn't been added to the inferior
3616 list yet at this point. */
3619 = get_thread_arch_aspace_regcache (ecs
->ws
.value
.related_pid
,
3621 parent_inf
->aspace
);
3622 /* Read PC value of parent process. */
3623 parent_pc
= regcache_read_pc (regcache
);
3625 if (debug_displaced
)
3626 fprintf_unfiltered (gdb_stdlog
,
3627 "displaced: write child pc from %s to %s\n",
3629 regcache_read_pc (child_regcache
)),
3630 paddress (gdbarch
, parent_pc
));
3632 regcache_write_pc (child_regcache
, parent_pc
);
3636 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3637 context_switch (ecs
->ptid
);
3639 /* Immediately detach breakpoints from the child before there's
3640 any chance of letting the user delete breakpoints from the
3641 breakpoint lists. If we don't do this early, it's easy to
3642 leave left over traps in the child, vis: "break foo; catch
3643 fork; c; <fork>; del; c; <child calls foo>". We only follow
3644 the fork on the last `continue', and by that time the
3645 breakpoint at "foo" is long gone from the breakpoint table.
3646 If we vforked, then we don't need to unpatch here, since both
3647 parent and child are sharing the same memory pages; we'll
3648 need to unpatch at follow/detach time instead to be certain
3649 that new breakpoints added between catchpoint hit time and
3650 vfork follow are detached. */
3651 if (ecs
->ws
.kind
!= TARGET_WAITKIND_VFORKED
)
3653 /* This won't actually modify the breakpoint list, but will
3654 physically remove the breakpoints from the child. */
3655 detach_breakpoints (ecs
->ws
.value
.related_pid
);
3658 if (singlestep_breakpoints_inserted_p
)
3660 /* Pull the single step breakpoints out of the target. */
3661 remove_single_step_breakpoints ();
3662 singlestep_breakpoints_inserted_p
= 0;
3665 /* In case the event is caught by a catchpoint, remember that
3666 the event is to be followed at the next resume of the thread,
3667 and not immediately. */
3668 ecs
->event_thread
->pending_follow
= ecs
->ws
;
3670 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3672 ecs
->event_thread
->control
.stop_bpstat
3673 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3674 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3676 /* If no catchpoint triggered for this, then keep going. Note
3677 that we're interested in knowing the bpstat actually causes a
3678 stop, not just if it may explain the signal. Software
3679 watchpoints, for example, always appear in the bpstat. */
3680 if (!bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
3686 = (follow_fork_mode_string
== follow_fork_mode_child
);
3688 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3690 should_resume
= follow_fork ();
3693 child
= ecs
->ws
.value
.related_pid
;
3695 /* In non-stop mode, also resume the other branch. */
3696 if (non_stop
&& !detach_fork
)
3699 switch_to_thread (parent
);
3701 switch_to_thread (child
);
3703 ecs
->event_thread
= inferior_thread ();
3704 ecs
->ptid
= inferior_ptid
;
3709 switch_to_thread (child
);
3711 switch_to_thread (parent
);
3713 ecs
->event_thread
= inferior_thread ();
3714 ecs
->ptid
= inferior_ptid
;
3719 stop_stepping (ecs
);
3722 process_event_stop_test (ecs
);
3725 case TARGET_WAITKIND_VFORK_DONE
:
3726 /* Done with the shared memory region. Re-insert breakpoints in
3727 the parent, and keep going. */
3730 fprintf_unfiltered (gdb_stdlog
,
3731 "infrun: TARGET_WAITKIND_VFORK_DONE\n");
3733 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3734 context_switch (ecs
->ptid
);
3736 current_inferior ()->waiting_for_vfork_done
= 0;
3737 current_inferior ()->pspace
->breakpoints_not_allowed
= 0;
3738 /* This also takes care of reinserting breakpoints in the
3739 previously locked inferior. */
3743 case TARGET_WAITKIND_EXECD
:
3745 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_EXECD\n");
3747 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3748 context_switch (ecs
->ptid
);
3750 singlestep_breakpoints_inserted_p
= 0;
3751 cancel_single_step_breakpoints ();
3753 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3755 /* Do whatever is necessary to the parent branch of the vfork. */
3756 handle_vfork_child_exec_or_exit (1);
3758 /* This causes the eventpoints and symbol table to be reset.
3759 Must do this now, before trying to determine whether to
3761 follow_exec (inferior_ptid
, ecs
->ws
.value
.execd_pathname
);
3763 ecs
->event_thread
->control
.stop_bpstat
3764 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3765 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3767 /* Note that this may be referenced from inside
3768 bpstat_stop_status above, through inferior_has_execd. */
3769 xfree (ecs
->ws
.value
.execd_pathname
);
3770 ecs
->ws
.value
.execd_pathname
= NULL
;
3772 /* If no catchpoint triggered for this, then keep going. */
3773 if (!bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
3775 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3779 process_event_stop_test (ecs
);
3782 /* Be careful not to try to gather much state about a thread
3783 that's in a syscall. It's frequently a losing proposition. */
3784 case TARGET_WAITKIND_SYSCALL_ENTRY
:
3786 fprintf_unfiltered (gdb_stdlog
,
3787 "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
3788 /* Getting the current syscall number. */
3789 if (handle_syscall_event (ecs
) == 0)
3790 process_event_stop_test (ecs
);
3793 /* Before examining the threads further, step this thread to
3794 get it entirely out of the syscall. (We get notice of the
3795 event when the thread is just on the verge of exiting a
3796 syscall. Stepping one instruction seems to get it back
3798 case TARGET_WAITKIND_SYSCALL_RETURN
:
3800 fprintf_unfiltered (gdb_stdlog
,
3801 "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
3802 if (handle_syscall_event (ecs
) == 0)
3803 process_event_stop_test (ecs
);
3806 case TARGET_WAITKIND_STOPPED
:
3808 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_STOPPED\n");
3809 ecs
->event_thread
->suspend
.stop_signal
= ecs
->ws
.value
.sig
;
3810 handle_signal_stop (ecs
);
3813 case TARGET_WAITKIND_NO_HISTORY
:
3815 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_NO_HISTORY\n");
3816 /* Reverse execution: target ran out of history info. */
3818 /* Pull the single step breakpoints out of the target. */
3819 if (singlestep_breakpoints_inserted_p
)
3821 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3822 context_switch (ecs
->ptid
);
3823 remove_single_step_breakpoints ();
3824 singlestep_breakpoints_inserted_p
= 0;
3826 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3827 print_no_history_reason ();
3828 stop_stepping (ecs
);
3833 /* Come here when the program has stopped with a signal. */
3836 handle_signal_stop (struct execution_control_state
*ecs
)
3838 struct frame_info
*frame
;
3839 struct gdbarch
*gdbarch
;
3840 int stopped_by_watchpoint
;
3841 enum stop_kind stop_soon
;
3844 gdb_assert (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
3846 /* Do we need to clean up the state of a thread that has
3847 completed a displaced single-step? (Doing so usually affects
3848 the PC, so do it here, before we set stop_pc.) */
3849 displaced_step_fixup (ecs
->ptid
,
3850 ecs
->event_thread
->suspend
.stop_signal
);
3852 /* If we either finished a single-step or hit a breakpoint, but
3853 the user wanted this thread to be stopped, pretend we got a
3854 SIG0 (generic unsignaled stop). */
3855 if (ecs
->event_thread
->stop_requested
3856 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
3857 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3859 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3863 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3864 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3865 struct cleanup
*old_chain
= save_inferior_ptid ();
3867 inferior_ptid
= ecs
->ptid
;
3869 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_pc = %s\n",
3870 paddress (gdbarch
, stop_pc
));
3871 if (target_stopped_by_watchpoint ())
3875 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped by watchpoint\n");
3877 if (target_stopped_data_address (¤t_target
, &addr
))
3878 fprintf_unfiltered (gdb_stdlog
,
3879 "infrun: stopped data address = %s\n",
3880 paddress (gdbarch
, addr
));
3882 fprintf_unfiltered (gdb_stdlog
,
3883 "infrun: (no data address available)\n");
3886 do_cleanups (old_chain
);
3889 /* This is originated from start_remote(), start_inferior() and
3890 shared libraries hook functions. */
3891 stop_soon
= get_inferior_stop_soon (ecs
->ptid
);
3892 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_REMOTE
)
3894 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3895 context_switch (ecs
->ptid
);
3897 fprintf_unfiltered (gdb_stdlog
, "infrun: quietly stopped\n");
3898 stop_print_frame
= 1;
3899 stop_stepping (ecs
);
3903 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
3906 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3907 context_switch (ecs
->ptid
);
3909 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped\n");
3910 stop_print_frame
= 0;
3911 stop_stepping (ecs
);
3915 /* This originates from attach_command(). We need to overwrite
3916 the stop_signal here, because some kernels don't ignore a
3917 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
3918 See more comments in inferior.h. On the other hand, if we
3919 get a non-SIGSTOP, report it to the user - assume the backend
3920 will handle the SIGSTOP if it should show up later.
3922 Also consider that the attach is complete when we see a
3923 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
3924 target extended-remote report it instead of a SIGSTOP
3925 (e.g. gdbserver). We already rely on SIGTRAP being our
3926 signal, so this is no exception.
3928 Also consider that the attach is complete when we see a
3929 GDB_SIGNAL_0. In non-stop mode, GDB will explicitly tell
3930 the target to stop all threads of the inferior, in case the
3931 low level attach operation doesn't stop them implicitly. If
3932 they weren't stopped implicitly, then the stub will report a
3933 GDB_SIGNAL_0, meaning: stopped for no particular reason
3934 other than GDB's request. */
3935 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
3936 && (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_STOP
3937 || ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
3938 || ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_0
))
3940 stop_print_frame
= 1;
3941 stop_stepping (ecs
);
3942 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3946 /* See if something interesting happened to the non-current thread. If
3947 so, then switch to that thread. */
3948 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3951 fprintf_unfiltered (gdb_stdlog
, "infrun: context switch\n");
3953 context_switch (ecs
->ptid
);
3955 if (deprecated_context_hook
)
3956 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
3959 /* At this point, get hold of the now-current thread's frame. */
3960 frame
= get_current_frame ();
3961 gdbarch
= get_frame_arch (frame
);
3963 /* Pull the single step breakpoints out of the target. */
3964 if (singlestep_breakpoints_inserted_p
)
3966 /* However, before doing so, if this single-step breakpoint was
3967 actually for another thread, set this thread up for moving
3969 if (!ptid_equal (ecs
->ptid
, singlestep_ptid
)
3970 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
3972 struct regcache
*regcache
;
3973 struct address_space
*aspace
;
3976 regcache
= get_thread_regcache (ecs
->ptid
);
3977 aspace
= get_regcache_aspace (regcache
);
3978 pc
= regcache_read_pc (regcache
);
3979 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
3983 fprintf_unfiltered (gdb_stdlog
,
3984 "infrun: [%s] hit step over single-step"
3985 " breakpoint of [%s]\n",
3986 target_pid_to_str (ecs
->ptid
),
3987 target_pid_to_str (singlestep_ptid
));
3989 ecs
->hit_singlestep_breakpoint
= 1;
3993 remove_single_step_breakpoints ();
3994 singlestep_breakpoints_inserted_p
= 0;
3997 if (ecs
->stepped_after_stopped_by_watchpoint
)
3998 stopped_by_watchpoint
= 0;
4000 stopped_by_watchpoint
= watchpoints_triggered (&ecs
->ws
);
4002 /* If necessary, step over this watchpoint. We'll be back to display
4004 if (stopped_by_watchpoint
4005 && (target_have_steppable_watchpoint
4006 || gdbarch_have_nonsteppable_watchpoint (gdbarch
)))
4008 /* At this point, we are stopped at an instruction which has
4009 attempted to write to a piece of memory under control of
4010 a watchpoint. The instruction hasn't actually executed
4011 yet. If we were to evaluate the watchpoint expression
4012 now, we would get the old value, and therefore no change
4013 would seem to have occurred.
4015 In order to make watchpoints work `right', we really need
4016 to complete the memory write, and then evaluate the
4017 watchpoint expression. We do this by single-stepping the
4020 It may not be necessary to disable the watchpoint to stop over
4021 it. For example, the PA can (with some kernel cooperation)
4022 single step over a watchpoint without disabling the watchpoint.
4024 It is far more common to need to disable a watchpoint to step
4025 the inferior over it. If we have non-steppable watchpoints,
4026 we must disable the current watchpoint; it's simplest to
4027 disable all watchpoints and breakpoints. */
4030 if (!target_have_steppable_watchpoint
)
4032 remove_breakpoints ();
4033 /* See comment in resume why we need to stop bypassing signals
4034 while breakpoints have been removed. */
4035 target_pass_signals (0, NULL
);
4038 hw_step
= maybe_software_singlestep (gdbarch
, stop_pc
);
4039 target_resume (ecs
->ptid
, hw_step
, GDB_SIGNAL_0
);
4040 waiton_ptid
= ecs
->ptid
;
4041 if (target_have_steppable_watchpoint
)
4042 infwait_state
= infwait_step_watch_state
;
4044 infwait_state
= infwait_nonstep_watch_state
;
4045 prepare_to_wait (ecs
);
4049 ecs
->event_thread
->stepping_over_breakpoint
= 0;
4050 bpstat_clear (&ecs
->event_thread
->control
.stop_bpstat
);
4051 ecs
->event_thread
->control
.stop_step
= 0;
4052 stop_print_frame
= 1;
4053 stopped_by_random_signal
= 0;
4055 /* Hide inlined functions starting here, unless we just performed stepi or
4056 nexti. After stepi and nexti, always show the innermost frame (not any
4057 inline function call sites). */
4058 if (ecs
->event_thread
->control
.step_range_end
!= 1)
4060 struct address_space
*aspace
=
4061 get_regcache_aspace (get_thread_regcache (ecs
->ptid
));
4063 /* skip_inline_frames is expensive, so we avoid it if we can
4064 determine that the address is one where functions cannot have
4065 been inlined. This improves performance with inferiors that
4066 load a lot of shared libraries, because the solib event
4067 breakpoint is defined as the address of a function (i.e. not
4068 inline). Note that we have to check the previous PC as well
4069 as the current one to catch cases when we have just
4070 single-stepped off a breakpoint prior to reinstating it.
4071 Note that we're assuming that the code we single-step to is
4072 not inline, but that's not definitive: there's nothing
4073 preventing the event breakpoint function from containing
4074 inlined code, and the single-step ending up there. If the
4075 user had set a breakpoint on that inlined code, the missing
4076 skip_inline_frames call would break things. Fortunately
4077 that's an extremely unlikely scenario. */
4078 if (!pc_at_non_inline_function (aspace
, stop_pc
, &ecs
->ws
)
4079 && !(ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4080 && ecs
->event_thread
->control
.trap_expected
4081 && pc_at_non_inline_function (aspace
,
4082 ecs
->event_thread
->prev_pc
,
4085 skip_inline_frames (ecs
->ptid
);
4087 /* Re-fetch current thread's frame in case that invalidated
4089 frame
= get_current_frame ();
4090 gdbarch
= get_frame_arch (frame
);
4094 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4095 && ecs
->event_thread
->control
.trap_expected
4096 && gdbarch_single_step_through_delay_p (gdbarch
)
4097 && currently_stepping (ecs
->event_thread
))
4099 /* We're trying to step off a breakpoint. Turns out that we're
4100 also on an instruction that needs to be stepped multiple
4101 times before it's been fully executing. E.g., architectures
4102 with a delay slot. It needs to be stepped twice, once for
4103 the instruction and once for the delay slot. */
4104 int step_through_delay
4105 = gdbarch_single_step_through_delay (gdbarch
, frame
);
4107 if (debug_infrun
&& step_through_delay
)
4108 fprintf_unfiltered (gdb_stdlog
, "infrun: step through delay\n");
4109 if (ecs
->event_thread
->control
.step_range_end
== 0
4110 && step_through_delay
)
4112 /* The user issued a continue when stopped at a breakpoint.
4113 Set up for another trap and get out of here. */
4114 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4118 else if (step_through_delay
)
4120 /* The user issued a step when stopped at a breakpoint.
4121 Maybe we should stop, maybe we should not - the delay
4122 slot *might* correspond to a line of source. In any
4123 case, don't decide that here, just set
4124 ecs->stepping_over_breakpoint, making sure we
4125 single-step again before breakpoints are re-inserted. */
4126 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4130 /* See if there is a breakpoint/watchpoint/catchpoint/etc. that
4131 handles this event. */
4132 ecs
->event_thread
->control
.stop_bpstat
4133 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
4134 stop_pc
, ecs
->ptid
, &ecs
->ws
);
4136 /* Following in case break condition called a
4138 stop_print_frame
= 1;
4140 /* This is where we handle "moribund" watchpoints. Unlike
4141 software breakpoints traps, hardware watchpoint traps are
4142 always distinguishable from random traps. If no high-level
4143 watchpoint is associated with the reported stop data address
4144 anymore, then the bpstat does not explain the signal ---
4145 simply make sure to ignore it if `stopped_by_watchpoint' is
4149 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4150 && !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
4152 && stopped_by_watchpoint
)
4153 fprintf_unfiltered (gdb_stdlog
,
4154 "infrun: no user watchpoint explains "
4155 "watchpoint SIGTRAP, ignoring\n");
4157 /* NOTE: cagney/2003-03-29: These checks for a random signal
4158 at one stage in the past included checks for an inferior
4159 function call's call dummy's return breakpoint. The original
4160 comment, that went with the test, read:
4162 ``End of a stack dummy. Some systems (e.g. Sony news) give
4163 another signal besides SIGTRAP, so check here as well as
4166 If someone ever tries to get call dummys on a
4167 non-executable stack to work (where the target would stop
4168 with something like a SIGSEGV), then those tests might need
4169 to be re-instated. Given, however, that the tests were only
4170 enabled when momentary breakpoints were not being used, I
4171 suspect that it won't be the case.
4173 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
4174 be necessary for call dummies on a non-executable stack on
4177 /* See if the breakpoints module can explain the signal. */
4179 = !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
4180 ecs
->event_thread
->suspend
.stop_signal
);
4182 /* If not, perhaps stepping/nexting can. */
4184 random_signal
= !(ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4185 && currently_stepping (ecs
->event_thread
));
4187 /* Perhaps the thread hit a single-step breakpoint of _another_
4188 thread. Single-step breakpoints are transparent to the
4189 breakpoints module. */
4191 random_signal
= !ecs
->hit_singlestep_breakpoint
;
4193 /* No? Perhaps we got a moribund watchpoint. */
4195 random_signal
= !stopped_by_watchpoint
;
4197 /* For the program's own signals, act according to
4198 the signal handling tables. */
4202 /* Signal not for debugging purposes. */
4204 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ecs
->ptid
));
4205 enum gdb_signal stop_signal
= ecs
->event_thread
->suspend
.stop_signal
;
4208 fprintf_unfiltered (gdb_stdlog
, "infrun: random signal (%s)\n",
4209 gdb_signal_to_symbol_string (stop_signal
));
4211 stopped_by_random_signal
= 1;
4213 if (signal_print
[ecs
->event_thread
->suspend
.stop_signal
])
4216 target_terminal_ours_for_output ();
4217 print_signal_received_reason
4218 (ecs
->event_thread
->suspend
.stop_signal
);
4220 /* Always stop on signals if we're either just gaining control
4221 of the program, or the user explicitly requested this thread
4222 to remain stopped. */
4223 if (stop_soon
!= NO_STOP_QUIETLY
4224 || ecs
->event_thread
->stop_requested
4226 && signal_stop_state (ecs
->event_thread
->suspend
.stop_signal
)))
4228 stop_stepping (ecs
);
4231 /* If not going to stop, give terminal back
4232 if we took it away. */
4234 target_terminal_inferior ();
4236 /* Clear the signal if it should not be passed. */
4237 if (signal_program
[ecs
->event_thread
->suspend
.stop_signal
] == 0)
4238 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4240 if (ecs
->event_thread
->prev_pc
== stop_pc
4241 && ecs
->event_thread
->control
.trap_expected
4242 && ecs
->event_thread
->control
.step_resume_breakpoint
== NULL
)
4244 /* We were just starting a new sequence, attempting to
4245 single-step off of a breakpoint and expecting a SIGTRAP.
4246 Instead this signal arrives. This signal will take us out
4247 of the stepping range so GDB needs to remember to, when
4248 the signal handler returns, resume stepping off that
4250 /* To simplify things, "continue" is forced to use the same
4251 code paths as single-step - set a breakpoint at the
4252 signal return address and then, once hit, step off that
4255 fprintf_unfiltered (gdb_stdlog
,
4256 "infrun: signal arrived while stepping over "
4259 insert_hp_step_resume_breakpoint_at_frame (frame
);
4260 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
4261 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4262 ecs
->event_thread
->control
.trap_expected
= 0;
4264 /* If we were nexting/stepping some other thread, switch to
4265 it, so that we don't continue it, losing control. */
4266 if (!switch_back_to_stepped_thread (ecs
))
4271 if (ecs
->event_thread
->control
.step_range_end
!= 0
4272 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
4273 && pc_in_thread_step_range (stop_pc
, ecs
->event_thread
)
4274 && frame_id_eq (get_stack_frame_id (frame
),
4275 ecs
->event_thread
->control
.step_stack_frame_id
)
4276 && ecs
->event_thread
->control
.step_resume_breakpoint
== NULL
)
4278 /* The inferior is about to take a signal that will take it
4279 out of the single step range. Set a breakpoint at the
4280 current PC (which is presumably where the signal handler
4281 will eventually return) and then allow the inferior to
4284 Note that this is only needed for a signal delivered
4285 while in the single-step range. Nested signals aren't a
4286 problem as they eventually all return. */
4288 fprintf_unfiltered (gdb_stdlog
,
4289 "infrun: signal may take us out of "
4290 "single-step range\n");
4292 insert_hp_step_resume_breakpoint_at_frame (frame
);
4293 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4294 ecs
->event_thread
->control
.trap_expected
= 0;
4299 /* Note: step_resume_breakpoint may be non-NULL. This occures
4300 when either there's a nested signal, or when there's a
4301 pending signal enabled just as the signal handler returns
4302 (leaving the inferior at the step-resume-breakpoint without
4303 actually executing it). Either way continue until the
4304 breakpoint is really hit. */
4306 if (!switch_back_to_stepped_thread (ecs
))
4309 fprintf_unfiltered (gdb_stdlog
,
4310 "infrun: random signal, keep going\n");
4317 process_event_stop_test (ecs
);
4320 /* Come here when we've got some debug event / signal we can explain
4321 (IOW, not a random signal), and test whether it should cause a
4322 stop, or whether we should resume the inferior (transparently).
4323 E.g., could be a breakpoint whose condition evaluates false; we
4324 could be still stepping within the line; etc. */
4327 process_event_stop_test (struct execution_control_state
*ecs
)
4329 struct symtab_and_line stop_pc_sal
;
4330 struct frame_info
*frame
;
4331 struct gdbarch
*gdbarch
;
4332 CORE_ADDR jmp_buf_pc
;
4333 struct bpstat_what what
;
4335 /* Handle cases caused by hitting a breakpoint. */
4337 frame
= get_current_frame ();
4338 gdbarch
= get_frame_arch (frame
);
4340 what
= bpstat_what (ecs
->event_thread
->control
.stop_bpstat
);
4342 if (what
.call_dummy
)
4344 stop_stack_dummy
= what
.call_dummy
;
4347 /* If we hit an internal event that triggers symbol changes, the
4348 current frame will be invalidated within bpstat_what (e.g., if we
4349 hit an internal solib event). Re-fetch it. */
4350 frame
= get_current_frame ();
4351 gdbarch
= get_frame_arch (frame
);
4353 switch (what
.main_action
)
4355 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
4356 /* If we hit the breakpoint at longjmp while stepping, we
4357 install a momentary breakpoint at the target of the
4361 fprintf_unfiltered (gdb_stdlog
,
4362 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
4364 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4366 if (what
.is_longjmp
)
4368 struct value
*arg_value
;
4370 /* If we set the longjmp breakpoint via a SystemTap probe,
4371 then use it to extract the arguments. The destination PC
4372 is the third argument to the probe. */
4373 arg_value
= probe_safe_evaluate_at_pc (frame
, 2);
4375 jmp_buf_pc
= value_as_address (arg_value
);
4376 else if (!gdbarch_get_longjmp_target_p (gdbarch
)
4377 || !gdbarch_get_longjmp_target (gdbarch
,
4378 frame
, &jmp_buf_pc
))
4381 fprintf_unfiltered (gdb_stdlog
,
4382 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME "
4383 "(!gdbarch_get_longjmp_target)\n");
4388 /* Insert a breakpoint at resume address. */
4389 insert_longjmp_resume_breakpoint (gdbarch
, jmp_buf_pc
);
4392 check_exception_resume (ecs
, frame
);
4396 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
4398 struct frame_info
*init_frame
;
4400 /* There are several cases to consider.
4402 1. The initiating frame no longer exists. In this case we
4403 must stop, because the exception or longjmp has gone too
4406 2. The initiating frame exists, and is the same as the
4407 current frame. We stop, because the exception or longjmp
4410 3. The initiating frame exists and is different from the
4411 current frame. This means the exception or longjmp has
4412 been caught beneath the initiating frame, so keep going.
4414 4. longjmp breakpoint has been placed just to protect
4415 against stale dummy frames and user is not interested in
4416 stopping around longjmps. */
4419 fprintf_unfiltered (gdb_stdlog
,
4420 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
4422 gdb_assert (ecs
->event_thread
->control
.exception_resume_breakpoint
4424 delete_exception_resume_breakpoint (ecs
->event_thread
);
4426 if (what
.is_longjmp
)
4428 check_longjmp_breakpoint_for_call_dummy (ecs
->event_thread
->num
);
4430 if (!frame_id_p (ecs
->event_thread
->initiating_frame
))
4438 init_frame
= frame_find_by_id (ecs
->event_thread
->initiating_frame
);
4442 struct frame_id current_id
4443 = get_frame_id (get_current_frame ());
4444 if (frame_id_eq (current_id
,
4445 ecs
->event_thread
->initiating_frame
))
4447 /* Case 2. Fall through. */
4457 /* For Cases 1 and 2, remove the step-resume breakpoint, if it
4459 delete_step_resume_breakpoint (ecs
->event_thread
);
4461 ecs
->event_thread
->control
.stop_step
= 1;
4462 print_end_stepping_range_reason ();
4463 stop_stepping (ecs
);
4467 case BPSTAT_WHAT_SINGLE
:
4469 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_SINGLE\n");
4470 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4471 /* Still need to check other stuff, at least the case where we
4472 are stepping and step out of the right range. */
4475 case BPSTAT_WHAT_STEP_RESUME
:
4477 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
4479 delete_step_resume_breakpoint (ecs
->event_thread
);
4480 if (ecs
->event_thread
->control
.proceed_to_finish
4481 && execution_direction
== EXEC_REVERSE
)
4483 struct thread_info
*tp
= ecs
->event_thread
;
4485 /* We are finishing a function in reverse, and just hit the
4486 step-resume breakpoint at the start address of the
4487 function, and we're almost there -- just need to back up
4488 by one more single-step, which should take us back to the
4490 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
4494 fill_in_stop_func (gdbarch
, ecs
);
4495 if (stop_pc
== ecs
->stop_func_start
4496 && execution_direction
== EXEC_REVERSE
)
4498 /* We are stepping over a function call in reverse, and just
4499 hit the step-resume breakpoint at the start address of
4500 the function. Go back to single-stepping, which should
4501 take us back to the function call. */
4502 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4508 case BPSTAT_WHAT_STOP_NOISY
:
4510 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
4511 stop_print_frame
= 1;
4513 /* Assume the thread stopped for a breapoint. We'll still check
4514 whether a/the breakpoint is there when the thread is next
4516 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4518 stop_stepping (ecs
);
4521 case BPSTAT_WHAT_STOP_SILENT
:
4523 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
4524 stop_print_frame
= 0;
4526 /* Assume the thread stopped for a breapoint. We'll still check
4527 whether a/the breakpoint is there when the thread is next
4529 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4530 stop_stepping (ecs
);
4533 case BPSTAT_WHAT_HP_STEP_RESUME
:
4535 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_HP_STEP_RESUME\n");
4537 delete_step_resume_breakpoint (ecs
->event_thread
);
4538 if (ecs
->event_thread
->step_after_step_resume_breakpoint
)
4540 /* Back when the step-resume breakpoint was inserted, we
4541 were trying to single-step off a breakpoint. Go back to
4543 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
4544 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4550 case BPSTAT_WHAT_KEEP_CHECKING
:
4554 /* We come here if we hit a breakpoint but should not stop for it.
4555 Possibly we also were stepping and should stop for that. So fall
4556 through and test for stepping. But, if not stepping, do not
4559 /* In all-stop mode, if we're currently stepping but have stopped in
4560 some other thread, we need to switch back to the stepped thread. */
4561 if (switch_back_to_stepped_thread (ecs
))
4564 if (ecs
->event_thread
->control
.step_resume_breakpoint
)
4567 fprintf_unfiltered (gdb_stdlog
,
4568 "infrun: step-resume breakpoint is inserted\n");
4570 /* Having a step-resume breakpoint overrides anything
4571 else having to do with stepping commands until
4572 that breakpoint is reached. */
4577 if (ecs
->event_thread
->control
.step_range_end
== 0)
4580 fprintf_unfiltered (gdb_stdlog
, "infrun: no stepping, continue\n");
4581 /* Likewise if we aren't even stepping. */
4586 /* Re-fetch current thread's frame in case the code above caused
4587 the frame cache to be re-initialized, making our FRAME variable
4588 a dangling pointer. */
4589 frame
= get_current_frame ();
4590 gdbarch
= get_frame_arch (frame
);
4591 fill_in_stop_func (gdbarch
, ecs
);
4593 /* If stepping through a line, keep going if still within it.
4595 Note that step_range_end is the address of the first instruction
4596 beyond the step range, and NOT the address of the last instruction
4599 Note also that during reverse execution, we may be stepping
4600 through a function epilogue and therefore must detect when
4601 the current-frame changes in the middle of a line. */
4603 if (pc_in_thread_step_range (stop_pc
, ecs
->event_thread
)
4604 && (execution_direction
!= EXEC_REVERSE
4605 || frame_id_eq (get_frame_id (frame
),
4606 ecs
->event_thread
->control
.step_frame_id
)))
4610 (gdb_stdlog
, "infrun: stepping inside range [%s-%s]\n",
4611 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_start
),
4612 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_end
));
4614 /* Tentatively re-enable range stepping; `resume' disables it if
4615 necessary (e.g., if we're stepping over a breakpoint or we
4616 have software watchpoints). */
4617 ecs
->event_thread
->control
.may_range_step
= 1;
4619 /* When stepping backward, stop at beginning of line range
4620 (unless it's the function entry point, in which case
4621 keep going back to the call point). */
4622 if (stop_pc
== ecs
->event_thread
->control
.step_range_start
4623 && stop_pc
!= ecs
->stop_func_start
4624 && execution_direction
== EXEC_REVERSE
)
4626 ecs
->event_thread
->control
.stop_step
= 1;
4627 print_end_stepping_range_reason ();
4628 stop_stepping (ecs
);
4636 /* We stepped out of the stepping range. */
4638 /* If we are stepping at the source level and entered the runtime
4639 loader dynamic symbol resolution code...
4641 EXEC_FORWARD: we keep on single stepping until we exit the run
4642 time loader code and reach the callee's address.
4644 EXEC_REVERSE: we've already executed the callee (backward), and
4645 the runtime loader code is handled just like any other
4646 undebuggable function call. Now we need only keep stepping
4647 backward through the trampoline code, and that's handled further
4648 down, so there is nothing for us to do here. */
4650 if (execution_direction
!= EXEC_REVERSE
4651 && ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
4652 && in_solib_dynsym_resolve_code (stop_pc
))
4654 CORE_ADDR pc_after_resolver
=
4655 gdbarch_skip_solib_resolver (gdbarch
, stop_pc
);
4658 fprintf_unfiltered (gdb_stdlog
,
4659 "infrun: stepped into dynsym resolve code\n");
4661 if (pc_after_resolver
)
4663 /* Set up a step-resume breakpoint at the address
4664 indicated by SKIP_SOLIB_RESOLVER. */
4665 struct symtab_and_line sr_sal
;
4668 sr_sal
.pc
= pc_after_resolver
;
4669 sr_sal
.pspace
= get_frame_program_space (frame
);
4671 insert_step_resume_breakpoint_at_sal (gdbarch
,
4672 sr_sal
, null_frame_id
);
4679 if (ecs
->event_thread
->control
.step_range_end
!= 1
4680 && (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
4681 || ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
4682 && get_frame_type (frame
) == SIGTRAMP_FRAME
)
4685 fprintf_unfiltered (gdb_stdlog
,
4686 "infrun: stepped into signal trampoline\n");
4687 /* The inferior, while doing a "step" or "next", has ended up in
4688 a signal trampoline (either by a signal being delivered or by
4689 the signal handler returning). Just single-step until the
4690 inferior leaves the trampoline (either by calling the handler
4696 /* If we're in the return path from a shared library trampoline,
4697 we want to proceed through the trampoline when stepping. */
4698 /* macro/2012-04-25: This needs to come before the subroutine
4699 call check below as on some targets return trampolines look
4700 like subroutine calls (MIPS16 return thunks). */
4701 if (gdbarch_in_solib_return_trampoline (gdbarch
,
4702 stop_pc
, ecs
->stop_func_name
)
4703 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
4705 /* Determine where this trampoline returns. */
4706 CORE_ADDR real_stop_pc
;
4708 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
4711 fprintf_unfiltered (gdb_stdlog
,
4712 "infrun: stepped into solib return tramp\n");
4714 /* Only proceed through if we know where it's going. */
4717 /* And put the step-breakpoint there and go until there. */
4718 struct symtab_and_line sr_sal
;
4720 init_sal (&sr_sal
); /* initialize to zeroes */
4721 sr_sal
.pc
= real_stop_pc
;
4722 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
4723 sr_sal
.pspace
= get_frame_program_space (frame
);
4725 /* Do not specify what the fp should be when we stop since
4726 on some machines the prologue is where the new fp value
4728 insert_step_resume_breakpoint_at_sal (gdbarch
,
4729 sr_sal
, null_frame_id
);
4731 /* Restart without fiddling with the step ranges or
4738 /* Check for subroutine calls. The check for the current frame
4739 equalling the step ID is not necessary - the check of the
4740 previous frame's ID is sufficient - but it is a common case and
4741 cheaper than checking the previous frame's ID.
4743 NOTE: frame_id_eq will never report two invalid frame IDs as
4744 being equal, so to get into this block, both the current and
4745 previous frame must have valid frame IDs. */
4746 /* The outer_frame_id check is a heuristic to detect stepping
4747 through startup code. If we step over an instruction which
4748 sets the stack pointer from an invalid value to a valid value,
4749 we may detect that as a subroutine call from the mythical
4750 "outermost" function. This could be fixed by marking
4751 outermost frames as !stack_p,code_p,special_p. Then the
4752 initial outermost frame, before sp was valid, would
4753 have code_addr == &_start. See the comment in frame_id_eq
4755 if (!frame_id_eq (get_stack_frame_id (frame
),
4756 ecs
->event_thread
->control
.step_stack_frame_id
)
4757 && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()),
4758 ecs
->event_thread
->control
.step_stack_frame_id
)
4759 && (!frame_id_eq (ecs
->event_thread
->control
.step_stack_frame_id
,
4761 || step_start_function
!= find_pc_function (stop_pc
))))
4763 CORE_ADDR real_stop_pc
;
4766 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into subroutine\n");
4768 if ((ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_NONE
)
4769 || ((ecs
->event_thread
->control
.step_range_end
== 1)
4770 && in_prologue (gdbarch
, ecs
->event_thread
->prev_pc
,
4771 ecs
->stop_func_start
)))
4773 /* I presume that step_over_calls is only 0 when we're
4774 supposed to be stepping at the assembly language level
4775 ("stepi"). Just stop. */
4776 /* Also, maybe we just did a "nexti" inside a prolog, so we
4777 thought it was a subroutine call but it was not. Stop as
4779 /* And this works the same backward as frontward. MVS */
4780 ecs
->event_thread
->control
.stop_step
= 1;
4781 print_end_stepping_range_reason ();
4782 stop_stepping (ecs
);
4786 /* Reverse stepping through solib trampolines. */
4788 if (execution_direction
== EXEC_REVERSE
4789 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
4790 && (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
4791 || (ecs
->stop_func_start
== 0
4792 && in_solib_dynsym_resolve_code (stop_pc
))))
4794 /* Any solib trampoline code can be handled in reverse
4795 by simply continuing to single-step. We have already
4796 executed the solib function (backwards), and a few
4797 steps will take us back through the trampoline to the
4803 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
4805 /* We're doing a "next".
4807 Normal (forward) execution: set a breakpoint at the
4808 callee's return address (the address at which the caller
4811 Reverse (backward) execution. set the step-resume
4812 breakpoint at the start of the function that we just
4813 stepped into (backwards), and continue to there. When we
4814 get there, we'll need to single-step back to the caller. */
4816 if (execution_direction
== EXEC_REVERSE
)
4818 /* If we're already at the start of the function, we've either
4819 just stepped backward into a single instruction function,
4820 or stepped back out of a signal handler to the first instruction
4821 of the function. Just keep going, which will single-step back
4823 if (ecs
->stop_func_start
!= stop_pc
&& ecs
->stop_func_start
!= 0)
4825 struct symtab_and_line sr_sal
;
4827 /* Normal function call return (static or dynamic). */
4829 sr_sal
.pc
= ecs
->stop_func_start
;
4830 sr_sal
.pspace
= get_frame_program_space (frame
);
4831 insert_step_resume_breakpoint_at_sal (gdbarch
,
4832 sr_sal
, null_frame_id
);
4836 insert_step_resume_breakpoint_at_caller (frame
);
4842 /* If we are in a function call trampoline (a stub between the
4843 calling routine and the real function), locate the real
4844 function. That's what tells us (a) whether we want to step
4845 into it at all, and (b) what prologue we want to run to the
4846 end of, if we do step into it. */
4847 real_stop_pc
= skip_language_trampoline (frame
, stop_pc
);
4848 if (real_stop_pc
== 0)
4849 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
4850 if (real_stop_pc
!= 0)
4851 ecs
->stop_func_start
= real_stop_pc
;
4853 if (real_stop_pc
!= 0 && in_solib_dynsym_resolve_code (real_stop_pc
))
4855 struct symtab_and_line sr_sal
;
4858 sr_sal
.pc
= ecs
->stop_func_start
;
4859 sr_sal
.pspace
= get_frame_program_space (frame
);
4861 insert_step_resume_breakpoint_at_sal (gdbarch
,
4862 sr_sal
, null_frame_id
);
4867 /* If we have line number information for the function we are
4868 thinking of stepping into and the function isn't on the skip
4871 If there are several symtabs at that PC (e.g. with include
4872 files), just want to know whether *any* of them have line
4873 numbers. find_pc_line handles this. */
4875 struct symtab_and_line tmp_sal
;
4877 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
4878 if (tmp_sal
.line
!= 0
4879 && !function_name_is_marked_for_skip (ecs
->stop_func_name
,
4882 if (execution_direction
== EXEC_REVERSE
)
4883 handle_step_into_function_backward (gdbarch
, ecs
);
4885 handle_step_into_function (gdbarch
, ecs
);
4890 /* If we have no line number and the step-stop-if-no-debug is
4891 set, we stop the step so that the user has a chance to switch
4892 in assembly mode. */
4893 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
4894 && step_stop_if_no_debug
)
4896 ecs
->event_thread
->control
.stop_step
= 1;
4897 print_end_stepping_range_reason ();
4898 stop_stepping (ecs
);
4902 if (execution_direction
== EXEC_REVERSE
)
4904 /* If we're already at the start of the function, we've either just
4905 stepped backward into a single instruction function without line
4906 number info, or stepped back out of a signal handler to the first
4907 instruction of the function without line number info. Just keep
4908 going, which will single-step back to the caller. */
4909 if (ecs
->stop_func_start
!= stop_pc
)
4911 /* Set a breakpoint at callee's start address.
4912 From there we can step once and be back in the caller. */
4913 struct symtab_and_line sr_sal
;
4916 sr_sal
.pc
= ecs
->stop_func_start
;
4917 sr_sal
.pspace
= get_frame_program_space (frame
);
4918 insert_step_resume_breakpoint_at_sal (gdbarch
,
4919 sr_sal
, null_frame_id
);
4923 /* Set a breakpoint at callee's return address (the address
4924 at which the caller will resume). */
4925 insert_step_resume_breakpoint_at_caller (frame
);
4931 /* Reverse stepping through solib trampolines. */
4933 if (execution_direction
== EXEC_REVERSE
4934 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
4936 if (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
4937 || (ecs
->stop_func_start
== 0
4938 && in_solib_dynsym_resolve_code (stop_pc
)))
4940 /* Any solib trampoline code can be handled in reverse
4941 by simply continuing to single-step. We have already
4942 executed the solib function (backwards), and a few
4943 steps will take us back through the trampoline to the
4948 else if (in_solib_dynsym_resolve_code (stop_pc
))
4950 /* Stepped backward into the solib dynsym resolver.
4951 Set a breakpoint at its start and continue, then
4952 one more step will take us out. */
4953 struct symtab_and_line sr_sal
;
4956 sr_sal
.pc
= ecs
->stop_func_start
;
4957 sr_sal
.pspace
= get_frame_program_space (frame
);
4958 insert_step_resume_breakpoint_at_sal (gdbarch
,
4959 sr_sal
, null_frame_id
);
4965 stop_pc_sal
= find_pc_line (stop_pc
, 0);
4967 /* NOTE: tausq/2004-05-24: This if block used to be done before all
4968 the trampoline processing logic, however, there are some trampolines
4969 that have no names, so we should do trampoline handling first. */
4970 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
4971 && ecs
->stop_func_name
== NULL
4972 && stop_pc_sal
.line
== 0)
4975 fprintf_unfiltered (gdb_stdlog
,
4976 "infrun: stepped into undebuggable function\n");
4978 /* The inferior just stepped into, or returned to, an
4979 undebuggable function (where there is no debugging information
4980 and no line number corresponding to the address where the
4981 inferior stopped). Since we want to skip this kind of code,
4982 we keep going until the inferior returns from this
4983 function - unless the user has asked us not to (via
4984 set step-mode) or we no longer know how to get back
4985 to the call site. */
4986 if (step_stop_if_no_debug
4987 || !frame_id_p (frame_unwind_caller_id (frame
)))
4989 /* If we have no line number and the step-stop-if-no-debug
4990 is set, we stop the step so that the user has a chance to
4991 switch in assembly mode. */
4992 ecs
->event_thread
->control
.stop_step
= 1;
4993 print_end_stepping_range_reason ();
4994 stop_stepping (ecs
);
4999 /* Set a breakpoint at callee's return address (the address
5000 at which the caller will resume). */
5001 insert_step_resume_breakpoint_at_caller (frame
);
5007 if (ecs
->event_thread
->control
.step_range_end
== 1)
5009 /* It is stepi or nexti. We always want to stop stepping after
5012 fprintf_unfiltered (gdb_stdlog
, "infrun: stepi/nexti\n");
5013 ecs
->event_thread
->control
.stop_step
= 1;
5014 print_end_stepping_range_reason ();
5015 stop_stepping (ecs
);
5019 if (stop_pc_sal
.line
== 0)
5021 /* We have no line number information. That means to stop
5022 stepping (does this always happen right after one instruction,
5023 when we do "s" in a function with no line numbers,
5024 or can this happen as a result of a return or longjmp?). */
5026 fprintf_unfiltered (gdb_stdlog
, "infrun: no line number info\n");
5027 ecs
->event_thread
->control
.stop_step
= 1;
5028 print_end_stepping_range_reason ();
5029 stop_stepping (ecs
);
5033 /* Look for "calls" to inlined functions, part one. If the inline
5034 frame machinery detected some skipped call sites, we have entered
5035 a new inline function. */
5037 if (frame_id_eq (get_frame_id (get_current_frame ()),
5038 ecs
->event_thread
->control
.step_frame_id
)
5039 && inline_skipped_frames (ecs
->ptid
))
5041 struct symtab_and_line call_sal
;
5044 fprintf_unfiltered (gdb_stdlog
,
5045 "infrun: stepped into inlined function\n");
5047 find_frame_sal (get_current_frame (), &call_sal
);
5049 if (ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_ALL
)
5051 /* For "step", we're going to stop. But if the call site
5052 for this inlined function is on the same source line as
5053 we were previously stepping, go down into the function
5054 first. Otherwise stop at the call site. */
5056 if (call_sal
.line
== ecs
->event_thread
->current_line
5057 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
5058 step_into_inline_frame (ecs
->ptid
);
5060 ecs
->event_thread
->control
.stop_step
= 1;
5061 print_end_stepping_range_reason ();
5062 stop_stepping (ecs
);
5067 /* For "next", we should stop at the call site if it is on a
5068 different source line. Otherwise continue through the
5069 inlined function. */
5070 if (call_sal
.line
== ecs
->event_thread
->current_line
5071 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
5075 ecs
->event_thread
->control
.stop_step
= 1;
5076 print_end_stepping_range_reason ();
5077 stop_stepping (ecs
);
5083 /* Look for "calls" to inlined functions, part two. If we are still
5084 in the same real function we were stepping through, but we have
5085 to go further up to find the exact frame ID, we are stepping
5086 through a more inlined call beyond its call site. */
5088 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
5089 && !frame_id_eq (get_frame_id (get_current_frame ()),
5090 ecs
->event_thread
->control
.step_frame_id
)
5091 && stepped_in_from (get_current_frame (),
5092 ecs
->event_thread
->control
.step_frame_id
))
5095 fprintf_unfiltered (gdb_stdlog
,
5096 "infrun: stepping through inlined function\n");
5098 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
5102 ecs
->event_thread
->control
.stop_step
= 1;
5103 print_end_stepping_range_reason ();
5104 stop_stepping (ecs
);
5109 if ((stop_pc
== stop_pc_sal
.pc
)
5110 && (ecs
->event_thread
->current_line
!= stop_pc_sal
.line
5111 || ecs
->event_thread
->current_symtab
!= stop_pc_sal
.symtab
))
5113 /* We are at the start of a different line. So stop. Note that
5114 we don't stop if we step into the middle of a different line.
5115 That is said to make things like for (;;) statements work
5118 fprintf_unfiltered (gdb_stdlog
,
5119 "infrun: stepped to a different line\n");
5120 ecs
->event_thread
->control
.stop_step
= 1;
5121 print_end_stepping_range_reason ();
5122 stop_stepping (ecs
);
5126 /* We aren't done stepping.
5128 Optimize by setting the stepping range to the line.
5129 (We might not be in the original line, but if we entered a
5130 new line in mid-statement, we continue stepping. This makes
5131 things like for(;;) statements work better.) */
5133 ecs
->event_thread
->control
.step_range_start
= stop_pc_sal
.pc
;
5134 ecs
->event_thread
->control
.step_range_end
= stop_pc_sal
.end
;
5135 ecs
->event_thread
->control
.may_range_step
= 1;
5136 set_step_info (frame
, stop_pc_sal
);
5139 fprintf_unfiltered (gdb_stdlog
, "infrun: keep going\n");
5143 /* In all-stop mode, if we're currently stepping but have stopped in
5144 some other thread, we may need to switch back to the stepped
5145 thread. Returns true we set the inferior running, false if we left
5146 it stopped (and the event needs further processing). */
5149 switch_back_to_stepped_thread (struct execution_control_state
*ecs
)
5153 struct thread_info
*tp
;
5154 struct thread_info
*stepping_thread
;
5155 struct thread_info
*step_over
;
5157 /* If any thread is blocked on some internal breakpoint, and we
5158 simply need to step over that breakpoint to get it going
5159 again, do that first. */
5161 /* However, if we see an event for the stepping thread, then we
5162 know all other threads have been moved past their breakpoints
5163 already. Let the caller check whether the step is finished,
5164 etc., before deciding to move it past a breakpoint. */
5165 if (ecs
->event_thread
->control
.step_range_end
!= 0)
5168 /* Check if the current thread is blocked on an incomplete
5169 step-over, interrupted by a random signal. */
5170 if (ecs
->event_thread
->control
.trap_expected
5171 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_TRAP
)
5175 fprintf_unfiltered (gdb_stdlog
,
5176 "infrun: need to finish step-over of [%s]\n",
5177 target_pid_to_str (ecs
->event_thread
->ptid
));
5183 /* Check if the current thread is blocked by a single-step
5184 breakpoint of another thread. */
5185 if (ecs
->hit_singlestep_breakpoint
)
5189 fprintf_unfiltered (gdb_stdlog
,
5190 "infrun: need to step [%s] over single-step "
5192 target_pid_to_str (ecs
->ptid
));
5198 /* Otherwise, we no longer expect a trap in the current thread.
5199 Clear the trap_expected flag before switching back -- this is
5200 what keep_going does as well, if we call it. */
5201 ecs
->event_thread
->control
.trap_expected
= 0;
5203 /* If scheduler locking applies even if not stepping, there's no
5204 need to walk over threads. Above we've checked whether the
5205 current thread is stepping. If some other thread not the
5206 event thread is stepping, then it must be that scheduler
5207 locking is not in effect. */
5208 if (schedlock_applies (0))
5211 /* Look for the stepping/nexting thread, and check if any other
5212 thread other than the stepping thread needs to start a
5213 step-over. Do all step-overs before actually proceeding with
5215 stepping_thread
= NULL
;
5219 /* Ignore threads of processes we're not resuming. */
5221 && ptid_get_pid (tp
->ptid
) != ptid_get_pid (inferior_ptid
))
5224 /* When stepping over a breakpoint, we lock all threads
5225 except the one that needs to move past the breakpoint.
5226 If a non-event thread has this set, the "incomplete
5227 step-over" check above should have caught it earlier. */
5228 gdb_assert (!tp
->control
.trap_expected
);
5230 /* Did we find the stepping thread? */
5231 if (tp
->control
.step_range_end
)
5233 /* Yep. There should only one though. */
5234 gdb_assert (stepping_thread
== NULL
);
5236 /* The event thread is handled at the top, before we
5238 gdb_assert (tp
!= ecs
->event_thread
);
5240 /* If some thread other than the event thread is
5241 stepping, then scheduler locking can't be in effect,
5242 otherwise we wouldn't have resumed the current event
5243 thread in the first place. */
5244 gdb_assert (!schedlock_applies (1));
5246 stepping_thread
= tp
;
5248 else if (thread_still_needs_step_over (tp
))
5252 /* At the top we've returned early if the event thread
5253 is stepping. If some other thread not the event
5254 thread is stepping, then scheduler locking can't be
5255 in effect, and we can resume this thread. No need to
5256 keep looking for the stepping thread then. */
5261 if (step_over
!= NULL
)
5266 fprintf_unfiltered (gdb_stdlog
,
5267 "infrun: need to step-over [%s]\n",
5268 target_pid_to_str (tp
->ptid
));
5271 /* Only the stepping thread should have this set. */
5272 gdb_assert (tp
->control
.step_range_end
== 0);
5274 ecs
->ptid
= tp
->ptid
;
5275 ecs
->event_thread
= tp
;
5276 switch_to_thread (ecs
->ptid
);
5281 if (stepping_thread
!= NULL
)
5283 struct frame_info
*frame
;
5284 struct gdbarch
*gdbarch
;
5286 tp
= stepping_thread
;
5288 /* If the stepping thread exited, then don't try to switch
5289 back and resume it, which could fail in several different
5290 ways depending on the target. Instead, just keep going.
5292 We can find a stepping dead thread in the thread list in
5295 - The target supports thread exit events, and when the
5296 target tries to delete the thread from the thread list,
5297 inferior_ptid pointed at the exiting thread. In such
5298 case, calling delete_thread does not really remove the
5299 thread from the list; instead, the thread is left listed,
5300 with 'exited' state.
5302 - The target's debug interface does not support thread
5303 exit events, and so we have no idea whatsoever if the
5304 previously stepping thread is still alive. For that
5305 reason, we need to synchronously query the target
5307 if (is_exited (tp
->ptid
)
5308 || !target_thread_alive (tp
->ptid
))
5311 fprintf_unfiltered (gdb_stdlog
,
5312 "infrun: not switching back to "
5313 "stepped thread, it has vanished\n");
5315 delete_thread (tp
->ptid
);
5321 fprintf_unfiltered (gdb_stdlog
,
5322 "infrun: switching back to stepped thread\n");
5324 ecs
->event_thread
= tp
;
5325 ecs
->ptid
= tp
->ptid
;
5326 context_switch (ecs
->ptid
);
5328 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
5329 frame
= get_current_frame ();
5330 gdbarch
= get_frame_arch (frame
);
5332 /* If the PC of the thread we were trying to single-step has
5333 changed, then that thread has trapped or been signaled,
5334 but the event has not been reported to GDB yet. Re-poll
5335 the target looking for this particular thread's event
5336 (i.e. temporarily enable schedlock) by:
5338 - setting a break at the current PC
5339 - resuming that particular thread, only (by setting
5342 This prevents us continuously moving the single-step
5343 breakpoint forward, one instruction at a time,
5346 if (gdbarch_software_single_step_p (gdbarch
)
5347 && stop_pc
!= tp
->prev_pc
)
5350 fprintf_unfiltered (gdb_stdlog
,
5351 "infrun: expected thread advanced also\n");
5353 insert_single_step_breakpoint (get_frame_arch (frame
),
5354 get_frame_address_space (frame
),
5356 singlestep_breakpoints_inserted_p
= 1;
5357 ecs
->event_thread
->control
.trap_expected
= 1;
5358 singlestep_ptid
= inferior_ptid
;
5359 singlestep_pc
= stop_pc
;
5361 resume (0, GDB_SIGNAL_0
);
5362 prepare_to_wait (ecs
);
5367 fprintf_unfiltered (gdb_stdlog
,
5368 "infrun: expected thread still "
5369 "hasn't advanced\n");
5379 /* Is thread TP in the middle of single-stepping? */
5382 currently_stepping (struct thread_info
*tp
)
5384 return ((tp
->control
.step_range_end
5385 && tp
->control
.step_resume_breakpoint
== NULL
)
5386 || tp
->control
.trap_expected
5387 || bpstat_should_step ());
5390 /* Inferior has stepped into a subroutine call with source code that
5391 we should not step over. Do step to the first line of code in
5395 handle_step_into_function (struct gdbarch
*gdbarch
,
5396 struct execution_control_state
*ecs
)
5399 struct symtab_and_line stop_func_sal
, sr_sal
;
5401 fill_in_stop_func (gdbarch
, ecs
);
5403 s
= find_pc_symtab (stop_pc
);
5404 if (s
&& s
->language
!= language_asm
)
5405 ecs
->stop_func_start
= gdbarch_skip_prologue (gdbarch
,
5406 ecs
->stop_func_start
);
5408 stop_func_sal
= find_pc_line (ecs
->stop_func_start
, 0);
5409 /* Use the step_resume_break to step until the end of the prologue,
5410 even if that involves jumps (as it seems to on the vax under
5412 /* If the prologue ends in the middle of a source line, continue to
5413 the end of that source line (if it is still within the function).
5414 Otherwise, just go to end of prologue. */
5415 if (stop_func_sal
.end
5416 && stop_func_sal
.pc
!= ecs
->stop_func_start
5417 && stop_func_sal
.end
< ecs
->stop_func_end
)
5418 ecs
->stop_func_start
= stop_func_sal
.end
;
5420 /* Architectures which require breakpoint adjustment might not be able
5421 to place a breakpoint at the computed address. If so, the test
5422 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
5423 ecs->stop_func_start to an address at which a breakpoint may be
5424 legitimately placed.
5426 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
5427 made, GDB will enter an infinite loop when stepping through
5428 optimized code consisting of VLIW instructions which contain
5429 subinstructions corresponding to different source lines. On
5430 FR-V, it's not permitted to place a breakpoint on any but the
5431 first subinstruction of a VLIW instruction. When a breakpoint is
5432 set, GDB will adjust the breakpoint address to the beginning of
5433 the VLIW instruction. Thus, we need to make the corresponding
5434 adjustment here when computing the stop address. */
5436 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
5438 ecs
->stop_func_start
5439 = gdbarch_adjust_breakpoint_address (gdbarch
,
5440 ecs
->stop_func_start
);
5443 if (ecs
->stop_func_start
== stop_pc
)
5445 /* We are already there: stop now. */
5446 ecs
->event_thread
->control
.stop_step
= 1;
5447 print_end_stepping_range_reason ();
5448 stop_stepping (ecs
);
5453 /* Put the step-breakpoint there and go until there. */
5454 init_sal (&sr_sal
); /* initialize to zeroes */
5455 sr_sal
.pc
= ecs
->stop_func_start
;
5456 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
5457 sr_sal
.pspace
= get_frame_program_space (get_current_frame ());
5459 /* Do not specify what the fp should be when we stop since on
5460 some machines the prologue is where the new fp value is
5462 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
, null_frame_id
);
5464 /* And make sure stepping stops right away then. */
5465 ecs
->event_thread
->control
.step_range_end
5466 = ecs
->event_thread
->control
.step_range_start
;
5471 /* Inferior has stepped backward into a subroutine call with source
5472 code that we should not step over. Do step to the beginning of the
5473 last line of code in it. */
5476 handle_step_into_function_backward (struct gdbarch
*gdbarch
,
5477 struct execution_control_state
*ecs
)
5480 struct symtab_and_line stop_func_sal
;
5482 fill_in_stop_func (gdbarch
, ecs
);
5484 s
= find_pc_symtab (stop_pc
);
5485 if (s
&& s
->language
!= language_asm
)
5486 ecs
->stop_func_start
= gdbarch_skip_prologue (gdbarch
,
5487 ecs
->stop_func_start
);
5489 stop_func_sal
= find_pc_line (stop_pc
, 0);
5491 /* OK, we're just going to keep stepping here. */
5492 if (stop_func_sal
.pc
== stop_pc
)
5494 /* We're there already. Just stop stepping now. */
5495 ecs
->event_thread
->control
.stop_step
= 1;
5496 print_end_stepping_range_reason ();
5497 stop_stepping (ecs
);
5501 /* Else just reset the step range and keep going.
5502 No step-resume breakpoint, they don't work for
5503 epilogues, which can have multiple entry paths. */
5504 ecs
->event_thread
->control
.step_range_start
= stop_func_sal
.pc
;
5505 ecs
->event_thread
->control
.step_range_end
= stop_func_sal
.end
;
5511 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
5512 This is used to both functions and to skip over code. */
5515 insert_step_resume_breakpoint_at_sal_1 (struct gdbarch
*gdbarch
,
5516 struct symtab_and_line sr_sal
,
5517 struct frame_id sr_id
,
5518 enum bptype sr_type
)
5520 /* There should never be more than one step-resume or longjmp-resume
5521 breakpoint per thread, so we should never be setting a new
5522 step_resume_breakpoint when one is already active. */
5523 gdb_assert (inferior_thread ()->control
.step_resume_breakpoint
== NULL
);
5524 gdb_assert (sr_type
== bp_step_resume
|| sr_type
== bp_hp_step_resume
);
5527 fprintf_unfiltered (gdb_stdlog
,
5528 "infrun: inserting step-resume breakpoint at %s\n",
5529 paddress (gdbarch
, sr_sal
.pc
));
5531 inferior_thread ()->control
.step_resume_breakpoint
5532 = set_momentary_breakpoint (gdbarch
, sr_sal
, sr_id
, sr_type
);
5536 insert_step_resume_breakpoint_at_sal (struct gdbarch
*gdbarch
,
5537 struct symtab_and_line sr_sal
,
5538 struct frame_id sr_id
)
5540 insert_step_resume_breakpoint_at_sal_1 (gdbarch
,
5545 /* Insert a "high-priority step-resume breakpoint" at RETURN_FRAME.pc.
5546 This is used to skip a potential signal handler.
5548 This is called with the interrupted function's frame. The signal
5549 handler, when it returns, will resume the interrupted function at
5553 insert_hp_step_resume_breakpoint_at_frame (struct frame_info
*return_frame
)
5555 struct symtab_and_line sr_sal
;
5556 struct gdbarch
*gdbarch
;
5558 gdb_assert (return_frame
!= NULL
);
5559 init_sal (&sr_sal
); /* initialize to zeros */
5561 gdbarch
= get_frame_arch (return_frame
);
5562 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
, get_frame_pc (return_frame
));
5563 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
5564 sr_sal
.pspace
= get_frame_program_space (return_frame
);
5566 insert_step_resume_breakpoint_at_sal_1 (gdbarch
, sr_sal
,
5567 get_stack_frame_id (return_frame
),
5571 /* Insert a "step-resume breakpoint" at the previous frame's PC. This
5572 is used to skip a function after stepping into it (for "next" or if
5573 the called function has no debugging information).
5575 The current function has almost always been reached by single
5576 stepping a call or return instruction. NEXT_FRAME belongs to the
5577 current function, and the breakpoint will be set at the caller's
5580 This is a separate function rather than reusing
5581 insert_hp_step_resume_breakpoint_at_frame in order to avoid
5582 get_prev_frame, which may stop prematurely (see the implementation
5583 of frame_unwind_caller_id for an example). */
5586 insert_step_resume_breakpoint_at_caller (struct frame_info
*next_frame
)
5588 struct symtab_and_line sr_sal
;
5589 struct gdbarch
*gdbarch
;
5591 /* We shouldn't have gotten here if we don't know where the call site
5593 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame
)));
5595 init_sal (&sr_sal
); /* initialize to zeros */
5597 gdbarch
= frame_unwind_caller_arch (next_frame
);
5598 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
,
5599 frame_unwind_caller_pc (next_frame
));
5600 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
5601 sr_sal
.pspace
= frame_unwind_program_space (next_frame
);
5603 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
,
5604 frame_unwind_caller_id (next_frame
));
5607 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
5608 new breakpoint at the target of a jmp_buf. The handling of
5609 longjmp-resume uses the same mechanisms used for handling
5610 "step-resume" breakpoints. */
5613 insert_longjmp_resume_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
5615 /* There should never be more than one longjmp-resume breakpoint per
5616 thread, so we should never be setting a new
5617 longjmp_resume_breakpoint when one is already active. */
5618 gdb_assert (inferior_thread ()->control
.exception_resume_breakpoint
== NULL
);
5621 fprintf_unfiltered (gdb_stdlog
,
5622 "infrun: inserting longjmp-resume breakpoint at %s\n",
5623 paddress (gdbarch
, pc
));
5625 inferior_thread ()->control
.exception_resume_breakpoint
=
5626 set_momentary_breakpoint_at_pc (gdbarch
, pc
, bp_longjmp_resume
);
5629 /* Insert an exception resume breakpoint. TP is the thread throwing
5630 the exception. The block B is the block of the unwinder debug hook
5631 function. FRAME is the frame corresponding to the call to this
5632 function. SYM is the symbol of the function argument holding the
5633 target PC of the exception. */
5636 insert_exception_resume_breakpoint (struct thread_info
*tp
,
5638 struct frame_info
*frame
,
5641 volatile struct gdb_exception e
;
5643 /* We want to ignore errors here. */
5644 TRY_CATCH (e
, RETURN_MASK_ERROR
)
5646 struct symbol
*vsym
;
5647 struct value
*value
;
5649 struct breakpoint
*bp
;
5651 vsym
= lookup_symbol (SYMBOL_LINKAGE_NAME (sym
), b
, VAR_DOMAIN
, NULL
);
5652 value
= read_var_value (vsym
, frame
);
5653 /* If the value was optimized out, revert to the old behavior. */
5654 if (! value_optimized_out (value
))
5656 handler
= value_as_address (value
);
5659 fprintf_unfiltered (gdb_stdlog
,
5660 "infrun: exception resume at %lx\n",
5661 (unsigned long) handler
);
5663 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
5664 handler
, bp_exception_resume
);
5666 /* set_momentary_breakpoint_at_pc invalidates FRAME. */
5669 bp
->thread
= tp
->num
;
5670 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
5675 /* A helper for check_exception_resume that sets an
5676 exception-breakpoint based on a SystemTap probe. */
5679 insert_exception_resume_from_probe (struct thread_info
*tp
,
5680 const struct bound_probe
*probe
,
5681 struct frame_info
*frame
)
5683 struct value
*arg_value
;
5685 struct breakpoint
*bp
;
5687 arg_value
= probe_safe_evaluate_at_pc (frame
, 1);
5691 handler
= value_as_address (arg_value
);
5694 fprintf_unfiltered (gdb_stdlog
,
5695 "infrun: exception resume at %s\n",
5696 paddress (get_objfile_arch (probe
->objfile
),
5699 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
5700 handler
, bp_exception_resume
);
5701 bp
->thread
= tp
->num
;
5702 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
5705 /* This is called when an exception has been intercepted. Check to
5706 see whether the exception's destination is of interest, and if so,
5707 set an exception resume breakpoint there. */
5710 check_exception_resume (struct execution_control_state
*ecs
,
5711 struct frame_info
*frame
)
5713 volatile struct gdb_exception e
;
5714 struct bound_probe probe
;
5715 struct symbol
*func
;
5717 /* First see if this exception unwinding breakpoint was set via a
5718 SystemTap probe point. If so, the probe has two arguments: the
5719 CFA and the HANDLER. We ignore the CFA, extract the handler, and
5720 set a breakpoint there. */
5721 probe
= find_probe_by_pc (get_frame_pc (frame
));
5724 insert_exception_resume_from_probe (ecs
->event_thread
, &probe
, frame
);
5728 func
= get_frame_function (frame
);
5732 TRY_CATCH (e
, RETURN_MASK_ERROR
)
5735 struct block_iterator iter
;
5739 /* The exception breakpoint is a thread-specific breakpoint on
5740 the unwinder's debug hook, declared as:
5742 void _Unwind_DebugHook (void *cfa, void *handler);
5744 The CFA argument indicates the frame to which control is
5745 about to be transferred. HANDLER is the destination PC.
5747 We ignore the CFA and set a temporary breakpoint at HANDLER.
5748 This is not extremely efficient but it avoids issues in gdb
5749 with computing the DWARF CFA, and it also works even in weird
5750 cases such as throwing an exception from inside a signal
5753 b
= SYMBOL_BLOCK_VALUE (func
);
5754 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
5756 if (!SYMBOL_IS_ARGUMENT (sym
))
5763 insert_exception_resume_breakpoint (ecs
->event_thread
,
5772 stop_stepping (struct execution_control_state
*ecs
)
5775 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_stepping\n");
5777 clear_step_over_info ();
5779 /* Let callers know we don't want to wait for the inferior anymore. */
5780 ecs
->wait_some_more
= 0;
5783 /* Called when we should continue running the inferior, because the
5784 current event doesn't cause a user visible stop. This does the
5785 resuming part; waiting for the next event is done elsewhere. */
5788 keep_going (struct execution_control_state
*ecs
)
5790 /* Make sure normal_stop is called if we get a QUIT handled before
5792 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
5794 /* Save the pc before execution, to compare with pc after stop. */
5795 ecs
->event_thread
->prev_pc
5796 = regcache_read_pc (get_thread_regcache (ecs
->ptid
));
5798 if (ecs
->event_thread
->control
.trap_expected
5799 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_TRAP
)
5801 /* We haven't yet gotten our trap, and either: intercepted a
5802 non-signal event (e.g., a fork); or took a signal which we
5803 are supposed to pass through to the inferior. Simply
5805 discard_cleanups (old_cleanups
);
5806 resume (currently_stepping (ecs
->event_thread
),
5807 ecs
->event_thread
->suspend
.stop_signal
);
5811 volatile struct gdb_exception e
;
5812 struct regcache
*regcache
= get_current_regcache ();
5814 /* Either the trap was not expected, but we are continuing
5815 anyway (if we got a signal, the user asked it be passed to
5818 We got our expected trap, but decided we should resume from
5821 We're going to run this baby now!
5823 Note that insert_breakpoints won't try to re-insert
5824 already inserted breakpoints. Therefore, we don't
5825 care if breakpoints were already inserted, or not. */
5827 /* If we need to step over a breakpoint, and we're not using
5828 displaced stepping to do so, insert all breakpoints
5829 (watchpoints, etc.) but the one we're stepping over, step one
5830 instruction, and then re-insert the breakpoint when that step
5832 if ((ecs
->hit_singlestep_breakpoint
5833 || thread_still_needs_step_over (ecs
->event_thread
))
5834 && !use_displaced_stepping (get_regcache_arch (regcache
)))
5836 set_step_over_info (get_regcache_aspace (regcache
),
5837 regcache_read_pc (regcache
));
5840 clear_step_over_info ();
5842 /* Stop stepping if inserting breakpoints fails. */
5843 TRY_CATCH (e
, RETURN_MASK_ERROR
)
5845 insert_breakpoints ();
5849 exception_print (gdb_stderr
, e
);
5850 stop_stepping (ecs
);
5854 ecs
->event_thread
->control
.trap_expected
5855 = (ecs
->event_thread
->stepping_over_breakpoint
5856 || ecs
->hit_singlestep_breakpoint
);
5858 /* Do not deliver GDB_SIGNAL_TRAP (except when the user
5859 explicitly specifies that such a signal should be delivered
5860 to the target program). Typically, that would occur when a
5861 user is debugging a target monitor on a simulator: the target
5862 monitor sets a breakpoint; the simulator encounters this
5863 breakpoint and halts the simulation handing control to GDB;
5864 GDB, noting that the stop address doesn't map to any known
5865 breakpoint, returns control back to the simulator; the
5866 simulator then delivers the hardware equivalent of a
5867 GDB_SIGNAL_TRAP to the program being debugged. */
5868 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
5869 && !signal_program
[ecs
->event_thread
->suspend
.stop_signal
])
5870 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5872 discard_cleanups (old_cleanups
);
5873 resume (currently_stepping (ecs
->event_thread
),
5874 ecs
->event_thread
->suspend
.stop_signal
);
5877 prepare_to_wait (ecs
);
5880 /* This function normally comes after a resume, before
5881 handle_inferior_event exits. It takes care of any last bits of
5882 housekeeping, and sets the all-important wait_some_more flag. */
5885 prepare_to_wait (struct execution_control_state
*ecs
)
5888 fprintf_unfiltered (gdb_stdlog
, "infrun: prepare_to_wait\n");
5890 /* This is the old end of the while loop. Let everybody know we
5891 want to wait for the inferior some more and get called again
5893 ecs
->wait_some_more
= 1;
5896 /* Several print_*_reason functions to print why the inferior has stopped.
5897 We always print something when the inferior exits, or receives a signal.
5898 The rest of the cases are dealt with later on in normal_stop and
5899 print_it_typical. Ideally there should be a call to one of these
5900 print_*_reason functions functions from handle_inferior_event each time
5901 stop_stepping is called. */
5903 /* Print why the inferior has stopped.
5904 We are done with a step/next/si/ni command, print why the inferior has
5905 stopped. For now print nothing. Print a message only if not in the middle
5906 of doing a "step n" operation for n > 1. */
5909 print_end_stepping_range_reason (void)
5911 if ((!inferior_thread ()->step_multi
5912 || !inferior_thread ()->control
.stop_step
)
5913 && ui_out_is_mi_like_p (current_uiout
))
5914 ui_out_field_string (current_uiout
, "reason",
5915 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE
));
5918 /* The inferior was terminated by a signal, print why it stopped. */
5921 print_signal_exited_reason (enum gdb_signal siggnal
)
5923 struct ui_out
*uiout
= current_uiout
;
5925 annotate_signalled ();
5926 if (ui_out_is_mi_like_p (uiout
))
5928 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED
));
5929 ui_out_text (uiout
, "\nProgram terminated with signal ");
5930 annotate_signal_name ();
5931 ui_out_field_string (uiout
, "signal-name",
5932 gdb_signal_to_name (siggnal
));
5933 annotate_signal_name_end ();
5934 ui_out_text (uiout
, ", ");
5935 annotate_signal_string ();
5936 ui_out_field_string (uiout
, "signal-meaning",
5937 gdb_signal_to_string (siggnal
));
5938 annotate_signal_string_end ();
5939 ui_out_text (uiout
, ".\n");
5940 ui_out_text (uiout
, "The program no longer exists.\n");
5943 /* The inferior program is finished, print why it stopped. */
5946 print_exited_reason (int exitstatus
)
5948 struct inferior
*inf
= current_inferior ();
5949 const char *pidstr
= target_pid_to_str (pid_to_ptid (inf
->pid
));
5950 struct ui_out
*uiout
= current_uiout
;
5952 annotate_exited (exitstatus
);
5955 if (ui_out_is_mi_like_p (uiout
))
5956 ui_out_field_string (uiout
, "reason",
5957 async_reason_lookup (EXEC_ASYNC_EXITED
));
5958 ui_out_text (uiout
, "[Inferior ");
5959 ui_out_text (uiout
, plongest (inf
->num
));
5960 ui_out_text (uiout
, " (");
5961 ui_out_text (uiout
, pidstr
);
5962 ui_out_text (uiout
, ") exited with code ");
5963 ui_out_field_fmt (uiout
, "exit-code", "0%o", (unsigned int) exitstatus
);
5964 ui_out_text (uiout
, "]\n");
5968 if (ui_out_is_mi_like_p (uiout
))
5970 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY
));
5971 ui_out_text (uiout
, "[Inferior ");
5972 ui_out_text (uiout
, plongest (inf
->num
));
5973 ui_out_text (uiout
, " (");
5974 ui_out_text (uiout
, pidstr
);
5975 ui_out_text (uiout
, ") exited normally]\n");
5979 /* Signal received, print why the inferior has stopped. The signal table
5980 tells us to print about it. */
5983 print_signal_received_reason (enum gdb_signal siggnal
)
5985 struct ui_out
*uiout
= current_uiout
;
5989 if (siggnal
== GDB_SIGNAL_0
&& !ui_out_is_mi_like_p (uiout
))
5991 struct thread_info
*t
= inferior_thread ();
5993 ui_out_text (uiout
, "\n[");
5994 ui_out_field_string (uiout
, "thread-name",
5995 target_pid_to_str (t
->ptid
));
5996 ui_out_field_fmt (uiout
, "thread-id", "] #%d", t
->num
);
5997 ui_out_text (uiout
, " stopped");
6001 ui_out_text (uiout
, "\nProgram received signal ");
6002 annotate_signal_name ();
6003 if (ui_out_is_mi_like_p (uiout
))
6005 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED
));
6006 ui_out_field_string (uiout
, "signal-name",
6007 gdb_signal_to_name (siggnal
));
6008 annotate_signal_name_end ();
6009 ui_out_text (uiout
, ", ");
6010 annotate_signal_string ();
6011 ui_out_field_string (uiout
, "signal-meaning",
6012 gdb_signal_to_string (siggnal
));
6013 annotate_signal_string_end ();
6015 ui_out_text (uiout
, ".\n");
6018 /* Reverse execution: target ran out of history info, print why the inferior
6022 print_no_history_reason (void)
6024 ui_out_text (current_uiout
, "\nNo more reverse-execution history.\n");
6027 /* Print current location without a level number, if we have changed
6028 functions or hit a breakpoint. Print source line if we have one.
6029 bpstat_print contains the logic deciding in detail what to print,
6030 based on the event(s) that just occurred. */
6033 print_stop_event (struct target_waitstatus
*ws
)
6037 int do_frame_printing
= 1;
6038 struct thread_info
*tp
= inferior_thread ();
6040 bpstat_ret
= bpstat_print (tp
->control
.stop_bpstat
, ws
->kind
);
6044 /* FIXME: cagney/2002-12-01: Given that a frame ID does (or
6045 should) carry around the function and does (or should) use
6046 that when doing a frame comparison. */
6047 if (tp
->control
.stop_step
6048 && frame_id_eq (tp
->control
.step_frame_id
,
6049 get_frame_id (get_current_frame ()))
6050 && step_start_function
== find_pc_function (stop_pc
))
6052 /* Finished step, just print source line. */
6053 source_flag
= SRC_LINE
;
6057 /* Print location and source line. */
6058 source_flag
= SRC_AND_LOC
;
6061 case PRINT_SRC_AND_LOC
:
6062 /* Print location and source line. */
6063 source_flag
= SRC_AND_LOC
;
6065 case PRINT_SRC_ONLY
:
6066 source_flag
= SRC_LINE
;
6069 /* Something bogus. */
6070 source_flag
= SRC_LINE
;
6071 do_frame_printing
= 0;
6074 internal_error (__FILE__
, __LINE__
, _("Unknown value."));
6077 /* The behavior of this routine with respect to the source
6079 SRC_LINE: Print only source line
6080 LOCATION: Print only location
6081 SRC_AND_LOC: Print location and source line. */
6082 if (do_frame_printing
)
6083 print_stack_frame (get_selected_frame (NULL
), 0, source_flag
, 1);
6085 /* Display the auto-display expressions. */
6089 /* Here to return control to GDB when the inferior stops for real.
6090 Print appropriate messages, remove breakpoints, give terminal our modes.
6092 STOP_PRINT_FRAME nonzero means print the executing frame
6093 (pc, function, args, file, line number and line text).
6094 BREAKPOINTS_FAILED nonzero means stop was due to error
6095 attempting to insert breakpoints. */
6100 struct target_waitstatus last
;
6102 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
6104 get_last_target_status (&last_ptid
, &last
);
6106 /* If an exception is thrown from this point on, make sure to
6107 propagate GDB's knowledge of the executing state to the
6108 frontend/user running state. A QUIT is an easy exception to see
6109 here, so do this before any filtered output. */
6111 make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
6112 else if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
6113 && last
.kind
!= TARGET_WAITKIND_EXITED
6114 && last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
6115 make_cleanup (finish_thread_state_cleanup
, &inferior_ptid
);
6117 /* As with the notification of thread events, we want to delay
6118 notifying the user that we've switched thread context until
6119 the inferior actually stops.
6121 There's no point in saying anything if the inferior has exited.
6122 Note that SIGNALLED here means "exited with a signal", not
6123 "received a signal".
6125 Also skip saying anything in non-stop mode. In that mode, as we
6126 don't want GDB to switch threads behind the user's back, to avoid
6127 races where the user is typing a command to apply to thread x,
6128 but GDB switches to thread y before the user finishes entering
6129 the command, fetch_inferior_event installs a cleanup to restore
6130 the current thread back to the thread the user had selected right
6131 after this event is handled, so we're not really switching, only
6132 informing of a stop. */
6134 && !ptid_equal (previous_inferior_ptid
, inferior_ptid
)
6135 && target_has_execution
6136 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
6137 && last
.kind
!= TARGET_WAITKIND_EXITED
6138 && last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
6140 target_terminal_ours_for_output ();
6141 printf_filtered (_("[Switching to %s]\n"),
6142 target_pid_to_str (inferior_ptid
));
6143 annotate_thread_changed ();
6144 previous_inferior_ptid
= inferior_ptid
;
6147 if (last
.kind
== TARGET_WAITKIND_NO_RESUMED
)
6149 gdb_assert (sync_execution
|| !target_can_async_p ());
6151 target_terminal_ours_for_output ();
6152 printf_filtered (_("No unwaited-for children left.\n"));
6155 if (!breakpoints_always_inserted_mode () && target_has_execution
)
6157 if (remove_breakpoints ())
6159 target_terminal_ours_for_output ();
6160 printf_filtered (_("Cannot remove breakpoints because "
6161 "program is no longer writable.\nFurther "
6162 "execution is probably impossible.\n"));
6166 /* If an auto-display called a function and that got a signal,
6167 delete that auto-display to avoid an infinite recursion. */
6169 if (stopped_by_random_signal
)
6170 disable_current_display ();
6172 /* Don't print a message if in the middle of doing a "step n"
6173 operation for n > 1 */
6174 if (target_has_execution
6175 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
6176 && last
.kind
!= TARGET_WAITKIND_EXITED
6177 && inferior_thread ()->step_multi
6178 && inferior_thread ()->control
.stop_step
)
6181 target_terminal_ours ();
6182 async_enable_stdin ();
6184 /* Set the current source location. This will also happen if we
6185 display the frame below, but the current SAL will be incorrect
6186 during a user hook-stop function. */
6187 if (has_stack_frames () && !stop_stack_dummy
)
6188 set_current_sal_from_frame (get_current_frame ());
6190 /* Let the user/frontend see the threads as stopped. */
6191 do_cleanups (old_chain
);
6193 /* Look up the hook_stop and run it (CLI internally handles problem
6194 of stop_command's pre-hook not existing). */
6196 catch_errors (hook_stop_stub
, stop_command
,
6197 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
6199 if (!has_stack_frames ())
6202 if (last
.kind
== TARGET_WAITKIND_SIGNALLED
6203 || last
.kind
== TARGET_WAITKIND_EXITED
)
6206 /* Select innermost stack frame - i.e., current frame is frame 0,
6207 and current location is based on that.
6208 Don't do this on return from a stack dummy routine,
6209 or if the program has exited. */
6211 if (!stop_stack_dummy
)
6213 select_frame (get_current_frame ());
6215 /* If --batch-silent is enabled then there's no need to print the current
6216 source location, and to try risks causing an error message about
6217 missing source files. */
6218 if (stop_print_frame
&& !batch_silent
)
6219 print_stop_event (&last
);
6222 /* Save the function value return registers, if we care.
6223 We might be about to restore their previous contents. */
6224 if (inferior_thread ()->control
.proceed_to_finish
6225 && execution_direction
!= EXEC_REVERSE
)
6227 /* This should not be necessary. */
6229 regcache_xfree (stop_registers
);
6231 /* NB: The copy goes through to the target picking up the value of
6232 all the registers. */
6233 stop_registers
= regcache_dup (get_current_regcache ());
6236 if (stop_stack_dummy
== STOP_STACK_DUMMY
)
6238 /* Pop the empty frame that contains the stack dummy.
6239 This also restores inferior state prior to the call
6240 (struct infcall_suspend_state). */
6241 struct frame_info
*frame
= get_current_frame ();
6243 gdb_assert (get_frame_type (frame
) == DUMMY_FRAME
);
6245 /* frame_pop() calls reinit_frame_cache as the last thing it
6246 does which means there's currently no selected frame. We
6247 don't need to re-establish a selected frame if the dummy call
6248 returns normally, that will be done by
6249 restore_infcall_control_state. However, we do have to handle
6250 the case where the dummy call is returning after being
6251 stopped (e.g. the dummy call previously hit a breakpoint).
6252 We can't know which case we have so just always re-establish
6253 a selected frame here. */
6254 select_frame (get_current_frame ());
6258 annotate_stopped ();
6260 /* Suppress the stop observer if we're in the middle of:
6262 - a step n (n > 1), as there still more steps to be done.
6264 - a "finish" command, as the observer will be called in
6265 finish_command_continuation, so it can include the inferior
6266 function's return value.
6268 - calling an inferior function, as we pretend we inferior didn't
6269 run at all. The return value of the call is handled by the
6270 expression evaluator, through call_function_by_hand. */
6272 if (!target_has_execution
6273 || last
.kind
== TARGET_WAITKIND_SIGNALLED
6274 || last
.kind
== TARGET_WAITKIND_EXITED
6275 || last
.kind
== TARGET_WAITKIND_NO_RESUMED
6276 || (!(inferior_thread ()->step_multi
6277 && inferior_thread ()->control
.stop_step
)
6278 && !(inferior_thread ()->control
.stop_bpstat
6279 && inferior_thread ()->control
.proceed_to_finish
)
6280 && !inferior_thread ()->control
.in_infcall
))
6282 if (!ptid_equal (inferior_ptid
, null_ptid
))
6283 observer_notify_normal_stop (inferior_thread ()->control
.stop_bpstat
,
6286 observer_notify_normal_stop (NULL
, stop_print_frame
);
6289 if (target_has_execution
)
6291 if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
6292 && last
.kind
!= TARGET_WAITKIND_EXITED
)
6293 /* Delete the breakpoint we stopped at, if it wants to be deleted.
6294 Delete any breakpoint that is to be deleted at the next stop. */
6295 breakpoint_auto_delete (inferior_thread ()->control
.stop_bpstat
);
6298 /* Try to get rid of automatically added inferiors that are no
6299 longer needed. Keeping those around slows down things linearly.
6300 Note that this never removes the current inferior. */
6305 hook_stop_stub (void *cmd
)
6307 execute_cmd_pre_hook ((struct cmd_list_element
*) cmd
);
6312 signal_stop_state (int signo
)
6314 return signal_stop
[signo
];
6318 signal_print_state (int signo
)
6320 return signal_print
[signo
];
6324 signal_pass_state (int signo
)
6326 return signal_program
[signo
];
6330 signal_cache_update (int signo
)
6334 for (signo
= 0; signo
< (int) GDB_SIGNAL_LAST
; signo
++)
6335 signal_cache_update (signo
);
6340 signal_pass
[signo
] = (signal_stop
[signo
] == 0
6341 && signal_print
[signo
] == 0
6342 && signal_program
[signo
] == 1
6343 && signal_catch
[signo
] == 0);
6347 signal_stop_update (int signo
, int state
)
6349 int ret
= signal_stop
[signo
];
6351 signal_stop
[signo
] = state
;
6352 signal_cache_update (signo
);
6357 signal_print_update (int signo
, int state
)
6359 int ret
= signal_print
[signo
];
6361 signal_print
[signo
] = state
;
6362 signal_cache_update (signo
);
6367 signal_pass_update (int signo
, int state
)
6369 int ret
= signal_program
[signo
];
6371 signal_program
[signo
] = state
;
6372 signal_cache_update (signo
);
6376 /* Update the global 'signal_catch' from INFO and notify the
6380 signal_catch_update (const unsigned int *info
)
6384 for (i
= 0; i
< GDB_SIGNAL_LAST
; ++i
)
6385 signal_catch
[i
] = info
[i
] > 0;
6386 signal_cache_update (-1);
6387 target_pass_signals ((int) GDB_SIGNAL_LAST
, signal_pass
);
6391 sig_print_header (void)
6393 printf_filtered (_("Signal Stop\tPrint\tPass "
6394 "to program\tDescription\n"));
6398 sig_print_info (enum gdb_signal oursig
)
6400 const char *name
= gdb_signal_to_name (oursig
);
6401 int name_padding
= 13 - strlen (name
);
6403 if (name_padding
<= 0)
6406 printf_filtered ("%s", name
);
6407 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
6408 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
6409 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
6410 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
6411 printf_filtered ("%s\n", gdb_signal_to_string (oursig
));
6414 /* Specify how various signals in the inferior should be handled. */
6417 handle_command (char *args
, int from_tty
)
6420 int digits
, wordlen
;
6421 int sigfirst
, signum
, siglast
;
6422 enum gdb_signal oursig
;
6425 unsigned char *sigs
;
6426 struct cleanup
*old_chain
;
6430 error_no_arg (_("signal to handle"));
6433 /* Allocate and zero an array of flags for which signals to handle. */
6435 nsigs
= (int) GDB_SIGNAL_LAST
;
6436 sigs
= (unsigned char *) alloca (nsigs
);
6437 memset (sigs
, 0, nsigs
);
6439 /* Break the command line up into args. */
6441 argv
= gdb_buildargv (args
);
6442 old_chain
= make_cleanup_freeargv (argv
);
6444 /* Walk through the args, looking for signal oursigs, signal names, and
6445 actions. Signal numbers and signal names may be interspersed with
6446 actions, with the actions being performed for all signals cumulatively
6447 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
6449 while (*argv
!= NULL
)
6451 wordlen
= strlen (*argv
);
6452 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
6456 sigfirst
= siglast
= -1;
6458 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
6460 /* Apply action to all signals except those used by the
6461 debugger. Silently skip those. */
6464 siglast
= nsigs
- 1;
6466 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
6468 SET_SIGS (nsigs
, sigs
, signal_stop
);
6469 SET_SIGS (nsigs
, sigs
, signal_print
);
6471 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
6473 UNSET_SIGS (nsigs
, sigs
, signal_program
);
6475 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
6477 SET_SIGS (nsigs
, sigs
, signal_print
);
6479 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
6481 SET_SIGS (nsigs
, sigs
, signal_program
);
6483 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
6485 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
6487 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
6489 SET_SIGS (nsigs
, sigs
, signal_program
);
6491 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
6493 UNSET_SIGS (nsigs
, sigs
, signal_print
);
6494 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
6496 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
6498 UNSET_SIGS (nsigs
, sigs
, signal_program
);
6500 else if (digits
> 0)
6502 /* It is numeric. The numeric signal refers to our own
6503 internal signal numbering from target.h, not to host/target
6504 signal number. This is a feature; users really should be
6505 using symbolic names anyway, and the common ones like
6506 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
6508 sigfirst
= siglast
= (int)
6509 gdb_signal_from_command (atoi (*argv
));
6510 if ((*argv
)[digits
] == '-')
6513 gdb_signal_from_command (atoi ((*argv
) + digits
+ 1));
6515 if (sigfirst
> siglast
)
6517 /* Bet he didn't figure we'd think of this case... */
6525 oursig
= gdb_signal_from_name (*argv
);
6526 if (oursig
!= GDB_SIGNAL_UNKNOWN
)
6528 sigfirst
= siglast
= (int) oursig
;
6532 /* Not a number and not a recognized flag word => complain. */
6533 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv
);
6537 /* If any signal numbers or symbol names were found, set flags for
6538 which signals to apply actions to. */
6540 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
6542 switch ((enum gdb_signal
) signum
)
6544 case GDB_SIGNAL_TRAP
:
6545 case GDB_SIGNAL_INT
:
6546 if (!allsigs
&& !sigs
[signum
])
6548 if (query (_("%s is used by the debugger.\n\
6549 Are you sure you want to change it? "),
6550 gdb_signal_to_name ((enum gdb_signal
) signum
)))
6556 printf_unfiltered (_("Not confirmed, unchanged.\n"));
6557 gdb_flush (gdb_stdout
);
6562 case GDB_SIGNAL_DEFAULT
:
6563 case GDB_SIGNAL_UNKNOWN
:
6564 /* Make sure that "all" doesn't print these. */
6575 for (signum
= 0; signum
< nsigs
; signum
++)
6578 signal_cache_update (-1);
6579 target_pass_signals ((int) GDB_SIGNAL_LAST
, signal_pass
);
6580 target_program_signals ((int) GDB_SIGNAL_LAST
, signal_program
);
6584 /* Show the results. */
6585 sig_print_header ();
6586 for (; signum
< nsigs
; signum
++)
6588 sig_print_info (signum
);
6594 do_cleanups (old_chain
);
6597 /* Complete the "handle" command. */
6599 static VEC (char_ptr
) *
6600 handle_completer (struct cmd_list_element
*ignore
,
6601 const char *text
, const char *word
)
6603 VEC (char_ptr
) *vec_signals
, *vec_keywords
, *return_val
;
6604 static const char * const keywords
[] =
6618 vec_signals
= signal_completer (ignore
, text
, word
);
6619 vec_keywords
= complete_on_enum (keywords
, word
, word
);
6621 return_val
= VEC_merge (char_ptr
, vec_signals
, vec_keywords
);
6622 VEC_free (char_ptr
, vec_signals
);
6623 VEC_free (char_ptr
, vec_keywords
);
6628 xdb_handle_command (char *args
, int from_tty
)
6631 struct cleanup
*old_chain
;
6634 error_no_arg (_("xdb command"));
6636 /* Break the command line up into args. */
6638 argv
= gdb_buildargv (args
);
6639 old_chain
= make_cleanup_freeargv (argv
);
6640 if (argv
[1] != (char *) NULL
)
6645 bufLen
= strlen (argv
[0]) + 20;
6646 argBuf
= (char *) xmalloc (bufLen
);
6650 enum gdb_signal oursig
;
6652 oursig
= gdb_signal_from_name (argv
[0]);
6653 memset (argBuf
, 0, bufLen
);
6654 if (strcmp (argv
[1], "Q") == 0)
6655 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
6658 if (strcmp (argv
[1], "s") == 0)
6660 if (!signal_stop
[oursig
])
6661 sprintf (argBuf
, "%s %s", argv
[0], "stop");
6663 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
6665 else if (strcmp (argv
[1], "i") == 0)
6667 if (!signal_program
[oursig
])
6668 sprintf (argBuf
, "%s %s", argv
[0], "pass");
6670 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
6672 else if (strcmp (argv
[1], "r") == 0)
6674 if (!signal_print
[oursig
])
6675 sprintf (argBuf
, "%s %s", argv
[0], "print");
6677 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
6683 handle_command (argBuf
, from_tty
);
6685 printf_filtered (_("Invalid signal handling flag.\n"));
6690 do_cleanups (old_chain
);
6694 gdb_signal_from_command (int num
)
6696 if (num
>= 1 && num
<= 15)
6697 return (enum gdb_signal
) num
;
6698 error (_("Only signals 1-15 are valid as numeric signals.\n\
6699 Use \"info signals\" for a list of symbolic signals."));
6702 /* Print current contents of the tables set by the handle command.
6703 It is possible we should just be printing signals actually used
6704 by the current target (but for things to work right when switching
6705 targets, all signals should be in the signal tables). */
6708 signals_info (char *signum_exp
, int from_tty
)
6710 enum gdb_signal oursig
;
6712 sig_print_header ();
6716 /* First see if this is a symbol name. */
6717 oursig
= gdb_signal_from_name (signum_exp
);
6718 if (oursig
== GDB_SIGNAL_UNKNOWN
)
6720 /* No, try numeric. */
6722 gdb_signal_from_command (parse_and_eval_long (signum_exp
));
6724 sig_print_info (oursig
);
6728 printf_filtered ("\n");
6729 /* These ugly casts brought to you by the native VAX compiler. */
6730 for (oursig
= GDB_SIGNAL_FIRST
;
6731 (int) oursig
< (int) GDB_SIGNAL_LAST
;
6732 oursig
= (enum gdb_signal
) ((int) oursig
+ 1))
6736 if (oursig
!= GDB_SIGNAL_UNKNOWN
6737 && oursig
!= GDB_SIGNAL_DEFAULT
&& oursig
!= GDB_SIGNAL_0
)
6738 sig_print_info (oursig
);
6741 printf_filtered (_("\nUse the \"handle\" command "
6742 "to change these tables.\n"));
6745 /* Check if it makes sense to read $_siginfo from the current thread
6746 at this point. If not, throw an error. */
6749 validate_siginfo_access (void)
6751 /* No current inferior, no siginfo. */
6752 if (ptid_equal (inferior_ptid
, null_ptid
))
6753 error (_("No thread selected."));
6755 /* Don't try to read from a dead thread. */
6756 if (is_exited (inferior_ptid
))
6757 error (_("The current thread has terminated"));
6759 /* ... or from a spinning thread. */
6760 if (is_running (inferior_ptid
))
6761 error (_("Selected thread is running."));
6764 /* The $_siginfo convenience variable is a bit special. We don't know
6765 for sure the type of the value until we actually have a chance to
6766 fetch the data. The type can change depending on gdbarch, so it is
6767 also dependent on which thread you have selected.
6769 1. making $_siginfo be an internalvar that creates a new value on
6772 2. making the value of $_siginfo be an lval_computed value. */
6774 /* This function implements the lval_computed support for reading a
6778 siginfo_value_read (struct value
*v
)
6780 LONGEST transferred
;
6782 validate_siginfo_access ();
6785 target_read (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
,
6787 value_contents_all_raw (v
),
6789 TYPE_LENGTH (value_type (v
)));
6791 if (transferred
!= TYPE_LENGTH (value_type (v
)))
6792 error (_("Unable to read siginfo"));
6795 /* This function implements the lval_computed support for writing a
6799 siginfo_value_write (struct value
*v
, struct value
*fromval
)
6801 LONGEST transferred
;
6803 validate_siginfo_access ();
6805 transferred
= target_write (¤t_target
,
6806 TARGET_OBJECT_SIGNAL_INFO
,
6808 value_contents_all_raw (fromval
),
6810 TYPE_LENGTH (value_type (fromval
)));
6812 if (transferred
!= TYPE_LENGTH (value_type (fromval
)))
6813 error (_("Unable to write siginfo"));
6816 static const struct lval_funcs siginfo_value_funcs
=
6822 /* Return a new value with the correct type for the siginfo object of
6823 the current thread using architecture GDBARCH. Return a void value
6824 if there's no object available. */
6826 static struct value
*
6827 siginfo_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
,
6830 if (target_has_stack
6831 && !ptid_equal (inferior_ptid
, null_ptid
)
6832 && gdbarch_get_siginfo_type_p (gdbarch
))
6834 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
6836 return allocate_computed_value (type
, &siginfo_value_funcs
, NULL
);
6839 return allocate_value (builtin_type (gdbarch
)->builtin_void
);
6843 /* infcall_suspend_state contains state about the program itself like its
6844 registers and any signal it received when it last stopped.
6845 This state must be restored regardless of how the inferior function call
6846 ends (either successfully, or after it hits a breakpoint or signal)
6847 if the program is to properly continue where it left off. */
6849 struct infcall_suspend_state
6851 struct thread_suspend_state thread_suspend
;
6852 #if 0 /* Currently unused and empty structures are not valid C. */
6853 struct inferior_suspend_state inferior_suspend
;
6858 struct regcache
*registers
;
6860 /* Format of SIGINFO_DATA or NULL if it is not present. */
6861 struct gdbarch
*siginfo_gdbarch
;
6863 /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
6864 TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the
6865 content would be invalid. */
6866 gdb_byte
*siginfo_data
;
6869 struct infcall_suspend_state
*
6870 save_infcall_suspend_state (void)
6872 struct infcall_suspend_state
*inf_state
;
6873 struct thread_info
*tp
= inferior_thread ();
6875 struct inferior
*inf
= current_inferior ();
6877 struct regcache
*regcache
= get_current_regcache ();
6878 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6879 gdb_byte
*siginfo_data
= NULL
;
6881 if (gdbarch_get_siginfo_type_p (gdbarch
))
6883 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
6884 size_t len
= TYPE_LENGTH (type
);
6885 struct cleanup
*back_to
;
6887 siginfo_data
= xmalloc (len
);
6888 back_to
= make_cleanup (xfree
, siginfo_data
);
6890 if (target_read (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
, NULL
,
6891 siginfo_data
, 0, len
) == len
)
6892 discard_cleanups (back_to
);
6895 /* Errors ignored. */
6896 do_cleanups (back_to
);
6897 siginfo_data
= NULL
;
6901 inf_state
= XCNEW (struct infcall_suspend_state
);
6905 inf_state
->siginfo_gdbarch
= gdbarch
;
6906 inf_state
->siginfo_data
= siginfo_data
;
6909 inf_state
->thread_suspend
= tp
->suspend
;
6910 #if 0 /* Currently unused and empty structures are not valid C. */
6911 inf_state
->inferior_suspend
= inf
->suspend
;
6914 /* run_inferior_call will not use the signal due to its `proceed' call with
6915 GDB_SIGNAL_0 anyway. */
6916 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
6918 inf_state
->stop_pc
= stop_pc
;
6920 inf_state
->registers
= regcache_dup (regcache
);
6925 /* Restore inferior session state to INF_STATE. */
6928 restore_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
6930 struct thread_info
*tp
= inferior_thread ();
6932 struct inferior
*inf
= current_inferior ();
6934 struct regcache
*regcache
= get_current_regcache ();
6935 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6937 tp
->suspend
= inf_state
->thread_suspend
;
6938 #if 0 /* Currently unused and empty structures are not valid C. */
6939 inf
->suspend
= inf_state
->inferior_suspend
;
6942 stop_pc
= inf_state
->stop_pc
;
6944 if (inf_state
->siginfo_gdbarch
== gdbarch
)
6946 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
6948 /* Errors ignored. */
6949 target_write (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
, NULL
,
6950 inf_state
->siginfo_data
, 0, TYPE_LENGTH (type
));
6953 /* The inferior can be gone if the user types "print exit(0)"
6954 (and perhaps other times). */
6955 if (target_has_execution
)
6956 /* NB: The register write goes through to the target. */
6957 regcache_cpy (regcache
, inf_state
->registers
);
6959 discard_infcall_suspend_state (inf_state
);
6963 do_restore_infcall_suspend_state_cleanup (void *state
)
6965 restore_infcall_suspend_state (state
);
6969 make_cleanup_restore_infcall_suspend_state
6970 (struct infcall_suspend_state
*inf_state
)
6972 return make_cleanup (do_restore_infcall_suspend_state_cleanup
, inf_state
);
6976 discard_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
6978 regcache_xfree (inf_state
->registers
);
6979 xfree (inf_state
->siginfo_data
);
6984 get_infcall_suspend_state_regcache (struct infcall_suspend_state
*inf_state
)
6986 return inf_state
->registers
;
6989 /* infcall_control_state contains state regarding gdb's control of the
6990 inferior itself like stepping control. It also contains session state like
6991 the user's currently selected frame. */
6993 struct infcall_control_state
6995 struct thread_control_state thread_control
;
6996 struct inferior_control_state inferior_control
;
6999 enum stop_stack_kind stop_stack_dummy
;
7000 int stopped_by_random_signal
;
7001 int stop_after_trap
;
7003 /* ID if the selected frame when the inferior function call was made. */
7004 struct frame_id selected_frame_id
;
7007 /* Save all of the information associated with the inferior<==>gdb
7010 struct infcall_control_state
*
7011 save_infcall_control_state (void)
7013 struct infcall_control_state
*inf_status
= xmalloc (sizeof (*inf_status
));
7014 struct thread_info
*tp
= inferior_thread ();
7015 struct inferior
*inf
= current_inferior ();
7017 inf_status
->thread_control
= tp
->control
;
7018 inf_status
->inferior_control
= inf
->control
;
7020 tp
->control
.step_resume_breakpoint
= NULL
;
7021 tp
->control
.exception_resume_breakpoint
= NULL
;
7023 /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of
7024 chain. If caller's caller is walking the chain, they'll be happier if we
7025 hand them back the original chain when restore_infcall_control_state is
7027 tp
->control
.stop_bpstat
= bpstat_copy (tp
->control
.stop_bpstat
);
7030 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
7031 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
7032 inf_status
->stop_after_trap
= stop_after_trap
;
7034 inf_status
->selected_frame_id
= get_frame_id (get_selected_frame (NULL
));
7040 restore_selected_frame (void *args
)
7042 struct frame_id
*fid
= (struct frame_id
*) args
;
7043 struct frame_info
*frame
;
7045 frame
= frame_find_by_id (*fid
);
7047 /* If inf_status->selected_frame_id is NULL, there was no previously
7051 warning (_("Unable to restore previously selected frame."));
7055 select_frame (frame
);
7060 /* Restore inferior session state to INF_STATUS. */
7063 restore_infcall_control_state (struct infcall_control_state
*inf_status
)
7065 struct thread_info
*tp
= inferior_thread ();
7066 struct inferior
*inf
= current_inferior ();
7068 if (tp
->control
.step_resume_breakpoint
)
7069 tp
->control
.step_resume_breakpoint
->disposition
= disp_del_at_next_stop
;
7071 if (tp
->control
.exception_resume_breakpoint
)
7072 tp
->control
.exception_resume_breakpoint
->disposition
7073 = disp_del_at_next_stop
;
7075 /* Handle the bpstat_copy of the chain. */
7076 bpstat_clear (&tp
->control
.stop_bpstat
);
7078 tp
->control
= inf_status
->thread_control
;
7079 inf
->control
= inf_status
->inferior_control
;
7082 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
7083 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
7084 stop_after_trap
= inf_status
->stop_after_trap
;
7086 if (target_has_stack
)
7088 /* The point of catch_errors is that if the stack is clobbered,
7089 walking the stack might encounter a garbage pointer and
7090 error() trying to dereference it. */
7092 (restore_selected_frame
, &inf_status
->selected_frame_id
,
7093 "Unable to restore previously selected frame:\n",
7094 RETURN_MASK_ERROR
) == 0)
7095 /* Error in restoring the selected frame. Select the innermost
7097 select_frame (get_current_frame ());
7104 do_restore_infcall_control_state_cleanup (void *sts
)
7106 restore_infcall_control_state (sts
);
7110 make_cleanup_restore_infcall_control_state
7111 (struct infcall_control_state
*inf_status
)
7113 return make_cleanup (do_restore_infcall_control_state_cleanup
, inf_status
);
7117 discard_infcall_control_state (struct infcall_control_state
*inf_status
)
7119 if (inf_status
->thread_control
.step_resume_breakpoint
)
7120 inf_status
->thread_control
.step_resume_breakpoint
->disposition
7121 = disp_del_at_next_stop
;
7123 if (inf_status
->thread_control
.exception_resume_breakpoint
)
7124 inf_status
->thread_control
.exception_resume_breakpoint
->disposition
7125 = disp_del_at_next_stop
;
7127 /* See save_infcall_control_state for info on stop_bpstat. */
7128 bpstat_clear (&inf_status
->thread_control
.stop_bpstat
);
7133 /* restore_inferior_ptid() will be used by the cleanup machinery
7134 to restore the inferior_ptid value saved in a call to
7135 save_inferior_ptid(). */
7138 restore_inferior_ptid (void *arg
)
7140 ptid_t
*saved_ptid_ptr
= arg
;
7142 inferior_ptid
= *saved_ptid_ptr
;
7146 /* Save the value of inferior_ptid so that it may be restored by a
7147 later call to do_cleanups(). Returns the struct cleanup pointer
7148 needed for later doing the cleanup. */
7151 save_inferior_ptid (void)
7153 ptid_t
*saved_ptid_ptr
;
7155 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
7156 *saved_ptid_ptr
= inferior_ptid
;
7157 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
7160 /* See inferior.h. */
7163 clear_exit_convenience_vars (void)
7165 clear_internalvar (lookup_internalvar ("_exitsignal"));
7166 clear_internalvar (lookup_internalvar ("_exitcode"));
7170 /* User interface for reverse debugging:
7171 Set exec-direction / show exec-direction commands
7172 (returns error unless target implements to_set_exec_direction method). */
7174 int execution_direction
= EXEC_FORWARD
;
7175 static const char exec_forward
[] = "forward";
7176 static const char exec_reverse
[] = "reverse";
7177 static const char *exec_direction
= exec_forward
;
7178 static const char *const exec_direction_names
[] = {
7185 set_exec_direction_func (char *args
, int from_tty
,
7186 struct cmd_list_element
*cmd
)
7188 if (target_can_execute_reverse
)
7190 if (!strcmp (exec_direction
, exec_forward
))
7191 execution_direction
= EXEC_FORWARD
;
7192 else if (!strcmp (exec_direction
, exec_reverse
))
7193 execution_direction
= EXEC_REVERSE
;
7197 exec_direction
= exec_forward
;
7198 error (_("Target does not support this operation."));
7203 show_exec_direction_func (struct ui_file
*out
, int from_tty
,
7204 struct cmd_list_element
*cmd
, const char *value
)
7206 switch (execution_direction
) {
7208 fprintf_filtered (out
, _("Forward.\n"));
7211 fprintf_filtered (out
, _("Reverse.\n"));
7214 internal_error (__FILE__
, __LINE__
,
7215 _("bogus execution_direction value: %d"),
7216 (int) execution_direction
);
7221 show_schedule_multiple (struct ui_file
*file
, int from_tty
,
7222 struct cmd_list_element
*c
, const char *value
)
7224 fprintf_filtered (file
, _("Resuming the execution of threads "
7225 "of all processes is %s.\n"), value
);
7228 /* Implementation of `siginfo' variable. */
7230 static const struct internalvar_funcs siginfo_funcs
=
7238 _initialize_infrun (void)
7242 struct cmd_list_element
*c
;
7244 add_info ("signals", signals_info
, _("\
7245 What debugger does when program gets various signals.\n\
7246 Specify a signal as argument to print info on that signal only."));
7247 add_info_alias ("handle", "signals", 0);
7249 c
= add_com ("handle", class_run
, handle_command
, _("\
7250 Specify how to handle signals.\n\
7251 Usage: handle SIGNAL [ACTIONS]\n\
7252 Args are signals and actions to apply to those signals.\n\
7253 If no actions are specified, the current settings for the specified signals\n\
7254 will be displayed instead.\n\
7256 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
7257 from 1-15 are allowed for compatibility with old versions of GDB.\n\
7258 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
7259 The special arg \"all\" is recognized to mean all signals except those\n\
7260 used by the debugger, typically SIGTRAP and SIGINT.\n\
7262 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
7263 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
7264 Stop means reenter debugger if this signal happens (implies print).\n\
7265 Print means print a message if this signal happens.\n\
7266 Pass means let program see this signal; otherwise program doesn't know.\n\
7267 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
7268 Pass and Stop may be combined.\n\
7270 Multiple signals may be specified. Signal numbers and signal names\n\
7271 may be interspersed with actions, with the actions being performed for\n\
7272 all signals cumulatively specified."));
7273 set_cmd_completer (c
, handle_completer
);
7277 add_com ("lz", class_info
, signals_info
, _("\
7278 What debugger does when program gets various signals.\n\
7279 Specify a signal as argument to print info on that signal only."));
7280 add_com ("z", class_run
, xdb_handle_command
, _("\
7281 Specify how to handle a signal.\n\
7282 Args are signals and actions to apply to those signals.\n\
7283 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
7284 from 1-15 are allowed for compatibility with old versions of GDB.\n\
7285 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
7286 The special arg \"all\" is recognized to mean all signals except those\n\
7287 used by the debugger, typically SIGTRAP and SIGINT.\n\
7288 Recognized actions include \"s\" (toggles between stop and nostop),\n\
7289 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
7290 nopass), \"Q\" (noprint)\n\
7291 Stop means reenter debugger if this signal happens (implies print).\n\
7292 Print means print a message if this signal happens.\n\
7293 Pass means let program see this signal; otherwise program doesn't know.\n\
7294 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
7295 Pass and Stop may be combined."));
7299 stop_command
= add_cmd ("stop", class_obscure
,
7300 not_just_help_class_command
, _("\
7301 There is no `stop' command, but you can set a hook on `stop'.\n\
7302 This allows you to set a list of commands to be run each time execution\n\
7303 of the program stops."), &cmdlist
);
7305 add_setshow_zuinteger_cmd ("infrun", class_maintenance
, &debug_infrun
, _("\
7306 Set inferior debugging."), _("\
7307 Show inferior debugging."), _("\
7308 When non-zero, inferior specific debugging is enabled."),
7311 &setdebuglist
, &showdebuglist
);
7313 add_setshow_boolean_cmd ("displaced", class_maintenance
,
7314 &debug_displaced
, _("\
7315 Set displaced stepping debugging."), _("\
7316 Show displaced stepping debugging."), _("\
7317 When non-zero, displaced stepping specific debugging is enabled."),
7319 show_debug_displaced
,
7320 &setdebuglist
, &showdebuglist
);
7322 add_setshow_boolean_cmd ("non-stop", no_class
,
7324 Set whether gdb controls the inferior in non-stop mode."), _("\
7325 Show whether gdb controls the inferior in non-stop mode."), _("\
7326 When debugging a multi-threaded program and this setting is\n\
7327 off (the default, also called all-stop mode), when one thread stops\n\
7328 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
7329 all other threads in the program while you interact with the thread of\n\
7330 interest. When you continue or step a thread, you can allow the other\n\
7331 threads to run, or have them remain stopped, but while you inspect any\n\
7332 thread's state, all threads stop.\n\
7334 In non-stop mode, when one thread stops, other threads can continue\n\
7335 to run freely. You'll be able to step each thread independently,\n\
7336 leave it stopped or free to run as needed."),
7342 numsigs
= (int) GDB_SIGNAL_LAST
;
7343 signal_stop
= (unsigned char *) xmalloc (sizeof (signal_stop
[0]) * numsigs
);
7344 signal_print
= (unsigned char *)
7345 xmalloc (sizeof (signal_print
[0]) * numsigs
);
7346 signal_program
= (unsigned char *)
7347 xmalloc (sizeof (signal_program
[0]) * numsigs
);
7348 signal_catch
= (unsigned char *)
7349 xmalloc (sizeof (signal_catch
[0]) * numsigs
);
7350 signal_pass
= (unsigned char *)
7351 xmalloc (sizeof (signal_program
[0]) * numsigs
);
7352 for (i
= 0; i
< numsigs
; i
++)
7355 signal_print
[i
] = 1;
7356 signal_program
[i
] = 1;
7357 signal_catch
[i
] = 0;
7360 /* Signals caused by debugger's own actions
7361 should not be given to the program afterwards. */
7362 signal_program
[GDB_SIGNAL_TRAP
] = 0;
7363 signal_program
[GDB_SIGNAL_INT
] = 0;
7365 /* Signals that are not errors should not normally enter the debugger. */
7366 signal_stop
[GDB_SIGNAL_ALRM
] = 0;
7367 signal_print
[GDB_SIGNAL_ALRM
] = 0;
7368 signal_stop
[GDB_SIGNAL_VTALRM
] = 0;
7369 signal_print
[GDB_SIGNAL_VTALRM
] = 0;
7370 signal_stop
[GDB_SIGNAL_PROF
] = 0;
7371 signal_print
[GDB_SIGNAL_PROF
] = 0;
7372 signal_stop
[GDB_SIGNAL_CHLD
] = 0;
7373 signal_print
[GDB_SIGNAL_CHLD
] = 0;
7374 signal_stop
[GDB_SIGNAL_IO
] = 0;
7375 signal_print
[GDB_SIGNAL_IO
] = 0;
7376 signal_stop
[GDB_SIGNAL_POLL
] = 0;
7377 signal_print
[GDB_SIGNAL_POLL
] = 0;
7378 signal_stop
[GDB_SIGNAL_URG
] = 0;
7379 signal_print
[GDB_SIGNAL_URG
] = 0;
7380 signal_stop
[GDB_SIGNAL_WINCH
] = 0;
7381 signal_print
[GDB_SIGNAL_WINCH
] = 0;
7382 signal_stop
[GDB_SIGNAL_PRIO
] = 0;
7383 signal_print
[GDB_SIGNAL_PRIO
] = 0;
7385 /* These signals are used internally by user-level thread
7386 implementations. (See signal(5) on Solaris.) Like the above
7387 signals, a healthy program receives and handles them as part of
7388 its normal operation. */
7389 signal_stop
[GDB_SIGNAL_LWP
] = 0;
7390 signal_print
[GDB_SIGNAL_LWP
] = 0;
7391 signal_stop
[GDB_SIGNAL_WAITING
] = 0;
7392 signal_print
[GDB_SIGNAL_WAITING
] = 0;
7393 signal_stop
[GDB_SIGNAL_CANCEL
] = 0;
7394 signal_print
[GDB_SIGNAL_CANCEL
] = 0;
7396 /* Update cached state. */
7397 signal_cache_update (-1);
7399 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support
,
7400 &stop_on_solib_events
, _("\
7401 Set stopping for shared library events."), _("\
7402 Show stopping for shared library events."), _("\
7403 If nonzero, gdb will give control to the user when the dynamic linker\n\
7404 notifies gdb of shared library events. The most common event of interest\n\
7405 to the user would be loading/unloading of a new library."),
7406 set_stop_on_solib_events
,
7407 show_stop_on_solib_events
,
7408 &setlist
, &showlist
);
7410 add_setshow_enum_cmd ("follow-fork-mode", class_run
,
7411 follow_fork_mode_kind_names
,
7412 &follow_fork_mode_string
, _("\
7413 Set debugger response to a program call of fork or vfork."), _("\
7414 Show debugger response to a program call of fork or vfork."), _("\
7415 A fork or vfork creates a new process. follow-fork-mode can be:\n\
7416 parent - the original process is debugged after a fork\n\
7417 child - the new process is debugged after a fork\n\
7418 The unfollowed process will continue to run.\n\
7419 By default, the debugger will follow the parent process."),
7421 show_follow_fork_mode_string
,
7422 &setlist
, &showlist
);
7424 add_setshow_enum_cmd ("follow-exec-mode", class_run
,
7425 follow_exec_mode_names
,
7426 &follow_exec_mode_string
, _("\
7427 Set debugger response to a program call of exec."), _("\
7428 Show debugger response to a program call of exec."), _("\
7429 An exec call replaces the program image of a process.\n\
7431 follow-exec-mode can be:\n\
7433 new - the debugger creates a new inferior and rebinds the process\n\
7434 to this new inferior. The program the process was running before\n\
7435 the exec call can be restarted afterwards by restarting the original\n\
7438 same - the debugger keeps the process bound to the same inferior.\n\
7439 The new executable image replaces the previous executable loaded in\n\
7440 the inferior. Restarting the inferior after the exec call restarts\n\
7441 the executable the process was running after the exec call.\n\
7443 By default, the debugger will use the same inferior."),
7445 show_follow_exec_mode_string
,
7446 &setlist
, &showlist
);
7448 add_setshow_enum_cmd ("scheduler-locking", class_run
,
7449 scheduler_enums
, &scheduler_mode
, _("\
7450 Set mode for locking scheduler during execution."), _("\
7451 Show mode for locking scheduler during execution."), _("\
7452 off == no locking (threads may preempt at any time)\n\
7453 on == full locking (no thread except the current thread may run)\n\
7454 step == scheduler locked during every single-step operation.\n\
7455 In this mode, no other thread may run during a step command.\n\
7456 Other threads may run while stepping over a function call ('next')."),
7457 set_schedlock_func
, /* traps on target vector */
7458 show_scheduler_mode
,
7459 &setlist
, &showlist
);
7461 add_setshow_boolean_cmd ("schedule-multiple", class_run
, &sched_multi
, _("\
7462 Set mode for resuming threads of all processes."), _("\
7463 Show mode for resuming threads of all processes."), _("\
7464 When on, execution commands (such as 'continue' or 'next') resume all\n\
7465 threads of all processes. When off (which is the default), execution\n\
7466 commands only resume the threads of the current process. The set of\n\
7467 threads that are resumed is further refined by the scheduler-locking\n\
7468 mode (see help set scheduler-locking)."),
7470 show_schedule_multiple
,
7471 &setlist
, &showlist
);
7473 add_setshow_boolean_cmd ("step-mode", class_run
, &step_stop_if_no_debug
, _("\
7474 Set mode of the step operation."), _("\
7475 Show mode of the step operation."), _("\
7476 When set, doing a step over a function without debug line information\n\
7477 will stop at the first instruction of that function. Otherwise, the\n\
7478 function is skipped and the step command stops at a different source line."),
7480 show_step_stop_if_no_debug
,
7481 &setlist
, &showlist
);
7483 add_setshow_auto_boolean_cmd ("displaced-stepping", class_run
,
7484 &can_use_displaced_stepping
, _("\
7485 Set debugger's willingness to use displaced stepping."), _("\
7486 Show debugger's willingness to use displaced stepping."), _("\
7487 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
7488 supported by the target architecture. If off, gdb will not use displaced\n\
7489 stepping to step over breakpoints, even if such is supported by the target\n\
7490 architecture. If auto (which is the default), gdb will use displaced stepping\n\
7491 if the target architecture supports it and non-stop mode is active, but will not\n\
7492 use it in all-stop mode (see help set non-stop)."),
7494 show_can_use_displaced_stepping
,
7495 &setlist
, &showlist
);
7497 add_setshow_enum_cmd ("exec-direction", class_run
, exec_direction_names
,
7498 &exec_direction
, _("Set direction of execution.\n\
7499 Options are 'forward' or 'reverse'."),
7500 _("Show direction of execution (forward/reverse)."),
7501 _("Tells gdb whether to execute forward or backward."),
7502 set_exec_direction_func
, show_exec_direction_func
,
7503 &setlist
, &showlist
);
7505 /* Set/show detach-on-fork: user-settable mode. */
7507 add_setshow_boolean_cmd ("detach-on-fork", class_run
, &detach_fork
, _("\
7508 Set whether gdb will detach the child of a fork."), _("\
7509 Show whether gdb will detach the child of a fork."), _("\
7510 Tells gdb whether to detach the child of a fork."),
7511 NULL
, NULL
, &setlist
, &showlist
);
7513 /* Set/show disable address space randomization mode. */
7515 add_setshow_boolean_cmd ("disable-randomization", class_support
,
7516 &disable_randomization
, _("\
7517 Set disabling of debuggee's virtual address space randomization."), _("\
7518 Show disabling of debuggee's virtual address space randomization."), _("\
7519 When this mode is on (which is the default), randomization of the virtual\n\
7520 address space is disabled. Standalone programs run with the randomization\n\
7521 enabled by default on some platforms."),
7522 &set_disable_randomization
,
7523 &show_disable_randomization
,
7524 &setlist
, &showlist
);
7526 /* ptid initializations */
7527 inferior_ptid
= null_ptid
;
7528 target_last_wait_ptid
= minus_one_ptid
;
7530 observer_attach_thread_ptid_changed (infrun_thread_ptid_changed
);
7531 observer_attach_thread_stop_requested (infrun_thread_stop_requested
);
7532 observer_attach_thread_exit (infrun_thread_thread_exit
);
7533 observer_attach_inferior_exit (infrun_inferior_exit
);
7535 /* Explicitly create without lookup, since that tries to create a
7536 value with a void typed value, and when we get here, gdbarch
7537 isn't initialized yet. At this point, we're quite sure there
7538 isn't another convenience variable of the same name. */
7539 create_internalvar_type_lazy ("_siginfo", &siginfo_funcs
, NULL
);
7541 add_setshow_boolean_cmd ("observer", no_class
,
7542 &observer_mode_1
, _("\
7543 Set whether gdb controls the inferior in observer mode."), _("\
7544 Show whether gdb controls the inferior in observer mode."), _("\
7545 In observer mode, GDB can get data from the inferior, but not\n\
7546 affect its execution. Registers and memory may not be changed,\n\
7547 breakpoints may not be set, and the program cannot be interrupted\n\