diff options
author | Pedro Alves <palves@redhat.com> | 2017-03-08 18:54:34 +0000 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2017-03-08 18:54:34 +0000 |
commit | c65d6b55b3a592906c470c566f57ad8ceacc1605 (patch) | |
tree | 1021885bd9ddfc11033d35d5fab7d538b8fb5dd9 /gdb/testsuite | |
parent | 15c22686d0e33d87262bc9075296eeddd7d955f7 (diff) | |
download | gdb-c65d6b55b3a592906c470c566f57ad8ceacc1605.zip gdb-c65d6b55b3a592906c470c566f57ad8ceacc1605.tar.gz gdb-c65d6b55b3a592906c470c566f57ad8ceacc1605.tar.bz2 |
Fix PR18360 - internal error when using "interrupt -a"
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.
Diffstat (limited to 'gdb/testsuite')
4 files changed, 285 insertions, 1 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 4575e27..499377b 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,11 @@ 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. + +2017-03-08 Pedro Alves <palves@redhat.com> + * gdb.arch/amd64-entry-value-param-dwarf5.exp: Use with_test_prefix. * gdb.arch/amd64-entry-value-param.exp: Use with_test_prefix. diff --git a/gdb/testsuite/gdb.threads/interrupt-while-step-over.c b/gdb/testsuite/gdb.threads/interrupt-while-step-over.c new file mode 100644 index 0000000..0a62e34 --- /dev/null +++ b/gdb/testsuite/gdb.threads/interrupt-while-step-over.c @@ -0,0 +1,75 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2016-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/>. */ + +#include <pthread.h> +#include <unistd.h> +#include <stdlib.h> + +#define NUM_THREADS 20 +const int num_threads = NUM_THREADS; + +static pthread_t child_thread[NUM_THREADS]; + +static pthread_barrier_t threads_started_barrier; + +volatile int always_zero; +volatile unsigned int dummy; + +static void +infinite_loop (void) +{ + while (1) + { + dummy++; /* set breakpoint here */ + } +} + +static void * +child_function (void *arg) +{ + pthread_barrier_wait (&threads_started_barrier); + + infinite_loop (); +} + +void +all_started (void) +{ +} + +int +main (void) +{ + int res; + int i; + + alarm (300); + + pthread_barrier_init (&threads_started_barrier, NULL, NUM_THREADS + 1); + + for (i = 0; i < NUM_THREADS; i++) + { + res = pthread_create (&child_thread[i], NULL, child_function, NULL); + } + + /* Wait until all threads have been scheduled. */ + pthread_barrier_wait (&threads_started_barrier); + + all_started (); + + infinite_loop (); +} diff --git a/gdb/testsuite/gdb.threads/interrupt-while-step-over.exp b/gdb/testsuite/gdb.threads/interrupt-while-step-over.exp new file mode 100644 index 0000000..68d2570 --- /dev/null +++ b/gdb/testsuite/gdb.threads/interrupt-while-step-over.exp @@ -0,0 +1,204 @@ +# Copyright (C) 2016-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/>. + +# Regression test for PR gdb/18360. Test that "interrupt -a" while +# some thread is stepping over a breakpoint behaves as expected. + +standard_testfile + +if {[prepare_for_testing "failed to prepare" $testfile $srcfile \ + {debug pthreads}] == -1} { + return -1 +} + +if {![runto_main]} { + fail "can't run to main" + return -1 +} + +# Read the number of threads out of the inferior. +set NUM_THREADS [get_integer_valueof "num_threads" -1] + +# Account for the main thread. +incr NUM_THREADS + +# Run command and wait for the prompt, without end anchor. + +proc gdb_test_no_anchor {cmd} { + global gdb_prompt + + gdb_test_multiple $cmd $cmd { + -re "$gdb_prompt " { + pass $cmd + } + -re "infrun:" { + exp_continue + } + } +} + +# Enable/disable debugging. + +proc enable_debug {enable} { + + # Comment out to debug problems with the test. + return + + gdb_test_no_anchor "set debug infrun $enable" + gdb_test_no_anchor "set debug displaced $enable" +} + +# If RESULT is not zero, make the caller return RESULT. + +proc return_if_nonzero { result } { + if {$result != 0} { + return -code return $result + } +} + +# Do one iteration of "c -a& -> interrupt -a". Return zero on sucess, +# and non-zero if some test fails. + +proc test_one_iteration {} { + global gdb_prompt + global NUM_THREADS + global decimal + + set saw_continuing 0 + set test "continue -a &" + return_if_nonzero [gdb_test_multiple $test $test { + -re "Continuing.\r\n" { + set saw_continuing 1 + exp_continue + } + -re "$gdb_prompt " { + if ![gdb_assert $saw_continuing $test] { + return 1 + } + } + -re "infrun:" { + exp_continue + } + }] + + set running_count 0 + set test "all threads are running" + return_if_nonzero [gdb_test_multiple "info threads" $test { + -re "Thread \[^\r\n\]* \\(running\\)" { + incr running_count + exp_continue + } + -re "$gdb_prompt " { + if ![gdb_assert {$running_count == $NUM_THREADS} $test] { + return 1 + } + } + -re "infrun:" { + exp_continue + } + }] + + set test "interrupt -a" + return_if_nonzero [gdb_test_multiple $test $test { + -re "$gdb_prompt " { + pass $test + } + -re "infrun:" { + exp_continue + } + }] + + set stopped_count 0 + set test "wait for stops" + # Don't return on failure here, in order to let "info threads" put + # useful info in gdb.log. + gdb_test_multiple "" $test { + -re "Thread $decimal \[^\r\n\]*stopped" { + incr stopped_count + if {$stopped_count != $NUM_THREADS} { + exp_continue + } + } + -re "$gdb_prompt " { + gdb_assert {$stopped_count == $NUM_THREADS} $test + } + -re "infrun:" { + exp_continue + } + } + + # Check if all threads are seen as stopped with "info + # threads". It's a bit redundant with the test above, but + # it's useful to have this in the gdb.log if the above ever + # happens to fail. + set running_count 0 + set test "all threads are stopped" + return_if_nonzero [gdb_test_multiple "info threads" $test { + -re "Thread \[^\r\n\]* \\(running\\)" { + incr running_count + exp_continue + } + -re "$gdb_prompt " { + if ![gdb_assert {$running_count == 0} $test] { + return 1 + } + } + }] + + return 0 +} + +# The test driver proper. If DISPLACED is "on", turn on displaced +# stepping. If "off", turn it off. + +proc testdriver {displaced} { + global binfile + global GDBFLAGS + + save_vars { GDBFLAGS } { + append GDBFLAGS " -ex \"set non-stop on\"" + clean_restart $binfile + } + + gdb_test_no_output "set displaced-stepping $displaced" + + if ![runto all_started] { + fail "couldn't run to all_started" + return + } + set break_line [gdb_get_line_number "set breakpoint here"] + + gdb_test "break $break_line if always_zero" "Breakpoint .*" "set breakpoint" + + enable_debug 1 + + for {set iter 0} {$iter < 20} {incr iter} { + with_test_prefix "iter=$iter" { + # Return early if some test fails, to avoid cascading + # timeouts if something goes wrong. + if {[test_one_iteration] != 0} { + return + } + } + } +} + +foreach_with_prefix displaced-stepping {"on" "off"} { + if { ${displaced-stepping} != "off" && ![support_displaced_stepping] } { + continue + } + + testdriver ${displaced-stepping} +} diff --git a/gdb/testsuite/gdb.threads/signal-while-stepping-over-bp-other-thread.exp b/gdb/testsuite/gdb.threads/signal-while-stepping-over-bp-other-thread.exp index 200ab5b..144a13b 100644 --- a/gdb/testsuite/gdb.threads/signal-while-stepping-over-bp-other-thread.exp +++ b/gdb/testsuite/gdb.threads/signal-while-stepping-over-bp-other-thread.exp @@ -100,7 +100,6 @@ gdb_test_sequence $test $test { "need to step-over" "resume \\(step=1" "signal arrived while stepping over breakpoint" - "(restart threads|switching back to stepped thread)" "stepped to a different line" "callme" } |