aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@efficios.com>2025-02-25 23:24:28 -0500
committerSimon Marchi <simon.marchi@polymtl.ca>2025-02-28 14:17:14 -0500
commitcb9995e8d8fab4e48ba202fe8456e68cc130490a (patch)
treefabc739c009568ea8b37f39c71959323f15c8b23
parentc981932fc5c89205ff2c14ff1bf25d32fa7e3b0d (diff)
downloadbinutils-cb9995e8d8fab4e48ba202fe8456e68cc130490a.zip
binutils-cb9995e8d8fab4e48ba202fe8456e68cc130490a.tar.gz
binutils-cb9995e8d8fab4e48ba202fe8456e68cc130490a.tar.bz2
gdb/dwarf: add dwarf2_per_bfd::filename and use it where possible
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>
-rw-r--r--gdb/dwarf2/dwz.c14
-rw-r--r--gdb/dwarf2/index-cache.c9
-rw-r--r--gdb/dwarf2/read.c8
-rw-r--r--gdb/dwarf2/read.h4
4 files changed, 17 insertions, 18 deletions
diff --git a/gdb/dwarf2/dwz.c b/gdb/dwarf2/dwz.c
index af26550..e1e407f 100644
--- a/gdb/dwarf2/dwz.c
+++ b/gdb/dwarf2/dwz.c
@@ -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));
diff --git a/gdb/dwarf2/index-cache.c b/gdb/dwarf2/index-cache.c
index 9e3396e..6c344d7 100644
--- a/gdb/dwarf2/index-cache.c
+++ b/gdb/dwarf2/index-cache.c
@@ -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 ());
}
}
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 59d79af..b377b07 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -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);
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index 4463015..fcb7d40 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -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
{