From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id AfcgGuoQYmr2WSkAWB0awg (envelope-from ) for ; Thu, 23 Jul 2026 09:02:34 -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=jpmyqyJW; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 66E081E099; Thu, 23 Jul 2026 09:02:34 -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 345361E099 for ; Thu, 23 Jul 2026 09:02:33 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9FCA64BA7997 for ; Thu, 23 Jul 2026 13:02:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9FCA64BA7997 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=jpmyqyJW Received: from insect.cherry.relay.mailchannels.net (insect.cherry.relay.mailchannels.net [23.83.223.93]) by sourceware.org (Postfix) with ESMTPS id 19F0F4BA79B0 for ; Thu, 23 Jul 2026 13:02:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 19F0F4BA79B0 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 19F0F4BA79B0 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=23.83.223.93 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1784811725; cv=none; b=Y5k01/j7tcR6WW52NsH5988iNVgJ/eMBtgDx5OSnjgylLppYb0sTRV0jP9uzACbGWw3CPGyhfhB4ztp/Xb7Fwo2cb5Xlq5nngPPfoKm8zibsvVRs+RXbpdoaay/EOpizfT6vdqrqBLkUpIPaq8kmulqxMoadv/zG7RaWhNSEgPQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1784811725; c=relaxed/simple; bh=IHd/r+0MfYLb+MqXk7VSEJHgQCGkwMSI2VATUWyt2C0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=jjhQFUGpIPneZ1/ih3dLdwAp+rk/w+cXaUlkau2aHUW+qSNDGWCQQDgUZ0dn5cgwQFkZiWbphYHSR+Il6w7f7xgEQd0dP+1lAMnCUykjK6sS3bQRu/zm0g+gNRD4O3jLBzeVDmajvBPFZX5yTnj6JrMIvn0q5ED7+zmpPYqABHU= 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=jpmyqyJW DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 19F0F4BA79B0 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 2CEF640DB6 for ; Thu, 23 Jul 2026 13:02:04 +0000 (UTC) Received: from pdx1-sub0-mail-a249.dreamhost.com (trex-green-8.trex.outbound.svc.cluster.local [100.104.12.45]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id B659C40F11 for ; Thu, 23 Jul 2026 13:02:03 +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-Skirt-Whimsical: 586e1c600ee19de2_1784811724016_3878455060 X-MC-Loop-Signature: 1784811724016:152658914 X-MC-Ingress-Time: 1784811724016 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.12.45 (trex/8.0.2); Thu, 23 Jul 2026 13:02:04 +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 4h5WVM1DVfz1049 for ; Thu, 23 Jul 2026 06:02:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=palves.net; s=dreamhost; t=1784811723; bh=P38IOlHCd3r9s7t9d3qNgbiSMKbQhqf6eHKsxEn1qTM=; h=From:To:Subject:Date:Content-Transfer-Encoding; b=jpmyqyJW/GUMRrQhD7wuVWjHbyLaiBsztFo+ZY5N5UAKeloGMQY21YyvyZ/avYs7S PqnqAwK70d3nXoC1EMOe8JuJZuV7pikdhchqwX0O2AdGAF4Lv6btzMtm+V1KXFlJGm cilFzGWacXuadBU5OdXdujU8sSHVSXs//hCGMVxTyz6LGyFjk6C7galL/P/Lut+lOO LE/+m+8BzdI/lc7OEE4ch2I4m+McbCkWT0EwFhSgQFZU9S5ZeNTo6CH6Sj9EbKE2ED 87vsh2ck4GaRQEpmX3KmrzbzG1o7YABYkmP1D6XTv56vK5Dp7JClU/dM0+mxI3mEb3 dW5a02JcBSsBA== From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 03/27] gdb/testsuite: Find host binutils in a native Windows/MSVC config Date: Thu, 23 Jul 2026 14:00:54 +0100 Message-ID: <20260723130118.206735-4-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 This is the second of two pieces making plain "make check" Just Work OOTB when testing a MinGW-hosted GDB targeting the MSVC ABI: --host=x86_64-w64-mingw32 --target=x86_64-pc-windows-msvc The gdb_find_objcopy gdb_find_objdump gdb_find_readelf gdb_find_windres gdb_find_eu-unstrip procs in lib/future.exp fall back to dejagnu's "transform", which prefixes the tool with the target triplet whenever the host and target triplets differ. For a MinGW-hosted GDB targeting the MSVC ABI, that fallback produces e.g. x86_64-pc-windows-msvc-objcopy, which does not exist, so tests that use these tools fail with, e.g.: couldn't execute "x86_64-pc-windows-msvc-objcopy": no such file or directory FAIL: gdb.base/step-symless.exp: strip stub symbols Even though the two triplets differ, this is a Windows native configuration and a host tool could be used. Both gdb/configure.ac and gdb/testsuite/configure.ac use GDB_AC_NATIVE, which treats this --host/--target combination as native. gdb/testsuite/configure.ac already stores that result in the gdb_native substitution variable, so propagate it to the testsuite via site.exp. Doing it this way keeps a single source of truth rather than reimplementing the same logic in Tcl. Which host tool to run, though, depends on the environment. For example: - The MSYS2 binutils package has bare tools only, e.g. objdump, with no x86_64-w64-mingw32-objdump: https://packages.msys2.org/packages/mingw-w64-x86_64-binutils - The xPack MinGW binutils distribution has host-triple-prefixed tools only, e.g. x86_64-w64-mingw32-objdump, with no bare objdump: https://github.com/xpack-dev-tools/gcc-xpack/ So rather than assume one spelling, search for whichever exists. Add a gdb_transform_tool helper that, given a tool name, searches PATH in the following order: 1. The target-prefixed name (via "transform"). This is the preexisting behavior for a genuine cross. 2. For native configurations only, the host-triple-prefixed name. 3. For native configurations only, the bare name. So for: --host=x86_64-w64-mingw32 --target=x86_64-pc-windows-msvc and for objdump, we try: x86_64-pc-windows-msvc-objdump x86_64-w64-mingw32-objdump objdump If none of the candidates is found, the helper returns the target-prefixed name unchanged as before, so the "tool not found" error is exactly as before. Change-Id: If48c625503c7c14bf8365e35bfe58c38a3bb7ae9 --- gdb/testsuite/Makefile.in | 1 + gdb/testsuite/lib/future.exp | 83 +++++++++++++++++++++++++++--------- gdb/testsuite/lib/gdb.exp | 13 ++++++ 3 files changed, 77 insertions(+), 20 deletions(-) diff --git a/gdb/testsuite/Makefile.in b/gdb/testsuite/Makefile.in index b852dbceb50..c4d7f4f284c 100644 --- a/gdb/testsuite/Makefile.in +++ b/gdb/testsuite/Makefile.in @@ -135,6 +135,7 @@ $(abs_builddir)/site.exp site.exp: Makefile echo "set srcdir ${abs_srcdir}" >> ./tmp0; \ echo "set tool gdb" >> ./tmp0; \ echo "set enable_libctf ${enable_libctf}" >> ./tmp0; \ + echo "set gdb_native $(if $(filter yes,$(gdb_native)),1,0)" >> ./tmp0; \ echo 'source $${srcdir}/lib/append_gdb_boards_dir.exp' >> ./tmp0; \ echo "## All variables above are generated by configure. Do Not Edit ##" >> ./tmp0; \ cat ./tmp0 > site.exp; \ diff --git a/gdb/testsuite/lib/future.exp b/gdb/testsuite/lib/future.exp index 3ab160a05fc..ca37fdaaf52 100644 --- a/gdb/testsuite/lib/future.exp +++ b/gdb/testsuite/lib/future.exp @@ -146,55 +146,98 @@ proc gdb_find_ldd {} { return $ldd } +# Return the name of a target binary utility TOOL, e.g. "objcopy". +# +# Normally, this is the target-prefixed TOOL, as computed by dejagnu's +# 'transform'. On a native configuration, if that name is not on +# PATH, fall back to a host tool instead. This makes the binary +# utilities usable when the host and target triplets differ on what we +# still consider a native configuration, e.g. a MinGW-hosted GDB +# targeting the MSVC ABI. +# +# Only use this for a tool that behaves the same whether it is the +# host or the target build of the tool -- the binary utilities that +# operate on the shared object file format (objcopy, objdump, readelf, +# etc.) qualify. Do not use this for a tool whose behavior depends on +# the target, such as the compiler: the host compiler builds for the +# host, not for the debuggee's ABI. + +proc gdb_transform_tool {tool} { + # Compute the target-prefixed name with transform's verbose + # logging suppressed -- we may end up only probing this candidate + # and not running it (in the native case), so we don't want + # transform's "Transforming ..." line in the log until we know + # this is the name we return. + set save_verbose $::verbose + set ::verbose -1 + set target_tool [transform $tool] + set ::verbose $save_verbose + + # Default to the target-prefixed name. It is the right tool for a + # cross, and for the not-found case it gives the same "tool not + # found" error as DejaGnu's transform would. + set result $target_tool + + if {[which $target_tool] == 0 && [gdb_is_native_config]} { + # Try looking for a host tool: the host-triple-prefixed name + # first (e.g. x86_64-w64-mingw32-objcopy), then the bare name + # (e.g. objcopy). + set host_tool "[ishost {}]-$tool" + if {[which $host_tool] != 0} { + set result $host_tool + } elseif {[which $tool] != 0} { + set result $tool + } + } + + # Log the transformation the way dejagnu's transform would, but + # for the name we actually settled on. + if {$result ne $tool} { + verbose "Transforming $tool to $result" + } + + return $result +} + proc gdb_find_objcopy {} { global OBJCOPY_FOR_TARGET if {[info exists OBJCOPY_FOR_TARGET]} { - set objcopy $OBJCOPY_FOR_TARGET - } else { - set objcopy [transform objcopy] + return $OBJCOPY_FOR_TARGET } - return $objcopy + return [gdb_transform_tool objcopy] } # find target objdump proc gdb_find_objdump {} { global OBJDUMP_FOR_TARGET if {[info exists OBJDUMP_FOR_TARGET]} { - set objdump $OBJDUMP_FOR_TARGET - } else { - set objdump [transform objdump] + return $OBJDUMP_FOR_TARGET } - return $objdump + return [gdb_transform_tool objdump] } proc gdb_find_readelf {} { global READELF_FOR_TARGET if {[info exists READELF_FOR_TARGET]} { - set readelf $READELF_FOR_TARGET - } else { - set readelf [transform readelf] + return $READELF_FOR_TARGET } - return $readelf + return [gdb_transform_tool readelf] } proc gdb_find_windres {} { global WINDRES_FOR_TARGET if {[info exists WINDRES_FOR_TARGET]} { - set windres $WINDRES_FOR_TARGET - } else { - set windres [transform windres] + return $WINDRES_FOR_TARGET } - return $windres + return [gdb_transform_tool windres] } proc gdb_find_eu-unstrip {} { global EU_UNSTRIP_FOR_TARGET if {[info exists EU_UNSTRIP_FOR_TARGET]} { - set eu_unstrip $EU_UNSTRIP_FOR_TARGET - } else { - set eu_unstrip [transform eu-unstrip] + return $EU_UNSTRIP_FOR_TARGET } - return $eu_unstrip + return [gdb_transform_tool eu-unstrip] } # Local version of default_target_compile, to be used for languages that diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index eea39d4e8cc..b4046c402d4 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -4223,6 +4223,19 @@ proc is_windows_based_target {} { return [expr {[istarget *-*-cygwin*] || [istarget *-*-mingw*]}] } +# Return true if this is a native configuration in GDB's sense. This +# is broader than dejagnu's isnative, which returns true iff we have +# identical host and target triplets. On Windows the host and target +# triplets can differ and the GDB build can still natively debug the +# target. E.g. a mingw-hosted GDB targeting binaries produced by a +# compiler defaulting to windows-msvc. + +proc gdb_is_native_config {} { + # configure already worked this out and the result is found in + # site.exp in this boolean. + return $::gdb_native +} + # Return 1 if displaced stepping is supported on target, otherwise, return 0. proc support_displaced_stepping {} { -- 2.54.0