From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id WTWVHiASYmqmWykAWB0awg (envelope-from ) for ; Thu, 23 Jul 2026 09:07:44 -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=LWP0usNF; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 7909D1E099; Thu, 23 Jul 2026 09:07:44 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.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 autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (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 D66911E099 for ; Thu, 23 Jul 2026 09:07:42 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7E59D4BA79B3 for ; Thu, 23 Jul 2026 13:07:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7E59D4BA79B3 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=LWP0usNF Received: from liger.cherry.relay.mailchannels.net (liger.cherry.relay.mailchannels.net [23.83.223.103]) by sourceware.org (Postfix) with ESMTPS id CA65A4BA7999 for ; Thu, 23 Jul 2026 13:06:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CA65A4BA7999 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 CA65A4BA7999 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=23.83.223.103 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1784812020; cv=none; b=UuXQt/ymKFF2bGWWq2HSqjBb6MUy5KjvB1wee5aXdZEhyXkJU6jX0RNU6ezCngA2Hj/0PJLe4mawAy+Byasb1UtK4TYDTOi9gigKV5GiDXpU79zRQiFmuerfuKEUOUhL+Rar6ED25OwJthGQEgYyGh6sDNVtv7rNGlO4ntVr0Uw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1784812020; c=relaxed/simple; bh=JDSaKjaEUNhKcL8VmsOjHXGzsYPnEfQQrixkw01VaMM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=cfzwz6MUIcxXD1QqXTcYy1R31AVxJHtQBxSCWUT8QutsOaasrlbO9MY8FpdQeayk83HYUNXfNC7CkPxdFySG+punNzNCt8BqDZcFTw70ERQf7namX7olJogCfUsLIumPkTALJeyLpikVCBH/DosYPHS5wxJVs/XPOxXB+ECA05E= ARC-Authentication-Results: i=1; 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=LWP0usNF DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CA65A4BA7999 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 E97C84144D for ; Thu, 23 Jul 2026 13:06:58 +0000 (UTC) Received: from pdx1-sub0-mail-a249.dreamhost.com (100-104-245-50.trex-nlb.outbound.svc.cluster.local [100.104.245.50]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 9DD0F406F2 for ; Thu, 23 Jul 2026 13:06:58 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|pedro@palves.net X-MC-Relay: Good X-MailChannels-SenderId: dreamhost|x-authsender|pedro@palves.net X-MailChannels-Auth-Id: dreamhost X-Juvenile-Thoughtful: 1dac84ed4038373c_1784812018905_1904766248 X-MC-Loop-Signature: 1784812018905:2447905594 X-MC-Ingress-Time: 1784812018904 Received: from pdx1-sub0-mail-a249.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.104.245.50 (trex/8.0.2); Thu, 23 Jul 2026 13:06:58 +0000 Received: from localhost (bl20-181-64.dsl.telepac.pt [2.81.181.64]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: pedro@palves.net) by pdx1-sub0-mail-a249.dreamhost.com (Postfix) with ESMTPSA id 4h5Wc20dx0z105D for ; Thu, 23 Jul 2026 06:06:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=palves.net; s=dreamhost; t=1784812018; bh=Fj69PmE/yv1ApaPOdsdsC5IXufI+BII45O0wATdK62M=; h=From:To:Subject:Date:Content-Transfer-Encoding; b=LWP0usNF6AAhTMSwmVSQCb7sPj6u8I2imSWiZbLgCWFEN7IPWTJYhaTNQyL9k8HsV VXUdI4kCufJknyWdaFFuGDWmCs6hkRSbSIZmNbru9Ayp0xaLggGUIbaWNZjDrspq50 OzwVpbeOYjWkePAeMiMSnVAl3mSEeTCWVhsPGt9Sv4ohGEe+zF2rUDdSiuVtzr6ITc 3NKR7yZu+IAqxdzlyn8b8WgzMtGn3MRNWVpmd/8w9spHKbluYTo0PoUXsLV0w7Dvuj OkU8ClVpD0iDEPd2wm+Pu9NGqIBGGE3Jk4mOXPvINGlv3ZJ6y3NkCxb1to6oe7YNOF tQ+DhHNWyiyeA== From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 26/27] gdb/testsuite: Factor out dlopen/LoadLibrary shim into lib/gdb-dlfcn.h Date: Thu, 23 Jul 2026 14:01:17 +0100 Message-ID: <20260723130118.206735-27-pedro@palves.net> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260723130118.206735-1-pedro@palves.net> References: <20260723130118.206735-1-pedro@palves.net> 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 Several testcases that dlopen a shared library at runtime have a set of similar preprocessor shims that map the POSIX dlopen/dlsym/dlclose/dlerror interfaces onto the equivalent Win32 functions on Windows. This commit moves the shims into a new testsuite/lib/gdb-dlfcn.h, and includes it from each testcase. gdb_compile already adds testsuite/lib/ to the include path, so no .exp changes are needed. The header provides a small static gdb_dlerror() for the Windows side, formatting GetLastError() the way watchpoint-solib.c and unload.c used to do inline, so those two lose their in-body __WIN32__ blocks too and just call dlerror() unconditionally. TEXT() is dropped: it only matters for the WinCE wide-char build (_WIN32_WCE), and we dropped WinCE support long ago. This will make the following patch trivial. Change-Id: I7618808a3c766ae5570358f6e0bfb9ceabf4f4c0 --- gdb/testsuite/gdb.base/bp-disabled-by-cond.c | 13 +---- gdb/testsuite/gdb.base/catch-load.c | 8 +-- .../gdb.base/corefile-buildid-shlib.c | 10 +--- gdb/testsuite/gdb.base/jit-unload.c | 9 +--- gdb/testsuite/gdb.base/shlib-unload.c | 13 +---- gdb/testsuite/gdb.base/solib-disc.c | 10 +--- gdb/testsuite/gdb.base/unload.c | 21 +------- gdb/testsuite/gdb.base/watchpoint-solib.c | 17 +------ gdb/testsuite/gdb.mi/mi-catch-load.c | 8 +-- gdb/testsuite/gdb.mi/mi-dprintf-modified.c | 13 +---- gdb/testsuite/gdb.perf/solib.c | 9 +--- gdb/testsuite/gdb.python/py-event-load.c | 8 +-- gdb/testsuite/lib/gdb-dlfcn.h | 51 +++++++++++++++++++ 13 files changed, 63 insertions(+), 127 deletions(-) create mode 100644 gdb/testsuite/lib/gdb-dlfcn.h diff --git a/gdb/testsuite/gdb.base/bp-disabled-by-cond.c b/gdb/testsuite/gdb.base/bp-disabled-by-cond.c index 0d147b34410..f09f90b43a6 100644 --- a/gdb/testsuite/gdb.base/bp-disabled-by-cond.c +++ b/gdb/testsuite/gdb.base/bp-disabled-by-cond.c @@ -18,18 +18,7 @@ #include #include -#ifdef __WIN32__ -#include -#define dlopen(name, mode) LoadLibrary (TEXT (name)) -#ifdef _WIN32_WCE -# define dlsym(handle, func) GetProcAddress (handle, TEXT (func)) -#else -# define dlsym(handle, func) GetProcAddress (handle, func) -#endif -#define dlclose(handle) FreeLibrary (handle) -#else -#include -#endif +#include "gdb-dlfcn.h" void breakpt () diff --git a/gdb/testsuite/gdb.base/catch-load.c b/gdb/testsuite/gdb.base/catch-load.c index bb53fddc557..e9f8f63362d 100644 --- a/gdb/testsuite/gdb.base/catch-load.c +++ b/gdb/testsuite/gdb.base/catch-load.c @@ -17,13 +17,7 @@ #include -#ifdef __WIN32__ -#include -#define dlopen(name, mode) LoadLibrary (TEXT (name)) -#define dlclose(handle) FreeLibrary (handle) -#else -#include -#endif +#include "gdb-dlfcn.h" /* This is updated by the .exp file. */ char *libname = "catch-load-so.so"; diff --git a/gdb/testsuite/gdb.base/corefile-buildid-shlib.c b/gdb/testsuite/gdb.base/corefile-buildid-shlib.c index 480494d98f7..dca51bc6749 100644 --- a/gdb/testsuite/gdb.base/corefile-buildid-shlib.c +++ b/gdb/testsuite/gdb.base/corefile-buildid-shlib.c @@ -19,15 +19,7 @@ #include #include -#ifdef __WIN32__ -#include -#define dlopen(name, mode) LoadLibrary (name) -#define dlsym(handle, func) GetProcAddress (handle, func) -#define dlclose(handle) FreeLibrary (handle) -#define dlerror() "an error occurred" -#else -#include -#endif +#include "gdb-dlfcn.h" const char *the_shlib = SHLIB_NAME; diff --git a/gdb/testsuite/gdb.base/jit-unload.c b/gdb/testsuite/gdb.base/jit-unload.c index 058fb54fd71..e10ba221314 100644 --- a/gdb/testsuite/gdb.base/jit-unload.c +++ b/gdb/testsuite/gdb.base/jit-unload.c @@ -20,14 +20,7 @@ #include #include -#ifdef __WIN32__ -#include -#define dlopen(name, mode) LoadLibrary (TEXT (name)) -#define dlclose(handle) FreeLibrary (handle) -#define dlerror() "an error occurred" -#else -#include -#endif +#include "gdb-dlfcn.h" int diff --git a/gdb/testsuite/gdb.base/shlib-unload.c b/gdb/testsuite/gdb.base/shlib-unload.c index e2c2051a19f..6332945b690 100644 --- a/gdb/testsuite/gdb.base/shlib-unload.c +++ b/gdb/testsuite/gdb.base/shlib-unload.c @@ -17,18 +17,7 @@ #include -#ifdef __WIN32__ -#include -#define dlopen(name, mode) LoadLibrary (TEXT (name)) -#ifdef _WIN32_WCE -# define dlsym(handle, func) GetProcAddress (handle, TEXT (func)) -#else -# define dlsym(handle, func) GetProcAddress (handle, func) -#endif -#define dlclose(handle) FreeLibrary (handle) -#else -#include -#endif +#include "gdb-dlfcn.h" #include diff --git a/gdb/testsuite/gdb.base/solib-disc.c b/gdb/testsuite/gdb.base/solib-disc.c index 9230ab13c67..365e352f579 100644 --- a/gdb/testsuite/gdb.base/solib-disc.c +++ b/gdb/testsuite/gdb.base/solib-disc.c @@ -18,15 +18,7 @@ #include #include -#ifdef __WIN32__ -#include -#define dlopen(name, mode) LoadLibrary (name) -#define dlsym(handle, func) GetProcAddress (handle, func) -#define dlclose(handle) FreeLibrary (handle) -#define dlerror() "an error occurred" -#else -#include -#endif +#include "gdb-dlfcn.h" int main() { diff --git a/gdb/testsuite/gdb.base/unload.c b/gdb/testsuite/gdb.base/unload.c index 7c365aef9ef..98451a43a27 100644 --- a/gdb/testsuite/gdb.base/unload.c +++ b/gdb/testsuite/gdb.base/unload.c @@ -18,18 +18,7 @@ #include #include -#ifdef __WIN32__ -#include -#define dlopen(name, mode) LoadLibrary (TEXT (name)) -#ifdef _WIN32_WCE -# define dlsym(handle, func) GetProcAddress (handle, TEXT (func)) -#else -# define dlsym(handle, func) GetProcAddress (handle, func) -#endif -#define dlclose(handle) FreeLibrary (handle) -#else -#include -#endif +#include "gdb-dlfcn.h" int k = 0; @@ -52,11 +41,7 @@ int main() if (!unloadshr) { -#ifdef __WIN32__ - fprintf (stderr, "error %d occurred\n", GetLastError ()); -#else fprintf (stderr, "%s\n", dlerror ()); -#endif exit (1); } @@ -79,11 +64,7 @@ int main() if (!unloadshr) { -#ifdef __WIN32__ - fprintf (stderr, "error %d occurred\n", GetLastError ()); -#else fprintf (stderr, "%s\n", dlerror ()); -#endif exit (1); } diff --git a/gdb/testsuite/gdb.base/watchpoint-solib.c b/gdb/testsuite/gdb.base/watchpoint-solib.c index 79a9e91c642..0e4732f8325 100644 --- a/gdb/testsuite/gdb.base/watchpoint-solib.c +++ b/gdb/testsuite/gdb.base/watchpoint-solib.c @@ -18,18 +18,7 @@ #include #include -#ifdef __WIN32__ -#include -#define dlopen(name, mode) LoadLibrary (TEXT (name)) -#ifdef _WIN32_WCE -# define dlsym(handle, func) GetProcAddress (handle, TEXT (func)) -#else -# define dlsym(handle, func) GetProcAddress (handle, func) -#endif -#define dlclose(handle) FreeLibrary (handle) -#else -#include -#endif +#include "gdb-dlfcn.h" void open_shlib () @@ -41,11 +30,7 @@ void open_shlib () if (!handle) { -#ifdef __WIN32__ - fprintf (stderr, "error %d occurred\n", GetLastError ()); -#else fprintf (stderr, "%s\n", dlerror ()); -#endif exit (1); } diff --git a/gdb/testsuite/gdb.mi/mi-catch-load.c b/gdb/testsuite/gdb.mi/mi-catch-load.c index 0808d9fa759..bad7f79a37b 100644 --- a/gdb/testsuite/gdb.mi/mi-catch-load.c +++ b/gdb/testsuite/gdb.mi/mi-catch-load.c @@ -17,13 +17,7 @@ #include -#ifdef __WIN32__ -#include -#define dlopen(name, mode) LoadLibrary (TEXT (name)) -#define dlclose(handle) FreeLibrary (handle) -#else -#include -#endif +#include "gdb-dlfcn.h" char *libname = "mi-catch-load-so.so"; diff --git a/gdb/testsuite/gdb.mi/mi-dprintf-modified.c b/gdb/testsuite/gdb.mi/mi-dprintf-modified.c index 03b88712bfc..af8ca6c5940 100644 --- a/gdb/testsuite/gdb.mi/mi-dprintf-modified.c +++ b/gdb/testsuite/gdb.mi/mi-dprintf-modified.c @@ -17,18 +17,7 @@ #include -#ifdef __WIN32__ -#include -#define dlopen(name, mode) LoadLibrary (TEXT (name)) -#ifdef _WIN32_WCE -# define dlsym(handle, func) GetProcAddress (handle, TEXT (func)) -#else -# define dlsym(handle, func) GetProcAddress (handle, func) -#endif -#define dlclose(handle) FreeLibrary (handle) -#else -#include -#endif +#include "gdb-dlfcn.h" #include diff --git a/gdb/testsuite/gdb.perf/solib.c b/gdb/testsuite/gdb.perf/solib.c index 372330b50a7..c4be9e9b46e 100644 --- a/gdb/testsuite/gdb.perf/solib.c +++ b/gdb/testsuite/gdb.perf/solib.c @@ -18,14 +18,7 @@ #include #include -#ifdef __WIN32__ -#include -#define dlopen(name, mode) LoadLibrary (TEXT (name)) -# define dlsym(handle, func) GetProcAddress (handle, func) -#define dlclose(handle) FreeLibrary (handle) -#else -#include -#endif +#include "gdb-dlfcn.h" static void **handles; diff --git a/gdb/testsuite/gdb.python/py-event-load.c b/gdb/testsuite/gdb.python/py-event-load.c index 1ab5bf832e9..e4887e1a056 100644 --- a/gdb/testsuite/gdb.python/py-event-load.c +++ b/gdb/testsuite/gdb.python/py-event-load.c @@ -17,13 +17,7 @@ #include -#ifdef __WIN32__ -#include -#define dlopen(name, mode) LoadLibrary (TEXT (name)) -#define dlclose(handle) FreeLibrary (handle) -#else -#include -#endif +#include "gdb-dlfcn.h" /* This is updated by the .exp file. */ char *libname = "py-events-shlib.so"; diff --git a/gdb/testsuite/lib/gdb-dlfcn.h b/gdb/testsuite/lib/gdb-dlfcn.h new file mode 100644 index 00000000000..02cd6141b2c --- /dev/null +++ b/gdb/testsuite/lib/gdb-dlfcn.h @@ -0,0 +1,51 @@ +/* This file is part of GDB, the GNU debugger. + + Copyright 2026 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 . */ + +/* Provide the POSIX dlopen/dlsym/dlclose/dlerror interface for test + programs that load a shared library at runtime, mapping it to the + Win32 loader API on Windows. */ + +#ifndef GDB_DLFCN_H +#define GDB_DLFCN_H + +#ifdef __WIN32__ + +#include +#include + +#define dlopen(name, mode) LoadLibrary (name) +#define dlsym(handle, func) GetProcAddress (handle, func) +#define dlclose(handle) FreeLibrary (handle) +#define dlerror() gdb_dlerror () + +static char _gdb_dlerror_buf[64]; + +static const char * +gdb_dlerror (void) +{ + snprintf (_gdb_dlerror_buf, sizeof (_gdb_dlerror_buf), + "error %lu occurred", (unsigned long) GetLastError ()); + return _gdb_dlerror_buf; +} + +#else /* POSIX systems */ + +#include + +#endif + +#endif /* GDB_DLFCN_H */ -- 2.54.0