[RFA,07/22] Change scoped_minimal_symbol_reader to store objfile
Commit Message
This changes scoped_minimal_symbol_reader to require the objfile to be
passed to the constructor. The class now records the objfile and
automatically uses it later in "install".
This is a minor cleanup that will come in useful in the next patch.
It is separate from the first patch to keep that one a bit simpler to
understand.
2016-09-26 Tom Tromey <tom@tromey.com>
* xcoffread.c (xcoff_initial_scan): Update.
* mipsread.c (mipscoff_symfile_read): Update.
* minsyms.c (scoped_minimal_symbol_reader): Add obj argument.
Initialize member.
(install): Remove objfile argument.
* mdebugread.c (elfmdebug_build_psymtabs): Update.
* machoread.c (macho_symfile_read): Update.
* elfread.c (elf_read_minimal_symbols): Update.
* dbxread.c (dbx_symfile_read): Update.
* coffread.c (coff_symfile_read): Update.
* minsyms.h (scoped_minimal_symbol_reader): Add objfile member.
(constructor): Add objfile argument.
(scoped_minimal_symbol_reader::install): Remove objfile argument.
---
gdb/ChangeLog | 16 ++++++++++++++++
gdb/coffread.c | 4 ++--
gdb/dbxread.c | 4 ++--
gdb/elfread.c | 4 ++--
gdb/machoread.c | 4 ++--
gdb/mdebugread.c | 4 ++--
gdb/minsyms.c | 5 +++--
gdb/minsyms.h | 6 ++++--
gdb/mipsread.c | 4 ++--
gdb/xcoffread.c | 4 ++--
10 files changed, 37 insertions(+), 18 deletions(-)
Comments
> Currently, minimal symbol table creation is not reentrant; it
> relies on global (static) variables in minsyms.c. */
>
> - explicit scoped_minimal_symbol_reader ();
> + explicit scoped_minimal_symbol_reader (struct objfile *);
C++ doesn't require the explicit struct / union when refering to the
type, though of course you can keep them if you think it makes something
clearer.
> @@ -79,6 +79,8 @@ class scoped_minimal_symbol_reader
> scoped_minimal_symbol_reader &operator=
> (const scoped_minimal_symbol_reader &);
> scoped_minimal_symbol_reader (const scoped_minimal_symbol_reader &);
> +
> + struct objfile *objfile;
fwiw gcc convention is to prefix members with m_, so doing so in gdb as
well would be nice.
Trev
>>>>> "Trevor" == Trevor Saunders <tbsaunde@tbsaunde.org> writes:
>> Currently, minimal symbol table creation is not reentrant; it
>> relies on global (static) variables in minsyms.c. */
>>
>> - explicit scoped_minimal_symbol_reader ();
>> + explicit scoped_minimal_symbol_reader (struct objfile *);
Trevor> C++ doesn't require the explicit struct / union when refering to the
Trevor> type, though of course you can keep them if you think it makes something
Trevor> clearer.
I kept it just because "struct objfile" is used everywhere else in gdb.
>> @@ -79,6 +79,8 @@ class scoped_minimal_symbol_reader
>> scoped_minimal_symbol_reader &operator=
>> (const scoped_minimal_symbol_reader &);
>> scoped_minimal_symbol_reader (const scoped_minimal_symbol_reader &);
>> +
>> + struct objfile *objfile;
Trevor> fwiw gcc convention is to prefix members with m_, so doing so in gdb as
Trevor> well would be nice.
I made this change.
Tom
@@ -1,5 +1,21 @@
2016-09-26 Tom Tromey <tom@tromey.com>
+ * xcoffread.c (xcoff_initial_scan): Update.
+ * mipsread.c (mipscoff_symfile_read): Update.
+ * minsyms.c (scoped_minimal_symbol_reader): Add obj argument.
+ Initialize member.
+ (install): Remove objfile argument.
+ * mdebugread.c (elfmdebug_build_psymtabs): Update.
+ * machoread.c (macho_symfile_read): Update.
+ * elfread.c (elf_read_minimal_symbols): Update.
+ * dbxread.c (dbx_symfile_read): Update.
+ * coffread.c (coff_symfile_read): Update.
+ * minsyms.h (scoped_minimal_symbol_reader): Add objfile member.
+ (constructor): Add objfile argument.
+ (scoped_minimal_symbol_reader::install): Remove objfile argument.
+
+2016-09-26 Tom Tromey <tom@tromey.com>
+
* xcoffread.c (xcoff_initial_scan): Use
scoped_minimal_symbol_reader.
* mipsread.c (mipscoff_symfile_read): Use
@@ -645,7 +645,7 @@ coff_symfile_read (struct objfile *objfile, int symfile_flags)
if (val < 0)
error (_("\"%s\": can't get string table"), name);
- scoped_minimal_symbol_reader reader;
+ scoped_minimal_symbol_reader reader (objfile);
/* Now that the executable file is positioned at symbol table,
process it and define symbols accordingly. */
@@ -655,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. */
- reader.install (objfile);
+ reader.install ();
if (pe_file)
{
@@ -558,7 +558,7 @@ dbx_symfile_read (struct objfile *objfile, int symfile_flags)
free_pending_blocks ();
back_to = make_cleanup (really_free_pendings, 0);
- scoped_minimal_symbol_reader reader;
+ scoped_minimal_symbol_reader reader (objfile);
/* Read stabs data from executable file and define symbols. */
@@ -571,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. */
- reader.install (objfile);
+ reader.install ();
do_cleanups (back_to);
}
@@ -1049,7 +1049,7 @@ elf_read_minimal_symbols (struct objfile *objfile, int symfile_flags,
return;
}
- scoped_minimal_symbol_reader reader;
+ scoped_minimal_symbol_reader reader (objfile);
back_to = make_cleanup (null_cleanup, NULL);
/* Allocate struct to keep track of the symfile. */
@@ -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. */
- reader.install (objfile);
+ reader.install ();
do_cleanups (back_to);
if (symtab_create_debug)
@@ -861,7 +861,7 @@ macho_symfile_read (struct objfile *objfile, int symfile_flags)
symbol_table = (asymbol **) xmalloc (storage_needed);
make_cleanup (xfree, symbol_table);
- scoped_minimal_symbol_reader reader;
+ scoped_minimal_symbol_reader reader (objfile);
symcount = bfd_canonicalize_symtab (objfile->obfd, symbol_table);
@@ -872,7 +872,7 @@ macho_symfile_read (struct objfile *objfile, int symfile_flags)
macho_symtab_read (objfile, symcount, symbol_table, &oso_vector);
- reader.install (objfile);
+ reader.install ();
}
/* Try to read .eh_frame / .debug_frame. */
@@ -4875,7 +4875,7 @@ elfmdebug_build_psymtabs (struct objfile *objfile,
information from .mdebug in an ELF file, or whether we will.
Re-initialize the minimal symbol reader in case we do. */
- scoped_minimal_symbol_reader reader;
+ scoped_minimal_symbol_reader reader (objfile);
info = ((struct ecoff_debug_info *)
obstack_alloc (&objfile->objfile_obstack,
@@ -4887,7 +4887,7 @@ elfmdebug_build_psymtabs (struct objfile *objfile,
mdebug_build_psymtabs (objfile, swap, info);
- reader.install (objfile);
+ reader.install ();
}
void
@@ -921,7 +921,8 @@ get_symbol_leading_char (bfd *abfd)
/* See minsyms.h. */
-scoped_minimal_symbol_reader::scoped_minimal_symbol_reader ()
+scoped_minimal_symbol_reader::scoped_minimal_symbol_reader (struct objfile *obj)
+: objfile (obj)
{
msym_count = 0;
msym_bunch = NULL;
@@ -1232,7 +1233,7 @@ build_minimal_symbol_hash_tables (struct objfile *objfile)
attempts to demangle them if we later add more minimal symbols. */
void
-scoped_minimal_symbol_reader::install (struct objfile *objfile)
+scoped_minimal_symbol_reader::install ()
{
int bindex;
int mcount;
@@ -64,14 +64,14 @@ class scoped_minimal_symbol_reader
Currently, minimal symbol table creation is not reentrant; it
relies on global (static) variables in minsyms.c. */
- explicit scoped_minimal_symbol_reader ();
+ explicit scoped_minimal_symbol_reader (struct objfile *);
~scoped_minimal_symbol_reader ();
/* Install the minimal symbols that have been collected into the
given objfile. */
- void install (struct objfile *);
+ void install ();
private:
@@ -79,6 +79,8 @@ class scoped_minimal_symbol_reader
scoped_minimal_symbol_reader &operator=
(const scoped_minimal_symbol_reader &);
scoped_minimal_symbol_reader (const scoped_minimal_symbol_reader &);
+
+ struct objfile *objfile;
};
/* Record a new minimal symbol. This is the "full" entry point;
@@ -70,7 +70,7 @@ mipscoff_symfile_read (struct objfile *objfile, int symfile_flags)
{
bfd *abfd = objfile->obfd;
- scoped_minimal_symbol_reader reader;
+ scoped_minimal_symbol_reader reader (objfile);
/* Now that the executable file is positioned at symbol table,
process it and define symbols accordingly. */
@@ -89,7 +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. */
- reader.install (objfile);
+ reader.install ();
}
/* Perform any local cleanups required when we are done with a
@@ -3006,7 +3006,7 @@ xcoff_initial_scan (struct objfile *objfile, int symfile_flags)
free_pending_blocks ();
back_to = make_cleanup (really_free_pendings, 0);
- scoped_minimal_symbol_reader reader;
+ scoped_minimal_symbol_reader reader (objfile);
/* Now that the symbol table data of the executable file are all in core,
process them and define symbols accordingly. */
@@ -3016,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. */
- reader.install (objfile);
+ reader.install ();
/* DWARF2 sections. */