[7/9] Remove the exec_bfd macro

Message ID 20200722033444.18522-8-tom@tromey.com
State New
Headers show
Series
  • Remove some macros from exec.h and progspace.h
Related show

Commit Message

Tom Tromey July 22, 2020, 3:34 a.m.
This removes the exec_bfd macro, in favor of new accessors on
program_space.  In one spot the accessor can't be used; but this is
still a big improvement over the macro, IMO.

gdb/ChangeLog
2020-07-21  Tom Tromey  <tom@tromey.com>

	* windows-tdep.c (windows_solib_create_inferior_hook): Update.
	* symfile.c (reread_symbols): Update.
	* symfile-mem.c (add_symbol_file_from_memory_command)
	(add_vsyscall_page): Update.
	* source-cache.c (source_cache::get_plain_source_lines): Update.
	* solib-svr4.c (find_program_interpreter, elf_locate_base)
	(svr4_current_sos_direct, svr4_exec_displacement)
	(svr4_relocate_main_executable): Update.
	(svr4_iterate_over_objfiles_in_search_order): Update.
	* solib-frv.c (enable_break2, enable_break): Update.
	* solib-dsbt.c (lm_base, enable_break): Update.
	* solib-darwin.c (find_program_interpreter)
	(darwin_solib_create_inferior_hook): Update.
	* sol-thread.c (rw_common, ps_pdmodel): Update.
	* rs6000-nat.c (rs6000_nat_target::create_inferior): Update.
	* remote.c (compare_sections_command)
	(remote_target::trace_set_readonly_regions): Update.
	* remote-sim.c (get_sim_inferior_data)
	(gdbsim_target::create_inferior, gdbsim_target::create_inferior): Update.
	(gdbsim_target_open, gdbsim_target::files_info): Update.
	* exec.h (exec_bfd): Remove macro.
	* progspace.c (initialize_progspace): Update.
	* proc-service.c (ps_addr_to_core_addr, core_addr_to_ps_addr):
	Update.
	* nto-procfs.c (nto_procfs_target::post_attach)
	(nto_procfs_target::create_inferior): Update.
	* maint.c (maintenance_info_sections): Update.
	* linux-thread-db.c (thread_db_target::get_thread_local_address):
	Update.
	* infcmd.c (post_create_inferior): Update.
	* gcore.c (default_gcore_arch, default_gcore_target): Update.
	(objfile_find_memory_regions): Update.
	* exec.c (validate_exec_file, exec_file_attach)
	(exec_read_partial_read_only, print_section_info): Update.
	* corelow.c (core_target_open): Update.
	* corefile.c (reopen_exec_file, validate_files): Update.
	* arm-tdep.c (gdb_print_insn_arm): Update.
	* arch-utils.c (gdbarch_update_p, default_print_insn): Update.
	* progspace.h (struct program_space) <exec_bfd, set_exec_bfd>: New
	methods.
---
 gdb/ChangeLog         | 43 +++++++++++++++++++++++++++
 gdb/arch-utils.c      |  4 +--
 gdb/arm-tdep.c        |  4 +--
 gdb/corefile.c        | 10 +++----
 gdb/corelow.c         |  4 +--
 gdb/exec.c            | 38 +++++++++++++-----------
 gdb/exec.h            |  2 --
 gdb/gcore.c           | 12 ++++----
 gdb/infcmd.c          |  2 +-
 gdb/linux-thread-db.c |  4 +--
 gdb/maint.c           |  8 ++---
 gdb/nto-procfs.c      |  4 +--
 gdb/proc-service.c    |  6 ++--
 gdb/progspace.c       |  6 ++--
 gdb/progspace.h       | 12 ++++++++
 gdb/remote-sim.c      | 17 ++++++-----
 gdb/remote.c          | 12 ++++----
 gdb/rs6000-nat.c      |  6 ++--
 gdb/sol-thread.c      |  6 ++--
 gdb/solib-darwin.c    | 10 +++----
 gdb/solib-dsbt.c      | 11 +++----
 gdb/solib-frv.c       | 10 ++++---
 gdb/solib-svr4.c      | 68 ++++++++++++++++++++++++++-----------------
 gdb/source-cache.c    |  2 +-
 gdb/symfile-mem.c     |  6 ++--
 gdb/symfile.c         |  4 +--
 gdb/tracefile-tfile.c |  2 +-
 gdb/windows-tdep.c    |  3 +-
 28 files changed, 198 insertions(+), 118 deletions(-)

-- 
2.17.2

Patch

diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
index 13ba50abe61..5cf97374386 100644
--- a/gdb/arch-utils.c
+++ b/gdb/arch-utils.c
@@ -527,7 +527,7 @@  gdbarch_update_p (struct gdbarch_info info)
 
   /* Check for the current file.  */
   if (info.abfd == NULL)
-    info.abfd = exec_bfd;
+    info.abfd = current_program_space->exec_bfd ();
   if (info.abfd == NULL)
     info.abfd = core_bfd;
 
@@ -989,7 +989,7 @@  default_print_insn (bfd_vma memaddr, disassemble_info *info)
   disassembler_ftype disassemble_fn;
 
   disassemble_fn = disassembler (info->arch, info->endian == BFD_ENDIAN_BIG,
-				 info->mach, exec_bfd);
+				 info->mach, current_program_space->exec_bfd ());
 
   gdb_assert (disassemble_fn != NULL);
   return (*disassemble_fn) (memaddr, info);
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 9cedcc85755..8bc8fcc62d1 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -7645,9 +7645,9 @@  gdb_print_insn_arm (bfd_vma memaddr, disassemble_info *info)
   /* GDB is able to get bfd_mach from the exe_bfd, info->mach is
      accurate, so mark USER_SPECIFIED_MACHINE_TYPE bit.  Otherwise,
      opcodes/arm-dis.c:print_insn reset info->mach, and it will trigger
-     the assert on the mismatch of info->mach and bfd_get_mach (exec_bfd)
+     the assert on the mismatch of info->mach and bfd_get_mach (current_program_space->exec_bfd ())
      in default_print_insn.  */
-  if (exec_bfd != NULL)
+  if (current_program_space->exec_bfd () != NULL)
     info->flags |= USER_SPECIFIED_MACHINE_TYPE;
 
   return default_print_insn (memaddr, info);
diff --git a/gdb/corefile.c b/gdb/corefile.c
index 1586e9f175a..09fec24c4cd 100644
--- a/gdb/corefile.c
+++ b/gdb/corefile.c
@@ -108,11 +108,11 @@  reopen_exec_file (void)
   struct stat st;
 
   /* Don't do anything if there isn't an exec file.  */
-  if (exec_bfd == NULL)
+  if (current_program_space->exec_bfd () == NULL)
     return;
 
   /* If the timestamp of the exec file has changed, reopen it.  */
-  std::string filename = bfd_get_filename (exec_bfd);
+  std::string filename = bfd_get_filename (current_program_space->exec_bfd ());
   res = stat (filename.c_str (), &st);
 
   if (res == 0
@@ -132,11 +132,11 @@  reopen_exec_file (void)
 void
 validate_files (void)
 {
-  if (exec_bfd && core_bfd)
+  if (current_program_space->exec_bfd () && core_bfd)
     {
-      if (!core_file_matches_executable_p (core_bfd, exec_bfd))
+      if (!core_file_matches_executable_p (core_bfd, current_program_space->exec_bfd ()))
 	warning (_("core file may not match specified executable file."));
-      else if (bfd_get_mtime (exec_bfd) > bfd_get_mtime (core_bfd))
+      else if (bfd_get_mtime (current_program_space->exec_bfd ()) > bfd_get_mtime (core_bfd))
 	warning (_("exec file is newer than core file."));
     }
 }
diff --git a/gdb/corelow.c b/gdb/corelow.c
index 3958af1e67a..29992a0ae7d 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -333,7 +333,7 @@  core_target_open (const char *arg, int from_tty)
      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 (!exec_bfd)
+  if (!current_program_space->exec_bfd ())
     set_gdbarch_from_file (core_bfd);
 
   push_target (std::move (target_holder));
@@ -373,7 +373,7 @@  core_target_open (const char *arg, int from_tty)
       switch_to_thread (thread);
     }
 
-  if (exec_bfd == nullptr)
+  if (current_program_space->exec_bfd () == nullptr)
     locate_exec_from_corefile_build_id (core_bfd, from_tty);
 
   post_create_inferior (target, from_tty);
diff --git a/gdb/exec.c b/gdb/exec.c
index b2c7a58b27f..75f3990e0f0 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -237,7 +237,8 @@  validate_exec_file (int from_tty)
   reopen_exec_file ();
   current_exec_file = get_exec_file (0);
 
-  const bfd_build_id *exec_file_build_id = build_id_bfd_get (exec_bfd);
+  const bfd_build_id *exec_file_build_id
+    = build_id_bfd_get (current_program_space->exec_bfd ());
   if (exec_file_build_id != nullptr)
     {
       /* Prepend the target prefix, to force gdb_bfd_open to open the
@@ -364,10 +365,10 @@  exec_file_locate_attach (int pid, int defer_bp_reset, int from_tty)
 void
 exec_file_attach (const char *filename, int from_tty)
 {
-  /* First, acquire a reference to the current exec_bfd.  We release
+  /* First, acquire a reference to the current current_program_space->exec_bfd ().  We release
      this at the end of the function; but acquiring it now lets the
      BFD cache return it if this call refers to the same file.  */
-  gdb_bfd_ref_ptr exec_bfd_holder = gdb_bfd_ref_ptr::new_reference (exec_bfd);
+  gdb_bfd_ref_ptr exec_bfd_holder = gdb_bfd_ref_ptr::new_reference (current_program_space->exec_bfd ());
 
   /* Remove any previous exec file.  */
   current_program_space->exec_close ();
@@ -449,9 +450,9 @@  exec_file_attach (const char *filename, int from_tty)
 			      FOPEN_RUB, scratch_chan);
       else
 	temp = gdb_bfd_open (canonical_pathname, gnutarget, scratch_chan);
-      exec_bfd = temp.release ();
+      current_program_space->set_exec_bfd (temp.release ());
 
-      if (!exec_bfd)
+      if (!current_program_space->exec_bfd ())
 	{
 	  error (_("\"%ps\": could not open as an executable file: %s."),
 		 styled_string (file_name_style.style (), scratch_pathname),
@@ -463,12 +464,12 @@  exec_file_attach (const char *filename, int from_tty)
       gdb_assert (current_program_space->exec_filename == nullptr);
       if (load_via_target)
 	current_program_space->exec_filename
-	  = make_unique_xstrdup (bfd_get_filename (exec_bfd));
+	  = make_unique_xstrdup (bfd_get_filename (current_program_space->exec_bfd ()));
       else
 	current_program_space->exec_filename
 	  = gdb_realpath_keepfile (scratch_pathname);
 
-      if (!bfd_check_format_matches (exec_bfd, bfd_object, &matching))
+      if (!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
 	     it.  */
@@ -478,7 +479,8 @@  exec_file_attach (const char *filename, int from_tty)
 		 gdb_bfd_errmsg (bfd_get_error (), matching).c_str ());
 	}
 
-      if (build_section_table (exec_bfd, &sections, &sections_end))
+      if (build_section_table (current_program_space->exec_bfd (),
+			       &sections, &sections_end))
 	{
 	  /* Make sure to close exec_bfd, or else "run" might try to use
 	     it.  */
@@ -488,16 +490,18 @@  exec_file_attach (const char *filename, int from_tty)
 		 bfd_errmsg (bfd_get_error ()));
 	}
 
-      current_program_space->ebfd_mtime = bfd_get_mtime (exec_bfd);
+      current_program_space->ebfd_mtime
+	= bfd_get_mtime (current_program_space->exec_bfd ());
 
       validate_files ();
 
-      set_gdbarch_from_file (exec_bfd);
+      set_gdbarch_from_file (current_program_space->exec_bfd ());
 
       /* Add the executable's sections to the current address spaces'
 	 list of sections.  This possibly pushes the exec_ops
 	 target.  */
-      add_target_sections (&exec_bfd, sections, sections_end);
+      add_target_sections (&current_program_space->ebfd,
+			   sections, sections_end);
       xfree (sections);
 
       /* Tell display code (if any) about the changed file name.  */
@@ -811,13 +815,13 @@  exec_read_partial_read_only (gdb_byte *readbuf, ULONGEST offset,
   /* It's unduly pedantic to refuse to look at the executable for
      read-only pieces; so do the equivalent of readonly regions aka
      QTro packet.  */
-  if (exec_bfd != NULL)
+  if (current_program_space->exec_bfd () != NULL)
     {
       asection *s;
       bfd_size_type size;
       bfd_vma vma;
 
-      for (s = exec_bfd->sections; s; s = s->next)
+      for (s = current_program_space->exec_bfd ()->sections; s; s = s->next)
 	{
 	  if ((s->flags & SEC_LOAD) == 0
 	      || (s->flags & SEC_READONLY) == 0)
@@ -833,7 +837,7 @@  exec_read_partial_read_only (gdb_byte *readbuf, ULONGEST offset,
 	      if (amt > len)
 		amt = len;
 
-	      amt = bfd_get_section_contents (exec_bfd, s,
+	      amt = bfd_get_section_contents (current_program_space->exec_bfd (), s,
 					      readbuf, offset - vma, amt);
 
 	      if (amt == 0)
@@ -1041,7 +1045,7 @@  print_section_info (struct target_section_table *t, bfd *abfd)
 				  bfd_get_filename (abfd)));
   wrap_here ("        ");
   printf_filtered (_("file type %s.\n"), bfd_get_target (abfd));
-  if (abfd == exec_bfd)
+  if (abfd == current_program_space->exec_bfd ())
     {
       /* gcc-3.4 does not like the initialization in
 	 <p == t->sections_end>.  */
@@ -1104,8 +1108,8 @@  print_section_info (struct target_section_table *t, bfd *abfd)
 void
 exec_target::files_info ()
 {
-  if (exec_bfd)
-    print_section_info (&current_program_space->target_sections, exec_bfd);
+  if (current_program_space->exec_bfd ())
+    print_section_info (&current_program_space->target_sections, current_program_space->exec_bfd ());
   else
     puts_filtered (_("\t<no file loaded>\n"));
 }
diff --git a/gdb/exec.h b/gdb/exec.h
index db03f3a24fb..c0d34ddcd00 100644
--- a/gdb/exec.h
+++ b/gdb/exec.h
@@ -30,8 +30,6 @@  struct target_ops;
 struct bfd;
 struct objfile;
 
-#define exec_bfd current_program_space->ebfd
-
 /* Builds a section table, given args BFD, SECTABLE_PTR, SECEND_PTR.
    Returns 0 if OK, 1 on error.  */
 
diff --git a/gdb/gcore.c b/gdb/gcore.c
index 8036ce52d50..8ed04569b51 100644
--- a/gdb/gcore.c
+++ b/gdb/gcore.c
@@ -173,10 +173,10 @@  default_gcore_arch (void)
 
   if (bfdarch != NULL)
     return bfdarch->arch;
-  if (exec_bfd == NULL)
+  if (current_program_space->exec_bfd () == NULL)
     error (_("Can't find bfd architecture for corefile (need execfile)."));
 
-  return bfd_get_arch (exec_bfd);
+  return bfd_get_arch (current_program_space->exec_bfd ());
 }
 
 static const char *
@@ -186,12 +186,12 @@  default_gcore_target (void)
   if (gdbarch_gcore_bfd_target_p (target_gdbarch ()))
     return gdbarch_gcore_bfd_target (target_gdbarch ());
 
-  /* Otherwise, try to fall back to the exec_bfd target.  This will probably
+  /* Otherwise, try to fall back to the exec target.  This will probably
      not work for non-ELF targets.  */
-  if (exec_bfd == NULL)
+  if (current_program_space->exec_bfd () == NULL)
     return NULL;
   else
-    return bfd_get_target (exec_bfd);
+    return bfd_get_target (current_program_space->exec_bfd ());
 }
 
 /* Derive a reasonable stack segment by unwinding the target stack,
@@ -502,7 +502,7 @@  objfile_find_memory_regions (struct target_ops *self,
 	     obfd);
 
   /* Make a heap segment.  */
-  if (derive_heap_segment (exec_bfd, &temp_bottom, &temp_top))
+  if (derive_heap_segment (current_program_space->exec_bfd (), &temp_bottom, &temp_top))
     (*func) (temp_bottom, temp_top - temp_bottom,
 	     1, /* Heap section will be readable.  */
 	     1, /* Heap section will be writable.  */
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index cfc31699925..e48a1bb2e6e 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -308,7 +308,7 @@  post_create_inferior (struct target_ops *target, int from_tty)
 	throw;
     }
 
-  if (exec_bfd)
+  if (current_program_space->exec_bfd ())
     {
       const unsigned solib_add_generation
 	= current_program_space->solib_add_generation;
diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c
index b3cda05cd6e..7c288db52a8 100644
--- a/gdb/linux-thread-db.c
+++ b/gdb/linux-thread-db.c
@@ -1800,8 +1800,8 @@  thread_db_target::get_thread_local_address (ptid_t ptid,
 
       /* Cast assuming host == target.  Joy.  */
       /* Do proper sign extension for the target.  */
-      gdb_assert (exec_bfd);
-      return (bfd_get_sign_extend_vma (exec_bfd) > 0
+      gdb_assert (current_program_space->exec_bfd ());
+      return (bfd_get_sign_extend_vma (current_program_space->exec_bfd ()) > 0
 	      ? (CORE_ADDR) (intptr_t) address
 	      : (CORE_ADDR) (uintptr_t) address);
     }
diff --git a/gdb/maint.c b/gdb/maint.c
index b4890c34cab..51031003b72 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -403,14 +403,14 @@  print_bfd_section_info_maybe_relocated (bfd *abfd,
 static void
 maintenance_info_sections (const char *arg, int from_tty)
 {
-  if (exec_bfd)
+  if (current_program_space->exec_bfd ())
     {
       bool allobj = false;
 
       printf_filtered (_("Exec file:\n"));
-      printf_filtered ("    `%s', ", bfd_get_filename (exec_bfd));
+      printf_filtered ("    `%s', ", bfd_get_filename (current_program_space->exec_bfd ()));
       wrap_here ("        ");
-      printf_filtered (_("file type %s.\n"), bfd_get_target (exec_bfd));
+      printf_filtered (_("file type %s.\n"), bfd_get_target (current_program_space->exec_bfd ()));
 
       /* Only this function cares about the 'ALLOBJ' argument;
 	 if 'ALLOBJ' is the only argument, discard it rather than
@@ -427,7 +427,7 @@  maintenance_info_sections (const char *arg, int from_tty)
 	  if (allobj)
 	    printf_filtered (_("  Object file: %s\n"),
 			     bfd_get_filename (ofile->obfd));
-	  else if (ofile->obfd != exec_bfd)
+	  else if (ofile->obfd != current_program_space->exec_bfd ())
 	    continue;
 
 	  maint_print_section_data print_data (ofile, arg, ofile->obfd);
diff --git a/gdb/nto-procfs.c b/gdb/nto-procfs.c
index 91d2cc5914d..90cd67fd776 100644
--- a/gdb/nto-procfs.c
+++ b/gdb/nto-procfs.c
@@ -728,7 +728,7 @@  nto_procfs_target::attach (const char *args, int from_tty)
 void
 nto_procfs_target::post_attach (pid_t pid)
 {
-  if (exec_bfd)
+  if (current_program_space->exec_bfd ())
     solib_create_inferior_hook (0);
 }
 
@@ -1322,7 +1322,7 @@  nto_procfs_target::create_inferior (const char *exec_file,
     push_target (ops);
   target_terminal::init ();
 
-  if (exec_bfd != NULL
+  if (current_program_space->exec_bfd () != NULL
       || (symfile_objfile != NULL && symfile_objfile->obfd != NULL))
     solib_create_inferior_hook (0);
 }
diff --git a/gdb/proc-service.c b/gdb/proc-service.c
index e0383700a1d..2025f3a66c5 100644
--- a/gdb/proc-service.c
+++ b/gdb/proc-service.c
@@ -42,7 +42,8 @@ 
 static CORE_ADDR
 ps_addr_to_core_addr (psaddr_t addr)
 {
-  if (exec_bfd && bfd_get_sign_extend_vma (exec_bfd))
+  if (current_program_space->exec_bfd ()
+      && bfd_get_sign_extend_vma (current_program_space->exec_bfd ()))
     return (intptr_t) addr;
   else
     return (uintptr_t) addr;
@@ -53,7 +54,8 @@  ps_addr_to_core_addr (psaddr_t addr)
 static psaddr_t
 core_addr_to_ps_addr (CORE_ADDR addr)
 {
-  if (exec_bfd && bfd_get_sign_extend_vma (exec_bfd))
+  if (current_program_space->exec_bfd ()
+      && bfd_get_sign_extend_vma (current_program_space->exec_bfd ()))
     return (psaddr_t) (intptr_t) addr;
   else
     return (psaddr_t) (uintptr_t) addr;
diff --git a/gdb/progspace.c b/gdb/progspace.c
index ca32a0a1b8d..49243a6394d 100644
--- a/gdb/progspace.c
+++ b/gdb/progspace.c
@@ -228,7 +228,7 @@  program_space::exec_close ()
       gdb_bfd_unref (ebfd);
 
       /* Removing target sections may close the exec_ops target.
-	 Clear exec_bfd before doing so to prevent recursion.  */
+	 Clear ebfd before doing so to prevent recursion.  */
       ebfd = NULL;
       ebfd_mtime = 0;
 
@@ -460,7 +460,7 @@  initialize_progspace (void)
      _initialize_foo routines may need to install their per-pspace
      data keys.  We can only allocate a progspace when all those
      modules have done that.  Do this before
-     initialize_current_architecture, because that accesses exec_bfd,
-     which in turn dereferences current_program_space.  */
+     initialize_current_architecture, because that accesses the ebfd
+     of current_program_space.  */
   current_program_space = new program_space (new_address_space ());
 }
diff --git a/gdb/progspace.h b/gdb/progspace.h
index ef39f8a1dab..5f952ea9b84 100644
--- a/gdb/progspace.h
+++ b/gdb/progspace.h
@@ -276,6 +276,18 @@  struct program_space
      to read memory from, this unpushes the exec_ops target.  */
   void exec_close ();
 
+  /* Return the exec BFD for this program space.  */
+  bfd *exec_bfd () const
+  {
+    return ebfd;
+  }
+
+  /* Set the exec BFD for this program space to ABFD.  */
+  void set_exec_bfd (bfd *abfd)
+  {
+    ebfd = abfd;
+  }
+
   /* Unique ID number.  */
   int num = 0;
 
diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c
index 9af6486bca8..41b1214f045 100644
--- a/gdb/remote-sim.c
+++ b/gdb/remote-sim.c
@@ -211,7 +211,8 @@  get_sim_inferior_data (struct inferior *inf, int sim_instance_needed)
   if (sim_instance_needed == SIM_INSTANCE_NEEDED
       && (sim_data == NULL || sim_data->gdbsim_desc == NULL))
     {
-      sim_desc = sim_open (SIM_OPEN_DEBUG, &gdb_callback, exec_bfd, sim_argv);
+      sim_desc = sim_open (SIM_OPEN_DEBUG, &gdb_callback,
+			   current_program_space->exec_bfd (), sim_argv);
       if (sim_desc == NULL)
 	error (_("Unable to create simulator instance for inferior %d."),
 	       inf->num);
@@ -620,7 +621,7 @@  gdbsim_target::create_inferior (const char *exec_file,
   char *arg_buf;
   const char *args = allargs.c_str ();
 
-  if (exec_file == 0 || exec_bfd == 0)
+  if (exec_file == 0 || current_program_space->exec_bfd () == 0)
     warning (_("No executable file specified."));
   if (!sim_data->program_loaded)
     warning (_("No program loaded."));
@@ -648,7 +649,8 @@  gdbsim_target::create_inferior (const char *exec_file,
       built_argv.reset (arg_buf);
     }
 
-  if (sim_create_inferior (sim_data->gdbsim_desc, exec_bfd,
+  if (sim_create_inferior (sim_data->gdbsim_desc,
+			   current_program_space->exec_bfd (),
 			   built_argv.get (), env)
       != SIM_RC_OK)
     error (_("Unable to create sim inferior."));
@@ -738,7 +740,8 @@  gdbsim_target_open (const char *args, int from_tty)
   sim_argv = argv.release ();
 
   init_callbacks ();
-  gdbsim_desc = sim_open (SIM_OPEN_DEBUG, &gdb_callback, exec_bfd, sim_argv);
+  gdbsim_desc = sim_open (SIM_OPEN_DEBUG, &gdb_callback,
+			  current_program_space->exec_bfd (), sim_argv);
 
   if (gdbsim_desc == 0)
     {
@@ -1103,13 +1106,13 @@  gdbsim_target::files_info ()
     = get_sim_inferior_data (current_inferior (), SIM_INSTANCE_NEEDED);
   const char *file = "nothing";
 
-  if (exec_bfd)
-    file = bfd_get_filename (exec_bfd);
+  if (current_program_space->exec_bfd ())
+    file = bfd_get_filename (current_program_space->exec_bfd ());
 
   if (remote_debug)
     fprintf_unfiltered (gdb_stdlog, "gdbsim_files_info: file \"%s\"\n", file);
 
-  if (exec_bfd)
+  if (current_program_space->exec_bfd ())
     {
       fprintf_unfiltered (gdb_stdlog, "\tAttached to %s running program %s\n",
 			  target_shortname, file);
diff --git a/gdb/remote.c b/gdb/remote.c
index 59075cb09f2..d0836fff6e5 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -56,7 +56,7 @@ 
 #include <signal.h>
 #include "serial.h"
 
-#include "gdbcore.h" /* for exec_bfd */
+#include "gdbcore.h"
 
 #include "remote-fileio.h"
 #include "gdb/fileio.h"
@@ -10767,7 +10767,7 @@  compare_sections_command (const char *args, int from_tty)
   int res;
   int read_only = 0;
 
-  if (!exec_bfd)
+  if (!current_program_space->exec_bfd ())
     error (_("command cannot be used without an exec file"));
 
   if (args != NULL && strcmp (args, "-r") == 0)
@@ -10776,7 +10776,7 @@  compare_sections_command (const char *args, int from_tty)
       args = NULL;
     }
 
-  for (s = exec_bfd->sections; s; s = s->next)
+  for (s = current_program_space->exec_bfd ()->sections; s; s = s->next)
     {
       if (!(s->flags & SEC_LOAD))
 	continue;		/* Skip non-loadable section.  */
@@ -10796,7 +10796,7 @@  compare_sections_command (const char *args, int from_tty)
       lma = s->lma;
 
       gdb::byte_vector sectdata (size);
-      bfd_get_section_contents (exec_bfd, s, sectdata.data (), 0, size);
+      bfd_get_section_contents (current_program_space->exec_bfd (), s, sectdata.data (), 0, size);
 
       res = target_verify_memory (sectdata.data (), lma, size);
 
@@ -13171,14 +13171,14 @@  remote_target::trace_set_readonly_regions ()
   int anysecs = 0;
   int offset = 0;
 
-  if (!exec_bfd)
+  if (!current_program_space->exec_bfd ())
     return;			/* No information to give.  */
 
   struct remote_state *rs = get_remote_state ();
 
   strcpy (rs->buf.data (), "QTro");
   offset = strlen (rs->buf.data ());
-  for (s = exec_bfd->sections; s; s = s->next)
+  for (s = current_program_space->exec_bfd ()->sections; s; s = s->next)
     {
       char tmp1[40], tmp2[40];
       int sec_length;
diff --git a/gdb/rs6000-nat.c b/gdb/rs6000-nat.c
index 654e06e3e4b..f7ec3a70ee1 100644
--- a/gdb/rs6000-nat.c
+++ b/gdb/rs6000-nat.c
@@ -581,11 +581,11 @@  rs6000_nat_target::create_inferior (const char *exec_file,
      Blindly calling rs6000_gdbarch_init used to work in older versions of
      GDB, as rs6000_gdbarch_init incorrectly used the previous tdep to
      determine the wordsize.  */
-  if (exec_bfd)
+  if (current_program_space->exec_bfd ())
     {
       const struct bfd_arch_info *exec_bfd_arch_info;
 
-      exec_bfd_arch_info = bfd_get_arch_info (exec_bfd);
+      exec_bfd_arch_info = bfd_get_arch_info (current_program_space->exec_bfd ());
       if (arch == exec_bfd_arch_info->arch)
 	return;
     }
@@ -594,7 +594,7 @@  rs6000_nat_target::create_inferior (const char *exec_file,
 
   gdbarch_info_init (&info);
   info.bfd_arch_info = bfd_get_arch_info (&abfd);
-  info.abfd = exec_bfd;
+  info.abfd = current_program_space->exec_bfd ();
 
   if (!gdbarch_update_p (info))
     internal_error (__FILE__, __LINE__,
diff --git a/gdb/sol-thread.c b/gdb/sol-thread.c
index a24d51d1db2..01e052dccdf 100644
--- a/gdb/sol-thread.c
+++ b/gdb/sol-thread.c
@@ -794,7 +794,7 @@  rw_common (int dowrite, const struct ps_prochandle *ph, psaddr_t addr,
 #if defined (__sparcv9)
   /* For Sparc64 cross Sparc32, make sure the address has not been
      accidentally sign-extended (or whatever) to beyond 32 bits.  */
-  if (bfd_get_arch_size (exec_bfd) == 32)
+  if (bfd_get_arch_size (current_program_space->exec_bfd ()) == 32)
     addr &= 0xffffffff;
 #endif
 
@@ -950,9 +950,9 @@  ps_lsetfpregs (struct ps_prochandle *ph, lwpid_t lwpid,
 ps_err_e
 ps_pdmodel (struct ps_prochandle *ph, int *data_model)
 {
-  if (exec_bfd == 0)
+  if (current_program_space->exec_bfd () == 0)
     *data_model = PR_MODEL_UNKNOWN;
-  else if (bfd_get_arch_size (exec_bfd) == 32)
+  else if (bfd_get_arch_size (current_program_space->exec_bfd ()) == 32)
     *data_model = PR_MODEL_ILP32;
   else
     *data_model = PR_MODEL_LP64;
diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c
index 3806c7e48cc..e55b2082949 100644
--- a/gdb/solib-darwin.c
+++ b/gdb/solib-darwin.c
@@ -192,12 +192,12 @@  find_program_interpreter (void)
 {
   char *buf = NULL;
 
-  /* If we have an exec_bfd, get the interpreter from the load commands.  */
-  if (exec_bfd)
+  /* If we have an current_program_space->exec_bfd (), get the interpreter from the load commands.  */
+  if (current_program_space->exec_bfd ())
     {
       bfd_mach_o_load_command *cmd;
 
-      if (bfd_mach_o_lookup_command (exec_bfd,
+      if (bfd_mach_o_lookup_command (current_program_space->exec_bfd (),
                                      BFD_MACH_O_LC_LOAD_DYLINKER, &cmd) == 1)
         return cmd->command.dylinker.name_str;
     }
@@ -543,7 +543,7 @@  darwin_solib_create_inferior_hook (int from_tty)
       CORE_ADDR vmaddr;
 
       /* Find the base address of the executable.  */
-      vmaddr = bfd_mach_o_get_base_address (exec_bfd);
+      vmaddr = bfd_mach_o_get_base_address (current_program_space->exec_bfd ());
 
       /* Relocate.  */
       if (vmaddr != load_addr)
@@ -557,7 +557,7 @@  darwin_solib_create_inferior_hook (int from_tty)
     {
       /* Dyld hasn't yet relocated itself, so the notifier address may
 	 be incorrect (as it has to be relocated).  */
-      CORE_ADDR start = bfd_get_start_address (exec_bfd);
+      CORE_ADDR start = bfd_get_start_address (current_program_space->exec_bfd ());
       if (start == 0)
 	notifier = 0;
       else
diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c
index ae76bb74c05..6b0f068191f 100644
--- a/gdb/solib-dsbt.c
+++ b/gdb/solib-dsbt.c
@@ -562,7 +562,7 @@  lm_base (void)
 			    "lm_base: get addr %x by _GLOBAL_OFFSET_TABLE_.\n",
 			    (unsigned int) addr);
     }
-  else if (scan_dyntag (DT_PLTGOT, exec_bfd, &addr))
+  else if (scan_dyntag (DT_PLTGOT, current_program_space->exec_bfd (), &addr))
     {
       struct int_elf32_dsbt_loadmap *ldm;
 
@@ -778,7 +778,7 @@  enable_break (void)
   asection *interp_sect;
   struct dsbt_info *info;
 
-  if (exec_bfd == NULL)
+  if (current_program_space->exec_bfd () == NULL)
     return 0;
 
   if (!target_has_execution)
@@ -793,7 +793,8 @@  enable_break (void)
 
   /* Find the .interp section; if not found, warn the user and drop
      into the old breakpoint at symbol code.  */
-  interp_sect = bfd_get_section_by_name (exec_bfd, ".interp");
+  interp_sect = bfd_get_section_by_name (current_program_space->exec_bfd (),
+					 ".interp");
   if (interp_sect)
     {
       unsigned int interp_sect_size;
@@ -806,8 +807,8 @@  enable_break (void)
 	 the contents specify the dynamic linker this program uses.  */
       interp_sect_size = bfd_section_size (interp_sect);
       buf = (char *) alloca (interp_sect_size);
-      bfd_get_section_contents (exec_bfd, interp_sect,
-				buf, 0, interp_sect_size);
+      bfd_get_section_contents (current_program_space->exec_bfd (),
+				interp_sect, buf, 0, interp_sect_size);
 
       /* Now we need to figure out where the dynamic linker was
 	 loaded so that we can load its symbols and place a breakpoint
diff --git a/gdb/solib-frv.c b/gdb/solib-frv.c
index bce33a3e4d6..08c9cf7ca5c 100644
--- a/gdb/solib-frv.c
+++ b/gdb/solib-frv.c
@@ -531,7 +531,8 @@  enable_break2 (void)
 
   /* Find the .interp section; if not found, warn the user and drop
      into the old breakpoint at symbol code.  */
-  interp_sect = bfd_get_section_by_name (exec_bfd, ".interp");
+  interp_sect = bfd_get_section_by_name (current_program_space->exec_bfd (),
+					 ".interp");
   if (interp_sect)
     {
       unsigned int interp_sect_size;
@@ -545,8 +546,8 @@  enable_break2 (void)
          the contents specify the dynamic linker this program uses.  */
       interp_sect_size = bfd_section_size (interp_sect);
       buf = (char *) alloca (interp_sect_size);
-      bfd_get_section_contents (exec_bfd, interp_sect,
-				buf, 0, interp_sect_size);
+      bfd_get_section_contents (current_program_space->exec_bfd (),
+				interp_sect, buf, 0, interp_sect_size);
 
       /* Now we need to figure out where the dynamic linker was
          loaded so that we can load its symbols and place a breakpoint
@@ -735,7 +736,8 @@  enable_break (void)
   /* Check for the presence of a .interp section.  If there is no
      such section, the executable is statically linked.  */
 
-  interp_sect = bfd_get_section_by_name (exec_bfd, ".interp");
+  interp_sect = bfd_get_section_by_name (current_program_space->exec_bfd (),
+					 ".interp");
 
   if (interp_sect == NULL)
     {
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 520d9e8ed12..7b004828761 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -554,20 +554,22 @@  read_program_header (int type, int *p_arch_size, CORE_ADDR *base_addr)
 static gdb::optional<gdb::byte_vector>
 find_program_interpreter (void)
 {
-  /* If we have an exec_bfd, use its section table.  */
-  if (exec_bfd
-      && bfd_get_flavour (exec_bfd) == bfd_target_elf_flavour)
+  /* If we have an current_program_space->exec_bfd (), use its section table.  */
+  if (current_program_space->exec_bfd ()
+      && (bfd_get_flavour (current_program_space->exec_bfd ())
+	  == bfd_target_elf_flavour))
    {
      struct bfd_section *interp_sect;
 
-     interp_sect = bfd_get_section_by_name (exec_bfd, ".interp");
+     interp_sect = bfd_get_section_by_name (current_program_space->exec_bfd (),
+					    ".interp");
      if (interp_sect != NULL)
       {
 	int sect_size = bfd_section_size (interp_sect);
 
 	gdb::byte_vector buf (sect_size);
-	bfd_get_section_contents (exec_bfd, interp_sect, buf.data (), 0,
-				  sect_size);
+	bfd_get_section_contents (current_program_space->exec_bfd (),
+				  interp_sect, buf.data (), 0, sect_size);
 	return buf;
       }
    }
@@ -762,7 +764,8 @@  elf_locate_base (void)
   /* Look for DT_MIPS_RLD_MAP first.  MIPS executables use this
      instead of DT_DEBUG, although they sometimes contain an unused
      DT_DEBUG.  */
-  if (scan_dyntag (DT_MIPS_RLD_MAP, exec_bfd, &dyn_ptr, NULL)
+  if (scan_dyntag (DT_MIPS_RLD_MAP, current_program_space->exec_bfd (),
+		   &dyn_ptr, NULL)
       || scan_dyntag_auxv (DT_MIPS_RLD_MAP, &dyn_ptr, NULL))
     {
       struct type *ptr_type = builtin_type (target_gdbarch ())->builtin_data_ptr;
@@ -780,7 +783,8 @@  elf_locate_base (void)
   /* Then check DT_MIPS_RLD_MAP_REL.  MIPS executables now use this form
      because of needing to support PIE.  DT_MIPS_RLD_MAP will also exist
      in non-PIE.  */
-  if (scan_dyntag (DT_MIPS_RLD_MAP_REL, exec_bfd, &dyn_ptr, &dyn_ptr_addr)
+  if (scan_dyntag (DT_MIPS_RLD_MAP_REL, current_program_space->exec_bfd (),
+		   &dyn_ptr, &dyn_ptr_addr)
       || scan_dyntag_auxv (DT_MIPS_RLD_MAP_REL, &dyn_ptr, &dyn_ptr_addr))
     {
       struct type *ptr_type = builtin_type (target_gdbarch ())->builtin_data_ptr;
@@ -796,7 +800,7 @@  elf_locate_base (void)
     }
 
   /* Find DT_DEBUG.  */
-  if (scan_dyntag (DT_DEBUG, exec_bfd, &dyn_ptr, NULL)
+  if (scan_dyntag (DT_DEBUG, current_program_space->exec_bfd (), &dyn_ptr, NULL)
       || scan_dyntag_auxv (DT_DEBUG, &dyn_ptr, NULL))
     return dyn_ptr;
 
@@ -1399,7 +1403,9 @@  svr4_current_sos_direct (struct svr4_info *info)
 
   /* Assume that everything is a library if the dynamic loader was loaded
      late by a static executable.  */
-  if (exec_bfd && bfd_get_section_by_name (exec_bfd, ".dynamic") == NULL)
+  if (current_program_space->exec_bfd ()
+      && bfd_get_section_by_name (current_program_space->exec_bfd (),
+				  ".dynamic") == NULL)
     ignore_first = 0;
   else
     ignore_first = 1;
@@ -2564,27 +2570,30 @@  svr4_exec_displacement (CORE_ADDR *displacementp)
      a call to gdbarch_convert_from_func_ptr_addr.  */
   CORE_ADDR entry_point, exec_displacement;
 
-  if (exec_bfd == NULL)
+  if (current_program_space->exec_bfd () == NULL)
     return 0;
 
   /* Therefore for ELF it is ET_EXEC and not ET_DYN.  Both shared libraries
      being executed themselves and PIE (Position Independent Executable)
      executables are ET_DYN.  */
 
-  if ((bfd_get_file_flags (exec_bfd) & DYNAMIC) == 0)
+  if ((bfd_get_file_flags (current_program_space->exec_bfd ()) & DYNAMIC) == 0)
     return 0;
 
   if (target_auxv_search (current_top_target (), AT_ENTRY, &entry_point) <= 0)
     return 0;
 
-  exec_displacement = entry_point - bfd_get_start_address (exec_bfd);
+  exec_displacement
+    = entry_point - bfd_get_start_address (current_program_space->exec_bfd ());
 
   /* Verify the EXEC_DISPLACEMENT candidate complies with the required page
      alignment.  It is cheaper than the program headers comparison below.  */
 
-  if (bfd_get_flavour (exec_bfd) == bfd_target_elf_flavour)
+  if (bfd_get_flavour (current_program_space->exec_bfd ())
+      == bfd_target_elf_flavour)
     {
-      const struct elf_backend_data *elf = get_elf_backend_data (exec_bfd);
+      const struct elf_backend_data *elf
+	= get_elf_backend_data (current_program_space->exec_bfd ());
 
       /* p_align of PT_LOAD segments does not specify any alignment but
 	 only congruency of addresses:
@@ -2601,7 +2610,8 @@  svr4_exec_displacement (CORE_ADDR *displacementp)
      looking at a different file than the one used by the kernel - for
      instance, "gdb program" connected to "gdbserver :PORT ld.so program".  */
 
-  if (bfd_get_flavour (exec_bfd) == bfd_target_elf_flavour)
+  if (bfd_get_flavour (current_program_space->exec_bfd ())
+      == bfd_target_elf_flavour)
     {
       /* Be optimistic and return 0 only if GDB was able to verify the headers
 	 really do not match.  */
@@ -2610,7 +2620,7 @@  svr4_exec_displacement (CORE_ADDR *displacementp)
       gdb::optional<gdb::byte_vector> phdrs_target
 	= read_program_header (-1, &arch_size, NULL);
       gdb::optional<gdb::byte_vector> phdrs_binary
-	= read_program_headers_from_bfd (exec_bfd);
+	= read_program_headers_from_bfd (current_program_space->exec_bfd ());
       if (phdrs_target && phdrs_binary)
 	{
 	  enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
@@ -2629,14 +2639,16 @@  svr4_exec_displacement (CORE_ADDR *displacementp)
 	     content offset for the verification purpose.  */
 
 	  if (phdrs_target->size () != phdrs_binary->size ()
-	      || bfd_get_arch_size (exec_bfd) != arch_size)
+	      || bfd_get_arch_size (current_program_space->exec_bfd ()) != arch_size)
 	    return 0;
 	  else if (arch_size == 32
 		   && phdrs_target->size () >= sizeof (Elf32_External_Phdr)
 	           && phdrs_target->size () % sizeof (Elf32_External_Phdr) == 0)
 	    {
-	      Elf_Internal_Ehdr *ehdr2 = elf_tdata (exec_bfd)->elf_header;
-	      Elf_Internal_Phdr *phdr2 = elf_tdata (exec_bfd)->phdr;
+	      Elf_Internal_Ehdr *ehdr2
+		= elf_tdata (current_program_space->exec_bfd ())->elf_header;
+	      Elf_Internal_Phdr *phdr2
+		= elf_tdata (current_program_space->exec_bfd ())->phdr;
 	      CORE_ADDR displacement = 0;
 	      int i;
 
@@ -2736,6 +2748,7 @@  svr4_exec_displacement (CORE_ADDR *displacementp)
 		    }
 
 		  /* prelink can convert .plt SHT_NOBITS to SHT_PROGBITS.  */
+		  bfd *exec_bfd = current_program_space->exec_bfd ();
 		  plt2_asect = bfd_get_section_by_name (exec_bfd, ".plt");
 		  if (plt2_asect)
 		    {
@@ -2770,8 +2783,8 @@  svr4_exec_displacement (CORE_ADDR *displacementp)
 		   && phdrs_target->size () >= sizeof (Elf64_External_Phdr)
 	           && phdrs_target->size () % sizeof (Elf64_External_Phdr) == 0)
 	    {
-	      Elf_Internal_Ehdr *ehdr2 = elf_tdata (exec_bfd)->elf_header;
-	      Elf_Internal_Phdr *phdr2 = elf_tdata (exec_bfd)->phdr;
+	      Elf_Internal_Ehdr *ehdr2 = elf_tdata (current_program_space->exec_bfd ())->elf_header;
+	      Elf_Internal_Phdr *phdr2 = elf_tdata (current_program_space->exec_bfd ())->phdr;
 	      CORE_ADDR displacement = 0;
 	      int i;
 
@@ -2870,7 +2883,7 @@  svr4_exec_displacement (CORE_ADDR *displacementp)
 		    }
 
 		  /* prelink can convert .plt SHT_NOBITS to SHT_PROGBITS.  */
-		  plt2_asect = bfd_get_section_by_name (exec_bfd, ".plt");
+		  plt2_asect = bfd_get_section_by_name (current_program_space->exec_bfd (), ".plt");
 		  if (plt2_asect)
 		    {
 		      int content2;
@@ -2883,7 +2896,7 @@  svr4_exec_displacement (CORE_ADDR *displacementp)
 		      filesz = extract_unsigned_integer (buf_filesz_p, 8,
 							 byte_order);
 
-		      /* PLT2_ASECT is from on-disk file (exec_bfd) while
+		      /* PLT2_ASECT is from on-disk file (current_program_space->exec_bfd ()) while
 			 FILESZ is from the in-memory image.  */
 		      if (content2)
 			filesz += bfd_section_size (plt2_asect);
@@ -2914,7 +2927,7 @@  svr4_exec_displacement (CORE_ADDR *displacementp)
       printf_unfiltered (_("Using PIE (Position Independent Executable) "
 			   "displacement %s for \"%s\".\n"),
 			 paddress (target_gdbarch (), exec_displacement),
-			 bfd_get_filename (exec_bfd));
+			 bfd_get_filename (current_program_space->exec_bfd ()));
     }
 
   *displacementp = exec_displacement;
@@ -2969,10 +2982,11 @@  svr4_relocate_main_executable (void)
 				   displacement);
       objfile_relocate (symfile_objfile, new_offsets);
     }
-  else if (exec_bfd)
+  else if (current_program_space->exec_bfd ())
     {
       asection *asect;
 
+      bfd *exec_bfd = current_program_space->exec_bfd ();
       for (asect = exec_bfd->sections; asect != NULL; asect = asect->next)
 	exec_set_section_address (bfd_get_filename (exec_bfd), asect->index,
 				  bfd_section_vma (asect) + displacement);
@@ -3228,7 +3242,7 @@  svr4_iterate_over_objfiles_in_search_order
         current_objfile = current_objfile->separate_debug_objfile_backlink;
 
       if (current_objfile == symfile_objfile)
-	abfd = exec_bfd;
+	abfd = current_program_space->exec_bfd ();
       else
 	abfd = current_objfile->obfd;
 
diff --git a/gdb/source-cache.c b/gdb/source-cache.c
index c67d087c76d..098fcf72e4e 100644
--- a/gdb/source-cache.c
+++ b/gdb/source-cache.c
@@ -68,7 +68,7 @@  source_cache::get_plain_source_lines (struct symtab *s,
   time_t mtime = 0;
   if (SYMTAB_OBJFILE (s) != NULL && SYMTAB_OBJFILE (s)->obfd != NULL)
     mtime = SYMTAB_OBJFILE (s)->mtime;
-  else if (exec_bfd)
+  else if (current_program_space->exec_bfd ())
     mtime = current_program_space->ebfd_mtime;
 
   if (mtime && mtime < st.st_mtime)
diff --git a/gdb/symfile-mem.c b/gdb/symfile-mem.c
index 78096fcbae1..fc5407c6372 100644
--- a/gdb/symfile-mem.c
+++ b/gdb/symfile-mem.c
@@ -145,7 +145,7 @@  add_symbol_file_from_memory_command (const char *args, int from_tty)
   if (symfile_objfile != NULL)
     templ = symfile_objfile->obfd;
   else
-    templ = exec_bfd;
+    templ = current_program_space->exec_bfd ();
   if (templ == NULL)
     error (_("Must use symbol-file or exec-file "
 	     "before add-symbol-file-from-memory."));
@@ -167,8 +167,8 @@  add_vsyscall_page (struct target_ops *target, int from_tty)
 
       if (core_bfd != NULL)
 	bfd = core_bfd;
-      else if (exec_bfd != NULL)
-	bfd = exec_bfd;
+      else if (current_program_space->exec_bfd () != NULL)
+	bfd = current_program_space->exec_bfd ();
       else
        /* FIXME: cagney/2004-05-06: Should not require an existing
 	  BFD when trying to create a run-time BFD of the VSYSCALL
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 2c38ce4431a..57ad9829dec 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -2483,9 +2483,9 @@  reread_symbols (void)
 	  /* We need to do this whenever any symbols go away.  */
 	  clear_symtab_users_cleanup defer_clear_users (0);
 
-	  if (exec_bfd != NULL
+	  if (current_program_space->exec_bfd () != NULL
 	      && filename_cmp (bfd_get_filename (objfile->obfd),
-			       bfd_get_filename (exec_bfd)) == 0)
+			       bfd_get_filename (current_program_space->exec_bfd ())) == 0)
 	    {
 	      /* Reload EXEC_BFD without asking anything.  */
 
diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c
index fd7bab822a1..167cc92b587 100644
--- a/gdb/tracefile-tfile.c
+++ b/gdb/tracefile-tfile.c
@@ -25,7 +25,7 @@ 
 #include "regcache.h"
 #include "inferior.h"
 #include "gdbthread.h"
-#include "exec.h" /* exec_bfd */
+#include "exec.h"
 #include "completer.h"
 #include "filenames.h"
 #include "remote.h"
diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c
index aa0adeba99b..6fcb629fe73 100644
--- a/gdb/windows-tdep.c
+++ b/gdb/windows-tdep.c
@@ -910,7 +910,8 @@  windows_solib_create_inferior_hook (int from_tty)
   /* Rebase executable if the base address changed because of ASLR.  */
   if (symfile_objfile != nullptr && exec_base != 0)
     {
-      CORE_ADDR vmaddr = pe_data (exec_bfd)->pe_opthdr.ImageBase;
+      CORE_ADDR vmaddr
+	= pe_data (current_program_space->exec_bfd ())->pe_opthdr.ImageBase;
       if (vmaddr != exec_base)
 	objfile_rebase (symfile_objfile, exec_base - vmaddr);
     }