+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
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
{
}
}
-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)
{
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
: 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);
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