Make dwarf2_get_dwz_file take a dwarf2_per_bfd
authorSimon Marchi <simon.marchi@polymtl.ca>
Wed, 27 May 2020 15:13:54 +0000 (11:13 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 27 May 2020 15:15:54 +0000 (11:15 -0400)
This allows removing a per_bfd->dwarf2_per_objfile reference in
get_abbrev_section_for_cu.

This requires saving the bfd in dwarf2_per_bfd.  The constructor of
dwarf2_per_bfd already accepts the bfd, so it's just a matter of saving
it in a field.

I replaced uses of objfile_name with bfd_get_filename, which should be
equivalent in this case.

gdb/ChangeLog:

* dwarf2/read.h (struct dwarf2_per_bfd) <obfd>: New member.
(dwarf2_get_dwz_file): Replace parameter with dwarf2_per_bfd.
* dwarf2/read.c (dwarf2_per_bfd::dwarf2_per_bfd): Assign obfd
field.
(dwarf2_get_dwz_file): Replace parameter with dwarf2_per_bfd.
(create_cus_from_index): Update.
(dwarf2_read_gdb_index): Update.
(create_cus_from_debug_names): Update.
(dwarf2_read_debug_names): Update.
(get_abbrev_section_for_cu): Update.
(create_all_comp_units): Update.
(read_attribute_value): Update.
(get_debug_line_section): Update.
* dwarf2/index-cache.c (index_cache::store): Update.
* dwarf2/index-write.c (save_gdb_index_command): Update.
* dwarf2/macro.c (dwarf_decode_macro_bytes): Update.

Change-Id: Ifb23f55dda93c499aae57b6a9aff9c6ff9d2f45f

gdb/ChangeLog
gdb/dwarf2/index-cache.c
gdb/dwarf2/index-write.c
gdb/dwarf2/macro.c
gdb/dwarf2/read.c
gdb/dwarf2/read.h

index 799d1ed2dfec291e87cab180e158b4477ac422c5..39fa1aeae47e53699e6395549809583677b748dd 100644 (file)
@@ -1,3 +1,22 @@
+2020-05-27  Simon Marchi  <simon.marchi@polymtl.ca>
+
+       * dwarf2/read.h (struct dwarf2_per_bfd) <obfd>: New member.
+       (dwarf2_get_dwz_file): Replace parameter with dwarf2_per_bfd.
+       * dwarf2/read.c (dwarf2_per_bfd::dwarf2_per_bfd): Assign obfd
+       field.
+       (dwarf2_get_dwz_file): Replace parameter with dwarf2_per_bfd.
+       (create_cus_from_index): Update.
+       (dwarf2_read_gdb_index): Update.
+       (create_cus_from_debug_names): Update.
+       (dwarf2_read_debug_names): Update.
+       (get_abbrev_section_for_cu): Update.
+       (create_all_comp_units): Update.
+       (read_attribute_value): Update.
+       (get_debug_line_section): Update.
+       * dwarf2/index-cache.c (index_cache::store): Update.
+       * dwarf2/index-write.c (save_gdb_index_command): Update.
+       * dwarf2/macro.c (dwarf_decode_macro_bytes): Update.
+
 2020-05-27  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * dwarf2/read.h (struct dwarf2_per_cu_data) <per_bfd>: New
index 76e7ce6ab721a2cee38aa226f5314ef77ca8de53..cb79c87f0338d0e4eef0e318ee80f2b7f5ef6829 100644 (file)
@@ -108,7 +108,7 @@ index_cache::store (struct dwarf2_per_objfile *dwarf2_per_objfile)
 
   /* Get build id of dwz file, if present.  */
   gdb::optional<std::string> dwz_build_id_str;
-  const dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile);
+  const dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
   const char *dwz_build_id_ptr = NULL;
 
   if (dwz != nullptr)
index a9c665165c7c2822570db6a59cbc31dc99f9456d..a113aa653a5dbe9ca102a4db23b6bcf4d5fbe663 100644 (file)
@@ -1761,7 +1761,8 @@ save_gdb_index_command (const char *arg, int from_tty)
          try
            {
              const char *basename = lbasename (objfile_name (objfile));
-             const dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile);
+             const dwz_file *dwz
+               = dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
              const char *dwz_basename = NULL;
 
              if (dwz != NULL)
index c2580193205cebcf4ee2e346a23d5aa6633fb367..a44e2c77035b586a0e81a246de48a2622cfd549f 100644 (file)
@@ -507,7 +507,7 @@ dwarf_decode_macro_bytes (struct dwarf2_per_objfile *dwarf2_per_objfile,
                    || section_is_dwz)
                  {
                    struct dwz_file *dwz
-                     = dwarf2_get_dwz_file (dwarf2_per_objfile);
+                     = dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
 
                    body = dwz->read_string (objfile, str_offset);
                  }
@@ -644,7 +644,8 @@ dwarf_decode_macro_bytes (struct dwarf2_per_objfile *dwarf2_per_objfile,
 
            if (macinfo_type == DW_MACRO_import_sup)
              {
-               struct dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile);
+               struct dwz_file *dwz
+                 = dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
 
                dwz->macro.read (objfile);
 
index da1638d3a197bc4216b1e31febeed00582e4759f..aa1c3f0e92be5cd60558ac9776c739bf44aca60b 100644 (file)
@@ -1752,7 +1752,8 @@ line_header_eq_voidp (const void *item_lhs, const void *item_rhs)
 
 dwarf2_per_bfd::dwarf2_per_bfd (bfd *obfd, const dwarf2_debug_sections *names,
                                bool can_copy_)
-  : can_copy (can_copy_)
+  : obfd (obfd),
+    can_copy (can_copy_)
 {
   if (names == NULL)
     names = &dwarf2_elf_names;
@@ -2112,19 +2113,19 @@ locate_dwz_sections (bfd *abfd, asection *sectp, void *arg)
 /* See dwarf2read.h.  */
 
 struct dwz_file *
-dwarf2_get_dwz_file (struct dwarf2_per_objfile *dwarf2_per_objfile)
+dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd)
 {
   const char *filename;
   bfd_size_type buildid_len_arg;
   size_t buildid_len;
   bfd_byte *buildid;
 
-  if (dwarf2_per_objfile->per_bfd->dwz_file != NULL)
-    return dwarf2_per_objfile->per_bfd->dwz_file.get ();
+  if (per_bfd->dwz_file != NULL)
+    return per_bfd->dwz_file.get ();
 
   bfd_set_error (bfd_error_no_error);
   gdb::unique_xmalloc_ptr<char> data
-    (bfd_get_alt_debug_link_info (dwarf2_per_objfile->objfile->obfd,
+    (bfd_get_alt_debug_link_info (per_bfd->obfd,
                                  &buildid_len_arg, &buildid));
   if (data == NULL)
     {
@@ -2144,7 +2145,7 @@ dwarf2_get_dwz_file (struct dwarf2_per_objfile *dwarf2_per_objfile)
   if (!IS_ABSOLUTE_PATH (filename))
     {
       gdb::unique_xmalloc_ptr<char> abs
-       = gdb_realpath (objfile_name (dwarf2_per_objfile->objfile));
+       = gdb_realpath (bfd_get_filename (per_bfd->obfd));
 
       abs_storage = ldirname (abs.get ()) + SLASH_STRING + filename;
       filename = abs_storage.c_str ();
@@ -2165,7 +2166,7 @@ dwarf2_get_dwz_file (struct dwarf2_per_objfile *dwarf2_per_objfile)
   if (dwz_bfd == nullptr)
     {
       gdb::unique_xmalloc_ptr<char> alt_filename;
-      const char *origname = dwarf2_per_objfile->objfile->original_name;
+      const char *origname = bfd_get_filename (per_bfd->obfd);
 
       scoped_fd fd (debuginfod_debuginfo_query (buildid,
                                                buildid_len,
@@ -2187,7 +2188,7 @@ dwarf2_get_dwz_file (struct dwarf2_per_objfile *dwarf2_per_objfile)
 
   if (dwz_bfd == NULL)
     error (_("could not find '.gnu_debugaltlink' file for %s"),
-          objfile_name (dwarf2_per_objfile->objfile));
+          bfd_get_filename (per_bfd->obfd));
 
   std::unique_ptr<struct dwz_file> result
     (new struct dwz_file (std::move (dwz_bfd)));
@@ -2195,10 +2196,9 @@ dwarf2_get_dwz_file (struct dwarf2_per_objfile *dwarf2_per_objfile)
   bfd_map_over_sections (result->dwz_bfd.get (), locate_dwz_sections,
                         result.get ());
 
-  gdb_bfd_record_inclusion (dwarf2_per_objfile->objfile->obfd,
-                           result->dwz_bfd.get ());
-  dwarf2_per_objfile->per_bfd->dwz_file = std::move (result);
-  return dwarf2_per_objfile->per_bfd->dwz_file.get ();
+  gdb_bfd_record_inclusion (per_bfd->obfd, result->dwz_bfd.get ());
+  per_bfd->dwz_file = std::move (result);
+  return per_bfd->dwz_file.get ();
 }
 \f
 /* DWARF quick_symbols_functions support.  */
@@ -2526,7 +2526,7 @@ create_cus_from_index (struct dwarf2_per_objfile *dwarf2_per_objfile,
   if (dwz_elements == 0)
     return;
 
-  dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile);
+  dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
   create_cus_from_index_list (dwarf2_per_objfile, dwz_list, dwz_elements,
                              &dwz->info, 1);
 }
@@ -3073,7 +3073,7 @@ dwarf2_read_gdb_index
 
   /* If there is a .dwz file, read it so we can get its CU list as
      well.  */
-  dwz = dwarf2_get_dwz_file (dwarf2_per_objfile);
+  dwz = dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
   if (dwz != NULL)
     {
       struct mapped_index dwz_map;
@@ -5173,7 +5173,7 @@ create_cus_from_debug_names (struct dwarf2_per_objfile *dwarf2_per_objfile,
   if (dwz_map.cu_count == 0)
     return;
 
-  dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile);
+  dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
   create_cus_from_debug_names_list (dwarf2_per_objfile, dwz_map, dwz->info,
                                    true /* is_dwz */);
 }
@@ -5200,7 +5200,7 @@ dwarf2_read_debug_names (struct dwarf2_per_objfile *dwarf2_per_objfile)
 
   /* If there is a .dwz file, read it so we can get its CU list as
      well.  */
-  dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile);
+  dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
   if (dwz != NULL)
     {
       if (!read_debug_names_from_section (objfile,
@@ -6032,12 +6032,12 @@ static struct dwarf2_section_info *
 get_abbrev_section_for_cu (struct dwarf2_per_cu_data *this_cu)
 {
   struct dwarf2_section_info *abbrev;
-  struct dwarf2_per_objfile *dwarf2_per_objfile = this_cu->dwarf2_per_objfile;
+  dwarf2_per_bfd *per_bfd = this_cu->per_bfd;
 
   if (this_cu->is_dwz)
-    abbrev = &dwarf2_get_dwz_file (dwarf2_per_objfile)->abbrev;
+    abbrev = &dwarf2_get_dwz_file (per_bfd)->abbrev;
   else
-    abbrev = &dwarf2_per_objfile->per_bfd->abbrev;
+    abbrev = &per_bfd->abbrev;
 
   return abbrev;
 }
@@ -8058,7 +8058,7 @@ create_all_comp_units (struct dwarf2_per_objfile *dwarf2_per_objfile)
   read_comp_units_from_section (dwarf2_per_objfile, &dwarf2_per_objfile->per_bfd->info,
                                &dwarf2_per_objfile->per_bfd->abbrev, 0);
 
-  dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile);
+  dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
   if (dwz != NULL)
     read_comp_units_from_section (dwarf2_per_objfile, &dwz->info, &dwz->abbrev,
                                  1);
@@ -19103,7 +19103,7 @@ read_attribute_value (const struct die_reader_specs *reader,
       /* FALLTHROUGH */
     case DW_FORM_GNU_strp_alt:
       {
-       struct dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile);
+       dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
        LONGEST str_offset = cu_header->read_offset (abfd, info_ptr,
                                                     &bytes_read);
 
@@ -19698,7 +19698,7 @@ get_debug_line_section (struct dwarf2_cu *cu)
     section = &cu->dwo_unit->dwo_file->sections.line;
   else if (cu->per_cu->is_dwz)
     {
-      struct dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile);
+      dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
 
       section = &dwz->line;
     }
index 02478d1aa84c0281159ad30fcc02974e453904f1..e9c74a40a8775da6e2c10c2f4b33437d5924edbc 100644 (file)
@@ -136,6 +136,9 @@ private:
                        const dwarf2_debug_sections &names);
 
 public:
+  /* The corresponding BFD.  */
+  bfd *obfd;
+
   /* Objects that can be shared across objfiles are stored in this
      obstack or on the psymtab obstack, while objects that are
      objfile-specific are stored on the objfile obstack.  */
@@ -578,8 +581,7 @@ struct signatured_type
    there is no .gnu_debugaltlink section in the file.  Error if there
    is such a section but the file cannot be found.  */
 
-extern struct dwz_file *dwarf2_get_dwz_file
-    (struct dwarf2_per_objfile *dwarf2_per_objfile);
+extern dwz_file *dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd);
 
 /* Return the type of the DIE at DIE_OFFSET in the CU named by
    PER_CU.  */