On 05/11/2018 11:52 AM, Alan Hayward wrote:
> +/* Compare the contents of the register stored in the regcache (ignoring the
> + first OFFSET bytes) to the contents of BUF (without any offset). Returns 0
> + if identical. */
Is this a tristate return, like memcmp? If yes, that should be explicitly documented.
If not, I'd suggest renaming the function to something like raw_equals or
raw_contents_eq, flipping the logic around and return a bool, with true
meaning equal.
The description should probably be moved to the .h file.
> +
> +int
> +regcache::raw_compare (int regnum, const void *buf, int offset) const
> +{
> + gdb_assert (register_size (tdesc, regnum) > offset);
> + return memcmp (buf, register_data (this, regnum, 1) + offset,
> + register_size (tdesc, regnum) - offset);
> +}
Thanks,
Pedro Alves
@@ -300,7 +300,7 @@ regcache_register_size (const struct regcache *regcache, int n)
}
static unsigned char *
-register_data (struct regcache *regcache, int n, int fetch)
+register_data (const struct regcache *regcache, int n, int fetch)
{
return (regcache->registers
+ find_register_by_number (regcache->tdesc, n).offset / 8);
@@ -312,23 +312,27 @@ register_data (struct regcache *regcache, int n, int fetch)
void
supply_register (struct regcache *regcache, int n, const void *buf)
+{
+ return regcache->raw_supply (n, buf);
+}
+
+void
+regcache::raw_supply (int n, const void *buf)
{
if (buf)
{
- memcpy (register_data (regcache, n, 0), buf,
- register_size (regcache->tdesc, n));
+ memcpy (register_data (this, n, 0), buf, register_size (tdesc, n));
#ifndef IN_PROCESS_AGENT
- if (regcache->register_status != NULL)
- regcache->register_status[n] = REG_VALID;
+ if (register_status != NULL)
+ register_status[n] = REG_VALID;
#endif
}
else
{
- memset (register_data (regcache, n, 0), 0,
- register_size (regcache->tdesc, n));
+ memset (register_data (this, n, 0), 0, register_size (tdesc, n));
#ifndef IN_PROCESS_AGENT
- if (regcache->register_status != NULL)
- regcache->register_status[n] = REG_UNAVAILABLE;
+ if (register_status != NULL)
+ register_status[n] = REG_UNAVAILABLE;
#endif
}
}
@@ -410,10 +414,16 @@ supply_register_by_name (struct regcache *regcache,
void
collect_register (struct regcache *regcache, int n, void *buf)
{
- memcpy (buf, register_data (regcache, n, 1),
- register_size (regcache->tdesc, n));
+ regcache->raw_collect (n, buf);
+}
+
+void
+regcache::raw_collect (int n, void *buf) const
+{
+ memcpy (buf, register_data (this, n, 1), register_size (tdesc, n));
}
+
enum register_status
regcache_raw_read_unsigned (struct regcache *regcache, int regnum,
ULONGEST *val)
@@ -480,3 +490,26 @@ regcache_write_pc (struct regcache *regcache, CORE_ADDR pc)
}
#endif
+
+enum register_status
+regcache::get_register_status (int regnum) const
+{
+#ifndef IN_PROCESS_AGENT
+ gdb_assert (regnum >= 0 && regnum < tdesc->reg_defs.size ());
+ return (enum register_status) (register_status[regnum]);
+#else
+ return REG_VALID;
+#endif
+}
+
+/* Compare the contents of the register stored in the regcache (ignoring the
+ first OFFSET bytes) to the contents of BUF (without any offset). Returns 0
+ if identical. */
+
+int
+regcache::raw_compare (int regnum, const void *buf, int offset) const
+{
+ gdb_assert (register_size (tdesc, regnum) > offset);
+ return memcmp (buf, register_data (this, regnum, 1) + offset,
+ register_size (tdesc, regnum) - offset);
+}
@@ -45,6 +45,14 @@ struct regcache
/* One of REG_UNAVAILBLE or REG_VALID. */
unsigned char *register_status;
#endif
+
+ void raw_supply (int regnum, const void *buf);
+
+ void raw_collect (int regnum, void *buf) const;
+
+ int raw_compare (int regnum, const void *buf, int offset) const;
+
+ enum register_status get_register_status (int regnum) const;
};
struct regcache *init_register_cache (struct regcache *regcache,
@@ -1197,6 +1197,23 @@ regcache::collect_regset (const struct regset *regset,
transfer_regset (regset, NULL, regnum, NULL, buf, size);
}
+/* Compare the contents of the register stored in the regcache (ignoring the
+ first OFFSET bytes) to the contents of BUF (without any offset). Returns 0
+ if identical. */
+
+int
+regcache::raw_compare (int regnum, const void *buf, int offset) const
+{
+ const char *regbuf;
+ size_t size;
+
+ gdb_assert (buf != NULL);
+ assert_regnum (regnum);
+
+ regbuf = (const char *) register_buffer (regnum);
+ size = m_descr->sizeof_register[regnum];
+ return memcmp (buf, regbuf + offset, size - offset);
+}
/* Special handling for register PC. */
@@ -357,6 +357,8 @@ public:
void collect_regset (const struct regset *regset, int regnum,
void *buf, size_t size) const;
+ int raw_compare (int regnum, const void *buf, int offset) const;
+
ptid_t ptid () const
{
return m_ptid;