From: Pedro Alves <pedro@palves.net>
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 [thread overview]
Message-ID: <20260723130118.206735-4-pedro@palves.net> (raw)
In-Reply-To: <20260723130118.206735-1-pedro@palves.net>
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
next prev parent reply other threads:[~2026-07-23 13:02 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-23 13:00 [PATCH 00/27] Teach the testsuite about the Windows/MSVC target Pedro Alves
2026-07-23 13:00 ` [PATCH 01/27] gdb/testsuite: Don't link with -lm on windows-msvc Pedro Alves
2026-07-23 13:00 ` [PATCH 02/27] gdb/testsuite: Use unprefixed runtest for a native Windows/MSVC build Pedro Alves
2026-07-23 13:00 ` Pedro Alves [this message]
2026-07-23 13:00 ` [PATCH 04/27] gdb/testsuite: Compile with -Wno-deprecated-declarations on windows-msvc Pedro Alves
2026-07-23 13:00 ` [PATCH 05/27] gdb/testsuite: Recognize windows-msvc across lib/gdb.exp procedures Pedro Alves
2026-07-23 13:00 ` [PATCH 06/27] gdb/testsuite: Don't pass -fPIC on PE/COFF targets Pedro Alves
2026-07-23 13:00 ` [PATCH 07/27] gdb/testsuite: Use /IMPLIB on windows-msvc to name import libraries Pedro Alves
2026-07-23 13:00 ` [PATCH 08/27] gdb/testsuite: Export all DLL symbols on windows-msvc via generated .def Pedro Alves
2026-07-23 13:01 ` [PATCH 09/27] gdb/testsuite: Restrict --no-as-needed to ELF targets Pedro Alves
2026-07-23 13:01 ` [PATCH 10/27] gdb.base/set-cwd.exp: Use is_windows_native_target Pedro Alves
2026-07-23 13:01 ` [PATCH 11/27] gdb.base/exitsignal.exp: " Pedro Alves
2026-07-23 13:01 ` [PATCH 12/27] gdb.base/exitsignal.exp: Relax SIGSEGV second-chance pattern Pedro Alves
2026-07-23 13:01 ` [PATCH 13/27] gdb/testsuite: Skip -Ttext-segment on PE Pedro Alves
2026-07-23 13:01 ` [PATCH 14/27] gdb/testsuite: Support text_segment on windows-msvc via /BASE Pedro Alves
2026-07-23 13:01 ` [PATCH 15/27] gdb.base/shreloc.exp: Use gdb_compile text_segment to set image base Pedro Alves
2026-07-23 13:01 ` [PATCH 16/27] gdb/coffread: Don't relocate absolute symbols Pedro Alves
2026-07-23 13:01 ` [PATCH 17/27] gdb.base/shreloc.exp: Test absolute symbols portably Pedro Alves
2026-07-23 13:01 ` [PATCH 18/27] gdb: %p => host_address_to_string, target-section owner token Pedro Alves
2026-07-23 13:01 ` [PATCH 19/27] gdb: %p => host_address_to_string, dump_for_expression Pedro Alves
2026-07-23 13:01 ` [PATCH 20/27] gdb: %p => host_address_to_string, find_symtab_matching_filename Pedro Alves
2026-07-23 13:01 ` [PATCH 21/27] gdb: %p => host_address_to_string, handle_output_debug_string Pedro Alves
2026-07-23 13:01 ` [PATCH 22/27] gdb.base/maint-info-sections.exp: Match exec file name with optional .exe Pedro Alves
2026-07-23 13:01 ` [PATCH 23/27] gdb.base/maint-info-sections.exp: Remove stale Windows DATA xfail Pedro Alves
2026-07-23 13:01 ` [PATCH 24/27] gdb.base/solib-weak.exp: Skip on all PE/COFF targets Pedro Alves
2026-07-23 13:01 ` [PATCH 25/27] gdb.server/wrapper.exp: Skip on all Windows targets Pedro Alves
2026-07-23 13:01 ` [PATCH 26/27] gdb/testsuite: Factor out dlopen/LoadLibrary shim into lib/gdb-dlfcn.h Pedro Alves
2026-07-23 13:01 ` [PATCH 27/27] gdb/testsuite/lib/gdb-dlfcn.h: __WIN32__ => _WIN32 Pedro Alves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260723130118.206735-4-pedro@palves.net \
--to=pedro@palves.net \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox