From: Andrew Burgess Date: Wed, 27 Aug 2025 19:11:06 +0000 (+0100) Subject: gdb: pass core file through gdbarch API when loading shared libraries X-Git-Tag: gdb-17-branchpoint~13 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ce24177c0492757a3de465011e180fc3fb66021e;p=thirdparty%2Fbinutils-gdb.git 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 --- diff --git a/gdb/corelow.c b/gdb/corelow.c index b91f4900274..abcf9f9848c 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -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; diff --git a/gdb/gdbarch-gen.c b/gdb/gdbarch-gen.c index 025e5664be4..01f8e1b045c 100644 --- a/gdb/gdbarch-gen.c +++ b/gdb/gdbarch-gen.c @@ -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 diff --git a/gdb/gdbarch-gen.h b/gdb/gdbarch-gen.h index 2870e7c9b93..1de58512ec9 100644 --- a/gdb/gdbarch-gen.h +++ b/gdb/gdbarch-gen.h @@ -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. */ diff --git a/gdb/gdbarch_components.py b/gdb/gdbarch_components.py index 20f9c8059f3..323f81ce4c0 100644 --- a/gdb/gdbarch_components.py +++ b/gdb/gdbarch_components.py @@ -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, ) diff --git a/gdb/rs6000-aix-tdep.c b/gdb/rs6000-aix-tdep.c index 6322bbc62cf..536f6473f88 100644 --- a/gdb/rs6000-aix-tdep.c +++ b/gdb/rs6000-aix-tdep.c @@ -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 ())); diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c index 9157ebe03b3..c6f5803f37a 100644 --- a/gdb/windows-tdep.c +++ b/gdb/windows-tdep.c @@ -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, "\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 += "\n"; ULONGEST len_avail = data.xml.length (); diff --git a/gdb/windows-tdep.h b/gdb/windows-tdep.h index 87a618edfd0..4d8e6bc8226 100644 --- a/gdb/windows-tdep.h +++ b/gdb/windows-tdep.h @@ -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);