[review] Virtualize "readin" and "compunit_symtab"

Message ID gerrit.1572228195000.Idb923f196d7e03bf7cb9cfc8134ed06dd3f211ce@gnutoolchain-gerrit.osci.io
State Superseded
Headers show
Series
  • [review] Virtualize "readin" and "compunit_symtab"
Related show

Commit Message

Simon Marchi (Code Review) Oct. 28, 2019, 2:03 a.m.
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/383
......................................................................

Virtualize "readin" and "compunit_symtab"

This patch removes the "readin" and "compunit_symtab" members from
partial_symtab, replacing them with methods.  Then it introduces a new
"standard_psymtab" class, which restores these members; and changes
the symbol readers to use this intermediate class as the base class of
their partial symtab subclasses.

The reason for this is to make it possible for a symbol reader to
implement an alternate mapping between partial and full symbol tables.
This is important in order to be able to share psymtabs across
objfiles -- whether a psymtab has been "readin" is objfile-dependent,
as are the pointers to the full symbol tables.

gdb/ChangeLog
2019-10-27  Tom Tromey  <tom@tromey.com>

	* psymtab.c (partial_map_expand_apply)
	(psym_find_pc_sect_compunit_symtab, psym_lookup_symbol)
	(psymtab_to_symtab, psym_find_last_source_symtab, dump_psymtab)
	(psym_print_stats, psym_expand_symtabs_for_function)
	(psym_map_symbol_filenames, psym_map_matching_symbols)
	(psym_expand_symtabs_matching)
	(partial_symtab::read_dependencies, maintenance_info_psymtabs)
	(maintenance_check_psymtabs): Use new methods.
	* psympriv.h (struct partial_symtab) <readin_p,
	get_compunit_symtab>: New methods.
	<readin, compunit_symtab>: Remove members.
	(struct standard_psymtab): New.
	(struct legacy_psymtab): Derive from standard_psymtab.
	* dwarf2read.h (struct dwarf2_psymtab): Derive from
	standard_psymtab.
	* ctfread.c (struct ctf_psymtab): Derive from standard_psymtab.

Change-Id: Idb923f196d7e03bf7cb9cfc8134ed06dd3f211ce
---
M gdb/ChangeLog
M gdb/ctfread.c
M gdb/dwarf2read.h
M gdb/psympriv.h
M gdb/psymtab.c
5 files changed, 90 insertions(+), 35 deletions(-)




-- 
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: Idb923f196d7e03bf7cb9cfc8134ed06dd3f211ce
Gerrit-Change-Number: 383
Gerrit-PatchSet: 1
Gerrit-Owner: Tom Tromey <tromey@sourceware.org>
Gerrit-MessageType: newchange

Comments

Simon Marchi (Code Review) Jan. 26, 2020, 11:38 p.m. | #1
Tom Tromey has posted comments on this change.

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/383
......................................................................


Patch Set 1:

I'm going to check this series in now.


-- 
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: Idb923f196d7e03bf7cb9cfc8134ed06dd3f211ce
Gerrit-Change-Number: 383
Gerrit-PatchSet: 1
Gerrit-Owner: Tom Tromey <tromey@sourceware.org>
Gerrit-Reviewer: Tom Tromey <tromey@sourceware.org>
Gerrit-Comment-Date: Sun, 26 Jan 2020 23:38:55 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
Gerrit-MessageType: comment

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 81b2cc4..d34babd 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,24 @@ 
 2019-10-27  Tom Tromey  <tom@tromey.com>
 
+	* psymtab.c (partial_map_expand_apply)
+	(psym_find_pc_sect_compunit_symtab, psym_lookup_symbol)
+	(psymtab_to_symtab, psym_find_last_source_symtab, dump_psymtab)
+	(psym_print_stats, psym_expand_symtabs_for_function)
+	(psym_map_symbol_filenames, psym_map_matching_symbols)
+	(psym_expand_symtabs_matching)
+	(partial_symtab::read_dependencies, maintenance_info_psymtabs)
+	(maintenance_check_psymtabs): Use new methods.
+	* psympriv.h (struct partial_symtab) <readin_p,
+	get_compunit_symtab>: New methods.
+	<readin, compunit_symtab>: Remove members.
+	(struct standard_psymtab): New.
+	(struct legacy_psymtab): Derive from standard_psymtab.
+	* dwarf2read.h (struct dwarf2_psymtab): Derive from
+	standard_psymtab.
+	* ctfread.c (struct ctf_psymtab): Derive from standard_psymtab.
+
+2019-10-27  Tom Tromey  <tom@tromey.com>
+
 	* xcoffread.c (xcoff_psymtab_to_symtab_1): Call
 	read_dependencies.  Add assert.
 	* psymtab.c (partial_symtab::read_dependencies): New method.
diff --git a/gdb/ctfread.c b/gdb/ctfread.c
index 074bc68..5ec3b2f 100644
--- a/gdb/ctfread.c
+++ b/gdb/ctfread.c
@@ -97,10 +97,10 @@ 
 } ctf_context_t;
 
 /* A partial symtab, specialized for this module.  */
-struct ctf_psymtab : public partial_symtab
+struct ctf_psymtab : public standard_psymtab
 {
   ctf_psymtab (const char *filename, struct objfile *objfile, CORE_ADDR addr)
-    : partial_symtab (filename, objfile, addr)
+    : standard_psymtab (filename, objfile, addr)
   {
   }
 
diff --git a/gdb/dwarf2read.h b/gdb/dwarf2read.h
index 25287be..df7c00a 100644
--- a/gdb/dwarf2read.h
+++ b/gdb/dwarf2read.h
@@ -270,16 +270,16 @@ 
 dwarf2_per_objfile *get_dwarf2_per_objfile (struct objfile *objfile);
 
 /* A partial symtab specialized for DWARF.  */
-struct dwarf2_psymtab : public partial_symtab
+struct dwarf2_psymtab : public standard_psymtab
 {
   dwarf2_psymtab (const char *filename, struct objfile *objfile)
-    : partial_symtab (filename, objfile)
+    : standard_psymtab (filename, objfile)
   {
   }
 
   dwarf2_psymtab (const char *filename, struct objfile *objfile,
 		  CORE_ADDR addr)
-    : partial_symtab (filename, objfile, addr)
+    : standard_psymtab (filename, objfile, addr)
   {
   }
 
diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index d6b2ab8..30abfb6 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -137,6 +137,15 @@ 
   /* Ensure that all the dependencies are read in.  */
   void read_dependencies (struct objfile *);
 
+  /* Return true if the symtab corresponding to this psymtab has been
+     readin.  */
+  virtual bool readin_p () const = 0;
+
+  /* Return a pointer to the compunit allocated for this source file.
+     Return nullptr if !readin or if there was no symtab.  */
+  virtual struct compunit_symtab *get_compunit_symtab () const = 0;
+
+
   /* Return the raw low text address of this partial_symtab.  */
   CORE_ADDR raw_text_low () const
   {
@@ -267,12 +276,6 @@ 
   int statics_offset = 0;
   int n_static_syms = 0;
 
-  /* True if the symtab corresponding to this psymtab has been readin.
-     This is located here so that this structure packs better on
-     64-bit systems.  */
-
-  bool readin = false;
-
   /* True iff objfile->psymtabs_addrmap is properly populated for this
      partial_symtab.  For discontiguous overlapping psymtabs is the only usable
      info in PSYMTABS_ADDRMAP.  */
@@ -291,6 +294,40 @@ 
 
   unsigned int text_low_valid : 1;
   unsigned int text_high_valid : 1;
+};
+
+/* A partial symtab that tracks the "readin" and "compunit_symtab"
+   information in the ordinary way -- by storing it directly in this
+   object.  */
+struct standard_psymtab : public partial_symtab
+{
+  standard_psymtab (const char *filename, struct objfile *objfile)
+    : partial_symtab (filename, objfile)
+  {
+  }
+
+  standard_psymtab (const char *filename, struct objfile *objfile,
+		    CORE_ADDR addr)
+    : partial_symtab (filename, objfile, addr)
+  {
+  }
+
+  bool readin_p () const override
+  {
+    return readin;
+  }
+
+  /* Return a pointer to the compunit allocated for this source file.
+     Return nullptr if !readin or if there was no symtab.  */
+  struct compunit_symtab *get_compunit_symtab () const override
+  {
+    return compunit_symtab;
+  }
+
+  /* True if the symtab corresponding to this psymtab has been
+     readin.  */
+
+  bool readin = false;
 
   /* Pointer to compunit eventually allocated for this source file, 0 if
      !readin or if we haven't looked for the symtab after it was readin.  */
@@ -302,16 +339,16 @@ 
    not be used in new code, but exists to transition the somewhat
    unmaintained "legacy" debug formats.  */
 
-struct legacy_psymtab : public partial_symtab
+struct legacy_psymtab : public standard_psymtab
 {
   legacy_psymtab (const char *filename, struct objfile *objfile)
-    : partial_symtab (filename, objfile)
+    : standard_psymtab (filename, objfile)
   {
   }
 
   legacy_psymtab (const char *filename, struct objfile *objfile,
 		  CORE_ADDR addr)
-    : partial_symtab (filename, objfile, addr)
+    : standard_psymtab (filename, objfile, addr)
   {
   }
 
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 5554e42..b568633 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -131,7 +131,7 @@ 
   gdb_assert (pst->user == NULL);
 
   /* Don't visit already-expanded psymtabs.  */
-  if (pst->readin)
+  if (pst->readin_p ())
     return 0;
 
   /* This may expand more than one symtab, and we want to iterate over
@@ -386,7 +386,7 @@ 
 						    msymbol);
   if (ps != NULL)
     {
-      if (warn_if_readin && ps->readin)
+      if (warn_if_readin && ps->readin_p ())
 	/* Might want to error() here (in case symtab is corrupt and
 	   will cause a core dump), but maybe we can successfully
 	   continue, so let's not.  */
@@ -394,7 +394,7 @@ 
 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
 		 paddress (get_objfile_arch (objfile), pc));
       psymtab_to_symtab (objfile, ps);
-      return ps->compunit_symtab;
+      return ps->get_compunit_symtab ();
     }
   return NULL;
 }
@@ -485,8 +485,8 @@ 
 
   for (partial_symtab *ps : require_partial_symbols (objfile, 1))
     {
-      if (!ps->readin && lookup_partial_symbol (objfile, ps, name,
-						psymtab_index, domain))
+      if (!ps->readin_p () && lookup_partial_symbol (objfile, ps, name,
+						     psymtab_index, domain))
 	{
 	  struct symbol *sym, *with_opaque = NULL;
 	  struct compunit_symtab *stab = psymtab_to_symtab (objfile, ps);
@@ -751,11 +751,11 @@ 
     pst = pst->user;
 
   /* If it's been looked up before, return it.  */
-  if (pst->compunit_symtab)
-    return pst->compunit_symtab;
+  if (pst->get_compunit_symtab ())
+    return pst->get_compunit_symtab ();
 
   /* If it has not yet been read in, read it.  */
-  if (!pst->readin)
+  if (!pst->readin_p ())
     {
       scoped_restore decrementer = increment_reading_symtab ();
 
@@ -773,7 +773,7 @@ 
 	printf_filtered (_("done.\n"));
     }
 
-  return pst->compunit_symtab;
+  return pst->get_compunit_symtab ();
 }
 
 /* Psymtab version of find_last_source_symtab.  See its definition in
@@ -796,7 +796,7 @@ 
 
   if (cs_pst)
     {
-      if (cs_pst->readin)
+      if (cs_pst->readin_p ())
 	{
 	  internal_error (__FILE__, __LINE__,
 			  _("select_source_symtab: "
@@ -953,11 +953,11 @@ 
   gdb_print_host_address (objfile, outfile);
   fprintf_filtered (outfile, ")\n");
 
-  if (psymtab->readin)
+  if (psymtab->readin_p ())
     {
       fprintf_filtered (outfile,
 			"  Full symtab was read (at ");
-      gdb_print_host_address (psymtab->compunit_symtab, outfile);
+      gdb_print_host_address (psymtab->get_compunit_symtab (), outfile);
       fprintf_filtered (outfile, ")\n");
     }
 
@@ -1011,7 +1011,7 @@ 
   i = 0;
   for (partial_symtab *ps : require_partial_symbols (objfile, 1))
     {
-      if (!ps->readin)
+      if (!ps->readin_p ())
 	i++;
     }
   printf_filtered (_("  Number of psym tables (not yet expanded): %d\n"), i);
@@ -1051,7 +1051,7 @@ 
 {
   for (partial_symtab *ps : require_partial_symbols (objfile, 1))
     {
-      if (ps->readin)
+      if (ps->readin_p ())
 	continue;
 
       if ((lookup_partial_symbol (objfile, ps, func_name, 1, VAR_DOMAIN)
@@ -1106,7 +1106,7 @@ 
     {
       const char *fullname;
 
-      if (ps->readin)
+      if (ps->readin_p ())
 	continue;
 
       /* We can skip shared psymtabs here, because any file name will be
@@ -1186,7 +1186,7 @@ 
   for (partial_symtab *ps : require_partial_symbols (objfile, 1))
     {
       QUIT;
-      if (ps->readin
+      if (ps->readin_p ()
 	  || match_partial_symbol (objfile, ps, global, name, domain,
 				   ordered_compare))
 	{
@@ -1319,7 +1319,7 @@ 
     {
       QUIT;
 
-      if (ps->readin)
+      if (ps->readin_p ())
 	continue;
 
       /* We skip shared psymtabs because file-matching doesn't apply
@@ -1661,7 +1661,6 @@ 
   filename
     = ((const char *) objfile->per_bfd->filename_cache.insert
        (filename_, strlen (filename_) + 1));
-  compunit_symtab = NULL;
 
   if (symtab_create_debug)
     {
@@ -1691,7 +1690,7 @@ 
 {
   for (int i = 0; i < number_of_dependencies; ++i)
     {
-      if (!dependencies[i]->readin)
+      if (!dependencies[i]->readin_p ())
 	{
 	  /* Inform about additional files to be read in.  */
 	  if (info_verbose)
@@ -2003,7 +2002,7 @@ 
 				 host_address_to_string (psymtab));
 
 		printf_filtered ("    readin %s\n",
-				 psymtab->readin ? "yes" : "no");
+				 psymtab->readin_p () ? "yes" : "no");
 		printf_filtered ("    fullname %s\n",
 				 psymtab->fullname
 				 ? psymtab->fullname : "(null)");
@@ -2094,7 +2093,7 @@ 
 	/* 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->compunit_symtab;
+	cust = ps->get_compunit_symtab ();
 
 	/* First do some checks that don't require the associated symtab.  */
 	if (ps->text_high (objfile) < ps->text_low (objfile))