From: Pedro Alves <pedro@palves.net>
To: gdb-patches@sourceware.org
Subject: [PATCH 2/2] gdb/testsuite: Force DWARF debug info on windows-msvc
Date: Tue, 11 Aug 2026 01:37:00 +0100 [thread overview]
Message-ID: <20260811003700.3580470-3-pedro@palves.net> (raw)
In-Reply-To: <20260811003700.3580470-1-pedro@palves.net>
Clang's windows-msvc targets default to outputting PDB debug info for
host code, which GDB does not understand. This commit makes the
testsuite tell the compiler/linker to emit DWARF instead.
There is a block in gdb_compile already doing this for AIX, so we
extend it.
Extra care is taken to make it possible to run the testsuite with
another debug format, by passing the (pre-existing) debug_format flag,
like this for example on the command line:
$ make check RUNTESTFLAGS="--target_board unix/gdb:debug_flags=-gcodeview"
or with a custom board that sets debug_flags.
Change-Id: I5bcafa408696b349b829b4ffbd75037be25b3f3b
---
gdb/testsuite/lib/gdb.exp | 85 ++++++++++++++++++++++++++++++++-------
1 file changed, 70 insertions(+), 15 deletions(-)
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 912ddf1cd54..0d3497fa3f2 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -6747,21 +6747,76 @@ proc gdb_compile {source dest type options} {
}
}
- # On AIX systems, until GCC 12 (maybe later), stabs was the default
- # debug option, but we'd like to have dwarf instead.
- # If we're running on one of those systems and debug was requested,
- # but no explicit -g<format> option was given, use -gdwarf to force
- # that as the debug info for the inferior.
- # This list should be exhaustive:
- set debug_format "btf|ctf|stabs|vms|coff|xcoff"
- # Since additional_flags is a comma separated list, identify if there
- # are other (optional) flags in the list.
- set other_options "-\[a-zA-Z0-9\]*,"
- set full_regexp "^additional_flags=\($other_options\)*-g\($debug_format\)"
- if { [istarget *-*-aix*]
- && [lsearch -exact $options debug] != -1
- && [lsearch -regexp $options $full_regexp] == -1} {
- lappend new_options "additional_flags=-gdwarf"
+ # Some systems default to debug formats other than DWARF, but we'd
+ # like to have DWARF instead:
+ #
+ # - On AIX systems, until GCC 12 (maybe later), stabs was the
+ # default debug option.
+ #
+ # - windows-msvc targets default to PDB/CodeView debug info, which
+ # we don't support.
+ #
+ # If we're running on one of those systems and debug was
+ # requested, but no explicit -g<format> option was given, nor has
+ # a specific debug format been requested via debug_flags in the
+ # target board, use -gdwarf to force DWARF as the debug info for
+ # the inferior.
+ if {[lsearch -exact $options debug] != -1} {
+ # This list should be exhaustive:
+ set debug_format "btf|ctf|stabs|vms|coff|xcoff|dwarf|codeview"
+ # True if we're using DWARF.
+ set using_dwarf 0
+ # Since additional_flags is a comma separated list, identify
+ # if there are other (optional) flags in the list.
+ set other_options "-\[a-zA-Z0-9\]*,"
+ set full_regexp "^additional_flags=\($other_options\)*-g\($debug_format\)"
+ if { ([istarget *-*-aix*] || [istarget *-*-windows-msvc*])
+ && ![board_info [target_info name] exists debug_flags]
+ && [lsearch -regexp $options $full_regexp] == -1} {
+ # Nothing is explicitly choosing a debug format. Emit
+ # DWARF.
+ lappend new_options "additional_flags=-gdwarf"
+ set using_dwarf 1
+ }
+
+ # On windows-msvc, if we're targeting DWARF, we need a couple
+ # extra linker (lld-link) options. This is a separate check
+ # from the above because we need to check whether the board
+ # file selects DWARF via debug_flags.
+ if { [istarget *-*-windows-msvc*] } {
+ set dwarf_regexp "^additional_flags=\($other_options\)*-gdwarf"
+ if { [board_info [target_info name] exists debug_flags] } {
+ # The board wants a specific debug format. Check
+ # whether it's DWARF.
+ set board_debug_flags "[board_info [target_info name] debug_flags]"
+ if { [lsearch -regexp $board_debug_flags "-gdwarf"] != -1 } {
+ set using_dwarf 1
+ }
+ } elseif { [lsearch -regexp $options $dwarf_regexp] == -1 } {
+ # The testcase explicitly requested DWARF.
+ set using_dwarf 1
+ }
+
+ if {$using_dwarf} {
+ # Passing "-debug:dwarf" to lld-link suppresses:
+ # lld-link: warning: section name .debug_info is longer
+ # than 8 characters and will use a non-standard string table
+ #
+ # -Wl,/ignore:longsections would also work, but
+ # telling lld-link we're outputting DWARF does more
+ # than suppress the warning.
+ #
+ # Passing -debug:none before -debug:dwarf is necessary
+ # to disable PDB emission. This is because Clang
+ # passes -debug to lld-link if you specify _any_ -g
+ # option, including -gdwarf, and -debug makes lld-link
+ # emit a PDB file. IOW, even plain -gdwarf still
+ # emits a (mostly empty and useless) PDB file.
+ # -debug:dwarf does not disable PDB emission (by
+ # design), but "-debug:none" does disable it.
+ lappend new_options "ldflags=-Wl,-debug:none -Wl,-debug:dwarf"
+ }
+ }
}
set shlib_found 0
--
2.54.0
prev parent reply other threads:[~2026-08-11 0:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-11 0:36 [PATCH 0/2] gdb/testsuite: Make windows-msvc test with lld-link + DWARF Pedro Alves
2026-08-11 0:36 ` [PATCH 1/2] gdb/testsuite: Force lld-link linker on windows-msvc Pedro Alves
2026-08-11 0:37 ` Pedro Alves [this message]
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=20260811003700.3580470-3-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