]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add methods to gdbserver regcache and raw_compare
authorAlan Hayward <alan.hayward@arm.com>
Fri, 11 May 2018 10:52:55 +0000 (11:52 +0100)
committerSimon Marchi <simon.marchi@ericsson.com>
Fri, 1 Jun 2018 04:34:18 +0000 (00:34 -0400)
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.

gdb/gdbserver/regcache.c
gdb/gdbserver/regcache.h
gdb/regcache.c
gdb/regcache.h

index 0718b9f9a04d58577f71ab14887e18dc05fee018..88f0db048321304e653c4fc6842eb98c898955e9 100644 (file)
@@ -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);
+}
index 2c0df648f6d439517b56844d00b1bf0a1c9eafd1..b3631bebd27efc29196b5b819a0a2d2144e05a7f 100644 (file)
@@ -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,
index 71898cf7708c5f7825248b230806d8fd9e2473a3..a2a43da04604a2a14c9c1c93f1628ded9bb8b8dd 100644 (file)
@@ -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.  */
 
index f84138f543953abc2e63d92dc2f9d5b7a7764d70..432e1b30a92fa33728e1cdf17c4464502beb4508 100644 (file)
@@ -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);