From eb36a3eb2f846b8d4b16c1bb114136961d0ce5bf Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sat, 20 Mar 2021 17:23:40 -0600 Subject: [PATCH] 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/ChangeLog | 24 ++++++++++++++++++++++++ gdb/ctfread.c | 4 +++- gdb/dbxread.c | 4 +++- gdb/dwarf2/public.h | 4 +++- gdb/dwarf2/read.c | 34 ++++++++++++++++++++-------------- gdb/elfread.c | 19 +++---------------- gdb/mdebugread.c | 4 +++- gdb/objfiles.h | 11 ----------- gdb/psympriv.h | 5 +++++ gdb/psymtab.c | 6 ------ gdb/psymtab.h | 4 ---- gdb/symfile.c | 5 ----- gdb/xcoffread.c | 4 +++- 13 files changed, 67 insertions(+), 61 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index e87cb76e825..03235e98d72 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,27 @@ +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. + 2021-03-20 Tom Tromey * dwarf2/read.c (dwarf2_build_psymtabs): Update. diff --git a/gdb/ctfread.c b/gdb/ctfread.c index 7713500c1fe..616464c77df 100644 --- a/gdb/ctfread.c +++ b/gdb/ctfread.c @@ -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); } diff --git a/gdb/dbxread.c b/gdb/dbxread.c index a6f44d5a564..99a36cafa15 100644 --- a/gdb/dbxread.c +++ b/gdb/dbxread.c @@ -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 diff --git a/gdb/dwarf2/public.h b/gdb/dwarf2/public.h index 6b0fe0874b2..e6653f4f38d 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 94538484fd7..acbc5fa1ad1 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 (); diff --git a/gdb/elfread.c b/gdb/elfread.c index 1cf9b2addc4..85100875347 100644 --- a/gdb/elfread.c +++ b/gdb/elfread.c @@ -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 diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c index 34ee718e22a..7bf4564aecb 100644 --- a/gdb/mdebugread.c +++ b/gdb/mdebugread.c @@ -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 diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 2f566709eb2..41f8fc913d8 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -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 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 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. */ diff --git a/gdb/psympriv.h b/gdb/psympriv.h index b6139111b6e..bbae2fc90e4 100644 --- a/gdb/psympriv.h +++ b/gdb/psympriv.h @@ -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; diff --git a/gdb/psymtab.c b/gdb/psymtab.c index 785eda04c9e..597817269c1 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -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 &storage) -{ - return quick_symbol_functions_up (new psymbol_functions (storage)); -} - /* Partially fill a partial symtab. It will be completely filled at diff --git a/gdb/psymtab.h b/gdb/psymtab.h index e19cac64aa4..522ccf3a12a 100644 --- a/gdb/psymtab.h +++ b/gdb/psymtab.h @@ -145,8 +145,4 @@ private: gdb::optional m_obstack; }; - -extern quick_symbol_functions_up make_psymbol_functions - (const std::shared_ptr &); - #endif /* PSYMTAB_H */ diff --git a/gdb/symfile.c b/gdb/symfile.c index 244565f8f47..adcdc169306 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -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); diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c index f8d428127da..30ac876e8e3 100644 --- a/gdb/xcoffread.c +++ b/gdb/xcoffread.c @@ -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 -- 2.30.2