[PATCH 19/26] gdbserver: fix the declared type of register_status in regcache

Tankut Baris Aktemur via Gdb-patches
2023-02-28T11:31:54Z

The register_status field of regcache is declared as `unsigned char *`.
This is incorrect, because `enum register_status` from
gdbsupport/common-regcache.h is based on signed char and
REG_UNAVAILABLE is defined as -1. Fix the declared type.

The get/set methods already use the correct type, but we update cast
operations in two places.
---
gdbserver/regcache.cc | 4 ++--
gdbserver/regcache.h | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc
index 0e21c1aa7d1..09ea58bdbd6 100644
--- a/gdbserver/regcache.cc
+++ b/gdbserver/regcache.cc
@@ -147,7 +147,7 @@ regcache::initialize (const target_desc *tdesc,
= (unsigned char *) xcalloc (1, tdesc->registers_size);
this->registers_owned = true;
this->register_status
- = (unsigned char *) xmalloc (tdesc->reg_defs.size ());
+ = (enum register_status *) xmalloc (tdesc->reg_defs.size ());
memset ((void *) this->register_status, REG_UNAVAILABLE,
tdesc->reg_defs.size ());
#else
@@ -490,7 +490,7 @@ regcache::get_register_status (int regnum) const
#ifndef IN_PROCESS_AGENT
gdb_assert (regnum >= 0 && regnum < tdesc->reg_defs.size ());
if (register_status != nullptr)
- return (enum register_status) (register_status[regnum]);
+ return register_status[regnum];
else
return REG_VALID;
#else
diff --git a/gdbserver/regcache.h b/gdbserver/regcache.h
index 3fcd4643a42..ad71a9acaec 100644
--- a/gdbserver/regcache.h
+++ b/gdbserver/regcache.h
@@ -46,8 +46,8 @@ struct regcache : public reg_buffer_common
bool registers_owned = false;
unsigned char *registers = nullptr;
#ifndef IN_PROCESS_AGENT
- /* One of REG_UNAVAILABLE or REG_VALID. */
- unsigned char *register_status = nullptr;
+ /* See gdbsupport/common-regcache.h. */
+ enum register_status *register_status = nullptr;

/* Constructors. */
regcache () = default;
--
2.25.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva