From 16b0db75af6b4b4d434aa84c74d58b7290e04143 Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Tue, 31 Mar 2020 12:17:27 +0200 Subject: [PATCH] [gdb/testsuite] Fix c-linkage-name.exp with -flto When running test-case gdb.base/c-linkage-name.exp with target board unix/-flto/-O0/-flto-partition=none/-ffat-lto-objects, I run into: ... PASS: gdb.base/c-linkage-name.exp: maint info psymtab: c-linkage-name-2.c: no FAIL: gdb.base/c-linkage-name.exp: print symada__cS before partial symtab \ expansion ... The test-case tries to print a symbol before and after symtab expansion. And it tries to ensure (since commit 13c3a74afb) that the symtab containing the symbol is not yet expanded when doing the 'before' print, by placing the symbol in a different CU (c-linkage-name-2.c) from the one containing main (c-linkage-name.c), such that when we load the exec and expand the symtab containing main, the symtab containing the symbol isn't. The generated debug info for the test-case when using mentioned target board however is structured like this: ... <0>: Abbrev Number: 1 (DW_TAG_compile_unit) DW_AT_name : <1>: Abbrev Number: 2 (DW_TAG_imported_unit) DW_AT_import : <0x16b> [Abbrev Number: 1] <1>: Abbrev Number: 2 (DW_TAG_imported_unit) DW_AT_import : <0x19c> [Abbrev Number: 1] <1>: Abbrev Number: 3 (DW_TAG_subprogram) DW_AT_abstract_origin: <0x17d> <1><115>: Abbrev Number: 4 (DW_TAG_variable) <116> DW_AT_abstract_origin: <0x1ce> <0><16b>: Abbrev Number: 1 (DW_TAG_compile_unit) <171> DW_AT_name : c-linkage-name.c <1><17d>: Abbrev Number: 2 (DW_TAG_subprogram) <17e> DW_AT_name : main <0><19c>: Abbrev Number: 1 (DW_TAG_compile_unit) <1a2> DW_AT_name : c-linkage-name-2.c <1><1ce>: Abbrev Number: 5 (DW_TAG_variable) <1cf> DW_AT_name : mundane <1d6> DW_AT_linkage_name: symada__cS ... So, the CU named contains both the concrete main and the concrete symbol, which explains the FAIL. The first test should fail, but passes for two reasons. First of all, due to PR symtab/25700, we have two regular partial symtabs c-linkage-name-2.c instead of one, and one of them is expanded, the other one not: ... { psymtab c-linkage-name-2.c ((struct partial_symtab *) 0x38d6f60) readin yes { psymtab c-linkage-name-2.c ((struct partial_symtab *) 0x38d6fe0) readin no ... And then there's the include symtab, which is also not expanded: ... { psymtab c-linkage-name-2.c ((struct partial_symtab *) 0x38143e0) readin no ... Fix the FAIL by explicitly setting the language before load, changing the language setting from auto/c to manual/c, such that the symtab containing main is no longer expanded. And make the symtab expansion testing more robust by using the output of "maint info symtabs" instead of "maint info psymtabs". Tested on x86_64-linux, using native and target boards cc-with-gdb-index.exp, cc-with-debug-names.exp, readnow.exp and unix/-flto/-O0/-flto-partition=none/-ffat-lto-objects. gdb/testsuite/ChangeLog: 2020-03-31 Tom de Vries * gdb.base/c-linkage-name.exp: Fix test-case comment. Set language to c. Use "maint info symtabs" to check symtab expansion. --- gdb/testsuite/ChangeLog | 5 +++++ gdb/testsuite/gdb.base/c-linkage-name.exp | 20 +++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 9d879fba3bc..bb31bcdf3ac 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-03-31 Tom de Vries + + * gdb.base/c-linkage-name.exp: Fix test-case comment. Set language to + c. Use "maint info symtabs" to check symtab expansion. + 2020-03-30 Tom de Vries * gdb.base/c-linkage-name.exp: Use readnow call to mark a test diff --git a/gdb/testsuite/gdb.base/c-linkage-name.exp b/gdb/testsuite/gdb.base/c-linkage-name.exp index 9a472a79a29..8afd8ce301a 100644 --- a/gdb/testsuite/gdb.base/c-linkage-name.exp +++ b/gdb/testsuite/gdb.base/c-linkage-name.exp @@ -14,8 +14,8 @@ # along with this program. If not, see . # This file is part of the gdb testsuite. It is intended to test that -# gdb can correctly print arrays with indexes for each element of the -# array. +# gdb can correctly print an ada symbol with linkage name before and after +# symtab expansion. standard_testfile c-linkage-name.c c-linkage-name-2.c @@ -25,13 +25,19 @@ if { [gdb_compile "${sources}" "${binfile}" executable {debug}] != "" } { return -1 } -clean_restart ${binfile} +clean_restart +gdb_test_no_output "set language c" +gdb_load ${binfile} set readnow [readnow] -# Verify that partial symtab expansion has not taken place for -# c-linkage-name-2.c. +set test "verify no symtab expansion" +if { $readnow } { + unsupported $test +} else { + # Verify that symtab expansion has not taken place. -verify_psymtab_expanded c-linkage-name-2.c no + gdb_test_no_output "maint info symtabs" $test +} set test "print symada__cS before partial symtab expansion" if { $readnow } { @@ -54,7 +60,7 @@ gdb_test "break do_something_other_cu" \ # Verify that partial symtab expansion has taken place for # c-linkage-name-2.c. -verify_psymtab_expanded c-linkage-name-2.c yes +gdb_test "maint info symtabs" "\{ symtab \[^\r\n\]*c-linkage-name-2.c.*" # Flush the symbol cache to prevent the lookup to return the same as before. -- 2.30.2