/* 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;
}
--- /dev/null
+# 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 <http://www.gnu.org/licenses/>.
+
+# 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"