Re: [PATCH v2 02/47] Add test for continuing with some threads running

Pedro Alves
2026-04-02T13:07:33Z

Hi!

On 2025-05-21 20:36, Kevin Buettner wrote:
> On Mon, 19 May 2025 14:22:23 +0100

Wow, another year passed... :-/

> Pedro Alves <pedro@palves.net> wrote:
>
>> This testcase would have helped catch some issues I ran into while
>> working on the Windows non-stop support.
>>
>> It tests continuing all threads in all-stop mode when at least one
>> thread is already running.
>
> LGTM.
>
> Approved-by: Kevin Buettner <kevinb@redhat.com>
>

Thank you. I've merged this, as below, with minor tweaks to adjust to modern times:

- copyright year
- "maint set target-non-stop on" for gdbserver
- gdb_watchdog instead of alarm
- tcl formatting to please pre-commit
- pass testfile instead of binfile to clean_restart

From f0fab4d2e5ff01cd81534eb64b43f8ab3da5a82a Mon Sep 17 00:00:00 2001
From: Pedro Alves <pedro@palves.net>
Date: Fri, 24 Jan 2025 18:10:50 +0000
Subject: [PATCH] Add test for continuing with some threads running

This testcase would have helped catch some issues I ran into while
working on the Windows non-stop support.

It tests continuing all threads in all-stop mode when at least one
thread is already running.

Approved-by: Kevin Buettner <kevinb@redhat.com>
Change-Id: Ie8cd5c67502aed3c3b159d5eb5eeedee2f84eeef
commit-id:f4f07192
---
.../gdb.threads/continue-some-running.c | 77 +++++++++++++++++++
.../gdb.threads/continue-some-running.exp | 57 ++++++++++++++
2 files changed, 134 insertions(+)
create mode 100644 gdb/testsuite/gdb.threads/continue-some-running.c
create mode 100644 gdb/testsuite/gdb.threads/continue-some-running.exp

diff --git a/gdb/testsuite/gdb.threads/continue-some-running.c b/gdb/testsuite/gdb.threads/continue-some-running.c
new file mode 100644
index 00000000000..fd77af3cefa
--- /dev/null
+++ b/gdb/testsuite/gdb.threads/continue-some-running.c
@@ -0,0 +1,77 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2025-2026 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 <assert.h>
+#include <unistd.h>
+#include "gdb_watchdog.h"
+
+volatile int wait_for_gdb = 1;
+
+#define NUM_THREADS 3
+
+static pthread_barrier_t threads_started_barrier;
+
+static pthread_barrier_t may_exit_barrier;
+
+static void *
+thread_func (void *arg)
+{
+ /* Wait until all threads have started. */
+ pthread_barrier_wait (&threads_started_barrier);
+
+ /* Wait until the main thread lets us exit. */
+ pthread_barrier_wait (&may_exit_barrier);
+
+ return NULL;
+}
+
+static void
+threads_started (void)
+{
+}
+
+int
+main (void)
+{
+ pthread_t thread[NUM_THREADS];
+ int i;
+
+ gdb_watchdog (30);
+
+ pthread_barrier_init (&threads_started_barrier, NULL, NUM_THREADS + 1);
+ pthread_barrier_init (&may_exit_barrier, NULL, NUM_THREADS + 1);
+
+ for (i = 0; i < NUM_THREADS; i++)
+ {
+ int ret;
+
+ ret = pthread_create (&thread[i], NULL, thread_func, NULL);
+ assert (ret == 0);
+ }
+
+ pthread_barrier_wait (&threads_started_barrier);
+
+ threads_started ();
+
+ pthread_barrier_wait (&may_exit_barrier);
+
+ for (i = 0; i < NUM_THREADS; i++)
+ pthread_join (thread[i], NULL);
+
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.threads/continue-some-running.exp b/gdb/testsuite/gdb.threads/continue-some-running.exp
new file mode 100644
index 00000000000..d6716e8ff16
--- /dev/null
+++ b/gdb/testsuite/gdb.threads/continue-some-running.exp
@@ -0,0 +1,57 @@
+# Copyright 2025-2026 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 continuing in all-stop mode when one thread is already running.
+
+standard_testfile .c
+
+if { [build_executable "failed to prepare" $testfile $srcfile \
+ {debug pthreads}] \
+ == -1 } {
+ return
+}
+
+proc test {} {
+ # This test requires background execution, which relies on
+ # non-stop mode.
+ save_vars { ::GDBFLAGS } {
+ append ::GDBFLAGS " -ex \"maint set target-non-stop on\""
+ clean_restart $::testfile
+ }
+
+ if {![runto threads_started]} {
+ return
+ }
+
+ delete_breakpoints
+
+ # Set a non-main thread running, while everything else is left
+ # stopped.
+ gdb_test_no_output "set scheduler-locking on"
+
+ gdb_test "thread 2" ".*" "switch to secondary thread"
+
+ gdb_test -no-prompt-anchor "continue &" "Continuing\\."
+
+ # Now resume all threads, while there is already one thread
+ # running.
+ gdb_test "thread 1" ".*" "switch to main thread"
+
+ gdb_test_no_output "set scheduler-locking off"
+
+ gdb_continue_to_end "" continue 1
+}
+
+test

--
2.53.0