aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2015-06-29 16:07:57 +0100
committerPedro Alves <palves@redhat.com>2015-06-29 16:07:57 +0100
commit28bf096c62d7da6b349605f3940f4c586a850f78 (patch)
tree65c0704ba57a22a29c866b96b3bcd7b08211ca43 /gdb/testsuite
parent2880b51c25b055013c2f4939a5d0c0779b972bb3 (diff)
downloadgdb-28bf096c62d7da6b349605f3940f4c586a850f78.zip
gdb-28bf096c62d7da6b349605f3940f4c586a850f78.tar.gz
gdb-28bf096c62d7da6b349605f3940f4c586a850f78.tar.bz2
PR threads/18127 - threads spawned by infcall end up stuck in "running" state
Refs: https://sourceware.org/ml/gdb/2015-03/msg00024.html https://sourceware.org/ml/gdb/2015-06/msg00005.html On GNU/Linux, if an infcall spawns a thread, that thread ends up with stuck running state. This happens because: - when linux-nat.c detects a new thread, it marks them as running, and does not report anything to the core. - we skip finish_thread_state when the thread that is running the infcall stops. As result, that new thread ends up with stuck "running" state, even though it really is stopped. On Windows, _all_ threads end up stuck in running state, not just the one that was spawned. That happens because when a new thread is detected, unlike linux-nat.c, windows-nat.c reports TARGET_WAITKIND_SPURIOUS to infrun. It's the fact that that event does not cause a user-visible stop that triggers the problem. When the target is re-resumed, we call set_running with a wildcard ptid, which marks all thread as running. That set_running is not suppressed because the (leader) thread being resumed does not have in_infcall set. Later, when the infcall finally finishes successfully, nothing marks all threads back to stopped. We can trigger the same problem on all targets by having a thread other than the one that is running the infcall report a breakpoint hit to infrun, and then have that breakpoint not cause a stop. That's what the included test does. The fix is to stop GDB from suppressing the set_running calls while doing an infcall, and then set the threads back to stopped when the call finishes, iff they were originally stopped before the infcall started. (Note the MI *running/*stopped event suppression isn't affected.) Tested on x86_64 GNU/Linux. gdb/ChangeLog: 2015-06-29 Pedro Alves <palves@redhat.com> PR threads/18127 * infcall.c (run_inferior_call): On infcall success, if the thread was marked stopped before, reset it back to stopped. * infrun.c (resume): Don't suppress the set_running calls when doing an infcall. (normal_stop): Only discard the finish_thread_state cleanup if the infcall succeeded. gdb/testsuite/ChangeLog: 2015-06-29 Pedro Alves <palves@redhat.com> PR threads/18127 * gdb.threads/hand-call-new-thread.c: New file. * gdb.threads/hand-call-new-thread.c: New file.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/ChangeLog6
-rw-r--r--gdb/testsuite/gdb.threads/hand-call-new-thread.c50
-rw-r--r--gdb/testsuite/gdb.threads/hand-call-new-thread.exp48
3 files changed, 104 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 89d8e32..d9ec546 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2015-06-29 Pedro Alves <palves@redhat.com>
+
+ PR threads/18127
+ * gdb.threads/hand-call-new-thread.c: New file.
+ * gdb.threads/hand-call-new-thread.c: New file.
+
2015-06-26 Keith Seitz <keiths@redhat.com>
Doug Evans <dje@google.com>
diff --git a/gdb/testsuite/gdb.threads/hand-call-new-thread.c b/gdb/testsuite/gdb.threads/hand-call-new-thread.c
new file mode 100644
index 0000000..042be9b
--- /dev/null
+++ b/gdb/testsuite/gdb.threads/hand-call-new-thread.c
@@ -0,0 +1,50 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2015 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 <unistd.h>
+#include <stdlib.h>
+#include <pthread.h>
+#include <assert.h>
+
+static int
+foo (void)
+{
+ usleep (1);
+}
+
+static void *
+thread_function (void *arg)
+{
+ while (1)
+ foo ();
+}
+
+void
+new_thread (void)
+{
+ pthread_t thread;
+ int res;
+
+ res = pthread_create (&thread, NULL, thread_function, NULL);
+ assert (res == 0);
+}
+
+int
+main (int argc, char **argv)
+{
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.threads/hand-call-new-thread.exp b/gdb/testsuite/gdb.threads/hand-call-new-thread.exp
new file mode 100644
index 0000000..a02d8ba
--- /dev/null
+++ b/gdb/testsuite/gdb.threads/hand-call-new-thread.exp
@@ -0,0 +1,48 @@
+# Copyright (C) 2015 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/>.
+
+# Ensure that new threads created while an infcall is ongoing are set
+# to stopped state once the call finishes.
+
+standard_testfile
+
+if [prepare_for_testing "failed to prepare" $testfile $srcfile {debug pthreads}] {
+ return -1
+}
+
+if ![runto_main] {
+ continue
+}
+
+# Set a thread-specific breakpoint that the wrong thread trips on
+# while running the infcall. Check that no thread ends up in stale
+# "running" state once the call finishes.
+gdb_test "b foo thread 1" "Breakpoint .*$srcfile.*"
+
+for {set i 0} {$i < 3} {incr i} {
+ with_test_prefix "iter $i" {
+ gdb_test "p new_thread ()" " = void"
+
+ set message "no thread marked running"
+ gdb_test_multiple "info threads" $message {
+ -re "\\\(running\\\).*$gdb_prompt $" {
+ fail $message
+ }
+ -re "$gdb_prompt $" {
+ pass $message
+ }
+ }
+ }
+}