[PATCH 2/2] gdb/testsuite: Force DWARF debug info on windows-msvc
Pedro Alves <[email protected]>
| Newsgroups | gmane.comp.gdb.patches |
|---|---|
| Message-ID | <[email protected]> |
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