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/>. */
28 #include "exceptions.h"
29 #include "breakpoint.h"
33 #include "cli/cli-script.h"
35 #include "gdbthread.h"
47 #include "dictionary.h"
49 #include "gdb_assert.h"
50 #include "mi/mi-common.h"
51 #include "event-top.h"
53 #include "record-full.h"
54 #include "inline-frame.h"
56 #include "tracepoint.h"
57 #include "continuations.h"
62 #include "completer.h"
63 #include "target-descriptions.h"
64 #include "target-dcache.h"
66 /* Prototypes for local functions */
68 static void signals_info (char *, int);
70 static void handle_command (char *, int);
72 static void sig_print_info (enum gdb_signal
);
74 static void sig_print_header (void);
76 static void resume_cleanups (void *);
78 static int hook_stop_stub (void *);
80 static int restore_selected_frame (void *);
82 static int follow_fork (void);
84 static void set_schedlock_func (char *args
, int from_tty
,
85 struct cmd_list_element
*c
);
87 static int currently_stepping (struct thread_info
*tp
);
89 static void xdb_handle_command (char *args
, int from_tty
);
91 static void end_stepping_range (void);
93 void _initialize_infrun (void);
95 void nullify_last_target_wait_ptid (void);
97 static void insert_hp_step_resume_breakpoint_at_frame (struct frame_info
*);
99 static void insert_step_resume_breakpoint_at_caller (struct frame_info
*);
101 static void insert_longjmp_resume_breakpoint (struct gdbarch
*, CORE_ADDR
);
103 /* When set, stop the 'step' command if we enter a function which has
104 no line number information. The normal behavior is that we step
105 over such function. */
106 int step_stop_if_no_debug
= 0;
108 show_step_stop_if_no_debug (struct ui_file
*file
, int from_tty
,
109 struct cmd_list_element
*c
, const char *value
)
111 fprintf_filtered (file
, _("Mode of the step operation is %s.\n"), value
);
114 /* In asynchronous mode, but simulating synchronous execution. */
116 int sync_execution
= 0;
118 /* proceed and normal_stop use this to notify the user when the
119 inferior stopped in a different thread than it had been running
122 static ptid_t previous_inferior_ptid
;
124 /* If set (default for legacy reasons), when following a fork, GDB
125 will detach from one of the fork branches, child or parent.
126 Exactly which branch is detached depends on 'set follow-fork-mode'
129 static int detach_fork
= 1;
131 int debug_displaced
= 0;
133 show_debug_displaced (struct ui_file
*file
, int from_tty
,
134 struct cmd_list_element
*c
, const char *value
)
136 fprintf_filtered (file
, _("Displace stepping debugging is %s.\n"), value
);
139 unsigned int debug_infrun
= 0;
141 show_debug_infrun (struct ui_file
*file
, int from_tty
,
142 struct cmd_list_element
*c
, const char *value
)
144 fprintf_filtered (file
, _("Inferior debugging is %s.\n"), value
);
148 /* Support for disabling address space randomization. */
150 int disable_randomization
= 1;
153 show_disable_randomization (struct ui_file
*file
, int from_tty
,
154 struct cmd_list_element
*c
, const char *value
)
156 if (target_supports_disable_randomization ())
157 fprintf_filtered (file
,
158 _("Disabling randomization of debuggee's "
159 "virtual address space is %s.\n"),
162 fputs_filtered (_("Disabling randomization of debuggee's "
163 "virtual address space is unsupported on\n"
164 "this platform.\n"), file
);
168 set_disable_randomization (char *args
, int from_tty
,
169 struct cmd_list_element
*c
)
171 if (!target_supports_disable_randomization ())
172 error (_("Disabling randomization of debuggee's "
173 "virtual address space is unsupported on\n"
177 /* User interface for non-stop mode. */
180 static int non_stop_1
= 0;
183 set_non_stop (char *args
, int from_tty
,
184 struct cmd_list_element
*c
)
186 if (target_has_execution
)
188 non_stop_1
= non_stop
;
189 error (_("Cannot change this setting while the inferior is running."));
192 non_stop
= non_stop_1
;
196 show_non_stop (struct ui_file
*file
, int from_tty
,
197 struct cmd_list_element
*c
, const char *value
)
199 fprintf_filtered (file
,
200 _("Controlling the inferior in non-stop mode is %s.\n"),
204 /* "Observer mode" is somewhat like a more extreme version of
205 non-stop, in which all GDB operations that might affect the
206 target's execution have been disabled. */
208 int observer_mode
= 0;
209 static int observer_mode_1
= 0;
212 set_observer_mode (char *args
, int from_tty
,
213 struct cmd_list_element
*c
)
215 if (target_has_execution
)
217 observer_mode_1
= observer_mode
;
218 error (_("Cannot change this setting while the inferior is running."));
221 observer_mode
= observer_mode_1
;
223 may_write_registers
= !observer_mode
;
224 may_write_memory
= !observer_mode
;
225 may_insert_breakpoints
= !observer_mode
;
226 may_insert_tracepoints
= !observer_mode
;
227 /* We can insert fast tracepoints in or out of observer mode,
228 but enable them if we're going into this mode. */
230 may_insert_fast_tracepoints
= 1;
231 may_stop
= !observer_mode
;
232 update_target_permissions ();
234 /* Going *into* observer mode we must force non-stop, then
235 going out we leave it that way. */
238 pagination_enabled
= 0;
239 non_stop
= non_stop_1
= 1;
243 printf_filtered (_("Observer mode is now %s.\n"),
244 (observer_mode
? "on" : "off"));
248 show_observer_mode (struct ui_file
*file
, int from_tty
,
249 struct cmd_list_element
*c
, const char *value
)
251 fprintf_filtered (file
, _("Observer mode is %s.\n"), value
);
254 /* This updates the value of observer mode based on changes in
255 permissions. Note that we are deliberately ignoring the values of
256 may-write-registers and may-write-memory, since the user may have
257 reason to enable these during a session, for instance to turn on a
258 debugging-related global. */
261 update_observer_mode (void)
265 newval
= (!may_insert_breakpoints
266 && !may_insert_tracepoints
267 && may_insert_fast_tracepoints
271 /* Let the user know if things change. */
272 if (newval
!= observer_mode
)
273 printf_filtered (_("Observer mode is now %s.\n"),
274 (newval
? "on" : "off"));
276 observer_mode
= observer_mode_1
= newval
;
279 /* Tables of how to react to signals; the user sets them. */
281 static unsigned char *signal_stop
;
282 static unsigned char *signal_print
;
283 static unsigned char *signal_program
;
285 /* Table of signals that are registered with "catch signal". A
286 non-zero entry indicates that the signal is caught by some "catch
287 signal" command. This has size GDB_SIGNAL_LAST, to accommodate all
289 static unsigned char *signal_catch
;
291 /* Table of signals that the target may silently handle.
292 This is automatically determined from the flags above,
293 and simply cached here. */
294 static unsigned char *signal_pass
;
296 #define SET_SIGS(nsigs,sigs,flags) \
298 int signum = (nsigs); \
299 while (signum-- > 0) \
300 if ((sigs)[signum]) \
301 (flags)[signum] = 1; \
304 #define UNSET_SIGS(nsigs,sigs,flags) \
306 int signum = (nsigs); \
307 while (signum-- > 0) \
308 if ((sigs)[signum]) \
309 (flags)[signum] = 0; \
312 /* Update the target's copy of SIGNAL_PROGRAM. The sole purpose of
313 this function is to avoid exporting `signal_program'. */
316 update_signals_program_target (void)
318 target_program_signals ((int) GDB_SIGNAL_LAST
, signal_program
);
321 /* Value to pass to target_resume() to cause all threads to resume. */
323 #define RESUME_ALL minus_one_ptid
325 /* Command list pointer for the "stop" placeholder. */
327 static struct cmd_list_element
*stop_command
;
329 /* Function inferior was in as of last step command. */
331 static struct symbol
*step_start_function
;
333 /* Nonzero if we want to give control to the user when we're notified
334 of shared library events by the dynamic linker. */
335 int stop_on_solib_events
;
337 /* Enable or disable optional shared library event breakpoints
338 as appropriate when the above flag is changed. */
341 set_stop_on_solib_events (char *args
, int from_tty
, struct cmd_list_element
*c
)
343 update_solib_breakpoints ();
347 show_stop_on_solib_events (struct ui_file
*file
, int from_tty
,
348 struct cmd_list_element
*c
, const char *value
)
350 fprintf_filtered (file
, _("Stopping for shared library events is %s.\n"),
354 /* Nonzero means expecting a trace trap
355 and should stop the inferior and return silently when it happens. */
359 /* Save register contents here when executing a "finish" command or are
360 about to pop a stack dummy frame, if-and-only-if proceed_to_finish is set.
361 Thus this contains the return value from the called function (assuming
362 values are returned in a register). */
364 struct regcache
*stop_registers
;
366 /* Nonzero after stop if current stack frame should be printed. */
368 static int stop_print_frame
;
370 /* This is a cached copy of the pid/waitstatus of the last event
371 returned by target_wait()/deprecated_target_wait_hook(). This
372 information is returned by get_last_target_status(). */
373 static ptid_t target_last_wait_ptid
;
374 static struct target_waitstatus target_last_waitstatus
;
376 static void context_switch (ptid_t ptid
);
378 void init_thread_stepping_state (struct thread_info
*tss
);
380 static void init_infwait_state (void);
382 static const char follow_fork_mode_child
[] = "child";
383 static const char follow_fork_mode_parent
[] = "parent";
385 static const char *const follow_fork_mode_kind_names
[] = {
386 follow_fork_mode_child
,
387 follow_fork_mode_parent
,
391 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
393 show_follow_fork_mode_string (struct ui_file
*file
, int from_tty
,
394 struct cmd_list_element
*c
, const char *value
)
396 fprintf_filtered (file
,
397 _("Debugger response to a program "
398 "call of fork or vfork is \"%s\".\n"),
403 /* Tell the target to follow the fork we're stopped at. Returns true
404 if the inferior should be resumed; false, if the target for some
405 reason decided it's best not to resume. */
410 int follow_child
= (follow_fork_mode_string
== follow_fork_mode_child
);
411 int should_resume
= 1;
412 struct thread_info
*tp
;
414 /* Copy user stepping state to the new inferior thread. FIXME: the
415 followed fork child thread should have a copy of most of the
416 parent thread structure's run control related fields, not just these.
417 Initialized to avoid "may be used uninitialized" warnings from gcc. */
418 struct breakpoint
*step_resume_breakpoint
= NULL
;
419 struct breakpoint
*exception_resume_breakpoint
= NULL
;
420 CORE_ADDR step_range_start
= 0;
421 CORE_ADDR step_range_end
= 0;
422 struct frame_id step_frame_id
= { 0 };
423 struct interp
*command_interp
= NULL
;
428 struct target_waitstatus wait_status
;
430 /* Get the last target status returned by target_wait(). */
431 get_last_target_status (&wait_ptid
, &wait_status
);
433 /* If not stopped at a fork event, then there's nothing else to
435 if (wait_status
.kind
!= TARGET_WAITKIND_FORKED
436 && wait_status
.kind
!= TARGET_WAITKIND_VFORKED
)
439 /* Check if we switched over from WAIT_PTID, since the event was
441 if (!ptid_equal (wait_ptid
, minus_one_ptid
)
442 && !ptid_equal (inferior_ptid
, wait_ptid
))
444 /* We did. Switch back to WAIT_PTID thread, to tell the
445 target to follow it (in either direction). We'll
446 afterwards refuse to resume, and inform the user what
448 switch_to_thread (wait_ptid
);
453 tp
= inferior_thread ();
455 /* If there were any forks/vforks that were caught and are now to be
456 followed, then do so now. */
457 switch (tp
->pending_follow
.kind
)
459 case TARGET_WAITKIND_FORKED
:
460 case TARGET_WAITKIND_VFORKED
:
462 ptid_t parent
, child
;
464 /* If the user did a next/step, etc, over a fork call,
465 preserve the stepping state in the fork child. */
466 if (follow_child
&& should_resume
)
468 step_resume_breakpoint
= clone_momentary_breakpoint
469 (tp
->control
.step_resume_breakpoint
);
470 step_range_start
= tp
->control
.step_range_start
;
471 step_range_end
= tp
->control
.step_range_end
;
472 step_frame_id
= tp
->control
.step_frame_id
;
473 exception_resume_breakpoint
474 = clone_momentary_breakpoint (tp
->control
.exception_resume_breakpoint
);
475 command_interp
= tp
->control
.command_interp
;
477 /* For now, delete the parent's sr breakpoint, otherwise,
478 parent/child sr breakpoints are considered duplicates,
479 and the child version will not be installed. Remove
480 this when the breakpoints module becomes aware of
481 inferiors and address spaces. */
482 delete_step_resume_breakpoint (tp
);
483 tp
->control
.step_range_start
= 0;
484 tp
->control
.step_range_end
= 0;
485 tp
->control
.step_frame_id
= null_frame_id
;
486 delete_exception_resume_breakpoint (tp
);
487 tp
->control
.command_interp
= NULL
;
490 parent
= inferior_ptid
;
491 child
= tp
->pending_follow
.value
.related_pid
;
493 /* Tell the target to do whatever is necessary to follow
494 either parent or child. */
495 if (target_follow_fork (follow_child
, detach_fork
))
497 /* Target refused to follow, or there's some other reason
498 we shouldn't resume. */
503 /* This pending follow fork event is now handled, one way
504 or another. The previous selected thread may be gone
505 from the lists by now, but if it is still around, need
506 to clear the pending follow request. */
507 tp
= find_thread_ptid (parent
);
509 tp
->pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
511 /* This makes sure we don't try to apply the "Switched
512 over from WAIT_PID" logic above. */
513 nullify_last_target_wait_ptid ();
515 /* If we followed the child, switch to it... */
518 switch_to_thread (child
);
520 /* ... and preserve the stepping state, in case the
521 user was stepping over the fork call. */
524 tp
= inferior_thread ();
525 tp
->control
.step_resume_breakpoint
526 = step_resume_breakpoint
;
527 tp
->control
.step_range_start
= step_range_start
;
528 tp
->control
.step_range_end
= step_range_end
;
529 tp
->control
.step_frame_id
= step_frame_id
;
530 tp
->control
.exception_resume_breakpoint
531 = exception_resume_breakpoint
;
532 tp
->control
.command_interp
= command_interp
;
536 /* If we get here, it was because we're trying to
537 resume from a fork catchpoint, but, the user
538 has switched threads away from the thread that
539 forked. In that case, the resume command
540 issued is most likely not applicable to the
541 child, so just warn, and refuse to resume. */
542 warning (_("Not resuming: switched threads "
543 "before following fork child.\n"));
546 /* Reset breakpoints in the child as appropriate. */
547 follow_inferior_reset_breakpoints ();
550 switch_to_thread (parent
);
554 case TARGET_WAITKIND_SPURIOUS
:
555 /* Nothing to follow. */
558 internal_error (__FILE__
, __LINE__
,
559 "Unexpected pending_follow.kind %d\n",
560 tp
->pending_follow
.kind
);
564 return should_resume
;
568 follow_inferior_reset_breakpoints (void)
570 struct thread_info
*tp
= inferior_thread ();
572 /* Was there a step_resume breakpoint? (There was if the user
573 did a "next" at the fork() call.) If so, explicitly reset its
576 step_resumes are a form of bp that are made to be per-thread.
577 Since we created the step_resume bp when the parent process
578 was being debugged, and now are switching to the child process,
579 from the breakpoint package's viewpoint, that's a switch of
580 "threads". We must update the bp's notion of which thread
581 it is for, or it'll be ignored when it triggers. */
583 if (tp
->control
.step_resume_breakpoint
)
584 breakpoint_re_set_thread (tp
->control
.step_resume_breakpoint
);
586 if (tp
->control
.exception_resume_breakpoint
)
587 breakpoint_re_set_thread (tp
->control
.exception_resume_breakpoint
);
589 /* Reinsert all breakpoints in the child. The user may have set
590 breakpoints after catching the fork, in which case those
591 were never set in the child, but only in the parent. This makes
592 sure the inserted breakpoints match the breakpoint list. */
594 breakpoint_re_set ();
595 insert_breakpoints ();
598 /* The child has exited or execed: resume threads of the parent the
599 user wanted to be executing. */
602 proceed_after_vfork_done (struct thread_info
*thread
,
605 int pid
= * (int *) arg
;
607 if (ptid_get_pid (thread
->ptid
) == pid
608 && is_running (thread
->ptid
)
609 && !is_executing (thread
->ptid
)
610 && !thread
->stop_requested
611 && thread
->suspend
.stop_signal
== GDB_SIGNAL_0
)
614 fprintf_unfiltered (gdb_stdlog
,
615 "infrun: resuming vfork parent thread %s\n",
616 target_pid_to_str (thread
->ptid
));
618 switch_to_thread (thread
->ptid
);
619 clear_proceed_status ();
620 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
, 0);
626 /* Called whenever we notice an exec or exit event, to handle
627 detaching or resuming a vfork parent. */
630 handle_vfork_child_exec_or_exit (int exec
)
632 struct inferior
*inf
= current_inferior ();
634 if (inf
->vfork_parent
)
636 int resume_parent
= -1;
638 /* This exec or exit marks the end of the shared memory region
639 between the parent and the child. If the user wanted to
640 detach from the parent, now is the time. */
642 if (inf
->vfork_parent
->pending_detach
)
644 struct thread_info
*tp
;
645 struct cleanup
*old_chain
;
646 struct program_space
*pspace
;
647 struct address_space
*aspace
;
649 /* follow-fork child, detach-on-fork on. */
651 inf
->vfork_parent
->pending_detach
= 0;
655 /* If we're handling a child exit, then inferior_ptid
656 points at the inferior's pid, not to a thread. */
657 old_chain
= save_inferior_ptid ();
658 save_current_program_space ();
659 save_current_inferior ();
662 old_chain
= save_current_space_and_thread ();
664 /* We're letting loose of the parent. */
665 tp
= any_live_thread_of_process (inf
->vfork_parent
->pid
);
666 switch_to_thread (tp
->ptid
);
668 /* We're about to detach from the parent, which implicitly
669 removes breakpoints from its address space. There's a
670 catch here: we want to reuse the spaces for the child,
671 but, parent/child are still sharing the pspace at this
672 point, although the exec in reality makes the kernel give
673 the child a fresh set of new pages. The problem here is
674 that the breakpoints module being unaware of this, would
675 likely chose the child process to write to the parent
676 address space. Swapping the child temporarily away from
677 the spaces has the desired effect. Yes, this is "sort
680 pspace
= inf
->pspace
;
681 aspace
= inf
->aspace
;
685 if (debug_infrun
|| info_verbose
)
687 target_terminal_ours ();
690 fprintf_filtered (gdb_stdlog
,
691 "Detaching vfork parent process "
692 "%d after child exec.\n",
693 inf
->vfork_parent
->pid
);
695 fprintf_filtered (gdb_stdlog
,
696 "Detaching vfork parent process "
697 "%d after child exit.\n",
698 inf
->vfork_parent
->pid
);
701 target_detach (NULL
, 0);
704 inf
->pspace
= pspace
;
705 inf
->aspace
= aspace
;
707 do_cleanups (old_chain
);
711 /* We're staying attached to the parent, so, really give the
712 child a new address space. */
713 inf
->pspace
= add_program_space (maybe_new_address_space ());
714 inf
->aspace
= inf
->pspace
->aspace
;
716 set_current_program_space (inf
->pspace
);
718 resume_parent
= inf
->vfork_parent
->pid
;
720 /* Break the bonds. */
721 inf
->vfork_parent
->vfork_child
= NULL
;
725 struct cleanup
*old_chain
;
726 struct program_space
*pspace
;
728 /* If this is a vfork child exiting, then the pspace and
729 aspaces were shared with the parent. Since we're
730 reporting the process exit, we'll be mourning all that is
731 found in the address space, and switching to null_ptid,
732 preparing to start a new inferior. But, since we don't
733 want to clobber the parent's address/program spaces, we
734 go ahead and create a new one for this exiting
737 /* Switch to null_ptid, so that clone_program_space doesn't want
738 to read the selected frame of a dead process. */
739 old_chain
= save_inferior_ptid ();
740 inferior_ptid
= null_ptid
;
742 /* This inferior is dead, so avoid giving the breakpoints
743 module the option to write through to it (cloning a
744 program space resets breakpoints). */
747 pspace
= add_program_space (maybe_new_address_space ());
748 set_current_program_space (pspace
);
750 inf
->symfile_flags
= SYMFILE_NO_READ
;
751 clone_program_space (pspace
, inf
->vfork_parent
->pspace
);
752 inf
->pspace
= pspace
;
753 inf
->aspace
= pspace
->aspace
;
755 /* Put back inferior_ptid. We'll continue mourning this
757 do_cleanups (old_chain
);
759 resume_parent
= inf
->vfork_parent
->pid
;
760 /* Break the bonds. */
761 inf
->vfork_parent
->vfork_child
= NULL
;
764 inf
->vfork_parent
= NULL
;
766 gdb_assert (current_program_space
== inf
->pspace
);
768 if (non_stop
&& resume_parent
!= -1)
770 /* If the user wanted the parent to be running, let it go
772 struct cleanup
*old_chain
= make_cleanup_restore_current_thread ();
775 fprintf_unfiltered (gdb_stdlog
,
776 "infrun: resuming vfork parent process %d\n",
779 iterate_over_threads (proceed_after_vfork_done
, &resume_parent
);
781 do_cleanups (old_chain
);
786 /* Enum strings for "set|show follow-exec-mode". */
788 static const char follow_exec_mode_new
[] = "new";
789 static const char follow_exec_mode_same
[] = "same";
790 static const char *const follow_exec_mode_names
[] =
792 follow_exec_mode_new
,
793 follow_exec_mode_same
,
797 static const char *follow_exec_mode_string
= follow_exec_mode_same
;
799 show_follow_exec_mode_string (struct ui_file
*file
, int from_tty
,
800 struct cmd_list_element
*c
, const char *value
)
802 fprintf_filtered (file
, _("Follow exec mode is \"%s\".\n"), value
);
805 /* EXECD_PATHNAME is assumed to be non-NULL. */
808 follow_exec (ptid_t pid
, char *execd_pathname
)
810 struct thread_info
*th
= inferior_thread ();
811 struct inferior
*inf
= current_inferior ();
813 /* This is an exec event that we actually wish to pay attention to.
814 Refresh our symbol table to the newly exec'd program, remove any
817 If there are breakpoints, they aren't really inserted now,
818 since the exec() transformed our inferior into a fresh set
821 We want to preserve symbolic breakpoints on the list, since
822 we have hopes that they can be reset after the new a.out's
823 symbol table is read.
825 However, any "raw" breakpoints must be removed from the list
826 (e.g., the solib bp's), since their address is probably invalid
829 And, we DON'T want to call delete_breakpoints() here, since
830 that may write the bp's "shadow contents" (the instruction
831 value that was overwritten witha TRAP instruction). Since
832 we now have a new a.out, those shadow contents aren't valid. */
834 mark_breakpoints_out ();
836 update_breakpoints_after_exec ();
838 /* If there was one, it's gone now. We cannot truly step-to-next
839 statement through an exec(). */
840 th
->control
.step_resume_breakpoint
= NULL
;
841 th
->control
.exception_resume_breakpoint
= NULL
;
842 th
->control
.step_range_start
= 0;
843 th
->control
.step_range_end
= 0;
845 /* The target reports the exec event to the main thread, even if
846 some other thread does the exec, and even if the main thread was
847 already stopped --- if debugging in non-stop mode, it's possible
848 the user had the main thread held stopped in the previous image
849 --- release it now. This is the same behavior as step-over-exec
850 with scheduler-locking on in all-stop mode. */
851 th
->stop_requested
= 0;
853 /* What is this a.out's name? */
854 printf_unfiltered (_("%s is executing new program: %s\n"),
855 target_pid_to_str (inferior_ptid
),
858 /* We've followed the inferior through an exec. Therefore, the
859 inferior has essentially been killed & reborn. */
861 gdb_flush (gdb_stdout
);
863 breakpoint_init_inferior (inf_execd
);
865 if (gdb_sysroot
&& *gdb_sysroot
)
867 char *name
= alloca (strlen (gdb_sysroot
)
868 + strlen (execd_pathname
)
871 strcpy (name
, gdb_sysroot
);
872 strcat (name
, execd_pathname
);
873 execd_pathname
= name
;
876 /* Reset the shared library package. This ensures that we get a
877 shlib event when the child reaches "_start", at which point the
878 dld will have had a chance to initialize the child. */
879 /* Also, loading a symbol file below may trigger symbol lookups, and
880 we don't want those to be satisfied by the libraries of the
881 previous incarnation of this process. */
882 no_shared_libraries (NULL
, 0);
884 if (follow_exec_mode_string
== follow_exec_mode_new
)
886 struct program_space
*pspace
;
888 /* The user wants to keep the old inferior and program spaces
889 around. Create a new fresh one, and switch to it. */
891 inf
= add_inferior (current_inferior ()->pid
);
892 pspace
= add_program_space (maybe_new_address_space ());
893 inf
->pspace
= pspace
;
894 inf
->aspace
= pspace
->aspace
;
896 exit_inferior_num_silent (current_inferior ()->num
);
898 set_current_inferior (inf
);
899 set_current_program_space (pspace
);
903 /* The old description may no longer be fit for the new image.
904 E.g, a 64-bit process exec'ed a 32-bit process. Clear the
905 old description; we'll read a new one below. No need to do
906 this on "follow-exec-mode new", as the old inferior stays
907 around (its description is later cleared/refetched on
909 target_clear_description ();
912 gdb_assert (current_program_space
== inf
->pspace
);
914 /* That a.out is now the one to use. */
915 exec_file_attach (execd_pathname
, 0);
917 /* SYMFILE_DEFER_BP_RESET is used as the proper displacement for PIE
918 (Position Independent Executable) main symbol file will get applied by
919 solib_create_inferior_hook below. breakpoint_re_set would fail to insert
920 the breakpoints with the zero displacement. */
922 symbol_file_add (execd_pathname
,
924 | SYMFILE_MAINLINE
| SYMFILE_DEFER_BP_RESET
),
927 if ((inf
->symfile_flags
& SYMFILE_NO_READ
) == 0)
928 set_initial_language ();
930 /* If the target can specify a description, read it. Must do this
931 after flipping to the new executable (because the target supplied
932 description must be compatible with the executable's
933 architecture, and the old executable may e.g., be 32-bit, while
934 the new one 64-bit), and before anything involving memory or
936 target_find_description ();
938 solib_create_inferior_hook (0);
940 jit_inferior_created_hook ();
942 breakpoint_re_set ();
944 /* Reinsert all breakpoints. (Those which were symbolic have
945 been reset to the proper address in the new a.out, thanks
946 to symbol_file_command...). */
947 insert_breakpoints ();
949 /* The next resume of this inferior should bring it to the shlib
950 startup breakpoints. (If the user had also set bp's on
951 "main" from the old (parent) process, then they'll auto-
952 matically get reset there in the new process.). */
955 /* Non-zero if we just simulating a single-step. This is needed
956 because we cannot remove the breakpoints in the inferior process
957 until after the `wait' in `wait_for_inferior'. */
958 static int singlestep_breakpoints_inserted_p
= 0;
960 /* The thread we inserted single-step breakpoints for. */
961 static ptid_t singlestep_ptid
;
963 /* PC when we started this single-step. */
964 static CORE_ADDR singlestep_pc
;
966 /* Info about an instruction that is being stepped over. Invalid if
969 struct step_over_info
971 /* The instruction's address space. */
972 struct address_space
*aspace
;
974 /* The instruction's address. */
978 /* The step-over info of the location that is being stepped over.
980 Note that with async/breakpoint always-inserted mode, a user might
981 set a new breakpoint/watchpoint/etc. exactly while a breakpoint is
982 being stepped over. As setting a new breakpoint inserts all
983 breakpoints, we need to make sure the breakpoint being stepped over
984 isn't inserted then. We do that by only clearing the step-over
985 info when the step-over is actually finished (or aborted).
987 Presently GDB can only step over one breakpoint at any given time.
988 Given threads that can't run code in the same address space as the
989 breakpoint's can't really miss the breakpoint, GDB could be taught
990 to step-over at most one breakpoint per address space (so this info
991 could move to the address space object if/when GDB is extended).
992 The set of breakpoints being stepped over will normally be much
993 smaller than the set of all breakpoints, so a flag in the
994 breakpoint location structure would be wasteful. A separate list
995 also saves complexity and run-time, as otherwise we'd have to go
996 through all breakpoint locations clearing their flag whenever we
997 start a new sequence. Similar considerations weigh against storing
998 this info in the thread object. Plus, not all step overs actually
999 have breakpoint locations -- e.g., stepping past a single-step
1000 breakpoint, or stepping to complete a non-continuable
1002 static struct step_over_info step_over_info
;
1004 /* Record the address of the breakpoint/instruction we're currently
1008 set_step_over_info (struct address_space
*aspace
, CORE_ADDR address
)
1010 step_over_info
.aspace
= aspace
;
1011 step_over_info
.address
= address
;
1014 /* Called when we're not longer stepping over a breakpoint / an
1015 instruction, so all breakpoints are free to be (re)inserted. */
1018 clear_step_over_info (void)
1020 step_over_info
.aspace
= NULL
;
1021 step_over_info
.address
= 0;
1024 /* See inferior.h. */
1027 stepping_past_instruction_at (struct address_space
*aspace
,
1030 return (step_over_info
.aspace
!= NULL
1031 && breakpoint_address_match (aspace
, address
,
1032 step_over_info
.aspace
,
1033 step_over_info
.address
));
1037 /* Displaced stepping. */
1039 /* In non-stop debugging mode, we must take special care to manage
1040 breakpoints properly; in particular, the traditional strategy for
1041 stepping a thread past a breakpoint it has hit is unsuitable.
1042 'Displaced stepping' is a tactic for stepping one thread past a
1043 breakpoint it has hit while ensuring that other threads running
1044 concurrently will hit the breakpoint as they should.
1046 The traditional way to step a thread T off a breakpoint in a
1047 multi-threaded program in all-stop mode is as follows:
1049 a0) Initially, all threads are stopped, and breakpoints are not
1051 a1) We single-step T, leaving breakpoints uninserted.
1052 a2) We insert breakpoints, and resume all threads.
1054 In non-stop debugging, however, this strategy is unsuitable: we
1055 don't want to have to stop all threads in the system in order to
1056 continue or step T past a breakpoint. Instead, we use displaced
1059 n0) Initially, T is stopped, other threads are running, and
1060 breakpoints are inserted.
1061 n1) We copy the instruction "under" the breakpoint to a separate
1062 location, outside the main code stream, making any adjustments
1063 to the instruction, register, and memory state as directed by
1065 n2) We single-step T over the instruction at its new location.
1066 n3) We adjust the resulting register and memory state as directed
1067 by T's architecture. This includes resetting T's PC to point
1068 back into the main instruction stream.
1071 This approach depends on the following gdbarch methods:
1073 - gdbarch_max_insn_length and gdbarch_displaced_step_location
1074 indicate where to copy the instruction, and how much space must
1075 be reserved there. We use these in step n1.
1077 - gdbarch_displaced_step_copy_insn copies a instruction to a new
1078 address, and makes any necessary adjustments to the instruction,
1079 register contents, and memory. We use this in step n1.
1081 - gdbarch_displaced_step_fixup adjusts registers and memory after
1082 we have successfuly single-stepped the instruction, to yield the
1083 same effect the instruction would have had if we had executed it
1084 at its original address. We use this in step n3.
1086 - gdbarch_displaced_step_free_closure provides cleanup.
1088 The gdbarch_displaced_step_copy_insn and
1089 gdbarch_displaced_step_fixup functions must be written so that
1090 copying an instruction with gdbarch_displaced_step_copy_insn,
1091 single-stepping across the copied instruction, and then applying
1092 gdbarch_displaced_insn_fixup should have the same effects on the
1093 thread's memory and registers as stepping the instruction in place
1094 would have. Exactly which responsibilities fall to the copy and
1095 which fall to the fixup is up to the author of those functions.
1097 See the comments in gdbarch.sh for details.
1099 Note that displaced stepping and software single-step cannot
1100 currently be used in combination, although with some care I think
1101 they could be made to. Software single-step works by placing
1102 breakpoints on all possible subsequent instructions; if the
1103 displaced instruction is a PC-relative jump, those breakpoints
1104 could fall in very strange places --- on pages that aren't
1105 executable, or at addresses that are not proper instruction
1106 boundaries. (We do generally let other threads run while we wait
1107 to hit the software single-step breakpoint, and they might
1108 encounter such a corrupted instruction.) One way to work around
1109 this would be to have gdbarch_displaced_step_copy_insn fully
1110 simulate the effect of PC-relative instructions (and return NULL)
1111 on architectures that use software single-stepping.
1113 In non-stop mode, we can have independent and simultaneous step
1114 requests, so more than one thread may need to simultaneously step
1115 over a breakpoint. The current implementation assumes there is
1116 only one scratch space per process. In this case, we have to
1117 serialize access to the scratch space. If thread A wants to step
1118 over a breakpoint, but we are currently waiting for some other
1119 thread to complete a displaced step, we leave thread A stopped and
1120 place it in the displaced_step_request_queue. Whenever a displaced
1121 step finishes, we pick the next thread in the queue and start a new
1122 displaced step operation on it. See displaced_step_prepare and
1123 displaced_step_fixup for details. */
1125 struct displaced_step_request
1128 struct displaced_step_request
*next
;
1131 /* Per-inferior displaced stepping state. */
1132 struct displaced_step_inferior_state
1134 /* Pointer to next in linked list. */
1135 struct displaced_step_inferior_state
*next
;
1137 /* The process this displaced step state refers to. */
1140 /* A queue of pending displaced stepping requests. One entry per
1141 thread that needs to do a displaced step. */
1142 struct displaced_step_request
*step_request_queue
;
1144 /* If this is not null_ptid, this is the thread carrying out a
1145 displaced single-step in process PID. This thread's state will
1146 require fixing up once it has completed its step. */
1149 /* The architecture the thread had when we stepped it. */
1150 struct gdbarch
*step_gdbarch
;
1152 /* The closure provided gdbarch_displaced_step_copy_insn, to be used
1153 for post-step cleanup. */
1154 struct displaced_step_closure
*step_closure
;
1156 /* The address of the original instruction, and the copy we
1158 CORE_ADDR step_original
, step_copy
;
1160 /* Saved contents of copy area. */
1161 gdb_byte
*step_saved_copy
;
1164 /* The list of states of processes involved in displaced stepping
1166 static struct displaced_step_inferior_state
*displaced_step_inferior_states
;
1168 /* Get the displaced stepping state of process PID. */
1170 static struct displaced_step_inferior_state
*
1171 get_displaced_stepping_state (int pid
)
1173 struct displaced_step_inferior_state
*state
;
1175 for (state
= displaced_step_inferior_states
;
1177 state
= state
->next
)
1178 if (state
->pid
== pid
)
1184 /* Add a new displaced stepping state for process PID to the displaced
1185 stepping state list, or return a pointer to an already existing
1186 entry, if it already exists. Never returns NULL. */
1188 static struct displaced_step_inferior_state
*
1189 add_displaced_stepping_state (int pid
)
1191 struct displaced_step_inferior_state
*state
;
1193 for (state
= displaced_step_inferior_states
;
1195 state
= state
->next
)
1196 if (state
->pid
== pid
)
1199 state
= xcalloc (1, sizeof (*state
));
1201 state
->next
= displaced_step_inferior_states
;
1202 displaced_step_inferior_states
= state
;
1207 /* If inferior is in displaced stepping, and ADDR equals to starting address
1208 of copy area, return corresponding displaced_step_closure. Otherwise,
1211 struct displaced_step_closure
*
1212 get_displaced_step_closure_by_addr (CORE_ADDR addr
)
1214 struct displaced_step_inferior_state
*displaced
1215 = get_displaced_stepping_state (ptid_get_pid (inferior_ptid
));
1217 /* If checking the mode of displaced instruction in copy area. */
1218 if (displaced
&& !ptid_equal (displaced
->step_ptid
, null_ptid
)
1219 && (displaced
->step_copy
== addr
))
1220 return displaced
->step_closure
;
1225 /* Remove the displaced stepping state of process PID. */
1228 remove_displaced_stepping_state (int pid
)
1230 struct displaced_step_inferior_state
*it
, **prev_next_p
;
1232 gdb_assert (pid
!= 0);
1234 it
= displaced_step_inferior_states
;
1235 prev_next_p
= &displaced_step_inferior_states
;
1240 *prev_next_p
= it
->next
;
1245 prev_next_p
= &it
->next
;
1251 infrun_inferior_exit (struct inferior
*inf
)
1253 remove_displaced_stepping_state (inf
->pid
);
1256 /* If ON, and the architecture supports it, GDB will use displaced
1257 stepping to step over breakpoints. If OFF, or if the architecture
1258 doesn't support it, GDB will instead use the traditional
1259 hold-and-step approach. If AUTO (which is the default), GDB will
1260 decide which technique to use to step over breakpoints depending on
1261 which of all-stop or non-stop mode is active --- displaced stepping
1262 in non-stop mode; hold-and-step in all-stop mode. */
1264 static enum auto_boolean can_use_displaced_stepping
= AUTO_BOOLEAN_AUTO
;
1267 show_can_use_displaced_stepping (struct ui_file
*file
, int from_tty
,
1268 struct cmd_list_element
*c
,
1271 if (can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
)
1272 fprintf_filtered (file
,
1273 _("Debugger's willingness to use displaced stepping "
1274 "to step over breakpoints is %s (currently %s).\n"),
1275 value
, non_stop
? "on" : "off");
1277 fprintf_filtered (file
,
1278 _("Debugger's willingness to use displaced stepping "
1279 "to step over breakpoints is %s.\n"), value
);
1282 /* Return non-zero if displaced stepping can/should be used to step
1283 over breakpoints. */
1286 use_displaced_stepping (struct gdbarch
*gdbarch
)
1288 return (((can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
&& non_stop
)
1289 || can_use_displaced_stepping
== AUTO_BOOLEAN_TRUE
)
1290 && gdbarch_displaced_step_copy_insn_p (gdbarch
)
1291 && find_record_target () == NULL
);
1294 /* Clean out any stray displaced stepping state. */
1296 displaced_step_clear (struct displaced_step_inferior_state
*displaced
)
1298 /* Indicate that there is no cleanup pending. */
1299 displaced
->step_ptid
= null_ptid
;
1301 if (displaced
->step_closure
)
1303 gdbarch_displaced_step_free_closure (displaced
->step_gdbarch
,
1304 displaced
->step_closure
);
1305 displaced
->step_closure
= NULL
;
1310 displaced_step_clear_cleanup (void *arg
)
1312 struct displaced_step_inferior_state
*state
= arg
;
1314 displaced_step_clear (state
);
1317 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */
1319 displaced_step_dump_bytes (struct ui_file
*file
,
1320 const gdb_byte
*buf
,
1325 for (i
= 0; i
< len
; i
++)
1326 fprintf_unfiltered (file
, "%02x ", buf
[i
]);
1327 fputs_unfiltered ("\n", file
);
1330 /* Prepare to single-step, using displaced stepping.
1332 Note that we cannot use displaced stepping when we have a signal to
1333 deliver. If we have a signal to deliver and an instruction to step
1334 over, then after the step, there will be no indication from the
1335 target whether the thread entered a signal handler or ignored the
1336 signal and stepped over the instruction successfully --- both cases
1337 result in a simple SIGTRAP. In the first case we mustn't do a
1338 fixup, and in the second case we must --- but we can't tell which.
1339 Comments in the code for 'random signals' in handle_inferior_event
1340 explain how we handle this case instead.
1342 Returns 1 if preparing was successful -- this thread is going to be
1343 stepped now; or 0 if displaced stepping this thread got queued. */
1345 displaced_step_prepare (ptid_t ptid
)
1347 struct cleanup
*old_cleanups
, *ignore_cleanups
;
1348 struct thread_info
*tp
= find_thread_ptid (ptid
);
1349 struct regcache
*regcache
= get_thread_regcache (ptid
);
1350 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1351 CORE_ADDR original
, copy
;
1353 struct displaced_step_closure
*closure
;
1354 struct displaced_step_inferior_state
*displaced
;
1357 /* We should never reach this function if the architecture does not
1358 support displaced stepping. */
1359 gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch
));
1361 /* Disable range stepping while executing in the scratch pad. We
1362 want a single-step even if executing the displaced instruction in
1363 the scratch buffer lands within the stepping range (e.g., a
1365 tp
->control
.may_range_step
= 0;
1367 /* We have to displaced step one thread at a time, as we only have
1368 access to a single scratch space per inferior. */
1370 displaced
= add_displaced_stepping_state (ptid_get_pid (ptid
));
1372 if (!ptid_equal (displaced
->step_ptid
, null_ptid
))
1374 /* Already waiting for a displaced step to finish. Defer this
1375 request and place in queue. */
1376 struct displaced_step_request
*req
, *new_req
;
1378 if (debug_displaced
)
1379 fprintf_unfiltered (gdb_stdlog
,
1380 "displaced: defering step of %s\n",
1381 target_pid_to_str (ptid
));
1383 new_req
= xmalloc (sizeof (*new_req
));
1384 new_req
->ptid
= ptid
;
1385 new_req
->next
= NULL
;
1387 if (displaced
->step_request_queue
)
1389 for (req
= displaced
->step_request_queue
;
1393 req
->next
= new_req
;
1396 displaced
->step_request_queue
= new_req
;
1402 if (debug_displaced
)
1403 fprintf_unfiltered (gdb_stdlog
,
1404 "displaced: stepping %s now\n",
1405 target_pid_to_str (ptid
));
1408 displaced_step_clear (displaced
);
1410 old_cleanups
= save_inferior_ptid ();
1411 inferior_ptid
= ptid
;
1413 original
= regcache_read_pc (regcache
);
1415 copy
= gdbarch_displaced_step_location (gdbarch
);
1416 len
= gdbarch_max_insn_length (gdbarch
);
1418 /* Save the original contents of the copy area. */
1419 displaced
->step_saved_copy
= xmalloc (len
);
1420 ignore_cleanups
= make_cleanup (free_current_contents
,
1421 &displaced
->step_saved_copy
);
1422 status
= target_read_memory (copy
, displaced
->step_saved_copy
, len
);
1424 throw_error (MEMORY_ERROR
,
1425 _("Error accessing memory address %s (%s) for "
1426 "displaced-stepping scratch space."),
1427 paddress (gdbarch
, copy
), safe_strerror (status
));
1428 if (debug_displaced
)
1430 fprintf_unfiltered (gdb_stdlog
, "displaced: saved %s: ",
1431 paddress (gdbarch
, copy
));
1432 displaced_step_dump_bytes (gdb_stdlog
,
1433 displaced
->step_saved_copy
,
1437 closure
= gdbarch_displaced_step_copy_insn (gdbarch
,
1438 original
, copy
, regcache
);
1440 /* We don't support the fully-simulated case at present. */
1441 gdb_assert (closure
);
1443 /* Save the information we need to fix things up if the step
1445 displaced
->step_ptid
= ptid
;
1446 displaced
->step_gdbarch
= gdbarch
;
1447 displaced
->step_closure
= closure
;
1448 displaced
->step_original
= original
;
1449 displaced
->step_copy
= copy
;
1451 make_cleanup (displaced_step_clear_cleanup
, displaced
);
1453 /* Resume execution at the copy. */
1454 regcache_write_pc (regcache
, copy
);
1456 discard_cleanups (ignore_cleanups
);
1458 do_cleanups (old_cleanups
);
1460 if (debug_displaced
)
1461 fprintf_unfiltered (gdb_stdlog
, "displaced: displaced pc to %s\n",
1462 paddress (gdbarch
, copy
));
1468 write_memory_ptid (ptid_t ptid
, CORE_ADDR memaddr
,
1469 const gdb_byte
*myaddr
, int len
)
1471 struct cleanup
*ptid_cleanup
= save_inferior_ptid ();
1473 inferior_ptid
= ptid
;
1474 write_memory (memaddr
, myaddr
, len
);
1475 do_cleanups (ptid_cleanup
);
1478 /* Restore the contents of the copy area for thread PTID. */
1481 displaced_step_restore (struct displaced_step_inferior_state
*displaced
,
1484 ULONGEST len
= gdbarch_max_insn_length (displaced
->step_gdbarch
);
1486 write_memory_ptid (ptid
, displaced
->step_copy
,
1487 displaced
->step_saved_copy
, len
);
1488 if (debug_displaced
)
1489 fprintf_unfiltered (gdb_stdlog
, "displaced: restored %s %s\n",
1490 target_pid_to_str (ptid
),
1491 paddress (displaced
->step_gdbarch
,
1492 displaced
->step_copy
));
1496 displaced_step_fixup (ptid_t event_ptid
, enum gdb_signal signal
)
1498 struct cleanup
*old_cleanups
;
1499 struct displaced_step_inferior_state
*displaced
1500 = get_displaced_stepping_state (ptid_get_pid (event_ptid
));
1502 /* Was any thread of this process doing a displaced step? */
1503 if (displaced
== NULL
)
1506 /* Was this event for the pid we displaced? */
1507 if (ptid_equal (displaced
->step_ptid
, null_ptid
)
1508 || ! ptid_equal (displaced
->step_ptid
, event_ptid
))
1511 old_cleanups
= make_cleanup (displaced_step_clear_cleanup
, displaced
);
1513 displaced_step_restore (displaced
, displaced
->step_ptid
);
1515 /* Did the instruction complete successfully? */
1516 if (signal
== GDB_SIGNAL_TRAP
)
1518 /* Fix up the resulting state. */
1519 gdbarch_displaced_step_fixup (displaced
->step_gdbarch
,
1520 displaced
->step_closure
,
1521 displaced
->step_original
,
1522 displaced
->step_copy
,
1523 get_thread_regcache (displaced
->step_ptid
));
1527 /* Since the instruction didn't complete, all we can do is
1529 struct regcache
*regcache
= get_thread_regcache (event_ptid
);
1530 CORE_ADDR pc
= regcache_read_pc (regcache
);
1532 pc
= displaced
->step_original
+ (pc
- displaced
->step_copy
);
1533 regcache_write_pc (regcache
, pc
);
1536 do_cleanups (old_cleanups
);
1538 displaced
->step_ptid
= null_ptid
;
1540 /* Are there any pending displaced stepping requests? If so, run
1541 one now. Leave the state object around, since we're likely to
1542 need it again soon. */
1543 while (displaced
->step_request_queue
)
1545 struct displaced_step_request
*head
;
1547 struct regcache
*regcache
;
1548 struct gdbarch
*gdbarch
;
1549 CORE_ADDR actual_pc
;
1550 struct address_space
*aspace
;
1552 head
= displaced
->step_request_queue
;
1554 displaced
->step_request_queue
= head
->next
;
1557 context_switch (ptid
);
1559 regcache
= get_thread_regcache (ptid
);
1560 actual_pc
= regcache_read_pc (regcache
);
1561 aspace
= get_regcache_aspace (regcache
);
1563 if (breakpoint_here_p (aspace
, actual_pc
))
1565 if (debug_displaced
)
1566 fprintf_unfiltered (gdb_stdlog
,
1567 "displaced: stepping queued %s now\n",
1568 target_pid_to_str (ptid
));
1570 displaced_step_prepare (ptid
);
1572 gdbarch
= get_regcache_arch (regcache
);
1574 if (debug_displaced
)
1576 CORE_ADDR actual_pc
= regcache_read_pc (regcache
);
1579 fprintf_unfiltered (gdb_stdlog
, "displaced: run %s: ",
1580 paddress (gdbarch
, actual_pc
));
1581 read_memory (actual_pc
, buf
, sizeof (buf
));
1582 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
1585 if (gdbarch_displaced_step_hw_singlestep (gdbarch
,
1586 displaced
->step_closure
))
1587 target_resume (ptid
, 1, GDB_SIGNAL_0
);
1589 target_resume (ptid
, 0, GDB_SIGNAL_0
);
1591 /* Done, we're stepping a thread. */
1597 struct thread_info
*tp
= inferior_thread ();
1599 /* The breakpoint we were sitting under has since been
1601 tp
->control
.trap_expected
= 0;
1603 /* Go back to what we were trying to do. */
1604 step
= currently_stepping (tp
);
1606 if (debug_displaced
)
1607 fprintf_unfiltered (gdb_stdlog
,
1608 "displaced: breakpoint is gone: %s, step(%d)\n",
1609 target_pid_to_str (tp
->ptid
), step
);
1611 target_resume (ptid
, step
, GDB_SIGNAL_0
);
1612 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
1614 /* This request was discarded. See if there's any other
1615 thread waiting for its turn. */
1620 /* Update global variables holding ptids to hold NEW_PTID if they were
1621 holding OLD_PTID. */
1623 infrun_thread_ptid_changed (ptid_t old_ptid
, ptid_t new_ptid
)
1625 struct displaced_step_request
*it
;
1626 struct displaced_step_inferior_state
*displaced
;
1628 if (ptid_equal (inferior_ptid
, old_ptid
))
1629 inferior_ptid
= new_ptid
;
1631 if (ptid_equal (singlestep_ptid
, old_ptid
))
1632 singlestep_ptid
= new_ptid
;
1634 for (displaced
= displaced_step_inferior_states
;
1636 displaced
= displaced
->next
)
1638 if (ptid_equal (displaced
->step_ptid
, old_ptid
))
1639 displaced
->step_ptid
= new_ptid
;
1641 for (it
= displaced
->step_request_queue
; it
; it
= it
->next
)
1642 if (ptid_equal (it
->ptid
, old_ptid
))
1643 it
->ptid
= new_ptid
;
1650 /* Things to clean up if we QUIT out of resume (). */
1652 resume_cleanups (void *ignore
)
1657 static const char schedlock_off
[] = "off";
1658 static const char schedlock_on
[] = "on";
1659 static const char schedlock_step
[] = "step";
1660 static const char *const scheduler_enums
[] = {
1666 static const char *scheduler_mode
= schedlock_off
;
1668 show_scheduler_mode (struct ui_file
*file
, int from_tty
,
1669 struct cmd_list_element
*c
, const char *value
)
1671 fprintf_filtered (file
,
1672 _("Mode for locking scheduler "
1673 "during execution is \"%s\".\n"),
1678 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
1680 if (!target_can_lock_scheduler
)
1682 scheduler_mode
= schedlock_off
;
1683 error (_("Target '%s' cannot support this command."), target_shortname
);
1687 /* True if execution commands resume all threads of all processes by
1688 default; otherwise, resume only threads of the current inferior
1690 int sched_multi
= 0;
1692 /* Try to setup for software single stepping over the specified location.
1693 Return 1 if target_resume() should use hardware single step.
1695 GDBARCH the current gdbarch.
1696 PC the location to step over. */
1699 maybe_software_singlestep (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
1703 if (execution_direction
== EXEC_FORWARD
1704 && gdbarch_software_single_step_p (gdbarch
)
1705 && gdbarch_software_single_step (gdbarch
, get_current_frame ()))
1708 /* Do not pull these breakpoints until after a `wait' in
1709 `wait_for_inferior'. */
1710 singlestep_breakpoints_inserted_p
= 1;
1711 singlestep_ptid
= inferior_ptid
;
1717 /* Return a ptid representing the set of threads that we will proceed,
1718 in the perspective of the user/frontend. We may actually resume
1719 fewer threads at first, e.g., if a thread is stopped at a
1720 breakpoint that needs stepping-off, but that should not be visible
1721 to the user/frontend, and neither should the frontend/user be
1722 allowed to proceed any of the threads that happen to be stopped for
1723 internal run control handling, if a previous command wanted them
1727 user_visible_resume_ptid (int step
)
1729 /* By default, resume all threads of all processes. */
1730 ptid_t resume_ptid
= RESUME_ALL
;
1732 /* Maybe resume only all threads of the current process. */
1733 if (!sched_multi
&& target_supports_multi_process ())
1735 resume_ptid
= pid_to_ptid (ptid_get_pid (inferior_ptid
));
1738 /* Maybe resume a single thread after all. */
1741 /* With non-stop mode on, threads are always handled
1743 resume_ptid
= inferior_ptid
;
1745 else if ((scheduler_mode
== schedlock_on
)
1746 || (scheduler_mode
== schedlock_step
1747 && (step
|| singlestep_breakpoints_inserted_p
)))
1749 /* User-settable 'scheduler' mode requires solo thread resume. */
1750 resume_ptid
= inferior_ptid
;
1756 /* Resume the inferior, but allow a QUIT. This is useful if the user
1757 wants to interrupt some lengthy single-stepping operation
1758 (for child processes, the SIGINT goes to the inferior, and so
1759 we get a SIGINT random_signal, but for remote debugging and perhaps
1760 other targets, that's not true).
1762 STEP nonzero if we should step (zero to continue instead).
1763 SIG is the signal to give the inferior (zero for none). */
1765 resume (int step
, enum gdb_signal sig
)
1767 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
1768 struct regcache
*regcache
= get_current_regcache ();
1769 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1770 struct thread_info
*tp
= inferior_thread ();
1771 CORE_ADDR pc
= regcache_read_pc (regcache
);
1772 struct address_space
*aspace
= get_regcache_aspace (regcache
);
1778 if (current_inferior ()->waiting_for_vfork_done
)
1780 /* Don't try to single-step a vfork parent that is waiting for
1781 the child to get out of the shared memory region (by exec'ing
1782 or exiting). This is particularly important on software
1783 single-step archs, as the child process would trip on the
1784 software single step breakpoint inserted for the parent
1785 process. Since the parent will not actually execute any
1786 instruction until the child is out of the shared region (such
1787 are vfork's semantics), it is safe to simply continue it.
1788 Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for
1789 the parent, and tell it to `keep_going', which automatically
1790 re-sets it stepping. */
1792 fprintf_unfiltered (gdb_stdlog
,
1793 "infrun: resume : clear step\n");
1798 fprintf_unfiltered (gdb_stdlog
,
1799 "infrun: resume (step=%d, signal=%s), "
1800 "trap_expected=%d, current thread [%s] at %s\n",
1801 step
, gdb_signal_to_symbol_string (sig
),
1802 tp
->control
.trap_expected
,
1803 target_pid_to_str (inferior_ptid
),
1804 paddress (gdbarch
, pc
));
1806 /* Normally, by the time we reach `resume', the breakpoints are either
1807 removed or inserted, as appropriate. The exception is if we're sitting
1808 at a permanent breakpoint; we need to step over it, but permanent
1809 breakpoints can't be removed. So we have to test for it here. */
1810 if (breakpoint_here_p (aspace
, pc
) == permanent_breakpoint_here
)
1812 if (gdbarch_skip_permanent_breakpoint_p (gdbarch
))
1813 gdbarch_skip_permanent_breakpoint (gdbarch
, regcache
);
1816 The program is stopped at a permanent breakpoint, but GDB does not know\n\
1817 how to step past a permanent breakpoint on this architecture. Try using\n\
1818 a command like `return' or `jump' to continue execution."));
1821 /* If we have a breakpoint to step over, make sure to do a single
1822 step only. Same if we have software watchpoints. */
1823 if (tp
->control
.trap_expected
|| bpstat_should_step ())
1824 tp
->control
.may_range_step
= 0;
1826 /* If enabled, step over breakpoints by executing a copy of the
1827 instruction at a different address.
1829 We can't use displaced stepping when we have a signal to deliver;
1830 the comments for displaced_step_prepare explain why. The
1831 comments in the handle_inferior event for dealing with 'random
1832 signals' explain what we do instead.
1834 We can't use displaced stepping when we are waiting for vfork_done
1835 event, displaced stepping breaks the vfork child similarly as single
1836 step software breakpoint. */
1837 if (use_displaced_stepping (gdbarch
)
1838 && (tp
->control
.trap_expected
1839 || (hw_step
&& gdbarch_software_single_step_p (gdbarch
)))
1840 && sig
== GDB_SIGNAL_0
1841 && !current_inferior ()->waiting_for_vfork_done
)
1843 struct displaced_step_inferior_state
*displaced
;
1845 if (!displaced_step_prepare (inferior_ptid
))
1847 /* Got placed in displaced stepping queue. Will be resumed
1848 later when all the currently queued displaced stepping
1849 requests finish. The thread is not executing at this
1850 point, and the call to set_executing will be made later.
1851 But we need to call set_running here, since from the
1852 user/frontend's point of view, threads were set running.
1853 Unless we're calling an inferior function, as in that
1854 case we pretend the inferior doesn't run at all. */
1855 if (!tp
->control
.in_infcall
)
1856 set_running (user_visible_resume_ptid (step
), 1);
1857 discard_cleanups (old_cleanups
);
1861 /* Update pc to reflect the new address from which we will execute
1862 instructions due to displaced stepping. */
1863 pc
= regcache_read_pc (get_thread_regcache (inferior_ptid
));
1865 displaced
= get_displaced_stepping_state (ptid_get_pid (inferior_ptid
));
1866 hw_step
= gdbarch_displaced_step_hw_singlestep (gdbarch
,
1867 displaced
->step_closure
);
1870 /* Do we need to do it the hard way, w/temp breakpoints? */
1872 step
= maybe_software_singlestep (gdbarch
, pc
);
1874 /* Currently, our software single-step implementation leads to different
1875 results than hardware single-stepping in one situation: when stepping
1876 into delivering a signal which has an associated signal handler,
1877 hardware single-step will stop at the first instruction of the handler,
1878 while software single-step will simply skip execution of the handler.
1880 For now, this difference in behavior is accepted since there is no
1881 easy way to actually implement single-stepping into a signal handler
1882 without kernel support.
1884 However, there is one scenario where this difference leads to follow-on
1885 problems: if we're stepping off a breakpoint by removing all breakpoints
1886 and then single-stepping. In this case, the software single-step
1887 behavior means that even if there is a *breakpoint* in the signal
1888 handler, GDB still would not stop.
1890 Fortunately, we can at least fix this particular issue. We detect
1891 here the case where we are about to deliver a signal while software
1892 single-stepping with breakpoints removed. In this situation, we
1893 revert the decisions to remove all breakpoints and insert single-
1894 step breakpoints, and instead we install a step-resume breakpoint
1895 at the current address, deliver the signal without stepping, and
1896 once we arrive back at the step-resume breakpoint, actually step
1897 over the breakpoint we originally wanted to step over. */
1898 if (singlestep_breakpoints_inserted_p
1899 && tp
->control
.trap_expected
&& sig
!= GDB_SIGNAL_0
)
1901 /* If we have nested signals or a pending signal is delivered
1902 immediately after a handler returns, might might already have
1903 a step-resume breakpoint set on the earlier handler. We cannot
1904 set another step-resume breakpoint; just continue on until the
1905 original breakpoint is hit. */
1906 if (tp
->control
.step_resume_breakpoint
== NULL
)
1908 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
1909 tp
->step_after_step_resume_breakpoint
= 1;
1912 remove_single_step_breakpoints ();
1913 singlestep_breakpoints_inserted_p
= 0;
1915 clear_step_over_info ();
1916 tp
->control
.trap_expected
= 0;
1918 insert_breakpoints ();
1921 /* If STEP is set, it's a request to use hardware stepping
1922 facilities. But in that case, we should never
1923 use singlestep breakpoint. */
1924 gdb_assert (!(singlestep_breakpoints_inserted_p
&& step
));
1926 /* Decide the set of threads to ask the target to resume. Start
1927 by assuming everything will be resumed, than narrow the set
1928 by applying increasingly restricting conditions. */
1929 resume_ptid
= user_visible_resume_ptid (step
);
1931 /* Even if RESUME_PTID is a wildcard, and we end up resuming less
1932 (e.g., we might need to step over a breakpoint), from the
1933 user/frontend's point of view, all threads in RESUME_PTID are now
1934 running. Unless we're calling an inferior function, as in that
1935 case pretend we inferior doesn't run at all. */
1936 if (!tp
->control
.in_infcall
)
1937 set_running (resume_ptid
, 1);
1939 /* Maybe resume a single thread after all. */
1940 if ((step
|| singlestep_breakpoints_inserted_p
)
1941 && tp
->control
.trap_expected
)
1943 /* We're allowing a thread to run past a breakpoint it has
1944 hit, by single-stepping the thread with the breakpoint
1945 removed. In which case, we need to single-step only this
1946 thread, and keep others stopped, as they can miss this
1947 breakpoint if allowed to run. */
1948 resume_ptid
= inferior_ptid
;
1951 if (gdbarch_cannot_step_breakpoint (gdbarch
))
1953 /* Most targets can step a breakpoint instruction, thus
1954 executing it normally. But if this one cannot, just
1955 continue and we will hit it anyway. */
1956 if (step
&& breakpoint_inserted_here_p (aspace
, pc
))
1961 && use_displaced_stepping (gdbarch
)
1962 && tp
->control
.trap_expected
)
1964 struct regcache
*resume_regcache
= get_thread_regcache (resume_ptid
);
1965 struct gdbarch
*resume_gdbarch
= get_regcache_arch (resume_regcache
);
1966 CORE_ADDR actual_pc
= regcache_read_pc (resume_regcache
);
1969 fprintf_unfiltered (gdb_stdlog
, "displaced: run %s: ",
1970 paddress (resume_gdbarch
, actual_pc
));
1971 read_memory (actual_pc
, buf
, sizeof (buf
));
1972 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
1975 if (tp
->control
.may_range_step
)
1977 /* If we're resuming a thread with the PC out of the step
1978 range, then we're doing some nested/finer run control
1979 operation, like stepping the thread out of the dynamic
1980 linker or the displaced stepping scratch pad. We
1981 shouldn't have allowed a range step then. */
1982 gdb_assert (pc_in_thread_step_range (pc
, tp
));
1985 /* Install inferior's terminal modes. */
1986 target_terminal_inferior ();
1988 /* Avoid confusing the next resume, if the next stop/resume
1989 happens to apply to another thread. */
1990 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
1992 /* Advise target which signals may be handled silently. If we have
1993 removed breakpoints because we are stepping over one (which can
1994 happen only if we are not using displaced stepping), we need to
1995 receive all signals to avoid accidentally skipping a breakpoint
1996 during execution of a signal handler. */
1997 if ((step
|| singlestep_breakpoints_inserted_p
)
1998 && tp
->control
.trap_expected
1999 && !use_displaced_stepping (gdbarch
))
2000 target_pass_signals (0, NULL
);
2002 target_pass_signals ((int) GDB_SIGNAL_LAST
, signal_pass
);
2004 target_resume (resume_ptid
, step
, sig
);
2006 discard_cleanups (old_cleanups
);
2011 /* Clear out all variables saying what to do when inferior is continued.
2012 First do this, then set the ones you want, then call `proceed'. */
2015 clear_proceed_status_thread (struct thread_info
*tp
)
2018 fprintf_unfiltered (gdb_stdlog
,
2019 "infrun: clear_proceed_status_thread (%s)\n",
2020 target_pid_to_str (tp
->ptid
));
2022 tp
->control
.trap_expected
= 0;
2023 tp
->control
.step_range_start
= 0;
2024 tp
->control
.step_range_end
= 0;
2025 tp
->control
.may_range_step
= 0;
2026 tp
->control
.step_frame_id
= null_frame_id
;
2027 tp
->control
.step_stack_frame_id
= null_frame_id
;
2028 tp
->control
.step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
2029 tp
->stop_requested
= 0;
2031 tp
->control
.stop_step
= 0;
2033 tp
->control
.proceed_to_finish
= 0;
2035 tp
->control
.command_interp
= NULL
;
2037 /* Discard any remaining commands or status from previous stop. */
2038 bpstat_clear (&tp
->control
.stop_bpstat
);
2042 clear_proceed_status_callback (struct thread_info
*tp
, void *data
)
2044 if (is_exited (tp
->ptid
))
2047 clear_proceed_status_thread (tp
);
2052 clear_proceed_status (void)
2056 /* In all-stop mode, delete the per-thread status of all
2057 threads, even if inferior_ptid is null_ptid, there may be
2058 threads on the list. E.g., we may be launching a new
2059 process, while selecting the executable. */
2060 iterate_over_threads (clear_proceed_status_callback
, NULL
);
2063 if (!ptid_equal (inferior_ptid
, null_ptid
))
2065 struct inferior
*inferior
;
2069 /* If in non-stop mode, only delete the per-thread status of
2070 the current thread. */
2071 clear_proceed_status_thread (inferior_thread ());
2074 inferior
= current_inferior ();
2075 inferior
->control
.stop_soon
= NO_STOP_QUIETLY
;
2078 stop_after_trap
= 0;
2080 clear_step_over_info ();
2082 observer_notify_about_to_proceed ();
2086 regcache_xfree (stop_registers
);
2087 stop_registers
= NULL
;
2091 /* Returns true if TP is still stopped at a breakpoint that needs
2092 stepping-over in order to make progress. If the breakpoint is gone
2093 meanwhile, we can skip the whole step-over dance. */
2096 thread_still_needs_step_over (struct thread_info
*tp
)
2098 if (tp
->stepping_over_breakpoint
)
2100 struct regcache
*regcache
= get_thread_regcache (tp
->ptid
);
2102 if (breakpoint_here_p (get_regcache_aspace (regcache
),
2103 regcache_read_pc (regcache
)))
2106 tp
->stepping_over_breakpoint
= 0;
2112 /* Returns true if scheduler locking applies. STEP indicates whether
2113 we're about to do a step/next-like command to a thread. */
2116 schedlock_applies (int step
)
2118 return (scheduler_mode
== schedlock_on
2119 || (scheduler_mode
== schedlock_step
2123 /* Look a thread other than EXCEPT that has previously reported a
2124 breakpoint event, and thus needs a step-over in order to make
2125 progress. Returns NULL is none is found. STEP indicates whether
2126 we're about to step the current thread, in order to decide whether
2127 "set scheduler-locking step" applies. */
2129 static struct thread_info
*
2130 find_thread_needs_step_over (int step
, struct thread_info
*except
)
2132 struct thread_info
*tp
, *current
;
2134 /* With non-stop mode on, threads are always handled individually. */
2135 gdb_assert (! non_stop
);
2137 current
= inferior_thread ();
2139 /* If scheduler locking applies, we can avoid iterating over all
2141 if (schedlock_applies (step
))
2143 if (except
!= current
2144 && thread_still_needs_step_over (current
))
2152 /* Ignore the EXCEPT thread. */
2155 /* Ignore threads of processes we're not resuming. */
2157 && ptid_get_pid (tp
->ptid
) != ptid_get_pid (inferior_ptid
))
2160 if (thread_still_needs_step_over (tp
))
2167 /* Basic routine for continuing the program in various fashions.
2169 ADDR is the address to resume at, or -1 for resume where stopped.
2170 SIGGNAL is the signal to give it, or 0 for none,
2171 or -1 for act according to how it stopped.
2172 STEP is nonzero if should trap after one instruction.
2173 -1 means return after that and print nothing.
2174 You should probably set various step_... variables
2175 before calling here, if you are stepping.
2177 You should call clear_proceed_status before calling proceed. */
2180 proceed (CORE_ADDR addr
, enum gdb_signal siggnal
, int step
)
2182 struct regcache
*regcache
;
2183 struct gdbarch
*gdbarch
;
2184 struct thread_info
*tp
;
2186 struct address_space
*aspace
;
2188 /* If we're stopped at a fork/vfork, follow the branch set by the
2189 "set follow-fork-mode" command; otherwise, we'll just proceed
2190 resuming the current thread. */
2191 if (!follow_fork ())
2193 /* The target for some reason decided not to resume. */
2195 if (target_can_async_p ())
2196 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
2200 /* We'll update this if & when we switch to a new thread. */
2201 previous_inferior_ptid
= inferior_ptid
;
2203 regcache
= get_current_regcache ();
2204 gdbarch
= get_regcache_arch (regcache
);
2205 aspace
= get_regcache_aspace (regcache
);
2206 pc
= regcache_read_pc (regcache
);
2207 tp
= inferior_thread ();
2210 step_start_function
= find_pc_function (pc
);
2212 stop_after_trap
= 1;
2214 /* Fill in with reasonable starting values. */
2215 init_thread_stepping_state (tp
);
2217 if (addr
== (CORE_ADDR
) -1)
2219 if (pc
== stop_pc
&& breakpoint_here_p (aspace
, pc
)
2220 && execution_direction
!= EXEC_REVERSE
)
2221 /* There is a breakpoint at the address we will resume at,
2222 step one instruction before inserting breakpoints so that
2223 we do not stop right away (and report a second hit at this
2226 Note, we don't do this in reverse, because we won't
2227 actually be executing the breakpoint insn anyway.
2228 We'll be (un-)executing the previous instruction. */
2229 tp
->stepping_over_breakpoint
= 1;
2230 else if (gdbarch_single_step_through_delay_p (gdbarch
)
2231 && gdbarch_single_step_through_delay (gdbarch
,
2232 get_current_frame ()))
2233 /* We stepped onto an instruction that needs to be stepped
2234 again before re-inserting the breakpoint, do so. */
2235 tp
->stepping_over_breakpoint
= 1;
2239 regcache_write_pc (regcache
, addr
);
2242 /* Record the interpreter that issued the execution command that
2243 caused this thread to resume. If the top level interpreter is
2244 MI/async, and the execution command was a CLI command
2245 (next/step/etc.), we'll want to print stop event output to the MI
2246 console channel (the stepped-to line, etc.), as if the user
2247 entered the execution command on a real GDB console. */
2248 inferior_thread ()->control
.command_interp
= command_interp ();
2251 fprintf_unfiltered (gdb_stdlog
,
2252 "infrun: proceed (addr=%s, signal=%s, step=%d)\n",
2253 paddress (gdbarch
, addr
),
2254 gdb_signal_to_symbol_string (siggnal
), step
);
2257 /* In non-stop, each thread is handled individually. The context
2258 must already be set to the right thread here. */
2262 struct thread_info
*step_over
;
2264 /* In a multi-threaded task we may select another thread and
2265 then continue or step.
2267 But if the old thread was stopped at a breakpoint, it will
2268 immediately cause another breakpoint stop without any
2269 execution (i.e. it will report a breakpoint hit incorrectly).
2270 So we must step over it first.
2272 Look for a thread other than the current (TP) that reported a
2273 breakpoint hit and hasn't been resumed yet since. */
2274 step_over
= find_thread_needs_step_over (step
, tp
);
2275 if (step_over
!= NULL
)
2278 fprintf_unfiltered (gdb_stdlog
,
2279 "infrun: need to step-over [%s] first\n",
2280 target_pid_to_str (step_over
->ptid
));
2282 /* Store the prev_pc for the stepping thread too, needed by
2283 switch_back_to_stepping thread. */
2284 tp
->prev_pc
= regcache_read_pc (get_current_regcache ());
2285 switch_to_thread (step_over
->ptid
);
2290 /* If we need to step over a breakpoint, and we're not using
2291 displaced stepping to do so, insert all breakpoints (watchpoints,
2292 etc.) but the one we're stepping over, step one instruction, and
2293 then re-insert the breakpoint when that step is finished. */
2294 if (tp
->stepping_over_breakpoint
&& !use_displaced_stepping (gdbarch
))
2296 struct regcache
*regcache
= get_current_regcache ();
2298 set_step_over_info (get_regcache_aspace (regcache
),
2299 regcache_read_pc (regcache
));
2302 clear_step_over_info ();
2304 insert_breakpoints ();
2306 tp
->control
.trap_expected
= tp
->stepping_over_breakpoint
;
2310 /* Pass the last stop signal to the thread we're resuming,
2311 irrespective of whether the current thread is the thread that
2312 got the last event or not. This was historically GDB's
2313 behaviour before keeping a stop_signal per thread. */
2315 struct thread_info
*last_thread
;
2317 struct target_waitstatus last_status
;
2319 get_last_target_status (&last_ptid
, &last_status
);
2320 if (!ptid_equal (inferior_ptid
, last_ptid
)
2321 && !ptid_equal (last_ptid
, null_ptid
)
2322 && !ptid_equal (last_ptid
, minus_one_ptid
))
2324 last_thread
= find_thread_ptid (last_ptid
);
2327 tp
->suspend
.stop_signal
= last_thread
->suspend
.stop_signal
;
2328 last_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2333 if (siggnal
!= GDB_SIGNAL_DEFAULT
)
2334 tp
->suspend
.stop_signal
= siggnal
;
2335 /* If this signal should not be seen by program,
2336 give it zero. Used for debugging signals. */
2337 else if (!signal_program
[tp
->suspend
.stop_signal
])
2338 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2340 annotate_starting ();
2342 /* Make sure that output from GDB appears before output from the
2344 gdb_flush (gdb_stdout
);
2346 /* Refresh prev_pc value just prior to resuming. This used to be
2347 done in stop_stepping, however, setting prev_pc there did not handle
2348 scenarios such as inferior function calls or returning from
2349 a function via the return command. In those cases, the prev_pc
2350 value was not set properly for subsequent commands. The prev_pc value
2351 is used to initialize the starting line number in the ecs. With an
2352 invalid value, the gdb next command ends up stopping at the position
2353 represented by the next line table entry past our start position.
2354 On platforms that generate one line table entry per line, this
2355 is not a problem. However, on the ia64, the compiler generates
2356 extraneous line table entries that do not increase the line number.
2357 When we issue the gdb next command on the ia64 after an inferior call
2358 or a return command, we often end up a few instructions forward, still
2359 within the original line we started.
2361 An attempt was made to refresh the prev_pc at the same time the
2362 execution_control_state is initialized (for instance, just before
2363 waiting for an inferior event). But this approach did not work
2364 because of platforms that use ptrace, where the pc register cannot
2365 be read unless the inferior is stopped. At that point, we are not
2366 guaranteed the inferior is stopped and so the regcache_read_pc() call
2367 can fail. Setting the prev_pc value here ensures the value is updated
2368 correctly when the inferior is stopped. */
2369 tp
->prev_pc
= regcache_read_pc (get_current_regcache ());
2371 /* Reset to normal state. */
2372 init_infwait_state ();
2374 /* Resume inferior. */
2375 resume (tp
->control
.trap_expected
|| step
|| bpstat_should_step (),
2376 tp
->suspend
.stop_signal
);
2378 /* Wait for it to stop (if not standalone)
2379 and in any case decode why it stopped, and act accordingly. */
2380 /* Do this only if we are not using the event loop, or if the target
2381 does not support asynchronous execution. */
2382 if (!target_can_async_p ())
2384 wait_for_inferior ();
2390 /* Start remote-debugging of a machine over a serial link. */
2393 start_remote (int from_tty
)
2395 struct inferior
*inferior
;
2397 inferior
= current_inferior ();
2398 inferior
->control
.stop_soon
= STOP_QUIETLY_REMOTE
;
2400 /* Always go on waiting for the target, regardless of the mode. */
2401 /* FIXME: cagney/1999-09-23: At present it isn't possible to
2402 indicate to wait_for_inferior that a target should timeout if
2403 nothing is returned (instead of just blocking). Because of this,
2404 targets expecting an immediate response need to, internally, set
2405 things up so that the target_wait() is forced to eventually
2407 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
2408 differentiate to its caller what the state of the target is after
2409 the initial open has been performed. Here we're assuming that
2410 the target has stopped. It should be possible to eventually have
2411 target_open() return to the caller an indication that the target
2412 is currently running and GDB state should be set to the same as
2413 for an async run. */
2414 wait_for_inferior ();
2416 /* Now that the inferior has stopped, do any bookkeeping like
2417 loading shared libraries. We want to do this before normal_stop,
2418 so that the displayed frame is up to date. */
2419 post_create_inferior (¤t_target
, from_tty
);
2424 /* Initialize static vars when a new inferior begins. */
2427 init_wait_for_inferior (void)
2429 /* These are meaningless until the first time through wait_for_inferior. */
2431 breakpoint_init_inferior (inf_starting
);
2433 clear_proceed_status ();
2435 target_last_wait_ptid
= minus_one_ptid
;
2437 previous_inferior_ptid
= inferior_ptid
;
2438 init_infwait_state ();
2440 /* Discard any skipped inlined frames. */
2441 clear_inline_frame_state (minus_one_ptid
);
2443 singlestep_ptid
= null_ptid
;
2448 /* This enum encodes possible reasons for doing a target_wait, so that
2449 wfi can call target_wait in one place. (Ultimately the call will be
2450 moved out of the infinite loop entirely.) */
2454 infwait_normal_state
,
2455 infwait_step_watch_state
,
2456 infwait_nonstep_watch_state
2459 /* The PTID we'll do a target_wait on.*/
2462 /* Current inferior wait state. */
2463 static enum infwait_states infwait_state
;
2465 /* Data to be passed around while handling an event. This data is
2466 discarded between events. */
2467 struct execution_control_state
2470 /* The thread that got the event, if this was a thread event; NULL
2472 struct thread_info
*event_thread
;
2474 struct target_waitstatus ws
;
2475 int stop_func_filled_in
;
2476 CORE_ADDR stop_func_start
;
2477 CORE_ADDR stop_func_end
;
2478 const char *stop_func_name
;
2481 /* We were in infwait_step_watch_state or
2482 infwait_nonstep_watch_state state, and the thread reported an
2484 int stepped_after_stopped_by_watchpoint
;
2486 /* True if the event thread hit the single-step breakpoint of
2487 another thread. Thus the event doesn't cause a stop, the thread
2488 needs to be single-stepped past the single-step breakpoint before
2489 we can switch back to the original stepping thread. */
2490 int hit_singlestep_breakpoint
;
2493 static void handle_inferior_event (struct execution_control_state
*ecs
);
2495 static void handle_step_into_function (struct gdbarch
*gdbarch
,
2496 struct execution_control_state
*ecs
);
2497 static void handle_step_into_function_backward (struct gdbarch
*gdbarch
,
2498 struct execution_control_state
*ecs
);
2499 static void handle_signal_stop (struct execution_control_state
*ecs
);
2500 static void check_exception_resume (struct execution_control_state
*,
2501 struct frame_info
*);
2503 static void stop_stepping (struct execution_control_state
*ecs
);
2504 static void prepare_to_wait (struct execution_control_state
*ecs
);
2505 static void keep_going (struct execution_control_state
*ecs
);
2506 static void process_event_stop_test (struct execution_control_state
*ecs
);
2507 static int switch_back_to_stepped_thread (struct execution_control_state
*ecs
);
2509 /* Callback for iterate over threads. If the thread is stopped, but
2510 the user/frontend doesn't know about that yet, go through
2511 normal_stop, as if the thread had just stopped now. ARG points at
2512 a ptid. If PTID is MINUS_ONE_PTID, applies to all threads. If
2513 ptid_is_pid(PTID) is true, applies to all threads of the process
2514 pointed at by PTID. Otherwise, apply only to the thread pointed by
2518 infrun_thread_stop_requested_callback (struct thread_info
*info
, void *arg
)
2520 ptid_t ptid
= * (ptid_t
*) arg
;
2522 if ((ptid_equal (info
->ptid
, ptid
)
2523 || ptid_equal (minus_one_ptid
, ptid
)
2524 || (ptid_is_pid (ptid
)
2525 && ptid_get_pid (ptid
) == ptid_get_pid (info
->ptid
)))
2526 && is_running (info
->ptid
)
2527 && !is_executing (info
->ptid
))
2529 struct cleanup
*old_chain
;
2530 struct execution_control_state ecss
;
2531 struct execution_control_state
*ecs
= &ecss
;
2533 memset (ecs
, 0, sizeof (*ecs
));
2535 old_chain
= make_cleanup_restore_current_thread ();
2537 overlay_cache_invalid
= 1;
2538 /* Flush target cache before starting to handle each event.
2539 Target was running and cache could be stale. This is just a
2540 heuristic. Running threads may modify target memory, but we
2541 don't get any event. */
2542 target_dcache_invalidate ();
2544 /* Go through handle_inferior_event/normal_stop, so we always
2545 have consistent output as if the stop event had been
2547 ecs
->ptid
= info
->ptid
;
2548 ecs
->event_thread
= find_thread_ptid (info
->ptid
);
2549 ecs
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
2550 ecs
->ws
.value
.sig
= GDB_SIGNAL_0
;
2552 handle_inferior_event (ecs
);
2554 if (!ecs
->wait_some_more
)
2556 struct thread_info
*tp
;
2560 /* Finish off the continuations. */
2561 tp
= inferior_thread ();
2562 do_all_intermediate_continuations_thread (tp
, 1);
2563 do_all_continuations_thread (tp
, 1);
2566 do_cleanups (old_chain
);
2572 /* This function is attached as a "thread_stop_requested" observer.
2573 Cleanup local state that assumed the PTID was to be resumed, and
2574 report the stop to the frontend. */
2577 infrun_thread_stop_requested (ptid_t ptid
)
2579 struct displaced_step_inferior_state
*displaced
;
2581 /* PTID was requested to stop. Remove it from the displaced
2582 stepping queue, so we don't try to resume it automatically. */
2584 for (displaced
= displaced_step_inferior_states
;
2586 displaced
= displaced
->next
)
2588 struct displaced_step_request
*it
, **prev_next_p
;
2590 it
= displaced
->step_request_queue
;
2591 prev_next_p
= &displaced
->step_request_queue
;
2594 if (ptid_match (it
->ptid
, ptid
))
2596 *prev_next_p
= it
->next
;
2602 prev_next_p
= &it
->next
;
2609 iterate_over_threads (infrun_thread_stop_requested_callback
, &ptid
);
2613 infrun_thread_thread_exit (struct thread_info
*tp
, int silent
)
2615 if (ptid_equal (target_last_wait_ptid
, tp
->ptid
))
2616 nullify_last_target_wait_ptid ();
2619 /* Callback for iterate_over_threads. */
2622 delete_step_resume_breakpoint_callback (struct thread_info
*info
, void *data
)
2624 if (is_exited (info
->ptid
))
2627 delete_step_resume_breakpoint (info
);
2628 delete_exception_resume_breakpoint (info
);
2632 /* In all-stop, delete the step resume breakpoint of any thread that
2633 had one. In non-stop, delete the step resume breakpoint of the
2634 thread that just stopped. */
2637 delete_step_thread_step_resume_breakpoint (void)
2639 if (!target_has_execution
2640 || ptid_equal (inferior_ptid
, null_ptid
))
2641 /* If the inferior has exited, we have already deleted the step
2642 resume breakpoints out of GDB's lists. */
2647 /* If in non-stop mode, only delete the step-resume or
2648 longjmp-resume breakpoint of the thread that just stopped
2650 struct thread_info
*tp
= inferior_thread ();
2652 delete_step_resume_breakpoint (tp
);
2653 delete_exception_resume_breakpoint (tp
);
2656 /* In all-stop mode, delete all step-resume and longjmp-resume
2657 breakpoints of any thread that had them. */
2658 iterate_over_threads (delete_step_resume_breakpoint_callback
, NULL
);
2661 /* A cleanup wrapper. */
2664 delete_step_thread_step_resume_breakpoint_cleanup (void *arg
)
2666 delete_step_thread_step_resume_breakpoint ();
2669 /* Pretty print the results of target_wait, for debugging purposes. */
2672 print_target_wait_results (ptid_t waiton_ptid
, ptid_t result_ptid
,
2673 const struct target_waitstatus
*ws
)
2675 char *status_string
= target_waitstatus_to_string (ws
);
2676 struct ui_file
*tmp_stream
= mem_fileopen ();
2679 /* The text is split over several lines because it was getting too long.
2680 Call fprintf_unfiltered (gdb_stdlog) once so that the text is still
2681 output as a unit; we want only one timestamp printed if debug_timestamp
2684 fprintf_unfiltered (tmp_stream
,
2685 "infrun: target_wait (%d", ptid_get_pid (waiton_ptid
));
2686 if (ptid_get_pid (waiton_ptid
) != -1)
2687 fprintf_unfiltered (tmp_stream
,
2688 " [%s]", target_pid_to_str (waiton_ptid
));
2689 fprintf_unfiltered (tmp_stream
, ", status) =\n");
2690 fprintf_unfiltered (tmp_stream
,
2691 "infrun: %d [%s],\n",
2692 ptid_get_pid (result_ptid
),
2693 target_pid_to_str (result_ptid
));
2694 fprintf_unfiltered (tmp_stream
,
2698 text
= ui_file_xstrdup (tmp_stream
, NULL
);
2700 /* This uses %s in part to handle %'s in the text, but also to avoid
2701 a gcc error: the format attribute requires a string literal. */
2702 fprintf_unfiltered (gdb_stdlog
, "%s", text
);
2704 xfree (status_string
);
2706 ui_file_delete (tmp_stream
);
2709 /* Prepare and stabilize the inferior for detaching it. E.g.,
2710 detaching while a thread is displaced stepping is a recipe for
2711 crashing it, as nothing would readjust the PC out of the scratch
2715 prepare_for_detach (void)
2717 struct inferior
*inf
= current_inferior ();
2718 ptid_t pid_ptid
= pid_to_ptid (inf
->pid
);
2719 struct cleanup
*old_chain_1
;
2720 struct displaced_step_inferior_state
*displaced
;
2722 displaced
= get_displaced_stepping_state (inf
->pid
);
2724 /* Is any thread of this process displaced stepping? If not,
2725 there's nothing else to do. */
2726 if (displaced
== NULL
|| ptid_equal (displaced
->step_ptid
, null_ptid
))
2730 fprintf_unfiltered (gdb_stdlog
,
2731 "displaced-stepping in-process while detaching");
2733 old_chain_1
= make_cleanup_restore_integer (&inf
->detaching
);
2736 while (!ptid_equal (displaced
->step_ptid
, null_ptid
))
2738 struct cleanup
*old_chain_2
;
2739 struct execution_control_state ecss
;
2740 struct execution_control_state
*ecs
;
2743 memset (ecs
, 0, sizeof (*ecs
));
2745 overlay_cache_invalid
= 1;
2746 /* Flush target cache before starting to handle each event.
2747 Target was running and cache could be stale. This is just a
2748 heuristic. Running threads may modify target memory, but we
2749 don't get any event. */
2750 target_dcache_invalidate ();
2752 if (deprecated_target_wait_hook
)
2753 ecs
->ptid
= deprecated_target_wait_hook (pid_ptid
, &ecs
->ws
, 0);
2755 ecs
->ptid
= target_wait (pid_ptid
, &ecs
->ws
, 0);
2758 print_target_wait_results (pid_ptid
, ecs
->ptid
, &ecs
->ws
);
2760 /* If an error happens while handling the event, propagate GDB's
2761 knowledge of the executing state to the frontend/user running
2763 old_chain_2
= make_cleanup (finish_thread_state_cleanup
,
2766 /* Now figure out what to do with the result of the result. */
2767 handle_inferior_event (ecs
);
2769 /* No error, don't finish the state yet. */
2770 discard_cleanups (old_chain_2
);
2772 /* Breakpoints and watchpoints are not installed on the target
2773 at this point, and signals are passed directly to the
2774 inferior, so this must mean the process is gone. */
2775 if (!ecs
->wait_some_more
)
2777 discard_cleanups (old_chain_1
);
2778 error (_("Program exited while detaching"));
2782 discard_cleanups (old_chain_1
);
2785 /* Wait for control to return from inferior to debugger.
2787 If inferior gets a signal, we may decide to start it up again
2788 instead of returning. That is why there is a loop in this function.
2789 When this function actually returns it means the inferior
2790 should be left stopped and GDB should read more commands. */
2793 wait_for_inferior (void)
2795 struct cleanup
*old_cleanups
;
2799 (gdb_stdlog
, "infrun: wait_for_inferior ()\n");
2802 make_cleanup (delete_step_thread_step_resume_breakpoint_cleanup
, NULL
);
2806 struct execution_control_state ecss
;
2807 struct execution_control_state
*ecs
= &ecss
;
2808 struct cleanup
*old_chain
;
2810 memset (ecs
, 0, sizeof (*ecs
));
2812 overlay_cache_invalid
= 1;
2814 /* Flush target cache before starting to handle each event.
2815 Target was running and cache could be stale. This is just a
2816 heuristic. Running threads may modify target memory, but we
2817 don't get any event. */
2818 target_dcache_invalidate ();
2820 if (deprecated_target_wait_hook
)
2821 ecs
->ptid
= deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
, 0);
2823 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
, 0);
2826 print_target_wait_results (waiton_ptid
, ecs
->ptid
, &ecs
->ws
);
2828 /* If an error happens while handling the event, propagate GDB's
2829 knowledge of the executing state to the frontend/user running
2831 old_chain
= make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
2833 /* Now figure out what to do with the result of the result. */
2834 handle_inferior_event (ecs
);
2836 /* No error, don't finish the state yet. */
2837 discard_cleanups (old_chain
);
2839 if (!ecs
->wait_some_more
)
2843 do_cleanups (old_cleanups
);
2846 /* Asynchronous version of wait_for_inferior. It is called by the
2847 event loop whenever a change of state is detected on the file
2848 descriptor corresponding to the target. It can be called more than
2849 once to complete a single execution command. In such cases we need
2850 to keep the state in a global variable ECSS. If it is the last time
2851 that this function is called for a single execution command, then
2852 report to the user that the inferior has stopped, and do the
2853 necessary cleanups. */
2856 fetch_inferior_event (void *client_data
)
2858 struct execution_control_state ecss
;
2859 struct execution_control_state
*ecs
= &ecss
;
2860 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
2861 struct cleanup
*ts_old_chain
;
2862 int was_sync
= sync_execution
;
2865 memset (ecs
, 0, sizeof (*ecs
));
2867 /* We're handling a live event, so make sure we're doing live
2868 debugging. If we're looking at traceframes while the target is
2869 running, we're going to need to get back to that mode after
2870 handling the event. */
2873 make_cleanup_restore_current_traceframe ();
2874 set_current_traceframe (-1);
2878 /* In non-stop mode, the user/frontend should not notice a thread
2879 switch due to internal events. Make sure we reverse to the
2880 user selected thread and frame after handling the event and
2881 running any breakpoint commands. */
2882 make_cleanup_restore_current_thread ();
2884 overlay_cache_invalid
= 1;
2885 /* Flush target cache before starting to handle each event. Target
2886 was running and cache could be stale. This is just a heuristic.
2887 Running threads may modify target memory, but we don't get any
2889 target_dcache_invalidate ();
2891 make_cleanup_restore_integer (&execution_direction
);
2892 execution_direction
= target_execution_direction ();
2894 if (deprecated_target_wait_hook
)
2896 deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
, TARGET_WNOHANG
);
2898 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
, TARGET_WNOHANG
);
2901 print_target_wait_results (waiton_ptid
, ecs
->ptid
, &ecs
->ws
);
2903 /* If an error happens while handling the event, propagate GDB's
2904 knowledge of the executing state to the frontend/user running
2907 ts_old_chain
= make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
2909 ts_old_chain
= make_cleanup (finish_thread_state_cleanup
, &ecs
->ptid
);
2911 /* Get executed before make_cleanup_restore_current_thread above to apply
2912 still for the thread which has thrown the exception. */
2913 make_bpstat_clear_actions_cleanup ();
2915 /* Now figure out what to do with the result of the result. */
2916 handle_inferior_event (ecs
);
2918 if (!ecs
->wait_some_more
)
2920 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ecs
->ptid
));
2922 delete_step_thread_step_resume_breakpoint ();
2924 /* We may not find an inferior if this was a process exit. */
2925 if (inf
== NULL
|| inf
->control
.stop_soon
== NO_STOP_QUIETLY
)
2928 if (target_has_execution
2929 && ecs
->ws
.kind
!= TARGET_WAITKIND_NO_RESUMED
2930 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
2931 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
2932 && ecs
->event_thread
->step_multi
2933 && ecs
->event_thread
->control
.stop_step
)
2934 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
2937 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
2942 /* No error, don't finish the thread states yet. */
2943 discard_cleanups (ts_old_chain
);
2945 /* Revert thread and frame. */
2946 do_cleanups (old_chain
);
2948 /* If the inferior was in sync execution mode, and now isn't,
2949 restore the prompt (a synchronous execution command has finished,
2950 and we're ready for input). */
2951 if (interpreter_async
&& was_sync
&& !sync_execution
)
2952 observer_notify_sync_execution_done ();
2956 && exec_done_display_p
2957 && (ptid_equal (inferior_ptid
, null_ptid
)
2958 || !is_running (inferior_ptid
)))
2959 printf_unfiltered (_("completed.\n"));
2962 /* Record the frame and location we're currently stepping through. */
2964 set_step_info (struct frame_info
*frame
, struct symtab_and_line sal
)
2966 struct thread_info
*tp
= inferior_thread ();
2968 tp
->control
.step_frame_id
= get_frame_id (frame
);
2969 tp
->control
.step_stack_frame_id
= get_stack_frame_id (frame
);
2971 tp
->current_symtab
= sal
.symtab
;
2972 tp
->current_line
= sal
.line
;
2975 /* Clear context switchable stepping state. */
2978 init_thread_stepping_state (struct thread_info
*tss
)
2980 tss
->stepping_over_breakpoint
= 0;
2981 tss
->step_after_step_resume_breakpoint
= 0;
2984 /* Set the cached copy of the last ptid/waitstatus. */
2987 set_last_target_status (ptid_t ptid
, struct target_waitstatus status
)
2989 target_last_wait_ptid
= ptid
;
2990 target_last_waitstatus
= status
;
2993 /* Return the cached copy of the last pid/waitstatus returned by
2994 target_wait()/deprecated_target_wait_hook(). The data is actually
2995 cached by handle_inferior_event(), which gets called immediately
2996 after target_wait()/deprecated_target_wait_hook(). */
2999 get_last_target_status (ptid_t
*ptidp
, struct target_waitstatus
*status
)
3001 *ptidp
= target_last_wait_ptid
;
3002 *status
= target_last_waitstatus
;
3006 nullify_last_target_wait_ptid (void)
3008 target_last_wait_ptid
= minus_one_ptid
;
3011 /* Switch thread contexts. */
3014 context_switch (ptid_t ptid
)
3016 if (debug_infrun
&& !ptid_equal (ptid
, inferior_ptid
))
3018 fprintf_unfiltered (gdb_stdlog
, "infrun: Switching context from %s ",
3019 target_pid_to_str (inferior_ptid
));
3020 fprintf_unfiltered (gdb_stdlog
, "to %s\n",
3021 target_pid_to_str (ptid
));
3024 switch_to_thread (ptid
);
3028 adjust_pc_after_break (struct execution_control_state
*ecs
)
3030 struct regcache
*regcache
;
3031 struct gdbarch
*gdbarch
;
3032 struct address_space
*aspace
;
3033 CORE_ADDR breakpoint_pc
, decr_pc
;
3035 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
3036 we aren't, just return.
3038 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
3039 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
3040 implemented by software breakpoints should be handled through the normal
3043 NOTE drow/2004-01-31: On some targets, breakpoints may generate
3044 different signals (SIGILL or SIGEMT for instance), but it is less
3045 clear where the PC is pointing afterwards. It may not match
3046 gdbarch_decr_pc_after_break. I don't know any specific target that
3047 generates these signals at breakpoints (the code has been in GDB since at
3048 least 1992) so I can not guess how to handle them here.
3050 In earlier versions of GDB, a target with
3051 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
3052 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
3053 target with both of these set in GDB history, and it seems unlikely to be
3054 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
3056 if (ecs
->ws
.kind
!= TARGET_WAITKIND_STOPPED
)
3059 if (ecs
->ws
.value
.sig
!= GDB_SIGNAL_TRAP
)
3062 /* In reverse execution, when a breakpoint is hit, the instruction
3063 under it has already been de-executed. The reported PC always
3064 points at the breakpoint address, so adjusting it further would
3065 be wrong. E.g., consider this case on a decr_pc_after_break == 1
3068 B1 0x08000000 : INSN1
3069 B2 0x08000001 : INSN2
3071 PC -> 0x08000003 : INSN4
3073 Say you're stopped at 0x08000003 as above. Reverse continuing
3074 from that point should hit B2 as below. Reading the PC when the
3075 SIGTRAP is reported should read 0x08000001 and INSN2 should have
3076 been de-executed already.
3078 B1 0x08000000 : INSN1
3079 B2 PC -> 0x08000001 : INSN2
3083 We can't apply the same logic as for forward execution, because
3084 we would wrongly adjust the PC to 0x08000000, since there's a
3085 breakpoint at PC - 1. We'd then report a hit on B1, although
3086 INSN1 hadn't been de-executed yet. Doing nothing is the correct
3088 if (execution_direction
== EXEC_REVERSE
)
3091 /* If this target does not decrement the PC after breakpoints, then
3092 we have nothing to do. */
3093 regcache
= get_thread_regcache (ecs
->ptid
);
3094 gdbarch
= get_regcache_arch (regcache
);
3096 decr_pc
= target_decr_pc_after_break (gdbarch
);
3100 aspace
= get_regcache_aspace (regcache
);
3102 /* Find the location where (if we've hit a breakpoint) the
3103 breakpoint would be. */
3104 breakpoint_pc
= regcache_read_pc (regcache
) - decr_pc
;
3106 /* Check whether there actually is a software breakpoint inserted at
3109 If in non-stop mode, a race condition is possible where we've
3110 removed a breakpoint, but stop events for that breakpoint were
3111 already queued and arrive later. To suppress those spurious
3112 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
3113 and retire them after a number of stop events are reported. */
3114 if (software_breakpoint_inserted_here_p (aspace
, breakpoint_pc
)
3115 || (non_stop
&& moribund_breakpoint_here_p (aspace
, breakpoint_pc
)))
3117 struct cleanup
*old_cleanups
= make_cleanup (null_cleanup
, NULL
);
3119 if (record_full_is_used ())
3120 record_full_gdb_operation_disable_set ();
3122 /* When using hardware single-step, a SIGTRAP is reported for both
3123 a completed single-step and a software breakpoint. Need to
3124 differentiate between the two, as the latter needs adjusting
3125 but the former does not.
3127 The SIGTRAP can be due to a completed hardware single-step only if
3128 - we didn't insert software single-step breakpoints
3129 - the thread to be examined is still the current thread
3130 - this thread is currently being stepped
3132 If any of these events did not occur, we must have stopped due
3133 to hitting a software breakpoint, and have to back up to the
3136 As a special case, we could have hardware single-stepped a
3137 software breakpoint. In this case (prev_pc == breakpoint_pc),
3138 we also need to back up to the breakpoint address. */
3140 if (singlestep_breakpoints_inserted_p
3141 || !ptid_equal (ecs
->ptid
, inferior_ptid
)
3142 || !currently_stepping (ecs
->event_thread
)
3143 || ecs
->event_thread
->prev_pc
== breakpoint_pc
)
3144 regcache_write_pc (regcache
, breakpoint_pc
);
3146 do_cleanups (old_cleanups
);
3151 init_infwait_state (void)
3153 waiton_ptid
= pid_to_ptid (-1);
3154 infwait_state
= infwait_normal_state
;
3158 stepped_in_from (struct frame_info
*frame
, struct frame_id step_frame_id
)
3160 for (frame
= get_prev_frame (frame
);
3162 frame
= get_prev_frame (frame
))
3164 if (frame_id_eq (get_frame_id (frame
), step_frame_id
))
3166 if (get_frame_type (frame
) != INLINE_FRAME
)
3173 /* Auxiliary function that handles syscall entry/return events.
3174 It returns 1 if the inferior should keep going (and GDB
3175 should ignore the event), or 0 if the event deserves to be
3179 handle_syscall_event (struct execution_control_state
*ecs
)
3181 struct regcache
*regcache
;
3184 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3185 context_switch (ecs
->ptid
);
3187 regcache
= get_thread_regcache (ecs
->ptid
);
3188 syscall_number
= ecs
->ws
.value
.syscall_number
;
3189 stop_pc
= regcache_read_pc (regcache
);
3191 if (catch_syscall_enabled () > 0
3192 && catching_syscall_number (syscall_number
) > 0)
3195 fprintf_unfiltered (gdb_stdlog
, "infrun: syscall number = '%d'\n",
3198 ecs
->event_thread
->control
.stop_bpstat
3199 = bpstat_stop_status (get_regcache_aspace (regcache
),
3200 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3202 if (bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
3204 /* Catchpoint hit. */
3209 /* If no catchpoint triggered for this, then keep going. */
3214 /* Lazily fill in the execution_control_state's stop_func_* fields. */
3217 fill_in_stop_func (struct gdbarch
*gdbarch
,
3218 struct execution_control_state
*ecs
)
3220 if (!ecs
->stop_func_filled_in
)
3222 /* Don't care about return value; stop_func_start and stop_func_name
3223 will both be 0 if it doesn't work. */
3224 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
3225 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
3226 ecs
->stop_func_start
3227 += gdbarch_deprecated_function_start_offset (gdbarch
);
3229 if (gdbarch_skip_entrypoint_p (gdbarch
))
3230 ecs
->stop_func_start
= gdbarch_skip_entrypoint (gdbarch
,
3231 ecs
->stop_func_start
);
3233 ecs
->stop_func_filled_in
= 1;
3238 /* Return the STOP_SOON field of the inferior pointed at by PTID. */
3240 static enum stop_kind
3241 get_inferior_stop_soon (ptid_t ptid
)
3243 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ptid
));
3245 gdb_assert (inf
!= NULL
);
3246 return inf
->control
.stop_soon
;
3249 /* Given an execution control state that has been freshly filled in by
3250 an event from the inferior, figure out what it means and take
3253 The alternatives are:
3255 1) stop_stepping and return; to really stop and return to the
3258 2) keep_going and return; to wait for the next event (set
3259 ecs->event_thread->stepping_over_breakpoint to 1 to single step
3263 handle_inferior_event (struct execution_control_state
*ecs
)
3265 enum stop_kind stop_soon
;
3267 if (ecs
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
3269 /* We had an event in the inferior, but we are not interested in
3270 handling it at this level. The lower layers have already
3271 done what needs to be done, if anything.
3273 One of the possible circumstances for this is when the
3274 inferior produces output for the console. The inferior has
3275 not stopped, and we are ignoring the event. Another possible
3276 circumstance is any event which the lower level knows will be
3277 reported multiple times without an intervening resume. */
3279 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_IGNORE\n");
3280 prepare_to_wait (ecs
);
3284 if (ecs
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
3285 && target_can_async_p () && !sync_execution
)
3287 /* There were no unwaited-for children left in the target, but,
3288 we're not synchronously waiting for events either. Just
3289 ignore. Otherwise, if we were running a synchronous
3290 execution command, we need to cancel it and give the user
3291 back the terminal. */
3293 fprintf_unfiltered (gdb_stdlog
,
3294 "infrun: TARGET_WAITKIND_NO_RESUMED (ignoring)\n");
3295 prepare_to_wait (ecs
);
3299 /* Cache the last pid/waitstatus. */
3300 set_last_target_status (ecs
->ptid
, ecs
->ws
);
3302 /* Always clear state belonging to the previous time we stopped. */
3303 stop_stack_dummy
= STOP_NONE
;
3305 if (ecs
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
)
3307 /* No unwaited-for children left. IOW, all resumed children
3310 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_NO_RESUMED\n");
3312 stop_print_frame
= 0;
3313 stop_stepping (ecs
);
3317 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
3318 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
)
3320 ecs
->event_thread
= find_thread_ptid (ecs
->ptid
);
3321 /* If it's a new thread, add it to the thread database. */
3322 if (ecs
->event_thread
== NULL
)
3323 ecs
->event_thread
= add_thread (ecs
->ptid
);
3325 /* Disable range stepping. If the next step request could use a
3326 range, this will be end up re-enabled then. */
3327 ecs
->event_thread
->control
.may_range_step
= 0;
3330 /* Dependent on valid ECS->EVENT_THREAD. */
3331 adjust_pc_after_break (ecs
);
3333 /* Dependent on the current PC value modified by adjust_pc_after_break. */
3334 reinit_frame_cache ();
3336 breakpoint_retire_moribund ();
3338 /* First, distinguish signals caused by the debugger from signals
3339 that have to do with the program's own actions. Note that
3340 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
3341 on the operating system version. Here we detect when a SIGILL or
3342 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
3343 something similar for SIGSEGV, since a SIGSEGV will be generated
3344 when we're trying to execute a breakpoint instruction on a
3345 non-executable stack. This happens for call dummy breakpoints
3346 for architectures like SPARC that place call dummies on the
3348 if (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
3349 && (ecs
->ws
.value
.sig
== GDB_SIGNAL_ILL
3350 || ecs
->ws
.value
.sig
== GDB_SIGNAL_SEGV
3351 || ecs
->ws
.value
.sig
== GDB_SIGNAL_EMT
))
3353 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3355 if (breakpoint_inserted_here_p (get_regcache_aspace (regcache
),
3356 regcache_read_pc (regcache
)))
3359 fprintf_unfiltered (gdb_stdlog
,
3360 "infrun: Treating signal as SIGTRAP\n");
3361 ecs
->ws
.value
.sig
= GDB_SIGNAL_TRAP
;
3365 /* Mark the non-executing threads accordingly. In all-stop, all
3366 threads of all processes are stopped when we get any event
3367 reported. In non-stop mode, only the event thread stops. If
3368 we're handling a process exit in non-stop mode, there's nothing
3369 to do, as threads of the dead process are gone, and threads of
3370 any other process were left running. */
3372 set_executing (minus_one_ptid
, 0);
3373 else if (ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
3374 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
)
3375 set_executing (ecs
->ptid
, 0);
3377 switch (infwait_state
)
3379 case infwait_normal_state
:
3381 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_normal_state\n");
3384 case infwait_step_watch_state
:
3386 fprintf_unfiltered (gdb_stdlog
,
3387 "infrun: infwait_step_watch_state\n");
3389 ecs
->stepped_after_stopped_by_watchpoint
= 1;
3392 case infwait_nonstep_watch_state
:
3394 fprintf_unfiltered (gdb_stdlog
,
3395 "infrun: infwait_nonstep_watch_state\n");
3396 insert_breakpoints ();
3398 /* FIXME-maybe: is this cleaner than setting a flag? Does it
3399 handle things like signals arriving and other things happening
3400 in combination correctly? */
3401 ecs
->stepped_after_stopped_by_watchpoint
= 1;
3405 internal_error (__FILE__
, __LINE__
, _("bad switch"));
3408 infwait_state
= infwait_normal_state
;
3409 waiton_ptid
= pid_to_ptid (-1);
3411 switch (ecs
->ws
.kind
)
3413 case TARGET_WAITKIND_LOADED
:
3415 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_LOADED\n");
3416 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3417 context_switch (ecs
->ptid
);
3418 /* Ignore gracefully during startup of the inferior, as it might
3419 be the shell which has just loaded some objects, otherwise
3420 add the symbols for the newly loaded objects. Also ignore at
3421 the beginning of an attach or remote session; we will query
3422 the full list of libraries once the connection is
3425 stop_soon
= get_inferior_stop_soon (ecs
->ptid
);
3426 if (stop_soon
== NO_STOP_QUIETLY
)
3428 struct regcache
*regcache
;
3430 regcache
= get_thread_regcache (ecs
->ptid
);
3432 handle_solib_event ();
3434 ecs
->event_thread
->control
.stop_bpstat
3435 = bpstat_stop_status (get_regcache_aspace (regcache
),
3436 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3438 if (bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
3440 /* A catchpoint triggered. */
3441 process_event_stop_test (ecs
);
3445 /* If requested, stop when the dynamic linker notifies
3446 gdb of events. This allows the user to get control
3447 and place breakpoints in initializer routines for
3448 dynamically loaded objects (among other things). */
3449 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3450 if (stop_on_solib_events
)
3452 /* Make sure we print "Stopped due to solib-event" in
3454 stop_print_frame
= 1;
3456 stop_stepping (ecs
);
3461 /* If we are skipping through a shell, or through shared library
3462 loading that we aren't interested in, resume the program. If
3463 we're running the program normally, also resume. */
3464 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== NO_STOP_QUIETLY
)
3466 /* Loading of shared libraries might have changed breakpoint
3467 addresses. Make sure new breakpoints are inserted. */
3468 if (stop_soon
== NO_STOP_QUIETLY
3469 && !breakpoints_always_inserted_mode ())
3470 insert_breakpoints ();
3471 resume (0, GDB_SIGNAL_0
);
3472 prepare_to_wait (ecs
);
3476 /* But stop if we're attaching or setting up a remote
3478 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
3479 || stop_soon
== STOP_QUIETLY_REMOTE
)
3482 fprintf_unfiltered (gdb_stdlog
, "infrun: quietly stopped\n");
3483 stop_stepping (ecs
);
3487 internal_error (__FILE__
, __LINE__
,
3488 _("unhandled stop_soon: %d"), (int) stop_soon
);
3490 case TARGET_WAITKIND_SPURIOUS
:
3492 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SPURIOUS\n");
3493 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3494 context_switch (ecs
->ptid
);
3495 resume (0, GDB_SIGNAL_0
);
3496 prepare_to_wait (ecs
);
3499 case TARGET_WAITKIND_EXITED
:
3500 case TARGET_WAITKIND_SIGNALLED
:
3503 if (ecs
->ws
.kind
== TARGET_WAITKIND_EXITED
)
3504 fprintf_unfiltered (gdb_stdlog
,
3505 "infrun: TARGET_WAITKIND_EXITED\n");
3507 fprintf_unfiltered (gdb_stdlog
,
3508 "infrun: TARGET_WAITKIND_SIGNALLED\n");
3511 inferior_ptid
= ecs
->ptid
;
3512 set_current_inferior (find_inferior_pid (ptid_get_pid (ecs
->ptid
)));
3513 set_current_program_space (current_inferior ()->pspace
);
3514 handle_vfork_child_exec_or_exit (0);
3515 target_terminal_ours (); /* Must do this before mourn anyway. */
3517 /* Clearing any previous state of convenience variables. */
3518 clear_exit_convenience_vars ();
3520 if (ecs
->ws
.kind
== TARGET_WAITKIND_EXITED
)
3522 /* Record the exit code in the convenience variable $_exitcode, so
3523 that the user can inspect this again later. */
3524 set_internalvar_integer (lookup_internalvar ("_exitcode"),
3525 (LONGEST
) ecs
->ws
.value
.integer
);
3527 /* Also record this in the inferior itself. */
3528 current_inferior ()->has_exit_code
= 1;
3529 current_inferior ()->exit_code
= (LONGEST
) ecs
->ws
.value
.integer
;
3531 /* Support the --return-child-result option. */
3532 return_child_result_value
= ecs
->ws
.value
.integer
;
3534 observer_notify_exited (ecs
->ws
.value
.integer
);
3538 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3539 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3541 if (gdbarch_gdb_signal_to_target_p (gdbarch
))
3543 /* Set the value of the internal variable $_exitsignal,
3544 which holds the signal uncaught by the inferior. */
3545 set_internalvar_integer (lookup_internalvar ("_exitsignal"),
3546 gdbarch_gdb_signal_to_target (gdbarch
,
3547 ecs
->ws
.value
.sig
));
3551 /* We don't have access to the target's method used for
3552 converting between signal numbers (GDB's internal
3553 representation <-> target's representation).
3554 Therefore, we cannot do a good job at displaying this
3555 information to the user. It's better to just warn
3556 her about it (if infrun debugging is enabled), and
3559 fprintf_filtered (gdb_stdlog
, _("\
3560 Cannot fill $_exitsignal with the correct signal number.\n"));
3563 observer_notify_signal_exited (ecs
->ws
.value
.sig
);
3566 gdb_flush (gdb_stdout
);
3567 target_mourn_inferior ();
3568 singlestep_breakpoints_inserted_p
= 0;
3569 cancel_single_step_breakpoints ();
3570 stop_print_frame
= 0;
3571 stop_stepping (ecs
);
3574 /* The following are the only cases in which we keep going;
3575 the above cases end in a continue or goto. */
3576 case TARGET_WAITKIND_FORKED
:
3577 case TARGET_WAITKIND_VFORKED
:
3580 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
3581 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_FORKED\n");
3583 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_VFORKED\n");
3586 /* Check whether the inferior is displaced stepping. */
3588 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3589 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3590 struct displaced_step_inferior_state
*displaced
3591 = get_displaced_stepping_state (ptid_get_pid (ecs
->ptid
));
3593 /* If checking displaced stepping is supported, and thread
3594 ecs->ptid is displaced stepping. */
3595 if (displaced
&& ptid_equal (displaced
->step_ptid
, ecs
->ptid
))
3597 struct inferior
*parent_inf
3598 = find_inferior_pid (ptid_get_pid (ecs
->ptid
));
3599 struct regcache
*child_regcache
;
3600 CORE_ADDR parent_pc
;
3602 /* GDB has got TARGET_WAITKIND_FORKED or TARGET_WAITKIND_VFORKED,
3603 indicating that the displaced stepping of syscall instruction
3604 has been done. Perform cleanup for parent process here. Note
3605 that this operation also cleans up the child process for vfork,
3606 because their pages are shared. */
3607 displaced_step_fixup (ecs
->ptid
, GDB_SIGNAL_TRAP
);
3609 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
3611 /* Restore scratch pad for child process. */
3612 displaced_step_restore (displaced
, ecs
->ws
.value
.related_pid
);
3615 /* Since the vfork/fork syscall instruction was executed in the scratchpad,
3616 the child's PC is also within the scratchpad. Set the child's PC
3617 to the parent's PC value, which has already been fixed up.
3618 FIXME: we use the parent's aspace here, although we're touching
3619 the child, because the child hasn't been added to the inferior
3620 list yet at this point. */
3623 = get_thread_arch_aspace_regcache (ecs
->ws
.value
.related_pid
,
3625 parent_inf
->aspace
);
3626 /* Read PC value of parent process. */
3627 parent_pc
= regcache_read_pc (regcache
);
3629 if (debug_displaced
)
3630 fprintf_unfiltered (gdb_stdlog
,
3631 "displaced: write child pc from %s to %s\n",
3633 regcache_read_pc (child_regcache
)),
3634 paddress (gdbarch
, parent_pc
));
3636 regcache_write_pc (child_regcache
, parent_pc
);
3640 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3641 context_switch (ecs
->ptid
);
3643 /* Immediately detach breakpoints from the child before there's
3644 any chance of letting the user delete breakpoints from the
3645 breakpoint lists. If we don't do this early, it's easy to
3646 leave left over traps in the child, vis: "break foo; catch
3647 fork; c; <fork>; del; c; <child calls foo>". We only follow
3648 the fork on the last `continue', and by that time the
3649 breakpoint at "foo" is long gone from the breakpoint table.
3650 If we vforked, then we don't need to unpatch here, since both
3651 parent and child are sharing the same memory pages; we'll
3652 need to unpatch at follow/detach time instead to be certain
3653 that new breakpoints added between catchpoint hit time and
3654 vfork follow are detached. */
3655 if (ecs
->ws
.kind
!= TARGET_WAITKIND_VFORKED
)
3657 /* This won't actually modify the breakpoint list, but will
3658 physically remove the breakpoints from the child. */
3659 detach_breakpoints (ecs
->ws
.value
.related_pid
);
3662 if (singlestep_breakpoints_inserted_p
)
3664 /* Pull the single step breakpoints out of the target. */
3665 remove_single_step_breakpoints ();
3666 singlestep_breakpoints_inserted_p
= 0;
3669 /* In case the event is caught by a catchpoint, remember that
3670 the event is to be followed at the next resume of the thread,
3671 and not immediately. */
3672 ecs
->event_thread
->pending_follow
= ecs
->ws
;
3674 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3676 ecs
->event_thread
->control
.stop_bpstat
3677 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3678 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3680 /* If no catchpoint triggered for this, then keep going. Note
3681 that we're interested in knowing the bpstat actually causes a
3682 stop, not just if it may explain the signal. Software
3683 watchpoints, for example, always appear in the bpstat. */
3684 if (!bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
3690 = (follow_fork_mode_string
== follow_fork_mode_child
);
3692 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3694 should_resume
= follow_fork ();
3697 child
= ecs
->ws
.value
.related_pid
;
3699 /* In non-stop mode, also resume the other branch. */
3700 if (non_stop
&& !detach_fork
)
3703 switch_to_thread (parent
);
3705 switch_to_thread (child
);
3707 ecs
->event_thread
= inferior_thread ();
3708 ecs
->ptid
= inferior_ptid
;
3713 switch_to_thread (child
);
3715 switch_to_thread (parent
);
3717 ecs
->event_thread
= inferior_thread ();
3718 ecs
->ptid
= inferior_ptid
;
3723 stop_stepping (ecs
);
3726 process_event_stop_test (ecs
);
3729 case TARGET_WAITKIND_VFORK_DONE
:
3730 /* Done with the shared memory region. Re-insert breakpoints in
3731 the parent, and keep going. */
3734 fprintf_unfiltered (gdb_stdlog
,
3735 "infrun: TARGET_WAITKIND_VFORK_DONE\n");
3737 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3738 context_switch (ecs
->ptid
);
3740 current_inferior ()->waiting_for_vfork_done
= 0;
3741 current_inferior ()->pspace
->breakpoints_not_allowed
= 0;
3742 /* This also takes care of reinserting breakpoints in the
3743 previously locked inferior. */
3747 case TARGET_WAITKIND_EXECD
:
3749 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_EXECD\n");
3751 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3752 context_switch (ecs
->ptid
);
3754 singlestep_breakpoints_inserted_p
= 0;
3755 cancel_single_step_breakpoints ();
3757 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3759 /* Do whatever is necessary to the parent branch of the vfork. */
3760 handle_vfork_child_exec_or_exit (1);
3762 /* This causes the eventpoints and symbol table to be reset.
3763 Must do this now, before trying to determine whether to
3765 follow_exec (inferior_ptid
, ecs
->ws
.value
.execd_pathname
);
3767 ecs
->event_thread
->control
.stop_bpstat
3768 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3769 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3771 /* Note that this may be referenced from inside
3772 bpstat_stop_status above, through inferior_has_execd. */
3773 xfree (ecs
->ws
.value
.execd_pathname
);
3774 ecs
->ws
.value
.execd_pathname
= NULL
;
3776 /* If no catchpoint triggered for this, then keep going. */
3777 if (!bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
3779 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3783 process_event_stop_test (ecs
);
3786 /* Be careful not to try to gather much state about a thread
3787 that's in a syscall. It's frequently a losing proposition. */
3788 case TARGET_WAITKIND_SYSCALL_ENTRY
:
3790 fprintf_unfiltered (gdb_stdlog
,
3791 "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
3792 /* Getting the current syscall number. */
3793 if (handle_syscall_event (ecs
) == 0)
3794 process_event_stop_test (ecs
);
3797 /* Before examining the threads further, step this thread to
3798 get it entirely out of the syscall. (We get notice of the
3799 event when the thread is just on the verge of exiting a
3800 syscall. Stepping one instruction seems to get it back
3802 case TARGET_WAITKIND_SYSCALL_RETURN
:
3804 fprintf_unfiltered (gdb_stdlog
,
3805 "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
3806 if (handle_syscall_event (ecs
) == 0)
3807 process_event_stop_test (ecs
);
3810 case TARGET_WAITKIND_STOPPED
:
3812 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_STOPPED\n");
3813 ecs
->event_thread
->suspend
.stop_signal
= ecs
->ws
.value
.sig
;
3814 handle_signal_stop (ecs
);
3817 case TARGET_WAITKIND_NO_HISTORY
:
3819 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_NO_HISTORY\n");
3820 /* Reverse execution: target ran out of history info. */
3822 /* Pull the single step breakpoints out of the target. */
3823 if (singlestep_breakpoints_inserted_p
)
3825 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3826 context_switch (ecs
->ptid
);
3827 remove_single_step_breakpoints ();
3828 singlestep_breakpoints_inserted_p
= 0;
3830 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3831 observer_notify_no_history ();
3832 stop_stepping (ecs
);
3837 /* Come here when the program has stopped with a signal. */
3840 handle_signal_stop (struct execution_control_state
*ecs
)
3842 struct frame_info
*frame
;
3843 struct gdbarch
*gdbarch
;
3844 int stopped_by_watchpoint
;
3845 enum stop_kind stop_soon
;
3848 gdb_assert (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
3850 /* Do we need to clean up the state of a thread that has
3851 completed a displaced single-step? (Doing so usually affects
3852 the PC, so do it here, before we set stop_pc.) */
3853 displaced_step_fixup (ecs
->ptid
,
3854 ecs
->event_thread
->suspend
.stop_signal
);
3856 /* If we either finished a single-step or hit a breakpoint, but
3857 the user wanted this thread to be stopped, pretend we got a
3858 SIG0 (generic unsignaled stop). */
3859 if (ecs
->event_thread
->stop_requested
3860 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
3861 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3863 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3867 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3868 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3869 struct cleanup
*old_chain
= save_inferior_ptid ();
3871 inferior_ptid
= ecs
->ptid
;
3873 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_pc = %s\n",
3874 paddress (gdbarch
, stop_pc
));
3875 if (target_stopped_by_watchpoint ())
3879 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped by watchpoint\n");
3881 if (target_stopped_data_address (¤t_target
, &addr
))
3882 fprintf_unfiltered (gdb_stdlog
,
3883 "infrun: stopped data address = %s\n",
3884 paddress (gdbarch
, addr
));
3886 fprintf_unfiltered (gdb_stdlog
,
3887 "infrun: (no data address available)\n");
3890 do_cleanups (old_chain
);
3893 /* This is originated from start_remote(), start_inferior() and
3894 shared libraries hook functions. */
3895 stop_soon
= get_inferior_stop_soon (ecs
->ptid
);
3896 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_REMOTE
)
3898 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3899 context_switch (ecs
->ptid
);
3901 fprintf_unfiltered (gdb_stdlog
, "infrun: quietly stopped\n");
3902 stop_print_frame
= 1;
3903 stop_stepping (ecs
);
3907 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
3910 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3911 context_switch (ecs
->ptid
);
3913 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped\n");
3914 stop_print_frame
= 0;
3915 stop_stepping (ecs
);
3919 /* This originates from attach_command(). We need to overwrite
3920 the stop_signal here, because some kernels don't ignore a
3921 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
3922 See more comments in inferior.h. On the other hand, if we
3923 get a non-SIGSTOP, report it to the user - assume the backend
3924 will handle the SIGSTOP if it should show up later.
3926 Also consider that the attach is complete when we see a
3927 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
3928 target extended-remote report it instead of a SIGSTOP
3929 (e.g. gdbserver). We already rely on SIGTRAP being our
3930 signal, so this is no exception.
3932 Also consider that the attach is complete when we see a
3933 GDB_SIGNAL_0. In non-stop mode, GDB will explicitly tell
3934 the target to stop all threads of the inferior, in case the
3935 low level attach operation doesn't stop them implicitly. If
3936 they weren't stopped implicitly, then the stub will report a
3937 GDB_SIGNAL_0, meaning: stopped for no particular reason
3938 other than GDB's request. */
3939 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
3940 && (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_STOP
3941 || ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
3942 || ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_0
))
3944 stop_print_frame
= 1;
3945 stop_stepping (ecs
);
3946 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3950 /* See if something interesting happened to the non-current thread. If
3951 so, then switch to that thread. */
3952 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3955 fprintf_unfiltered (gdb_stdlog
, "infrun: context switch\n");
3957 context_switch (ecs
->ptid
);
3959 if (deprecated_context_hook
)
3960 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
3963 /* At this point, get hold of the now-current thread's frame. */
3964 frame
= get_current_frame ();
3965 gdbarch
= get_frame_arch (frame
);
3967 /* Pull the single step breakpoints out of the target. */
3968 if (singlestep_breakpoints_inserted_p
)
3970 /* However, before doing so, if this single-step breakpoint was
3971 actually for another thread, set this thread up for moving
3973 if (!ptid_equal (ecs
->ptid
, singlestep_ptid
)
3974 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
3976 struct regcache
*regcache
;
3977 struct address_space
*aspace
;
3980 regcache
= get_thread_regcache (ecs
->ptid
);
3981 aspace
= get_regcache_aspace (regcache
);
3982 pc
= regcache_read_pc (regcache
);
3983 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
3987 fprintf_unfiltered (gdb_stdlog
,
3988 "infrun: [%s] hit step over single-step"
3989 " breakpoint of [%s]\n",
3990 target_pid_to_str (ecs
->ptid
),
3991 target_pid_to_str (singlestep_ptid
));
3993 ecs
->hit_singlestep_breakpoint
= 1;
3997 remove_single_step_breakpoints ();
3998 singlestep_breakpoints_inserted_p
= 0;
4001 if (ecs
->stepped_after_stopped_by_watchpoint
)
4002 stopped_by_watchpoint
= 0;
4004 stopped_by_watchpoint
= watchpoints_triggered (&ecs
->ws
);
4006 /* If necessary, step over this watchpoint. We'll be back to display
4008 if (stopped_by_watchpoint
4009 && (target_have_steppable_watchpoint
4010 || gdbarch_have_nonsteppable_watchpoint (gdbarch
)))
4012 /* At this point, we are stopped at an instruction which has
4013 attempted to write to a piece of memory under control of
4014 a watchpoint. The instruction hasn't actually executed
4015 yet. If we were to evaluate the watchpoint expression
4016 now, we would get the old value, and therefore no change
4017 would seem to have occurred.
4019 In order to make watchpoints work `right', we really need
4020 to complete the memory write, and then evaluate the
4021 watchpoint expression. We do this by single-stepping the
4024 It may not be necessary to disable the watchpoint to stop over
4025 it. For example, the PA can (with some kernel cooperation)
4026 single step over a watchpoint without disabling the watchpoint.
4028 It is far more common to need to disable a watchpoint to step
4029 the inferior over it. If we have non-steppable watchpoints,
4030 we must disable the current watchpoint; it's simplest to
4031 disable all watchpoints and breakpoints. */
4034 if (!target_have_steppable_watchpoint
)
4036 remove_breakpoints ();
4037 /* See comment in resume why we need to stop bypassing signals
4038 while breakpoints have been removed. */
4039 target_pass_signals (0, NULL
);
4042 hw_step
= maybe_software_singlestep (gdbarch
, stop_pc
);
4043 target_resume (ecs
->ptid
, hw_step
, GDB_SIGNAL_0
);
4044 waiton_ptid
= ecs
->ptid
;
4045 if (target_have_steppable_watchpoint
)
4046 infwait_state
= infwait_step_watch_state
;
4048 infwait_state
= infwait_nonstep_watch_state
;
4049 prepare_to_wait (ecs
);
4053 ecs
->event_thread
->stepping_over_breakpoint
= 0;
4054 bpstat_clear (&ecs
->event_thread
->control
.stop_bpstat
);
4055 ecs
->event_thread
->control
.stop_step
= 0;
4056 stop_print_frame
= 1;
4057 stopped_by_random_signal
= 0;
4059 /* Hide inlined functions starting here, unless we just performed stepi or
4060 nexti. After stepi and nexti, always show the innermost frame (not any
4061 inline function call sites). */
4062 if (ecs
->event_thread
->control
.step_range_end
!= 1)
4064 struct address_space
*aspace
=
4065 get_regcache_aspace (get_thread_regcache (ecs
->ptid
));
4067 /* skip_inline_frames is expensive, so we avoid it if we can
4068 determine that the address is one where functions cannot have
4069 been inlined. This improves performance with inferiors that
4070 load a lot of shared libraries, because the solib event
4071 breakpoint is defined as the address of a function (i.e. not
4072 inline). Note that we have to check the previous PC as well
4073 as the current one to catch cases when we have just
4074 single-stepped off a breakpoint prior to reinstating it.
4075 Note that we're assuming that the code we single-step to is
4076 not inline, but that's not definitive: there's nothing
4077 preventing the event breakpoint function from containing
4078 inlined code, and the single-step ending up there. If the
4079 user had set a breakpoint on that inlined code, the missing
4080 skip_inline_frames call would break things. Fortunately
4081 that's an extremely unlikely scenario. */
4082 if (!pc_at_non_inline_function (aspace
, stop_pc
, &ecs
->ws
)
4083 && !(ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4084 && ecs
->event_thread
->control
.trap_expected
4085 && pc_at_non_inline_function (aspace
,
4086 ecs
->event_thread
->prev_pc
,
4089 skip_inline_frames (ecs
->ptid
);
4091 /* Re-fetch current thread's frame in case that invalidated
4093 frame
= get_current_frame ();
4094 gdbarch
= get_frame_arch (frame
);
4098 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4099 && ecs
->event_thread
->control
.trap_expected
4100 && gdbarch_single_step_through_delay_p (gdbarch
)
4101 && currently_stepping (ecs
->event_thread
))
4103 /* We're trying to step off a breakpoint. Turns out that we're
4104 also on an instruction that needs to be stepped multiple
4105 times before it's been fully executing. E.g., architectures
4106 with a delay slot. It needs to be stepped twice, once for
4107 the instruction and once for the delay slot. */
4108 int step_through_delay
4109 = gdbarch_single_step_through_delay (gdbarch
, frame
);
4111 if (debug_infrun
&& step_through_delay
)
4112 fprintf_unfiltered (gdb_stdlog
, "infrun: step through delay\n");
4113 if (ecs
->event_thread
->control
.step_range_end
== 0
4114 && step_through_delay
)
4116 /* The user issued a continue when stopped at a breakpoint.
4117 Set up for another trap and get out of here. */
4118 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4122 else if (step_through_delay
)
4124 /* The user issued a step when stopped at a breakpoint.
4125 Maybe we should stop, maybe we should not - the delay
4126 slot *might* correspond to a line of source. In any
4127 case, don't decide that here, just set
4128 ecs->stepping_over_breakpoint, making sure we
4129 single-step again before breakpoints are re-inserted. */
4130 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4134 /* See if there is a breakpoint/watchpoint/catchpoint/etc. that
4135 handles this event. */
4136 ecs
->event_thread
->control
.stop_bpstat
4137 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
4138 stop_pc
, ecs
->ptid
, &ecs
->ws
);
4140 /* Following in case break condition called a
4142 stop_print_frame
= 1;
4144 /* This is where we handle "moribund" watchpoints. Unlike
4145 software breakpoints traps, hardware watchpoint traps are
4146 always distinguishable from random traps. If no high-level
4147 watchpoint is associated with the reported stop data address
4148 anymore, then the bpstat does not explain the signal ---
4149 simply make sure to ignore it if `stopped_by_watchpoint' is
4153 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4154 && !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
4156 && stopped_by_watchpoint
)
4157 fprintf_unfiltered (gdb_stdlog
,
4158 "infrun: no user watchpoint explains "
4159 "watchpoint SIGTRAP, ignoring\n");
4161 /* NOTE: cagney/2003-03-29: These checks for a random signal
4162 at one stage in the past included checks for an inferior
4163 function call's call dummy's return breakpoint. The original
4164 comment, that went with the test, read:
4166 ``End of a stack dummy. Some systems (e.g. Sony news) give
4167 another signal besides SIGTRAP, so check here as well as
4170 If someone ever tries to get call dummys on a
4171 non-executable stack to work (where the target would stop
4172 with something like a SIGSEGV), then those tests might need
4173 to be re-instated. Given, however, that the tests were only
4174 enabled when momentary breakpoints were not being used, I
4175 suspect that it won't be the case.
4177 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
4178 be necessary for call dummies on a non-executable stack on
4181 /* See if the breakpoints module can explain the signal. */
4183 = !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
4184 ecs
->event_thread
->suspend
.stop_signal
);
4186 /* If not, perhaps stepping/nexting can. */
4188 random_signal
= !(ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4189 && currently_stepping (ecs
->event_thread
));
4191 /* Perhaps the thread hit a single-step breakpoint of _another_
4192 thread. Single-step breakpoints are transparent to the
4193 breakpoints module. */
4195 random_signal
= !ecs
->hit_singlestep_breakpoint
;
4197 /* No? Perhaps we got a moribund watchpoint. */
4199 random_signal
= !stopped_by_watchpoint
;
4201 /* For the program's own signals, act according to
4202 the signal handling tables. */
4206 /* Signal not for debugging purposes. */
4208 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ecs
->ptid
));
4209 enum gdb_signal stop_signal
= ecs
->event_thread
->suspend
.stop_signal
;
4212 fprintf_unfiltered (gdb_stdlog
, "infrun: random signal (%s)\n",
4213 gdb_signal_to_symbol_string (stop_signal
));
4215 stopped_by_random_signal
= 1;
4217 if (signal_print
[ecs
->event_thread
->suspend
.stop_signal
])
4219 /* The signal table tells us to print about this signal. */
4221 target_terminal_ours_for_output ();
4222 observer_notify_signal_received (ecs
->event_thread
->suspend
.stop_signal
);
4224 /* Always stop on signals if we're either just gaining control
4225 of the program, or the user explicitly requested this thread
4226 to remain stopped. */
4227 if (stop_soon
!= NO_STOP_QUIETLY
4228 || ecs
->event_thread
->stop_requested
4230 && signal_stop_state (ecs
->event_thread
->suspend
.stop_signal
)))
4232 stop_stepping (ecs
);
4235 /* If not going to stop, give terminal back
4236 if we took it away. */
4238 target_terminal_inferior ();
4240 /* Clear the signal if it should not be passed. */
4241 if (signal_program
[ecs
->event_thread
->suspend
.stop_signal
] == 0)
4242 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4244 if (ecs
->event_thread
->prev_pc
== stop_pc
4245 && ecs
->event_thread
->control
.trap_expected
4246 && ecs
->event_thread
->control
.step_resume_breakpoint
== NULL
)
4248 /* We were just starting a new sequence, attempting to
4249 single-step off of a breakpoint and expecting a SIGTRAP.
4250 Instead this signal arrives. This signal will take us out
4251 of the stepping range so GDB needs to remember to, when
4252 the signal handler returns, resume stepping off that
4254 /* To simplify things, "continue" is forced to use the same
4255 code paths as single-step - set a breakpoint at the
4256 signal return address and then, once hit, step off that
4259 fprintf_unfiltered (gdb_stdlog
,
4260 "infrun: signal arrived while stepping over "
4263 insert_hp_step_resume_breakpoint_at_frame (frame
);
4264 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
4265 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4266 ecs
->event_thread
->control
.trap_expected
= 0;
4268 /* If we were nexting/stepping some other thread, switch to
4269 it, so that we don't continue it, losing control. */
4270 if (!switch_back_to_stepped_thread (ecs
))
4275 if (ecs
->event_thread
->control
.step_range_end
!= 0
4276 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
4277 && pc_in_thread_step_range (stop_pc
, ecs
->event_thread
)
4278 && frame_id_eq (get_stack_frame_id (frame
),
4279 ecs
->event_thread
->control
.step_stack_frame_id
)
4280 && ecs
->event_thread
->control
.step_resume_breakpoint
== NULL
)
4282 /* The inferior is about to take a signal that will take it
4283 out of the single step range. Set a breakpoint at the
4284 current PC (which is presumably where the signal handler
4285 will eventually return) and then allow the inferior to
4288 Note that this is only needed for a signal delivered
4289 while in the single-step range. Nested signals aren't a
4290 problem as they eventually all return. */
4292 fprintf_unfiltered (gdb_stdlog
,
4293 "infrun: signal may take us out of "
4294 "single-step range\n");
4296 insert_hp_step_resume_breakpoint_at_frame (frame
);
4297 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4298 ecs
->event_thread
->control
.trap_expected
= 0;
4303 /* Note: step_resume_breakpoint may be non-NULL. This occures
4304 when either there's a nested signal, or when there's a
4305 pending signal enabled just as the signal handler returns
4306 (leaving the inferior at the step-resume-breakpoint without
4307 actually executing it). Either way continue until the
4308 breakpoint is really hit. */
4310 if (!switch_back_to_stepped_thread (ecs
))
4313 fprintf_unfiltered (gdb_stdlog
,
4314 "infrun: random signal, keep going\n");
4321 process_event_stop_test (ecs
);
4324 /* Come here when we've got some debug event / signal we can explain
4325 (IOW, not a random signal), and test whether it should cause a
4326 stop, or whether we should resume the inferior (transparently).
4327 E.g., could be a breakpoint whose condition evaluates false; we
4328 could be still stepping within the line; etc. */
4331 process_event_stop_test (struct execution_control_state
*ecs
)
4333 struct symtab_and_line stop_pc_sal
;
4334 struct frame_info
*frame
;
4335 struct gdbarch
*gdbarch
;
4336 CORE_ADDR jmp_buf_pc
;
4337 struct bpstat_what what
;
4339 /* Handle cases caused by hitting a breakpoint. */
4341 frame
= get_current_frame ();
4342 gdbarch
= get_frame_arch (frame
);
4344 what
= bpstat_what (ecs
->event_thread
->control
.stop_bpstat
);
4346 if (what
.call_dummy
)
4348 stop_stack_dummy
= what
.call_dummy
;
4351 /* If we hit an internal event that triggers symbol changes, the
4352 current frame will be invalidated within bpstat_what (e.g., if we
4353 hit an internal solib event). Re-fetch it. */
4354 frame
= get_current_frame ();
4355 gdbarch
= get_frame_arch (frame
);
4357 switch (what
.main_action
)
4359 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
4360 /* If we hit the breakpoint at longjmp while stepping, we
4361 install a momentary breakpoint at the target of the
4365 fprintf_unfiltered (gdb_stdlog
,
4366 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
4368 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4370 if (what
.is_longjmp
)
4372 struct value
*arg_value
;
4374 /* If we set the longjmp breakpoint via a SystemTap probe,
4375 then use it to extract the arguments. The destination PC
4376 is the third argument to the probe. */
4377 arg_value
= probe_safe_evaluate_at_pc (frame
, 2);
4379 jmp_buf_pc
= value_as_address (arg_value
);
4380 else if (!gdbarch_get_longjmp_target_p (gdbarch
)
4381 || !gdbarch_get_longjmp_target (gdbarch
,
4382 frame
, &jmp_buf_pc
))
4385 fprintf_unfiltered (gdb_stdlog
,
4386 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME "
4387 "(!gdbarch_get_longjmp_target)\n");
4392 /* Insert a breakpoint at resume address. */
4393 insert_longjmp_resume_breakpoint (gdbarch
, jmp_buf_pc
);
4396 check_exception_resume (ecs
, frame
);
4400 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
4402 struct frame_info
*init_frame
;
4404 /* There are several cases to consider.
4406 1. The initiating frame no longer exists. In this case we
4407 must stop, because the exception or longjmp has gone too
4410 2. The initiating frame exists, and is the same as the
4411 current frame. We stop, because the exception or longjmp
4414 3. The initiating frame exists and is different from the
4415 current frame. This means the exception or longjmp has
4416 been caught beneath the initiating frame, so keep going.
4418 4. longjmp breakpoint has been placed just to protect
4419 against stale dummy frames and user is not interested in
4420 stopping around longjmps. */
4423 fprintf_unfiltered (gdb_stdlog
,
4424 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
4426 gdb_assert (ecs
->event_thread
->control
.exception_resume_breakpoint
4428 delete_exception_resume_breakpoint (ecs
->event_thread
);
4430 if (what
.is_longjmp
)
4432 check_longjmp_breakpoint_for_call_dummy (ecs
->event_thread
->num
);
4434 if (!frame_id_p (ecs
->event_thread
->initiating_frame
))
4442 init_frame
= frame_find_by_id (ecs
->event_thread
->initiating_frame
);
4446 struct frame_id current_id
4447 = get_frame_id (get_current_frame ());
4448 if (frame_id_eq (current_id
,
4449 ecs
->event_thread
->initiating_frame
))
4451 /* Case 2. Fall through. */
4461 /* For Cases 1 and 2, remove the step-resume breakpoint, if it
4463 delete_step_resume_breakpoint (ecs
->event_thread
);
4465 ecs
->event_thread
->control
.stop_step
= 1;
4466 end_stepping_range ();
4467 stop_stepping (ecs
);
4471 case BPSTAT_WHAT_SINGLE
:
4473 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_SINGLE\n");
4474 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4475 /* Still need to check other stuff, at least the case where we
4476 are stepping and step out of the right range. */
4479 case BPSTAT_WHAT_STEP_RESUME
:
4481 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
4483 delete_step_resume_breakpoint (ecs
->event_thread
);
4484 if (ecs
->event_thread
->control
.proceed_to_finish
4485 && execution_direction
== EXEC_REVERSE
)
4487 struct thread_info
*tp
= ecs
->event_thread
;
4489 /* We are finishing a function in reverse, and just hit the
4490 step-resume breakpoint at the start address of the
4491 function, and we're almost there -- just need to back up
4492 by one more single-step, which should take us back to the
4494 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
4498 fill_in_stop_func (gdbarch
, ecs
);
4499 if (stop_pc
== ecs
->stop_func_start
4500 && execution_direction
== EXEC_REVERSE
)
4502 /* We are stepping over a function call in reverse, and just
4503 hit the step-resume breakpoint at the start address of
4504 the function. Go back to single-stepping, which should
4505 take us back to the function call. */
4506 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4512 case BPSTAT_WHAT_STOP_NOISY
:
4514 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
4515 stop_print_frame
= 1;
4517 /* Assume the thread stopped for a breapoint. We'll still check
4518 whether a/the breakpoint is there when the thread is next
4520 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4522 stop_stepping (ecs
);
4525 case BPSTAT_WHAT_STOP_SILENT
:
4527 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
4528 stop_print_frame
= 0;
4530 /* Assume the thread stopped for a breapoint. We'll still check
4531 whether a/the breakpoint is there when the thread is next
4533 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4534 stop_stepping (ecs
);
4537 case BPSTAT_WHAT_HP_STEP_RESUME
:
4539 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_HP_STEP_RESUME\n");
4541 delete_step_resume_breakpoint (ecs
->event_thread
);
4542 if (ecs
->event_thread
->step_after_step_resume_breakpoint
)
4544 /* Back when the step-resume breakpoint was inserted, we
4545 were trying to single-step off a breakpoint. Go back to
4547 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
4548 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4554 case BPSTAT_WHAT_KEEP_CHECKING
:
4558 /* We come here if we hit a breakpoint but should not stop for it.
4559 Possibly we also were stepping and should stop for that. So fall
4560 through and test for stepping. But, if not stepping, do not
4563 /* In all-stop mode, if we're currently stepping but have stopped in
4564 some other thread, we need to switch back to the stepped thread. */
4565 if (switch_back_to_stepped_thread (ecs
))
4568 if (ecs
->event_thread
->control
.step_resume_breakpoint
)
4571 fprintf_unfiltered (gdb_stdlog
,
4572 "infrun: step-resume breakpoint is inserted\n");
4574 /* Having a step-resume breakpoint overrides anything
4575 else having to do with stepping commands until
4576 that breakpoint is reached. */
4581 if (ecs
->event_thread
->control
.step_range_end
== 0)
4584 fprintf_unfiltered (gdb_stdlog
, "infrun: no stepping, continue\n");
4585 /* Likewise if we aren't even stepping. */
4590 /* Re-fetch current thread's frame in case the code above caused
4591 the frame cache to be re-initialized, making our FRAME variable
4592 a dangling pointer. */
4593 frame
= get_current_frame ();
4594 gdbarch
= get_frame_arch (frame
);
4595 fill_in_stop_func (gdbarch
, ecs
);
4597 /* If stepping through a line, keep going if still within it.
4599 Note that step_range_end is the address of the first instruction
4600 beyond the step range, and NOT the address of the last instruction
4603 Note also that during reverse execution, we may be stepping
4604 through a function epilogue and therefore must detect when
4605 the current-frame changes in the middle of a line. */
4607 if (pc_in_thread_step_range (stop_pc
, ecs
->event_thread
)
4608 && (execution_direction
!= EXEC_REVERSE
4609 || frame_id_eq (get_frame_id (frame
),
4610 ecs
->event_thread
->control
.step_frame_id
)))
4614 (gdb_stdlog
, "infrun: stepping inside range [%s-%s]\n",
4615 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_start
),
4616 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_end
));
4618 /* Tentatively re-enable range stepping; `resume' disables it if
4619 necessary (e.g., if we're stepping over a breakpoint or we
4620 have software watchpoints). */
4621 ecs
->event_thread
->control
.may_range_step
= 1;
4623 /* When stepping backward, stop at beginning of line range
4624 (unless it's the function entry point, in which case
4625 keep going back to the call point). */
4626 if (stop_pc
== ecs
->event_thread
->control
.step_range_start
4627 && stop_pc
!= ecs
->stop_func_start
4628 && execution_direction
== EXEC_REVERSE
)
4630 ecs
->event_thread
->control
.stop_step
= 1;
4631 end_stepping_range ();
4632 stop_stepping (ecs
);
4640 /* We stepped out of the stepping range. */
4642 /* If we are stepping at the source level and entered the runtime
4643 loader dynamic symbol resolution code...
4645 EXEC_FORWARD: we keep on single stepping until we exit the run
4646 time loader code and reach the callee's address.
4648 EXEC_REVERSE: we've already executed the callee (backward), and
4649 the runtime loader code is handled just like any other
4650 undebuggable function call. Now we need only keep stepping
4651 backward through the trampoline code, and that's handled further
4652 down, so there is nothing for us to do here. */
4654 if (execution_direction
!= EXEC_REVERSE
4655 && ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
4656 && in_solib_dynsym_resolve_code (stop_pc
))
4658 CORE_ADDR pc_after_resolver
=
4659 gdbarch_skip_solib_resolver (gdbarch
, stop_pc
);
4662 fprintf_unfiltered (gdb_stdlog
,
4663 "infrun: stepped into dynsym resolve code\n");
4665 if (pc_after_resolver
)
4667 /* Set up a step-resume breakpoint at the address
4668 indicated by SKIP_SOLIB_RESOLVER. */
4669 struct symtab_and_line sr_sal
;
4672 sr_sal
.pc
= pc_after_resolver
;
4673 sr_sal
.pspace
= get_frame_program_space (frame
);
4675 insert_step_resume_breakpoint_at_sal (gdbarch
,
4676 sr_sal
, null_frame_id
);
4683 if (ecs
->event_thread
->control
.step_range_end
!= 1
4684 && (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
4685 || ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
4686 && get_frame_type (frame
) == SIGTRAMP_FRAME
)
4689 fprintf_unfiltered (gdb_stdlog
,
4690 "infrun: stepped into signal trampoline\n");
4691 /* The inferior, while doing a "step" or "next", has ended up in
4692 a signal trampoline (either by a signal being delivered or by
4693 the signal handler returning). Just single-step until the
4694 inferior leaves the trampoline (either by calling the handler
4700 /* If we're in the return path from a shared library trampoline,
4701 we want to proceed through the trampoline when stepping. */
4702 /* macro/2012-04-25: This needs to come before the subroutine
4703 call check below as on some targets return trampolines look
4704 like subroutine calls (MIPS16 return thunks). */
4705 if (gdbarch_in_solib_return_trampoline (gdbarch
,
4706 stop_pc
, ecs
->stop_func_name
)
4707 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
4709 /* Determine where this trampoline returns. */
4710 CORE_ADDR real_stop_pc
;
4712 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
4715 fprintf_unfiltered (gdb_stdlog
,
4716 "infrun: stepped into solib return tramp\n");
4718 /* Only proceed through if we know where it's going. */
4721 /* And put the step-breakpoint there and go until there. */
4722 struct symtab_and_line sr_sal
;
4724 init_sal (&sr_sal
); /* initialize to zeroes */
4725 sr_sal
.pc
= real_stop_pc
;
4726 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
4727 sr_sal
.pspace
= get_frame_program_space (frame
);
4729 /* Do not specify what the fp should be when we stop since
4730 on some machines the prologue is where the new fp value
4732 insert_step_resume_breakpoint_at_sal (gdbarch
,
4733 sr_sal
, null_frame_id
);
4735 /* Restart without fiddling with the step ranges or
4742 /* Check for subroutine calls. The check for the current frame
4743 equalling the step ID is not necessary - the check of the
4744 previous frame's ID is sufficient - but it is a common case and
4745 cheaper than checking the previous frame's ID.
4747 NOTE: frame_id_eq will never report two invalid frame IDs as
4748 being equal, so to get into this block, both the current and
4749 previous frame must have valid frame IDs. */
4750 /* The outer_frame_id check is a heuristic to detect stepping
4751 through startup code. If we step over an instruction which
4752 sets the stack pointer from an invalid value to a valid value,
4753 we may detect that as a subroutine call from the mythical
4754 "outermost" function. This could be fixed by marking
4755 outermost frames as !stack_p,code_p,special_p. Then the
4756 initial outermost frame, before sp was valid, would
4757 have code_addr == &_start. See the comment in frame_id_eq
4759 if (!frame_id_eq (get_stack_frame_id (frame
),
4760 ecs
->event_thread
->control
.step_stack_frame_id
)
4761 && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()),
4762 ecs
->event_thread
->control
.step_stack_frame_id
)
4763 && (!frame_id_eq (ecs
->event_thread
->control
.step_stack_frame_id
,
4765 || step_start_function
!= find_pc_function (stop_pc
))))
4767 CORE_ADDR real_stop_pc
;
4770 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into subroutine\n");
4772 if ((ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_NONE
)
4773 || ((ecs
->event_thread
->control
.step_range_end
== 1)
4774 && in_prologue (gdbarch
, ecs
->event_thread
->prev_pc
,
4775 ecs
->stop_func_start
)))
4777 /* I presume that step_over_calls is only 0 when we're
4778 supposed to be stepping at the assembly language level
4779 ("stepi"). Just stop. */
4780 /* Also, maybe we just did a "nexti" inside a prolog, so we
4781 thought it was a subroutine call but it was not. Stop as
4783 /* And this works the same backward as frontward. MVS */
4784 ecs
->event_thread
->control
.stop_step
= 1;
4785 end_stepping_range ();
4786 stop_stepping (ecs
);
4790 /* Reverse stepping through solib trampolines. */
4792 if (execution_direction
== EXEC_REVERSE
4793 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
4794 && (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
4795 || (ecs
->stop_func_start
== 0
4796 && in_solib_dynsym_resolve_code (stop_pc
))))
4798 /* Any solib trampoline code can be handled in reverse
4799 by simply continuing to single-step. We have already
4800 executed the solib function (backwards), and a few
4801 steps will take us back through the trampoline to the
4807 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
4809 /* We're doing a "next".
4811 Normal (forward) execution: set a breakpoint at the
4812 callee's return address (the address at which the caller
4815 Reverse (backward) execution. set the step-resume
4816 breakpoint at the start of the function that we just
4817 stepped into (backwards), and continue to there. When we
4818 get there, we'll need to single-step back to the caller. */
4820 if (execution_direction
== EXEC_REVERSE
)
4822 /* If we're already at the start of the function, we've either
4823 just stepped backward into a single instruction function,
4824 or stepped back out of a signal handler to the first instruction
4825 of the function. Just keep going, which will single-step back
4827 if (ecs
->stop_func_start
!= stop_pc
&& ecs
->stop_func_start
!= 0)
4829 struct symtab_and_line sr_sal
;
4831 /* Normal function call return (static or dynamic). */
4833 sr_sal
.pc
= ecs
->stop_func_start
;
4834 sr_sal
.pspace
= get_frame_program_space (frame
);
4835 insert_step_resume_breakpoint_at_sal (gdbarch
,
4836 sr_sal
, null_frame_id
);
4840 insert_step_resume_breakpoint_at_caller (frame
);
4846 /* If we are in a function call trampoline (a stub between the
4847 calling routine and the real function), locate the real
4848 function. That's what tells us (a) whether we want to step
4849 into it at all, and (b) what prologue we want to run to the
4850 end of, if we do step into it. */
4851 real_stop_pc
= skip_language_trampoline (frame
, stop_pc
);
4852 if (real_stop_pc
== 0)
4853 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
4854 if (real_stop_pc
!= 0)
4855 ecs
->stop_func_start
= real_stop_pc
;
4857 if (real_stop_pc
!= 0 && in_solib_dynsym_resolve_code (real_stop_pc
))
4859 struct symtab_and_line sr_sal
;
4862 sr_sal
.pc
= ecs
->stop_func_start
;
4863 sr_sal
.pspace
= get_frame_program_space (frame
);
4865 insert_step_resume_breakpoint_at_sal (gdbarch
,
4866 sr_sal
, null_frame_id
);
4871 /* If we have line number information for the function we are
4872 thinking of stepping into and the function isn't on the skip
4875 If there are several symtabs at that PC (e.g. with include
4876 files), just want to know whether *any* of them have line
4877 numbers. find_pc_line handles this. */
4879 struct symtab_and_line tmp_sal
;
4881 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
4882 if (tmp_sal
.line
!= 0
4883 && !function_name_is_marked_for_skip (ecs
->stop_func_name
,
4886 if (execution_direction
== EXEC_REVERSE
)
4887 handle_step_into_function_backward (gdbarch
, ecs
);
4889 handle_step_into_function (gdbarch
, ecs
);
4894 /* If we have no line number and the step-stop-if-no-debug is
4895 set, we stop the step so that the user has a chance to switch
4896 in assembly mode. */
4897 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
4898 && step_stop_if_no_debug
)
4900 ecs
->event_thread
->control
.stop_step
= 1;
4901 end_stepping_range ();
4902 stop_stepping (ecs
);
4906 if (execution_direction
== EXEC_REVERSE
)
4908 /* If we're already at the start of the function, we've either just
4909 stepped backward into a single instruction function without line
4910 number info, or stepped back out of a signal handler to the first
4911 instruction of the function without line number info. Just keep
4912 going, which will single-step back to the caller. */
4913 if (ecs
->stop_func_start
!= stop_pc
)
4915 /* Set a breakpoint at callee's start address.
4916 From there we can step once and be back in the caller. */
4917 struct symtab_and_line sr_sal
;
4920 sr_sal
.pc
= ecs
->stop_func_start
;
4921 sr_sal
.pspace
= get_frame_program_space (frame
);
4922 insert_step_resume_breakpoint_at_sal (gdbarch
,
4923 sr_sal
, null_frame_id
);
4927 /* Set a breakpoint at callee's return address (the address
4928 at which the caller will resume). */
4929 insert_step_resume_breakpoint_at_caller (frame
);
4935 /* Reverse stepping through solib trampolines. */
4937 if (execution_direction
== EXEC_REVERSE
4938 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
4940 if (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
4941 || (ecs
->stop_func_start
== 0
4942 && in_solib_dynsym_resolve_code (stop_pc
)))
4944 /* Any solib trampoline code can be handled in reverse
4945 by simply continuing to single-step. We have already
4946 executed the solib function (backwards), and a few
4947 steps will take us back through the trampoline to the
4952 else if (in_solib_dynsym_resolve_code (stop_pc
))
4954 /* Stepped backward into the solib dynsym resolver.
4955 Set a breakpoint at its start and continue, then
4956 one more step will take us out. */
4957 struct symtab_and_line sr_sal
;
4960 sr_sal
.pc
= ecs
->stop_func_start
;
4961 sr_sal
.pspace
= get_frame_program_space (frame
);
4962 insert_step_resume_breakpoint_at_sal (gdbarch
,
4963 sr_sal
, null_frame_id
);
4969 stop_pc_sal
= find_pc_line (stop_pc
, 0);
4971 /* NOTE: tausq/2004-05-24: This if block used to be done before all
4972 the trampoline processing logic, however, there are some trampolines
4973 that have no names, so we should do trampoline handling first. */
4974 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
4975 && ecs
->stop_func_name
== NULL
4976 && stop_pc_sal
.line
== 0)
4979 fprintf_unfiltered (gdb_stdlog
,
4980 "infrun: stepped into undebuggable function\n");
4982 /* The inferior just stepped into, or returned to, an
4983 undebuggable function (where there is no debugging information
4984 and no line number corresponding to the address where the
4985 inferior stopped). Since we want to skip this kind of code,
4986 we keep going until the inferior returns from this
4987 function - unless the user has asked us not to (via
4988 set step-mode) or we no longer know how to get back
4989 to the call site. */
4990 if (step_stop_if_no_debug
4991 || !frame_id_p (frame_unwind_caller_id (frame
)))
4993 /* If we have no line number and the step-stop-if-no-debug
4994 is set, we stop the step so that the user has a chance to
4995 switch in assembly mode. */
4996 ecs
->event_thread
->control
.stop_step
= 1;
4997 end_stepping_range ();
4998 stop_stepping (ecs
);
5003 /* Set a breakpoint at callee's return address (the address
5004 at which the caller will resume). */
5005 insert_step_resume_breakpoint_at_caller (frame
);
5011 if (ecs
->event_thread
->control
.step_range_end
== 1)
5013 /* It is stepi or nexti. We always want to stop stepping after
5016 fprintf_unfiltered (gdb_stdlog
, "infrun: stepi/nexti\n");
5017 ecs
->event_thread
->control
.stop_step
= 1;
5018 end_stepping_range ();
5019 stop_stepping (ecs
);
5023 if (stop_pc_sal
.line
== 0)
5025 /* We have no line number information. That means to stop
5026 stepping (does this always happen right after one instruction,
5027 when we do "s" in a function with no line numbers,
5028 or can this happen as a result of a return or longjmp?). */
5030 fprintf_unfiltered (gdb_stdlog
, "infrun: no line number info\n");
5031 ecs
->event_thread
->control
.stop_step
= 1;
5032 end_stepping_range ();
5033 stop_stepping (ecs
);
5037 /* Look for "calls" to inlined functions, part one. If the inline
5038 frame machinery detected some skipped call sites, we have entered
5039 a new inline function. */
5041 if (frame_id_eq (get_frame_id (get_current_frame ()),
5042 ecs
->event_thread
->control
.step_frame_id
)
5043 && inline_skipped_frames (ecs
->ptid
))
5045 struct symtab_and_line call_sal
;
5048 fprintf_unfiltered (gdb_stdlog
,
5049 "infrun: stepped into inlined function\n");
5051 find_frame_sal (get_current_frame (), &call_sal
);
5053 if (ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_ALL
)
5055 /* For "step", we're going to stop. But if the call site
5056 for this inlined function is on the same source line as
5057 we were previously stepping, go down into the function
5058 first. Otherwise stop at the call site. */
5060 if (call_sal
.line
== ecs
->event_thread
->current_line
5061 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
5062 step_into_inline_frame (ecs
->ptid
);
5064 ecs
->event_thread
->control
.stop_step
= 1;
5065 end_stepping_range ();
5066 stop_stepping (ecs
);
5071 /* For "next", we should stop at the call site if it is on a
5072 different source line. Otherwise continue through the
5073 inlined function. */
5074 if (call_sal
.line
== ecs
->event_thread
->current_line
5075 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
5079 ecs
->event_thread
->control
.stop_step
= 1;
5080 end_stepping_range ();
5081 stop_stepping (ecs
);
5087 /* Look for "calls" to inlined functions, part two. If we are still
5088 in the same real function we were stepping through, but we have
5089 to go further up to find the exact frame ID, we are stepping
5090 through a more inlined call beyond its call site. */
5092 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
5093 && !frame_id_eq (get_frame_id (get_current_frame ()),
5094 ecs
->event_thread
->control
.step_frame_id
)
5095 && stepped_in_from (get_current_frame (),
5096 ecs
->event_thread
->control
.step_frame_id
))
5099 fprintf_unfiltered (gdb_stdlog
,
5100 "infrun: stepping through inlined function\n");
5102 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
5106 ecs
->event_thread
->control
.stop_step
= 1;
5107 end_stepping_range ();
5108 stop_stepping (ecs
);
5113 if ((stop_pc
== stop_pc_sal
.pc
)
5114 && (ecs
->event_thread
->current_line
!= stop_pc_sal
.line
5115 || ecs
->event_thread
->current_symtab
!= stop_pc_sal
.symtab
))
5117 /* We are at the start of a different line. So stop. Note that
5118 we don't stop if we step into the middle of a different line.
5119 That is said to make things like for (;;) statements work
5122 fprintf_unfiltered (gdb_stdlog
,
5123 "infrun: stepped to a different line\n");
5124 ecs
->event_thread
->control
.stop_step
= 1;
5125 end_stepping_range ();
5126 stop_stepping (ecs
);
5130 /* We aren't done stepping.
5132 Optimize by setting the stepping range to the line.
5133 (We might not be in the original line, but if we entered a
5134 new line in mid-statement, we continue stepping. This makes
5135 things like for(;;) statements work better.) */
5137 ecs
->event_thread
->control
.step_range_start
= stop_pc_sal
.pc
;
5138 ecs
->event_thread
->control
.step_range_end
= stop_pc_sal
.end
;
5139 ecs
->event_thread
->control
.may_range_step
= 1;
5140 set_step_info (frame
, stop_pc_sal
);
5143 fprintf_unfiltered (gdb_stdlog
, "infrun: keep going\n");
5147 /* In all-stop mode, if we're currently stepping but have stopped in
5148 some other thread, we may need to switch back to the stepped
5149 thread. Returns true we set the inferior running, false if we left
5150 it stopped (and the event needs further processing). */
5153 switch_back_to_stepped_thread (struct execution_control_state
*ecs
)
5157 struct thread_info
*tp
;
5158 struct thread_info
*stepping_thread
;
5159 struct thread_info
*step_over
;
5161 /* If any thread is blocked on some internal breakpoint, and we
5162 simply need to step over that breakpoint to get it going
5163 again, do that first. */
5165 /* However, if we see an event for the stepping thread, then we
5166 know all other threads have been moved past their breakpoints
5167 already. Let the caller check whether the step is finished,
5168 etc., before deciding to move it past a breakpoint. */
5169 if (ecs
->event_thread
->control
.step_range_end
!= 0)
5172 /* Check if the current thread is blocked on an incomplete
5173 step-over, interrupted by a random signal. */
5174 if (ecs
->event_thread
->control
.trap_expected
5175 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_TRAP
)
5179 fprintf_unfiltered (gdb_stdlog
,
5180 "infrun: need to finish step-over of [%s]\n",
5181 target_pid_to_str (ecs
->event_thread
->ptid
));
5187 /* Check if the current thread is blocked by a single-step
5188 breakpoint of another thread. */
5189 if (ecs
->hit_singlestep_breakpoint
)
5193 fprintf_unfiltered (gdb_stdlog
,
5194 "infrun: need to step [%s] over single-step "
5196 target_pid_to_str (ecs
->ptid
));
5202 /* Otherwise, we no longer expect a trap in the current thread.
5203 Clear the trap_expected flag before switching back -- this is
5204 what keep_going does as well, if we call it. */
5205 ecs
->event_thread
->control
.trap_expected
= 0;
5207 /* If scheduler locking applies even if not stepping, there's no
5208 need to walk over threads. Above we've checked whether the
5209 current thread is stepping. If some other thread not the
5210 event thread is stepping, then it must be that scheduler
5211 locking is not in effect. */
5212 if (schedlock_applies (0))
5215 /* Look for the stepping/nexting thread, and check if any other
5216 thread other than the stepping thread needs to start a
5217 step-over. Do all step-overs before actually proceeding with
5219 stepping_thread
= NULL
;
5223 /* Ignore threads of processes we're not resuming. */
5225 && ptid_get_pid (tp
->ptid
) != ptid_get_pid (inferior_ptid
))
5228 /* When stepping over a breakpoint, we lock all threads
5229 except the one that needs to move past the breakpoint.
5230 If a non-event thread has this set, the "incomplete
5231 step-over" check above should have caught it earlier. */
5232 gdb_assert (!tp
->control
.trap_expected
);
5234 /* Did we find the stepping thread? */
5235 if (tp
->control
.step_range_end
)
5237 /* Yep. There should only one though. */
5238 gdb_assert (stepping_thread
== NULL
);
5240 /* The event thread is handled at the top, before we
5242 gdb_assert (tp
!= ecs
->event_thread
);
5244 /* If some thread other than the event thread is
5245 stepping, then scheduler locking can't be in effect,
5246 otherwise we wouldn't have resumed the current event
5247 thread in the first place. */
5248 gdb_assert (!schedlock_applies (1));
5250 stepping_thread
= tp
;
5252 else if (thread_still_needs_step_over (tp
))
5256 /* At the top we've returned early if the event thread
5257 is stepping. If some other thread not the event
5258 thread is stepping, then scheduler locking can't be
5259 in effect, and we can resume this thread. No need to
5260 keep looking for the stepping thread then. */
5265 if (step_over
!= NULL
)
5270 fprintf_unfiltered (gdb_stdlog
,
5271 "infrun: need to step-over [%s]\n",
5272 target_pid_to_str (tp
->ptid
));
5275 /* Only the stepping thread should have this set. */
5276 gdb_assert (tp
->control
.step_range_end
== 0);
5278 ecs
->ptid
= tp
->ptid
;
5279 ecs
->event_thread
= tp
;
5280 switch_to_thread (ecs
->ptid
);
5285 if (stepping_thread
!= NULL
)
5287 struct frame_info
*frame
;
5288 struct gdbarch
*gdbarch
;
5290 tp
= stepping_thread
;
5292 /* If the stepping thread exited, then don't try to switch
5293 back and resume it, which could fail in several different
5294 ways depending on the target. Instead, just keep going.
5296 We can find a stepping dead thread in the thread list in
5299 - The target supports thread exit events, and when the
5300 target tries to delete the thread from the thread list,
5301 inferior_ptid pointed at the exiting thread. In such
5302 case, calling delete_thread does not really remove the
5303 thread from the list; instead, the thread is left listed,
5304 with 'exited' state.
5306 - The target's debug interface does not support thread
5307 exit events, and so we have no idea whatsoever if the
5308 previously stepping thread is still alive. For that
5309 reason, we need to synchronously query the target
5311 if (is_exited (tp
->ptid
)
5312 || !target_thread_alive (tp
->ptid
))
5315 fprintf_unfiltered (gdb_stdlog
,
5316 "infrun: not switching back to "
5317 "stepped thread, it has vanished\n");
5319 delete_thread (tp
->ptid
);
5325 fprintf_unfiltered (gdb_stdlog
,
5326 "infrun: switching back to stepped thread\n");
5328 ecs
->event_thread
= tp
;
5329 ecs
->ptid
= tp
->ptid
;
5330 context_switch (ecs
->ptid
);
5332 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
5333 frame
= get_current_frame ();
5334 gdbarch
= get_frame_arch (frame
);
5336 /* If the PC of the thread we were trying to single-step has
5337 changed, then that thread has trapped or been signaled,
5338 but the event has not been reported to GDB yet. Re-poll
5339 the target looking for this particular thread's event
5340 (i.e. temporarily enable schedlock) by:
5342 - setting a break at the current PC
5343 - resuming that particular thread, only (by setting
5346 This prevents us continuously moving the single-step
5347 breakpoint forward, one instruction at a time,
5350 if (gdbarch_software_single_step_p (gdbarch
)
5351 && stop_pc
!= tp
->prev_pc
)
5354 fprintf_unfiltered (gdb_stdlog
,
5355 "infrun: expected thread advanced also\n");
5357 insert_single_step_breakpoint (get_frame_arch (frame
),
5358 get_frame_address_space (frame
),
5360 singlestep_breakpoints_inserted_p
= 1;
5361 ecs
->event_thread
->control
.trap_expected
= 1;
5362 singlestep_ptid
= inferior_ptid
;
5363 singlestep_pc
= stop_pc
;
5365 resume (0, GDB_SIGNAL_0
);
5366 prepare_to_wait (ecs
);
5371 fprintf_unfiltered (gdb_stdlog
,
5372 "infrun: expected thread still "
5373 "hasn't advanced\n");
5383 /* Is thread TP in the middle of single-stepping? */
5386 currently_stepping (struct thread_info
*tp
)
5388 return ((tp
->control
.step_range_end
5389 && tp
->control
.step_resume_breakpoint
== NULL
)
5390 || tp
->control
.trap_expected
5391 || bpstat_should_step ());
5394 /* Inferior has stepped into a subroutine call with source code that
5395 we should not step over. Do step to the first line of code in
5399 handle_step_into_function (struct gdbarch
*gdbarch
,
5400 struct execution_control_state
*ecs
)
5403 struct symtab_and_line stop_func_sal
, sr_sal
;
5405 fill_in_stop_func (gdbarch
, ecs
);
5407 s
= find_pc_symtab (stop_pc
);
5408 if (s
&& s
->language
!= language_asm
)
5409 ecs
->stop_func_start
= gdbarch_skip_prologue (gdbarch
,
5410 ecs
->stop_func_start
);
5412 stop_func_sal
= find_pc_line (ecs
->stop_func_start
, 0);
5413 /* Use the step_resume_break to step until the end of the prologue,
5414 even if that involves jumps (as it seems to on the vax under
5416 /* If the prologue ends in the middle of a source line, continue to
5417 the end of that source line (if it is still within the function).
5418 Otherwise, just go to end of prologue. */
5419 if (stop_func_sal
.end
5420 && stop_func_sal
.pc
!= ecs
->stop_func_start
5421 && stop_func_sal
.end
< ecs
->stop_func_end
)
5422 ecs
->stop_func_start
= stop_func_sal
.end
;
5424 /* Architectures which require breakpoint adjustment might not be able
5425 to place a breakpoint at the computed address. If so, the test
5426 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
5427 ecs->stop_func_start to an address at which a breakpoint may be
5428 legitimately placed.
5430 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
5431 made, GDB will enter an infinite loop when stepping through
5432 optimized code consisting of VLIW instructions which contain
5433 subinstructions corresponding to different source lines. On
5434 FR-V, it's not permitted to place a breakpoint on any but the
5435 first subinstruction of a VLIW instruction. When a breakpoint is
5436 set, GDB will adjust the breakpoint address to the beginning of
5437 the VLIW instruction. Thus, we need to make the corresponding
5438 adjustment here when computing the stop address. */
5440 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
5442 ecs
->stop_func_start
5443 = gdbarch_adjust_breakpoint_address (gdbarch
,
5444 ecs
->stop_func_start
);
5447 if (ecs
->stop_func_start
== stop_pc
)
5449 /* We are already there: stop now. */
5450 ecs
->event_thread
->control
.stop_step
= 1;
5451 end_stepping_range ();
5452 stop_stepping (ecs
);
5457 /* Put the step-breakpoint there and go until there. */
5458 init_sal (&sr_sal
); /* initialize to zeroes */
5459 sr_sal
.pc
= ecs
->stop_func_start
;
5460 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
5461 sr_sal
.pspace
= get_frame_program_space (get_current_frame ());
5463 /* Do not specify what the fp should be when we stop since on
5464 some machines the prologue is where the new fp value is
5466 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
, null_frame_id
);
5468 /* And make sure stepping stops right away then. */
5469 ecs
->event_thread
->control
.step_range_end
5470 = ecs
->event_thread
->control
.step_range_start
;
5475 /* Inferior has stepped backward into a subroutine call with source
5476 code that we should not step over. Do step to the beginning of the
5477 last line of code in it. */
5480 handle_step_into_function_backward (struct gdbarch
*gdbarch
,
5481 struct execution_control_state
*ecs
)
5484 struct symtab_and_line stop_func_sal
;
5486 fill_in_stop_func (gdbarch
, ecs
);
5488 s
= find_pc_symtab (stop_pc
);
5489 if (s
&& s
->language
!= language_asm
)
5490 ecs
->stop_func_start
= gdbarch_skip_prologue (gdbarch
,
5491 ecs
->stop_func_start
);
5493 stop_func_sal
= find_pc_line (stop_pc
, 0);
5495 /* OK, we're just going to keep stepping here. */
5496 if (stop_func_sal
.pc
== stop_pc
)
5498 /* We're there already. Just stop stepping now. */
5499 ecs
->event_thread
->control
.stop_step
= 1;
5500 end_stepping_range ();
5501 stop_stepping (ecs
);
5505 /* Else just reset the step range and keep going.
5506 No step-resume breakpoint, they don't work for
5507 epilogues, which can have multiple entry paths. */
5508 ecs
->event_thread
->control
.step_range_start
= stop_func_sal
.pc
;
5509 ecs
->event_thread
->control
.step_range_end
= stop_func_sal
.end
;
5515 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
5516 This is used to both functions and to skip over code. */
5519 insert_step_resume_breakpoint_at_sal_1 (struct gdbarch
*gdbarch
,
5520 struct symtab_and_line sr_sal
,
5521 struct frame_id sr_id
,
5522 enum bptype sr_type
)
5524 /* There should never be more than one step-resume or longjmp-resume
5525 breakpoint per thread, so we should never be setting a new
5526 step_resume_breakpoint when one is already active. */
5527 gdb_assert (inferior_thread ()->control
.step_resume_breakpoint
== NULL
);
5528 gdb_assert (sr_type
== bp_step_resume
|| sr_type
== bp_hp_step_resume
);
5531 fprintf_unfiltered (gdb_stdlog
,
5532 "infrun: inserting step-resume breakpoint at %s\n",
5533 paddress (gdbarch
, sr_sal
.pc
));
5535 inferior_thread ()->control
.step_resume_breakpoint
5536 = set_momentary_breakpoint (gdbarch
, sr_sal
, sr_id
, sr_type
);
5540 insert_step_resume_breakpoint_at_sal (struct gdbarch
*gdbarch
,
5541 struct symtab_and_line sr_sal
,
5542 struct frame_id sr_id
)
5544 insert_step_resume_breakpoint_at_sal_1 (gdbarch
,
5549 /* Insert a "high-priority step-resume breakpoint" at RETURN_FRAME.pc.
5550 This is used to skip a potential signal handler.
5552 This is called with the interrupted function's frame. The signal
5553 handler, when it returns, will resume the interrupted function at
5557 insert_hp_step_resume_breakpoint_at_frame (struct frame_info
*return_frame
)
5559 struct symtab_and_line sr_sal
;
5560 struct gdbarch
*gdbarch
;
5562 gdb_assert (return_frame
!= NULL
);
5563 init_sal (&sr_sal
); /* initialize to zeros */
5565 gdbarch
= get_frame_arch (return_frame
);
5566 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
, get_frame_pc (return_frame
));
5567 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
5568 sr_sal
.pspace
= get_frame_program_space (return_frame
);
5570 insert_step_resume_breakpoint_at_sal_1 (gdbarch
, sr_sal
,
5571 get_stack_frame_id (return_frame
),
5575 /* Insert a "step-resume breakpoint" at the previous frame's PC. This
5576 is used to skip a function after stepping into it (for "next" or if
5577 the called function has no debugging information).
5579 The current function has almost always been reached by single
5580 stepping a call or return instruction. NEXT_FRAME belongs to the
5581 current function, and the breakpoint will be set at the caller's
5584 This is a separate function rather than reusing
5585 insert_hp_step_resume_breakpoint_at_frame in order to avoid
5586 get_prev_frame, which may stop prematurely (see the implementation
5587 of frame_unwind_caller_id for an example). */
5590 insert_step_resume_breakpoint_at_caller (struct frame_info
*next_frame
)
5592 struct symtab_and_line sr_sal
;
5593 struct gdbarch
*gdbarch
;
5595 /* We shouldn't have gotten here if we don't know where the call site
5597 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame
)));
5599 init_sal (&sr_sal
); /* initialize to zeros */
5601 gdbarch
= frame_unwind_caller_arch (next_frame
);
5602 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
,
5603 frame_unwind_caller_pc (next_frame
));
5604 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
5605 sr_sal
.pspace
= frame_unwind_program_space (next_frame
);
5607 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
,
5608 frame_unwind_caller_id (next_frame
));
5611 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
5612 new breakpoint at the target of a jmp_buf. The handling of
5613 longjmp-resume uses the same mechanisms used for handling
5614 "step-resume" breakpoints. */
5617 insert_longjmp_resume_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
5619 /* There should never be more than one longjmp-resume breakpoint per
5620 thread, so we should never be setting a new
5621 longjmp_resume_breakpoint when one is already active. */
5622 gdb_assert (inferior_thread ()->control
.exception_resume_breakpoint
== NULL
);
5625 fprintf_unfiltered (gdb_stdlog
,
5626 "infrun: inserting longjmp-resume breakpoint at %s\n",
5627 paddress (gdbarch
, pc
));
5629 inferior_thread ()->control
.exception_resume_breakpoint
=
5630 set_momentary_breakpoint_at_pc (gdbarch
, pc
, bp_longjmp_resume
);
5633 /* Insert an exception resume breakpoint. TP is the thread throwing
5634 the exception. The block B is the block of the unwinder debug hook
5635 function. FRAME is the frame corresponding to the call to this
5636 function. SYM is the symbol of the function argument holding the
5637 target PC of the exception. */
5640 insert_exception_resume_breakpoint (struct thread_info
*tp
,
5642 struct frame_info
*frame
,
5645 volatile struct gdb_exception e
;
5647 /* We want to ignore errors here. */
5648 TRY_CATCH (e
, RETURN_MASK_ERROR
)
5650 struct symbol
*vsym
;
5651 struct value
*value
;
5653 struct breakpoint
*bp
;
5655 vsym
= lookup_symbol (SYMBOL_LINKAGE_NAME (sym
), b
, VAR_DOMAIN
, NULL
);
5656 value
= read_var_value (vsym
, frame
);
5657 /* If the value was optimized out, revert to the old behavior. */
5658 if (! value_optimized_out (value
))
5660 handler
= value_as_address (value
);
5663 fprintf_unfiltered (gdb_stdlog
,
5664 "infrun: exception resume at %lx\n",
5665 (unsigned long) handler
);
5667 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
5668 handler
, bp_exception_resume
);
5670 /* set_momentary_breakpoint_at_pc invalidates FRAME. */
5673 bp
->thread
= tp
->num
;
5674 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
5679 /* A helper for check_exception_resume that sets an
5680 exception-breakpoint based on a SystemTap probe. */
5683 insert_exception_resume_from_probe (struct thread_info
*tp
,
5684 const struct bound_probe
*probe
,
5685 struct frame_info
*frame
)
5687 struct value
*arg_value
;
5689 struct breakpoint
*bp
;
5691 arg_value
= probe_safe_evaluate_at_pc (frame
, 1);
5695 handler
= value_as_address (arg_value
);
5698 fprintf_unfiltered (gdb_stdlog
,
5699 "infrun: exception resume at %s\n",
5700 paddress (get_objfile_arch (probe
->objfile
),
5703 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
5704 handler
, bp_exception_resume
);
5705 bp
->thread
= tp
->num
;
5706 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
5709 /* This is called when an exception has been intercepted. Check to
5710 see whether the exception's destination is of interest, and if so,
5711 set an exception resume breakpoint there. */
5714 check_exception_resume (struct execution_control_state
*ecs
,
5715 struct frame_info
*frame
)
5717 volatile struct gdb_exception e
;
5718 struct bound_probe probe
;
5719 struct symbol
*func
;
5721 /* First see if this exception unwinding breakpoint was set via a
5722 SystemTap probe point. If so, the probe has two arguments: the
5723 CFA and the HANDLER. We ignore the CFA, extract the handler, and
5724 set a breakpoint there. */
5725 probe
= find_probe_by_pc (get_frame_pc (frame
));
5728 insert_exception_resume_from_probe (ecs
->event_thread
, &probe
, frame
);
5732 func
= get_frame_function (frame
);
5736 TRY_CATCH (e
, RETURN_MASK_ERROR
)
5739 struct block_iterator iter
;
5743 /* The exception breakpoint is a thread-specific breakpoint on
5744 the unwinder's debug hook, declared as:
5746 void _Unwind_DebugHook (void *cfa, void *handler);
5748 The CFA argument indicates the frame to which control is
5749 about to be transferred. HANDLER is the destination PC.
5751 We ignore the CFA and set a temporary breakpoint at HANDLER.
5752 This is not extremely efficient but it avoids issues in gdb
5753 with computing the DWARF CFA, and it also works even in weird
5754 cases such as throwing an exception from inside a signal
5757 b
= SYMBOL_BLOCK_VALUE (func
);
5758 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
5760 if (!SYMBOL_IS_ARGUMENT (sym
))
5767 insert_exception_resume_breakpoint (ecs
->event_thread
,
5776 stop_stepping (struct execution_control_state
*ecs
)
5779 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_stepping\n");
5781 clear_step_over_info ();
5783 /* Let callers know we don't want to wait for the inferior anymore. */
5784 ecs
->wait_some_more
= 0;
5787 /* Called when we should continue running the inferior, because the
5788 current event doesn't cause a user visible stop. This does the
5789 resuming part; waiting for the next event is done elsewhere. */
5792 keep_going (struct execution_control_state
*ecs
)
5794 /* Make sure normal_stop is called if we get a QUIT handled before
5796 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
5798 /* Save the pc before execution, to compare with pc after stop. */
5799 ecs
->event_thread
->prev_pc
5800 = regcache_read_pc (get_thread_regcache (ecs
->ptid
));
5802 if (ecs
->event_thread
->control
.trap_expected
5803 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_TRAP
)
5805 /* We haven't yet gotten our trap, and either: intercepted a
5806 non-signal event (e.g., a fork); or took a signal which we
5807 are supposed to pass through to the inferior. Simply
5809 discard_cleanups (old_cleanups
);
5810 resume (currently_stepping (ecs
->event_thread
),
5811 ecs
->event_thread
->suspend
.stop_signal
);
5815 volatile struct gdb_exception e
;
5816 struct regcache
*regcache
= get_current_regcache ();
5818 /* Either the trap was not expected, but we are continuing
5819 anyway (if we got a signal, the user asked it be passed to
5822 We got our expected trap, but decided we should resume from
5825 We're going to run this baby now!
5827 Note that insert_breakpoints won't try to re-insert
5828 already inserted breakpoints. Therefore, we don't
5829 care if breakpoints were already inserted, or not. */
5831 /* If we need to step over a breakpoint, and we're not using
5832 displaced stepping to do so, insert all breakpoints
5833 (watchpoints, etc.) but the one we're stepping over, step one
5834 instruction, and then re-insert the breakpoint when that step
5836 if ((ecs
->hit_singlestep_breakpoint
5837 || thread_still_needs_step_over (ecs
->event_thread
))
5838 && !use_displaced_stepping (get_regcache_arch (regcache
)))
5840 set_step_over_info (get_regcache_aspace (regcache
),
5841 regcache_read_pc (regcache
));
5844 clear_step_over_info ();
5846 /* Stop stepping if inserting breakpoints fails. */
5847 TRY_CATCH (e
, RETURN_MASK_ERROR
)
5849 insert_breakpoints ();
5853 exception_print (gdb_stderr
, e
);
5854 stop_stepping (ecs
);
5858 ecs
->event_thread
->control
.trap_expected
5859 = (ecs
->event_thread
->stepping_over_breakpoint
5860 || ecs
->hit_singlestep_breakpoint
);
5862 /* Do not deliver GDB_SIGNAL_TRAP (except when the user
5863 explicitly specifies that such a signal should be delivered
5864 to the target program). Typically, that would occur when a
5865 user is debugging a target monitor on a simulator: the target
5866 monitor sets a breakpoint; the simulator encounters this
5867 breakpoint and halts the simulation handing control to GDB;
5868 GDB, noting that the stop address doesn't map to any known
5869 breakpoint, returns control back to the simulator; the
5870 simulator then delivers the hardware equivalent of a
5871 GDB_SIGNAL_TRAP to the program being debugged. */
5872 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
5873 && !signal_program
[ecs
->event_thread
->suspend
.stop_signal
])
5874 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5876 discard_cleanups (old_cleanups
);
5877 resume (currently_stepping (ecs
->event_thread
),
5878 ecs
->event_thread
->suspend
.stop_signal
);
5881 prepare_to_wait (ecs
);
5884 /* This function normally comes after a resume, before
5885 handle_inferior_event exits. It takes care of any last bits of
5886 housekeeping, and sets the all-important wait_some_more flag. */
5889 prepare_to_wait (struct execution_control_state
*ecs
)
5892 fprintf_unfiltered (gdb_stdlog
, "infrun: prepare_to_wait\n");
5894 /* This is the old end of the while loop. Let everybody know we
5895 want to wait for the inferior some more and get called again
5897 ecs
->wait_some_more
= 1;
5900 /* We are done with the step range of a step/next/si/ni command.
5901 Called once for each n of a "step n" operation. Notify observers
5902 if not in the middle of doing a "step N" operation for N > 1. */
5905 end_stepping_range (void)
5907 if (inferior_thread ()->step_multi
5908 && inferior_thread ()->control
.stop_step
)
5911 observer_notify_end_stepping_range ();
5914 /* Several print_*_reason functions to print why the inferior has stopped.
5915 We always print something when the inferior exits, or receives a signal.
5916 The rest of the cases are dealt with later on in normal_stop and
5917 print_it_typical. Ideally there should be a call to one of these
5918 print_*_reason functions functions from handle_inferior_event each time
5919 stop_stepping is called.
5921 Note that we don't call these directly, instead we delegate that to
5922 the interpreters, through observers. Interpreters then call these
5923 with whatever uiout is right. */
5926 print_end_stepping_range_reason (struct ui_out
*uiout
)
5928 /* For CLI-like interpreters, print nothing. */
5930 if (ui_out_is_mi_like_p (uiout
))
5932 ui_out_field_string (uiout
, "reason",
5933 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE
));
5938 print_signal_exited_reason (struct ui_out
*uiout
, enum gdb_signal siggnal
)
5940 annotate_signalled ();
5941 if (ui_out_is_mi_like_p (uiout
))
5943 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED
));
5944 ui_out_text (uiout
, "\nProgram terminated with signal ");
5945 annotate_signal_name ();
5946 ui_out_field_string (uiout
, "signal-name",
5947 gdb_signal_to_name (siggnal
));
5948 annotate_signal_name_end ();
5949 ui_out_text (uiout
, ", ");
5950 annotate_signal_string ();
5951 ui_out_field_string (uiout
, "signal-meaning",
5952 gdb_signal_to_string (siggnal
));
5953 annotate_signal_string_end ();
5954 ui_out_text (uiout
, ".\n");
5955 ui_out_text (uiout
, "The program no longer exists.\n");
5959 print_exited_reason (struct ui_out
*uiout
, int exitstatus
)
5961 struct inferior
*inf
= current_inferior ();
5962 const char *pidstr
= target_pid_to_str (pid_to_ptid (inf
->pid
));
5964 annotate_exited (exitstatus
);
5967 if (ui_out_is_mi_like_p (uiout
))
5968 ui_out_field_string (uiout
, "reason",
5969 async_reason_lookup (EXEC_ASYNC_EXITED
));
5970 ui_out_text (uiout
, "[Inferior ");
5971 ui_out_text (uiout
, plongest (inf
->num
));
5972 ui_out_text (uiout
, " (");
5973 ui_out_text (uiout
, pidstr
);
5974 ui_out_text (uiout
, ") exited with code ");
5975 ui_out_field_fmt (uiout
, "exit-code", "0%o", (unsigned int) exitstatus
);
5976 ui_out_text (uiout
, "]\n");
5980 if (ui_out_is_mi_like_p (uiout
))
5982 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY
));
5983 ui_out_text (uiout
, "[Inferior ");
5984 ui_out_text (uiout
, plongest (inf
->num
));
5985 ui_out_text (uiout
, " (");
5986 ui_out_text (uiout
, pidstr
);
5987 ui_out_text (uiout
, ") exited normally]\n");
5992 print_signal_received_reason (struct ui_out
*uiout
, enum gdb_signal siggnal
)
5996 if (siggnal
== GDB_SIGNAL_0
&& !ui_out_is_mi_like_p (uiout
))
5998 struct thread_info
*t
= inferior_thread ();
6000 ui_out_text (uiout
, "\n[");
6001 ui_out_field_string (uiout
, "thread-name",
6002 target_pid_to_str (t
->ptid
));
6003 ui_out_field_fmt (uiout
, "thread-id", "] #%d", t
->num
);
6004 ui_out_text (uiout
, " stopped");
6008 ui_out_text (uiout
, "\nProgram received signal ");
6009 annotate_signal_name ();
6010 if (ui_out_is_mi_like_p (uiout
))
6012 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED
));
6013 ui_out_field_string (uiout
, "signal-name",
6014 gdb_signal_to_name (siggnal
));
6015 annotate_signal_name_end ();
6016 ui_out_text (uiout
, ", ");
6017 annotate_signal_string ();
6018 ui_out_field_string (uiout
, "signal-meaning",
6019 gdb_signal_to_string (siggnal
));
6020 annotate_signal_string_end ();
6022 ui_out_text (uiout
, ".\n");
6026 print_no_history_reason (struct ui_out
*uiout
)
6028 ui_out_text (uiout
, "\nNo more reverse-execution history.\n");
6031 /* Print current location without a level number, if we have changed
6032 functions or hit a breakpoint. Print source line if we have one.
6033 bpstat_print contains the logic deciding in detail what to print,
6034 based on the event(s) that just occurred. */
6037 print_stop_event (struct target_waitstatus
*ws
)
6041 int do_frame_printing
= 1;
6042 struct thread_info
*tp
= inferior_thread ();
6044 bpstat_ret
= bpstat_print (tp
->control
.stop_bpstat
, ws
->kind
);
6048 /* FIXME: cagney/2002-12-01: Given that a frame ID does (or
6049 should) carry around the function and does (or should) use
6050 that when doing a frame comparison. */
6051 if (tp
->control
.stop_step
6052 && frame_id_eq (tp
->control
.step_frame_id
,
6053 get_frame_id (get_current_frame ()))
6054 && step_start_function
== find_pc_function (stop_pc
))
6056 /* Finished step, just print source line. */
6057 source_flag
= SRC_LINE
;
6061 /* Print location and source line. */
6062 source_flag
= SRC_AND_LOC
;
6065 case PRINT_SRC_AND_LOC
:
6066 /* Print location and source line. */
6067 source_flag
= SRC_AND_LOC
;
6069 case PRINT_SRC_ONLY
:
6070 source_flag
= SRC_LINE
;
6073 /* Something bogus. */
6074 source_flag
= SRC_LINE
;
6075 do_frame_printing
= 0;
6078 internal_error (__FILE__
, __LINE__
, _("Unknown value."));
6081 /* The behavior of this routine with respect to the source
6083 SRC_LINE: Print only source line
6084 LOCATION: Print only location
6085 SRC_AND_LOC: Print location and source line. */
6086 if (do_frame_printing
)
6087 print_stack_frame (get_selected_frame (NULL
), 0, source_flag
, 1);
6089 /* Display the auto-display expressions. */
6093 /* Here to return control to GDB when the inferior stops for real.
6094 Print appropriate messages, remove breakpoints, give terminal our modes.
6096 STOP_PRINT_FRAME nonzero means print the executing frame
6097 (pc, function, args, file, line number and line text).
6098 BREAKPOINTS_FAILED nonzero means stop was due to error
6099 attempting to insert breakpoints. */
6104 struct target_waitstatus last
;
6106 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
6108 get_last_target_status (&last_ptid
, &last
);
6110 /* If an exception is thrown from this point on, make sure to
6111 propagate GDB's knowledge of the executing state to the
6112 frontend/user running state. A QUIT is an easy exception to see
6113 here, so do this before any filtered output. */
6115 make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
6116 else if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
6117 && last
.kind
!= TARGET_WAITKIND_EXITED
6118 && last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
6119 make_cleanup (finish_thread_state_cleanup
, &inferior_ptid
);
6121 /* As with the notification of thread events, we want to delay
6122 notifying the user that we've switched thread context until
6123 the inferior actually stops.
6125 There's no point in saying anything if the inferior has exited.
6126 Note that SIGNALLED here means "exited with a signal", not
6127 "received a signal".
6129 Also skip saying anything in non-stop mode. In that mode, as we
6130 don't want GDB to switch threads behind the user's back, to avoid
6131 races where the user is typing a command to apply to thread x,
6132 but GDB switches to thread y before the user finishes entering
6133 the command, fetch_inferior_event installs a cleanup to restore
6134 the current thread back to the thread the user had selected right
6135 after this event is handled, so we're not really switching, only
6136 informing of a stop. */
6138 && !ptid_equal (previous_inferior_ptid
, inferior_ptid
)
6139 && target_has_execution
6140 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
6141 && last
.kind
!= TARGET_WAITKIND_EXITED
6142 && last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
6144 target_terminal_ours_for_output ();
6145 printf_filtered (_("[Switching to %s]\n"),
6146 target_pid_to_str (inferior_ptid
));
6147 annotate_thread_changed ();
6148 previous_inferior_ptid
= inferior_ptid
;
6151 if (last
.kind
== TARGET_WAITKIND_NO_RESUMED
)
6153 gdb_assert (sync_execution
|| !target_can_async_p ());
6155 target_terminal_ours_for_output ();
6156 printf_filtered (_("No unwaited-for children left.\n"));
6159 if (!breakpoints_always_inserted_mode () && target_has_execution
)
6161 if (remove_breakpoints ())
6163 target_terminal_ours_for_output ();
6164 printf_filtered (_("Cannot remove breakpoints because "
6165 "program is no longer writable.\nFurther "
6166 "execution is probably impossible.\n"));
6170 /* If an auto-display called a function and that got a signal,
6171 delete that auto-display to avoid an infinite recursion. */
6173 if (stopped_by_random_signal
)
6174 disable_current_display ();
6176 /* Don't print a message if in the middle of doing a "step n"
6177 operation for n > 1 */
6178 if (target_has_execution
6179 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
6180 && last
.kind
!= TARGET_WAITKIND_EXITED
6181 && inferior_thread ()->step_multi
6182 && inferior_thread ()->control
.stop_step
)
6185 target_terminal_ours ();
6186 async_enable_stdin ();
6188 /* Set the current source location. This will also happen if we
6189 display the frame below, but the current SAL will be incorrect
6190 during a user hook-stop function. */
6191 if (has_stack_frames () && !stop_stack_dummy
)
6192 set_current_sal_from_frame (get_current_frame ());
6194 /* Let the user/frontend see the threads as stopped, but do nothing
6195 if the thread was running an infcall. We may be e.g., evaluating
6196 a breakpoint condition. In that case, the thread had state
6197 THREAD_RUNNING before the infcall, and shall remain set to
6198 running, all without informing the user/frontend about state
6199 transition changes. If this is actually a call command, then the
6200 thread was originally already stopped, so there's no state to
6202 if (target_has_execution
&& inferior_thread ()->control
.in_infcall
)
6203 discard_cleanups (old_chain
);
6205 do_cleanups (old_chain
);
6207 /* Look up the hook_stop and run it (CLI internally handles problem
6208 of stop_command's pre-hook not existing). */
6210 catch_errors (hook_stop_stub
, stop_command
,
6211 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
6213 if (!has_stack_frames ())
6216 if (last
.kind
== TARGET_WAITKIND_SIGNALLED
6217 || last
.kind
== TARGET_WAITKIND_EXITED
)
6220 /* Select innermost stack frame - i.e., current frame is frame 0,
6221 and current location is based on that.
6222 Don't do this on return from a stack dummy routine,
6223 or if the program has exited. */
6225 if (!stop_stack_dummy
)
6227 select_frame (get_current_frame ());
6229 /* If --batch-silent is enabled then there's no need to print the current
6230 source location, and to try risks causing an error message about
6231 missing source files. */
6232 if (stop_print_frame
&& !batch_silent
)
6233 print_stop_event (&last
);
6236 /* Save the function value return registers, if we care.
6237 We might be about to restore their previous contents. */
6238 if (inferior_thread ()->control
.proceed_to_finish
6239 && execution_direction
!= EXEC_REVERSE
)
6241 /* This should not be necessary. */
6243 regcache_xfree (stop_registers
);
6245 /* NB: The copy goes through to the target picking up the value of
6246 all the registers. */
6247 stop_registers
= regcache_dup (get_current_regcache ());
6250 if (stop_stack_dummy
== STOP_STACK_DUMMY
)
6252 /* Pop the empty frame that contains the stack dummy.
6253 This also restores inferior state prior to the call
6254 (struct infcall_suspend_state). */
6255 struct frame_info
*frame
= get_current_frame ();
6257 gdb_assert (get_frame_type (frame
) == DUMMY_FRAME
);
6259 /* frame_pop() calls reinit_frame_cache as the last thing it
6260 does which means there's currently no selected frame. We
6261 don't need to re-establish a selected frame if the dummy call
6262 returns normally, that will be done by
6263 restore_infcall_control_state. However, we do have to handle
6264 the case where the dummy call is returning after being
6265 stopped (e.g. the dummy call previously hit a breakpoint).
6266 We can't know which case we have so just always re-establish
6267 a selected frame here. */
6268 select_frame (get_current_frame ());
6272 annotate_stopped ();
6274 /* Suppress the stop observer if we're in the middle of:
6276 - a step n (n > 1), as there still more steps to be done.
6278 - a "finish" command, as the observer will be called in
6279 finish_command_continuation, so it can include the inferior
6280 function's return value.
6282 - calling an inferior function, as we pretend we inferior didn't
6283 run at all. The return value of the call is handled by the
6284 expression evaluator, through call_function_by_hand. */
6286 if (!target_has_execution
6287 || last
.kind
== TARGET_WAITKIND_SIGNALLED
6288 || last
.kind
== TARGET_WAITKIND_EXITED
6289 || last
.kind
== TARGET_WAITKIND_NO_RESUMED
6290 || (!(inferior_thread ()->step_multi
6291 && inferior_thread ()->control
.stop_step
)
6292 && !(inferior_thread ()->control
.stop_bpstat
6293 && inferior_thread ()->control
.proceed_to_finish
)
6294 && !inferior_thread ()->control
.in_infcall
))
6296 if (!ptid_equal (inferior_ptid
, null_ptid
))
6297 observer_notify_normal_stop (inferior_thread ()->control
.stop_bpstat
,
6300 observer_notify_normal_stop (NULL
, stop_print_frame
);
6303 if (target_has_execution
)
6305 if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
6306 && last
.kind
!= TARGET_WAITKIND_EXITED
)
6307 /* Delete the breakpoint we stopped at, if it wants to be deleted.
6308 Delete any breakpoint that is to be deleted at the next stop. */
6309 breakpoint_auto_delete (inferior_thread ()->control
.stop_bpstat
);
6312 /* Try to get rid of automatically added inferiors that are no
6313 longer needed. Keeping those around slows down things linearly.
6314 Note that this never removes the current inferior. */
6319 hook_stop_stub (void *cmd
)
6321 execute_cmd_pre_hook ((struct cmd_list_element
*) cmd
);
6326 signal_stop_state (int signo
)
6328 return signal_stop
[signo
];
6332 signal_print_state (int signo
)
6334 return signal_print
[signo
];
6338 signal_pass_state (int signo
)
6340 return signal_program
[signo
];
6344 signal_cache_update (int signo
)
6348 for (signo
= 0; signo
< (int) GDB_SIGNAL_LAST
; signo
++)
6349 signal_cache_update (signo
);
6354 signal_pass
[signo
] = (signal_stop
[signo
] == 0
6355 && signal_print
[signo
] == 0
6356 && signal_program
[signo
] == 1
6357 && signal_catch
[signo
] == 0);
6361 signal_stop_update (int signo
, int state
)
6363 int ret
= signal_stop
[signo
];
6365 signal_stop
[signo
] = state
;
6366 signal_cache_update (signo
);
6371 signal_print_update (int signo
, int state
)
6373 int ret
= signal_print
[signo
];
6375 signal_print
[signo
] = state
;
6376 signal_cache_update (signo
);
6381 signal_pass_update (int signo
, int state
)
6383 int ret
= signal_program
[signo
];
6385 signal_program
[signo
] = state
;
6386 signal_cache_update (signo
);
6390 /* Update the global 'signal_catch' from INFO and notify the
6394 signal_catch_update (const unsigned int *info
)
6398 for (i
= 0; i
< GDB_SIGNAL_LAST
; ++i
)
6399 signal_catch
[i
] = info
[i
] > 0;
6400 signal_cache_update (-1);
6401 target_pass_signals ((int) GDB_SIGNAL_LAST
, signal_pass
);
6405 sig_print_header (void)
6407 printf_filtered (_("Signal Stop\tPrint\tPass "
6408 "to program\tDescription\n"));
6412 sig_print_info (enum gdb_signal oursig
)
6414 const char *name
= gdb_signal_to_name (oursig
);
6415 int name_padding
= 13 - strlen (name
);
6417 if (name_padding
<= 0)
6420 printf_filtered ("%s", name
);
6421 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
6422 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
6423 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
6424 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
6425 printf_filtered ("%s\n", gdb_signal_to_string (oursig
));
6428 /* Specify how various signals in the inferior should be handled. */
6431 handle_command (char *args
, int from_tty
)
6434 int digits
, wordlen
;
6435 int sigfirst
, signum
, siglast
;
6436 enum gdb_signal oursig
;
6439 unsigned char *sigs
;
6440 struct cleanup
*old_chain
;
6444 error_no_arg (_("signal to handle"));
6447 /* Allocate and zero an array of flags for which signals to handle. */
6449 nsigs
= (int) GDB_SIGNAL_LAST
;
6450 sigs
= (unsigned char *) alloca (nsigs
);
6451 memset (sigs
, 0, nsigs
);
6453 /* Break the command line up into args. */
6455 argv
= gdb_buildargv (args
);
6456 old_chain
= make_cleanup_freeargv (argv
);
6458 /* Walk through the args, looking for signal oursigs, signal names, and
6459 actions. Signal numbers and signal names may be interspersed with
6460 actions, with the actions being performed for all signals cumulatively
6461 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
6463 while (*argv
!= NULL
)
6465 wordlen
= strlen (*argv
);
6466 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
6470 sigfirst
= siglast
= -1;
6472 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
6474 /* Apply action to all signals except those used by the
6475 debugger. Silently skip those. */
6478 siglast
= nsigs
- 1;
6480 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
6482 SET_SIGS (nsigs
, sigs
, signal_stop
);
6483 SET_SIGS (nsigs
, sigs
, signal_print
);
6485 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
6487 UNSET_SIGS (nsigs
, sigs
, signal_program
);
6489 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
6491 SET_SIGS (nsigs
, sigs
, signal_print
);
6493 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
6495 SET_SIGS (nsigs
, sigs
, signal_program
);
6497 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
6499 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
6501 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
6503 SET_SIGS (nsigs
, sigs
, signal_program
);
6505 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
6507 UNSET_SIGS (nsigs
, sigs
, signal_print
);
6508 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
6510 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
6512 UNSET_SIGS (nsigs
, sigs
, signal_program
);
6514 else if (digits
> 0)
6516 /* It is numeric. The numeric signal refers to our own
6517 internal signal numbering from target.h, not to host/target
6518 signal number. This is a feature; users really should be
6519 using symbolic names anyway, and the common ones like
6520 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
6522 sigfirst
= siglast
= (int)
6523 gdb_signal_from_command (atoi (*argv
));
6524 if ((*argv
)[digits
] == '-')
6527 gdb_signal_from_command (atoi ((*argv
) + digits
+ 1));
6529 if (sigfirst
> siglast
)
6531 /* Bet he didn't figure we'd think of this case... */
6539 oursig
= gdb_signal_from_name (*argv
);
6540 if (oursig
!= GDB_SIGNAL_UNKNOWN
)
6542 sigfirst
= siglast
= (int) oursig
;
6546 /* Not a number and not a recognized flag word => complain. */
6547 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv
);
6551 /* If any signal numbers or symbol names were found, set flags for
6552 which signals to apply actions to. */
6554 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
6556 switch ((enum gdb_signal
) signum
)
6558 case GDB_SIGNAL_TRAP
:
6559 case GDB_SIGNAL_INT
:
6560 if (!allsigs
&& !sigs
[signum
])
6562 if (query (_("%s is used by the debugger.\n\
6563 Are you sure you want to change it? "),
6564 gdb_signal_to_name ((enum gdb_signal
) signum
)))
6570 printf_unfiltered (_("Not confirmed, unchanged.\n"));
6571 gdb_flush (gdb_stdout
);
6576 case GDB_SIGNAL_DEFAULT
:
6577 case GDB_SIGNAL_UNKNOWN
:
6578 /* Make sure that "all" doesn't print these. */
6589 for (signum
= 0; signum
< nsigs
; signum
++)
6592 signal_cache_update (-1);
6593 target_pass_signals ((int) GDB_SIGNAL_LAST
, signal_pass
);
6594 target_program_signals ((int) GDB_SIGNAL_LAST
, signal_program
);
6598 /* Show the results. */
6599 sig_print_header ();
6600 for (; signum
< nsigs
; signum
++)
6602 sig_print_info (signum
);
6608 do_cleanups (old_chain
);
6611 /* Complete the "handle" command. */
6613 static VEC (char_ptr
) *
6614 handle_completer (struct cmd_list_element
*ignore
,
6615 const char *text
, const char *word
)
6617 VEC (char_ptr
) *vec_signals
, *vec_keywords
, *return_val
;
6618 static const char * const keywords
[] =
6632 vec_signals
= signal_completer (ignore
, text
, word
);
6633 vec_keywords
= complete_on_enum (keywords
, word
, word
);
6635 return_val
= VEC_merge (char_ptr
, vec_signals
, vec_keywords
);
6636 VEC_free (char_ptr
, vec_signals
);
6637 VEC_free (char_ptr
, vec_keywords
);
6642 xdb_handle_command (char *args
, int from_tty
)
6645 struct cleanup
*old_chain
;
6648 error_no_arg (_("xdb command"));
6650 /* Break the command line up into args. */
6652 argv
= gdb_buildargv (args
);
6653 old_chain
= make_cleanup_freeargv (argv
);
6654 if (argv
[1] != (char *) NULL
)
6659 bufLen
= strlen (argv
[0]) + 20;
6660 argBuf
= (char *) xmalloc (bufLen
);
6664 enum gdb_signal oursig
;
6666 oursig
= gdb_signal_from_name (argv
[0]);
6667 memset (argBuf
, 0, bufLen
);
6668 if (strcmp (argv
[1], "Q") == 0)
6669 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
6672 if (strcmp (argv
[1], "s") == 0)
6674 if (!signal_stop
[oursig
])
6675 sprintf (argBuf
, "%s %s", argv
[0], "stop");
6677 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
6679 else if (strcmp (argv
[1], "i") == 0)
6681 if (!signal_program
[oursig
])
6682 sprintf (argBuf
, "%s %s", argv
[0], "pass");
6684 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
6686 else if (strcmp (argv
[1], "r") == 0)
6688 if (!signal_print
[oursig
])
6689 sprintf (argBuf
, "%s %s", argv
[0], "print");
6691 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
6697 handle_command (argBuf
, from_tty
);
6699 printf_filtered (_("Invalid signal handling flag.\n"));
6704 do_cleanups (old_chain
);
6708 gdb_signal_from_command (int num
)
6710 if (num
>= 1 && num
<= 15)
6711 return (enum gdb_signal
) num
;
6712 error (_("Only signals 1-15 are valid as numeric signals.\n\
6713 Use \"info signals\" for a list of symbolic signals."));
6716 /* Print current contents of the tables set by the handle command.
6717 It is possible we should just be printing signals actually used
6718 by the current target (but for things to work right when switching
6719 targets, all signals should be in the signal tables). */
6722 signals_info (char *signum_exp
, int from_tty
)
6724 enum gdb_signal oursig
;
6726 sig_print_header ();
6730 /* First see if this is a symbol name. */
6731 oursig
= gdb_signal_from_name (signum_exp
);
6732 if (oursig
== GDB_SIGNAL_UNKNOWN
)
6734 /* No, try numeric. */
6736 gdb_signal_from_command (parse_and_eval_long (signum_exp
));
6738 sig_print_info (oursig
);
6742 printf_filtered ("\n");
6743 /* These ugly casts brought to you by the native VAX compiler. */
6744 for (oursig
= GDB_SIGNAL_FIRST
;
6745 (int) oursig
< (int) GDB_SIGNAL_LAST
;
6746 oursig
= (enum gdb_signal
) ((int) oursig
+ 1))
6750 if (oursig
!= GDB_SIGNAL_UNKNOWN
6751 && oursig
!= GDB_SIGNAL_DEFAULT
&& oursig
!= GDB_SIGNAL_0
)
6752 sig_print_info (oursig
);
6755 printf_filtered (_("\nUse the \"handle\" command "
6756 "to change these tables.\n"));
6759 /* Check if it makes sense to read $_siginfo from the current thread
6760 at this point. If not, throw an error. */
6763 validate_siginfo_access (void)
6765 /* No current inferior, no siginfo. */
6766 if (ptid_equal (inferior_ptid
, null_ptid
))
6767 error (_("No thread selected."));
6769 /* Don't try to read from a dead thread. */
6770 if (is_exited (inferior_ptid
))
6771 error (_("The current thread has terminated"));
6773 /* ... or from a spinning thread. */
6774 if (is_running (inferior_ptid
))
6775 error (_("Selected thread is running."));
6778 /* The $_siginfo convenience variable is a bit special. We don't know
6779 for sure the type of the value until we actually have a chance to
6780 fetch the data. The type can change depending on gdbarch, so it is
6781 also dependent on which thread you have selected.
6783 1. making $_siginfo be an internalvar that creates a new value on
6786 2. making the value of $_siginfo be an lval_computed value. */
6788 /* This function implements the lval_computed support for reading a
6792 siginfo_value_read (struct value
*v
)
6794 LONGEST transferred
;
6796 validate_siginfo_access ();
6799 target_read (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
,
6801 value_contents_all_raw (v
),
6803 TYPE_LENGTH (value_type (v
)));
6805 if (transferred
!= TYPE_LENGTH (value_type (v
)))
6806 error (_("Unable to read siginfo"));
6809 /* This function implements the lval_computed support for writing a
6813 siginfo_value_write (struct value
*v
, struct value
*fromval
)
6815 LONGEST transferred
;
6817 validate_siginfo_access ();
6819 transferred
= target_write (¤t_target
,
6820 TARGET_OBJECT_SIGNAL_INFO
,
6822 value_contents_all_raw (fromval
),
6824 TYPE_LENGTH (value_type (fromval
)));
6826 if (transferred
!= TYPE_LENGTH (value_type (fromval
)))
6827 error (_("Unable to write siginfo"));
6830 static const struct lval_funcs siginfo_value_funcs
=
6836 /* Return a new value with the correct type for the siginfo object of
6837 the current thread using architecture GDBARCH. Return a void value
6838 if there's no object available. */
6840 static struct value
*
6841 siginfo_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
,
6844 if (target_has_stack
6845 && !ptid_equal (inferior_ptid
, null_ptid
)
6846 && gdbarch_get_siginfo_type_p (gdbarch
))
6848 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
6850 return allocate_computed_value (type
, &siginfo_value_funcs
, NULL
);
6853 return allocate_value (builtin_type (gdbarch
)->builtin_void
);
6857 /* infcall_suspend_state contains state about the program itself like its
6858 registers and any signal it received when it last stopped.
6859 This state must be restored regardless of how the inferior function call
6860 ends (either successfully, or after it hits a breakpoint or signal)
6861 if the program is to properly continue where it left off. */
6863 struct infcall_suspend_state
6865 struct thread_suspend_state thread_suspend
;
6866 #if 0 /* Currently unused and empty structures are not valid C. */
6867 struct inferior_suspend_state inferior_suspend
;
6872 struct regcache
*registers
;
6874 /* Format of SIGINFO_DATA or NULL if it is not present. */
6875 struct gdbarch
*siginfo_gdbarch
;
6877 /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
6878 TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the
6879 content would be invalid. */
6880 gdb_byte
*siginfo_data
;
6883 struct infcall_suspend_state
*
6884 save_infcall_suspend_state (void)
6886 struct infcall_suspend_state
*inf_state
;
6887 struct thread_info
*tp
= inferior_thread ();
6889 struct inferior
*inf
= current_inferior ();
6891 struct regcache
*regcache
= get_current_regcache ();
6892 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6893 gdb_byte
*siginfo_data
= NULL
;
6895 if (gdbarch_get_siginfo_type_p (gdbarch
))
6897 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
6898 size_t len
= TYPE_LENGTH (type
);
6899 struct cleanup
*back_to
;
6901 siginfo_data
= xmalloc (len
);
6902 back_to
= make_cleanup (xfree
, siginfo_data
);
6904 if (target_read (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
, NULL
,
6905 siginfo_data
, 0, len
) == len
)
6906 discard_cleanups (back_to
);
6909 /* Errors ignored. */
6910 do_cleanups (back_to
);
6911 siginfo_data
= NULL
;
6915 inf_state
= XCNEW (struct infcall_suspend_state
);
6919 inf_state
->siginfo_gdbarch
= gdbarch
;
6920 inf_state
->siginfo_data
= siginfo_data
;
6923 inf_state
->thread_suspend
= tp
->suspend
;
6924 #if 0 /* Currently unused and empty structures are not valid C. */
6925 inf_state
->inferior_suspend
= inf
->suspend
;
6928 /* run_inferior_call will not use the signal due to its `proceed' call with
6929 GDB_SIGNAL_0 anyway. */
6930 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
6932 inf_state
->stop_pc
= stop_pc
;
6934 inf_state
->registers
= regcache_dup (regcache
);
6939 /* Restore inferior session state to INF_STATE. */
6942 restore_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
6944 struct thread_info
*tp
= inferior_thread ();
6946 struct inferior
*inf
= current_inferior ();
6948 struct regcache
*regcache
= get_current_regcache ();
6949 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6951 tp
->suspend
= inf_state
->thread_suspend
;
6952 #if 0 /* Currently unused and empty structures are not valid C. */
6953 inf
->suspend
= inf_state
->inferior_suspend
;
6956 stop_pc
= inf_state
->stop_pc
;
6958 if (inf_state
->siginfo_gdbarch
== gdbarch
)
6960 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
6962 /* Errors ignored. */
6963 target_write (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
, NULL
,
6964 inf_state
->siginfo_data
, 0, TYPE_LENGTH (type
));
6967 /* The inferior can be gone if the user types "print exit(0)"
6968 (and perhaps other times). */
6969 if (target_has_execution
)
6970 /* NB: The register write goes through to the target. */
6971 regcache_cpy (regcache
, inf_state
->registers
);
6973 discard_infcall_suspend_state (inf_state
);
6977 do_restore_infcall_suspend_state_cleanup (void *state
)
6979 restore_infcall_suspend_state (state
);
6983 make_cleanup_restore_infcall_suspend_state
6984 (struct infcall_suspend_state
*inf_state
)
6986 return make_cleanup (do_restore_infcall_suspend_state_cleanup
, inf_state
);
6990 discard_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
6992 regcache_xfree (inf_state
->registers
);
6993 xfree (inf_state
->siginfo_data
);
6998 get_infcall_suspend_state_regcache (struct infcall_suspend_state
*inf_state
)
7000 return inf_state
->registers
;
7003 /* infcall_control_state contains state regarding gdb's control of the
7004 inferior itself like stepping control. It also contains session state like
7005 the user's currently selected frame. */
7007 struct infcall_control_state
7009 struct thread_control_state thread_control
;
7010 struct inferior_control_state inferior_control
;
7013 enum stop_stack_kind stop_stack_dummy
;
7014 int stopped_by_random_signal
;
7015 int stop_after_trap
;
7017 /* ID if the selected frame when the inferior function call was made. */
7018 struct frame_id selected_frame_id
;
7021 /* Save all of the information associated with the inferior<==>gdb
7024 struct infcall_control_state
*
7025 save_infcall_control_state (void)
7027 struct infcall_control_state
*inf_status
= xmalloc (sizeof (*inf_status
));
7028 struct thread_info
*tp
= inferior_thread ();
7029 struct inferior
*inf
= current_inferior ();
7031 inf_status
->thread_control
= tp
->control
;
7032 inf_status
->inferior_control
= inf
->control
;
7034 tp
->control
.step_resume_breakpoint
= NULL
;
7035 tp
->control
.exception_resume_breakpoint
= NULL
;
7037 /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of
7038 chain. If caller's caller is walking the chain, they'll be happier if we
7039 hand them back the original chain when restore_infcall_control_state is
7041 tp
->control
.stop_bpstat
= bpstat_copy (tp
->control
.stop_bpstat
);
7044 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
7045 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
7046 inf_status
->stop_after_trap
= stop_after_trap
;
7048 inf_status
->selected_frame_id
= get_frame_id (get_selected_frame (NULL
));
7054 restore_selected_frame (void *args
)
7056 struct frame_id
*fid
= (struct frame_id
*) args
;
7057 struct frame_info
*frame
;
7059 frame
= frame_find_by_id (*fid
);
7061 /* If inf_status->selected_frame_id is NULL, there was no previously
7065 warning (_("Unable to restore previously selected frame."));
7069 select_frame (frame
);
7074 /* Restore inferior session state to INF_STATUS. */
7077 restore_infcall_control_state (struct infcall_control_state
*inf_status
)
7079 struct thread_info
*tp
= inferior_thread ();
7080 struct inferior
*inf
= current_inferior ();
7082 if (tp
->control
.step_resume_breakpoint
)
7083 tp
->control
.step_resume_breakpoint
->disposition
= disp_del_at_next_stop
;
7085 if (tp
->control
.exception_resume_breakpoint
)
7086 tp
->control
.exception_resume_breakpoint
->disposition
7087 = disp_del_at_next_stop
;
7089 /* Handle the bpstat_copy of the chain. */
7090 bpstat_clear (&tp
->control
.stop_bpstat
);
7092 tp
->control
= inf_status
->thread_control
;
7093 inf
->control
= inf_status
->inferior_control
;
7096 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
7097 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
7098 stop_after_trap
= inf_status
->stop_after_trap
;
7100 if (target_has_stack
)
7102 /* The point of catch_errors is that if the stack is clobbered,
7103 walking the stack might encounter a garbage pointer and
7104 error() trying to dereference it. */
7106 (restore_selected_frame
, &inf_status
->selected_frame_id
,
7107 "Unable to restore previously selected frame:\n",
7108 RETURN_MASK_ERROR
) == 0)
7109 /* Error in restoring the selected frame. Select the innermost
7111 select_frame (get_current_frame ());
7118 do_restore_infcall_control_state_cleanup (void *sts
)
7120 restore_infcall_control_state (sts
);
7124 make_cleanup_restore_infcall_control_state
7125 (struct infcall_control_state
*inf_status
)
7127 return make_cleanup (do_restore_infcall_control_state_cleanup
, inf_status
);
7131 discard_infcall_control_state (struct infcall_control_state
*inf_status
)
7133 if (inf_status
->thread_control
.step_resume_breakpoint
)
7134 inf_status
->thread_control
.step_resume_breakpoint
->disposition
7135 = disp_del_at_next_stop
;
7137 if (inf_status
->thread_control
.exception_resume_breakpoint
)
7138 inf_status
->thread_control
.exception_resume_breakpoint
->disposition
7139 = disp_del_at_next_stop
;
7141 /* See save_infcall_control_state for info on stop_bpstat. */
7142 bpstat_clear (&inf_status
->thread_control
.stop_bpstat
);
7147 /* restore_inferior_ptid() will be used by the cleanup machinery
7148 to restore the inferior_ptid value saved in a call to
7149 save_inferior_ptid(). */
7152 restore_inferior_ptid (void *arg
)
7154 ptid_t
*saved_ptid_ptr
= arg
;
7156 inferior_ptid
= *saved_ptid_ptr
;
7160 /* Save the value of inferior_ptid so that it may be restored by a
7161 later call to do_cleanups(). Returns the struct cleanup pointer
7162 needed for later doing the cleanup. */
7165 save_inferior_ptid (void)
7167 ptid_t
*saved_ptid_ptr
;
7169 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
7170 *saved_ptid_ptr
= inferior_ptid
;
7171 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
7174 /* See inferior.h. */
7177 clear_exit_convenience_vars (void)
7179 clear_internalvar (lookup_internalvar ("_exitsignal"));
7180 clear_internalvar (lookup_internalvar ("_exitcode"));
7184 /* User interface for reverse debugging:
7185 Set exec-direction / show exec-direction commands
7186 (returns error unless target implements to_set_exec_direction method). */
7188 int execution_direction
= EXEC_FORWARD
;
7189 static const char exec_forward
[] = "forward";
7190 static const char exec_reverse
[] = "reverse";
7191 static const char *exec_direction
= exec_forward
;
7192 static const char *const exec_direction_names
[] = {
7199 set_exec_direction_func (char *args
, int from_tty
,
7200 struct cmd_list_element
*cmd
)
7202 if (target_can_execute_reverse
)
7204 if (!strcmp (exec_direction
, exec_forward
))
7205 execution_direction
= EXEC_FORWARD
;
7206 else if (!strcmp (exec_direction
, exec_reverse
))
7207 execution_direction
= EXEC_REVERSE
;
7211 exec_direction
= exec_forward
;
7212 error (_("Target does not support this operation."));
7217 show_exec_direction_func (struct ui_file
*out
, int from_tty
,
7218 struct cmd_list_element
*cmd
, const char *value
)
7220 switch (execution_direction
) {
7222 fprintf_filtered (out
, _("Forward.\n"));
7225 fprintf_filtered (out
, _("Reverse.\n"));
7228 internal_error (__FILE__
, __LINE__
,
7229 _("bogus execution_direction value: %d"),
7230 (int) execution_direction
);
7235 show_schedule_multiple (struct ui_file
*file
, int from_tty
,
7236 struct cmd_list_element
*c
, const char *value
)
7238 fprintf_filtered (file
, _("Resuming the execution of threads "
7239 "of all processes is %s.\n"), value
);
7242 /* Implementation of `siginfo' variable. */
7244 static const struct internalvar_funcs siginfo_funcs
=
7252 _initialize_infrun (void)
7256 struct cmd_list_element
*c
;
7258 add_info ("signals", signals_info
, _("\
7259 What debugger does when program gets various signals.\n\
7260 Specify a signal as argument to print info on that signal only."));
7261 add_info_alias ("handle", "signals", 0);
7263 c
= add_com ("handle", class_run
, handle_command
, _("\
7264 Specify how to handle signals.\n\
7265 Usage: handle SIGNAL [ACTIONS]\n\
7266 Args are signals and actions to apply to those signals.\n\
7267 If no actions are specified, the current settings for the specified signals\n\
7268 will be displayed instead.\n\
7270 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
7271 from 1-15 are allowed for compatibility with old versions of GDB.\n\
7272 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
7273 The special arg \"all\" is recognized to mean all signals except those\n\
7274 used by the debugger, typically SIGTRAP and SIGINT.\n\
7276 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
7277 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
7278 Stop means reenter debugger if this signal happens (implies print).\n\
7279 Print means print a message if this signal happens.\n\
7280 Pass means let program see this signal; otherwise program doesn't know.\n\
7281 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
7282 Pass and Stop may be combined.\n\
7284 Multiple signals may be specified. Signal numbers and signal names\n\
7285 may be interspersed with actions, with the actions being performed for\n\
7286 all signals cumulatively specified."));
7287 set_cmd_completer (c
, handle_completer
);
7291 add_com ("lz", class_info
, signals_info
, _("\
7292 What debugger does when program gets various signals.\n\
7293 Specify a signal as argument to print info on that signal only."));
7294 add_com ("z", class_run
, xdb_handle_command
, _("\
7295 Specify how to handle a signal.\n\
7296 Args are signals and actions to apply to those signals.\n\
7297 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
7298 from 1-15 are allowed for compatibility with old versions of GDB.\n\
7299 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
7300 The special arg \"all\" is recognized to mean all signals except those\n\
7301 used by the debugger, typically SIGTRAP and SIGINT.\n\
7302 Recognized actions include \"s\" (toggles between stop and nostop),\n\
7303 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
7304 nopass), \"Q\" (noprint)\n\
7305 Stop means reenter debugger if this signal happens (implies print).\n\
7306 Print means print a message if this signal happens.\n\
7307 Pass means let program see this signal; otherwise program doesn't know.\n\
7308 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
7309 Pass and Stop may be combined."));
7313 stop_command
= add_cmd ("stop", class_obscure
,
7314 not_just_help_class_command
, _("\
7315 There is no `stop' command, but you can set a hook on `stop'.\n\
7316 This allows you to set a list of commands to be run each time execution\n\
7317 of the program stops."), &cmdlist
);
7319 add_setshow_zuinteger_cmd ("infrun", class_maintenance
, &debug_infrun
, _("\
7320 Set inferior debugging."), _("\
7321 Show inferior debugging."), _("\
7322 When non-zero, inferior specific debugging is enabled."),
7325 &setdebuglist
, &showdebuglist
);
7327 add_setshow_boolean_cmd ("displaced", class_maintenance
,
7328 &debug_displaced
, _("\
7329 Set displaced stepping debugging."), _("\
7330 Show displaced stepping debugging."), _("\
7331 When non-zero, displaced stepping specific debugging is enabled."),
7333 show_debug_displaced
,
7334 &setdebuglist
, &showdebuglist
);
7336 add_setshow_boolean_cmd ("non-stop", no_class
,
7338 Set whether gdb controls the inferior in non-stop mode."), _("\
7339 Show whether gdb controls the inferior in non-stop mode."), _("\
7340 When debugging a multi-threaded program and this setting is\n\
7341 off (the default, also called all-stop mode), when one thread stops\n\
7342 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
7343 all other threads in the program while you interact with the thread of\n\
7344 interest. When you continue or step a thread, you can allow the other\n\
7345 threads to run, or have them remain stopped, but while you inspect any\n\
7346 thread's state, all threads stop.\n\
7348 In non-stop mode, when one thread stops, other threads can continue\n\
7349 to run freely. You'll be able to step each thread independently,\n\
7350 leave it stopped or free to run as needed."),
7356 numsigs
= (int) GDB_SIGNAL_LAST
;
7357 signal_stop
= (unsigned char *) xmalloc (sizeof (signal_stop
[0]) * numsigs
);
7358 signal_print
= (unsigned char *)
7359 xmalloc (sizeof (signal_print
[0]) * numsigs
);
7360 signal_program
= (unsigned char *)
7361 xmalloc (sizeof (signal_program
[0]) * numsigs
);
7362 signal_catch
= (unsigned char *)
7363 xmalloc (sizeof (signal_catch
[0]) * numsigs
);
7364 signal_pass
= (unsigned char *)
7365 xmalloc (sizeof (signal_program
[0]) * numsigs
);
7366 for (i
= 0; i
< numsigs
; i
++)
7369 signal_print
[i
] = 1;
7370 signal_program
[i
] = 1;
7371 signal_catch
[i
] = 0;
7374 /* Signals caused by debugger's own actions
7375 should not be given to the program afterwards. */
7376 signal_program
[GDB_SIGNAL_TRAP
] = 0;
7377 signal_program
[GDB_SIGNAL_INT
] = 0;
7379 /* Signals that are not errors should not normally enter the debugger. */
7380 signal_stop
[GDB_SIGNAL_ALRM
] = 0;
7381 signal_print
[GDB_SIGNAL_ALRM
] = 0;
7382 signal_stop
[GDB_SIGNAL_VTALRM
] = 0;
7383 signal_print
[GDB_SIGNAL_VTALRM
] = 0;
7384 signal_stop
[GDB_SIGNAL_PROF
] = 0;
7385 signal_print
[GDB_SIGNAL_PROF
] = 0;
7386 signal_stop
[GDB_SIGNAL_CHLD
] = 0;
7387 signal_print
[GDB_SIGNAL_CHLD
] = 0;
7388 signal_stop
[GDB_SIGNAL_IO
] = 0;
7389 signal_print
[GDB_SIGNAL_IO
] = 0;
7390 signal_stop
[GDB_SIGNAL_POLL
] = 0;
7391 signal_print
[GDB_SIGNAL_POLL
] = 0;
7392 signal_stop
[GDB_SIGNAL_URG
] = 0;
7393 signal_print
[GDB_SIGNAL_URG
] = 0;
7394 signal_stop
[GDB_SIGNAL_WINCH
] = 0;
7395 signal_print
[GDB_SIGNAL_WINCH
] = 0;
7396 signal_stop
[GDB_SIGNAL_PRIO
] = 0;
7397 signal_print
[GDB_SIGNAL_PRIO
] = 0;
7399 /* These signals are used internally by user-level thread
7400 implementations. (See signal(5) on Solaris.) Like the above
7401 signals, a healthy program receives and handles them as part of
7402 its normal operation. */
7403 signal_stop
[GDB_SIGNAL_LWP
] = 0;
7404 signal_print
[GDB_SIGNAL_LWP
] = 0;
7405 signal_stop
[GDB_SIGNAL_WAITING
] = 0;
7406 signal_print
[GDB_SIGNAL_WAITING
] = 0;
7407 signal_stop
[GDB_SIGNAL_CANCEL
] = 0;
7408 signal_print
[GDB_SIGNAL_CANCEL
] = 0;
7410 /* Update cached state. */
7411 signal_cache_update (-1);
7413 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support
,
7414 &stop_on_solib_events
, _("\
7415 Set stopping for shared library events."), _("\
7416 Show stopping for shared library events."), _("\
7417 If nonzero, gdb will give control to the user when the dynamic linker\n\
7418 notifies gdb of shared library events. The most common event of interest\n\
7419 to the user would be loading/unloading of a new library."),
7420 set_stop_on_solib_events
,
7421 show_stop_on_solib_events
,
7422 &setlist
, &showlist
);
7424 add_setshow_enum_cmd ("follow-fork-mode", class_run
,
7425 follow_fork_mode_kind_names
,
7426 &follow_fork_mode_string
, _("\
7427 Set debugger response to a program call of fork or vfork."), _("\
7428 Show debugger response to a program call of fork or vfork."), _("\
7429 A fork or vfork creates a new process. follow-fork-mode can be:\n\
7430 parent - the original process is debugged after a fork\n\
7431 child - the new process is debugged after a fork\n\
7432 The unfollowed process will continue to run.\n\
7433 By default, the debugger will follow the parent process."),
7435 show_follow_fork_mode_string
,
7436 &setlist
, &showlist
);
7438 add_setshow_enum_cmd ("follow-exec-mode", class_run
,
7439 follow_exec_mode_names
,
7440 &follow_exec_mode_string
, _("\
7441 Set debugger response to a program call of exec."), _("\
7442 Show debugger response to a program call of exec."), _("\
7443 An exec call replaces the program image of a process.\n\
7445 follow-exec-mode can be:\n\
7447 new - the debugger creates a new inferior and rebinds the process\n\
7448 to this new inferior. The program the process was running before\n\
7449 the exec call can be restarted afterwards by restarting the original\n\
7452 same - the debugger keeps the process bound to the same inferior.\n\
7453 The new executable image replaces the previous executable loaded in\n\
7454 the inferior. Restarting the inferior after the exec call restarts\n\
7455 the executable the process was running after the exec call.\n\
7457 By default, the debugger will use the same inferior."),
7459 show_follow_exec_mode_string
,
7460 &setlist
, &showlist
);
7462 add_setshow_enum_cmd ("scheduler-locking", class_run
,
7463 scheduler_enums
, &scheduler_mode
, _("\
7464 Set mode for locking scheduler during execution."), _("\
7465 Show mode for locking scheduler during execution."), _("\
7466 off == no locking (threads may preempt at any time)\n\
7467 on == full locking (no thread except the current thread may run)\n\
7468 step == scheduler locked during every single-step operation.\n\
7469 In this mode, no other thread may run during a step command.\n\
7470 Other threads may run while stepping over a function call ('next')."),
7471 set_schedlock_func
, /* traps on target vector */
7472 show_scheduler_mode
,
7473 &setlist
, &showlist
);
7475 add_setshow_boolean_cmd ("schedule-multiple", class_run
, &sched_multi
, _("\
7476 Set mode for resuming threads of all processes."), _("\
7477 Show mode for resuming threads of all processes."), _("\
7478 When on, execution commands (such as 'continue' or 'next') resume all\n\
7479 threads of all processes. When off (which is the default), execution\n\
7480 commands only resume the threads of the current process. The set of\n\
7481 threads that are resumed is further refined by the scheduler-locking\n\
7482 mode (see help set scheduler-locking)."),
7484 show_schedule_multiple
,
7485 &setlist
, &showlist
);
7487 add_setshow_boolean_cmd ("step-mode", class_run
, &step_stop_if_no_debug
, _("\
7488 Set mode of the step operation."), _("\
7489 Show mode of the step operation."), _("\
7490 When set, doing a step over a function without debug line information\n\
7491 will stop at the first instruction of that function. Otherwise, the\n\
7492 function is skipped and the step command stops at a different source line."),
7494 show_step_stop_if_no_debug
,
7495 &setlist
, &showlist
);
7497 add_setshow_auto_boolean_cmd ("displaced-stepping", class_run
,
7498 &can_use_displaced_stepping
, _("\
7499 Set debugger's willingness to use displaced stepping."), _("\
7500 Show debugger's willingness to use displaced stepping."), _("\
7501 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
7502 supported by the target architecture. If off, gdb will not use displaced\n\
7503 stepping to step over breakpoints, even if such is supported by the target\n\
7504 architecture. If auto (which is the default), gdb will use displaced stepping\n\
7505 if the target architecture supports it and non-stop mode is active, but will not\n\
7506 use it in all-stop mode (see help set non-stop)."),
7508 show_can_use_displaced_stepping
,
7509 &setlist
, &showlist
);
7511 add_setshow_enum_cmd ("exec-direction", class_run
, exec_direction_names
,
7512 &exec_direction
, _("Set direction of execution.\n\
7513 Options are 'forward' or 'reverse'."),
7514 _("Show direction of execution (forward/reverse)."),
7515 _("Tells gdb whether to execute forward or backward."),
7516 set_exec_direction_func
, show_exec_direction_func
,
7517 &setlist
, &showlist
);
7519 /* Set/show detach-on-fork: user-settable mode. */
7521 add_setshow_boolean_cmd ("detach-on-fork", class_run
, &detach_fork
, _("\
7522 Set whether gdb will detach the child of a fork."), _("\
7523 Show whether gdb will detach the child of a fork."), _("\
7524 Tells gdb whether to detach the child of a fork."),
7525 NULL
, NULL
, &setlist
, &showlist
);
7527 /* Set/show disable address space randomization mode. */
7529 add_setshow_boolean_cmd ("disable-randomization", class_support
,
7530 &disable_randomization
, _("\
7531 Set disabling of debuggee's virtual address space randomization."), _("\
7532 Show disabling of debuggee's virtual address space randomization."), _("\
7533 When this mode is on (which is the default), randomization of the virtual\n\
7534 address space is disabled. Standalone programs run with the randomization\n\
7535 enabled by default on some platforms."),
7536 &set_disable_randomization
,
7537 &show_disable_randomization
,
7538 &setlist
, &showlist
);
7540 /* ptid initializations */
7541 inferior_ptid
= null_ptid
;
7542 target_last_wait_ptid
= minus_one_ptid
;
7544 observer_attach_thread_ptid_changed (infrun_thread_ptid_changed
);
7545 observer_attach_thread_stop_requested (infrun_thread_stop_requested
);
7546 observer_attach_thread_exit (infrun_thread_thread_exit
);
7547 observer_attach_inferior_exit (infrun_inferior_exit
);
7549 /* Explicitly create without lookup, since that tries to create a
7550 value with a void typed value, and when we get here, gdbarch
7551 isn't initialized yet. At this point, we're quite sure there
7552 isn't another convenience variable of the same name. */
7553 create_internalvar_type_lazy ("_siginfo", &siginfo_funcs
, NULL
);
7555 add_setshow_boolean_cmd ("observer", no_class
,
7556 &observer_mode_1
, _("\
7557 Set whether gdb controls the inferior in observer mode."), _("\
7558 Show whether gdb controls the inferior in observer mode."), _("\
7559 In observer mode, GDB can get data from the inferior, but not\n\
7560 affect its execution. Registers and memory may not be changed,\n\
7561 breakpoints may not be set, and the program cannot be interrupted\n\