Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Yao Qi <qiyaoltc@gmail.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 3/4] Use tag dispatch regcache ctor in regcache_dup
Date: Fri, 28 Apr 2017 14:26:00 -0000	[thread overview]
Message-ID: <1493389594-24434-4-git-send-email-yao.qi@linaro.org> (raw)
In-Reply-To: <1493389594-24434-1-git-send-email-yao.qi@linaro.org>

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


  reply	other threads:[~2017-04-28 14:26 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-25 20:28 [PATCH 0/6] Class-fy regcache in GDB 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 6/6] Remove cleanup in get_return_value 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 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-25 20:29 ` [PATCH 3/6] Class-fy regcache Yao Qi
2017-04-27 17:35   ` Pedro Alves
2017-04-28 14:26 ` [PATCH 0/4 v2] Class-fy regcache in GDB Yao Qi
2017-04-28 14:26   ` Yao Qi [this message]
2017-04-28 15:04     ` [PATCH 3/4] Use tag dispatch regcache ctor in regcache_dup Pedro Alves
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1493389594-24434-4-git-send-email-yao.qi@linaro.org \
    --to=qiyaoltc@gmail.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox