From: Kevin Buettner <kevinb@redhat.com>
To: Pedro Alves <pedro@palves.net>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] testsuite: Introduce gdb_watchdog (avoid unistd.h/alarm)
Date: Sat, 9 Aug 2025 20:28:51 -0700 [thread overview]
Message-ID: <20250809202851.500f1572@f41-zbm-amd> (raw)
In-Reply-To: <20250808225050.1761370-1-pedro@palves.net>
Hi Pedro,
On Fri, 8 Aug 2025 23:50:50 +0100
Pedro Alves <pedro@palves.net> wrote:
> There are a good number of testcases in the testsuite that use alarm()
> as a watchdog that aborts the test if something goes wrong.
>
> alarm()/SIG_ALRM do not exist on (native) Windows, so those tests fail
> to compile there.
>
> For example, testing with x86_64-w64-mingw32-gcc, we see:
>
> Running /c/rocgdb/src/gdb/testsuite/gdb.base/attach.exp ...
> gdb compile failed, C:/rocgdb/src/gdb/testsuite/gdb.base/attach.c: In
> function 'main': C:/rocgdb/src/gdb/testsuite/gdb.base/attach.c:17:3:
> error: implicit declaration of function 'alarm'
> [-Wimplicit-function-declaration] 17 | alarm (60); | ^~~~~
>
> While testing with a clang configured to default to
> x86_64-pc-windows-msvc, which uses the C/C++ runtime headers from
> Visual Studio and has no unistd.h, we get:
>
> Running /c/rocgdb/src/gdb/testsuite/gdb.base/attach.exp ...
> gdb compile failed, C:/rocgdb/src/gdb/testsuite/gdb.base/attach.c:8:10:
> fatal error: 'unistd.h' file not found 8 | #include <unistd.h>
> | ^~~~~~~~~~
>
> Handle this by adding a new testsuite/lib/gdb_watchdog.h header that
> defines a new gdb_watchdog function, which wraps alarm on Unix-like
> systems, and uses a timer on Windows.
>
> This patch adjusts gdb.base/attach.c as example of usage. Testing
> gdb.base/attach.exp with clang/x86_64-pc-windows-msvc required a
> related portability tweak to can_spawn_for_attach, to not rely on
> unistd.h on Windows.
>
> gdb.rocm/mi-attach.cpp is another example adjusted, one which always
> runs with clang configured as x86_64-pc-windows-msvc on Windows (via
> hipcc).
This all sounds reasonble to me.
One possible nit, and it's *way* outside my wheelhouse, so feel free to
ignore it...
[...]
> +static VOID CALLBACK
> +_gdb_watchdog_timer_routine (PVOID lpParam, BOOLEAN TimerOrWaitFired)
> +{
> + fputs (_gdb_watchdog_msg, stderr);
> + fflush (stderr);
On POSIX, fputs and fflush are not async-signal-safe. It's my
understanding that they aren't on WIN32 either, but I don't know
whether this is actually a signal handler. In any case, my AI
assistant (Qwen3 Coder) says that something like this might
work:
DWORD bytes_written;
WriteFile(GetStdHandle(STD_ERROR_HANDLE), _gdb_watchdog_msg,
sizeof(_gdb_watchdog_msg)-1, &bytes_written, NULL);
Regardless, the rest LGTM. And even if fputs and fflush aren't
async-signal-safe in this context, I doubt that it matters much.
So...
Approved-by: Kevin Buettner <kevinb@redhat.com>
next prev parent reply other threads:[~2025-08-10 3:29 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-08 22:50 Pedro Alves
2025-08-10 3:28 ` Kevin Buettner [this message]
2025-08-11 11:48 ` Pedro Alves
2025-08-12 14:41 ` Tom Tromey
2025-08-12 18:57 ` Pedro Alves
2025-08-13 0:51 ` [PATCH v2] " Pedro Alves
2025-08-22 19:08 ` Pedro Alves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250809202851.500f1572@f41-zbm-amd \
--to=kevinb@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=pedro@palves.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox