aboutsummaryrefslogtreecommitdiff
path: root/gdb/symtab.c
diff options
context:
space:
mode:
authorDoug Evans <xdje42@gmail.com>2014-12-23 07:55:39 -0800
committerDoug Evans <xdje42@gmail.com>2014-12-23 07:58:14 -0800
commit1994afbf19892c9e614a034fbf1a5233e9addce3 (patch)
treeaf1c6640f99921a6f636e860dc10914dc53cedea /gdb/symtab.c
parent9d7b48dc6e8415e95f5228a6f66b414827eb0204 (diff)
downloadgdb-1994afbf19892c9e614a034fbf1a5233e9addce3.zip
gdb-1994afbf19892c9e614a034fbf1a5233e9addce3.tar.gz
gdb-1994afbf19892c9e614a034fbf1a5233e9addce3.tar.bz2
Look up primitive types as symbols.
gdb/ChangeLog: * ada-lang.c (user_select_syms): Only fetch symtab if symbol is objfile-owned. (cache_symbol): Ignore symbols that are not objfile-owned. * block.c (block_objfile): New function. (block_gdbarch): New function. * block.h (block_objfile): Declare. (block_gdbarch): Declare. * c-exp.y (classify_name): Remove call to language_lookup_primitive_type. No longer necessary. * gdbtypes.c (lookup_typename): Call lookup_symbol_in_language. Remove call to language_lookup_primitive_type. No longer necessary. * guile/scm-symbol.c (syscm_gdbarch_data_key): New static global. (syscm_gdbarch_data): New struct. (syscm_init_arch_symbols): New function. (syscm_get_symbol_map): Renamed from syscm_objfile_symbol_map. All callers updated. Handle symbols owned by arches. (gdbscm_symbol_symtab): Handle symbols owned by arches. (gdbscm_initialize_symbols): Initialize syscm_gdbarch_data_key. * language.c (language_lookup_primitive_type_1): New function. (language_lookup_primitive_type): Call it. (language_alloc_type_symbol): New function. (language_init_primitive_type_symbols): New function. (language_lookup_primitive_type_as_symbol): New function. * language.h (struct language_arch_info) <primitive_type_symbols>: New member. (language_lookup_primitive_type): Add function comment. (language_lookup_primitive_type_as_symbol): Declare. * printcmd.c (address_info): Handle arch-owned symbols. * python/py-symbol.c (sympy_get_symtab): Ditto. (set_symbol): Ditto. (sympy_dealloc): Ditto. * symmisc.c (print_symbol): Ditto. * symtab.c (fixup_symbol_section): Ditto. (lookup_symbol_aux): Initialize block_found. (basic_lookup_symbol_nonlocal): Try looking up the symbol as a primitive type. (initialize_objfile_symbol_1): New function. (initialize_objfile_symbol): Call it. (allocate_symbol): Call it. (allocate_template_symbol): Call it. (symbol_objfile): Assert symbol is objfile-owned. (symbol_arch, symbol_symtab, symbol_set_symtab): Ditto. * symtab.h (struct symbol) <owner>: Replaces member "symtab". (struct symbol) <is_objfile_owned>: New member. (SYMBOL_OBJFILE_OWNED): New macro. * cp-namespace.c (cp_lookup_bare_symbol): New arg langdef. All callers updated. Try to find the symbol as a primitive type. (lookup_namespace_scope): New arg langdef. All callers updated. Call cp_lookup_bare_symbol directly for simple bare symbols.
Diffstat (limited to 'gdb/symtab.c')
-rw-r--r--gdb/symtab.c60
1 files changed, 52 insertions, 8 deletions
diff --git a/gdb/symtab.c b/gdb/symtab.c
index e7cd5af..0efd9d2 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -1150,6 +1150,9 @@ fixup_symbol_section (struct symbol *sym, struct objfile *objfile)
if (!sym)
return NULL;
+ if (!SYMBOL_OBJFILE_OWNED (sym))
+ return sym;
+
/* We either have an OBJFILE, or we can get at it from the sym's
symtab. Anything else is a bug. */
gdb_assert (objfile || symbol_symtab (sym));
@@ -1421,6 +1424,13 @@ lookup_symbol_aux (const char *name, const struct block *block,
domain_name (domain), language_str (language));
}
+ /* Initialize block_found so that the language la_lookup_symbol_nonlocal
+ routines don't have to set it (to NULL) if a primitive type is found.
+ We do this early so that block_found is also NULL if no symbol is
+ found (though this is not part of the API, and callers cannot assume
+ this). */
+ block_found = NULL;
+
/* Make sure we do something sensible with is_a_field_of_this, since
the callers that set this parameter to some non-null value will
certainly use it later. If we don't set it, the contents of
@@ -1848,6 +1858,25 @@ basic_lookup_symbol_nonlocal (const struct language_defn *langdef,
if (sym != NULL)
return sym;
+ /* If we didn't find a definition for a builtin type in the static block,
+ search for it now. This is actually the right thing to do and can be
+ a massive performance win. E.g., when debugging a program with lots of
+ shared libraries we could search all of them only to find out the
+ builtin type isn't defined in any of them. This is common for types
+ like "void". */
+ if (domain == VAR_DOMAIN)
+ {
+ struct gdbarch *gdbarch;
+
+ if (block == NULL)
+ gdbarch = target_gdbarch ();
+ else
+ gdbarch = block_gdbarch (block);
+ sym = language_lookup_primitive_type_as_symbol (langdef, gdbarch, name);
+ if (sym != NULL)
+ return sym;
+ }
+
return lookup_global_symbol (name, block, domain);
}
@@ -5313,13 +5342,23 @@ initialize_ordinary_address_classes (void)
-/* Initialize the symbol SYM. */
+/* Helper function to initialize the fields of an objfile-owned symbol.
+ It assumed that *SYM is already all zeroes. */
+
+static void
+initialize_objfile_symbol_1 (struct symbol *sym)
+{
+ SYMBOL_OBJFILE_OWNED (sym) = 1;
+ SYMBOL_SECTION (sym) = -1;
+}
+
+/* Initialize the symbol SYM, and mark it as being owned by an objfile. */
void
initialize_objfile_symbol (struct symbol *sym)
{
memset (sym, 0, sizeof (*sym));
- SYMBOL_SECTION (sym) = -1;
+ initialize_objfile_symbol_1 (sym);
}
/* Allocate and initialize a new 'struct symbol' on OBJFILE's
@@ -5331,7 +5370,7 @@ allocate_symbol (struct objfile *objfile)
struct symbol *result;
result = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol);
- SYMBOL_SECTION (result) = -1;
+ initialize_objfile_symbol_1 (result);
return result;
}
@@ -5345,7 +5384,7 @@ allocate_template_symbol (struct objfile *objfile)
struct template_symbol *result;
result = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct template_symbol);
- SYMBOL_SECTION (&result->base) = -1;
+ initialize_objfile_symbol_1 (&result->base);
return result;
}
@@ -5355,7 +5394,8 @@ allocate_template_symbol (struct objfile *objfile)
struct objfile *
symbol_objfile (const struct symbol *symbol)
{
- return SYMTAB_OBJFILE (symbol->symtab);
+ gdb_assert (SYMBOL_OBJFILE_OWNED (symbol));
+ return SYMTAB_OBJFILE (symbol->owner.symtab);
}
/* See symtab.h. */
@@ -5363,7 +5403,9 @@ symbol_objfile (const struct symbol *symbol)
struct gdbarch *
symbol_arch (const struct symbol *symbol)
{
- return get_objfile_arch (symbol_objfile (symbol));
+ if (!SYMBOL_OBJFILE_OWNED (symbol))
+ return symbol->owner.arch;
+ return get_objfile_arch (SYMTAB_OBJFILE (symbol->owner.symtab));
}
/* See symtab.h. */
@@ -5371,7 +5413,8 @@ symbol_arch (const struct symbol *symbol)
struct symtab *
symbol_symtab (const struct symbol *symbol)
{
- return symbol->symtab;
+ gdb_assert (SYMBOL_OBJFILE_OWNED (symbol));
+ return symbol->owner.symtab;
}
/* See symtab.h. */
@@ -5379,7 +5422,8 @@ symbol_symtab (const struct symbol *symbol)
void
symbol_set_symtab (struct symbol *symbol, struct symtab *symtab)
{
- symbol->symtab = symtab;
+ gdb_assert (SYMBOL_OBJFILE_OWNED (symbol));
+ symbol->owner.symtab = symtab;
}