[binutils-gdb] gdb/dwarf: make dwarf2_get_dwz_file a method of dwarf2_per_bfd

Simon Marchi simark@sourceware.org
Tue Mar 4 15:55:19 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=66195fe109289637e6f1668464c660e782c519f9

commit 66195fe109289637e6f1668464c660e782c519f9
Author: Simon Marchi <simon.marchi@efficios.com>
Date:   Mon Mar 3 16:35:36 2025 -0500

    gdb/dwarf: make dwarf2_get_dwz_file a method of dwarf2_per_bfd
    
    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>

Diff:
---
 gdb/dwarf2/dwz.c              | 17 -----------------
 gdb/dwarf2/dwz.h              |  8 --------
 gdb/dwarf2/index-cache.c      |  2 +-
 gdb/dwarf2/index-write.c      |  2 +-
 gdb/dwarf2/macro.c            |  6 ++----
 gdb/dwarf2/read-debug-names.c |  4 ++--
 gdb/dwarf2/read-gdb-index.c   |  5 ++---
 gdb/dwarf2/read.c             | 12 ++++--------
 gdb/dwarf2/read.h             | 20 ++++++++++++++++++++
 9 files changed, 32 insertions(+), 44 deletions(-)

diff --git a/gdb/dwarf2/dwz.c b/gdb/dwarf2/dwz.c
index e1e407f774c..f36d6a6418a 100644
--- a/gdb/dwarf2/dwz.c
+++ b/gdb/dwarf2/dwz.c
@@ -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;
-}
diff --git a/gdb/dwarf2/dwz.h b/gdb/dwarf2/dwz.h
index 13b7692070f..cd5143ff084 100644
--- a/gdb/dwarf2/dwz.h
+++ b/gdb/dwarf2/dwz.h
@@ -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
diff --git a/gdb/dwarf2/index-cache.c b/gdb/dwarf2/index-cache.c
index 6c344d7920d..7617bd709b9 100644
--- a/gdb/dwarf2/index-cache.c
+++ b/gdb/dwarf2/index-cache.c
@@ -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)
     {
diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c
index 1d0dacb4b52..fc78cfda613 100644
--- a/gdb/dwarf2/index-write.c
+++ b/gdb/dwarf2/index-write.c
@@ -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)
diff --git a/gdb/dwarf2/macro.c b/gdb/dwarf2/macro.c
index 9ab9b345ef6..2d9d4b7bbcf 100644
--- a/gdb/dwarf2/macro.c
+++ b/gdb/dwarf2/macro.c
@@ -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 ();
diff --git a/gdb/dwarf2/read-debug-names.c b/gdb/dwarf2/read-debug-names.c
index 34db3dbee79..2cd32d09abe 100644
--- a/gdb/dwarf2/read-debug-names.c
+++ b/gdb/dwarf2/read-debug-names.c
@@ -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,
diff --git a/gdb/dwarf2/read-gdb-index.c b/gdb/dwarf2/read-gdb-index.c
index 282ac5b4ef4..e513e80ffce 100644
--- a/gdb/dwarf2/read-gdb-index.c
+++ b/gdb/dwarf2/read-gdb-index.c
@@ -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;
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 0bef46a10e4..a10659039bc 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -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;
 
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index 7a98eb4f66e..612f575510c 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -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.  */


More information about the Gdb-cvs mailing list