[PATCH/RFC/RFA] Add regcache_raw_{supply,collect}

Mark Kettenis kettenis@chello.nl
Thu Aug 28 22:02:00 GMT 2003


With this path I propose the addition of two new regcache interfaces
to replace supply_register() and regcache_collect().  My work on
debugging 32-bit code on AMD64 and unifying ELF core file support will
be touching several places where we transfer registers to and from the
register cache.  The current functions aren't named very consistently.
Moreover, somewhere in the future we want to get rid of the single
register cache, so we should be able to specify a register cache.
That's why I think we need the following functions:

  /* Supply register REGNUM, whose contents are stored in BUF, to REGCACHE.  */

  void regcache_raw_supply (struct regcache *regcache,
			    int regnum, const void *buf);

  /* Collect register REGNUM from REGCACHE and store its contents in BUF.  */

  void regcache_raw_collect (const struct regcache *regcache,
			     int regnum, void *buf);

For now, these will only be called with CURRENT_REGCACHE as their
first argument, but if we start to use these functions now it will be
easier to start using multiple register caches in the future.

Opinions?

Mark


Index: ChangeLog
from  Mark Kettenis  <kettenis@gnu.org>

	* regcache.c (register_buffer): Consitify first argument.
	(regcache_raw_supply, regcache_raw_collect): New
	functions.

Index: regcache.c
===================================================================
RCS file: /cvs/src/src/gdb/regcache.c,v
retrieving revision 1.94
diff -u -p -r1.94 regcache.c
--- regcache.c 4 Aug 2003 22:24:44 -0000 1.94
+++ regcache.c 28 Aug 2003 22:01:55 -0000
@@ -345,7 +345,7 @@ make_cleanup_regcache_xfree (struct regc
 /* Return  a pointer to register REGNUM's buffer cache.  */
 
 static char *
-register_buffer (struct regcache *regcache, int regnum)
+register_buffer (const struct regcache *regcache, int regnum)
 {
   return regcache->registers + regcache->descr->register_offset[regnum];
 }
@@ -1201,6 +1201,10 @@ write_register_pid (int regnum, CORE_ADD
   inferior_ptid = save_ptid;
 }
 
+/* FIXME: kettenis/20030828: We should get rid of supply_register and
+   regcache_collect in favour of regcache_raw_supply and
+   regcache_raw_collect.  */
+
 /* SUPPLY_REGISTER()
 
    Record that register REGNUM contains VAL.  This is used when the
@@ -1250,6 +1254,55 @@ regcache_collect (int regnum, void *buf)
 {
   memcpy (buf, register_buffer (current_regcache, regnum),
 	  REGISTER_RAW_SIZE (regnum));
+}
+
+/* Supply register REGNUM, whose contents are store in BUF, to REGCACHE.  */
+
+void
+regcache_raw_supply (struct regcache *regcache, int regnum, const void *buf)
+{
+  void *regbuf;
+  size_t size;
+
+  gdb_assert (regcache != NULL && buf != NULL);
+  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
+  gdb_assert (!regcache->readonly_p);
+
+  /* FIXME: kettenis/20030828: It shouldn't be necessary to handle
+     CURRENT_REGCACHE specially here.  */
+  if (regcache == current_regcache
+      && !ptid_equal (registers_ptid, inferior_ptid))
+    {
+      registers_changed ();
+      registers_ptid = inferior_ptid;
+    }
+
+  regbuf = register_buffer (regcache, regnum);
+  size = regcache->descr->sizeof_register[regnum];
+
+  if (buf)
+    memcpy (regbuf, buf, size);
+  else
+    memset (regbuf, 0, size);
+
+  /* Mark the register as cached.  */
+  regcache->register_valid_p[regnum] = 1;
+}
+
+/* Collect register REGNUM from REGCACHE and store its contents in BUF.  */
+
+void
+regcache_raw_collect (const struct regcache *regcache, int regnum, void *buf)
+{
+  const void *regbuf;
+  size_t size;
+
+  gdb_assert (regcache != NULL && buf != NULL);
+  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
+
+  regbuf = register_buffer (regcache, regnum);
+  size = regcache->descr->sizeof_register[regnum];
+  memcpy (buf, regbuf, size);
 }
 
 
Index: regcache.h
===================================================================
RCS file: /cvs/src/src/gdb/regcache.h,v
retrieving revision 1.35
diff -u -p -r1.35 regcache.h
--- regcache.h 15 May 2003 18:01:50 -0000 1.35
+++ regcache.h 28 Aug 2003 22:01:56 -0000
@@ -94,6 +94,10 @@ void regcache_cooked_write_part (struct 
 
 extern void supply_register (int regnum, const void *val);
 extern void regcache_collect (int regnum, void *buf);
+extern void regcache_raw_supply (struct regcache *regcache,
+				 int regnum, const void *buf);
+extern void regcache_raw_collect (const struct regcache *regcache,
+				  int regnum, void *buf);
 
 
 /* The register's ``offset''.



More information about the Gdb-patches mailing list