From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id kTcdL3V/lmjpKgcAWB0awg (envelope-from ) for ; Fri, 08 Aug 2025 18:51:33 -0400 Received: by simark.ca (Postfix, from userid 112) id A83081E100; Fri, 8 Aug 2025 18:51:33 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-9.0 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED, RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE autolearn=ham autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id D194A1E091 for ; Fri, 8 Aug 2025 18:51:32 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6048E3858D29 for ; Fri, 8 Aug 2025 22:51:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6048E3858D29 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) by sourceware.org (Postfix) with ESMTPS id 5CB753858D29 for ; Fri, 8 Aug 2025 22:51:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5CB753858D29 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5CB753858D29 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1754693460; cv=none; b=EGW6V0IGhr6Ma7W3ngeIB0lL1Oy/r29RIv55BHYfk7q3lNX2u430Hz0zoruiFHtHd+Othd0y8rwFog8bA965PS1DKPEIyX+ADMvD4n4kqrvRvfMYpF7j75+vfypwrqAl/zb4sbZ8cnRVb8dmh8QaJhws1gy4N08Z+AwPo5uVxvc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1754693460; c=relaxed/simple; bh=YMZzA7Mvz+bIlPCIK32YuqYBDj+DixbxH5lI0AD3mGo=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=rVD8lnWniuTrEWccosKajWMvsjHg7VwJu8MsZwI5ND0TBRJ5LqKgPyFTXBYlSr63FjieNFlrgydpilZnkvwJnyOlHJhs+BLEe2WPxlcP3TybBo2+YmwQHP9R3ChKtrtKH0yi1AP/dWq9wRwqfJHJvePY9Nhx5QldbFTqKpjljgo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5CB753858D29 Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-459e20ec1d9so25299805e9.3 for ; Fri, 08 Aug 2025 15:51:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754693459; x=1755298259; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/V5Gp3ajzr6lCVk6/0TneqfDFEUPCA2fai1JtoBfMZA=; b=OpNRTdno0ldWVdEce7WBvVxtH8Nin7ry38zRIusa7ip44wx0q0wBTJBZMG1aszYetJ 1JzuhcffLSikWzxREHsvjzlb7RXgeReSfgavS0mo0kQLMxwDSVfkYLSdSn4wfkT3j7/a DMoXrev3qSxh4o+INwuxVG+aW+jfuM887yNKl6ya2q/KPgLPOG02X2gwtZOyXG9jmyO4 NED7YL8tQjR1TF6c3Ap6A/xXjmdMlhkw4UEYqML+QH2oNp2mUQ9uLBbwCJICA8w7bw1S CZivTv7k/cx2dkqUn3V0FPHCbb7TG/i+vbvDUX8mJmEpoxHfKOYcsGqlVGKO+6u5m+mu nWYg== X-Gm-Message-State: AOJu0YwrZiY0EcgzQtXmcSeIAY3cX7TMmB7tHsE0SVxBckdRJfg6f710 lgW2ZGWO/aJIFEGFJwip2wWeVd20pKvtB/4GsHp5qL2BEI7Pqj/gIcZSxRUbkapJ X-Gm-Gg: ASbGncvq6g/b5jdDzbCC+gtHG4r6GZWuYMCj9PI8TCpDKIjV2Y0zHNZLEezfBfQe29h WRTFDTc6fcGb0WM5OfE1+5rL2qx2R2TKrOEX7DvhDr4D2RCgRc2RKsDGdWW6sUz1mUkW3C5VGU3 Sbkeczr7zBhqAXu8ODpVtIHdJ5OsMxg1PNXAJwgizakmHfYdGI8bUaj5kidsqTPCKdkbMp4IZog RL5oCTCVrTAliOHOQl2CMtkivsXTK0ClM79xWfR5pBgdzCuVFTTju5DyTAg29bIcLF60BNGGKHS vFgdeF1a019r02kRiyD3U6GSqN7aYE67jniK/69CcpwGoTxeiu/UqPYvaqMPw63NVedI/gmuPaq u4wWQ/wVNk/7Y2KZsHirH5SEmeur3LUqOydDMWMXepHmGsovGx+9/Kkg= X-Google-Smtp-Source: AGHT+IEvPOwd5MiXbgPZ4HtMl67ZcIcGsLiuMrC1DC3kTTl2iu8YbY2ogxwhlxdLwNSGFx5STFgwEA== X-Received: by 2002:a05:600c:46c7:b0:458:bdd1:b7ef with SMTP id 5b1f17b1804b1-459f4f9b21amr39963445e9.19.1754693458785; Fri, 08 Aug 2025 15:50:58 -0700 (PDT) Received: from localhost (bl21-214-172.dsl.telepac.pt. [2.82.214.172]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-459e075805csm203411965e9.4.2025.08.08.15.50.58 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 08 Aug 2025 15:50:58 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH] testsuite: Introduce gdb_watchdog (avoid unistd.h/alarm) Date: Fri, 8 Aug 2025 23:50:50 +0100 Message-ID: <20250808225050.1761370-1-pedro@palves.net> X-Mailer: git-send-email 2.50.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org 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 | ^~~~~~~~~~ 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). Change-Id: I3b07bcb60de039d34888ef3494a5000de4471951 --- gdb/testsuite/gdb.base/attach.c | 4 +- gdb/testsuite/gdb.rocm/mi-attach.cpp | 4 +- gdb/testsuite/lib/gdb.exp | 15 ++++- gdb/testsuite/lib/gdb_watchdog.h | 83 ++++++++++++++++++++++++++++ 4 files changed, 101 insertions(+), 5 deletions(-) create mode 100644 gdb/testsuite/lib/gdb_watchdog.h diff --git a/gdb/testsuite/gdb.base/attach.c b/gdb/testsuite/gdb.base/attach.c index b3c54984012..41b304ef594 100644 --- a/gdb/testsuite/gdb.base/attach.c +++ b/gdb/testsuite/gdb.base/attach.c @@ -5,7 +5,7 @@ exit unless/until gdb sets the variable to non-zero.) */ #include -#include +#include "../lib/gdb_watchdog.h" int bidule = 0; volatile int should_exit = 0; @@ -14,7 +14,7 @@ int main () { int local_i = 0; - alarm (60); + gdb_watchdog (60); while (! should_exit) { diff --git a/gdb/testsuite/gdb.rocm/mi-attach.cpp b/gdb/testsuite/gdb.rocm/mi-attach.cpp index da7659dc566..5752cdd10bb 100644 --- a/gdb/testsuite/gdb.rocm/mi-attach.cpp +++ b/gdb/testsuite/gdb.rocm/mi-attach.cpp @@ -15,8 +15,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include #include +#include "../lib/gdb_watchdog.h" __global__ void kern () @@ -30,7 +30,7 @@ main () { /* This program will run outside of GDB, make sure that if anything goes wrong it eventually gets killed. */ - alarm (30); + gdb_watchdog (30); kern<<<1, 1>>> (); return hipDeviceSynchronize () != hipSuccess; diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 98691dfce25..857d1d634c2 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -6846,7 +6846,20 @@ gdb_caching_proc can_spawn_for_attach {} { set me "can_spawn_for_attach" set src { - #include + #ifdef _WIN32 + # include + #else + # include + #endif + + #ifdef _WIN32 + unsigned + sleep (unsigned seconds) + { + Sleep (seconds * 1000); + return 0; + } + #endif int main (void) diff --git a/gdb/testsuite/lib/gdb_watchdog.h b/gdb/testsuite/lib/gdb_watchdog.h new file mode 100644 index 00000000000..e16f6b06f38 --- /dev/null +++ b/gdb/testsuite/lib/gdb_watchdog.h @@ -0,0 +1,83 @@ +/* This file 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 . */ + +/* Set a watchdog that aborts the testcase after a timeout. */ + +#ifndef GDB_WATCHDOG_H +#define GDB_WATCHDOG_H + +/* Forward define to make sure the definitions have the right + prototype, at least in C. */ +static void gdb_watchdog (unsigned int seconds); + +static const char _gdb_watchdog_msg[] = "gdb_watchdog: timeout expired - aborting test\n"; + +#ifdef _WIN32 +#include +#include +#include + +static VOID CALLBACK +_gdb_watchdog_timer_routine (PVOID lpParam, BOOLEAN TimerOrWaitFired) +{ + fputs (_gdb_watchdog_msg, stderr); + fflush (stderr); + abort (); +} + +static void +gdb_watchdog (unsigned int seconds) +{ + HANDLE timer; + HANDLE timer_queue; + + timer_queue = CreateTimerQueue (); + if (timer_queue == NULL) + return; + + if (!CreateTimerQueueTimer (&timer, timer_queue, + _gdb_watchdog_timer_routine, NULL, + seconds * 1000, 0, 0)) + { + /* Failed to create timer. */ + DeleteTimerQueue (timer_queue); + } +} + +#else /* POSIX systems */ + +#include +#include +#include + +static void +_gdb_sigalrm_handler (int signo) +{ + write (2, _gdb_watchdog_msg, sizeof (_gdb_watchdog_msg) - 1); + abort (); +} + +static void +gdb_watchdog (unsigned int seconds) +{ + signal (SIGALRM, _gdb_sigalrm_handler); + alarm (seconds); +} + +#endif + +#endif /* GDB_WATCHDOG_H */ base-commit: f5b1b0288a97965bd71668b046fa35a85c4cea04 -- 2.50.1