From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 74ADD3858C1F for ; Tue, 22 Nov 2022 20:38:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 74ADD3858C1F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca Received: from [172.16.0.64] (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id F30CB1E0CB; Tue, 22 Nov 2022 15:38:30 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1669149511; bh=0NIijUHZaLo6oC1tfycGQHI6esqZceuBPlm9XV+09V8=; h=Date:Subject:To:References:From:In-Reply-To:From; b=Q3FjJb48F1Ic4Tg4Ncl3dSu/sC43/YYAXnjenJCcFzh8yX6vf+Z52xNJ3QxnesMje 9PQEd5lgGgXGobFi6Dbj9PAJ0g0x5i8HxWMZsTm3biQk09BxbJxNGC+GlY1oks3x3E DEJl815IxSnSPdh2O7tUWeoTJfu8XGWxXro2o7vk= Message-ID: <7fc99741-64d8-f213-ea64-aa401bd42d4c@simark.ca> Date: Tue, 22 Nov 2022 15:38:30 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: Re: [PATCH 3/5] fbsd-nat: Pass an optional register base to the register set helpers. Content-Language: fr To: John Baldwin , gdb-patches@sourceware.org References: <20220708005816.9408-1-jhb@FreeBSD.org> <20220708005816.9408-4-jhb@FreeBSD.org> From: Simon Marchi In-Reply-To: <20220708005816.9408-4-jhb@FreeBSD.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,SPF_HELO_PASS,SPF_PASS,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 List-Id: On 7/7/22 20:58, John Baldwin wrote: > This is needed to permit using the helpers for register sets with a > variable base. In particular regnum needs to be converted into a > relative register number before passed to regcache_map_supplies. > --- > gdb/fbsd-nat.c | 34 +++++++++++++++++++--------------- > gdb/fbsd-nat.h | 49 ++++++++++++++++++++++++++++--------------------- > 2 files changed, 47 insertions(+), 36 deletions(-) > > diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c > index 9d7383ac0ab..edcd3fc3ed1 100644 > --- a/gdb/fbsd-nat.c > +++ b/gdb/fbsd-nat.c > @@ -1732,14 +1732,15 @@ fbsd_nat_target::supports_disable_randomization () > bool > fbsd_nat_target::fetch_register_set (struct regcache *regcache, int regnum, > int fetch_op, const struct regset *regset, > - void *regs, size_t size) > + int regbase, 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)) > + if (regnum == -1 > + || (regnum >= regbase && regcache_map_supplies (map, regnum - regbase, > + regcache->arch(), size))) My understanding is that it would be an internal error if the caller passed a regnum that is < regbase. In order words, should you do: gdb_assert (regnum >= regbase); ? Actually, after reading the following patches, I think the answer is no. When requesting a single register, we will still go through all the fetch functions and we expect them to do nothing if the register is not theirs. Leaving the question there in case others wonder about the same thing. I was also wondering if it would be better to do the absolute -> relative conversion in the caller. All this function knows is the regset-relative view of things. In the end it doesn't matter much, it just moves a condition from here to the callers. I'm fine with whatever you prefer. Approved-By: Simon Marchi Simon