]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
testsuite: Introduce gdb_watchdog (avoid unistd.h/alarm)
authorPedro Alves <pedro@palves.net>
Fri, 8 Aug 2025 22:50:04 +0000 (23:50 +0100)
committerPedro Alves <pedro@palves.net>
Fri, 22 Aug 2025 18:45:49 +0000 (19:45 +0100)
commite771abf8ff88a5d98b8960a7ea49708b9ec42521
tree0593c57081ca075f6835da24fb8a54b414f1d985
parent3214cb0ce58245516d35cd93887f0d3bc14b5ebf
testsuite: Introduce gdb_watchdog (avoid unistd.h/alarm)

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).

Approved-by: Kevin Buettner <kevinb@redhat.com>
Change-Id: I3b07bcb60de039d34888ef3494a5000de4471951
gdb/testsuite/gdb.base/attach.c
gdb/testsuite/gdb.rocm/mi-attach.cpp
gdb/testsuite/lib/gdb.exp
gdb/testsuite/lib/gdb_watchdog.h [new file with mode: 0644]