]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: remove program_space::core_bfd member function
authorAndrew Burgess <aburgess@redhat.com>
Wed, 10 Sep 2025 10:04:45 +0000 (11:04 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Wed, 8 Oct 2025 12:29:06 +0000 (13:29 +0100)
This commit removes the program_space::core_bfd member function, which
was left in place as a temporary hack in the last commit in order to
reduce the size of the last commit.

In every place that 'current_program_space->core_bfd ()' was used I
now call 'get_inferior_core_bfd (current_inferior ())'.

I think there is further scope for improving things in the future,
reducing the number of times we access the core file via global state,
but doing that cleanup might be more involved than the clean up I've
done up to this point.  So I'm leaving that work for the future.

But I think in some places, at the top level (e.g. user command
functions), there's always going to be some cases where we just need
to access the current global state, this is just the nature of the
command handlers.

There should be no user visible changes after this commit.

Approved-By: Tom Tromey <tom@tromey.com>
13 files changed:
gdb/corefile.c
gdb/corelow.c
gdb/fbsd-tdep.c
gdb/linux-tdep.c
gdb/linux-thread-db.c
gdb/maint.c
gdb/progspace.c
gdb/progspace.h
gdb/record-full.c
gdb/sol-thread.c
gdb/solib-dsbt.c
gdb/solib-frv.c
gdb/symfile-mem.c

index a2c75c02c2f0440d937a77a09a1a1079f40567f9..666ff55e81416ceab0f61cd206052a1dbda1a694 100644 (file)
@@ -66,13 +66,14 @@ reopen_exec_file (void)
 void
 validate_files (void)
 {
-  if (current_program_space->exec_bfd () && current_program_space->core_bfd ())
+  bfd *ebfd = current_program_space->exec_bfd ();
+  bfd *cbfd = get_inferior_core_bfd (current_inferior ());
+
+  if (ebfd != nullptr && cbfd != nullptr)
     {
-      if (!core_file_matches_executable_p (current_program_space->core_bfd (),
-                                          current_program_space->exec_bfd ()))
+      if (!core_file_matches_executable_p (cbfd, ebfd))
        warning (_("core file may not match specified executable file."));
-      else if (gdb_bfd_get_mtime (current_program_space->exec_bfd ())
-              > gdb_bfd_get_mtime (current_program_space->core_bfd ()))
+      else if (gdb_bfd_get_mtime (ebfd) > gdb_bfd_get_mtime (cbfd))
        warning (_("exec file is newer than core file."));
     }
 }
index 6175e967a33084219a77d3d16710758a3ccd28b0..d48154de1f57370921bd0c3d04d091519ec1ea46 100644 (file)
@@ -1015,7 +1015,7 @@ core_target_open (const char *arg, int from_tty)
   gdb_assert (current_inferior ()->process_target () == nullptr);
 
   /* Which will clear up any existing core file BFD.  */
-  gdb_assert (current_program_space->core_bfd () == nullptr);
+  gdb_assert (get_inferior_core_bfd (current_inferior ()) == nullptr);
 
   std::string filename = extract_single_filename_arg (arg);
 
index c0a93e8871a34b76b2f61611a85a23f664b6181b..a2f000b87cbb8a55e4239939cb8c84ea937bbe5a 100644 (file)
@@ -2317,7 +2317,7 @@ fbsd_vdso_range (struct gdbarch *gdbarch, struct mem_range *range)
   if (!target_has_execution ())
     {
       /* Search for the ending address in the NT_PROCSTAT_VMMAP note. */
-      bfd *cbfd = current_program_space->core_bfd ();
+      bfd *cbfd = get_inferior_core_bfd (current_inferior ());
       asection *section = bfd_get_section_by_name (cbfd,
                                                   ".note.freebsdcore.vmmap");
       if (section == nullptr)
index 3c813f51d4ffba6ea4c2f19da337f6b488192e3c..77557d53fde7f7742bc6f4f358feeb2d67b6b48f 100644 (file)
@@ -1511,12 +1511,13 @@ linux_process_address_in_memtag_page (CORE_ADDR address)
 static bool
 linux_core_file_address_in_memtag_page (CORE_ADDR address)
 {
-  if (current_program_space->core_bfd () == nullptr)
+  bfd *cbfd = get_inferior_core_bfd (current_inferior ());
+
+  if (cbfd == nullptr)
     return false;
 
   memtag_section_info info;
-  return get_next_core_memtag_section (current_program_space->core_bfd (),
-                                      nullptr, address, info);
+  return get_next_core_memtag_section (cbfd, nullptr, address, info);
 }
 
 /* See linux-tdep.h.  */
@@ -2693,15 +2694,14 @@ linux_vsyscall_range_raw (struct gdbarch *gdbarch, struct mem_range *range)
       long phdrs_size;
       int num_phdrs, i;
 
-      phdrs_size
-       = bfd_get_elf_phdr_upper_bound (current_program_space->core_bfd ());
+      bfd *cbfd = get_inferior_core_bfd (current_inferior ());
+      phdrs_size = bfd_get_elf_phdr_upper_bound (cbfd);
       if (phdrs_size == -1)
        return 0;
 
       gdb::unique_xmalloc_ptr<Elf_Internal_Phdr>
        phdrs ((Elf_Internal_Phdr *) xmalloc (phdrs_size));
-      num_phdrs = bfd_get_elf_phdrs (current_program_space->core_bfd (),
-                                    phdrs.get ());
+      num_phdrs = bfd_get_elf_phdrs (cbfd, phdrs.get ());
       if (num_phdrs == -1)
        return 0;
 
index 63e4c69c9817d3bbda23d4d53eb790522db3df02..f00e3b53375e8ae16a7ef04d7ad00c7210f00a30 100644 (file)
@@ -1215,7 +1215,8 @@ thread_db_load (void)
     return false;
 
   /* Don't attempt to use thread_db for remote targets.  */
-  if (!(target_can_run () || current_program_space->core_bfd () != nullptr))
+  if (!(target_can_run ()
+       || get_inferior_core_bfd (current_inferior ()) != nullptr))
     return false;
 
   if (thread_db_load_search ())
index ca7648f1030df4ac20556b179db163e91232e641..576582925c63d7fe4a4513fa0bbcd98e4c98bc5b 100644 (file)
@@ -39,6 +39,7 @@
 #include "gdbsupport/thread-pool.h"
 #include "event-top.h"
 #include "cp-support.h"
+#include "gdbcore.h"
 
 #include "cli/cli-decode.h"
 #include "cli/cli-utils.h"
@@ -474,9 +475,9 @@ maintenance_info_sections (const char *arg, int from_tty)
                                  &ofile, arg);
     }
 
-  if (current_program_space->core_bfd () != nullptr)
-    maint_print_all_sections (_("Core file: "),
-                             current_program_space->core_bfd (), nullptr, arg);
+  bfd *cbfd = get_inferior_core_bfd (current_inferior ());
+  if (cbfd != nullptr)
+    maint_print_all_sections (_("Core file: "), cbfd, nullptr, arg);
 }
 
 /* Implement the "maintenance info target-sections" command.  */
index 59b9c8c6b31fc70511152bece8dec15a3eabc98a..6ee0134f20b822da13f0e64ec82a0c89942ef85d 100644 (file)
@@ -436,19 +436,6 @@ update_address_spaces (void)
 
 /* See progspace.h.  */
 
-bfd *
-program_space::core_bfd () const
-{
-  /* This only works because we (currently) never call the core_bfd method
-     on anything other than the current program space.  Don't worry too
-     much, this is a temporary bodge, and will be removed in the next
-     commit.  */
-  gdb_assert (this == current_program_space);
-  return get_inferior_core_bfd (current_inferior ());
-}
-
-/* See progspace.h.  */
-
 void
 program_space::clear_solib_cache ()
 {
index 302520e85f462debd3c9d49ac0f25ae958e58e56..1cf60420f73938cd8d21e920029b8624fd32117a 100644 (file)
@@ -292,8 +292,6 @@ struct program_space
     ebfd = std::move (abfd);
   }
 
-  bfd *core_bfd () const;
-
   /* Reset saved solib data at the start of an solib event.  This lets
      us properly collect the data when calling solib_add, so it can then
      later be printed.  */
index 22227c33c2a5ee76ea2ce6e24bf8b572dcaacc77..396ba3283e13e75c7338013eb0516b4256052216 100644 (file)
@@ -987,8 +987,9 @@ record_full_open (const char *args, int from_tty)
   record_full_list = &record_full_first;
   record_full_list->next = NULL;
 
-  if (current_program_space->core_bfd () != nullptr)
-    record_full_core_open_1 (*current_program_space->core_bfd ());
+  bfd *cbfd = get_inferior_core_bfd (current_inferior ());
+  if (cbfd != nullptr)
+    record_full_core_open_1 (*cbfd);
   else
     record_full_open_1 ();
 
index 55e1d3e2595f4976da4328d5a59c13c1cdb1034c..0aa45950696e1d42ab31a052c11215c00129a013 100644 (file)
@@ -605,7 +605,8 @@ check_for_thread_db (void)
   ptid_t ptid;
 
   /* Don't attempt to use thread_db for remote targets.  */
-  if (!(target_can_run () || current_program_space->core_bfd () != nullptr))
+  if (!(target_can_run ()
+       || get_inferior_core_bfd(current_inferior ()) != nullptr))
     return;
 
   /* Do nothing if we couldn't load libthread_db.so.1.  */
index 719678b56aad3a1c54fed65d45351a6e1d9b0871..883164eda0445ec9013a450578a6b865438e4ac7 100644 (file)
@@ -27,6 +27,7 @@
 #include "solib-dsbt.h"
 #include "elf/common.h"
 #include "cli/cli-cmds.h"
+#include "gdbcore.h"
 
 #define GOT_MODULE_OFFSET 4
 
@@ -549,7 +550,7 @@ dsbt_solib_ops::current_sos () const
      solib_create_inferior_hook.   (See post_create_inferior in
      infcmd.c.)  */
   if (info->main_executable_lm_info == 0
-      && current_program_space->core_bfd () != nullptr)
+      && get_inferior_core_bfd (current_inferior ()) != nullptr)
     dsbt_relocate_main_executable ();
 
   /* Locate the address of the first link map struct.  */
index ac5872e2938fd0f7c1d0f78c4226a1eb7f3e72be..beb880228fcd68d463f3f60312986e6f7b311684 100644 (file)
@@ -26,6 +26,7 @@
 #include "gdb_bfd.h"
 #include "inferior.h"
 #include "solib-frv.h"
+#include "gdbcore.h"
 
 /* solib_ops for FR-V systems.  */
 
@@ -341,7 +342,7 @@ frv_solib_ops::current_sos () const
      solib_create_inferior_hook().   (See post_create_inferior() in
      infcmd.c.)  */
   if (main_executable_lm_info == 0
-      && current_program_space->core_bfd () != nullptr)
+      && get_inferior_core_bfd (current_inferior ()) != nullptr)
     frv_relocate_main_executable ();
 
   /* Fetch the GOT corresponding to the main executable.  */
index 274dc0f57b9aa55f3d41d50b7357ca7ffc59d8b1..9bf79f7dbdf21f73de3bafd4468190b57b2e42c0 100644 (file)
@@ -166,8 +166,8 @@ add_vsyscall_page (inferior *inf)
     {
       struct bfd *bfd;
 
-      if (current_program_space->core_bfd () != nullptr)
-       bfd = current_program_space->core_bfd ();
+      if (get_inferior_core_bfd (current_inferior ()) != nullptr)
+       bfd = get_inferior_core_bfd (current_inferior ());
       else if (current_program_space->exec_bfd () != nullptr)
        bfd = current_program_space->exec_bfd ();
       else