aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2016-09-22 13:47:48 -0600
committerTom Tromey <tom@tromey.com>2016-10-21 14:17:33 -0600
commit873a915e0ad44cb303b071638536f27569491030 (patch)
tree6209436a7e32b15b891764df1e5e2738e33a4ec5
parent4b6749b9a4680e79affdb9c02ea2f5ba39a54587 (diff)
downloadgdb-873a915e0ad44cb303b071638536f27569491030.zip
gdb-873a915e0ad44cb303b071638536f27569491030.tar.gz
gdb-873a915e0ad44cb303b071638536f27569491030.tar.bz2
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.
-rw-r--r--gdb/ChangeLog27
-rw-r--r--gdb/coffread.c10
-rw-r--r--gdb/dbxread.c5
-rw-r--r--gdb/elfread.c6
-rw-r--r--gdb/machoread.c5
-rw-r--r--gdb/mdebugread.c7
-rw-r--r--gdb/minsyms.c56
-rw-r--r--gdb/minsyms.h43
-rw-r--r--gdb/mipsread.c7
-rw-r--r--gdb/xcoffread.c5
10 files changed, 89 insertions, 82 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index ebfdf99..017396c 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,32 @@
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)
(gdb_readline_wrapper): Use scoped_restore.
* infrun.c (fetch_inferior_event): Use scoped_restore.
diff --git a/gdb/coffread.c b/gdb/coffread.c
index 830deb5..67b9cb7 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -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)
diff --git a/gdb/dbxread.c b/gdb/dbxread.c
index d5a9587..26d50e1 100644
--- a/gdb/dbxread.c
+++ b/gdb/dbxread.c
@@ -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);
}
diff --git a/gdb/elfread.c b/gdb/elfread.c
index 84355cf..4f55e37 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -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)
diff --git a/gdb/machoread.c b/gdb/machoread.c
index 2eff534..45ae67b 100644
--- a/gdb/machoread.c
+++ b/gdb/machoread.c
@@ -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. */
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index 157ce77..358ee70 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -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
diff --git a/gdb/minsyms.c b/gdb/minsyms.c
index b478402..a100d4c 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -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;
diff --git a/gdb/minsyms.h b/gdb/minsyms.h
index 8857f1a..d75bd41 100644
--- a/gdb/minsyms.h
+++ b/gdb/minsyms.h
@@ -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:
+
+ /* 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.
@@ -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
diff --git a/gdb/mipsread.c b/gdb/mipsread.c
index 27a59d2..dff1cb1 100644
--- a/gdb/mipsread.c
+++ b/gdb/mipsread.c
@@ -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
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index 9ceefa0..3c843a0 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -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. */