+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)
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,
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. */
/* 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)
{
}
}
- /* Free the installed minimal symbol data. */
- do_cleanups (cleanup_minimal_symbols);
-
bfd_map_over_sections (abfd, coff_locate_sections, (void *) info);
if (info->stabsects)
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. */
/* 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);
}
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);
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)
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);
macho_symtab_read (objfile, symcount, symbol_table, &oso_vector);
- install_minimal_symbols (objfile);
+ reader.install (objfile);
}
/* Try to read .eh_frame / .debug_frame. */
{
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,
mdebug_build_psymtabs (objfile, swap, info);
- install_minimal_symbols (objfile);
- do_cleanups (back_to);
+ reader.install (objfile);
}
void
/* See minsyms.h. */
-void
-init_minimal_symbol_collection (void)
+minimal_symbol_reader::minimal_symbol_reader ()
{
msym_count = 0;
msym_bunch = NULL;
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
}
}
-/* 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.
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;
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:
+
+ /* 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. */
+
+ explicit minimal_symbol_reader ();
+
+ ~minimal_symbol_reader ();
-void init_minimal_symbol_collection (void);
+ /* Install the minimal symbols that have been collected into the
+ given objfile. */
-/* 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. */
+ void install (struct objfile *);
-struct cleanup *make_cleanup_discard_minimal_symbols (void);
+ 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.
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
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. */
/* 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
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. */
/* 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. */