This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch/rfc] Overhaul regcache for {save,restore}_reggroup


Hello,

This patch brings in the last big change sitting on the reggroups branch.

It adds regcache save/restore functions to to the regcache.
These functions save/restore a subset of registers determined by the save/restore reggroups (by default REGNUMs in the range [0 .. NUM_REGS) are in both the save_reggroup and restore_reggroup, and hence are saved/restored).

As part of this, a saved read-only regcache is expanded so that it can hold the saved value of any register in the full [0 .. NUM_REGS+NUM_PSEUDO_REGS) range.  This is so that architectures with memory-mapped registers (which fall into the range [NUM_REGS .. NUM_REGS+NUM_PSEUDO_REGS) have somewhere to save them.

I'll look to commit it in a few days,

(Oh, and it deletes the last remaining core reference to read_register_bytes() or write_register_bytes()).
No comment :-) I found while re-re-merging this that it was a little to chumpy for my liking so I've broken it down further. So far I've committed the attached. It contains strictly mechanical changes.

Andrew


2002-11-07  Andrew Cagney  <ac131313@redhat.com>

	* regcache.h (regcache_save, regcache_restore): Declare.
	
	* regcache.c (struct regcache_descr): Add fields
	sizeof_cooked_registers and sizeof_cooked_register_valid_p.
	(init_legacy_regcache_descr): Compute sizeof_cooked_registers.
	Update comments.
	(init_regcache_descr): Compute sizeof_cooked_register_valid_p and
	sizeof_cooked_registers.  Update comments.
	(struct regcache): Replace passthrough_p with readonly_p.  Replace
	raw_registers and raw_register_valid_p with registers and
	register_valid_p.
	(regcache_cooked_read): Check for cached cooked values.
	(regcache_xmalloc): Update.
	(regcache_save): New function.
	(regcache_restore): New function.
	(regcache_cpy): Rewrite using regcache_save, regcache_restore and
	regcache_cpy_no_passthrough.
	(regcache_raw_read): Update.
	(regcache_raw_write): Update.
	(build_regcache): Update.
	(regcache_xfree): Update.
	(regcache_cpy_no_passthrough): Update.
	(regcache_valid_p): Update.
	(deprecated_grub_regcache_for_registers): Update.
	(deprecated_grub_regcache_for_register_valid): Update.
	(register_buffer): Move declaration to start.  Update.
	(regcache_raw_read): Update.
	(regcache_raw_write): Update.


2002-11-13  Andrew Cagney  <cagney@redhat.com>

	* regcache.c (register_buffer): Move to near start of file, update
	description.
	(regcache_raw_read): Use.
	(regcache_raw_write): Use.
	(struct regcache): Rename raw_registers to registers and
	raw_register_valid_p to register_valid_p.
	(regcache_xmalloc): Update.
	(regcache_xfree): Update.
	(register_buffer): Update.
	(regcache_cpy): Update.
	(regcache_cpy_no_passthrough): Update.
	(regcache_valid_p): Update.
	(deprecated_grub_regcache_for_registers): Update.
	(deprecated_grub_regcache_for_register_valid): Update.
	(set_register_cached): Update.
	(regcache_raw_write): Update.

Index: regcache.c
===================================================================
RCS file: /cvs/src/src/gdb/regcache.c,v
retrieving revision 1.63
diff -u -r1.63 regcache.c
--- regcache.c	7 Nov 2002 21:43:23 -0000	1.63
+++ regcache.c	13 Nov 2002 15:53:32 -0000
@@ -277,8 +277,11 @@
 struct regcache
 {
   struct regcache_descr *descr;
-  char *raw_registers;
-  char *raw_register_valid_p;
+  /* The register buffers.  A read-only register cache can hold the
+     full [0 .. NUM_REGS + NUM_PSEUDO_REGS) while a read/write
+     register cache can only hold [0 .. NUM_REGS).  */
+  char *registers;
+  char *register_valid_p;
   /* If a value isn't in the cache should the corresponding target be
      queried for a value.  */
   int passthrough_p;
@@ -293,9 +296,9 @@
   descr = regcache_descr (gdbarch);
   regcache = XMALLOC (struct regcache);
   regcache->descr = descr;
-  regcache->raw_registers
+  regcache->registers
     = XCALLOC (descr->sizeof_raw_registers, char);
-  regcache->raw_register_valid_p
+  regcache->register_valid_p
     = XCALLOC (descr->sizeof_raw_register_valid_p, char);
   regcache->passthrough_p = 0;
   return regcache;
@@ -306,8 +309,8 @@
 {
   if (regcache == NULL)
     return;
-  xfree (regcache->raw_registers);
-  xfree (regcache->raw_register_valid_p);
+  xfree (regcache->registers);
+  xfree (regcache->register_valid_p);
   xfree (regcache);
 }
 
@@ -323,6 +326,14 @@
   return make_cleanup (do_regcache_xfree, regcache);
 }
 
+/* Return  a pointer to register REGNUM's buffer cache.  */
+
+static char *
+register_buffer (struct regcache *regcache, int regnum)
+{
+  return regcache->registers + regcache->descr->register_offset[regnum];
+}
+
 void
 regcache_cpy (struct regcache *dst, struct regcache *src)
 {
@@ -338,7 +349,7 @@
     {
       /* ULGH!!!!  Old way.  Use REGISTER bytes and let code below
 	 untangle fetch.  */
-      read_register_bytes (0, dst->raw_registers, REGISTER_BYTES);
+      read_register_bytes (0, dst->registers, REGISTER_BYTES);
       return;
     }
   /* FIXME: cagney/2002-05-17: To say this bit is bad is being polite.
@@ -348,7 +359,7 @@
     {
       /* ULGH!!!!  Old way.  Use REGISTER bytes and let code below
 	 untangle fetch.  */
-      write_register_bytes (0, src->raw_registers, REGISTER_BYTES);
+      write_register_bytes (0, src->registers, REGISTER_BYTES);
       return;
     }
   buf = alloca (src->descr->max_register_size);
@@ -370,9 +381,8 @@
      move of data into the current_regcache().  Doing this would be
      silly - it would mean that valid_p would be completly invalid.  */
   gdb_assert (dst != current_regcache);
-  memcpy (dst->raw_registers, src->raw_registers,
-	  dst->descr->sizeof_raw_registers);
-  memcpy (dst->raw_register_valid_p, src->raw_register_valid_p,
+  memcpy (dst->registers, src->registers, dst->descr->sizeof_raw_registers);
+  memcpy (dst->register_valid_p, src->register_valid_p,
 	  dst->descr->sizeof_raw_register_valid_p);
 }
 
@@ -401,19 +411,19 @@
 {
   gdb_assert (regcache != NULL);
   gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
-  return regcache->raw_register_valid_p[regnum];
+  return regcache->register_valid_p[regnum];
 }
 
 char *
 deprecated_grub_regcache_for_registers (struct regcache *regcache)
 {
-  return regcache->raw_registers;
+  return regcache->registers;
 }
 
 char *
 deprecated_grub_regcache_for_register_valid (struct regcache *regcache)
 {
-  return regcache->raw_register_valid_p;
+  return regcache->register_valid_p;
 }
 
 /* Global structure containing the current regcache.  */
@@ -471,16 +481,7 @@
 {
   gdb_assert (regnum >= 0);
   gdb_assert (regnum < current_regcache->descr->nr_raw_registers);
-  current_regcache->raw_register_valid_p[regnum] = state;
-}
-
-/* If REGNUM >= 0, return a pointer to register REGNUM's cache buffer area,
-   else return a pointer to the start of the cache buffer.  */
-
-static char *
-register_buffer (struct regcache *regcache, int regnum)
-{
-  return regcache->raw_registers + regcache->descr->register_offset[regnum];
+  current_regcache->register_valid_p[regnum] = state;
 }
 
 /* Return whether register REGNUM is a real register.  */
@@ -686,8 +687,7 @@
 	target_fetch_registers (regnum);
     }
   /* Copy the value directly into the register cache.  */
-  memcpy (buf, (regcache->raw_registers
-		+ regcache->descr->register_offset[regnum]),
+  memcpy (buf, register_buffer (regcache, regnum),
 	  regcache->descr->sizeof_register[regnum]);
 }
 
@@ -856,10 +856,9 @@
      value in cache.  */
   if (!regcache->passthrough_p)
     {
-      memcpy ((regcache->raw_registers
-	       + regcache->descr->register_offset[regnum]), buf,
+      memcpy (register_buffer (regcache, regnum), buf,
 	      regcache->descr->sizeof_register[regnum]);
-      regcache->raw_register_valid_p[regnum] = 1;
+      regcache->register_valid_p[regnum] = 1;
       return;
     }
 
@@ -881,7 +880,7 @@
   target_prepare_to_store ();
   memcpy (register_buffer (regcache, regnum), buf,
 	  regcache->descr->sizeof_register[regnum]);
-  regcache->raw_register_valid_p[regnum] = 1;
+  regcache->register_valid_p[regnum] = 1;
   target_store_registers (regnum);
 }
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]