diff options
author | Simon Marchi <simon.marchi@efficios.com> | 2023-12-01 11:27:15 -0500 |
---|---|---|
committer | Simon Marchi <simon.marchi@efficios.com> | 2023-12-14 16:04:49 +0000 |
commit | e4e20d45110d919a5a2da2db84806f315ab59d90 (patch) | |
tree | c153a7c86e48bbb61850d2dd0f230bef3ba8e9ae /gdbserver/regcache.cc | |
parent | c3a03de70fd373c0f8fc4ba5df1c0db29445112c (diff) | |
download | binutils-e4e20d45110d919a5a2da2db84806f315ab59d90.zip binutils-e4e20d45110d919a5a2da2db84806f315ab59d90.tar.gz binutils-e4e20d45110d919a5a2da2db84806f315ab59d90.tar.bz2 |
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>
Diffstat (limited to 'gdbserver/regcache.cc')
-rw-r--r-- | gdbserver/regcache.cc | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc index 2e75a94..823ea1f 100644 --- a/gdbserver/regcache.cc +++ b/gdbserver/regcache.cc @@ -21,6 +21,8 @@ #include "gdbthread.h" #include "tdesc.h" #include "gdbsupport/rsp-low.h" +#include "gdbsupport/gdb-checked-static-cast.h" + #ifndef IN_PROCESS_AGENT struct regcache * @@ -64,7 +66,7 @@ get_thread_regcache (struct thread_info *thread, int fetch) /* See gdbsupport/common-regcache.h. */ -struct regcache * +reg_buffer_common * get_thread_regcache_for_ptid (ptid_t ptid) { return get_thread_regcache (find_thread_ptid (ptid), 1); @@ -307,9 +309,10 @@ register_size (const struct target_desc *tdesc, int n) /* See gdbsupport/common-regcache.h. */ int -regcache_register_size (const struct regcache *regcache, int n) +regcache_register_size (const reg_buffer_common *regcache, int n) { - return register_size (regcache->tdesc, n); + return register_size + (gdb::checked_static_cast<const struct regcache *> (regcache)->tdesc, n); } static unsigned char * @@ -437,10 +440,11 @@ regcache::raw_collect (int n, void *buf) const } enum register_status -regcache_raw_read_unsigned (struct regcache *regcache, int regnum, +regcache_raw_read_unsigned (reg_buffer_common *reg_buf, int regnum, ULONGEST *val) { int size; + regcache *regcache = gdb::checked_static_cast<struct regcache *> (reg_buf); gdb_assert (regcache != NULL); @@ -486,9 +490,10 @@ collect_register_by_name (struct regcache *regcache, /* Special handling for register PC. */ CORE_ADDR -regcache_read_pc (struct regcache *regcache) +regcache_read_pc (reg_buffer_common *regcache) { - return the_target->read_pc (regcache); + return the_target->read_pc + (gdb::checked_static_cast<struct regcache *> (regcache)); } void |