Remove ALL_MSYMBOLS and ALL_OBJFILE_MSYMBOLS

This removes the ALL_MSYMBOLS and ALL_OBJFILE_MSYMBOLS macros,
replacing their uses with ranged for loops.

In a couple of spots, a new declaration was needed in order to work
around shadowing; these are just temporary and are removed in a
subsequent patch.

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

	* symtab.c (search_symbols)
	(default_collect_symbol_completion_matches_break_on): Use
	objfile_msymbols.
	* ada-lang.c (ada_lookup_simple_minsym)
	(ada_collect_symbol_completion_matches): Use objfile_msymbols.
	* minsyms.c (find_solib_trampoline_target): Use objfile_msymbols.
	* hppa-tdep.c (hppa_lookup_stub_minimal_symbol): Use
	objfile_msymbols.
	* coffread.c (coff_symfile_read): Use objfile_msymbols.
	* symmisc.c (dump_msymbols): Use objfile_msymbols.
	* objc-lang.c (find_methods): Use objfile_msymbols.
	(info_selectors_command, info_classes_command): Likewise.
	* stabsread.c (scan_file_globals): Use objfile_msymbols.
	* objfiles.h (class objfile_msymbols): New.
	(ALL_OBJFILE_MSYMBOLS): Remove.
	(ALL_MSYMBOLS): Remove.
This commit is contained in:
Tom Tromey
2018-11-23 17:32:08 -07:00
parent cac85af246
commit 5325b9bf1e
10 changed files with 375 additions and 264 deletions

View File

@ -1,3 +1,22 @@
2019-01-09 Tom Tromey <tom@tromey.com>
* symtab.c (search_symbols)
(default_collect_symbol_completion_matches_break_on): Use
objfile_msymbols.
* ada-lang.c (ada_lookup_simple_minsym)
(ada_collect_symbol_completion_matches): Use objfile_msymbols.
* minsyms.c (find_solib_trampoline_target): Use objfile_msymbols.
* hppa-tdep.c (hppa_lookup_stub_minimal_symbol): Use
objfile_msymbols.
* coffread.c (coff_symfile_read): Use objfile_msymbols.
* symmisc.c (dump_msymbols): Use objfile_msymbols.
* objc-lang.c (find_methods): Use objfile_msymbols.
(info_selectors_command, info_classes_command): Likewise.
* stabsread.c (scan_file_globals): Use objfile_msymbols.
* objfiles.h (class objfile_msymbols): New.
(ALL_OBJFILE_MSYMBOLS): Remove.
(ALL_MSYMBOLS): Remove.
2019-01-09 Tom Tromey <tom@tromey.com>
* common/next-iterator.h (next_adapter): Add Iterator template

View File

@ -4913,8 +4913,6 @@ struct bound_minimal_symbol
ada_lookup_simple_minsym (const char *name)
{
struct bound_minimal_symbol result;
struct objfile *objfile;
struct minimal_symbol *msymbol;
memset (&result, 0, sizeof (result));
@ -4924,7 +4922,9 @@ ada_lookup_simple_minsym (const char *name)
symbol_name_matcher_ftype *match_name
= ada_get_symbol_name_matcher (lookup_name);
ALL_MSYMBOLS (objfile, msymbol)
for (objfile *objfile : all_objfiles (current_program_space))
{
for (minimal_symbol *msymbol : objfile_msymbols (objfile))
{
if (match_name (MSYMBOL_LINKAGE_NAME (msymbol), lookup_name, NULL)
&& MSYMBOL_TYPE (msymbol) != mst_solib_trampoline)
@ -4934,6 +4934,7 @@ ada_lookup_simple_minsym (const char *name)
break;
}
}
}
return result;
}
@ -6391,8 +6392,6 @@ ada_collect_symbol_completion_matches (completion_tracker &tracker,
{
struct symbol *sym;
struct compunit_symtab *s;
struct minimal_symbol *msymbol;
struct objfile *objfile;
const struct block *b, *surrounding_static_block = 0;
struct block_iterator iter;
@ -6412,7 +6411,9 @@ ada_collect_symbol_completion_matches (completion_tracker &tracker,
anything that isn't a text symbol (everything else will be
handled by the psymtab code above). */
ALL_MSYMBOLS (objfile, msymbol)
for (objfile *objfile : all_objfiles (current_program_space))
{
for (minimal_symbol *msymbol : objfile_msymbols (objfile))
{
QUIT;
@ -6441,6 +6442,7 @@ ada_collect_symbol_completion_matches (completion_tracker &tracker,
MSYMBOL_LINKAGE_NAME (msymbol),
lookup_name, text, word);
}
}
/* Search upwards from currently selected frame (so that we can
complete on local vars. */
@ -6465,6 +6467,7 @@ ada_collect_symbol_completion_matches (completion_tracker &tracker,
/* Go through the symtabs and check the externs and statics for
symbols which match. */
struct objfile *objfile;
ALL_COMPUNITS (objfile, s)
{
QUIT;

View File

@ -661,9 +661,7 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
if (pe_file)
{
struct minimal_symbol *msym;
ALL_OBJFILE_MSYMBOLS (objfile, msym)
for (minimal_symbol *msym : objfile_msymbols (objfile))
{
const char *name = MSYMBOL_LINKAGE_NAME (msym);

View File

@ -2540,11 +2540,11 @@ struct bound_minimal_symbol
hppa_lookup_stub_minimal_symbol (const char *name,
enum unwind_stub_types stub_type)
{
struct objfile *objfile;
struct minimal_symbol *msym;
struct bound_minimal_symbol result = { NULL, NULL };
ALL_MSYMBOLS (objfile, msym)
for (objfile *objfile : all_objfiles (current_program_space))
{
for (minimal_symbol *msym : objfile_msymbols (objfile))
{
if (strcmp (MSYMBOL_LINKAGE_NAME (msym), name) == 0)
{
@ -2559,6 +2559,7 @@ hppa_lookup_stub_minimal_symbol (const char *name,
}
}
}
}
return result;
}

View File

@ -1488,15 +1488,16 @@ lookup_solib_trampoline_symbol_by_pc (CORE_ADDR pc)
CORE_ADDR
find_solib_trampoline_target (struct frame_info *frame, CORE_ADDR pc)
{
struct objfile *objfile;
struct minimal_symbol *msymbol;
struct minimal_symbol *tsymbol = lookup_solib_trampoline_symbol_by_pc (pc);
if (tsymbol != NULL)
{
ALL_MSYMBOLS (objfile, msymbol)
for (objfile *objfile : all_objfiles (current_program_space))
{
/* Also handle minimal symbols pointing to function descriptors. */
for (minimal_symbol *msymbol : objfile_msymbols (objfile))
{
/* Also handle minimal symbols pointing to function
descriptors. */
if ((MSYMBOL_TYPE (msymbol) == mst_text
|| MSYMBOL_TYPE (msymbol) == mst_text_gnu_ifunc
|| MSYMBOL_TYPE (msymbol) == mst_data
@ -1513,6 +1514,7 @@ find_solib_trampoline_target (struct frame_info *frame, CORE_ADDR pc)
}
}
}
}
return 0;
}

View File

@ -562,8 +562,6 @@ compare_selectors (const void *a, const void *b)
static void
info_selectors_command (const char *regexp, int from_tty)
{
struct objfile *objfile;
struct minimal_symbol *msymbol;
const char *name;
char *val;
int matches = 0;
@ -607,7 +605,9 @@ info_selectors_command (const char *regexp, int from_tty)
}
/* First time thru is JUST to get max length and count. */
ALL_MSYMBOLS (objfile, msymbol)
for (objfile *objfile : all_objfiles (current_program_space))
{
for (minimal_symbol *msymbol : objfile_msymbols (objfile))
{
QUIT;
name = MSYMBOL_NATURAL_NAME (msymbol);
@ -637,6 +637,7 @@ info_selectors_command (const char *regexp, int from_tty)
}
}
}
}
if (matches)
{
printf_filtered (_("Selectors matching \"%s\":\n\n"),
@ -644,7 +645,9 @@ info_selectors_command (const char *regexp, int from_tty)
sym_arr = XALLOCAVEC (struct symbol *, matches);
matches = 0;
ALL_MSYMBOLS (objfile, msymbol)
for (objfile *objfile : all_objfiles (current_program_space))
{
for (minimal_symbol *msymbol : objfile_msymbols (objfile))
{
QUIT;
name = MSYMBOL_NATURAL_NAME (msymbol);
@ -661,6 +664,7 @@ info_selectors_command (const char *regexp, int from_tty)
sym_arr[matches++] = (struct symbol *) msymbol;
}
}
}
qsort (sym_arr, matches, sizeof (struct minimal_symbol *),
compare_selectors);
@ -723,8 +727,6 @@ compare_classes (const void *a, const void *b)
static void
info_classes_command (const char *regexp, int from_tty)
{
struct objfile *objfile;
struct minimal_symbol *msymbol;
const char *name;
char *val;
int matches = 0;
@ -757,7 +759,9 @@ info_classes_command (const char *regexp, int from_tty)
}
/* First time thru is JUST to get max length and count. */
ALL_MSYMBOLS (objfile, msymbol)
for (objfile *objfile : all_objfiles (current_program_space))
{
for (minimal_symbol *msymbol : objfile_msymbols (objfile))
{
QUIT;
name = MSYMBOL_NATURAL_NAME (msymbol);
@ -775,13 +779,16 @@ info_classes_command (const char *regexp, int from_tty)
matches++;
}
}
}
if (matches)
{
printf_filtered (_("Classes matching \"%s\":\n\n"),
regexp ? regexp : "*");
sym_arr = XALLOCAVEC (struct symbol *, matches);
matches = 0;
ALL_MSYMBOLS (objfile, msymbol)
for (objfile *objfile : all_objfiles (current_program_space))
{
for (minimal_symbol *msymbol : objfile_msymbols (objfile))
{
QUIT;
name = MSYMBOL_NATURAL_NAME (msymbol);
@ -791,6 +798,7 @@ info_classes_command (const char *regexp, int from_tty)
if (regexp == NULL || re_exec(name+2) != 0)
sym_arr[matches++] = (struct symbol *) msymbol;
}
}
qsort (sym_arr, matches, sizeof (struct minimal_symbol *),
compare_classes);
@ -987,7 +995,6 @@ find_methods (char type, const char *theclass, const char *category,
for (objfile *objfile : all_objfiles (current_program_space))
{
unsigned int *objc_csym;
struct minimal_symbol *msymbol = NULL;
/* The objfile_csym variable counts the number of ObjC methods
that this objfile defines. We save that count as a private
@ -1001,7 +1008,7 @@ find_methods (char type, const char *theclass, const char *category,
/* There are no ObjC symbols in this objfile. Skip it entirely. */
continue;
ALL_OBJFILE_MSYMBOLS (objfile, msymbol)
for (minimal_symbol *msymbol : objfile_msymbols (objfile))
{
QUIT;

View File

@ -623,12 +623,85 @@ public:
#define ALL_OBJFILE_COMPUNITS(objfile, cu) \
for ((cu) = (objfile) -> compunit_symtabs; (cu) != NULL; (cu) = (cu) -> next)
/* Traverse all minimal symbols in one objfile. */
/* A range adapter that makes it possible to iterate over all
minimal symbols of an objfile. */
#define ALL_OBJFILE_MSYMBOLS(objfile, m) \
for ((m) = (objfile)->per_bfd->msymbols; \
MSYMBOL_LINKAGE_NAME (m) != NULL; \
(m)++)
class objfile_msymbols
{
public:
explicit objfile_msymbols (struct objfile *objfile)
: m_objfile (objfile)
{
}
struct iterator
{
typedef iterator self_type;
typedef struct minimal_symbol *value_type;
typedef struct minimal_symbol *&reference;
typedef struct minimal_symbol **pointer;
typedef std::forward_iterator_tag iterator_category;
typedef int difference_type;
explicit iterator (struct objfile *objfile)
: m_msym (objfile->per_bfd->msymbols)
{
/* Make sure to properly handle the case where there are no
minsyms. */
if (MSYMBOL_LINKAGE_NAME (m_msym) == nullptr)
m_msym = nullptr;
}
iterator ()
: m_msym (nullptr)
{
}
value_type operator* () const
{
return m_msym;
}
bool operator== (const self_type &other) const
{
return m_msym == other.m_msym;
}
bool operator!= (const self_type &other) const
{
return m_msym != other.m_msym;
}
self_type &operator++ ()
{
if (m_msym != nullptr)
{
++m_msym;
if (MSYMBOL_LINKAGE_NAME (m_msym) == nullptr)
m_msym = nullptr;
}
return *this;
}
private:
struct minimal_symbol *m_msym;
};
iterator begin () const
{
return iterator (m_objfile);
}
iterator end () const
{
return iterator ();
}
private:
struct objfile *m_objfile;
};
/* Traverse all symtabs in all objfiles in the current symbol
space. */
@ -643,13 +716,6 @@ public:
ALL_OBJFILES (objfile) \
ALL_OBJFILE_COMPUNITS (objfile, cu)
/* Traverse all minimal symbols in all objfiles in the current symbol
space. */
#define ALL_MSYMBOLS(objfile, m) \
ALL_OBJFILES (objfile) \
ALL_OBJFILE_MSYMBOLS (objfile, m)
#define ALL_OBJFILE_OSECTIONS(objfile, osect) \
for (osect = objfile->sections; osect < objfile->sections_end; osect++) \
if (osect->the_bfd_section == NULL) \

View File

@ -4573,7 +4573,6 @@ void
scan_file_globals (struct objfile *objfile)
{
int hash;
struct minimal_symbol *msymbol;
struct symbol *sym, *prev;
struct objfile *resolve_objfile;
@ -4599,7 +4598,7 @@ scan_file_globals (struct objfile *objfile)
if (hash >= HASHSIZE)
return;
ALL_OBJFILE_MSYMBOLS (resolve_objfile, msymbol)
for (minimal_symbol *msymbol : objfile_msymbols (resolve_objfile))
{
QUIT;

View File

@ -183,7 +183,6 @@ static void
dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
{
struct gdbarch *gdbarch = get_objfile_arch (objfile);
struct minimal_symbol *msymbol;
int index;
char ms_type;
@ -194,7 +193,7 @@ dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
return;
}
index = 0;
ALL_OBJFILE_MSYMBOLS (objfile, msymbol)
for (minimal_symbol *msymbol : objfile_msymbols (objfile))
{
struct obj_section *section = MSYMBOL_OBJ_SECTION (objfile, msymbol);

View File

@ -4344,8 +4344,6 @@ search_symbols (const char *regexp, enum search_domain kind,
int i = 0;
struct block_iterator iter;
struct symbol *sym;
struct objfile *objfile;
struct minimal_symbol *msymbol;
int found_misc = 0;
static const enum minimal_symbol_type types[]
= {mst_data, mst_text, mst_abs};
@ -4454,7 +4452,9 @@ search_symbols (const char *regexp, enum search_domain kind,
if (nfiles == 0 && (kind == VARIABLES_DOMAIN || kind == FUNCTIONS_DOMAIN))
{
ALL_MSYMBOLS (objfile, msymbol)
for (objfile *objfile : all_objfiles (current_program_space))
{
for (minimal_symbol *msymbol : objfile_msymbols (objfile))
{
QUIT;
@ -4470,21 +4470,27 @@ search_symbols (const char *regexp, enum search_domain kind,
|| preg->exec (MSYMBOL_NATURAL_NAME (msymbol), 0,
NULL, 0) == 0)
{
/* Note: An important side-effect of these lookup functions
is to expand the symbol table if msymbol is found, for the
benefit of the next loop on ALL_COMPUNITS. */
/* Note: An important side-effect of these
lookup functions is to expand the symbol
table if msymbol is found, for the benefit of
the next loop on ALL_COMPUNITS. */
if (kind == FUNCTIONS_DOMAIN
? (find_pc_compunit_symtab
(MSYMBOL_VALUE_ADDRESS (objfile, msymbol)) == NULL)
(MSYMBOL_VALUE_ADDRESS (objfile, msymbol))
== NULL)
: (lookup_symbol_in_objfile_from_linkage_name
(objfile, MSYMBOL_LINKAGE_NAME (msymbol), VAR_DOMAIN)
(objfile, MSYMBOL_LINKAGE_NAME (msymbol),
VAR_DOMAIN)
.symbol == NULL))
found_misc = 1;
}
}
}
}
}
{
struct objfile *objfile;
ALL_COMPUNITS (objfile, cust)
{
bv = COMPUNIT_BLOCKVECTOR (cust);
@ -4497,8 +4503,9 @@ search_symbols (const char *regexp, enum search_domain kind,
QUIT;
/* Check first sole REAL_SYMTAB->FILENAME. It does not need to be
a substring of symtab_to_fullname as it may contain "./" etc. */
/* Check first sole REAL_SYMTAB->FILENAME. It does
not need to be a substring of symtab_to_fullname as
it may contain "./" etc. */
if ((file_matches (real_symtab->filename, files, nfiles, 0)
|| ((basenames_may_differ
|| file_matches (lbasename (real_symtab->filename),
@ -4512,9 +4519,10 @@ search_symbols (const char *regexp, enum search_domain kind,
&& SYMBOL_CLASS (sym) != LOC_TYPEDEF
&& SYMBOL_CLASS (sym) != LOC_UNRESOLVED
&& SYMBOL_CLASS (sym) != LOC_BLOCK
/* LOC_CONST can be used for more than just enums,
e.g., c++ static const members.
We only want to skip enums here. */
/* LOC_CONST can be used for more than
just enums, e.g., c++ static const
members. We only want to skip enums
here. */
&& !(SYMBOL_CLASS (sym) == LOC_CONST
&& (TYPE_CODE (SYMBOL_TYPE (sym))
== TYPE_CODE_ENUM))
@ -4523,7 +4531,8 @@ search_symbols (const char *regexp, enum search_domain kind,
|| (kind == FUNCTIONS_DOMAIN
&& SYMBOL_CLASS (sym) == LOC_BLOCK
&& (!treg.has_value ()
|| treg_matches_sym_type_name (*treg, sym)))
|| treg_matches_sym_type_name (*treg,
sym)))
|| (kind == TYPES_DOMAIN
&& SYMBOL_CLASS (sym) == LOC_TYPEDEF))))
{
@ -4533,6 +4542,7 @@ search_symbols (const char *regexp, enum search_domain kind,
}
}
}
}
if (!result.empty ())
sort_search_symbols_remove_dups (&result);
@ -4545,7 +4555,9 @@ search_symbols (const char *regexp, enum search_domain kind,
if ((found_misc || (nfiles == 0 && kind != FUNCTIONS_DOMAIN))
&& !treg.has_value ())
{
ALL_MSYMBOLS (objfile, msymbol)
for (objfile *objfile : all_objfiles (current_program_space))
{
for (minimal_symbol *msymbol : objfile_msymbols (objfile))
{
QUIT;
@ -4565,10 +4577,12 @@ search_symbols (const char *regexp, enum search_domain kind,
symbol might be found via find_pc_symtab. */
if (kind != FUNCTIONS_DOMAIN
|| (find_pc_compunit_symtab
(MSYMBOL_VALUE_ADDRESS (objfile, msymbol)) == NULL))
(MSYMBOL_VALUE_ADDRESS (objfile, msymbol))
== NULL))
{
if (lookup_symbol_in_objfile_from_linkage_name
(objfile, MSYMBOL_LINKAGE_NAME (msymbol), VAR_DOMAIN)
(objfile, MSYMBOL_LINKAGE_NAME (msymbol),
VAR_DOMAIN)
.symbol == NULL)
{
/* match */
@ -4579,6 +4593,7 @@ search_symbols (const char *regexp, enum search_domain kind,
}
}
}
}
return result;
}
@ -5188,8 +5203,6 @@ default_collect_symbol_completion_matches_break_on
struct symbol *sym;
struct compunit_symtab *cust;
struct minimal_symbol *msymbol;
struct objfile *objfile;
const struct block *b;
const struct block *surrounding_static_block, *surrounding_global_block;
struct block_iterator iter;
@ -5259,7 +5272,9 @@ default_collect_symbol_completion_matches_break_on
if (code == TYPE_CODE_UNDEF)
{
ALL_MSYMBOLS (objfile, msymbol)
for (objfile *objfile : all_objfiles (current_program_space))
{
for (minimal_symbol *msymbol : objfile_msymbols (objfile))
{
QUIT;
@ -5273,8 +5288,10 @@ default_collect_symbol_completion_matches_break_on
sym_text, word);
}
}
}
/* Add completions for all currently loaded symbol tables. */
struct objfile *objfile;
ALL_COMPUNITS (objfile, cust)
add_symtab_completions (cust, tracker, mode, lookup_name,
sym_text, word, code);