[binutils-gdb] [gdb] Add gdb_bfd_check_format and gdb_bfd_check_format_matches
Tom de Vries via Gdb-cvs <[email protected]> Thu, 28 May 2026 20:16:51 +0000 (GMT)
| Newsgroups | gmane.comp.gdb.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=7f91647689e8fd3d9b1d07745f95ab12fbc24e7f commit 7f91647689e8fd3d9b1d07745f95ab12fbc24e7f Author: Tom de Vries <[email protected]> Date: Thu May 28 22:16:46 2026 +0200 [gdb] Add gdb_bfd_check_format and gdb_bfd_check_format_matches Add new bfd wrappers: - gdb_bfd_check_format for bfd_check_format, and - gdb_bfd_check_format_matches for bfd_check_format_matches. and run this command to use them: ... $ sed -i 's/bfd_check_format/gdb_bfd_check_format/' \ $(find gdb* -type f | egrep -v "/testsuite/|ChangeLog") ... No functional changes. Approved-By: Tom Tromey <[email protected]> Diff: --- gdb/build-id.c | 4 ++-- gdb/cli/cli-dump.c | 2 +- gdb/compile/compile-object-load.c | 2 +- gdb/corelow.c | 8 ++++---- gdb/dwarf2/dwz.c | 2 +- gdb/dwarf2/read.c | 2 +- gdb/exec.c | 2 +- gdb/gdb_bfd.c | 16 ++++++++++++++++ gdb/gdb_bfd.h | 11 ++++++++++- gdb/i386-darwin-tdep.c | 2 +- gdb/jit.c | 2 +- gdb/machoread.c | 6 +++--- gdb/minidebug.c | 2 +- gdb/solib-aix.c | 6 +++--- gdb/solib-rocm.c | 2 +- gdb/solib.c | 4 ++-- gdb/symfile-mem.c | 2 +- gdb/symfile.c | 6 +++--- gdb/windows-nat.c | 2 +- 19 files changed, 54 insertions(+), 29 deletions(-) diff --git a/gdb/build-id.c b/gdb/build-id.c index b49216d4cad..123d87e519c 100644 --- a/gdb/build-id.c +++ b/gdb/build-id.c @@ -42,8 +42,8 @@ build_id_bfd_get (bfd *abfd) if (abfd == nullptr) return nullptr; - if (!bfd_check_format (abfd, bfd_object) - && !bfd_check_format (abfd, bfd_core)) + if (!gdb_bfd_check_format (abfd, bfd_object) + && !gdb_bfd_check_format (abfd, bfd_core)) return NULL; if (abfd->build_id != NULL) diff --git a/gdb/cli/cli-dump.c b/gdb/cli/cli-dump.c index 66ab5922693..6c6abaa9de3 100644 --- a/gdb/cli/cli-dump.c +++ b/gdb/cli/cli-dump.c @@ -89,7 +89,7 @@ bfd_openr_or_error (const char *filename, const char *target) styled_string (file_name_style.style (), filename), bfd_errmsg (bfd_get_error ())); - if (!bfd_check_format (ibfd.get (), bfd_object)) + if (!gdb_bfd_check_format (ibfd.get (), bfd_object)) error (_("'%ps' is not a recognized file format."), styled_string (file_name_style.style (), filename)); diff --git a/gdb/compile/compile-object-load.c b/gdb/compile/compile-object-load.c index 4ea924582fb..20e4c3e51ce 100644 --- a/gdb/compile/compile-object-load.c +++ b/gdb/compile/compile-object-load.c @@ -621,7 +621,7 @@ compile_object_load (const compile_file_names &file_names, styled_string (file_name_style.style (), filename.get ()), bfd_errmsg (bfd_get_error ())); - if (!bfd_check_format_matches (abfd.get (), bfd_object, &matching)) + if (!gdb_bfd_check_format_matches (abfd.get (), bfd_object, &matching)) error (_("\"%ps\": not in loadable format: %s"), styled_string (file_name_style.style (), filename.get ()), gdb_bfd_errmsg (bfd_get_error (), matching).c_str ()); diff --git a/gdb/corelow.c b/gdb/corelow.c index 008da68155f..819e7cae6f9 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -450,7 +450,7 @@ core_target::build_file_mappings () = gdb_bfd_open (expanded_fname.get (), gnutarget); if (tmp_bfd != nullptr - && bfd_check_format (tmp_bfd.get (), bfd_object) + && gdb_bfd_check_format (tmp_bfd.get (), bfd_object) && build_id_bfd_get (tmp_bfd.get ()) != nullptr) { /* The newly opened TMP_BFD has a build-id, and this mapped @@ -469,7 +469,7 @@ core_target::build_file_mappings () if ((expanded_fname == nullptr || abfd == nullptr - || !bfd_check_format (abfd.get (), bfd_object)) + || !gdb_bfd_check_format (abfd.get (), bfd_object)) && file_data.build_id != nullptr) { abfd = find_objfile_by_build_id (current_program_space, @@ -492,7 +492,7 @@ core_target::build_file_mappings () if (expanded_fname == nullptr || abfd == nullptr - || !bfd_check_format (abfd.get (), bfd_object)) + || !gdb_bfd_check_format (abfd.get (), bfd_object)) { /* If ABFD was opened, but the wrong format, close it now. */ abfd = nullptr; @@ -1071,7 +1071,7 @@ core_target_open (const char *arg, int from_tty) if (temp_bfd == NULL) perror_with_name (filename.c_str ()); - if (!bfd_check_format (temp_bfd.get (), bfd_core)) + if (!gdb_bfd_check_format (temp_bfd.get (), bfd_core)) { /* Do it after the err msg */ /* FIXME: should be checking for errors from bfd_close (for one diff --git a/gdb/dwarf2/dwz.c b/gdb/dwarf2/dwz.c index 8f3d52567ec..e61e7fd7605 100644 --- a/gdb/dwarf2/dwz.c +++ b/gdb/dwarf2/dwz.c @@ -171,7 +171,7 @@ get_debug_sup_info (bfd *abfd, static bool verify_id (bfd *abfd, size_t len, const bfd_byte *buildid, bool dwarf5) { - if (!bfd_check_format (abfd, bfd_object)) + if (!gdb_bfd_check_format (abfd, bfd_object)) return false; if (dwarf5) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index c761b732819..8067af5f52e 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -6750,7 +6750,7 @@ try_open_dwop_file (dwarf2_per_bfd *per_bfd, const char *file_name, int is_dwp, static gdb::mutex mutex; gdb::lock_guard<gdb::mutex> lock (mutex); - if (!bfd_check_format (sym_bfd.get (), bfd_object)) + if (!gdb_bfd_check_format (sym_bfd.get (), bfd_object)) return NULL; /* Success. Record the bfd as having been included by the objfile's bfd. diff --git a/gdb/exec.c b/gdb/exec.c index 873686e6286..36ec45c14bc 100644 --- a/gdb/exec.c +++ b/gdb/exec.c @@ -479,7 +479,7 @@ exec_file_attach (const char *filename, int from_tty) (make_unique_xstrdup (gdb_realpath_keepfile (scratch_pathname).c_str ())); - if (!bfd_check_format_matches (current_program_space->exec_bfd (), + if (!gdb_bfd_check_format_matches (current_program_space->exec_bfd (), bfd_object, &matching)) { /* Make sure to close exec_bfd, or else "run" might try to use diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c index 952875955ad..7a845d6e04b 100644 --- a/gdb/gdb_bfd.c +++ b/gdb/gdb_bfd.c @@ -1200,6 +1200,22 @@ gdb_bfd_canonicalize_symtab (bfd *abfd, bool should_throw) symbol_table.size () - 1); } +/* See gdb_bfd.h. */ + +bool +gdb_bfd_check_format (bfd *abfd, bfd_format format) +{ + return bfd_check_format (abfd, format); +} + +/* See gdb_bfd.h. */ + +bool +gdb_bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching) +{ + return bfd_check_format_matches (abfd, format, matching); +} + /* Implement the 'maint info bfd' command. */ static void diff --git a/gdb/gdb_bfd.h b/gdb/gdb_bfd.h index 69bfa3011aa..ff9f2337e6e 100644 --- a/gdb/gdb_bfd.h +++ b/gdb/gdb_bfd.h @@ -268,7 +268,7 @@ extern long gdb_bfd_get_mtime (bfd *abfd) /* A wrapper for bfd_errmsg to produce a more helpful error message in the case of bfd_error_file_ambiguously recognized. MATCHING, if non-NULL, is the corresponding argument to - bfd_check_format_matches, and will be freed. */ + gdb_bfd_check_format_matches, and will be freed. */ extern std::string gdb_bfd_errmsg (bfd_error_type error_tag, char **matching); @@ -289,4 +289,13 @@ extern void gdb_bfd_init (); extern gdb::array_view<asymbol *> gdb_bfd_canonicalize_symtab (bfd *abfd, bool should_throw = true); +/* A wrapper for bfd_check_format. */ + +extern bool gdb_bfd_check_format (bfd *abfd, bfd_format format); + +/* A wrapper for bfd_check_format_matches. */ + +extern bool gdb_bfd_check_format_matches (bfd *abfd, bfd_format format, + char ***matching); + #endif /* GDB_GDB_BFD_H */ diff --git a/gdb/i386-darwin-tdep.c b/gdb/i386-darwin-tdep.c index b9ea7cb3f36..f7512eaf9a3 100644 --- a/gdb/i386-darwin-tdep.c +++ b/gdb/i386-darwin-tdep.c @@ -277,7 +277,7 @@ i386_darwin_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) static enum gdb_osabi i386_mach_o_osabi_sniffer (bfd *abfd) { - if (!bfd_check_format (abfd, bfd_object)) + if (!gdb_bfd_check_format (abfd, bfd_object)) return GDB_OSABI_UNKNOWN; if (bfd_get_arch (abfd) == bfd_arch_i386) diff --git a/gdb/jit.c b/gdb/jit.c index 5fa3869316c..251e8331c4a 100644 --- a/gdb/jit.c +++ b/gdb/jit.c @@ -782,7 +782,7 @@ jit_bfd_try_read_symtab (struct jit_code_entry *code_entry, /* Check the format. NOTE: This initializes important data that GDB uses! We would segfault later without this line. */ - if (!bfd_check_format (nbfd.get (), bfd_object)) + if (!gdb_bfd_check_format (nbfd.get (), bfd_object)) { gdb_printf (gdb_stderr, _("\ JITed symbol file is not an object file, ignoring it.\n")); diff --git a/gdb/machoread.c b/gdb/machoread.c index 6bd063a89e9..d273ec2ef90 100644 --- a/gdb/machoread.c +++ b/gdb/machoread.c @@ -422,7 +422,7 @@ macho_add_oso_symfile (oso_el *oso, const gdb_bfd_ref_ptr &abfd, macho_debug (0, _("Loading debugging symbols from oso: %s\n"), oso->name); - if (!bfd_check_format (abfd.get (), bfd_object)) + if (!gdb_bfd_check_format (abfd.get (), bfd_object)) { warning (_("`%s': can't read symbols: %s."), oso->name, bfd_errmsg (bfd_get_error ())); @@ -634,7 +634,7 @@ macho_symfile_read_all_oso (std::vector<oso_el> *oso_vector_ptr, ix = last_ix; continue; } - if (!bfd_check_format (archive_bfd.get (), bfd_archive)) + if (!gdb_bfd_check_format (archive_bfd.get (), bfd_archive)) { warning (_("OSO archive file \"%s\" not an archive."), archive_name.c_str ()); @@ -748,7 +748,7 @@ macho_check_dsym (struct objfile *objfile, std::string *filenamep) return NULL; } - if (!bfd_check_format (dsym_bfd.get (), bfd_object)) + if (!gdb_bfd_check_format (dsym_bfd.get (), bfd_object)) { warning (_("bad dsym file format: %s"), bfd_errmsg (bfd_get_error ())); return NULL; diff --git a/gdb/minidebug.c b/gdb/minidebug.c index 10222ec233d..8c84b7c9664 100644 --- a/gdb/minidebug.c +++ b/gdb/minidebug.c @@ -251,7 +251,7 @@ find_separate_debug_file_in_section (struct objfile *objfile) if (abfd == NULL) return NULL; - if (!bfd_check_format (abfd.get (), bfd_object)) + if (!gdb_bfd_check_format (abfd.get (), bfd_object)) { warning (_("Cannot parse .gnu_debugdata section; not a BFD object")); return NULL; diff --git a/gdb/solib-aix.c b/gdb/solib-aix.c index 4f029529106..70576065121 100644 --- a/gdb/solib-aix.c +++ b/gdb/solib-aix.c @@ -547,10 +547,10 @@ aix_solib_ops::bfd_open (const char *pathname) const return NULL; } - if (bfd_check_format (archive_bfd.get (), bfd_object)) + if (gdb_bfd_check_format (archive_bfd.get (), bfd_object)) return archive_bfd; - if (! bfd_check_format (archive_bfd.get (), bfd_archive)) + if (! gdb_bfd_check_format (archive_bfd.get (), bfd_archive)) { warning (_("\"%ps\": not in executable format: %s."), styled_string (file_name_style.style (), filename.c_str ()), @@ -590,7 +590,7 @@ aix_solib_ops::bfd_open (const char *pathname) const return NULL; } - if (! bfd_check_format (object_bfd.get (), bfd_object)) + if (! gdb_bfd_check_format (object_bfd.get (), bfd_object)) { warning (_("%ps(%s): not in object format: %s."), styled_string (file_name_style.style (), filename.c_str ()), diff --git a/gdb/solib-rocm.c b/gdb/solib-rocm.c index 38904b9633c..34cb2bb9e57 100644 --- a/gdb/solib-rocm.c +++ b/gdb/solib-rocm.c @@ -677,7 +677,7 @@ rocm_solib_ops::bfd_open (const char *pathname) const bfd_errmsg (bfd_get_error ())); /* Check bfd format. */ - if (!bfd_check_format (abfd.get (), bfd_object)) + if (!gdb_bfd_check_format (abfd.get (), bfd_object)) error (_("`%s': not in executable format: %s"), bfd_get_filename (abfd.get ()), bfd_errmsg (bfd_get_error ())); diff --git a/gdb/solib.c b/gdb/solib.c index 158c58d9689..d92d0dd9a3d 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -419,7 +419,7 @@ solib_bfd_open (const char *pathname) gdb_bfd_ref_ptr abfd (solib_bfd_fopen (found_pathname.get (), found_file)); /* Check bfd format. */ - if (!bfd_check_format (abfd.get (), bfd_object)) + if (!gdb_bfd_check_format (abfd.get (), bfd_object)) error (_("`%ps': not in executable format: %s"), styled_string (file_name_style.style (), bfd_get_filename (abfd.get ())), @@ -1683,7 +1683,7 @@ gdb_bfd_read_elf_soname (const char *filename) return {}; /* Check that ABFD is an ET_DYN ELF file. */ - if (!bfd_check_format (abfd.get (), bfd_object) + if (!gdb_bfd_check_format (abfd.get (), bfd_object) || !(bfd_get_file_flags (abfd.get ()) & DYNAMIC)) return {}; diff --git a/gdb/symfile-mem.c b/gdb/symfile-mem.c index 941292d3128..7d86fd88228 100644 --- a/gdb/symfile-mem.c +++ b/gdb/symfile-mem.c @@ -108,7 +108,7 @@ symbol_file_add_from_memory (struct bfd *templ, CORE_ADDR addr, name = "shared object read from target memory"; bfd_set_filename (nbfd, name); - if (!bfd_check_format (nbfd, bfd_object)) + if (!gdb_bfd_check_format (nbfd, bfd_object)) error (_("Got object file from memory but can't read symbols: %s."), bfd_errmsg (bfd_get_error ())); diff --git a/gdb/symfile.c b/gdb/symfile.c index 0413f7f7ce1..5f046a03567 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -1706,7 +1706,7 @@ symfile_bfd_open (const char *name) styled_string (file_name_style.style (), name), bfd_errmsg (bfd_get_error ())); - if (!bfd_check_format (sym_bfd.get (), bfd_object)) + if (!gdb_bfd_check_format (sym_bfd.get (), bfd_object)) error (_("`%ps': can't read symbols: %s."), styled_string (file_name_style.style (), name), bfd_errmsg (bfd_get_error ())); @@ -2018,7 +2018,7 @@ generic_load (const char *args, int from_tty) if (loadfile_bfd == NULL) perror_with_name (filename.get ()); - if (!bfd_check_format (loadfile_bfd.get (), bfd_object)) + if (!gdb_bfd_check_format (loadfile_bfd.get (), bfd_object)) error (_("\"%ps\" is not an object file: %s"), styled_string (file_name_style.style (), filename.get ()), bfd_errmsg (bfd_get_error ())); @@ -2564,7 +2564,7 @@ reread_symbols (int from_tty) std::string original_name = objfile.original_name; /* bfd_openr sets cacheable to true, which is what we want. */ - if (!bfd_check_format (objfile.obfd.get (), bfd_object)) + if (!gdb_bfd_check_format (objfile.obfd.get (), bfd_object)) error (_("Can't read symbols from %ps: %s."), styled_string (file_name_style.style (), objfile_name (&objfile)), diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index a284438bd36..d9e924f16c6 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -699,7 +699,7 @@ windows_make_so (const char *name, LPVOID load_addr) if (abfd == NULL) return so; - if (bfd_check_format (abfd.get (), bfd_object)) + if (gdb_bfd_check_format (abfd.get (), bfd_object)) text = bfd_get_section_by_name (abfd.get (), ".text"); if (!text)