aboutsummaryrefslogtreecommitdiff
path: root/gdb/symtab.c
diff options
context:
space:
mode:
authorJoel Brobecker <brobecker@gnat.com>2012-05-10 16:24:40 +0000
committerJoel Brobecker <brobecker@gnat.com>2012-05-10 16:24:40 +0000
commit99a547d6792f51503719e01937129b94597c5a67 (patch)
treeeaf163b5d17c124f62efb4a227734dd7b7854c83 /gdb/symtab.c
parent0ece64fd6fb4dcbb1cbe579fed01dcac2c19f888 (diff)
downloadgdb-99a547d6792f51503719e01937129b94597c5a67.zip
gdb-99a547d6792f51503719e01937129b94597c5a67.tar.gz
gdb-99a547d6792f51503719e01937129b94597c5a67.tar.bz2
Search global symbols from the expression's block objfile first.
gdb/ChangeLog: * findvar.c (default_read_var_value): For LOC_UNRESOLVED symbols, try locating the symbol in the symbol's own objfile first, before extending the search to all objfiles. * symtab.c (lookup_symbol_aux_objfile): New function, extracted out of lookup_symbol_aux_symtabs. (lookup_symbol_aux_symtabs): Add new parameter "exclude_objfile". Replace extracted-out code by call to lookup_symbol_aux_objfile. Do not search EXCLUDE_OBJFILE. (lookup_static_symbol_aux): Update call to lookup_symbol_aux_symtabs. (lookup_symbol_global): Search for matches in the block's objfile first, before searching all other objfiles.
Diffstat (limited to 'gdb/symtab.c')
-rw-r--r--gdb/symtab.c108
1 files changed, 76 insertions, 32 deletions
diff --git a/gdb/symtab.c b/gdb/symtab.c
index d68e542..3fce349 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -95,7 +95,8 @@ struct symbol *lookup_symbol_aux_local (const char *name,
static
struct symbol *lookup_symbol_aux_symtabs (int block_index,
const char *name,
- const domain_enum domain);
+ const domain_enum domain,
+ struct objfile *exclude_objfile);
static
struct symbol *lookup_symbol_aux_quick (struct objfile *objfile,
@@ -1361,7 +1362,7 @@ lookup_static_symbol_aux (const char *name, const domain_enum domain)
struct objfile *objfile;
struct symbol *sym;
- sym = lookup_symbol_aux_symtabs (STATIC_BLOCK, name, domain);
+ sym = lookup_symbol_aux_symtabs (STATIC_BLOCK, name, domain, NULL);
if (sym != NULL)
return sym;
@@ -1500,40 +1501,61 @@ lookup_global_symbol_from_objfile (const struct objfile *main_objfile,
return NULL;
}
-/* Check to see if the symbol is defined in one of the symtabs.
- BLOCK_INDEX should be either GLOBAL_BLOCK or STATIC_BLOCK,
+/* Check to see if the symbol is defined in one of the OBJFILE's
+ symtabs. BLOCK_INDEX should be either GLOBAL_BLOCK or STATIC_BLOCK,
depending on whether or not we want to search global symbols or
static symbols. */
static struct symbol *
-lookup_symbol_aux_symtabs (int block_index, const char *name,
- const domain_enum domain)
+lookup_symbol_aux_objfile (struct objfile *objfile, int block_index,
+ const char *name, const domain_enum domain)
{
- struct symbol *sym;
- struct objfile *objfile;
+ struct symbol *sym = NULL;
struct blockvector *bv;
const struct block *block;
struct symtab *s;
+ if (objfile->sf)
+ objfile->sf->qf->pre_expand_symtabs_matching (objfile, block_index,
+ name, domain);
+
+ ALL_OBJFILE_SYMTABS (objfile, s)
+ if (s->primary)
+ {
+ bv = BLOCKVECTOR (s);
+ block = BLOCKVECTOR_BLOCK (bv, block_index);
+ sym = lookup_block_symbol (block, name, domain);
+ if (sym)
+ {
+ block_found = block;
+ return fixup_symbol_section (sym, objfile);
+ }
+ }
+
+ return NULL;
+}
+
+/* Same as lookup_symbol_aux_objfile, except that it searches all
+ objfiles except for EXCLUDE_OBJFILE. Return the first match found.
+
+ If EXCLUDE_OBJFILE is NULL, then all objfiles are searched. */
+
+static struct symbol *
+lookup_symbol_aux_symtabs (int block_index, const char *name,
+ const domain_enum domain,
+ struct objfile *exclude_objfile)
+{
+ struct symbol *sym;
+ struct objfile *objfile;
+
ALL_OBJFILES (objfile)
{
- if (objfile->sf)
- objfile->sf->qf->pre_expand_symtabs_matching (objfile,
- block_index,
- name, domain);
-
- ALL_OBJFILE_SYMTABS (objfile, s)
- if (s->primary)
- {
- bv = BLOCKVECTOR (s);
- block = BLOCKVECTOR_BLOCK (bv, block_index);
- sym = lookup_block_symbol (block, name, domain);
- if (sym)
- {
- block_found = block;
- return fixup_symbol_section (sym, objfile);
- }
- }
+ if (objfile != exclude_objfile)
+ {
+ sym = lookup_symbol_aux_objfile (objfile, block_index, name, domain);
+ if (sym)
+ return sym;
+ }
}
return NULL;
@@ -1659,24 +1681,46 @@ lookup_symbol_global (const char *name,
const domain_enum domain)
{
struct symbol *sym = NULL;
+ struct objfile *block_objfile = NULL;
struct objfile *objfile = NULL;
/* Call library-specific lookup procedure. */
- objfile = lookup_objfile_from_block (block);
- if (objfile != NULL)
- sym = solib_global_lookup (objfile, name, domain);
+ block_objfile = lookup_objfile_from_block (block);
+ if (block_objfile != NULL)
+ sym = solib_global_lookup (block_objfile, name, domain);
if (sym != NULL)
return sym;
- sym = lookup_symbol_aux_symtabs (GLOBAL_BLOCK, name, domain);
+ /* If BLOCK_OBJFILE is not NULL, then search this objfile first.
+ In case the global symbol is defined in multiple objfiles,
+ we have a better chance of finding the most relevant symbol. */
+
+ if (block_objfile != NULL)
+ {
+ sym = lookup_symbol_aux_objfile (block_objfile, GLOBAL_BLOCK,
+ name, domain);
+ if (sym == NULL)
+ sym = lookup_symbol_aux_quick (block_objfile, GLOBAL_BLOCK,
+ name, domain);
+ if (sym != NULL)
+ return sym;
+ }
+
+ /* Symbol not found in the BLOCK_OBJFILE, so try all the other
+ objfiles, starting with symtabs first, and then partial symtabs. */
+
+ sym = lookup_symbol_aux_symtabs (GLOBAL_BLOCK, name, domain, block_objfile);
if (sym != NULL)
return sym;
ALL_OBJFILES (objfile)
{
- sym = lookup_symbol_aux_quick (objfile, GLOBAL_BLOCK, name, domain);
- if (sym)
- return sym;
+ if (objfile != block_objfile)
+ {
+ sym = lookup_symbol_aux_quick (objfile, GLOBAL_BLOCK, name, domain);
+ if (sym)
+ return sym;
+ }
}
return NULL;