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(-)
On 2/28/23 06:28, Tankut Baris Aktemur via Gdb-patches wrote:
> 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.
Does this method (and eventually the register_status field) need to be
public? Or is it only set internally, through some other methods?
> @@ -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
I don't understand why some spots (like here) check for register_status
being nullptr, but others (like get_register_status) don't.
Simon
@@ -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
@@ -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;