diff --git a/gdb/ChangeLog b/gdb/ChangeLog index f1ebf09ff46..109456689aa 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,7 @@ +2020-04-23 Tom de Vries + + * symtab.c (lookup_global_symbol): Prefer def over decl. + 2020-04-23 Tom de Vries PR symtab/25807 diff --git a/gdb/symtab.c b/gdb/symtab.c index 1eef97837e8..4e9f91056b8 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -2718,17 +2718,23 @@ lookup_global_symbol (const char *name, global block first. This yields "more expected" behavior, and is needed to support 'FILENAME'::VARIABLE lookups. */ const struct block *global_block = block_global_block (block); + symbol *sym = NULL; if (global_block != nullptr) { - symbol *sym = lookup_symbol_in_block (name, - symbol_name_match_type::FULL, - global_block, domain); - if (sym != nullptr) + sym = lookup_symbol_in_block (name, + symbol_name_match_type::FULL, + global_block, domain); + if (sym != NULL && best_symbol (sym, domain)) return { sym, global_block }; } struct objfile *objfile = lookup_objfile_from_block (block); - return lookup_global_or_static_symbol (name, GLOBAL_BLOCK, objfile, domain); + block_symbol bs + = lookup_global_or_static_symbol (name, GLOBAL_BLOCK, objfile, domain); + if (better_symbol (sym, bs.symbol, domain) == sym) + return { sym, global_block }; + else + return bs; } bool diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index e37aca2b5af..10683db566d 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2020-04-23 Tom de Vries + + * gdb.base/decl-before-def.exp: Run to main and print a again. + 2020-04-23 Tom de Vries * gdb.base/decl-before-def-decl.c: New test. diff --git a/gdb/testsuite/gdb.base/decl-before-def.exp b/gdb/testsuite/gdb.base/decl-before-def.exp index feb2084a82f..0af3bdf3c75 100644 --- a/gdb/testsuite/gdb.base/decl-before-def.exp +++ b/gdb/testsuite/gdb.base/decl-before-def.exp @@ -24,3 +24,10 @@ if {[prepare_for_testing "failed to prepare" $testfile $sources]} { gdb_test "maint expand-symtabs" gdb_test "p a" { = \{1, 2\}} + +if ![runto_main] then { + fail "can't run to main" + return 0 +} + +gdb_test "p a" { = \{1, 2\}}