From patchwork Mon Oct 9 18:36:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 77312 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 259F63861816 for ; Mon, 9 Oct 2023 18:38:07 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail.baldwin.cx (bigwig.baldwin.cx [IPv6:2607:f138:0:13::2]) by sourceware.org (Postfix) with ESMTPS id 6E02E385694E for ; Mon, 9 Oct 2023 18:36:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6E02E385694E 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.baldwin.net (unknown [98.47.15.113]) by mail.baldwin.cx (Postfix) with ESMTPSA id 5C0BA1A84E33; Mon, 9 Oct 2023 14:36:49 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Cc: Willgerodt@sourceware.org, Felix , George@sourceware.org, Jini Susan , Simon Marchi Subject: [RFC 11/13] x86-linux-nat: Support fetching TARGET_OBJECT_X86_CPUID objects Date: Mon, 9 Oct 2023 11:36:13 -0700 Message-ID: <20231009183617.24862-12-jhb@FreeBSD.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231009183617.24862-1-jhb@FreeBSD.org> References: <20231009183617.24862-1-jhb@FreeBSD.org> MIME-Version: 1.0 X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.6.4 (mail.baldwin.cx [0.0.0.0]); Mon, 09 Oct 2023 14:36:50 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.103.1 at mail.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_STATUS, KHOP_HELO_FCRDNS, SPF_HELO_PASS, SPF_SOFTFAIL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org When probing for the cached XSAVE layout, fetch the CPUID note data and cache it until needed for a future fetch via ::xfer_partial. --- gdb/configure.nat | 7 ++++--- gdb/x86-linux-nat.c | 37 +++++++++++++++++++++++++++++++++++++ gdb/x86-linux-nat.h | 9 +++++++++ 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/gdb/configure.nat b/gdb/configure.nat index 4ed71d8619d..c540e070dbb 100644 --- a/gdb/configure.nat +++ b/gdb/configure.nat @@ -255,8 +255,8 @@ case ${gdb_host} in ;; i386) # Host: Intel 386 running GNU/Linux. - NATDEPFILES="${NATDEPFILES} x86-nat.o nat/x86-dregs.o \ - nat/x86-xstate.o \ + NATDEPFILES="${NATDEPFILES} x86-nat.o nat/x86-cpuid.o \ + nat/x86-dregs.o nat/x86-xstate.o \ i386-linux-nat.o x86-linux-nat.o nat/linux-btrace.o \ nat/x86-linux.o nat/x86-linux-dregs.o" ;; @@ -321,7 +321,8 @@ case ${gdb_host} in case ${gdb_host_cpu} in i386) # Host: GNU/Linux x86-64 - NATDEPFILES="${NATDEPFILES} x86-nat.o nat/x86-dregs.o \ + NATDEPFILES="${NATDEPFILES} x86-nat.o nat/x86-cpuid.o \ + nat/x86-dregs.o \ nat/x86-xstate.o amd64-nat.o amd64-linux-nat.o x86-linux-nat.o \ nat/linux-btrace.o \ nat/x86-linux.o nat/x86-linux-dregs.o \ diff --git a/gdb/x86-linux-nat.c b/gdb/x86-linux-nat.c index cd8fd9c1dcd..517faccf934 100644 --- a/gdb/x86-linux-nat.c +++ b/gdb/x86-linux-nat.c @@ -36,6 +36,7 @@ #include "amd64-linux-tdep.h" #endif #include "gdbsupport/x86-xstate.h" +#include "nat/x86-cpuid.h" #include "nat/x86-xstate.h" #include "nat/linux-btrace.h" #include "nat/linux-nat.h" @@ -182,6 +183,8 @@ x86_linux_nat_target::read_description () / sizeof (uint64_t))]; m_xsave_layout = x86_fetch_xsave_layout (xcr0, x86_xsave_length ()); + + x86_cpuid_note (m_cpuid_note, m_cpuid_note_len); } } @@ -213,6 +216,40 @@ x86_linux_nat_target::read_description () gdb_assert_not_reached ("failed to return tdesc"); } + +enum target_xfer_status +x86_linux_nat_target::xfer_partial (enum target_object object, + const char *annex, gdb_byte *readbuf, + const gdb_byte *writebuf, + ULONGEST offset, ULONGEST len, + ULONGEST *xfered_len) +{ + switch (object) + { + case TARGET_OBJECT_X86_CPUID: + if (readbuf) + { + size_t size = m_cpuid_note_len; + if (offset >= size) + return TARGET_XFER_EOF; + size -= offset; + if (size > len) + size = len; + + if (size == 0) + return TARGET_XFER_EOF; + + memcpy (readbuf, m_cpuid_note.get () + offset, size); + *xfered_len = size; + return TARGET_XFER_OK; + } + return TARGET_XFER_E_IO; + default: + return linux_nat_target::xfer_partial (object, annex, readbuf, + writebuf, offset, len, + xfered_len); + } +} /* Enable branch tracing. */ diff --git a/gdb/x86-linux-nat.h b/gdb/x86-linux-nat.h index a0f8ffc993e..c2a6452ce27 100644 --- a/gdb/x86-linux-nat.h +++ b/gdb/x86-linux-nat.h @@ -45,6 +45,13 @@ struct x86_linux_nat_target : public x86_nat_target x86_xsave_layout fetch_x86_xsave_layout () override { return m_xsave_layout; } + enum target_xfer_status xfer_partial (enum target_object object, + const char *annex, + gdb_byte *readbuf, + const gdb_byte *writebuf, + ULONGEST offset, ULONGEST len, + ULONGEST *xfered_len) override; + /* These two are rewired to low_ versions. linux-nat.c queries stopped-by-watchpoint info as soon as an lwp stops (via the low_ methods) and caches the result, to be returned via the normal @@ -81,6 +88,8 @@ struct x86_linux_nat_target : public x86_nat_target private: x86_xsave_layout m_xsave_layout; + gdb::unique_xmalloc_ptr m_cpuid_note; + size_t m_cpuid_note_len; };