aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYao Qi <yao.qi@linaro.org>2017-04-28 22:48:42 +0100
committerYao Qi <yao.qi@linaro.org>2017-04-28 22:48:42 +0100
commitdeb1fa3edaf10c65d1f39951779927da955e3a57 (patch)
tree2c9ec3e61edf329ab924e7506ca7725abb91212a
parentb421c83cb866120ab347d60fda20fb0e2011be8c (diff)
downloadgdb-deb1fa3edaf10c65d1f39951779927da955e3a57.zip
gdb-deb1fa3edaf10c65d1f39951779927da955e3a57.tar.gz
gdb-deb1fa3edaf10c65d1f39951779927da955e3a57.tar.bz2
Use tag dispatch regcache ctor in regcache_dup
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-28 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.
-rw-r--r--gdb/ChangeLog9
-rw-r--r--gdb/regcache.c30
-rw-r--r--gdb/regcache.h12
3 files changed, 34 insertions, 17 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 7e89c74..29e9cbd 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,4 +1,13 @@
2017-04-28 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.
+
+2017-04-28 Yao Qi <yao.qi@linaro.org>
* regcache.c (regcache_dup): Assert !src->m_readonly_p and
call method save instead of regcache_cpy.
diff --git a/gdb/regcache.c b/gdb/regcache.c
index c30d1c7..03f172e 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.arch (), src.aspace (), true)
+{
+ gdb_assert (!src.m_readonly_p);
+ save (do_cooked_read, (void *) &src);
+}
+
gdbarch *
regcache::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->m_readonly_p);
- newbuf = regcache_xmalloc (src->arch (), 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 c5d21f7..36255da 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