From eb36a3eb2f846b8d4b16c1bb114136961d0ce5bf Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sat, 20 Mar 2021 17:23:40 -0600 Subject: 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 * 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) : Remove. : 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. --- gdb/dwarf2/public.h | 4 +++- gdb/dwarf2/read.c | 34 ++++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 15 deletions(-) (limited to 'gdb/dwarf2') diff --git a/gdb/dwarf2/public.h b/gdb/dwarf2/public.h index 6b0fe08..e6653f4 100644 --- a/gdb/dwarf2/public.h +++ b/gdb/dwarf2/public.h @@ -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 (); diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 9453848..acbc5fa 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -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 (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 &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 (); -- cgit v1.1