static int currently_stepping (struct thread_info *tp);
-static int currently_stepping_or_nexting_callback (struct thread_info *tp,
- void *data);
-
static void xdb_handle_command (char *args, int from_tty);
static void print_exited_reason (int exitstatus);
return 0;
}
+/* Returns true if scheduler locking applies. STEP indicates whether
+ we're about to do a step/next-like command to a thread. */
+
+static int
+schedlock_applies (int step)
+{
+ return (scheduler_mode == schedlock_on
+ || (scheduler_mode == schedlock_step
+ && step));
+}
+
/* Look a thread other than EXCEPT that has previously reported a
breakpoint event, and thus needs a step-over in order to make
progress. Returns NULL is none is found. STEP indicates whether
static struct thread_info *
find_thread_needs_step_over (int step, struct thread_info *except)
{
- int schedlock_enabled;
struct thread_info *tp, *current;
/* With non-stop mode on, threads are always handled individually. */
gdb_assert (! non_stop);
- schedlock_enabled = (scheduler_mode == schedlock_on
- || (scheduler_mode == schedlock_step
- && step));
-
current = inferior_thread ();
/* If scheduler locking applies, we can avoid iterating over all
threads. */
- if (schedlock_enabled)
+ if (schedlock_applies (step))
{
if (except != current
&& thread_still_needs_step_over (current))
{
struct thread_info *tp;
struct thread_info *stepping_thread;
+ struct thread_info *step_over;
/* If any thread is blocked on some internal breakpoint, and we
simply need to step over that breakpoint to get it going
return 1;
}
- stepping_thread
- = iterate_over_threads (currently_stepping_or_nexting_callback,
- ecs->event_thread);
+ /* Otherwise, we no longer expect a trap in the current thread.
+ Clear the trap_expected flag before switching back -- this is
+ what keep_going does as well, if we call it. */
+ ecs->event_thread->control.trap_expected = 0;
+
+ /* If scheduler locking applies even if not stepping, there's no
+ need to walk over threads. Above we've checked whether the
+ current thread is stepping. If some other thread not the
+ event thread is stepping, then it must be that scheduler
+ locking is not in effect. */
+ if (schedlock_applies (0))
+ return 0;
+
+ /* Look for the stepping/nexting thread, and check if any other
+ thread other than the stepping thread needs to start a
+ step-over. Do all step-overs before actually proceeding with
+ step/next/etc. */
+ stepping_thread = NULL;
+ step_over = NULL;
+ ALL_THREADS (tp)
+ {
+ /* Ignore threads of processes we're not resuming. */
+ if (!sched_multi
+ && ptid_get_pid (tp->ptid) != ptid_get_pid (inferior_ptid))
+ continue;
+
+ /* When stepping over a breakpoint, we lock all threads
+ except the one that needs to move past the breakpoint.
+ If a non-event thread has this set, the "incomplete
+ step-over" check above should have caught it earlier. */
+ gdb_assert (!tp->control.trap_expected);
+
+ /* Did we find the stepping thread? */
+ if (tp->control.step_range_end)
+ {
+ /* Yep. There should only one though. */
+ gdb_assert (stepping_thread == NULL);
+
+ /* The event thread is handled at the top, before we
+ enter this loop. */
+ gdb_assert (tp != ecs->event_thread);
+
+ /* If some thread other than the event thread is
+ stepping, then scheduler locking can't be in effect,
+ otherwise we wouldn't have resumed the current event
+ thread in the first place. */
+ gdb_assert (!schedlock_applies (1));
+
+ stepping_thread = tp;
+ }
+ else if (thread_still_needs_step_over (tp))
+ {
+ step_over = tp;
+
+ /* At the top we've returned early if the event thread
+ is stepping. If some other thread not the event
+ thread is stepping, then scheduler locking can't be
+ in effect, and we can resume this thread. No need to
+ keep looking for the stepping thread then. */
+ break;
+ }
+ }
- /* Check if any other thread except the stepping thread that
- needs to start a step-over. Do that before actually
- proceeding with step/next/etc. */
- tp = find_thread_needs_step_over (stepping_thread != NULL,
- stepping_thread);
- if (tp != NULL)
+ if (step_over != NULL)
{
+ tp = step_over;
if (debug_infrun)
{
fprintf_unfiltered (gdb_stdlog,
target_pid_to_str (tp->ptid));
}
- gdb_assert (!tp->control.trap_expected);
+ /* Only the stepping thread should have this set. */
gdb_assert (tp->control.step_range_end == 0);
- /* We no longer expect a trap in the current thread. Clear
- the trap_expected flag before switching. This is what
- keep_going would do as well, if we called it. */
- ecs->event_thread->control.trap_expected = 0;
-
ecs->ptid = tp->ptid;
ecs->event_thread = tp;
switch_to_thread (ecs->ptid);
return 1;
}
- tp = stepping_thread;
- if (tp != NULL)
+ if (stepping_thread != NULL)
{
struct frame_info *frame;
struct gdbarch *gdbarch;
+ tp = stepping_thread;
+
/* If the stepping thread exited, then don't try to switch
back and resume it, which could fail in several different
ways depending on the target. Instead, just keep going.
return 1;
}
- /* Otherwise, we no longer expect a trap in the current thread.
- Clear the trap_expected flag before switching back -- this is
- what keep_going would do as well, if we called it. */
- ecs->event_thread->control.trap_expected = 0;
-
if (debug_infrun)
fprintf_unfiltered (gdb_stdlog,
"infrun: switching back to stepped thread\n");
|| bpstat_should_step ());
}
-/* Returns true if any thread *but* the one passed in "data" is in the
- middle of stepping or of handling a "next". */
-
-static int
-currently_stepping_or_nexting_callback (struct thread_info *tp, void *data)
-{
- if (tp == data)
- return 0;
-
- return (tp->control.step_range_end
- || tp->control.trap_expected);
-}
-
/* Inferior has stepped into a subroutine call with source code that
we should not step over. Do step to the first line of code in
it. */
--- /dev/null
+# Copyright 2014 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#
+# Regression test for a bug where GDB would internal error if a thread
+# runs into a breakpoint that needs stepping over, just after stepping
+# over another breakpoint, without a user visible stop in between.
+#
+standard_testfile
+
+if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
+ return -1
+}
+
+if ![runto_main] then {
+ fail "Can't run to main"
+ return 0
+}
+
+# Make sure the target doesn't hide the breakpoint hits (that don't
+# cause a user visible stop) from GDB.
+gdb_test_no_output "set breakpoint condition-evaluation host"
+
+set up_to_nl "\[^\r\n\]+\[\r\n\]+"
+
+# Number of consecutive breakpoints in a row to try.
+set n_insns 3
+
+# Extract addresses of a few consecutive instructions.
+set test "get breakpoint addresses"
+if { [gdb_test_multiple "x /[expr $n_insns + 1]i \$pc" $test {
+ -re "=> $hex${up_to_nl} ($hex)${up_to_nl} ($hex)${up_to_nl} ($hex)${up_to_nl}$gdb_prompt $" {
+ for {set i 1} {$i <= $n_insns} {incr i} {
+ set bp_addrs($i) $expect_out($i,string)
+ }
+ pass $test
+ }
+}] != 0 } {
+ # No use proceeding if bp_addrs wasn't set.
+ return
+}
+
+for {set i 1} {$i <= $n_insns} {incr i} {
+ with_test_prefix "insn $i" {
+ gdb_test "break \*$bp_addrs($i)" \
+ "Breakpoint $decimal at $bp_addrs($i): file .*" \
+ "set breakpoint"
+
+ # Give the breakpoint a condition that always fails, so that
+ # the thread is immediately re-resumed.
+ gdb_test_no_output "condition \$bpnum condition" \
+ "set condition"
+ }
+}
+
+set lineno [gdb_get_line_number "break here"]
+gdb_breakpoint $lineno
+gdb_continue_to_breakpoint "break here" ".*break here.*"