public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/6] Class-fy regcache in GDB
@ 2017-04-25 20:28 Yao Qi
  2017-04-25 20:28 ` [PATCH 6/6] Remove cleanup in get_return_value Yao Qi
                   ` (6 more replies)
  0 siblings, 7 replies; 24+ messages in thread
From: Yao Qi @ 2017-04-25 20:28 UTC (permalink / raw)
  To: gdb-patches

This patch set changes "struct regcache" to a class, that is, change all
regcache_* apis to regcache class methods.  I am also thinking that add
a new class readonly_regcache, and regcache extends from it.  However I
stopped here, because they are sufficient for me to do some other unit
tests.  Note that this patch doesn't touch regcache in GDBserver.

The patch set is tested on x86_64-linux and ppc-linux (gcc110).

*** BLURB HERE ***

Yao Qi (6):
  Change readonly_p to bool
  Add constructor and destructor to regcache
  Class-fy regcache
  Simplify regcache_dup
  Use copy ctor in regcache_dup
  Remove cleanup in get_return_value

 gdb/infcmd.c   |  14 +-
 gdb/regcache.c | 755 ++++++++++++++++++++++++++++++++-------------------------
 gdb/regcache.h | 166 ++++++++++++-
 gdb/target.c   |   5 +-
 4 files changed, 595 insertions(+), 345 deletions(-)

-- 
1.9.1

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 1/6 OBV] Change readonly_p to bool
  2017-04-25 20:28 [PATCH 0/6] Class-fy regcache in GDB Yao Qi
  2017-04-25 20:28 ` [PATCH 6/6] Remove cleanup in get_return_value Yao Qi
  2017-04-25 20:28 ` [PATCH 4/6] Simplify regcache_dup Yao Qi
@ 2017-04-25 20:28 ` Yao Qi
  2017-04-25 20:28 ` [PATCH 2/6] Add constructor and destructor to regcache Yao Qi
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 24+ messages in thread
From: Yao Qi @ 2017-04-25 20:28 UTC (permalink / raw)
  To: gdb-patches

This patch changes readonly_p type to bool.  It is obvious, and I'll push
it in.

gdb:

2017-04-25  Yao Qi  <yao.qi@linaro.org>

	* regcache.c (struct regcache) <readonly_p>: Change its type
	to bool.
	(regcache_xmalloc_1): Update parameter type and callers update.
---
 gdb/regcache.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/gdb/regcache.c b/gdb/regcache.c
index 41c23a5..966f0c7 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -209,7 +209,7 @@ struct regcache
      cache can only be updated via the methods regcache_dup() and
      regcache_cpy().  The actual contents are determined by the
      reggroup_save and reggroup_restore methods.  */
-  int readonly_p;
+  bool readonly_p;
   /* If this is a read-write cache, which thread's registers is
      it connected to?  */
   ptid_t ptid;
@@ -227,7 +227,7 @@ regcache_get_ptid (const struct regcache *regcache)
 
 static struct regcache *
 regcache_xmalloc_1 (struct gdbarch *gdbarch, struct address_space *aspace,
-		    int readonly_p)
+		    bool readonly_p)
 {
   struct regcache_descr *descr;
   struct regcache *regcache;
@@ -259,7 +259,7 @@ regcache_xmalloc_1 (struct gdbarch *gdbarch, struct address_space *aspace,
 struct regcache *
 regcache_xmalloc (struct gdbarch *gdbarch, struct address_space *aspace)
 {
-  return regcache_xmalloc_1 (gdbarch, aspace, 1);
+  return regcache_xmalloc_1 (gdbarch, aspace, true);
 }
 
 void
@@ -507,7 +507,7 @@ get_thread_arch_aspace_regcache (ptid_t ptid, struct gdbarch *gdbarch,
 	&& get_regcache_arch (list->regcache) == gdbarch)
       return list->regcache;
 
-  new_regcache = regcache_xmalloc_1 (gdbarch, aspace, 0);
+  new_regcache = regcache_xmalloc_1 (gdbarch, aspace, false);
   new_regcache->ptid = ptid;
 
   list = XNEW (struct regcache_list);
-- 
1.9.1

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 6/6] Remove cleanup in get_return_value
  2017-04-25 20:28 [PATCH 0/6] Class-fy regcache in GDB Yao Qi
@ 2017-04-25 20:28 ` Yao Qi
  2017-04-25 20:28 ` [PATCH 4/6] Simplify regcache_dup Yao Qi
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 24+ messages in thread
From: Yao Qi @ 2017-04-25 20:28 UTC (permalink / raw)
  To: gdb-patches

With regcache copy ctor, we can use it to create local object in
get_return_value (), so that the cleanup can be removed.

gdb:

2017-04-25  Yao Qi  <yao.qi@linaro.org>

	* infcmd.c (get_return_value): Use regcache copy ctor, and
	remove cleanup.
---
 gdb/infcmd.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 22b2c7a..090da8e 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -1604,15 +1604,9 @@ advance_command (char *arg, int from_tty)
 struct value *
 get_return_value (struct value *function, struct type *value_type)
 {
-  struct regcache *stop_regs;
-  struct gdbarch *gdbarch;
+  struct regcache stop_regs = regcache (*get_current_regcache ());
+  struct gdbarch *gdbarch = stop_regs.get_arch ();
   struct value *value;
-  struct cleanup *cleanup;
-
-  stop_regs = regcache_dup (get_current_regcache ());
-  cleanup = make_cleanup_regcache_xfree (stop_regs);
-
-  gdbarch = get_regcache_arch (stop_regs);
 
   value_type = check_typedef (value_type);
   gdb_assert (TYPE_CODE (value_type) != TYPE_CODE_VOID);
@@ -1631,7 +1625,7 @@ get_return_value (struct value *function, struct type *value_type)
     case RETURN_VALUE_ABI_RETURNS_ADDRESS:
     case RETURN_VALUE_ABI_PRESERVES_ADDRESS:
       value = allocate_value (value_type);
-      gdbarch_return_value (gdbarch, function, value_type, stop_regs,
+      gdbarch_return_value (gdbarch, function, value_type, &stop_regs,
 			    value_contents_raw (value), NULL);
       break;
     case RETURN_VALUE_STRUCT_CONVENTION:
@@ -1641,8 +1635,6 @@ get_return_value (struct value *function, struct type *value_type)
       internal_error (__FILE__, __LINE__, _("bad switch"));
     }
 
-  do_cleanups (cleanup);
-
   return value;
 }
 
-- 
1.9.1

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 4/6] Simplify regcache_dup
  2017-04-25 20:28 [PATCH 0/6] Class-fy regcache in GDB Yao Qi
  2017-04-25 20:28 ` [PATCH 6/6] Remove cleanup in get_return_value Yao Qi
@ 2017-04-25 20:28 ` Yao Qi
  2017-04-25 20:28 ` [PATCH 1/6 OBV] Change readonly_p to bool Yao Qi
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 24+ messages in thread
From: Yao Qi @ 2017-04-25 20:28 UTC (permalink / raw)
  To: gdb-patches

regcache_dup, in fact, is to create a readonly regcache from a
non-readonly regcache.  This patch adds an assert that src is not
readonly.

gdb:

2017-04-25  Yao Qi  <yao.qi@linaro.org>

	* regcache.c (regcache_dup): Assert !src->readonly_p and
	call method save instead of regcache_cpy.
	* regcache.h (struct regcache): Make regcache_dup a friend.
---
 gdb/regcache.c | 3 ++-
 gdb/regcache.h | 3 +++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/gdb/regcache.c b/gdb/regcache.c
index f4fcf65..28163c2 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -422,8 +422,9 @@ regcache_dup (struct regcache *src)
 {
   struct regcache *newbuf;
 
+  gdb_assert (!src->readonly_p);
   newbuf = regcache_xmalloc (src->get_arch (), get_regcache_aspace (src));
-  regcache_cpy (newbuf, src);
+  newbuf->save (do_cooked_read, src);
   return newbuf;
 }
 
diff --git a/gdb/regcache.h b/gdb/regcache.h
index 8794966..e6494a9 100644
--- a/gdb/regcache.h
+++ b/gdb/regcache.h
@@ -378,6 +378,9 @@ private:
 
   friend void
   regcache_cpy (struct regcache *dst, struct regcache *src);
+
+  friend struct regcache *
+  regcache_dup (struct regcache *src);
 };
 
 /* Copy/duplicate the contents of a register cache.  By default, the
-- 
1.9.1

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 2/6] Add constructor and destructor to regcache
  2017-04-25 20:28 [PATCH 0/6] Class-fy regcache in GDB Yao Qi
                   ` (2 preceding siblings ...)
  2017-04-25 20:28 ` [PATCH 1/6 OBV] Change readonly_p to bool Yao Qi
@ 2017-04-25 20:28 ` Yao Qi
  2017-04-27 17:34   ` Pedro Alves
  2017-04-25 20:29 ` [PATCH 3/6] Class-fy regcache Yao Qi
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 24+ messages in thread
From: Yao Qi @ 2017-04-25 20:28 UTC (permalink / raw)
  To: gdb-patches

This patch adds ctor and dtor to regcache.

gdb:

2017-04-25  Yao Qi  <yao.qi@linaro.org>

	* regcache.c (regcache::regcache): New function.
	(regcache::~regcache): New function.
	(regcache_xmalloc_1): Remove.
	(regcache_xmalloc): Call new regcache.
	(regcache_xfree): Call delete regcache.
	(get_thread_arch_aspace_regcache): Call new regcache.
---
 gdb/regcache.c | 78 +++++++++++++++++++++++++++++++---------------------------
 1 file changed, 42 insertions(+), 36 deletions(-)

diff --git a/gdb/regcache.c b/gdb/regcache.c
index 966f0c7..e0554c7 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -191,6 +191,17 @@ regcache_register_size (const struct regcache *regcache, int n)
 
 struct regcache
 {
+public:
+  explicit regcache (struct gdbarch *gdbarch, struct address_space *aspace_)
+    : regcache (gdbarch, aspace_, true)
+  {}
+
+  ~regcache ()
+  {
+    xfree (registers);
+    xfree (register_status);
+  }
+
   struct regcache_descr *descr;
 
   /* The address space of this register cache (for registers where it
@@ -213,6 +224,33 @@ struct regcache
   /* If this is a read-write cache, which thread's registers is
      it connected to?  */
   ptid_t ptid;
+
+private:
+  explicit regcache (struct gdbarch *gdbarch, struct address_space *aspace_,
+		     bool readonly_p_)
+    : aspace (aspace_), readonly_p (readonly_p_)
+  {
+    gdb_assert (gdbarch != NULL);
+    descr = regcache_descr (gdbarch);
+
+  if (readonly_p)
+    {
+      registers = XCNEWVEC (gdb_byte, descr->sizeof_cooked_registers);
+      register_status = XCNEWVEC (signed char,
+				  descr->sizeof_cooked_register_status);
+    }
+  else
+    {
+      registers = XCNEWVEC (gdb_byte, descr->sizeof_raw_registers);
+      register_status = XCNEWVEC (signed char,
+				  descr->sizeof_raw_register_status);
+    }
+  ptid = minus_one_ptid;
+  }
+
+  friend struct regcache *
+  get_thread_arch_aspace_regcache (ptid_t ptid, struct gdbarch *gdbarch,
+				   struct address_space *aspace);
 };
 
 /* See regcache.h.  */
@@ -225,41 +263,10 @@ regcache_get_ptid (const struct regcache *regcache)
   return regcache->ptid;
 }
 
-static struct regcache *
-regcache_xmalloc_1 (struct gdbarch *gdbarch, struct address_space *aspace,
-		    bool readonly_p)
-{
-  struct regcache_descr *descr;
-  struct regcache *regcache;
-
-  gdb_assert (gdbarch != NULL);
-  descr = regcache_descr (gdbarch);
-  regcache = XNEW (struct regcache);
-  regcache->descr = descr;
-  regcache->readonly_p = readonly_p;
-  if (readonly_p)
-    {
-      regcache->registers
-	= XCNEWVEC (gdb_byte, descr->sizeof_cooked_registers);
-      regcache->register_status
-	= XCNEWVEC (signed char, descr->sizeof_cooked_register_status);
-    }
-  else
-    {
-      regcache->registers
-	= XCNEWVEC (gdb_byte, descr->sizeof_raw_registers);
-      regcache->register_status
-	= XCNEWVEC (signed char, descr->sizeof_raw_register_status);
-    }
-  regcache->aspace = aspace;
-  regcache->ptid = minus_one_ptid;
-  return regcache;
-}
-
 struct regcache *
 regcache_xmalloc (struct gdbarch *gdbarch, struct address_space *aspace)
 {
-  return regcache_xmalloc_1 (gdbarch, aspace, true);
+  return new regcache (gdbarch, aspace);
 }
 
 void
@@ -267,9 +274,8 @@ regcache_xfree (struct regcache *regcache)
 {
   if (regcache == NULL)
     return;
-  xfree (regcache->registers);
-  xfree (regcache->register_status);
-  xfree (regcache);
+
+  delete regcache;
 }
 
 static void
@@ -507,7 +513,7 @@ get_thread_arch_aspace_regcache (ptid_t ptid, struct gdbarch *gdbarch,
 	&& get_regcache_arch (list->regcache) == gdbarch)
       return list->regcache;
 
-  new_regcache = regcache_xmalloc_1 (gdbarch, aspace, false);
+  new_regcache = new regcache (gdbarch, aspace, false);
   new_regcache->ptid = ptid;
 
   list = XNEW (struct regcache_list);
-- 
1.9.1

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 5/6] Use copy ctor in regcache_dup
  2017-04-25 20:28 [PATCH 0/6] Class-fy regcache in GDB Yao Qi
                   ` (4 preceding siblings ...)
  2017-04-25 20:29 ` [PATCH 3/6] Class-fy regcache Yao Qi
@ 2017-04-25 20:29 ` Yao Qi
  2017-04-27 17:37   ` Pedro Alves
  2017-04-28 14:26 ` [PATCH 0/4 v2] Class-fy regcache in GDB Yao Qi
  6 siblings, 1 reply; 24+ messages in thread
From: Yao Qi @ 2017-04-25 20:29 UTC (permalink / raw)
  To: gdb-patches

gdb:

2017-04-25  Yao Qi  <yao.qi@linaro.org>

	* regcache.c (regcache::regcache): New copy ctor.
	(do_cooked_read): Moved above.
	(regcache_dup): Use copy ctor.
	* regcache.h (struct regcache): Declare copy ctor and remove
	friend regcache_dup.
---
 gdb/regcache.c | 30 ++++++++++++++++--------------
 gdb/regcache.h |  7 ++++---
 2 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/gdb/regcache.c b/gdb/regcache.c
index 28163c2..3fc0aee 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -209,6 +209,21 @@ regcache::regcache (struct gdbarch *gdbarch, struct address_space *aspace_,
   ptid = minus_one_ptid;
 }
 
+static enum register_status
+do_cooked_read (void *src, int regnum, gdb_byte *buf)
+{
+  struct regcache *regcache = (struct regcache *) src;
+
+  return regcache_cooked_read (regcache, regnum, buf);
+}
+
+regcache::regcache (const regcache &origin)
+  : regcache (origin.get_arch (), origin.get_aspace (), true)
+{
+  gdb_assert (!origin.readonly_p);
+  save (do_cooked_read, (void *) &origin);
+}
+
 struct gdbarch *
 regcache::get_arch () const
 {
@@ -371,14 +386,6 @@ regcache::restore (struct regcache *src)
     }
 }
 
-static enum register_status
-do_cooked_read (void *src, int regnum, gdb_byte *buf)
-{
-  struct regcache *regcache = (struct regcache *) src;
-
-  return regcache_cooked_read (regcache, regnum, buf);
-}
-
 void
 regcache_cpy (struct regcache *dst, struct regcache *src)
 {
@@ -420,12 +427,7 @@ regcache::cpy_no_passthrough (struct regcache *src)
 struct regcache *
 regcache_dup (struct regcache *src)
 {
-  struct regcache *newbuf;
-
-  gdb_assert (!src->readonly_p);
-  newbuf = regcache_xmalloc (src->get_arch (), get_regcache_aspace (src));
-  newbuf->save (do_cooked_read, src);
-  return newbuf;
+  return new regcache (*src);
 }
 
 enum register_status
diff --git a/gdb/regcache.h b/gdb/regcache.h
index e6494a9..0d302a7 100644
--- a/gdb/regcache.h
+++ b/gdb/regcache.h
@@ -240,6 +240,10 @@ public:
     : regcache (gdbarch, aspace_, true)
   {}
 
+  /* Copy constructor, create a readonly regcache from a non-readonly
+     regcache.  */
+  regcache (const regcache &);
+
   ~regcache ()
   {
     xfree (registers);
@@ -378,9 +382,6 @@ private:
 
   friend void
   regcache_cpy (struct regcache *dst, struct regcache *src);
-
-  friend struct regcache *
-  regcache_dup (struct regcache *src);
 };
 
 /* Copy/duplicate the contents of a register cache.  By default, the
-- 
1.9.1

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 3/6] Class-fy regcache
  2017-04-25 20:28 [PATCH 0/6] Class-fy regcache in GDB Yao Qi
                   ` (3 preceding siblings ...)
  2017-04-25 20:28 ` [PATCH 2/6] Add constructor and destructor to regcache Yao Qi
@ 2017-04-25 20:29 ` Yao Qi
  2017-04-27 17:35   ` Pedro Alves
  2017-04-25 20:29 ` [PATCH 5/6] Use copy ctor in regcache_dup Yao Qi
  2017-04-28 14:26 ` [PATCH 0/4 v2] Class-fy regcache in GDB Yao Qi
  6 siblings, 1 reply; 24+ messages in thread
From: Yao Qi @ 2017-04-25 20:29 UTC (permalink / raw)
  To: gdb-patches

This patch moves regcache declaration to regcache.h, and converts
regcache apis to member functions, for example, regcache_invalidate
is changed to regcache::invalidate.  Some changes are not done in
this patch,

 - keep "struct regcache" instead of renaming to "class regcache",
   because "struct regcache" is widely used (even in GDBserver).
 - regcache_dup can be replaced by a copy ctor,
 - regcache_cpy may be replaced by assignment operator,

gdb:

2017-04-28  Yao Qi  <yao.qi@linaro.org>

	* regcache.c (struct regcache): Move to regcache.h
	(regcache::get_arch): New method.
	(regcache_get_ptid): Update.
	(get_regcache_arch): Call get_arch method.
	(get_regcache_aspace): Call method get_aspace.
	(register_buffer): Change it to method.
	(regcache_save): Change it to regcache::save.
	(regcache_restore): Likewise.
	(regcache_cpy_no_passthrough): Remove the declaration.
	(regcache_cpy): Call methods restore and cpy_no_passthrough.
	(regcache_cpy_no_passthrough): Change it to method
	cpy_no_passthrough.
	(regcache_register_status): Change it to method
	get_register_status.
	(regcache_invalidate): Change it to method invalidate.
	(regcache_thread_ptid_changed): Use get_ptid and set_ptid.
	(regcache_raw_update): Change it to method raw_update.
	(regcache_raw_read): Likewise.
	(regcache_raw_read_signed): Likewise.
	(regcache_raw_read_unsigned): Likewise.
	(regcache_raw_write_signed): Likewise.
	(regcache_raw_write_unsigned): Likewise.
	(regcache_cooked_read): Likewise.
	(regcache_cooked_read_value): Likewise.
	(regcache_cooked_read_signed): Likewise.
	(regcache_cooked_read_unsigned): Likewise.
	(regcache_cooked_write_signed): Likewise.
	(regcache_cooked_write_unsigned): Likewise.
	(regcache_raw_set_cached_value): Likewise.
	(regcache_raw_write): Likewise.
	(regcache_cooked_write): Likewise.
	(regcache_xfer_part): Likewise.
	(regcache_raw_read_part): Likewise.
	(regcache_raw_write_part): Likewise.
	(regcache_cooked_read_part): Likewise.
	(regcache_cooked_write_part): Likewise.
	(regcache_raw_supply): Likewise.
	(regcache_raw_collect): Likewise.
	(regcache_transfer_regset): Likewise.
	(regcache_supply_regset): Likewise.
	(regcache_collect_regset): Likewise.
	(regcache_debug_print_register): Likewise.
	(enum regcache_dump_what): Move it to regcache.h.
	(regcache_dump): Change it to method dump.
	* regcache.h (enum regcache_dump_what): New.
	(struct regcache): New.
	* target.c (target_fetch_registers): Call method
	debug_print_register.
	(target_store_registers): Likewise.
---
 gdb/regcache.c | 702 ++++++++++++++++++++++++++++++++-------------------------
 gdb/regcache.h | 162 ++++++++++++-
 gdb/target.c   |   5 +-
 3 files changed, 557 insertions(+), 312 deletions(-)

diff --git a/gdb/regcache.c b/gdb/regcache.c
index e0554c7..f4fcf65 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -187,51 +187,12 @@ regcache_register_size (const struct regcache *regcache, int n)
   return register_size (get_regcache_arch (regcache), n);
 }
 
-/* The register cache for storing raw register values.  */
-
-struct regcache
+regcache::regcache (struct gdbarch *gdbarch, struct address_space *aspace_,
+		    bool readonly_p_)
+  : aspace (aspace_), readonly_p (readonly_p_)
 {
-public:
-  explicit regcache (struct gdbarch *gdbarch, struct address_space *aspace_)
-    : regcache (gdbarch, aspace_, true)
-  {}
-
-  ~regcache ()
-  {
-    xfree (registers);
-    xfree (register_status);
-  }
-
-  struct regcache_descr *descr;
-
-  /* The address space of this register cache (for registers where it
-     makes sense, like PC or SP).  */
-  struct address_space *aspace;
-
-  /* The register buffers.  A read-only register cache can hold the
-     full [0 .. gdbarch_num_regs + gdbarch_num_pseudo_regs) while a read/write
-     register cache can only hold [0 .. gdbarch_num_regs).  */
-  gdb_byte *registers;
-  /* Register cache status.  */
-  signed char *register_status;
-  /* Is this a read-only cache?  A read-only cache is used for saving
-     the target's register state (e.g, across an inferior function
-     call or just before forcing a function return).  A read-only
-     cache can only be updated via the methods regcache_dup() and
-     regcache_cpy().  The actual contents are determined by the
-     reggroup_save and reggroup_restore methods.  */
-  bool readonly_p;
-  /* If this is a read-write cache, which thread's registers is
-     it connected to?  */
-  ptid_t ptid;
-
-private:
-  explicit regcache (struct gdbarch *gdbarch, struct address_space *aspace_,
-		     bool readonly_p_)
-    : aspace (aspace_), readonly_p (readonly_p_)
-  {
-    gdb_assert (gdbarch != NULL);
-    descr = regcache_descr (gdbarch);
+  gdb_assert (gdbarch != NULL);
+  descr = regcache_descr (gdbarch);
 
   if (readonly_p)
     {
@@ -246,21 +207,22 @@ private:
 				  descr->sizeof_raw_register_status);
     }
   ptid = minus_one_ptid;
-  }
+}
 
-  friend struct regcache *
-  get_thread_arch_aspace_regcache (ptid_t ptid, struct gdbarch *gdbarch,
-				   struct address_space *aspace);
-};
+struct gdbarch *
+regcache::get_arch () const
+{
+  return descr->gdbarch;
+}
 
 /* See regcache.h.  */
 
 ptid_t
 regcache_get_ptid (const struct regcache *regcache)
 {
-  gdb_assert (!ptid_equal (regcache->ptid, minus_one_ptid));
+  gdb_assert (!ptid_equal (regcache->get_ptid (), minus_one_ptid));
 
-  return regcache->ptid;
+  return regcache->get_ptid ();
 }
 
 struct regcache *
@@ -321,84 +283,90 @@ make_cleanup_regcache_invalidate (struct regcache *regcache, int regnum)
 struct gdbarch *
 get_regcache_arch (const struct regcache *regcache)
 {
-  return regcache->descr->gdbarch;
+  return regcache->get_arch ();
 }
 
 struct address_space *
 get_regcache_aspace (const struct regcache *regcache)
 {
-  return regcache->aspace;
+  return regcache->get_aspace ();
 }
 
 /* Return  a pointer to register REGNUM's buffer cache.  */
 
-static gdb_byte *
-register_buffer (const struct regcache *regcache, int regnum)
+gdb_byte *
+regcache::register_buffer (int regnum) const
 {
-  return regcache->registers + regcache->descr->register_offset[regnum];
+  return registers + descr->register_offset[regnum];
 }
 
 void
-regcache_save (struct regcache *dst, regcache_cooked_read_ftype *cooked_read,
-	       void *src)
+regcache_save (struct regcache *regcache,
+	       regcache_cooked_read_ftype *cooked_read, void *src)
 {
-  struct gdbarch *gdbarch = dst->descr->gdbarch;
+  regcache->save (cooked_read, src);
+}
+
+void
+regcache::save (regcache_cooked_read_ftype *cooked_read,
+		void *src)
+{
+  struct gdbarch *gdbarch = descr->gdbarch;
   gdb_byte buf[MAX_REGISTER_SIZE];
   int regnum;
 
   /* The DST should be `read-only', if it wasn't then the save would
      end up trying to write the register values back out to the
      target.  */
-  gdb_assert (dst->readonly_p);
+  gdb_assert (readonly_p);
   /* Clear the dest.  */
-  memset (dst->registers, 0, dst->descr->sizeof_cooked_registers);
-  memset (dst->register_status, 0,
-	  dst->descr->sizeof_cooked_register_status);
+  memset (registers, 0, descr->sizeof_cooked_registers);
+  memset (register_status, 0, descr->sizeof_cooked_register_status);
   /* Copy over any registers (identified by their membership in the
      save_reggroup) and mark them as valid.  The full [0 .. gdbarch_num_regs +
      gdbarch_num_pseudo_regs) range is checked since some architectures need
      to save/restore `cooked' registers that live in memory.  */
-  for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++)
+  for (regnum = 0; regnum < descr->nr_cooked_registers; regnum++)
     {
       if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
 	{
 	  enum register_status status = cooked_read (src, regnum, buf);
 
 	  if (status == REG_VALID)
-	    memcpy (register_buffer (dst, regnum), buf,
+	    memcpy (register_buffer (regnum), buf,
 		    register_size (gdbarch, regnum));
 	  else
 	    {
 	      gdb_assert (status != REG_UNKNOWN);
 
-	      memset (register_buffer (dst, regnum), 0,
+	      memset (register_buffer (regnum), 0,
 		      register_size (gdbarch, regnum));
 	    }
-	  dst->register_status[regnum] = status;
+	  register_status[regnum] = status;
 	}
     }
 }
 
-static void
-regcache_restore (struct regcache *dst, struct regcache *src)
+void
+regcache::restore (struct regcache *src)
 {
-  struct gdbarch *gdbarch = dst->descr->gdbarch;
+  struct gdbarch *gdbarch = descr->gdbarch;
   int regnum;
 
   /* The dst had better not be read-only.  If it is, the `restore'
      doesn't make much sense.  */
-  gdb_assert (!dst->readonly_p);
+  gdb_assert (!readonly_p);
   gdb_assert (src->readonly_p);
   /* Copy over any registers, being careful to only restore those that
      were both saved and need to be restored.  The full [0 .. gdbarch_num_regs
      + gdbarch_num_pseudo_regs) range is checked since some architectures need
      to save/restore `cooked' registers that live in memory.  */
-  for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++)
+  for (regnum = 0; regnum < descr->nr_cooked_registers; regnum++)
     {
       if (gdbarch_register_reggroup_p (gdbarch, regnum, restore_reggroup))
 	{
 	  if (src->register_status[regnum] == REG_VALID)
-	    regcache_cooked_write (dst, regnum, register_buffer (src, regnum));
+	    cooked_write (regnum, src->register_buffer (regnum));
 	}
     }
 }
@@ -411,9 +379,6 @@ do_cooked_read (void *src, int regnum, gdb_byte *buf)
   return regcache_cooked_read (regcache, regnum, buf);
 }
 
-static void regcache_cpy_no_passthrough (struct regcache *dst,
-					 struct regcache *src);
-
 void
 regcache_cpy (struct regcache *dst, struct regcache *src)
 {
@@ -425,9 +390,9 @@ regcache_cpy (struct regcache *dst, struct regcache *src)
   if (!src->readonly_p)
     regcache_save (dst, do_cooked_read, src);
   else if (!dst->readonly_p)
-    regcache_restore (dst, src);
+    dst->restore (src);
   else
-    regcache_cpy_no_passthrough (dst, src);
+    dst->cpy_no_passthrough (src);
 }
 
 /* Copy/duplicate the contents of a register cache.  Unlike regcache_cpy,
@@ -435,21 +400,21 @@ regcache_cpy (struct regcache *dst, struct regcache *src)
    Only values values already in the cache are transferred.  The SRC and DST
    buffers must not overlap.  */
 
-static void
-regcache_cpy_no_passthrough (struct regcache *dst, struct regcache *src)
+void
+regcache::cpy_no_passthrough (struct regcache *src)
 {
-  gdb_assert (src != NULL && dst != NULL);
-  gdb_assert (src->descr->gdbarch == dst->descr->gdbarch);
+  gdb_assert (src != NULL);
+  gdb_assert (src->descr->gdbarch == descr->gdbarch);
   /* NOTE: cagney/2002-05-17: Don't let the caller do a no-passthrough
      move of data into a thread's regcache.  Doing this would be silly
      - it would mean that regcache->register_status would be
      completely invalid.  */
-  gdb_assert (dst->readonly_p && src->readonly_p);
+  gdb_assert (readonly_p && src->readonly_p);
 
-  memcpy (dst->registers, src->registers,
-	  dst->descr->sizeof_cooked_registers);
-  memcpy (dst->register_status, src->register_status,
-	  dst->descr->sizeof_cooked_register_status);
+  memcpy (registers, src->registers,
+	  descr->sizeof_cooked_registers);
+  memcpy (register_status, src->register_status,
+	  descr->sizeof_cooked_register_status);
 }
 
 struct regcache *
@@ -457,7 +422,7 @@ regcache_dup (struct regcache *src)
 {
   struct regcache *newbuf;
 
-  newbuf = regcache_xmalloc (src->descr->gdbarch, get_regcache_aspace (src));
+  newbuf = regcache_xmalloc (src->get_arch (), get_regcache_aspace (src));
   regcache_cpy (newbuf, src);
   return newbuf;
 }
@@ -466,25 +431,36 @@ enum register_status
 regcache_register_status (const struct regcache *regcache, int regnum)
 {
   gdb_assert (regcache != NULL);
+  return regcache->get_register_status (regnum);
+}
+
+enum register_status
+regcache::get_register_status (int regnum) const
+{
   gdb_assert (regnum >= 0);
-  if (regcache->readonly_p)
-    gdb_assert (regnum < regcache->descr->nr_cooked_registers);
+  if (readonly_p)
+    gdb_assert (regnum < descr->nr_cooked_registers);
   else
-    gdb_assert (regnum < regcache->descr->nr_raw_registers);
+    gdb_assert (regnum < descr->nr_raw_registers);
 
-  return (enum register_status) regcache->register_status[regnum];
+  return (enum register_status) register_status[regnum];
 }
 
 void
 regcache_invalidate (struct regcache *regcache, int regnum)
 {
   gdb_assert (regcache != NULL);
-  gdb_assert (regnum >= 0);
-  gdb_assert (!regcache->readonly_p);
-  gdb_assert (regnum < regcache->descr->nr_raw_registers);
-  regcache->register_status[regnum] = REG_UNKNOWN;
+  regcache->invalidate (regnum);
 }
 
+void
+regcache::invalidate (int regnum)
+{
+  gdb_assert (regnum >= 0);
+  gdb_assert (!readonly_p);
+  gdb_assert (regnum < descr->nr_raw_registers);
+  register_status[regnum] = REG_UNKNOWN;
+}
 
 /* Global structure containing the current regcache.  */
 
@@ -587,8 +563,8 @@ regcache_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid)
   struct regcache_list *list;
 
   for (list = current_regcache; list; list = list->next)
-    if (ptid_equal (list->regcache->ptid, old_ptid))
-      list->regcache->ptid = new_ptid;
+    if (ptid_equal (list->regcache->get_ptid (), old_ptid))
+      list->regcache->set_ptid (new_ptid);
 }
 
 /* Low level examining and depositing of registers.
@@ -611,7 +587,7 @@ registers_changed_ptid (ptid_t ptid)
   list_link = &current_regcache;
   while (list)
     {
-      if (ptid_match (list->regcache->ptid, ptid))
+      if (ptid_match (list->regcache->get_ptid (), ptid))
 	{
 	  struct regcache_list *dead = list;
 
@@ -657,55 +633,73 @@ void
 regcache_raw_update (struct regcache *regcache, int regnum)
 {
   gdb_assert (regcache != NULL);
-  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
+
+  regcache->raw_update (regnum);
+}
+
+void
+regcache::raw_update (int regnum)
+{
+  gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
 
   /* Make certain that the register cache is up-to-date with respect
      to the current thread.  This switching shouldn't be necessary
      only there is still only one target side register cache.  Sigh!
      On the bright side, at least there is a regcache object.  */
 
-  if (!regcache->readonly_p
-      && regcache_register_status (regcache, regnum) == REG_UNKNOWN)
+  if (!readonly_p && get_register_status (regnum) == REG_UNKNOWN)
     {
-      target_fetch_registers (regcache, regnum);
+      target_fetch_registers (this, regnum);
 
       /* A number of targets can't access the whole set of raw
 	 registers (because the debug API provides no means to get at
 	 them).  */
-      if (regcache->register_status[regnum] == REG_UNKNOWN)
-	regcache->register_status[regnum] = REG_UNAVAILABLE;
+      if (register_status[regnum] == REG_UNKNOWN)
+	register_status[regnum] = REG_UNAVAILABLE;
     }
 }
 
 enum register_status
 regcache_raw_read (struct regcache *regcache, int regnum, gdb_byte *buf)
 {
+  return regcache->raw_read (regnum, buf);
+}
+
+enum register_status
+regcache::raw_read (int regnum, gdb_byte *buf)
+{
   gdb_assert (buf != NULL);
-  regcache_raw_update (regcache, regnum);
+  raw_update (regnum);
 
-  if (regcache->register_status[regnum] != REG_VALID)
-    memset (buf, 0, regcache->descr->sizeof_register[regnum]);
+  if (register_status[regnum] != REG_VALID)
+    memset (buf, 0, descr->sizeof_register[regnum]);
   else
-    memcpy (buf, register_buffer (regcache, regnum),
-	    regcache->descr->sizeof_register[regnum]);
+    memcpy (buf, register_buffer (regnum),
+	    descr->sizeof_register[regnum]);
 
-  return (enum register_status) regcache->register_status[regnum];
+  return (enum register_status) register_status[regnum];
 }
 
 enum register_status
 regcache_raw_read_signed (struct regcache *regcache, int regnum, LONGEST *val)
 {
+  gdb_assert (regcache != NULL);
+  return regcache->raw_read_signed (regnum, val);
+}
+
+enum register_status
+regcache::raw_read_signed (int regnum, LONGEST *val)
+{
   gdb_byte *buf;
   enum register_status status;
 
-  gdb_assert (regcache != NULL);
-  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
-  buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]);
-  status = regcache_raw_read (regcache, regnum, buf);
+  gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
+  buf = (gdb_byte *) alloca (descr->sizeof_register[regnum]);
+  status = raw_read (regnum, buf);
   if (status == REG_VALID)
     *val = extract_signed_integer
-      (buf, regcache->descr->sizeof_register[regnum],
-       gdbarch_byte_order (regcache->descr->gdbarch));
+      (buf, descr->sizeof_register[regnum],
+       gdbarch_byte_order (descr->gdbarch));
   else
     *val = 0;
   return status;
@@ -715,17 +709,24 @@ enum register_status
 regcache_raw_read_unsigned (struct regcache *regcache, int regnum,
 			    ULONGEST *val)
 {
+  gdb_assert (regcache != NULL);
+  return regcache->raw_read_unsigned (regnum, val);
+}
+
+
+enum register_status
+regcache::raw_read_unsigned (int regnum, ULONGEST *val)
+{
   gdb_byte *buf;
   enum register_status status;
 
-  gdb_assert (regcache != NULL);
-  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
-  buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]);
-  status = regcache_raw_read (regcache, regnum, buf);
+  gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
+  buf = (gdb_byte *) alloca (descr->sizeof_register[regnum]);
+  status = raw_read (regnum, buf);
   if (status == REG_VALID)
     *val = extract_unsigned_integer
-      (buf, regcache->descr->sizeof_register[regnum],
-       gdbarch_byte_order (regcache->descr->gdbarch));
+      (buf, descr->sizeof_register[regnum],
+       gdbarch_byte_order (descr->gdbarch));
   else
     *val = 0;
   return status;
@@ -734,28 +735,40 @@ regcache_raw_read_unsigned (struct regcache *regcache, int regnum,
 void
 regcache_raw_write_signed (struct regcache *regcache, int regnum, LONGEST val)
 {
+  gdb_assert (regcache != NULL);
+  regcache->raw_write_signed (regnum, val);
+}
+
+void
+regcache::raw_write_signed (int regnum, LONGEST val)
+{
   gdb_byte *buf;
 
-  gdb_assert (regcache != NULL);
-  gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers);
-  buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]);
-  store_signed_integer (buf, regcache->descr->sizeof_register[regnum],
-			gdbarch_byte_order (regcache->descr->gdbarch), val);
-  regcache_raw_write (regcache, regnum, buf);
+  gdb_assert (regnum >=0 && regnum < descr->nr_raw_registers);
+  buf = (gdb_byte *) alloca (descr->sizeof_register[regnum]);
+  store_signed_integer (buf, descr->sizeof_register[regnum],
+			gdbarch_byte_order (descr->gdbarch), val);
+  raw_write (regnum, buf);
 }
 
 void
 regcache_raw_write_unsigned (struct regcache *regcache, int regnum,
 			     ULONGEST val)
 {
+  gdb_assert (regcache != NULL);
+  regcache->raw_write_unsigned (regnum, val);
+}
+
+void
+regcache::raw_write_unsigned (int regnum, ULONGEST val)
+{
   gdb_byte *buf;
 
-  gdb_assert (regcache != NULL);
-  gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers);
-  buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]);
-  store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum],
-			  gdbarch_byte_order (regcache->descr->gdbarch), val);
-  regcache_raw_write (regcache, regnum, buf);
+  gdb_assert (regnum >=0 && regnum < descr->nr_raw_registers);
+  buf = (gdb_byte *) alloca (descr->sizeof_register[regnum]);
+  store_unsigned_integer (buf, descr->sizeof_register[regnum],
+			  gdbarch_byte_order (descr->gdbarch), val);
+  raw_write (regnum, buf);
 }
 
 LONGEST
@@ -774,38 +787,44 @@ regcache_raw_get_signed (struct regcache *regcache, int regnum)
 enum register_status
 regcache_cooked_read (struct regcache *regcache, int regnum, gdb_byte *buf)
 {
+  return regcache->cooked_read (regnum, buf);
+}
+
+enum register_status
+regcache::cooked_read (int regnum, gdb_byte *buf)
+{
   gdb_assert (regnum >= 0);
-  gdb_assert (regnum < regcache->descr->nr_cooked_registers);
-  if (regnum < regcache->descr->nr_raw_registers)
-    return regcache_raw_read (regcache, regnum, buf);
-  else if (regcache->readonly_p
-	   && regcache->register_status[regnum] != REG_UNKNOWN)
+  gdb_assert (regnum < descr->nr_cooked_registers);
+  if (regnum < descr->nr_raw_registers)
+    return raw_read (regnum, buf);
+  else if (readonly_p
+	   && register_status[regnum] != REG_UNKNOWN)
     {
       /* Read-only register cache, perhaps the cooked value was
 	 cached?  */
-      if (regcache->register_status[regnum] == REG_VALID)
-	memcpy (buf, register_buffer (regcache, regnum),
-		regcache->descr->sizeof_register[regnum]);
+      if (register_status[regnum] == REG_VALID)
+	memcpy (buf, register_buffer (regnum),
+		descr->sizeof_register[regnum]);
       else
-	memset (buf, 0, regcache->descr->sizeof_register[regnum]);
+	memset (buf, 0, descr->sizeof_register[regnum]);
 
-      return (enum register_status) regcache->register_status[regnum];
+      return (enum register_status) register_status[regnum];
     }
-  else if (gdbarch_pseudo_register_read_value_p (regcache->descr->gdbarch))
+  else if (gdbarch_pseudo_register_read_value_p (descr->gdbarch))
     {
       struct value *mark, *computed;
       enum register_status result = REG_VALID;
 
       mark = value_mark ();
 
-      computed = gdbarch_pseudo_register_read_value (regcache->descr->gdbarch,
-						     regcache, regnum);
+      computed = gdbarch_pseudo_register_read_value (descr->gdbarch,
+						     this, regnum);
       if (value_entirely_available (computed))
 	memcpy (buf, value_contents_raw (computed),
-		regcache->descr->sizeof_register[regnum]);
+		descr->sizeof_register[regnum]);
       else
 	{
-	  memset (buf, 0, regcache->descr->sizeof_register[regnum]);
+	  memset (buf, 0, descr->sizeof_register[regnum]);
 	  result = REG_UNAVAILABLE;
 	}
 
@@ -814,58 +833,68 @@ regcache_cooked_read (struct regcache *regcache, int regnum, gdb_byte *buf)
       return result;
     }
   else
-    return gdbarch_pseudo_register_read (regcache->descr->gdbarch, regcache,
+    return gdbarch_pseudo_register_read (descr->gdbarch, this,
 					 regnum, buf);
 }
 
 struct value *
 regcache_cooked_read_value (struct regcache *regcache, int regnum)
 {
+  return regcache->cooked_read_value (regnum);
+}
+
+struct value *
+regcache::cooked_read_value (int regnum)
+{
   gdb_assert (regnum >= 0);
-  gdb_assert (regnum < regcache->descr->nr_cooked_registers);
+  gdb_assert (regnum < descr->nr_cooked_registers);
 
-  if (regnum < regcache->descr->nr_raw_registers
-      || (regcache->readonly_p
-	  && regcache->register_status[regnum] != REG_UNKNOWN)
-      || !gdbarch_pseudo_register_read_value_p (regcache->descr->gdbarch))
+  if (regnum < descr->nr_raw_registers
+      || (readonly_p && register_status[regnum] != REG_UNKNOWN)
+      || !gdbarch_pseudo_register_read_value_p (descr->gdbarch))
     {
       struct value *result;
 
-      result = allocate_value (register_type (regcache->descr->gdbarch,
-					      regnum));
+      result = allocate_value (register_type (descr->gdbarch, regnum));
       VALUE_LVAL (result) = lval_register;
       VALUE_REGNUM (result) = regnum;
 
       /* It is more efficient in general to do this delegation in this
 	 direction than in the other one, even though the value-based
 	 API is preferred.  */
-      if (regcache_cooked_read (regcache, regnum,
-				value_contents_raw (result)) == REG_UNAVAILABLE)
+      if (cooked_read (regnum,
+		       value_contents_raw (result)) == REG_UNAVAILABLE)
 	mark_value_bytes_unavailable (result, 0,
 				      TYPE_LENGTH (value_type (result)));
 
       return result;
     }
   else
-    return gdbarch_pseudo_register_read_value (regcache->descr->gdbarch,
-					       regcache, regnum);
+    return gdbarch_pseudo_register_read_value (descr->gdbarch,
+					       this, regnum);
 }
 
 enum register_status
 regcache_cooked_read_signed (struct regcache *regcache, int regnum,
 			     LONGEST *val)
 {
+  gdb_assert (regcache != NULL);
+  return regcache->cooked_read_signed (regnum, val);
+}
+
+enum register_status
+regcache::cooked_read_signed (int regnum, LONGEST *val)
+{
   enum register_status status;
   gdb_byte *buf;
 
-  gdb_assert (regcache != NULL);
-  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers);
-  buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]);
-  status = regcache_cooked_read (regcache, regnum, buf);
+  gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
+  buf = (gdb_byte *) alloca (descr->sizeof_register[regnum]);
+  status = cooked_read (regnum, buf);
   if (status == REG_VALID)
     *val = extract_signed_integer
-      (buf, regcache->descr->sizeof_register[regnum],
-       gdbarch_byte_order (regcache->descr->gdbarch));
+      (buf, descr->sizeof_register[regnum],
+       gdbarch_byte_order (descr->gdbarch));
   else
     *val = 0;
   return status;
@@ -875,17 +904,23 @@ enum register_status
 regcache_cooked_read_unsigned (struct regcache *regcache, int regnum,
 			       ULONGEST *val)
 {
+  gdb_assert (regcache != NULL);
+  return regcache->cooked_read_unsigned (regnum, val);
+}
+
+enum register_status
+regcache::cooked_read_unsigned (int regnum, ULONGEST *val)
+{
   enum register_status status;
   gdb_byte *buf;
 
-  gdb_assert (regcache != NULL);
-  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers);
-  buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]);
-  status = regcache_cooked_read (regcache, regnum, buf);
+  gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
+  buf = (gdb_byte *) alloca (descr->sizeof_register[regnum]);
+  status = cooked_read (regnum, buf);
   if (status == REG_VALID)
     *val = extract_unsigned_integer
-      (buf, regcache->descr->sizeof_register[regnum],
-       gdbarch_byte_order (regcache->descr->gdbarch));
+      (buf, descr->sizeof_register[regnum],
+       gdbarch_byte_order (descr->gdbarch));
   else
     *val = 0;
   return status;
@@ -895,28 +930,40 @@ void
 regcache_cooked_write_signed (struct regcache *regcache, int regnum,
 			      LONGEST val)
 {
+  gdb_assert (regcache != NULL);
+  regcache->cooked_write_signed (regnum, val);
+}
+
+void
+regcache::cooked_write_signed (int regnum, LONGEST val)
+{
   gdb_byte *buf;
 
-  gdb_assert (regcache != NULL);
-  gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers);
-  buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]);
-  store_signed_integer (buf, regcache->descr->sizeof_register[regnum],
-			gdbarch_byte_order (regcache->descr->gdbarch), val);
-  regcache_cooked_write (regcache, regnum, buf);
+  gdb_assert (regnum >=0 && regnum < descr->nr_cooked_registers);
+  buf = (gdb_byte *) alloca (descr->sizeof_register[regnum]);
+  store_signed_integer (buf, descr->sizeof_register[regnum],
+			gdbarch_byte_order (descr->gdbarch), val);
+  cooked_write (regnum, buf);
 }
 
 void
 regcache_cooked_write_unsigned (struct regcache *regcache, int regnum,
 				ULONGEST val)
 {
+  gdb_assert (regcache != NULL);
+  regcache->cooked_write_unsigned (regnum, val);
+}
+
+void
+regcache::cooked_write_unsigned (int regnum, ULONGEST val)
+{
   gdb_byte *buf;
 
-  gdb_assert (regcache != NULL);
-  gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers);
-  buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]);
-  store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum],
-			  gdbarch_byte_order (regcache->descr->gdbarch), val);
-  regcache_cooked_write (regcache, regnum, buf);
+  gdb_assert (regnum >=0 && regnum < descr->nr_cooked_registers);
+  buf = (gdb_byte *) alloca (descr->sizeof_register[regnum]);
+  store_unsigned_integer (buf, descr->sizeof_register[regnum],
+			  gdbarch_byte_order (descr->gdbarch), val);
+  cooked_write (regnum, buf);
 }
 
 /* See regcache.h.  */
@@ -925,41 +972,54 @@ void
 regcache_raw_set_cached_value (struct regcache *regcache, int regnum,
 			       const gdb_byte *buf)
 {
-  memcpy (register_buffer (regcache, regnum), buf,
-	  regcache->descr->sizeof_register[regnum]);
-  regcache->register_status[regnum] = REG_VALID;
+  regcache->raw_set_cached_value (regnum, buf);
+}
+
+void
+regcache::raw_set_cached_value (int regnum, const gdb_byte *buf)
+{
+  memcpy (register_buffer (regnum), buf,
+	  descr->sizeof_register[regnum]);
+  register_status[regnum] = REG_VALID;
 }
 
 void
 regcache_raw_write (struct regcache *regcache, int regnum,
 		    const gdb_byte *buf)
 {
+  gdb_assert (regcache != NULL && buf != NULL);
+  regcache->raw_write (regnum, buf);
+}
+
+void
+regcache::raw_write (int regnum, const gdb_byte *buf)
+{
   struct cleanup *old_chain;
 
-  gdb_assert (regcache != NULL && buf != NULL);
-  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
-  gdb_assert (!regcache->readonly_p);
+  gdb_assert (buf != NULL);
+  gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
+  gdb_assert (!readonly_p);
 
   /* On the sparc, writing %g0 is a no-op, so we don't even want to
      change the registers array if something writes to this register.  */
-  if (gdbarch_cannot_store_register (get_regcache_arch (regcache), regnum))
+  if (gdbarch_cannot_store_register (get_arch (), regnum))
     return;
 
   /* If we have a valid copy of the register, and new value == old
      value, then don't bother doing the actual store.  */
-  if (regcache_register_status (regcache, regnum) == REG_VALID
-      && (memcmp (register_buffer (regcache, regnum), buf,
-		  regcache->descr->sizeof_register[regnum]) == 0))
+  if (get_register_status (regnum) == REG_VALID
+      && (memcmp (register_buffer (regnum), buf,
+		  descr->sizeof_register[regnum]) == 0))
     return;
 
-  target_prepare_to_store (regcache);
-  regcache_raw_set_cached_value (regcache, regnum, buf);
+  target_prepare_to_store (this);
+  raw_set_cached_value (regnum, buf);
 
   /* Register a cleanup function for invalidating the register after it is
      written, in case of a failure.  */
-  old_chain = make_cleanup_regcache_invalidate (regcache, regnum);
+  old_chain = make_cleanup_regcache_invalidate (this, regnum);
 
-  target_store_registers (regcache, regnum);
+  target_store_registers (this, regnum);
 
   /* The target did not throw an error so we can discard invalidating the
      register and restore the cleanup chain to what it was.  */
@@ -970,12 +1030,18 @@ void
 regcache_cooked_write (struct regcache *regcache, int regnum,
 		       const gdb_byte *buf)
 {
+  regcache->cooked_write (regnum, buf);
+}
+
+void
+regcache::cooked_write (int regnum, const gdb_byte *buf)
+{
   gdb_assert (regnum >= 0);
-  gdb_assert (regnum < regcache->descr->nr_cooked_registers);
-  if (regnum < regcache->descr->nr_raw_registers)
-    regcache_raw_write (regcache, regnum, buf);
+  gdb_assert (regnum < descr->nr_cooked_registers);
+  if (regnum < descr->nr_raw_registers)
+    raw_write (regnum, buf);
   else
-    gdbarch_pseudo_register_write (regcache->descr->gdbarch, regcache,
+    gdbarch_pseudo_register_write (descr->gdbarch, this,
 				   regnum, buf);
 }
 
@@ -987,17 +1053,16 @@ typedef void (regcache_read_ftype) (struct regcache *regcache, int regnum,
 typedef void (regcache_write_ftype) (struct regcache *regcache, int regnum,
 				     const void *buf);
 
-static enum register_status
-regcache_xfer_part (struct regcache *regcache, int regnum,
-		    int offset, int len, void *in, const void *out,
-		    enum register_status (*read) (struct regcache *regcache,
-						  int regnum,
-						  gdb_byte *buf),
-		    void (*write) (struct regcache *regcache, int regnum,
-				   const gdb_byte *buf))
-{
-  struct regcache_descr *descr = regcache->descr;
-  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+enum register_status
+regcache::xfer_part (int regnum, int offset, int len, void *in,
+		     const void *out,
+		     enum register_status (*read) (struct regcache *regcache,
+						   int regnum,
+						   gdb_byte *buf),
+		     void (*write) (struct regcache *regcache, int regnum,
+				    const gdb_byte *buf))
+{
+  struct gdbarch *gdbarch = get_arch ();
   gdb_byte *reg = (gdb_byte *) alloca (register_size (gdbarch, regnum));
 
   gdb_assert (offset >= 0 && offset <= descr->sizeof_register[regnum]);
@@ -1013,7 +1078,7 @@ regcache_xfer_part (struct regcache *regcache, int regnum,
       enum register_status status;
 
       gdb_assert (read != NULL);
-      status = read (regcache, regnum, reg);
+      status = read (this, regnum, reg);
       if (status != REG_VALID)
 	return status;
     }
@@ -1026,7 +1091,7 @@ regcache_xfer_part (struct regcache *regcache, int regnum,
   if (out != NULL)
     {
       gdb_assert (write != NULL);
-      write (regcache, regnum, reg);
+      write (this, regnum, reg);
     }
 
   return REG_VALID;
@@ -1036,44 +1101,63 @@ enum register_status
 regcache_raw_read_part (struct regcache *regcache, int regnum,
 			int offset, int len, gdb_byte *buf)
 {
-  struct regcache_descr *descr = regcache->descr;
+  return regcache->raw_read_part (regnum, offset, len, buf);
+}
 
+enum register_status
+regcache::raw_read_part (int regnum, int offset, int len, gdb_byte *buf)
+{
   gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
-  return regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
-			     regcache_raw_read, regcache_raw_write);
+  return xfer_part (regnum, offset, len, buf, NULL,
+		    regcache_raw_read, regcache_raw_write);
 }
 
 void
 regcache_raw_write_part (struct regcache *regcache, int regnum,
 			 int offset, int len, const gdb_byte *buf)
 {
-  struct regcache_descr *descr = regcache->descr;
+  regcache->raw_write_part (regnum, offset, len, buf);
+}
 
+void
+regcache::raw_write_part (int regnum, int offset, int len,
+			  const gdb_byte *buf)
+{
   gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
-  regcache_xfer_part (regcache, regnum, offset, len, NULL, buf,
-		      regcache_raw_read, regcache_raw_write);
+  xfer_part (regnum, offset, len, NULL, buf, regcache_raw_read,
+	     regcache_raw_write);
 }
 
 enum register_status
 regcache_cooked_read_part (struct regcache *regcache, int regnum,
 			   int offset, int len, gdb_byte *buf)
 {
-  struct regcache_descr *descr = regcache->descr;
+  return regcache->cooked_read_part (regnum, offset, len, buf);
+}
+
 
+enum register_status
+regcache::cooked_read_part (int regnum, int offset, int len, gdb_byte *buf)
+{
   gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
-  return regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
-			     regcache_cooked_read, regcache_cooked_write);
+  return xfer_part (regnum, offset, len, buf, NULL,
+		    regcache_cooked_read, regcache_cooked_write);
 }
 
 void
 regcache_cooked_write_part (struct regcache *regcache, int regnum,
 			    int offset, int len, const gdb_byte *buf)
 {
-  struct regcache_descr *descr = regcache->descr;
+  regcache->cooked_write_part (regnum, offset, len, buf);
+}
 
+void
+regcache::cooked_write_part (int regnum, int offset, int len,
+			     const gdb_byte *buf)
+{
   gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
-  regcache_xfer_part (regcache, regnum, offset, len, NULL, buf,
-		      regcache_cooked_read, regcache_cooked_write);
+  xfer_part (regnum, offset, len, NULL, buf,
+	     regcache_cooked_read, regcache_cooked_write);
 }
 
 /* Supply register REGNUM, whose contents are stored in BUF, to REGCACHE.  */
@@ -1081,20 +1165,26 @@ regcache_cooked_write_part (struct regcache *regcache, int regnum,
 void
 regcache_raw_supply (struct regcache *regcache, int regnum, const void *buf)
 {
+  gdb_assert (regcache != NULL);
+  regcache->raw_supply (regnum, buf);
+}
+
+void
+regcache::raw_supply (int regnum, const void *buf)
+{
   void *regbuf;
   size_t size;
 
-  gdb_assert (regcache != NULL);
-  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
-  gdb_assert (!regcache->readonly_p);
+  gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
+  gdb_assert (!readonly_p);
 
-  regbuf = register_buffer (regcache, regnum);
-  size = regcache->descr->sizeof_register[regnum];
+  regbuf = register_buffer (regnum);
+  size = descr->sizeof_register[regnum];
 
   if (buf)
     {
       memcpy (regbuf, buf, size);
-      regcache->register_status[regnum] = REG_VALID;
+      register_status[regnum] = REG_VALID;
     }
   else
     {
@@ -1102,7 +1192,7 @@ regcache_raw_supply (struct regcache *regcache, int regnum, const void *buf)
 	 in case the register value manages to escape somewhere (due
 	 to a bug, no less).  */
       memset (regbuf, 0, size);
-      regcache->register_status[regnum] = REG_UNAVAILABLE;
+      register_status[regnum] = REG_UNAVAILABLE;
     }
 }
 
@@ -1111,14 +1201,21 @@ regcache_raw_supply (struct regcache *regcache, int regnum, const void *buf)
 void
 regcache_raw_collect (const struct regcache *regcache, int regnum, void *buf)
 {
+  gdb_assert (regcache != NULL && buf != NULL);
+  regcache->raw_collect (regnum, buf);
+}
+
+void
+regcache::raw_collect (int regnum, void *buf) const
+{
   const void *regbuf;
   size_t size;
 
-  gdb_assert (regcache != NULL && buf != NULL);
-  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
+  gdb_assert (buf != NULL);
+  gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
 
-  regbuf = register_buffer (regcache, regnum);
-  size = regcache->descr->sizeof_register[regnum];
+  regbuf = register_buffer (regnum);
+  size = descr->sizeof_register[regnum];
   memcpy (buf, regbuf, size);
 }
 
@@ -1126,12 +1223,11 @@ regcache_raw_collect (const struct regcache *regcache, int regnum, void *buf)
    set to or from a buffer.  This is the main worker function for
    regcache_supply_regset and regcache_collect_regset.  */
 
-static void
-regcache_transfer_regset (const struct regset *regset,
-			  const struct regcache *regcache,
-			  struct regcache *out_regcache,
-			  int regnum, const void *in_buf,
-			  void *out_buf, size_t size)
+void
+regcache::transfer_regset (const struct regset *regset,
+			   struct regcache *out_regcache,
+			   int regnum, const void *in_buf,
+			   void *out_buf, size_t size) const
 {
   const struct regcache_map_entry *map;
   int offs = 0, count;
@@ -1144,7 +1240,7 @@ regcache_transfer_regset (const struct regset *regset,
       int slot_size = map->size;
 
       if (slot_size == 0 && regno != REGCACHE_MAP_SKIP)
-	slot_size = regcache->descr->sizeof_register[regno];
+	slot_size = descr->sizeof_register[regno];
 
       if (regno == REGCACHE_MAP_SKIP
 	  || (regnum != -1
@@ -1158,12 +1254,11 @@ regcache_transfer_regset (const struct regset *regset,
 	      break;
 
 	    if (out_buf)
-	      regcache_raw_collect (regcache, regno,
-				    (gdb_byte *) out_buf + offs);
+	      raw_collect (regno, (gdb_byte *) out_buf + offs);
 	    else
-	      regcache_raw_supply (out_regcache, regno, in_buf
-				   ? (const gdb_byte *) in_buf + offs
-				   : NULL);
+	      out_regcache->raw_supply (regno, in_buf
+					? (const gdb_byte *) in_buf + offs
+					: NULL);
 	  }
       else
 	{
@@ -1173,12 +1268,11 @@ regcache_transfer_regset (const struct regset *regset,
 	    return;
 
 	  if (out_buf)
-	    regcache_raw_collect (regcache, regnum,
-				  (gdb_byte *) out_buf + offs);
+	    raw_collect (regnum, (gdb_byte *) out_buf + offs);
 	  else
-	    regcache_raw_supply (out_regcache, regnum, in_buf
-				 ? (const gdb_byte *) in_buf + offs
-				 : NULL);
+	    out_regcache->raw_supply (regnum, in_buf
+				      ? (const gdb_byte *) in_buf + offs
+				      : NULL);
 	  return;
 	}
     }
@@ -1193,8 +1287,14 @@ regcache_supply_regset (const struct regset *regset,
 			struct regcache *regcache,
 			int regnum, const void *buf, size_t size)
 {
-  regcache_transfer_regset (regset, regcache, regcache, regnum,
-			    buf, NULL, size);
+  regcache->supply_regset (regset, regnum, buf, size);
+}
+
+void
+regcache::supply_regset (const struct regset *regset,
+			 int regnum, const void *buf, size_t size)
+{
+  transfer_regset (regset, this, regnum, buf, NULL, size);
 }
 
 /* Collect register REGNUM from REGCACHE to BUF, using the register
@@ -1206,8 +1306,14 @@ regcache_collect_regset (const struct regset *regset,
 			 const struct regcache *regcache,
 			 int regnum, void *buf, size_t size)
 {
-  regcache_transfer_regset (regset, regcache, NULL, regnum,
-			    NULL, buf, size);
+  regcache->collect_regset (regset, regnum, buf, size);
+}
+
+void
+regcache::collect_regset (const struct regset *regset,
+			 int regnum, void *buf, size_t size) const
+{
+  transfer_regset (regset, NULL, regnum, NULL, buf, size);
 }
 
 
@@ -1260,10 +1366,9 @@ regcache_write_pc (struct regcache *regcache, CORE_ADDR pc)
 }
 
 void
-regcache_debug_print_register (const char *func, struct regcache *regcache,
-			       int regno)
+regcache::debug_print_register (const char *func,  int regno)
 {
-  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  struct gdbarch *gdbarch = get_arch ();
 
   fprintf_unfiltered (gdb_stdlog, "%s ", func);
   if (regno >= 0 && regno < gdbarch_num_regs (gdbarch)
@@ -1277,7 +1382,7 @@ regcache_debug_print_register (const char *func, struct regcache *regcache,
     {
       enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
       int size = register_size (gdbarch, regno);
-      gdb_byte *buf = register_buffer (regcache, regno);
+      gdb_byte *buf = register_buffer (regno);
 
       fprintf_unfiltered (gdb_stdlog, " = ");
       for (int i = 0; i < size; i++)
@@ -1304,19 +1409,11 @@ reg_flush_command (char *command, int from_tty)
     printf_filtered (_("Register cache flushed.\n"));
 }
 
-enum regcache_dump_what
-{
-  regcache_dump_none, regcache_dump_raw,
-  regcache_dump_cooked, regcache_dump_groups,
-  regcache_dump_remote
-};
-
-static void
-regcache_dump (struct regcache *regcache, struct ui_file *file,
-	       enum regcache_dump_what what_to_dump)
+void
+regcache::dump (ui_file *file, enum regcache_dump_what what_to_dump)
 {
   struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
-  struct gdbarch *gdbarch = regcache->descr->gdbarch;
+  struct gdbarch *gdbarch = descr->gdbarch;
   int regnum;
   int footnote_nr = 0;
   int footnote_register_size = 0;
@@ -1327,24 +1424,24 @@ regcache_dump (struct regcache *regcache, struct ui_file *file,
 
 #if 0
   fprintf_unfiltered (file, "nr_raw_registers %d\n",
-		      regcache->descr->nr_raw_registers);
+		      descr->nr_raw_registers);
   fprintf_unfiltered (file, "nr_cooked_registers %d\n",
-		      regcache->descr->nr_cooked_registers);
+		      descr->nr_cooked_registers);
   fprintf_unfiltered (file, "sizeof_raw_registers %ld\n",
-		      regcache->descr->sizeof_raw_registers);
+		      descr->sizeof_raw_registers);
   fprintf_unfiltered (file, "sizeof_raw_register_status %ld\n",
-		      regcache->descr->sizeof_raw_register_status);
+		      descr->sizeof_raw_register_status);
   fprintf_unfiltered (file, "gdbarch_num_regs %d\n", 
 		      gdbarch_num_regs (gdbarch));
   fprintf_unfiltered (file, "gdbarch_num_pseudo_regs %d\n",
 		      gdbarch_num_pseudo_regs (gdbarch));
 #endif
 
-  gdb_assert (regcache->descr->nr_cooked_registers
+  gdb_assert (descr->nr_cooked_registers
 	      == (gdbarch_num_regs (gdbarch)
 		  + gdbarch_num_pseudo_regs (gdbarch)));
 
-  for (regnum = -1; regnum < regcache->descr->nr_cooked_registers; regnum++)
+  for (regnum = -1; regnum < descr->nr_cooked_registers; regnum++)
     {
       /* Name.  */
       if (regnum < 0)
@@ -1381,12 +1478,12 @@ regcache_dump (struct regcache *regcache, struct ui_file *file,
       else
 	{
 	  fprintf_unfiltered (file, " %6ld",
-			      regcache->descr->register_offset[regnum]);
-	  if (register_offset != regcache->descr->register_offset[regnum]
+			      descr->register_offset[regnum]);
+	  if (register_offset != descr->register_offset[regnum]
 	      || (regnum > 0
-		  && (regcache->descr->register_offset[regnum]
-		      != (regcache->descr->register_offset[regnum - 1]
-			  + regcache->descr->sizeof_register[regnum - 1])))
+		  && (descr->register_offset[regnum]
+		      != (descr->register_offset[regnum - 1]
+			  + descr->sizeof_register[regnum - 1])))
 	      )
 	    {
 	      if (!footnote_register_offset)
@@ -1395,16 +1492,15 @@ regcache_dump (struct regcache *regcache, struct ui_file *file,
 	    }
 	  else
 	    fprintf_unfiltered (file, "  ");
-	  register_offset = (regcache->descr->register_offset[regnum]
-			     + regcache->descr->sizeof_register[regnum]);
+	  register_offset = (descr->register_offset[regnum]
+			     + descr->sizeof_register[regnum]);
 	}
 
       /* Size.  */
       if (regnum < 0)
 	fprintf_unfiltered (file, " %5s ", "Size");
       else
-	fprintf_unfiltered (file, " %5ld",
-			    regcache->descr->sizeof_register[regnum]);
+	fprintf_unfiltered (file, " %5ld", descr->sizeof_register[regnum]);
 
       /* Type.  */
       {
@@ -1416,7 +1512,7 @@ regcache_dump (struct regcache *regcache, struct ui_file *file,
 	  {
 	    static const char blt[] = "builtin_type";
 
-	    t = TYPE_NAME (register_type (regcache->descr->gdbarch, regnum));
+	    t = TYPE_NAME (register_type (get_arch (), regnum));
 	    if (t == NULL)
 	      {
 		char *n;
@@ -1442,17 +1538,17 @@ regcache_dump (struct regcache *regcache, struct ui_file *file,
 	{
 	  if (regnum < 0)
 	    fprintf_unfiltered (file, "Raw value");
-	  else if (regnum >= regcache->descr->nr_raw_registers)
+	  else if (regnum >= descr->nr_raw_registers)
 	    fprintf_unfiltered (file, "<cooked>");
-	  else if (regcache_register_status (regcache, regnum) == REG_UNKNOWN)
+	  else if (get_register_status (regnum) == REG_UNKNOWN)
 	    fprintf_unfiltered (file, "<invalid>");
-	  else if (regcache_register_status (regcache, regnum) == REG_UNAVAILABLE)
+	  else if (get_register_status (regnum) == REG_UNAVAILABLE)
 	    fprintf_unfiltered (file, "<unavailable>");
 	  else
 	    {
-	      regcache_raw_read (regcache, regnum, buf);
+	      raw_read (regnum, buf);
 	      print_hex_chars (file, buf,
-			       regcache->descr->sizeof_register[regnum],
+			       descr->sizeof_register[regnum],
 			       gdbarch_byte_order (gdbarch));
 	    }
 	}
@@ -1466,14 +1562,14 @@ regcache_dump (struct regcache *regcache, struct ui_file *file,
 	    {
 	      enum register_status status;
 
-	      status = regcache_cooked_read (regcache, regnum, buf);
+	      status = cooked_read (regnum, buf);
 	      if (status == REG_UNKNOWN)
 		fprintf_unfiltered (file, "<invalid>");
 	      else if (status == REG_UNAVAILABLE)
 		fprintf_unfiltered (file, "<unavailable>");
 	      else
 		print_hex_chars (file, buf,
-				 regcache->descr->sizeof_register[regnum],
+				 descr->sizeof_register[regnum],
 				 gdbarch_byte_order (gdbarch));
 	    }
 	}
@@ -1509,11 +1605,11 @@ regcache_dump (struct regcache *regcache, struct ui_file *file,
 	    {
 	      fprintf_unfiltered (file, "Rmt Nr  g/G Offset");
 	    }
-	  else if (regnum < regcache->descr->nr_raw_registers)
+	  else if (regnum < descr->nr_raw_registers)
 	    {
 	      int pnum, poffset;
 
-	      if (remote_register_number_and_offset (get_regcache_arch (regcache), regnum,
+	      if (remote_register_number_and_offset (get_arch (), regnum,
 						     &pnum, &poffset))
 		fprintf_unfiltered (file, "%7d %11d", pnum, poffset);
 	    }
@@ -1539,14 +1635,14 @@ static void
 regcache_print (char *args, enum regcache_dump_what what_to_dump)
 {
   if (args == NULL)
-    regcache_dump (get_current_regcache (), gdb_stdout, what_to_dump);
+    get_current_regcache ()->dump (gdb_stdout, what_to_dump);
   else
     {
       stdio_file file;
 
       if (!file.open (args, "w"))
 	perror_with_name (_("maintenance print architecture"));
-      regcache_dump (get_current_regcache (), &file, what_to_dump);
+      get_current_regcache ()->dump (&file, what_to_dump);
     }
 }
 
diff --git a/gdb/regcache.h b/gdb/regcache.h
index 1d60fa7..8794966 100644
--- a/gdb/regcache.h
+++ b/gdb/regcache.h
@@ -224,6 +224,162 @@ extern void regcache_save (struct regcache *dst,
 			   regcache_cooked_read_ftype *cooked_read,
 			   void *cooked_read_context);
 
+enum regcache_dump_what
+{
+  regcache_dump_none, regcache_dump_raw,
+  regcache_dump_cooked, regcache_dump_groups,
+  regcache_dump_remote
+};
+
+/* The register cache for storing raw register values.  */
+
+struct regcache
+{
+public:
+  explicit regcache (struct gdbarch *gdbarch, struct address_space *aspace_)
+    : regcache (gdbarch, aspace_, true)
+  {}
+
+  ~regcache ()
+  {
+    xfree (registers);
+    xfree (register_status);
+  }
+
+  struct gdbarch *get_arch () const;
+
+  struct address_space *
+  get_aspace () const
+  {
+    return aspace;
+  }
+
+  void save (regcache_cooked_read_ftype *cooked_read, void *src);
+
+  enum register_status cooked_read (int regnum, gdb_byte *buf);
+  void cooked_write (int regnum, const gdb_byte *buf);
+
+  enum register_status raw_read (int regnum, gdb_byte *buf);
+  void raw_write (int regnum, const gdb_byte *buf);
+
+  enum register_status raw_read_signed (int regnum, LONGEST *val);
+
+  void raw_write_signed (int regnum, LONGEST val);
+
+  enum register_status raw_read_unsigned (int regnum, ULONGEST *val);
+
+  void raw_write_unsigned (int regnum, ULONGEST val);
+
+  struct value *cooked_read_value (int regnum);
+
+  enum register_status cooked_read_signed (int regnum, LONGEST *val);
+
+  void cooked_write_signed (int regnum, LONGEST val);
+
+  enum register_status cooked_read_unsigned (int regnum, ULONGEST *val);
+
+  void cooked_write_unsigned (int regnum, ULONGEST val);
+
+  void raw_update (int regnum);
+
+  void raw_collect (int regnum, void *buf) const;
+
+  void raw_supply (int regnum, const void *buf);
+
+  enum register_status get_register_status (int regnum) const;
+
+  void raw_set_cached_value (int regnum, const gdb_byte *buf);
+
+  void invalidate (int regnum);
+
+  enum register_status raw_read_part (int regnum, int offset, int len,
+				      gdb_byte *buf);
+
+  void raw_write_part (int regnum, int offset, int len, const gdb_byte *buf);
+
+  enum register_status cooked_read_part (int regnum, int offset, int len,
+					 gdb_byte *buf);
+
+  void cooked_write_part (int regnum, int offset, int len,
+			  const gdb_byte *buf);
+
+  void supply_regset (const struct regset *regset,
+		      int regnum, const void *buf, size_t size);
+
+
+  void collect_regset (const struct regset *regset, int regnum,
+		       void *buf, size_t size) const;
+
+  void dump (ui_file *file, enum regcache_dump_what what_to_dump);
+
+  ptid_t get_ptid () const
+  {
+    return ptid;
+  }
+
+  void set_ptid (const ptid_t ptid)
+  {
+    this->ptid = ptid;
+  }
+
+/* Dump the contents of a register from the register cache to the target
+   debug.  */
+  void debug_print_register (const char *func, int regno);
+
+private:
+  explicit regcache (struct gdbarch *gdbarch, struct address_space *aspace_,
+		     bool readonly_p_);
+
+  gdb_byte *register_buffer (int regnum) const;
+
+  void
+  restore (struct regcache *src);
+
+  void cpy_no_passthrough (struct regcache *src);
+
+  enum register_status
+  xfer_part (int regnum, int offset, int len, void *in, const void *out,
+	     enum register_status (*read) (struct regcache *regcache,
+					   int regnum, gdb_byte *buf),
+	     void (*write) (struct regcache *regcache, int regnum,
+			    const gdb_byte *buf));
+
+  void transfer_regset (const struct regset *regset,
+			struct regcache *out_regcache,
+			int regnum, const void *in_buf,
+			void *out_buf, size_t size) const;
+
+  struct regcache_descr *descr;
+
+  /* The address space of this register cache (for registers where it
+     makes sense, like PC or SP).  */
+  struct address_space *aspace;
+
+  /* The register buffers.  A read-only register cache can hold the
+     full [0 .. gdbarch_num_regs + gdbarch_num_pseudo_regs) while a read/write
+     register cache can only hold [0 .. gdbarch_num_regs).  */
+  gdb_byte *registers;
+  /* Register cache status.  */
+  signed char *register_status;
+  /* Is this a read-only cache?  A read-only cache is used for saving
+     the target's register state (e.g, across an inferior function
+     call or just before forcing a function return).  A read-only
+     cache can only be updated via the methods regcache_dup() and
+     regcache_cpy().  The actual contents are determined by the
+     reggroup_save and reggroup_restore methods.  */
+  bool readonly_p;
+  /* If this is a read-write cache, which thread's registers is
+     it connected to?  */
+  ptid_t ptid;
+
+  friend struct regcache *
+  get_thread_arch_aspace_regcache (ptid_t ptid, struct gdbarch *gdbarch,
+				   struct address_space *aspace);
+
+  friend void
+  regcache_cpy (struct regcache *dst, struct regcache *src);
+};
+
 /* Copy/duplicate the contents of a register cache.  By default, the
    operation is pass-through.  Writes to DST and reads from SRC will
    go through to the target.  See also regcache_cpy_no_passthrough.
@@ -236,10 +392,4 @@ extern void regcache_cpy (struct regcache *dest, struct regcache *src);
 extern void registers_changed (void);
 extern void registers_changed_ptid (ptid_t);
 
-/* Dump the contents of a register from the register cache to the target
-   debug.  */
-extern void regcache_debug_print_register (const char *func,
-					   struct regcache *regcache,
-					   int regno);
-
 #endif /* REGCACHE_H */
diff --git a/gdb/target.c b/gdb/target.c
index 10a5315..e526bcc 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -3552,7 +3552,7 @@ target_fetch_registers (struct regcache *regcache, int regno)
 {
   current_target.to_fetch_registers (&current_target, regcache, regno);
   if (targetdebug)
-    regcache_debug_print_register ("target_fetch_registers", regcache, regno);
+    regcache->debug_print_register ("target_fetch_registers", regno);
 }
 
 void
@@ -3564,8 +3564,7 @@ target_store_registers (struct regcache *regcache, int regno)
   current_target.to_store_registers (&current_target, regcache, regno);
   if (targetdebug)
     {
-      regcache_debug_print_register ("target_store_registers", regcache,
-				     regno);
+      regcache->debug_print_register ("target_store_registers", regno);
     }
 }
 
-- 
1.9.1

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 2/6] Add constructor and destructor to regcache
  2017-04-25 20:28 ` [PATCH 2/6] Add constructor and destructor to regcache Yao Qi
@ 2017-04-27 17:34   ` Pedro Alves
  2017-04-28 13:42     ` Yao Qi
  0 siblings, 1 reply; 24+ messages in thread
From: Pedro Alves @ 2017-04-27 17:34 UTC (permalink / raw)
  To: Yao Qi, gdb-patches

A few minor nits below, but looks good to me otherwise.

On 04/25/2017 09:28 PM, Yao Qi wrote:

> diff --git a/gdb/regcache.c b/gdb/regcache.c
> index 966f0c7..e0554c7 100644
> --- a/gdb/regcache.c
> +++ b/gdb/regcache.c
> @@ -191,6 +191,17 @@ regcache_register_size (const struct regcache *regcache, int n)
>  
>  struct regcache
>  {
> +public:
> +  explicit regcache (struct gdbarch *gdbarch, struct address_space *aspace_)
> +    : regcache (gdbarch, aspace_, true)

There's no real good reason to use "explicit" when you have more than
one parameter.

> +  {}
> +
> +  ~regcache ()
> +  {
> +    xfree (registers);
> +    xfree (register_status);
> +  }
> +
>    struct regcache_descr *descr;
>  
>    /* The address space of this register cache (for registers where it
> @@ -213,6 +224,33 @@ struct regcache
>    /* If this is a read-write cache, which thread's registers is
>       it connected to?  */
>    ptid_t ptid;
> +
> +private:
> +  explicit regcache (struct gdbarch *gdbarch, struct address_space *aspace_,
> +		     bool readonly_p_)

Ditto.

> +    : aspace (aspace_), readonly_p (readonly_p_)
> +  {
> +    gdb_assert (gdbarch != NULL);
> +    descr = regcache_descr (gdbarch);
> +
> +  if (readonly_p)
> +    {
> +      registers = XCNEWVEC (gdb_byte, descr->sizeof_cooked_registers);
> +      register_status = XCNEWVEC (signed char,
> +				  descr->sizeof_cooked_register_status);
> +    }
> +  else
> +    {
> +      registers = XCNEWVEC (gdb_byte, descr->sizeof_raw_registers);
> +      register_status = XCNEWVEC (signed char,
> +				  descr->sizeof_raw_register_status);
> +    }
> +  ptid = minus_one_ptid;
> +  }
> +
> +  friend struct regcache *
> +  get_thread_arch_aspace_regcache (ptid_t ptid, struct gdbarch *gdbarch,
> +				   struct address_space *aspace);
>  };

(I'd drop the "struct" in the aspace parameters.)

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 3/6] Class-fy regcache
  2017-04-25 20:29 ` [PATCH 3/6] Class-fy regcache Yao Qi
@ 2017-04-27 17:35   ` Pedro Alves
  0 siblings, 0 replies; 24+ messages in thread
From: Pedro Alves @ 2017-04-27 17:35 UTC (permalink / raw)
  To: Yao Qi, gdb-patches

On 04/25/2017 09:28 PM, Yao Qi wrote:
> This patch moves regcache declaration to regcache.h, and converts
> regcache apis to member functions, for example, regcache_invalidate
> is changed to regcache::invalidate.  Some changes are not done in
> this patch,
> 
>  - keep "struct regcache" instead of renaming to "class regcache",
>    because "struct regcache" is widely used (even in GDBserver).

"struct regcache *" and "class regcache *" are interchangeble,
they mean exactly the same thing.

> +
> +/* Dump the contents of a register from the register cache to the target
> +   debug.  */
> +  void debug_print_register (const char *func, int regno);
> +
> +private:
> +  explicit regcache (struct gdbarch *gdbarch, struct address_space *aspace_,
> +		     bool readonly_p_);
> +
> +  gdb_byte *register_buffer (int regnum) const;
> +
> +  void
> +  restore (struct regcache *src);
> +
> +  void cpy_no_passthrough (struct regcache *src);
> +
> +  enum register_status
> +  xfer_part (int regnum, int offset, int len, void *in, const void *out,
> +	     enum register_status (*read) (struct regcache *regcache,
> +					   int regnum, gdb_byte *buf),
> +	     void (*write) (struct regcache *regcache, int regnum,
> +			    const gdb_byte *buf));
> +


"restore" and "xfer_part" stand out as having odd formatting with
the type on its own line.

> +  void transfer_regset (const struct regset *regset,
> +			struct regcache *out_regcache,
> +			int regnum, const void *in_buf,
> +			void *out_buf, size_t size) const;
> +
> +  struct regcache_descr *descr;
> +
> +  /* The address space of this register cache (for registers where it
> +     makes sense, like PC or SP).  */
> +  struct address_space *aspace;
> +
> +  /* The register buffers.  A read-only register cache can hold the
> +     full [0 .. gdbarch_num_regs + gdbarch_num_pseudo_regs) while a read/write
> +     register cache can only hold [0 .. gdbarch_num_regs).  */
> +  gdb_byte *registers;
> +  /* Register cache status.  */
> +  signed char *register_status;
> +  /* Is this a read-only cache?  A read-only cache is used for saving
> +     the target's register state (e.g, across an inferior function
> +     call or just before forcing a function return).  A read-only
> +     cache can only be updated via the methods regcache_dup() and
> +     regcache_cpy().  The actual contents are determined by the
> +     reggroup_save and reggroup_restore methods.  */
> +  bool readonly_p;
> +  /* If this is a read-write cache, which thread's registers is
> +     it connected to?  */
> +  ptid_t ptid;

All these fields should be prefixed with "m_" now.  You already
need to touch all code that references these fields, so it seems to
me that the patch would have the exact same size if you do it
at the same time.  That allow renaming the
get_ptid() method to ptid(), "get_aspace()" to "aspace()" etc. too.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 5/6] Use copy ctor in regcache_dup
  2017-04-25 20:29 ` [PATCH 5/6] Use copy ctor in regcache_dup Yao Qi
@ 2017-04-27 17:37   ` Pedro Alves
  2017-04-28  9:11     ` Yao Qi
  0 siblings, 1 reply; 24+ messages in thread
From: Pedro Alves @ 2017-04-27 17:37 UTC (permalink / raw)
  To: Yao Qi, gdb-patches

On 04/25/2017 09:28 PM, Yao Qi wrote:
> gdb:
> 
> 2017-04-25  Yao Qi  <yao.qi@linaro.org>
> 
> 	* regcache.c (regcache::regcache): New copy ctor.
> 	(do_cooked_read): Moved above.
> 	(regcache_dup): Use copy ctor.
> 	* regcache.h (struct regcache): Declare copy ctor and remove
> 	friend regcache_dup.
> ---

> index e6494a9..0d302a7 100644
> --- a/gdb/regcache.h
> +++ b/gdb/regcache.h
> @@ -240,6 +240,10 @@ public:
>      : regcache (gdbarch, aspace_, true)
>    {}
>  
> +  /* Copy constructor, create a readonly regcache from a non-readonly
> +     regcache.  */
> +  regcache (const regcache &);

This one doesn't look right to me.  This isn't a copy in the
normal C++ object copy sense.  The new object isn't semantically the
same as the source.  One can't use the new object the same way as the
source regcache, they're not interchangeable.  This is bound to generate
confusion and problems.

Considering patch #6, it'd make more sense to me to
make that a separate constructor with tag dispatching, like:

struct regcache
{
  struct readonly_t {};
  static constexpr readonly_t readonly {};

  regcache (readonly_t, const regcache &src); // old regcache_dup
};

Then used like:

regcache ro_copy (regcache::readonly, src);

or if you want, you could make that tag-based ctor private and
add a factory function:

struct regcache
{
private:
  struct readonly_t {};
  regcache(readonly_t, const regcache &src);

  regcache(regcache &&src) { // implement this } // move ctor

public:
  static regcache make_readonly_copy (const regcache &src)
  {
    return regcache (readonly_t{}, src);
  }
};

Used like 

 regcache ro_copy = regcache::make_readonly_copy (src);

In any case, I think we should make sure to disable
the regular copy methods since the type doesn't really
support normal copy:

  regcache(const regcache &) = delete;
  void operator= (const regcache &) = delete;

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 5/6] Use copy ctor in regcache_dup
  2017-04-27 17:37   ` Pedro Alves
@ 2017-04-28  9:11     ` Yao Qi
  2017-04-28  9:51       ` Pedro Alves
  0 siblings, 1 reply; 24+ messages in thread
From: Yao Qi @ 2017-04-28  9:11 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

Pedro Alves <palves@redhat.com> writes:

> This one doesn't look right to me.  This isn't a copy in the
> normal C++ object copy sense.  The new object isn't semantically the
> same as the source.  One can't use the new object the same way as the
> source regcache, they're not interchangeable.  This is bound to generate
> confusion and problems.

I thought about this.  The reason I still do this is that I can't think
of a case that we need to copy a read-write regcache to another
read-write regcache.  So far, we only use copy(or transform) a
read-write regcache to a read-only regcache.  However, I agree with you,
it is not a normal "copy ctor".

>
> Considering patch #6, it'd make more sense to me to
> make that a separate constructor with tag dispatching, like:
>
> struct regcache
> {
>   struct readonly_t {};
>   static constexpr readonly_t readonly {};
>
>   regcache (readonly_t, const regcache &src); // old regcache_dup
> };
>
> Then used like:
>
> regcache ro_copy (regcache::readonly, src);
>
> or if you want, you could make that tag-based ctor private and
> add a factory function:
>
> struct regcache
> {
> private:
>   struct readonly_t {};
>   regcache(readonly_t, const regcache &src);
>
>   regcache(regcache &&src) { // implement this } // move ctor
>
> public:
>   static regcache make_readonly_copy (const regcache &src)
>   {
>     return regcache (readonly_t{}, src);
>   }
> };
>
> Used like 
>
>  regcache ro_copy = regcache::make_readonly_copy (src);

I have a different design on this, that is, put readonly regcache and
readwrite regcache to two classes.  readwrite regcache inherits readonly
regcache, and readonly regcache has a constructor whose argument is a
readwrite regcache.

class readonly_regcache
{
public:
  explicit readonly_regcache (const regcache &);
}

class regcache : public readonly_regcache
{
}

What do you think?

>
> In any case, I think we should make sure to disable
> the regular copy methods since the type doesn't really
> support normal copy:
>
>   regcache(const regcache &) = delete;
>   void operator= (const regcache &) = delete;

I agree.  I'll add it.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 5/6] Use copy ctor in regcache_dup
  2017-04-28  9:11     ` Yao Qi
@ 2017-04-28  9:51       ` Pedro Alves
  2017-04-28 13:20         ` Yao Qi
  0 siblings, 1 reply; 24+ messages in thread
From: Pedro Alves @ 2017-04-28  9:51 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

On 04/28/2017 10:11 AM, Yao Qi wrote:
> Pedro Alves <palves@redhat.com> writes:
> 
>> This one doesn't look right to me.  This isn't a copy in the
>> normal C++ object copy sense.  The new object isn't semantically the
>> same as the source.  One can't use the new object the same way as the
>> source regcache, they're not interchangeable.  This is bound to generate
>> confusion and problems.
> 
> I thought about this.  The reason I still do this is that I can't think
> of a case that we need to copy a read-write regcache to another
> read-write regcache.  So far, we only use copy(or transform) a
> read-write regcache to a read-only regcache.  However, I agree with you,
> it is not a normal "copy ctor".
> 
>>
>> Considering patch #6, it'd make more sense to me to
>> make that a separate constructor with tag dispatching, like:
>>
>> struct regcache
>> {
>>   struct readonly_t {};
>>   static constexpr readonly_t readonly {};
>>
>>   regcache (readonly_t, const regcache &src); // old regcache_dup
>> };
>>
>> Then used like:
>>
>> regcache ro_copy (regcache::readonly, src);
>>
>> or if you want, you could make that tag-based ctor private and
>> add a factory function:
>>


> 
> I have a different design on this, that is, put readonly regcache and
> readwrite regcache to two classes.  readwrite regcache inherits readonly
> regcache, and readonly regcache has a constructor whose argument is a
> readwrite regcache.

*nod*  I had seen it in the series' intro, but was going with the
idea of avoid that work.  If we can get it nicely expressed in
the type system, then it's even better.

> 
> class readonly_regcache
> {
> public:
>   explicit readonly_regcache (const regcache &);
> }
> 
> class regcache : public readonly_regcache
> {
> }
> 
> What do you think?

I think that that's too incomplete to evaluate.  :-)

Why regcache on top of readonly_regcache and not the other
way around?  Off hand, I'd think that 

 struct regcache_base;
 struct readonly_regcache : regcache_base {};
 struct regcache : regcache_base {};

would be the "obvious" first choice.

What happens to all the "regcache->readonly_p" checks in
spread around in multiple functions?  Do they disappear?  
I think that if the design ends up with that flag still present 
and functions exposing interfaces that work with
a "struct regcache *" that can either be readonly
or write-through, then it's likely that the design
isn't complete.  [But replacing a single boolean
checked in a few select places by virtual methods and a
full blown vtable and a bunch of dispatching makes me
cringe a bit too.  :-)  But OTOH, I suspect you want
to add virtual methods for unit testing.]

I'm totally not against this direction, to be clear,
but it'd still suggest adding the tag dispatch ctor
first (the simple version with no factory, just adds two
lines of code compared to the copy ctor version), which
allows getting rid of the heap allocation and the cleanups
as you're doing in patch #6, and then consider changing
the hierarchy in a follow up patch.

> 
>>
>> In any case, I think we should make sure to disable
>> the regular copy methods since the type doesn't really
>> support normal copy:
>>
>>   regcache(const regcache &) = delete;
>>   void operator= (const regcache &) = delete;
> 
> I agree.  I'll add it.

Thanks.

-- 
Pedro Alves

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 5/6] Use copy ctor in regcache_dup
  2017-04-28  9:51       ` Pedro Alves
@ 2017-04-28 13:20         ` Yao Qi
  0 siblings, 0 replies; 24+ messages in thread
From: Yao Qi @ 2017-04-28 13:20 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

Pedro Alves <palves@redhat.com> writes:

> I think that that's too incomplete to evaluate.  :-)
>
> Why regcache on top of readonly_regcache and not the other
> way around?  Off hand, I'd think that 
>
>  struct regcache_base;
>  struct readonly_regcache : regcache_base {};
>  struct regcache : regcache_base {};
>
> would be the "obvious" first choice.

I have to agree, design like this affects other parts a lot though.

>
> What happens to all the "regcache->readonly_p" checks in
> spread around in multiple functions?  Do they disappear?

I wish they will.
  
> I think that if the design ends up with that flag still present 
> and functions exposing interfaces that work with
> a "struct regcache *" that can either be readonly
> or write-through, then it's likely that the design
> isn't complete.  [But replacing a single boolean
> checked in a few select places by virtual methods and a
> full blown vtable and a bunch of dispatching makes me
> cringe a bit too.  :-)  But OTOH, I suspect you want
> to add virtual methods for unit testing.]

I get your point and let me see how far can I go.  Yes, I need to make
some regcache methods virtual for unit tests, so far I only need to make
raw_write and ~regcache virtual.

>
> I'm totally not against this direction, to be clear,
> but it'd still suggest adding the tag dispatch ctor
> first (the simple version with no factory, just adds two
> lines of code compared to the copy ctor version), which
> allows getting rid of the heap allocation and the cleanups
> as you're doing in patch #6, and then consider changing
> the hierarchy in a follow up patch.

No problem, I'll replace my copy ctor with your tag dispatch ctor.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 2/6] Add constructor and destructor to regcache
  2017-04-27 17:34   ` Pedro Alves
@ 2017-04-28 13:42     ` Yao Qi
  0 siblings, 0 replies; 24+ messages in thread
From: Yao Qi @ 2017-04-28 13:42 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

Pedro Alves <palves@redhat.com> writes:

>> +  explicit regcache (struct gdbarch *gdbarch, struct address_space *aspace_)
>> +    : regcache (gdbarch, aspace_, true)
>
> There's no real good reason to use "explicit" when you have more than
> one parameter.
>

Removed.

>> +
>> +private:
>> +  explicit regcache (struct gdbarch *gdbarch, struct address_space *aspace_,
>> +		     bool readonly_p_)
>
> Ditto.
>

Removed.

>> +    : aspace (aspace_), readonly_p (readonly_p_)
>> +  {
>> +    gdb_assert (gdbarch != NULL);
>> +    descr = regcache_descr (gdbarch);
>> +
>> +  if (readonly_p)
>> +    {
>> +      registers = XCNEWVEC (gdb_byte, descr->sizeof_cooked_registers);
>> +      register_status = XCNEWVEC (signed char,
>> +				  descr->sizeof_cooked_register_status);
>> +    }
>> +  else
>> +    {
>> +      registers = XCNEWVEC (gdb_byte, descr->sizeof_raw_registers);
>> +      register_status = XCNEWVEC (signed char,
>> +				  descr->sizeof_raw_register_status);
>> +    }
>> +  ptid = minus_one_ptid;
>> +  }
>> +
>> +  friend struct regcache *
>> +  get_thread_arch_aspace_regcache (ptid_t ptid, struct gdbarch *gdbarch,
>> +				   struct address_space *aspace);
>>  };
>
> (I'd drop the "struct" in the aspace parameters.)

Removed.

Patch below is pushed in.

-- 
Yao (齐尧)
From c35356d17072b89ae7d6b34c20f4b2cd69ed8468 Mon Sep 17 00:00:00 2001
From: Yao Qi <yao.qi@linaro.org>
Date: Thu, 20 Apr 2017 14:54:26 +0100
Subject: [PATCH] Add constructor and destructor to regcache

This patch adds ctor and dtor to regcache.

gdb:

2017-04-28  Yao Qi  <yao.qi@linaro.org>

	* regcache.c (regcache::regcache): New function.
	(regcache::~regcache): New function.
	(regcache_xmalloc_1): Remove.
	(regcache_xmalloc): Call new regcache.
	(regcache_xfree): Call delete regcache.
	(get_thread_arch_aspace_regcache): Call new regcache.

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index d99c5a2..efaf8bb 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,14 @@
 2017-04-28  Yao Qi  <yao.qi@linaro.org>
 
+	* regcache.c (regcache::regcache): New function.
+	(regcache::~regcache): New function.
+	(regcache_xmalloc_1): Remove.
+	(regcache_xmalloc): Call new regcache.
+	(regcache_xfree): Call delete regcache.
+	(get_thread_arch_aspace_regcache): Call new regcache.
+
+2017-04-28  Yao Qi  <yao.qi@linaro.org>
+
 	* mips-linux-nat.c (mips_linux_new_thread): Use ptid method
 	lwp instead of ptid_get_lwp.
 
diff --git a/gdb/regcache.c b/gdb/regcache.c
index 966f0c7..798812e 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -191,6 +191,17 @@ regcache_register_size (const struct regcache *regcache, int n)
 
 struct regcache
 {
+public:
+  regcache (gdbarch *gdbarch, address_space *aspace_)
+    : regcache (gdbarch, aspace_, true)
+  {}
+
+  ~regcache ()
+  {
+    xfree (registers);
+    xfree (register_status);
+  }
+
   struct regcache_descr *descr;
 
   /* The address space of this register cache (for registers where it
@@ -213,6 +224,32 @@ struct regcache
   /* If this is a read-write cache, which thread's registers is
      it connected to?  */
   ptid_t ptid;
+
+private:
+  regcache (gdbarch *gdbarch, address_space *aspace_, bool readonly_p_)
+    : aspace (aspace_), readonly_p (readonly_p_)
+  {
+    gdb_assert (gdbarch != NULL);
+    descr = regcache_descr (gdbarch);
+
+  if (readonly_p)
+    {
+      registers = XCNEWVEC (gdb_byte, descr->sizeof_cooked_registers);
+      register_status = XCNEWVEC (signed char,
+				  descr->sizeof_cooked_register_status);
+    }
+  else
+    {
+      registers = XCNEWVEC (gdb_byte, descr->sizeof_raw_registers);
+      register_status = XCNEWVEC (signed char,
+				  descr->sizeof_raw_register_status);
+    }
+  ptid = minus_one_ptid;
+  }
+
+  friend regcache *
+  get_thread_arch_aspace_regcache (ptid_t ptid, gdbarch *gdbarch,
+				   address_space *aspace);
 };
 
 /* See regcache.h.  */
@@ -225,41 +262,10 @@ regcache_get_ptid (const struct regcache *regcache)
   return regcache->ptid;
 }
 
-static struct regcache *
-regcache_xmalloc_1 (struct gdbarch *gdbarch, struct address_space *aspace,
-		    bool readonly_p)
-{
-  struct regcache_descr *descr;
-  struct regcache *regcache;
-
-  gdb_assert (gdbarch != NULL);
-  descr = regcache_descr (gdbarch);
-  regcache = XNEW (struct regcache);
-  regcache->descr = descr;
-  regcache->readonly_p = readonly_p;
-  if (readonly_p)
-    {
-      regcache->registers
-	= XCNEWVEC (gdb_byte, descr->sizeof_cooked_registers);
-      regcache->register_status
-	= XCNEWVEC (signed char, descr->sizeof_cooked_register_status);
-    }
-  else
-    {
-      regcache->registers
-	= XCNEWVEC (gdb_byte, descr->sizeof_raw_registers);
-      regcache->register_status
-	= XCNEWVEC (signed char, descr->sizeof_raw_register_status);
-    }
-  regcache->aspace = aspace;
-  regcache->ptid = minus_one_ptid;
-  return regcache;
-}
-
 struct regcache *
 regcache_xmalloc (struct gdbarch *gdbarch, struct address_space *aspace)
 {
-  return regcache_xmalloc_1 (gdbarch, aspace, true);
+  return new regcache (gdbarch, aspace);
 }
 
 void
@@ -267,9 +273,8 @@ regcache_xfree (struct regcache *regcache)
 {
   if (regcache == NULL)
     return;
-  xfree (regcache->registers);
-  xfree (regcache->register_status);
-  xfree (regcache);
+
+  delete regcache;
 }
 
 static void
@@ -507,7 +512,7 @@ get_thread_arch_aspace_regcache (ptid_t ptid, struct gdbarch *gdbarch,
 	&& get_regcache_arch (list->regcache) == gdbarch)
       return list->regcache;
 
-  new_regcache = regcache_xmalloc_1 (gdbarch, aspace, false);
+  new_regcache = new regcache (gdbarch, aspace, false);
   new_regcache->ptid = ptid;
 
   list = XNEW (struct regcache_list);

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 1/4] Class-fy regcache
  2017-04-28 14:26 ` [PATCH 0/4 v2] Class-fy regcache in GDB Yao Qi
  2017-04-28 14:26   ` [PATCH 2/4] Simplify regcache_dup Yao Qi
@ 2017-04-28 14:26   ` Yao Qi
  2017-04-28 15:03     ` Pedro Alves
  2017-04-28 14:26   ` [PATCH 4/4] Remove cleanup in get_return_value Yao Qi
  2017-04-28 14:26   ` [PATCH 3/4] Use tag dispatch regcache ctor in regcache_dup Yao Qi
  3 siblings, 1 reply; 24+ messages in thread
From: Yao Qi @ 2017-04-28 14:26 UTC (permalink / raw)
  To: gdb-patches

This patch moves regcache declaration to regcache.h, and converts
regcache apis to member functions, for example, regcache_invalidate
is changed to regcache::invalidate.

This patch also add "m_" prefix to these private fields.

v2:
 - Change "struct regcache" to "class regcache",
 - Rename private fields with "m_",
 - Simplify declaration of xfer_part using decltype

gdb:

2017-04-28  Yao Qi  <yao.qi@linaro.org>

	* regcache.c (struct regcache): Move to regcache.h
	(regcache::get_gdbarch): New method.
	(regcache_get_ptid): Update.
	(get_regcache_arch): Call get_gdbarch method.
	(get_regcache_aspace): Call method aspace.
	(register_buffer): Change it to method.
	(regcache_save): Change it to regcache::save.
	(regcache_restore): Likewise.
	(regcache_cpy_no_passthrough): Remove the declaration.
	(regcache_cpy): Call methods restore and cpy_no_passthrough.
	(regcache_cpy_no_passthrough): Change it to method
	cpy_no_passthrough.
	(regcache_register_status): Change it to method
	get_register_status.
	(regcache_invalidate): Change it to method invalidate.
	(regcache_thread_ptid_changed): Use methods ptid and set_ptid.
	(regcache_raw_update): Change it to method raw_update.
	(regcache_raw_read): Likewise.
	(regcache_raw_read_signed): Likewise.
	(regcache_raw_read_unsigned): Likewise.
	(regcache_raw_write_signed): Likewise.
	(regcache_raw_write_unsigned): Likewise.
	(regcache_cooked_read): Likewise.
	(regcache_cooked_read_value): Likewise.
	(regcache_cooked_read_signed): Likewise.
	(regcache_cooked_read_unsigned): Likewise.
	(regcache_cooked_write_signed): Likewise.
	(regcache_cooked_write_unsigned): Likewise.
	(regcache_raw_set_cached_value): Likewise.
	(regcache_raw_write): Likewise.
	(regcache_cooked_write): Likewise.
	(regcache_xfer_part): Likewise.
	(regcache_raw_read_part): Likewise.
	(regcache_raw_write_part): Likewise.
	(regcache_cooked_read_part): Likewise.
	(regcache_cooked_write_part): Likewise.
	(regcache_raw_supply): Likewise.
	(regcache_raw_collect): Likewise.
	(regcache_transfer_regset): Likewise.
	(regcache_supply_regset): Likewise.
	(regcache_collect_regset): Likewise.
	(regcache_debug_print_register): Likewise.
	(enum regcache_dump_what): Move it to regcache.h.
	(regcache_dump): Change it to method dump.
	* regcache.h (enum regcache_dump_what): New.
	(class regcache): New.
	* target.c (target_fetch_registers): Call method
	debug_print_register.
	(target_store_registers): Likewise.
---
 gdb/regcache.c | 747 ++++++++++++++++++++++++++++++++-------------------------
 gdb/regcache.h | 157 +++++++++++-
 gdb/target.c   |   5 +-
 3 files changed, 575 insertions(+), 334 deletions(-)

diff --git a/gdb/regcache.c b/gdb/regcache.c
index 798812e..6c3603e 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -187,79 +187,42 @@ regcache_register_size (const struct regcache *regcache, int n)
   return register_size (get_regcache_arch (regcache), n);
 }
 
-/* The register cache for storing raw register values.  */
-
-struct regcache
+regcache::regcache (gdbarch *gdbarch, address_space *aspace_,
+		    bool readonly_p_)
+  : m_aspace (aspace_), m_readonly_p (readonly_p_)
 {
-public:
-  regcache (gdbarch *gdbarch, address_space *aspace_)
-    : regcache (gdbarch, aspace_, true)
-  {}
-
-  ~regcache ()
-  {
-    xfree (registers);
-    xfree (register_status);
-  }
-
-  struct regcache_descr *descr;
-
-  /* The address space of this register cache (for registers where it
-     makes sense, like PC or SP).  */
-  struct address_space *aspace;
-
-  /* The register buffers.  A read-only register cache can hold the
-     full [0 .. gdbarch_num_regs + gdbarch_num_pseudo_regs) while a read/write
-     register cache can only hold [0 .. gdbarch_num_regs).  */
-  gdb_byte *registers;
-  /* Register cache status.  */
-  signed char *register_status;
-  /* Is this a read-only cache?  A read-only cache is used for saving
-     the target's register state (e.g, across an inferior function
-     call or just before forcing a function return).  A read-only
-     cache can only be updated via the methods regcache_dup() and
-     regcache_cpy().  The actual contents are determined by the
-     reggroup_save and reggroup_restore methods.  */
-  bool readonly_p;
-  /* If this is a read-write cache, which thread's registers is
-     it connected to?  */
-  ptid_t ptid;
-
-private:
-  regcache (gdbarch *gdbarch, address_space *aspace_, bool readonly_p_)
-    : aspace (aspace_), readonly_p (readonly_p_)
-  {
-    gdb_assert (gdbarch != NULL);
-    descr = regcache_descr (gdbarch);
+  gdb_assert (gdbarch != NULL);
+  m_descr = regcache_descr (gdbarch);
 
-  if (readonly_p)
+  if (m_readonly_p)
     {
-      registers = XCNEWVEC (gdb_byte, descr->sizeof_cooked_registers);
-      register_status = XCNEWVEC (signed char,
-				  descr->sizeof_cooked_register_status);
+      m_registers = XCNEWVEC (gdb_byte, m_descr->sizeof_cooked_registers);
+      m_register_status = XCNEWVEC (signed char,
+				    m_descr->sizeof_cooked_register_status);
     }
   else
     {
-      registers = XCNEWVEC (gdb_byte, descr->sizeof_raw_registers);
-      register_status = XCNEWVEC (signed char,
-				  descr->sizeof_raw_register_status);
+      m_registers = XCNEWVEC (gdb_byte, m_descr->sizeof_raw_registers);
+      m_register_status = XCNEWVEC (signed char,
+				    m_descr->sizeof_raw_register_status);
     }
-  ptid = minus_one_ptid;
-  }
+  m_ptid = minus_one_ptid;
+}
 
-  friend regcache *
-  get_thread_arch_aspace_regcache (ptid_t ptid, gdbarch *gdbarch,
-				   address_space *aspace);
-};
+gdbarch *
+regcache::get_gdbarch () const
+{
+  return m_descr->gdbarch;
+}
 
 /* See regcache.h.  */
 
 ptid_t
 regcache_get_ptid (const struct regcache *regcache)
 {
-  gdb_assert (!ptid_equal (regcache->ptid, minus_one_ptid));
+  gdb_assert (!ptid_equal (regcache->ptid (), minus_one_ptid));
 
-  return regcache->ptid;
+  return regcache->ptid ();
 }
 
 struct regcache *
@@ -320,84 +283,90 @@ make_cleanup_regcache_invalidate (struct regcache *regcache, int regnum)
 struct gdbarch *
 get_regcache_arch (const struct regcache *regcache)
 {
-  return regcache->descr->gdbarch;
+  return regcache->get_gdbarch ();
 }
 
 struct address_space *
 get_regcache_aspace (const struct regcache *regcache)
 {
-  return regcache->aspace;
+  return regcache->aspace ();
 }
 
 /* Return  a pointer to register REGNUM's buffer cache.  */
 
-static gdb_byte *
-register_buffer (const struct regcache *regcache, int regnum)
+gdb_byte *
+regcache::register_buffer (int regnum) const
 {
-  return regcache->registers + regcache->descr->register_offset[regnum];
+  return m_registers + m_descr->register_offset[regnum];
 }
 
 void
-regcache_save (struct regcache *dst, regcache_cooked_read_ftype *cooked_read,
-	       void *src)
+regcache_save (struct regcache *regcache,
+	       regcache_cooked_read_ftype *cooked_read, void *src)
 {
-  struct gdbarch *gdbarch = dst->descr->gdbarch;
+  regcache->save (cooked_read, src);
+}
+
+void
+regcache::save (regcache_cooked_read_ftype *cooked_read,
+		void *src)
+{
+  struct gdbarch *gdbarch = m_descr->gdbarch;
   gdb_byte buf[MAX_REGISTER_SIZE];
   int regnum;
 
   /* The DST should be `read-only', if it wasn't then the save would
      end up trying to write the register values back out to the
      target.  */
-  gdb_assert (dst->readonly_p);
+  gdb_assert (m_readonly_p);
   /* Clear the dest.  */
-  memset (dst->registers, 0, dst->descr->sizeof_cooked_registers);
-  memset (dst->register_status, 0,
-	  dst->descr->sizeof_cooked_register_status);
+  memset (m_registers, 0, m_descr->sizeof_cooked_registers);
+  memset (m_register_status, 0, m_descr->sizeof_cooked_register_status);
   /* Copy over any registers (identified by their membership in the
      save_reggroup) and mark them as valid.  The full [0 .. gdbarch_num_regs +
      gdbarch_num_pseudo_regs) range is checked since some architectures need
      to save/restore `cooked' registers that live in memory.  */
-  for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++)
+  for (regnum = 0; regnum < m_descr->nr_cooked_registers; regnum++)
     {
       if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
 	{
 	  enum register_status status = cooked_read (src, regnum, buf);
 
 	  if (status == REG_VALID)
-	    memcpy (register_buffer (dst, regnum), buf,
+	    memcpy (register_buffer (regnum), buf,
 		    register_size (gdbarch, regnum));
 	  else
 	    {
 	      gdb_assert (status != REG_UNKNOWN);
 
-	      memset (register_buffer (dst, regnum), 0,
+	      memset (register_buffer (regnum), 0,
 		      register_size (gdbarch, regnum));
 	    }
-	  dst->register_status[regnum] = status;
+	  m_register_status[regnum] = status;
 	}
     }
 }
 
-static void
-regcache_restore (struct regcache *dst, struct regcache *src)
+void
+regcache::restore (struct regcache *src)
 {
-  struct gdbarch *gdbarch = dst->descr->gdbarch;
+  struct gdbarch *gdbarch = m_descr->gdbarch;
   int regnum;
 
   /* The dst had better not be read-only.  If it is, the `restore'
      doesn't make much sense.  */
-  gdb_assert (!dst->readonly_p);
-  gdb_assert (src->readonly_p);
+  gdb_assert (!m_readonly_p);
+  gdb_assert (src->m_readonly_p);
   /* Copy over any registers, being careful to only restore those that
      were both saved and need to be restored.  The full [0 .. gdbarch_num_regs
      + gdbarch_num_pseudo_regs) range is checked since some architectures need
      to save/restore `cooked' registers that live in memory.  */
-  for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++)
+  for (regnum = 0; regnum < m_descr->nr_cooked_registers; regnum++)
     {
       if (gdbarch_register_reggroup_p (gdbarch, regnum, restore_reggroup))
 	{
-	  if (src->register_status[regnum] == REG_VALID)
-	    regcache_cooked_write (dst, regnum, register_buffer (src, regnum));
+	  if (src->m_register_status[regnum] == REG_VALID)
+	    cooked_write (regnum, src->register_buffer (regnum));
 	}
     }
 }
@@ -410,23 +379,20 @@ do_cooked_read (void *src, int regnum, gdb_byte *buf)
   return regcache_cooked_read (regcache, regnum, buf);
 }
 
-static void regcache_cpy_no_passthrough (struct regcache *dst,
-					 struct regcache *src);
-
 void
 regcache_cpy (struct regcache *dst, struct regcache *src)
 {
   gdb_assert (src != NULL && dst != NULL);
-  gdb_assert (src->descr->gdbarch == dst->descr->gdbarch);
+  gdb_assert (src->m_descr->gdbarch == dst->m_descr->gdbarch);
   gdb_assert (src != dst);
-  gdb_assert (src->readonly_p || dst->readonly_p);
+  gdb_assert (src->m_readonly_p || dst->m_readonly_p);
 
-  if (!src->readonly_p)
+  if (!src->m_readonly_p)
     regcache_save (dst, do_cooked_read, src);
-  else if (!dst->readonly_p)
-    regcache_restore (dst, src);
+  else if (!dst->m_readonly_p)
+    dst->restore (src);
   else
-    regcache_cpy_no_passthrough (dst, src);
+    dst->cpy_no_passthrough (src);
 }
 
 /* Copy/duplicate the contents of a register cache.  Unlike regcache_cpy,
@@ -434,21 +400,21 @@ regcache_cpy (struct regcache *dst, struct regcache *src)
    Only values values already in the cache are transferred.  The SRC and DST
    buffers must not overlap.  */
 
-static void
-regcache_cpy_no_passthrough (struct regcache *dst, struct regcache *src)
+void
+regcache::cpy_no_passthrough (struct regcache *src)
 {
-  gdb_assert (src != NULL && dst != NULL);
-  gdb_assert (src->descr->gdbarch == dst->descr->gdbarch);
+  gdb_assert (src != NULL);
+  gdb_assert (src->m_descr->gdbarch == m_descr->gdbarch);
   /* NOTE: cagney/2002-05-17: Don't let the caller do a no-passthrough
      move of data into a thread's regcache.  Doing this would be silly
      - it would mean that regcache->register_status would be
      completely invalid.  */
-  gdb_assert (dst->readonly_p && src->readonly_p);
+  gdb_assert (m_readonly_p && src->m_readonly_p);
 
-  memcpy (dst->registers, src->registers,
-	  dst->descr->sizeof_cooked_registers);
-  memcpy (dst->register_status, src->register_status,
-	  dst->descr->sizeof_cooked_register_status);
+  memcpy (m_registers, src->m_registers,
+	  m_descr->sizeof_cooked_registers);
+  memcpy (m_register_status, src->m_register_status,
+	  m_descr->sizeof_cooked_register_status);
 }
 
 struct regcache *
@@ -456,7 +422,7 @@ regcache_dup (struct regcache *src)
 {
   struct regcache *newbuf;
 
-  newbuf = regcache_xmalloc (src->descr->gdbarch, get_regcache_aspace (src));
+  newbuf = regcache_xmalloc (src->get_gdbarch (), get_regcache_aspace (src));
   regcache_cpy (newbuf, src);
   return newbuf;
 }
@@ -465,25 +431,36 @@ enum register_status
 regcache_register_status (const struct regcache *regcache, int regnum)
 {
   gdb_assert (regcache != NULL);
+  return regcache->get_register_status (regnum);
+}
+
+enum register_status
+regcache::get_register_status (int regnum) const
+{
   gdb_assert (regnum >= 0);
-  if (regcache->readonly_p)
-    gdb_assert (regnum < regcache->descr->nr_cooked_registers);
+  if (m_readonly_p)
+    gdb_assert (regnum < m_descr->nr_cooked_registers);
   else
-    gdb_assert (regnum < regcache->descr->nr_raw_registers);
+    gdb_assert (regnum < m_descr->nr_raw_registers);
 
-  return (enum register_status) regcache->register_status[regnum];
+  return (enum register_status) m_register_status[regnum];
 }
 
 void
 regcache_invalidate (struct regcache *regcache, int regnum)
 {
   gdb_assert (regcache != NULL);
-  gdb_assert (regnum >= 0);
-  gdb_assert (!regcache->readonly_p);
-  gdb_assert (regnum < regcache->descr->nr_raw_registers);
-  regcache->register_status[regnum] = REG_UNKNOWN;
+  regcache->invalidate (regnum);
 }
 
+void
+regcache::invalidate (int regnum)
+{
+  gdb_assert (regnum >= 0);
+  gdb_assert (!m_readonly_p);
+  gdb_assert (regnum < m_descr->nr_raw_registers);
+  m_register_status[regnum] = REG_UNKNOWN;
+}
 
 /* Global structure containing the current regcache.  */
 
@@ -508,12 +485,12 @@ get_thread_arch_aspace_regcache (ptid_t ptid, struct gdbarch *gdbarch,
   struct regcache *new_regcache;
 
   for (list = current_regcache; list; list = list->next)
-    if (ptid_equal (list->regcache->ptid, ptid)
+    if (ptid_equal (list->regcache->ptid (), ptid)
 	&& get_regcache_arch (list->regcache) == gdbarch)
       return list->regcache;
 
   new_regcache = new regcache (gdbarch, aspace, false);
-  new_regcache->ptid = ptid;
+  new_regcache->set_ptid (ptid);
 
   list = XNEW (struct regcache_list);
   list->regcache = new_regcache;
@@ -586,8 +563,8 @@ regcache_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid)
   struct regcache_list *list;
 
   for (list = current_regcache; list; list = list->next)
-    if (ptid_equal (list->regcache->ptid, old_ptid))
-      list->regcache->ptid = new_ptid;
+    if (ptid_equal (list->regcache->ptid (), old_ptid))
+      list->regcache->set_ptid (new_ptid);
 }
 
 /* Low level examining and depositing of registers.
@@ -610,7 +587,7 @@ registers_changed_ptid (ptid_t ptid)
   list_link = &current_regcache;
   while (list)
     {
-      if (ptid_match (list->regcache->ptid, ptid))
+      if (ptid_match (list->regcache->ptid (), ptid))
 	{
 	  struct regcache_list *dead = list;
 
@@ -656,55 +633,73 @@ void
 regcache_raw_update (struct regcache *regcache, int regnum)
 {
   gdb_assert (regcache != NULL);
-  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
+
+  regcache->raw_update (regnum);
+}
+
+void
+regcache::raw_update (int regnum)
+{
+  gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
 
   /* Make certain that the register cache is up-to-date with respect
      to the current thread.  This switching shouldn't be necessary
      only there is still only one target side register cache.  Sigh!
      On the bright side, at least there is a regcache object.  */
 
-  if (!regcache->readonly_p
-      && regcache_register_status (regcache, regnum) == REG_UNKNOWN)
+  if (!m_readonly_p && get_register_status (regnum) == REG_UNKNOWN)
     {
-      target_fetch_registers (regcache, regnum);
+      target_fetch_registers (this, regnum);
 
       /* A number of targets can't access the whole set of raw
 	 registers (because the debug API provides no means to get at
 	 them).  */
-      if (regcache->register_status[regnum] == REG_UNKNOWN)
-	regcache->register_status[regnum] = REG_UNAVAILABLE;
+      if (m_register_status[regnum] == REG_UNKNOWN)
+	m_register_status[regnum] = REG_UNAVAILABLE;
     }
 }
 
 enum register_status
 regcache_raw_read (struct regcache *regcache, int regnum, gdb_byte *buf)
 {
+  return regcache->raw_read (regnum, buf);
+}
+
+enum register_status
+regcache::raw_read (int regnum, gdb_byte *buf)
+{
   gdb_assert (buf != NULL);
-  regcache_raw_update (regcache, regnum);
+  raw_update (regnum);
 
-  if (regcache->register_status[regnum] != REG_VALID)
-    memset (buf, 0, regcache->descr->sizeof_register[regnum]);
+  if (m_register_status[regnum] != REG_VALID)
+    memset (buf, 0, m_descr->sizeof_register[regnum]);
   else
-    memcpy (buf, register_buffer (regcache, regnum),
-	    regcache->descr->sizeof_register[regnum]);
+    memcpy (buf, register_buffer (regnum),
+	    m_descr->sizeof_register[regnum]);
 
-  return (enum register_status) regcache->register_status[regnum];
+  return (enum register_status) m_register_status[regnum];
 }
 
 enum register_status
 regcache_raw_read_signed (struct regcache *regcache, int regnum, LONGEST *val)
 {
+  gdb_assert (regcache != NULL);
+  return regcache->raw_read_signed (regnum, val);
+}
+
+enum register_status
+regcache::raw_read_signed (int regnum, LONGEST *val)
+{
   gdb_byte *buf;
   enum register_status status;
 
-  gdb_assert (regcache != NULL);
-  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
-  buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]);
-  status = regcache_raw_read (regcache, regnum, buf);
+  gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
+  buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
+  status = raw_read (regnum, buf);
   if (status == REG_VALID)
     *val = extract_signed_integer
-      (buf, regcache->descr->sizeof_register[regnum],
-       gdbarch_byte_order (regcache->descr->gdbarch));
+      (buf, m_descr->sizeof_register[regnum],
+       gdbarch_byte_order (m_descr->gdbarch));
   else
     *val = 0;
   return status;
@@ -714,17 +709,24 @@ enum register_status
 regcache_raw_read_unsigned (struct regcache *regcache, int regnum,
 			    ULONGEST *val)
 {
+  gdb_assert (regcache != NULL);
+  return regcache->raw_read_unsigned (regnum, val);
+}
+
+
+enum register_status
+regcache::raw_read_unsigned (int regnum, ULONGEST *val)
+{
   gdb_byte *buf;
   enum register_status status;
 
-  gdb_assert (regcache != NULL);
-  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
-  buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]);
-  status = regcache_raw_read (regcache, regnum, buf);
+  gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
+  buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
+  status = raw_read (regnum, buf);
   if (status == REG_VALID)
     *val = extract_unsigned_integer
-      (buf, regcache->descr->sizeof_register[regnum],
-       gdbarch_byte_order (regcache->descr->gdbarch));
+      (buf, m_descr->sizeof_register[regnum],
+       gdbarch_byte_order (m_descr->gdbarch));
   else
     *val = 0;
   return status;
@@ -733,28 +735,40 @@ regcache_raw_read_unsigned (struct regcache *regcache, int regnum,
 void
 regcache_raw_write_signed (struct regcache *regcache, int regnum, LONGEST val)
 {
+  gdb_assert (regcache != NULL);
+  regcache->raw_write_signed (regnum, val);
+}
+
+void
+regcache::raw_write_signed (int regnum, LONGEST val)
+{
   gdb_byte *buf;
 
-  gdb_assert (regcache != NULL);
-  gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers);
-  buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]);
-  store_signed_integer (buf, regcache->descr->sizeof_register[regnum],
-			gdbarch_byte_order (regcache->descr->gdbarch), val);
-  regcache_raw_write (regcache, regnum, buf);
+  gdb_assert (regnum >=0 && regnum < m_descr->nr_raw_registers);
+  buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
+  store_signed_integer (buf, m_descr->sizeof_register[regnum],
+			gdbarch_byte_order (m_descr->gdbarch), val);
+  raw_write (regnum, buf);
 }
 
 void
 regcache_raw_write_unsigned (struct regcache *regcache, int regnum,
 			     ULONGEST val)
 {
+  gdb_assert (regcache != NULL);
+  regcache->raw_write_unsigned (regnum, val);
+}
+
+void
+regcache::raw_write_unsigned (int regnum, ULONGEST val)
+{
   gdb_byte *buf;
 
-  gdb_assert (regcache != NULL);
-  gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers);
-  buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]);
-  store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum],
-			  gdbarch_byte_order (regcache->descr->gdbarch), val);
-  regcache_raw_write (regcache, regnum, buf);
+  gdb_assert (regnum >=0 && regnum < m_descr->nr_raw_registers);
+  buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
+  store_unsigned_integer (buf, m_descr->sizeof_register[regnum],
+			  gdbarch_byte_order (m_descr->gdbarch), val);
+  raw_write (regnum, buf);
 }
 
 LONGEST
@@ -773,38 +787,44 @@ regcache_raw_get_signed (struct regcache *regcache, int regnum)
 enum register_status
 regcache_cooked_read (struct regcache *regcache, int regnum, gdb_byte *buf)
 {
+  return regcache->cooked_read (regnum, buf);
+}
+
+enum register_status
+regcache::cooked_read (int regnum, gdb_byte *buf)
+{
   gdb_assert (regnum >= 0);
-  gdb_assert (regnum < regcache->descr->nr_cooked_registers);
-  if (regnum < regcache->descr->nr_raw_registers)
-    return regcache_raw_read (regcache, regnum, buf);
-  else if (regcache->readonly_p
-	   && regcache->register_status[regnum] != REG_UNKNOWN)
+  gdb_assert (regnum < m_descr->nr_cooked_registers);
+  if (regnum < m_descr->nr_raw_registers)
+    return raw_read (regnum, buf);
+  else if (m_readonly_p
+	   && m_register_status[regnum] != REG_UNKNOWN)
     {
       /* Read-only register cache, perhaps the cooked value was
 	 cached?  */
-      if (regcache->register_status[regnum] == REG_VALID)
-	memcpy (buf, register_buffer (regcache, regnum),
-		regcache->descr->sizeof_register[regnum]);
+      if (m_register_status[regnum] == REG_VALID)
+	memcpy (buf, register_buffer (regnum),
+		m_descr->sizeof_register[regnum]);
       else
-	memset (buf, 0, regcache->descr->sizeof_register[regnum]);
+	memset (buf, 0, m_descr->sizeof_register[regnum]);
 
-      return (enum register_status) regcache->register_status[regnum];
+      return (enum register_status) m_register_status[regnum];
     }
-  else if (gdbarch_pseudo_register_read_value_p (regcache->descr->gdbarch))
+  else if (gdbarch_pseudo_register_read_value_p (m_descr->gdbarch))
     {
       struct value *mark, *computed;
       enum register_status result = REG_VALID;
 
       mark = value_mark ();
 
-      computed = gdbarch_pseudo_register_read_value (regcache->descr->gdbarch,
-						     regcache, regnum);
+      computed = gdbarch_pseudo_register_read_value (m_descr->gdbarch,
+						     this, regnum);
       if (value_entirely_available (computed))
 	memcpy (buf, value_contents_raw (computed),
-		regcache->descr->sizeof_register[regnum]);
+		m_descr->sizeof_register[regnum]);
       else
 	{
-	  memset (buf, 0, regcache->descr->sizeof_register[regnum]);
+	  memset (buf, 0, m_descr->sizeof_register[regnum]);
 	  result = REG_UNAVAILABLE;
 	}
 
@@ -813,58 +833,68 @@ regcache_cooked_read (struct regcache *regcache, int regnum, gdb_byte *buf)
       return result;
     }
   else
-    return gdbarch_pseudo_register_read (regcache->descr->gdbarch, regcache,
+    return gdbarch_pseudo_register_read (m_descr->gdbarch, this,
 					 regnum, buf);
 }
 
 struct value *
 regcache_cooked_read_value (struct regcache *regcache, int regnum)
 {
+  return regcache->cooked_read_value (regnum);
+}
+
+struct value *
+regcache::cooked_read_value (int regnum)
+{
   gdb_assert (regnum >= 0);
-  gdb_assert (regnum < regcache->descr->nr_cooked_registers);
+  gdb_assert (regnum < m_descr->nr_cooked_registers);
 
-  if (regnum < regcache->descr->nr_raw_registers
-      || (regcache->readonly_p
-	  && regcache->register_status[regnum] != REG_UNKNOWN)
-      || !gdbarch_pseudo_register_read_value_p (regcache->descr->gdbarch))
+  if (regnum < m_descr->nr_raw_registers
+      || (m_readonly_p && m_register_status[regnum] != REG_UNKNOWN)
+      || !gdbarch_pseudo_register_read_value_p (m_descr->gdbarch))
     {
       struct value *result;
 
-      result = allocate_value (register_type (regcache->descr->gdbarch,
-					      regnum));
+      result = allocate_value (register_type (m_descr->gdbarch, regnum));
       VALUE_LVAL (result) = lval_register;
       VALUE_REGNUM (result) = regnum;
 
       /* It is more efficient in general to do this delegation in this
 	 direction than in the other one, even though the value-based
 	 API is preferred.  */
-      if (regcache_cooked_read (regcache, regnum,
-				value_contents_raw (result)) == REG_UNAVAILABLE)
+      if (cooked_read (regnum,
+		       value_contents_raw (result)) == REG_UNAVAILABLE)
 	mark_value_bytes_unavailable (result, 0,
 				      TYPE_LENGTH (value_type (result)));
 
       return result;
     }
   else
-    return gdbarch_pseudo_register_read_value (regcache->descr->gdbarch,
-					       regcache, regnum);
+    return gdbarch_pseudo_register_read_value (m_descr->gdbarch,
+					       this, regnum);
 }
 
 enum register_status
 regcache_cooked_read_signed (struct regcache *regcache, int regnum,
 			     LONGEST *val)
 {
+  gdb_assert (regcache != NULL);
+  return regcache->cooked_read_signed (regnum, val);
+}
+
+enum register_status
+regcache::cooked_read_signed (int regnum, LONGEST *val)
+{
   enum register_status status;
   gdb_byte *buf;
 
-  gdb_assert (regcache != NULL);
-  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers);
-  buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]);
-  status = regcache_cooked_read (regcache, regnum, buf);
+  gdb_assert (regnum >= 0 && regnum < m_descr->nr_cooked_registers);
+  buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
+  status = cooked_read (regnum, buf);
   if (status == REG_VALID)
     *val = extract_signed_integer
-      (buf, regcache->descr->sizeof_register[regnum],
-       gdbarch_byte_order (regcache->descr->gdbarch));
+      (buf, m_descr->sizeof_register[regnum],
+       gdbarch_byte_order (m_descr->gdbarch));
   else
     *val = 0;
   return status;
@@ -874,17 +904,23 @@ enum register_status
 regcache_cooked_read_unsigned (struct regcache *regcache, int regnum,
 			       ULONGEST *val)
 {
+  gdb_assert (regcache != NULL);
+  return regcache->cooked_read_unsigned (regnum, val);
+}
+
+enum register_status
+regcache::cooked_read_unsigned (int regnum, ULONGEST *val)
+{
   enum register_status status;
   gdb_byte *buf;
 
-  gdb_assert (regcache != NULL);
-  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers);
-  buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]);
-  status = regcache_cooked_read (regcache, regnum, buf);
+  gdb_assert (regnum >= 0 && regnum < m_descr->nr_cooked_registers);
+  buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
+  status = cooked_read (regnum, buf);
   if (status == REG_VALID)
     *val = extract_unsigned_integer
-      (buf, regcache->descr->sizeof_register[regnum],
-       gdbarch_byte_order (regcache->descr->gdbarch));
+      (buf, m_descr->sizeof_register[regnum],
+       gdbarch_byte_order (m_descr->gdbarch));
   else
     *val = 0;
   return status;
@@ -894,28 +930,40 @@ void
 regcache_cooked_write_signed (struct regcache *regcache, int regnum,
 			      LONGEST val)
 {
+  gdb_assert (regcache != NULL);
+  regcache->cooked_write_signed (regnum, val);
+}
+
+void
+regcache::cooked_write_signed (int regnum, LONGEST val)
+{
   gdb_byte *buf;
 
-  gdb_assert (regcache != NULL);
-  gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers);
-  buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]);
-  store_signed_integer (buf, regcache->descr->sizeof_register[regnum],
-			gdbarch_byte_order (regcache->descr->gdbarch), val);
-  regcache_cooked_write (regcache, regnum, buf);
+  gdb_assert (regnum >=0 && regnum < m_descr->nr_cooked_registers);
+  buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
+  store_signed_integer (buf, m_descr->sizeof_register[regnum],
+			gdbarch_byte_order (m_descr->gdbarch), val);
+  cooked_write (regnum, buf);
 }
 
 void
 regcache_cooked_write_unsigned (struct regcache *regcache, int regnum,
 				ULONGEST val)
 {
+  gdb_assert (regcache != NULL);
+  regcache->cooked_write_unsigned (regnum, val);
+}
+
+void
+regcache::cooked_write_unsigned (int regnum, ULONGEST val)
+{
   gdb_byte *buf;
 
-  gdb_assert (regcache != NULL);
-  gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers);
-  buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]);
-  store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum],
-			  gdbarch_byte_order (regcache->descr->gdbarch), val);
-  regcache_cooked_write (regcache, regnum, buf);
+  gdb_assert (regnum >=0 && regnum < m_descr->nr_cooked_registers);
+  buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
+  store_unsigned_integer (buf, m_descr->sizeof_register[regnum],
+			  gdbarch_byte_order (m_descr->gdbarch), val);
+  cooked_write (regnum, buf);
 }
 
 /* See regcache.h.  */
@@ -924,41 +972,54 @@ void
 regcache_raw_set_cached_value (struct regcache *regcache, int regnum,
 			       const gdb_byte *buf)
 {
-  memcpy (register_buffer (regcache, regnum), buf,
-	  regcache->descr->sizeof_register[regnum]);
-  regcache->register_status[regnum] = REG_VALID;
+  regcache->raw_set_cached_value (regnum, buf);
+}
+
+void
+regcache::raw_set_cached_value (int regnum, const gdb_byte *buf)
+{
+  memcpy (register_buffer (regnum), buf,
+	  m_descr->sizeof_register[regnum]);
+  m_register_status[regnum] = REG_VALID;
 }
 
 void
 regcache_raw_write (struct regcache *regcache, int regnum,
 		    const gdb_byte *buf)
 {
+  gdb_assert (regcache != NULL && buf != NULL);
+  regcache->raw_write (regnum, buf);
+}
+
+void
+regcache::raw_write (int regnum, const gdb_byte *buf)
+{
   struct cleanup *old_chain;
 
-  gdb_assert (regcache != NULL && buf != NULL);
-  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
-  gdb_assert (!regcache->readonly_p);
+  gdb_assert (buf != NULL);
+  gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
+  gdb_assert (!m_readonly_p);
 
   /* On the sparc, writing %g0 is a no-op, so we don't even want to
      change the registers array if something writes to this register.  */
-  if (gdbarch_cannot_store_register (get_regcache_arch (regcache), regnum))
+  if (gdbarch_cannot_store_register (get_gdbarch (), regnum))
     return;
 
   /* If we have a valid copy of the register, and new value == old
      value, then don't bother doing the actual store.  */
-  if (regcache_register_status (regcache, regnum) == REG_VALID
-      && (memcmp (register_buffer (regcache, regnum), buf,
-		  regcache->descr->sizeof_register[regnum]) == 0))
+  if (get_register_status (regnum) == REG_VALID
+      && (memcmp (register_buffer (regnum), buf,
+		  m_descr->sizeof_register[regnum]) == 0))
     return;
 
-  target_prepare_to_store (regcache);
-  regcache_raw_set_cached_value (regcache, regnum, buf);
+  target_prepare_to_store (this);
+  raw_set_cached_value (regnum, buf);
 
   /* Register a cleanup function for invalidating the register after it is
      written, in case of a failure.  */
-  old_chain = make_cleanup_regcache_invalidate (regcache, regnum);
+  old_chain = make_cleanup_regcache_invalidate (this, regnum);
 
-  target_store_registers (regcache, regnum);
+  target_store_registers (this, regnum);
 
   /* The target did not throw an error so we can discard invalidating the
      register and restore the cleanup chain to what it was.  */
@@ -969,12 +1030,18 @@ void
 regcache_cooked_write (struct regcache *regcache, int regnum,
 		       const gdb_byte *buf)
 {
+  regcache->cooked_write (regnum, buf);
+}
+
+void
+regcache::cooked_write (int regnum, const gdb_byte *buf)
+{
   gdb_assert (regnum >= 0);
-  gdb_assert (regnum < regcache->descr->nr_cooked_registers);
-  if (regnum < regcache->descr->nr_raw_registers)
-    regcache_raw_write (regcache, regnum, buf);
+  gdb_assert (regnum < m_descr->nr_cooked_registers);
+  if (regnum < m_descr->nr_raw_registers)
+    raw_write (regnum, buf);
   else
-    gdbarch_pseudo_register_write (regcache->descr->gdbarch, regcache,
+    gdbarch_pseudo_register_write (m_descr->gdbarch, this,
 				   regnum, buf);
 }
 
@@ -986,33 +1053,32 @@ typedef void (regcache_read_ftype) (struct regcache *regcache, int regnum,
 typedef void (regcache_write_ftype) (struct regcache *regcache, int regnum,
 				     const void *buf);
 
-static enum register_status
-regcache_xfer_part (struct regcache *regcache, int regnum,
-		    int offset, int len, void *in, const void *out,
-		    enum register_status (*read) (struct regcache *regcache,
-						  int regnum,
-						  gdb_byte *buf),
-		    void (*write) (struct regcache *regcache, int regnum,
-				   const gdb_byte *buf))
-{
-  struct regcache_descr *descr = regcache->descr;
-  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+enum register_status
+regcache::xfer_part (int regnum, int offset, int len, void *in,
+		     const void *out,
+		     enum register_status (*read) (struct regcache *regcache,
+						   int regnum,
+						   gdb_byte *buf),
+		     void (*write) (struct regcache *regcache, int regnum,
+				    const gdb_byte *buf))
+{
+  struct gdbarch *gdbarch = get_gdbarch ();
   gdb_byte *reg = (gdb_byte *) alloca (register_size (gdbarch, regnum));
 
-  gdb_assert (offset >= 0 && offset <= descr->sizeof_register[regnum]);
-  gdb_assert (len >= 0 && offset + len <= descr->sizeof_register[regnum]);
+  gdb_assert (offset >= 0 && offset <= m_descr->sizeof_register[regnum]);
+  gdb_assert (len >= 0 && offset + len <= m_descr->sizeof_register[regnum]);
   /* Something to do?  */
   if (offset + len == 0)
     return REG_VALID;
   /* Read (when needed) ...  */
   if (in != NULL
       || offset > 0
-      || offset + len < descr->sizeof_register[regnum])
+      || offset + len < m_descr->sizeof_register[regnum])
     {
       enum register_status status;
 
       gdb_assert (read != NULL);
-      status = read (regcache, regnum, reg);
+      status = read (this, regnum, reg);
       if (status != REG_VALID)
 	return status;
     }
@@ -1025,7 +1091,7 @@ regcache_xfer_part (struct regcache *regcache, int regnum,
   if (out != NULL)
     {
       gdb_assert (write != NULL);
-      write (regcache, regnum, reg);
+      write (this, regnum, reg);
     }
 
   return REG_VALID;
@@ -1035,44 +1101,63 @@ enum register_status
 regcache_raw_read_part (struct regcache *regcache, int regnum,
 			int offset, int len, gdb_byte *buf)
 {
-  struct regcache_descr *descr = regcache->descr;
+  return regcache->raw_read_part (regnum, offset, len, buf);
+}
 
-  gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
-  return regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
-			     regcache_raw_read, regcache_raw_write);
+enum register_status
+regcache::raw_read_part (int regnum, int offset, int len, gdb_byte *buf)
+{
+  gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
+  return xfer_part (regnum, offset, len, buf, NULL,
+		    regcache_raw_read, regcache_raw_write);
 }
 
 void
 regcache_raw_write_part (struct regcache *regcache, int regnum,
 			 int offset, int len, const gdb_byte *buf)
 {
-  struct regcache_descr *descr = regcache->descr;
+  regcache->raw_write_part (regnum, offset, len, buf);
+}
 
-  gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
-  regcache_xfer_part (regcache, regnum, offset, len, NULL, buf,
-		      regcache_raw_read, regcache_raw_write);
+void
+regcache::raw_write_part (int regnum, int offset, int len,
+			  const gdb_byte *buf)
+{
+  gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
+  xfer_part (regnum, offset, len, NULL, buf, regcache_raw_read,
+	     regcache_raw_write);
 }
 
 enum register_status
 regcache_cooked_read_part (struct regcache *regcache, int regnum,
 			   int offset, int len, gdb_byte *buf)
 {
-  struct regcache_descr *descr = regcache->descr;
+  return regcache->cooked_read_part (regnum, offset, len, buf);
+}
 
-  gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
-  return regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
-			     regcache_cooked_read, regcache_cooked_write);
+
+enum register_status
+regcache::cooked_read_part (int regnum, int offset, int len, gdb_byte *buf)
+{
+  gdb_assert (regnum >= 0 && regnum < m_descr->nr_cooked_registers);
+  return xfer_part (regnum, offset, len, buf, NULL,
+		    regcache_cooked_read, regcache_cooked_write);
 }
 
 void
 regcache_cooked_write_part (struct regcache *regcache, int regnum,
 			    int offset, int len, const gdb_byte *buf)
 {
-  struct regcache_descr *descr = regcache->descr;
+  regcache->cooked_write_part (regnum, offset, len, buf);
+}
 
-  gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
-  regcache_xfer_part (regcache, regnum, offset, len, NULL, buf,
-		      regcache_cooked_read, regcache_cooked_write);
+void
+regcache::cooked_write_part (int regnum, int offset, int len,
+			     const gdb_byte *buf)
+{
+  gdb_assert (regnum >= 0 && regnum < m_descr->nr_cooked_registers);
+  xfer_part (regnum, offset, len, NULL, buf,
+	     regcache_cooked_read, regcache_cooked_write);
 }
 
 /* Supply register REGNUM, whose contents are stored in BUF, to REGCACHE.  */
@@ -1080,20 +1165,26 @@ regcache_cooked_write_part (struct regcache *regcache, int regnum,
 void
 regcache_raw_supply (struct regcache *regcache, int regnum, const void *buf)
 {
+  gdb_assert (regcache != NULL);
+  regcache->raw_supply (regnum, buf);
+}
+
+void
+regcache::raw_supply (int regnum, const void *buf)
+{
   void *regbuf;
   size_t size;
 
-  gdb_assert (regcache != NULL);
-  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
-  gdb_assert (!regcache->readonly_p);
+  gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
+  gdb_assert (!m_readonly_p);
 
-  regbuf = register_buffer (regcache, regnum);
-  size = regcache->descr->sizeof_register[regnum];
+  regbuf = register_buffer (regnum);
+  size = m_descr->sizeof_register[regnum];
 
   if (buf)
     {
       memcpy (regbuf, buf, size);
-      regcache->register_status[regnum] = REG_VALID;
+      m_register_status[regnum] = REG_VALID;
     }
   else
     {
@@ -1101,7 +1192,7 @@ regcache_raw_supply (struct regcache *regcache, int regnum, const void *buf)
 	 in case the register value manages to escape somewhere (due
 	 to a bug, no less).  */
       memset (regbuf, 0, size);
-      regcache->register_status[regnum] = REG_UNAVAILABLE;
+      m_register_status[regnum] = REG_UNAVAILABLE;
     }
 }
 
@@ -1110,14 +1201,21 @@ regcache_raw_supply (struct regcache *regcache, int regnum, const void *buf)
 void
 regcache_raw_collect (const struct regcache *regcache, int regnum, void *buf)
 {
+  gdb_assert (regcache != NULL && buf != NULL);
+  regcache->raw_collect (regnum, buf);
+}
+
+void
+regcache::raw_collect (int regnum, void *buf) const
+{
   const void *regbuf;
   size_t size;
 
-  gdb_assert (regcache != NULL && buf != NULL);
-  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
+  gdb_assert (buf != NULL);
+  gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
 
-  regbuf = register_buffer (regcache, regnum);
-  size = regcache->descr->sizeof_register[regnum];
+  regbuf = register_buffer (regnum);
+  size = m_descr->sizeof_register[regnum];
   memcpy (buf, regbuf, size);
 }
 
@@ -1125,12 +1223,11 @@ regcache_raw_collect (const struct regcache *regcache, int regnum, void *buf)
    set to or from a buffer.  This is the main worker function for
    regcache_supply_regset and regcache_collect_regset.  */
 
-static void
-regcache_transfer_regset (const struct regset *regset,
-			  const struct regcache *regcache,
-			  struct regcache *out_regcache,
-			  int regnum, const void *in_buf,
-			  void *out_buf, size_t size)
+void
+regcache::transfer_regset (const struct regset *regset,
+			   struct regcache *out_regcache,
+			   int regnum, const void *in_buf,
+			   void *out_buf, size_t size) const
 {
   const struct regcache_map_entry *map;
   int offs = 0, count;
@@ -1143,7 +1240,7 @@ regcache_transfer_regset (const struct regset *regset,
       int slot_size = map->size;
 
       if (slot_size == 0 && regno != REGCACHE_MAP_SKIP)
-	slot_size = regcache->descr->sizeof_register[regno];
+	slot_size = m_descr->sizeof_register[regno];
 
       if (regno == REGCACHE_MAP_SKIP
 	  || (regnum != -1
@@ -1157,12 +1254,11 @@ regcache_transfer_regset (const struct regset *regset,
 	      break;
 
 	    if (out_buf)
-	      regcache_raw_collect (regcache, regno,
-				    (gdb_byte *) out_buf + offs);
+	      raw_collect (regno, (gdb_byte *) out_buf + offs);
 	    else
-	      regcache_raw_supply (out_regcache, regno, in_buf
-				   ? (const gdb_byte *) in_buf + offs
-				   : NULL);
+	      out_regcache->raw_supply (regno, in_buf
+					? (const gdb_byte *) in_buf + offs
+					: NULL);
 	  }
       else
 	{
@@ -1172,12 +1268,11 @@ regcache_transfer_regset (const struct regset *regset,
 	    return;
 
 	  if (out_buf)
-	    regcache_raw_collect (regcache, regnum,
-				  (gdb_byte *) out_buf + offs);
+	    raw_collect (regnum, (gdb_byte *) out_buf + offs);
 	  else
-	    regcache_raw_supply (out_regcache, regnum, in_buf
-				 ? (const gdb_byte *) in_buf + offs
-				 : NULL);
+	    out_regcache->raw_supply (regnum, in_buf
+				      ? (const gdb_byte *) in_buf + offs
+				      : NULL);
 	  return;
 	}
     }
@@ -1192,8 +1287,14 @@ regcache_supply_regset (const struct regset *regset,
 			struct regcache *regcache,
 			int regnum, const void *buf, size_t size)
 {
-  regcache_transfer_regset (regset, regcache, regcache, regnum,
-			    buf, NULL, size);
+  regcache->supply_regset (regset, regnum, buf, size);
+}
+
+void
+regcache::supply_regset (const struct regset *regset,
+			 int regnum, const void *buf, size_t size)
+{
+  transfer_regset (regset, this, regnum, buf, NULL, size);
 }
 
 /* Collect register REGNUM from REGCACHE to BUF, using the register
@@ -1205,8 +1306,14 @@ regcache_collect_regset (const struct regset *regset,
 			 const struct regcache *regcache,
 			 int regnum, void *buf, size_t size)
 {
-  regcache_transfer_regset (regset, regcache, NULL, regnum,
-			    NULL, buf, size);
+  regcache->collect_regset (regset, regnum, buf, size);
+}
+
+void
+regcache::collect_regset (const struct regset *regset,
+			 int regnum, void *buf, size_t size) const
+{
+  transfer_regset (regset, NULL, regnum, NULL, buf, size);
 }
 
 
@@ -1259,10 +1366,9 @@ regcache_write_pc (struct regcache *regcache, CORE_ADDR pc)
 }
 
 void
-regcache_debug_print_register (const char *func, struct regcache *regcache,
-			       int regno)
+regcache::debug_print_register (const char *func,  int regno)
 {
-  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  struct gdbarch *gdbarch = get_gdbarch ();
 
   fprintf_unfiltered (gdb_stdlog, "%s ", func);
   if (regno >= 0 && regno < gdbarch_num_regs (gdbarch)
@@ -1276,7 +1382,7 @@ regcache_debug_print_register (const char *func, struct regcache *regcache,
     {
       enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
       int size = register_size (gdbarch, regno);
-      gdb_byte *buf = register_buffer (regcache, regno);
+      gdb_byte *buf = register_buffer (regno);
 
       fprintf_unfiltered (gdb_stdlog, " = ");
       for (int i = 0; i < size; i++)
@@ -1303,19 +1409,11 @@ reg_flush_command (char *command, int from_tty)
     printf_filtered (_("Register cache flushed.\n"));
 }
 
-enum regcache_dump_what
-{
-  regcache_dump_none, regcache_dump_raw,
-  regcache_dump_cooked, regcache_dump_groups,
-  regcache_dump_remote
-};
-
-static void
-regcache_dump (struct regcache *regcache, struct ui_file *file,
-	       enum regcache_dump_what what_to_dump)
+void
+regcache::dump (ui_file *file, enum regcache_dump_what what_to_dump)
 {
   struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
-  struct gdbarch *gdbarch = regcache->descr->gdbarch;
+  struct gdbarch *gdbarch = m_descr->gdbarch;
   int regnum;
   int footnote_nr = 0;
   int footnote_register_size = 0;
@@ -1326,24 +1424,24 @@ regcache_dump (struct regcache *regcache, struct ui_file *file,
 
 #if 0
   fprintf_unfiltered (file, "nr_raw_registers %d\n",
-		      regcache->descr->nr_raw_registers);
+		      m_descr->nr_raw_registers);
   fprintf_unfiltered (file, "nr_cooked_registers %d\n",
-		      regcache->descr->nr_cooked_registers);
+		      m_descr->nr_cooked_registers);
   fprintf_unfiltered (file, "sizeof_raw_registers %ld\n",
-		      regcache->descr->sizeof_raw_registers);
+		      m_descr->sizeof_raw_registers);
   fprintf_unfiltered (file, "sizeof_raw_register_status %ld\n",
-		      regcache->descr->sizeof_raw_register_status);
+		      m_descr->sizeof_raw_register_status);
   fprintf_unfiltered (file, "gdbarch_num_regs %d\n", 
 		      gdbarch_num_regs (gdbarch));
   fprintf_unfiltered (file, "gdbarch_num_pseudo_regs %d\n",
 		      gdbarch_num_pseudo_regs (gdbarch));
 #endif
 
-  gdb_assert (regcache->descr->nr_cooked_registers
+  gdb_assert (m_descr->nr_cooked_registers
 	      == (gdbarch_num_regs (gdbarch)
 		  + gdbarch_num_pseudo_regs (gdbarch)));
 
-  for (regnum = -1; regnum < regcache->descr->nr_cooked_registers; regnum++)
+  for (regnum = -1; regnum < m_descr->nr_cooked_registers; regnum++)
     {
       /* Name.  */
       if (regnum < 0)
@@ -1380,12 +1478,12 @@ regcache_dump (struct regcache *regcache, struct ui_file *file,
       else
 	{
 	  fprintf_unfiltered (file, " %6ld",
-			      regcache->descr->register_offset[regnum]);
-	  if (register_offset != regcache->descr->register_offset[regnum]
+			      m_descr->register_offset[regnum]);
+	  if (register_offset != m_descr->register_offset[regnum]
 	      || (regnum > 0
-		  && (regcache->descr->register_offset[regnum]
-		      != (regcache->descr->register_offset[regnum - 1]
-			  + regcache->descr->sizeof_register[regnum - 1])))
+		  && (m_descr->register_offset[regnum]
+		      != (m_descr->register_offset[regnum - 1]
+			  + m_descr->sizeof_register[regnum - 1])))
 	      )
 	    {
 	      if (!footnote_register_offset)
@@ -1394,16 +1492,15 @@ regcache_dump (struct regcache *regcache, struct ui_file *file,
 	    }
 	  else
 	    fprintf_unfiltered (file, "  ");
-	  register_offset = (regcache->descr->register_offset[regnum]
-			     + regcache->descr->sizeof_register[regnum]);
+	  register_offset = (m_descr->register_offset[regnum]
+			     + m_descr->sizeof_register[regnum]);
 	}
 
       /* Size.  */
       if (regnum < 0)
 	fprintf_unfiltered (file, " %5s ", "Size");
       else
-	fprintf_unfiltered (file, " %5ld",
-			    regcache->descr->sizeof_register[regnum]);
+	fprintf_unfiltered (file, " %5ld", m_descr->sizeof_register[regnum]);
 
       /* Type.  */
       {
@@ -1415,7 +1512,7 @@ regcache_dump (struct regcache *regcache, struct ui_file *file,
 	  {
 	    static const char blt[] = "builtin_type";
 
-	    t = TYPE_NAME (register_type (regcache->descr->gdbarch, regnum));
+	    t = TYPE_NAME (register_type (get_gdbarch (), regnum));
 	    if (t == NULL)
 	      {
 		char *n;
@@ -1441,17 +1538,17 @@ regcache_dump (struct regcache *regcache, struct ui_file *file,
 	{
 	  if (regnum < 0)
 	    fprintf_unfiltered (file, "Raw value");
-	  else if (regnum >= regcache->descr->nr_raw_registers)
+	  else if (regnum >= m_descr->nr_raw_registers)
 	    fprintf_unfiltered (file, "<cooked>");
-	  else if (regcache_register_status (regcache, regnum) == REG_UNKNOWN)
+	  else if (get_register_status (regnum) == REG_UNKNOWN)
 	    fprintf_unfiltered (file, "<invalid>");
-	  else if (regcache_register_status (regcache, regnum) == REG_UNAVAILABLE)
+	  else if (get_register_status (regnum) == REG_UNAVAILABLE)
 	    fprintf_unfiltered (file, "<unavailable>");
 	  else
 	    {
-	      regcache_raw_read (regcache, regnum, buf);
+	      raw_read (regnum, buf);
 	      print_hex_chars (file, buf,
-			       regcache->descr->sizeof_register[regnum],
+			       m_descr->sizeof_register[regnum],
 			       gdbarch_byte_order (gdbarch));
 	    }
 	}
@@ -1465,14 +1562,14 @@ regcache_dump (struct regcache *regcache, struct ui_file *file,
 	    {
 	      enum register_status status;
 
-	      status = regcache_cooked_read (regcache, regnum, buf);
+	      status = cooked_read (regnum, buf);
 	      if (status == REG_UNKNOWN)
 		fprintf_unfiltered (file, "<invalid>");
 	      else if (status == REG_UNAVAILABLE)
 		fprintf_unfiltered (file, "<unavailable>");
 	      else
 		print_hex_chars (file, buf,
-				 regcache->descr->sizeof_register[regnum],
+				 m_descr->sizeof_register[regnum],
 				 gdbarch_byte_order (gdbarch));
 	    }
 	}
@@ -1508,11 +1605,11 @@ regcache_dump (struct regcache *regcache, struct ui_file *file,
 	    {
 	      fprintf_unfiltered (file, "Rmt Nr  g/G Offset");
 	    }
-	  else if (regnum < regcache->descr->nr_raw_registers)
+	  else if (regnum < m_descr->nr_raw_registers)
 	    {
 	      int pnum, poffset;
 
-	      if (remote_register_number_and_offset (get_regcache_arch (regcache), regnum,
+	      if (remote_register_number_and_offset (get_gdbarch (), regnum,
 						     &pnum, &poffset))
 		fprintf_unfiltered (file, "%7d %11d", pnum, poffset);
 	    }
@@ -1538,14 +1635,14 @@ static void
 regcache_print (char *args, enum regcache_dump_what what_to_dump)
 {
   if (args == NULL)
-    regcache_dump (get_current_regcache (), gdb_stdout, what_to_dump);
+    get_current_regcache ()->dump (gdb_stdout, what_to_dump);
   else
     {
       stdio_file file;
 
       if (!file.open (args, "w"))
 	perror_with_name (_("maintenance print architecture"));
-      regcache_dump (get_current_regcache (), &file, what_to_dump);
+      get_current_regcache ()->dump (&file, what_to_dump);
     }
 }
 
diff --git a/gdb/regcache.h b/gdb/regcache.h
index 1d60fa7..992f0f1 100644
--- a/gdb/regcache.h
+++ b/gdb/regcache.h
@@ -224,6 +224,157 @@ extern void regcache_save (struct regcache *dst,
 			   regcache_cooked_read_ftype *cooked_read,
 			   void *cooked_read_context);
 
+enum regcache_dump_what
+{
+  regcache_dump_none, regcache_dump_raw,
+  regcache_dump_cooked, regcache_dump_groups,
+  regcache_dump_remote
+};
+
+/* The register cache for storing raw register values.  */
+
+class regcache
+{
+public:
+  regcache (gdbarch *gdbarch, address_space *aspace_)
+    : regcache (gdbarch, aspace_, true)
+  {}
+
+  ~regcache ()
+  {
+    xfree (m_registers);
+    xfree (m_register_status);
+  }
+
+  gdbarch *get_gdbarch () const;
+
+  address_space *aspace () const
+  {
+    return m_aspace;
+  }
+
+  void save (regcache_cooked_read_ftype *cooked_read, void *src);
+
+  enum register_status cooked_read (int regnum, gdb_byte *buf);
+  void cooked_write (int regnum, const gdb_byte *buf);
+
+  enum register_status raw_read (int regnum, gdb_byte *buf);
+  void raw_write (int regnum, const gdb_byte *buf);
+
+  enum register_status raw_read_signed (int regnum, LONGEST *val);
+
+  void raw_write_signed (int regnum, LONGEST val);
+
+  enum register_status raw_read_unsigned (int regnum, ULONGEST *val);
+
+  void raw_write_unsigned (int regnum, ULONGEST val);
+
+  struct value *cooked_read_value (int regnum);
+
+  enum register_status cooked_read_signed (int regnum, LONGEST *val);
+
+  void cooked_write_signed (int regnum, LONGEST val);
+
+  enum register_status cooked_read_unsigned (int regnum, ULONGEST *val);
+
+  void cooked_write_unsigned (int regnum, ULONGEST val);
+
+  void raw_update (int regnum);
+
+  void raw_collect (int regnum, void *buf) const;
+
+  void raw_supply (int regnum, const void *buf);
+
+  enum register_status get_register_status (int regnum) const;
+
+  void raw_set_cached_value (int regnum, const gdb_byte *buf);
+
+  void invalidate (int regnum);
+
+  enum register_status raw_read_part (int regnum, int offset, int len,
+				      gdb_byte *buf);
+
+  void raw_write_part (int regnum, int offset, int len, const gdb_byte *buf);
+
+  enum register_status cooked_read_part (int regnum, int offset, int len,
+					 gdb_byte *buf);
+
+  void cooked_write_part (int regnum, int offset, int len,
+			  const gdb_byte *buf);
+
+  void supply_regset (const struct regset *regset,
+		      int regnum, const void *buf, size_t size);
+
+
+  void collect_regset (const struct regset *regset, int regnum,
+		       void *buf, size_t size) const;
+
+  void dump (ui_file *file, enum regcache_dump_what what_to_dump);
+
+  ptid_t ptid () const
+  {
+    return m_ptid;
+  }
+
+  void set_ptid (const ptid_t ptid)
+  {
+    this->m_ptid = ptid;
+  }
+
+/* Dump the contents of a register from the register cache to the target
+   debug.  */
+  void debug_print_register (const char *func, int regno);
+
+private:
+  regcache (gdbarch *gdbarch, address_space *aspace_, bool readonly_p_);
+
+  gdb_byte *register_buffer (int regnum) const;
+
+  void restore (struct regcache *src);
+
+  void cpy_no_passthrough (struct regcache *src);
+
+  enum register_status xfer_part (int regnum, int offset, int len, void *in,
+				  const void *out,
+				  decltype (regcache_raw_read) read,
+				  decltype (regcache_raw_write) write);
+
+  void transfer_regset (const struct regset *regset,
+			struct regcache *out_regcache,
+			int regnum, const void *in_buf,
+			void *out_buf, size_t size) const;
+
+  struct regcache_descr *m_descr;
+
+  /* The address space of this register cache (for registers where it
+     makes sense, like PC or SP).  */
+  struct address_space *m_aspace;
+
+  /* The register buffers.  A read-only register cache can hold the
+     full [0 .. gdbarch_num_regs + gdbarch_num_pseudo_regs) while a read/write
+     register cache can only hold [0 .. gdbarch_num_regs).  */
+  gdb_byte *m_registers;
+  /* Register cache status.  */
+  signed char *m_register_status;
+  /* Is this a read-only cache?  A read-only cache is used for saving
+     the target's register state (e.g, across an inferior function
+     call or just before forcing a function return).  A read-only
+     cache can only be updated via the methods regcache_dup() and
+     regcache_cpy().  The actual contents are determined by the
+     reggroup_save and reggroup_restore methods.  */
+  bool m_readonly_p;
+  /* If this is a read-write cache, which thread's registers is
+     it connected to?  */
+  ptid_t m_ptid;
+
+  friend struct regcache *
+  get_thread_arch_aspace_regcache (ptid_t ptid, struct gdbarch *gdbarch,
+				   struct address_space *aspace);
+
+  friend void
+  regcache_cpy (struct regcache *dst, struct regcache *src);
+};
+
 /* Copy/duplicate the contents of a register cache.  By default, the
    operation is pass-through.  Writes to DST and reads from SRC will
    go through to the target.  See also regcache_cpy_no_passthrough.
@@ -236,10 +387,4 @@ extern void regcache_cpy (struct regcache *dest, struct regcache *src);
 extern void registers_changed (void);
 extern void registers_changed_ptid (ptid_t);
 
-/* Dump the contents of a register from the register cache to the target
-   debug.  */
-extern void regcache_debug_print_register (const char *func,
-					   struct regcache *regcache,
-					   int regno);
-
 #endif /* REGCACHE_H */
diff --git a/gdb/target.c b/gdb/target.c
index 10a5315..e526bcc 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -3552,7 +3552,7 @@ target_fetch_registers (struct regcache *regcache, int regno)
 {
   current_target.to_fetch_registers (&current_target, regcache, regno);
   if (targetdebug)
-    regcache_debug_print_register ("target_fetch_registers", regcache, regno);
+    regcache->debug_print_register ("target_fetch_registers", regno);
 }
 
 void
@@ -3564,8 +3564,7 @@ target_store_registers (struct regcache *regcache, int regno)
   current_target.to_store_registers (&current_target, regcache, regno);
   if (targetdebug)
     {
-      regcache_debug_print_register ("target_store_registers", regcache,
-				     regno);
+      regcache->debug_print_register ("target_store_registers", regno);
     }
 }
 
-- 
1.9.1

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 4/4] Remove cleanup in get_return_value
  2017-04-28 14:26 ` [PATCH 0/4 v2] Class-fy regcache in GDB Yao Qi
  2017-04-28 14:26   ` [PATCH 2/4] Simplify regcache_dup Yao Qi
  2017-04-28 14:26   ` [PATCH 1/4] Class-fy regcache Yao Qi
@ 2017-04-28 14:26   ` Yao Qi
  2017-04-28 15:05     ` Pedro Alves
  2017-04-28 14:26   ` [PATCH 3/4] Use tag dispatch regcache ctor in regcache_dup Yao Qi
  3 siblings, 1 reply; 24+ messages in thread
From: Yao Qi @ 2017-04-28 14:26 UTC (permalink / raw)
  To: gdb-patches

With regcache ctor, we can use it to create local object in
get_return_value (), so that the cleanup can be removed.

gdb:

2017-04-27  Yao Qi  <yao.qi@linaro.org>

	* infcmd.c (get_return_value): Use regcache ctor, and remove
	cleanup.
---
 gdb/infcmd.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 22b2c7a..dfdaefb 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -1604,15 +1604,9 @@ advance_command (char *arg, int from_tty)
 struct value *
 get_return_value (struct value *function, struct type *value_type)
 {
-  struct regcache *stop_regs;
-  struct gdbarch *gdbarch;
+  regcache stop_regs (regcache::readonly, *get_current_regcache ());
+  struct gdbarch *gdbarch = stop_regs.get_gdbarch ();
   struct value *value;
-  struct cleanup *cleanup;
-
-  stop_regs = regcache_dup (get_current_regcache ());
-  cleanup = make_cleanup_regcache_xfree (stop_regs);
-
-  gdbarch = get_regcache_arch (stop_regs);
 
   value_type = check_typedef (value_type);
   gdb_assert (TYPE_CODE (value_type) != TYPE_CODE_VOID);
@@ -1631,7 +1625,7 @@ get_return_value (struct value *function, struct type *value_type)
     case RETURN_VALUE_ABI_RETURNS_ADDRESS:
     case RETURN_VALUE_ABI_PRESERVES_ADDRESS:
       value = allocate_value (value_type);
-      gdbarch_return_value (gdbarch, function, value_type, stop_regs,
+      gdbarch_return_value (gdbarch, function, value_type, &stop_regs,
 			    value_contents_raw (value), NULL);
       break;
     case RETURN_VALUE_STRUCT_CONVENTION:
@@ -1641,8 +1635,6 @@ get_return_value (struct value *function, struct type *value_type)
       internal_error (__FILE__, __LINE__, _("bad switch"));
     }
 
-  do_cleanups (cleanup);
-
   return value;
 }
 
-- 
1.9.1

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 3/4] Use tag dispatch regcache ctor in regcache_dup
  2017-04-28 14:26 ` [PATCH 0/4 v2] Class-fy regcache in GDB Yao Qi
                     ` (2 preceding siblings ...)
  2017-04-28 14:26   ` [PATCH 4/4] Remove cleanup in get_return_value Yao Qi
@ 2017-04-28 14:26   ` Yao Qi
  2017-04-28 15:04     ` Pedro Alves
  3 siblings, 1 reply; 24+ messages in thread
From: Yao Qi @ 2017-04-28 14:26 UTC (permalink / raw)
  To: gdb-patches

This patch adds a tag dispatch ctor to create read-only regcache from
a write-through regcache, also this patch deletes copy ctor and
assignment operator.

gdb:

2017-04-27  Yao Qi  <yao.qi@linaro.org>
	    Pedro Alves  <palves@redhat.com>

	* regcache.c (regcache::regcache): New tag dispatch ctor.
	(do_cooked_read): Moved above.
	(regcache_dup): Use the tag dispatch ctor..
	* regcache.h (regcache): Declare ctor, delete copy ctor and
	assignment operator, remove friend regcache_dup.
---
 gdb/regcache.c | 30 ++++++++++++++++--------------
 gdb/regcache.h | 12 +++++++++---
 2 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/gdb/regcache.c b/gdb/regcache.c
index 0be5fdb..882573c 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -209,6 +209,21 @@ regcache::regcache (gdbarch *gdbarch, address_space *aspace_,
   m_ptid = minus_one_ptid;
 }
 
+static enum register_status
+do_cooked_read (void *src, int regnum, gdb_byte *buf)
+{
+  struct regcache *regcache = (struct regcache *) src;
+
+  return regcache_cooked_read (regcache, regnum, buf);
+}
+
+regcache::regcache (readonly_t, const regcache &src)
+  : regcache (src.get_gdbarch (), src.aspace (), true)
+{
+  gdb_assert (!src.m_readonly_p);
+  save (do_cooked_read, (void *) &src);
+}
+
 gdbarch *
 regcache::get_gdbarch () const
 {
@@ -371,14 +386,6 @@ regcache::restore (struct regcache *src)
     }
 }
 
-static enum register_status
-do_cooked_read (void *src, int regnum, gdb_byte *buf)
-{
-  struct regcache *regcache = (struct regcache *) src;
-
-  return regcache_cooked_read (regcache, regnum, buf);
-}
-
 void
 regcache_cpy (struct regcache *dst, struct regcache *src)
 {
@@ -420,12 +427,7 @@ regcache::cpy_no_passthrough (struct regcache *src)
 struct regcache *
 regcache_dup (struct regcache *src)
 {
-  struct regcache *newbuf;
-
-  gdb_assert (!src->readonly_p);
-  newbuf = regcache_xmalloc (src->get_gdbarch (), get_regcache_aspace (src));
-  newbuf->save (do_cooked_read, src);
-  return newbuf;
+  return new regcache (regcache::readonly, *src);
 }
 
 enum register_status
diff --git a/gdb/regcache.h b/gdb/regcache.h
index 713fd41..92defdd 100644
--- a/gdb/regcache.h
+++ b/gdb/regcache.h
@@ -240,6 +240,15 @@ public:
     : regcache (gdbarch, aspace_, true)
   {}
 
+  struct readonly_t {};
+  static constexpr readonly_t readonly {};
+
+  /* Create a readonly regcache from a non-readonly regcache.  */
+  regcache (readonly_t, const regcache &src);
+
+  regcache (const regcache &) = delete;
+  void operator= (const regcache &) = delete;
+
   ~regcache ()
   {
     xfree (m_registers);
@@ -373,9 +382,6 @@ private:
 
   friend void
   regcache_cpy (struct regcache *dst, struct regcache *src);
-
-  friend struct regcache *
-  regcache_dup (struct regcache *src);
 };
 
 /* Copy/duplicate the contents of a register cache.  By default, the
-- 
1.9.1

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 0/4 v2] Class-fy regcache in GDB
  2017-04-25 20:28 [PATCH 0/6] Class-fy regcache in GDB Yao Qi
                   ` (5 preceding siblings ...)
  2017-04-25 20:29 ` [PATCH 5/6] Use copy ctor in regcache_dup Yao Qi
@ 2017-04-28 14:26 ` Yao Qi
  2017-04-28 14:26   ` [PATCH 2/4] Simplify regcache_dup Yao Qi
                     ` (3 more replies)
  6 siblings, 4 replies; 24+ messages in thread
From: Yao Qi @ 2017-04-28 14:26 UTC (permalink / raw)
  To: gdb-patches

This patch set changes "struct regcache" to a class, that is, change all
regcache_* apis to regcache class methods.

V1 can be found https://sourceware.org/ml/gdb-patches/2017-04/msg00684.html

*** BLURB HERE ***

Yao Qi (4):
  Class-fy regcache
  Simplify regcache_dup
  Use tag dispatch regcache ctor in regcache_dup
  Remove cleanup in get_return_value

 gdb/infcmd.c   |  14 +-
 gdb/regcache.c | 774 ++++++++++++++++++++++++++++++++-------------------------
 gdb/regcache.h | 166 ++++++++++++-
 gdb/target.c   |   5 +-
 4 files changed, 602 insertions(+), 357 deletions(-)

-- 
1.9.1

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 2/4] Simplify regcache_dup
  2017-04-28 14:26 ` [PATCH 0/4 v2] Class-fy regcache in GDB Yao Qi
@ 2017-04-28 14:26   ` Yao Qi
  2017-04-28 15:03     ` Pedro Alves
  2017-04-28 14:26   ` [PATCH 1/4] Class-fy regcache Yao Qi
                     ` (2 subsequent siblings)
  3 siblings, 1 reply; 24+ messages in thread
From: Yao Qi @ 2017-04-28 14:26 UTC (permalink / raw)
  To: gdb-patches

regcache_dup, in fact, is to create a readonly regcache from a
non-readonly regcache.  This patch adds an assert that src is not
readonly.

gdb:

2017-04-25  Yao Qi  <yao.qi@linaro.org>

	* regcache.c (regcache_dup): Assert !src->readonly_p and
	call method save instead of regcache_cpy.
	* regcache.h (struct regcache): Make regcache_dup a friend.
---
 gdb/regcache.c | 3 ++-
 gdb/regcache.h | 3 +++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/gdb/regcache.c b/gdb/regcache.c
index 6c3603e..0be5fdb 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -422,8 +422,9 @@ regcache_dup (struct regcache *src)
 {
   struct regcache *newbuf;
 
+  gdb_assert (!src->readonly_p);
   newbuf = regcache_xmalloc (src->get_gdbarch (), get_regcache_aspace (src));
-  regcache_cpy (newbuf, src);
+  newbuf->save (do_cooked_read, src);
   return newbuf;
 }
 
diff --git a/gdb/regcache.h b/gdb/regcache.h
index 992f0f1..713fd41 100644
--- a/gdb/regcache.h
+++ b/gdb/regcache.h
@@ -373,6 +373,9 @@ private:
 
   friend void
   regcache_cpy (struct regcache *dst, struct regcache *src);
+
+  friend struct regcache *
+  regcache_dup (struct regcache *src);
 };
 
 /* Copy/duplicate the contents of a register cache.  By default, the
-- 
1.9.1

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 2/4] Simplify regcache_dup
  2017-04-28 14:26   ` [PATCH 2/4] Simplify regcache_dup Yao Qi
@ 2017-04-28 15:03     ` Pedro Alves
  0 siblings, 0 replies; 24+ messages in thread
From: Pedro Alves @ 2017-04-28 15:03 UTC (permalink / raw)
  To: Yao Qi, gdb-patches

On 04/28/2017 03:26 PM, Yao Qi wrote:
> regcache_dup, in fact, is to create a readonly regcache from a
> non-readonly regcache.  This patch adds an assert that src is not
> readonly.

LGTM.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 1/4] Class-fy regcache
  2017-04-28 14:26   ` [PATCH 1/4] Class-fy regcache Yao Qi
@ 2017-04-28 15:03     ` Pedro Alves
  2017-04-28 21:44       ` Yao Qi
  0 siblings, 1 reply; 24+ messages in thread
From: Pedro Alves @ 2017-04-28 15:03 UTC (permalink / raw)
  To: Yao Qi, gdb-patches

On 04/28/2017 03:26 PM, Yao Qi wrote:
> @@ -320,84 +283,90 @@ make_cleanup_regcache_invalidate (struct regcache *regcache, int regnum)
>  struct gdbarch *
>  get_regcache_arch (const struct regcache *regcache)
>  {
> -  return regcache->descr->gdbarch;
> +  return regcache->get_gdbarch ();
>  }

This "get_" oddly stayed behind.  I think you should rename
it to "arch()".  (That's what we called the equivalent 
method in struct gdb_disassembler.)

Otherwise looks good to me.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 3/4] Use tag dispatch regcache ctor in regcache_dup
  2017-04-28 14:26   ` [PATCH 3/4] Use tag dispatch regcache ctor in regcache_dup Yao Qi
@ 2017-04-28 15:04     ` Pedro Alves
  0 siblings, 0 replies; 24+ messages in thread
From: Pedro Alves @ 2017-04-28 15:04 UTC (permalink / raw)
  To: Yao Qi, gdb-patches

On 04/28/2017 03:26 PM, Yao Qi wrote:
> This patch adds a tag dispatch ctor to create read-only regcache from
> a write-through regcache, also this patch deletes copy ctor and
> assignment operator.

Thanks.  LGTM.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 4/4] Remove cleanup in get_return_value
  2017-04-28 14:26   ` [PATCH 4/4] Remove cleanup in get_return_value Yao Qi
@ 2017-04-28 15:05     ` Pedro Alves
  0 siblings, 0 replies; 24+ messages in thread
From: Pedro Alves @ 2017-04-28 15:05 UTC (permalink / raw)
  To: Yao Qi, gdb-patches

On 04/28/2017 03:26 PM, Yao Qi wrote:
> With regcache ctor, we can use it to create local object in
> get_return_value (), so that the cleanup can be removed.

LGTM.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 1/4] Class-fy regcache
  2017-04-28 15:03     ` Pedro Alves
@ 2017-04-28 21:44       ` Yao Qi
  0 siblings, 0 replies; 24+ messages in thread
From: Yao Qi @ 2017-04-28 21:44 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

Pedro Alves <palves@redhat.com> writes:

> This "get_" oddly stayed behind.  I think you should rename
> it to "arch()".  (That's what we called the equivalent 
> method in struct gdb_disassembler.)
>
> Otherwise looks good to me.

OK, renamed it.  Patches are pushed in.

-- 
Yao (齐尧)
From 156924f50d61d192944f6bbcbfe4e304719a17a9 Mon Sep 17 00:00:00 2001
From: Yao Qi <yao.qi@linaro.org>
Date: Fri, 28 Apr 2017 11:39:13 +0100
Subject: [PATCH] Class-fy regcache

This patch moves regcache declaration to regcache.h, and converts
regcache apis to member functions, for example, regcache_invalidate
is changed to regcache::invalidate.

This patch also add "m_" prefix to these private fields.

gdb:

2017-04-28  Yao Qi  <yao.qi@linaro.org>

	* regcache.c (struct regcache): Move to regcache.h
	(regcache::arch): New method.
	(regcache_get_ptid): Update.
	(get_regcache_arch): Call arch method.
	(get_regcache_aspace): Call method aspace.
	(register_buffer): Change it to method.
	(regcache_save): Change it to regcache::save.
	(regcache_restore): Likewise.
	(regcache_cpy_no_passthrough): Remove the declaration.
	(regcache_cpy): Call methods restore and cpy_no_passthrough.
	(regcache_cpy_no_passthrough): Change it to method
	cpy_no_passthrough.
	(regcache_register_status): Change it to method
	get_register_status.
	(regcache_invalidate): Change it to method invalidate.
	(regcache_thread_ptid_changed): Use methods ptid and set_ptid.
	(regcache_raw_update): Change it to method raw_update.
	(regcache_raw_read): Likewise.
	(regcache_raw_read_signed): Likewise.
	(regcache_raw_read_unsigned): Likewise.
	(regcache_raw_write_signed): Likewise.
	(regcache_raw_write_unsigned): Likewise.
	(regcache_cooked_read): Likewise.
	(regcache_cooked_read_value): Likewise.
	(regcache_cooked_read_signed): Likewise.
	(regcache_cooked_read_unsigned): Likewise.
	(regcache_cooked_write_signed): Likewise.
	(regcache_cooked_write_unsigned): Likewise.
	(regcache_raw_set_cached_value): Likewise.
	(regcache_raw_write): Likewise.
	(regcache_cooked_write): Likewise.
	(regcache_xfer_part): Likewise.
	(regcache_raw_read_part): Likewise.
	(regcache_raw_write_part): Likewise.
	(regcache_cooked_read_part): Likewise.
	(regcache_cooked_write_part): Likewise.
	(regcache_raw_supply): Likewise.
	(regcache_raw_collect): Likewise.
	(regcache_transfer_regset): Likewise.
	(regcache_supply_regset): Likewise.
	(regcache_collect_regset): Likewise.
	(regcache_debug_print_register): Likewise.
	(enum regcache_dump_what): Move it to regcache.h.
	(regcache_dump): Change it to method dump.
	* regcache.h (enum regcache_dump_what): New.
	(class regcache): New.
	* target.c (target_fetch_registers): Call method
	debug_print_register.
	(target_store_registers): Likewise.

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 24768c4..537213d 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,55 @@
+2017-04-28  Yao Qi  <yao.qi@linaro.org>
+
+	* regcache.c (struct regcache): Move to regcache.h
+	(regcache::arch): New method.
+	(regcache_get_ptid): Update.
+	(get_regcache_arch): Call arch method.
+	(get_regcache_aspace): Call method aspace.
+	(register_buffer): Change it to method.
+	(regcache_save): Change it to regcache::save.
+	(regcache_restore): Likewise.
+	(regcache_cpy_no_passthrough): Remove the declaration.
+	(regcache_cpy): Call methods restore and cpy_no_passthrough.
+	(regcache_cpy_no_passthrough): Change it to method
+	cpy_no_passthrough.
+	(regcache_register_status): Change it to method
+	get_register_status.
+	(regcache_invalidate): Change it to method invalidate.
+	(regcache_thread_ptid_changed): Use methods ptid and set_ptid.
+	(regcache_raw_update): Change it to method raw_update.
+	(regcache_raw_read): Likewise.
+	(regcache_raw_read_signed): Likewise.
+	(regcache_raw_read_unsigned): Likewise.
+	(regcache_raw_write_signed): Likewise.
+	(regcache_raw_write_unsigned): Likewise.
+	(regcache_cooked_read): Likewise.
+	(regcache_cooked_read_value): Likewise.
+	(regcache_cooked_read_signed): Likewise.
+	(regcache_cooked_read_unsigned): Likewise.
+	(regcache_cooked_write_signed): Likewise.
+	(regcache_cooked_write_unsigned): Likewise.
+	(regcache_raw_set_cached_value): Likewise.
+	(regcache_raw_write): Likewise.
+	(regcache_cooked_write): Likewise.
+	(regcache_xfer_part): Likewise.
+	(regcache_raw_read_part): Likewise.
+	(regcache_raw_write_part): Likewise.
+	(regcache_cooked_read_part): Likewise.
+	(regcache_cooked_write_part): Likewise.
+	(regcache_raw_supply): Likewise.
+	(regcache_raw_collect): Likewise.
+	(regcache_transfer_regset): Likewise.
+	(regcache_supply_regset): Likewise.
+	(regcache_collect_regset): Likewise.
+	(regcache_debug_print_register): Likewise.
+	(enum regcache_dump_what): Move it to regcache.h.
+	(regcache_dump): Change it to method dump.
+	* regcache.h (enum regcache_dump_what): New.
+	(class regcache): New.
+	* target.c (target_fetch_registers): Call method
+	debug_print_register.
+	(target_store_registers): Likewise.
+
 2017-04-28  Simon Marchi  <simon.marchi@ericsson.com>
 
 	* windows-nat.c (struct lm_info_windows): Initialize field.
diff --git a/gdb/regcache.c b/gdb/regcache.c
index 798812e..11f6a87 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -187,79 +187,42 @@ regcache_register_size (const struct regcache *regcache, int n)
   return register_size (get_regcache_arch (regcache), n);
 }
 
-/* The register cache for storing raw register values.  */
-
-struct regcache
+regcache::regcache (gdbarch *gdbarch, address_space *aspace_,
+		    bool readonly_p_)
+  : m_aspace (aspace_), m_readonly_p (readonly_p_)
 {
-public:
-  regcache (gdbarch *gdbarch, address_space *aspace_)
-    : regcache (gdbarch, aspace_, true)
-  {}
-
-  ~regcache ()
-  {
-    xfree (registers);
-    xfree (register_status);
-  }
-
-  struct regcache_descr *descr;
-
-  /* The address space of this register cache (for registers where it
-     makes sense, like PC or SP).  */
-  struct address_space *aspace;
-
-  /* The register buffers.  A read-only register cache can hold the
-     full [0 .. gdbarch_num_regs + gdbarch_num_pseudo_regs) while a read/write
-     register cache can only hold [0 .. gdbarch_num_regs).  */
-  gdb_byte *registers;
-  /* Register cache status.  */
-  signed char *register_status;
-  /* Is this a read-only cache?  A read-only cache is used for saving
-     the target's register state (e.g, across an inferior function
-     call or just before forcing a function return).  A read-only
-     cache can only be updated via the methods regcache_dup() and
-     regcache_cpy().  The actual contents are determined by the
-     reggroup_save and reggroup_restore methods.  */
-  bool readonly_p;
-  /* If this is a read-write cache, which thread's registers is
-     it connected to?  */
-  ptid_t ptid;
-
-private:
-  regcache (gdbarch *gdbarch, address_space *aspace_, bool readonly_p_)
-    : aspace (aspace_), readonly_p (readonly_p_)
-  {
-    gdb_assert (gdbarch != NULL);
-    descr = regcache_descr (gdbarch);
+  gdb_assert (gdbarch != NULL);
+  m_descr = regcache_descr (gdbarch);
 
-  if (readonly_p)
+  if (m_readonly_p)
     {
-      registers = XCNEWVEC (gdb_byte, descr->sizeof_cooked_registers);
-      register_status = XCNEWVEC (signed char,
-				  descr->sizeof_cooked_register_status);
+      m_registers = XCNEWVEC (gdb_byte, m_descr->sizeof_cooked_registers);
+      m_register_status = XCNEWVEC (signed char,
+				    m_descr->sizeof_cooked_register_status);
     }
   else
     {
-      registers = XCNEWVEC (gdb_byte, descr->sizeof_raw_registers);
-      register_status = XCNEWVEC (signed char,
-				  descr->sizeof_raw_register_status);
+      m_registers = XCNEWVEC (gdb_byte, m_descr->sizeof_raw_registers);
+      m_register_status = XCNEWVEC (signed char,
+				    m_descr->sizeof_raw_register_status);
     }
-  ptid = minus_one_ptid;
-  }
+  m_ptid = minus_one_ptid;
+}
 
-  friend regcache *
-  get_thread_arch_aspace_regcache (ptid_t ptid, gdbarch *gdbarch,
-				   address_space *aspace);
-};
+gdbarch *
+regcache::arch () const
+{
+  return m_descr->gdbarch;
+}
 
 /* See regcache.h.  */
 
 ptid_t
 regcache_get_ptid (const struct regcache *regcache)
 {
-  gdb_assert (!ptid_equal (regcache->ptid, minus_one_ptid));
+  gdb_assert (!ptid_equal (regcache->ptid (), minus_one_ptid));
 
-  return regcache->ptid;
+  return regcache->ptid ();
 }
 
 struct regcache *
@@ -320,84 +283,90 @@ make_cleanup_regcache_invalidate (struct regcache *regcache, int regnum)
 struct gdbarch *
 get_regcache_arch (const struct regcache *regcache)
 {
-  return regcache->descr->gdbarch;
+  return regcache->arch ();
 }
 
 struct address_space *
 get_regcache_aspace (const struct regcache *regcache)
 {
-  return regcache->aspace;
+  return regcache->aspace ();
 }
 
 /* Return  a pointer to register REGNUM's buffer cache.  */
 
-static gdb_byte *
-register_buffer (const struct regcache *regcache, int regnum)
+gdb_byte *
+regcache::register_buffer (int regnum) const
 {
-  return regcache->registers + regcache->descr->register_offset[regnum];
+  return m_registers + m_descr->register_offset[regnum];
 }
 
 void
-regcache_save (struct regcache *dst, regcache_cooked_read_ftype *cooked_read,
-	       void *src)
+regcache_save (struct regcache *regcache,
+	       regcache_cooked_read_ftype *cooked_read, void *src)
 {
-  struct gdbarch *gdbarch = dst->descr->gdbarch;
+  regcache->save (cooked_read, src);
+}
+
+void
+regcache::save (regcache_cooked_read_ftype *cooked_read,
+		void *src)
+{
+  struct gdbarch *gdbarch = m_descr->gdbarch;
   gdb_byte buf[MAX_REGISTER_SIZE];
   int regnum;
 
   /* The DST should be `read-only', if it wasn't then the save would
      end up trying to write the register values back out to the
      target.  */
-  gdb_assert (dst->readonly_p);
+  gdb_assert (m_readonly_p);
   /* Clear the dest.  */
-  memset (dst->registers, 0, dst->descr->sizeof_cooked_registers);
-  memset (dst->register_status, 0,
-	  dst->descr->sizeof_cooked_register_status);
+  memset (m_registers, 0, m_descr->sizeof_cooked_registers);
+  memset (m_register_status, 0, m_descr->sizeof_cooked_register_status);
   /* Copy over any registers (identified by their membership in the
      save_reggroup) and mark them as valid.  The full [0 .. gdbarch_num_regs +
      gdbarch_num_pseudo_regs) range is checked since some architectures need
      to save/restore `cooked' registers that live in memory.  */
-  for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++)
+  for (regnum = 0; regnum < m_descr->nr_cooked_registers; regnum++)
     {
       if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
 	{
 	  enum register_status status = cooked_read (src, regnum, buf);
 
 	  if (status == REG_VALID)
-	    memcpy (register_buffer (dst, regnum), buf,
+	    memcpy (register_buffer (regnum), buf,
 		    register_size (gdbarch, regnum));
 	  else
 	    {
 	      gdb_assert (status != REG_UNKNOWN);
 
-	      memset (register_buffer (dst, regnum), 0,
+	      memset (register_buffer (regnum), 0,
 		      register_size (gdbarch, regnum));
 	    }
-	  dst->register_status[regnum] = status;
+	  m_register_status[regnum] = status;
 	}
     }
 }
 
-static void
-regcache_restore (struct regcache *dst, struct regcache *src)
+void
+regcache::restore (struct regcache *src)
 {
-  struct gdbarch *gdbarch = dst->descr->gdbarch;
+  struct gdbarch *gdbarch = m_descr->gdbarch;
   int regnum;
 
   /* The dst had better not be read-only.  If it is, the `restore'
      doesn't make much sense.  */
-  gdb_assert (!dst->readonly_p);
-  gdb_assert (src->readonly_p);
+  gdb_assert (!m_readonly_p);
+  gdb_assert (src->m_readonly_p);
   /* Copy over any registers, being careful to only restore those that
      were both saved and need to be restored.  The full [0 .. gdbarch_num_regs
      + gdbarch_num_pseudo_regs) range is checked since some architectures need
      to save/restore `cooked' registers that live in memory.  */
-  for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++)
+  for (regnum = 0; regnum < m_descr->nr_cooked_registers; regnum++)
     {
       if (gdbarch_register_reggroup_p (gdbarch, regnum, restore_reggroup))
 	{
-	  if (src->register_status[regnum] == REG_VALID)
-	    regcache_cooked_write (dst, regnum, register_buffer (src, regnum));
+	  if (src->m_register_status[regnum] == REG_VALID)
+	    cooked_write (regnum, src->register_buffer (regnum));
 	}
     }
 }
@@ -410,23 +379,20 @@ do_cooked_read (void *src, int regnum, gdb_byte *buf)
   return regcache_cooked_read (regcache, regnum, buf);
 }
 
-static void regcache_cpy_no_passthrough (struct regcache *dst,
-					 struct regcache *src);
-
 void
 regcache_cpy (struct regcache *dst, struct regcache *src)
 {
   gdb_assert (src != NULL && dst != NULL);
-  gdb_assert (src->descr->gdbarch == dst->descr->gdbarch);
+  gdb_assert (src->m_descr->gdbarch == dst->m_descr->gdbarch);
   gdb_assert (src != dst);
-  gdb_assert (src->readonly_p || dst->readonly_p);
+  gdb_assert (src->m_readonly_p || dst->m_readonly_p);
 
-  if (!src->readonly_p)
+  if (!src->m_readonly_p)
     regcache_save (dst, do_cooked_read, src);
-  else if (!dst->readonly_p)
-    regcache_restore (dst, src);
+  else if (!dst->m_readonly_p)
+    dst->restore (src);
   else
-    regcache_cpy_no_passthrough (dst, src);
+    dst->cpy_no_passthrough (src);
 }
 
 /* Copy/duplicate the contents of a register cache.  Unlike regcache_cpy,
@@ -434,21 +400,21 @@ regcache_cpy (struct regcache *dst, struct regcache *src)
    Only values values already in the cache are transferred.  The SRC and DST
    buffers must not overlap.  */
 
-static void
-regcache_cpy_no_passthrough (struct regcache *dst, struct regcache *src)
+void
+regcache::cpy_no_passthrough (struct regcache *src)
 {
-  gdb_assert (src != NULL && dst != NULL);
-  gdb_assert (src->descr->gdbarch == dst->descr->gdbarch);
+  gdb_assert (src != NULL);
+  gdb_assert (src->m_descr->gdbarch == m_descr->gdbarch);
   /* NOTE: cagney/2002-05-17: Don't let the caller do a no-passthrough
      move of data into a thread's regcache.  Doing this would be silly
      - it would mean that regcache->register_status would be
      completely invalid.  */
-  gdb_assert (dst->readonly_p && src->readonly_p);
+  gdb_assert (m_readonly_p && src->m_readonly_p);
 
-  memcpy (dst->registers, src->registers,
-	  dst->descr->sizeof_cooked_registers);
-  memcpy (dst->register_status, src->register_status,
-	  dst->descr->sizeof_cooked_register_status);
+  memcpy (m_registers, src->m_registers,
+	  m_descr->sizeof_cooked_registers);
+  memcpy (m_register_status, src->m_register_status,
+	  m_descr->sizeof_cooked_register_status);
 }
 
 struct regcache *
@@ -456,7 +422,7 @@ regcache_dup (struct regcache *src)
 {
   struct regcache *newbuf;
 
-  newbuf = regcache_xmalloc (src->descr->gdbarch, get_regcache_aspace (src));
+  newbuf = regcache_xmalloc (src->arch (), get_regcache_aspace (src));
   regcache_cpy (newbuf, src);
   return newbuf;
 }
@@ -465,25 +431,36 @@ enum register_status
 regcache_register_status (const struct regcache *regcache, int regnum)
 {
   gdb_assert (regcache != NULL);
+  return regcache->get_register_status (regnum);
+}
+
+enum register_status
+regcache::get_register_status (int regnum) const
+{
   gdb_assert (regnum >= 0);
-  if (regcache->readonly_p)
-    gdb_assert (regnum < regcache->descr->nr_cooked_registers);
+  if (m_readonly_p)
+    gdb_assert (regnum < m_descr->nr_cooked_registers);
   else
-    gdb_assert (regnum < regcache->descr->nr_raw_registers);
+    gdb_assert (regnum < m_descr->nr_raw_registers);
 
-  return (enum register_status) regcache->register_status[regnum];
+  return (enum register_status) m_register_status[regnum];
 }
 
 void
 regcache_invalidate (struct regcache *regcache, int regnum)
 {
   gdb_assert (regcache != NULL);
-  gdb_assert (regnum >= 0);
-  gdb_assert (!regcache->readonly_p);
-  gdb_assert (regnum < regcache->descr->nr_raw_registers);
-  regcache->register_status[regnum] = REG_UNKNOWN;
+  regcache->invalidate (regnum);
 }
 
+void
+regcache::invalidate (int regnum)
+{
+  gdb_assert (regnum >= 0);
+  gdb_assert (!m_readonly_p);
+  gdb_assert (regnum < m_descr->nr_raw_registers);
+  m_register_status[regnum] = REG_UNKNOWN;
+}
 
 /* Global structure containing the current regcache.  */
 
@@ -508,12 +485,12 @@ get_thread_arch_aspace_regcache (ptid_t ptid, struct gdbarch *gdbarch,
   struct regcache *new_regcache;
 
   for (list = current_regcache; list; list = list->next)
-    if (ptid_equal (list->regcache->ptid, ptid)
+    if (ptid_equal (list->regcache->ptid (), ptid)
 	&& get_regcache_arch (list->regcache) == gdbarch)
       return list->regcache;
 
   new_regcache = new regcache (gdbarch, aspace, false);
-  new_regcache->ptid = ptid;
+  new_regcache->set_ptid (ptid);
 
   list = XNEW (struct regcache_list);
   list->regcache = new_regcache;
@@ -586,8 +563,8 @@ regcache_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid)
   struct regcache_list *list;
 
   for (list = current_regcache; list; list = list->next)
-    if (ptid_equal (list->regcache->ptid, old_ptid))
-      list->regcache->ptid = new_ptid;
+    if (ptid_equal (list->regcache->ptid (), old_ptid))
+      list->regcache->set_ptid (new_ptid);
 }
 
 /* Low level examining and depositing of registers.
@@ -610,7 +587,7 @@ registers_changed_ptid (ptid_t ptid)
   list_link = &current_regcache;
   while (list)
     {
-      if (ptid_match (list->regcache->ptid, ptid))
+      if (ptid_match (list->regcache->ptid (), ptid))
 	{
 	  struct regcache_list *dead = list;
 
@@ -656,55 +633,73 @@ void
 regcache_raw_update (struct regcache *regcache, int regnum)
 {
   gdb_assert (regcache != NULL);
-  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
+
+  regcache->raw_update (regnum);
+}
+
+void
+regcache::raw_update (int regnum)
+{
+  gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
 
   /* Make certain that the register cache is up-to-date with respect
      to the current thread.  This switching shouldn't be necessary
      only there is still only one target side register cache.  Sigh!
      On the bright side, at least there is a regcache object.  */
 
-  if (!regcache->readonly_p
-      && regcache_register_status (regcache, regnum) == REG_UNKNOWN)
+  if (!m_readonly_p && get_register_status (regnum) == REG_UNKNOWN)
     {
-      target_fetch_registers (regcache, regnum);
+      target_fetch_registers (this, regnum);
 
       /* A number of targets can't access the whole set of raw
 	 registers (because the debug API provides no means to get at
 	 them).  */
-      if (regcache->register_status[regnum] == REG_UNKNOWN)
-	regcache->register_status[regnum] = REG_UNAVAILABLE;
+      if (m_register_status[regnum] == REG_UNKNOWN)
+	m_register_status[regnum] = REG_UNAVAILABLE;
     }
 }
 
 enum register_status
 regcache_raw_read (struct regcache *regcache, int regnum, gdb_byte *buf)
 {
+  return regcache->raw_read (regnum, buf);
+}
+
+enum register_status
+regcache::raw_read (int regnum, gdb_byte *buf)
+{
   gdb_assert (buf != NULL);
-  regcache_raw_update (regcache, regnum);
+  raw_update (regnum);
 
-  if (regcache->register_status[regnum] != REG_VALID)
-    memset (buf, 0, regcache->descr->sizeof_register[regnum]);
+  if (m_register_status[regnum] != REG_VALID)
+    memset (buf, 0, m_descr->sizeof_register[regnum]);
   else
-    memcpy (buf, register_buffer (regcache, regnum),
-	    regcache->descr->sizeof_register[regnum]);
+    memcpy (buf, register_buffer (regnum),
+	    m_descr->sizeof_register[regnum]);
 
-  return (enum register_status) regcache->register_status[regnum];
+  return (enum register_status) m_register_status[regnum];
 }
 
 enum register_status
 regcache_raw_read_signed (struct regcache *regcache, int regnum, LONGEST *val)
 {
+  gdb_assert (regcache != NULL);
+  return regcache->raw_read_signed (regnum, val);
+}
+
+enum register_status
+regcache::raw_read_signed (int regnum, LONGEST *val)
+{
   gdb_byte *buf;
   enum register_status status;
 
-  gdb_assert (regcache != NULL);
-  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
-  buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]);
-  status = regcache_raw_read (regcache, regnum, buf);
+  gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
+  buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
+  status = raw_read (regnum, buf);
   if (status == REG_VALID)
     *val = extract_signed_integer
-      (buf, regcache->descr->sizeof_register[regnum],
-       gdbarch_byte_order (regcache->descr->gdbarch));
+      (buf, m_descr->sizeof_register[regnum],
+       gdbarch_byte_order (m_descr->gdbarch));
   else
     *val = 0;
   return status;
@@ -714,17 +709,24 @@ enum register_status
 regcache_raw_read_unsigned (struct regcache *regcache, int regnum,
 			    ULONGEST *val)
 {
+  gdb_assert (regcache != NULL);
+  return regcache->raw_read_unsigned (regnum, val);
+}
+
+
+enum register_status
+regcache::raw_read_unsigned (int regnum, ULONGEST *val)
+{
   gdb_byte *buf;
   enum register_status status;
 
-  gdb_assert (regcache != NULL);
-  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
-  buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]);
-  status = regcache_raw_read (regcache, regnum, buf);
+  gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
+  buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
+  status = raw_read (regnum, buf);
   if (status == REG_VALID)
     *val = extract_unsigned_integer
-      (buf, regcache->descr->sizeof_register[regnum],
-       gdbarch_byte_order (regcache->descr->gdbarch));
+      (buf, m_descr->sizeof_register[regnum],
+       gdbarch_byte_order (m_descr->gdbarch));
   else
     *val = 0;
   return status;
@@ -733,28 +735,40 @@ regcache_raw_read_unsigned (struct regcache *regcache, int regnum,
 void
 regcache_raw_write_signed (struct regcache *regcache, int regnum, LONGEST val)
 {
+  gdb_assert (regcache != NULL);
+  regcache->raw_write_signed (regnum, val);
+}
+
+void
+regcache::raw_write_signed (int regnum, LONGEST val)
+{
   gdb_byte *buf;
 
-  gdb_assert (regcache != NULL);
-  gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers);
-  buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]);
-  store_signed_integer (buf, regcache->descr->sizeof_register[regnum],
-			gdbarch_byte_order (regcache->descr->gdbarch), val);
-  regcache_raw_write (regcache, regnum, buf);
+  gdb_assert (regnum >=0 && regnum < m_descr->nr_raw_registers);
+  buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
+  store_signed_integer (buf, m_descr->sizeof_register[regnum],
+			gdbarch_byte_order (m_descr->gdbarch), val);
+  raw_write (regnum, buf);
 }
 
 void
 regcache_raw_write_unsigned (struct regcache *regcache, int regnum,
 			     ULONGEST val)
 {
+  gdb_assert (regcache != NULL);
+  regcache->raw_write_unsigned (regnum, val);
+}
+
+void
+regcache::raw_write_unsigned (int regnum, ULONGEST val)
+{
   gdb_byte *buf;
 
-  gdb_assert (regcache != NULL);
-  gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers);
-  buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]);
-  store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum],
-			  gdbarch_byte_order (regcache->descr->gdbarch), val);
-  regcache_raw_write (regcache, regnum, buf);
+  gdb_assert (regnum >=0 && regnum < m_descr->nr_raw_registers);
+  buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
+  store_unsigned_integer (buf, m_descr->sizeof_register[regnum],
+			  gdbarch_byte_order (m_descr->gdbarch), val);
+  raw_write (regnum, buf);
 }
 
 LONGEST
@@ -773,38 +787,44 @@ regcache_raw_get_signed (struct regcache *regcache, int regnum)
 enum register_status
 regcache_cooked_read (struct regcache *regcache, int regnum, gdb_byte *buf)
 {
+  return regcache->cooked_read (regnum, buf);
+}
+
+enum register_status
+regcache::cooked_read (int regnum, gdb_byte *buf)
+{
   gdb_assert (regnum >= 0);
-  gdb_assert (regnum < regcache->descr->nr_cooked_registers);
-  if (regnum < regcache->descr->nr_raw_registers)
-    return regcache_raw_read (regcache, regnum, buf);
-  else if (regcache->readonly_p
-	   && regcache->register_status[regnum] != REG_UNKNOWN)
+  gdb_assert (regnum < m_descr->nr_cooked_registers);
+  if (regnum < m_descr->nr_raw_registers)
+    return raw_read (regnum, buf);
+  else if (m_readonly_p
+	   && m_register_status[regnum] != REG_UNKNOWN)
     {
       /* Read-only register cache, perhaps the cooked value was
 	 cached?  */
-      if (regcache->register_status[regnum] == REG_VALID)
-	memcpy (buf, register_buffer (regcache, regnum),
-		regcache->descr->sizeof_register[regnum]);
+      if (m_register_status[regnum] == REG_VALID)
+	memcpy (buf, register_buffer (regnum),
+		m_descr->sizeof_register[regnum]);
       else
-	memset (buf, 0, regcache->descr->sizeof_register[regnum]);
+	memset (buf, 0, m_descr->sizeof_register[regnum]);
 
-      return (enum register_status) regcache->register_status[regnum];
+      return (enum register_status) m_register_status[regnum];
     }
-  else if (gdbarch_pseudo_register_read_value_p (regcache->descr->gdbarch))
+  else if (gdbarch_pseudo_register_read_value_p (m_descr->gdbarch))
     {
       struct value *mark, *computed;
       enum register_status result = REG_VALID;
 
       mark = value_mark ();
 
-      computed = gdbarch_pseudo_register_read_value (regcache->descr->gdbarch,
-						     regcache, regnum);
+      computed = gdbarch_pseudo_register_read_value (m_descr->gdbarch,
+						     this, regnum);
       if (value_entirely_available (computed))
 	memcpy (buf, value_contents_raw (computed),
-		regcache->descr->sizeof_register[regnum]);
+		m_descr->sizeof_register[regnum]);
       else
 	{
-	  memset (buf, 0, regcache->descr->sizeof_register[regnum]);
+	  memset (buf, 0, m_descr->sizeof_register[regnum]);
 	  result = REG_UNAVAILABLE;
 	}
 
@@ -813,58 +833,68 @@ regcache_cooked_read (struct regcache *regcache, int regnum, gdb_byte *buf)
       return result;
     }
   else
-    return gdbarch_pseudo_register_read (regcache->descr->gdbarch, regcache,
+    return gdbarch_pseudo_register_read (m_descr->gdbarch, this,
 					 regnum, buf);
 }
 
 struct value *
 regcache_cooked_read_value (struct regcache *regcache, int regnum)
 {
+  return regcache->cooked_read_value (regnum);
+}
+
+struct value *
+regcache::cooked_read_value (int regnum)
+{
   gdb_assert (regnum >= 0);
-  gdb_assert (regnum < regcache->descr->nr_cooked_registers);
+  gdb_assert (regnum < m_descr->nr_cooked_registers);
 
-  if (regnum < regcache->descr->nr_raw_registers
-      || (regcache->readonly_p
-	  && regcache->register_status[regnum] != REG_UNKNOWN)
-      || !gdbarch_pseudo_register_read_value_p (regcache->descr->gdbarch))
+  if (regnum < m_descr->nr_raw_registers
+      || (m_readonly_p && m_register_status[regnum] != REG_UNKNOWN)
+      || !gdbarch_pseudo_register_read_value_p (m_descr->gdbarch))
     {
       struct value *result;
 
-      result = allocate_value (register_type (regcache->descr->gdbarch,
-					      regnum));
+      result = allocate_value (register_type (m_descr->gdbarch, regnum));
       VALUE_LVAL (result) = lval_register;
       VALUE_REGNUM (result) = regnum;
 
       /* It is more efficient in general to do this delegation in this
 	 direction than in the other one, even though the value-based
 	 API is preferred.  */
-      if (regcache_cooked_read (regcache, regnum,
-				value_contents_raw (result)) == REG_UNAVAILABLE)
+      if (cooked_read (regnum,
+		       value_contents_raw (result)) == REG_UNAVAILABLE)
 	mark_value_bytes_unavailable (result, 0,
 				      TYPE_LENGTH (value_type (result)));
 
       return result;
     }
   else
-    return gdbarch_pseudo_register_read_value (regcache->descr->gdbarch,
-					       regcache, regnum);
+    return gdbarch_pseudo_register_read_value (m_descr->gdbarch,
+					       this, regnum);
 }
 
 enum register_status
 regcache_cooked_read_signed (struct regcache *regcache, int regnum,
 			     LONGEST *val)
 {
+  gdb_assert (regcache != NULL);
+  return regcache->cooked_read_signed (regnum, val);
+}
+
+enum register_status
+regcache::cooked_read_signed (int regnum, LONGEST *val)
+{
   enum register_status status;
   gdb_byte *buf;
 
-  gdb_assert (regcache != NULL);
-  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers);
-  buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]);
-  status = regcache_cooked_read (regcache, regnum, buf);
+  gdb_assert (regnum >= 0 && regnum < m_descr->nr_cooked_registers);
+  buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
+  status = cooked_read (regnum, buf);
   if (status == REG_VALID)
     *val = extract_signed_integer
-      (buf, regcache->descr->sizeof_register[regnum],
-       gdbarch_byte_order (regcache->descr->gdbarch));
+      (buf, m_descr->sizeof_register[regnum],
+       gdbarch_byte_order (m_descr->gdbarch));
   else
     *val = 0;
   return status;
@@ -874,17 +904,23 @@ enum register_status
 regcache_cooked_read_unsigned (struct regcache *regcache, int regnum,
 			       ULONGEST *val)
 {
+  gdb_assert (regcache != NULL);
+  return regcache->cooked_read_unsigned (regnum, val);
+}
+
+enum register_status
+regcache::cooked_read_unsigned (int regnum, ULONGEST *val)
+{
   enum register_status status;
   gdb_byte *buf;
 
-  gdb_assert (regcache != NULL);
-  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers);
-  buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]);
-  status = regcache_cooked_read (regcache, regnum, buf);
+  gdb_assert (regnum >= 0 && regnum < m_descr->nr_cooked_registers);
+  buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
+  status = cooked_read (regnum, buf);
   if (status == REG_VALID)
     *val = extract_unsigned_integer
-      (buf, regcache->descr->sizeof_register[regnum],
-       gdbarch_byte_order (regcache->descr->gdbarch));
+      (buf, m_descr->sizeof_register[regnum],
+       gdbarch_byte_order (m_descr->gdbarch));
   else
     *val = 0;
   return status;
@@ -894,28 +930,40 @@ void
 regcache_cooked_write_signed (struct regcache *regcache, int regnum,
 			      LONGEST val)
 {
+  gdb_assert (regcache != NULL);
+  regcache->cooked_write_signed (regnum, val);
+}
+
+void
+regcache::cooked_write_signed (int regnum, LONGEST val)
+{
   gdb_byte *buf;
 
-  gdb_assert (regcache != NULL);
-  gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers);
-  buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]);
-  store_signed_integer (buf, regcache->descr->sizeof_register[regnum],
-			gdbarch_byte_order (regcache->descr->gdbarch), val);
-  regcache_cooked_write (regcache, regnum, buf);
+  gdb_assert (regnum >=0 && regnum < m_descr->nr_cooked_registers);
+  buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
+  store_signed_integer (buf, m_descr->sizeof_register[regnum],
+			gdbarch_byte_order (m_descr->gdbarch), val);
+  cooked_write (regnum, buf);
 }
 
 void
 regcache_cooked_write_unsigned (struct regcache *regcache, int regnum,
 				ULONGEST val)
 {
+  gdb_assert (regcache != NULL);
+  regcache->cooked_write_unsigned (regnum, val);
+}
+
+void
+regcache::cooked_write_unsigned (int regnum, ULONGEST val)
+{
   gdb_byte *buf;
 
-  gdb_assert (regcache != NULL);
-  gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers);
-  buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]);
-  store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum],
-			  gdbarch_byte_order (regcache->descr->gdbarch), val);
-  regcache_cooked_write (regcache, regnum, buf);
+  gdb_assert (regnum >=0 && regnum < m_descr->nr_cooked_registers);
+  buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
+  store_unsigned_integer (buf, m_descr->sizeof_register[regnum],
+			  gdbarch_byte_order (m_descr->gdbarch), val);
+  cooked_write (regnum, buf);
 }
 
 /* See regcache.h.  */
@@ -924,41 +972,54 @@ void
 regcache_raw_set_cached_value (struct regcache *regcache, int regnum,
 			       const gdb_byte *buf)
 {
-  memcpy (register_buffer (regcache, regnum), buf,
-	  regcache->descr->sizeof_register[regnum]);
-  regcache->register_status[regnum] = REG_VALID;
+  regcache->raw_set_cached_value (regnum, buf);
+}
+
+void
+regcache::raw_set_cached_value (int regnum, const gdb_byte *buf)
+{
+  memcpy (register_buffer (regnum), buf,
+	  m_descr->sizeof_register[regnum]);
+  m_register_status[regnum] = REG_VALID;
 }
 
 void
 regcache_raw_write (struct regcache *regcache, int regnum,
 		    const gdb_byte *buf)
 {
+  gdb_assert (regcache != NULL && buf != NULL);
+  regcache->raw_write (regnum, buf);
+}
+
+void
+regcache::raw_write (int regnum, const gdb_byte *buf)
+{
   struct cleanup *old_chain;
 
-  gdb_assert (regcache != NULL && buf != NULL);
-  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
-  gdb_assert (!regcache->readonly_p);
+  gdb_assert (buf != NULL);
+  gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
+  gdb_assert (!m_readonly_p);
 
   /* On the sparc, writing %g0 is a no-op, so we don't even want to
      change the registers array if something writes to this register.  */
-  if (gdbarch_cannot_store_register (get_regcache_arch (regcache), regnum))
+  if (gdbarch_cannot_store_register (arch (), regnum))
     return;
 
   /* If we have a valid copy of the register, and new value == old
      value, then don't bother doing the actual store.  */
-  if (regcache_register_status (regcache, regnum) == REG_VALID
-      && (memcmp (register_buffer (regcache, regnum), buf,
-		  regcache->descr->sizeof_register[regnum]) == 0))
+  if (get_register_status (regnum) == REG_VALID
+      && (memcmp (register_buffer (regnum), buf,
+		  m_descr->sizeof_register[regnum]) == 0))
     return;
 
-  target_prepare_to_store (regcache);
-  regcache_raw_set_cached_value (regcache, regnum, buf);
+  target_prepare_to_store (this);
+  raw_set_cached_value (regnum, buf);
 
   /* Register a cleanup function for invalidating the register after it is
      written, in case of a failure.  */
-  old_chain = make_cleanup_regcache_invalidate (regcache, regnum);
+  old_chain = make_cleanup_regcache_invalidate (this, regnum);
 
-  target_store_registers (regcache, regnum);
+  target_store_registers (this, regnum);
 
   /* The target did not throw an error so we can discard invalidating the
      register and restore the cleanup chain to what it was.  */
@@ -969,12 +1030,18 @@ void
 regcache_cooked_write (struct regcache *regcache, int regnum,
 		       const gdb_byte *buf)
 {
+  regcache->cooked_write (regnum, buf);
+}
+
+void
+regcache::cooked_write (int regnum, const gdb_byte *buf)
+{
   gdb_assert (regnum >= 0);
-  gdb_assert (regnum < regcache->descr->nr_cooked_registers);
-  if (regnum < regcache->descr->nr_raw_registers)
-    regcache_raw_write (regcache, regnum, buf);
+  gdb_assert (regnum < m_descr->nr_cooked_registers);
+  if (regnum < m_descr->nr_raw_registers)
+    raw_write (regnum, buf);
   else
-    gdbarch_pseudo_register_write (regcache->descr->gdbarch, regcache,
+    gdbarch_pseudo_register_write (m_descr->gdbarch, this,
 				   regnum, buf);
 }
 
@@ -986,33 +1053,32 @@ typedef void (regcache_read_ftype) (struct regcache *regcache, int regnum,
 typedef void (regcache_write_ftype) (struct regcache *regcache, int regnum,
 				     const void *buf);
 
-static enum register_status
-regcache_xfer_part (struct regcache *regcache, int regnum,
-		    int offset, int len, void *in, const void *out,
-		    enum register_status (*read) (struct regcache *regcache,
-						  int regnum,
-						  gdb_byte *buf),
-		    void (*write) (struct regcache *regcache, int regnum,
-				   const gdb_byte *buf))
-{
-  struct regcache_descr *descr = regcache->descr;
-  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+enum register_status
+regcache::xfer_part (int regnum, int offset, int len, void *in,
+		     const void *out,
+		     enum register_status (*read) (struct regcache *regcache,
+						   int regnum,
+						   gdb_byte *buf),
+		     void (*write) (struct regcache *regcache, int regnum,
+				    const gdb_byte *buf))
+{
+  struct gdbarch *gdbarch = arch ();
   gdb_byte *reg = (gdb_byte *) alloca (register_size (gdbarch, regnum));
 
-  gdb_assert (offset >= 0 && offset <= descr->sizeof_register[regnum]);
-  gdb_assert (len >= 0 && offset + len <= descr->sizeof_register[regnum]);
+  gdb_assert (offset >= 0 && offset <= m_descr->sizeof_register[regnum]);
+  gdb_assert (len >= 0 && offset + len <= m_descr->sizeof_register[regnum]);
   /* Something to do?  */
   if (offset + len == 0)
     return REG_VALID;
   /* Read (when needed) ...  */
   if (in != NULL
       || offset > 0
-      || offset + len < descr->sizeof_register[regnum])
+      || offset + len < m_descr->sizeof_register[regnum])
     {
       enum register_status status;
 
       gdb_assert (read != NULL);
-      status = read (regcache, regnum, reg);
+      status = read (this, regnum, reg);
       if (status != REG_VALID)
 	return status;
     }
@@ -1025,7 +1091,7 @@ regcache_xfer_part (struct regcache *regcache, int regnum,
   if (out != NULL)
     {
       gdb_assert (write != NULL);
-      write (regcache, regnum, reg);
+      write (this, regnum, reg);
     }
 
   return REG_VALID;
@@ -1035,44 +1101,63 @@ enum register_status
 regcache_raw_read_part (struct regcache *regcache, int regnum,
 			int offset, int len, gdb_byte *buf)
 {
-  struct regcache_descr *descr = regcache->descr;
+  return regcache->raw_read_part (regnum, offset, len, buf);
+}
 
-  gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
-  return regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
-			     regcache_raw_read, regcache_raw_write);
+enum register_status
+regcache::raw_read_part (int regnum, int offset, int len, gdb_byte *buf)
+{
+  gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
+  return xfer_part (regnum, offset, len, buf, NULL,
+		    regcache_raw_read, regcache_raw_write);
 }
 
 void
 regcache_raw_write_part (struct regcache *regcache, int regnum,
 			 int offset, int len, const gdb_byte *buf)
 {
-  struct regcache_descr *descr = regcache->descr;
+  regcache->raw_write_part (regnum, offset, len, buf);
+}
 
-  gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
-  regcache_xfer_part (regcache, regnum, offset, len, NULL, buf,
-		      regcache_raw_read, regcache_raw_write);
+void
+regcache::raw_write_part (int regnum, int offset, int len,
+			  const gdb_byte *buf)
+{
+  gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
+  xfer_part (regnum, offset, len, NULL, buf, regcache_raw_read,
+	     regcache_raw_write);
 }
 
 enum register_status
 regcache_cooked_read_part (struct regcache *regcache, int regnum,
 			   int offset, int len, gdb_byte *buf)
 {
-  struct regcache_descr *descr = regcache->descr;
+  return regcache->cooked_read_part (regnum, offset, len, buf);
+}
 
-  gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
-  return regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
-			     regcache_cooked_read, regcache_cooked_write);
+
+enum register_status
+regcache::cooked_read_part (int regnum, int offset, int len, gdb_byte *buf)
+{
+  gdb_assert (regnum >= 0 && regnum < m_descr->nr_cooked_registers);
+  return xfer_part (regnum, offset, len, buf, NULL,
+		    regcache_cooked_read, regcache_cooked_write);
 }
 
 void
 regcache_cooked_write_part (struct regcache *regcache, int regnum,
 			    int offset, int len, const gdb_byte *buf)
 {
-  struct regcache_descr *descr = regcache->descr;
+  regcache->cooked_write_part (regnum, offset, len, buf);
+}
 
-  gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
-  regcache_xfer_part (regcache, regnum, offset, len, NULL, buf,
-		      regcache_cooked_read, regcache_cooked_write);
+void
+regcache::cooked_write_part (int regnum, int offset, int len,
+			     const gdb_byte *buf)
+{
+  gdb_assert (regnum >= 0 && regnum < m_descr->nr_cooked_registers);
+  xfer_part (regnum, offset, len, NULL, buf,
+	     regcache_cooked_read, regcache_cooked_write);
 }
 
 /* Supply register REGNUM, whose contents are stored in BUF, to REGCACHE.  */
@@ -1080,20 +1165,26 @@ regcache_cooked_write_part (struct regcache *regcache, int regnum,
 void
 regcache_raw_supply (struct regcache *regcache, int regnum, const void *buf)
 {
+  gdb_assert (regcache != NULL);
+  regcache->raw_supply (regnum, buf);
+}
+
+void
+regcache::raw_supply (int regnum, const void *buf)
+{
   void *regbuf;
   size_t size;
 
-  gdb_assert (regcache != NULL);
-  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
-  gdb_assert (!regcache->readonly_p);
+  gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
+  gdb_assert (!m_readonly_p);
 
-  regbuf = register_buffer (regcache, regnum);
-  size = regcache->descr->sizeof_register[regnum];
+  regbuf = register_buffer (regnum);
+  size = m_descr->sizeof_register[regnum];
 
   if (buf)
     {
       memcpy (regbuf, buf, size);
-      regcache->register_status[regnum] = REG_VALID;
+      m_register_status[regnum] = REG_VALID;
     }
   else
     {
@@ -1101,7 +1192,7 @@ regcache_raw_supply (struct regcache *regcache, int regnum, const void *buf)
 	 in case the register value manages to escape somewhere (due
 	 to a bug, no less).  */
       memset (regbuf, 0, size);
-      regcache->register_status[regnum] = REG_UNAVAILABLE;
+      m_register_status[regnum] = REG_UNAVAILABLE;
     }
 }
 
@@ -1110,14 +1201,21 @@ regcache_raw_supply (struct regcache *regcache, int regnum, const void *buf)
 void
 regcache_raw_collect (const struct regcache *regcache, int regnum, void *buf)
 {
+  gdb_assert (regcache != NULL && buf != NULL);
+  regcache->raw_collect (regnum, buf);
+}
+
+void
+regcache::raw_collect (int regnum, void *buf) const
+{
   const void *regbuf;
   size_t size;
 
-  gdb_assert (regcache != NULL && buf != NULL);
-  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
+  gdb_assert (buf != NULL);
+  gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
 
-  regbuf = register_buffer (regcache, regnum);
-  size = regcache->descr->sizeof_register[regnum];
+  regbuf = register_buffer (regnum);
+  size = m_descr->sizeof_register[regnum];
   memcpy (buf, regbuf, size);
 }
 
@@ -1125,12 +1223,11 @@ regcache_raw_collect (const struct regcache *regcache, int regnum, void *buf)
    set to or from a buffer.  This is the main worker function for
    regcache_supply_regset and regcache_collect_regset.  */
 
-static void
-regcache_transfer_regset (const struct regset *regset,
-			  const struct regcache *regcache,
-			  struct regcache *out_regcache,
-			  int regnum, const void *in_buf,
-			  void *out_buf, size_t size)
+void
+regcache::transfer_regset (const struct regset *regset,
+			   struct regcache *out_regcache,
+			   int regnum, const void *in_buf,
+			   void *out_buf, size_t size) const
 {
   const struct regcache_map_entry *map;
   int offs = 0, count;
@@ -1143,7 +1240,7 @@ regcache_transfer_regset (const struct regset *regset,
       int slot_size = map->size;
 
       if (slot_size == 0 && regno != REGCACHE_MAP_SKIP)
-	slot_size = regcache->descr->sizeof_register[regno];
+	slot_size = m_descr->sizeof_register[regno];
 
       if (regno == REGCACHE_MAP_SKIP
 	  || (regnum != -1
@@ -1157,12 +1254,11 @@ regcache_transfer_regset (const struct regset *regset,
 	      break;
 
 	    if (out_buf)
-	      regcache_raw_collect (regcache, regno,
-				    (gdb_byte *) out_buf + offs);
+	      raw_collect (regno, (gdb_byte *) out_buf + offs);
 	    else
-	      regcache_raw_supply (out_regcache, regno, in_buf
-				   ? (const gdb_byte *) in_buf + offs
-				   : NULL);
+	      out_regcache->raw_supply (regno, in_buf
+					? (const gdb_byte *) in_buf + offs
+					: NULL);
 	  }
       else
 	{
@@ -1172,12 +1268,11 @@ regcache_transfer_regset (const struct regset *regset,
 	    return;
 
 	  if (out_buf)
-	    regcache_raw_collect (regcache, regnum,
-				  (gdb_byte *) out_buf + offs);
+	    raw_collect (regnum, (gdb_byte *) out_buf + offs);
 	  else
-	    regcache_raw_supply (out_regcache, regnum, in_buf
-				 ? (const gdb_byte *) in_buf + offs
-				 : NULL);
+	    out_regcache->raw_supply (regnum, in_buf
+				      ? (const gdb_byte *) in_buf + offs
+				      : NULL);
 	  return;
 	}
     }
@@ -1192,8 +1287,14 @@ regcache_supply_regset (const struct regset *regset,
 			struct regcache *regcache,
 			int regnum, const void *buf, size_t size)
 {
-  regcache_transfer_regset (regset, regcache, regcache, regnum,
-			    buf, NULL, size);
+  regcache->supply_regset (regset, regnum, buf, size);
+}
+
+void
+regcache::supply_regset (const struct regset *regset,
+			 int regnum, const void *buf, size_t size)
+{
+  transfer_regset (regset, this, regnum, buf, NULL, size);
 }
 
 /* Collect register REGNUM from REGCACHE to BUF, using the register
@@ -1205,8 +1306,14 @@ regcache_collect_regset (const struct regset *regset,
 			 const struct regcache *regcache,
 			 int regnum, void *buf, size_t size)
 {
-  regcache_transfer_regset (regset, regcache, NULL, regnum,
-			    NULL, buf, size);
+  regcache->collect_regset (regset, regnum, buf, size);
+}
+
+void
+regcache::collect_regset (const struct regset *regset,
+			 int regnum, void *buf, size_t size) const
+{
+  transfer_regset (regset, NULL, regnum, NULL, buf, size);
 }
 
 
@@ -1259,10 +1366,9 @@ regcache_write_pc (struct regcache *regcache, CORE_ADDR pc)
 }
 
 void
-regcache_debug_print_register (const char *func, struct regcache *regcache,
-			       int regno)
+regcache::debug_print_register (const char *func,  int regno)
 {
-  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  struct gdbarch *gdbarch = arch ();
 
   fprintf_unfiltered (gdb_stdlog, "%s ", func);
   if (regno >= 0 && regno < gdbarch_num_regs (gdbarch)
@@ -1276,7 +1382,7 @@ regcache_debug_print_register (const char *func, struct regcache *regcache,
     {
       enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
       int size = register_size (gdbarch, regno);
-      gdb_byte *buf = register_buffer (regcache, regno);
+      gdb_byte *buf = register_buffer (regno);
 
       fprintf_unfiltered (gdb_stdlog, " = ");
       for (int i = 0; i < size; i++)
@@ -1303,19 +1409,11 @@ reg_flush_command (char *command, int from_tty)
     printf_filtered (_("Register cache flushed.\n"));
 }
 
-enum regcache_dump_what
-{
-  regcache_dump_none, regcache_dump_raw,
-  regcache_dump_cooked, regcache_dump_groups,
-  regcache_dump_remote
-};
-
-static void
-regcache_dump (struct regcache *regcache, struct ui_file *file,
-	       enum regcache_dump_what what_to_dump)
+void
+regcache::dump (ui_file *file, enum regcache_dump_what what_to_dump)
 {
   struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
-  struct gdbarch *gdbarch = regcache->descr->gdbarch;
+  struct gdbarch *gdbarch = m_descr->gdbarch;
   int regnum;
   int footnote_nr = 0;
   int footnote_register_size = 0;
@@ -1326,24 +1424,24 @@ regcache_dump (struct regcache *regcache, struct ui_file *file,
 
 #if 0
   fprintf_unfiltered (file, "nr_raw_registers %d\n",
-		      regcache->descr->nr_raw_registers);
+		      m_descr->nr_raw_registers);
   fprintf_unfiltered (file, "nr_cooked_registers %d\n",
-		      regcache->descr->nr_cooked_registers);
+		      m_descr->nr_cooked_registers);
   fprintf_unfiltered (file, "sizeof_raw_registers %ld\n",
-		      regcache->descr->sizeof_raw_registers);
+		      m_descr->sizeof_raw_registers);
   fprintf_unfiltered (file, "sizeof_raw_register_status %ld\n",
-		      regcache->descr->sizeof_raw_register_status);
+		      m_descr->sizeof_raw_register_status);
   fprintf_unfiltered (file, "gdbarch_num_regs %d\n", 
 		      gdbarch_num_regs (gdbarch));
   fprintf_unfiltered (file, "gdbarch_num_pseudo_regs %d\n",
 		      gdbarch_num_pseudo_regs (gdbarch));
 #endif
 
-  gdb_assert (regcache->descr->nr_cooked_registers
+  gdb_assert (m_descr->nr_cooked_registers
 	      == (gdbarch_num_regs (gdbarch)
 		  + gdbarch_num_pseudo_regs (gdbarch)));
 
-  for (regnum = -1; regnum < regcache->descr->nr_cooked_registers; regnum++)
+  for (regnum = -1; regnum < m_descr->nr_cooked_registers; regnum++)
     {
       /* Name.  */
       if (regnum < 0)
@@ -1380,12 +1478,12 @@ regcache_dump (struct regcache *regcache, struct ui_file *file,
       else
 	{
 	  fprintf_unfiltered (file, " %6ld",
-			      regcache->descr->register_offset[regnum]);
-	  if (register_offset != regcache->descr->register_offset[regnum]
+			      m_descr->register_offset[regnum]);
+	  if (register_offset != m_descr->register_offset[regnum]
 	      || (regnum > 0
-		  && (regcache->descr->register_offset[regnum]
-		      != (regcache->descr->register_offset[regnum - 1]
-			  + regcache->descr->sizeof_register[regnum - 1])))
+		  && (m_descr->register_offset[regnum]
+		      != (m_descr->register_offset[regnum - 1]
+			  + m_descr->sizeof_register[regnum - 1])))
 	      )
 	    {
 	      if (!footnote_register_offset)
@@ -1394,16 +1492,15 @@ regcache_dump (struct regcache *regcache, struct ui_file *file,
 	    }
 	  else
 	    fprintf_unfiltered (file, "  ");
-	  register_offset = (regcache->descr->register_offset[regnum]
-			     + regcache->descr->sizeof_register[regnum]);
+	  register_offset = (m_descr->register_offset[regnum]
+			     + m_descr->sizeof_register[regnum]);
 	}
 
       /* Size.  */
       if (regnum < 0)
 	fprintf_unfiltered (file, " %5s ", "Size");
       else
-	fprintf_unfiltered (file, " %5ld",
-			    regcache->descr->sizeof_register[regnum]);
+	fprintf_unfiltered (file, " %5ld", m_descr->sizeof_register[regnum]);
 
       /* Type.  */
       {
@@ -1415,7 +1512,7 @@ regcache_dump (struct regcache *regcache, struct ui_file *file,
 	  {
 	    static const char blt[] = "builtin_type";
 
-	    t = TYPE_NAME (register_type (regcache->descr->gdbarch, regnum));
+	    t = TYPE_NAME (register_type (arch (), regnum));
 	    if (t == NULL)
 	      {
 		char *n;
@@ -1441,17 +1538,17 @@ regcache_dump (struct regcache *regcache, struct ui_file *file,
 	{
 	  if (regnum < 0)
 	    fprintf_unfiltered (file, "Raw value");
-	  else if (regnum >= regcache->descr->nr_raw_registers)
+	  else if (regnum >= m_descr->nr_raw_registers)
 	    fprintf_unfiltered (file, "<cooked>");
-	  else if (regcache_register_status (regcache, regnum) == REG_UNKNOWN)
+	  else if (get_register_status (regnum) == REG_UNKNOWN)
 	    fprintf_unfiltered (file, "<invalid>");
-	  else if (regcache_register_status (regcache, regnum) == REG_UNAVAILABLE)
+	  else if (get_register_status (regnum) == REG_UNAVAILABLE)
 	    fprintf_unfiltered (file, "<unavailable>");
 	  else
 	    {
-	      regcache_raw_read (regcache, regnum, buf);
+	      raw_read (regnum, buf);
 	      print_hex_chars (file, buf,
-			       regcache->descr->sizeof_register[regnum],
+			       m_descr->sizeof_register[regnum],
 			       gdbarch_byte_order (gdbarch));
 	    }
 	}
@@ -1465,14 +1562,14 @@ regcache_dump (struct regcache *regcache, struct ui_file *file,
 	    {
 	      enum register_status status;
 
-	      status = regcache_cooked_read (regcache, regnum, buf);
+	      status = cooked_read (regnum, buf);
 	      if (status == REG_UNKNOWN)
 		fprintf_unfiltered (file, "<invalid>");
 	      else if (status == REG_UNAVAILABLE)
 		fprintf_unfiltered (file, "<unavailable>");
 	      else
 		print_hex_chars (file, buf,
-				 regcache->descr->sizeof_register[regnum],
+				 m_descr->sizeof_register[regnum],
 				 gdbarch_byte_order (gdbarch));
 	    }
 	}
@@ -1508,11 +1605,11 @@ regcache_dump (struct regcache *regcache, struct ui_file *file,
 	    {
 	      fprintf_unfiltered (file, "Rmt Nr  g/G Offset");
 	    }
-	  else if (regnum < regcache->descr->nr_raw_registers)
+	  else if (regnum < m_descr->nr_raw_registers)
 	    {
 	      int pnum, poffset;
 
-	      if (remote_register_number_and_offset (get_regcache_arch (regcache), regnum,
+	      if (remote_register_number_and_offset (arch (), regnum,
 						     &pnum, &poffset))
 		fprintf_unfiltered (file, "%7d %11d", pnum, poffset);
 	    }
@@ -1538,14 +1635,14 @@ static void
 regcache_print (char *args, enum regcache_dump_what what_to_dump)
 {
   if (args == NULL)
-    regcache_dump (get_current_regcache (), gdb_stdout, what_to_dump);
+    get_current_regcache ()->dump (gdb_stdout, what_to_dump);
   else
     {
       stdio_file file;
 
       if (!file.open (args, "w"))
 	perror_with_name (_("maintenance print architecture"));
-      regcache_dump (get_current_regcache (), &file, what_to_dump);
+      get_current_regcache ()->dump (&file, what_to_dump);
     }
 }
 
diff --git a/gdb/regcache.h b/gdb/regcache.h
index 1d60fa7..e03a39f 100644
--- a/gdb/regcache.h
+++ b/gdb/regcache.h
@@ -224,6 +224,157 @@ extern void regcache_save (struct regcache *dst,
 			   regcache_cooked_read_ftype *cooked_read,
 			   void *cooked_read_context);
 
+enum regcache_dump_what
+{
+  regcache_dump_none, regcache_dump_raw,
+  regcache_dump_cooked, regcache_dump_groups,
+  regcache_dump_remote
+};
+
+/* The register cache for storing raw register values.  */
+
+class regcache
+{
+public:
+  regcache (gdbarch *gdbarch, address_space *aspace_)
+    : regcache (gdbarch, aspace_, true)
+  {}
+
+  ~regcache ()
+  {
+    xfree (m_registers);
+    xfree (m_register_status);
+  }
+
+  gdbarch *arch () const;
+
+  address_space *aspace () const
+  {
+    return m_aspace;
+  }
+
+  void save (regcache_cooked_read_ftype *cooked_read, void *src);
+
+  enum register_status cooked_read (int regnum, gdb_byte *buf);
+  void cooked_write (int regnum, const gdb_byte *buf);
+
+  enum register_status raw_read (int regnum, gdb_byte *buf);
+  void raw_write (int regnum, const gdb_byte *buf);
+
+  enum register_status raw_read_signed (int regnum, LONGEST *val);
+
+  void raw_write_signed (int regnum, LONGEST val);
+
+  enum register_status raw_read_unsigned (int regnum, ULONGEST *val);
+
+  void raw_write_unsigned (int regnum, ULONGEST val);
+
+  struct value *cooked_read_value (int regnum);
+
+  enum register_status cooked_read_signed (int regnum, LONGEST *val);
+
+  void cooked_write_signed (int regnum, LONGEST val);
+
+  enum register_status cooked_read_unsigned (int regnum, ULONGEST *val);
+
+  void cooked_write_unsigned (int regnum, ULONGEST val);
+
+  void raw_update (int regnum);
+
+  void raw_collect (int regnum, void *buf) const;
+
+  void raw_supply (int regnum, const void *buf);
+
+  enum register_status get_register_status (int regnum) const;
+
+  void raw_set_cached_value (int regnum, const gdb_byte *buf);
+
+  void invalidate (int regnum);
+
+  enum register_status raw_read_part (int regnum, int offset, int len,
+				      gdb_byte *buf);
+
+  void raw_write_part (int regnum, int offset, int len, const gdb_byte *buf);
+
+  enum register_status cooked_read_part (int regnum, int offset, int len,
+					 gdb_byte *buf);
+
+  void cooked_write_part (int regnum, int offset, int len,
+			  const gdb_byte *buf);
+
+  void supply_regset (const struct regset *regset,
+		      int regnum, const void *buf, size_t size);
+
+
+  void collect_regset (const struct regset *regset, int regnum,
+		       void *buf, size_t size) const;
+
+  void dump (ui_file *file, enum regcache_dump_what what_to_dump);
+
+  ptid_t ptid () const
+  {
+    return m_ptid;
+  }
+
+  void set_ptid (const ptid_t ptid)
+  {
+    this->m_ptid = ptid;
+  }
+
+/* Dump the contents of a register from the register cache to the target
+   debug.  */
+  void debug_print_register (const char *func, int regno);
+
+private:
+  regcache (gdbarch *gdbarch, address_space *aspace_, bool readonly_p_);
+
+  gdb_byte *register_buffer (int regnum) const;
+
+  void restore (struct regcache *src);
+
+  void cpy_no_passthrough (struct regcache *src);
+
+  enum register_status xfer_part (int regnum, int offset, int len, void *in,
+				  const void *out,
+				  decltype (regcache_raw_read) read,
+				  decltype (regcache_raw_write) write);
+
+  void transfer_regset (const struct regset *regset,
+			struct regcache *out_regcache,
+			int regnum, const void *in_buf,
+			void *out_buf, size_t size) const;
+
+  struct regcache_descr *m_descr;
+
+  /* The address space of this register cache (for registers where it
+     makes sense, like PC or SP).  */
+  struct address_space *m_aspace;
+
+  /* The register buffers.  A read-only register cache can hold the
+     full [0 .. gdbarch_num_regs + gdbarch_num_pseudo_regs) while a read/write
+     register cache can only hold [0 .. gdbarch_num_regs).  */
+  gdb_byte *m_registers;
+  /* Register cache status.  */
+  signed char *m_register_status;
+  /* Is this a read-only cache?  A read-only cache is used for saving
+     the target's register state (e.g, across an inferior function
+     call or just before forcing a function return).  A read-only
+     cache can only be updated via the methods regcache_dup() and
+     regcache_cpy().  The actual contents are determined by the
+     reggroup_save and reggroup_restore methods.  */
+  bool m_readonly_p;
+  /* If this is a read-write cache, which thread's registers is
+     it connected to?  */
+  ptid_t m_ptid;
+
+  friend struct regcache *
+  get_thread_arch_aspace_regcache (ptid_t ptid, struct gdbarch *gdbarch,
+				   struct address_space *aspace);
+
+  friend void
+  regcache_cpy (struct regcache *dst, struct regcache *src);
+};
+
 /* Copy/duplicate the contents of a register cache.  By default, the
    operation is pass-through.  Writes to DST and reads from SRC will
    go through to the target.  See also regcache_cpy_no_passthrough.
@@ -236,10 +387,4 @@ extern void regcache_cpy (struct regcache *dest, struct regcache *src);
 extern void registers_changed (void);
 extern void registers_changed_ptid (ptid_t);
 
-/* Dump the contents of a register from the register cache to the target
-   debug.  */
-extern void regcache_debug_print_register (const char *func,
-					   struct regcache *regcache,
-					   int regno);
-
 #endif /* REGCACHE_H */
diff --git a/gdb/target.c b/gdb/target.c
index 10a5315..e526bcc 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -3552,7 +3552,7 @@ target_fetch_registers (struct regcache *regcache, int regno)
 {
   current_target.to_fetch_registers (&current_target, regcache, regno);
   if (targetdebug)
-    regcache_debug_print_register ("target_fetch_registers", regcache, regno);
+    regcache->debug_print_register ("target_fetch_registers", regno);
 }
 
 void
@@ -3564,8 +3564,7 @@ target_store_registers (struct regcache *regcache, int regno)
   current_target.to_store_registers (&current_target, regcache, regno);
   if (targetdebug)
     {
-      regcache_debug_print_register ("target_store_registers", regcache,
-				     regno);
+      regcache->debug_print_register ("target_store_registers", regno);
     }
 }
 

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2017-04-28 21:44 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-25 20:28 [PATCH 0/6] Class-fy regcache in GDB Yao Qi
2017-04-25 20:28 ` [PATCH 6/6] Remove cleanup in get_return_value Yao Qi
2017-04-25 20:28 ` [PATCH 4/6] Simplify regcache_dup Yao Qi
2017-04-25 20:28 ` [PATCH 1/6 OBV] Change readonly_p to bool Yao Qi
2017-04-25 20:28 ` [PATCH 2/6] Add constructor and destructor to regcache Yao Qi
2017-04-27 17:34   ` Pedro Alves
2017-04-28 13:42     ` Yao Qi
2017-04-25 20:29 ` [PATCH 3/6] Class-fy regcache Yao Qi
2017-04-27 17:35   ` Pedro Alves
2017-04-25 20:29 ` [PATCH 5/6] Use copy ctor in regcache_dup Yao Qi
2017-04-27 17:37   ` Pedro Alves
2017-04-28  9:11     ` Yao Qi
2017-04-28  9:51       ` Pedro Alves
2017-04-28 13:20         ` Yao Qi
2017-04-28 14:26 ` [PATCH 0/4 v2] Class-fy regcache in GDB Yao Qi
2017-04-28 14:26   ` [PATCH 2/4] Simplify regcache_dup Yao Qi
2017-04-28 15:03     ` Pedro Alves
2017-04-28 14:26   ` [PATCH 1/4] Class-fy regcache Yao Qi
2017-04-28 15:03     ` Pedro Alves
2017-04-28 21:44       ` Yao Qi
2017-04-28 14:26   ` [PATCH 4/4] Remove cleanup in get_return_value Yao Qi
2017-04-28 15:05     ` Pedro Alves
2017-04-28 14:26   ` [PATCH 3/4] Use tag dispatch regcache ctor in regcache_dup Yao Qi
2017-04-28 15:04     ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).