gdb: pass core file through gdbarch API when loading shared libraries

Continuing the removal of 'current_program_space->core_bfd ()' from
GDB, this commit updates two gdbarch methods:

  gdbarch_core_xfer_shared_libraries
  gdbarch_core_xfer_shared_libraries_aix

to take the core file BFD as a reference parameter.  For now this just
moves the 'current_program_space->core_bfd ()' calls up the program
stack into core_target::xfer_partial.  In the future I plan to move
the core file BFD object out of the program_space and into the
core_target, at which point these new global accesses can also be
removed.

There should be no user visible changes after this commit.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
This commit is contained in:
Andrew Burgess
2025-08-27 20:11:06 +01:00
parent cc91060a47
commit ce24177c04
7 changed files with 32 additions and 24 deletions

View File

@@ -1632,9 +1632,9 @@ core_target::xfer_partial (enum target_object object, const char *annex,
return TARGET_XFER_E_IO;
else
{
*xfered_len = gdbarch_core_xfer_shared_libraries (m_core_gdbarch,
readbuf,
offset, len);
*xfered_len = gdbarch_core_xfer_shared_libraries
(m_core_gdbarch, *current_program_space->core_bfd (),
readbuf, offset, len);
if (*xfered_len == 0)
return TARGET_XFER_EOF;
@@ -1653,9 +1653,9 @@ core_target::xfer_partial (enum target_object object, const char *annex,
else
{
*xfered_len
= gdbarch_core_xfer_shared_libraries_aix (m_core_gdbarch,
readbuf, offset,
len);
= gdbarch_core_xfer_shared_libraries_aix
(m_core_gdbarch, *current_program_space->core_bfd (),
readbuf, offset, len);
if (*xfered_len == 0)
return TARGET_XFER_EOF;

View File

@@ -3970,13 +3970,13 @@ gdbarch_core_xfer_shared_libraries_p (struct gdbarch *gdbarch)
}
ULONGEST
gdbarch_core_xfer_shared_libraries (struct gdbarch *gdbarch, gdb_byte *readbuf, ULONGEST offset, ULONGEST len)
gdbarch_core_xfer_shared_libraries (struct gdbarch *gdbarch, struct bfd &cbfd, gdb_byte *readbuf, ULONGEST offset, ULONGEST len)
{
gdb_assert (gdbarch != NULL);
gdb_assert (gdbarch->core_xfer_shared_libraries != NULL);
if (gdbarch_debug >= 2)
gdb_printf (gdb_stdlog, "gdbarch_core_xfer_shared_libraries called\n");
return gdbarch->core_xfer_shared_libraries (gdbarch, readbuf, offset, len);
return gdbarch->core_xfer_shared_libraries (gdbarch, cbfd, readbuf, offset, len);
}
void
@@ -3994,13 +3994,13 @@ gdbarch_core_xfer_shared_libraries_aix_p (struct gdbarch *gdbarch)
}
ULONGEST
gdbarch_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch, gdb_byte *readbuf, ULONGEST offset, ULONGEST len)
gdbarch_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch, struct bfd &cbfd, gdb_byte *readbuf, ULONGEST offset, ULONGEST len)
{
gdb_assert (gdbarch != NULL);
gdb_assert (gdbarch->core_xfer_shared_libraries_aix != NULL);
if (gdbarch_debug >= 2)
gdb_printf (gdb_stdlog, "gdbarch_core_xfer_shared_libraries_aix called\n");
return gdbarch->core_xfer_shared_libraries_aix (gdbarch, readbuf, offset, len);
return gdbarch->core_xfer_shared_libraries_aix (gdbarch, cbfd, readbuf, offset, len);
}
void

View File

@@ -1029,8 +1029,8 @@ extern void set_gdbarch_decode_memtag_section (struct gdbarch *gdbarch, gdbarch_
extern bool gdbarch_core_xfer_shared_libraries_p (struct gdbarch *gdbarch);
typedef ULONGEST (gdbarch_core_xfer_shared_libraries_ftype) (struct gdbarch *gdbarch, gdb_byte *readbuf, ULONGEST offset, ULONGEST len);
extern ULONGEST gdbarch_core_xfer_shared_libraries (struct gdbarch *gdbarch, gdb_byte *readbuf, ULONGEST offset, ULONGEST len);
typedef ULONGEST (gdbarch_core_xfer_shared_libraries_ftype) (struct gdbarch *gdbarch, struct bfd &cbfd, gdb_byte *readbuf, ULONGEST offset, ULONGEST len);
extern ULONGEST gdbarch_core_xfer_shared_libraries (struct gdbarch *gdbarch, struct bfd &cbfd, gdb_byte *readbuf, ULONGEST offset, ULONGEST len);
extern void set_gdbarch_core_xfer_shared_libraries (struct gdbarch *gdbarch, gdbarch_core_xfer_shared_libraries_ftype *core_xfer_shared_libraries);
/* Read offset OFFSET of TARGET_OBJECT_LIBRARIES_AIX formatted shared
@@ -1039,8 +1039,8 @@ extern void set_gdbarch_core_xfer_shared_libraries (struct gdbarch *gdbarch, gdb
extern bool gdbarch_core_xfer_shared_libraries_aix_p (struct gdbarch *gdbarch);
typedef ULONGEST (gdbarch_core_xfer_shared_libraries_aix_ftype) (struct gdbarch *gdbarch, gdb_byte *readbuf, ULONGEST offset, ULONGEST len);
extern ULONGEST gdbarch_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch, gdb_byte *readbuf, ULONGEST offset, ULONGEST len);
typedef ULONGEST (gdbarch_core_xfer_shared_libraries_aix_ftype) (struct gdbarch *gdbarch, struct bfd &cbfd, gdb_byte *readbuf, ULONGEST offset, ULONGEST len);
extern ULONGEST gdbarch_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch, struct bfd &cbfd, gdb_byte *readbuf, ULONGEST offset, ULONGEST len);
extern void set_gdbarch_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch, gdbarch_core_xfer_shared_libraries_aix_ftype *core_xfer_shared_libraries_aix);
/* How the core target converts a PTID from a core file to a string. */

View File

@@ -1738,7 +1738,12 @@ failed, otherwise, return the red length of READBUF.
""",
type="ULONGEST",
name="core_xfer_shared_libraries",
params=[("gdb_byte *", "readbuf"), ("ULONGEST", "offset"), ("ULONGEST", "len")],
params=[
("struct bfd &", "cbfd"),
("gdb_byte *", "readbuf"),
("ULONGEST", "offset"),
("ULONGEST", "len"),
],
predicate=True,
)
@@ -1750,7 +1755,12 @@ Return the number of bytes read (zero indicates failure).
""",
type="ULONGEST",
name="core_xfer_shared_libraries_aix",
params=[("gdb_byte *", "readbuf"), ("ULONGEST", "offset"), ("ULONGEST", "len")],
params=[
("struct bfd &", "cbfd"),
("gdb_byte *", "readbuf"),
("ULONGEST", "offset"),
("ULONGEST", "len"),
],
predicate=True,
)

View File

@@ -1330,6 +1330,7 @@ rs6000_aix_ld_info_to_xml (struct gdbarch *gdbarch, const gdb_byte *ldi_buf,
static ULONGEST
rs6000_aix_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch,
struct bfd &cbfd,
gdb_byte *readbuf,
ULONGEST offset,
ULONGEST len)
@@ -1337,8 +1338,7 @@ rs6000_aix_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch,
struct bfd_section *ldinfo_sec;
int ldinfo_size;
ldinfo_sec = bfd_get_section_by_name (current_program_space->core_bfd (),
".ldinfo");
ldinfo_sec = bfd_get_section_by_name (&cbfd, ".ldinfo");
if (ldinfo_sec == NULL)
error (_("cannot find .ldinfo section from core file: %s"),
bfd_errmsg (bfd_get_error ()));
@@ -1346,8 +1346,7 @@ rs6000_aix_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch,
gdb::byte_vector ldinfo_buf (ldinfo_size);
if (! bfd_get_section_contents (current_program_space->core_bfd (),
ldinfo_sec, ldinfo_buf.data (), 0,
if (! bfd_get_section_contents (&cbfd, ldinfo_sec, ldinfo_buf.data (), 0,
ldinfo_size))
error (_("unable to read .ldinfo section from core file: %s"),
bfd_errmsg (bfd_get_error ()));

View File

@@ -1162,13 +1162,11 @@ core_process_module_section (bfd *abfd, asection *sect, void *obj)
ULONGEST
windows_core_xfer_shared_libraries (struct gdbarch *gdbarch,
gdb_byte *readbuf,
struct bfd &cbfd, gdb_byte *readbuf,
ULONGEST offset, ULONGEST len)
{
cpms_data data { gdbarch, "<library-list>\n", 0 };
bfd_map_over_sections (current_program_space->core_bfd (),
core_process_module_section,
&data);
bfd_map_over_sections (&cbfd, core_process_module_section, &data);
data.xml += "</library-list>\n";
ULONGEST len_avail = data.xml.length ();

View File

@@ -33,6 +33,7 @@ extern void windows_xfer_shared_library (const char* so_name,
std::string &xml);
extern ULONGEST windows_core_xfer_shared_libraries (struct gdbarch *gdbarch,
struct bfd &cbfd,
gdb_byte *readbuf,
ULONGEST offset,
ULONGEST len);