From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id IfXgGFnAqGi71AkAWB0awg (envelope-from ) for ; Fri, 22 Aug 2025 15:09:13 -0400 Received: by simark.ca (Postfix, from userid 112) id 62CA11E048; Fri, 22 Aug 2025 15:09:13 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=no 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 783981E023 for ; Fri, 22 Aug 2025 15:09:12 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 093973851C2B for ; Fri, 22 Aug 2025 19:09:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 093973851C2B Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) by sourceware.org (Postfix) with ESMTPS id C75463851A93 for ; Fri, 22 Aug 2025 19:08:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C75463851A93 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 C75463851A93 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1755889715; cv=none; b=jvYKQPZwzTM6Fc6JmrQ5ij9u0KgzZXkqVHC7oF9t25+r90mfjzqH6mAz8OnZYsgv0RH9N0QaMuLcO/cVRHRoLtyMrnUiW0NKGVX7P8BnYd1rme4CwkQqbzdKS69Ipef3pUfX0leNS+iNUF6wxxTzlWQBsxOE9EdCOp6leIpmjqg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1755889715; c=relaxed/simple; bh=antVlVZkXajJKpUicpRN7ute1M3y1Uwy+dOf8FBN0QE=; h=Message-ID:Date:MIME-Version:Subject:From:To; b=qWYx+nGR1Vyy45TkOReT5ArLDKyUOq2TCc1NMHqTKCGuHcdsHaOrYMztefX7yoJ0RE9xsvXhFOnuQvmIWQd+VKH72v8QMgWvWyIBHTvHlm7YghsRme+IT+y+iic/Cr6LvHZdHHkfKx/vzkVN8+MArRh/qhFYx0IMF1/5chhcOcQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C75463851A93 Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-3b9e7437908so1655347f8f.3 for ; Fri, 22 Aug 2025 12:08:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755889714; x=1756494514; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=O9cPlz92PWL8glM+ukqDXskHECFxTovXZWR5J5M5gpM=; b=vg5L78pwq3kp/jaQqxqYSzNLPFRoMe9q5DF37GsyBuyCxj/y0jUlNCbHS1q5DICq++ 4YeyDeHVLu+iaqVAh3JNImButJS1dXxLWFXIPslrTps+pDvbTdle95bgdZEIfPTlH0w+ mUzFvjKqOORmfA1Fkv2xZXJMNOLgDAOUH2Mvw0fjoQkj8SlxtCH66zMXaopwuNSUUseS SnZBE8nlGvYg8pzWV+TZ3PQ9RbKXXu49U25wT7+8O92Tm7Rb9x5YvlObftR8CjiwavIs 4WReJ2Ml0vFbxyuzfjE6tv7JRy4Ygs+xeVOvMqyEtah7pAga+nOXNS5BzlgVycqFGXPE hE6Q== X-Gm-Message-State: AOJu0YyEDNGlp8HRsbydIxcxE/mrSodxbmsPcJFyGQBfYJbQtfFgJRxD 7Ek90HaG4ppHxlIpCeYUqXVexxMZTlZF5SzsdOXAeZc/q9PFK5PZukfh X-Gm-Gg: ASbGncuiHmHXrLN2xfnrIg4wUbieR25zZ+IH5SksxE3IcHD+GfdHoPMk3tB/OdRTYVC oRKITonEduR4vTZBTKVe3XRh6GIr1Mlq2qFZRP0w3KfxverDMXLNABT9t4FzY8J5M/ZXHtVr/OT WBoTD5p3l62Q7a6nAZR0dqEXE6g+1SpkaG7PA7e2Ez4kq8cANhMGWXqeIivK38h85WUgU5Mu6fJ iYTWasui8uhENplyrtjhHyvCORZwWSVlicJQqxwpBF0RAJlVDyySKKjeIRuwO72gppS8aqs59F3 a4lZ/JZFzgUEyJJeiuqhGP2CaSgo48pQikTfDJ8vD7nV0Miqtnpl9J5fnEsDqIkXRNBSDTMI6yB ZkAxebF/mqG5od3aABj+sFfGtYyZx3ZlqZZFXXRQRwPer8eAV2reSXzVpiSdoEAqVdEkNyrdGcQ == X-Google-Smtp-Source: AGHT+IEZ16VtKx4F6KhejcDGwSDfknc8DHSgSFyttrhwdZnyxCqHRpvGG+JfcDMri55cIxvhMgoQUQ== X-Received: by 2002:a05:6000:4287:b0:3b8:ffd1:80d2 with SMTP id ffacd0b85a97d-3c5dac1aae7mr3854580f8f.24.1755889713331; Fri, 22 Aug 2025 12:08:33 -0700 (PDT) Received: from ?IPV6:2001:8a0:faf3:7600:ecf:b103:3f7d:622c? ([2001:8a0:faf3:7600:ecf:b103:3f7d:622c]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3c7116e1397sm511164f8f.49.2025.08.22.12.08.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 22 Aug 2025 12:08:32 -0700 (PDT) Message-ID: <605400fd-fedd-46f9-83ea-20262cef8377@palves.net> Date: Fri, 22 Aug 2025 20:08:29 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] testsuite: Introduce gdb_watchdog (avoid unistd.h/alarm) From: Pedro Alves To: Tom Tromey Cc: gdb-patches@sourceware.org References: <20250808225050.1761370-1-pedro@palves.net> <87tt2cob4h.fsf@tromey.com> <2e78248c-2838-4655-9420-600c4f3e1868@palves.net> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 On 2025-08-13 01:51, Pedro Alves wrote: > On 2025-08-12 19:57, Pedro Alves wrote: >> On 2025-08-12 15:41, Tom Tromey wrote: >>>>>>>> "Pedro" == Pedro Alves writes: >>> >>> Pedro> Handle this by adding a new testsuite/lib/gdb_watchdog.h header that >>> Pedro> defines a new gdb_watchdog function, which wraps alarm on Unix-like >>> Pedro> systems, and uses a timer on Windows. >>> >>> It seems like this would need some special work to handle the remote >>> host testing case. >>> >>> Pedro> +#include "../lib/gdb_watchdog.h" >>> >>> ... at least, I assume this isn't automatically copied to the remote. >>> >> >> Hmm. Yeah, I forget it's also possible to compile on the host side. >> >> I see that for example lib/attributes.h is handled with lappend_include_file >> and include_file. I'll take a better look. > > > So locally I have patches touching a lot more testcases, converting them to use > gdb_watchdog. I adjusted them all locally to use lappend_include_file, but > I didn't like the result all that much. It's annoying to have to list the > includes twice, once in the source files, and once in the .exp file. > > Even worst is that in my local series, I have a patch that makes > gdb_watchdog.h include another header in testsuite/lib/, and the lappend_include_file > approach would mean that every .exp file that includes gdb_watchdog.h would need > to be updated to also lappend_include_file the header that gdb_watchdog.h includes. > > So I thought about making this automatic, and came up with this: > > [PATCH] Automatically handle includes in testsuite/lib/ > https://inbox.sourceware.org/gdb-patches/20250813004100.2525141-1-pedro@palves.net/T/#u > > Let me know what you think. > > With that in place, the updated gdb_watchdog patch is below. The only difference > is that we now include gdb_watchdog.h like so: > > #include "gdb_watchdog.h" > > instead of: > > #include "../lib/gdb_watchdog.h" > FYI, I've now pushed this. But after pushing I noticed that this v2 patch email doesn't appear to have reached the mailing list? I can't find it in the archives, and have gotten a copy via the list. Odd. Here's what I pushed. The v2 version that I sent before had an incomplete change in the Windows version of gdb_watchdog. I had noticed that it's not necessary to create a timer queue, there's a default one, and switched to doing that in v2 (passing NULL as timer queue to CreateTimerQueueTimer), but had forgotten to delete the DeleteTimerQueue line. In this version, I'm simply aborting immediately if creating the timer fails. I don't expect that that will ever be reached, and the idea of aborting is that if it ever is reached, it's better to see the problem immediately so we can better understand how it can happen, instead of silently failing to have a watchdog in place. I have some follow up patches making use of gdb_watchdog in other tests. Pedro Alves >From e771abf8ff88a5d98b8960a7ea49708b9ec42521 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Fri, 8 Aug 2025 23:50:04 +0100 Subject: [PATCH] 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 | ^~~~~~~~~~ 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 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 | 75 ++++++++++++++++++++++++++++ 4 files changed, 93 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..5133dd07e55 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 "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..441d460146a 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 "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 0361f10b9a6..d989314c28d 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -6849,7 +6849,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..15d63e76198 --- /dev/null +++ b/gdb/testsuite/lib/gdb_watchdog.h @@ -0,0 +1,75 @@ +/* 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 declaration 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); + abort (); +} + +static void +gdb_watchdog (unsigned int seconds) +{ + HANDLE timer; + + if (!CreateTimerQueueTimer (&timer, NULL, + _gdb_watchdog_timer_routine, NULL, + seconds * 1000, 0, 0)) + abort (); +} + +#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: 3214cb0ce58245516d35cd93887f0d3bc14b5ebf -- 2.50.1