diff options
author | Simon Marchi <simon.marchi@efficios.com> | 2022-04-06 21:51:57 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@polymtl.ca> | 2022-04-07 14:41:28 -0400 |
commit | 9be5d742dbe3d23f740bbeb5bd1337da8ece536e (patch) | |
tree | 4b87a6e848daac7225d457c1b299e44303c040f7 /gdb/testsuite | |
parent | 4f7df13ee75be36ae5c6046b6d6f60e04498b719 (diff) | |
download | gdb-9be5d742dbe3d23f740bbeb5bd1337da8ece536e.zip gdb-9be5d742dbe3d23f740bbeb5bd1337da8ece536e.tar.gz gdb-9be5d742dbe3d23f740bbeb5bd1337da8ece536e.tar.bz2 |
gdb/testsuite: add "macros" option to gdb_compile
Make gdb_compile handle a new "macros" option, which makes it pass the
appropriate flag to make the compiler include macro information in the
debug info. This will help simplify tests using macros, reduce
redundant code, and make it easier to add support for a new compiler.
Right now it only handles clang specially (using -fdebug-macro) and
falls back to -g3 otherwise (which works for gcc). Other compilers can
be added as needed.
There are some tests that are currently skipped if the compiler is nor
gcc nor clang. After this patch, the tests will attempt to run (the -g3
fall back will be used). That gives a chance to people using other
compilers to notice something is wrong and maybe add support for their
compiler. If it is needed to support a compiler that doesn't have a way
to include macro information, then we can always introduce a
"skip_macro_tests" that can be used to skip over them.
Change-Id: I50cd6ab1bfbb478c1005486408e214b551364c9b
Diffstat (limited to 'gdb/testsuite')
-rw-r--r-- | gdb/testsuite/gdb.base/info-macros.exp | 14 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/macscp.exp | 11 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/style.exp | 23 | ||||
-rw-r--r-- | gdb/testsuite/gdb.linespec/macro-relative.exp | 9 | ||||
-rw-r--r-- | gdb/testsuite/lib/gdb.exp | 13 |
5 files changed, 22 insertions, 48 deletions
diff --git a/gdb/testsuite/gdb.base/info-macros.exp b/gdb/testsuite/gdb.base/info-macros.exp index b3e1032..39c9bc6 100644 --- a/gdb/testsuite/gdb.base/info-macros.exp +++ b/gdb/testsuite/gdb.base/info-macros.exp @@ -21,19 +21,7 @@ if [using_fission] { return -1 } -set options {debug} - -get_compiler_info -if { [test_compiler_info gcc*] } { - lappend options "additional_flags=-g3" -} elseif { [test_compiler_info clang*] } { - lappend options "additional_flags=-fdebug-macro" -} else { - untested "no compiler info" - return -1 -} - -if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} $options] } { +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} {debug macros}] } { return -1 } diff --git a/gdb/testsuite/gdb.base/macscp.exp b/gdb/testsuite/gdb.base/macscp.exp index 4c06423..be9bd53 100644 --- a/gdb/testsuite/gdb.base/macscp.exp +++ b/gdb/testsuite/gdb.base/macscp.exp @@ -18,19 +18,12 @@ standard_testfile macscp1.c set objfile [standard_output_file ${testfile}.o] -set options { debug additional_flags=-DFROM_COMMANDLINE=ARG} - -get_compiler_info -if { [test_compiler_info "gcc-*"] } { - lappend options additional_flags=-g3 -} elseif { [test_compiler_info "clang-*"] } { - lappend options additional_flags=-fdebug-macro -} +set options {debug macros additional_flags=-DFROM_COMMANDLINE=ARG} # Generate the intermediate object file. This is required by Darwin to # have access to the .debug_macinfo section. if {[gdb_compile "${srcdir}/${subdir}/macscp1.c" "${objfile}" \ - object $options] != "" + object $options] != "" || [gdb_compile "${objfile}" "${binfile}" executable $options] != "" } { untested "failed to compile" return -1 diff --git a/gdb/testsuite/gdb.base/style.exp b/gdb/testsuite/gdb.base/style.exp index 611b8ae..6bb5e1c 100644 --- a/gdb/testsuite/gdb.base/style.exp +++ b/gdb/testsuite/gdb.base/style.exp @@ -20,18 +20,7 @@ load_lib gdb-python.exp standard_testfile # Compile the test executable. -set test_macros 0 -set options debug -get_compiler_info -if { [test_compiler_info "gcc-*"] } { - lappend options additional_flags=-g3 - set test_macros 1 -} elseif { [test_compiler_info "clang-*"] } { - lappend options additional_flags=-fdebug-macro - set test_macros 1 -} - -if {[build_executable "failed to build" $testfile $srcfile $options]} { +if {[build_executable "failed to build" $testfile $srcfile {debug macros}]} { return -1 } @@ -75,7 +64,7 @@ proc clean_restart_and_disable { args } { # CLEAN_RESTART_AND_DISABLE instead of CLEAN_RESTART, this ensures # that the test operates as expected as styles are disabled. proc run_style_tests { } { - global testfile srcfile hex binfile test_macros + global testfile srcfile hex binfile global currently_disabled_style decimal hex save_vars { env(TERM) } { @@ -181,11 +170,9 @@ proc run_style_tests { } { gdb_test_no_output "set width 0" "" } - if {$test_macros} { - set macro_line [gdb_get_line_number "\#define SOME_MACRO"] - gdb_test "info macro SOME_MACRO" \ - "Defined at $base_file_expr:$macro_line\r\n#define SOME_MACRO 23" - } + set macro_line [gdb_get_line_number "\#define SOME_MACRO"] + gdb_test "info macro SOME_MACRO" \ + "Defined at $base_file_expr:$macro_line\r\n#define SOME_MACRO 23" gdb_test_no_output "set width 0" diff --git a/gdb/testsuite/gdb.linespec/macro-relative.exp b/gdb/testsuite/gdb.linespec/macro-relative.exp index f827420..609f290 100644 --- a/gdb/testsuite/gdb.linespec/macro-relative.exp +++ b/gdb/testsuite/gdb.linespec/macro-relative.exp @@ -26,14 +26,7 @@ if [is_remote host] { return 0 } -set opts {debug additional_flags=-I.} - -get_compiler_info -if [test_compiler_info gcc*] { - lappend opts additional_flags=-g3 -} elseif [test_compiler_info clang*] { - lappend opts additional_flags=-fdebug-macro -} +set opts {debug additional_flags=-I. macros} if { [file pathtype $objdir] == "relative" } { untested "objdir $objdir should be absolute" diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 859c473..0ef7e12 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -4349,6 +4349,8 @@ set gdb_saved_set_unbuffered_mode_obj "" # - nowarnings: Inhibit all compiler warnings. # - pie: Force creation of PIE executables. # - nopie: Prevent creation of PIE executables. +# - macros: Add the required compiler flag to include macro information in +# debug information # # And here are some of the not too obscure options understood by DejaGnu that # influence the compilation: @@ -4576,6 +4578,17 @@ proc gdb_compile {source dest type options} { lappend options "$flag" } + set macros [lsearch -exact $options macros] + if {$macros != -1} { + if { [test_compiler_info "clang-*"] } { + set flag "additional_flags=-fdebug-macro" + } else { + set flag "additional_flags=-g3" + } + + set options [lreplace $options $macros $macros $flag] + } + if { $type == "executable" } { if { ([istarget "*-*-mingw*"] || [istarget "*-*-*djgpp"] |