[PATCH v2 07/11] gdbserver: introduce and use regcache::set_register_status

Tankut Baris Aktemur
2024-12-30T10:57:15Z

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.

In two places, we also do cosmetic improvements to for-loops.
---
gdbserver/regcache.cc | 38 ++++++++++++++++++--------------------
gdbserver/regcache.h | 3 +++
2 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc
index bd2f5a6af8298d2961c1f589a52a8fbf9c9a6c8a..eab6bdcfc86124c25013c565c5432c98dfc27500 100644
--- a/gdbserver/regcache.cc
+++ b/gdbserver/regcache.cc
@@ -305,16 +305,14 @@ regcache::raw_supply (int n, gdb::array_view<const gdb_byte> src)
{
copy (src, dst);
#ifndef IN_PROCESS_AGENT
- if (register_status != NULL)
- register_status[n] = REG_VALID;
+ set_register_status (n, REG_VALID);
#endif
}
else
{
memset (dst.data (), 0, dst.size ());
#ifndef IN_PROCESS_AGENT
- if (register_status != NULL)
- register_status[n] = REG_UNAVAILABLE;
+ set_register_status (n, REG_UNAVAILABLE);
#endif
}
}
@@ -327,8 +325,7 @@ supply_register_zeroed (struct regcache *regcache, int n)
auto dst = register_data (regcache, n);
memset (dst.data (), 0, dst.size ());
#ifndef IN_PROCESS_AGENT
- if (regcache->register_status != NULL)
- regcache->register_status[n] = REG_VALID;
+ regcache->set_register_status (n, REG_VALID);
#endif
}

@@ -338,8 +335,7 @@ regcache::raw_supply_part_zeroed (int regnum, int offset, size_t size)
auto dst = register_data (this, regnum).slice (offset, size);
memset (dst.data (), 0, dst.size ());
#ifndef IN_PROCESS_AGENT
- if (register_status != NULL)
- register_status[regnum] = REG_VALID;
+ set_register_status (regnum, REG_VALID);
#endif
}

@@ -369,12 +365,8 @@ supply_regblock (struct regcache *regcache, const void *buf)

memcpy (regcache->registers, buf, tdesc->registers_size);
#ifndef IN_PROCESS_AGENT
- {
- int i;
-
- for (i = 0; i < tdesc->reg_defs.size (); i++)
- regcache->register_status[i] = REG_VALID;
- }
+ for (int i = 0; i < tdesc->reg_defs.size (); i++)
+ regcache->set_register_status (i, REG_VALID);
#endif
}
else
@@ -383,12 +375,8 @@ supply_regblock (struct regcache *regcache, const void *buf)

memset (regcache->registers, 0, tdesc->registers_size);
#ifndef IN_PROCESS_AGENT
- {
- int i;
-
- for (i = 0; i < tdesc->reg_defs.size (); i++)
- regcache->register_status[i] = REG_UNAVAILABLE;
- }
+ for (int i = 0; i < tdesc->reg_defs.size (); i++)
+ regcache->set_register_status (i, REG_UNAVAILABLE);
#endif
}
}
@@ -509,6 +497,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 b371b5a2da6fcc5df5dc0037f5fb980a92ff9aca..08c2ddd04e1307e0493b45a944bd30b762b0663b 100644
--- a/gdbserver/regcache.h
+++ b/gdbserver/regcache.h
@@ -59,6 +59,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, gdb::array_view<const gdb_byte> src) override;

--
2.34.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Sean Fennelly, Jeffrey Schneiderman, Tiffany Doon Silva