gdb: remove program_space::core_bfd member function

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>
This commit is contained in:
Andrew Burgess
2025-09-10 11:04:45 +01:00
parent c97e57bc9d
commit 84f8be0d9c
13 changed files with 32 additions and 40 deletions

View 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."));
}
}

View 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);

View 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)

View 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;

View 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 ())

View 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. */

View 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 ()
{

View 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. */

View 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 ();

View 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. */

View 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. */

View 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. */

View 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