]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/dwarf: make dwarf2_get_dwz_file a method of dwarf2_per_bfd
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 3 Mar 2025 21:35:36 +0000 (16:35 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Tue, 4 Mar 2025 15:41:54 +0000 (10:41 -0500)
dwarf2_get_dwz_file looks more or less like a simple getter of
dwarf2_per_bfd::dwz_file, so make it into a method.

I typically avoid the `get_` prefix for getters, but that would conflict
with the field name here.

Change-Id: Idd0d5b1bd3813babf438b20aac514b19c77cfc18
Approved-By: Tom Tromey <tom@tromey.com>
gdb/dwarf2/dwz.c
gdb/dwarf2/dwz.h
gdb/dwarf2/index-cache.c
gdb/dwarf2/index-write.c
gdb/dwarf2/macro.c
gdb/dwarf2/read-debug-names.c
gdb/dwarf2/read-gdb-index.c
gdb/dwarf2/read.c
gdb/dwarf2/read.h

index e1e407f774c7cc88841d452e13dffcc2c9827b13..f36d6a6418a4220d7d531e3bf5b6e047b40edd6e 100644 (file)
@@ -272,20 +272,3 @@ dwarf2_read_dwz_file (dwarf2_per_objfile *per_objfile)
 
   per_bfd->dwz_file = std::move (result);
 }
-
-/* See dwz.h.  */
-
-struct dwz_file *
-dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd, bool require)
-{
-  gdb_assert (!require || per_bfd->dwz_file.has_value ());
-
-  dwz_file *result = nullptr;
-  if (per_bfd->dwz_file.has_value ())
-    {
-      result = per_bfd->dwz_file->get ();
-      if (require && result == nullptr)
-       error (_("could not read '.gnu_debugaltlink' section"));
-    }
-  return result;
-}
index 13b7692070f22cc325f53859d0eb5da20a3d29ee..cd5143ff0848564e1c831f4eb7ddccd7231d28e6 100644 (file)
@@ -68,14 +68,6 @@ struct dwz_file
 
 using dwz_file_up = std::unique_ptr<dwz_file>;
 
-/* Return the separate '.dwz' debug file.  If there is no
-   .gnu_debugaltlink section in the file, then the result depends on
-   REQUIRE: if REQUIRE is true, then error; if REQUIRE is false,
-   return NULL.  */
-
-extern dwz_file *dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd,
-                                     bool require = false);
-
 /* Open the separate '.dwz' debug file, if needed.  This just sets the
    appropriate field in the per-BFD structure.  If the DWZ file
    exists, the relevant sections are read in as well.  Throws an error
index 6c344d7920d5810d03a6d084a069416f448b4056..7617bd709b99f811aa38cc15fb9fe448ecf7d750 100644 (file)
@@ -110,7 +110,7 @@ index_cache_store_context::index_cache_store_context (const index_cache &ic,
   m_build_id_str = build_id_to_string (build_id);
 
   /* Get build id of dwz file, if present.  */
-  const dwz_file *dwz = dwarf2_get_dwz_file (per_bfd);
+  const dwz_file *dwz = per_bfd->get_dwz_file ();
 
   if (dwz != nullptr)
     {
index 1d0dacb4b5220a88b19c770f8f8dd55ec152fe05..fc78cfda613e9b2c2adb6e53bdef443c0937b86d 100644 (file)
@@ -1681,7 +1681,7 @@ save_gdb_index_command (const char *args, int from_tty)
          try
            {
              const char *basename = lbasename (objfile_name (objfile));
-             const dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd);
+             const dwz_file *dwz = per_objfile->per_bfd->get_dwz_file ();
              const char *dwz_basename = NULL;
 
              if (dwz != NULL)
index 9ab9b345ef649a928437cc1e12f1ed8904ebfdf6..2d9d4b7bbcf0e79da203fb23ecc21925f7c5ead3 100644 (file)
@@ -503,8 +503,7 @@ dwarf_decode_macro_bytes (dwarf2_per_objfile *per_objfile,
                    || macinfo_type == DW_MACRO_undef_sup
                    || section_is_dwz)
                  {
-                   dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd,
-                                                        true);
+                   dwz_file *dwz = per_objfile->per_bfd->get_dwz_file (true);
 
                    body = dwz->read_string (objfile, str_offset);
                  }
@@ -710,8 +709,7 @@ dwarf_decode_macro_bytes (dwarf2_per_objfile *per_objfile,
 
            if (macinfo_type == DW_MACRO_import_sup)
              {
-               dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd,
-                                                    true);
+               dwz_file *dwz = per_objfile->per_bfd->get_dwz_file (true);
 
                include_section = &dwz->macro;
                include_bfd = include_section->get_bfd_owner ();
index 34db3dbee79f5cc9c97dd4251e8ac13436151c70..2cd32d09abe597672596d0d38f1a7a0173edce53 100644 (file)
@@ -777,7 +777,7 @@ check_cus_from_debug_names (dwarf2_per_bfd *per_bfd,
   if (dwz_map.cu_count == 0)
     return true;
 
-  dwz_file *dwz = dwarf2_get_dwz_file (per_bfd);
+  dwz_file *dwz = per_bfd->get_dwz_file ();
   return check_cus_from_debug_names_list (per_bfd, dwz_map, dwz->info,
                                          true /* is_dwz */);
 }
@@ -803,7 +803,7 @@ do_dwarf2_read_debug_names (dwarf2_per_objfile *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 (per_bfd);
+  dwz_file *dwz = per_bfd->get_dwz_file ();
   if (dwz != NULL)
     {
       if (!read_debug_names_from_section (per_objfile,
index 282ac5b4ef4bd4973851cb9cd78a8642a1c42730..e513e80ffce30c277233dd7fb07e43d5fc168df6 100644 (file)
@@ -1348,7 +1348,7 @@ create_cus_from_gdb_index (dwarf2_per_bfd *per_bfd,
   if (dwz_elements == 0)
     return;
 
-  dwz_file *dwz = dwarf2_get_dwz_file (per_bfd);
+  dwz_file *dwz = per_bfd->get_dwz_file ();
   create_cus_from_gdb_index_list (per_bfd, dwz_list, dwz_elements,
                                  &dwz->info, 1);
 }
@@ -1480,7 +1480,6 @@ dwarf2_read_gdb_index
 {
   const gdb_byte *cu_list, *types_list, *dwz_list = NULL;
   offset_type cu_list_elements, types_list_elements, dwz_list_elements = 0;
-  struct dwz_file *dwz;
   struct objfile *objfile = per_objfile->objfile;
   dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
 
@@ -1504,7 +1503,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 (per_bfd);
+  dwz_file *dwz = per_bfd->get_dwz_file ();
   if (dwz != NULL)
     {
       mapped_gdb_index dwz_map;
index 0bef46a10e4b478b9c6e0add23752779ba98a61f..a10659039bcb80aa27bd9db954114f09dc71ac0c 100644 (file)
@@ -2516,7 +2516,7 @@ get_abbrev_section_for_cu (dwarf2_per_cu *this_cu)
   dwarf2_per_bfd *per_bfd = this_cu->per_bfd;
 
   if (this_cu->is_dwz)
-    abbrev = &dwarf2_get_dwz_file (per_bfd, true)->abbrev;
+    abbrev = &per_bfd->get_dwz_file (true)->abbrev;
   else
     abbrev = &per_bfd->abbrev;
 
@@ -4328,7 +4328,7 @@ create_all_units (dwarf2_per_objfile *per_objfile)
                                  &per_objfile->per_bfd->abbrev, 0, sig_types,
                                  rcuh_kind::TYPE);
 
-  dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd);
+  dwz_file *dwz = per_objfile->per_bfd->get_dwz_file ();
   if (dwz != NULL)
     {
       read_comp_units_from_section (per_objfile, &dwz->info, &dwz->abbrev, 1,
@@ -16467,7 +16467,7 @@ read_attribute_value (const struct die_reader_specs *reader,
       [[fallthrough]];
     case DW_FORM_GNU_strp_alt:
       {
-       dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd, true);
+       dwz_file *dwz = per_objfile->per_bfd->get_dwz_file (true);
        LONGEST str_offset = cu_header->read_offset (abfd, info_ptr,
                                                     &bytes_read);
 
@@ -17156,11 +17156,7 @@ get_debug_line_section (struct dwarf2_cu *cu)
   if (cu->dwo_unit && cu->per_cu->is_debug_types)
     section = &cu->dwo_unit->dwo_file->sections.line;
   else if (cu->per_cu->is_dwz)
-    {
-      dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd, true);
-
-      section = &dwz->line;
-    }
+    section = &per_objfile->per_bfd->get_dwz_file (true)->line;
   else
     section = &per_objfile->per_bfd->line;
 
index 7a98eb4f66e15bf3b57181f7bd5ffa5402cffd7d..612f575510c8b2fadbeb126a7487c2fc91d23a7e 100644 (file)
@@ -491,6 +491,26 @@ struct dwarf2_per_bfd
     return this->all_comp_units_index_tus[index];
   }
 
+  /* Return the separate '.dwz' debug file.  If there is no
+     .gnu_debugaltlink section in the file, then the result depends on
+     REQUIRE: if REQUIRE is true, error out; if REQUIRE is false,
+     return nullptr.  */
+  struct dwz_file *get_dwz_file (bool require = false)
+  {
+    gdb_assert (!require || this->dwz_file.has_value ());
+
+    struct dwz_file *result = nullptr;
+
+    if (this->dwz_file.has_value ())
+      {
+       result = this->dwz_file->get ();
+       if (require && result == nullptr)
+         error (_("could not read '.gnu_debugaltlink' section"));
+      }
+
+    return result;
+  }
+
   /* A convenience function to allocate a dwarf2_per_cu.  The returned object
      has its "index" field set properly.  The object is allocated on the
      dwarf2_per_bfd obstack.  */