Introduce minimal_symbol_reader

This patch introduced minimal_symbol_reader, a RAII-based class which
replaces the current make_cleanup_discard_minimal_symbols.

2016-10-21  Tom Tromey  <tom@tromey.com>

	* xcoffread.c (xcoff_initial_scan): Use
	minimal_symbol_reader.
	* mipsread.c (mipscoff_symfile_read): Use
	minimal_symbol_reader.
	* minsyms.h (minimal_symbol_reader): New class.
	(init_minimal_symbol_collection)
	(make_cleanup_discard_minimal_symbols, install_minimal_symbols):
	Don't declare.
	* minsyms.c (minimal_symbol_reader): Renamed from
	init_minimal_symbol_collection, turned into constructor.
	(~minimal_symbol_reader): Renamed from
	do_discard_minimal_symbols_cleanup, turned into destructor.
	(make_cleanup_discard_minimal_symbols): Remove.
	(minimal_symbol_reader::install): Rename form
	install_minimal_symbols.
	* mdebugread.c (elfmdebug_build_psymtabs): Use
	minimal_symbol_reader.
	* machoread.c (macho_symfile_read): Use
	minimal_symbol_reader.
	* elfread.c (elf_read_minimal_symbols): Use
	minimal_symbol_reader.
	* dbxread.c (dbx_symfile_read): Use minimal_symbol_reader.
	* coffread.c (coff_symfile_read): Use
	minimal_symbol_reader.
This commit is contained in:
Tom Tromey 2016-09-22 13:47:48 -06:00
parent 4b6749b9a4
commit 873a915e0a
10 changed files with 89 additions and 82 deletions

View File

@ -1,3 +1,30 @@
2016-10-21 Tom Tromey <tom@tromey.com>
* xcoffread.c (xcoff_initial_scan): Use
minimal_symbol_reader.
* mipsread.c (mipscoff_symfile_read): Use
minimal_symbol_reader.
* minsyms.h (minimal_symbol_reader): New class.
(init_minimal_symbol_collection)
(make_cleanup_discard_minimal_symbols, install_minimal_symbols):
Don't declare.
* minsyms.c (minimal_symbol_reader): Renamed from
init_minimal_symbol_collection, turned into constructor.
(~minimal_symbol_reader): Renamed from
do_discard_minimal_symbols_cleanup, turned into destructor.
(make_cleanup_discard_minimal_symbols): Remove.
(minimal_symbol_reader::install): Rename form
install_minimal_symbols.
* mdebugread.c (elfmdebug_build_psymtabs): Use
minimal_symbol_reader.
* machoread.c (macho_symfile_read): Use
minimal_symbol_reader.
* elfread.c (elf_read_minimal_symbols): Use
minimal_symbol_reader.
* dbxread.c (dbx_symfile_read): Use minimal_symbol_reader.
* coffread.c (coff_symfile_read): Use
minimal_symbol_reader.
2016-10-21 Tom Tromey <tom@tromey.com>
* top.c (new_ui_command, wait_sync_command_done)

View File

@ -568,7 +568,7 @@ coff_symfile_read (struct objfile *objfile, int symfile_flags)
unsigned int num_symbols;
int symtab_offset;
int stringtab_offset;
struct cleanup *back_to, *cleanup_minimal_symbols;
struct cleanup *back_to;
int stabstrsize;
info = (struct coff_symfile_info *) objfile_data (objfile,
@ -645,8 +645,7 @@ coff_symfile_read (struct objfile *objfile, int symfile_flags)
if (val < 0)
error (_("\"%s\": can't get string table"), name);
init_minimal_symbol_collection ();
cleanup_minimal_symbols = make_cleanup_discard_minimal_symbols ();
minimal_symbol_reader reader;
/* Now that the executable file is positioned at symbol table,
process it and define symbols accordingly. */
@ -656,7 +655,7 @@ coff_symfile_read (struct objfile *objfile, int symfile_flags)
/* Install any minimal symbols that have been collected as the
current minimal symbols for this objfile. */
install_minimal_symbols (objfile);
reader.install (objfile);
if (pe_file)
{
@ -699,9 +698,6 @@ coff_symfile_read (struct objfile *objfile, int symfile_flags)
}
}
/* Free the installed minimal symbol data. */
do_cleanups (cleanup_minimal_symbols);
bfd_map_over_sections (abfd, coff_locate_sections, (void *) info);
if (info->stabsects)

View File

@ -558,8 +558,7 @@ dbx_symfile_read (struct objfile *objfile, int symfile_flags)
free_pending_blocks ();
back_to = make_cleanup (really_free_pendings, 0);
init_minimal_symbol_collection ();
make_cleanup_discard_minimal_symbols ();
minimal_symbol_reader reader;
/* Read stabs data from executable file and define symbols. */
@ -572,7 +571,7 @@ dbx_symfile_read (struct objfile *objfile, int symfile_flags)
/* Install any minimal symbols that have been collected as the current
minimal symbols for this objfile. */
install_minimal_symbols (objfile);
reader.install (objfile);
do_cleanups (back_to);
}

View File

@ -1049,8 +1049,8 @@ elf_read_minimal_symbols (struct objfile *objfile, int symfile_flags,
return;
}
init_minimal_symbol_collection ();
back_to = make_cleanup_discard_minimal_symbols ();
minimal_symbol_reader reader;
back_to = make_cleanup (null_cleanup, NULL);
/* Allocate struct to keep track of the symfile. */
dbx = XCNEW (struct dbx_symfile_info);
@ -1149,7 +1149,7 @@ elf_read_minimal_symbols (struct objfile *objfile, int symfile_flags,
responsibility to install them. "mdebug" appears to be the only one
which will do this. */
install_minimal_symbols (objfile);
reader.install (objfile);
do_cleanups (back_to);
if (symtab_create_debug)

View File

@ -855,8 +855,7 @@ macho_symfile_read (struct objfile *objfile, int symfile_flags)
symbol_table = (asymbol **) xmalloc (storage_needed);
make_cleanup (xfree, symbol_table);
init_minimal_symbol_collection ();
make_cleanup_discard_minimal_symbols ();
minimal_symbol_reader reader;
symcount = bfd_canonicalize_symtab (objfile->obfd, symbol_table);
@ -867,7 +866,7 @@ macho_symfile_read (struct objfile *objfile, int symfile_flags)
macho_symtab_read (objfile, symcount, symbol_table, &oso_vector);
install_minimal_symbols (objfile);
reader.install (objfile);
}
/* Try to read .eh_frame / .debug_frame. */

View File

@ -4870,14 +4870,12 @@ elfmdebug_build_psymtabs (struct objfile *objfile,
{
bfd *abfd = objfile->obfd;
struct ecoff_debug_info *info;
struct cleanup *back_to;
/* FIXME: It's not clear whether we should be getting minimal symbol
information from .mdebug in an ELF file, or whether we will.
Re-initialize the minimal symbol reader in case we do. */
init_minimal_symbol_collection ();
back_to = make_cleanup_discard_minimal_symbols ();
minimal_symbol_reader reader;
info = ((struct ecoff_debug_info *)
obstack_alloc (&objfile->objfile_obstack,
@ -4889,8 +4887,7 @@ elfmdebug_build_psymtabs (struct objfile *objfile,
mdebug_build_psymtabs (objfile, swap, info);
install_minimal_symbols (objfile);
do_cleanups (back_to);
reader.install (objfile);
}
void

View File

@ -921,8 +921,7 @@ get_symbol_leading_char (bfd *abfd)
/* See minsyms.h. */
void
init_minimal_symbol_collection (void)
minimal_symbol_reader::minimal_symbol_reader ()
{
msym_count = 0;
msym_bunch = NULL;
@ -932,6 +931,26 @@ init_minimal_symbol_collection (void)
msym_bunch_index = BUNCH_SIZE;
}
/* Discard the currently collected minimal symbols, if any. If we wish
to save them for later use, we must have already copied them somewhere
else before calling this function.
FIXME: We could allocate the minimal symbol bunches on their own
obstack and then simply blow the obstack away when we are done with
it. Is it worth the extra trouble though? */
minimal_symbol_reader::~minimal_symbol_reader ()
{
struct msym_bunch *next;
while (msym_bunch != NULL)
{
next = msym_bunch->next;
xfree (msym_bunch);
msym_bunch = next;
}
}
/* See minsyms.h. */
void
@ -1087,37 +1106,6 @@ compare_minimal_symbols (const void *fn1p, const void *fn2p)
}
}
/* Discard the currently collected minimal symbols, if any. If we wish
to save them for later use, we must have already copied them somewhere
else before calling this function.
FIXME: We could allocate the minimal symbol bunches on their own
obstack and then simply blow the obstack away when we are done with
it. Is it worth the extra trouble though? */
static void
do_discard_minimal_symbols_cleanup (void *arg)
{
struct msym_bunch *next;
while (msym_bunch != NULL)
{
next = msym_bunch->next;
xfree (msym_bunch);
msym_bunch = next;
}
}
/* See minsyms.h. */
struct cleanup *
make_cleanup_discard_minimal_symbols (void)
{
return make_cleanup (do_discard_minimal_symbols_cleanup, 0);
}
/* Compact duplicate entries out of a minimal symbol table by walking
through the table and compacting out entries with duplicate addresses
and matching names. Return the number of entries remaining.
@ -1244,7 +1232,7 @@ build_minimal_symbol_hash_tables (struct objfile *objfile)
attempts to demangle them if we later add more minimal symbols. */
void
install_minimal_symbols (struct objfile *objfile)
minimal_symbol_reader::install (struct objfile *objfile)
{
int bindex;
int mcount;

View File

@ -53,21 +53,33 @@ struct bound_minimal_symbol
as opaque and use functions provided by minsyms.c to inspect them.
*/
/* Prepare to start collecting minimal symbols. This should be called
by a symbol reader to initialize the minimal symbol module.
Currently, minimal symbol table creation is not reentrant; it
relies on global (static) variables in minsyms.c. */
/* An RAII-based object that is used to record minimal symbols while
they are being read. */
class minimal_symbol_reader
{
public:
void init_minimal_symbol_collection (void);
/* Prepare to start collecting minimal symbols. This should be called
by a symbol reader to initialize the minimal symbol module.
Currently, minimal symbol table creation is not reentrant; it
relies on global (static) variables in minsyms.c. */
/* Return a cleanup which is used to clean up the global state left
over by minimal symbol creation. After calling
init_minimal_symbol_collection, a symbol reader should call this
function. Then, after all minimal symbols have been read,
regardless of whether they are installed or not, the cleanup
returned by this function should be run. */
explicit minimal_symbol_reader ();
struct cleanup *make_cleanup_discard_minimal_symbols (void);
~minimal_symbol_reader ();
/* Install the minimal symbols that have been collected into the
given objfile. */
void install (struct objfile *);
private:
/* No need for these. They are intentionally not defined anywhere. */
minimal_symbol_reader &operator=
(const minimal_symbol_reader &);
minimal_symbol_reader (const minimal_symbol_reader &);
};
/* Record a new minimal symbol. This is the "full" entry point;
simpler convenience entry points are also provided below.
@ -122,13 +134,6 @@ struct minimal_symbol *prim_record_minimal_symbol_and_info
int section,
struct objfile *);
/* Install the minimal symbols that have been collected into the given
objfile. After this is called, the cleanup returned by
make_cleanup_discard_minimal_symbols should be run in order to
clean up global state. */
void install_minimal_symbols (struct objfile *);
/* Create the terminating entry of OBJFILE's minimal symbol table.
If OBJFILE->msymbols is zero, allocate a single entry from
OBJFILE->objfile_obstack; otherwise, just initialize

View File

@ -69,10 +69,8 @@ static void
mipscoff_symfile_read (struct objfile *objfile, int symfile_flags)
{
bfd *abfd = objfile->obfd;
struct cleanup *back_to;
init_minimal_symbol_collection ();
back_to = make_cleanup_discard_minimal_symbols ();
minimal_symbol_reader reader;
/* Now that the executable file is positioned at symbol table,
process it and define symbols accordingly. */
@ -91,8 +89,7 @@ mipscoff_symfile_read (struct objfile *objfile, int symfile_flags)
/* Install any minimal symbols that have been collected as the current
minimal symbols for this objfile. */
install_minimal_symbols (objfile);
do_cleanups (back_to);
reader.install (objfile);
}
/* Perform any local cleanups required when we are done with a

View File

@ -3006,8 +3006,7 @@ xcoff_initial_scan (struct objfile *objfile, int symfile_flags)
free_pending_blocks ();
back_to = make_cleanup (really_free_pendings, 0);
init_minimal_symbol_collection ();
make_cleanup_discard_minimal_symbols ();
minimal_symbol_reader reader;
/* Now that the symbol table data of the executable file are all in core,
process them and define symbols accordingly. */
@ -3017,7 +3016,7 @@ xcoff_initial_scan (struct objfile *objfile, int symfile_flags)
/* Install any minimal symbols that have been collected as the current
minimal symbols for this objfile. */
install_minimal_symbols (objfile);
reader.install (objfile);
/* DWARF2 sections. */