Re: [PATCH v2 00/47] Windows non-stop mode

Pedro Alves
2025-06-11T23:52:24Z

[-- Attachment #1: Type: text/plain, Size: 3107 bytes --]

On 2025-06-05 18:57, Tom Tromey wrote:
>
> I'm not quite as sure about the last one. This test sets a couple of
> breakpoints that have 'commands', where the commands delete the
> breakpoint, like:
>
> [ break main.adb:4 then ... ]
> "silent",
> 'printf "Breakpoint hit #1.\\n"',
> "clear main.adb:4",
> "continue",
> "end",
>
> When running the expected output is seen but gdb says:
>
> (gdb) run
> Starting program: C:\[...]
> Breakpoint hit #1.
> Breakpoint hit #2.
> No unwaited-for children left.
>
> It's that last line that causes the problem. The test expects an "exit
> notification", which is kind of complicated in this test suite, but I
> think for native testing boils down to a message like "[Inferior
> ... exited ...]".
>
> I see this "unwaited-for" text in infrun.c. But I wonder if this is
> really intended.

Hmm, I'm not sure how you're seeing that. That is the output of a TARGET_WAITKIND_NO_RESUMED
event. But it can also be a TARGET_WAITKIND_THREAD_EXITED, which GDB treats as
TARGET_WAITKIND_NO_RESUMED in some cases, but only if the target backend is not in non-stop mode.

In any case, TARGET_WAITKIND_NO_RESUMED means that infrun now believes that the target
has no resumed threads left running, so if it went back to waiting for events, it
would be stuck there forever, as no thread would ever report an event -- none is resumed.

"No unwaited-for children left" is the text I came up with back when I added
TARGET_WAITKIND_NO_RESUMED, and I based it on "man waitpid", which says:

ERRORS
ECHILD (for wait()) The calling process does not have any unwaited-for children.

I kind of regret it, though. Something like "No resumed threads left." would be
probably clearer and less implementer-speak.

Is the test using scheduler locking (and was previously ignoring the error
that "set scheduler-locking on" currently issues on Windows) ?

I ask because that is expected output if you continue with scheduler locking enabled,
and the thread exits. E.g., the new gdb.threads/leader-exit-schedlock.exp testcase added
by the series, has:

Thread 1 "leader-exit-schedlock" hit Breakpoint 2, main () at /home/alves/rocm/gdb/src/gdb/testsuite/gdb.threads/leader-exit-schedlock.c:55
55 return 0; /* break-here */
(gdb) PASS: gdb.threads/leader-exit-schedlock.exp: target-non-stop=off: exit-threads-first=0: schedlock=on: continue to breakpoint: break-here
set scheduler-locking on
(gdb) PASS: gdb.threads/leader-exit-schedlock.exp: target-non-stop=off: exit-threads-first=0: schedlock=on: set scheduler-locking on
c
Continuing.
[Thread 11496.0x150 exited]
No unwaited-for children left.

But I don't suppose your test was really doing that.

Maybe some logs like:

set debug infrun
set debugevents on
set debugexceptions on
set debugexec on

would help see what's going on.

I wrote a new testcase based on your description, see attached. It passes cleanly here.

Can you help pointing me to what would need to be changed in the test to make it closer to the AdaCore test?

Pedro Alves

[-- Attachment #2: 0001-New-gdb.threads-continue-break-command.exp-testcase.patch --]
[-- Type: text/x-patch, Size: 5301 bytes --]

From 326bf95fb5b5b92145d6b2aa30fc30cb7fcd2171 Mon Sep 17 00:00:00 2001
From: Pedro Alves <pedro@palves.net>
Date: Wed, 11 Jun 2025 23:35:57 +0100
Subject: [PATCH] New gdb.threads/continue-break-command.exp testcase

Change-Id: Ie57493bb5032f28619db418d9d8068aae2d40b09
---
.../gdb.threads/continue-break-command.c | 94 +++++++++++++++++++
.../gdb.threads/continue-break-command.exp | 76 +++++++++++++++
2 files changed, 170 insertions(+)
create mode 100644 gdb/testsuite/gdb.threads/continue-break-command.c
create mode 100644 gdb/testsuite/gdb.threads/continue-break-command.exp

diff --git a/gdb/testsuite/gdb.threads/continue-break-command.c b/gdb/testsuite/gdb.threads/continue-break-command.c
new file mode 100644
index 00000000000..78fabdc5d33
--- /dev/null
+++ b/gdb/testsuite/gdb.threads/continue-break-command.c
@@ -0,0 +1,94 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2025 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>
+
+#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)
+{
+}
+
+static void
+foo ()
+{
+}
+
+static void
+bar ()
+{
+}
+
+int
+main (void)
+{
+ pthread_t thread[NUM_THREADS];
+ int i;
+
+ alarm (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 ();
+
+ /* The testcase sets breakpoints on these two, that when hit, are
+ removed. */
+ foo ();
+ bar ();
+
+ /* Call them again to make sure the breakpoints are really
+ deleted. */
+ foo ();
+ bar ();
+
+ 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-break-command.exp b/gdb/testsuite/gdb.threads/continue-break-command.exp
new file mode 100644
index 00000000000..5f020425419
--- /dev/null
+++ b/gdb/testsuite/gdb.threads/continue-break-command.exp
@@ -0,0 +1,76 @@
+# Copyright 2025 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/>.
+
+# XXX, some meaninful explanation here.
+
+standard_testfile .c
+
+if { [build_executable "failed to prepare" $testfile $srcfile \
+ {debug pthreads}] \
+ == -1 } {
+ return
+}
+
+proc test {} {
+ clean_restart $::binfile
+
+ if ![runto threads_started] {
+ return
+ }
+
+ # Disable "[Thread 14192.0x3618 exited with code 0]" messages.
+ gdb_test_no_output "set print thread-events off"
+
+ gdb_breakpoint "foo" message
+ gdb_test_multiple "commands" "command for foo" {
+ -re "End with" {
+ gdb_test \
+ [multi_line_input \
+ {silent} \
+ {printf "Breakpoint hit #1.\n"} \
+ {clear foo} \
+ {continue} \
+ {end}] \
+ "" \
+ $gdb_test_name
+ }
+ }
+
+ gdb_breakpoint "bar" message
+ gdb_test_multiple "commands" "commands for bar" {
+ -re "End with" {
+ gdb_test \
+ [multi_line_input \
+ {silent} \
+ {printf "Breakpoint hit #2.\n"} \
+ {clear bar} \
+ {continue} \
+ {end}] \
+ "" \
+ $gdb_test_name
+ }
+ }
+
+ gdb_test "info breakpoints" ".*"
+
+ gdb_test_sequence "continue" "" \
+ [list \
+ "Continuing\\." \
+ "^\r\nBreakpoint hit #1\\." \
+ "^\r\nBreakpoint hit #2\\." \
+ "^\r\n$::inferior_exited_re normally"]
+}
+
+test

base-commit: eb6c9310ee4d6cbde509d251fafb54ae45f5a5bf
--
2.49.0