]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb] Add gdb_bfd_check_format and gdb_bfd_check_format_matches
authorTom de Vries <tdevries@suse.de>
Thu, 28 May 2026 20:16:46 +0000 (22:16 +0200)
committerTom de Vries <tdevries@suse.de>
Thu, 28 May 2026 20:16:46 +0000 (22:16 +0200)
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 <tom@tromey.com>
19 files changed:
gdb/build-id.c
gdb/cli/cli-dump.c
gdb/compile/compile-object-load.c
gdb/corelow.c
gdb/dwarf2/dwz.c
gdb/dwarf2/read.c
gdb/exec.c
gdb/gdb_bfd.c
gdb/gdb_bfd.h
gdb/i386-darwin-tdep.c
gdb/jit.c
gdb/machoread.c
gdb/minidebug.c
gdb/solib-aix.c
gdb/solib-rocm.c
gdb/solib.c
gdb/symfile-mem.c
gdb/symfile.c
gdb/windows-nat.c

index b49216d4cad77f359f92f4dbfc172d7938e11900..123d87e519cc2d05dc4f0a3c77f61934dc3214e1 100644 (file)
@@ -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)
index 66ab5922693e157e8fc8aacf732b15ccfe3c0ba6..6c6abaa9de32ef24e64dcfcf89694d25a6397249 100644 (file)
@@ -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));
 
index 4ea924582fb34f5e1c703bd2d845849d2ff4a196..20e4c3e51ceffa90ad7dbf69cb4a70eee2e9f336 100644 (file)
@@ -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 ());
index 008da68155f6fbdcdbbbd3d7e845c8dc7eb840ab..819e7cae6f98a6568e815bd1765a2f7bfb8c41fe 100644 (file)
@@ -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
index 8f3d52567ec5962ca557020baa3f524b12a12578..e61e7fd76053ccfefc4fe20cda3b94964eae576a 100644 (file)
@@ -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)
index c761b7328196fdfb55fc44519728ba15f6dcc5e4..8067af5f52e1cd9b6d21a172184b65e895358ff8 100644 (file)
@@ -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.
index 873686e628654c6f13cdf52006e798c119470854..36ec45c14bc94ef1f7780533ad5c633c1aaf6e97 100644 (file)
@@ -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
index 952875955ad546551886c41c7c1b956e08f9be75..7a845d6e04b5d9058740719f14b8b6d8dc277b24 100644 (file)
@@ -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
index 69bfa3011aaac2d3241c8751685c6888ade01d58..ff9f2337e6e59344a3b9063fea56ec60a420259d 100644 (file)
@@ -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 */
index b9ea7cb3f362fe38235499b358975b5a68da6142..f7512eaf9a3b8ad15727307a8cd33f5c51f1dc13 100644 (file)
@@ -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)
index 5fa3869316c32b89a5da75247afb28895852d911..251e8331c4a9ef3b7b08210eb0af1f0ed320b6d0 100644 (file)
--- 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"));
index 6bd063a89e93fb3e33f33c38b449209cf5c27ba6..d273ec2ef90fb2e182e327ca0b03abbcfe2bbe01 100644 (file)
@@ -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;
index 10222ec233d0687d202ee31b76c6e6564901c653..8c84b7c966405ae46cfd97ff9a0fd116ca5f3ecb 100644 (file)
@@ -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;
index 4f02952910644bf67f9ea1fe31915914b2ab15dc..705760651217d820cc2f4ebbc039577be2ae2feb 100644 (file)
@@ -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 ()),
index 38904b9633cb72928dd81626ca438fea4286d418..34cb2bb9e57ce9cc379f8fd40885a2da0914bf25 100644 (file)
@@ -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 ()));
 
index 158c58d96890d2373228299152054c667de91e3e..d92d0dd9a3dd064fb186b0090c06c258203eed79 100644 (file)
@@ -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 {};
 
index 941292d3128a430e2bc420882a89a11f75b1b7ed..7d86fd882289fa71514f5ec49881a2bfc346719b 100644 (file)
@@ -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 ()));
 
index 0413f7f7ce1ba5dd10402787a3573cc819db5c2d..5f046a03567eccbddeb9859b088496c3e2698037 100644 (file)
@@ -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)),
index a284438bd36dacbc59a6fbe44b826dd3a5c77874..d9e924f16c6e5d362281623191a2ece046e5c71a 100644 (file)
@@ -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)