From: Simon Marchi Date: Wed, 26 Feb 2025 04:24:28 +0000 (-0500) Subject: gdb/dwarf: add dwarf2_per_bfd::filename and use it where possible X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cb9995e8d8fab4e48ba202fe8456e68cc130490a;p=thirdparty%2Fbinutils-gdb.git 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 --- diff --git a/gdb/dwarf2/dwz.c b/gdb/dwarf2/dwz.c index af265505c01..e1e407f774c 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 abs - = gdb_realpath (bfd_get_filename (per_bfd->obfd)); + gdb::unique_xmalloc_ptr 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 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 (std::move (dwz_bfd)); diff --git a/gdb/dwarf2/index-cache.c b/gdb/dwarf2/index-cache.c index 9e3396ebd88..6c344d7920d 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 59d79af004c..b377b07cf7c 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) : "", - 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 4463015d98d..fcb7d403d9f 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 {