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; }
return m_expected_exec_filename;
}
+ bfd *core_bfd () const
+ { return m_core_bfd.get (); }
+
private: /* per-core data */
/* Get rid of the core inferior. */
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. */
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);
}
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 ();
}
/* 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)
{
/* 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 ®ion : file_data.regions)
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. */
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 ());
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);
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);
/* 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;
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)
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);
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);
/* 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 ();
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)
}
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 ());
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
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;
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;
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;
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;
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;
{
*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;
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);
/* 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';
{
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;
}
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);
}
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. */
/* 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;
}
/* 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. */
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);
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 {};
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
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 ());
}
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);
}