public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 00/26] Allow multiple "partial" symtab readers per objfile
@ 2021-02-28 20:37 Tom Tromey
  2021-02-28 20:37 ` [PATCH 01/26] Move some DWARF code out of symfile.h Tom Tromey
                   ` (26 more replies)
  0 siblings, 27 replies; 30+ messages in thread
From: Tom Tromey @ 2021-02-28 20:37 UTC (permalink / raw)
  To: gdb-patches

Right now, gdb attaches partial symtabs to each objfile, whether the
objfile needs them or not.  Furthermore, multiple symbol readers can
create partial symbols, and they must all share the same storage.
This latter restriction affects the DWARF reader -- it can't share
psymtabs if some other reader has created them.

This series lifts these restrictions.  At the end, an objfile can have
any number of "partial symbol" (really the so-called "quick"
functions) readers, even zero.  Each reader is separate, and so the
restrictions on sharing of DWARF partial symbols are lifted.

I used my script to regression test each patch here on x86-64 Fedora 32.

Tom



^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 01/26] Move some DWARF code out of symfile.h
  2021-02-28 20:37 [PATCH 00/26] Allow multiple "partial" symtab readers per objfile Tom Tromey
@ 2021-02-28 20:37 ` Tom Tromey
  2021-02-28 20:37 ` [PATCH 02/26] Introduce dwarf2/public.h Tom Tromey
                   ` (25 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: Tom Tromey @ 2021-02-28 20:37 UTC (permalink / raw)
  To: gdb-patches

This moves a bit of the DWARF-specific code out of symfile.h and into
dwarf2/read.h.

gdb/ChangeLog
2021-02-28  Tom Tromey  <tom@tromey.com>

	* symfile.h (enum dwarf2_section_enum)
	(dwarf2_get_section_info): Move to dwarf2/read.h.
	* dwarf2/read.h (enum dwarf2_section_enum)
	(dwarf2_get_section_info): Move from symfile.h.
---
 gdb/ChangeLog     |  7 +++++++
 gdb/dwarf2/read.h | 11 +++++++++++
 gdb/symfile.h     | 11 -----------
 3 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index c7f6a111b8c..fbcd8ad0380 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -694,4 +694,15 @@ struct type *dwarf2_fetch_die_type_sect_off
 /* When non-zero, dump line number entries as they are read in.  */
 extern unsigned int dwarf_line_debug;
 
+/* Dwarf2 sections that can be accessed by dwarf2_get_section_info.  */
+enum dwarf2_section_enum {
+  DWARF2_DEBUG_FRAME,
+  DWARF2_EH_FRAME
+};
+
+extern void dwarf2_get_section_info (struct objfile *,
+                                     enum dwarf2_section_enum,
+				     asection **, const gdb_byte **,
+				     bfd_size_type *);
+
 #endif /* DWARF2READ_H */
diff --git a/gdb/symfile.h b/gdb/symfile.h
index 23e2ad8c3a9..b7e2009b669 100644
--- a/gdb/symfile.h
+++ b/gdb/symfile.h
@@ -603,17 +603,6 @@ extern int dwarf2_has_info (struct objfile *,
 			    const struct dwarf2_debug_sections *,
 			    bool = false);
 
-/* Dwarf2 sections that can be accessed by dwarf2_get_section_info.  */
-enum dwarf2_section_enum {
-  DWARF2_DEBUG_FRAME,
-  DWARF2_EH_FRAME
-};
-
-extern void dwarf2_get_section_info (struct objfile *,
-				     enum dwarf2_section_enum,
-				     asection **, const gdb_byte **,
-				     bfd_size_type *);
-
 /* A DWARF names index variant.  */
 enum class dw_index_kind
 {
-- 
2.26.2


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 02/26] Introduce dwarf2/public.h
  2021-02-28 20:37 [PATCH 00/26] Allow multiple "partial" symtab readers per objfile 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 ` Tom Tromey
  2021-02-28 20:37 ` [PATCH 03/26] Change objfile_has_partial_symbols to a method Tom Tromey
                   ` (24 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: Tom Tromey @ 2021-02-28 20:37 UTC (permalink / raw)
  To: gdb-patches

This moves some more DWARF code out of symfile.h and into a new
header, dwarf2/public.h.  This header is intended to describe the
public API of the DWARF reader.

gdb/ChangeLog
2021-02-28  Tom Tromey  <tom@tromey.com>

	* coffread.c: Include dwarf2/public.h.
	* dwarf2/frame.c: Include dwarf2/public.h.
	* dwarf2/index-write.h: Include dwarf2/public.h, not symfile.h.
	* dwarf2/public.h: New file.
	* dwarf2/read.c: Include dwarf2/public.h.
	* elfread.c: Include dwarf2/public.h.
	* machoread.c: Include dwarf2/public.h.
	* symfile.h (dwarf2_has_info, enum dw_index_kind)
	(dwarf2_initialize_objfile, dwarf2_build_psymtabs)
	(dwarf2_build_frame_info): Move to dwarf2/public.h.
	* xcoffread.c: Include dwarf2/public.h.
---
 gdb/ChangeLog            | 14 ++++++++++++
 gdb/coffread.c           |  1 +
 gdb/dwarf2/frame.c       |  1 +
 gdb/dwarf2/index-write.h |  2 +-
 gdb/dwarf2/public.h      | 46 ++++++++++++++++++++++++++++++++++++++++
 gdb/dwarf2/read.c        |  1 +
 gdb/elfread.c            |  1 +
 gdb/machoread.c          |  1 +
 gdb/symfile.h            | 23 --------------------
 gdb/xcoffread.c          |  1 +
 10 files changed, 67 insertions(+), 24 deletions(-)
 create mode 100644 gdb/dwarf2/public.h

diff --git a/gdb/coffread.c b/gdb/coffread.c
index 49a2485d38c..d15ba6593fc 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -36,6 +36,7 @@
 #include "target.h"
 #include "block.h"
 #include "dictionary.h"
+#include "dwarf2/public.h"
 
 #include "coff-pe-read.h"
 
diff --git a/gdb/dwarf2/frame.c b/gdb/dwarf2/frame.c
index 4d62b197d3a..f8612c96f27 100644
--- a/gdb/dwarf2/frame.c
+++ b/gdb/dwarf2/frame.c
@@ -37,6 +37,7 @@
 #include "complaints.h"
 #include "dwarf2/frame.h"
 #include "dwarf2/read.h"
+#include "dwarf2/public.h"
 #include "ax.h"
 #include "dwarf2/loc.h"
 #include "dwarf2/frame-tailcall.h"
diff --git a/gdb/dwarf2/index-write.h b/gdb/dwarf2/index-write.h
index 5f6761c91a7..27f1f03cd8b 100644
--- a/gdb/dwarf2/index-write.h
+++ b/gdb/dwarf2/index-write.h
@@ -20,8 +20,8 @@
 #ifndef DWARF_INDEX_WRITE_H
 #define DWARF_INDEX_WRITE_H
 
-#include "symfile.h"
 #include "dwarf2/read.h"
+#include "dwarf2/public.h"
 
 /* Create index files for OBJFILE in the directory DIR.
 
diff --git a/gdb/dwarf2/public.h b/gdb/dwarf2/public.h
new file mode 100644
index 00000000000..d0182d4e673
--- /dev/null
+++ b/gdb/dwarf2/public.h
@@ -0,0 +1,46 @@
+/* Public API for gdb DWARF reader
+
+   Copyright (C) 2021 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef DWARF2_PUBLIC_H
+#define DWARF2_PUBLIC_H
+
+extern int dwarf2_has_info (struct objfile *,
+                            const struct dwarf2_debug_sections *,
+			    bool = false);
+
+/* A DWARF names index variant.  */
+enum class dw_index_kind
+{
+  /* GDB's own .gdb_index format.   */
+  GDB_INDEX,
+
+  /* DWARF5 .debug_names.  */
+  DEBUG_NAMES,
+};
+
+/* Initialize for reading DWARF for OBJFILE.  Return false if this
+   file will use psymtabs, or true if using an index, in which case
+   *INDEX_KIND is set to the index variant in use.  */
+extern bool dwarf2_initialize_objfile (struct objfile *objfile,
+				       dw_index_kind *index_kind);
+
+extern void dwarf2_build_psymtabs (struct objfile *);
+extern void dwarf2_build_frame_info (struct objfile *);
+
+#endif /* DWARF2_PUBLIC_H */
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 7ab5d719004..3c25f4efba6 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -41,6 +41,7 @@
 #include "dwarf2/macro.h"
 #include "dwarf2/die.h"
 #include "dwarf2/stringify.h"
+#include "dwarf2/public.h"
 #include "bfd.h"
 #include "elf-bfd.h"
 #include "symtab.h"
diff --git a/gdb/elfread.c b/gdb/elfread.c
index ce63d6b4b56..8f06c8edc79 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -51,6 +51,7 @@
 #include "gdbsupport/gdb_string_view.h"
 #include "gdbsupport/scoped_fd.h"
 #include "debuginfod-support.h"
+#include "dwarf2/public.h"
 
 /* Forward declarations.  */
 extern const struct sym_fns elf_sym_fns_gdb_index;
diff --git a/gdb/machoread.c b/gdb/machoread.c
index 0ff61e12f5a..ff50ae54f2a 100644
--- a/gdb/machoread.c
+++ b/gdb/machoread.c
@@ -32,6 +32,7 @@
 #include "gdb_bfd.h"
 #include <string>
 #include <algorithm>
+#include "dwarf2/public.h"
 
 /* If non-zero displays debugging message.  */
 static unsigned int mach_o_debug_level = 0;
diff --git a/gdb/symfile.h b/gdb/symfile.h
index b7e2009b669..882f17be027 100644
--- a/gdb/symfile.h
+++ b/gdb/symfile.h
@@ -599,29 +599,6 @@ struct dwarf2_debug_sections {
   int sentinel;
 };
 
-extern int dwarf2_has_info (struct objfile *,
-			    const struct dwarf2_debug_sections *,
-			    bool = false);
-
-/* A DWARF names index variant.  */
-enum class dw_index_kind
-{
-  /* GDB's own .gdb_index format.   */
-  GDB_INDEX,
-
-  /* DWARF5 .debug_names.  */
-  DEBUG_NAMES,
-};
-
-/* Initialize for reading DWARF for OBJFILE.  Return false if this
-   file will use psymtabs, or true if using an index, in which case
-   *INDEX_KIND is set to the index variant in use.  */
-extern bool dwarf2_initialize_objfile (struct objfile *objfile,
-				       dw_index_kind *index_kind);
-
-extern void dwarf2_build_psymtabs (struct objfile *);
-extern void dwarf2_build_frame_info (struct objfile *);
-
 /* From minidebug.c.  */
 
 extern gdb_bfd_ref_ptr find_separate_debug_file_in_section (struct objfile *);
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index cd93943a812..6dab4e59234 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -47,6 +47,7 @@
 #include "expression.h"
 #include "complaints.h"
 #include "psympriv.h"
+#include "dwarf2/public.h"
 
 #include "gdb-stabs.h"
 
-- 
2.26.2


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 03/26] Change objfile_has_partial_symbols to a method
  2021-02-28 20:37 [PATCH 00/26] Allow multiple "partial" symtab readers per objfile 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 ` Tom Tromey
  2021-02-28 20:37 ` [PATCH 04/26] Change objfile::has_partial_symbols to return bool Tom Tromey
                   ` (23 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: Tom Tromey @ 2021-02-28 20:37 UTC (permalink / raw)
  To: gdb-patches

This changes objfile_has_partial_symbols to be a method on objfile.

There are some other functions that could benefit from this sort of
change, but this was the only one that was relevant to this series.

gdb/ChangeLog
2021-02-28  Tom Tromey  <tom@tromey.com>

	* symfile.c (read_symbols): Update.
	* objfiles.h (struct objfile) <has_partial_symbols>: New method.
	(objfile_has_partial_symbols): Don't declare.
	* objfiles.c (objfile::has_partial_symbols): Rename from
	objfile_has_partial_symbols.
	(objfile_has_symbols, have_partial_symbols): Update.
	* elfread.c (elf_symfile_read): Update.
	* dwarf2/read.c (dwarf2_has_info): Update.
	* coffread.c (coff_symfile_read): Update.
---
 gdb/ChangeLog     | 12 ++++++++++++
 gdb/coffread.c    |  2 +-
 gdb/dwarf2/read.c |  2 +-
 gdb/elfread.c     |  6 +++---
 gdb/objfiles.c    | 16 ++++++++--------
 gdb/objfiles.h    |  5 +++--
 gdb/symfile.c     |  2 +-
 7 files changed, 29 insertions(+), 16 deletions(-)

diff --git a/gdb/coffread.c b/gdb/coffread.c
index d15ba6593fc..badcb5a6084 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -708,7 +708,7 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
   dwarf2_build_frame_info (objfile);
 
   /* Try to add separate debug file if no symbols table found.   */
-  if (!objfile_has_partial_symbols (objfile))
+  if (!objfile->has_partial_symbols ())
     {
       std::string debugfile = find_separate_debug_file_by_buildid (objfile);
 
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 3c25f4efba6..02176e8da8f 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -1953,7 +1953,7 @@ dwarf2_has_info (struct objfile *objfile,
       /* 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 (objfile)
+      if (!objfile->has_partial_symbols ()
 	  && !gdb_bfd_requires_relocations (objfile->obfd))
 	{
 	  /* See if one has been created for this BFD yet.  */
diff --git a/gdb/elfread.c b/gdb/elfread.c
index 8f06c8edc79..439f5cc29a0 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -1266,7 +1266,7 @@ elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
       /* 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 (objfile)
+      if (!objfile->has_partial_symbols ()
 	  && dwarf2_initialize_objfile (objfile, &index_kind))
 	{
 	  switch (index_kind)
@@ -1293,14 +1293,14 @@ elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
      SYMTABS/PSYMTABS.  `.gnu_debuglink' may no longer be present with
      `.note.gnu.build-id'.
 
-     .gnu_debugdata is !objfile_has_partial_symbols because it contains only
+     .gnu_debugdata is !objfile::has_partial_symbols because it contains only
      .symtab, not .debug_* section.  But if we already added .gnu_debugdata as
      an objfile via find_separate_debug_file_in_section there was no separate
      debug info available.  Therefore do not attempt to search for another one,
      objfile->separate_debug_objfile->separate_debug_objfile GDB guarantees to
      be NULL and we would possibly violate it.  */
 
-  else if (!objfile_has_partial_symbols (objfile)
+  else if (!objfile->has_partial_symbols ()
 	   && objfile->separate_debug_objfile == NULL
 	   && objfile->separate_debug_objfile_backlink == NULL)
     {
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 2a513d82f1a..53ca66d17e6 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -810,23 +810,23 @@ objfile_rebase (struct objfile *objfile, CORE_ADDR slide)
     breakpoint_re_set ();
 }
 \f
-/* Return non-zero if OBJFILE has partial symbols.  */
+/* See objfiles.h.  */
 
 int
-objfile_has_partial_symbols (struct objfile *objfile)
+objfile::has_partial_symbols ()
 {
-  if (!objfile->sf)
+  if (!sf)
     return 0;
 
   /* If we have not read psymbols, but we have a function capable of reading
      them, then that is an indication that they are in fact available.  Without
      this function the symbols may have been already read in but they also may
      not be present in this objfile.  */
-  if ((objfile->flags & OBJF_PSYMTABS_READ) == 0
-      && objfile->sf->sym_read_psymbols != NULL)
+  if ((flags & OBJF_PSYMTABS_READ) == 0
+      && sf->sym_read_psymbols != NULL)
     return 1;
 
-  return objfile->sf->qf->has_symbols (objfile);
+  return sf->qf->has_symbols (this);
 }
 
 /* Return non-zero if OBJFILE has full symbols.  */
@@ -844,7 +844,7 @@ int
 objfile_has_symbols (struct objfile *objfile)
 {
   for (::objfile *o : objfile->separate_debug_objfiles ())
-    if (objfile_has_partial_symbols (o) || objfile_has_full_symbols (o))
+    if (o->has_partial_symbols () || objfile_has_full_symbols (o))
       return 1;
   return 0;
 }
@@ -859,7 +859,7 @@ have_partial_symbols (void)
 {
   for (objfile *ofp : current_program_space->objfiles ())
     {
-      if (objfile_has_partial_symbols (ofp))
+      if (ofp->has_partial_symbols ())
 	return 1;
     }
   return 0;
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 052f109db4d..0568e16ae4c 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -548,6 +548,9 @@ struct objfile
     return per_bfd->gdbarch;
   }
 
+  /* Return true if OBJFILE has partial symbols.  */
+
+  int has_partial_symbols ();
 
   /* The object file's original name as specified by the user,
      made absolute, and tilde-expanded.  However, it is not canonicalized
@@ -738,8 +741,6 @@ extern void free_objfile_separate_debug (struct objfile *);
 extern void objfile_relocate (struct objfile *, const section_offsets &);
 extern void objfile_rebase (struct objfile *, CORE_ADDR);
 
-extern int objfile_has_partial_symbols (struct objfile *objfile);
-
 extern int objfile_has_full_symbols (struct objfile *objfile);
 
 extern int objfile_has_symbols (struct objfile *objfile);
diff --git a/gdb/symfile.c b/gdb/symfile.c
index ec5d34ac783..34d6363a91a 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -775,7 +775,7 @@ read_symbols (struct objfile *objfile, symfile_add_flags add_flags)
 
   /* find_separate_debug_file_in_section should be called only if there is
      single binary with no existing separate debug info file.  */
-  if (!objfile_has_partial_symbols (objfile)
+  if (!objfile->has_partial_symbols ()
       && objfile->separate_debug_objfile == NULL
       && objfile->separate_debug_objfile_backlink == NULL)
     {
-- 
2.26.2


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 04/26] Change objfile::has_partial_symbols to return bool
  2021-02-28 20:37 [PATCH 00/26] Allow multiple "partial" symtab readers per objfile Tom Tromey
                   ` (2 preceding siblings ...)
  2021-02-28 20:37 ` [PATCH 03/26] Change objfile_has_partial_symbols to a method Tom Tromey
@ 2021-02-28 20:37 ` Tom Tromey
  2021-02-28 20:37 ` [PATCH 05/26] Introduce method wrappers for quick_symbol_functions Tom Tromey
                   ` (22 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: Tom Tromey @ 2021-02-28 20:37 UTC (permalink / raw)
  To: gdb-patches

This changes objfile::has_partial_symbols and
quick_symbol_functions::has_symbols to return bool.

gdb/ChangeLog
2021-02-28  Tom Tromey  <tom@tromey.com>

	* objfiles.h (struct objfile) <has_partial_symbols>: Return bool.
	* symfile.h (struct quick_symbol_functions) <has_symbols>: Return
	bool.
	* symfile-debug.c (debug_qf_has_symbols): Return bool.
	* psymtab.c (psym_has_symbols): Return bool.
	* objfiles.c (objfile::has_partial_symbols): Return bool.
	* dwarf2/read.c (dw2_has_symbols): Return bool.
---
 gdb/ChangeLog       | 10 ++++++++++
 gdb/dwarf2/read.c   |  4 ++--
 gdb/objfiles.c      |  6 +++---
 gdb/objfiles.h      |  2 +-
 gdb/psymtab.c       |  2 +-
 gdb/symfile-debug.c |  4 ++--
 gdb/symfile.h       |  2 +-
 7 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 02176e8da8f..7e55a0ec486 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -5115,10 +5115,10 @@ dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun,
     });
 }
 
-static int
+static bool
 dw2_has_symbols (struct objfile *objfile)
 {
-  return 1;
+  return true;
 }
 
 const struct quick_symbol_functions dwarf2_gdb_index_functions =
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 53ca66d17e6..746f7d1f296 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -812,11 +812,11 @@ objfile_rebase (struct objfile *objfile, CORE_ADDR slide)
 \f
 /* See objfiles.h.  */
 
-int
+bool
 objfile::has_partial_symbols ()
 {
   if (!sf)
-    return 0;
+    return false;
 
   /* If we have not read psymbols, but we have a function capable of reading
      them, then that is an indication that they are in fact available.  Without
@@ -824,7 +824,7 @@ objfile::has_partial_symbols ()
      not be present in this objfile.  */
   if ((flags & OBJF_PSYMTABS_READ) == 0
       && sf->sym_read_psymbols != NULL)
-    return 1;
+    return true;
 
   return sf->qf->has_symbols (this);
 }
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 0568e16ae4c..f961bdc0116 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -550,7 +550,7 @@ struct objfile
 
   /* Return true if OBJFILE has partial symbols.  */
 
-  int has_partial_symbols ();
+  bool has_partial_symbols ();
 
   /* The object file's original name as specified by the user,
      made absolute, and tilde-expanded.  However, it is not canonicalized
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 7f41c010e39..94b5acdea54 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -1334,7 +1334,7 @@ psym_expand_symtabs_matching
 /* Psymtab version of has_symbols.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
-static int
+static bool
 psym_has_symbols (struct objfile *objfile)
 {
   return objfile->partial_symtabs->psymtabs != NULL;
diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index 2929af81c37..7c022ae341d 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -70,12 +70,12 @@ debug_symtab_name (struct symtab *symtab)
 \f
 /* Debugging version of struct quick_symbol_functions.  */
 
-static int
+static bool
 debug_qf_has_symbols (struct objfile *objfile)
 {
   const struct debug_sym_fns_data *debug_data
     = symfile_debug_objfile_data_key.get (objfile);
-  int retval;
+  bool retval;
 
   retval = debug_data->real_sf->qf->has_symbols (objfile);
 
diff --git a/gdb/symfile.h b/gdb/symfile.h
index 882f17be027..facffeab810 100644
--- a/gdb/symfile.h
+++ b/gdb/symfile.h
@@ -150,7 +150,7 @@ struct quick_symbol_functions
 {
   /* Return true if this objfile has any "partial" symbols
      available.  */
-  int (*has_symbols) (struct objfile *objfile);
+  bool (*has_symbols) (struct objfile *objfile);
 
   /* Return the symbol table for the "last" file appearing in
      OBJFILE.  */
-- 
2.26.2


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 05/26] Introduce method wrappers for quick_symbol_functions
  2021-02-28 20:37 [PATCH 00/26] Allow multiple "partial" symtab readers per objfile Tom Tromey
                   ` (3 preceding siblings ...)
  2021-02-28 20:37 ` [PATCH 04/26] Change objfile::has_partial_symbols to return bool Tom Tromey
@ 2021-02-28 20:37 ` 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
                   ` (21 subsequent siblings)
  26 siblings, 1 reply; 30+ messages in thread
From: Tom Tromey @ 2021-02-28 20:37 UTC (permalink / raw)
  To: gdb-patches

This introduces wrappers for each function in quick_symbol_functions.
The wrappers are methods on objfile, and are defined in
symfile-debug.c, so that they can use the symfile_debug variable.
Places that call the quick functions are all updated to call these new
wrapper methods.

gdb/ChangeLog
2021-02-28  Tom Tromey  <tom@tromey.com>

	* symtab.c (iterate_over_symtabs, expand_symtab_containing_pc)
	(lookup_symbol_via_quick_fns, find_quick_global_symbol_language)
	(basic_lookup_transparent_type_quick)
	(find_pc_sect_compunit_symtab, find_symbol_at_address)
	(find_line_symtab, global_symbol_searcher::expand_symtabs):
	Update.
	* symmisc.c (print_objfile_statistics, dump_objfile)
	(maintenance_expand_symtabs): Update.
	* symfile.c (symbol_file_add_with_addrs)
	(expand_symtabs_matching, map_symbol_filenames): Update.
	* symfile-debug.c (objfile::has_partial_symbols)
	(objfile::find_last_source_symtab)
	(objfile::forget_cached_source_info)
	(objfile::map_symtabs_matching_filename, objfile::lookup_symbol)
	(objfile::print_stats, objfile::dump)
	(objfile::expand_symtabs_for_function)
	(objfile::expand_all_symtabs)
	(objfile::expand_symtabs_with_fullname)
	(objfile::map_matching_symbols)
	(objfile::expand_symtabs_matching)
	(objfile::find_pc_sect_compunit_symtab)
	(objfile::map_symbol_filenames)
	(objfile::find_compunit_symtab_by_address)
	(objfile::lookup_global_symbol_language): New methods.
	(debug_sym_quick_functions): Remove.
	(debug_sym_fns, install_symfile_debug_logging): Update.
	* source.c (forget_cached_source_info_for_objfile)
	(select_source_symtab): Update.
	* objfiles.h (struct objfile): Add methods corresponding to
	quick_symbol_functions.
	* objfiles.c (objfile::has_partial_symbols): Move to
	symfile-debug.c.
	* linespec.c (iterate_over_all_matching_symtabs): Update.
	* cp-support.c (add_symbol_overload_list_qualified): Update.
	* ada-lang.c (add_nonlocal_symbols): Update.
---
 gdb/ChangeLog       |  38 ++++
 gdb/ada-lang.c      |  11 +-
 gdb/cp-support.c    |   5 +-
 gdb/linespec.c      |   8 +-
 gdb/objfiles.c      |  19 --
 gdb/objfiles.h      |  69 +++++++-
 gdb/source.c        |   6 +-
 gdb/symfile-debug.c | 418 +++++++++++++++++++++-----------------------
 gdb/symfile.c       |  20 +--
 gdb/symmisc.c       |  34 ++--
 gdb/symtab.c        | 106 ++++-------
 11 files changed, 368 insertions(+), 366 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 419347f776d..17b0aca2d8d 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -5629,10 +5629,8 @@ add_nonlocal_symbols (struct obstack *obstackp,
     {
       data.objfile = objfile;
 
-      objfile->sf->qf->map_matching_symbols (objfile, lookup_name,
-					     domain, global, callback,
-					     (is_wild_match
-					      ? NULL : compare_names));
+      objfile->map_matching_symbols (lookup_name, domain, global, callback,
+				     is_wild_match ? NULL : compare_names);
 
       for (compunit_symtab *cu : objfile->compunits ())
 	{
@@ -5654,9 +5652,8 @@ add_nonlocal_symbols (struct obstack *obstackp,
       for (objfile *objfile : current_program_space->objfiles ())
 	{
 	  data.objfile = objfile;
-	  objfile->sf->qf->map_matching_symbols (objfile, name1,
-						 domain, global, callback,
-						 compare_names);
+	  objfile->map_matching_symbols (name1, domain, global, callback,
+					 compare_names);
 	}
     }      	
 }
diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index 1abc3e22a72..45fe834aa03 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -1452,10 +1452,7 @@ add_symbol_overload_list_qualified (const char *func_name,
      matching FUNC_NAME.  Make sure we read that symbol table in.  */
 
   for (objfile *objf : current_program_space->objfiles ())
-    {
-      if (objf->sf)
-	objf->sf->qf->expand_symtabs_for_function (objf, func_name);
-    }
+    objf->expand_symtabs_for_function (func_name);
 
   /* Search upwards from currently selected frame (so that we can
      complete on local vars.  */
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 9bfa159514e..c7dbd3eeae2 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -1168,12 +1168,8 @@ iterate_over_all_matching_symtabs
 
       for (objfile *objfile : current_program_space->objfiles ())
 	{
-	  if (objfile->sf)
-	    objfile->sf->qf->expand_symtabs_matching (objfile,
-						      NULL,
-						      &lookup_name,
-						      NULL, NULL,
-						      search_domain);
+	  objfile->expand_symtabs_matching (NULL, &lookup_name, NULL, NULL,
+					    search_domain);
 
 	  for (compunit_symtab *cu : objfile->compunits ())
 	    {
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 746f7d1f296..f18f6158fc3 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -810,25 +810,6 @@ objfile_rebase (struct objfile *objfile, CORE_ADDR slide)
     breakpoint_re_set ();
 }
 \f
-/* See objfiles.h.  */
-
-bool
-objfile::has_partial_symbols ()
-{
-  if (!sf)
-    return false;
-
-  /* If we have not read psymbols, but we have a function capable of reading
-     them, then that is an indication that they are in fact available.  Without
-     this function the symbols may have been already read in but they also may
-     not be present in this objfile.  */
-  if ((flags & OBJF_PSYMTABS_READ) == 0
-      && sf->sym_read_psymbols != NULL)
-    return true;
-
-  return sf->qf->has_symbols (this);
-}
-
 /* Return non-zero if OBJFILE has full symbols.  */
 
 int
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index f961bdc0116..c55f0f174fc 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -415,8 +415,8 @@ class separate_debug_range
 
    GDB typically reads symbols twice -- first an initial scan which just
    reads "partial symbols"; these are partial information for the
-   static/global symbols in a symbol file.  When later looking up symbols,
-   objfile->sf->qf->lookup_symbol is used to check if we only have a partial
+   static/global symbols in a symbol file.  When later looking up
+   symbols, lookup_symbol is used to check if we only have a partial
    symbol and if so, read and expand the full compunit.  */
 
 struct objfile
@@ -552,6 +552,71 @@ struct objfile
 
   bool has_partial_symbols ();
 
+  /* See quick_symbol_functions.  */
+  struct symtab *find_last_source_symtab ();
+
+  /* See quick_symbol_functions.  */
+  void forget_cached_source_info ();
+
+  /* See quick_symbol_functions.  */
+  bool map_symtabs_matching_filename
+    (const char *name, const char *real_path,
+     gdb::function_view<bool (symtab *)> callback);
+
+  /* See quick_symbol_functions.  */
+  struct compunit_symtab *lookup_symbol (block_enum kind, const char *name,
+					 domain_enum domain);
+
+  /* See quick_symbol_functions.  */
+  void print_stats ();
+
+  /* See quick_symbol_functions.  */
+  void dump ();
+
+  /* See quick_symbol_functions.  */
+  void expand_symtabs_for_function (const char *func_name);
+
+  /* See quick_symbol_functions.  */
+  void expand_all_symtabs ();
+
+  /* See quick_symbol_functions.  */
+  void expand_symtabs_with_fullname (const char *fullname);
+
+  /* See quick_symbol_functions.  */
+  void map_matching_symbols
+    (const lookup_name_info &name, domain_enum domain,
+     int global,
+     gdb::function_view<symbol_found_callback_ftype> callback,
+     symbol_compare_ftype *ordered_compare);
+
+  /* See quick_symbol_functions.  */
+  void expand_symtabs_matching
+    (gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
+     const lookup_name_info *lookup_name,
+     gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
+     gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
+     enum search_domain kind);
+
+  /* See quick_symbol_functions.  */
+  struct compunit_symtab *find_pc_sect_compunit_symtab
+    (struct bound_minimal_symbol msymbol,
+     CORE_ADDR pc,
+     struct obj_section *section,
+     int warn_if_readin);
+
+  /* See quick_symbol_functions.  */
+  void map_symbol_filenames (symbol_filename_ftype *fun, void *data,
+			     int need_fullname);
+
+  /* See quick_symbol_functions.  */
+  struct compunit_symtab *find_compunit_symtab_by_address (CORE_ADDR address);
+
+  /* See quick_symbol_functions.  */
+  enum language lookup_global_symbol_language (const char *name,
+					       domain_enum domain,
+					       bool *symbol_found_p);
+
+
   /* The object file's original name as specified by the user,
      made absolute, and tilde-expanded.  However, it is not canonicalized
      (i.e., it has not been passed through gdb_realpath).
diff --git a/gdb/source.c b/gdb/source.c
index 3a8f829759b..6fc27ae72f7 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -342,8 +342,7 @@ select_source_symtab (struct symtab *s)
 
   for (objfile *objfile : current_program_space->objfiles ())
     {
-      if (objfile->sf)
-	s = objfile->sf->qf->find_last_source_symtab (objfile);
+      s = objfile->find_last_source_symtab ();
       if (s)
 	new_symtab = s;
     }
@@ -417,8 +416,7 @@ forget_cached_source_info_for_objfile (struct objfile *objfile)
 	}
     }
 
-  if (objfile->sf)
-    objfile->sf->qf->forget_cached_source_info (objfile);
+  objfile->forget_cached_source_info ();
 }
 
 /* See source.h.  */
diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index 7c022ae341d..419f24d2240 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -68,312 +68,296 @@ debug_symtab_name (struct symtab *symtab)
   return symtab_to_filename_for_display (symtab);
 }
 \f
-/* Debugging version of struct quick_symbol_functions.  */
 
-static bool
-debug_qf_has_symbols (struct objfile *objfile)
+/* See objfiles.h.  */
+
+bool
+objfile::has_partial_symbols ()
 {
-  const struct debug_sym_fns_data *debug_data
-    = symfile_debug_objfile_data_key.get (objfile);
-  bool retval;
+  bool retval = false;
 
-  retval = debug_data->real_sf->qf->has_symbols (objfile);
+  /* If we have not read psymbols, but we have a function capable of reading
+     them, then that is an indication that they are in fact available.  Without
+     this function the symbols may have been already read in but they also may
+     not be present in this objfile.  */
+  if ((flags & OBJF_PSYMTABS_READ) == 0
+      && sf != nullptr
+      && sf->sym_read_psymbols != NULL)
+    retval = true;
+  else if (sf != nullptr)
+    retval = sf->qf->has_symbols (this);
 
-  fprintf_filtered (gdb_stdlog, "qf->has_symbols (%s) = %d\n",
-		    objfile_debug_name (objfile), retval);
+  if (debug_symfile)
+    fprintf_filtered (gdb_stdlog, "qf->has_symbols (%s) = %d\n",
+		      objfile_debug_name (this), retval);
 
   return retval;
 }
 
-static struct symtab *
-debug_qf_find_last_source_symtab (struct objfile *objfile)
+struct symtab *
+objfile::find_last_source_symtab ()
 {
-  const struct debug_sym_fns_data *debug_data
-    = symfile_debug_objfile_data_key.get (objfile);
-  struct symtab *retval;
+  struct symtab *retval = nullptr;
 
-  fprintf_filtered (gdb_stdlog, "qf->find_last_source_symtab (%s)\n",
-		    objfile_debug_name (objfile));
+  if (debug_symfile)
+    fprintf_filtered (gdb_stdlog, "qf->find_last_source_symtab (%s)\n",
+		      objfile_debug_name (this));
 
-  retval = debug_data->real_sf->qf->find_last_source_symtab (objfile);
+  if (sf != nullptr)
+    retval = sf->qf->find_last_source_symtab (this);
 
-  fprintf_filtered (gdb_stdlog, "qf->find_last_source_symtab (...) = %s\n",
-		    retval ? debug_symtab_name (retval) : "NULL");
+  if (debug_symfile)
+    fprintf_filtered (gdb_stdlog, "qf->find_last_source_symtab (...) = %s\n",
+		      retval ? debug_symtab_name (retval) : "NULL");
 
   return retval;
 }
 
-static void
-debug_qf_forget_cached_source_info (struct objfile *objfile)
+void
+objfile::forget_cached_source_info ()
 {
-  const struct debug_sym_fns_data *debug_data
-    = symfile_debug_objfile_data_key.get (objfile);
-
-  fprintf_filtered (gdb_stdlog, "qf->forget_cached_source_info (%s)\n",
-		    objfile_debug_name (objfile));
+  if (debug_symfile)
+    fprintf_filtered (gdb_stdlog, "qf->forget_cached_source_info (%s)\n",
+		      objfile_debug_name (this));
 
-  debug_data->real_sf->qf->forget_cached_source_info (objfile);
+  if (sf != nullptr)
+    sf->qf->forget_cached_source_info (this);
 }
 
-static bool
-debug_qf_map_symtabs_matching_filename
-  (struct objfile *objfile, const char *name, const char *real_path,
+bool
+objfile::map_symtabs_matching_filename
+  (const char *name, const char *real_path,
    gdb::function_view<bool (symtab *)> callback)
 {
-  const struct debug_sym_fns_data *debug_data
-    = symfile_debug_objfile_data_key.get (objfile);
-
-  fprintf_filtered (gdb_stdlog,
-		    "qf->map_symtabs_matching_filename (%s, \"%s\", \"%s\", %s)\n",
-		    objfile_debug_name (objfile), name,
-		    real_path ? real_path : NULL,
-		    host_address_to_string (&callback));
-
-  bool retval = (debug_data->real_sf->qf->map_symtabs_matching_filename
-		 (objfile, name, real_path, callback));
+  if (debug_symfile)
+    fprintf_filtered (gdb_stdlog,
+		      "qf->map_symtabs_matching_filename (%s, \"%s\", "
+		      "\"%s\", %s)\n",
+		      objfile_debug_name (this), name,
+		      real_path ? real_path : NULL,
+		      host_address_to_string (&callback));
+
+  bool retval = false;
+  if (sf != nullptr)
+    retval = (sf->qf->map_symtabs_matching_filename
+	      (this, name, real_path, callback));
 
-  fprintf_filtered (gdb_stdlog,
-		    "qf->map_symtabs_matching_filename (...) = %d\n",
-		    retval);
+  if (debug_symfile)
+    fprintf_filtered (gdb_stdlog,
+		      "qf->map_symtabs_matching_filename (...) = %d\n",
+		      retval);
 
   return retval;
 }
 
-static struct compunit_symtab *
-debug_qf_lookup_symbol (struct objfile *objfile, block_enum kind,
-			const char *name, domain_enum domain)
+struct compunit_symtab *
+objfile::lookup_symbol (block_enum kind, const char *name, domain_enum domain)
 {
-  const struct debug_sym_fns_data *debug_data
-    = symfile_debug_objfile_data_key.get (objfile);
-  struct compunit_symtab *retval;
+  struct compunit_symtab *retval = nullptr;
 
-  fprintf_filtered (gdb_stdlog,
-		    "qf->lookup_symbol (%s, %d, \"%s\", %s)\n",
-		    objfile_debug_name (objfile), kind, name,
-		    domain_name (domain));
+  if (debug_symfile)
+    fprintf_filtered (gdb_stdlog,
+		      "qf->lookup_symbol (%s, %d, \"%s\", %s)\n",
+		      objfile_debug_name (this), kind, name,
+		      domain_name (domain));
 
-  retval = debug_data->real_sf->qf->lookup_symbol (objfile, kind, name,
-						   domain);
+  if (sf != nullptr)
+    retval = sf->qf->lookup_symbol (this, kind, name, domain);
 
-  fprintf_filtered (gdb_stdlog, "qf->lookup_symbol (...) = %s\n",
-		    retval
-		    ? debug_symtab_name (compunit_primary_filetab (retval))
-		    : "NULL");
+  if (debug_symfile)
+    fprintf_filtered (gdb_stdlog, "qf->lookup_symbol (...) = %s\n",
+		      retval
+		      ? debug_symtab_name (compunit_primary_filetab (retval))
+		      : "NULL");
 
   return retval;
 }
 
-static void
-debug_qf_print_stats (struct objfile *objfile)
+void
+objfile::print_stats ()
 {
-  const struct debug_sym_fns_data *debug_data
-    = symfile_debug_objfile_data_key.get (objfile);
-
-  fprintf_filtered (gdb_stdlog, "qf->print_stats (%s)\n",
-		    objfile_debug_name (objfile));
+  if (debug_symfile)
+    fprintf_filtered (gdb_stdlog, "qf->print_stats (%s)\n",
+		      objfile_debug_name (this));
 
-  debug_data->real_sf->qf->print_stats (objfile);
+  if (sf != nullptr)
+    sf->qf->print_stats (this);
 }
 
-static void
-debug_qf_dump (struct objfile *objfile)
+void
+objfile::dump ()
 {
-  const struct debug_sym_fns_data *debug_data
-    = symfile_debug_objfile_data_key.get (objfile);
-
-  fprintf_filtered (gdb_stdlog, "qf->dump (%s)\n",
-		    objfile_debug_name (objfile));
+  if (debug_symfile)
+    fprintf_filtered (gdb_stdlog, "qf->dump (%s)\n",
+		      objfile_debug_name (this));
 
-  debug_data->real_sf->qf->dump (objfile);
+  if (sf != nullptr)
+    sf->qf->dump (this);
 }
 
-static void
-debug_qf_expand_symtabs_for_function (struct objfile *objfile,
-				      const char *func_name)
+void
+objfile::expand_symtabs_for_function (const char *func_name)
 {
-  const struct debug_sym_fns_data *debug_data
-    = symfile_debug_objfile_data_key.get (objfile);
-
-  fprintf_filtered (gdb_stdlog,
-		    "qf->expand_symtabs_for_function (%s, \"%s\")\n",
-		    objfile_debug_name (objfile), func_name);
+  if (debug_symfile)
+    fprintf_filtered (gdb_stdlog,
+		      "qf->expand_symtabs_for_function (%s, \"%s\")\n",
+		      objfile_debug_name (this), func_name);
 
-  debug_data->real_sf->qf->expand_symtabs_for_function (objfile, func_name);
+  if (sf != nullptr)
+    sf->qf->expand_symtabs_for_function (this, func_name);
 }
 
-static void
-debug_qf_expand_all_symtabs (struct objfile *objfile)
+void
+objfile::expand_all_symtabs ()
 {
-  const struct debug_sym_fns_data *debug_data
-    = symfile_debug_objfile_data_key.get (objfile);
-
-  fprintf_filtered (gdb_stdlog, "qf->expand_all_symtabs (%s)\n",
-		    objfile_debug_name (objfile));
+  if (debug_symfile)
+    fprintf_filtered (gdb_stdlog, "qf->expand_all_symtabs (%s)\n",
+		      objfile_debug_name (this));
 
-  debug_data->real_sf->qf->expand_all_symtabs (objfile);
+  if (sf != nullptr)
+    sf->qf->expand_all_symtabs (this);
 }
 
-static void
-debug_qf_expand_symtabs_with_fullname (struct objfile *objfile,
-				       const char *fullname)
+void
+objfile::expand_symtabs_with_fullname (const char *fullname)
 {
-  const struct debug_sym_fns_data *debug_data
-    = symfile_debug_objfile_data_key.get (objfile);
-
-  fprintf_filtered (gdb_stdlog,
-		    "qf->expand_symtabs_with_fullname (%s, \"%s\")\n",
-		    objfile_debug_name (objfile), fullname);
+  if (debug_symfile)
+    fprintf_filtered (gdb_stdlog,
+		      "qf->expand_symtabs_with_fullname (%s, \"%s\")\n",
+		      objfile_debug_name (this), fullname);
 
-  debug_data->real_sf->qf->expand_symtabs_with_fullname (objfile, fullname);
+  if (sf != nullptr)
+    sf->qf->expand_symtabs_with_fullname (this, fullname);
 }
 
-static void
-debug_qf_map_matching_symbols
-  (struct objfile *objfile,
-   const lookup_name_info &name, domain_enum domain,
+void
+objfile::map_matching_symbols
+  (const lookup_name_info &name, domain_enum domain,
    int global,
    gdb::function_view<symbol_found_callback_ftype> callback,
    symbol_compare_ftype *ordered_compare)
 {
-  const struct debug_sym_fns_data *debug_data
-    = symfile_debug_objfile_data_key.get (objfile);
-
-  fprintf_filtered (gdb_stdlog,
-		    "qf->map_matching_symbols (%s, %s, %d, %s)\n",
-		    objfile_debug_name (objfile),
-		    domain_name (domain), global,
-		    host_address_to_string (ordered_compare));
+  if (debug_symfile)
+    fprintf_filtered (gdb_stdlog,
+		      "qf->map_matching_symbols (%s, %s, %d, %s)\n",
+		      objfile_debug_name (this),
+		      domain_name (domain), global,
+		      host_address_to_string (ordered_compare));
 
-  debug_data->real_sf->qf->map_matching_symbols (objfile, name,
-						 domain, global,
-						 callback,
-						 ordered_compare);
+  if (sf != nullptr)
+    sf->qf->map_matching_symbols (this, name, domain, global,
+				  callback, ordered_compare);
 }
 
-static void
-debug_qf_expand_symtabs_matching
-  (struct objfile *objfile,
-   gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
+void
+objfile::expand_symtabs_matching
+  (gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
    const lookup_name_info *lookup_name,
    gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
    gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
    enum search_domain kind)
 {
-  const struct debug_sym_fns_data *debug_data
-    = symfile_debug_objfile_data_key.get (objfile);
+  if (debug_symfile)
+    fprintf_filtered (gdb_stdlog,
+		      "qf->expand_symtabs_matching (%s, %s, %s, %s, %s)\n",
+		      objfile_debug_name (this),
+		      host_address_to_string (&file_matcher),
+		      host_address_to_string (&symbol_matcher),
+		      host_address_to_string (&expansion_notify),
+		      search_domain_name (kind));
 
-  fprintf_filtered (gdb_stdlog,
-		    "qf->expand_symtabs_matching (%s, %s, %s, %s, %s)\n",
-		    objfile_debug_name (objfile),
-		    host_address_to_string (&file_matcher),
-		    host_address_to_string (&symbol_matcher),
-		    host_address_to_string (&expansion_notify),
-		    search_domain_name (kind));
-
-  debug_data->real_sf->qf->expand_symtabs_matching (objfile,
-						    file_matcher,
-						    lookup_name,
-						    symbol_matcher,
-						    expansion_notify,
-						    kind);
-}
-
-static struct compunit_symtab *
-debug_qf_find_pc_sect_compunit_symtab (struct objfile *objfile,
-				       struct bound_minimal_symbol msymbol,
+  if (sf != nullptr)
+    sf->qf->expand_symtabs_matching (this, file_matcher, lookup_name,
+				     symbol_matcher, expansion_notify, kind);
+}
+
+struct compunit_symtab *
+objfile::find_pc_sect_compunit_symtab (struct bound_minimal_symbol msymbol,
 				       CORE_ADDR pc,
 				       struct obj_section *section,
 				       int warn_if_readin)
 {
-  const struct debug_sym_fns_data *debug_data
-    = symfile_debug_objfile_data_key.get (objfile);
-  struct compunit_symtab *retval;
+  struct compunit_symtab *retval = nullptr;
 
-  fprintf_filtered (gdb_stdlog,
-		    "qf->find_pc_sect_compunit_symtab (%s, %s, %s, %s, %d)\n",
-		    objfile_debug_name (objfile),
-		    host_address_to_string (msymbol.minsym),
-		    hex_string (pc),
-		    host_address_to_string (section),
-		    warn_if_readin);
-
-  retval
-    = debug_data->real_sf->qf->find_pc_sect_compunit_symtab (objfile, msymbol,
-							     pc, section,
-							     warn_if_readin);
+  if (debug_symfile)
+    fprintf_filtered (gdb_stdlog,
+		      "qf->find_pc_sect_compunit_symtab (%s, %s, %s, %s, %d)\n",
+		      objfile_debug_name (this),
+		      host_address_to_string (msymbol.minsym),
+		      hex_string (pc),
+		      host_address_to_string (section),
+		      warn_if_readin);
+
+  if (sf != nullptr)
+    retval
+      = sf->qf->find_pc_sect_compunit_symtab (this, msymbol, pc, section,
+					      warn_if_readin);
 
-  fprintf_filtered (gdb_stdlog,
-		    "qf->find_pc_sect_compunit_symtab (...) = %s\n",
-		    retval
-		    ? debug_symtab_name (compunit_primary_filetab (retval))
-		    : "NULL");
+  if (debug_symfile)
+    fprintf_filtered (gdb_stdlog,
+		      "qf->find_pc_sect_compunit_symtab (...) = %s\n",
+		      retval
+		      ? debug_symtab_name (compunit_primary_filetab (retval))
+		      : "NULL");
 
   return retval;
 }
 
-static void
-debug_qf_map_symbol_filenames (struct objfile *objfile,
-			       symbol_filename_ftype *fun, void *data,
+void
+objfile::map_symbol_filenames (symbol_filename_ftype *fun, void *data,
 			       int need_fullname)
 {
-  const struct debug_sym_fns_data *debug_data
-    = symfile_debug_objfile_data_key.get (objfile);
-  fprintf_filtered (gdb_stdlog,
-		    "qf->map_symbol_filenames (%s, %s, %s, %d)\n",
-		    objfile_debug_name (objfile),
-		    host_address_to_string (fun),
-		    host_address_to_string (data),
-		    need_fullname);
+  if (debug_symfile)
+    fprintf_filtered (gdb_stdlog,
+		      "qf->map_symbol_filenames (%s, %s, %s, %d)\n",
+		      objfile_debug_name (this),
+		      host_address_to_string (fun),
+		      host_address_to_string (data),
+		      need_fullname);
 
-  debug_data->real_sf->qf->map_symbol_filenames (objfile, fun, data,
-						 need_fullname);
+  if (sf != nullptr)
+    sf->qf->map_symbol_filenames (this, fun, data, need_fullname);
 }
 
-static struct compunit_symtab *
-debug_qf_find_compunit_symtab_by_address (struct objfile *objfile,
-					  CORE_ADDR address)
+struct compunit_symtab *
+objfile::find_compunit_symtab_by_address (CORE_ADDR address)
 {
-  const struct debug_sym_fns_data *debug_data
-    = symfile_debug_objfile_data_key.get (objfile);
-  fprintf_filtered (gdb_stdlog,
-		    "qf->find_compunit_symtab_by_address (%s, %s)\n",
-		    objfile_debug_name (objfile),
-		    hex_string (address));
+  if (debug_symfile)
+    fprintf_filtered (gdb_stdlog,
+		      "qf->find_compunit_symtab_by_address (%s, %s)\n",
+		      objfile_debug_name (this),
+		      hex_string (address));
 
   struct compunit_symtab *result = NULL;
-  if (debug_data->real_sf->qf->map_symbol_filenames != NULL)
-    result
-      = debug_data->real_sf->qf->find_compunit_symtab_by_address (objfile,
-								  address);
+  if (sf != nullptr && sf->qf->find_compunit_symtab_by_address != NULL)
+    result = sf->qf->find_compunit_symtab_by_address (this, address);
 
-  fprintf_filtered (gdb_stdlog,
-		    "qf->find_compunit_symtab_by_address (...) = %s\n",
-		    result
-		    ? debug_symtab_name (compunit_primary_filetab (result))
-		    : "NULL");
+  if (debug_symfile)
+    fprintf_filtered (gdb_stdlog,
+		      "qf->find_compunit_symtab_by_address (...) = %s\n",
+		      result
+		      ? debug_symtab_name (compunit_primary_filetab (result))
+		      : "NULL");
+
+  return result;
+}
+
+enum language
+objfile::lookup_global_symbol_language (const char *name,
+					domain_enum domain,
+					bool *symbol_found_p)
+{
+  enum language result = language_unknown;
+
+  if (sf != nullptr && sf->qf->lookup_global_symbol_language != nullptr)
+    result = sf->qf->lookup_global_symbol_language (this, name, domain,
+						    symbol_found_p);
+  else
+    *symbol_found_p = false;
 
   return result;
 }
 
-static const struct quick_symbol_functions debug_sym_quick_functions =
-{
-  debug_qf_has_symbols,
-  debug_qf_find_last_source_symtab,
-  debug_qf_forget_cached_source_info,
-  debug_qf_map_symtabs_matching_filename,
-  debug_qf_lookup_symbol,
-  NULL,
-  debug_qf_print_stats,
-  debug_qf_dump,
-  debug_qf_expand_symtabs_for_function,
-  debug_qf_expand_all_symtabs,
-  debug_qf_expand_symtabs_with_fullname,
-  debug_qf_map_matching_symbols,
-  debug_qf_expand_symtabs_matching,
-  debug_qf_find_pc_sect_compunit_symtab,
-  debug_qf_find_compunit_symtab_by_address,
-  debug_qf_map_symbol_filenames
-};
 \f
 /* Debugging version of struct sym_probe_fns.  */
 
@@ -532,7 +516,7 @@ static const struct sym_fns debug_sym_fns =
   debug_sym_read_linetable,
   debug_sym_relocate,
   &debug_sym_probe_fns,
-  &debug_sym_quick_functions
+  nullptr
 };
 \f
 /* Install the debugging versions of the symfile functions for OBJFILE.
@@ -571,7 +555,7 @@ install_symfile_debug_logging (struct objfile *objfile)
   COPY_SF_PTR (real_sf, debug_data, sym_relocate, debug_sym_relocate);
   if (real_sf->sym_probe_fns)
     debug_data->debug_sf.sym_probe_fns = &debug_sym_probe_fns;
-  debug_data->debug_sf.qf = &debug_sym_quick_functions;
+  debug_data->debug_sf.qf = real_sf->qf;
 
 #undef COPY_SF_PTR
 
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 34d6363a91a..ac9adc816a4 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -1100,8 +1100,7 @@ symbol_file_add_with_addrs (bfd *abfd, const char *name,
 	printf_filtered (_("Expanding full symbols from %ps...\n"),
 			 styled_string (file_name_style.style (), name));
 
-      if (objfile->sf)
-	objfile->sf->qf->expand_all_symtabs (objfile);
+      objfile->expand_all_symtabs ();
     }
 
   /* Note that we only print a message if we have no symbols and have
@@ -3731,13 +3730,10 @@ expand_symtabs_matching
    enum search_domain kind)
 {
   for (objfile *objfile : current_program_space->objfiles ())
-    {
-      if (objfile->sf)
-	objfile->sf->qf->expand_symtabs_matching (objfile, file_matcher,
-						  &lookup_name,
-						  symbol_matcher,
-						  expansion_notify, kind);
-    }
+    objfile->expand_symtabs_matching (file_matcher,
+				      &lookup_name,
+				      symbol_matcher,
+				      expansion_notify, kind);
 }
 
 /* Wrapper around the quick_symbol_functions map_symbol_filenames "method".
@@ -3749,11 +3745,7 @@ map_symbol_filenames (symbol_filename_ftype *fun, void *data,
 		      int need_fullname)
 {
   for (objfile *objfile : current_program_space->objfiles ())
-    {
-      if (objfile->sf)
-	objfile->sf->qf->map_symbol_filenames (objfile, fun, data,
-					       need_fullname);
-    }
+    objfile->map_symbol_filenames (fun, data, need_fullname);
 }
 
 #if GDB_SELF_TEST
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index 3703e50c6de..0aab30d08ab 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -105,8 +105,7 @@ print_objfile_statistics (void)
 	if (OBJSTAT (objfile, n_types) > 0)
 	  printf_filtered (_("  Number of \"types\" defined: %d\n"),
 			   OBJSTAT (objfile, n_types));
-	if (objfile->sf)
-	  objfile->sf->qf->print_stats (objfile);
+	objfile->print_stats ();
 	i = linetables = 0;
 	for (compunit_symtab *cu : objfile->compunits ())
 	  {
@@ -153,8 +152,7 @@ dump_objfile (struct objfile *objfile)
   printf_filtered (", %d minsyms\n\n",
 		   objfile->per_bfd->minimal_symbol_count);
 
-  if (objfile->sf)
-    objfile->sf->qf->dump (objfile);
+  objfile->dump ();
 
   if (objfile->compunit_symtabs != NULL)
     {
@@ -963,23 +961,17 @@ maintenance_expand_symtabs (const char *args, int from_tty)
 
   for (struct program_space *pspace : program_spaces)
     for (objfile *objfile : pspace->objfiles ())
-      {
-	if (objfile->sf)
-	  {
-	    objfile->sf->qf->expand_symtabs_matching
-	      (objfile,
-	       [&] (const char *filename, bool basenames)
-	       {
-		 /* KISS: Only apply the regexp to the complete file name.  */
-		 return (!basenames
-			 && (regexp == NULL || re_exec (filename)));
-	       },
-	       NULL,
-	       NULL,
-	       NULL,
-	       ALL_DOMAIN);
-	  }
-      }
+      objfile->expand_symtabs_matching
+	([&] (const char *filename, bool basenames)
+	 {
+	   /* KISS: Only apply the regexp to the complete file name.  */
+	   return (!basenames
+		   && (regexp == NULL || re_exec (filename)));
+	 },
+	 NULL,
+	 NULL,
+	 NULL,
+	 ALL_DOMAIN);
 }
 \f
 
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 3650b49832e..084e8ecc2e8 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -555,11 +555,8 @@ iterate_over_symtabs (const char *name,
 
   for (objfile *objfile : current_program_space->objfiles ())
     {
-      if (objfile->sf
-	  && objfile->sf->qf->map_symtabs_matching_filename (objfile,
-							     name,
-							     real_path.get (),
-							     callback))
+      if (objfile->map_symtabs_matching_filename (name, real_path.get (),
+						  callback))
 	return;
     }
 }
@@ -1114,11 +1111,8 @@ expand_symtab_containing_pc (CORE_ADDR pc, struct obj_section *section)
 
   for (objfile *objfile : current_program_space->objfiles ())
     {
-      struct compunit_symtab *cust = NULL;
-
-      if (objfile->sf)
-	cust = objfile->sf->qf->find_pc_sect_compunit_symtab (objfile, msymbol,
-							      pc, section, 0);
+      struct compunit_symtab *cust
+	= objfile->find_pc_sect_compunit_symtab (msymbol, pc, section, 0);
       if (cust)
 	return;
     }
@@ -2369,9 +2363,6 @@ lookup_symbol_via_quick_fns (struct objfile *objfile,
   const struct block *block;
   struct block_symbol result;
 
-  if (!objfile->sf)
-    return {};
-
   if (symbol_lookup_debug > 1)
     {
       fprintf_unfiltered (gdb_stdlog,
@@ -2382,7 +2373,7 @@ lookup_symbol_via_quick_fns (struct objfile *objfile,
 			  name, domain_name (domain));
     }
 
-  cust = objfile->sf->qf->lookup_symbol (objfile, block_index, name, domain);
+  cust = objfile->lookup_symbol (block_index, name, domain);
   if (cust == NULL)
     {
       if (symbol_lookup_debug > 1)
@@ -2549,23 +2540,13 @@ lookup_symbol_in_objfile (struct objfile *objfile, enum block_enum block_index,
 static enum language
 find_quick_global_symbol_language (const char *name, const domain_enum domain)
 {
-  for (objfile *objfile : current_program_space->objfiles ())
-    {
-      if (objfile->sf && objfile->sf->qf
-	  && objfile->sf->qf->lookup_global_symbol_language)
-	continue;
-      return language_unknown;
-    }
-
   for (objfile *objfile : current_program_space->objfiles ())
     {
       bool symbol_found_p;
       enum language lang
-	= objfile->sf->qf->lookup_global_symbol_language (objfile, name, domain,
-							  &symbol_found_p);
-      if (!symbol_found_p)
-	continue;
-      return lang;
+	= objfile->lookup_global_symbol_language (name, domain, &symbol_found_p);
+      if (symbol_found_p)
+	return lang;
     }
 
   return language_unknown;
@@ -2749,10 +2730,7 @@ basic_lookup_transparent_type_quick (struct objfile *objfile,
   const struct block *block;
   struct symbol *sym;
 
-  if (!objfile->sf)
-    return NULL;
-  cust = objfile->sf->qf->lookup_symbol (objfile, block_index, name,
-					 STRUCT_DOMAIN);
+  cust = objfile->lookup_symbol (block_index, name, STRUCT_DOMAIN);
   if (cust == NULL)
     return NULL;
 
@@ -2955,16 +2933,15 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section)
 	  /* In order to better support objfiles that contain both
 	     stabs and coff debugging info, we continue on if a psymtab
 	     can't be found.  */
-	  if ((obj_file->flags & OBJF_REORDERED) && obj_file->sf)
+	  if ((obj_file->flags & OBJF_REORDERED) != 0)
 	    {
 	      struct compunit_symtab *result;
 
 	      result
-		= obj_file->sf->qf->find_pc_sect_compunit_symtab (obj_file,
-								  msymbol,
-								  pc,
-								  section,
-								  0);
+		= obj_file->find_pc_sect_compunit_symtab (msymbol,
+							  pc,
+							  section,
+							  0);
 	      if (result != NULL)
 		return result;
 	    }
@@ -3005,14 +2982,8 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section)
 
   for (objfile *objf : current_program_space->objfiles ())
     {
-      struct compunit_symtab *result;
-
-      if (!objf->sf)
-	continue;
-      result = objf->sf->qf->find_pc_sect_compunit_symtab (objf,
-							   msymbol,
-							   pc, section,
-							   1);
+      struct compunit_symtab *result
+	= objf->find_pc_sect_compunit_symtab (msymbol, pc, section, 1);
       if (result != NULL)
 	return result;
     }
@@ -3059,11 +3030,9 @@ find_symbol_at_address (CORE_ADDR address)
 
   for (objfile *objfile : current_program_space->objfiles ())
     {
-      /* If this objfile doesn't have "quick" functions, then it may
-	 have been read with -readnow, in which case we need to search
-	 the symtabs directly.  */
-      if (objfile->sf == NULL
-	  || objfile->sf->qf->find_compunit_symtab_by_address == NULL)
+      /* If this objfile was read with -readnow, then we need to
+	 search the symtabs directly.  */
+      if ((objfile->flags & OBJF_READNOW) != 0)
 	{
 	  for (compunit_symtab *symtab : objfile->compunits ())
 	    {
@@ -3075,8 +3044,7 @@ find_symbol_at_address (CORE_ADDR address)
       else
 	{
 	  struct compunit_symtab *symtab
-	    = objfile->sf->qf->find_compunit_symtab_by_address (objfile,
-								address);
+	    = objfile->find_compunit_symtab_by_address (address);
 	  if (symtab != NULL)
 	    {
 	      struct symbol *sym = search_symtab (symtab, address);
@@ -3451,11 +3419,7 @@ find_line_symtab (struct symtab *sym_tab, int line,
 	best = 0;
 
       for (objfile *objfile : current_program_space->objfiles ())
-	{
-	  if (objfile->sf)
-	    objfile->sf->qf->expand_symtabs_with_fullname
-	      (objfile, symtab_to_fullname (sym_tab));
-	}
+	objfile->expand_symtabs_with_fullname (symtab_to_fullname (sym_tab));
 
       for (objfile *objfile : current_program_space->objfiles ())
 	{
@@ -4576,21 +4540,19 @@ global_symbol_searcher::expand_symtabs
   enum search_domain kind = m_kind;
   bool found_msymbol = false;
 
-  if (objfile->sf)
-    objfile->sf->qf->expand_symtabs_matching
-      (objfile,
-       [&] (const char *filename, bool basenames)
-       {
-	 return file_matches (filename, filenames, basenames);
-       },
-       &lookup_name_info::match_any (),
-       [&] (const char *symname)
-       {
-	 return (!preg.has_value ()
-		 || preg->exec (symname, 0, NULL, 0) == 0);
-       },
-       NULL,
-       kind);
+  objfile->expand_symtabs_matching
+    ([&] (const char *filename, bool basenames)
+     {
+       return file_matches (filename, filenames, basenames);
+     },
+     &lookup_name_info::match_any (),
+     [&] (const char *symname)
+     {
+       return (!preg.has_value ()
+	       || preg->exec (symname, 0, NULL, 0) == 0);
+     },
+     NULL,
+     kind);
 
   /* Here, we search through the minimal symbol tables for functions and
      variables that match, and force their symbols to be read.  This is in
-- 
2.26.2


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 06/26] Move quick_symbol_functions to a new header
  2021-02-28 20:37 [PATCH 00/26] Allow multiple "partial" symtab readers per objfile Tom Tromey
                   ` (4 preceding siblings ...)
  2021-02-28 20:37 ` [PATCH 05/26] Introduce method wrappers for quick_symbol_functions Tom Tromey
@ 2021-02-28 20:37 ` Tom Tromey
  2021-02-28 20:37 ` [PATCH 07/26] Move sym_fns::qf to objfile Tom Tromey
                   ` (20 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: Tom Tromey @ 2021-02-28 20:37 UTC (permalink / raw)
  To: gdb-patches

This introduces a new header, quick-symbol.h, and moves
quick_symbol_functions and related typedefs into it.

gdb/ChangeLog
2021-02-28  Tom Tromey  <tom@tromey.com>

	* symfile.h (symbol_compare_ftype, symbol_filename_ftype)
	(expand_symtabs_file_matcher_ftype)
	(expand_symtabs_symbol_matcher_ftype)
	(expand_symtabs_exp_notify_ftype, struct quick_symbol_functions):
	Move to quick-symbol.h.
	* quick-symbol.h: New file.
---
 gdb/ChangeLog      |   9 ++
 gdb/quick-symbol.h | 228 +++++++++++++++++++++++++++++++++++++++++++++
 gdb/symfile.h      | 206 +---------------------------------------
 3 files changed, 238 insertions(+), 205 deletions(-)
 create mode 100644 gdb/quick-symbol.h

diff --git a/gdb/quick-symbol.h b/gdb/quick-symbol.h
new file mode 100644
index 00000000000..fa5f5012211
--- /dev/null
+++ b/gdb/quick-symbol.h
@@ -0,0 +1,228 @@
+/* "Quick" symbol functions
+
+   Copyright (C) 2021 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef GDB_QUICK_SYMBOL_H
+#define GDB_QUICK_SYMBOL_H
+
+/* Comparison function for symbol look ups.  */
+
+typedef int (symbol_compare_ftype) (const char *string1,
+				    const char *string2);
+
+/* Callback for quick_symbol_functions->map_symbol_filenames.  */
+
+typedef void (symbol_filename_ftype) (const char *filename,
+				      const char *fullname, void *data);
+
+/* Callback for quick_symbol_functions->expand_symtabs_matching
+   to match a file name.  */
+
+typedef bool (expand_symtabs_file_matcher_ftype) (const char *filename,
+						  bool basenames);
+
+/* Callback for quick_symbol_functions->expand_symtabs_matching
+   to match a symbol name.  */
+
+typedef bool (expand_symtabs_symbol_matcher_ftype) (const char *name);
+
+/* Callback for quick_symbol_functions->expand_symtabs_matching
+   to be called after a symtab has been expanded.  */
+
+typedef void (expand_symtabs_exp_notify_ftype) (compunit_symtab *symtab);
+
+/* The "quick" symbol functions exist so that symbol readers can
+   avoiding an initial read of all the symbols.  For example, symbol
+   readers might choose to use the "partial symbol table" utilities,
+   which is one implementation of the quick symbol functions.
+
+   The quick symbol functions are generally opaque: the underlying
+   representation is hidden from the caller.
+
+   In general, these functions should only look at whatever special
+   index the symbol reader creates -- looking through the symbol
+   tables themselves is handled by generic code.  If a function is
+   defined as returning a "symbol table", this means that the function
+   should only return a newly-created symbol table; it should not
+   examine pre-existing ones.
+
+   The exact list of functions here was determined in an ad hoc way
+   based on gdb's history.  */
+
+struct quick_symbol_functions
+{
+  /* Return true if this objfile has any "partial" symbols
+     available.  */
+  bool (*has_symbols) (struct objfile *objfile);
+
+  /* Return the symbol table for the "last" file appearing in
+     OBJFILE.  */
+  struct symtab *(*find_last_source_symtab) (struct objfile *objfile);
+
+  /* Forget all cached full file names for OBJFILE.  */
+  void (*forget_cached_source_info) (struct objfile *objfile);
+
+  /* Expand and iterate over each "partial" symbol table in OBJFILE
+     where the source file is named NAME.
+
+     If NAME is not absolute, a match after a '/' in the symbol table's
+     file name will also work, REAL_PATH is NULL then.  If NAME is
+     absolute then REAL_PATH is non-NULL absolute file name as resolved
+     via gdb_realpath from NAME.
+
+     If a match is found, the "partial" symbol table is expanded.
+     Then, this calls iterate_over_some_symtabs (or equivalent) over
+     all newly-created symbol tables, passing CALLBACK to it.
+     The result of this call is returned.  */
+  bool (*map_symtabs_matching_filename)
+    (struct objfile *objfile, const char *name, const char *real_path,
+     gdb::function_view<bool (symtab *)> callback);
+
+  /* Check to see if the symbol is defined in a "partial" symbol table
+     of OBJFILE.  BLOCK_INDEX should be either GLOBAL_BLOCK or STATIC_BLOCK,
+     depending on whether we want to search global symbols or static
+     symbols.  NAME is the name of the symbol to look for.  DOMAIN
+     indicates what sort of symbol to search for.
+
+     Returns the newly-expanded compunit in which the symbol is
+     defined, or NULL if no such symbol table exists.  If OBJFILE
+     contains !TYPE_OPAQUE symbol prefer its compunit.  If it contains
+     only TYPE_OPAQUE symbol(s), return at least that compunit.  */
+  struct compunit_symtab *(*lookup_symbol) (struct objfile *objfile,
+					    block_enum block_index,
+					    const char *name,
+					    domain_enum domain);
+
+  /* Check to see if the global symbol is defined in a "partial" symbol table
+     of OBJFILE. NAME is the name of the symbol to look for.  DOMAIN
+     indicates what sort of symbol to search for.
+
+     If found, sets *symbol_found_p to true and returns the symbol language.
+     defined, or NULL if no such symbol table exists.  */
+  enum language (*lookup_global_symbol_language) (struct objfile *objfile,
+						  const char *name,
+						  domain_enum domain,
+						  bool *symbol_found_p);
+
+  /* Print statistics about any indices loaded for OBJFILE.  The
+     statistics should be printed to gdb_stdout.  This is used for
+     "maint print statistics".  */
+  void (*print_stats) (struct objfile *objfile);
+
+  /* Dump any indices loaded for OBJFILE.  The dump should go to
+     gdb_stdout.  This is used for "maint print objfiles".  */
+  void (*dump) (struct objfile *objfile);
+
+  /* Find all the symbols in OBJFILE named FUNC_NAME, and ensure that
+     the corresponding symbol tables are loaded.  */
+  void (*expand_symtabs_for_function) (struct objfile *objfile,
+				       const char *func_name);
+
+  /* Read all symbol tables associated with OBJFILE.  */
+  void (*expand_all_symtabs) (struct objfile *objfile);
+
+  /* Read all symbol tables associated with OBJFILE which have
+     symtab_to_fullname equal to FULLNAME.
+     This is for the purposes of examining code only, e.g., expand_line_sal.
+     The routine may ignore debug info that is known to not be useful with
+     code, e.g., DW_TAG_type_unit for dwarf debug info.  */
+  void (*expand_symtabs_with_fullname) (struct objfile *objfile,
+					const char *fullname);
+
+  /* Find global or static symbols in all tables that are in DOMAIN
+     and for which MATCH (symbol name, NAME) == 0, passing each to 
+     CALLBACK, reading in partial symbol tables as needed.  Look
+     through global symbols if GLOBAL and otherwise static symbols.
+     Passes NAME and NAMESPACE to CALLBACK with each symbol
+     found.  After each block is processed, passes NULL to CALLBACK.
+     MATCH must be weaker than strcmp_iw_ordered in the sense that
+     strcmp_iw_ordered(x,y) == 0 --> MATCH(x,y) == 0.  ORDERED_COMPARE,
+     if non-null, must be an ordering relation compatible with
+     strcmp_iw_ordered in the sense that
+	    strcmp_iw_ordered(x,y) == 0 --> ORDERED_COMPARE(x,y) == 0
+     and 
+	    strcmp_iw_ordered(x,y) <= 0 --> ORDERED_COMPARE(x,y) <= 0
+     (allowing strcmp_iw_ordered(x,y) < 0 while ORDERED_COMPARE(x, y) == 0).
+     CALLBACK returns true to indicate that the scan should continue, or
+     false to indicate that the scan should be terminated.  */
+
+  void (*map_matching_symbols)
+    (struct objfile *,
+     const lookup_name_info &lookup_name,
+     domain_enum domain,
+     int global,
+     gdb::function_view<symbol_found_callback_ftype> callback,
+     symbol_compare_ftype *ordered_compare);
+
+  /* Expand all symbol tables in OBJFILE matching some criteria.
+
+     FILE_MATCHER is called for each file in OBJFILE.  The file name
+     is passed to it.  If the matcher returns false, the file is
+     skipped.  If FILE_MATCHER is NULL the file is not skipped.  If
+     BASENAMES is true the matcher should consider only file base
+     names (the passed file name is already only the lbasename'd
+     part).
+
+     If the file is not skipped, and SYMBOL_MATCHER and LOOKUP_NAME are NULL,
+     the symbol table is expanded.
+
+     Otherwise, individual symbols are considered.
+
+     If KIND does not match, the symbol is skipped.
+
+     If the symbol name does not match LOOKUP_NAME, the symbol is skipped.
+
+     If SYMBOL_MATCHER returns false, then the symbol is skipped.
+
+     Otherwise, the symbol's symbol table is expanded.  */
+  void (*expand_symtabs_matching)
+    (struct objfile *objfile,
+     gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
+     const lookup_name_info *lookup_name,
+     gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
+     gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
+     enum search_domain kind);
+
+  /* Return the comp unit from OBJFILE that contains PC and
+     SECTION.  Return NULL if there is no such compunit.  This
+     should return the compunit that contains a symbol whose
+     address exactly matches PC, or, if there is no exact match, the
+     compunit that contains a symbol whose address is closest to
+     PC.  */
+  struct compunit_symtab *(*find_pc_sect_compunit_symtab)
+    (struct objfile *objfile, struct bound_minimal_symbol msymbol,
+     CORE_ADDR pc, struct obj_section *section, int warn_if_readin);
+
+  /* Return the comp unit from OBJFILE that contains a symbol at
+     ADDRESS.  Return NULL if there is no such comp unit.  Unlike
+     find_pc_sect_compunit_symtab, any sort of symbol (not just text
+     symbols) can be considered, and only exact address matches are
+     considered.  This pointer may be NULL.  */
+  struct compunit_symtab *(*find_compunit_symtab_by_address)
+    (struct objfile *objfile, CORE_ADDR address);
+
+  /* Call a callback for every file defined in OBJFILE whose symtab is
+     not already read in.  FUN is the callback.  It is passed the file's
+     FILENAME, the file's FULLNAME (if need_fullname is non-zero), and
+     the DATA passed to this function.  */
+  void (*map_symbol_filenames) (struct objfile *objfile,
+				symbol_filename_ftype *fun, void *data,
+				int need_fullname);
+};
+
+#endif /* GDB_QUICK_SYMBOL_H */
diff --git a/gdb/symfile.h b/gdb/symfile.h
index facffeab810..7e64db74b8d 100644
--- a/gdb/symfile.h
+++ b/gdb/symfile.h
@@ -28,6 +28,7 @@
 #include "gdb_bfd.h"
 #include "gdbsupport/function-view.h"
 #include "target-section.h"
+#include "quick-symbol.h"
 
 /* Opaque declarations.  */
 struct target_section;
@@ -41,11 +42,6 @@ struct agent_expr;
 struct axs_value;
 class probe;
 
-/* Comparison function for symbol look ups.  */
-
-typedef int (symbol_compare_ftype) (const char *string1,
-				    const char *string2);
-
 struct other_sections
 {
   other_sections (CORE_ADDR addr_, std::string &&name_, int sectindex_)
@@ -107,206 +103,6 @@ struct symfile_segment_data
 
 using symfile_segment_data_up = std::unique_ptr<symfile_segment_data>;
 
-/* Callback for quick_symbol_functions->map_symbol_filenames.  */
-
-typedef void (symbol_filename_ftype) (const char *filename,
-				      const char *fullname, void *data);
-
-/* Callback for quick_symbol_functions->expand_symtabs_matching
-   to match a file name.  */
-
-typedef bool (expand_symtabs_file_matcher_ftype) (const char *filename,
-						  bool basenames);
-
-/* Callback for quick_symbol_functions->expand_symtabs_matching
-   to match a symbol name.  */
-
-typedef bool (expand_symtabs_symbol_matcher_ftype) (const char *name);
-
-/* Callback for quick_symbol_functions->expand_symtabs_matching
-   to be called after a symtab has been expanded.  */
-
-typedef void (expand_symtabs_exp_notify_ftype) (compunit_symtab *symtab);
-
-/* The "quick" symbol functions exist so that symbol readers can
-   avoiding an initial read of all the symbols.  For example, symbol
-   readers might choose to use the "partial symbol table" utilities,
-   which is one implementation of the quick symbol functions.
-
-   The quick symbol functions are generally opaque: the underlying
-   representation is hidden from the caller.
-
-   In general, these functions should only look at whatever special
-   index the symbol reader creates -- looking through the symbol
-   tables themselves is handled by generic code.  If a function is
-   defined as returning a "symbol table", this means that the function
-   should only return a newly-created symbol table; it should not
-   examine pre-existing ones.
-
-   The exact list of functions here was determined in an ad hoc way
-   based on gdb's history.  */
-
-struct quick_symbol_functions
-{
-  /* Return true if this objfile has any "partial" symbols
-     available.  */
-  bool (*has_symbols) (struct objfile *objfile);
-
-  /* Return the symbol table for the "last" file appearing in
-     OBJFILE.  */
-  struct symtab *(*find_last_source_symtab) (struct objfile *objfile);
-
-  /* Forget all cached full file names for OBJFILE.  */
-  void (*forget_cached_source_info) (struct objfile *objfile);
-
-  /* Expand and iterate over each "partial" symbol table in OBJFILE
-     where the source file is named NAME.
-
-     If NAME is not absolute, a match after a '/' in the symbol table's
-     file name will also work, REAL_PATH is NULL then.  If NAME is
-     absolute then REAL_PATH is non-NULL absolute file name as resolved
-     via gdb_realpath from NAME.
-
-     If a match is found, the "partial" symbol table is expanded.
-     Then, this calls iterate_over_some_symtabs (or equivalent) over
-     all newly-created symbol tables, passing CALLBACK to it.
-     The result of this call is returned.  */
-  bool (*map_symtabs_matching_filename)
-    (struct objfile *objfile, const char *name, const char *real_path,
-     gdb::function_view<bool (symtab *)> callback);
-
-  /* Check to see if the symbol is defined in a "partial" symbol table
-     of OBJFILE.  BLOCK_INDEX should be either GLOBAL_BLOCK or STATIC_BLOCK,
-     depending on whether we want to search global symbols or static
-     symbols.  NAME is the name of the symbol to look for.  DOMAIN
-     indicates what sort of symbol to search for.
-
-     Returns the newly-expanded compunit in which the symbol is
-     defined, or NULL if no such symbol table exists.  If OBJFILE
-     contains !TYPE_OPAQUE symbol prefer its compunit.  If it contains
-     only TYPE_OPAQUE symbol(s), return at least that compunit.  */
-  struct compunit_symtab *(*lookup_symbol) (struct objfile *objfile,
-					    block_enum block_index,
-					    const char *name,
-					    domain_enum domain);
-
-  /* Check to see if the global symbol is defined in a "partial" symbol table
-     of OBJFILE. NAME is the name of the symbol to look for.  DOMAIN
-     indicates what sort of symbol to search for.
-
-     If found, sets *symbol_found_p to true and returns the symbol language.
-     defined, or NULL if no such symbol table exists.  */
-  enum language (*lookup_global_symbol_language) (struct objfile *objfile,
-						  const char *name,
-						  domain_enum domain,
-						  bool *symbol_found_p);
-
-  /* Print statistics about any indices loaded for OBJFILE.  The
-     statistics should be printed to gdb_stdout.  This is used for
-     "maint print statistics".  */
-  void (*print_stats) (struct objfile *objfile);
-
-  /* Dump any indices loaded for OBJFILE.  The dump should go to
-     gdb_stdout.  This is used for "maint print objfiles".  */
-  void (*dump) (struct objfile *objfile);
-
-  /* Find all the symbols in OBJFILE named FUNC_NAME, and ensure that
-     the corresponding symbol tables are loaded.  */
-  void (*expand_symtabs_for_function) (struct objfile *objfile,
-				       const char *func_name);
-
-  /* Read all symbol tables associated with OBJFILE.  */
-  void (*expand_all_symtabs) (struct objfile *objfile);
-
-  /* Read all symbol tables associated with OBJFILE which have
-     symtab_to_fullname equal to FULLNAME.
-     This is for the purposes of examining code only, e.g., expand_line_sal.
-     The routine may ignore debug info that is known to not be useful with
-     code, e.g., DW_TAG_type_unit for dwarf debug info.  */
-  void (*expand_symtabs_with_fullname) (struct objfile *objfile,
-					const char *fullname);
-
-  /* Find global or static symbols in all tables that are in DOMAIN
-     and for which MATCH (symbol name, NAME) == 0, passing each to 
-     CALLBACK, reading in partial symbol tables as needed.  Look
-     through global symbols if GLOBAL and otherwise static symbols.
-     Passes NAME and NAMESPACE to CALLBACK with each symbol
-     found.  After each block is processed, passes NULL to CALLBACK.
-     MATCH must be weaker than strcmp_iw_ordered in the sense that
-     strcmp_iw_ordered(x,y) == 0 --> MATCH(x,y) == 0.  ORDERED_COMPARE,
-     if non-null, must be an ordering relation compatible with
-     strcmp_iw_ordered in the sense that
-	    strcmp_iw_ordered(x,y) == 0 --> ORDERED_COMPARE(x,y) == 0
-     and 
-	    strcmp_iw_ordered(x,y) <= 0 --> ORDERED_COMPARE(x,y) <= 0
-     (allowing strcmp_iw_ordered(x,y) < 0 while ORDERED_COMPARE(x, y) == 0).
-     CALLBACK returns true to indicate that the scan should continue, or
-     false to indicate that the scan should be terminated.  */
-
-  void (*map_matching_symbols)
-    (struct objfile *,
-     const lookup_name_info &lookup_name,
-     domain_enum domain,
-     int global,
-     gdb::function_view<symbol_found_callback_ftype> callback,
-     symbol_compare_ftype *ordered_compare);
-
-  /* Expand all symbol tables in OBJFILE matching some criteria.
-
-     FILE_MATCHER is called for each file in OBJFILE.  The file name
-     is passed to it.  If the matcher returns false, the file is
-     skipped.  If FILE_MATCHER is NULL the file is not skipped.  If
-     BASENAMES is true the matcher should consider only file base
-     names (the passed file name is already only the lbasename'd
-     part).
-
-     If the file is not skipped, and SYMBOL_MATCHER and LOOKUP_NAME are NULL,
-     the symbol table is expanded.
-
-     Otherwise, individual symbols are considered.
-
-     If KIND does not match, the symbol is skipped.
-
-     If the symbol name does not match LOOKUP_NAME, the symbol is skipped.
-
-     If SYMBOL_MATCHER returns false, then the symbol is skipped.
-
-     Otherwise, the symbol's symbol table is expanded.  */
-  void (*expand_symtabs_matching)
-    (struct objfile *objfile,
-     gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
-     const lookup_name_info *lookup_name,
-     gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
-     gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
-     enum search_domain kind);
-
-  /* Return the comp unit from OBJFILE that contains PC and
-     SECTION.  Return NULL if there is no such compunit.  This
-     should return the compunit that contains a symbol whose
-     address exactly matches PC, or, if there is no exact match, the
-     compunit that contains a symbol whose address is closest to
-     PC.  */
-  struct compunit_symtab *(*find_pc_sect_compunit_symtab)
-    (struct objfile *objfile, struct bound_minimal_symbol msymbol,
-     CORE_ADDR pc, struct obj_section *section, int warn_if_readin);
-
-  /* Return the comp unit from OBJFILE that contains a symbol at
-     ADDRESS.  Return NULL if there is no such comp unit.  Unlike
-     find_pc_sect_compunit_symtab, any sort of symbol (not just text
-     symbols) can be considered, and only exact address matches are
-     considered.  This pointer may be NULL.  */
-  struct compunit_symtab *(*find_compunit_symtab_by_address)
-    (struct objfile *objfile, CORE_ADDR address);
-
-  /* Call a callback for every file defined in OBJFILE whose symtab is
-     not already read in.  FUN is the callback.  It is passed the file's
-     FILENAME, the file's FULLNAME (if need_fullname is non-zero), and
-     the DATA passed to this function.  */
-  void (*map_symbol_filenames) (struct objfile *objfile,
-				symbol_filename_ftype *fun, void *data,
-				int need_fullname);
-};
-
 /* Structure of functions used for probe support.  If one of these functions
    is provided, all must be.  */
 
-- 
2.26.2


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 07/26] Move sym_fns::qf to objfile
  2021-02-28 20:37 [PATCH 00/26] Allow multiple "partial" symtab readers per objfile Tom Tromey
                   ` (5 preceding siblings ...)
  2021-02-28 20:37 ` [PATCH 06/26] Move quick_symbol_functions to a new header Tom Tromey
@ 2021-02-28 20:37 ` Tom Tromey
  2021-02-28 20:37 ` [PATCH 08/26] Convert quick_symbol_functions to use methods Tom Tromey
                   ` (19 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: Tom Tromey @ 2021-02-28 20:37 UTC (permalink / raw)
  To: gdb-patches

Currently the "partial" symbol reader is attached to the objfile's
symbol functions.  However, in order to allow multiple separate
partial symbol readers, this association must be changed.  This patch
moves the "qf" member out of sym_fns as a step toward that goal.

gdb/ChangeLog
2021-02-28  Tom Tromey  <tom@tromey.com>

	* psymtab.c (require_partial_symbols): Check that 'sf' is not
	null.
	* xcoffread.c (xcoff_sym_fns): Update.
	* symfile.h (struct sym_fns) <qf>: Remove.
	* symfile.c (syms_from_objfile_1, reread_symbols): Update.
	* symfile-debug.c (objfile::has_partial_symbols)
	(objfile::find_last_source_symtab)
	(objfile::forget_cached_source_info)
	(objfile::map_symtabs_matching_filename, objfile::lookup_symbol)
	(objfile::print_stats, objfile::dump)
	(objfile::expand_symtabs_for_function)
	(objfile::expand_all_symtabs)
	(objfile::expand_symtabs_with_fullname)
	(objfile::map_matching_symbols)
	(objfile::expand_symtabs_matching)
	(objfile::find_pc_sect_compunit_symtab)
	(objfile::map_symbol_filenames)
	(objfile::find_compunit_symtab_by_address)
	(objfile::lookup_global_symbol_language, debug_sym_fns)
	(install_symfile_debug_logging): Update.
	* objfiles.h (struct objfile) <qf>: New member.
	* mipsread.c (ecoff_sym_fns): Update.
	* machoread.c (macho_sym_fns): Update.
	* elfread.c (elf_sym_fns_gdb_index, elf_sym_fns_debug_names):
	Don't declare.
	(elf_symfile_read, elf_sym_fns, elf_sym_fns_lazy_psyms): Update.
	* dbxread.c (aout_sym_fns): Update.
	* coffread.c (coff_sym_fns): Update.
---
 gdb/ChangeLog       | 31 +++++++++++++++++++
 gdb/coffread.c      |  1 -
 gdb/dbxread.c       |  1 -
 gdb/elfread.c       | 42 ++-----------------------
 gdb/machoread.c     |  1 -
 gdb/mipsread.c      |  1 -
 gdb/objfiles.h      |  4 +++
 gdb/psymtab.c       |  3 +-
 gdb/symfile-debug.c | 75 ++++++++++++++++++++++-----------------------
 gdb/symfile.c       |  2 ++
 gdb/symfile.h       |  4 ---
 gdb/xcoffread.c     |  1 -
 12 files changed, 77 insertions(+), 89 deletions(-)

diff --git a/gdb/coffread.c b/gdb/coffread.c
index badcb5a6084..676deec8cbe 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -2180,7 +2180,6 @@ static const struct sym_fns coff_sym_fns =
   default_symfile_relocate,	/* sym_relocate: Relocate a debug
 				   section.  */
   NULL,				/* sym_probe_fns */
-  &psym_functions
 };
 
 void _initialize_coffread ();
diff --git a/gdb/dbxread.c b/gdb/dbxread.c
index 6450cd32cb0..9003822a0f1 100644
--- a/gdb/dbxread.c
+++ b/gdb/dbxread.c
@@ -3130,7 +3130,6 @@ static const struct sym_fns aout_sym_fns =
   NULL,
   default_symfile_relocate,	/* Relocate a debug section.  */
   NULL,				/* sym_probe_fns */
-  &psym_functions
 };
 
 void _initialize_dbxread ();
diff --git a/gdb/elfread.c b/gdb/elfread.c
index 439f5cc29a0..3ba7221bfc9 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -54,8 +54,6 @@
 #include "dwarf2/public.h"
 
 /* Forward declarations.  */
-extern const struct sym_fns elf_sym_fns_gdb_index;
-extern const struct sym_fns elf_sym_fns_debug_names;
 extern const struct sym_fns elf_sym_fns_lazy_psyms;
 
 /* The struct elfinfo is available only during ELF symbol table and
@@ -1272,10 +1270,10 @@ elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
 	  switch (index_kind)
 	    {
 	    case dw_index_kind::GDB_INDEX:
-	      objfile_set_sym_fns (objfile, &elf_sym_fns_gdb_index);
+	      objfile->qf = &dwarf2_gdb_index_functions;
 	      break;
 	    case dw_index_kind::DEBUG_NAMES:
-	      objfile_set_sym_fns (objfile, &elf_sym_fns_debug_names);
+	      objfile->qf = &dwarf2_debug_names_functions;
 	      break;
 	    }
 	}
@@ -1437,7 +1435,6 @@ static const struct sym_fns elf_sym_fns =
   NULL,
   default_symfile_relocate,	/* Relocate a debug section.  */
   &elf_probe_fns,		/* sym_probe_fns */
-  &psym_functions
 };
 
 /* The same as elf_sym_fns, but not registered and lazily reads
@@ -1455,41 +1452,6 @@ const struct sym_fns elf_sym_fns_lazy_psyms =
   NULL,
   default_symfile_relocate,	/* Relocate a debug section.  */
   &elf_probe_fns,		/* sym_probe_fns */
-  &psym_functions
-};
-
-/* The same as elf_sym_fns, but not registered and uses the
-   DWARF-specific GNU index rather than psymtab.  */
-const struct sym_fns elf_sym_fns_gdb_index =
-{
-  elf_new_init,			/* init anything gbl to entire symab */
-  elf_symfile_init,		/* read initial info, setup for sym_red() */
-  elf_symfile_read,		/* read a symbol file into symtab */
-  NULL,				/* sym_read_psymbols */
-  elf_symfile_finish,		/* finished with file, cleanup */
-  default_symfile_offsets,	/* Translate ext. to int. relocation */
-  elf_symfile_segments,		/* Get segment information from a file.  */
-  NULL,
-  default_symfile_relocate,	/* Relocate a debug section.  */
-  &elf_probe_fns,		/* sym_probe_fns */
-  &dwarf2_gdb_index_functions
-};
-
-/* The same as elf_sym_fns, but not registered and uses the
-   DWARF-specific .debug_names index rather than psymtab.  */
-const struct sym_fns elf_sym_fns_debug_names =
-{
-  elf_new_init,			/* init anything gbl to entire symab */
-  elf_symfile_init,		/* read initial info, setup for sym_red() */
-  elf_symfile_read,		/* read a symbol file into symtab */
-  NULL,				/* sym_read_psymbols */
-  elf_symfile_finish,		/* finished with file, cleanup */
-  default_symfile_offsets,	/* Translate ext. to int. relocation */
-  elf_symfile_segments,		/* Get segment information from a file.  */
-  NULL,
-  default_symfile_relocate,	/* Relocate a debug section.  */
-  &elf_probe_fns,		/* sym_probe_fns */
-  &dwarf2_debug_names_functions
 };
 
 /* STT_GNU_IFUNC resolver vector to be installed to gnu_ifunc_fns_p.  */
diff --git a/gdb/machoread.c b/gdb/machoread.c
index ff50ae54f2a..44baaa26f65 100644
--- a/gdb/machoread.c
+++ b/gdb/machoread.c
@@ -958,7 +958,6 @@ static const struct sym_fns macho_sym_fns = {
   NULL,
   macho_symfile_relocate,	/* Relocate a debug section.  */
   NULL,				/* sym_get_probes */
-  &psym_functions
 };
 
 void _initialize_machoread ();
diff --git a/gdb/mipsread.c b/gdb/mipsread.c
index 052b31c70db..3f0697b9150 100644
--- a/gdb/mipsread.c
+++ b/gdb/mipsread.c
@@ -376,7 +376,6 @@ static const struct sym_fns ecoff_sym_fns =
   NULL,
   default_symfile_relocate,	/* Relocate a debug section.  */
   NULL,				/* sym_probe_fns */
-  &psym_functions
 };
 
 void _initialize_mipsread ();
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index c55f0f174fc..8d4a23ae044 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -677,6 +677,10 @@ struct objfile
 
   const struct sym_fns *sf = nullptr;
 
+  /* The "quick" (aka partial) symbol functions for this symbol
+     reader.  */
+  const struct quick_symbol_functions *qf = nullptr;
+
   /* Per objfile data-pointers required by other GDB modules.  */
 
   REGISTRY_FIELDS {};
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 94b5acdea54..8c02fa253dc 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -84,7 +84,8 @@ require_partial_symbols (struct objfile *objfile, bool verbose)
     {
       objfile->flags |= OBJF_PSYMTABS_READ;
 
-      if (objfile->sf->sym_read_psymbols)
+      if (objfile->sf != nullptr
+	  && objfile->sf->sym_read_psymbols)
 	{
 	  if (verbose)
 	    printf_filtered (_("Reading symbols from %s...\n"),
diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index 419f24d2240..da3439d7928 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -84,8 +84,8 @@ objfile::has_partial_symbols ()
       && sf != nullptr
       && sf->sym_read_psymbols != NULL)
     retval = true;
-  else if (sf != nullptr)
-    retval = sf->qf->has_symbols (this);
+  else if (qf != nullptr)
+    retval = qf->has_symbols (this);
 
   if (debug_symfile)
     fprintf_filtered (gdb_stdlog, "qf->has_symbols (%s) = %d\n",
@@ -103,8 +103,8 @@ objfile::find_last_source_symtab ()
     fprintf_filtered (gdb_stdlog, "qf->find_last_source_symtab (%s)\n",
 		      objfile_debug_name (this));
 
-  if (sf != nullptr)
-    retval = sf->qf->find_last_source_symtab (this);
+  if (qf != nullptr)
+    retval = qf->find_last_source_symtab (this);
 
   if (debug_symfile)
     fprintf_filtered (gdb_stdlog, "qf->find_last_source_symtab (...) = %s\n",
@@ -120,8 +120,8 @@ objfile::forget_cached_source_info ()
     fprintf_filtered (gdb_stdlog, "qf->forget_cached_source_info (%s)\n",
 		      objfile_debug_name (this));
 
-  if (sf != nullptr)
-    sf->qf->forget_cached_source_info (this);
+  if (qf != nullptr)
+    qf->forget_cached_source_info (this);
 }
 
 bool
@@ -138,8 +138,8 @@ objfile::map_symtabs_matching_filename
 		      host_address_to_string (&callback));
 
   bool retval = false;
-  if (sf != nullptr)
-    retval = (sf->qf->map_symtabs_matching_filename
+  if (qf != nullptr)
+    retval = (qf->map_symtabs_matching_filename
 	      (this, name, real_path, callback));
 
   if (debug_symfile)
@@ -161,8 +161,8 @@ objfile::lookup_symbol (block_enum kind, const char *name, domain_enum domain)
 		      objfile_debug_name (this), kind, name,
 		      domain_name (domain));
 
-  if (sf != nullptr)
-    retval = sf->qf->lookup_symbol (this, kind, name, domain);
+  if (qf != nullptr)
+    retval = qf->lookup_symbol (this, kind, name, domain);
 
   if (debug_symfile)
     fprintf_filtered (gdb_stdlog, "qf->lookup_symbol (...) = %s\n",
@@ -180,8 +180,8 @@ objfile::print_stats ()
     fprintf_filtered (gdb_stdlog, "qf->print_stats (%s)\n",
 		      objfile_debug_name (this));
 
-  if (sf != nullptr)
-    sf->qf->print_stats (this);
+  if (qf != nullptr)
+    qf->print_stats (this);
 }
 
 void
@@ -191,8 +191,8 @@ objfile::dump ()
     fprintf_filtered (gdb_stdlog, "qf->dump (%s)\n",
 		      objfile_debug_name (this));
 
-  if (sf != nullptr)
-    sf->qf->dump (this);
+  if (qf != nullptr)
+    qf->dump (this);
 }
 
 void
@@ -203,8 +203,8 @@ objfile::expand_symtabs_for_function (const char *func_name)
 		      "qf->expand_symtabs_for_function (%s, \"%s\")\n",
 		      objfile_debug_name (this), func_name);
 
-  if (sf != nullptr)
-    sf->qf->expand_symtabs_for_function (this, func_name);
+  if (qf != nullptr)
+    qf->expand_symtabs_for_function (this, func_name);
 }
 
 void
@@ -214,8 +214,8 @@ objfile::expand_all_symtabs ()
     fprintf_filtered (gdb_stdlog, "qf->expand_all_symtabs (%s)\n",
 		      objfile_debug_name (this));
 
-  if (sf != nullptr)
-    sf->qf->expand_all_symtabs (this);
+  if (qf != nullptr)
+    qf->expand_all_symtabs (this);
 }
 
 void
@@ -226,8 +226,8 @@ objfile::expand_symtabs_with_fullname (const char *fullname)
 		      "qf->expand_symtabs_with_fullname (%s, \"%s\")\n",
 		      objfile_debug_name (this), fullname);
 
-  if (sf != nullptr)
-    sf->qf->expand_symtabs_with_fullname (this, fullname);
+  if (qf != nullptr)
+    qf->expand_symtabs_with_fullname (this, fullname);
 }
 
 void
@@ -244,9 +244,9 @@ objfile::map_matching_symbols
 		      domain_name (domain), global,
 		      host_address_to_string (ordered_compare));
 
-  if (sf != nullptr)
-    sf->qf->map_matching_symbols (this, name, domain, global,
-				  callback, ordered_compare);
+  if (qf != nullptr)
+    qf->map_matching_symbols (this, name, domain, global,
+			      callback, ordered_compare);
 }
 
 void
@@ -266,9 +266,9 @@ objfile::expand_symtabs_matching
 		      host_address_to_string (&expansion_notify),
 		      search_domain_name (kind));
 
-  if (sf != nullptr)
-    sf->qf->expand_symtabs_matching (this, file_matcher, lookup_name,
-				     symbol_matcher, expansion_notify, kind);
+  if (qf != nullptr)
+    qf->expand_symtabs_matching (this, file_matcher, lookup_name,
+				 symbol_matcher, expansion_notify, kind);
 }
 
 struct compunit_symtab *
@@ -288,10 +288,9 @@ objfile::find_pc_sect_compunit_symtab (struct bound_minimal_symbol msymbol,
 		      host_address_to_string (section),
 		      warn_if_readin);
 
-  if (sf != nullptr)
-    retval
-      = sf->qf->find_pc_sect_compunit_symtab (this, msymbol, pc, section,
-					      warn_if_readin);
+  if (qf != nullptr)
+    retval = qf->find_pc_sect_compunit_symtab (this, msymbol, pc, section,
+					       warn_if_readin);
 
   if (debug_symfile)
     fprintf_filtered (gdb_stdlog,
@@ -315,8 +314,8 @@ objfile::map_symbol_filenames (symbol_filename_ftype *fun, void *data,
 		      host_address_to_string (data),
 		      need_fullname);
 
-  if (sf != nullptr)
-    sf->qf->map_symbol_filenames (this, fun, data, need_fullname);
+  if (qf != nullptr)
+    qf->map_symbol_filenames (this, fun, data, need_fullname);
 }
 
 struct compunit_symtab *
@@ -329,8 +328,8 @@ objfile::find_compunit_symtab_by_address (CORE_ADDR address)
 		      hex_string (address));
 
   struct compunit_symtab *result = NULL;
-  if (sf != nullptr && sf->qf->find_compunit_symtab_by_address != NULL)
-    result = sf->qf->find_compunit_symtab_by_address (this, address);
+  if (qf != nullptr && qf->find_compunit_symtab_by_address != NULL)
+    result = qf->find_compunit_symtab_by_address (this, address);
 
   if (debug_symfile)
     fprintf_filtered (gdb_stdlog,
@@ -349,9 +348,9 @@ objfile::lookup_global_symbol_language (const char *name,
 {
   enum language result = language_unknown;
 
-  if (sf != nullptr && sf->qf->lookup_global_symbol_language != nullptr)
-    result = sf->qf->lookup_global_symbol_language (this, name, domain,
-						    symbol_found_p);
+  if (qf != nullptr && qf->lookup_global_symbol_language != nullptr)
+    result = qf->lookup_global_symbol_language (this, name, domain,
+						symbol_found_p);
   else
     *symbol_found_p = false;
 
@@ -516,7 +515,6 @@ static const struct sym_fns debug_sym_fns =
   debug_sym_read_linetable,
   debug_sym_relocate,
   &debug_sym_probe_fns,
-  nullptr
 };
 \f
 /* Install the debugging versions of the symfile functions for OBJFILE.
@@ -555,7 +553,6 @@ install_symfile_debug_logging (struct objfile *objfile)
   COPY_SF_PTR (real_sf, debug_data, sym_relocate, debug_sym_relocate);
   if (real_sf->sym_probe_fns)
     debug_data->debug_sf.sym_probe_fns = &debug_sym_probe_fns;
-  debug_data->debug_sf.qf = real_sf->qf;
 
 #undef COPY_SF_PTR
 
diff --git a/gdb/symfile.c b/gdb/symfile.c
index ac9adc816a4..d56d623c588 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -904,6 +904,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->qf = &psym_functions;
 
   if (objfile->sf == NULL)
     {
@@ -2554,6 +2555,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->qf = &psym_functions;
 
 	  build_objfile_section_table (objfile);
 
diff --git a/gdb/symfile.h b/gdb/symfile.h
index 7e64db74b8d..0bd50899679 100644
--- a/gdb/symfile.h
+++ b/gdb/symfile.h
@@ -180,10 +180,6 @@ struct sym_fns
   /* If non-NULL, this objfile has probe support, and all the probe
      functions referred to here will be non-NULL.  */
   const struct sym_probe_fns *sym_probe_fns;
-
-  /* The "quick" (aka partial) symbol functions for this symbol
-     reader.  */
-  const struct quick_symbol_functions *qf;
 };
 
 extern section_addr_info
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index 6dab4e59234..207152ece4b 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -3005,7 +3005,6 @@ static const struct sym_fns xcoff_sym_fns =
   aix_process_linenos,
   default_symfile_relocate,	/* Relocate a debug section.  */
   NULL,				/* sym_probe_fns */
-  &psym_functions
 };
 
 /* Same as xcoff_get_n_import_files, but for core files.  */
-- 
2.26.2


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 08/26] Convert quick_symbol_functions to use methods
  2021-02-28 20:37 [PATCH 00/26] Allow multiple "partial" symtab readers per objfile Tom Tromey
                   ` (6 preceding siblings ...)
  2021-02-28 20:37 ` [PATCH 07/26] Move sym_fns::qf to objfile Tom Tromey
@ 2021-02-28 20:37 ` Tom Tromey
  2021-02-28 20:37 ` [PATCH 09/26] Move psymbol_map out of objfile Tom Tromey
                   ` (18 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: Tom Tromey @ 2021-02-28 20:37 UTC (permalink / raw)
  To: gdb-patches

This changes quick_symbol_functions to be a base class with pure
virtual methods, rather than a struct holding function pointers.
Then, objfile is changed to hold a unique_ptr to an instance of this
class.

struct psymbol_functions is put into psympriv.h, and not psymtab.c,
because that is convenient later in the series.

gdb/ChangeLog
2021-02-28  Tom Tromey  <tom@tromey.com>

	* psympriv.h (struct psymbol_functions): New.
	* symfile.c (syms_from_objfile_1, reread_symbols): Update.
	* symfile-debug.c (objfile::find_compunit_symtab_by_address)
	(objfile::lookup_global_symbol_language): Update.
	* quick-symbol.h (struct quick_symbol_functions): Convert function
	pointers to methods.  Add virtual destructor.
	(quick_symbol_functions_up): New typedef.
	* psymtab.h (psym_functions, dwarf2_gdb_index_functions)
	(dwarf2_debug_names_functions): Don't declare.
	(make_psymbol_functions): Declare.
	* psymtab.c (psymbol_functions::map_symtabs_matching_filename)
	(psymbol_functions::find_pc_sect_compunit_symtab)
	(psymbol_functions::lookup_symbol)
	(psymbol_functions::lookup_global_symbol_language)
	(psymbol_functions::find_last_source_symtab)
	(psymbol_functions::forget_cached_source_info)
	(psymbol_functions::print_stats, psymbol_functions::dump)
	(psymbol_functions::expand_symtabs_for_function)
	(psymbol_functions::expand_all_symtabs)
	(psymbol_functions::expand_symtabs_with_fullname)
	(psymbol_functions::map_symbol_filenames)
	(psymbol_functions::map_matching_symbols)
	(psymbol_functions::expand_symtabs_matching)
	(psymbol_functions::has_symbols)
	(psymbol_functions::find_compunit_symtab_by_address): Rename.
	(psym_functions): Remove.
	(make_psymbol_functions): New function.
	* objfiles.h (struct objfile) <qf>: Change type.
	* elfread.c (elf_symfile_read): Update.
	* dwarf2/read.c (struct dwarf2_base_index_functions)
	(struct dwarf2_gdb_index, struct dwarf2_debug_names_index): New.
	(make_dwarf_gdb_index, make_dwarf_debug_names): New functions.
	(dwarf2_base_index_functions::find_last_source_symtab)
	(dwarf2_base_index_functions::forget_cached_source_info)
	(dwarf2_base_index_functions::map_symtabs_matching_filename)
	(dwarf2_gdb_index::lookup_symbol)
	(dwarf2_base_index_functions::print_stats)
	(dwarf2_gdb_index::dump)
	(dwarf2_gdb_index::expand_symtabs_for_function)
	(dwarf2_base_index_functions::expand_all_symtabs)
	(dwarf2_base_index_functions::expand_symtabs_with_fullname):
	Rename.
	(dwarf2_gdb_index::map_matching_symbols): New method.
	(dwarf2_gdb_index::expand_symtabs_matching): New method.
	(dwarf2_base_index_functions::find_pc_sect_compunit_symtab)
	(dwarf2_base_index_functions::map_symbol_filenames)
	(dwarf2_base_index_functions::has_symbols): Rename.
	(dwarf2_gdb_index_functions): Remove.
	(dwarf2_debug_names_index::lookup_symbol)
	(dwarf2_debug_names_index::dump)
	(dwarf2_debug_names_index::expand_symtabs_for_function)
	(dwarf2_debug_names_index::map_matching_symbols)
	(dwarf2_debug_names_index::expand_symtabs_matching): Rename.
	(dwarf2_debug_names_functions): Remove.
	* dwarf2/public.h (make_dwarf_gdb_index, make_dwarf_debug_names):
	Declare.
---
 gdb/ChangeLog       |  59 ++++++++++
 gdb/dwarf2/public.h |   3 +
 gdb/dwarf2/read.c   | 274 ++++++++++++++++++++++++++++++--------------
 gdb/elfread.c       |   4 +-
 gdb/objfiles.h      |   3 +-
 gdb/psympriv.h      |  64 +++++++++++
 gdb/psymtab.c       | 114 +++++++++---------
 gdb/psymtab.h       |   7 +-
 gdb/quick-symbol.h  |  71 ++++++------
 gdb/symfile-debug.c |   4 +-
 gdb/symfile.c       |   4 +-
 11 files changed, 416 insertions(+), 191 deletions(-)

diff --git a/gdb/dwarf2/public.h b/gdb/dwarf2/public.h
index d0182d4e673..6b0fe0874b2 100644
--- a/gdb/dwarf2/public.h
+++ b/gdb/dwarf2/public.h
@@ -43,4 +43,7 @@ extern bool dwarf2_initialize_objfile (struct objfile *objfile,
 extern void dwarf2_build_psymtabs (struct objfile *);
 extern void dwarf2_build_frame_info (struct objfile *);
 
+extern quick_symbol_functions_up make_dwarf_gdb_index ();
+extern quick_symbol_functions_up make_dwarf_debug_names ();
+
 #endif /* DWARF2_PUBLIC_H */
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 7e55a0ec486..a24ead568ee 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -2392,7 +2392,7 @@ dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd)
   return per_bfd->dwz_file.get ();
 }
 \f
-/* DWARF quick_symbols_functions support.  */
+/* DWARF quick_symbol_functions support.  */
 
 /* TUs can share .debug_line entries, and there can be a lot more TUs than
    unique line tables, so we maintain a separate table of all .debug_line
@@ -2435,6 +2435,119 @@ struct dwarf2_per_cu_quick_data
   unsigned int no_file_data : 1;
 };
 
+struct dwarf2_base_index_functions : public quick_symbol_functions
+{
+  bool has_symbols (struct objfile *objfile) override;
+
+  struct symtab *find_last_source_symtab (struct objfile *objfile) override;
+
+  void forget_cached_source_info (struct objfile *objfile) override;
+
+  bool map_symtabs_matching_filename
+    (struct objfile *objfile, const char *name, const char *real_path,
+     gdb::function_view<bool (symtab *)> callback) override;
+
+  enum language lookup_global_symbol_language (struct objfile *objfile,
+					       const char *name,
+					       domain_enum domain,
+					       bool *symbol_found_p) override
+  {
+    *symbol_found_p = false;
+    return language_unknown;
+  }
+
+  void print_stats (struct objfile *objfile) override;
+
+  void expand_all_symtabs (struct objfile *objfile) override;
+
+  void expand_symtabs_with_fullname (struct objfile *objfile,
+				     const char *fullname) override;
+
+  struct compunit_symtab *find_pc_sect_compunit_symtab
+    (struct objfile *objfile, struct bound_minimal_symbol msymbol,
+     CORE_ADDR pc, struct obj_section *section, int warn_if_readin) override;
+
+  struct compunit_symtab *find_compunit_symtab_by_address
+    (struct objfile *objfile, CORE_ADDR address) override
+  {
+    return nullptr;
+  }
+
+  void map_symbol_filenames (struct objfile *objfile,
+			     symbol_filename_ftype *fun, void *data,
+			     int need_fullname) override;
+};
+
+struct dwarf2_gdb_index : public dwarf2_base_index_functions
+{
+  struct compunit_symtab *lookup_symbol (struct objfile *objfile,
+					 block_enum block_index,
+					 const char *name,
+					 domain_enum domain) override;
+
+  void dump (struct objfile *objfile) override;
+
+  void expand_symtabs_for_function (struct objfile *objfile,
+				    const char *func_name) override;
+
+  void map_matching_symbols
+    (struct objfile *,
+     const lookup_name_info &lookup_name,
+     domain_enum domain,
+     int global,
+     gdb::function_view<symbol_found_callback_ftype> callback,
+     symbol_compare_ftype *ordered_compare) override;
+
+  void expand_symtabs_matching
+    (struct objfile *objfile,
+     gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
+     const lookup_name_info *lookup_name,
+     gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
+     gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
+     enum search_domain kind) override;
+};
+
+struct dwarf2_debug_names_index : public dwarf2_base_index_functions
+{
+  struct compunit_symtab *lookup_symbol (struct objfile *objfile,
+					 block_enum block_index,
+					 const char *name,
+					 domain_enum domain) override;
+
+  void dump (struct objfile *objfile) override;
+
+  void expand_symtabs_for_function (struct objfile *objfile,
+				    const char *func_name) override;
+
+  void map_matching_symbols
+    (struct objfile *,
+     const lookup_name_info &lookup_name,
+     domain_enum domain,
+     int global,
+     gdb::function_view<symbol_found_callback_ftype> callback,
+     symbol_compare_ftype *ordered_compare) override;
+
+  void expand_symtabs_matching
+    (struct objfile *objfile,
+     gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
+     const lookup_name_info *lookup_name,
+     gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
+     gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
+     enum search_domain kind) override;
+};
+
+quick_symbol_functions_up
+make_dwarf_gdb_index ()
+{
+  return quick_symbol_functions_up (new dwarf2_gdb_index);
+}
+
+quick_symbol_functions_up
+make_dwarf_debug_names ()
+{
+  return quick_symbol_functions_up (new dwarf2_debug_names_index);
+}
+
 /* Utility hash function for a stmt_list_hash.  */
 
 static hashval_t
@@ -3449,8 +3562,8 @@ dw2_get_real_path (dwarf2_per_objfile *per_objfile,
   return qfn->real_names[index];
 }
 
-static struct symtab *
-dw2_find_last_source_symtab (struct objfile *objfile)
+struct symtab *
+dwarf2_base_index_functions::find_last_source_symtab (struct objfile *objfile)
 {
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
   dwarf2_per_cu_data *dwarf_cu = per_objfile->per_bfd->all_comp_units.back ();
@@ -3483,8 +3596,9 @@ dw2_free_cached_file_names (void **slot, void *info)
   return 1;
 }
 
-static void
-dw2_forget_cached_source_info (struct objfile *objfile)
+void
+dwarf2_base_index_functions::forget_cached_source_info
+     (struct objfile *objfile)
 {
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
@@ -3518,8 +3632,8 @@ dw2_map_expand_apply (struct objfile *objfile,
 
 /* Implementation of the map_symtabs_matching_filename method.  */
 
-static bool
-dw2_map_symtabs_matching_filename
+bool
+dwarf2_base_index_functions::map_symtabs_matching_filename
   (struct objfile *objfile, const char *name, const char *real_path,
    gdb::function_view<bool (symtab *)> callback)
 {
@@ -3768,9 +3882,10 @@ dw2_symtab_iter_next (struct dw2_symtab_iterator *iter)
   return NULL;
 }
 
-static struct compunit_symtab *
-dw2_lookup_symbol (struct objfile *objfile, block_enum block_index,
-		   const char *name, domain_enum domain)
+struct compunit_symtab *
+dwarf2_gdb_index::lookup_symbol (struct objfile *objfile,
+				 block_enum block_index,
+				 const char *name, domain_enum domain)
 {
   struct compunit_symtab *stab_best = NULL;
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
@@ -3811,8 +3926,8 @@ dw2_lookup_symbol (struct objfile *objfile, block_enum block_index,
   return stab_best;
 }
 
-static void
-dw2_print_stats (struct objfile *objfile)
+void
+dwarf2_base_index_functions::print_stats (struct objfile *objfile)
 {
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
   int total = (per_objfile->per_bfd->all_comp_units.size ()
@@ -3835,8 +3950,8 @@ dw2_print_stats (struct objfile *objfile)
    One use is to verify .gdb_index has been loaded by the
    gdb.dwarf2/gdb-index.exp testcase.  */
 
-static void
-dw2_dump (struct objfile *objfile)
+void
+dwarf2_gdb_index::dump (struct objfile *objfile)
 {
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
@@ -3852,9 +3967,9 @@ dw2_dump (struct objfile *objfile)
   printf_filtered ("\n");
 }
 
-static void
-dw2_expand_symtabs_for_function (struct objfile *objfile,
-				 const char *func_name)
+void
+dwarf2_gdb_index::expand_symtabs_for_function (struct objfile *objfile,
+					       const char *func_name)
 {
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
@@ -3868,8 +3983,8 @@ dw2_expand_symtabs_for_function (struct objfile *objfile,
 
 }
 
-static void
-dw2_expand_all_symtabs (struct objfile *objfile)
+void
+dwarf2_base_index_functions::expand_all_symtabs (struct objfile *objfile)
 {
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
   int total_units = (per_objfile->per_bfd->all_comp_units.size ()
@@ -3888,9 +4003,9 @@ dw2_expand_all_symtabs (struct objfile *objfile)
     }
 }
 
-static void
-dw2_expand_symtabs_with_fullname (struct objfile *objfile,
-				  const char *fullname)
+void
+dwarf2_base_index_functions::expand_symtabs_with_fullname
+     (struct objfile *objfile, const char *fullname)
 {
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
@@ -3996,6 +4111,18 @@ dw2_map_matching_symbols
     }
 }
 
+void
+dwarf2_gdb_index::map_matching_symbols
+  (struct objfile *objfile,
+   const lookup_name_info &name, domain_enum domain,
+   int global,
+   gdb::function_view<symbol_found_callback_ftype> callback,
+   symbol_compare_ftype *ordered_compare)
+{
+  dw2_map_matching_symbols (objfile, name, domain, global, callback,
+			    ordered_compare);
+}
+
 /* Starting from a search name, return the string that finds the upper
    bound of all strings that start with SEARCH_NAME in a sorted name
    list.  Returns the empty string to indicate that the upper bound is
@@ -4989,6 +5116,19 @@ dw2_expand_symtabs_matching
     }, per_objfile);
 }
 
+void
+dwarf2_gdb_index::expand_symtabs_matching
+    (struct objfile *objfile,
+     gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
+     const lookup_name_info *lookup_name,
+     gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
+     gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
+     enum search_domain kind)
+{
+  dw2_expand_symtabs_matching (objfile, file_matcher, lookup_name,
+			       symbol_matcher, expansion_notify, kind);
+}
+
 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
    symtab.  */
 
@@ -5017,12 +5157,13 @@ recursively_find_pc_sect_compunit_symtab (struct compunit_symtab *cust,
   return NULL;
 }
 
-static struct compunit_symtab *
-dw2_find_pc_sect_compunit_symtab (struct objfile *objfile,
-				  struct bound_minimal_symbol msymbol,
-				  CORE_ADDR pc,
-				  struct obj_section *section,
-				  int warn_if_readin)
+struct compunit_symtab *
+dwarf2_base_index_functions::find_pc_sect_compunit_symtab
+     (struct objfile *objfile,
+      struct bound_minimal_symbol msymbol,
+      CORE_ADDR pc,
+      struct obj_section *section,
+      int warn_if_readin)
 {
   struct dwarf2_per_cu_data *data;
   struct compunit_symtab *result;
@@ -5048,9 +5189,11 @@ dw2_find_pc_sect_compunit_symtab (struct objfile *objfile,
   return result;
 }
 
-static void
-dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun,
-			  void *data, int need_fullname)
+void
+dwarf2_base_index_functions::map_symbol_filenames (struct objfile *objfile,
+						   symbol_filename_ftype *fun,
+						   void *data,
+						   int need_fullname)
 {
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
@@ -5115,32 +5258,12 @@ dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun,
     });
 }
 
-static bool
-dw2_has_symbols (struct objfile *objfile)
+bool
+dwarf2_base_index_functions::has_symbols (struct objfile *objfile)
 {
   return true;
 }
 
-const struct quick_symbol_functions dwarf2_gdb_index_functions =
-{
-  dw2_has_symbols,
-  dw2_find_last_source_symtab,
-  dw2_forget_cached_source_info,
-  dw2_map_symtabs_matching_filename,
-  dw2_lookup_symbol,
-  NULL,
-  dw2_print_stats,
-  dw2_dump,
-  dw2_expand_symtabs_for_function,
-  dw2_expand_all_symtabs,
-  dw2_expand_symtabs_with_fullname,
-  dw2_map_matching_symbols,
-  dw2_expand_symtabs_matching,
-  dw2_find_pc_sect_compunit_symtab,
-  NULL,
-  dw2_map_symbol_filenames
-};
-
 /* DWARF-5 debug_names reader.  */
 
 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension.  */
@@ -5875,9 +5998,10 @@ dw2_debug_names_iterator::next ()
   return per_cu;
 }
 
-static struct compunit_symtab *
-dw2_debug_names_lookup_symbol (struct objfile *objfile, block_enum block_index,
-			       const char *name, domain_enum domain)
+struct compunit_symtab *
+dwarf2_debug_names_index::lookup_symbol
+     (struct objfile *objfile, block_enum block_index,
+      const char *name, domain_enum domain)
 {
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
@@ -5926,8 +6050,8 @@ dw2_debug_names_lookup_symbol (struct objfile *objfile, block_enum block_index,
    via "mt print objfiles".  The gdb.dwarf2/gdb-index.exp testcase
    uses this to verify that .debug_names has been loaded.  */
 
-static void
-dw2_debug_names_dump (struct objfile *objfile)
+void
+dwarf2_debug_names_index::dump (struct objfile *objfile)
 {
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
@@ -5940,9 +6064,9 @@ dw2_debug_names_dump (struct objfile *objfile)
   printf_filtered ("\n");
 }
 
-static void
-dw2_debug_names_expand_symtabs_for_function (struct objfile *objfile,
-					     const char *func_name)
+void
+dwarf2_debug_names_index::expand_symtabs_for_function
+     (struct objfile *objfile, const char *func_name)
 {
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
@@ -5960,8 +6084,8 @@ dw2_debug_names_expand_symtabs_for_function (struct objfile *objfile,
     }
 }
 
-static void
-dw2_debug_names_map_matching_symbols
+void
+dwarf2_debug_names_index::map_matching_symbols
   (struct objfile *objfile,
    const lookup_name_info &name, domain_enum domain,
    int global,
@@ -6018,8 +6142,8 @@ dw2_debug_names_map_matching_symbols
     }
 }
 
-static void
-dw2_debug_names_expand_symtabs_matching
+void
+dwarf2_debug_names_index::expand_symtabs_matching
   (struct objfile *objfile,
    gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
    const lookup_name_info *lookup_name,
@@ -6065,26 +6189,6 @@ dw2_debug_names_expand_symtabs_matching
     }, per_objfile);
 }
 
-const struct quick_symbol_functions dwarf2_debug_names_functions =
-{
-  dw2_has_symbols,
-  dw2_find_last_source_symtab,
-  dw2_forget_cached_source_info,
-  dw2_map_symtabs_matching_filename,
-  dw2_debug_names_lookup_symbol,
-  NULL,
-  dw2_print_stats,
-  dw2_debug_names_dump,
-  dw2_debug_names_expand_symtabs_for_function,
-  dw2_expand_all_symtabs,
-  dw2_expand_symtabs_with_fullname,
-  dw2_debug_names_map_matching_symbols,
-  dw2_debug_names_expand_symtabs_matching,
-  dw2_find_pc_sect_compunit_symtab,
-  NULL,
-  dw2_map_symbol_filenames
-};
-
 /* Get the content of the .gdb_index section of OBJ.  SECTION_OWNER should point
    to either a dwarf2_per_bfd or dwz_file object.  */
 
diff --git a/gdb/elfread.c b/gdb/elfread.c
index 3ba7221bfc9..4ca1f4d5284 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -1270,10 +1270,10 @@ elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
 	  switch (index_kind)
 	    {
 	    case dw_index_kind::GDB_INDEX:
-	      objfile->qf = &dwarf2_gdb_index_functions;
+	      objfile->qf = make_dwarf_gdb_index ();
 	      break;
 	    case dw_index_kind::DEBUG_NAMES:
-	      objfile->qf = &dwarf2_debug_names_functions;
+	      objfile->qf = make_dwarf_debug_names ();
 	      break;
 	    }
 	}
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 8d4a23ae044..7235713cbdf 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -37,6 +37,7 @@
 #include "gdbarch.h"
 #include "gdbsupport/refcounted-object.h"
 #include "jit.h"
+#include "quick-symbol.h"
 
 struct htab;
 struct objfile_data;
@@ -679,7 +680,7 @@ struct objfile
 
   /* The "quick" (aka partial) symbol functions for this symbol
      reader.  */
-  const struct quick_symbol_functions *qf = nullptr;
+  quick_symbol_functions_up qf;
 
   /* Per objfile data-pointers required by other GDB modules.  */
 
diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index 1f35ef2a44b..6b9ee184e9c 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -473,4 +473,68 @@ class psymtab_discarder
   struct partial_symtab *m_psymtab;
 };
 
+/* An implementation of quick_symbol_functions, specialized for
+   partial symbols.  */
+struct psymbol_functions : public quick_symbol_functions
+{
+  bool has_symbols (struct objfile *objfile) override;
+
+  struct symtab *find_last_source_symtab (struct objfile *objfile) override;
+
+  void forget_cached_source_info (struct objfile *objfile) override;
+
+  bool map_symtabs_matching_filename
+    (struct objfile *objfile, const char *name, const char *real_path,
+     gdb::function_view<bool (symtab *)> callback) override;
+
+  struct compunit_symtab *lookup_symbol (struct objfile *objfile,
+					 block_enum block_index,
+					 const char *name,
+					 domain_enum domain) override;
+
+  enum language lookup_global_symbol_language (struct objfile *objfile,
+					       const char *name,
+					       domain_enum domain,
+					       bool *symbol_found_p) override;
+
+  void print_stats (struct objfile *objfile) override;
+
+  void dump (struct objfile *objfile) override;
+
+  void expand_symtabs_for_function (struct objfile *objfile,
+				    const char *func_name) override;
+
+  void expand_all_symtabs (struct objfile *objfile) override;
+
+  void expand_symtabs_with_fullname (struct objfile *objfile,
+				     const char *fullname) override;
+
+  void map_matching_symbols
+    (struct objfile *,
+     const lookup_name_info &lookup_name,
+     domain_enum domain,
+     int global,
+     gdb::function_view<symbol_found_callback_ftype> callback,
+     symbol_compare_ftype *ordered_compare) override;
+
+  void expand_symtabs_matching
+    (struct objfile *objfile,
+     gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
+     const lookup_name_info *lookup_name,
+     gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
+     gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
+     enum search_domain kind) override;
+
+  struct compunit_symtab *find_pc_sect_compunit_symtab
+    (struct objfile *objfile, struct bound_minimal_symbol msymbol,
+     CORE_ADDR pc, struct obj_section *section, int warn_if_readin) override;
+
+  struct compunit_symtab *find_compunit_symtab_by_address
+    (struct objfile *objfile, CORE_ADDR address) override;
+
+  void map_symbol_filenames (struct objfile *objfile,
+			     symbol_filename_ftype *fun, void *data,
+			     int need_fullname) override;
+};
+
 #endif /* PSYMPRIV_H */
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 8c02fa253dc..c022daa7894 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -132,8 +132,8 @@ partial_map_expand_apply (struct objfile *objfile,
 /*  Psymtab version of map_symtabs_matching_filename.  See its definition in
     the definition of quick_symbol_functions in symfile.h.  */
 
-static bool
-psym_map_symtabs_matching_filename
+bool
+psymbol_functions::map_symtabs_matching_filename
   (struct objfile *objfile,
    const char *name,
    const char *real_path,
@@ -359,12 +359,13 @@ find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc,
 /* Psymtab version of find_pc_sect_compunit_symtab.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
-static struct compunit_symtab *
-psym_find_pc_sect_compunit_symtab (struct objfile *objfile,
-				   struct bound_minimal_symbol msymbol,
-				   CORE_ADDR pc,
-				   struct obj_section *section,
-				   int warn_if_readin)
+struct compunit_symtab *
+psymbol_functions::find_pc_sect_compunit_symtab
+     (struct objfile *objfile,
+      struct bound_minimal_symbol msymbol,
+      CORE_ADDR pc,
+      struct obj_section *section,
+      int warn_if_readin)
 {
   struct partial_symtab *ps = find_pc_sect_psymtab (objfile, pc, section,
 						    msymbol);
@@ -449,10 +450,10 @@ find_pc_sect_psymbol (struct objfile *objfile,
 /* Psymtab version of lookup_symbol.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
-static struct compunit_symtab *
-psym_lookup_symbol (struct objfile *objfile,
-		    block_enum block_index, const char *name,
-		    const domain_enum domain)
+struct compunit_symtab *
+psymbol_functions::lookup_symbol (struct objfile *objfile,
+				  block_enum block_index, const char *name,
+				  const domain_enum domain)
 {
   const int psymtab_index = (block_index == GLOBAL_BLOCK ? 1 : 0);
   struct compunit_symtab *stab_best = NULL;
@@ -500,9 +501,11 @@ psym_lookup_symbol (struct objfile *objfile,
 /* Psymtab version of lookup_global_symbol_language.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
-static enum language
-psym_lookup_global_symbol_language (struct objfile *objfile, const char *name,
-				    domain_enum domain, bool *symbol_found_p)
+enum language
+psymbol_functions::lookup_global_symbol_language (struct objfile *objfile,
+						  const char *name,
+						  domain_enum domain,
+						  bool *symbol_found_p)
 {
   *symbol_found_p = false;
   if (objfile->sf == NULL)
@@ -754,8 +757,8 @@ psymtab_to_symtab (struct objfile *objfile, struct partial_symtab *pst)
 /* Psymtab version of find_last_source_symtab.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
-static struct symtab *
-psym_find_last_source_symtab (struct objfile *ofp)
+struct symtab *
+psymbol_functions::find_last_source_symtab (struct objfile *ofp)
 {
   struct partial_symtab *cs_pst = NULL;
 
@@ -792,8 +795,8 @@ psym_find_last_source_symtab (struct objfile *ofp)
 /* Psymtab version of forget_cached_source_info.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
-static void
-psym_forget_cached_source_info (struct objfile *objfile)
+void
+psymbol_functions::forget_cached_source_info (struct objfile *objfile)
 {
   for (partial_symtab *pst : require_partial_symbols (objfile, true))
     {
@@ -975,8 +978,8 @@ dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
 /* Psymtab version of print_stats.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
-static void
-psym_print_stats (struct objfile *objfile)
+void
+psymbol_functions::print_stats (struct objfile *objfile)
 {
   int i;
 
@@ -992,8 +995,8 @@ psym_print_stats (struct objfile *objfile)
 /* Psymtab version of dump.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
-static void
-psym_dump (struct objfile *objfile)
+void
+psymbol_functions::dump (struct objfile *objfile)
 {
   struct partial_symtab *psymtab;
 
@@ -1017,9 +1020,9 @@ psym_dump (struct objfile *objfile)
 /* Psymtab version of expand_symtabs_for_function.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
-static void
-psym_expand_symtabs_for_function (struct objfile *objfile,
-				  const char *func_name)
+void
+psymbol_functions::expand_symtabs_for_function (struct objfile *objfile,
+						const char *func_name)
 {
   lookup_name_info base_lookup (func_name, symbol_name_match_type::FULL);
   lookup_name_info lookup_name = base_lookup.make_ignore_params ();
@@ -1040,8 +1043,8 @@ psym_expand_symtabs_for_function (struct objfile *objfile,
 /* Psymtab version of expand_all_symtabs.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
-static void
-psym_expand_all_symtabs (struct objfile *objfile)
+void
+psymbol_functions::expand_all_symtabs (struct objfile *objfile)
 {
   for (partial_symtab *psymtab : require_partial_symbols (objfile, true))
     psymtab_to_symtab (objfile, psymtab);
@@ -1050,9 +1053,9 @@ psym_expand_all_symtabs (struct objfile *objfile)
 /* Psymtab version of expand_symtabs_with_fullname.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
-static void
-psym_expand_symtabs_with_fullname (struct objfile *objfile,
-				   const char *fullname)
+void
+psymbol_functions::expand_symtabs_with_fullname (struct objfile *objfile,
+						 const char *fullname)
 {
   for (partial_symtab *p : require_partial_symbols (objfile, true))
     {
@@ -1072,10 +1075,11 @@ psym_expand_symtabs_with_fullname (struct objfile *objfile,
 /* Psymtab version of map_symbol_filenames.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
-static void
-psym_map_symbol_filenames (struct objfile *objfile,
-			   symbol_filename_ftype *fun, void *data,
-			   int need_fullname)
+void
+psymbol_functions::map_symbol_filenames (struct objfile *objfile,
+					 symbol_filename_ftype *fun,
+					 void *data,
+					 int need_fullname)
 {
   for (partial_symtab *ps : require_partial_symbols (objfile, true))
     {
@@ -1148,8 +1152,8 @@ psymtab_to_fullname (struct partial_symtab *ps)
 /* Psymtab version of map_matching_symbols.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
-static void
-psym_map_matching_symbols
+void
+psymbol_functions::map_matching_symbols
   (struct objfile *objfile,
    const lookup_name_info &name, domain_enum domain,
    int global,
@@ -1273,8 +1277,8 @@ recursively_search_psymtabs
 /* Psymtab version of expand_symtabs_matching.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
-static void
-psym_expand_symtabs_matching
+void
+psymbol_functions::expand_symtabs_matching
   (struct objfile *objfile,
    gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
    const lookup_name_info *lookup_name,
@@ -1335,8 +1339,8 @@ psym_expand_symtabs_matching
 /* Psymtab version of has_symbols.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
-static bool
-psym_has_symbols (struct objfile *objfile)
+bool
+psymbol_functions::has_symbols (struct objfile *objfile)
 {
   return objfile->partial_symtabs->psymtabs != NULL;
 }
@@ -1367,9 +1371,9 @@ psym_fill_psymbol_map (struct objfile *objfile,
 /* See find_compunit_symtab_by_address in quick_symbol_functions, in
    symfile.h.  */
 
-static compunit_symtab *
-psym_find_compunit_symtab_by_address (struct objfile *objfile,
-				      CORE_ADDR address)
+compunit_symtab *
+psymbol_functions::find_compunit_symtab_by_address (struct objfile *objfile,
+						    CORE_ADDR address)
 {
   if (objfile->psymbol_map.empty ())
     {
@@ -1409,25 +1413,11 @@ psym_find_compunit_symtab_by_address (struct objfile *objfile,
   return psymtab_to_symtab (objfile, iter->second);
 }
 
-const struct quick_symbol_functions psym_functions =
+quick_symbol_functions_up
+make_psymbol_functions ()
 {
-  psym_has_symbols,
-  psym_find_last_source_symtab,
-  psym_forget_cached_source_info,
-  psym_map_symtabs_matching_filename,
-  psym_lookup_symbol,
-  psym_lookup_global_symbol_language,
-  psym_print_stats,
-  psym_dump,
-  psym_expand_symtabs_for_function,
-  psym_expand_all_symtabs,
-  psym_expand_symtabs_with_fullname,
-  psym_map_matching_symbols,
-  psym_expand_symtabs_matching,
-  psym_find_pc_sect_compunit_symtab,
-  psym_find_compunit_symtab_by_address,
-  psym_map_symbol_filenames
-};
+  return quick_symbol_functions_up (new psymbol_functions);
+}
 
 \f
 
diff --git a/gdb/psymtab.h b/gdb/psymtab.h
index dbff302b1d1..45eaf0b9013 100644
--- a/gdb/psymtab.h
+++ b/gdb/psymtab.h
@@ -146,11 +146,6 @@ class psymtab_storage
 };
 
 
-extern const struct quick_symbol_functions psym_functions;
-
-extern const struct quick_symbol_functions dwarf2_gdb_index_functions;
-extern const struct quick_symbol_functions dwarf2_debug_names_functions;
-
 /* Ensure that the partial symbols for OBJFILE have been loaded.  If
    VERBOSE is true, then this will print a message when symbols
    are loaded.  This function returns a range adapter suitable for
@@ -159,4 +154,6 @@ extern const struct quick_symbol_functions dwarf2_debug_names_functions;
 extern psymtab_storage::partial_symtab_range require_partial_symbols
     (struct objfile *objfile, bool verbose);
 
+extern quick_symbol_functions_up make_psymbol_functions ();
+
 #endif /* PSYMTAB_H */
diff --git a/gdb/quick-symbol.h b/gdb/quick-symbol.h
index fa5f5012211..85e7a32eacd 100644
--- a/gdb/quick-symbol.h
+++ b/gdb/quick-symbol.h
@@ -66,16 +66,20 @@ typedef void (expand_symtabs_exp_notify_ftype) (compunit_symtab *symtab);
 
 struct quick_symbol_functions
 {
+  virtual ~quick_symbol_functions ()
+  {
+  }
+
   /* Return true if this objfile has any "partial" symbols
      available.  */
-  bool (*has_symbols) (struct objfile *objfile);
+  virtual bool has_symbols (struct objfile *objfile) = 0;
 
   /* Return the symbol table for the "last" file appearing in
      OBJFILE.  */
-  struct symtab *(*find_last_source_symtab) (struct objfile *objfile);
+  virtual struct symtab *find_last_source_symtab (struct objfile *objfile) = 0;
 
   /* Forget all cached full file names for OBJFILE.  */
-  void (*forget_cached_source_info) (struct objfile *objfile);
+  virtual void forget_cached_source_info (struct objfile *objfile) = 0;
 
   /* Expand and iterate over each "partial" symbol table in OBJFILE
      where the source file is named NAME.
@@ -89,9 +93,9 @@ struct quick_symbol_functions
      Then, this calls iterate_over_some_symtabs (or equivalent) over
      all newly-created symbol tables, passing CALLBACK to it.
      The result of this call is returned.  */
-  bool (*map_symtabs_matching_filename)
+  virtual bool map_symtabs_matching_filename
     (struct objfile *objfile, const char *name, const char *real_path,
-     gdb::function_view<bool (symtab *)> callback);
+     gdb::function_view<bool (symtab *)> callback) = 0;
 
   /* Check to see if the symbol is defined in a "partial" symbol table
      of OBJFILE.  BLOCK_INDEX should be either GLOBAL_BLOCK or STATIC_BLOCK,
@@ -103,10 +107,10 @@ struct quick_symbol_functions
      defined, or NULL if no such symbol table exists.  If OBJFILE
      contains !TYPE_OPAQUE symbol prefer its compunit.  If it contains
      only TYPE_OPAQUE symbol(s), return at least that compunit.  */
-  struct compunit_symtab *(*lookup_symbol) (struct objfile *objfile,
-					    block_enum block_index,
-					    const char *name,
-					    domain_enum domain);
+  virtual struct compunit_symtab *lookup_symbol (struct objfile *objfile,
+						 block_enum block_index,
+						 const char *name,
+						 domain_enum domain) = 0;
 
   /* Check to see if the global symbol is defined in a "partial" symbol table
      of OBJFILE. NAME is the name of the symbol to look for.  DOMAIN
@@ -114,35 +118,36 @@ struct quick_symbol_functions
 
      If found, sets *symbol_found_p to true and returns the symbol language.
      defined, or NULL if no such symbol table exists.  */
-  enum language (*lookup_global_symbol_language) (struct objfile *objfile,
-						  const char *name,
-						  domain_enum domain,
-						  bool *symbol_found_p);
+  virtual enum language lookup_global_symbol_language
+       (struct objfile *objfile,
+	const char *name,
+	domain_enum domain,
+	bool *symbol_found_p) = 0;
 
   /* Print statistics about any indices loaded for OBJFILE.  The
      statistics should be printed to gdb_stdout.  This is used for
      "maint print statistics".  */
-  void (*print_stats) (struct objfile *objfile);
+  virtual void print_stats (struct objfile *objfile) = 0;
 
   /* Dump any indices loaded for OBJFILE.  The dump should go to
      gdb_stdout.  This is used for "maint print objfiles".  */
-  void (*dump) (struct objfile *objfile);
+  virtual void dump (struct objfile *objfile) = 0;
 
   /* Find all the symbols in OBJFILE named FUNC_NAME, and ensure that
      the corresponding symbol tables are loaded.  */
-  void (*expand_symtabs_for_function) (struct objfile *objfile,
-				       const char *func_name);
+  virtual void expand_symtabs_for_function (struct objfile *objfile,
+					    const char *func_name) = 0;
 
   /* Read all symbol tables associated with OBJFILE.  */
-  void (*expand_all_symtabs) (struct objfile *objfile);
+  virtual void expand_all_symtabs (struct objfile *objfile) = 0;
 
   /* Read all symbol tables associated with OBJFILE which have
      symtab_to_fullname equal to FULLNAME.
      This is for the purposes of examining code only, e.g., expand_line_sal.
      The routine may ignore debug info that is known to not be useful with
      code, e.g., DW_TAG_type_unit for dwarf debug info.  */
-  void (*expand_symtabs_with_fullname) (struct objfile *objfile,
-					const char *fullname);
+  virtual void expand_symtabs_with_fullname (struct objfile *objfile,
+					     const char *fullname) = 0;
 
   /* Find global or static symbols in all tables that are in DOMAIN
      and for which MATCH (symbol name, NAME) == 0, passing each to 
@@ -161,13 +166,13 @@ struct quick_symbol_functions
      CALLBACK returns true to indicate that the scan should continue, or
      false to indicate that the scan should be terminated.  */
 
-  void (*map_matching_symbols)
+  virtual void map_matching_symbols
     (struct objfile *,
      const lookup_name_info &lookup_name,
      domain_enum domain,
      int global,
      gdb::function_view<symbol_found_callback_ftype> callback,
-     symbol_compare_ftype *ordered_compare);
+     symbol_compare_ftype *ordered_compare) = 0;
 
   /* Expand all symbol tables in OBJFILE matching some criteria.
 
@@ -190,13 +195,13 @@ struct quick_symbol_functions
      If SYMBOL_MATCHER returns false, then the symbol is skipped.
 
      Otherwise, the symbol's symbol table is expanded.  */
-  void (*expand_symtabs_matching)
+  virtual void expand_symtabs_matching
     (struct objfile *objfile,
      gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
      const lookup_name_info *lookup_name,
      gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
      gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
-     enum search_domain kind);
+     enum search_domain kind) = 0;
 
   /* Return the comp unit from OBJFILE that contains PC and
      SECTION.  Return NULL if there is no such compunit.  This
@@ -204,25 +209,27 @@ struct quick_symbol_functions
      address exactly matches PC, or, if there is no exact match, the
      compunit that contains a symbol whose address is closest to
      PC.  */
-  struct compunit_symtab *(*find_pc_sect_compunit_symtab)
+  virtual struct compunit_symtab *find_pc_sect_compunit_symtab
     (struct objfile *objfile, struct bound_minimal_symbol msymbol,
-     CORE_ADDR pc, struct obj_section *section, int warn_if_readin);
+     CORE_ADDR pc, struct obj_section *section, int warn_if_readin) = 0;
 
   /* Return the comp unit from OBJFILE that contains a symbol at
      ADDRESS.  Return NULL if there is no such comp unit.  Unlike
      find_pc_sect_compunit_symtab, any sort of symbol (not just text
      symbols) can be considered, and only exact address matches are
-     considered.  This pointer may be NULL.  */
-  struct compunit_symtab *(*find_compunit_symtab_by_address)
-    (struct objfile *objfile, CORE_ADDR address);
+     considered.  */
+  virtual struct compunit_symtab *find_compunit_symtab_by_address
+    (struct objfile *objfile, CORE_ADDR address) = 0;
 
   /* Call a callback for every file defined in OBJFILE whose symtab is
      not already read in.  FUN is the callback.  It is passed the file's
      FILENAME, the file's FULLNAME (if need_fullname is non-zero), and
      the DATA passed to this function.  */
-  void (*map_symbol_filenames) (struct objfile *objfile,
-				symbol_filename_ftype *fun, void *data,
-				int need_fullname);
+  virtual void map_symbol_filenames (struct objfile *objfile,
+				     symbol_filename_ftype *fun, void *data,
+				     int need_fullname) = 0;
 };
 
+typedef std::unique_ptr<quick_symbol_functions> quick_symbol_functions_up;
+
 #endif /* GDB_QUICK_SYMBOL_H */
diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index da3439d7928..55865ab03b0 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -328,7 +328,7 @@ objfile::find_compunit_symtab_by_address (CORE_ADDR address)
 		      hex_string (address));
 
   struct compunit_symtab *result = NULL;
-  if (qf != nullptr && qf->find_compunit_symtab_by_address != NULL)
+  if (qf != nullptr)
     result = qf->find_compunit_symtab_by_address (this, address);
 
   if (debug_symfile)
@@ -348,7 +348,7 @@ objfile::lookup_global_symbol_language (const char *name,
 {
   enum language result = language_unknown;
 
-  if (qf != nullptr && qf->lookup_global_symbol_language != nullptr)
+  if (qf != nullptr)
     result = qf->lookup_global_symbol_language (this, name, domain,
 						symbol_found_p);
   else
diff --git a/gdb/symfile.c b/gdb/symfile.c
index d56d623c588..d0b9da2138b 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -904,7 +904,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->qf = &psym_functions;
+  objfile->qf = make_psymbol_functions ();
 
   if (objfile->sf == NULL)
     {
@@ -2555,7 +2555,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->qf = &psym_functions;
+	  objfile->qf = make_psymbol_functions ();
 
 	  build_objfile_section_table (objfile);
 
-- 
2.26.2


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 09/26] Move psymbol_map out of objfile
  2021-02-28 20:37 [PATCH 00/26] Allow multiple "partial" symtab readers per objfile Tom Tromey
                   ` (7 preceding siblings ...)
  2021-02-28 20:37 ` [PATCH 08/26] Convert quick_symbol_functions to use methods Tom Tromey
@ 2021-02-28 20:37 ` Tom Tromey
  2021-02-28 20:37 ` [PATCH 10/26] Change how some psymbol readers access the psymtab storage Tom Tromey
                   ` (17 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: Tom Tromey @ 2021-02-28 20:37 UTC (permalink / raw)
  To: gdb-patches

objfile::psymbol_map is used to implement a Rust feature.  It is
currently specific to partial symbols -- it isn't used by the DWARF
indices.

This patch moves it out of objfile and into psymbol_functions, adding
a new method to quick_symbol_functions to handle the clearing case.
This is needed because the map holds unrelocated addresses.

gdb/ChangeLog
2021-02-28  Tom Tromey  <tom@tromey.com>

	* quick-symbol.h (struct quick_symbol_functions)
	<relocated>: New method.
	* psymtab.h (struct psymbol_functions) <relocated>: New
	method.
	<fill_psymbol_map>: Declare method.
	<m_psymbol_map>: New member.
	* psymtab.c (psymbol_functions::fill_psymbol_map): Rename.
	(psymbol_functions::find_compunit_symtab_by_address): Update.
	* objfiles.h (reset_psymtabs): Don't clear psymbol_map.
	(struct objfile) <psymbol_map>: Remove.
	* objfiles.c (objfile_relocate1): Update.
---
 gdb/ChangeLog      | 14 ++++++++++++++
 gdb/objfiles.c     |  6 +++---
 gdb/objfiles.h     |  6 ------
 gdb/psympriv.h     | 17 +++++++++++++++++
 gdb/psymtab.c      | 37 +++++++++++++++++++------------------
 gdb/quick-symbol.h |  7 +++++++
 6 files changed, 60 insertions(+), 27 deletions(-)

diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index f18f6158fc3..bfa5f0443e3 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -703,9 +703,9 @@ objfile_relocate1 (struct objfile *objfile,
       }
   }
 
-  /* This stores relocated addresses and so must be cleared.  This
-     will cause it to be recreated on demand.  */
-  objfile->psymbol_map.clear ();
+  /* Notify the quick symbol object.  */
+  if (objfile->qf)
+    objfile->qf->relocated ();
 
   /* Relocate isolated symbols.  */
   {
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 7235713cbdf..cd136eef788 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -459,7 +459,6 @@ struct objfile
 
   void reset_psymtabs ()
   {
-    psymbol_map.clear ();
     partial_symtabs.reset (new psymtab_storage ());
   }
 
@@ -665,11 +664,6 @@ struct objfile
 
   struct obstack objfile_obstack {};
 
-  /* Map symbol addresses to the partial symtab that defines the
-     object at that address.  */
-
-  std::vector<std::pair<CORE_ADDR, partial_symtab *>> psymbol_map;
-
   /* Structure which keeps track of functions that manipulate objfile's
      of the same type as this objfile.  I.e. the function to read partial
      symbols for example.  Note that this structure is in statically
diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index 6b9ee184e9c..73f00a50992 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -535,6 +535,23 @@ struct psymbol_functions : public quick_symbol_functions
   void map_symbol_filenames (struct objfile *objfile,
 			     symbol_filename_ftype *fun, void *data,
 			     int need_fullname) override;
+
+  void relocated () override
+  {
+    m_psymbol_map.clear ();
+  }
+
+private:
+
+  void fill_psymbol_map (struct objfile *objfile,
+			 struct partial_symtab *psymtab,
+			 std::set<CORE_ADDR> *seen_addrs,
+			 const std::vector<partial_symbol *> &symbols);
+
+  /* Map symbol addresses to the partial symtab that defines the
+     object at that address.  */
+
+  std::vector<std::pair<CORE_ADDR, partial_symtab *>> m_psymbol_map;
 };
 
 #endif /* PSYMPRIV_H */
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index c022daa7894..45a4db71c1f 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -1346,13 +1346,14 @@ psymbol_functions::has_symbols (struct objfile *objfile)
 }
 
 /* Helper function for psym_find_compunit_symtab_by_address that fills
-   in psymbol_map for a given range of psymbols.  */
+   in m_psymbol_map for a given range of psymbols.  */
 
-static void
-psym_fill_psymbol_map (struct objfile *objfile,
-		       struct partial_symtab *psymtab,
-		       std::set<CORE_ADDR> *seen_addrs,
-		       const std::vector<partial_symbol *> &symbols)
+void
+psymbol_functions::fill_psymbol_map
+     (struct objfile *objfile,
+      struct partial_symtab *psymtab,
+      std::set<CORE_ADDR> *seen_addrs,
+      const std::vector<partial_symbol *> &symbols)
 {
   for (partial_symbol *psym : symbols)
     {
@@ -1362,7 +1363,7 @@ psym_fill_psymbol_map (struct objfile *objfile,
 	  if (seen_addrs->find (addr) == seen_addrs->end ())
 	    {
 	      seen_addrs->insert (addr);
-	      objfile->psymbol_map.emplace_back (addr, psymtab);
+	      m_psymbol_map.emplace_back (addr, psymtab);
 	    }
 	}
     }
@@ -1375,23 +1376,23 @@ compunit_symtab *
 psymbol_functions::find_compunit_symtab_by_address (struct objfile *objfile,
 						    CORE_ADDR address)
 {
-  if (objfile->psymbol_map.empty ())
+  if (m_psymbol_map.empty ())
     {
       std::set<CORE_ADDR> seen_addrs;
 
       for (partial_symtab *pst : require_partial_symbols (objfile, true))
 	{
-	  psym_fill_psymbol_map (objfile, pst,
-				 &seen_addrs,
-				 pst->global_psymbols);
-	  psym_fill_psymbol_map (objfile, pst,
-				 &seen_addrs,
-				 pst->static_psymbols);
+	  fill_psymbol_map (objfile, pst,
+			    &seen_addrs,
+			    pst->global_psymbols);
+	  fill_psymbol_map (objfile, pst,
+			    &seen_addrs,
+			    pst->static_psymbols);
 	}
 
-      objfile->psymbol_map.shrink_to_fit ();
+      m_psymbol_map.shrink_to_fit ();
 
-      std::sort (objfile->psymbol_map.begin (), objfile->psymbol_map.end (),
+      std::sort (m_psymbol_map.begin (), m_psymbol_map.end (),
 		 [] (const std::pair<CORE_ADDR, partial_symtab *> &a,
 		     const std::pair<CORE_ADDR, partial_symtab *> &b)
 		 {
@@ -1400,14 +1401,14 @@ psymbol_functions::find_compunit_symtab_by_address (struct objfile *objfile,
     }
 
   auto iter = std::lower_bound
-    (objfile->psymbol_map.begin (), objfile->psymbol_map.end (), address,
+    (m_psymbol_map.begin (), m_psymbol_map.end (), address,
      [] (const std::pair<CORE_ADDR, partial_symtab *> &a,
 	 CORE_ADDR b)
      {
        return a.first < b;
      });
 
-  if (iter == objfile->psymbol_map.end () || iter->first != address)
+  if (iter == m_psymbol_map.end () || iter->first != address)
     return NULL;
 
   return psymtab_to_symtab (objfile, iter->second);
diff --git a/gdb/quick-symbol.h b/gdb/quick-symbol.h
index 85e7a32eacd..319ffe681c8 100644
--- a/gdb/quick-symbol.h
+++ b/gdb/quick-symbol.h
@@ -228,6 +228,13 @@ struct quick_symbol_functions
   virtual void map_symbol_filenames (struct objfile *objfile,
 				     symbol_filename_ftype *fun, void *data,
 				     int need_fullname) = 0;
+
+  /* This is called when the objfile is relocated.  It can be used to
+     clean up any internal caches.  */
+  virtual void relocated ()
+  {
+    /* Do nothing.  */
+  }
 };
 
 typedef std::unique_ptr<quick_symbol_functions> quick_symbol_functions_up;
-- 
2.26.2


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 10/26] Change how some psymbol readers access the psymtab storage
  2021-02-28 20:37 [PATCH 00/26] Allow multiple "partial" symtab readers per objfile Tom Tromey
                   ` (8 preceding siblings ...)
  2021-02-28 20:37 ` [PATCH 09/26] Move psymbol_map out of objfile Tom Tromey
@ 2021-02-28 20:37 ` Tom Tromey
  2021-02-28 20:37 ` [PATCH 11/26] Do not pass objfile to psymtab_discarder Tom Tromey
                   ` (16 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: Tom Tromey @ 2021-02-28 20:37 UTC (permalink / raw)
  To: gdb-patches

Currently, all psymbol readers access the psymtab storage via the
objfile.  This is done directly at any spot requiring the storage.

In order to move psymbols out of the objfile, the psymtab_storage must
be passed in explicitly.  This patch consolidates the access of the
storage in a single place in these readers, updating various functions
to pass the storage object around.  "Hidden" uses, like
"objfile->psymtabs ()", are also updated.

The DWARF reader is not yet touched.  That requires more complicated
changes.

gdb/ChangeLog
2021-02-28  Tom Tromey  <tom@tromey.com>

	* xcoffread.c (xcoff_end_psymtab): Add partial_symtabs parameter.
	(xcoff_end_psymtab): Update.
	(scan_xcoff_symtab): Add partial_symtabs parameter.
	(xcoff_initial_scan): Update.
	* stabsread.h (dbx_end_psymtab): Add partial_symtabs parameter.
	* mdebugread.c (mdebug_build_psymtabs): Update.
	(parse_partial_symbols): Add partial_symtabs parameter.
	* dbxread.c (dbx_symfile_read): Update.
	(read_dbx_symtab): Add partial_symtabs parameter.
	(read_dbx_symtab): Update.
	(dbx_end_psymtab): Add partial_symtabs parameter.
---
 gdb/ChangeLog    | 14 ++++++++++++++
 gdb/dbxread.c    | 32 ++++++++++++++++++++------------
 gdb/mdebugread.c | 15 +++++++++------
 gdb/stabsread.h  |  3 ++-
 gdb/xcoffread.c  | 22 ++++++++++++++--------
 5 files changed, 59 insertions(+), 27 deletions(-)

diff --git a/gdb/dbxread.c b/gdb/dbxread.c
index 9003822a0f1..9a470bf8177 100644
--- a/gdb/dbxread.c
+++ b/gdb/dbxread.c
@@ -270,7 +270,8 @@ static void dbx_read_symtab (legacy_psymtab *self,
 
 static void dbx_expand_psymtab (legacy_psymtab *, struct objfile *);
 
-static void read_dbx_symtab (minimal_symbol_reader &, struct objfile *);
+static void read_dbx_symtab (minimal_symbol_reader &, psymtab_storage *,
+			     struct objfile *);
 
 static legacy_psymtab *find_corresponding_bincl_psymtab (const char *,
 								int);
@@ -544,7 +545,8 @@ dbx_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
 
   /* Read stabs data from executable file and define symbols.  */
 
-  read_dbx_symtab (reader, objfile);
+  psymtab_storage *partial_symtabs = objfile->partial_symtabs.get ();
+  read_dbx_symtab (reader, partial_symtabs, objfile);
 
   /* Install any minimal symbols that have been collected as the current
      minimal symbols for this objfile.  */
@@ -946,7 +948,9 @@ function_outside_compilation_unit_complaint (const char *arg1)
    debugging information is available.  */
 
 static void
-read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
+read_dbx_symtab (minimal_symbol_reader &reader,
+		 psymtab_storage *partial_symtabs,
+		 struct objfile *objfile)
 {
   struct gdbarch *gdbarch = objfile->arch ();
   struct external_nlist *bufp = 0;	/* =0 avoids gcc -Wall glitch.  */
@@ -1127,7 +1131,8 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 		     which are not the address.  */
 		  && nlist.n_value >= pst->raw_text_low ())
 		{
-		  dbx_end_psymtab (objfile, pst, psymtab_include_list,
+		  dbx_end_psymtab (objfile, partial_symtabs,
+				   pst, psymtab_include_list,
 				   includes_used, symnum * symbol_size,
 				   nlist.n_value > pst->raw_text_high ()
 				   ? nlist.n_value : pst->raw_text_high (),
@@ -1242,7 +1247,8 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 
 		if (pst)
 		  {
-		    dbx_end_psymtab (objfile, pst, psymtab_include_list,
+		    dbx_end_psymtab (objfile, partial_symtabs,
+				     pst, psymtab_include_list,
 				     includes_used, symnum * symbol_size,
 				     (valu > pst->raw_text_high ()
 				      ? valu : pst->raw_text_high ()),
@@ -1813,7 +1819,7 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 	     compiled without debugging info follows this module.  */
 	  if (pst && gdbarch_sofun_address_maybe_missing (gdbarch))
 	    {
-	      dbx_end_psymtab (objfile, pst,
+	      dbx_end_psymtab (objfile, partial_symtabs, pst,
 			       psymtab_include_list, includes_used,
 			       symnum * symbol_size,
 			       (CORE_ADDR) 0, dependency_list,
@@ -1879,7 +1885,8 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 	 : lowest_text_address)
 	+ text_size;
 
-      dbx_end_psymtab (objfile, pst, psymtab_include_list, includes_used,
+      dbx_end_psymtab (objfile, partial_symtabs,
+		       pst, psymtab_include_list, includes_used,
 		       symnum * symbol_size,
 		       (text_end > pst->raw_text_high ()
 			? text_end : pst->raw_text_high ()),
@@ -1923,7 +1930,8 @@ start_psymtab (struct objfile *objfile, const char *filename, CORE_ADDR textlow,
    FIXME:  List variables and peculiarities of same.  */
 
 legacy_psymtab *
-dbx_end_psymtab (struct objfile *objfile, legacy_psymtab *pst,
+dbx_end_psymtab (struct objfile *objfile, psymtab_storage *partial_symtabs,
+		 legacy_psymtab *pst,
 		 const char **include_list, int num_includes,
 		 int capping_symbol_offset, CORE_ADDR capping_text,
 		 legacy_psymtab **dependency_list,
@@ -1997,7 +2005,7 @@ dbx_end_psymtab (struct objfile *objfile, legacy_psymtab *pst,
 	 address, set it to our starting address.  Take care to not set our
 	 own ending address to our starting address.  */
 
-      for (partial_symtab *p1 : objfile->psymtabs ())
+      for (partial_symtab *p1 : partial_symtabs->range ())
 	if (!p1->text_high_valid && p1->text_low_valid && p1 != pst)
 	  p1->set_text_high (pst->raw_text_low ());
     }
@@ -2010,7 +2018,7 @@ dbx_end_psymtab (struct objfile *objfile, legacy_psymtab *pst,
   if (number_dependencies)
     {
       pst->dependencies
-	= objfile->partial_symtabs->allocate_dependencies (number_dependencies);
+	= partial_symtabs->allocate_dependencies (number_dependencies);
       memcpy (pst->dependencies, dependency_list,
 	      number_dependencies * sizeof (legacy_psymtab *));
     }
@@ -2030,7 +2038,7 @@ dbx_end_psymtab (struct objfile *objfile, legacy_psymtab *pst,
       /* We could save slight bits of space by only making one of these,
 	 shared by the entire set of include files.  FIXME-someday.  */
       subpst->dependencies =
-	objfile->partial_symtabs->allocate_dependencies (1);
+	partial_symtabs->allocate_dependencies (1);
       subpst->dependencies[0] = pst;
       subpst->number_of_dependencies = 1;
 
@@ -2050,7 +2058,7 @@ dbx_end_psymtab (struct objfile *objfile, legacy_psymtab *pst,
 	 is not empty, but we don't realize that.  Fixing that without slowing
 	 things down might be tricky.  */
 
-      objfile->partial_symtabs->discard_psymtab (pst);
+      partial_symtabs->discard_psymtab (pst);
 
       /* Indicate that psymtab was thrown away.  */
       pst = NULL;
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index 2fe4ae08d20..d178beef734 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -222,6 +222,7 @@ static int upgrade_type (int, struct type **, int, union aux_ext *,
 			 int, const char *);
 
 static void parse_partial_symbols (minimal_symbol_reader &,
+				   psymtab_storage *,
 				   struct objfile *);
 
 static int has_opaque_xref (FDR *, SYMR *);
@@ -357,7 +358,8 @@ mdebug_build_psymtabs (minimal_symbol_reader &reader,
 	(*swap->swap_fdr_in) (objfile->obfd, fdr_src, fdr_ptr);
     }
 
-  parse_partial_symbols (reader, objfile);
+  psymtab_storage *partial_symtabs = objfile->partial_symtabs.get ();
+  parse_partial_symbols (reader, partial_symtabs, objfile);
 
 #if 0
   /* Check to make sure file was compiled with -g.  If not, warn the
@@ -2281,6 +2283,7 @@ record_minimal_symbol (minimal_symbol_reader &reader,
 
 static void
 parse_partial_symbols (minimal_symbol_reader &reader,
+		       psymtab_storage *partial_symtabs,
 		       struct objfile *objfile)
 {
   struct gdbarch *gdbarch = objfile->arch ();
@@ -3642,7 +3645,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
       /* Link pst to FDR.  dbx_end_psymtab returns NULL if the psymtab was
 	 empty and put on the free list.  */
       fdr_to_pst[f_idx].pst
-	= dbx_end_psymtab (objfile, save_pst,
+	= dbx_end_psymtab (objfile, partial_symtabs, save_pst,
 			   psymtab_include_list, includes_used,
 			   -1, save_pst->raw_text_high (),
 			   dependency_list, dependencies_used,
@@ -3666,7 +3669,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 	  && save_pst->text_low_valid
 	  && !(objfile->flags & OBJF_REORDERED))
 	{
-	  for (partial_symtab *iter : objfile->psymtabs ())
+	  for (partial_symtab *iter : partial_symtabs->range ())
 	    {
 	      if (save_pst != iter
 		  && save_pst->raw_text_low () >= iter->raw_text_low ()
@@ -3697,7 +3700,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 	 source files or a reverse .h -> .c dependency for header files.  */
       pst->number_of_dependencies = 0;
       pst->dependencies
-	= objfile->partial_symtabs->allocate_dependencies (fh->crfd - 1);
+	= partial_symtabs->allocate_dependencies (fh->crfd - 1);
       for (s_idx = 1; s_idx < fh->crfd; s_idx++)
 	{
 	  RFDT rh;
@@ -3726,11 +3729,11 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 
   /* Remove the dummy psymtab created for -O3 images above, if it is
      still empty, to enable the detection of stripped executables.  */
-  partial_symtab *pst_del = objfile->partial_symtabs->psymtabs;
+  partial_symtab *pst_del = partial_symtabs->psymtabs;
   if (pst_del->next == NULL
       && pst_del->number_of_dependencies == 0
       && pst_del->empty ())
-    objfile->partial_symtabs->discard_psymtab (pst_del);
+    partial_symtabs->discard_psymtab (pst_del);
 }
 
 /* If the current psymbol has an enumerated type, we need to add
diff --git a/gdb/stabsread.h b/gdb/stabsread.h
index 8b5d70b72f4..e9d5663cc97 100644
--- a/gdb/stabsread.h
+++ b/gdb/stabsread.h
@@ -172,7 +172,8 @@ extern void finish_global_stabs (struct objfile *objfile);
    they are only used by some stabs readers.  */
 
 extern legacy_psymtab *dbx_end_psymtab
-  (struct objfile *objfile, legacy_psymtab *pst,
+  (struct objfile *objfile, psymtab_storage *partial_symtabs,
+   legacy_psymtab *pst,
    const char **include_list, int num_includes,
    int capping_symbol_offset, CORE_ADDR capping_text,
    legacy_psymtab **dependency_list, int number_dependencies,
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index 207152ece4b..a336c3fadd0 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -202,6 +202,7 @@ eb_complaint (int arg1)
 static void xcoff_initial_scan (struct objfile *, symfile_add_flags);
 
 static void scan_xcoff_symtab (minimal_symbol_reader &,
+			       psymtab_storage *partial_symtabs,
 			       struct objfile *);
 
 static const char *xcoff_next_symbol_text (struct objfile *);
@@ -1985,7 +1986,8 @@ xcoff_start_psymtab (struct objfile *objfile,
    are the information for includes and dependencies.  */
 
 static legacy_psymtab *
-xcoff_end_psymtab (struct objfile *objfile, legacy_psymtab *pst,
+xcoff_end_psymtab (struct objfile *objfile, psymtab_storage *partial_symtabs,
+		   legacy_psymtab *pst,
 		   const char **include_list, int num_includes,
 		   int capping_symbol_number,
 		   legacy_psymtab **dependency_list,
@@ -2007,7 +2009,7 @@ xcoff_end_psymtab (struct objfile *objfile, legacy_psymtab *pst,
   if (number_dependencies)
     {
       pst->dependencies
-	= objfile->partial_symtabs->allocate_dependencies (number_dependencies);
+	= partial_symtabs->allocate_dependencies (number_dependencies);
       memcpy (pst->dependencies, dependency_list,
 	      number_dependencies * sizeof (legacy_psymtab *));
     }
@@ -2026,7 +2028,7 @@ xcoff_end_psymtab (struct objfile *objfile, legacy_psymtab *pst,
       /* We could save slight bits of space by only making one of these,
 	 shared by the entire set of include files.  FIXME-someday.  */
       subpst->dependencies =
-	objfile->partial_symtabs->allocate_dependencies (1);
+	partial_symtabs->allocate_dependencies (1);
       subpst->dependencies[0] = pst;
       subpst->number_of_dependencies = 1;
 
@@ -2042,7 +2044,7 @@ xcoff_end_psymtab (struct objfile *objfile, legacy_psymtab *pst,
       /* Empty psymtabs happen as a result of header files which don't have
 	 any symbols in them.  There can be a lot of them.  */
 
-      objfile->partial_symtabs->discard_psymtab (pst);
+      partial_symtabs->discard_psymtab (pst);
 
       /* Indicate that psymtab was thrown away.  */
       pst = NULL;
@@ -2111,6 +2113,7 @@ function_outside_compilation_unit_complaint (const char *arg1)
 
 static void
 scan_xcoff_symtab (minimal_symbol_reader &reader,
+		   psymtab_storage *partial_symtabs,
 		   struct objfile *objfile)
 {
   CORE_ADDR toc_offset = 0;	/* toc offset value in data section.  */
@@ -2232,7 +2235,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 			       each program csect, because their text
 			       sections need not be adjacent.  */
 			    xcoff_end_psymtab
-			      (objfile, pst, psymtab_include_list,
+			      (objfile, partial_symtabs, pst, psymtab_include_list,
 			       includes_used, symnum_before, dependency_list,
 			       dependencies_used, textlow_not_set);
 			    includes_used = 0;
@@ -2401,7 +2404,8 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 
 	    if (pst)
 	      {
-		xcoff_end_psymtab (objfile, pst, psymtab_include_list,
+		xcoff_end_psymtab (objfile, partial_symtabs,
+				   pst, psymtab_include_list,
 				   includes_used, symnum_before,
 				   dependency_list, dependencies_used,
 				   textlow_not_set);
@@ -2818,7 +2822,8 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 
   if (pst)
     {
-      xcoff_end_psymtab (objfile, pst, psymtab_include_list, includes_used,
+      xcoff_end_psymtab (objfile, partial_symtabs,
+			 pst, psymtab_include_list, includes_used,
 			 ssymnum, dependency_list,
 			 dependencies_used, textlow_not_set);
     }
@@ -2929,7 +2934,8 @@ 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.  */
 
-  scan_xcoff_symtab (reader, objfile);
+  psymtab_storage *partial_symtabs = objfile->partial_symtabs.get ();
+  scan_xcoff_symtab (reader, partial_symtabs, objfile);
 
   /* Install any minimal symbols that have been collected as the current
      minimal symbols for this objfile.  */
-- 
2.26.2


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 11/26] Do not pass objfile to psymtab_discarder
  2021-02-28 20:37 [PATCH 00/26] Allow multiple "partial" symtab readers per objfile Tom Tromey
                   ` (9 preceding siblings ...)
  2021-02-28 20:37 ` [PATCH 10/26] Change how some psymbol readers access the psymtab storage Tom Tromey
@ 2021-02-28 20:37 ` Tom Tromey
  2021-02-28 20:37 ` [PATCH 12/26] Set per_bfd->partial_symtabs earlier Tom Tromey
                   ` (15 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: Tom Tromey @ 2021-02-28 20:37 UTC (permalink / raw)
  To: gdb-patches

This changes the psymtab_discarder to not assume that partial symtabs
are attached to the objfile.  Instead, a psymtab_storage object is
passed directly to it.

gdb/ChangeLog
2021-02-28  Tom Tromey  <tom@tromey.com>

	* psympriv.h (psymtab_discarder): Take psymtab_storage parameter.
	(~psymtab_discarder, keep): Update.
	<m_objfile>: Remove.
	<m_partial_symtabs>: New member.
	* dwarf2/read.c (dwarf2_build_psymtabs): Update.
---
 gdb/ChangeLog     |  8 ++++++++
 gdb/dwarf2/read.c |  2 +-
 gdb/psympriv.h    | 17 ++++++++---------
 3 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index a24ead568ee..5c7a4435268 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -6372,7 +6372,7 @@ dwarf2_build_psymtabs (struct objfile *objfile)
       /* 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);
+      psymtab_discarder psymtabs (objfile->partial_symtabs.get ());
       dwarf2_build_psymtabs_hard (per_objfile);
       psymtabs.keep ();
 
diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index 73f00a50992..0f24c104aca 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -446,29 +446,28 @@ class psymtab_discarder
 {
  public:
 
-  psymtab_discarder (struct objfile *objfile)
-    : m_objfile (objfile),
-      m_psymtab (objfile->partial_symtabs->psymtabs)
+  psymtab_discarder (psymtab_storage *partial_symtabs)
+    : m_partial_symtabs (partial_symtabs),
+      m_psymtab (partial_symtabs->psymtabs)
   {
   }
 
   ~psymtab_discarder ()
   {
-    if (m_objfile != NULL)
-      m_objfile->partial_symtabs->discard_psymtabs_to (m_psymtab);
+    if (m_partial_symtabs != nullptr)
+      m_partial_symtabs->discard_psymtabs_to (m_psymtab);
   }
 
   /* Keep any partial symbol tables that were built.  */
   void keep ()
   {
-    m_objfile = NULL;
+    m_partial_symtabs = nullptr;
   }
 
  private:
 
-  /* The objfile.  If NULL this serves as a sentinel to indicate that
-     the psymtabs should be kept.  */
-  struct objfile *m_objfile;
+  /* The partial symbol storage object.  */
+  psymtab_storage *m_partial_symtabs;
   /* How far back to free.  */
   struct partial_symtab *m_psymtab;
 };
-- 
2.26.2


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 12/26] Set per_bfd->partial_symtabs earlier
  2021-02-28 20:37 [PATCH 00/26] Allow multiple "partial" symtab readers per objfile Tom Tromey
                   ` (10 preceding siblings ...)
  2021-02-28 20:37 ` [PATCH 11/26] Do not pass objfile to psymtab_discarder Tom Tromey
@ 2021-02-28 20:37 ` Tom Tromey
  2021-02-28 20:37 ` [PATCH 13/26] Change how DWARF indices use addrmap Tom Tromey
                   ` (14 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: Tom Tromey @ 2021-02-28 20:37 UTC (permalink / raw)
  To: gdb-patches

dwarf2_build_psymtabs sets per_bfd->partial_symtabs at its end, in
order to facilitate sharing.

However, in order to diassociate partial symtabs from the objfile, we
want to change the DWARF reader to reference partial symtabs via the
per_bfd.  So, we want to set this reference before reading psymtabs.
This is safe to do because the assignment is done unconditionally.

gdb/ChangeLog
2021-02-28  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (dwarf2_build_psymtabs): Set partial_symtabs
	earlier.
---
 gdb/ChangeLog     |  5 +++++
 gdb/dwarf2/read.c | 12 ++++++------
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 5c7a4435268..12f8cb9b114 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -6367,6 +6367,12 @@ dwarf2_build_psymtabs (struct objfile *objfile)
       return;
     }
 
+  /* 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;
+
   try
     {
       /* This isn't really ideal: all the data we allocate on the
@@ -6385,12 +6391,6 @@ dwarf2_build_psymtabs (struct objfile *objfile)
     {
       exception_print (gdb_stderr, except);
     }
-
-  /* Finish by setting 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;
 }
 
 /* Find the base address of the compilation unit for range lists and
-- 
2.26.2


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 13/26] Change how DWARF indices use addrmap
  2021-02-28 20:37 [PATCH 00/26] Allow multiple "partial" symtab readers per objfile Tom Tromey
                   ` (11 preceding siblings ...)
  2021-02-28 20:37 ` [PATCH 12/26] Set per_bfd->partial_symtabs earlier Tom Tromey
@ 2021-02-28 20:37 ` Tom Tromey
  2021-02-28 20:37 ` [PATCH 14/26] Move psymtab statistics printing to psymtab.c Tom Tromey
                   ` (13 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: Tom Tromey @ 2021-02-28 20:37 UTC (permalink / raw)
  To: gdb-patches

Currently the DWARF index readers reuse the objfile's partial symbol
table in order to store an addrmap.  We're going to be remove the
partial symbol object, so this patch changes the DWARF reader to store
this addrmap in the per_bfd object.  This object is chosen, rather
than the quick_symbol_functions subclass, because the addrmap can be
shared across objfiles.

gdb/ChangeLog
2021-02-28  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.h (struct dwarf2_per_bfd) <psymtabs_addrmap>: New
	member.
	* dwarf2/read.c (create_addrmap_from_index)
	(create_addrmap_from_aranges): Set per_bfd addrmap.
	(dwarf2_read_gdb_index): Don't set partial_symtabs.
	(dwarf2_base_index_functions::find_pc_sect_compunit_symtab): Use
	per_bfd addrmap.
	(dwarf2_read_debug_names): Don't set partial_symtabs.
	(dwarf2_initialize_objfile): Likewise.
---
 gdb/ChangeLog     | 12 ++++++++++++
 gdb/dwarf2/read.c | 43 +++++++++++++++++--------------------------
 gdb/dwarf2/read.h |  3 +++
 3 files changed, 32 insertions(+), 26 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 12f8cb9b114..773e38d0dc5 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -2942,13 +2942,14 @@ create_signatured_type_table_from_debug_names
 }
 
 /* Read the address map data from the mapped index, and use it to
-   populate the objfile's psymtabs_addrmap.  */
+   populate the psymtabs_addrmap.  */
 
 static void
 create_addrmap_from_index (dwarf2_per_objfile *per_objfile,
 			   struct mapped_index *index)
 {
   struct objfile *objfile = per_objfile->objfile;
+  dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
   struct gdbarch *gdbarch = objfile->arch ();
   const gdb_byte *iter, *end;
   struct addrmap *mutable_map;
@@ -2980,7 +2981,7 @@ create_addrmap_from_index (dwarf2_per_objfile *per_objfile,
 	  continue;
 	}
 
-      if (cu_index >= per_objfile->per_bfd->all_comp_units.size ())
+      if (cu_index >= per_bfd->all_comp_units.size ())
 	{
 	  complaint (_(".gdb_index address table has invalid CU number %u"),
 		     (unsigned) cu_index);
@@ -2990,15 +2991,15 @@ create_addrmap_from_index (dwarf2_per_objfile *per_objfile,
       lo = gdbarch_adjust_dwarf2_addr (gdbarch, lo + baseaddr) - baseaddr;
       hi = gdbarch_adjust_dwarf2_addr (gdbarch, hi + baseaddr) - baseaddr;
       addrmap_set_empty (mutable_map, lo, hi - 1,
-			 per_objfile->per_bfd->get_cu (cu_index));
+			 per_bfd->get_cu (cu_index));
     }
 
-  objfile->partial_symtabs->psymtabs_addrmap
-    = addrmap_create_fixed (mutable_map, objfile->partial_symtabs->obstack ());
+  per_bfd->index_addrmap = addrmap_create_fixed (mutable_map,
+						 &per_bfd->obstack);
 }
 
 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
-   populate the objfile's psymtabs_addrmap.  */
+   populate the psymtabs_addrmap.  */
 
 static void
 create_addrmap_from_aranges (dwarf2_per_objfile *per_objfile,
@@ -3008,6 +3009,7 @@ create_addrmap_from_aranges (dwarf2_per_objfile *per_objfile,
   bfd *abfd = objfile->obfd;
   struct gdbarch *gdbarch = objfile->arch ();
   const CORE_ADDR baseaddr = objfile->text_section_offset ();
+  dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
 
   auto_obstack temp_obstack;
   addrmap *mutable_map = addrmap_create_mutable (&temp_obstack);
@@ -3144,7 +3146,7 @@ create_addrmap_from_aranges (dwarf2_per_objfile *per_objfile,
 	  addr += address_size;
 	  if (start == 0 && length == 0)
 	    break;
-	  if (start == 0 && !per_objfile->per_bfd->has_section_at_zero)
+	  if (start == 0 && !per_bfd->has_section_at_zero)
 	    {
 	      /* Symbol was eliminated due to a COMDAT group.  */
 	      continue;
@@ -3158,8 +3160,8 @@ create_addrmap_from_aranges (dwarf2_per_objfile *per_objfile,
 	}
     }
 
-  objfile->partial_symtabs->psymtabs_addrmap
-    = addrmap_create_fixed (mutable_map, objfile->partial_symtabs->obstack ());
+  per_bfd->index_addrmap = addrmap_create_fixed (mutable_map,
+						 &per_bfd->obstack);
 }
 
 /* Find a slot in the mapped index INDEX for the object named NAME.
@@ -3426,11 +3428,6 @@ dwarf2_read_gdb_index
   per_bfd->quick_file_names_table =
     create_quick_file_names_table (per_bfd->all_comp_units.size ());
 
-  /* Save partial symtabs in the per_bfd object, for the benefit of subsequent
-     objfiles using the same BFD.  */
-  gdb_assert (per_bfd->partial_symtabs == nullptr);
-  per_bfd->partial_symtabs = objfile->partial_symtabs;
-
   return 1;
 }
 
@@ -5168,16 +5165,17 @@ dwarf2_base_index_functions::find_pc_sect_compunit_symtab
   struct dwarf2_per_cu_data *data;
   struct compunit_symtab *result;
 
-  if (!objfile->partial_symtabs->psymtabs_addrmap)
+  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
+  if (per_objfile->per_bfd->index_addrmap == nullptr)
     return NULL;
 
   CORE_ADDR baseaddr = objfile->text_section_offset ();
-  data = (struct dwarf2_per_cu_data *) addrmap_find
-    (objfile->partial_symtabs->psymtabs_addrmap, pc - baseaddr);
+  data = ((struct dwarf2_per_cu_data *)
+	  addrmap_find (per_objfile->per_bfd->index_addrmap,
+			pc - baseaddr));
   if (!data)
     return NULL;
 
-  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
   if (warn_if_readin && per_objfile->symtab_set_p (data))
     warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
 	     paddress (objfile->arch (), pc));
@@ -5588,11 +5586,6 @@ dwarf2_read_debug_names (dwarf2_per_objfile *per_objfile)
   per_bfd->quick_file_names_table =
     create_quick_file_names_table (per_objfile->per_bfd->all_comp_units.size ());
 
-  /* Save partial symtabs in the per_bfd object, for the benefit of subsequent
-     objfiles using the same BFD.  */
-  gdb_assert (per_bfd->partial_symtabs == nullptr);
-  per_bfd->partial_symtabs = objfile->partial_symtabs;
-
   return true;
 }
 
@@ -6294,7 +6287,6 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind)
   if (per_bfd->debug_names_table != nullptr)
     {
       *index_kind = dw_index_kind::DEBUG_NAMES;
-      per_objfile->objfile->partial_symtabs = per_bfd->partial_symtabs;
       per_objfile->resize_symtabs ();
       return true;
     }
@@ -6304,7 +6296,6 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind)
   if (per_bfd->index_table != nullptr)
     {
       *index_kind = dw_index_kind::GDB_INDEX;
-      per_objfile->objfile->partial_symtabs = per_bfd->partial_symtabs;
       per_objfile->resize_symtabs ();
       return true;
     }
@@ -14732,7 +14723,7 @@ dwarf2_ranges_process (unsigned offset, struct dwarf2_cu *cu, dwarf_tag tag,
 
 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
    Return 1 if the attributes are present and valid, otherwise, return 0.
-   If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'.  */
+   If RANGES_PST is not NULL we should set up the `psymtabs_addrmap'.  */
 
 static int
 dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index fbcd8ad0380..aba1d83e468 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -257,6 +257,9 @@ struct dwarf2_per_bfd
      partial symbols have been read the first time.  */
   std::shared_ptr<psymtab_storage> partial_symtabs;
 
+  /* The address map that is used by the DWARF index code.  */
+  struct addrmap *index_addrmap = nullptr;
+
 private:
 
   /* The total number of per_cu and signatured_type objects that have
-- 
2.26.2


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 14/26] Move psymtab statistics printing to psymtab.c
  2021-02-28 20:37 [PATCH 00/26] Allow multiple "partial" symtab readers per objfile Tom Tromey
                   ` (12 preceding siblings ...)
  2021-02-28 20:37 ` [PATCH 13/26] Change how DWARF indices use addrmap Tom Tromey
@ 2021-02-28 20:37 ` Tom Tromey
  2021-02-28 20:37 ` [PATCH 15/26] Change how DWARF index writer finds address map Tom Tromey
                   ` (12 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: Tom Tromey @ 2021-02-28 20:37 UTC (permalink / raw)
  To: gdb-patches

This moves all the psymtab statistics printing code form symmisc.c to
psymtab.c.  This changes the formatting of the output a little, but
considering that it is a maint command (and, I assume, a rarely used
one), this seems fine to me.

This change helps further dissociate the psymtab from the objfile.  In
the end there will be no direct connect -- only via the
quick_symbol_functions interface.

gdb/ChangeLog
2021-02-28  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (dwarf2_base_index_functions::print_stats): Add
	print_bcache parameter.
	* symfile-debug.c (objfile::print_stats): Add print_bcache
	parameter.
	* quick-symbol.h (struct quick_symbol_functions)
	<print_stats>: Add print_bcache parameter.
	* symmisc.c (print_symbol_bcache_statistics, count_psyms): Move
	code to psymtab.c.
	(print_objfile_statistics): Move psymtab code to psymtab.c.
	* psymtab.c (count_psyms): Move from symmisc.c.
	(psymbol_functions::print_stats): Print partial symbol and bcache
	statistics.  Add print_bcache parameter.
	* objfiles.h (print_symbol_bcache_statistics): Don't declare.
	(struct objfile) <print_stats>: Add print_bcache parameter.
	* maint.c (maintenance_print_statistics): Update.

gdb/testsuite/ChangeLog
2021-02-28  Tom Tromey  <tom@tromey.com>

	* gdb.base/maint.exp: Update "maint print statistics" output.
---
 gdb/ChangeLog                    | 18 ++++++++++++
 gdb/dwarf2/read.c                |  8 ++++--
 gdb/maint.c                      |  1 -
 gdb/objfiles.h                   |  3 +-
 gdb/psympriv.h                   |  2 +-
 gdb/psymtab.c                    | 43 ++++++++++++++++++++++++----
 gdb/quick-symbol.h               |  6 ++--
 gdb/symfile-debug.c              |  8 +++---
 gdb/symmisc.c                    | 49 ++++++--------------------------
 gdb/testsuite/ChangeLog          |  4 +++
 gdb/testsuite/gdb.base/maint.exp |  2 +-
 11 files changed, 84 insertions(+), 60 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 773e38d0dc5..4008e7dff2f 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -2456,7 +2456,7 @@ struct dwarf2_base_index_functions : public quick_symbol_functions
     return language_unknown;
   }
 
-  void print_stats (struct objfile *objfile) override;
+  void print_stats (struct objfile *objfile, bool print_bcache) override;
 
   void expand_all_symtabs (struct objfile *objfile) override;
 
@@ -3924,8 +3924,12 @@ dwarf2_gdb_index::lookup_symbol (struct objfile *objfile,
 }
 
 void
-dwarf2_base_index_functions::print_stats (struct objfile *objfile)
+dwarf2_base_index_functions::print_stats (struct objfile *objfile,
+					  bool print_bcache)
 {
+  if (print_bcache)
+    return;
+
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
   int total = (per_objfile->per_bfd->all_comp_units.size ()
 	       + per_objfile->per_bfd->all_type_units.size ());
diff --git a/gdb/maint.c b/gdb/maint.c
index bfdd1d5ca3e..5254cd6ed26 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -518,7 +518,6 @@ static void
 maintenance_print_statistics (const char *args, int from_tty)
 {
   print_objfile_statistics ();
-  print_symbol_bcache_statistics ();
 }
 
 static void
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index cd136eef788..ff60e18bca4 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -211,7 +211,6 @@ struct objstats
 #define OBJSTAT(objfile, expr) (objfile -> stats.expr)
 #define OBJSTATS struct objstats stats
 extern void print_objfile_statistics (void);
-extern void print_symbol_bcache_statistics (void);
 
 /* Number of entries in the minimal symbol hash table.  */
 #define MINIMAL_SYMBOL_HASH_SIZE 2039
@@ -568,7 +567,7 @@ struct objfile
 					 domain_enum domain);
 
   /* See quick_symbol_functions.  */
-  void print_stats ();
+  void print_stats (bool print_bcache);
 
   /* See quick_symbol_functions.  */
   void dump ();
diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index 0f24c104aca..943d6c13919 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -496,7 +496,7 @@ struct psymbol_functions : public quick_symbol_functions
 					       domain_enum domain,
 					       bool *symbol_found_p) override;
 
-  void print_stats (struct objfile *objfile) override;
+  void print_stats (struct objfile *objfile, bool print_bcache) override;
 
   void dump (struct objfile *objfile) override;
 
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 45a4db71c1f..867b71530eb 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -975,21 +975,52 @@ dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
   fprintf_filtered (outfile, "\n");
 }
 
+/* Count the number of partial symbols in OBJFILE.  */
+
+static int
+count_psyms (struct objfile *objfile)
+{
+  int count = 0;
+  for (partial_symtab *pst : objfile->psymtabs ())
+    {
+      count += pst->global_psymbols.size ();
+      count += pst->static_psymbols.size ();
+    }
+  return count;
+}
+
 /* Psymtab version of print_stats.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
 void
-psymbol_functions::print_stats (struct objfile *objfile)
+psymbol_functions::print_stats (struct objfile *objfile, bool print_bcache)
 {
   int i;
 
-  i = 0;
-  for (partial_symtab *ps : require_partial_symbols (objfile, true))
+  if (!print_bcache)
+    {
+      int n_psyms = count_psyms (objfile);
+      if (n_psyms > 0)
+	printf_filtered (_("  Number of \"partial\" symbols read: %d\n"),
+			 n_psyms);
+
+      i = 0;
+      for (partial_symtab *ps : require_partial_symbols (objfile, true))
+	{
+	  if (!ps->readin_p (objfile))
+	    i++;
+	}
+      printf_filtered (_("  Number of psym tables (not yet expanded): %d\n"),
+		       i);
+      printf_filtered (_("  Total memory used for psymbol cache: %d\n"),
+		       objfile->partial_symtabs->psymbol_cache.memory_used ());
+    }
+  else
     {
-      if (!ps->readin_p (objfile))
-	i++;
+      printf_filtered (_("Psymbol byte cache statistics:\n"));
+      objfile->partial_symtabs->psymbol_cache.print_statistics
+	("partial symbol cache");
     }
-  printf_filtered (_("  Number of psym tables (not yet expanded): %d\n"), i);
 }
 
 /* Psymtab version of dump.  See its definition in
diff --git a/gdb/quick-symbol.h b/gdb/quick-symbol.h
index 319ffe681c8..315a97a49e0 100644
--- a/gdb/quick-symbol.h
+++ b/gdb/quick-symbol.h
@@ -126,8 +126,10 @@ struct quick_symbol_functions
 
   /* Print statistics about any indices loaded for OBJFILE.  The
      statistics should be printed to gdb_stdout.  This is used for
-     "maint print statistics".  */
-  virtual void print_stats (struct objfile *objfile) = 0;
+     "maint print statistics".  Statistics are printed in two
+     sections.  PRINT_BCACHE is false when printing the first section
+     of general statistics, and true when printing bcache statistics.  */
+  virtual void print_stats (struct objfile *objfile, bool print_bcache) = 0;
 
   /* Dump any indices loaded for OBJFILE.  The dump should go to
      gdb_stdout.  This is used for "maint print objfiles".  */
diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index 55865ab03b0..406eac0b7d3 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -174,14 +174,14 @@ objfile::lookup_symbol (block_enum kind, const char *name, domain_enum domain)
 }
 
 void
-objfile::print_stats ()
+objfile::print_stats (bool print_bcache)
 {
   if (debug_symfile)
-    fprintf_filtered (gdb_stdlog, "qf->print_stats (%s)\n",
-		      objfile_debug_name (this));
+    fprintf_filtered (gdb_stdlog, "qf->print_stats (%s, %d)\n",
+		      objfile_debug_name (this), print_bcache);
 
   if (qf != nullptr)
-    qf->print_stats (this);
+    qf->print_stats (this, print_bcache);
 }
 
 void
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index 0aab30d08ab..9ea5cb55d0f 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -38,9 +38,6 @@
 #include "source.h"
 #include "readline/tilde.h"
 
-#include "psymtab.h"
-#include "psympriv.h"
-
 /* Prototypes for local functions */
 
 static int block_depth (const struct block *);
@@ -49,35 +46,6 @@ static void print_symbol (struct gdbarch *gdbarch, struct symbol *symbol,
 			  int depth, ui_file *outfile);
 \f
 
-void
-print_symbol_bcache_statistics (void)
-{
-  for (struct program_space *pspace : program_spaces)
-    for (objfile *objfile : pspace->objfiles ())
-      {
-	QUIT;
-	printf_filtered (_("Byte cache statistics for '%s':\n"),
-			 objfile_name (objfile));
-	objfile->partial_symtabs->psymbol_cache.print_statistics
-	  ("partial symbol cache");
-	objfile->per_bfd->string_cache.print_statistics ("string cache");
-      }
-}
-
-/* Count the number of partial symbols in OBJFILE.  */
-
-static int
-count_psyms (struct objfile *objfile)
-{
-  int count = 0;
-  for (partial_symtab *pst : objfile->psymtabs ())
-    {
-      count += pst->global_psymbols.size ();
-      count += pst->static_psymbols.size ();
-    }
-  return count;
-}
-
 void
 print_objfile_statistics (void)
 {
@@ -94,18 +62,13 @@ print_objfile_statistics (void)
 	if (objfile->per_bfd->n_minsyms > 0)
 	  printf_filtered (_("  Number of \"minimal\" symbols read: %d\n"),
 			   objfile->per_bfd->n_minsyms);
-
-	int n_psyms = count_psyms (objfile);
-	if (n_psyms > 0)
-	  printf_filtered (_("  Number of \"partial\" symbols read: %d\n"),
-			   n_psyms);
 	if (OBJSTAT (objfile, n_syms) > 0)
 	  printf_filtered (_("  Number of \"full\" symbols read: %d\n"),
 			   OBJSTAT (objfile, n_syms));
 	if (OBJSTAT (objfile, n_types) > 0)
 	  printf_filtered (_("  Number of \"types\" defined: %d\n"),
 			   OBJSTAT (objfile, n_types));
-	objfile->print_stats ();
+
 	i = linetables = 0;
 	for (compunit_symtab *cu : objfile->compunits ())
 	  {
@@ -124,6 +87,8 @@ print_objfile_statistics (void)
 	printf_filtered (_("  Number of symbol tables with blockvectors: %d\n"),
 			 blockvectors);
 
+	objfile->print_stats (false);
+
 	if (OBJSTAT (objfile, sz_strtab) > 0)
 	  printf_filtered (_("  Space used by string tables: %d\n"),
 			   OBJSTAT (objfile, sz_strtab));
@@ -133,11 +98,13 @@ print_objfile_statistics (void)
 	printf_filtered (_("  Total memory used for BFD obstack: %s\n"),
 			 pulongest (obstack_memory_used (&objfile->per_bfd
 							 ->storage_obstack)));
-	printf_filtered
-	  (_("  Total memory used for psymbol cache: %d\n"),
-	   objfile->partial_symtabs->psymbol_cache.memory_used ());
+
 	printf_filtered (_("  Total memory used for string cache: %d\n"),
 			 objfile->per_bfd->string_cache.memory_used ());
+	printf_filtered (_("Byte cache statistics for '%s':\n"),
+			 objfile_name (objfile));
+	objfile->per_bfd->string_cache.print_statistics ("string cache");
+	objfile->print_stats (true);
       }
 }
 
diff --git a/gdb/testsuite/gdb.base/maint.exp b/gdb/testsuite/gdb.base/maint.exp
index b418c023d73..e72392220cc 100644
--- a/gdb/testsuite/gdb.base/maint.exp
+++ b/gdb/testsuite/gdb.base/maint.exp
@@ -193,7 +193,7 @@ if [istarget "*-*-cygwin*"] {
 
 send_gdb "maint print statistics\n"
 gdb_expect  {
-    -re "Statistics for\[^\n\r\]*maint\[^\n\r\]*:\r\n  Number of \"minimal\" symbols read: $decimal\r\n(  Number of \"partial\" symbols read: $decimal\r\n)?  Number of \"full\" symbols read: $decimal\r\n  Number of \"types\" defined: $decimal\r\n(  Number of psym tables \\(not yet expanded\\): $decimal\r\n)?(  Number of read CUs: $decimal\r\n  Number of unread CUs: $decimal\r\n)?  Number of symbol tables: $decimal\r\n  Number of symbol tables with line tables: $decimal\r\n  Number of symbol tables with blockvectors: $decimal\r\n  Total memory used for objfile obstack: $decimal\r\n  Total memory used for BFD obstack: $decimal\r\n  Total memory used for psymbol cache: $decimal\r\n  Total memory used for string cache: $decimal\r\n" {
+    -re "Statistics for\[^\n\r\]*maint\[^\n\r\]*:\r\n  Number of \"minimal\" symbols read: $decimal\r\n  Number of \"full\" symbols read: $decimal\r\n  Number of \"types\" defined: $decimal\r\n(  Number of read CUs: $decimal\r\n  Number of unread CUs: $decimal\r\n)?  Number of symbol tables: $decimal\r\n  Number of symbol tables with line tables: $decimal\r\n  Number of symbol tables with blockvectors: $decimal\r\n(  Number of \"partial\" symbols read: $decimal\r\n)?(  Number of psym tables \\(not yet expanded\\): $decimal\r\n)?  Total memory used for psymbol cache: $decimal\r\n  Total memory used for objfile obstack: $decimal\r\n  Total memory used for BFD obstack: $decimal\r\n  Total memory used for string cache: $decimal\r\n" {
 	gdb_expect {
 	    -re "$gdb_prompt $" {
 		pass "maint print statistics"
-- 
2.26.2


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 15/26] Change how DWARF index writer finds address map
  2021-02-28 20:37 [PATCH 00/26] Allow multiple "partial" symtab readers per objfile Tom Tromey
                   ` (13 preceding siblings ...)
  2021-02-28 20:37 ` [PATCH 14/26] Move psymtab statistics printing to psymtab.c Tom Tromey
@ 2021-02-28 20:37 ` Tom Tromey
  2021-02-28 20:37 ` [PATCH 16/26] Reference psymtabs via per_bfd in DWARF reader Tom Tromey
                   ` (11 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: Tom Tromey @ 2021-02-28 20:37 UTC (permalink / raw)
  To: gdb-patches

This changes the DWARF index writer to find the psymtab address map in
the per_bfd object, rather than go via the objfile.

gdb/ChangeLog
2021-02-28  Tom Tromey  <tom@tromey.com>

	* dwarf2/index-write.c (struct addrmap_index_data) <objfile>:
	Remove.
	(add_address_entry): Remove objfile parameter.
	(add_address_entry_worker): Update.
	(write_address_map): Replace objfile parameter with per_bfd.
	(write_gdbindex, write_psymtabs_to_index): Update.
---
 gdb/ChangeLog            |  9 +++++++++
 gdb/dwarf2/index-write.c | 21 ++++++++++-----------
 2 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c
index a7b9ae66cae..f42a25331f8 100644
--- a/gdb/dwarf2/index-write.c
+++ b/gdb/dwarf2/index-write.c
@@ -413,7 +413,6 @@ struct addrmap_index_data
     : addr_vec (addr_vec_), cu_index_htab (cu_index_htab_)
   {}
 
-  struct objfile *objfile;
   data_buf &addr_vec;
   psym_index_map &cu_index_htab;
 
@@ -430,7 +429,7 @@ struct addrmap_index_data
 /* Write an address entry to ADDR_VEC.  */
 
 static void
-add_address_entry (struct objfile *objfile, data_buf &addr_vec,
+add_address_entry (data_buf &addr_vec,
 		   CORE_ADDR start, CORE_ADDR end, unsigned int cu_index)
 {
   addr_vec.append_uint (8, BFD_ENDIAN_LITTLE, start);
@@ -447,7 +446,7 @@ add_address_entry_worker (void *datap, CORE_ADDR start_addr, void *obj)
   partial_symtab *pst = (partial_symtab *) obj;
 
   if (data->previous_valid)
-    add_address_entry (data->objfile, data->addr_vec,
+    add_address_entry (data->addr_vec,
 		       data->previous_cu_start, start_addr,
 		       data->previous_cu_index);
 
@@ -465,12 +464,12 @@ add_address_entry_worker (void *datap, CORE_ADDR start_addr, void *obj)
   return 0;
 }
 
-/* Write OBJFILE's address map to ADDR_VEC.
+/* Write PER_BFD's address map to ADDR_VEC.
    CU_INDEX_HTAB is used to map addrmap entries to their CU indices
    in the index file.  */
 
 static void
-write_address_map (struct objfile *objfile, data_buf &addr_vec,
+write_address_map (dwarf2_per_bfd *per_bfd, data_buf &addr_vec,
 		   psym_index_map &cu_index_htab)
 {
   struct addrmap_index_data addrmap_index_data (addr_vec, cu_index_htab);
@@ -479,10 +478,9 @@ write_address_map (struct objfile *objfile, data_buf &addr_vec,
      the addrmap iterator only provides the start of a region; we have to
      wait until the next invocation to get the start of the next region.  */
 
-  addrmap_index_data.objfile = objfile;
   addrmap_index_data.previous_valid = 0;
 
-  addrmap_foreach (objfile->partial_symtabs->psymtabs_addrmap,
+  addrmap_foreach (per_bfd->partial_symtabs->psymtabs_addrmap,
 		   add_address_entry_worker, &addrmap_index_data);
 
   /* It's highly unlikely the last entry (end address = 0xff...ff)
@@ -491,7 +489,7 @@ write_address_map (struct objfile *objfile, data_buf &addr_vec,
      doesn't work here.  To cope we pass 0xff...ff, this is a rare situation
      anyway.  */
   if (addrmap_index_data.previous_valid)
-    add_address_entry (objfile, addr_vec,
+    add_address_entry (addr_vec,
 		       addrmap_index_data.previous_cu_start, (CORE_ADDR) -1,
 		       addrmap_index_data.previous_cu_index);
 }
@@ -1463,7 +1461,7 @@ write_gdbindex (dwarf2_per_objfile *per_objfile, FILE *out_file,
 
   /* Dump the address map.  */
   data_buf addr_vec;
-  write_address_map (objfile, addr_vec, cu_index_htab);
+  write_address_map (per_objfile->per_bfd, addr_vec, cu_index_htab);
 
   /* Write out the .debug_type entries, if any.  */
   data_buf types_cu_list;
@@ -1686,6 +1684,7 @@ write_psymtabs_to_index (dwarf2_per_objfile *per_objfile, const char *dir,
 			 const char *basename, const char *dwz_basename,
 			 dw_index_kind index_kind)
 {
+  dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
   struct objfile *objfile = per_objfile->objfile;
 
   if (per_objfile->per_bfd->using_index)
@@ -1694,8 +1693,8 @@ write_psymtabs_to_index (dwarf2_per_objfile *per_objfile, const char *dir,
   if (per_objfile->per_bfd->types.size () > 1)
     error (_("Cannot make an index when the file has multiple .debug_types sections"));
 
-  if (!objfile->partial_symtabs->psymtabs
-      || !objfile->partial_symtabs->psymtabs_addrmap)
+  if (!per_bfd->partial_symtabs->psymtabs
+      || !per_bfd->partial_symtabs->psymtabs_addrmap)
     return;
 
   struct stat st;
-- 
2.26.2


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 16/26] Reference psymtabs via per_bfd in DWARF reader
  2021-02-28 20:37 [PATCH 00/26] Allow multiple "partial" symtab readers per objfile Tom Tromey
                   ` (14 preceding siblings ...)
  2021-02-28 20:37 ` [PATCH 15/26] Change how DWARF index writer finds address map Tom Tromey
@ 2021-02-28 20:37 ` Tom Tromey
  2021-02-28 20:37 ` [PATCH 17/26] Attach partial symtab storage to psymbol_functions Tom Tromey
                   ` (10 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: Tom Tromey @ 2021-02-28 20:37 UTC (permalink / raw)
  To: gdb-patches

This changes the DWARF reader to reference the psymtabs via the
per_bfd object, rather than via the objfile.  This helps isolate the
partial symtabs from the objfile.

gdb/ChangeLog
2021-02-28  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (dwarf2_create_include_psymtab): Add per_bfd
	parameter.
	(process_psymtab_comp_unit_reader)
	(build_type_psymtab_dependencies, dwarf2_build_psymtabs_hard)
	(add_partial_subprogram, dwarf2_ranges_read, dwarf_decode_lines):
	Reference psymtabs via per_bfd.
---
 gdb/ChangeLog     |  9 +++++++++
 gdb/dwarf2/read.c | 40 +++++++++++++++++++++++-----------------
 2 files changed, 32 insertions(+), 17 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 4008e7dff2f..9aaf484a31e 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -6514,7 +6514,8 @@ struct dwarf2_include_psymtab : public partial_symtab
    partial symtab as being an include of PST.  */
 
 static void
-dwarf2_create_include_psymtab (const char *name, dwarf2_psymtab *pst,
+dwarf2_create_include_psymtab (dwarf2_per_bfd *per_bfd,
+			       const char *name, dwarf2_psymtab *pst,
 			       struct objfile *objfile)
 {
   dwarf2_include_psymtab *subpst = new dwarf2_include_psymtab (name, objfile);
@@ -6522,7 +6523,7 @@ dwarf2_create_include_psymtab (const char *name, dwarf2_psymtab *pst,
   if (!IS_ABSOLUTE_PATH (subpst->filename))
     subpst->dirname = pst->dirname;
 
-  subpst->dependencies = objfile->partial_symtabs->allocate_dependencies (1);
+  subpst->dependencies = per_bfd->partial_symtabs->allocate_dependencies (1);
   subpst->dependencies[0] = pst;
   subpst->number_of_dependencies = 1;
 }
@@ -7792,6 +7793,7 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
 {
   struct dwarf2_cu *cu = reader->cu;
   dwarf2_per_objfile *per_objfile = cu->per_objfile;
+  dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
   struct objfile *objfile = per_objfile->objfile;
   struct gdbarch *gdbarch = objfile->arch ();
   struct dwarf2_per_cu_data *per_cu = cu->per_cu;
@@ -7842,7 +7844,7 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
 	   - baseaddr - 1);
       /* Store the contiguous range if it is not empty; it can be
 	 empty for CUs with no code.  */
-      addrmap_set_empty (objfile->partial_symtabs->psymtabs_addrmap,
+      addrmap_set_empty (per_bfd->partial_symtabs->psymtabs_addrmap,
 			 low, high, pst);
     }
 
@@ -7893,7 +7895,7 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
 	 post-pass.  */
       pst->number_of_dependencies = len;
       pst->dependencies
-	= objfile->partial_symtabs->allocate_dependencies (len);
+	= per_bfd->partial_symtabs->allocate_dependencies (len);
       for (i = 0; i < len; ++i)
 	{
 	  pst->dependencies[i]
@@ -8149,7 +8151,7 @@ static int
 build_type_psymtab_dependencies (void **slot, void *info)
 {
   dwarf2_per_objfile *per_objfile = (dwarf2_per_objfile *) info;
-  struct objfile *objfile = per_objfile->objfile;
+  dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
   struct type_unit_group *tu_group = (struct type_unit_group *) *slot;
   struct dwarf2_per_cu_data *per_cu = &tu_group->per_cu;
   dwarf2_psymtab *pst = per_cu->v.psymtab;
@@ -8160,7 +8162,7 @@ build_type_psymtab_dependencies (void **slot, void *info)
   gdb_assert (per_cu->type_unit_group_p ());
 
   pst->number_of_dependencies = len;
-  pst->dependencies = objfile->partial_symtabs->allocate_dependencies (len);
+  pst->dependencies = per_bfd->partial_symtabs->allocate_dependencies (len);
   for (i = 0; i < len; ++i)
     {
       struct signatured_type *iter = tu_group->tus->at (i);
@@ -8284,6 +8286,7 @@ static void
 dwarf2_build_psymtabs_hard (dwarf2_per_objfile *per_objfile)
 {
   struct objfile *objfile = per_objfile->objfile;
+  dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
 
   dwarf_read_debug_printf ("Building psymtabs of objfile %s ...",
 			   objfile_name (objfile));
@@ -8292,7 +8295,7 @@ dwarf2_build_psymtabs_hard (dwarf2_per_objfile *per_objfile)
     = make_scoped_restore (&per_objfile->per_bfd->reading_partial_symbols,
 			   true);
 
-  per_objfile->per_bfd->info.read (objfile);
+  per_bfd->info.read (objfile);
 
   /* Any cached compilation units will be linked by the per-objfile
      read_in_chain.  Make sure to free them when we're done.  */
@@ -8307,10 +8310,10 @@ dwarf2_build_psymtabs_hard (dwarf2_per_objfile *per_objfile)
   auto_obstack temp_obstack;
 
   scoped_restore save_psymtabs_addrmap
-    = make_scoped_restore (&objfile->partial_symtabs->psymtabs_addrmap,
+    = make_scoped_restore (&per_bfd->partial_symtabs->psymtabs_addrmap,
 			   addrmap_create_mutable (&temp_obstack));
 
-  for (dwarf2_per_cu_data *per_cu : per_objfile->per_bfd->all_comp_units)
+  for (dwarf2_per_cu_data *per_cu : per_bfd->all_comp_units)
     {
       if (per_cu->v.psymtab != NULL)
 	/* In case a forward DW_TAG_imported_unit has read the CU already.  */
@@ -8323,9 +8326,9 @@ dwarf2_build_psymtabs_hard (dwarf2_per_objfile *per_objfile)
   process_skeletonless_type_units (per_objfile);
 
   /* Now that all TUs have been processed we can fill in the dependencies.  */
-  if (per_objfile->per_bfd->type_unit_groups != NULL)
+  if (per_bfd->type_unit_groups != NULL)
     {
-      htab_traverse_noresize (per_objfile->per_bfd->type_unit_groups.get (),
+      htab_traverse_noresize (per_bfd->type_unit_groups.get (),
 			      build_type_psymtab_dependencies, per_objfile);
     }
 
@@ -8334,9 +8337,9 @@ dwarf2_build_psymtabs_hard (dwarf2_per_objfile *per_objfile)
 
   set_partial_user (per_objfile);
 
-  objfile->partial_symtabs->psymtabs_addrmap
-    = addrmap_create_fixed (objfile->partial_symtabs->psymtabs_addrmap,
-			    objfile->partial_symtabs->obstack ());
+  per_bfd->partial_symtabs->psymtabs_addrmap
+    = addrmap_create_fixed (per_bfd->partial_symtabs->psymtabs_addrmap,
+			    per_bfd->partial_symtabs->obstack ());
   /* At this point we want to keep the address map.  */
   save_psymtabs_addrmap.release ();
 
@@ -8951,6 +8954,7 @@ add_partial_subprogram (struct partial_die_info *pdi,
 	  if (set_addrmap)
 	    {
 	      struct objfile *objfile = cu->per_objfile->objfile;
+	      dwarf2_per_bfd *per_bfd = cu->per_objfile->per_bfd;
 	      struct gdbarch *gdbarch = objfile->arch ();
 	      CORE_ADDR baseaddr;
 	      CORE_ADDR this_highpc;
@@ -8965,7 +8969,7 @@ add_partial_subprogram (struct partial_die_info *pdi,
 		= (gdbarch_adjust_dwarf2_addr (gdbarch,
 					       pdi->highpc + baseaddr)
 		   - baseaddr);
-	      addrmap_set_empty (objfile->partial_symtabs->psymtabs_addrmap,
+	      addrmap_set_empty (per_bfd->partial_symtabs->psymtabs_addrmap,
 				 this_lowpc, this_highpc - 1,
 				 cu->per_cu->v.psymtab);
 	    }
@@ -14735,6 +14739,7 @@ dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
 		    dwarf2_psymtab *ranges_pst, dwarf_tag tag)
 {
   struct objfile *objfile = cu->per_objfile->objfile;
+  dwarf2_per_bfd *per_bfd = cu->per_objfile->per_bfd;
   struct gdbarch *gdbarch = objfile->arch ();
   const CORE_ADDR baseaddr = objfile->text_section_offset ();
   int low_set = 0;
@@ -14756,7 +14761,7 @@ dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
 	  highpc = (gdbarch_adjust_dwarf2_addr (gdbarch,
 						range_end + baseaddr)
 		    - baseaddr);
-	  addrmap_set_empty (objfile->partial_symtabs->psymtabs_addrmap,
+	  addrmap_set_empty (per_bfd->partial_symtabs->psymtabs_addrmap,
 			     lowpc, highpc - 1, ranges_pst);
 	}
 
@@ -22085,7 +22090,8 @@ dwarf_decode_lines (struct line_header *lh, const char *comp_dir,
 	      psymtab_include_file_name (lh, file_entry, pst,
 					 comp_dir, &name_holder);
 	    if (include_name != NULL)
-	      dwarf2_create_include_psymtab (include_name, pst, objfile);
+	      dwarf2_create_include_psymtab (cu->per_objfile->per_bfd,
+					     include_name, pst, objfile);
 	  }
     }
   else
-- 
2.26.2


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 17/26] Attach partial symtab storage to psymbol_functions
  2021-02-28 20:37 [PATCH 00/26] Allow multiple "partial" symtab readers per objfile Tom Tromey
                   ` (15 preceding siblings ...)
  2021-02-28 20:37 ` [PATCH 16/26] Reference psymtabs via per_bfd in DWARF reader Tom Tromey
@ 2021-02-28 20:37 ` Tom Tromey
  2021-02-28 20:37 ` [PATCH 18/26] Rearrange psymtab_storage construction Tom Tromey
                   ` (9 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: Tom Tromey @ 2021-02-28 20:37 UTC (permalink / raw)
  To: gdb-patches

Currently, the storage for partial symtabs is attached to the objfile.
Ultimately, though, this direct assocation will be removed, and the
storage will be owned by the psymbol_functions object.

This patch is a step toward this goal.  The storage is already managed
as a shared_ptr, to enable cross-objfile sharing, so this adds a
reference from the psymbol_functions, and changes some code in
psymtab.c to use this reference instead.

gdb/ChangeLog
2021-02-28  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (dwarf2_build_psymtabs): Call
	set_partial_symtabs.
	* symfile.c (syms_from_objfile_1, reread_symbols): Update.
	* psymtab.h (make_psymbol_functions): Add partial_symtabs
	parameter.
	* psymtab.c (find_pc_sect_psymtab): Add partial_symtabs
	parameter.
	(psymbol_functions::find_pc_sect_compunit_symtab)
	(psymbol_functions::print_stats, psymbol_functions::dump)
	(psymbol_functions::has_symbols): Update.
	(make_psymbol_functions, dump_psymtab_addrmap): Add
	partial_symtabs parameter.
	(maintenance_print_psymbols): Update.
	(psymbol_functions::expand_symtabs_matching): Update.
	* psympriv.h (struct psymbol_functions): Add constructor.
	<m_partial_symtabs>: New member.
	<set_partial_symtabs>: New method.
---
 gdb/ChangeLog     | 20 ++++++++++++++++++
 gdb/dwarf2/read.c |  6 ++++++
 gdb/psympriv.h    | 15 ++++++++++++++
 gdb/psymtab.c     | 52 ++++++++++++++++++++++++++++-------------------
 gdb/psymtab.h     |  3 ++-
 gdb/symfile.c     |  4 ++--
 6 files changed, 76 insertions(+), 24 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 9aaf484a31e..3a050b351a0 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -6358,6 +6358,12 @@ 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.get ());
+      gdb_assert (psf != nullptr);
+      psf->set_partial_symtabs (per_bfd->partial_symtabs);
       per_objfile->resize_symtabs ();
       return;
     }
diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index 943d6c13919..b1b8027ce3a 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -476,6 +476,11 @@ class psymtab_discarder
    partial symbols.  */
 struct psymbol_functions : public quick_symbol_functions
 {
+  explicit psymbol_functions (const std::shared_ptr<psymtab_storage> &storage)
+    : m_partial_symtabs (storage)
+  {
+  }
+
   bool has_symbols (struct objfile *objfile) override;
 
   struct symtab *find_last_source_symtab (struct objfile *objfile) override;
@@ -540,6 +545,13 @@ struct psymbol_functions : public quick_symbol_functions
     m_psymbol_map.clear ();
   }
 
+  /* Replace the partial symbol table storage in this object with
+     SYMS.  */
+  void set_partial_symtabs (const std::shared_ptr<psymtab_storage> &syms)
+  {
+    m_partial_symtabs = syms;
+  }
+
 private:
 
   void fill_psymbol_map (struct objfile *objfile,
@@ -547,6 +559,9 @@ struct psymbol_functions : public quick_symbol_functions
 			 std::set<CORE_ADDR> *seen_addrs,
 			 const std::vector<partial_symbol *> &symbols);
 
+  /* Storage for the partial symbols.  */
+  std::shared_ptr<psymtab_storage> m_partial_symtabs;
+
   /* Map symbol addresses to the partial symtab that defines the
      object at that address.  */
 
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 867b71530eb..1549ead04d0 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -275,7 +275,9 @@ find_pc_sect_psymtab_closer (struct objfile *objfile,
    psymtab that contains a symbol whose address is closest to PC.  */
 
 static struct partial_symtab *
-find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc,
+find_pc_sect_psymtab (struct objfile *objfile,
+		      psymtab_storage *partial_symtabs,
+		      CORE_ADDR pc,
 		      struct obj_section *section,
 		      struct bound_minimal_symbol msymbol)
 {
@@ -291,14 +293,14 @@ find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc,
      partial symtabs then we will end up returning a pointer to an object
      that is not a partial_symtab, which doesn't end well.  */
 
-  if (objfile->partial_symtabs->psymtabs != NULL
-      && objfile->partial_symtabs->psymtabs_addrmap != NULL)
+  if (partial_symtabs->psymtabs != NULL
+      && partial_symtabs->psymtabs_addrmap != NULL)
     {
       CORE_ADDR baseaddr = objfile->text_section_offset ();
 
       struct partial_symtab *pst
 	= ((struct partial_symtab *)
-	   addrmap_find (objfile->partial_symtabs->psymtabs_addrmap,
+	   addrmap_find (partial_symtabs->psymtabs_addrmap,
 			 pc - baseaddr));
       if (pst != NULL)
 	{
@@ -367,7 +369,9 @@ psymbol_functions::find_pc_sect_compunit_symtab
       struct obj_section *section,
       int warn_if_readin)
 {
-  struct partial_symtab *ps = find_pc_sect_psymtab (objfile, pc, section,
+  struct partial_symtab *ps = find_pc_sect_psymtab (objfile,
+						    m_partial_symtabs.get (),
+						    pc, section,
 						    msymbol);
   if (ps != NULL)
     {
@@ -1013,12 +1017,12 @@ psymbol_functions::print_stats (struct objfile *objfile, bool print_bcache)
       printf_filtered (_("  Number of psym tables (not yet expanded): %d\n"),
 		       i);
       printf_filtered (_("  Total memory used for psymbol cache: %d\n"),
-		       objfile->partial_symtabs->psymbol_cache.memory_used ());
+		       m_partial_symtabs->psymbol_cache.memory_used ());
     }
   else
     {
       printf_filtered (_("Psymbol byte cache statistics:\n"));
-      objfile->partial_symtabs->psymbol_cache.print_statistics
+      m_partial_symtabs->psymbol_cache.print_statistics
 	("partial symbol cache");
     }
 }
@@ -1031,10 +1035,10 @@ psymbol_functions::dump (struct objfile *objfile)
 {
   struct partial_symtab *psymtab;
 
-  if (objfile->partial_symtabs->psymtabs)
+  if (m_partial_symtabs->psymtabs)
     {
       printf_filtered ("Psymtabs:\n");
-      for (psymtab = objfile->partial_symtabs->psymtabs;
+      for (psymtab = m_partial_symtabs->psymtabs;
 	   psymtab != NULL;
 	   psymtab = psymtab->next)
 	{
@@ -1321,7 +1325,7 @@ psymbol_functions::expand_symtabs_matching
   for (partial_symtab *ps : require_partial_symbols (objfile, true))
     ps->searched_flag = PST_NOT_SEARCHED;
 
-  for (partial_symtab *ps : objfile->psymtabs ())
+  for (partial_symtab *ps : m_partial_symtabs->range ())
     {
       QUIT;
 
@@ -1373,7 +1377,7 @@ psymbol_functions::expand_symtabs_matching
 bool
 psymbol_functions::has_symbols (struct objfile *objfile)
 {
-  return objfile->partial_symtabs->psymtabs != NULL;
+  return m_partial_symtabs->psymtabs != NULL;
 }
 
 /* Helper function for psym_find_compunit_symtab_by_address that fills
@@ -1446,9 +1450,9 @@ psymbol_functions::find_compunit_symtab_by_address (struct objfile *objfile,
 }
 
 quick_symbol_functions_up
-make_psymbol_functions ()
+make_psymbol_functions (const std::shared_ptr<psymtab_storage> &storage)
 {
-  return quick_symbol_functions_up (new psymbol_functions);
+  return quick_symbol_functions_up (new psymbol_functions (storage));
 }
 
 \f
@@ -1724,14 +1728,16 @@ dump_psymtab_addrmap_1 (void *datap, CORE_ADDR start_addr, void *obj)
    of PSYMTAB.  If PSYMTAB is NULL print the entire addrmap.  */
 
 static void
-dump_psymtab_addrmap (struct objfile *objfile, struct partial_symtab *psymtab,
+dump_psymtab_addrmap (struct objfile *objfile,
+		      psymtab_storage *partial_symtabs,
+		      struct partial_symtab *psymtab,
 		      struct ui_file *outfile)
 {
   struct dump_psymtab_addrmap_data addrmap_dump_data;
 
   if ((psymtab == NULL
        || psymtab->psymtabs_addrmap_supported)
-      && objfile->partial_symtabs->psymtabs_addrmap != NULL)
+      && partial_symtabs->psymtabs_addrmap != NULL)
     {
       addrmap_dump_data.objfile = objfile;
       addrmap_dump_data.psymtab = psymtab;
@@ -1739,7 +1745,7 @@ dump_psymtab_addrmap (struct objfile *objfile, struct partial_symtab *psymtab,
       addrmap_dump_data.previous_matched = 0;
       fprintf_filtered (outfile, "%sddress map:\n",
 			psymtab == NULL ? "Entire a" : "  A");
-      addrmap_foreach (objfile->partial_symtabs->psymtabs_addrmap,
+      addrmap_foreach (partial_symtabs->psymtabs_addrmap,
 		       dump_psymtab_addrmap_1, &addrmap_dump_data);
     }
 }
@@ -1830,14 +1836,17 @@ maintenance_print_psymbols (const char *args, int from_tty)
       if (!print_for_objfile)
 	continue;
 
+      psymtab_storage *partial_symtabs = objfile->partial_symtabs.get ();
+
       if (address_arg != NULL)
 	{
 	  struct bound_minimal_symbol msymbol = { NULL, NULL };
 
 	  /* We don't assume each pc has a unique objfile (this is for
 	     debugging).  */
-	  struct partial_symtab *ps = find_pc_sect_psymtab (objfile, pc,
-							    section, msymbol);
+	  struct partial_symtab *ps
+	    = find_pc_sect_psymtab (objfile, partial_symtabs, pc,
+				    section, msymbol);
 	  if (ps != NULL)
 	    {
 	      if (!printed_objfile_header)
@@ -1847,7 +1856,7 @@ maintenance_print_psymbols (const char *args, int from_tty)
 		  printed_objfile_header = 1;
 		}
 	      dump_psymtab (objfile, ps, outfile);
-	      dump_psymtab_addrmap (objfile, ps, outfile);
+	      dump_psymtab_addrmap (objfile, partial_symtabs, ps, outfile);
 	      found = 1;
 	    }
 	}
@@ -1874,7 +1883,8 @@ maintenance_print_psymbols (const char *args, int from_tty)
 		      printed_objfile_header = 1;
 		    }
 		  dump_psymtab (objfile, ps, outfile);
-		  dump_psymtab_addrmap (objfile, ps, outfile);
+		  dump_psymtab_addrmap (objfile, partial_symtabs, ps,
+					outfile);
 		}
 	    }
 	}
@@ -1886,7 +1896,7 @@ maintenance_print_psymbols (const char *args, int from_tty)
 	  && objfile->partial_symtabs->psymtabs_addrmap != NULL)
 	{
 	  outfile->puts ("\n");
-	  dump_psymtab_addrmap (objfile, NULL, outfile);
+	  dump_psymtab_addrmap (objfile, partial_symtabs, NULL, outfile);
 	}
     }
 
diff --git a/gdb/psymtab.h b/gdb/psymtab.h
index 45eaf0b9013..18b47c55b3c 100644
--- a/gdb/psymtab.h
+++ b/gdb/psymtab.h
@@ -154,6 +154,7 @@ class psymtab_storage
 extern psymtab_storage::partial_symtab_range require_partial_symbols
     (struct objfile *objfile, bool verbose);
 
-extern quick_symbol_functions_up make_psymbol_functions ();
+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 d0b9da2138b..12746c43374 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -904,7 +904,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->qf = make_psymbol_functions ();
+  objfile->qf = make_psymbol_functions (objfile->partial_symtabs);
 
   if (objfile->sf == NULL)
     {
@@ -2555,7 +2555,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->qf = make_psymbol_functions ();
+	  objfile->qf = make_psymbol_functions (objfile->partial_symtabs);
 
 	  build_objfile_section_table (objfile);
 
-- 
2.26.2


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 18/26] Rearrange psymtab_storage construction
  2021-02-28 20:37 [PATCH 00/26] Allow multiple "partial" symtab readers per objfile Tom Tromey
                   ` (16 preceding siblings ...)
  2021-02-28 20:37 ` [PATCH 17/26] Attach partial symtab storage to psymbol_functions Tom Tromey
@ 2021-02-28 20:37 ` Tom Tromey
  2021-02-28 20:37 ` [PATCH 19/26] Remove sym_fns::sym_read_psymbols Tom Tromey
                   ` (8 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: Tom Tromey @ 2021-02-28 20:37 UTC (permalink / raw)
  To: gdb-patches

This changes objfile so that it doesn't construct a psymtab_storage
object until the psymtab functions are installed.  It also applies a
similar treatment to reread_symbols.

gdb/ChangeLog
2021-02-28  Tom Tromey  <tom@tromey.com>

	* symfile.c (syms_from_objfile_1): Call reset_psymtabs.
	(reread_symbols): Move reset_psymtabs call later.
	* objfiles.c (objfile::objfile): Don't initialize
	partial_symtabs.
---
 gdb/ChangeLog  | 7 +++++++
 gdb/objfiles.c | 1 -
 gdb/symfile.c  | 4 ++--
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index bfa5f0443e3..ca135dd63c3 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -323,7 +323,6 @@ build_objfile_section_table (struct objfile *objfile)
 objfile::objfile (bfd *abfd, const char *name, objfile_flags flags_)
   : flags (flags_),
     pspace (current_program_space),
-    partial_symtabs (new psymtab_storage ()),
     obfd (abfd)
 {
   const char *expanded_name;
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 12746c43374..01304523c0d 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -904,6 +904,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 = make_psymbol_functions (objfile->partial_symtabs);
 
   if (objfile->sf == NULL)
@@ -2522,8 +2523,6 @@ reread_symbols (void)
 	    error (_("Can't read symbols from %s: %s."), objfile_name (objfile),
 		   bfd_errmsg (bfd_get_error ()));
 
-	  objfile->reset_psymtabs ();
-
 	  /* NB: after this call to obstack_free, objfiles_changed
 	     will need to be called (see discussion below).  */
 	  obstack_free (&objfile->objfile_obstack, 0);
@@ -2555,6 +2554,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 = make_psymbol_functions (objfile->partial_symtabs);
 
 	  build_objfile_section_table (objfile);
-- 
2.26.2


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 19/26] Remove sym_fns::sym_read_psymbols
  2021-02-28 20:37 [PATCH 00/26] Allow multiple "partial" symtab readers per objfile Tom Tromey
                   ` (17 preceding siblings ...)
  2021-02-28 20:37 ` [PATCH 18/26] Rearrange psymtab_storage construction Tom Tromey
@ 2021-02-28 20:37 ` Tom Tromey
  2021-02-28 20:37 ` [PATCH 20/26] Introduce objfile::require_partial_symbols Tom Tromey
                   ` (7 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: Tom Tromey @ 2021-02-28 20:37 UTC (permalink / raw)
  To: gdb-patches

Partial symbols are read via the sym_fns::sym_read_psymbols function
pointer.  In order to separate the partial symbols from the objfile,
this must instead be done via a virtual method on
quick_symbol_functions.  This patch implements this change.

gdb/ChangeLog
2021-02-28  Tom Tromey  <tom@tromey.com>

	* xcoffread.c (xcoff_sym_fns): Update.
	* symfile.h (struct sym_fns) <sym_read_psymbols>: Remove.
	* symfile-debug.c (objfile::has_partial_symbols): Use
	can_lazily_read_symbols.
	(debug_sym_read_psymbols): Remove.
	(debug_sym_fns, install_symfile_debug_logging): Update.
	* quick-symbol.h (struct quick_symbol_functions)
	<can_lazily_read_symbols, read_partial_symbols>: New methods.
	* psymtab.c (require_partial_symbols): Use new 'qf' methods.
	* mipsread.c (ecoff_sym_fns): Update.
	* machoread.c (macho_sym_fns): Update.
	* elfread.c (struct lazy_dwarf_reader): New.
	(elf_symfile_read): Update.
	(read_psyms): Now a method of lazy_dwarf_reader.
	(elf_sym_fns): Update.
	(elf_sym_fns_lazy_psyms): Remove.
	* dbxread.c (aout_sym_fns): Update.
	* coffread.c (coff_sym_fns): Update.
---
 gdb/ChangeLog       | 21 +++++++++++++++++++
 gdb/coffread.c      |  1 -
 gdb/dbxread.c       |  1 -
 gdb/elfread.c       | 49 ++++++++++++++++++---------------------------
 gdb/machoread.c     |  1 -
 gdb/mipsread.c      |  1 -
 gdb/psymtab.c       |  5 ++---
 gdb/quick-symbol.h  | 14 +++++++++++++
 gdb/symfile-debug.c | 19 ++----------------
 gdb/symfile.h       |  7 -------
 gdb/xcoffread.c     |  1 -
 11 files changed, 59 insertions(+), 61 deletions(-)

diff --git a/gdb/coffread.c b/gdb/coffread.c
index 676deec8cbe..b527f934c95 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -2168,7 +2168,6 @@ static const struct sym_fns coff_sym_fns =
 				   for sym_read() */
   coff_symfile_read,		/* sym_read: read a symbol file into
 				   symtab */
-  NULL,				/* sym_read_psymbols */
   coff_symfile_finish,		/* sym_finish: finished with file,
 				   cleanup */
   default_symfile_offsets,	/* sym_offsets: xlate external to
diff --git a/gdb/dbxread.c b/gdb/dbxread.c
index 9a470bf8177..e0cc2597f73 100644
--- a/gdb/dbxread.c
+++ b/gdb/dbxread.c
@@ -3131,7 +3131,6 @@ static const struct sym_fns aout_sym_fns =
   dbx_new_init,			/* init anything gbl to entire symtab */
   dbx_symfile_init,		/* read initial info, setup for sym_read() */
   dbx_symfile_read,		/* read a symbol file into symtab */
-  NULL,				/* sym_read_psymbols */
   dbx_symfile_finish,		/* finished with file, cleanup */
   default_symfile_offsets, 	/* parse user's offsets to internal form */
   default_symfile_segments,	/* Get segment information from a file.  */
diff --git a/gdb/elfread.c b/gdb/elfread.c
index 4ca1f4d5284..157a0717828 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -53,7 +53,24 @@
 #include "debuginfod-support.h"
 #include "dwarf2/public.h"
 
-/* Forward declarations.  */
+/* A subclass of psymbol_functions that arranges to read the DWARF
+   partial symbols when needed.  */
+struct lazy_dwarf_reader : public psymbol_functions
+{
+  using psymbol_functions::psymbol_functions;
+
+  bool can_lazily_read_symbols () override
+  {
+    return true;
+  }
+
+  void read_partial_symbols (struct objfile *objfile) override
+  {
+    if (dwarf2_has_info (objfile, nullptr))
+      dwarf2_build_psymtabs (objfile);
+  }
+};
+
 extern const struct sym_fns elf_sym_fns_lazy_psyms;
 
 /* The struct elfinfo is available only during ELF symbol table and
@@ -1283,7 +1300,8 @@ elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
 	     partial symbols, because OBJF_PSYMTABS_READ has not been
 	     set, and so our lazy reader function will still be called
 	     when needed.  */
-	  objfile_set_sym_fns (objfile, &elf_sym_fns_lazy_psyms);
+	  objfile->qf.reset
+	    (new lazy_dwarf_reader (objfile->partial_symtabs));
 	}
     }
   /* If the file has its own symbol tables it has no separate debug
@@ -1353,15 +1371,6 @@ elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
     }
 }
 
-/* Callback to lazily read psymtabs.  */
-
-static void
-read_psyms (struct objfile *objfile)
-{
-  if (dwarf2_has_info (objfile, NULL))
-    dwarf2_build_psymtabs (objfile);
-}
-
 /* Initialize anything that needs initializing when a completely new symbol
    file is specified (not just adding some symbols from another file, e.g. a
    shared library).  */
@@ -1428,24 +1437,6 @@ static const struct sym_fns elf_sym_fns =
   elf_new_init,			/* init anything gbl to entire symtab */
   elf_symfile_init,		/* read initial info, setup for sym_read() */
   elf_symfile_read,		/* read a symbol file into symtab */
-  NULL,				/* sym_read_psymbols */
-  elf_symfile_finish,		/* finished with file, cleanup */
-  default_symfile_offsets,	/* Translate ext. to int. relocation */
-  elf_symfile_segments,		/* Get segment information from a file.  */
-  NULL,
-  default_symfile_relocate,	/* Relocate a debug section.  */
-  &elf_probe_fns,		/* sym_probe_fns */
-};
-
-/* The same as elf_sym_fns, but not registered and lazily reads
-   psymbols.  */
-
-const struct sym_fns elf_sym_fns_lazy_psyms =
-{
-  elf_new_init,			/* init anything gbl to entire symtab */
-  elf_symfile_init,		/* read initial info, setup for sym_read() */
-  elf_symfile_read,		/* read a symbol file into symtab */
-  read_psyms,			/* sym_read_psymbols */
   elf_symfile_finish,		/* finished with file, cleanup */
   default_symfile_offsets,	/* Translate ext. to int. relocation */
   elf_symfile_segments,		/* Get segment information from a file.  */
diff --git a/gdb/machoread.c b/gdb/machoread.c
index 44baaa26f65..17aa9ceee01 100644
--- a/gdb/machoread.c
+++ b/gdb/machoread.c
@@ -951,7 +951,6 @@ static const struct sym_fns macho_sym_fns = {
   macho_new_init,               /* init anything gbl to entire symtab */
   macho_symfile_init,           /* read initial info, setup for sym_read() */
   macho_symfile_read,           /* read a symbol file into symtab */
-  NULL,				/* sym_read_psymbols */
   macho_symfile_finish,         /* finished with file, cleanup */
   macho_symfile_offsets,        /* xlate external to internal form */
   default_symfile_segments,	/* Get segment information from a file.  */
diff --git a/gdb/mipsread.c b/gdb/mipsread.c
index 3f0697b9150..b51af3eeaa6 100644
--- a/gdb/mipsread.c
+++ b/gdb/mipsread.c
@@ -369,7 +369,6 @@ static const struct sym_fns ecoff_sym_fns =
   mipscoff_new_init,		/* init anything gbl to entire symtab */
   mipscoff_symfile_init,	/* read initial info, setup for sym_read() */
   mipscoff_symfile_read,	/* read a symbol file into symtab */
-  NULL,				/* sym_read_psymbols */
   mipscoff_symfile_finish,	/* finished with file, cleanup */
   default_symfile_offsets,	/* dummy FIXME til implem sym reloc */
   default_symfile_segments,	/* Get segment information from a file.  */
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 1549ead04d0..b5ddef90878 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -84,13 +84,12 @@ require_partial_symbols (struct objfile *objfile, bool verbose)
     {
       objfile->flags |= OBJF_PSYMTABS_READ;
 
-      if (objfile->sf != nullptr
-	  && objfile->sf->sym_read_psymbols)
+      if (objfile->qf->can_lazily_read_symbols ())
 	{
 	  if (verbose)
 	    printf_filtered (_("Reading symbols from %s...\n"),
 			     objfile_name (objfile));
-	  (*objfile->sf->sym_read_psymbols) (objfile);
+	  objfile->qf->read_partial_symbols (objfile);
 
 	  if (verbose && !objfile_has_symbols (objfile))
 	    printf_filtered (_("(No debugging symbols found in %s)\n"),
diff --git a/gdb/quick-symbol.h b/gdb/quick-symbol.h
index 315a97a49e0..dd2b896fd5f 100644
--- a/gdb/quick-symbol.h
+++ b/gdb/quick-symbol.h
@@ -237,6 +237,20 @@ struct quick_symbol_functions
   {
     /* Do nothing.  */
   }
+
+  /* Return true if this class can lazily read the symbols.  This may
+     only return true if there are in fact symbols to be read, because
+     this is used in the implementation of 'has_partial_symbols'.  */
+  virtual bool can_lazily_read_symbols ()
+  {
+    return false;
+  }
+
+  /* Read the partial symbols for OBJFILE.  This will only ever be
+     called if can_lazily_read_symbols returns true.  */
+  virtual void read_partial_symbols (struct objfile *objfile)
+  {
+  }
 };
 
 typedef std::unique_ptr<quick_symbol_functions> quick_symbol_functions_up;
diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index 406eac0b7d3..94559c7370c 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -81,8 +81,8 @@ objfile::has_partial_symbols ()
      this function the symbols may have been already read in but they also may
      not be present in this objfile.  */
   if ((flags & OBJF_PSYMTABS_READ) == 0
-      && sf != nullptr
-      && sf->sym_read_psymbols != NULL)
+      && qf != nullptr
+      && qf->can_lazily_read_symbols ())
     retval = true;
   else if (qf != nullptr)
     retval = qf->has_symbols (this);
@@ -420,18 +420,6 @@ debug_sym_read (struct objfile *objfile, symfile_add_flags symfile_flags)
   debug_data->real_sf->sym_read (objfile, symfile_flags);
 }
 
-static void
-debug_sym_read_psymbols (struct objfile *objfile)
-{
-  const struct debug_sym_fns_data *debug_data
-    = symfile_debug_objfile_data_key.get (objfile);
-
-  fprintf_filtered (gdb_stdlog, "sf->sym_read_psymbols (%s)\n",
-		    objfile_debug_name (objfile));
-
-  debug_data->real_sf->sym_read_psymbols (objfile);
-}
-
 static void
 debug_sym_finish (struct objfile *objfile)
 {
@@ -508,7 +496,6 @@ static const struct sym_fns debug_sym_fns =
   debug_sym_new_init,
   debug_sym_init,
   debug_sym_read,
-  debug_sym_read_psymbols,
   debug_sym_finish,
   debug_sym_offsets,
   debug_sym_segments,
@@ -543,8 +530,6 @@ install_symfile_debug_logging (struct objfile *objfile)
   COPY_SF_PTR (real_sf, debug_data, sym_new_init, debug_sym_new_init);
   COPY_SF_PTR (real_sf, debug_data, sym_init, debug_sym_init);
   COPY_SF_PTR (real_sf, debug_data, sym_read, debug_sym_read);
-  COPY_SF_PTR (real_sf, debug_data, sym_read_psymbols,
-	       debug_sym_read_psymbols);
   COPY_SF_PTR (real_sf, debug_data, sym_finish, debug_sym_finish);
   COPY_SF_PTR (real_sf, debug_data, sym_offsets, debug_sym_offsets);
   COPY_SF_PTR (real_sf, debug_data, sym_segments, debug_sym_segments);
diff --git a/gdb/symfile.h b/gdb/symfile.h
index 0bd50899679..ba9a4a8cc30 100644
--- a/gdb/symfile.h
+++ b/gdb/symfile.h
@@ -137,13 +137,6 @@ struct sym_fns
 
   void (*sym_read) (struct objfile *, symfile_add_flags);
 
-  /* Read the partial symbols for an objfile.  This may be NULL, in which case
-     gdb has to check other ways if this objfile has any symbols.  This may
-     only be non-NULL if the objfile actually does have debuginfo available.
-     */
-
-  void (*sym_read_psymbols) (struct objfile *);
-
   /* Called when we are finished with an objfile.  Should do all
      cleanup that is specific to the object file format for the
      particular objfile.  */
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index a336c3fadd0..aab140d8aba 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -3004,7 +3004,6 @@ static const struct sym_fns xcoff_sym_fns =
   xcoff_new_init,		/* init anything gbl to entire symtab */
   xcoff_symfile_init,		/* read initial info, setup for sym_read() */
   xcoff_initial_scan,		/* read a symbol file into symtab */
-  NULL,				/* sym_read_psymbols */
   xcoff_symfile_finish,		/* finished with file, cleanup */
   xcoff_symfile_offsets,	/* xlate offsets ext->int form */
   default_symfile_segments,	/* Get segment information from a file.  */
-- 
2.26.2


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 20/26] Introduce objfile::require_partial_symbols
  2021-02-28 20:37 [PATCH 00/26] Allow multiple "partial" symtab readers per objfile Tom Tromey
                   ` (18 preceding siblings ...)
  2021-02-28 20:37 ` [PATCH 19/26] Remove sym_fns::sym_read_psymbols Tom Tromey
@ 2021-02-28 20:37 ` Tom Tromey
  2021-02-28 20:37 ` [PATCH 21/26] Add partial_symtabs parameter to psymtab construction functions Tom Tromey
                   ` (6 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: Tom Tromey @ 2021-02-28 20:37 UTC (permalink / raw)
  To: gdb-patches

This adds a new method, objfile::require_partial_symbols.  This reuses
most of the code from the old function in psymtab.c.  That function is
now made static, and simplified.

gdb/ChangeLog
2021-02-28  Tom Tromey  <tom@tromey.com>

	* symfile.c (read_symbols): Use objfile method.
	* symfile-debug.c (objfile::require_partial_symbols): New method.
	* psymtab.h (require_partial_symbols): Don't declare.
	* psymtab.c (require_partial_symbols): Use objfile method.  Now
	static.
	(psymbol_functions::map_symtabs_matching_filename, OBJFILE)
	(psymbol_functions::lookup_symbol)
	(psymbol_functions::lookup_global_symbol_language)
	(psymbol_functions::find_last_source_symtab)
	(psymbol_functions::forget_cached_source_info)
	(psymbol_functions::print_stats)
	(psymbol_functions::expand_symtabs_for_function)
	(psymbol_functions::expand_all_symtabs)
	(psymbol_functions::expand_symtabs_with_fullname)
	(psymbol_functions::map_symbol_filenames)
	(psymbol_functions::map_matching_symbols)
	(psymbol_functions::expand_symtabs_matching)
	(psymbol_functions::find_compunit_symtab_by_address)
	(maintenance_print_psymbols, maintenance_info_psymtabs)
	(maintenance_check_psymtabs): Update.
	* objfiles.h (struct objfile) <require_partial_symbols>: Declare
	new method.
---
 gdb/ChangeLog       | 25 ++++++++++++++++++
 gdb/objfiles.h      |  3 +++
 gdb/psymtab.c       | 63 ++++++++++++++++++---------------------------
 gdb/psymtab.h       |  8 ------
 gdb/symfile-debug.c | 21 +++++++++++++++
 gdb/symfile.c       |  4 +--
 6 files changed, 75 insertions(+), 49 deletions(-)

diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index ff60e18bca4..c51217be6f0 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -615,6 +615,9 @@ struct objfile
 					       domain_enum domain,
 					       bool *symbol_found_p);
 
+  /* See quick_symbol_functions.  */
+  void require_partial_symbols (bool verbose);
+
 
   /* The object file's original name as specified by the user,
      made absolute, and tilde-expanded.  However, it is not canonicalized
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index b5ddef90878..302ef9a192f 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -75,28 +75,15 @@ psymtab_storage::install_psymtab (partial_symtab *pst)
 
 \f
 
-/* See psymtab.h.  */
+/* Ensure that the partial symbols for OBJFILE have been loaded.  This
+   will print a message when symbols are loaded.  This function
+   returns a range adapter suitable for iterating over the psymtabs of
+   OBJFILE.  */
 
-psymtab_storage::partial_symtab_range
-require_partial_symbols (struct objfile *objfile, bool verbose)
+static psymtab_storage::partial_symtab_range
+require_partial_symbols (struct objfile *objfile)
 {
-  if ((objfile->flags & OBJF_PSYMTABS_READ) == 0)
-    {
-      objfile->flags |= OBJF_PSYMTABS_READ;
-
-      if (objfile->qf->can_lazily_read_symbols ())
-	{
-	  if (verbose)
-	    printf_filtered (_("Reading symbols from %s...\n"),
-			     objfile_name (objfile));
-	  objfile->qf->read_partial_symbols (objfile);
-
-	  if (verbose && !objfile_has_symbols (objfile))
-	    printf_filtered (_("(No debugging symbols found in %s)\n"),
-			     objfile_name (objfile));
-	}
-    }
-
+  objfile->require_partial_symbols (true);
   return objfile->psymtabs ();
 }
 
@@ -140,7 +127,7 @@ psymbol_functions::map_symtabs_matching_filename
 {
   const char *name_basename = lbasename (name);
 
-  for (partial_symtab *pst : require_partial_symbols (objfile, true))
+  for (partial_symtab *pst : require_partial_symbols (objfile))
     {
       /* Anonymous psymtabs don't have a file name.  */
       if (pst->anonymous)
@@ -342,7 +329,7 @@ find_pc_sect_psymtab (struct objfile *objfile,
      its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
      debug info type in single OBJFILE.  */
 
-  for (partial_symtab *pst : require_partial_symbols (objfile, true))
+  for (partial_symtab *pst : require_partial_symbols (objfile))
     if (!pst->psymtabs_addrmap_supported
 	&& pc >= pst->text_low (objfile) && pc < pst->text_high (objfile))
       {
@@ -465,7 +452,7 @@ psymbol_functions::lookup_symbol (struct objfile *objfile,
 
   lookup_name_info psym_lookup_name = lookup_name.make_ignore_params ();
 
-  for (partial_symtab *ps : require_partial_symbols (objfile, true))
+  for (partial_symtab *ps : require_partial_symbols (objfile))
     {
       if (!ps->readin_p (objfile)
 	  && lookup_partial_symbol (objfile, ps, psym_lookup_name,
@@ -516,7 +503,7 @@ psymbol_functions::lookup_global_symbol_language (struct objfile *objfile,
 
   lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
 
-  for (partial_symtab *ps : require_partial_symbols (objfile, true))
+  for (partial_symtab *ps : require_partial_symbols (objfile))
     {
       struct partial_symbol *psym;
       if (ps->readin_p (objfile))
@@ -765,7 +752,7 @@ psymbol_functions::find_last_source_symtab (struct objfile *ofp)
 {
   struct partial_symtab *cs_pst = NULL;
 
-  for (partial_symtab *ps : require_partial_symbols (ofp, true))
+  for (partial_symtab *ps : require_partial_symbols (ofp))
     {
       const char *name = ps->filename;
       int len = strlen (name);
@@ -801,7 +788,7 @@ psymbol_functions::find_last_source_symtab (struct objfile *ofp)
 void
 psymbol_functions::forget_cached_source_info (struct objfile *objfile)
 {
-  for (partial_symtab *pst : require_partial_symbols (objfile, true))
+  for (partial_symtab *pst : require_partial_symbols (objfile))
     {
       if (pst->fullname != NULL)
 	{
@@ -1008,7 +995,7 @@ psymbol_functions::print_stats (struct objfile *objfile, bool print_bcache)
 			 n_psyms);
 
       i = 0;
-      for (partial_symtab *ps : require_partial_symbols (objfile, true))
+      for (partial_symtab *ps : require_partial_symbols (objfile))
 	{
 	  if (!ps->readin_p (objfile))
 	    i++;
@@ -1061,7 +1048,7 @@ psymbol_functions::expand_symtabs_for_function (struct objfile *objfile,
   lookup_name_info base_lookup (func_name, symbol_name_match_type::FULL);
   lookup_name_info lookup_name = base_lookup.make_ignore_params ();
 
-  for (partial_symtab *ps : require_partial_symbols (objfile, true))
+  for (partial_symtab *ps : require_partial_symbols (objfile))
     {
       if (ps->readin_p (objfile))
 	continue;
@@ -1080,7 +1067,7 @@ psymbol_functions::expand_symtabs_for_function (struct objfile *objfile,
 void
 psymbol_functions::expand_all_symtabs (struct objfile *objfile)
 {
-  for (partial_symtab *psymtab : require_partial_symbols (objfile, true))
+  for (partial_symtab *psymtab : require_partial_symbols (objfile))
     psymtab_to_symtab (objfile, psymtab);
 }
 
@@ -1091,7 +1078,7 @@ void
 psymbol_functions::expand_symtabs_with_fullname (struct objfile *objfile,
 						 const char *fullname)
 {
-  for (partial_symtab *p : require_partial_symbols (objfile, true))
+  for (partial_symtab *p : require_partial_symbols (objfile))
     {
       /* Anonymous psymtabs don't have a name of a source file.  */
       if (p->anonymous)
@@ -1115,7 +1102,7 @@ psymbol_functions::map_symbol_filenames (struct objfile *objfile,
 					 void *data,
 					 int need_fullname)
 {
-  for (partial_symtab *ps : require_partial_symbols (objfile, true))
+  for (partial_symtab *ps : require_partial_symbols (objfile))
     {
       const char *fullname;
 
@@ -1196,7 +1183,7 @@ psymbol_functions::map_matching_symbols
 {
   const int block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
 
-  for (partial_symtab *ps : require_partial_symbols (objfile, true))
+  for (partial_symtab *ps : require_partial_symbols (objfile))
     {
       QUIT;
       if (ps->readin_p (objfile)
@@ -1321,7 +1308,7 @@ psymbol_functions::expand_symtabs_matching
    enum search_domain domain)
 {
   /* Clear the search flags.  */
-  for (partial_symtab *ps : require_partial_symbols (objfile, true))
+  for (partial_symtab *ps : require_partial_symbols (objfile))
     ps->searched_flag = PST_NOT_SEARCHED;
 
   for (partial_symtab *ps : m_partial_symtabs->range ())
@@ -1414,7 +1401,7 @@ psymbol_functions::find_compunit_symtab_by_address (struct objfile *objfile,
     {
       std::set<CORE_ADDR> seen_addrs;
 
-      for (partial_symtab *pst : require_partial_symbols (objfile, true))
+      for (partial_symtab *pst : require_partial_symbols (objfile))
 	{
 	  fill_psymbol_map (objfile, pst,
 			    &seen_addrs,
@@ -1861,7 +1848,7 @@ maintenance_print_psymbols (const char *args, int from_tty)
 	}
       else
 	{
-	  for (partial_symtab *ps : require_partial_symbols (objfile, true))
+	  for (partial_symtab *ps : require_partial_symbols (objfile))
 	    {
 	      int print_for_source = 0;
 
@@ -1892,7 +1879,7 @@ maintenance_print_psymbols (const char *args, int from_tty)
 
       if (address_arg == NULL
 	  && source_arg == NULL
-	  && objfile->partial_symtabs->psymtabs_addrmap != NULL)
+	  && partial_symtabs->psymtabs_addrmap != NULL)
 	{
 	  outfile->puts ("\n");
 	  dump_psymtab_addrmap (objfile, partial_symtabs, NULL, outfile);
@@ -1925,7 +1912,7 @@ maintenance_info_psymtabs (const char *regexp, int from_tty)
 	   actually find a symtab whose name matches.  */
 	int printed_objfile_start = 0;
 
-	for (partial_symtab *psymtab : require_partial_symbols (objfile, true))
+	for (partial_symtab *psymtab : require_partial_symbols (objfile))
 	  {
 	    QUIT;
 
@@ -2025,7 +2012,7 @@ maintenance_check_psymtabs (const char *ignore, int from_tty)
   const struct block *b;
 
   for (objfile *objfile : current_program_space->objfiles ())
-    for (partial_symtab *ps : require_partial_symbols (objfile, true))
+    for (partial_symtab *ps : require_partial_symbols (objfile))
       {
 	struct gdbarch *gdbarch = objfile->arch ();
 
diff --git a/gdb/psymtab.h b/gdb/psymtab.h
index 18b47c55b3c..e19cac64aa4 100644
--- a/gdb/psymtab.h
+++ b/gdb/psymtab.h
@@ -146,14 +146,6 @@ class psymtab_storage
 };
 
 
-/* Ensure that the partial symbols for OBJFILE have been loaded.  If
-   VERBOSE is true, then this will print a message when symbols
-   are loaded.  This function returns a range adapter suitable for
-   iterating over the psymtabs of OBJFILE.  */
-
-extern psymtab_storage::partial_symtab_range require_partial_symbols
-    (struct objfile *objfile, bool verbose);
-
 extern quick_symbol_functions_up make_psymbol_functions
      (const std::shared_ptr<psymtab_storage> &);
 
diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index 94559c7370c..99974536bf4 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -357,6 +357,27 @@ objfile::lookup_global_symbol_language (const char *name,
   return result;
 }
 
+void
+objfile::require_partial_symbols (bool verbose)
+{
+  if ((flags & OBJF_PSYMTABS_READ) == 0)
+    {
+      flags |= OBJF_PSYMTABS_READ;
+
+      if (qf->can_lazily_read_symbols ())
+	{
+	  if (verbose)
+	    printf_filtered (_("Reading symbols from %s...\n"),
+			     objfile_name (this));
+	  qf->read_partial_symbols (this);
+
+	  if (verbose && !objfile_has_symbols (this))
+	    printf_filtered (_("(No debugging symbols found in %s)\n"),
+			     objfile_name (this));
+	}
+    }
+}
+
 \f
 /* Debugging version of struct sym_probe_fns.  */
 
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 01304523c0d..d2ea04ed149 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -69,8 +69,6 @@
 #include <chrono>
 #include <algorithm>
 
-#include "psymtab.h"
-
 int (*deprecated_ui_load_progress_hook) (const char *section,
 					 unsigned long num);
 void (*deprecated_show_load_progress) (const char *section,
@@ -793,7 +791,7 @@ read_symbols (struct objfile *objfile, symfile_add_flags add_flags)
 	}
     }
   if ((add_flags & SYMFILE_NO_READ) == 0)
-    require_partial_symbols (objfile, false);
+    objfile->require_partial_symbols (false);
 }
 
 /* Initialize entry point information for this objfile.  */
-- 
2.26.2


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 21/26] Add partial_symtabs parameter to psymtab construction functions
  2021-02-28 20:37 [PATCH 00/26] Allow multiple "partial" symtab readers per objfile Tom Tromey
                   ` (19 preceding siblings ...)
  2021-02-28 20:37 ` [PATCH 20/26] Introduce objfile::require_partial_symbols Tom Tromey
@ 2021-02-28 20:37 ` Tom Tromey
  2021-02-28 20:37 ` [PATCH 22/26] Remove last objfile partial_symtab references from psymtab.c Tom Tromey
                   ` (5 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: Tom Tromey @ 2021-02-28 20:37 UTC (permalink / raw)
  To: gdb-patches

This adds a partial_symtabs parameter to the psymtab constructors and
to add_psymbol.  This helps with the overall project of removing the
partial symtabs from the objfile.

gdb/ChangeLog
2021-02-28  Tom Tromey  <tom@tromey.com>

	* xcoffread.c (xcoff_start_psymtab): Add partial_symtabs parameter.
	(xcoff_end_psymtab, scan_xcoff_symtab): Update.
	* psymtab.c (partial_symtab::partial_symtab): Add partial_symtabs
	parameter.
	(add_psymbol_to_bcache): Remove.
	(partial_symtab::add_psymbol): Add partial_symtabs parameter.
	(partial_symtab::add_psymbol, partial_symtab::partial_symtab):
	Likewise.
	* psympriv.h (partial_symtab): Add partial_symtabs parameter.
	<add_psymbol>: Likewise.
	(standard_psymtab, legacy_psymtab): Likewise.
	* mdebugread.c (parse_partial_symbols): Update.
	(handle_psymbol_enumerators): Add partial_symtabs parameter.
	(handle_psymbol_enumerators): Update.
	(new_psymtab): Add partial_symtabs parameter.
	* dwarf2/read.h (dwarf2_psymtab): Add partial_symtabs parameter.
	* dwarf2/read.c (dwarf2_include_psymtab): Add partial_symtabs
	parameter.
	(dwarf2_create_include_psymtab): Add partial_symtabs parameter.
	(create_partial_symtab, add_partial_symbol, dwarf_decode_lines):
	Update.
	* dbxread.c (read_dbx_symtab): Update.
	(start_psymtab): Add partial_symtabs parameter.
	(dbx_end_psymtab): Update.
	* ctfread.c (struct ctf_context) <partial_symtabs>: New member.
	(ctf_psymtab): Add partial_symtabs parameter.
	(create_partial_symtab, ctf_psymtab_type_cb, ctf_psymtab_var_cb):
	Update.
	(scan_partial_symbols): Add partial_symtabs parameter.
	(scan_partial_symbols, elfctf_build_psymtabs): Update.
---
 gdb/ChangeLog     | 33 ++++++++++++++++++++++++
 gdb/ctfread.c     | 26 ++++++++++++-------
 gdb/dbxread.c     | 42 ++++++++++++++++++------------
 gdb/dwarf2/read.c | 26 +++++++++++++------
 gdb/dwarf2/read.h |  6 +++--
 gdb/mdebugread.c  | 65 ++++++++++++++++++++++++++++++-----------------
 gdb/psympriv.h    | 34 +++++++++++++++++--------
 gdb/psymtab.c     | 39 ++++++++++++----------------
 gdb/xcoffread.c   | 39 ++++++++++++++++++----------
 9 files changed, 204 insertions(+), 106 deletions(-)

diff --git a/gdb/ctfread.c b/gdb/ctfread.c
index 928cb3025c3..6adfcc12056 100644
--- a/gdb/ctfread.c
+++ b/gdb/ctfread.c
@@ -115,6 +115,7 @@ struct ctf_context
 {
   ctf_dict_t *fp;
   struct objfile *of;
+  psymtab_storage *partial_symtabs;
   partial_symtab *pst;
   struct buildsym_compunit *builder;
 };
@@ -122,8 +123,11 @@ struct ctf_context
 /* A partial symtab, specialized for this module.  */
 struct ctf_psymtab : public standard_psymtab
 {
-  ctf_psymtab (const char *filename, struct objfile *objfile, CORE_ADDR addr)
-    : standard_psymtab (filename, objfile, addr)
+  ctf_psymtab (const char *filename,
+	       psymtab_storage *partial_symtabs,
+	       struct objfile *objfile,
+	       CORE_ADDR addr)
+    : standard_psymtab (filename, partial_symtabs, objfile, addr)
   {
   }
 
@@ -1311,16 +1315,18 @@ ctf_psymtab::read_symtab (struct objfile *objfile)
 static ctf_psymtab *
 create_partial_symtab (const char *name,
 		       ctf_dict_t *cfp,
+		       psymtab_storage *partial_symtabs,
 		       struct objfile *objfile)
 {
   ctf_psymtab *pst;
   struct ctf_context *ccx;
 
-  pst = new ctf_psymtab (name, objfile, 0);
+  pst = new ctf_psymtab (name, partial_symtabs, objfile, 0);
 
   ccx = XOBNEW (&objfile->objfile_obstack, struct ctf_context);
   ccx->fp = cfp;
   ccx->of = objfile;
+  ccx->partial_symtabs = partial_symtabs;
   ccx->pst = pst;
   ccx->builder = nullptr;
   pst->context = ccx;
@@ -1383,7 +1389,7 @@ ctf_psymtab_type_cb (ctf_id_t tid, void *arg)
   ccp->pst->add_psymbol (name.get (), true,
 			 domain, aclass, section,
 			 psymbol_placement::GLOBAL,
-			 0, language_c, ccp->of);
+			 0, language_c, ccp->partial_symtabs, ccp->of);
 
   return 0;
 }
@@ -1398,7 +1404,7 @@ ctf_psymtab_var_cb (const char *name, ctf_id_t id, void *arg)
   ccp->pst->add_psymbol (name, true,
 			 VAR_DOMAIN, LOC_STATIC, -1,
 			 psymbol_placement::GLOBAL,
-			 0, language_c, ccp->of);
+			 0, language_c, ccp->partial_symtabs, ccp->of);
   return 0;
 }
 
@@ -1406,11 +1412,12 @@ ctf_psymtab_var_cb (const char *name, ctf_id_t id, void *arg)
    debugging information is available.  */
 
 static void
-scan_partial_symbols (ctf_dict_t *cfp, struct objfile *of)
+scan_partial_symbols (ctf_dict_t *cfp, psymtab_storage *partial_symtabs,
+		      struct objfile *of)
 {
   bfd *abfd = of->obfd;
   const char *name = bfd_get_filename (abfd);
-  ctf_psymtab *pst = create_partial_symtab (name, cfp, of);
+  ctf_psymtab *pst = create_partial_symtab (name, cfp, partial_symtabs, of);
 
   struct ctf_context *ccx = pst->context;
 
@@ -1461,7 +1468,7 @@ scan_partial_symbols (ctf_dict_t *cfp, struct objfile *of)
       pst->add_psymbol (tname.get (), true,
 			tdomain, aclass, -1,
 			psymbol_placement::STATIC,
-			0, language_c, of);
+			0, language_c, partial_symtabs, of);
     }
 
   pst->end ();
@@ -1488,7 +1495,8 @@ elfctf_build_psymtabs (struct objfile *of)
 	   bfd_get_filename (abfd), ctf_errmsg (err));
   ctf_dict_key.emplace (of, fp);
 
-  scan_partial_symbols (fp, of);
+  psymtab_storage *partial_symtabs = of->partial_symtabs.get ();
+  scan_partial_symbols (fp, partial_symtabs, of);
 }
 
 #else
diff --git a/gdb/dbxread.c b/gdb/dbxread.c
index e0cc2597f73..a6f44d5a564 100644
--- a/gdb/dbxread.c
+++ b/gdb/dbxread.c
@@ -298,8 +298,8 @@ static void add_old_header_file (const char *, int);
 
 static void add_this_object_header_file (int);
 
-static legacy_psymtab *start_psymtab (struct objfile *, const char *,
-					     CORE_ADDR, int);
+static legacy_psymtab *start_psymtab (psymtab_storage *, struct objfile *,
+				      const char *, CORE_ADDR, int);
 
 /* Free up old header file tables.  */
 
@@ -1291,7 +1291,7 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 
 	    if (!pst)
 	      {
-		pst = start_psymtab (objfile,
+		pst = start_psymtab (partial_symtabs, objfile,
 				     namestring, valu,
 				     first_so_symnum * symbol_size);
 		pst->dirname = dirname_nso;
@@ -1467,7 +1467,8 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 				VAR_DOMAIN, LOC_STATIC,
 				data_sect_index,
 				psymbol_placement::STATIC,
-				nlist.n_value, psymtab_language, objfile);
+				nlist.n_value, psymtab_language,
+				partial_symtabs, objfile);
 	      continue;
 
 	    case 'G':
@@ -1477,7 +1478,8 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 				VAR_DOMAIN, LOC_STATIC,
 				data_sect_index,
 				psymbol_placement::GLOBAL,
-				nlist.n_value, psymtab_language, objfile);
+				nlist.n_value, psymtab_language,
+				partial_symtabs, objfile);
 	      continue;
 
 	    case 'T':
@@ -1494,14 +1496,16 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 		  pst->add_psymbol (gdb::string_view (sym_name, sym_len),
 				    true, STRUCT_DOMAIN, LOC_TYPEDEF, -1,
 				    psymbol_placement::STATIC,
-				    0, psymtab_language, objfile);
+				    0, psymtab_language,
+				    partial_symtabs, objfile);
 		  if (p[2] == 't')
 		    {
 		      /* Also a typedef with the same name.  */
 		      pst->add_psymbol (gdb::string_view (sym_name, sym_len),
 					true, VAR_DOMAIN, LOC_TYPEDEF, -1,
 					psymbol_placement::STATIC,
-					0, psymtab_language, objfile);
+					0, psymtab_language,
+					partial_symtabs, objfile);
 		      p += 1;
 		    }
 		}
@@ -1513,7 +1517,8 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 		  pst->add_psymbol (gdb::string_view (sym_name, sym_len),
 				    true, VAR_DOMAIN, LOC_TYPEDEF, -1,
 				    psymbol_placement::STATIC,
-				    0, psymtab_language, objfile);
+				    0, psymtab_language,
+				    partial_symtabs, objfile);
 		}
 	    check_enum:
 	      /* If this is an enumerated type, we need to
@@ -1574,7 +1579,8 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 		      pst->add_psymbol (gdb::string_view (p, q - p), true,
 					VAR_DOMAIN, LOC_CONST, -1,
 					psymbol_placement::STATIC, 0,
-					psymtab_language, objfile);
+					psymtab_language,
+					partial_symtabs, objfile);
 		      /* Point past the name.  */
 		      p = q;
 		      /* Skip over the value.  */
@@ -1592,7 +1598,8 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 	      pst->add_psymbol (gdb::string_view (sym_name, sym_len), true,
 				VAR_DOMAIN, LOC_CONST, -1,
 				psymbol_placement::STATIC, 0,
-				psymtab_language, objfile);
+				psymtab_language,
+				partial_symtabs, objfile);
 	      continue;
 
 	    case 'f':
@@ -1648,7 +1655,8 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 				VAR_DOMAIN, LOC_BLOCK,
 				SECT_OFF_TEXT (objfile),
 				psymbol_placement::STATIC,
-				nlist.n_value, psymtab_language, objfile);
+				nlist.n_value, psymtab_language,
+				partial_symtabs, objfile);
 	      continue;
 
 	      /* Global functions were ignored here, but now they
@@ -1707,7 +1715,8 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 				VAR_DOMAIN, LOC_BLOCK,
 				SECT_OFF_TEXT (objfile),
 				psymbol_placement::GLOBAL,
-				nlist.n_value, psymtab_language, objfile);
+				nlist.n_value, psymtab_language,
+				partial_symtabs, objfile);
 	      continue;
 
 	      /* Two things show up here (hopefully); static symbols of
@@ -1902,10 +1911,11 @@ read_dbx_symtab (minimal_symbol_reader &reader,
    (normal).  */
 
 static legacy_psymtab *
-start_psymtab (struct objfile *objfile, const char *filename, CORE_ADDR textlow,
-	       int ldsymoff)
+start_psymtab (psymtab_storage *partial_symtabs, struct objfile *objfile,
+	       const char *filename, CORE_ADDR textlow, int ldsymoff)
 {
-  legacy_psymtab *result = new legacy_psymtab (filename, objfile, textlow);
+  legacy_psymtab *result = new legacy_psymtab (filename, partial_symtabs,
+					       objfile, textlow);
 
   result->read_symtab_private =
     XOBNEW (&objfile->objfile_obstack, struct symloc);
@@ -2028,7 +2038,7 @@ dbx_end_psymtab (struct objfile *objfile, psymtab_storage *partial_symtabs,
   for (i = 0; i < num_includes; i++)
     {
       legacy_psymtab *subpst =
-	new legacy_psymtab (include_list[i], objfile);
+	new legacy_psymtab (include_list[i], partial_symtabs, objfile);
 
       subpst->read_symtab_private =
 	XOBNEW (&objfile->objfile_obstack, struct symloc);
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 3a050b351a0..183876bb5b7 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -6467,8 +6467,10 @@ read_abbrev_offset (dwarf2_per_objfile *per_objfile,
 /* A partial symtab that is used only for include files.  */
 struct dwarf2_include_psymtab : public partial_symtab
 {
-  dwarf2_include_psymtab (const char *filename, struct objfile *objfile)
-    : partial_symtab (filename, objfile)
+  dwarf2_include_psymtab (const char *filename,
+			  psymtab_storage *partial_symtabs,
+			  struct objfile *objfile)
+    : partial_symtab (filename, partial_symtabs, objfile)
   {
   }
 
@@ -6521,10 +6523,13 @@ struct dwarf2_include_psymtab : public partial_symtab
 
 static void
 dwarf2_create_include_psymtab (dwarf2_per_bfd *per_bfd,
-			       const char *name, dwarf2_psymtab *pst,
+			       const char *name,
+			       dwarf2_psymtab *pst,
+			       psymtab_storage *partial_symtabs,
 			       struct objfile *objfile)
 {
-  dwarf2_include_psymtab *subpst = new dwarf2_include_psymtab (name, objfile);
+  dwarf2_include_psymtab *subpst
+    = new dwarf2_include_psymtab (name, partial_symtabs, objfile);
 
   if (!IS_ABSOLUTE_PATH (subpst->filename))
     subpst->dirname = pst->dirname;
@@ -7779,7 +7784,8 @@ create_partial_symtab (dwarf2_per_cu_data *per_cu,
   struct objfile *objfile = per_objfile->objfile;
   dwarf2_psymtab *pst;
 
-  pst = new dwarf2_psymtab (name, objfile, per_cu);
+  pst = new dwarf2_psymtab (name, per_objfile->per_bfd->partial_symtabs.get (),
+			    objfile, per_cu);
 
   pst->psymtabs_addrmap_supported = true;
 
@@ -8893,7 +8899,9 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
 					    &objfile->objfile_obstack);
 	  psymbol.ginfo.set_linkage_name (pdi->linkage_name);
 	}
-      cu->per_cu->v.psymtab->add_psymbol (psymbol, *where, objfile);
+      cu->per_cu->v.psymtab->add_psymbol
+	(psymbol, *where, per_objfile->per_bfd->partial_symtabs.get (),
+	 objfile);
     }
 }
 
@@ -22096,8 +22104,10 @@ dwarf_decode_lines (struct line_header *lh, const char *comp_dir,
 	      psymtab_include_file_name (lh, file_entry, pst,
 					 comp_dir, &name_holder);
 	    if (include_name != NULL)
-	      dwarf2_create_include_psymtab (cu->per_objfile->per_bfd,
-					     include_name, pst, objfile);
+	      dwarf2_create_include_psymtab
+		(cu->per_objfile->per_bfd, include_name, pst,
+		 cu->per_objfile->per_bfd->partial_symtabs.get (),
+		 objfile);
 	  }
     }
   else
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index aba1d83e468..236b3358190 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -406,9 +406,11 @@ dwarf2_per_objfile *get_dwarf2_per_objfile (struct objfile *objfile);
 /* A partial symtab specialized for DWARF.  */
 struct dwarf2_psymtab : public partial_symtab
 {
-  dwarf2_psymtab (const char *filename, struct objfile *objfile,
+  dwarf2_psymtab (const char *filename,
+		  psymtab_storage *partial_symtabs,
+		  struct objfile *objfile,
 		  dwarf2_per_cu_data *per_cu)
-    : partial_symtab (filename, objfile, 0),
+    : partial_symtab (filename, partial_symtabs, objfile, 0),
       per_cu_data (per_cu)
   {
   }
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index d178beef734..34ee718e22a 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -252,7 +252,8 @@ static struct symbol *mylookup_symbol (const char *, const struct block *,
 
 static void sort_blocks (struct symtab *);
 
-static legacy_psymtab *new_psymtab (const char *, struct objfile *);
+static legacy_psymtab *new_psymtab (const char *, psymtab_storage *,
+				    struct objfile *);
 
 static void mdebug_expand_psymtab (legacy_psymtab *pst,
 				  struct objfile *objfile);
@@ -265,7 +266,8 @@ static int add_line (struct linetable *, int, CORE_ADDR, int);
 
 static struct linetable *shrink_linetable (struct linetable *);
 
-static void handle_psymbol_enumerators (struct objfile *, partial_symtab *,
+static void handle_psymbol_enumerators (struct objfile *, psymtab_storage *,
+					partial_symtab *,
 					FDR *, int, CORE_ADDR);
 
 static const char *mdebug_next_symbol_text (struct objfile *);
@@ -2365,7 +2367,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
   fdr_to_pst = fdr_to_pst_holder.data ();
   fdr_to_pst++;
   {
-    legacy_psymtab *new_pst = new_psymtab ("", objfile);
+    legacy_psymtab *new_pst = new_psymtab ("", partial_symtabs, objfile);
 
     fdr_to_pst[-1].pst = new_pst;
     FDR_IDX (new_pst) = -1;
@@ -2601,7 +2603,8 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 	textlow = fh->adr;
       else
 	textlow = 0;
-      pst = new legacy_psymtab (fdr_name (fh), objfile, textlow);
+      pst = new legacy_psymtab (fdr_name (fh), partial_symtabs, objfile,
+				textlow);
       pst->read_symtab_private = XOBNEW (&objfile->objfile_obstack, symloc);
       memset (pst->read_symtab_private, 0, sizeof (struct symloc));
 
@@ -3038,7 +3041,8 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 					  SECT_OFF_DATA (objfile),
 					  psymbol_placement::STATIC,
 					  sh.value,
-					  psymtab_language, objfile);
+					  psymtab_language,
+					  partial_symtabs, objfile);
 			continue;
 		      case 'G':
 			/* The addresses in these entries are reported
@@ -3050,7 +3054,8 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 					  SECT_OFF_DATA (objfile),
 					  psymbol_placement::GLOBAL,
 					  sh.value,
-					  psymtab_language, objfile);
+					  psymtab_language,
+					  partial_symtabs, objfile);
 			continue;
 
 		      case 'T':
@@ -3068,7 +3073,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 			      (gdb::string_view (namestring, p - namestring),
 			       true, STRUCT_DOMAIN, LOC_TYPEDEF, -1,
 			       psymbol_placement::STATIC, 0, psymtab_language,
-			       objfile);
+			       partial_symtabs, objfile);
 			    if (p[2] == 't')
 			      {
 				/* Also a typedef with the same name.  */
@@ -3077,7 +3082,8 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 						     p - namestring),
 				   true, VAR_DOMAIN, LOC_TYPEDEF, -1,
 				   psymbol_placement::STATIC, 0,
-				   psymtab_language, objfile);
+				   psymtab_language,
+				   partial_symtabs, objfile);
 				p += 1;
 			      }
 			  }
@@ -3091,7 +3097,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 						 p - namestring),
 			       true, VAR_DOMAIN, LOC_TYPEDEF, -1,
 			       psymbol_placement::STATIC, 0, psymtab_language,
-			       objfile);
+			       partial_symtabs, objfile);
 			  }
 		      check_enum:
 			/* If this is an enumerated type, we need to add
@@ -3158,7 +3164,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 						  LOC_CONST, -1,
 						  psymbol_placement::STATIC,
 						  0, psymtab_language,
-						  objfile);
+						  partial_symtabs, objfile);
 				/* Point past the name.  */
 				p = q;
 				/* Skip over the value.  */
@@ -3176,7 +3182,8 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 							    p - namestring),
 					  true, VAR_DOMAIN, LOC_CONST, -1,
 					  psymbol_placement::STATIC,
-					  0, psymtab_language, objfile);
+					  0, psymtab_language,
+					  partial_symtabs, objfile);
 			continue;
 
 		      case 'f':
@@ -3192,7 +3199,8 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 					  SECT_OFF_TEXT (objfile),
 					  psymbol_placement::STATIC,
 					  sh.value,
-					  psymtab_language, objfile);
+					  psymtab_language,
+					  partial_symtabs, objfile);
 			continue;
 
 			/* Global functions were ignored here, but now they
@@ -3212,7 +3220,8 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 					  SECT_OFF_TEXT (objfile),
 					  psymbol_placement::GLOBAL,
 					  sh.value,
-					  psymtab_language, objfile);
+					  psymtab_language,
+					  partial_symtabs, objfile);
 			continue;
 
 			/* Two things show up here (hopefully); static
@@ -3446,13 +3455,15 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 				      VAR_DOMAIN, LOC_BLOCK,
 				      section,
 				      psymbol_placement::GLOBAL,
-				      sh.value, psymtab_language, objfile);
+				      sh.value, psymtab_language,
+				      partial_symtabs, objfile);
 		  else
 		    pst->add_psymbol (sym_name, true,
 				      VAR_DOMAIN, LOC_BLOCK,
 				      section,
 				      psymbol_placement::STATIC,
-				      sh.value, psymtab_language, objfile);
+				      sh.value, psymtab_language,
+				      partial_symtabs, objfile);
 
 		  procaddr = sh.value;
 
@@ -3518,10 +3529,11 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 		      pst->add_psymbol (sym_name, true,
 					STRUCT_DOMAIN, LOC_TYPEDEF, -1,
 					psymbol_placement::STATIC,
-					0, psymtab_language, objfile);
+					0, psymtab_language,
+					partial_symtabs, objfile);
 		    }
-		  handle_psymbol_enumerators (objfile, pst, fh,
-					      sh.st, sh.value);
+		  handle_psymbol_enumerators (objfile, partial_symtabs,
+					      pst, fh, sh.st, sh.value);
 
 		  /* Skip over the block.  */
 		  new_sdx = sh.index;
@@ -3559,7 +3571,8 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 	      pst->add_psymbol (sym_name, true,
 				VAR_DOMAIN, theclass, section,
 				psymbol_placement::STATIC,
-				sh.value, psymtab_language, objfile);
+				sh.value, psymtab_language,
+				partial_symtabs, objfile);
 	    skip:
 	      cur_sdx++;	/* Go to next file symbol.  */
 	    }
@@ -3638,7 +3651,8 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 				VAR_DOMAIN, theclass,
 				section,
 				psymbol_placement::GLOBAL,
-				svalue, psymtab_language, objfile);
+				svalue, psymtab_language,
+				partial_symtabs, objfile);
 	    }
 	}
 
@@ -3740,7 +3754,9 @@ parse_partial_symbols (minimal_symbol_reader &reader,
    all the enum constants to the partial symbol table.  */
 
 static void
-handle_psymbol_enumerators (struct objfile *objfile, partial_symtab *pst,
+handle_psymbol_enumerators (struct objfile *objfile,
+			    psymtab_storage *partial_symtabs,
+			    partial_symtab *pst,
 			    FDR *fh, int stype, CORE_ADDR svalue)
 {
   const bfd_size_type external_sym_size = debug_swap->external_sym_size;
@@ -3799,7 +3815,7 @@ handle_psymbol_enumerators (struct objfile *objfile, partial_symtab *pst,
       pst->add_psymbol (name, true,
 			VAR_DOMAIN, LOC_CONST, -1,
 			psymbol_placement::STATIC, 0,
-			psymtab_language, objfile);
+			psymtab_language, partial_symtabs, objfile);
       ext_sym += external_sym_size;
     }
 }
@@ -4623,11 +4639,12 @@ new_symtab (const char *name, int maxlines, struct objfile *objfile)
 /* Allocate a new partial_symtab NAME.  */
 
 static legacy_psymtab *
-new_psymtab (const char *name, struct objfile *objfile)
+new_psymtab (const char *name, psymtab_storage *partial_symtabs,
+	     struct objfile *objfile)
 {
   legacy_psymtab *psymtab;
 
-  psymtab = new legacy_psymtab (name, objfile);
+  psymtab = new legacy_psymtab (name, partial_symtabs, objfile);
 
   /* Keep a backpointer to the file's symbols.  */
 
diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index b1b8027ce3a..8717bd259e1 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -117,14 +117,18 @@ struct partial_symtab
      partial symtab will also be installed using
      psymtab_storage::install.  */
 
-  partial_symtab (const char *filename, struct objfile *objfile)
+  partial_symtab (const char *filename,
+		  psymtab_storage *partial_symtabs,
+		  struct objfile *objfile)
     ATTRIBUTE_NONNULL (2) ATTRIBUTE_NONNULL (3);
 
   /* Like the above, but also sets the initial text low and text high
      from the ADDR argument, and sets the global- and
      static-offsets.  */
 
-  partial_symtab (const char *filename, struct objfile *objfile,
+  partial_symtab (const char *filename,
+		  psymtab_storage *partial_symtabs,
+		  struct objfile *objfile,
 		  CORE_ADDR addr)
     ATTRIBUTE_NONNULL (2) ATTRIBUTE_NONNULL (3);
 
@@ -236,6 +240,7 @@ struct partial_symtab
 		    psymbol_placement where,
 		    CORE_ADDR coreaddr,
 		    enum language language,
+		    psymtab_storage *partial_symtabs,
 		    struct objfile *objfile);
 
   /* Add a symbol to this partial symbol table of OBJFILE.  The psymbol
@@ -244,6 +249,7 @@ struct partial_symtab
 
   void add_psymbol (const partial_symbol &psym,
 		    psymbol_placement where,
+		    psymtab_storage *partial_symtabs,
 		    struct objfile *objfile);
 
 
@@ -361,14 +367,18 @@ struct partial_symtab
    object.  */
 struct standard_psymtab : public partial_symtab
 {
-  standard_psymtab (const char *filename, struct objfile *objfile)
-    : partial_symtab (filename, objfile)
+  standard_psymtab (const char *filename,
+		    psymtab_storage *partial_symtabs,
+		    struct objfile *objfile)
+    : partial_symtab (filename, partial_symtabs, objfile)
   {
   }
 
-  standard_psymtab (const char *filename, struct objfile *objfile,
+  standard_psymtab (const char *filename,
+		    psymtab_storage *partial_symtabs,
+		    struct objfile *objfile,
 		    CORE_ADDR addr)
-    : partial_symtab (filename, objfile, addr)
+    : partial_symtab (filename, partial_symtabs, objfile, addr)
   {
   }
 
@@ -399,14 +409,18 @@ struct standard_psymtab : public partial_symtab
 
 struct legacy_psymtab : public standard_psymtab
 {
-  legacy_psymtab (const char *filename, struct objfile *objfile)
-    : standard_psymtab (filename, objfile)
+  legacy_psymtab (const char *filename,
+		  psymtab_storage *partial_symtabs,
+		  struct objfile *objfile)
+    : standard_psymtab (filename, partial_symtabs, objfile)
   {
   }
 
-  legacy_psymtab (const char *filename, struct objfile *objfile,
+  legacy_psymtab (const char *filename,
+		  psymtab_storage *partial_symtabs,
+		  struct objfile *objfile,
 		  CORE_ADDR addr)
-    : standard_psymtab (filename, objfile, addr)
+    : standard_psymtab (filename, partial_symtabs, objfile, addr)
   {
   }
 
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 302ef9a192f..e662ba16cd6 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -1447,9 +1447,10 @@ make_psymbol_functions (const std::shared_ptr<psymtab_storage> &storage)
    the end of the symbol list.  */
 
 partial_symtab::partial_symtab (const char *filename,
+				psymtab_storage *partial_symtabs,
 				struct objfile *objfile,
 				CORE_ADDR textlow)
-  : partial_symtab (filename, objfile)
+  : partial_symtab (filename, partial_symtabs, objfile)
 {
   set_text_low (textlow);
   set_text_high (raw_text_low ()); /* default */
@@ -1514,33 +1515,21 @@ psymbol_bcache::compare (const void *addr1, const void *addr2, int length)
 	  && sym1->ginfo.linkage_name () == sym2->ginfo.linkage_name ());
 }
 
-/* Helper function, initialises partial symbol structure and stashes
-   it into objfile's bcache.  Note that our caching mechanism will
-   use all fields of struct partial_symbol to determine hash value of the
-   structure.  In other words, having two symbols with the same name but
-   different domain (or address) is possible and correct.  */
-
-static struct partial_symbol *
-add_psymbol_to_bcache (const partial_symbol &psymbol, struct objfile *objfile,
-		       bool *added)
-{
-  /* Stash the partial symbol away in the cache.  */
-  return ((struct partial_symbol *)
-	  objfile->partial_symtabs->psymbol_cache.insert
-	  (&psymbol, sizeof (struct partial_symbol), added));
-}
-
 /* See psympriv.h.  */
 
 void
 partial_symtab::add_psymbol (const partial_symbol &psymbol,
 			     psymbol_placement where,
+			     psymtab_storage *partial_symtabs,
 			     struct objfile *objfile)
 {
   bool added;
 
   /* Stash the partial symbol away in the cache.  */
-  partial_symbol *psym = add_psymbol_to_bcache (psymbol, objfile, &added);
+  partial_symbol *psym
+    = ((struct partial_symbol *)
+       partial_symtabs->psymbol_cache.insert
+       (&psymbol, sizeof (struct partial_symbol), &added));
 
   /* Do not duplicate global partial symbols.  */
   if (where == psymbol_placement::GLOBAL && !added)
@@ -1563,7 +1552,9 @@ partial_symtab::add_psymbol (gdb::string_view name, bool copy_name,
 			     short section,
 			     psymbol_placement where,
 			     CORE_ADDR coreaddr,
-			     enum language language, struct objfile *objfile)
+			     enum language language,
+			     psymtab_storage *partial_symtabs,
+			     struct objfile *objfile)
 {
   struct partial_symbol psymbol;
   memset (&psymbol, 0, sizeof (psymbol));
@@ -1572,20 +1563,22 @@ partial_symtab::add_psymbol (gdb::string_view name, bool copy_name,
   psymbol.ginfo.set_section_index (section);
   psymbol.domain = domain;
   psymbol.aclass = theclass;
-  psymbol.ginfo.set_language (language, objfile->partial_symtabs->obstack ());
+  psymbol.ginfo.set_language (language, partial_symtabs->obstack ());
   psymbol.ginfo.compute_and_set_names (name, copy_name, objfile->per_bfd);
 
-  add_psymbol (psymbol, where, objfile);
+  add_psymbol (psymbol, where, partial_symtabs, objfile);
 }
 
 /* See psympriv.h.  */
 
-partial_symtab::partial_symtab (const char *filename_, struct objfile *objfile)
+partial_symtab::partial_symtab (const char *filename_,
+				psymtab_storage *partial_symtabs,
+				struct objfile *objfile)
   : searched_flag (PST_NOT_SEARCHED),
     text_low_valid (0),
     text_high_valid (0)
 {
-  objfile->partial_symtabs->install_psymtab (this);
+  partial_symtabs->install_psymtab (this);
 
   filename = objfile->intern (filename_);
 
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index aab140d8aba..ee52ba53d92 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -1959,11 +1959,13 @@ static unsigned int first_fun_line_offset;
    (normal).  */
 
 static legacy_psymtab *
-xcoff_start_psymtab (struct objfile *objfile,
+xcoff_start_psymtab (psymtab_storage *partial_symtabs,
+		     struct objfile *objfile,
 		     const char *filename, int first_symnum)
 {
   /* We fill in textlow later.  */
-  legacy_psymtab *result = new legacy_psymtab (filename, objfile, 0);
+  legacy_psymtab *result = new legacy_psymtab (filename, partial_symtabs,
+					       objfile, 0);
 
   result->read_symtab_private =
     XOBNEW (&objfile->objfile_obstack, struct symloc);
@@ -2019,7 +2021,7 @@ xcoff_end_psymtab (struct objfile *objfile, psymtab_storage *partial_symtabs,
   for (i = 0; i < num_includes; i++)
     {
       legacy_psymtab *subpst =
-	new legacy_psymtab (include_list[i], objfile);
+	new legacy_psymtab (include_list[i], partial_symtabs, objfile);
 
       subpst->read_symtab_private = XOBNEW (&objfile->objfile_obstack, symloc);
       ((struct symloc *) subpst->read_symtab_private)->first_symnum = 0;
@@ -2243,7 +2245,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 			    /* Give all psymtabs for this source file the same
 			       name.  */
 			    pst = xcoff_start_psymtab
-			      (objfile,
+			      (partial_symtabs, objfile,
 			       filestring,
 			       symnum_before);
 			  }
@@ -2426,7 +2428,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 	    else
 	      filestring = namestring;
 
-	    pst = xcoff_start_psymtab (objfile,
+	    pst = xcoff_start_psymtab (partial_symtabs, objfile,
 				       filestring,
 				       symnum_before);
 	    last_csect_name = NULL;
@@ -2585,7 +2587,8 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 				  SECT_OFF_DATA (objfile),
 				  psymbol_placement::STATIC,
 				  symbol.n_value,
-				  psymtab_language, objfile);
+				  psymtab_language,
+				  partial_symtabs, objfile);
 		continue;
 
 	      case 'G':
@@ -2597,7 +2600,8 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 				  SECT_OFF_DATA (objfile),
 				  psymbol_placement::GLOBAL,
 				  symbol.n_value,
-				  psymtab_language, objfile);
+				  psymtab_language,
+				  partial_symtabs, objfile);
 		continue;
 
 	      case 'T':
@@ -2615,7 +2619,8 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 							p - namestring),
 				      true, STRUCT_DOMAIN, LOC_TYPEDEF, -1,
 				      psymbol_placement::STATIC,
-				      0, psymtab_language, objfile);
+				      0, psymtab_language,
+				      partial_symtabs, objfile);
 		    if (p[2] == 't')
 		      {
 			/* Also a typedef with the same name.  */
@@ -2623,7 +2628,8 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 							    p - namestring),
 					  true, VAR_DOMAIN, LOC_TYPEDEF, -1,
 					  psymbol_placement::STATIC,
-					  0, psymtab_language, objfile);
+					  0, psymtab_language,
+					  partial_symtabs, objfile);
 			p += 1;
 		      }
 		  }
@@ -2636,7 +2642,8 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 							p - namestring),
 				      true, VAR_DOMAIN, LOC_TYPEDEF, -1,
 				      psymbol_placement::STATIC,
-				      0, psymtab_language, objfile);
+				      0, psymtab_language,
+				      partial_symtabs, objfile);
 		  }
 	      check_enum:
 		/* If this is an enumerated type, we need to
@@ -2698,7 +2705,8 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 			pst->add_psymbol (gdb::string_view (p, q - p), true,
 					  VAR_DOMAIN, LOC_CONST, -1,
 					  psymbol_placement::STATIC,
-					  0, psymtab_language, objfile);
+					  0, psymtab_language,
+					  partial_symtabs, objfile);
 			/* Point past the name.  */
 			p = q;
 			/* Skip over the value.  */
@@ -2717,7 +2725,8 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 						    p - namestring),
 				  true, VAR_DOMAIN, LOC_CONST, -1,
 				  psymbol_placement::STATIC,
-				  0, psymtab_language, objfile);
+				  0, psymtab_language,
+				  partial_symtabs, objfile);
 		continue;
 
 	      case 'f':
@@ -2737,7 +2746,8 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 				  SECT_OFF_TEXT (objfile),
 				  psymbol_placement::STATIC,
 				  symbol.n_value,
-				  psymtab_language, objfile);
+				  psymtab_language,
+				  partial_symtabs, objfile);
 		continue;
 
 		/* Global functions were ignored here, but now they
@@ -2768,7 +2778,8 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 				  SECT_OFF_TEXT (objfile),
 				  psymbol_placement::GLOBAL,
 				  symbol.n_value,
-				  psymtab_language, objfile);
+				  psymtab_language,
+				  partial_symtabs, objfile);
 		continue;
 
 		/* Two things show up here (hopefully); static symbols of
-- 
2.26.2


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 22/26] Remove last objfile partial_symtab references from psymtab.c
  2021-02-28 20:37 [PATCH 00/26] Allow multiple "partial" symtab readers per objfile Tom Tromey
                   ` (20 preceding siblings ...)
  2021-02-28 20:37 ` [PATCH 21/26] Add partial_symtabs parameter to psymtab construction functions Tom Tromey
@ 2021-02-28 20:37 ` Tom Tromey
  2021-02-28 20:38 ` [PATCH 23/26] Change count_psyms to be a method on psymbol_functions Tom Tromey
                   ` (4 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: Tom Tromey @ 2021-02-28 20:37 UTC (permalink / raw)
  To: gdb-patches

This removes the last references to the partial_symtab via the objfile
from psymtab.c.  require_partial_symbols is now a method on
psymbol_functions, and maintenance_print_psymbols is changed to use
dynamic_cast to verify that it is examining partial symbols.

gdb/ChangeLog
2021-02-28  Tom Tromey  <tom@tromey.com>

	* psymtab.c (psymbol_functions::require_partial_symbols): Rename.
	(psymbol_functions::find_pc_sect_psymtab): Rename.
	(psymbol_functions::find_pc_sect_compunit_symtab)
	(maintenance_print_psymbols, maintenance_check_psymtabs): Update.
	* psympriv.h (struct psymbol_functions) <require_partial_symbols>:
	Declare new method.
	<get_partial_symtabs, find_pc_sect_psymtab>: Likewise.
---
 gdb/ChangeLog  |  10 +++
 gdb/psympriv.h |  23 ++++++
 gdb/psymtab.c  | 210 ++++++++++++++++++++++++++-----------------------
 3 files changed, 143 insertions(+), 100 deletions(-)

diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index 8717bd259e1..85651f522d2 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -559,6 +559,18 @@ struct psymbol_functions : public quick_symbol_functions
     m_psymbol_map.clear ();
   }
 
+  /* Ensure the partial symbols for OBJFILE have been loaded.  Return
+     a range adapter for the psymtabs.  */
+  psymtab_storage::partial_symtab_range require_partial_symbols
+       (struct objfile *objfile);
+
+  /* Return the partial symbol storage associated with this
+     object.  */
+  const std::shared_ptr<psymtab_storage> &get_partial_symtabs () const
+  {
+    return m_partial_symtabs;
+  }
+
   /* Replace the partial symbol table storage in this object with
      SYMS.  */
   void set_partial_symtabs (const std::shared_ptr<psymtab_storage> &syms)
@@ -566,6 +578,17 @@ struct psymbol_functions : public quick_symbol_functions
     m_partial_symtabs = syms;
   }
 
+  /* Find which partial symtab contains PC and SECTION.  Return NULL if
+     none.  We return the psymtab that contains a symbol whose address
+     exactly matches PC, or, if we cannot find an exact match, the
+     psymtab that contains a symbol whose address is closest to PC.  */
+
+  struct partial_symtab *find_pc_sect_psymtab
+       (struct objfile *objfile,
+	CORE_ADDR pc,
+	struct obj_section *section,
+	struct bound_minimal_symbol msymbol);
+
 private:
 
   void fill_psymbol_map (struct objfile *objfile,
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index e662ba16cd6..b2f929912ea 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -80,11 +80,11 @@ psymtab_storage::install_psymtab (partial_symtab *pst)
    returns a range adapter suitable for iterating over the psymtabs of
    OBJFILE.  */
 
-static psymtab_storage::partial_symtab_range
-require_partial_symbols (struct objfile *objfile)
+psymtab_storage::partial_symtab_range
+psymbol_functions::require_partial_symbols (struct objfile *objfile)
 {
   objfile->require_partial_symbols (true);
-  return objfile->psymtabs ();
+  return m_partial_symtabs->range ();
 }
 
 /* Helper function for psym_map_symtabs_matching_filename that
@@ -255,17 +255,13 @@ find_pc_sect_psymtab_closer (struct objfile *objfile,
   return best_pst;
 }
 
-/* Find which partial symtab contains PC and SECTION.  Return NULL if
-   none.  We return the psymtab that contains a symbol whose address
-   exactly matches PC, or, if we cannot find an exact match, the
-   psymtab that contains a symbol whose address is closest to PC.  */
+/* See psympriv.h.  */
 
-static struct partial_symtab *
-find_pc_sect_psymtab (struct objfile *objfile,
-		      psymtab_storage *partial_symtabs,
-		      CORE_ADDR pc,
-		      struct obj_section *section,
-		      struct bound_minimal_symbol msymbol)
+struct partial_symtab *
+psymbol_functions::find_pc_sect_psymtab (struct objfile *objfile,
+					 CORE_ADDR pc,
+					 struct obj_section *section,
+					 struct bound_minimal_symbol msymbol)
 {
   /* Try just the PSYMTABS_ADDRMAP mapping first as it has better
      granularity than the later used TEXTLOW/TEXTHIGH one.  However, we need
@@ -279,14 +275,14 @@ find_pc_sect_psymtab (struct objfile *objfile,
      partial symtabs then we will end up returning a pointer to an object
      that is not a partial_symtab, which doesn't end well.  */
 
-  if (partial_symtabs->psymtabs != NULL
-      && partial_symtabs->psymtabs_addrmap != NULL)
+  if (m_partial_symtabs->psymtabs != NULL
+      && m_partial_symtabs->psymtabs_addrmap != NULL)
     {
       CORE_ADDR baseaddr = objfile->text_section_offset ();
 
       struct partial_symtab *pst
 	= ((struct partial_symtab *)
-	   addrmap_find (partial_symtabs->psymtabs_addrmap,
+	   addrmap_find (m_partial_symtabs->psymtabs_addrmap,
 			 pc - baseaddr));
       if (pst != NULL)
 	{
@@ -356,7 +352,6 @@ psymbol_functions::find_pc_sect_compunit_symtab
       int warn_if_readin)
 {
   struct partial_symtab *ps = find_pc_sect_psymtab (objfile,
-						    m_partial_symtabs.get (),
 						    pc, section,
 						    msymbol);
   if (ps != NULL)
@@ -1815,7 +1810,12 @@ maintenance_print_psymbols (const char *args, int from_tty)
       if (!print_for_objfile)
 	continue;
 
-      psymtab_storage *partial_symtabs = objfile->partial_symtabs.get ();
+      psymbol_functions *psf
+	= dynamic_cast<psymbol_functions *> (objfile->qf.get ());
+      if (psf == nullptr)
+	continue;
+
+      psymtab_storage *partial_symtabs = psf->get_partial_symtabs ().get ();
 
       if (address_arg != NULL)
 	{
@@ -1824,8 +1824,7 @@ maintenance_print_psymbols (const char *args, int from_tty)
 	  /* We don't assume each pc has a unique objfile (this is for
 	     debugging).  */
 	  struct partial_symtab *ps
-	    = find_pc_sect_psymtab (objfile, partial_symtabs, pc,
-				    section, msymbol);
+	    = psf->find_pc_sect_psymtab (objfile, pc, section, msymbol);
 	  if (ps != NULL)
 	    {
 	      if (!printed_objfile_header)
@@ -1841,7 +1840,7 @@ maintenance_print_psymbols (const char *args, int from_tty)
 	}
       else
 	{
-	  for (partial_symtab *ps : require_partial_symbols (objfile))
+	  for (partial_symtab *ps : psf->require_partial_symbols (objfile))
 	    {
 	      int print_for_source = 0;
 
@@ -1905,7 +1904,11 @@ maintenance_info_psymtabs (const char *regexp, int from_tty)
 	   actually find a symtab whose name matches.  */
 	int printed_objfile_start = 0;
 
-	for (partial_symtab *psymtab : require_partial_symbols (objfile))
+	psymbol_functions *psf
+	  = dynamic_cast<psymbol_functions *> (objfile->qf.get ());
+	if (psf == nullptr)
+	  continue;
+	for (partial_symtab *psymtab : psf->require_partial_symbols (objfile))
 	  {
 	    QUIT;
 
@@ -2005,89 +2008,96 @@ maintenance_check_psymtabs (const char *ignore, int from_tty)
   const struct block *b;
 
   for (objfile *objfile : current_program_space->objfiles ())
-    for (partial_symtab *ps : require_partial_symbols (objfile))
-      {
-	struct gdbarch *gdbarch = objfile->arch ();
+    {
+      psymbol_functions *psf
+	= dynamic_cast<psymbol_functions *> (objfile->qf.get ());
+      if (psf == nullptr)
+	continue;
 
-	/* We don't call psymtab_to_symtab here because that may cause symtab
-	   expansion.  When debugging a problem it helps if checkers leave
-	   things unchanged.  */
-	cust = ps->get_compunit_symtab (objfile);
+      for (partial_symtab *ps : psf->require_partial_symbols (objfile))
+	{
+	  struct gdbarch *gdbarch = objfile->arch ();
 
-	/* First do some checks that don't require the associated symtab.  */
-	if (ps->text_high (objfile) < ps->text_low (objfile))
-	  {
-	    printf_filtered ("Psymtab ");
-	    puts_filtered (ps->filename);
-	    printf_filtered (" covers bad range ");
-	    fputs_filtered (paddress (gdbarch, ps->text_low (objfile)),
-			    gdb_stdout);
-	    printf_filtered (" - ");
-	    fputs_filtered (paddress (gdbarch, ps->text_high (objfile)),
-			    gdb_stdout);
-	    printf_filtered ("\n");
-	    continue;
-	  }
+	  /* We don't call psymtab_to_symtab here because that may cause symtab
+	     expansion.  When debugging a problem it helps if checkers leave
+	     things unchanged.  */
+	  cust = ps->get_compunit_symtab (objfile);
 
-	/* Now do checks requiring the associated symtab.  */
-	if (cust == NULL)
-	  continue;
-	bv = COMPUNIT_BLOCKVECTOR (cust);
-	b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
-	for (partial_symbol *psym : ps->static_psymbols)
-	  {
-	    /* Skip symbols for inlined functions without address.  These may
-	       or may not have a match in the full symtab.  */
-	    if (psym->aclass == LOC_BLOCK
-		&& psym->ginfo.value.address == 0)
+	  /* First do some checks that don't require the associated symtab.  */
+	  if (ps->text_high (objfile) < ps->text_low (objfile))
+	    {
+	      printf_filtered ("Psymtab ");
+	      puts_filtered (ps->filename);
+	      printf_filtered (" covers bad range ");
+	      fputs_filtered (paddress (gdbarch, ps->text_low (objfile)),
+			      gdb_stdout);
+	      printf_filtered (" - ");
+	      fputs_filtered (paddress (gdbarch, ps->text_high (objfile)),
+			      gdb_stdout);
+	      printf_filtered ("\n");
 	      continue;
+	    }
 
-	    sym = block_lookup_symbol (b, psym->ginfo.search_name (),
-				       symbol_name_match_type::SEARCH_NAME,
-				       psym->domain);
-	    if (!sym)
-	      {
-		printf_filtered ("Static symbol `");
-		puts_filtered (psym->ginfo.linkage_name ());
-		printf_filtered ("' only found in ");
-		puts_filtered (ps->filename);
-		printf_filtered (" psymtab\n");
-	      }
-	  }
-	b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
-	for (partial_symbol *psym : ps->global_psymbols)
-	  {
-	    sym = block_lookup_symbol (b, psym->ginfo.search_name (),
-				       symbol_name_match_type::SEARCH_NAME,
-				       psym->domain);
-	    if (!sym)
-	      {
-		printf_filtered ("Global symbol `");
-		puts_filtered (psym->ginfo.linkage_name ());
-		printf_filtered ("' only found in ");
-		puts_filtered (ps->filename);
-		printf_filtered (" psymtab\n");
-	      }
-	  }
-	if (ps->raw_text_high () != 0
-	    && (ps->text_low (objfile) < BLOCK_START (b)
-		|| ps->text_high (objfile) > BLOCK_END (b)))
-	  {
-	    printf_filtered ("Psymtab ");
-	    puts_filtered (ps->filename);
-	    printf_filtered (" covers ");
-	    fputs_filtered (paddress (gdbarch, ps->text_low (objfile)),
-			    gdb_stdout);
-	    printf_filtered (" - ");
-	    fputs_filtered (paddress (gdbarch, ps->text_high (objfile)),
-			    gdb_stdout);
-	    printf_filtered (" but symtab covers only ");
-	    fputs_filtered (paddress (gdbarch, BLOCK_START (b)), gdb_stdout);
-	    printf_filtered (" - ");
-	    fputs_filtered (paddress (gdbarch, BLOCK_END (b)), gdb_stdout);
-	    printf_filtered ("\n");
-	  }
-      }
+	  /* Now do checks requiring the associated symtab.  */
+	  if (cust == NULL)
+	    continue;
+	  bv = COMPUNIT_BLOCKVECTOR (cust);
+	  b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
+	  for (partial_symbol *psym : ps->static_psymbols)
+	    {
+	      /* Skip symbols for inlined functions without address.  These may
+		 or may not have a match in the full symtab.  */
+	      if (psym->aclass == LOC_BLOCK
+		  && psym->ginfo.value.address == 0)
+		continue;
+
+	      sym = block_lookup_symbol (b, psym->ginfo.search_name (),
+					 symbol_name_match_type::SEARCH_NAME,
+					 psym->domain);
+	      if (!sym)
+		{
+		  printf_filtered ("Static symbol `");
+		  puts_filtered (psym->ginfo.linkage_name ());
+		  printf_filtered ("' only found in ");
+		  puts_filtered (ps->filename);
+		  printf_filtered (" psymtab\n");
+		}
+	    }
+	  b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
+	  for (partial_symbol *psym : ps->global_psymbols)
+	    {
+	      sym = block_lookup_symbol (b, psym->ginfo.search_name (),
+					 symbol_name_match_type::SEARCH_NAME,
+					 psym->domain);
+	      if (!sym)
+		{
+		  printf_filtered ("Global symbol `");
+		  puts_filtered (psym->ginfo.linkage_name ());
+		  printf_filtered ("' only found in ");
+		  puts_filtered (ps->filename);
+		  printf_filtered (" psymtab\n");
+		}
+	    }
+	  if (ps->raw_text_high () != 0
+	      && (ps->text_low (objfile) < BLOCK_START (b)
+		  || ps->text_high (objfile) > BLOCK_END (b)))
+	    {
+	      printf_filtered ("Psymtab ");
+	      puts_filtered (ps->filename);
+	      printf_filtered (" covers ");
+	      fputs_filtered (paddress (gdbarch, ps->text_low (objfile)),
+			      gdb_stdout);
+	      printf_filtered (" - ");
+	      fputs_filtered (paddress (gdbarch, ps->text_high (objfile)),
+			      gdb_stdout);
+	      printf_filtered (" but symtab covers only ");
+	      fputs_filtered (paddress (gdbarch, BLOCK_START (b)), gdb_stdout);
+	      printf_filtered (" - ");
+	      fputs_filtered (paddress (gdbarch, BLOCK_END (b)), gdb_stdout);
+	      printf_filtered ("\n");
+	    }
+	}
+    }
 }
 
 void _initialize_psymtab ();
-- 
2.26.2


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 23/26] Change count_psyms to be a method on psymbol_functions
  2021-02-28 20:37 [PATCH 00/26] Allow multiple "partial" symtab readers per objfile Tom Tromey
                   ` (21 preceding siblings ...)
  2021-02-28 20:37 ` [PATCH 22/26] Remove last objfile partial_symtab references from psymtab.c Tom Tromey
@ 2021-02-28 20:38 ` Tom Tromey
  2021-02-28 20:38 ` [PATCH 24/26] Remove objfile::psymtabs Tom Tromey
                   ` (3 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: Tom Tromey @ 2021-02-28 20:38 UTC (permalink / raw)
  To: gdb-patches

This removes a use of objfile->psymtabs by changing count_psyms to be
a method on psymbol_functions.

gdb/ChangeLog
2021-02-28  Tom Tromey  <tom@tromey.com>

	* psymtab.c (psymbol_functions::count_psyms): Rename.
	(psymbol_functions::print_stats): Update.
	* psympriv.h (struct psymbol_functions) <count_psyms>: Declare
	method.
---
 gdb/ChangeLog  | 7 +++++++
 gdb/psympriv.h | 3 +++
 gdb/psymtab.c  | 8 ++++----
 3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index 85651f522d2..b6139111b6e 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -591,6 +591,9 @@ struct psymbol_functions : public quick_symbol_functions
 
 private:
 
+  /* Count the number of partial symbols in *THIS.  */
+  int count_psyms ();
+
   void fill_psymbol_map (struct objfile *objfile,
 			 struct partial_symtab *psymtab,
 			 std::set<CORE_ADDR> *seen_addrs,
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index b2f929912ea..3f3b5596864 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -962,11 +962,11 @@ dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
 
 /* Count the number of partial symbols in OBJFILE.  */
 
-static int
-count_psyms (struct objfile *objfile)
+int
+psymbol_functions::count_psyms ()
 {
   int count = 0;
-  for (partial_symtab *pst : objfile->psymtabs ())
+  for (partial_symtab *pst : m_partial_symtabs->range ())
     {
       count += pst->global_psymbols.size ();
       count += pst->static_psymbols.size ();
@@ -984,7 +984,7 @@ psymbol_functions::print_stats (struct objfile *objfile, bool print_bcache)
 
   if (!print_bcache)
     {
-      int n_psyms = count_psyms (objfile);
+      int n_psyms = count_psyms ();
       if (n_psyms > 0)
 	printf_filtered (_("  Number of \"partial\" symbols read: %d\n"),
 			 n_psyms);
-- 
2.26.2


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 24/26] Remove objfile::psymtabs
  2021-02-28 20:37 [PATCH 00/26] Allow multiple "partial" symtab readers per objfile Tom Tromey
                   ` (22 preceding siblings ...)
  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 ` Tom Tromey
  2021-02-28 20:38 ` [PATCH 25/26] Switch objfile to hold a list of psymbol readers Tom Tromey
                   ` (2 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: Tom Tromey @ 2021-02-28 20:38 UTC (permalink / raw)
  To: gdb-patches

The method objfile::psymtabs is no longer used and can be removed.

gdb/ChangeLog
2021-02-28  Tom Tromey  <tom@tromey.com>

	* objfiles.h (struct objfile) <psymtabs>: Remove method.
---
 gdb/ChangeLog  | 4 ++++
 gdb/objfiles.h | 8 --------
 2 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index c51217be6f0..cb441b117df 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -446,14 +446,6 @@ struct objfile
 
   DISABLE_COPY_AND_ASSIGN (objfile);
 
-  /* A range adapter that makes it possible to iterate over all
-     psymtabs in one objfile.  */
-
-  psymtab_storage::partial_symtab_range psymtabs ()
-  {
-    return partial_symtabs->range ();
-  }
-
   /* Reset the storage for the partial symbol tables.  */
 
   void reset_psymtabs ()
-- 
2.26.2


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 25/26] Switch objfile to hold a list of psymbol readers
  2021-02-28 20:37 [PATCH 00/26] Allow multiple "partial" symtab readers per objfile Tom Tromey
                   ` (23 preceding siblings ...)
  2021-02-28 20:38 ` [PATCH 24/26] Remove objfile::psymtabs Tom Tromey
@ 2021-02-28 20:38 ` Tom Tromey
  2021-02-28 20:38 ` [PATCH 26/26] Allow multiple partial symbol readers per objfile Tom Tromey
  2021-03-20 23:33 ` [PATCH 00/26] Allow multiple "partial" symtab " Tom Tromey
  26 siblings, 0 replies; 30+ messages in thread
From: Tom Tromey @ 2021-02-28 20:38 UTC (permalink / raw)
  To: gdb-patches

This changes objfile::qf to be a forward_list, and then updates all
the uses to iterate over the list.  Note that there is still only ever
a single element in the list; this is handled by clearing the list
whenever an object is added.

gdb/ChangeLog
2021-02-28  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (dwarf2_build_psymtabs): Update.
	* symfile.c (syms_from_objfile_1, reread_symbols): Update.
	* symfile-debug.c (objfile::has_partial_symbols)
	(objfile::find_last_source_symtab)
	(objfile::forget_cached_source_info)
	(objfile::map_symtabs_matching_filename, objfile::lookup_symbol)
	(objfile::print_stats, objfile::dump)
	(objfile::expand_symtabs_for_function)
	(objfile::expand_all_symtabs)
	(objfile::expand_symtabs_with_fullname)
	(objfile::map_matching_symbols)
	(objfile::expand_symtabs_matching)
	(objfile::find_pc_sect_compunit_symtab)
	(objfile::map_symbol_filenames)
	(objfile::find_compunit_symtab_by_address)
	(objfile::lookup_global_symbol_language)
	(objfile::require_partial_symbols): Update.
	* psymtab.c (maintenance_print_psymbols)
	(maintenance_info_psymtabs, maintenance_check_psymtabs): Update.
	* objfiles.h (struct objfile) <qf>: Now a forward_list.
	* objfiles.c (objfile_relocate1): Update.
	* elfread.c (elf_symfile_read): Update.
---
 gdb/ChangeLog       |  25 +++
 gdb/dwarf2/read.c   |   2 +-
 gdb/elfread.c       |   9 +-
 gdb/objfiles.c      |   4 +-
 gdb/objfiles.h      |   3 +-
 gdb/psymtab.c       | 412 +++++++++++++++++++++++---------------------
 gdb/symfile-debug.c | 137 +++++++++------
 gdb/symfile.c       |   7 +-
 8 files changed, 337 insertions(+), 262 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 183876bb5b7..570df071bf7 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -6361,7 +6361,7 @@ dwarf2_build_psymtabs (struct objfile *objfile)
       /* This is a temporary hack to ensure that the objfile and 'qf'
 	 psymtabs are identical.  */
       psymbol_functions *psf
-	= dynamic_cast<psymbol_functions *> (objfile->qf.get ());
+	= dynamic_cast<psymbol_functions *> (objfile->qf.front ().get ());
       gdb_assert (psf != nullptr);
       psf->set_partial_symtabs (per_bfd->partial_symtabs);
       per_objfile->resize_symtabs ();
diff --git a/gdb/elfread.c b/gdb/elfread.c
index 157a0717828..1cf9b2addc4 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -1287,10 +1287,12 @@ elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
 	  switch (index_kind)
 	    {
 	    case dw_index_kind::GDB_INDEX:
-	      objfile->qf = make_dwarf_gdb_index ();
+	      objfile->qf.clear ();
+	      objfile->qf.push_front (make_dwarf_gdb_index ());
 	      break;
 	    case dw_index_kind::DEBUG_NAMES:
-	      objfile->qf = make_dwarf_debug_names ();
+	      objfile->qf.clear ();
+	      objfile->qf.push_front (make_dwarf_debug_names ());
 	      break;
 	    }
 	}
@@ -1300,7 +1302,8 @@ elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
 	     partial symbols, because OBJF_PSYMTABS_READ has not been
 	     set, and so our lazy reader function will still be called
 	     when needed.  */
-	  objfile->qf.reset
+	  objfile->qf.clear ();
+	  objfile->qf.emplace_front
 	    (new lazy_dwarf_reader (objfile->partial_symtabs));
 	}
     }
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index ca135dd63c3..ed51c31c8b9 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -703,8 +703,8 @@ objfile_relocate1 (struct objfile *objfile,
   }
 
   /* Notify the quick symbol object.  */
-  if (objfile->qf)
-    objfile->qf->relocated ();
+  for (const auto &iter : objfile->qf)
+    iter->relocated ();
 
   /* Relocate isolated symbols.  */
   {
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index cb441b117df..2f566709eb2 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -38,6 +38,7 @@
 #include "gdbsupport/refcounted-object.h"
 #include "jit.h"
 #include "quick-symbol.h"
+#include <forward_list>
 
 struct htab;
 struct objfile_data;
@@ -668,7 +669,7 @@ struct objfile
 
   /* The "quick" (aka partial) symbol functions for this symbol
      reader.  */
-  quick_symbol_functions_up qf;
+  std::forward_list<quick_symbol_functions_up> qf;
 
   /* Per objfile data-pointers required by other GDB modules.  */
 
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 3f3b5596864..785eda04c9e 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -1810,49 +1810,25 @@ maintenance_print_psymbols (const char *args, int from_tty)
       if (!print_for_objfile)
 	continue;
 
-      psymbol_functions *psf
-	= dynamic_cast<psymbol_functions *> (objfile->qf.get ());
-      if (psf == nullptr)
-	continue;
-
-      psymtab_storage *partial_symtabs = psf->get_partial_symtabs ().get ();
-
-      if (address_arg != NULL)
+      for (const auto &iter : objfile->qf)
 	{
-	  struct bound_minimal_symbol msymbol = { NULL, NULL };
+	  psymbol_functions *psf
+	    = dynamic_cast<psymbol_functions *> (iter.get ());
+	  if (psf == nullptr)
+	    continue;
 
-	  /* We don't assume each pc has a unique objfile (this is for
-	     debugging).  */
-	  struct partial_symtab *ps
-	    = psf->find_pc_sect_psymtab (objfile, pc, section, msymbol);
-	  if (ps != NULL)
-	    {
-	      if (!printed_objfile_header)
-		{
-		  outfile->printf ("\nPartial symtabs for objfile %s\n",
-				  objfile_name (objfile));
-		  printed_objfile_header = 1;
-		}
-	      dump_psymtab (objfile, ps, outfile);
-	      dump_psymtab_addrmap (objfile, partial_symtabs, ps, outfile);
-	      found = 1;
-	    }
-	}
-      else
-	{
-	  for (partial_symtab *ps : psf->require_partial_symbols (objfile))
+	  psymtab_storage *partial_symtabs
+	    = psf->get_partial_symtabs ().get ();
+
+	  if (address_arg != NULL)
 	    {
-	      int print_for_source = 0;
+	      struct bound_minimal_symbol msymbol = { NULL, NULL };
 
-	      QUIT;
-	      if (source_arg != NULL)
-		{
-		  print_for_source
-		    = compare_filenames_for_search (ps->filename, source_arg);
-		  found = 1;
-		}
-	      if (source_arg == NULL
-		  || print_for_source)
+	      /* We don't assume each pc has a unique objfile (this is for
+		 debugging).  */
+	      struct partial_symtab *ps
+		= psf->find_pc_sect_psymtab (objfile, pc, section, msymbol);
+	      if (ps != NULL)
 		{
 		  if (!printed_objfile_header)
 		    {
@@ -1861,20 +1837,48 @@ maintenance_print_psymbols (const char *args, int from_tty)
 		      printed_objfile_header = 1;
 		    }
 		  dump_psymtab (objfile, ps, outfile);
-		  dump_psymtab_addrmap (objfile, partial_symtabs, ps,
-					outfile);
+		  dump_psymtab_addrmap (objfile, partial_symtabs, ps, outfile);
+		  found = 1;
+		}
+	    }
+	  else
+	    {
+	      for (partial_symtab *ps : psf->require_partial_symbols (objfile))
+		{
+		  int print_for_source = 0;
+
+		  QUIT;
+		  if (source_arg != NULL)
+		    {
+		      print_for_source
+			= compare_filenames_for_search (ps->filename, source_arg);
+		      found = 1;
+		    }
+		  if (source_arg == NULL
+		      || print_for_source)
+		    {
+		      if (!printed_objfile_header)
+			{
+			  outfile->printf ("\nPartial symtabs for objfile %s\n",
+					   objfile_name (objfile));
+			  printed_objfile_header = 1;
+			}
+		      dump_psymtab (objfile, ps, outfile);
+		      dump_psymtab_addrmap (objfile, partial_symtabs, ps,
+					    outfile);
+		    }
 		}
 	    }
-	}
 
-      /* If we're printing all the objfile's symbols dump the full addrmap.  */
+	  /* If we're printing all the objfile's symbols dump the full addrmap.  */
 
-      if (address_arg == NULL
-	  && source_arg == NULL
-	  && partial_symtabs->psymtabs_addrmap != NULL)
-	{
-	  outfile->puts ("\n");
-	  dump_psymtab_addrmap (objfile, partial_symtabs, NULL, outfile);
+	  if (address_arg == NULL
+	      && source_arg == NULL
+	      && partial_symtabs->psymtabs_addrmap != NULL)
+	    {
+	      outfile->puts ("\n");
+	      dump_psymtab_addrmap (objfile, partial_symtabs, NULL, outfile);
+	    }
 	}
     }
 
@@ -1904,91 +1908,94 @@ maintenance_info_psymtabs (const char *regexp, int from_tty)
 	   actually find a symtab whose name matches.  */
 	int printed_objfile_start = 0;
 
-	psymbol_functions *psf
-	  = dynamic_cast<psymbol_functions *> (objfile->qf.get ());
-	if (psf == nullptr)
-	  continue;
-	for (partial_symtab *psymtab : psf->require_partial_symbols (objfile))
+	for (const auto &iter : objfile->qf)
 	  {
-	    QUIT;
-
-	    if (! regexp
-		|| re_exec (psymtab->filename))
+	    psymbol_functions *psf
+	      = dynamic_cast<psymbol_functions *> (iter.get ());
+	    if (psf == nullptr)
+	      continue;
+	    for (partial_symtab *psymtab : psf->require_partial_symbols (objfile))
 	      {
-		if (! printed_objfile_start)
-		  {
-		    printf_filtered ("{ objfile %s ", objfile_name (objfile));
-		    wrap_here ("  ");
-		    printf_filtered ("((struct objfile *) %s)\n",
-				     host_address_to_string (objfile));
-		    printed_objfile_start = 1;
-		  }
+		QUIT;
 
-		printf_filtered ("  { psymtab %s ", psymtab->filename);
-		wrap_here ("    ");
-		printf_filtered ("((struct partial_symtab *) %s)\n",
-				 host_address_to_string (psymtab));
-
-		printf_filtered ("    readin %s\n",
-				 psymtab->readin_p (objfile) ? "yes" : "no");
-		printf_filtered ("    fullname %s\n",
-				 psymtab->fullname
-				 ? psymtab->fullname : "(null)");
-		printf_filtered ("    text addresses ");
-		fputs_filtered (paddress (gdbarch,
-					  psymtab->text_low (objfile)),
-				gdb_stdout);
-		printf_filtered (" -- ");
-		fputs_filtered (paddress (gdbarch,
-					  psymtab->text_high (objfile)),
-				gdb_stdout);
-		printf_filtered ("\n");
-		printf_filtered ("    psymtabs_addrmap_supported %s\n",
-				 (psymtab->psymtabs_addrmap_supported
-				  ? "yes" : "no"));
-		printf_filtered ("    globals ");
-		if (!psymtab->global_psymbols.empty ())
-		  printf_filtered
-		    ("(* (struct partial_symbol **) %s @ %d)\n",
-		     host_address_to_string (psymtab->global_psymbols.data ()),
-		     (int) psymtab->global_psymbols.size ());
-		else
-		  printf_filtered ("(none)\n");
-		printf_filtered ("    statics ");
-		if (!psymtab->static_psymbols.empty ())
-		  printf_filtered
-		    ("(* (struct partial_symbol **) %s @ %d)\n",
-		     host_address_to_string (psymtab->static_psymbols.data ()),
-		     (int) psymtab->static_psymbols.size ());
-		else
-		  printf_filtered ("(none)\n");
-		if (psymtab->user)
-		  printf_filtered ("    user %s "
-				   "((struct partial_symtab *) %s)\n",
-				   psymtab->user->filename,
-				   host_address_to_string (psymtab->user));
-		printf_filtered ("    dependencies ");
-		if (psymtab->number_of_dependencies)
+		if (! regexp
+		    || re_exec (psymtab->filename))
 		  {
-		    int i;
+		    if (! printed_objfile_start)
+		      {
+			printf_filtered ("{ objfile %s ", objfile_name (objfile));
+			wrap_here ("  ");
+			printf_filtered ("((struct objfile *) %s)\n",
+					 host_address_to_string (objfile));
+			printed_objfile_start = 1;
+		      }
 
-		    printf_filtered ("{\n");
-		    for (i = 0; i < psymtab->number_of_dependencies; i++)
+		    printf_filtered ("  { psymtab %s ", psymtab->filename);
+		    wrap_here ("    ");
+		    printf_filtered ("((struct partial_symtab *) %s)\n",
+				     host_address_to_string (psymtab));
+
+		    printf_filtered ("    readin %s\n",
+				     psymtab->readin_p (objfile) ? "yes" : "no");
+		    printf_filtered ("    fullname %s\n",
+				     psymtab->fullname
+				     ? psymtab->fullname : "(null)");
+		    printf_filtered ("    text addresses ");
+		    fputs_filtered (paddress (gdbarch,
+					      psymtab->text_low (objfile)),
+				    gdb_stdout);
+		    printf_filtered (" -- ");
+		    fputs_filtered (paddress (gdbarch,
+					      psymtab->text_high (objfile)),
+				    gdb_stdout);
+		    printf_filtered ("\n");
+		    printf_filtered ("    psymtabs_addrmap_supported %s\n",
+				     (psymtab->psymtabs_addrmap_supported
+				      ? "yes" : "no"));
+		    printf_filtered ("    globals ");
+		    if (!psymtab->global_psymbols.empty ())
+		      printf_filtered
+			("(* (struct partial_symbol **) %s @ %d)\n",
+			 host_address_to_string (psymtab->global_psymbols.data ()),
+			 (int) psymtab->global_psymbols.size ());
+		    else
+		      printf_filtered ("(none)\n");
+		    printf_filtered ("    statics ");
+		    if (!psymtab->static_psymbols.empty ())
+		      printf_filtered
+			("(* (struct partial_symbol **) %s @ %d)\n",
+			 host_address_to_string (psymtab->static_psymbols.data ()),
+			 (int) psymtab->static_psymbols.size ());
+		    else
+		      printf_filtered ("(none)\n");
+		    if (psymtab->user)
+		      printf_filtered ("    user %s "
+				       "((struct partial_symtab *) %s)\n",
+				       psymtab->user->filename,
+				       host_address_to_string (psymtab->user));
+		    printf_filtered ("    dependencies ");
+		    if (psymtab->number_of_dependencies)
 		      {
-			struct partial_symtab *dep = psymtab->dependencies[i];
-
-			/* Note the string concatenation there --- no
-			   comma.  */
-			printf_filtered ("      psymtab %s "
-					 "((struct partial_symtab *) %s)\n",
-					 dep->filename,
-					 host_address_to_string (dep));
+			int i;
+
+			printf_filtered ("{\n");
+			for (i = 0; i < psymtab->number_of_dependencies; i++)
+			  {
+			    struct partial_symtab *dep = psymtab->dependencies[i];
+
+			    /* Note the string concatenation there --- no
+			       comma.  */
+			    printf_filtered ("      psymtab %s "
+					     "((struct partial_symtab *) %s)\n",
+					     dep->filename,
+					     host_address_to_string (dep));
+			  }
+			printf_filtered ("    }\n");
 		      }
-		    printf_filtered ("    }\n");
+		    else
+		      printf_filtered ("(none)\n");
+		    printf_filtered ("  }\n");
 		  }
-		else
-		  printf_filtered ("(none)\n");
-		printf_filtered ("  }\n");
 	      }
 	  }
 
@@ -2009,93 +2016,96 @@ maintenance_check_psymtabs (const char *ignore, int from_tty)
 
   for (objfile *objfile : current_program_space->objfiles ())
     {
-      psymbol_functions *psf
-	= dynamic_cast<psymbol_functions *> (objfile->qf.get ());
-      if (psf == nullptr)
-	continue;
-
-      for (partial_symtab *ps : psf->require_partial_symbols (objfile))
+      for (const auto &iter : objfile->qf)
 	{
-	  struct gdbarch *gdbarch = objfile->arch ();
-
-	  /* We don't call psymtab_to_symtab here because that may cause symtab
-	     expansion.  When debugging a problem it helps if checkers leave
-	     things unchanged.  */
-	  cust = ps->get_compunit_symtab (objfile);
+	  psymbol_functions *psf
+	    = dynamic_cast<psymbol_functions *> (iter.get ());
+	  if (psf == nullptr)
+	    continue;
 
-	  /* First do some checks that don't require the associated symtab.  */
-	  if (ps->text_high (objfile) < ps->text_low (objfile))
+	  for (partial_symtab *ps : psf->require_partial_symbols (objfile))
 	    {
-	      printf_filtered ("Psymtab ");
-	      puts_filtered (ps->filename);
-	      printf_filtered (" covers bad range ");
-	      fputs_filtered (paddress (gdbarch, ps->text_low (objfile)),
-			      gdb_stdout);
-	      printf_filtered (" - ");
-	      fputs_filtered (paddress (gdbarch, ps->text_high (objfile)),
-			      gdb_stdout);
-	      printf_filtered ("\n");
-	      continue;
-	    }
+	      struct gdbarch *gdbarch = objfile->arch ();
 
-	  /* Now do checks requiring the associated symtab.  */
-	  if (cust == NULL)
-	    continue;
-	  bv = COMPUNIT_BLOCKVECTOR (cust);
-	  b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
-	  for (partial_symbol *psym : ps->static_psymbols)
-	    {
-	      /* Skip symbols for inlined functions without address.  These may
-		 or may not have a match in the full symtab.  */
-	      if (psym->aclass == LOC_BLOCK
-		  && psym->ginfo.value.address == 0)
-		continue;
+	      /* We don't call psymtab_to_symtab here because that may cause symtab
+		 expansion.  When debugging a problem it helps if checkers leave
+		 things unchanged.  */
+	      cust = ps->get_compunit_symtab (objfile);
 
-	      sym = block_lookup_symbol (b, psym->ginfo.search_name (),
-					 symbol_name_match_type::SEARCH_NAME,
-					 psym->domain);
-	      if (!sym)
+	      /* First do some checks that don't require the associated symtab.  */
+	      if (ps->text_high (objfile) < ps->text_low (objfile))
 		{
-		  printf_filtered ("Static symbol `");
-		  puts_filtered (psym->ginfo.linkage_name ());
-		  printf_filtered ("' only found in ");
+		  printf_filtered ("Psymtab ");
 		  puts_filtered (ps->filename);
-		  printf_filtered (" psymtab\n");
+		  printf_filtered (" covers bad range ");
+		  fputs_filtered (paddress (gdbarch, ps->text_low (objfile)),
+				  gdb_stdout);
+		  printf_filtered (" - ");
+		  fputs_filtered (paddress (gdbarch, ps->text_high (objfile)),
+				  gdb_stdout);
+		  printf_filtered ("\n");
+		  continue;
 		}
-	    }
-	  b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
-	  for (partial_symbol *psym : ps->global_psymbols)
-	    {
-	      sym = block_lookup_symbol (b, psym->ginfo.search_name (),
-					 symbol_name_match_type::SEARCH_NAME,
-					 psym->domain);
-	      if (!sym)
+
+	      /* Now do checks requiring the associated symtab.  */
+	      if (cust == NULL)
+		continue;
+	      bv = COMPUNIT_BLOCKVECTOR (cust);
+	      b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
+	      for (partial_symbol *psym : ps->static_psymbols)
+		{
+		  /* Skip symbols for inlined functions without address.  These may
+		     or may not have a match in the full symtab.  */
+		  if (psym->aclass == LOC_BLOCK
+		      && psym->ginfo.value.address == 0)
+		    continue;
+
+		  sym = block_lookup_symbol (b, psym->ginfo.search_name (),
+					     symbol_name_match_type::SEARCH_NAME,
+					     psym->domain);
+		  if (!sym)
+		    {
+		      printf_filtered ("Static symbol `");
+		      puts_filtered (psym->ginfo.linkage_name ());
+		      printf_filtered ("' only found in ");
+		      puts_filtered (ps->filename);
+		      printf_filtered (" psymtab\n");
+		    }
+		}
+	      b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
+	      for (partial_symbol *psym : ps->global_psymbols)
+		{
+		  sym = block_lookup_symbol (b, psym->ginfo.search_name (),
+					     symbol_name_match_type::SEARCH_NAME,
+					     psym->domain);
+		  if (!sym)
+		    {
+		      printf_filtered ("Global symbol `");
+		      puts_filtered (psym->ginfo.linkage_name ());
+		      printf_filtered ("' only found in ");
+		      puts_filtered (ps->filename);
+		      printf_filtered (" psymtab\n");
+		    }
+		}
+	      if (ps->raw_text_high () != 0
+		  && (ps->text_low (objfile) < BLOCK_START (b)
+		      || ps->text_high (objfile) > BLOCK_END (b)))
 		{
-		  printf_filtered ("Global symbol `");
-		  puts_filtered (psym->ginfo.linkage_name ());
-		  printf_filtered ("' only found in ");
+		  printf_filtered ("Psymtab ");
 		  puts_filtered (ps->filename);
-		  printf_filtered (" psymtab\n");
+		  printf_filtered (" covers ");
+		  fputs_filtered (paddress (gdbarch, ps->text_low (objfile)),
+				  gdb_stdout);
+		  printf_filtered (" - ");
+		  fputs_filtered (paddress (gdbarch, ps->text_high (objfile)),
+				  gdb_stdout);
+		  printf_filtered (" but symtab covers only ");
+		  fputs_filtered (paddress (gdbarch, BLOCK_START (b)), gdb_stdout);
+		  printf_filtered (" - ");
+		  fputs_filtered (paddress (gdbarch, BLOCK_END (b)), gdb_stdout);
+		  printf_filtered ("\n");
 		}
 	    }
-	  if (ps->raw_text_high () != 0
-	      && (ps->text_low (objfile) < BLOCK_START (b)
-		  || ps->text_high (objfile) > BLOCK_END (b)))
-	    {
-	      printf_filtered ("Psymtab ");
-	      puts_filtered (ps->filename);
-	      printf_filtered (" covers ");
-	      fputs_filtered (paddress (gdbarch, ps->text_low (objfile)),
-			      gdb_stdout);
-	      printf_filtered (" - ");
-	      fputs_filtered (paddress (gdbarch, ps->text_high (objfile)),
-			      gdb_stdout);
-	      printf_filtered (" but symtab covers only ");
-	      fputs_filtered (paddress (gdbarch, BLOCK_START (b)), gdb_stdout);
-	      printf_filtered (" - ");
-	      fputs_filtered (paddress (gdbarch, BLOCK_END (b)), gdb_stdout);
-	      printf_filtered ("\n");
-	    }
 	}
     }
 }
diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index 99974536bf4..3daede88292 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -80,12 +80,16 @@ objfile::has_partial_symbols ()
      them, then that is an indication that they are in fact available.  Without
      this function the symbols may have been already read in but they also may
      not be present in this objfile.  */
-  if ((flags & OBJF_PSYMTABS_READ) == 0
-      && qf != nullptr
-      && qf->can_lazily_read_symbols ())
-    retval = true;
-  else if (qf != nullptr)
-    retval = qf->has_symbols (this);
+  for (const auto &iter : qf)
+    {
+      if ((flags & OBJF_PSYMTABS_READ) == 0
+	  && iter->can_lazily_read_symbols ())
+	retval = true;
+      else
+	retval = iter->has_symbols (this);
+      if (retval)
+	break;
+    }
 
   if (debug_symfile)
     fprintf_filtered (gdb_stdlog, "qf->has_symbols (%s) = %d\n",
@@ -103,8 +107,12 @@ objfile::find_last_source_symtab ()
     fprintf_filtered (gdb_stdlog, "qf->find_last_source_symtab (%s)\n",
 		      objfile_debug_name (this));
 
-  if (qf != nullptr)
-    retval = qf->find_last_source_symtab (this);
+  for (const auto &iter : qf)
+    {
+      retval = iter->find_last_source_symtab (this);
+      if (retval != nullptr)
+	break;
+    }
 
   if (debug_symfile)
     fprintf_filtered (gdb_stdlog, "qf->find_last_source_symtab (...) = %s\n",
@@ -120,8 +128,8 @@ objfile::forget_cached_source_info ()
     fprintf_filtered (gdb_stdlog, "qf->forget_cached_source_info (%s)\n",
 		      objfile_debug_name (this));
 
-  if (qf != nullptr)
-    qf->forget_cached_source_info (this);
+  for (const auto &iter : qf)
+    iter->forget_cached_source_info (this);
 }
 
 bool
@@ -138,9 +146,13 @@ objfile::map_symtabs_matching_filename
 		      host_address_to_string (&callback));
 
   bool retval = false;
-  if (qf != nullptr)
-    retval = (qf->map_symtabs_matching_filename
-	      (this, name, real_path, callback));
+  for (const auto &iter : qf)
+    {
+      retval = (iter->map_symtabs_matching_filename
+		(this, name, real_path, callback));
+      if (retval)
+	break;
+    }
 
   if (debug_symfile)
     fprintf_filtered (gdb_stdlog,
@@ -161,8 +173,12 @@ objfile::lookup_symbol (block_enum kind, const char *name, domain_enum domain)
 		      objfile_debug_name (this), kind, name,
 		      domain_name (domain));
 
-  if (qf != nullptr)
-    retval = qf->lookup_symbol (this, kind, name, domain);
+  for (const auto &iter : qf)
+    {
+      retval = iter->lookup_symbol (this, kind, name, domain);
+      if (retval != nullptr)
+	break;
+    }
 
   if (debug_symfile)
     fprintf_filtered (gdb_stdlog, "qf->lookup_symbol (...) = %s\n",
@@ -180,8 +196,8 @@ objfile::print_stats (bool print_bcache)
     fprintf_filtered (gdb_stdlog, "qf->print_stats (%s, %d)\n",
 		      objfile_debug_name (this), print_bcache);
 
-  if (qf != nullptr)
-    qf->print_stats (this, print_bcache);
+  for (const auto &iter : qf)
+    iter->print_stats (this, print_bcache);
 }
 
 void
@@ -191,8 +207,8 @@ objfile::dump ()
     fprintf_filtered (gdb_stdlog, "qf->dump (%s)\n",
 		      objfile_debug_name (this));
 
-  if (qf != nullptr)
-    qf->dump (this);
+  for (const auto &iter : qf)
+    iter->dump (this);
 }
 
 void
@@ -203,8 +219,8 @@ objfile::expand_symtabs_for_function (const char *func_name)
 		      "qf->expand_symtabs_for_function (%s, \"%s\")\n",
 		      objfile_debug_name (this), func_name);
 
-  if (qf != nullptr)
-    qf->expand_symtabs_for_function (this, func_name);
+  for (const auto &iter : qf)
+    iter->expand_symtabs_for_function (this, func_name);
 }
 
 void
@@ -214,8 +230,8 @@ objfile::expand_all_symtabs ()
     fprintf_filtered (gdb_stdlog, "qf->expand_all_symtabs (%s)\n",
 		      objfile_debug_name (this));
 
-  if (qf != nullptr)
-    qf->expand_all_symtabs (this);
+  for (const auto &iter : qf)
+    iter->expand_all_symtabs (this);
 }
 
 void
@@ -226,8 +242,8 @@ objfile::expand_symtabs_with_fullname (const char *fullname)
 		      "qf->expand_symtabs_with_fullname (%s, \"%s\")\n",
 		      objfile_debug_name (this), fullname);
 
-  if (qf != nullptr)
-    qf->expand_symtabs_with_fullname (this, fullname);
+  for (const auto &iter : qf)
+    iter->expand_symtabs_with_fullname (this, fullname);
 }
 
 void
@@ -244,9 +260,9 @@ objfile::map_matching_symbols
 		      domain_name (domain), global,
 		      host_address_to_string (ordered_compare));
 
-  if (qf != nullptr)
-    qf->map_matching_symbols (this, name, domain, global,
-			      callback, ordered_compare);
+  for (const auto &iter : qf)
+    iter->map_matching_symbols (this, name, domain, global,
+				callback, ordered_compare);
 }
 
 void
@@ -266,9 +282,9 @@ objfile::expand_symtabs_matching
 		      host_address_to_string (&expansion_notify),
 		      search_domain_name (kind));
 
-  if (qf != nullptr)
-    qf->expand_symtabs_matching (this, file_matcher, lookup_name,
-				 symbol_matcher, expansion_notify, kind);
+  for (const auto &iter : qf)
+    iter->expand_symtabs_matching (this, file_matcher, lookup_name,
+				   symbol_matcher, expansion_notify, kind);
 }
 
 struct compunit_symtab *
@@ -288,9 +304,13 @@ objfile::find_pc_sect_compunit_symtab (struct bound_minimal_symbol msymbol,
 		      host_address_to_string (section),
 		      warn_if_readin);
 
-  if (qf != nullptr)
-    retval = qf->find_pc_sect_compunit_symtab (this, msymbol, pc, section,
-					       warn_if_readin);
+  for (const auto &iter : qf)
+    {
+      retval = iter->find_pc_sect_compunit_symtab (this, msymbol, pc, section,
+						   warn_if_readin);
+      if (retval != nullptr)
+	break;
+    }
 
   if (debug_symfile)
     fprintf_filtered (gdb_stdlog,
@@ -314,8 +334,8 @@ objfile::map_symbol_filenames (symbol_filename_ftype *fun, void *data,
 		      host_address_to_string (data),
 		      need_fullname);
 
-  if (qf != nullptr)
-    qf->map_symbol_filenames (this, fun, data, need_fullname);
+  for (const auto &iter : qf)
+    iter->map_symbol_filenames (this, fun, data, need_fullname);
 }
 
 struct compunit_symtab *
@@ -328,8 +348,12 @@ objfile::find_compunit_symtab_by_address (CORE_ADDR address)
 		      hex_string (address));
 
   struct compunit_symtab *result = NULL;
-  if (qf != nullptr)
-    result = qf->find_compunit_symtab_by_address (this, address);
+  for (const auto &iter : qf)
+    {
+      result = iter->find_compunit_symtab_by_address (this, address);
+      if (result != nullptr)
+	break;
+    }
 
   if (debug_symfile)
     fprintf_filtered (gdb_stdlog,
@@ -347,12 +371,15 @@ objfile::lookup_global_symbol_language (const char *name,
 					bool *symbol_found_p)
 {
   enum language result = language_unknown;
+  *symbol_found_p = false;
 
-  if (qf != nullptr)
-    result = qf->lookup_global_symbol_language (this, name, domain,
-						symbol_found_p);
-  else
-    *symbol_found_p = false;
+  for (const auto &iter : qf)
+    {
+      result = iter->lookup_global_symbol_language (this, name, domain,
+						    symbol_found_p);
+      if (*symbol_found_p)
+	break;
+    }
 
   return result;
 }
@@ -364,17 +391,23 @@ objfile::require_partial_symbols (bool verbose)
     {
       flags |= OBJF_PSYMTABS_READ;
 
-      if (qf->can_lazily_read_symbols ())
+      bool printed = false;
+      for (const auto &iter : qf)
 	{
-	  if (verbose)
-	    printf_filtered (_("Reading symbols from %s...\n"),
-			     objfile_name (this));
-	  qf->read_partial_symbols (this);
-
-	  if (verbose && !objfile_has_symbols (this))
-	    printf_filtered (_("(No debugging symbols found in %s)\n"),
-			     objfile_name (this));
+	  if (iter->can_lazily_read_symbols ())
+	    {
+	      if (verbose && !printed)
+		{
+		  printf_filtered (_("Reading symbols from %s...\n"),
+				   objfile_name (this));
+		  printed = true;
+		}
+	      iter->read_partial_symbols (this);
+	    }
 	}
+      if (printed && !objfile_has_symbols (this))
+	printf_filtered (_("(No debugging symbols found in %s)\n"),
+			 objfile_name (this));
     }
 }
 
diff --git a/gdb/symfile.c b/gdb/symfile.c
index d2ea04ed149..244565f8f47 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -903,7 +903,8 @@ syms_from_objfile_1 (struct objfile *objfile,
 
   objfile_set_sym_fns (objfile, find_sym_fns (objfile->obfd));
   objfile->reset_psymtabs ();
-  objfile->qf = make_psymbol_functions (objfile->partial_symtabs);
+  objfile->qf.clear ();
+  objfile->qf.push_front (make_psymbol_functions (objfile->partial_symtabs));
 
   if (objfile->sf == NULL)
     {
@@ -2553,7 +2554,9 @@ reread_symbols (void)
 	     start over.  PR symtab/15885  */
 	  objfile_set_sym_fns (objfile, find_sym_fns (objfile->obfd));
 	  objfile->reset_psymtabs ();
-	  objfile->qf = make_psymbol_functions (objfile->partial_symtabs);
+	  objfile->qf.clear ();
+	  objfile->qf.push_front
+	    (make_psymbol_functions (objfile->partial_symtabs));
 
 	  build_objfile_section_table (objfile);
 
-- 
2.26.2


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 26/26] Allow multiple partial symbol readers per objfile
  2021-02-28 20:37 [PATCH 00/26] Allow multiple "partial" symtab readers per objfile Tom Tromey
                   ` (24 preceding siblings ...)
  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
  2021-03-20 23:33 ` [PATCH 00/26] Allow multiple "partial" symtab " Tom Tromey
  26 siblings, 0 replies; 30+ messages in thread
From: Tom Tromey @ 2021-02-28 20:38 UTC (permalink / raw)
  To: gdb-patches

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


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 00/26] Allow multiple "partial" symtab readers per objfile
  2021-02-28 20:37 [PATCH 00/26] Allow multiple "partial" symtab readers per objfile Tom Tromey
                   ` (25 preceding siblings ...)
  2021-02-28 20:38 ` [PATCH 26/26] Allow multiple partial symbol readers per objfile Tom Tromey
@ 2021-03-20 23:33 ` Tom Tromey
  2021-03-22 14:13   ` Simon Marchi
  26 siblings, 1 reply; 30+ messages in thread
From: Tom Tromey @ 2021-03-20 23:33 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

Tom> This series lifts these restrictions.  At the end, an objfile can have
Tom> any number of "partial symbol" (really the so-called "quick"
Tom> functions) readers, even zero.  Each reader is separate, and so the
Tom> restrictions on sharing of DWARF partial symbols are lifted.

Tom> I used my script to regression test each patch here on x86-64 Fedora 32.

I rebased this today.  It required two minor changes, one to resolve a
conflict due to other DWARF-related changes in symfile.h, and one minor
update to account for a change in ctfread.c.

I re-regression-tested the final patch (but not every patch, as I'd done
earlier).

I'm checking this in now.

Tom

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 05/26] Introduce method wrappers for quick_symbol_functions
  2021-02-28 20:37 ` [PATCH 05/26] Introduce method wrappers for quick_symbol_functions Tom Tromey
@ 2021-03-22 13:52   ` Simon Marchi
  0 siblings, 0 replies; 30+ messages in thread
From: Simon Marchi @ 2021-03-22 13:52 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches



On 2021-02-28 3:37 p.m., Tom Tromey wrote:
> This introduces wrappers for each function in quick_symbol_functions.
> The wrappers are methods on objfile, and are defined in
> symfile-debug.c, so that they can use the symfile_debug variable.
> Places that call the quick functions are all updated to call these new
> wrapper methods.
> 
> gdb/ChangeLog
> 2021-02-28  Tom Tromey  <tom@tromey.com>
> 
> 	* symtab.c (iterate_over_symtabs, expand_symtab_containing_pc)
> 	(lookup_symbol_via_quick_fns, find_quick_global_symbol_language)
> 	(basic_lookup_transparent_type_quick)
> 	(find_pc_sect_compunit_symtab, find_symbol_at_address)
> 	(find_line_symtab, global_symbol_searcher::expand_symtabs):
> 	Update.
> 	* symmisc.c (print_objfile_statistics, dump_objfile)
> 	(maintenance_expand_symtabs): Update.
> 	* symfile.c (symbol_file_add_with_addrs)
> 	(expand_symtabs_matching, map_symbol_filenames): Update.
> 	* symfile-debug.c (objfile::has_partial_symbols)
> 	(objfile::find_last_source_symtab)
> 	(objfile::forget_cached_source_info)
> 	(objfile::map_symtabs_matching_filename, objfile::lookup_symbol)
> 	(objfile::print_stats, objfile::dump)
> 	(objfile::expand_symtabs_for_function)
> 	(objfile::expand_all_symtabs)
> 	(objfile::expand_symtabs_with_fullname)
> 	(objfile::map_matching_symbols)
> 	(objfile::expand_symtabs_matching)
> 	(objfile::find_pc_sect_compunit_symtab)
> 	(objfile::map_symbol_filenames)
> 	(objfile::find_compunit_symtab_by_address)
> 	(objfile::lookup_global_symbol_language): New methods.
> 	(debug_sym_quick_functions): Remove.
> 	(debug_sym_fns, install_symfile_debug_logging): Update.
> 	* source.c (forget_cached_source_info_for_objfile)
> 	(select_source_symtab): Update.
> 	* objfiles.h (struct objfile): Add methods corresponding to
> 	quick_symbol_functions.
> 	* objfiles.c (objfile::has_partial_symbols): Move to
> 	symfile-debug.c.
> 	* linespec.c (iterate_over_all_matching_symtabs): Update.
> 	* cp-support.c (add_symbol_overload_list_qualified): Update.
> 	* ada-lang.c (add_nonlocal_symbols): Update.

A bit late, but: wouldn't it be better to have the objfile methods
implemented in objfiles.c, and just export the symfile_debug variable?
We already have some _debug variables exported, this wouldn't be a
problem.

Simon

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 00/26] Allow multiple "partial" symtab readers per objfile
  2021-03-20 23:33 ` [PATCH 00/26] Allow multiple "partial" symtab " Tom Tromey
@ 2021-03-22 14:13   ` Simon Marchi
  0 siblings, 0 replies; 30+ messages in thread
From: Simon Marchi @ 2021-03-22 14:13 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On 2021-03-20 7:33 p.m., Tom Tromey wrote:
> Tom> This series lifts these restrictions.  At the end, an objfile can have
> Tom> any number of "partial symbol" (really the so-called "quick"
> Tom> functions) readers, even zero.  Each reader is separate, and so the
> Tom> restrictions on sharing of DWARF partial symbols are lifted.
> 
> Tom> I used my script to regression test each patch here on x86-64 Fedora 32.
> 
> I rebased this today.  It required two minor changes, one to resolve a
> conflict due to other DWARF-related changes in symfile.h, and one minor
> update to account for a change in ctfread.c.
> 
> I re-regression-tested the final patch (but not every patch, as I'd done
> earlier).
> 
> I'm checking this in now.

I didn't have time to look into this before you merged it, but it looks
like a nice change overall, thanks for doing this.

Simon

^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2021-03-22 14:13 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-28 20:37 [PATCH 00/26] Allow multiple "partial" symtab readers per objfile 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 ` [PATCH 26/26] Allow multiple partial symbol readers per objfile Tom Tromey
2021-03-20 23:33 ` [PATCH 00/26] Allow multiple "partial" symtab " Tom Tromey
2021-03-22 14:13   ` Simon Marchi

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).