]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/dwarf: add dwarf2_per_bfd::filename and use it where possible
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 26 Feb 2025 04:24:28 +0000 (23:24 -0500)
committerSimon Marchi <simon.marchi@polymtl.ca>
Fri, 28 Feb 2025 19:17:14 +0000 (14:17 -0500)
I noticed we quite often use:

    bfd_get_filename (per_bfd->obfd)

Add a shortcut for that.

Change-Id: I4e33925a481fd44088386510b01936d38e1d7d38
Approved-By: Andrew Burgess <aburgess@redhat.com>
gdb/dwarf2/dwz.c
gdb/dwarf2/index-cache.c
gdb/dwarf2/read.c
gdb/dwarf2/read.h

index af265505c019a09887e7105d6f1e8d30e1725ee3..e1e407f774c7cc88841d452e13dffcc2c9827b13 100644 (file)
@@ -213,8 +213,7 @@ dwarf2_read_dwz_file (dwarf2_per_objfile *per_objfile)
 
   if (!IS_ABSOLUTE_PATH (filename.c_str ()))
     {
-      gdb::unique_xmalloc_ptr<char> abs
-       = gdb_realpath (bfd_get_filename (per_bfd->obfd));
+      gdb::unique_xmalloc_ptr<char> abs = gdb_realpath (per_bfd->filename ());
 
       filename = ldirname (abs.get ()) + SLASH_STRING + filename;
     }
@@ -241,12 +240,9 @@ dwarf2_read_dwz_file (dwarf2_per_objfile *per_objfile)
   if (dwz_bfd == nullptr)
     {
       gdb::unique_xmalloc_ptr<char> alt_filename;
-      const char *origname = bfd_get_filename (per_bfd->obfd);
-
-      scoped_fd fd (debuginfod_debuginfo_query (buildid,
-                                               buildid_len,
-                                               origname,
-                                               &alt_filename));
+      scoped_fd fd
+       = debuginfod_debuginfo_query (buildid, buildid_len,
+                                     per_bfd->filename (), &alt_filename);
 
       if (fd.get () >= 0)
        {
@@ -263,7 +259,7 @@ dwarf2_read_dwz_file (dwarf2_per_objfile *per_objfile)
 
   if (dwz_bfd == NULL)
     error (_("could not find '.gnu_debugaltlink' file for %s"),
-          bfd_get_filename (per_bfd->obfd));
+          per_bfd->filename ());
 
   auto result = std::make_unique<dwz_file> (std::move (dwz_bfd));
 
index 9e3396ebd88c1029f551210d75d6e43e07fa0b78..6c344d7920d5810d03a6d084a069416f448b4056 100644 (file)
@@ -103,8 +103,7 @@ index_cache_store_context::index_cache_store_context (const index_cache &ic,
   const bfd_build_id *build_id = build_id_bfd_get (per_bfd->obfd);
   if (build_id == nullptr)
     {
-      index_cache_debug ("objfile %s has no build id",
-                        bfd_get_filename (per_bfd->obfd));
+      index_cache_debug ("objfile %s has no build id", per_bfd->filename ());
       m_enabled = false;
       return;
     }
@@ -149,7 +148,7 @@ index_cache_store_context::index_cache_store_context (const index_cache &ic,
   catch (const gdb_exception_error &except)
     {
       index_cache_debug ("couldn't store index cache for objfile %s: %s",
-                        bfd_get_filename (per_bfd->obfd), except.what ());
+                        per_bfd->filename (), except.what ());
       m_enabled = false;
     }
 }
@@ -169,7 +168,7 @@ index_cache_store_context::store () const
   try
     {
       index_cache_debug ("writing index cache for objfile %s",
-                        bfd_get_filename (m_per_bfd->obfd));
+                        m_per_bfd->filename ());
 
       /* Write the index itself to the directory, using the build id as the
         filename.  */
@@ -180,7 +179,7 @@ index_cache_store_context::store () const
   catch (const gdb_exception_error &except)
     {
       index_cache_debug ("couldn't store index cache for objfile %s: %s",
-                        bfd_get_filename (m_per_bfd->obfd), except.what ());
+                        m_per_bfd->filename (), except.what ());
     }
 }
 
index 59d79af004ca7b4e196838943223fa1734615625..b377b07cf7ce761e0052da66d3ab1f6c46c434e9 100644 (file)
@@ -3109,7 +3109,7 @@ lookup_dwo_unit (dwarf2_cu *cu, die_info *comp_unit_die, const char *dwo_name)
        error (_(DWARF_ERROR_PREFIX
                 "missing dwo_id for dwo_name %s"
                 " [in module %s]"),
-              dwo_name, bfd_get_filename (per_cu->per_bfd->obfd));
+              dwo_name, per_cu->per_bfd->filename ());
 
       dwo_unit = lookup_dwo_comp_unit (cu, dwo_name, comp_dir, *signature);
     }
@@ -7757,7 +7757,7 @@ create_dwp_v2_or_v5_section (dwarf2_per_bfd *per_bfd,
               "Bad DWP V2 or V5 section info, doesn't fit in section %s"
               " [in module %s]"),
             sectp ? bfd_section_name (sectp) : "<unknown>",
-            bfd_get_filename (per_bfd->obfd));
+            per_bfd->filename ());
     }
 
   result.virtual_offset = offset;
@@ -8221,7 +8221,7 @@ try_open_dwop_file (dwarf2_per_bfd *per_bfd, const char *file_name, int is_dwp,
     search_path = per_bfd->captured_debug_dir.c_str ();
 
   /* Add the path for the executable binary to the list of search paths.  */
-  std::string objfile_dir = ldirname (bfd_get_filename (per_bfd->obfd));
+  std::string objfile_dir = ldirname (per_bfd->filename ());
   search_path_holder.reset (concat (objfile_dir.c_str (),
                                    dirname_separator_string,
                                    search_path, nullptr));
@@ -20922,7 +20922,7 @@ dwarf2_find_containing_comp_unit (sect_offset sect_off,
        error (_(DWARF_ERROR_PREFIX
                 "could not find CU containing offset %s [in module %s]"),
               sect_offset_str (sect_off),
-              bfd_get_filename (per_bfd->obfd));
+              per_bfd->filename ());
 
       gdb_assert (per_bfd->all_units[low-1]->sect_off
                  <= sect_off);
index 4463015d98d2a5ea91ddcf66d6b17b961d3af3bd..fcb7d403d9fa5420f542cb32f1572d4def929d8f 100644 (file)
@@ -468,6 +468,10 @@ struct dwarf2_per_bfd
 
   DISABLE_COPY_AND_ASSIGN (dwarf2_per_bfd);
 
+  /* Return the filename of the BFD.  */
+  const char *filename () const
+  { return bfd_get_filename (this->obfd); }
+
   /* Return the CU given its index.  */
   dwarf2_per_cu_data *get_cu (int index) const
   {