Re: [PATCH 02/24] gdb: use reg_buffer_common throughout gdbsupport/common-regcache.h

John Baldwin
2023-11-11T19:42:55Z

On 11/7/23 9:00 PM, Simon Marchi wrote:
> From: Simon Marchi <simon.marchi@efficios.com>
>
> Right now, gdbsupport/common-regcache.h contains two abstractons for a
> regcache. An opaque type `regcache` (gdb and gdbserver both have their
> own regcache that is the concrete version of this) and an abstract base
> class `reg_buffer_common`, that is the base of regcaches on both sides.
> These abstractions allow code to be written for both gdb and gdbserver,
> for instance in the gdb/arch sub-directory.
>
> However, having two
> different abstractions is impractical. If some common code has a regcache,
> and wants to use an operation defined on reg_buffer_common, it can't.
> It would be better to have just one. Change all instances of `regcache
> *` in gdbsupport/common-regcache.h to be `reg_buffer_common *`, then fix
> fallouts.
>
> Implementations in gdb and gdbserver now need to down-cast (using
> gdb::checked_static_cast) from reg_buffer_common to their concrete
> regcache type. Some of them could be avoided by changing free functions
> (like regcache_register_size) to be virtual methods on
> reg_buffer_common. I tried it, it seems to work, but I did not include
> it in this series to avoid adding unnecessary changes.

I agree that just using reg_buffer_common in shared code is cleaner.
Adding more virtual methods to remove static_casts in a followup seems
sensible, but definitely fine to defer that to a separate followup.

Reviewed-by: John Baldwin <jhb@FreeBSD.org>

--
John Baldwin