aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2024-05-23 09:21:09 -0600
committerTom Tromey <tromey@adacore.com>2024-06-14 10:56:36 -0600
commit5ae8852d26a835715889b0ccad75d5d18572d302 (patch)
tree9142101be21d7aa0fc2fd35efaf8488ce93277ee
parentfd7b969b9ecb5b983bfd6560098306ee030c4649 (diff)
downloadgdb-5ae8852d26a835715889b0ccad75d5d18572d302.zip
gdb-5ae8852d26a835715889b0ccad75d5d18572d302.tar.gz
gdb-5ae8852d26a835715889b0ccad75d5d18572d302.tar.bz2
Examine template symbols in lookup_local_symbol
This changes lookup_local_symbol to directly examine any attached template symbols, rather than gating this lookup on the use of C++ or Fortran. As mentioned in an earlier patch, these objects are not necessarily C++-specific, and doing the search generically seems better. This also renames cp_lookup_symbol_imports_or_template now that the "template" part has been removed.
-rw-r--r--gdb/cp-namespace.c37
-rw-r--r--gdb/cp-support.h2
-rw-r--r--gdb/symtab.c16
3 files changed, 22 insertions, 33 deletions
diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c
index e5ef54d..89c1bbd 100644
--- a/gdb/cp-namespace.c
+++ b/gdb/cp-namespace.c
@@ -539,44 +539,23 @@ cp_lookup_symbol_via_imports (const char *scope,
return {};
}
-/* Search for symbols whose name match NAME in the given SCOPE.
- if BLOCK is a function, we'll search first through the template
- parameters and function type. Afterwards (or if BLOCK is not a function)
- search through imported directives using cp_lookup_symbol_via_imports. */
+/* Search for symbols whose name match NAME in the given SCOPE. */
struct block_symbol
-cp_lookup_symbol_imports_or_template (const char *scope,
- const char *name,
- const struct block *block,
- const domain_search_flags domain)
+cp_lookup_symbol_imports (const char *scope,
+ const char *name,
+ const struct block *block,
+ const domain_search_flags domain)
{
struct symbol *function = block->function ();
symbol_lookup_debug_printf
- ("cp_lookup_symbol_imports_or_template (%s, %s, %s, %s)",
+ ("cp_lookup_symbol_imports (%s, %s, %s, %s)",
scope, name, host_address_to_string (block),
domain_name (domain).c_str ());
if (function != NULL && function->language () == language_cplus)
{
- /* Search the function's template parameters. */
- if (function->is_template_function ())
- {
- struct template_symbol *templ
- = (struct template_symbol *) function;
- struct symbol *sym = search_symbol_list (name,
- templ->n_template_arguments,
- templ->template_arguments);
-
- if (sym != NULL)
- {
- symbol_lookup_debug_printf
- ("cp_lookup_symbol_imports_or_template (...) = %s",
- host_address_to_string (sym));
- return (struct block_symbol) {sym, block};
- }
- }
-
/* Search the template parameters of the function's defining
context. */
if (function->natural_name ())
@@ -612,7 +591,7 @@ cp_lookup_symbol_imports_or_template (const char *scope,
if (sym != NULL)
{
symbol_lookup_debug_printf
- ("cp_lookup_symbol_imports_or_template (...) = %s",
+ ("cp_lookup_symbol_imports (...) = %s",
host_address_to_string (sym));
return (struct block_symbol) {sym, parent};
}
@@ -622,7 +601,7 @@ cp_lookup_symbol_imports_or_template (const char *scope,
struct block_symbol result
= cp_lookup_symbol_via_imports (scope, name, block, domain, 1, 1);
- symbol_lookup_debug_printf ("cp_lookup_symbol_imports_or_template (...) = %s\n",
+ symbol_lookup_debug_printf ("cp_lookup_symbol_imports (...) = %s\n",
result.symbol != nullptr
? host_address_to_string (result.symbol) : "NULL");
return result;
diff --git a/gdb/cp-support.h b/gdb/cp-support.h
index 765c443..e266f31 100644
--- a/gdb/cp-support.h
+++ b/gdb/cp-support.h
@@ -146,7 +146,7 @@ extern struct block_symbol
const struct block *block,
const domain_search_flags domain);
-extern struct block_symbol cp_lookup_symbol_imports_or_template
+extern struct block_symbol cp_lookup_symbol_imports
(const char *scope,
const char *name,
const struct block *block,
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 9aa7064..bd0ace4 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -2236,17 +2236,27 @@ lookup_local_symbol (const char *name,
if (sym != NULL)
return (struct block_symbol) {sym, block};
+ struct symbol *function = block->function ();
+ if (function != nullptr && function->is_template_function ())
+ {
+ struct template_symbol *templ = (struct template_symbol *) function;
+ sym = search_symbol_list (name,
+ templ->n_template_arguments,
+ templ->template_arguments);
+ if (sym != nullptr)
+ return (struct block_symbol) {sym, block};
+ }
+
if (language == language_cplus || language == language_fortran)
{
struct block_symbol blocksym
- = cp_lookup_symbol_imports_or_template (scope, name, block,
- domain);
+ = cp_lookup_symbol_imports (scope, name, block, domain);
if (blocksym.symbol != NULL)
return blocksym;
}
- if (block->function () != NULL && block->inlined_p ())
+ if (function != nullptr && block->inlined_p ())
break;
block = block->superblock ();
}