public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 26/26] Allow multiple partial symbol readers per objfile
Date: Sun, 28 Feb 2021 13:38:03 -0700	[thread overview]
Message-ID: <20210228203803.1693413-27-tom@tromey.com> (raw)
In-Reply-To: <20210228203803.1693413-1-tom@tromey.com>

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-02-28  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.
---
 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/ctfread.c b/gdb/ctfread.c
index 6adfcc12056..ac86e853cbd 100644
--- a/gdb/ctfread.c
+++ b/gdb/ctfread.c
@@ -1495,7 +1495,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 570df071bf7..f197939002b 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -1951,10 +1951,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);
@@ -6348,7 +6346,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;
@@ -6357,29 +6355,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 ();
 
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 @@ struct objfile
 
   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 @@ struct objfile
 
   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.  */
 
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<psymtab_storage> &storage)
-{
-  return quick_symbol_functions_up (new psymbol_functions (storage));
-}
-
 \f
 
 /* 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 @@ class psymtab_storage
   gdb::optional<auto_obstack> m_obstack;
 };
 
-
-extern quick_symbol_functions_up make_psymbol_functions
-     (const std::shared_ptr<psymtab_storage> &);
-
 #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 ee52ba53d92..3354a7b7fd5 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -2945,7 +2945,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.26.2


  parent reply	other threads:[~2021-02-28 20:38 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-28 20:37 [PATCH 00/26] Allow multiple "partial" symtab " Tom Tromey
2021-02-28 20:37 ` [PATCH 01/26] Move some DWARF code out of symfile.h Tom Tromey
2021-02-28 20:37 ` [PATCH 02/26] Introduce dwarf2/public.h Tom Tromey
2021-02-28 20:37 ` [PATCH 03/26] Change objfile_has_partial_symbols to a method Tom Tromey
2021-02-28 20:37 ` [PATCH 04/26] Change objfile::has_partial_symbols to return bool Tom Tromey
2021-02-28 20:37 ` [PATCH 05/26] Introduce method wrappers for quick_symbol_functions Tom Tromey
2021-03-22 13:52   ` Simon Marchi
2021-02-28 20:37 ` [PATCH 06/26] Move quick_symbol_functions to a new header Tom Tromey
2021-02-28 20:37 ` [PATCH 07/26] Move sym_fns::qf to objfile Tom Tromey
2021-02-28 20:37 ` [PATCH 08/26] Convert quick_symbol_functions to use methods Tom Tromey
2021-02-28 20:37 ` [PATCH 09/26] Move psymbol_map out of objfile Tom Tromey
2021-02-28 20:37 ` [PATCH 10/26] Change how some psymbol readers access the psymtab storage Tom Tromey
2021-02-28 20:37 ` [PATCH 11/26] Do not pass objfile to psymtab_discarder Tom Tromey
2021-02-28 20:37 ` [PATCH 12/26] Set per_bfd->partial_symtabs earlier Tom Tromey
2021-02-28 20:37 ` [PATCH 13/26] Change how DWARF indices use addrmap Tom Tromey
2021-02-28 20:37 ` [PATCH 14/26] Move psymtab statistics printing to psymtab.c Tom Tromey
2021-02-28 20:37 ` [PATCH 15/26] Change how DWARF index writer finds address map Tom Tromey
2021-02-28 20:37 ` [PATCH 16/26] Reference psymtabs via per_bfd in DWARF reader Tom Tromey
2021-02-28 20:37 ` [PATCH 17/26] Attach partial symtab storage to psymbol_functions Tom Tromey
2021-02-28 20:37 ` [PATCH 18/26] Rearrange psymtab_storage construction Tom Tromey
2021-02-28 20:37 ` [PATCH 19/26] Remove sym_fns::sym_read_psymbols Tom Tromey
2021-02-28 20:37 ` [PATCH 20/26] Introduce objfile::require_partial_symbols Tom Tromey
2021-02-28 20:37 ` [PATCH 21/26] Add partial_symtabs parameter to psymtab construction functions Tom Tromey
2021-02-28 20:37 ` [PATCH 22/26] Remove last objfile partial_symtab references from psymtab.c Tom Tromey
2021-02-28 20:38 ` [PATCH 23/26] Change count_psyms to be a method on psymbol_functions Tom Tromey
2021-02-28 20:38 ` [PATCH 24/26] Remove objfile::psymtabs Tom Tromey
2021-02-28 20:38 ` [PATCH 25/26] Switch objfile to hold a list of psymbol readers Tom Tromey
2021-02-28 20:38 ` Tom Tromey [this message]
2021-03-20 23:33 ` [PATCH 00/26] Allow multiple "partial" symtab readers per objfile Tom Tromey
2021-03-22 14:13   ` Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210228203803.1693413-27-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).