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.
This commit is contained in:
Doug Evans 2014-12-23 07:55:39 -08:00
parent 9d7b48dc6e
commit 1994afbf19
15 changed files with 411 additions and 63 deletions

View file

@ -242,12 +242,18 @@ cp_basic_lookup_symbol (const char *name, const struct block *block,
}
/* Search bare symbol NAME in DOMAIN in BLOCK.
NAME is guaranteed to not have any scope (no "::").
NAME is guaranteed to not have any scope (no "::") in its name, though
if for example NAME is a template spec then "::" may appear in the
argument list.
If LANGDEF is non-NULL then try to lookup NAME as a primitive type in
that language. Normally we wouldn't need LANGDEF but fortran also uses
this code.
If SEARCH is non-zero then see if we can determine "this" from BLOCK, and
if so then also search for NAME in that class. */
static struct symbol *
cp_lookup_bare_symbol (const char *name, const struct block *block,
cp_lookup_bare_symbol (const struct language_defn *langdef,
const char *name, const struct block *block,
const domain_enum domain, int search)
{
struct symbol *sym;
@ -262,6 +268,25 @@ cp_lookup_bare_symbol (const char *name, const struct block *block,
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 (langdef != NULL && 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;
}
sym = lookup_global_symbol (name, block, domain);
if (sym != NULL)
return sym;
@ -378,7 +403,7 @@ cp_lookup_symbol_in_namespace (const char *namespace, const char *name,
prefix_len = cp_entire_prefix_len (name);
if (prefix_len == 0)
return cp_lookup_bare_symbol (name, block, domain, search);
return cp_lookup_bare_symbol (NULL, name, block, domain, search);
/* This would be simpler if we just called cp_lookup_nested_symbol
at this point. But that would require first looking up the containing
@ -753,7 +778,8 @@ cp_lookup_symbol_namespace (const char *scope,
"x". */
static struct symbol *
lookup_namespace_scope (const char *name,
lookup_namespace_scope (const struct language_defn *langdef,
const char *name,
const struct block *block,
const domain_enum domain,
const char *scope,
@ -775,14 +801,25 @@ lookup_namespace_scope (const char *name,
new_scope_len += 2;
}
new_scope_len += cp_find_first_component (scope + new_scope_len);
sym = lookup_namespace_scope (name, block, domain,
sym = lookup_namespace_scope (langdef, name, block, domain,
scope, new_scope_len);
if (sym != NULL)
return sym;
}
/* Okay, we didn't find a match in our children, so look for the
name in the current namespace. */
name in the current namespace.
If we there is no scope and we know we have a bare symbol, then short
circuit everything and call cp_lookup_bare_symbol directly.
This isn't an optimization, rather it allows us to pass LANGDEF which
is needed for primitive type lookup. The test doesn't have to be
perfect: if NAME is a bare symbol that our test doesn't catch (e.g., a
template symbol with "::" in the argument list) then
cp_lookup_symbol_in_namespace will catch it. */
if (scope_len == 0 && strchr (name, ':') == NULL)
return cp_lookup_bare_symbol (langdef, name, block, domain, 1);
namespace = alloca (scope_len + 1);
strncpy (namespace, scope, scope_len);
@ -817,7 +854,7 @@ cp_lookup_symbol_nonlocal (const struct language_defn *langdef,
/* First, try to find the symbol in the given namespace, and all
containing namespaces. */
sym = lookup_namespace_scope (name, block, domain, scope, 0);
sym = lookup_namespace_scope (langdef, name, block, domain, scope, 0);
/* Search for name in namespaces imported to this and parent blocks. */
if (sym == NULL)