gdb/ 2014-11-28 Jan Kratochvil * block.c (block_lookup_symbol_primary): New function. * block.h (block_lookup_symbol_primary): New declaration. * symtab.c (lookup_symbol_in_objfile_symtabs): Assert BLOCK_INDEX. Call block_lookup_symbol_primary. diff --git a/gdb/block.c b/gdb/block.c index 597d143..e791c73 100644 --- a/gdb/block.c +++ b/gdb/block.c @@ -746,3 +746,28 @@ block_lookup_symbol (const struct block *block, const char *name, return (sym_found); /* Will be NULL if not found. */ } } + +/* See block.h. */ + +struct symbol * +block_lookup_symbol_primary (const struct block *block, const char *name, + const domain_enum domain) +{ + struct symbol *sym; + struct dict_iterator dict_iter; + + /* Verify BLOCK is STATIC_BLOCK or GLOBAL_BLOCK. */ + gdb_assert (BLOCK_SUPERBLOCK (block) == NULL + || BLOCK_SUPERBLOCK (BLOCK_SUPERBLOCK (block)) == NULL); + + for (sym = dict_iter_name_first (block->dict, name, &dict_iter); + sym != NULL; + sym = dict_iter_name_next (name, &dict_iter)) + { + if (symbol_matches_domain (SYMBOL_LANGUAGE (sym), + SYMBOL_DOMAIN (sym), domain)) + return sym; + } + + return NULL; +} diff --git a/gdb/block.h b/gdb/block.h index bd358d6..409a5c7 100644 --- a/gdb/block.h +++ b/gdb/block.h @@ -276,6 +276,14 @@ extern struct symbol *block_lookup_symbol (const struct block *block, const char *name, const domain_enum domain); +/* Search BLOCK for symbol NAME in DOMAIN but only in primary symbol table of + BLOCK. BLOCK must be STATIC_BLOCK or GLOBAL_BLOCK. Function is useful if + one iterates all global/static blocks of an objfile. */ + +extern struct symbol *block_lookup_symbol_primary (const struct block *block, + const char *name, + const domain_enum domain); + /* Macro to loop through all symbols in BLOCK, in no particular order. ITER helps keep track of the iteration, and must be a struct block_iterator. SYM points to the current symbol. */ diff --git a/gdb/symtab.c b/gdb/symtab.c index 345c20d..fd93fb8 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -1618,6 +1618,8 @@ lookup_symbol_in_objfile_symtabs (struct objfile *objfile, int block_index, { struct compunit_symtab *cust; + gdb_assert (block_index == GLOBAL_BLOCK || block_index == STATIC_BLOCK); + ALL_OBJFILE_COMPUNITS (objfile, cust) { const struct blockvector *bv; @@ -1626,7 +1628,7 @@ lookup_symbol_in_objfile_symtabs (struct objfile *objfile, int block_index, bv = COMPUNIT_BLOCKVECTOR (cust); block = BLOCKVECTOR_BLOCK (bv, block_index); - sym = block_lookup_symbol (block, name, domain); + sym = block_lookup_symbol_primary (block, name, domain); if (sym) { block_found = block;