]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: move core file bfd from program_space into core_target
authorAndrew Burgess <aburgess@redhat.com>
Wed, 8 Oct 2025 10:18:07 +0000 (11:18 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Wed, 8 Oct 2025 12:29:06 +0000 (13:29 +0100)
This commit moves the 'gdb_bfd_ref_ptr cbfd' out of program_space and
into core_target, where it is now called m_core_bfd.

I believe this change makes sense as the core_target instance holds
additional information that is parsed from the core file BFD, and so
storing the parsed information separately from the BFD doesn't make
much sense to me.

To minimise the churn in this commit, I have retained the
program_space::core_bfd member function as a temporary hack.  This
function forwards the request to the new function
get_inferior_core_bfd.  This works fine for now as
program_space::core_bfd is, after this commit, only called on the
current_program_space.  If this all seems like a total hack, then it
is, but don't worry too much, the next commit will clean this all up.

I was tempted to make the new function get_inferior_core_bfd, a member
function of the inferior class, inferior::core_bfd.  In fact, that
would have been my preferred change.  However, the new function needs
visibility of the core_target class, which, right now is private
within the corelow.c file.

This shouldn't be a problem, we could just declare the member function
in inferior.h, and implement the function in corelow.c.  But this
would mean the implementation of inferior::core_bfd, would not live in
inferior.c.  Previously when I've implemented member functions outside
their natural home (e.g. an inferior function not in inferior.c) I've
received review feedback that this is not desirable.  So, for now,
I've gone with a free function.

I also needed to change get_current_core_target, renaming it to
get_core_target, and taking an inferior as an argument.  Existing call
sites are updated to pass 'current_inferior ()', but
get_inferior_core_bfd passes something that might not be the current
inferior.

There should be no user visible changes after this commit.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/arch-utils.c
gdb/corelow.c
gdb/gdbcore.h
gdb/inferior.c
gdb/progspace.c
gdb/progspace.h
gdb/python/py-corefile.c

index f2af80e70405d27d9efbb67ac79115179ff681a1..377694537bd43bf803a96ca2bdec42186e4c1dc1 100644 (file)
@@ -592,7 +592,7 @@ gdbarch_update_p (inferior *inf, struct gdbarch_info info)
     info.abfd = inf->pspace->exec_bfd ();
 
   if (info.abfd == NULL)
-    info.abfd = inf->pspace->core_bfd ();
+    info.abfd = get_inferior_core_bfd (inf);
 
   /* Check for the current target description.  */
   if (info.target_desc == NULL)
index ee97e29556e5545fba5702f4314bfb68f57a6451..6175e967a33084219a77d3d16710758a3ccd28b0 100644 (file)
@@ -188,7 +188,8 @@ Specify the filename of the core file.")
 class core_target final : public process_stratum_target
 {
 public:
-  core_target ();
+  /* CBFD is the open core file BFD object.  */
+  explicit core_target (gdb_bfd_ref_ptr cbfd);
 
   const target_info &info () const override
   { return core_target_info; }
@@ -280,6 +281,9 @@ public:
     return m_expected_exec_filename;
   }
 
+  bfd *core_bfd () const
+  { return m_core_bfd.get (); }
+
 private: /* per-core data */
 
   /* Get rid of the core inferior.  */
@@ -319,13 +323,46 @@ private: /* per-core data */
      when processing the memory-mapped file information.  This will only
      be set if we find a mapped with a suitable build-id.  */
   std::string m_expected_exec_filename;
+
+  /* The core file BFD object.  */
+  gdb_bfd_ref_ptr m_core_bfd;
 };
 
-core_target::core_target ()
+/* If INF is connected to a core target, then return a pointer to the
+   core_target.  If not connected to a core target, return NULL.  */
+
+static core_target *
+get_core_target (inferior *inf)
+{
+  target_ops *proc_target = inf->process_target ();
+  return dynamic_cast<core_target *> (proc_target);
+}
+
+/* See gdbcore.h.  */
+
+bfd *
+get_inferior_core_bfd (inferior *inf)
+{
+  gdb_assert (inf != nullptr);
+
+  core_target *targ = get_core_target (inf);
+  if (targ == nullptr)
+    return nullptr;
+
+  bfd *cbfd = targ->core_bfd ();
+  gdb_assert (cbfd != nullptr);
+
+  return cbfd;
+}
+
+/* See class declaration above.  */
+
+core_target::core_target (gdb_bfd_ref_ptr cbfd_ref)
+  : m_core_bfd (std::move (cbfd_ref))
 {
   /* Find a first arch based on the BFD.  We need the initial gdbarch so
      we can setup the hooks to find a target description.  */
-  m_core_gdbarch = gdbarch_from_bfd (current_program_space->core_bfd ());
+  m_core_gdbarch = gdbarch_from_bfd (this->core_bfd ());
 
   /* If the arch is able to read a target description from the core, it
      could yield a more specific gdbarch.  */
@@ -334,7 +371,7 @@ core_target::core_target ()
   if (tdesc != nullptr)
     {
       struct gdbarch_info info;
-      info.abfd = current_program_space->core_bfd ();
+      info.abfd = this->core_bfd ();
       info.target_desc = tdesc;
       m_core_gdbarch = gdbarch_find_by_info (info);
     }
@@ -342,10 +379,10 @@ core_target::core_target ()
   if (!m_core_gdbarch
       || !gdbarch_iterate_over_regset_sections_p (m_core_gdbarch))
     error (_("\"%s\": Core file format not supported"),
-          bfd_get_filename (current_program_space->core_bfd ()));
+          bfd_get_filename (this->core_bfd ()));
 
   /* Find the data section */
-  m_core_section_table = build_section_table (current_program_space->core_bfd ());
+  m_core_section_table = build_section_table (this->core_bfd ());
 
   build_file_mappings ();
 }
@@ -371,8 +408,7 @@ core_target::build_file_mappings ()
 
   /* All files mapped into the core file.  The key is the filename.  */
   std::vector<core_mapped_file> mapped_files
-    = gdb_read_core_file_mappings (m_core_gdbarch,
-                                  current_program_space->core_bfd ());
+    = gdb_read_core_file_mappings (m_core_gdbarch, this->core_bfd ());
 
   for (const core_mapped_file &file_data : mapped_files)
     {
@@ -532,8 +568,7 @@ core_target::build_file_mappings ()
          /* Ensure that the bfd will be closed when core_bfd is closed.
             This can be checked before/after a core file detach via "maint
             info bfds".  */
-         gdb_bfd_record_inclusion (current_program_space->core_bfd (),
-                                   abfd.get ());
+         gdb_bfd_record_inclusion (this->core_bfd (), abfd.get ());
 
          /* Create sections for each mapped region.  */
          for (const core_mapped_file::region &region : file_data.regions)
@@ -587,7 +622,7 @@ core_target::build_file_mappings ()
 void
 core_target::clear_core ()
 {
-  if (current_program_space->core_bfd () != nullptr)
+  if (this->core_bfd () != nullptr)
     {
       switch_to_no_thread ();    /* Avoid confusion from thread
                                    stuff.  */
@@ -597,7 +632,7 @@ core_target::clear_core ()
         comments in clear_solib in solib.c.  */
       clear_solib (current_program_space);
 
-      current_program_space->cbfd.reset (nullptr);
+      m_core_bfd.reset (nullptr);
 
       /* Notify that the core file has changed.  */
       gdb::observers::core_file_changed.notify (current_inferior ());
@@ -661,10 +696,10 @@ core_file_command (const char *filename, int from_tty)
 
   if (filename == NULL)
     {
-      if (current_program_space->core_bfd () != nullptr)
+      if (get_core_target (current_inferior ()) != nullptr)
        {
          target_detach (current_inferior (), from_tty);
-         gdb_assert (current_program_space->core_bfd () == nullptr);
+         gdb_assert (get_core_target (current_inferior ()) == nullptr);
        }
       else
        maybe_say_no_core_file_now (from_tty);
@@ -1015,9 +1050,7 @@ core_target_open (const char *arg, int from_tty)
             filename.c_str (), bfd_errmsg (bfd_get_error ()));
     }
 
-  current_program_space->cbfd = std::move (temp_bfd);
-
-  core_target *target = new core_target ();
+  core_target *target = new core_target (std::move (temp_bfd));
 
   /* Own the target until it is successfully pushed.  */
   target_ops_up target_holder (target);
@@ -1039,7 +1072,7 @@ core_target_open (const char *arg, int from_tty)
   /* Find (or fake) the pid for the process in this core file, and
      initialise the current inferior with that pid.  */
   bool fake_pid_p = false;
-  int pid = bfd_core_file_pid (current_program_space->core_bfd ());
+  int pid = bfd_core_file_pid (target->core_bfd ());
   if (pid == 0)
     {
       fake_pid_p = true;
@@ -1052,14 +1085,14 @@ core_target_open (const char *arg, int from_tty)
   inf->fake_pid_p = fake_pid_p;
 
   /* Rename any .reg/0 sections, giving them each a fake lwpid.  */
-  rename_vmcore_idle_reg_sections (current_program_space->core_bfd (), inf);
+  rename_vmcore_idle_reg_sections (target->core_bfd (), inf);
 
   /* Build up thread list from BFD sections, and possibly set the
      current thread to the .reg/NN section matching the .reg
      section.  */
   asection *reg_sect
-    = bfd_get_section_by_name (current_program_space->core_bfd (), ".reg");
-  for (asection *sect : gdb_bfd_sections (current_program_space->core_bfd ()))
+    = bfd_get_section_by_name (target->core_bfd (), ".reg");
+  for (asection *sect : gdb_bfd_sections (target->core_bfd ()))
     add_to_thread_list (sect, reg_sect, inf);
 
   if (inferior_ptid == null_ptid)
@@ -1089,20 +1122,20 @@ core_target_open (const char *arg, int from_tty)
      the core file.  */
   core_file_exec_context ctx
     = gdbarch_core_parse_exec_context (target->core_gdbarch (),
-                                      current_program_space->core_bfd ());
+                                      target->core_bfd ());
 
   /* If we don't have an executable loaded then see if we can locate one
      based on the core file.  */
   if (current_program_space->exec_bfd () == nullptr)
-    locate_exec_from_corefile_build_id (current_program_space->core_bfd (),
-                                       target, ctx, from_tty);
+    locate_exec_from_corefile_build_id (target->core_bfd (), target, ctx,
+                                       from_tty);
 
   /* If we have no exec file, try to set the architecture from the
      core file.  We don't do this unconditionally since an exec file
      typically contains more information that helps us determine the
      architecture than a core file.  */
   if (current_program_space->exec_bfd () == nullptr)
-    set_gdbarch_from_file (current_program_space->core_bfd ());
+    set_gdbarch_from_file (target->core_bfd ());
 
   post_create_inferior (from_tty, true);
 
@@ -1142,7 +1175,7 @@ core_target_open (const char *arg, int from_tty)
   else
     {
       const char *failing_command
-       = bfd_core_file_failing_command (current_program_space->core_bfd ());
+       = bfd_core_file_failing_command (target->core_bfd ());
       if (failing_command != nullptr)
        gdb_printf (_("Core was generated by `%s'.\n"),
                    failing_command);
@@ -1151,7 +1184,7 @@ core_target_open (const char *arg, int from_tty)
   /* Clearing any previous state of convenience variables.  */
   clear_exit_convenience_vars ();
 
-  siggy = bfd_core_file_failing_signal (current_program_space->core_bfd ());
+  siggy = bfd_core_file_failing_signal (target->core_bfd ());
   if (siggy > 0)
     {
       gdbarch *core_gdbarch = target->core_gdbarch ();
@@ -1257,8 +1290,7 @@ core_target::get_core_register_section (struct regcache *regcache,
 
   thread_section_name section_name (name, regcache->ptid ());
 
-  section = bfd_get_section_by_name (current_program_space->core_bfd (),
-                                    section_name.c_str ());
+  section = bfd_get_section_by_name (this->core_bfd (), section_name.c_str ());
   if (! section)
     {
       if (required)
@@ -1281,8 +1313,8 @@ core_target::get_core_register_section (struct regcache *regcache,
     }
 
   gdb::byte_vector contents (size);
-  if (!bfd_get_section_contents (current_program_space->core_bfd (), section,
-                                contents.data (), (file_ptr) 0, size))
+  if (!bfd_get_section_contents (this->core_bfd (), section, contents.data (),
+                                (file_ptr) 0, size))
     {
       warning (_("Couldn't read %s registers from `%s' section in core file."),
               human_name, section_name.c_str ());
@@ -1365,7 +1397,7 @@ core_target::fetch_registers (struct regcache *regcache, int regno)
 void
 core_target::files_info ()
 {
-  print_section_info (&m_core_section_table, current_program_space->core_bfd ());
+  print_section_info (&m_core_section_table, this->core_bfd ());
 }
 \f
 
@@ -1485,8 +1517,7 @@ core_target::xfer_partial (enum target_object object, const char *annex,
          struct bfd_section *section;
          bfd_size_type size;
 
-         section = bfd_get_section_by_name (current_program_space->core_bfd (),
-                                            ".auxv");
+         section = bfd_get_section_by_name (this->core_bfd (), ".auxv");
          if (section == NULL)
            return TARGET_XFER_E_IO;
 
@@ -1499,9 +1530,8 @@ core_target::xfer_partial (enum target_object object, const char *annex,
 
          if (size == 0)
            return TARGET_XFER_EOF;
-         if (!bfd_get_section_contents (current_program_space->core_bfd (),
-                                        section, readbuf, (file_ptr) offset,
-                                        size))
+         if (!bfd_get_section_contents (this->core_bfd (), section, readbuf,
+                                        (file_ptr) offset, size))
            {
              warning (_("Couldn't read NT_AUXV note in core file."));
              return TARGET_XFER_E_IO;
@@ -1522,8 +1552,7 @@ core_target::xfer_partial (enum target_object object, const char *annex,
          struct bfd_section *section;
          bfd_size_type size;
 
-         section = bfd_get_section_by_name (current_program_space->core_bfd (),
-                                            ".wcookie");
+         section = bfd_get_section_by_name (this->core_bfd (), ".wcookie");
          if (section == NULL)
            return TARGET_XFER_E_IO;
 
@@ -1536,9 +1565,8 @@ core_target::xfer_partial (enum target_object object, const char *annex,
 
          if (size == 0)
            return TARGET_XFER_EOF;
-         if (!bfd_get_section_contents (current_program_space->core_bfd (),
-                                        section, readbuf, (file_ptr) offset,
-                                        size))
+         if (!bfd_get_section_contents (this->core_bfd (), section, readbuf,
+                                        (file_ptr) offset, size))
            {
              warning (_("Couldn't read StackGhost cookie in core file."));
              return TARGET_XFER_E_IO;
@@ -1559,8 +1587,7 @@ core_target::xfer_partial (enum target_object object, const char *annex,
          else
            {
              *xfered_len = gdbarch_core_xfer_shared_libraries
-               (m_core_gdbarch, *current_program_space->core_bfd (),
-                readbuf, offset, len);
+               (m_core_gdbarch, *this->core_bfd (), readbuf, offset, len);
 
              if (*xfered_len == 0)
                return TARGET_XFER_EOF;
@@ -1580,8 +1607,7 @@ core_target::xfer_partial (enum target_object object, const char *annex,
            {
              *xfered_len
                = gdbarch_core_xfer_shared_libraries_aix
-               (m_core_gdbarch, *current_program_space->core_bfd (),
-                readbuf, offset, len);
+               (m_core_gdbarch, *this->core_bfd (), readbuf, offset, len);
 
              if (*xfered_len == 0)
                return TARGET_XFER_EOF;
@@ -1597,7 +1623,7 @@ core_target::xfer_partial (enum target_object object, const char *annex,
          if (m_core_gdbarch != nullptr
              && gdbarch_core_xfer_siginfo_p (m_core_gdbarch))
            {
-             struct bfd *cbfd = current_program_space->core_bfd ();
+             struct bfd *cbfd = this->core_bfd ();
              gdb_assert (cbfd != nullptr);
              LONGEST l = gdbarch_core_xfer_siginfo  (m_core_gdbarch, *cbfd,
                                                      readbuf, offset, len);
@@ -1646,21 +1672,21 @@ core_target::read_description ()
   /* First check whether the target wants us to use the corefile target
      description notes.  */
   if (gdbarch_use_target_description_from_corefile_notes
-       (m_core_gdbarch, current_program_space->core_bfd ()))
+       (m_core_gdbarch, m_core_bfd.get ()))
     {
       /* If the core file contains a target description note then go ahead and
         use that.  */
       bfd_size_type tdesc_note_size = 0;
       struct bfd_section *tdesc_note_section
-       = bfd_get_section_by_name (current_program_space->core_bfd (), ".gdb-tdesc");
+       = bfd_get_section_by_name (m_core_bfd.get (), ".gdb-tdesc");
       if (tdesc_note_section != nullptr)
        tdesc_note_size = bfd_section_size (tdesc_note_section);
       if (tdesc_note_size > 0)
        {
          gdb::char_vector contents (tdesc_note_size + 1);
-         if (bfd_get_section_contents (current_program_space->core_bfd (),
-                                       tdesc_note_section, contents.data (),
-                                       (file_ptr) 0, tdesc_note_size))
+         if (bfd_get_section_contents (m_core_bfd.get (), tdesc_note_section,
+                                       contents.data (), (file_ptr) 0,
+                                       tdesc_note_size))
            {
              /* Ensure we have a null terminator.  */
              contents[tdesc_note_size] = '\0';
@@ -1682,8 +1708,8 @@ core_target::read_description ()
     {
       const struct target_desc *result;
 
-      result = gdbarch_core_read_description
-                (m_core_gdbarch, this, current_program_space->core_bfd ());
+      result = gdbarch_core_read_description (m_core_gdbarch, this,
+                                             m_core_bfd.get ());
       if (result != nullptr)
        return result;
     }
@@ -1727,7 +1753,7 @@ core_target::thread_name (struct thread_info *thr)
   if (m_core_gdbarch != nullptr
       && gdbarch_core_thread_name_p (m_core_gdbarch))
     {
-      bfd *cbfd = current_program_space->core_bfd ();
+      bfd *cbfd = this->core_bfd ();
       gdb_assert (cbfd != nullptr);
       return gdbarch_core_thread_name (m_core_gdbarch, *cbfd, thr);
     }
@@ -1737,19 +1763,19 @@ core_target::thread_name (struct thread_info *thr)
 bool
 core_target::has_memory ()
 {
-  return current_program_space->core_bfd () != nullptr;
+  return this->core_bfd () != nullptr;
 }
 
 bool
 core_target::has_stack ()
 {
-  return current_program_space->core_bfd () != nullptr;
+  return this->core_bfd () != nullptr;
 }
 
 bool
 core_target::has_registers ()
 {
-  return current_program_space->core_bfd () != nullptr;
+  return this->core_bfd () != nullptr;
 }
 
 /* Implement the to_info_proc method.  */
@@ -1762,8 +1788,7 @@ core_target::info_proc (const char *args, enum info_proc_what request)
   /* Since this is the core file target, call the 'core_info_proc'
      method on gdbarch, not 'info_proc'.  */
   if (gdbarch_core_info_proc_p (gdbarch))
-    gdbarch_core_info_proc (gdbarch, current_program_space->core_bfd (),
-                           args, request);
+    gdbarch_core_info_proc (gdbarch, this->core_bfd (), args, request);
 
   return true;
 }
@@ -1776,8 +1801,7 @@ core_target::supports_memory_tagging ()
   /* Look for memory tag sections.  If they exist, that means this core file
      supports memory tagging.  */
 
-  return (bfd_get_section_by_name (current_program_space->core_bfd (), "memtag")
-         != nullptr);
+  return bfd_get_section_by_name (this->core_bfd (), "memtag") != nullptr;
 }
 
 /* Implementation of the "fetch_memtags" target_ops method.  */
@@ -1796,8 +1820,8 @@ core_target::fetch_memtags (CORE_ADDR address, size_t len,
   memtag_section_info info;
   info.memtag_section = nullptr;
 
-  while (get_next_core_memtag_section (current_program_space->core_bfd (),
-                                      info.memtag_section, address, info))
+  while (get_next_core_memtag_section (this->core_bfd (), info.memtag_section,
+                                      address, info))
   {
     size_t adjusted_length
       = (address + len < info.end_address) ? len : (info.end_address - address);
@@ -1838,7 +1862,7 @@ core_target::fetch_x86_xsave_layout ()
       gdbarch_core_read_x86_xsave_layout_p (m_core_gdbarch))
     {
       x86_xsave_layout layout;
-      bfd *cbfd = current_program_space->core_bfd ();
+      bfd *cbfd = this->core_bfd ();
       gdb_assert (cbfd != nullptr);
       if (!gdbarch_core_read_x86_xsave_layout (m_core_gdbarch, *cbfd, layout))
        return {};
@@ -1849,16 +1873,6 @@ core_target::fetch_x86_xsave_layout ()
   return {};
 }
 
-/* Get a pointer to the current core target.  If not connected to a
-   core target, return NULL.  */
-
-static core_target *
-get_current_core_target ()
-{
-  target_ops *proc_target = current_inferior ()->process_target ();
-  return dynamic_cast<core_target *> (proc_target);
-}
-
 /* Display file backed mappings from core file.  */
 
 void
@@ -1912,7 +1926,7 @@ core_target::info_proc_mappings (struct gdbarch *gdbarch)
 static void
 maintenance_print_core_file_backed_mappings (const char *args, int from_tty)
 {
-  core_target *targ = get_current_core_target ();
+  core_target *targ = get_core_target (current_inferior ());
   if (targ != nullptr)
     targ->info_proc_mappings (targ->core_gdbarch ());
 }
@@ -2183,10 +2197,12 @@ std::optional <core_target_mapped_file_info>
 core_target_find_mapped_file (const char *filename,
                              std::optional<CORE_ADDR> addr)
 {
-  core_target *targ = get_current_core_target ();
-  if (targ == nullptr || current_program_space->cbfd.get () == nullptr)
+  core_target *targ = get_core_target (current_inferior ());
+  if (targ == nullptr)
     return {};
 
+  gdb_assert (targ->core_bfd () != nullptr);
+
   return targ->lookup_mapped_file_info (filename, addr);
 }
 
index 23432ecbd074486f6dabc50f6b9b2704b3b9734d..8b4adaa79a14bdc9199231178d77fe1c15e69c43 100644 (file)
@@ -301,4 +301,9 @@ struct core_mapped_file
 extern std::vector<core_mapped_file> gdb_read_core_file_mappings
   (struct gdbarch *gdbarch, struct bfd *cbfd);
 
+/* Return the core file bfd for inferior INF, if that inferior has a core
+   file loaded.  Otherwise, return NULL.  */
+
+extern bfd *get_inferior_core_bfd (inferior *inf);
+
 #endif /* GDB_GDBCORE_H */
index 30612bb333364aec7d4ab4610d5bbcc3c41e2263..77626be4ab7442004369960a7f542d8169acb0de 100644 (file)
@@ -634,11 +634,11 @@ print_inferior (struct ui_out *uiout, const char *requested_inferiors)
          uiout->text (_("\n\tis vfork parent of inferior "));
          uiout->field_signed ("vfork-child", inf->vfork_child->num);
        }
-      if (inf->pspace->core_bfd () != nullptr)
+      if (get_inferior_core_bfd (inf) != nullptr)
        {
          uiout->text (_("\n\tcore file "));
          uiout->field_string ("core-file",
-                              bfd_get_filename (inf->pspace->core_bfd ()),
+                              bfd_get_filename (get_inferior_core_bfd (inf)),
                               file_name_style.style ());
        }
 
index 6ee0134f20b822da13f0e64ec82a0c89942ef85d..59b9c8c6b31fc70511152bece8dec15a3eabc98a 100644 (file)
@@ -436,6 +436,19 @@ 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 06fd33ed62d199c26efcf44830764a5e3be79a1f..302520e85f462debd3c9d49ac0f25ae958e58e56 100644 (file)
@@ -292,8 +292,7 @@ struct program_space
     ebfd = std::move (abfd);
   }
 
-  bfd *core_bfd () const
-  { return cbfd.get ();  }
+  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
@@ -339,9 +338,6 @@ struct program_space
   /* The last-modified time, from when the exec was brought in.  */
   long ebfd_mtime = 0;
 
-  /* Binary file diddling handle for the core file.  */
-  gdb_bfd_ref_ptr cbfd;
-
   /* The address space attached to this program space.  More than one
      program space may be bound to the same address space.  In the
      traditional unix-like debugging scenario, this will usually
index 7c9a4478f243a3b404206f72584b70b2f40b63ed..97f42427af1fbc36a0d795edcb00acc6d341c034 100644 (file)
@@ -128,9 +128,7 @@ gdbpy_core_file_from_inferior (inferior *inf)
   gdb_assert (inf != nullptr);
   gdb_assert (inf->pspace != nullptr);
 
-  program_space *pspace = inf->pspace;
-
-  if (pspace->core_bfd () == nullptr)
+  if (get_inferior_core_bfd (inf) == nullptr)
     return gdbpy_ref<>::new_reference (Py_None);
 
   PyObject *result = (PyObject *) cfpy_inferior_corefile_data_key.get (inf);
@@ -171,9 +169,7 @@ cfpy_corefile_object_is_valid (const corefile_object *obj)
   if (obj->inferior == nullptr)
     return false;
 
-  gdb_assert (obj->inferior->pspace != nullptr);
-
-  return obj->inferior->pspace->core_bfd () != nullptr;
+  return get_inferior_core_bfd (obj->inferior) != nullptr;
 }
 
 /* Require that COREFILE_OBJ be a valid core file.  A valid core file
@@ -200,7 +196,7 @@ cfpy_get_filename (PyObject *self, void *closure)
 
   /* If the program space's core file had been cleared, then this Corefile
      object would have been invalidated.  */
-  bfd *abfd = obj->inferior->pspace->core_bfd ();
+  bfd *abfd = get_inferior_core_bfd (obj->inferior);
   gdb_assert (abfd != nullptr);
 
   return host_string_to_python_string (bfd_get_filename (abfd)).release ();
@@ -247,7 +243,7 @@ cfpy_mapped_files (PyObject *self, PyObject *args)
     {
       mapped_files
        = gdb_read_core_file_mappings (obj->inferior->arch (),
-                                      current_program_space->core_bfd ());
+                                      get_inferior_core_bfd (obj->inferior));
     }
   catch (const gdb_exception &except)
     {
@@ -376,12 +372,12 @@ cfpy_repr (PyObject *self)
   if (!cfpy_corefile_object_is_valid (obj))
     return gdb_py_invalid_object_repr (self);
 
-  program_space *pspace = obj->inferior->pspace;
-  gdb_assert (pspace != nullptr);
+  bfd *core_bfd = get_inferior_core_bfd (obj->inferior);
+  gdb_assert (core_bfd != nullptr);
   return PyUnicode_FromFormat ("<%s inferior=%d filename='%s'>",
                               Py_TYPE (self)->tp_name,
                               obj->inferior->num,
-                              bfd_get_filename (pspace->core_bfd ()));
+                              bfd_get_filename (core_bfd));
 }
 
 \f