[PATCH 14/26] gdbserver: introduce and use regcache::set_register_status

Tankut Baris Aktemur via Gdb-patches
2023-02-28T11:30:47Z

Introduce and use a setter method in regcache to set the status of a
register. There already exists get_register_status. So, it made
sense to add the setter to control access to the register_status
field.
---
gdbserver/regcache.cc | 23 +++++++++++++++--------
gdbserver/regcache.h | 3 +++
2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc
index 79835ef4ff1..ec11082be6f 100644
--- a/gdbserver/regcache.cc
+++ b/gdbserver/regcache.cc
@@ -336,16 +336,14 @@ regcache::raw_supply (int n, const void *buf)
{
memcpy (register_data (n), buf, register_size (tdesc, n));
#ifndef IN_PROCESS_AGENT
- if (register_status != NULL)
- register_status[n] = REG_VALID;
+ set_register_status (n, REG_VALID);
#endif
}
else
{
memset (register_data (n), 0, register_size (tdesc, n));
#ifndef IN_PROCESS_AGENT
- if (register_status != NULL)
- register_status[n] = REG_UNAVAILABLE;
+ set_register_status (n, REG_UNAVAILABLE);
#endif
}
}
@@ -358,8 +356,7 @@ supply_register_zeroed (struct regcache *regcache, int n)
memset (regcache->register_data (n), 0,
register_size (regcache->tdesc, n));
#ifndef IN_PROCESS_AGENT
- if (regcache->register_status != NULL)
- regcache->register_status[n] = REG_VALID;
+ regcache->set_register_status (n, REG_VALID);
#endif
}

@@ -384,7 +381,7 @@ regcache::supply_regblock (const void *buf)
memcpy (registers, buf, tdesc->registers_size);
#ifndef IN_PROCESS_AGENT
for (int i = 0; i < tdesc->reg_defs.size (); i++)
- register_status[i] = REG_VALID;
+ set_register_status (i, REG_VALID);
#endif
}
else
@@ -392,7 +389,7 @@ regcache::supply_regblock (const void *buf)
memset (registers, 0, tdesc->registers_size);
#ifndef IN_PROCESS_AGENT
for (int i = 0; i < tdesc->reg_defs.size (); i++)
- register_status[i] = REG_UNAVAILABLE;
+ set_register_status (i, REG_UNAVAILABLE);
#endif
}
}
@@ -498,6 +495,16 @@ regcache::get_register_status (int regnum) const
#endif
}

+void
+regcache::set_register_status (int regnum, enum register_status status)
+{
+#ifndef IN_PROCESS_AGENT
+ gdb_assert (regnum >= 0 && regnum < tdesc->reg_defs.size ());
+ if (register_status != nullptr)
+ register_status[regnum] = status;
+#endif
+}
+
/* See gdbsupport/common-regcache.h. */

bool
diff --git a/gdbserver/regcache.h b/gdbserver/regcache.h
index 88e6ac32bae..ceef28086ce 100644
--- a/gdbserver/regcache.h
+++ b/gdbserver/regcache.h
@@ -64,6 +64,9 @@ struct regcache : public reg_buffer_common
/* See gdbsupport/common-regcache.h. */
enum register_status get_register_status (int regnum) const override;

+ /* Set the status of register REGNUM to STATUS. */
+ void set_register_status (int regnum, enum register_status status);
+
/* See gdbsupport/common-regcache.h. */
void raw_supply (int regnum, const void *buf) override;

--
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