Allow multiple partial symbol readers per objfile

This patch finally changes gdb so that an objfile can have multiple
sources of partial symbols (or mixed partial symbols and other kinds
of indices).

This is done by having each symbol reader create its own
psymbol_functions object and add it to the 'qf' list in the objfile.

gdb/ChangeLog
2021-03-20  Tom Tromey  <tom@tromey.com>

	* xcoffread.c (xcoff_initial_scan): Create partial symtabs.
	* symfile.c (syms_from_objfile_1, reread_symbols): Update.
	* psymtab.h (make_psymbol_functions): Don't declare.
	* psymtab.c (make_psymbol_functions): Remove.
	(maintenance_print_psymbols): Update.
	* psympriv.h (struct psymbol_functions): Add no-argument
	constructor.
	* objfiles.h (struct objfile) <reset_psymtabs>: Remove.
	<partial_symtabs>: Remove.
	* mdebugread.c (mdebug_build_psymtabs): Create partial symtabs.
	* elfread.c (read_partial_symbols): Update.
	(elf_symfile_read): Remove check for existing partial symbols.
	Don't clear "qf".
	* dwarf2/read.c (dwarf2_has_info): Remove check for existing
	partial symbols.
	(dwarf2_build_psymtabs): Add psymbol_functions parameter.  Create
	partial symtabs.
	* dwarf2/public.h (dwarf2_build_psymtabs): Add psymbol_functions
	parameter.
	* dbxread.c (dbx_symfile_read): Create partial symtabs.
	* ctfread.c (elfctf_build_psymtabs): Create partial symtabs.
This commit is contained in:
Tom Tromey 2021-03-20 17:23:40 -06:00
parent e11145903f
commit eb36a3eb2f
13 changed files with 67 additions and 61 deletions

View File

@ -1,3 +1,27 @@
2021-03-20 Tom Tromey <tom@tromey.com>
* xcoffread.c (xcoff_initial_scan): Create partial symtabs.
* symfile.c (syms_from_objfile_1, reread_symbols): Update.
* psymtab.h (make_psymbol_functions): Don't declare.
* psymtab.c (make_psymbol_functions): Remove.
(maintenance_print_psymbols): Update.
* psympriv.h (struct psymbol_functions): Add no-argument
constructor.
* objfiles.h (struct objfile) <reset_psymtabs>: Remove.
<partial_symtabs>: Remove.
* mdebugread.c (mdebug_build_psymtabs): Create partial symtabs.
* elfread.c (read_partial_symbols): Update.
(elf_symfile_read): Remove check for existing partial symbols.
Don't clear "qf".
* dwarf2/read.c (dwarf2_has_info): Remove check for existing
partial symbols.
(dwarf2_build_psymtabs): Add psymbol_functions parameter. Create
partial symtabs.
* dwarf2/public.h (dwarf2_build_psymtabs): Add psymbol_functions
parameter.
* dbxread.c (dbx_symfile_read): Create partial symtabs.
* ctfread.c (elfctf_build_psymtabs): Create partial symtabs.
2021-03-20 Tom Tromey <tom@tromey.com>
* dwarf2/read.c (dwarf2_build_psymtabs): Update.

View File

@ -1546,7 +1546,9 @@ elfctf_build_psymtabs (struct objfile *of)
bfd_get_filename (abfd), ctf_errmsg (err));
ctf_dict_key.emplace (of, fp);
psymtab_storage *partial_symtabs = of->partial_symtabs.get ();
psymbol_functions *psf = new psymbol_functions ();
psymtab_storage *partial_symtabs = psf->get_partial_symtabs ().get ();
of->qf.emplace_front (psf);
scan_partial_symbols (fp, partial_symtabs, of);
}

View File

@ -545,7 +545,9 @@ dbx_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
/* Read stabs data from executable file and define symbols. */
psymtab_storage *partial_symtabs = objfile->partial_symtabs.get ();
psymbol_functions *psf = new psymbol_functions ();
psymtab_storage *partial_symtabs = psf->get_partial_symtabs ().get ();
objfile->qf.emplace_front (psf);
read_dbx_symtab (reader, partial_symtabs, objfile);
/* Install any minimal symbols that have been collected as the current

View File

@ -40,7 +40,9 @@ enum class dw_index_kind
extern bool dwarf2_initialize_objfile (struct objfile *objfile,
dw_index_kind *index_kind);
extern void dwarf2_build_psymtabs (struct objfile *);
struct psymbol_functions;
extern void dwarf2_build_psymtabs (struct objfile *,
psymbol_functions *psf = nullptr);
extern void dwarf2_build_frame_info (struct objfile *);
extern quick_symbol_functions_up make_dwarf_gdb_index ();

View File

@ -1952,10 +1952,8 @@ dwarf2_has_info (struct objfile *objfile,
dwarf2_per_bfd *per_bfd;
/* We can share a "dwarf2_per_bfd" with other objfiles if the BFD
doesn't require relocations and if there aren't partial symbols
from some other reader. */
if (!objfile->has_partial_symbols ()
&& !gdb_bfd_requires_relocations (objfile->obfd))
doesn't require relocations. */
if (!gdb_bfd_requires_relocations (objfile->obfd))
{
/* See if one has been created for this BFD yet. */
per_bfd = dwarf2_per_bfd_bfd_data_key.get (objfile->obfd);
@ -6118,7 +6116,7 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind)
/* Build a partial symbol table. */
void
dwarf2_build_psymtabs (struct objfile *objfile)
dwarf2_build_psymtabs (struct objfile *objfile, psymbol_functions *psf)
{
dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
@ -6127,29 +6125,37 @@ dwarf2_build_psymtabs (struct objfile *objfile)
{
/* Partial symbols were already read, so now we can simply
attach them. */
objfile->partial_symtabs = per_bfd->partial_symtabs;
/* This is a temporary hack to ensure that the objfile and 'qf'
psymtabs are identical. */
psymbol_functions *psf
= dynamic_cast<psymbol_functions *> (objfile->qf.front ().get ());
gdb_assert (psf != nullptr);
psf->set_partial_symtabs (per_bfd->partial_symtabs);
if (psf == nullptr)
{
psf = new psymbol_functions (per_bfd->partial_symtabs);
objfile->qf.emplace_front (psf);
}
else
psf->set_partial_symtabs (per_bfd->partial_symtabs);
per_objfile->resize_symtabs ();
return;
}
if (psf == nullptr)
{
psf = new psymbol_functions;
objfile->qf.emplace_front (psf);
}
const std::shared_ptr<psymtab_storage> &partial_symtabs
= psf->get_partial_symtabs ();
/* Set the local reference to partial symtabs, so that we don't try
to read them again if reading another objfile with the same BFD.
If we can't in fact share, this won't make a difference anyway as
the dwarf2_per_bfd object won't be shared. */
per_bfd->partial_symtabs = objfile->partial_symtabs;
per_bfd->partial_symtabs = partial_symtabs;
try
{
/* This isn't really ideal: all the data we allocate on the
objfile's obstack is still uselessly kept around. However,
freeing it seems unsafe. */
psymtab_discarder psymtabs (objfile->partial_symtabs.get ());
psymtab_discarder psymtabs (partial_symtabs.get ());
dwarf2_build_psymtabs_hard (per_objfile);
psymtabs.keep ();

View File

@ -67,7 +67,7 @@ struct lazy_dwarf_reader : public psymbol_functions
void read_partial_symbols (struct objfile *objfile) override
{
if (dwarf2_has_info (objfile, nullptr))
dwarf2_build_psymtabs (objfile);
dwarf2_build_psymtabs (objfile, this);
}
};
@ -1278,16 +1278,11 @@ elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
{
dw_index_kind index_kind;
/* elf_sym_fns_gdb_index cannot handle simultaneous non-DWARF
debug information present in OBJFILE. If there is such debug
info present never use an index. */
if (!objfile->has_partial_symbols ()
&& dwarf2_initialize_objfile (objfile, &index_kind))
if (dwarf2_initialize_objfile (objfile, &index_kind))
{
switch (index_kind)
{
case dw_index_kind::GDB_INDEX:
objfile->qf.clear ();
objfile->qf.push_front (make_dwarf_gdb_index ());
break;
case dw_index_kind::DEBUG_NAMES:
@ -1297,15 +1292,7 @@ elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
}
}
else
{
/* It is ok to do this even if the stabs reader made some
partial symbols, because OBJF_PSYMTABS_READ has not been
set, and so our lazy reader function will still be called
when needed. */
objfile->qf.clear ();
objfile->qf.emplace_front
(new lazy_dwarf_reader (objfile->partial_symtabs));
}
objfile->qf.emplace_front (new lazy_dwarf_reader);
}
/* If the file has its own symbol tables it has no separate debug
info. `.dynsym'/`.symtab' go to MSYMBOLS, `.debug_info' goes to

View File

@ -360,7 +360,9 @@ mdebug_build_psymtabs (minimal_symbol_reader &reader,
(*swap->swap_fdr_in) (objfile->obfd, fdr_src, fdr_ptr);
}
psymtab_storage *partial_symtabs = objfile->partial_symtabs.get ();
psymbol_functions *psf = new psymbol_functions ();
psymtab_storage *partial_symtabs = psf->get_partial_symtabs ().get ();
objfile->qf.emplace_front (psf);
parse_partial_symbols (reader, partial_symtabs, objfile);
#if 0

View File

@ -447,13 +447,6 @@ public:
DISABLE_COPY_AND_ASSIGN (objfile);
/* Reset the storage for the partial symbol tables. */
void reset_psymtabs ()
{
partial_symtabs.reset (new psymtab_storage ());
}
typedef next_adapter<struct compunit_symtab> compunits_range;
/* A range adapter that makes it possible to iterate over all
@ -635,10 +628,6 @@ public:
struct compunit_symtab *compunit_symtabs = nullptr;
/* The partial symbol tables. */
std::shared_ptr<psymtab_storage> partial_symtabs;
/* The object file's BFD. Can be null if the objfile contains only
minimal symbols, e.g. the run time common symbols for SunOS4. */

View File

@ -495,6 +495,11 @@ struct psymbol_functions : public quick_symbol_functions
{
}
psymbol_functions ()
: m_partial_symtabs (new psymtab_storage)
{
}
bool has_symbols (struct objfile *objfile) override;
struct symtab *find_last_source_symtab (struct objfile *objfile) override;

View File

@ -1430,12 +1430,6 @@ psymbol_functions::find_compunit_symtab_by_address (struct objfile *objfile,
return psymtab_to_symtab (objfile, iter->second);
}
quick_symbol_functions_up
make_psymbol_functions (const std::shared_ptr<psymtab_storage> &storage)
{
return quick_symbol_functions_up (new psymbol_functions (storage));
}
/* Partially fill a partial symtab. It will be completely filled at

View File

@ -145,8 +145,4 @@ private:
gdb::optional<auto_obstack> m_obstack;
};
extern quick_symbol_functions_up make_psymbol_functions
(const std::shared_ptr<psymtab_storage> &);
#endif /* PSYMTAB_H */

View File

@ -902,9 +902,7 @@ syms_from_objfile_1 (struct objfile *objfile,
const int mainline = add_flags & SYMFILE_MAINLINE;
objfile_set_sym_fns (objfile, find_sym_fns (objfile->obfd));
objfile->reset_psymtabs ();
objfile->qf.clear ();
objfile->qf.push_front (make_psymbol_functions (objfile->partial_symtabs));
if (objfile->sf == NULL)
{
@ -2553,10 +2551,7 @@ reread_symbols (void)
based on whether .gdb_index is present, and we need it to
start over. PR symtab/15885 */
objfile_set_sym_fns (objfile, find_sym_fns (objfile->obfd));
objfile->reset_psymtabs ();
objfile->qf.clear ();
objfile->qf.push_front
(make_psymbol_functions (objfile->partial_symtabs));
build_objfile_section_table (objfile);

View File

@ -2946,7 +2946,9 @@ xcoff_initial_scan (struct objfile *objfile, symfile_add_flags symfile_flags)
/* Now that the symbol table data of the executable file are all in core,
process them and define symbols accordingly. */
psymtab_storage *partial_symtabs = objfile->partial_symtabs.get ();
psymbol_functions *psf = new psymbol_functions ();
psymtab_storage *partial_symtabs = psf->get_partial_symtabs ().get ();
objfile->qf.emplace_front (psf);
scan_xcoff_symtab (reader, partial_symtabs, objfile);
/* Install any minimal symbols that have been collected as the current