/* Target-struct-independent code to start (run) and stop an inferior
process.
- Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
- 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free
- Software Foundation, Inc.
+ Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
+ 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
+ Free Software Foundation, Inc.
This file is part of GDB.
/* The thread we inserted single-step breakpoints for. */
static ptid_t singlestep_ptid;
+/* PC when we started this single-step. */
+static CORE_ADDR singlestep_pc;
+
/* If another thread hit the singlestep breakpoint, we save the original
thread here so that we can resume single-stepping it later. */
static ptid_t saved_singlestep_ptid;
`wait_for_inferior' */
singlestep_breakpoints_inserted_p = 1;
singlestep_ptid = inferior_ptid;
+ singlestep_pc = read_pc ();
}
/* If there were any forks/vforks/execs that were caught and are
/* Start remote-debugging of a machine over a serial link. */
void
-start_remote (void)
+start_remote (int from_tty)
{
init_thread_list ();
init_wait_for_inferior ();
is currently running and GDB state should be set to the same as
for an async run. */
wait_for_inferior ();
+
+ /* Now that the inferior has stopped, do any bookkeeping like
+ loading shared libraries. We want to do this before normal_stop,
+ so that the displayed frame is up to date. */
+ post_create_inferior (¤t_target, from_tty);
+
normal_stop ();
}
static void step_into_function (struct execution_control_state *ecs);
static void insert_step_resume_breakpoint_at_frame (struct frame_info *step_frame);
+static void insert_step_resume_breakpoint_at_caller (struct frame_info *);
static void insert_step_resume_breakpoint_at_sal (struct symtab_and_line sr_sal,
struct frame_id sr_id);
static void stop_stepping (struct execution_control_state *ecs);
*status = target_last_waitstatus;
}
+void
+nullify_last_target_wait_ptid (void)
+{
+ target_last_wait_ptid = minus_one_ptid;
+}
+
/* Switch thread contexts, maintaining "infrun state". */
static void
be lost. This may happen as a result of the target module
mishandling thread creation. */
+ if (debug_infrun)
+ {
+ fprintf_unfiltered (gdb_stdlog, "infrun: Switching context from %s ",
+ target_pid_to_str (inferior_ptid));
+ fprintf_unfiltered (gdb_stdlog, "to %s\n",
+ target_pid_to_str (ecs->ptid));
+ }
+
if (in_thread_list (inferior_ptid) && in_thread_list (ecs->ptid))
{ /* Perform infrun state context switch: */
/* Save infrun state for the old thread. */
&ecs->current_line, &ecs->current_symtab);
}
inferior_ptid = ecs->ptid;
+ flush_cached_frames ();
}
static void
pending_follow.fork_event.parent_pid = PIDGET (ecs->ptid);
pending_follow.fork_event.child_pid = ecs->ws.value.related_pid;
+ if (!ptid_equal (ecs->ptid, inferior_ptid))
+ {
+ context_switch (ecs);
+ flush_cached_frames ();
+ }
+
stop_pc = read_pc ();
stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid, 0);
case TARGET_WAITKIND_EXECD:
if (debug_infrun)
- fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXECED\n");
+ fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXECD\n");
stop_signal = TARGET_SIGNAL_TRAP;
/* NOTE drow/2002-12-05: This code should be pushed down into the
if (inferior_ignoring_leading_exec_events)
{
inferior_ignoring_leading_exec_events--;
- if (pending_follow.kind == TARGET_WAITKIND_VFORKED)
- ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow.fork_event.
- parent_pid);
target_resume (ecs->ptid, 0, TARGET_SIGNAL_0);
prepare_to_wait (ecs);
return;
ecs->random_signal = !bpstat_explains_signal (stop_bpstat);
inferior_ptid = ecs->saved_inferior_ptid;
+ if (!ptid_equal (ecs->ptid, inferior_ptid))
+ {
+ context_switch (ecs);
+ flush_cached_frames ();
+ }
+
/* If no catchpoint triggered for this, then keep going. */
if (ecs->random_signal)
{
}
else if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p)
{
+ /* We have not context switched yet, so this should be true
+ no matter which thread hit the singlestep breakpoint. */
+ gdb_assert (ptid_equal (inferior_ptid, singlestep_ptid));
+ if (debug_infrun)
+ fprintf_unfiltered (gdb_stdlog, "infrun: software single step "
+ "trap for %s\n",
+ target_pid_to_str (ecs->ptid));
+
ecs->random_signal = 0;
/* The call to in_thread_list is necessary because PTIDs sometimes
change when we go from single-threaded to multi-threaded. If
if (!ptid_equal (singlestep_ptid, ecs->ptid)
&& in_thread_list (singlestep_ptid))
{
- thread_hop_needed = 1;
- stepping_past_singlestep_breakpoint = 1;
- saved_singlestep_ptid = singlestep_ptid;
+ /* If the PC of the thread we were trying to single-step
+ has changed, discard this event (which we were going
+ to ignore anyway), and pretend we saw that thread
+ trap. This prevents us continuously moving the
+ single-step breakpoint forward, one instruction at a
+ time. If the PC has changed, then the thread we were
+ trying to single-step has trapped or been signalled,
+ but the event has not been reported to GDB yet.
+
+ There might be some cases where this loses signal
+ information, if a signal has arrived at exactly the
+ same time that the PC changed, but this is the best
+ we can do with the information available. Perhaps we
+ should arrange to report all events for all threads
+ when they stop, or to re-poll the remote looking for
+ this particular thread (i.e. temporarily enable
+ schedlock). */
+ if (read_pc_pid (singlestep_ptid) != singlestep_pc)
+ {
+ if (debug_infrun)
+ fprintf_unfiltered (gdb_stdlog, "infrun: unexpected thread,"
+ " but expected thread advanced also\n");
+
+ /* The current context still belongs to
+ singlestep_ptid. Don't swap here, since that's
+ the context we want to use. Just fudge our
+ state and continue. */
+ ecs->ptid = singlestep_ptid;
+ stop_pc = read_pc_pid (ecs->ptid);
+ }
+ else
+ {
+ if (debug_infrun)
+ fprintf_unfiltered (gdb_stdlog,
+ "infrun: unexpected thread\n");
+
+ thread_hop_needed = 1;
+ stepping_past_singlestep_breakpoint = 1;
+ saved_singlestep_ptid = singlestep_ptid;
+ }
}
}
if (deprecated_context_hook)
deprecated_context_hook (pid_to_thread_id (ecs->ptid));
-
- flush_cached_frames ();
}
if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p)
duration of this command. Then, install a temporary
breakpoint at the target of the jmp_buf. */
if (debug_infrun)
- fprintf_unfiltered (gdb_stdlog, "infrun: BPSTATE_WHAT_SET_LONGJMP_RESUME\n");
+ fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
disable_longjmp_breakpoint ();
remove_breakpoints ();
breakpoints_inserted = 0;
case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE:
if (debug_infrun)
- fprintf_unfiltered (gdb_stdlog, "infrun: BPSTATE_WHAT_CLEAR_LONGJMP_RESUME\n");
+ fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
remove_breakpoints ();
breakpoints_inserted = 0;
disable_longjmp_breakpoint ();
case BPSTAT_WHAT_SINGLE:
if (debug_infrun)
- fprintf_unfiltered (gdb_stdlog, "infrun: BPSTATE_WHAT_SINGLE\n");
+ fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_SINGLE\n");
if (breakpoints_inserted)
{
remove_breakpoints ();
case BPSTAT_WHAT_STOP_NOISY:
if (debug_infrun)
- fprintf_unfiltered (gdb_stdlog, "infrun: BPSTATE_WHAT_STOP_NOISY\n");
+ fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
stop_print_frame = 1;
/* We are about to nuke the step_resume_breakpointt via the
case BPSTAT_WHAT_STOP_SILENT:
if (debug_infrun)
- fprintf_unfiltered (gdb_stdlog, "infrun: BPSTATE_WHAT_STOP_SILENT\n");
+ fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
stop_print_frame = 0;
/* We are about to nuke the step_resume_breakpoin via the
the one deleted is the one currently stopped at. MVS */
if (debug_infrun)
- fprintf_unfiltered (gdb_stdlog, "infrun: BPSTATE_WHAT_STEP_RESUME\n");
+ fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
if (step_resume_breakpoint == NULL)
{
case BPSTAT_WHAT_THROUGH_SIGTRAMP:
if (debug_infrun)
- fprintf_unfiltered (gdb_stdlog, "infrun: BPSTATE_WHAT_THROUGH_SIGTRAMP\n");
+ fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_THROUGH_SIGTRAMP\n");
/* If were waiting for a trap, hitting the step_resume_break
doesn't count as getting it. */
if (trap_expected)
case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK:
{
if (debug_infrun)
- fprintf_unfiltered (gdb_stdlog, "infrun: BPSTATE_WHAT_CHECK_SHLIBS\n");
+ fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_CHECK_SHLIBS\n");
/* Remove breakpoints, we eventually want to step over the
shlib event breakpoint, and SOLIB_ADD might adjust
breakpoint addresses via breakpoint_re_set. */
return;
}
- if (frame_id_eq (frame_unwind_id (get_current_frame ()), step_frame_id))
+ /* Check for subroutine calls. The check for the current frame
+ equalling the step ID is not necessary - the check of the
+ previous frame's ID is sufficient - but it is a common case and
+ cheaper than checking the previous frame's ID.
+
+ NOTE: frame_id_eq will never report two invalid frame IDs as
+ being equal, so to get into this block, both the current and
+ previous frame must have valid frame IDs. */
+ if (!frame_id_eq (get_frame_id (get_current_frame ()), step_frame_id)
+ && frame_id_eq (frame_unwind_id (get_current_frame ()), step_frame_id))
{
- /* It's a subroutine call. */
CORE_ADDR real_stop_pc;
if (debug_infrun)
/* We're doing a "next", set a breakpoint at callee's return
address (the address at which the caller will
resume). */
- insert_step_resume_breakpoint_at_frame (get_prev_frame (get_current_frame ()));
+ insert_step_resume_breakpoint_at_caller (get_current_frame ());
keep_going (ecs);
return;
}
/* Set a breakpoint at callee's return address (the address at
which the caller will resume). */
- insert_step_resume_breakpoint_at_frame (get_prev_frame (get_current_frame ()));
+ insert_step_resume_breakpoint_at_caller (get_current_frame ());
keep_going (ecs);
return;
}
and no line number corresponding to the address where the
inferior stopped). Since we want to skip this kind of code,
we keep going until the inferior returns from this
- function. */
- if (step_stop_if_no_debug)
+ function - unless the user has asked us not to (via
+ set step-mode) or we no longer know how to get back
+ to the call site. */
+ if (step_stop_if_no_debug
+ || !frame_id_p (frame_unwind_id (get_current_frame ())))
{
/* If we have no line number and the step-stop-if-no-debug
is set, we stop the step so that the user has a chance to
{
/* Set a breakpoint at callee's return address (the address
at which the caller will resume). */
- insert_step_resume_breakpoint_at_frame (get_prev_frame (get_current_frame ()));
+ insert_step_resume_breakpoint_at_caller (get_current_frame ());
keep_going (ecs);
return;
}
if (breakpoints_inserted)
insert_breakpoints ();
}
-
-/* Insert a "step resume breakpoint" at RETURN_FRAME.pc. This is used
- to skip a function (next, skip-no-debug) or signal. It's assumed
- that the function/signal handler being skipped eventually returns
- to the breakpoint inserted at RETURN_FRAME.pc.
- For the skip-function case, the function may have been reached by
- either single stepping a call / return / signal-return instruction,
- or by hitting a breakpoint. In all cases, the RETURN_FRAME belongs
- to the skip-function's caller.
+/* Insert a "step resume breakpoint" at RETURN_FRAME.pc. This is used
+ to skip a potential signal handler.
- For the signals case, this is called with the interrupted
- function's frame. The signal handler, when it returns, will resume
- the interrupted function at RETURN_FRAME.pc. */
+ This is called with the interrupted function's frame. The signal
+ handler, when it returns, will resume the interrupted function at
+ RETURN_FRAME.pc. */
static void
insert_step_resume_breakpoint_at_frame (struct frame_info *return_frame)
insert_step_resume_breakpoint_at_sal (sr_sal, get_frame_id (return_frame));
}
+/* Similar to insert_step_resume_breakpoint_at_frame, except
+ but a breakpoint at the previous frame's PC. This is used to
+ skip a function after stepping into it (for "next" or if the called
+ function has no debugging information).
+
+ The current function has almost always been reached by single
+ stepping a call or return instruction. NEXT_FRAME belongs to the
+ current function, and the breakpoint will be set at the caller's
+ resume address.
+
+ This is a separate function rather than reusing
+ insert_step_resume_breakpoint_at_frame in order to avoid
+ get_prev_frame, which may stop prematurely (see the implementation
+ of frame_unwind_id for an example). */
+
+static void
+insert_step_resume_breakpoint_at_caller (struct frame_info *next_frame)
+{
+ struct symtab_and_line sr_sal;
+
+ /* We shouldn't have gotten here if we don't know where the call site
+ is. */
+ gdb_assert (frame_id_p (frame_unwind_id (next_frame)));
+
+ init_sal (&sr_sal); /* initialize to zeros */
+
+ sr_sal.pc = ADDR_BITS_REMOVE (frame_pc_unwind (next_frame));
+ sr_sal.section = find_pc_overlay (sr_sal.pc);
+
+ insert_step_resume_breakpoint_at_sal (sr_sal, frame_unwind_id (next_frame));
+}
+
static void
stop_stepping (struct execution_control_state *ecs)
{
target_terminal_ours ();
+ /* Set the current source location. This will also happen if we
+ display the frame below, but the current SAL will be incorrect
+ during a user hook-stop function. */
+ if (target_has_stack && !stop_stack_dummy)
+ set_current_sal_from_frame (get_current_frame (), 1);
+
/* Look up the hook_stop and run it (CLI internally handles problem
of stop_command's pre-hook not existing). */
if (stop_command)