gdb: use reg_buffer_common throughout gdbsupport/common-regcache.h

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.

Change-Id: Ia5503adb6b5509a0f4604bd2a68b4642cc5283fd
Reviewed-by: John Baldwin <jhb@FreeBSD.org>
This commit is contained in:
Simon Marchi
2023-12-01 11:27:15 -05:00
parent c3a03de70f
commit e4e20d4511
13 changed files with 56 additions and 42 deletions

View File

@@ -903,8 +903,10 @@ static CORE_ADDR
arm_linux_get_next_pcs_syscall_next_pc (struct arm_get_next_pcs *self)
{
CORE_ADDR next_pc = 0;
CORE_ADDR pc = regcache_read_pc (self->regcache);
int is_thumb = arm_is_thumb (self->regcache);
regcache *regcache
= gdb::checked_static_cast<struct regcache *> (self->regcache);
CORE_ADDR pc = regcache_read_pc (regcache);
int is_thumb = arm_is_thumb (regcache);
ULONGEST svc_number = 0;
if (is_thumb)
@@ -914,7 +916,7 @@ arm_linux_get_next_pcs_syscall_next_pc (struct arm_get_next_pcs *self)
}
else
{
struct gdbarch *gdbarch = self->regcache->arch ();
struct gdbarch *gdbarch = regcache->arch ();
enum bfd_endian byte_order_for_code =
gdbarch_byte_order_for_code (gdbarch);
unsigned long this_instr =
@@ -937,8 +939,7 @@ arm_linux_get_next_pcs_syscall_next_pc (struct arm_get_next_pcs *self)
{
/* SIGRETURN or RT_SIGRETURN may affect the arm thumb mode, so
update IS_THUMB. */
next_pc = arm_linux_sigreturn_next_pc (self->regcache, svc_number,
&is_thumb);
next_pc = arm_linux_sigreturn_next_pc (regcache, svc_number, &is_thumb);
}
/* Addresses for calling Thumb functions have the bit 0 set. */