Re: [PATCH 3/5] fbsd-nat: Pass an optional register base to the register set helpers.

John Baldwin
2022-11-22T22:16:25Z

On 11/22/22 12:38 PM, Simon Marchi wrote:
> 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.

If you do the adjustment to an absolute value in the caller you have to still
special case for regnum == -1 when fetching all registers. The current approach
here means that the special case for that is handled down in
regcache:transfer_regset which already has a special case for -1.

--
John Baldwin