From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.baldwin.cx (bigwig.baldwin.cx [IPv6:2607:f138:0:13::2]) by sourceware.org (Postfix) with ESMTPS id E8D94386549C; Wed, 23 Mar 2022 21:00:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E8D94386549C 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 330631A84C75; Wed, 23 Mar 2022 17:00:55 -0400 (EDT) From: John Baldwin To: binutils@sourceware.org, gdb-patches@sourceware.org Subject: [PATCH 02/12] fbsd-nat: Add helper routines for register sets using PT_[G]SETREGSET. Date: Wed, 23 Mar 2022 14:00:41 -0700 Message-Id: <20220323210048.25525-3-jhb@FreeBSD.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220323210048.25525-1-jhb@FreeBSD.org> References: <20220323210048.25525-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, 23 Mar 2022 17:00:55 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.103.1 at mail.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-12.2 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: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Mar 2022 21:00:58 -0000 FreeBSD's kernel has recently added PT_GETREGSET and PT_SETREGSET operations to fetch a register set named by an ELF note type. These helper routines provide helpers to check for a register set's existence, fetch registers for a register set, and store registers to a register set. --- gdb/fbsd-nat.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++ gdb/fbsd-nat.h | 42 +++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c index 934fdbad6ef..84abdd9a322 100644 --- a/gdb/fbsd-nat.c +++ b/gdb/fbsd-nat.c @@ -1772,6 +1772,78 @@ fbsd_nat_target::store_register_set (struct regcache *regcache, int regnum, return false; } +#ifdef PT_GETREGSET +/* See fbsd-nat.h. */ + +bool +fbsd_nat_target::have_regset (ptid_t ptid, int note) +{ + pid_t pid = get_ptrace_pid (ptid); + struct iovec iov; + + iov.iov_base = nullptr; + iov.iov_len = 0; + if (ptrace (PT_GETREGSET, pid, (PTRACE_TYPE_ARG3) &iov, note) == -1) + return 0; + return iov.iov_len; +} + +/* See fbsd-nat.h. */ + +bool +fbsd_nat_target::fetch_regset (struct regcache *regcache, int regnum, int note, + const struct regset *regset, void *regs, + size_t size) +{ + const struct regcache_map_entry *map + = (const struct regcache_map_entry *) regset->regmap; + pid_t pid = get_ptrace_pid (regcache->ptid ()); + + if (regnum == -1 || regcache_map_supplies (map, regnum, regcache->arch(), + size)) + { + struct iovec iov; + + iov.iov_base = regs; + iov.iov_len = size; + if (ptrace (PT_GETREGSET, pid, (PTRACE_TYPE_ARG3) &iov, note) == -1) + perror_with_name (_("Couldn't get registers")); + + regcache->supply_regset (regset, regnum, regs, size); + return true; + } + return false; +} + +bool +fbsd_nat_target::store_regset (struct regcache *regcache, int regnum, int note, + const struct regset *regset, void *regs, + size_t size) +{ + const struct regcache_map_entry *map + = (const struct regcache_map_entry *) regset->regmap; + pid_t pid = get_ptrace_pid (regcache->ptid ()); + + if (regnum == -1 || regcache_map_supplies (map, regnum, regcache->arch(), + size)) + { + struct iovec iov; + + iov.iov_base = regs; + iov.iov_len = size; + if (ptrace (PT_GETREGSET, pid, (PTRACE_TYPE_ARG3) &iov, note) == -1) + perror_with_name (_("Couldn't get registers")); + + regcache->collect_regset (regset, regnum, regs, size); + + if (ptrace (PT_SETREGSET, pid, (PTRACE_TYPE_ARG3) &iov, note) == -1) + perror_with_name (_("Couldn't write registers")); + return true; + } + return false; +} +#endif + /* See fbsd-nat.h. */ bool diff --git a/gdb/fbsd-nat.h b/gdb/fbsd-nat.h index 82f7ee47949..6a4003627e4 100644 --- a/gdb/fbsd-nat.h +++ b/gdb/fbsd-nat.h @@ -151,6 +151,19 @@ class fbsd_nat_target : public inf_ptrace_target bool store_register_set (struct regcache *regcache, int regnum, int fetch_op, int store_op, const struct regset *regset, void *regs, size_t size); + +#ifdef PT_GETREGSET + /* Helper routines which use PT_GETREGSET and PT_SETREGSET for the + specified NOTE instead of regset-specific fetch and store + ops. */ + + bool fetch_regset (struct regcache *regcache, int regnum, int note, + const struct regset *regset, void *regs, size_t size); + + bool store_regset (struct regcache *regcache, int regnum, int note, + const struct regset *regset, void *regs, size_t size); +#endif + protected: /* Wrapper versions of the above helpers which accept a register set type such as 'struct reg' or 'struct fpreg'. */ @@ -172,6 +185,35 @@ class fbsd_nat_target : public inf_ptrace_target return store_register_set (regcache, regnum, fetch_op, store_op, regset, ®s, sizeof (regs)); } + +#ifdef PT_GETREGSET + /* Helper routine for use in read_description in subclasses. This + routine checks if the register set for the specified NOTE is + present for a given PTID. If the register set is present, the + the size of the register set is returned. If the register set is + not present, zero is returned. */ + + bool have_regset (ptid_t ptid, int note); + + /* Wrapper versions of the PT_GETREGSET and PT_REGSET helpers which + accept a register set type. */ + + template + bool fetch_regset (struct regcache *regcache, int regnum, int note, + const struct regset *regset) + { + Regset regs; + return fetch_regset (regcache, regnum, note, regset, ®s, sizeof (regs)); + } + + template + bool store_regset (struct regcache *regcache, int regnum, int note, + const struct regset *regset) + { + Regset regs; + return store_regset (regcache, regnum, note, regset, ®s, sizeof (regs)); + } +#endif }; /* Fetch the signal information for PTID and store it in *SIGINFO. -- 2.34.1