From e4e20d45110d919a5a2da2db84806f315ab59d90 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Fri, 1 Dec 2023 11:27:15 -0500 Subject: 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 --- gdbsupport/common-regcache.cc | 2 +- gdbsupport/common-regcache.h | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'gdbsupport') diff --git a/gdbsupport/common-regcache.cc b/gdbsupport/common-regcache.cc index 3515bed..b6f02ba 100644 --- a/gdbsupport/common-regcache.cc +++ b/gdbsupport/common-regcache.cc @@ -23,7 +23,7 @@ /* Return the register's value or throw if it's not available. */ ULONGEST -regcache_raw_get_unsigned (struct regcache *regcache, int regnum) +regcache_raw_get_unsigned (reg_buffer_common *regcache, int regnum) { ULONGEST value; enum register_status status; diff --git a/gdbsupport/common-regcache.h b/gdbsupport/common-regcache.h index e462f53..6d98ca8 100644 --- a/gdbsupport/common-regcache.h +++ b/gdbsupport/common-regcache.h @@ -20,6 +20,8 @@ #ifndef COMMON_COMMON_REGCACHE_H #define COMMON_COMMON_REGCACHE_H +struct reg_buffer_common; + /* This header is a stopgap until we have an independent regcache. */ enum register_status : signed char @@ -44,28 +46,29 @@ enum register_status : signed char thread specified by PTID. This function must be provided by the client. */ -extern struct regcache *get_thread_regcache_for_ptid (ptid_t ptid); +extern reg_buffer_common *get_thread_regcache_for_ptid (ptid_t ptid); /* Return the size of register numbered N in REGCACHE. This function must be provided by the client. */ -extern int regcache_register_size (const struct regcache *regcache, int n); +extern int regcache_register_size (const reg_buffer_common *regcache, int n); /* Read the PC register. This function must be provided by the client. */ -extern CORE_ADDR regcache_read_pc (struct regcache *regcache); +extern CORE_ADDR regcache_read_pc (reg_buffer_common *regcache); /* Read the PC register. If PC cannot be read, return 0. This is a wrapper around 'regcache_read_pc'. */ -extern CORE_ADDR regcache_read_pc_protected (regcache *regcache); +extern CORE_ADDR regcache_read_pc_protected (reg_buffer_common *regcache); /* Read a raw register into a unsigned integer. */ -extern enum register_status regcache_raw_read_unsigned - (struct regcache *regcache, int regnum, ULONGEST *val); +extern enum register_status +regcache_raw_read_unsigned (reg_buffer_common *regcache, int regnum, + ULONGEST *val); -ULONGEST regcache_raw_get_unsigned (struct regcache *regcache, int regnum); +ULONGEST regcache_raw_get_unsigned (reg_buffer_common *regcache, int regnum); struct reg_buffer_common { -- cgit v1.1