summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gdb/ChangeLog8
-rw-r--r--gdb/infrun.c18
-rw-r--r--gdb/testsuite/ChangeLog5
-rw-r--r--gdb/testsuite/gdb.multi/stop-all-on-exit.c27
-rw-r--r--gdb/testsuite/gdb.multi/stop-all-on-exit.exp64
5 files changed, 118 insertions, 4 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index c7f4ac4f54f..ef62216e0ad 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,13 @@
2020-04-01 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
+ * infrun.c (stop_all_threads): Update assertion, plus when
+ stopping threads, take into account that we might be trying
+ to stop an all-stop target.
+ (stop_waiting): Call 'stop_all_threads' if there exists a
+ non-stop target.
+
+2020-04-01 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
+
* target.h (exists_non_stop_target): New function declaration.
* target.c (exists_non_stop_target): New function.
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 1fb445aa247..8ff34c382d6 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -4711,7 +4711,7 @@ stop_all_threads (void)
int pass;
int iterations = 0;
- gdb_assert (target_is_non_stop_p ());
+ gdb_assert (exists_non_stop_target ());
if (debug_infrun)
fprintf_unfiltered (gdb_stdlog, "infrun: stop_all_threads\n");
@@ -4742,6 +4742,17 @@ stop_all_threads (void)
to tell the target to stop. */
for (thread_info *t : all_non_exited_threads ())
{
+ /* For a single-target setting with an all-stop target,
+ we would not even arrive here. For a multi-target
+ setting, until GDB is able to handle a mixture of
+ all-stop and non-stop targets, simply skip all-stop
+ targets' threads. This should be fine due to the
+ protection of 'check_multi_target_resumption'. */
+
+ switch_to_thread_no_regs (t);
+ if (!target_is_non_stop_p ())
+ continue;
+
if (t->executing)
{
/* If already stopping, don't request a stop again.
@@ -4753,7 +4764,6 @@ stop_all_threads (void)
"infrun: %s executing, "
"need stop\n",
target_pid_to_str (t->ptid).c_str ());
- switch_to_thread_no_regs (t);
target_stop (t->ptid);
t->stop_requested = 1;
}
@@ -7894,9 +7904,9 @@ stop_waiting (struct execution_control_state *ecs)
/* Let callers know we don't want to wait for the inferior anymore. */
ecs->wait_some_more = 0;
- /* If all-stop, but the target is always in non-stop mode, stop all
+ /* If all-stop, but there exists a non-stop target, stop all
threads now that we're presenting the stop to the user. */
- if (!non_stop && target_is_non_stop_p ())
+ if (!non_stop && exists_non_stop_target ())
stop_all_threads ();
}
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 58271cf8ccb..28d1bcfb1b0 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-04-01 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
+
+ * gdb.multi/stop-all-on-exit.c: New test.
+ * gdb.multi/stop-all-on-exit.exp: New file.
+
2020-04-01 Hannes Domani <ssbssa@yahoo.de>
PR gdb/24789
diff --git a/gdb/testsuite/gdb.multi/stop-all-on-exit.c b/gdb/testsuite/gdb.multi/stop-all-on-exit.c
new file mode 100644
index 00000000000..bca0c98e021
--- /dev/null
+++ b/gdb/testsuite/gdb.multi/stop-all-on-exit.c
@@ -0,0 +1,27 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2020 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>
+
+static unsigned int duration = 1;
+
+int
+main ()
+{
+ sleep (duration);
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.multi/stop-all-on-exit.exp b/gdb/testsuite/gdb.multi/stop-all-on-exit.exp
new file mode 100644
index 00000000000..61deb564e6a
--- /dev/null
+++ b/gdb/testsuite/gdb.multi/stop-all-on-exit.exp
@@ -0,0 +1,64 @@
+# This testcase is part of GDB, the GNU debugger.
+
+# Copyright 2020 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 in all-stop mode with multiple inferiors, GDB stops all
+# threads upon receiving an exit event from one of the inferiors.
+
+standard_testfile
+
+if {[prepare_for_testing "failed to prepare" $testfile $srcfile]} {
+ return -1
+}
+
+if {![runto_main]} {
+ fail "starting inferior 1"
+ return -1
+}
+
+# This is a test specific for a native target, where we use the
+# "-exec" argument to "add-inferior" and we explicitly don't do
+# "maint set target-non-stop on".
+if {![gdb_is_target_native]} {
+ untested "the test is aimed at a native target"
+ return 0
+}
+
+# Add a second inferior that will sleep longer.
+gdb_test "add-inferior -exec $binfile" "Added inferior 2.*" \
+ "add the second inferior"
+gdb_test "inferior 2" ".*Switching to inferior 2.*"
+if {![runto_main]} {
+ fail "starting inferior 2"
+ return -1
+}
+gdb_test "print duration=10" "= 10"
+
+# Now continue both processes. We should get the exit event from the
+# first inferior.
+gdb_test_no_output "set schedule-multiple on"
+gdb_continue_to_end
+
+# GDB is expected to have stopped the other inferior. Switch to the
+# slow inferior's thread. It should not be running.
+gdb_test_multiple "thread 2.1" "check thread 2.1 is not running" {
+ -re "\\(running\\)\[\r\n\]+$gdb_prompt" {
+ fail $gdb_test_name
+ }
+ -re "$gdb_prompt" {
+ pass $gdb_test_name
+ }
+}