From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id kvVAFt7hm2j2+QEAWB0awg (envelope-from ) for ; Tue, 12 Aug 2025 20:52:46 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=palves.net header.i=@palves.net header.a=rsa-sha256 header.s=dreamhost header.b=DmTtSL/I; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 4C8411E0B3; Tue, 12 Aug 2025 20:52:46 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED 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 E18E71E093 for ; Tue, 12 Aug 2025 20:52:44 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 58DC43858C62 for ; Wed, 13 Aug 2025 00:52:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 58DC43858C62 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=palves.net header.i=@palves.net header.a=rsa-sha256 header.s=dreamhost header.b=DmTtSL/I Received: from hamster.birch.relay.mailchannels.net (hamster.birch.relay.mailchannels.net [23.83.209.80]) by sourceware.org (Postfix) with ESMTPS id EBA163858D37 for ; Wed, 13 Aug 2025 00:51:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EBA163858D37 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=palves.net ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EBA163858D37 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=23.83.209.80 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1755046316; cv=pass; b=c3yyNYkamHWl+wIfylufBkSqkzomNdzSDrUagcr+YggmMt8TasG54VHwNjST4AXaYEUG6sSf4WQi45YdDJQOzMr/1MFJR2odDX60HA5hTg0S48sZs59SFyxLbjxfFRB0GmTjfAnueYMjUYEruGvWHOftGTkEGwIC5zzfpsJHrKc= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1755046316; c=relaxed/simple; bh=qRim5cql67iEBvcAFdTK+9yUoM2sNIhdzjJl4GG6Dfk=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:From:To; b=F/yJTcN99jjkyFxPv718FCNVEbWbKPdKUrW2N9eN4aKYe0+5KYSnb69OzBVhNBnKtMNVhkI+vO/7k6h/tcPrGbol021LSZAwTvVHLWX7ys29cgXYxdl+M4g5KVGOZiPfGjt7foMnaEAYxXS8o7+v4hr8UmeP+t1Ei3UGxTqdJHw= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EBA163858D37 X-Sender-Id: dreamhost|x-authsender|pedro@palves.net Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id AFE2D164E08; Wed, 13 Aug 2025 00:51:54 +0000 (UTC) Received: from pdx1-sub0-mail-a235.dreamhost.com (trex-blue-3.trex.outbound.svc.cluster.local [100.96.37.13]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 00CC3165B9D; Wed, 13 Aug 2025 00:51:53 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1755046314; a=rsa-sha256; cv=none; b=lMvGfx3V9/bUJ0ESD1i4DevA3wa0kcIbfpcxiq7T3tD2WmstLtS6z73v2/SgxmS+7ZPpBy 1fo5Quiy6pgd3dr3huJJK5nm1gTdffLxOD8ctJzU2R0IMCLmAd1t9Vim53YnbCdex8803f /CGVHjcnpnlxeo8dK0GJdePy4GBQkwT85HeJclZTgJUa5+nU0V6hshVaOXJLM+tNEtxob3 FPYkvSBKfVLcCPKksKRr+MZXnGijRpnRVq1JwK5ypRuKAdITvs8mO5iHqg6tZbh8zRM+0S pc8fisaZpE46AYn6dtZmyhSAuW7bIKEVPucLlEawlTSq6kMoNET4BuMKTXNfjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1755046314; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=NsdaOPe4wYYLPEF/2jBv47Cf+uQEkopmxmrF8cunhJ4=; b=MwmmK/JHGOf1QRcusQSArLCLGmmTmvxIILzRJunZDmaNma2v5D+JjJFxtok5eADndMC02f oPmzIlz7ECzCMpOnzEyB8SL/7PXSkz0RO6fqqCgCERwNxg4Uy8sg/+/4FtMZMHx0416wcD aB6VkZbExG8E2TaectJayW5hQMok/k3n+v0HPfIdbdP1PvmheEB4Yr93IGKclBF16zvUqH vUHWHg0FWYSSZxoC1ZzAyPtsobg/UsGcMNUFNyPmP/8iCHwaRFTiJdTNoh60czPKiMKVep y5FINXH+cB+DLR0t2jiaF2Cb/4aK9RhuyFaP9QfuSg0brd2Ta7qRzbKx2MrxEw== ARC-Authentication-Results: i=1; rspamd-865b9ccc6c-7vvtf; auth=pass smtp.auth=dreamhost smtp.mailfrom=pedro@palves.net X-Sender-Id: dreamhost|x-authsender|pedro@palves.net X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|pedro@palves.net X-MailChannels-Auth-Id: dreamhost X-Average-Hook: 2b72510561f0f54f_1755046314574_3164569000 X-MC-Loop-Signature: 1755046314573:3198772291 X-MC-Ingress-Time: 1755046314573 Received: from pdx1-sub0-mail-a235.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.96.37.13 (trex/7.1.3); Wed, 13 Aug 2025 00:51:54 +0000 Received: from [192.168.0.201] (bl21-214-172.dsl.telepac.pt [2.82.214.172]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: pedro@palves.net) by pdx1-sub0-mail-a235.dreamhost.com (Postfix) with ESMTPSA id 4c1qZd2WfZzRJ; Tue, 12 Aug 2025 17:51:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=palves.net; s=dreamhost; t=1755046313; bh=NsdaOPe4wYYLPEF/2jBv47Cf+uQEkopmxmrF8cunhJ4=; h=Date:Subject:From:To:Cc:Content-Type:Content-Transfer-Encoding; b=DmTtSL/IkuBQ8SUcTzcri2+3tA+SVj3NhinO2aOoCCnRkRbGIfZ4Rhhq+qtaW8UU+ XBDeENWEg7q1N6Df2UHKpGiZtEAw/RRnhINMjq/cwp9gyhU3z7PJBjGH+omyvaGebo Xt7o7StPVrMwL9WGRUNxdQTT1SReH8AKGzLSsE4Ys7OvcPLOKp0UMp2LiE1IcDiXxc 3uHftUzRmPBFwYRnbcy9KBhW0LpjaUqI6o8ICIDj0I30ib1wFK9/JkX6sFd5t2cdKL UiduGEk8u7cSLbS9OfUpmb0Lxb7aTWKzVpyA4a209FKqV2LsXGa0aI7G35PZj/Bwhu Lss4lIcSpYTQg== Message-ID: Date: Wed, 13 Aug 2025 01:51:43 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [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: <2e78248c-2838-4655-9420-600c4f3e1868@palves.net> 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-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" >From 338f5c87ccea20cfe65b122d227ee37499b04c6f Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Fri, 8 Aug 2025 23:50:04 +0100 Subject: [PATCH v2] 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). 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 | 78 ++++++++++++++++++++++++++++ 4 files changed, 96 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..459b958836e --- /dev/null +++ b/gdb/testsuite/lib/gdb_watchdog.h @@ -0,0 +1,78 @@ +/* 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); + abort (); +} + +static void +gdb_watchdog (unsigned int seconds) +{ + HANDLE timer; + + if (!CreateTimerQueueTimer (&timer, NULL, + _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 prerequisite-patch-id: 9b579e19acdb2121d8232cafc1bb63ef881684eb -- 2.50.1