From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.baldwin.cx (bigwig.baldwin.cx [66.216.25.90]) by sourceware.org (Postfix) with ESMTPS id 74C98394D881 for ; Wed, 16 Mar 2022 19:46:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 74C98394D881 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=FreeBSD.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=FreeBSD.org Received: from ralph.com (ralph.baldwin.cx [66.234.199.215]) by mail.baldwin.cx (Postfix) with ESMTPSA id CCA251A84C75 for ; Wed, 16 Mar 2022 15:46:16 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Subject: [RFC PATCH 2/4] core: Support fetching TARGET_OBJECT_X86_XSAVE_OFFSETS from architectures. Date: Wed, 16 Mar 2022 12:46:06 -0700 Message-Id: <20220316194608.89528-3-jhb@FreeBSD.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220316194608.89528-1-jhb@FreeBSD.org> References: <20220316194608.89528-1-jhb@FreeBSD.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.6.4 (mail.baldwin.cx [0.0.0.0]); Wed, 16 Mar 2022 15:46:17 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.103.1 at mail.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_STATUS, KHOP_HELO_FCRDNS, SPF_HELO_PASS, SPF_SOFTFAIL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Mar 2022 19:46:19 -0000 Add gdbarch_core_xfer_x86_xsave_offsets to fetch the x86 XSAVE offsets structure from a core file. --- gdb/corelow.c | 22 ++++++++++++++++++++++ gdb/gdbarch-components.py | 13 +++++++++++++ gdb/gdbarch-gen.h | 10 ++++++++++ gdb/gdbarch.c | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+) diff --git a/gdb/corelow.c b/gdb/corelow.c index f7f2bd3f318..c945d47df29 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -987,6 +987,28 @@ core_target::xfer_partial (enum target_object object, const char *annex, } return TARGET_XFER_E_IO; + case TARGET_OBJECT_X86_XSAVE_OFFSETS: + if (readbuf) + { + if (m_core_gdbarch != nullptr + && gdbarch_core_xfer_x86_xsave_offsets_p (m_core_gdbarch)) + { + LONGEST l = gdbarch_core_xfer_x86_xsave_offsets (m_core_gdbarch, + readbuf, offset, + len); + + if (l >= 0) + { + *xfered_len = l; + if (l == 0) + return TARGET_XFER_EOF; + else + return TARGET_XFER_OK; + } + } + } + return TARGET_XFER_E_IO; + default: fallthrough: return this->beneath ()->xfer_partial (object, annex, readbuf, diff --git a/gdb/gdbarch-components.py b/gdb/gdbarch-components.py index 4987f8a5fef..9c88433f02f 100644 --- a/gdb/gdbarch-components.py +++ b/gdb/gdbarch-components.py @@ -1585,6 +1585,19 @@ of bytes read (zero indicates EOF, a negative value indicates failure). invalid=True, ) +Method( + comment=""" +Read offset OFFSET of TARGET_OBJECT_X86_XSAVE_OFFSETS from core file +into buffer READBUF with length LEN. Return the number of bytes read +(zero indicates EOF, a negative value indicates failure). +""", + type="LONGEST", + name="core_xfer_x86_xsave_offsets", + params=[("gdb_byte *", "readbuf"), ("ULONGEST", "offset"), ("ULONGEST", "len")], + predicate=True, + invalid=True, +) + Value( comment=""" BFD target to use when generating a core file. diff --git a/gdb/gdbarch-gen.h b/gdb/gdbarch-gen.h index b7beb73d36d..9dca81b9c85 100644 --- a/gdb/gdbarch-gen.h +++ b/gdb/gdbarch-gen.h @@ -923,6 +923,16 @@ typedef LONGEST (gdbarch_core_xfer_siginfo_ftype) (struct gdbarch *gdbarch, gdb_ extern LONGEST gdbarch_core_xfer_siginfo (struct gdbarch *gdbarch, gdb_byte *readbuf, ULONGEST offset, ULONGEST len); extern void set_gdbarch_core_xfer_siginfo (struct gdbarch *gdbarch, gdbarch_core_xfer_siginfo_ftype *core_xfer_siginfo); +/* Read offset OFFSET of TARGET_OBJECT_X86_XSAVE_OFFSETS from core file + into buffer READBUF with length LEN. Return the number of bytes read + (zero indicates EOF, a negative value indicates failure). */ + +extern bool gdbarch_core_xfer_x86_xsave_offsets_p (struct gdbarch *gdbarch); + +typedef LONGEST (gdbarch_core_xfer_x86_xsave_offsets_ftype) (struct gdbarch *gdbarch, gdb_byte *readbuf, ULONGEST offset, ULONGEST len); +extern LONGEST gdbarch_core_xfer_x86_xsave_offsets (struct gdbarch *gdbarch, gdb_byte *readbuf, ULONGEST offset, ULONGEST len); +extern void set_gdbarch_core_xfer_x86_xsave_offsets (struct gdbarch *gdbarch, gdbarch_core_xfer_x86_xsave_offsets_ftype *core_xfer_x86_xsave_offsets); + /* BFD target to use when generating a core file. */ extern bool gdbarch_gcore_bfd_target_p (struct gdbarch *gdbarch); diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c index 55dd602b27f..7d2d8dbdb4b 100644 --- a/gdb/gdbarch.c +++ b/gdb/gdbarch.c @@ -176,6 +176,7 @@ struct gdbarch gdbarch_core_pid_to_str_ftype *core_pid_to_str; gdbarch_core_thread_name_ftype *core_thread_name; gdbarch_core_xfer_siginfo_ftype *core_xfer_siginfo; + gdbarch_core_xfer_x86_xsave_offsets_ftype *core_xfer_x86_xsave_offsets; const char * gcore_bfd_target; int vtable_function_descriptors; int vbit_in_delta; @@ -527,6 +528,7 @@ verify_gdbarch (struct gdbarch *gdbarch) /* Skip verify of core_pid_to_str, has predicate. */ /* Skip verify of core_thread_name, has predicate. */ /* Skip verify of core_xfer_siginfo, has predicate. */ + /* Skip verify of core_xfer_x86_xsave_offsets, has predicate. */ /* Skip verify of gcore_bfd_target, has predicate. */ /* Skip verify of vtable_function_descriptors, invalid_p == 0 */ /* Skip verify of vbit_in_delta, invalid_p == 0 */ @@ -1122,6 +1124,12 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file) fprintf_filtered (file, "gdbarch_dump: core_xfer_siginfo = <%s>\n", host_address_to_string (gdbarch->core_xfer_siginfo)); + fprintf_filtered (file, + "gdbarch_dump: gdbarch_core_xfer_x86_xsave_offsets_p() = %d\n", + gdbarch_core_xfer_x86_xsave_offsets_p (gdbarch)); + fprintf_filtered (file, + "gdbarch_dump: core_xfer_x86_xsave_offsets = <%s>\n", + host_address_to_string (gdbarch->core_xfer_x86_xsave_offsets)); fprintf_filtered (file, "gdbarch_dump: gdbarch_gcore_bfd_target_p() = %d\n", gdbarch_gcore_bfd_target_p (gdbarch)); @@ -3865,6 +3873,30 @@ set_gdbarch_core_xfer_siginfo (struct gdbarch *gdbarch, gdbarch->core_xfer_siginfo = core_xfer_siginfo; } +bool +gdbarch_core_xfer_x86_xsave_offsets_p (struct gdbarch *gdbarch) +{ + gdb_assert (gdbarch != NULL); + return gdbarch->core_xfer_x86_xsave_offsets != NULL; +} + +LONGEST +gdbarch_core_xfer_x86_xsave_offsets (struct gdbarch *gdbarch, gdb_byte *readbuf, ULONGEST offset, ULONGEST len) +{ + gdb_assert (gdbarch != NULL); + gdb_assert (gdbarch->core_xfer_x86_xsave_offsets != NULL); + if (gdbarch_debug >= 2) + fprintf_unfiltered (gdb_stdlog, "gdbarch_core_xfer_x86_xsave_offsets called\n"); + return gdbarch->core_xfer_x86_xsave_offsets (gdbarch, readbuf, offset, len); +} + +void +set_gdbarch_core_xfer_x86_xsave_offsets (struct gdbarch *gdbarch, + gdbarch_core_xfer_x86_xsave_offsets_ftype core_xfer_x86_xsave_offsets) +{ + gdbarch->core_xfer_x86_xsave_offsets = core_xfer_x86_xsave_offsets; +} + bool gdbarch_gcore_bfd_target_p (struct gdbarch *gdbarch) { -- 2.34.1