From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.freebsd.org (mx2.freebsd.org [IPv6:2610:1c1:1:606c::19:2]) by sourceware.org (Postfix) with ESMTPS id 89757388F00B for ; Mon, 12 Jul 2021 15:56:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 89757388F00B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=FreeBSD.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits)) (Client CN "mx1.freebsd.org", Issuer "R3" (verified OK)) by mx2.freebsd.org (Postfix) with ESMTPS id 457C69FDC5; Mon, 12 Jul 2021 15:56:04 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4GNpK01Hv9z4d3X; Mon, 12 Jul 2021 15:56:04 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from John-Baldwins-MacBook-Pro.local (d-24-233-223-154.va.cpe.atlanticbb.net [24.233.223.154]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: jhb) by smtp.freebsd.org (Postfix) with ESMTPSA id F2AFFFB9D; Mon, 12 Jul 2021 15:56:03 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Subject: Re: [PATCH 2/5] fbsd-nat: Add helper functions to fetch and store register sets. To: Pedro Alves , gdb-patches@sourceware.org References: <20210528202614.2081-1-jhb@FreeBSD.org> <20210528202614.2081-3-jhb@FreeBSD.org> <86b3abdb-9924-209e-e918-386b4687ea86@palves.net> From: John Baldwin Message-ID: <702acf29-35f0-1b3c-3338-556db2427e15@FreeBSD.org> Date: Mon, 12 Jul 2021 11:56:03 -0400 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <86b3abdb-9924-209e-e918-386b4687ea86@palves.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, NICE_REPLY_A, SPF_HELO_NONE, SPF_PASS, TXREP 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: Mon, 12 Jul 2021 15:56:08 -0000 On 7/10/21 12:42 PM, Pedro Alves wrote: > On 2021-05-28 9:26 p.m., John Baldwin wrote: >> In particular, this supports register sets described by a regcache_map >> which are fetched and stored with dedicated ptrace operations. These >> functions are intended to be used in architecture-specific >> fetch_registers and store_registers target methods. >> >> gdb/ChangeLog: >> >> * fbsd-nat.h (fetch_register_set, store_register_set): New. >> --- >> gdb/ChangeLog | 4 ++++ >> gdb/fbsd-nat.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ >> 2 files changed, 48 insertions(+) >> >> diff --git a/gdb/ChangeLog b/gdb/ChangeLog >> index 2e61aead178..cb48a7f242d 100644 >> --- a/gdb/ChangeLog >> +++ b/gdb/ChangeLog >> @@ -1,3 +1,7 @@ >> +2021-05-28 John Baldwin >> + >> + * fbsd-nat.h (fetch_register_set, store_register_set): New. >> + >> 2021-05-28 John Baldwin >> >> * regcache.c (regcache_map_supplies): New. >> diff --git a/gdb/fbsd-nat.h b/gdb/fbsd-nat.h >> index 772655d320e..3cca361df4a 100644 >> --- a/gdb/fbsd-nat.h >> +++ b/gdb/fbsd-nat.h >> @@ -21,6 +21,8 @@ >> #define FBSD_NAT_H >> >> #include "inf-ptrace.h" >> +#include "regcache.h" >> +#include "regset.h" >> #include >> #include >> >> @@ -98,6 +100,48 @@ class fbsd_nat_target : public inf_ptrace_target >> #endif >> >> bool supports_multi_process () override; >> + >> +protected: >> + template >> + void fetch_register_set (struct regcache *regcache, int regnum, int fetch_op, >> + const struct regset *regset) >> + { >> + const struct regcache_map_entry *map = >> + (const struct regcache_map_entry *) regset->regmap; >> + pid_t pid = get_ptrace_pid (regcache->ptid ()); >> + R regs; >> + >> + if (regnum == -1 || regcache_map_supplies (map, regnum, regcache->arch(), >> + sizeof(regs))) >> + { >> + if (ptrace (fetch_op, pid, (PTRACE_TYPE_ARG3) ®s, 0) == -1) >> + perror_with_name (_("Couldn't get registers")); >> + >> + regcache->supply_regset (regset, regnum, ®s, sizeof (regs)); >> + } >> + } > > BTW, AFAICT, you could de-duplicate most of this template function by splitting > it in two, with the main worker part not needing doesn't need to care about R's type. > Something like: I've done that (with the change of putting the private methods in the .c file itself) along with fixing the style things. I've just mailed it out as a V2 of the series (easier to see the result). Thanks! -- John Baldwin