diff --git a/gdb/corefile.c b/gdb/corefile.c index a2c75c02c2f..666ff55e814 100644 --- a/gdb/corefile.c +++ b/gdb/corefile.c @@ -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.")); } } diff --git a/gdb/corelow.c b/gdb/corelow.c index 6175e967a33..d48154de1f5 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -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); diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c index c0a93e8871a..a2f000b87cb 100644 --- a/gdb/fbsd-tdep.c +++ b/gdb/fbsd-tdep.c @@ -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) diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index 3c813f51d4f..77557d53fde 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -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 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; diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c index 63e4c69c981..f00e3b53375 100644 --- a/gdb/linux-thread-db.c +++ b/gdb/linux-thread-db.c @@ -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 ()) diff --git a/gdb/maint.c b/gdb/maint.c index ca7648f1030..576582925c6 100644 --- a/gdb/maint.c +++ b/gdb/maint.c @@ -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. */ diff --git a/gdb/progspace.c b/gdb/progspace.c index 59b9c8c6b31..6ee0134f20b 100644 --- a/gdb/progspace.c +++ b/gdb/progspace.c @@ -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 () { diff --git a/gdb/progspace.h b/gdb/progspace.h index 302520e85f4..1cf60420f73 100644 --- a/gdb/progspace.h +++ b/gdb/progspace.h @@ -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. */ diff --git a/gdb/record-full.c b/gdb/record-full.c index 22227c33c2a..396ba3283e1 100644 --- a/gdb/record-full.c +++ b/gdb/record-full.c @@ -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 (); diff --git a/gdb/sol-thread.c b/gdb/sol-thread.c index 55e1d3e2595..0aa45950696 100644 --- a/gdb/sol-thread.c +++ b/gdb/sol-thread.c @@ -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. */ diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c index 719678b56aa..883164eda04 100644 --- a/gdb/solib-dsbt.c +++ b/gdb/solib-dsbt.c @@ -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. */ diff --git a/gdb/solib-frv.c b/gdb/solib-frv.c index ac5872e2938..beb880228fc 100644 --- a/gdb/solib-frv.c +++ b/gdb/solib-frv.c @@ -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. */ diff --git a/gdb/symfile-mem.c b/gdb/symfile-mem.c index 274dc0f57b9..9bf79f7dbdf 100644 --- a/gdb/symfile-mem.c +++ b/gdb/symfile-mem.c @@ -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