diff options
author | Simon Marchi <simon.marchi@efficios.com> | 2022-03-28 11:03:53 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@polymtl.ca> | 2022-07-29 20:54:49 -0400 |
commit | 7900b17e334b114ff149c5a3da7884e6ab3f7136 (patch) | |
tree | c94560eb6cf1283b64eeb2177ef2ca25508f9419 /gdb/testsuite/lib/dwarf.exp | |
parent | ee26d001cdf44cff897f994c89ad333bfa66d59e (diff) | |
download | gdb-7900b17e334b114ff149c5a3da7884e6ab3f7136.zip gdb-7900b17e334b114ff149c5a3da7884e6ab3f7136.tar.gz gdb-7900b17e334b114ff149c5a3da7884e6ab3f7136.tar.bz2 |
gdb/testsuite: add macros test for source files compiled in various ways
Using different ways of passing source file paths to compilers results n
different file and directory paths in the line header. For example:
- gcc foo.c
- gcc ./foo.c
- gcc ../cwd/foo.c
- gcc $PWD/foo.c
Because of this, GDB sometimes failed to look up macros. The previous
patch fixed that as much as possible. This patch adds the corresponding
tests.
Add both a DWARF assembler-based test and a regular test. The DWARF
assembled-based one tests some hard-coded debug info based on what I
have observed some specific versions of gcc and clang generate. We want
to make sure that GDB keeps handling all these cases correctly, even if
it's not always clear whether they are really valid DWARF. Also, they
will be tested no matter what the current target compiler is for a given
test run.
The regular test is compiled using the target compiler, so it may help
find bugs when testing against some other toolchains than what was used
to generate the DWARF assembler-based test.
For the DWARF assembler-based test, add to testsuite/lib/dwarf.exp the
necessary code to generate a DWARF5 .debug_macro section. The design of
the new procs is based on what was done for rnglists and loclists.
To test against a specific compiler one can use this command, for
example:
$ make check TESTS="gdb.base/macro-source-path.exp" RUNTESTFLAGS="CC_FOR_TARGET=clang --target_board unix/gdb:debug_flags=-gdwarf-5"
Change-Id: Iab8da498e57d10cc2a3d09ea136685d9278cfcf6
Diffstat (limited to 'gdb/testsuite/lib/dwarf.exp')
-rw-r--r-- | gdb/testsuite/lib/dwarf.exp | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp index 3d0ea83..356451b 100644 --- a/gdb/testsuite/lib/dwarf.exp +++ b/gdb/testsuite/lib/dwarf.exp @@ -2144,6 +2144,98 @@ namespace eval Dwarf { incr _debug_loclists_locdesc_count } + # Emit a DWARF .debug_macro section. + # + # BODY must be Tcl code that emits the content of the section. It is + # evaluated in the caller's context. The body can use the `unit` proc + # (see `_macro_unit`) to generate macro units. + + proc macro { body } { + _section ".debug_macro" + + with_override Dwarf::unit Dwarf::_macro_unit { + uplevel $body + } + } + + # Generate one macro unit. + # + # This proc is meant to be used within proc macro's body. It is made + # available as `unit` while inside proc macro's body. + # + # BODY must be Tcl code that emits the content of the unit. It may call + # procedures defined below, prefixed with `_macro_unit_`, to generate the + # unit's content. It is evaluated in the caller's context. + # + # The `is-64 true|false` options tells whether to use 64-bit DWARF instead + # of 32-bit DWARF. The default is 32-bit. + # + # If specified, the `debug-line-offset-label` option is the name of a label + # to use for the unit header's `debug_line_offset` field value. If + # omitted, the unit header will not contain the `debug_line_offset` field. + + proc _macro_unit { options body } { + parse_options { + {"is-64" "false"} + {"debug-line-offset-label" ""} + } + + _op .2byte 5 "version" + + # Flags: + # + # offset_size_flag = set if is-64 is true + # debug_line_offset_flag = set if debug-line-offset-label is set + # opcode_operands_table_flag = 0 + set flags 0 + + if { ${is-64} } { + set flags [expr $flags | 0x1] + } + + if { ${debug-line-offset-label} != "" } { + set flags [expr $flags | 0x2] + } + + _op .byte $flags "flags" + + if { ${debug-line-offset-label} != "" } { + if { ${is-64} } { + _op .8byte ${debug-line-offset-label} "debug_line offset" + } else { + _op .4byte ${debug-line-offset-label} "debug_line offset" + } + } + + with_override Dwarf::define Dwarf::_macro_unit_define { + with_override Dwarf::start_file Dwarf::_macro_unit_start_file { + with_override Dwarf::end_file Dwarf::_macro_unit_end_file { + uplevel $body + }}} + } + + # Emit a DW_MACRO_define entry. + + proc _macro_unit_define { lineno text } { + _op .byte 0x1 "DW_MACRO_define" + _op .uleb128 $lineno "Line number" + _op .asciz "\"$text\"" "Macro definition" + } + + # Emit a DW_MACRO_start_file entry. + + proc _macro_unit_start_file { lineno file_idx } { + _op .byte 0x3 "DW_MACRO_start_file" + _op .uleb128 $lineno + _op .uleb128 $file_idx + } + + # Emit a DW_MACRO_end_file entry. + + proc _macro_unit_end_file {} { + _op .byte 0x4 "DW_MACRO_end_file" + } + # Emit a DWARF .debug_line unit. # OPTIONS is a list with an even number of elements containing # option-name and option-value pairs. |