gdb: pass objfile_per_bfd_storage instead of objfile to partial_symtab
authorSimon Marchi <simon.marchi@polymtl.ca>
Fri, 2 Apr 2021 15:45:25 +0000 (11:45 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Fri, 2 Apr 2021 15:45:37 +0000 (11:45 -0400)
Since partial_symtab is supposed to be objfile-independent (since series
[1]), I think it would make sense for partial_symtab to not take an
objfile as a parameter in its constructor.

This patch replaces that parameter with an objfile_per_bfd_storage
parameter.

The objfile is used for two things:

 - to get the objfile_name, for debug messages.  We can get that name
   from the bfd instead.
 - to intern the partial symtab filename.  Even though it goes through
   an objfile method, the request is actually forwarded to the
   underlying objfile_per_bfd_storage.  So we can ask the new
   objfile_per_bfd_storage instead.

In order to get a reference to the BFD from the objfile_per_bfd_storage,
the BFD is saved in the objfile_per_bfd_storage object.

[1] https://sourceware.org/pipermail/gdb-patches/2021-February/176625.html

gdb/ChangeLog:

* psympriv.h (struct partial_symtab) <partial_symtab>: Change
objfile parameter for objfile_per_bfd_storage, adjust callers.
(struct standard_psymtab) <standard_psymtab>: Likewise.
(struct legacy_psymtab) <legacy_psymtab>: Likewise.
* psymtab.c (partial_symtab::partial_symtab): Likewise.
* ctfread.c (struct ctf_psymtab): Likewise.
* dwarf2/read.h (struct dwarf2_psymtab): Likewise.
* dwarf2/read.c (struct dwarf2_include_psymtab): Likewise.
(dwarf2_create_include_psymtab): Likewise.
* objfiles.h (struct objfile_per_bfd_storage)
<objfile_per_bfd_storage>: Add bfd parameter, adjust callers.
<get_bfd>: New method.
<m_bfd>: New field.
* objfiles.c (get_objfile_bfd_data): Adjust.

Change-Id: I2ed3ab5d2e6f27d034bd4dc26ae2fae7b0b8a2b9

gdb/ChangeLog
gdb/ctfread.c
gdb/dbxread.c
gdb/dwarf2/read.c
gdb/dwarf2/read.h
gdb/mdebugread.c
gdb/objfiles.c
gdb/objfiles.h
gdb/psympriv.h
gdb/psymtab.c
gdb/xcoffread.c

index 6d61a2cc7c1bfa986f7e0b75a9c8998e9a728a3a..3530819cf95d972b3471b46f4ecf23461ec2715e 100644 (file)
@@ -1,3 +1,20 @@
+2021-04-02  Simon Marchi  <simon.marchi@polymtl.ca>
+
+       * psympriv.h (struct partial_symtab) <partial_symtab>: Change
+       objfile parameter for objfile_per_bfd_storage, adjust callers.
+       (struct standard_psymtab) <standard_psymtab>: Likewise.
+       (struct legacy_psymtab) <legacy_psymtab>: Likewise.
+       * psymtab.c (partial_symtab::partial_symtab): Likewise.
+       * ctfread.c (struct ctf_psymtab): Likewise.
+       * dwarf2/read.h (struct dwarf2_psymtab): Likewise.
+       * dwarf2/read.c (struct dwarf2_include_psymtab): Likewise.
+       (dwarf2_create_include_psymtab): Likewise.
+       * objfiles.h (struct objfile_per_bfd_storage)
+       <objfile_per_bfd_storage>: Add bfd parameter, adjust callers.
+       <get_bfd>: New method.
+       <m_bfd>: New field.
+       * objfiles.c (get_objfile_bfd_data): Adjust.
+
 2021-04-02  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * psymtab.c (partial_symtab::partial_symtab): Change
index 616464c77dfc9faab055cf7d2d08f718c35ee22e..fae244d448187158c2674fb241fb1c3ce5b03537 100644 (file)
@@ -125,9 +125,9 @@ struct ctf_psymtab : public standard_psymtab
 {
   ctf_psymtab (const char *filename,
               psymtab_storage *partial_symtabs,
-              struct objfile *objfile,
+              objfile_per_bfd_storage *objfile_per_bfd,
               CORE_ADDR addr)
-    : standard_psymtab (filename, partial_symtabs, objfile, addr)
+    : standard_psymtab (filename, partial_symtabs, objfile_per_bfd, addr)
   {
   }
 
@@ -1369,7 +1369,7 @@ create_partial_symtab (const char *name,
   ctf_psymtab *pst;
   struct ctf_context *ccx;
 
-  pst = new ctf_psymtab (name, partial_symtabs, objfile, 0);
+  pst = new ctf_psymtab (name, partial_symtabs, objfile->per_bfd, 0);
 
   ccx = XOBNEW (&objfile->objfile_obstack, struct ctf_context);
   ccx->fp = cfp;
index 99a36cafa153b70ee50639e36f1e76ba7c602bf5..5cf77e9c08a10aeecbe5a9ea84ac761dc55b661c 100644 (file)
@@ -1917,7 +1917,7 @@ start_psymtab (psymtab_storage *partial_symtabs, struct objfile *objfile,
               const char *filename, CORE_ADDR textlow, int ldsymoff)
 {
   legacy_psymtab *result = new legacy_psymtab (filename, partial_symtabs,
-                                              objfile, textlow);
+                                              objfile->per_bfd, textlow);
 
   result->read_symtab_private =
     XOBNEW (&objfile->objfile_obstack, struct symloc);
@@ -2040,7 +2040,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], partial_symtabs, objfile);
+       new legacy_psymtab (include_list[i], partial_symtabs, objfile->per_bfd);
 
       subpst->read_symtab_private =
        XOBNEW (&objfile->objfile_obstack, struct symloc);
index 49b07d579b554f0705ffe432d9c6f94aa674d591..43433f50d26bdae255a622f768c67b4a8e90f14b 100644 (file)
@@ -6248,8 +6248,8 @@ struct dwarf2_include_psymtab : public partial_symtab
 {
   dwarf2_include_psymtab (const char *filename,
                          psymtab_storage *partial_symtabs,
-                         struct objfile *objfile)
-    : partial_symtab (filename, partial_symtabs, objfile)
+                         objfile_per_bfd_storage *objfile_per_bfd)
+    : partial_symtab (filename, partial_symtabs, objfile_per_bfd)
   {
   }
 
@@ -6305,10 +6305,10 @@ dwarf2_create_include_psymtab (dwarf2_per_bfd *per_bfd,
                               const char *name,
                               dwarf2_psymtab *pst,
                               psymtab_storage *partial_symtabs,
-                              struct objfile *objfile)
+                              objfile_per_bfd_storage *objfile_per_bfd)
 {
   dwarf2_include_psymtab *subpst
-    = new dwarf2_include_psymtab (name, partial_symtabs, objfile);
+    = new dwarf2_include_psymtab (name, partial_symtabs, objfile_per_bfd);
 
   if (!IS_ABSOLUTE_PATH (subpst->filename))
     subpst->dirname = pst->dirname;
@@ -7560,11 +7560,9 @@ create_partial_symtab (dwarf2_per_cu_data *per_cu,
                       dwarf2_per_objfile *per_objfile,
                       const char *name)
 {
-  struct objfile *objfile = per_objfile->objfile;
-  dwarf2_psymtab *pst;
-
-  pst = new dwarf2_psymtab (name, per_objfile->per_bfd->partial_symtabs.get (),
-                           objfile, per_cu);
+  dwarf2_psymtab *pst
+    = new dwarf2_psymtab (name, per_objfile->per_bfd->partial_symtabs.get (),
+                         per_objfile->objfile->per_bfd, per_cu);
 
   pst->psymtabs_addrmap_supported = true;
 
@@ -22010,7 +22008,7 @@ dwarf_decode_lines (struct line_header *lh, const char *comp_dir,
              dwarf2_create_include_psymtab
                (cu->per_objfile->per_bfd, include_name, pst,
                 cu->per_objfile->per_bfd->partial_symtabs.get (),
-                objfile);
+                objfile->per_bfd);
          }
     }
   else
index 82ab3879a5b79a25ddd7bb156599e3c936a56981..416d8eae959b8408224cdf653bd1f9677fed0de5 100644 (file)
@@ -408,9 +408,9 @@ struct dwarf2_psymtab : public partial_symtab
 {
   dwarf2_psymtab (const char *filename,
                  psymtab_storage *partial_symtabs,
-                 struct objfile *objfile,
+                 objfile_per_bfd_storage *objfile_per_bfd,
                  dwarf2_per_cu_data *per_cu)
-    : partial_symtab (filename, partial_symtabs, objfile, 0),
+    : partial_symtab (filename, partial_symtabs, objfile_per_bfd, 0),
       per_cu_data (per_cu)
   {
   }
index 7bf4564aecbacaed9863995260bb79ef4a253537..026f2ff20da4ef7c370867aaf154fbe161b0f363 100644 (file)
@@ -2605,8 +2605,8 @@ parse_partial_symbols (minimal_symbol_reader &reader,
        textlow = fh->adr;
       else
        textlow = 0;
-      pst = new legacy_psymtab (fdr_name (fh), partial_symtabs, objfile,
-                               textlow);
+      pst = new legacy_psymtab (fdr_name (fh), partial_symtabs,
+                               objfile->per_bfd, textlow);
       pst->read_symtab_private = XOBNEW (&objfile->objfile_obstack, symloc);
       memset (pst->read_symtab_private, 0, sizeof (struct symloc));
 
@@ -4646,7 +4646,7 @@ new_psymtab (const char *name, psymtab_storage *partial_symtabs,
 {
   legacy_psymtab *psymtab;
 
-  psymtab = new legacy_psymtab (name, partial_symtabs, objfile);
+  psymtab = new legacy_psymtab (name, partial_symtabs, objfile->per_bfd);
 
   /* Keep a backpointer to the file's symbols.  */
 
index ed51c31c8b915d4a9c72bc4a120a29473625d526..702900761f38ace98d46efedae28f08c3105cfea 100644 (file)
@@ -134,7 +134,7 @@ get_objfile_bfd_data (struct objfile *objfile, struct bfd *abfd)
 
   if (storage == NULL)
     {
-      storage = new objfile_per_bfd_storage;
+      storage = new objfile_per_bfd_storage (abfd);
       /* If the object requires gdb to do relocations, we simply fall
         back to not sharing data across users.  These cases are rare
         enough that this seems reasonable.  */
index e8a8b5f6de78be04cd470661c6c32e1e0ab4d99a..bf6e6a1d01a9cfa0b6a34757bf657cf715277917 100644 (file)
@@ -264,8 +264,8 @@ private:
 
 struct objfile_per_bfd_storage
 {
-  objfile_per_bfd_storage ()
-    : minsyms_read (false)
+  objfile_per_bfd_storage (bfd *bfd)
+    : minsyms_read (false), m_bfd (bfd)
   {}
 
   ~objfile_per_bfd_storage ();
@@ -287,6 +287,13 @@ struct objfile_per_bfd_storage
     return (const char *) string_cache.insert (str.c_str (), str.size () + 1);
   }
 
+  /* Get the BFD this object is associated to.  */
+
+  bfd *get_bfd () const
+  {
+    return m_bfd;
+  }
+
   /* The storage has an obstack of its own.  */
 
   auto_obstack storage_obstack;
@@ -364,6 +371,11 @@ struct objfile_per_bfd_storage
   /* All the different languages of symbols found in the demangled
      hash table.  */
   std::bitset<nr_languages> demangled_hash_languages;
+
+private:
+  /* The BFD this object is associated to.  */
+
+  bfd *m_bfd;
 };
 
 /* An iterator that first returns a parent objfile, and then each
index 193d64fbcf2ff88c967254e67394185806cf1307..e4bf038108fca2b8e4b95e4eebfa2623ea7aed16 100644 (file)
@@ -111,7 +111,8 @@ enum class psymbol_placement
 
 struct partial_symtab
 {
-  /* Allocate a new partial symbol table associated with OBJFILE.
+  /* Allocate a new partial symbol table.
+
      FILENAME (which must be non-NULL) is the filename of this partial
      symbol table; it is copied into the appropriate storage.  The
      partial symtab will also be installed using
@@ -119,7 +120,7 @@ struct partial_symtab
 
   partial_symtab (const char *filename,
                  psymtab_storage *partial_symtabs,
-                 struct objfile *objfile)
+                 objfile_per_bfd_storage *objfile_per_bfd)
     ATTRIBUTE_NONNULL (2) ATTRIBUTE_NONNULL (3);
 
   /* Like the above, but also sets the initial text low and text high
@@ -128,7 +129,7 @@ struct partial_symtab
 
   partial_symtab (const char *filename,
                  psymtab_storage *partial_symtabs,
-                 struct objfile *objfile,
+                 objfile_per_bfd_storage *objfile_per_bfd,
                  CORE_ADDR addr)
     ATTRIBUTE_NONNULL (2) ATTRIBUTE_NONNULL (3);
 
@@ -369,16 +370,16 @@ struct standard_psymtab : public partial_symtab
 {
   standard_psymtab (const char *filename,
                    psymtab_storage *partial_symtabs,
-                   struct objfile *objfile)
-    : partial_symtab (filename, partial_symtabs, objfile)
+                   objfile_per_bfd_storage *objfile_per_bfd)
+    : partial_symtab (filename, partial_symtabs, objfile_per_bfd)
   {
   }
 
   standard_psymtab (const char *filename,
                    psymtab_storage *partial_symtabs,
-                   struct objfile *objfile,
+                   objfile_per_bfd_storage *objfile_per_bfd,
                    CORE_ADDR addr)
-    : partial_symtab (filename, partial_symtabs, objfile, addr)
+    : partial_symtab (filename, partial_symtabs, objfile_per_bfd, addr)
   {
   }
 
@@ -411,16 +412,16 @@ struct legacy_psymtab : public standard_psymtab
 {
   legacy_psymtab (const char *filename,
                  psymtab_storage *partial_symtabs,
-                 struct objfile *objfile)
-    : standard_psymtab (filename, partial_symtabs, objfile)
+                 objfile_per_bfd_storage *objfile_per_bfd)
+    : standard_psymtab (filename, partial_symtabs, objfile_per_bfd)
   {
   }
 
   legacy_psymtab (const char *filename,
                  psymtab_storage *partial_symtabs,
-                 struct objfile *objfile,
+                 objfile_per_bfd_storage *objfile_per_bfd,
                  CORE_ADDR addr)
-    : standard_psymtab (filename, partial_symtabs, objfile, addr)
+    : standard_psymtab (filename, partial_symtabs, objfile_per_bfd, addr)
   {
   }
 
index 26ea35ea40c2706ab0b2b82daea567091e49522a..6f3d856215158d2e00bd4497d5db4347570f943b 100644 (file)
@@ -1436,9 +1436,9 @@ psymbol_functions::find_compunit_symtab_by_address (struct objfile *objfile,
 
 partial_symtab::partial_symtab (const char *filename,
                                psymtab_storage *partial_symtabs,
-                               struct objfile *objfile,
+                               objfile_per_bfd_storage *objfile_per_bfd,
                                CORE_ADDR textlow)
-  : partial_symtab (filename, partial_symtabs, objfile)
+  : partial_symtab (filename, partial_symtabs, objfile_per_bfd)
 {
   set_text_low (textlow);
   set_text_high (raw_text_low ()); /* default */
@@ -1561,28 +1561,29 @@ partial_symtab::add_psymbol (gdb::string_view name, bool copy_name,
 
 partial_symtab::partial_symtab (const char *filename_,
                                psymtab_storage *partial_symtabs,
-                               struct objfile *objfile)
+                               objfile_per_bfd_storage *objfile_per_bfd)
   : searched_flag (PST_NOT_SEARCHED),
     text_low_valid (0),
     text_high_valid (0)
 {
   partial_symtabs->install_psymtab (this);
 
-  filename = objfile->intern (filename_);
+  filename = objfile_per_bfd->intern (filename_);
 
   if (symtab_create_debug)
     {
       /* Be a bit clever with debugging messages, and don't print objfile
         every time, only when it changes.  */
-      static std::string last_objfile_name;
-      const char *this_objfile_name = objfile_name (objfile);
+      static std::string last_bfd_name;
+      const char *this_bfd_name
+       = bfd_get_filename (objfile_per_bfd->get_bfd ());
 
-      if (last_objfile_name.empty () || last_objfile_name != this_objfile_name)
+      if (last_bfd_name.empty () || last_bfd_name != this_bfd_name)
        {
-         last_objfile_name = this_objfile_name;
+         last_bfd_name = this_bfd_name;
          fprintf_filtered (gdb_stdlog,
-                           "Creating one or more psymtabs for objfile %s ...\n",
-                           this_objfile_name);
+                           "Creating one or more psymtabs for %s ...\n",
+                           this_bfd_name);
        }
       fprintf_filtered (gdb_stdlog,
                        "Created psymtab %s for module %s.\n",
index 30ac876e8e36520d65ab4a52d4386cc0b9886685..368572797f6415b615864737a5cd911fc54c990e 100644 (file)
@@ -1966,7 +1966,7 @@ xcoff_start_psymtab (psymtab_storage *partial_symtabs,
 {
   /* We fill in textlow later.  */
   legacy_psymtab *result = new legacy_psymtab (filename, partial_symtabs,
-                                              objfile, 0);
+                                              objfile->per_bfd, 0);
 
   result->read_symtab_private =
     XOBNEW (&objfile->objfile_obstack, struct symloc);
@@ -2022,7 +2022,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], partial_symtabs, objfile);
+       new legacy_psymtab (include_list[i], partial_symtabs, objfile->per_bfd);
 
       subpst->read_symtab_private = XOBNEW (&objfile->objfile_obstack, symloc);
       ((struct symloc *) subpst->read_symtab_private)->first_symnum = 0;