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

Simon Marchi via Gdb-patches
2022-11-22T20:38:52Z

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.marchi@efficios.com>

Simon