Remove ALL_COMPUNITS

This removes the ALL_COMPUNITS, replacing its uses with two nested
ranged for loops.

gdb/ChangeLog
2019-01-09  Tom Tromey  <tom@tromey.com>

	* symtab.c (lookup_objfile_from_block)
	(find_pc_sect_compunit_symtab, search_symbols)
	(default_collect_symbol_completion_matches_break_on): Use
	objfile_compunits.
	* objfiles.h (ALL_COMPUNITS): Remove.
	* maint.c (count_symtabs_and_blocks): Use objfile_compunits.
	* cp-support.c (add_symbol_overload_list_qualified): Use
	objfile_compunits.
	* ada-lang.c (ada_collect_symbol_completion_matches)
	(ada_add_global_exceptions): Use objfile_compunits.
This commit is contained in:
Tom Tromey 2018-11-24 09:20:18 -07:00
parent 592553c469
commit d8aeb77f04
6 changed files with 216 additions and 189 deletions

View file

@ -1,3 +1,16 @@
2019-01-09 Tom Tromey <tom@tromey.com>
* symtab.c (lookup_objfile_from_block)
(find_pc_sect_compunit_symtab, search_symbols)
(default_collect_symbol_completion_matches_break_on): Use
objfile_compunits.
* objfiles.h (ALL_COMPUNITS): Remove.
* maint.c (count_symtabs_and_blocks): Use objfile_compunits.
* cp-support.c (add_symbol_overload_list_qualified): Use
objfile_compunits.
* ada-lang.c (ada_collect_symbol_completion_matches)
(ada_add_global_exceptions): Use objfile_compunits.
2019-01-09 Tom Tromey <tom@tromey.com> 2019-01-09 Tom Tromey <tom@tromey.com>
* source.c (select_source_symtab) * source.c (select_source_symtab)

View file

@ -6465,41 +6465,46 @@ ada_collect_symbol_completion_matches (completion_tracker &tracker,
/* Go through the symtabs and check the externs and statics for /* Go through the symtabs and check the externs and statics for
symbols which match. */ symbols which match. */
struct objfile *objfile; for (objfile *objfile : all_objfiles (current_program_space))
ALL_COMPUNITS (objfile, s)
{
QUIT;
b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (s), GLOBAL_BLOCK);
ALL_BLOCK_SYMBOLS (b, iter, sym)
{ {
if (completion_skip_symbol (mode, sym)) for (compunit_symtab *s : objfile_compunits (objfile))
continue; {
QUIT;
b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (s), GLOBAL_BLOCK);
ALL_BLOCK_SYMBOLS (b, iter, sym)
{
if (completion_skip_symbol (mode, sym))
continue;
completion_list_add_name (tracker, completion_list_add_name (tracker,
SYMBOL_LANGUAGE (sym), SYMBOL_LANGUAGE (sym),
SYMBOL_LINKAGE_NAME (sym), SYMBOL_LINKAGE_NAME (sym),
lookup_name, text, word); lookup_name, text, word);
}
}
} }
}
ALL_COMPUNITS (objfile, s) for (objfile *objfile : all_objfiles (current_program_space))
{
QUIT;
b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (s), STATIC_BLOCK);
/* Don't do this block twice. */
if (b == surrounding_static_block)
continue;
ALL_BLOCK_SYMBOLS (b, iter, sym)
{ {
if (completion_skip_symbol (mode, sym)) for (compunit_symtab *s : objfile_compunits (objfile))
continue; {
QUIT;
b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (s), STATIC_BLOCK);
/* Don't do this block twice. */
if (b == surrounding_static_block)
continue;
ALL_BLOCK_SYMBOLS (b, iter, sym)
{
if (completion_skip_symbol (mode, sym))
continue;
completion_list_add_name (tracker, completion_list_add_name (tracker,
SYMBOL_LANGUAGE (sym), SYMBOL_LANGUAGE (sym),
SYMBOL_LINKAGE_NAME (sym), SYMBOL_LINKAGE_NAME (sym),
lookup_name, text, word); lookup_name, text, word);
}
}
} }
}
} }
/* Field Access */ /* Field Access */
@ -13548,8 +13553,6 @@ static void
ada_add_global_exceptions (compiled_regex *preg, ada_add_global_exceptions (compiled_regex *preg,
std::vector<ada_exc_info> *exceptions) std::vector<ada_exc_info> *exceptions)
{ {
struct objfile *objfile;
/* In Ada, the symbol "search name" is a linkage name, whereas the /* In Ada, the symbol "search name" is a linkage name, whereas the
regular expression used to do the matching refers to the natural regular expression used to do the matching refers to the natural
name. So match against the decoded name. */ name. So match against the decoded name. */
@ -13563,26 +13566,29 @@ ada_add_global_exceptions (compiled_regex *preg,
NULL, NULL,
VARIABLES_DOMAIN); VARIABLES_DOMAIN);
ALL_COMPUNITS (objfile, s) for (objfile *objfile : all_objfiles (current_program_space))
{ {
const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (s); for (compunit_symtab *s : objfile_compunits (objfile))
int i;
for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
{ {
struct block *b = BLOCKVECTOR_BLOCK (bv, i); const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (s);
struct block_iterator iter; int i;
struct symbol *sym;
ALL_BLOCK_SYMBOLS (b, iter, sym) for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
if (ada_is_non_standard_exception_sym (sym) {
&& name_matches_regex (SYMBOL_NATURAL_NAME (sym), preg)) struct block *b = BLOCKVECTOR_BLOCK (bv, i);
{ struct block_iterator iter;
struct ada_exc_info info struct symbol *sym;
= {SYMBOL_PRINT_NAME (sym), SYMBOL_VALUE_ADDRESS (sym)};
exceptions->push_back (info); ALL_BLOCK_SYMBOLS (b, iter, sym)
} if (ada_is_non_standard_exception_sym (sym)
&& name_matches_regex (SYMBOL_NATURAL_NAME (sym), preg))
{
struct ada_exc_info info
= {SYMBOL_PRINT_NAME (sym), SYMBOL_VALUE_ADDRESS (sym)};
exceptions->push_back (info);
}
}
} }
} }
} }

View file

@ -1395,23 +1395,28 @@ add_symbol_overload_list_qualified (const char *func_name,
/* Go through the symtabs and check the externs and statics for /* Go through the symtabs and check the externs and statics for
symbols which match. */ symbols which match. */
struct objfile *objfile; for (objfile *objfile : all_objfiles (current_program_space))
ALL_COMPUNITS (objfile, cust) {
{ for (compunit_symtab *cust : objfile_compunits (objfile))
QUIT; {
b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), GLOBAL_BLOCK); QUIT;
add_symbol_overload_list_block (func_name, b, overload_list); b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), GLOBAL_BLOCK);
} add_symbol_overload_list_block (func_name, b, overload_list);
}
}
ALL_COMPUNITS (objfile, cust) for (objfile *objfile : all_objfiles (current_program_space))
{ {
QUIT; for (compunit_symtab *cust : objfile_compunits (objfile))
b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), STATIC_BLOCK); {
/* Don't do this block twice. */ QUIT;
if (b == surrounding_static_block) b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), STATIC_BLOCK);
continue; /* Don't do this block twice. */
add_symbol_overload_list_block (func_name, b, overload_list); if (b == surrounding_static_block)
} continue;
add_symbol_overload_list_block (func_name, b, overload_list);
}
}
} }
/* Lookup the rtti type for a class name. */ /* Lookup the rtti type for a class name. */

View file

@ -762,7 +762,6 @@ static void
count_symtabs_and_blocks (int *nr_symtabs_ptr, int *nr_compunit_symtabs_ptr, count_symtabs_and_blocks (int *nr_symtabs_ptr, int *nr_compunit_symtabs_ptr,
int *nr_blocks_ptr) int *nr_blocks_ptr)
{ {
struct objfile *o;
struct symtab *s; struct symtab *s;
int nr_symtabs = 0; int nr_symtabs = 0;
int nr_compunit_symtabs = 0; int nr_compunit_symtabs = 0;
@ -773,12 +772,15 @@ count_symtabs_and_blocks (int *nr_symtabs_ptr, int *nr_compunit_symtabs_ptr,
current_program_space may be NULL. */ current_program_space may be NULL. */
if (current_program_space != NULL) if (current_program_space != NULL)
{ {
ALL_COMPUNITS (o, cu) for (objfile *o : all_objfiles (current_program_space))
{ {
++nr_compunit_symtabs; for (compunit_symtab *cu : objfile_compunits (o))
nr_blocks += BLOCKVECTOR_NBLOCKS (COMPUNIT_BLOCKVECTOR (cu)); {
ALL_COMPUNIT_FILETABS (cu, s) ++nr_compunit_symtabs;
++nr_symtabs; nr_blocks += BLOCKVECTOR_NBLOCKS (COMPUNIT_BLOCKVECTOR (cu));
ALL_COMPUNIT_FILETABS (cu, s)
++nr_symtabs;
}
} }
} }

View file

@ -718,12 +718,6 @@ private:
ALL_OBJFILES (objfile) \ ALL_OBJFILES (objfile) \
ALL_OBJFILE_FILETABS (objfile, ps, s) ALL_OBJFILE_FILETABS (objfile, ps, s)
/* Traverse all compunits in all objfiles in the current program space. */
#define ALL_COMPUNITS(objfile, cu) \
ALL_OBJFILES (objfile) \
for (compunit_symtab *cu : objfile_compunits (objfile))
#define ALL_OBJFILE_OSECTIONS(objfile, osect) \ #define ALL_OBJFILE_OSECTIONS(objfile, osect) \
for (osect = objfile->sections; osect < objfile->sections_end; osect++) \ for (osect = objfile->sections; osect < objfile->sections_end; osect++) \
if (osect->the_bfd_section == NULL) \ if (osect->the_bfd_section == NULL) \

View file

@ -2166,22 +2166,23 @@ lookup_local_symbol (const char *name,
struct objfile * struct objfile *
lookup_objfile_from_block (const struct block *block) lookup_objfile_from_block (const struct block *block)
{ {
struct objfile *obj;
if (block == NULL) if (block == NULL)
return NULL; return NULL;
block = block_global_block (block); block = block_global_block (block);
/* Look through all blockvectors. */ /* Look through all blockvectors. */
ALL_COMPUNITS (obj, cust) for (objfile *obj : all_objfiles (current_program_space))
if (block == BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), {
GLOBAL_BLOCK)) for (compunit_symtab *cust : objfile_compunits (obj))
{ if (block == BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust),
if (obj->separate_debug_objfile_backlink) GLOBAL_BLOCK))
obj = obj->separate_debug_objfile_backlink; {
if (obj->separate_debug_objfile_backlink)
obj = obj->separate_debug_objfile_backlink;
return obj; return obj;
} }
}
return NULL; return NULL;
} }
@ -2871,7 +2872,6 @@ struct compunit_symtab *
find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section) find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section)
{ {
struct compunit_symtab *best_cust = NULL; struct compunit_symtab *best_cust = NULL;
struct objfile *obj_file;
CORE_ADDR distance = 0; CORE_ADDR distance = 0;
struct bound_minimal_symbol msymbol; struct bound_minimal_symbol msymbol;
@ -2904,57 +2904,62 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section)
It also happens for objfiles that have their functions reordered. It also happens for objfiles that have their functions reordered.
For these, the symtab we are looking for is not necessarily read in. */ For these, the symtab we are looking for is not necessarily read in. */
ALL_COMPUNITS (obj_file, cust) for (objfile *obj_file : all_objfiles (current_program_space))
{ {
struct block *b; for (compunit_symtab *cust : objfile_compunits (obj_file))
const struct blockvector *bv; {
struct block *b;
const struct blockvector *bv;
bv = COMPUNIT_BLOCKVECTOR (cust); bv = COMPUNIT_BLOCKVECTOR (cust);
b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
if (BLOCK_START (b) <= pc if (BLOCK_START (b) <= pc
&& BLOCK_END (b) > pc && BLOCK_END (b) > pc
&& (distance == 0 && (distance == 0
|| BLOCK_END (b) - BLOCK_START (b) < distance)) || BLOCK_END (b) - BLOCK_START (b) < distance))
{ {
/* For an objfile that has its functions reordered, /* For an objfile that has its functions reordered,
find_pc_psymtab will find the proper partial symbol table find_pc_psymtab will find the proper partial symbol table
and we simply return its corresponding symtab. */ and we simply return its corresponding symtab. */
/* In order to better support objfiles that contain both /* In order to better support objfiles that contain both
stabs and coff debugging info, we continue on if a psymtab stabs and coff debugging info, we continue on if a psymtab
can't be found. */ can't be found. */
if ((obj_file->flags & OBJF_REORDERED) && obj_file->sf) if ((obj_file->flags & OBJF_REORDERED) && obj_file->sf)
{ {
struct compunit_symtab *result; struct compunit_symtab *result;
result result
= obj_file->sf->qf->find_pc_sect_compunit_symtab (obj_file, = obj_file->sf->qf->find_pc_sect_compunit_symtab (obj_file,
msymbol, msymbol,
pc, section, pc,
0); section,
if (result != NULL) 0);
return result; if (result != NULL)
} return result;
if (section != 0) }
{ if (section != 0)
struct block_iterator iter; {
struct symbol *sym = NULL; struct block_iterator iter;
struct symbol *sym = NULL;
ALL_BLOCK_SYMBOLS (b, iter, sym) ALL_BLOCK_SYMBOLS (b, iter, sym)
{ {
fixup_symbol_section (sym, obj_file); fixup_symbol_section (sym, obj_file);
if (matching_obj_sections (SYMBOL_OBJ_SECTION (obj_file, sym), if (matching_obj_sections (SYMBOL_OBJ_SECTION (obj_file,
section)) sym),
break; section))
} break;
if (sym == NULL) }
continue; /* No symbol in this symtab matches if (sym == NULL)
section. */ continue; /* No symbol in this symtab matches
} section. */
distance = BLOCK_END (b) - BLOCK_START (b); }
best_cust = cust; distance = BLOCK_END (b) - BLOCK_START (b);
} best_cust = cust;
} }
}
}
if (best_cust != NULL) if (best_cust != NULL)
return best_cust; return best_cust;
@ -4465,7 +4470,7 @@ search_symbols (const char *regexp, enum search_domain kind,
/* Note: An important side-effect of these /* Note: An important side-effect of these
lookup functions is to expand the symbol lookup functions is to expand the symbol
table if msymbol is found, for the benefit of table if msymbol is found, for the benefit of
the next loop on ALL_COMPUNITS. */ the next loop on compunits. */
if (kind == FUNCTIONS_DOMAIN if (kind == FUNCTIONS_DOMAIN
? (find_pc_compunit_symtab ? (find_pc_compunit_symtab
(MSYMBOL_VALUE_ADDRESS (objfile, msymbol)) (MSYMBOL_VALUE_ADDRESS (objfile, msymbol))
@ -4481,60 +4486,60 @@ search_symbols (const char *regexp, enum search_domain kind,
} }
} }
{ for (objfile *objfile : all_objfiles (current_program_space))
struct objfile *objfile; {
ALL_COMPUNITS (objfile, cust) for (compunit_symtab *cust : objfile_compunits (objfile))
{ {
bv = COMPUNIT_BLOCKVECTOR (cust); bv = COMPUNIT_BLOCKVECTOR (cust);
for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++) for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
{ {
b = BLOCKVECTOR_BLOCK (bv, i); b = BLOCKVECTOR_BLOCK (bv, i);
ALL_BLOCK_SYMBOLS (b, iter, sym) ALL_BLOCK_SYMBOLS (b, iter, sym)
{ {
struct symtab *real_symtab = symbol_symtab (sym); struct symtab *real_symtab = symbol_symtab (sym);
QUIT; QUIT;
/* Check first sole REAL_SYMTAB->FILENAME. It does /* Check first sole REAL_SYMTAB->FILENAME. It does
not need to be a substring of symtab_to_fullname as not need to be a substring of symtab_to_fullname as
it may contain "./" etc. */ it may contain "./" etc. */
if ((file_matches (real_symtab->filename, files, nfiles, 0) if ((file_matches (real_symtab->filename, files, nfiles, 0)
|| ((basenames_may_differ || ((basenames_may_differ
|| file_matches (lbasename (real_symtab->filename), || file_matches (lbasename (real_symtab->filename),
files, nfiles, 1)) files, nfiles, 1))
&& file_matches (symtab_to_fullname (real_symtab), && file_matches (symtab_to_fullname (real_symtab),
files, nfiles, 0))) files, nfiles, 0)))
&& ((!preg.has_value () && ((!preg.has_value ()
|| preg->exec (SYMBOL_NATURAL_NAME (sym), 0, || preg->exec (SYMBOL_NATURAL_NAME (sym), 0,
NULL, 0) == 0) NULL, 0) == 0)
&& ((kind == VARIABLES_DOMAIN && ((kind == VARIABLES_DOMAIN
&& SYMBOL_CLASS (sym) != LOC_TYPEDEF && SYMBOL_CLASS (sym) != LOC_TYPEDEF
&& SYMBOL_CLASS (sym) != LOC_UNRESOLVED && SYMBOL_CLASS (sym) != LOC_UNRESOLVED
&& SYMBOL_CLASS (sym) != LOC_BLOCK && SYMBOL_CLASS (sym) != LOC_BLOCK
/* LOC_CONST can be used for more than /* LOC_CONST can be used for more than
just enums, e.g., c++ static const just enums, e.g., c++ static const
members. We only want to skip enums members. We only want to skip enums
here. */ here. */
&& !(SYMBOL_CLASS (sym) == LOC_CONST && !(SYMBOL_CLASS (sym) == LOC_CONST
&& (TYPE_CODE (SYMBOL_TYPE (sym)) && (TYPE_CODE (SYMBOL_TYPE (sym))
== TYPE_CODE_ENUM)) == TYPE_CODE_ENUM))
&& (!treg.has_value () && (!treg.has_value ()
|| treg_matches_sym_type_name (*treg, sym))) || treg_matches_sym_type_name (*treg, sym)))
|| (kind == FUNCTIONS_DOMAIN || (kind == FUNCTIONS_DOMAIN
&& SYMBOL_CLASS (sym) == LOC_BLOCK && SYMBOL_CLASS (sym) == LOC_BLOCK
&& (!treg.has_value () && (!treg.has_value ()
|| treg_matches_sym_type_name (*treg, || treg_matches_sym_type_name (*treg,
sym))) sym)))
|| (kind == TYPES_DOMAIN || (kind == TYPES_DOMAIN
&& SYMBOL_CLASS (sym) == LOC_TYPEDEF)))) && SYMBOL_CLASS (sym) == LOC_TYPEDEF))))
{ {
/* match */ /* match */
result.emplace_back (i, sym); result.emplace_back (i, sym);
} }
} }
} }
} }
} }
if (!result.empty ()) if (!result.empty ())
sort_search_symbols_remove_dups (&result); sort_search_symbols_remove_dups (&result);
@ -5282,10 +5287,12 @@ default_collect_symbol_completion_matches_break_on
} }
/* Add completions for all currently loaded symbol tables. */ /* Add completions for all currently loaded symbol tables. */
struct objfile *objfile; for (objfile *objfile : all_objfiles (current_program_space))
ALL_COMPUNITS (objfile, cust) {
add_symtab_completions (cust, tracker, mode, lookup_name, for (compunit_symtab *cust : objfile_compunits (objfile))
sym_text, word, code); add_symtab_completions (cust, tracker, mode, lookup_name,
sym_text, word, code);
}
/* Look through the partial symtabs for all symbols which begin by /* Look through the partial symtabs for all symbols which begin by
matching SYM_TEXT. Expand all CUs that you find to the list. */ matching SYM_TEXT. Expand all CUs that you find to the list. */