diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 202f05f7e94..41532c8efec 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -14926,31 +14926,33 @@ cooked_index_functions::expand_symtabs_matching /* Might have been looking for "a::b" and found "x::a::b". */ - if (symbol_matcher == nullptr) - { - if ((match_type == symbol_name_match_type::FULL - || (lang != language_ada - && match_type == symbol_name_match_type::EXPRESSION))) - { - if (parent != nullptr) - continue; + if (((match_type == symbol_name_match_type::FULL + || (lang != language_ada + && match_type == symbol_name_match_type::EXPRESSION))) + && parent != nullptr) + continue; - if (entry->lang != language_unknown) - { - symbol_name_matcher_ftype *name_matcher - = lang_def->get_symbol_name_matcher - (segment_lookup_names.back ()); - if (!name_matcher (entry->canonical, - segment_lookup_names.back (), nullptr)) - continue; - } - } - } - else + /* Check that the full name matches -- either by matching + the lookup name ourselves, or by passing the full name to + the symbol matcher. The former is a bit of a hack: it + seems like the loop above could just examine every + element of the name, avoiding the need to check here; but + this is hard. See PR symtab/32733. */ + if (symbol_matcher != nullptr || entry->lang != language_unknown) { auto_obstack temp_storage; - const char *full_name = entry->full_name (&temp_storage); - if (!symbol_matcher (full_name)) + const char *full_name = entry->full_name (&temp_storage, + false, true); + if (symbol_matcher == nullptr) + { + symbol_name_matcher_ftype *name_matcher + = (lang_def->get_symbol_name_matcher + (lookup_name_without_params)); + if (!name_matcher (full_name, lookup_name_without_params, + nullptr)) + continue; + } + else if (!symbol_matcher (full_name)) continue; } diff --git a/gdb/testsuite/gdb.dwarf2/no-expand-mixed-case.exp b/gdb/testsuite/gdb.dwarf2/no-expand-mixed-case.exp new file mode 100644 index 00000000000..7359eeac5b7 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/no-expand-mixed-case.exp @@ -0,0 +1,42 @@ +# Copyright 2025 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Searching for "INT" should not cause CU expansion in a C program. +# PR symtab/31010. + +require !readnow + +standard_testfile main.c + +if {[prepare_for_testing "failed to prepare" $testfile \ + $srcfile {debug}]} { + return +} + +# Check that no CUs have been expanded yet. +gdb_test_no_output "maint info symtabs" \ + "no symtabs before lookup" + +# The bug was that this caused CU expansion even though the type does +# not exist. +gdb_test "whatis INT" "No symbol \"INT\" in current context." + +# Check that no CUs were expanded by the lookup. This fails with +# .gdb_index. +if {[have_index $binfile] == "gdb_index"} { + setup_kfail symtab/31363 *-*-* +} +gdb_test_no_output "maint info symtabs" \ + "no symtabs after lookup"