aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Hayward <alan.hayward@arm.com>2018-05-11 11:52:55 +0100
committerSimon Marchi <simon.marchi@ericsson.com>2018-06-01 00:34:18 -0400
commitd56bdeb9c2e434b91d5e6d605b92bb1cd21177e5 (patch)
tree4db3b8434c7fdb2bfdfa6dd72fe06f45d5e7edff
parent6a229058a5443befdb7b614f164b997525d25c2d (diff)
downloadgdb-d56bdeb9c2e434b91d5e6d605b92bb1cd21177e5.zip
gdb-d56bdeb9c2e434b91d5e6d605b92bb1cd21177e5.tar.gz
gdb-d56bdeb9c2e434b91d5e6d605b92bb1cd21177e5.tar.bz2
Add methods to gdbserver regcache and raw_compare
Add additional functions to gdbserver regcache to make it more like gdb regcache. This will allow the next patch to add a common function which uses regcache. The alternatives for the next patch would be to either duplicate the common code in both gdb and gdbserver, or alternatively pass function pointers for read register, write register, get status to the common code. In addition, add a register compare function. This will be used in the next patch. Alternatively instead of adding a new function, I could read into a buffer and then compare. 2018-05-11 Alan Hayward <alan.hayward@arm.com> gdb/ * regcache.c (regcache::raw_compare): New function. * regcache.h (regcache::raw_compare): New declaration. gdbserver/ * regcache.c (register_data): New function. (supply_register): Call member function. (regcache::raw_supply): Replacement for supply_register. (collect_register): Call member function. (regcache::raw_collect): Replacement for collect_register. (regcache::get_register_status): New function. (regcache::raw_compare): Likewise. * regcache.h: (regcache::raw_supply): New declaration. * (regcache::raw_collect): Likewise. * (regcache::raw_compare): Likewise. * (regcache::get_register_status): Likewise.
-rw-r--r--gdb/gdbserver/regcache.c55
-rw-r--r--gdb/gdbserver/regcache.h8
-rw-r--r--gdb/regcache.c17
-rw-r--r--gdb/regcache.h2
4 files changed, 71 insertions, 11 deletions
diff --git a/gdb/gdbserver/regcache.c b/gdb/gdbserver/regcache.c
index 0718b9f..88f0db0 100644
--- a/gdb/gdbserver/regcache.c
+++ b/gdb/gdbserver/regcache.c
@@ -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);
@@ -313,22 +313,26 @@ 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);
+}
diff --git a/gdb/gdbserver/regcache.h b/gdb/gdbserver/regcache.h
index 2c0df64..b3631be 100644
--- a/gdb/gdbserver/regcache.h
+++ b/gdb/gdbserver/regcache.h
@@ -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,
diff --git a/gdb/regcache.c b/gdb/regcache.c
index 71898cf..a2a43da 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -1083,6 +1083,23 @@ reg_buffer::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
+reg_buffer::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. */
diff --git a/gdb/regcache.h b/gdb/regcache.h
index f84138f..432e1b3 100644
--- a/gdb/regcache.h
+++ b/gdb/regcache.h
@@ -162,6 +162,8 @@ public:
void invalidate (int regnum);
+ int raw_compare (int regnum, const void *buf, int offset) const;
+
/* Dump the contents of a register from the register cache to the target
debug. */
void debug_print_register (const char *func, int regno);