forked from Imagelibrary/binutils-gdb
If you do "interrupt -a" just while some thread is stepping over a breakpoint, gdb trips on an internal error. The test added by this patch manages to trigger this consistently by spawning a few threads that are constantly tripping on a conditional breakpoint whose condition always evaluates to false. With current gdb, you get: ~~~ interrupt -a .../src/gdb/inline-frame.c:343: internal-error: void skip_inline_frames(ptid_t): Assertion `find_inline_frame_state (ptid) == NULL' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session? (y or n) FAIL: gdb.threads/interrupt-while-step-over.exp: displaced-stepping=on: iter=0: interrupt -a (GDB internal error) [...] .../src/gdb/inline-frame.c:343: internal-error: void skip_inline_frames(ptid_t): Assertion `find_inline_frame_state (ptid) == NULL' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session? (y or n) FAIL: gdb.threads/interrupt-while-step-over.exp: displaced-stepping=off: iter=0: wait for stops (GDB internal error) ~~~ The assertion triggers because we're processing a stop for a thread that had already stopped before and thus had already its inline-frame state filled in. Calling handle_inferior_event_1 directly within a "thread_stop_requested" observer is something that I've wanted to get rid of before, for being fragile. Nowadays, infrun is aware of threads with pending events, so we can use that instead, and let the normal fetch_inferior_event -> handle_inferior_event code path handle the forced stop. The change to finish_step_over is necessary because sometimes a thread that was told to PTRACE_SINGLESTEP reports back a SIGSTOP instead of a SIGTRAP (i.e., we tell it to single-step, and then interrupt it quick enough that on the kernel side the thread dequeues the SIGTOP before ever having had a chance of executing the instruction to be stepped). SIGSTOP gets translated to a GDB_SIGNAL_0. And then finish_step_over would miss calling clear_step_over_info, and thus miss restarting the other threads (which in this case of threads with pending events, means setting their "resumed" flag, so their pending events can be consumed). And now that we always restart threads in finish_step_over, we no longer need to do that in handle_signal_stop. Tested on x86_64 Fedora 23, native and gdbserver. gdb/ChangeLog: 2017-03-08 Pedro Alves <palves@redhat.com> PR gdb/18360 * infrun.c (start_step_over, do_target_resume, resume) (restart_threads): Assert we're not resuming a thread that is meant to be stopped. (infrun_thread_stop_requested_callback): Delete. (infrun_thread_stop_requested): If the thread is internally stopped, queue a pending stop event and clear the thread's inline-frame state. (handle_stop_requested): New function. (handle_syscall_event, handle_inferior_event_1): Use handle_stop_requested. (handle_stop_requested): New function. (handle_signal_stop): Set the thread's stop_signal here instead of at caller. (finish_step_over): Clear step over info unconditionally. (handle_signal_stop): If the user had interrupted the event thread, consider the stop a random signal. (handle_signal_stop) <signal arrived while stepping over breakpoint>: Don't restart threads here. (stop_waiting): Don't clear step-over info here. gdb/testsuite/ChangeLog: 2017-03-08 Pedro Alves <palves@redhat.com> PR gdb/18360 * gdb.threads/interrupt-while-step-over.c: New file. * gdb.threads/interrupt-while-step-over.exp: New file.
113 lines
3.6 KiB
Plaintext
113 lines
3.6 KiB
Plaintext
# Copyright (C) 2011-2017 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/>.
|
|
|
|
# Test that GDB doesn't inadvertently resume the stepped thread when a
|
|
# signal arrives while stepping over the breakpoint that last caused a
|
|
# stop, when the thread that hit that breakpoint is not the stepped
|
|
# thread.
|
|
|
|
standard_testfile
|
|
set executable ${testfile}
|
|
|
|
if [target_info exists gdb,nosignals] {
|
|
verbose "Skipping ${testfile}.exp because of nosignals."
|
|
return -1
|
|
}
|
|
|
|
if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
|
|
executable [list debug "incdir=${objdir}"]] != "" } {
|
|
return -1
|
|
}
|
|
|
|
proc get_value {var test} {
|
|
global expect_out
|
|
global gdb_prompt
|
|
global decimal
|
|
|
|
set value -1
|
|
gdb_test_multiple "print $var" "$test" {
|
|
-re ".*= ($decimal).*\r\n$gdb_prompt $" {
|
|
set value $expect_out(1,string)
|
|
pass "$test"
|
|
}
|
|
}
|
|
return ${value}
|
|
}
|
|
|
|
# Start with a fresh gdb.
|
|
|
|
clean_restart $executable
|
|
|
|
if ![runto_main] {
|
|
return -1
|
|
}
|
|
|
|
gdb_breakpoint [gdb_get_line_number "set wait-thread-2 breakpoint here"]
|
|
gdb_continue_to_breakpoint "run to wait-thread-2 breakpoint"
|
|
gdb_test "info threads" "" "info threads with thread 2"
|
|
|
|
gdb_breakpoint [gdb_get_line_number "set wait-thread-3 breakpoint here"]
|
|
gdb_continue_to_breakpoint "run to breakpoint"
|
|
gdb_test "info threads" "" "info threads with thread 3"
|
|
|
|
gdb_test "set scheduler-locking on"
|
|
|
|
gdb_breakpoint [gdb_get_line_number "set breakpoint child_two here"]
|
|
gdb_breakpoint [gdb_get_line_number "set breakpoint child_one here"]
|
|
|
|
gdb_test "thread 3" "" "switch to thread 3 to run to its breakpoint"
|
|
gdb_continue_to_breakpoint "run to breakpoint in thread 3"
|
|
|
|
gdb_test "thread 2" "" "switch to thread 2 to run to its breakpoint"
|
|
gdb_continue_to_breakpoint "run to breakpoint in thread 2"
|
|
|
|
delete_breakpoints
|
|
|
|
gdb_test "b *\$pc" "" "set breakpoint to be stepped over"
|
|
# Make sure the first loop breaks without hitting the breakpoint
|
|
# again.
|
|
gdb_test "p *myp = 0" " = 0" "force loop break in thread 2"
|
|
|
|
# We want "print" to make sure the target reports the signal to the
|
|
# core.
|
|
gdb_test "handle SIGUSR1 print nostop pass" "" ""
|
|
|
|
gdb_test "thread 1" "" "switch to thread 1 to queue signal in thread 2"
|
|
gdb_test "next 2" "pthread_join .*" "queue signal in thread 2"
|
|
|
|
gdb_test "thread 3" "" "switch to thread 3 for stepping"
|
|
set my_number [get_value "my_number" "get my_number"]
|
|
set cnt_before [get_value "args\[$my_number\]" "get count before step"]
|
|
gdb_test "set scheduler-locking off"
|
|
|
|
# Make sure we're exercising the paths we want to.
|
|
gdb_test "set debug infrun 1"
|
|
|
|
set test "step"
|
|
gdb_test_sequence $test $test {
|
|
"need to step-over"
|
|
"resume \\(step=1"
|
|
"signal arrived while stepping over breakpoint"
|
|
"stepped to a different line"
|
|
"callme"
|
|
}
|
|
|
|
set cnt_after [get_value "args\[$my_number\]" "get count after step"]
|
|
|
|
# Test that GDB doesn't inadvertently resume the stepped thread when a
|
|
# signal arrives while stepping over a breakpoint in another thread.
|
|
|
|
gdb_assert { $cnt_before + 1 == $cnt_after } "stepped thread under control"
|