This is the mail archive of the
gdb-cvs@sourceware.org
mailing list for the GDB project.
[binutils-gdb] Simplify regcache_dup
- From: Yao Qi <qiyao at sourceware dot org>
- To: gdb-cvs at sourceware dot org
- Date: 28 Apr 2017 21:51:05 -0000
- Subject: [binutils-gdb] Simplify regcache_dup
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b421c83cb866120ab347d60fda20fb0e2011be8c
commit b421c83cb866120ab347d60fda20fb0e2011be8c
Author: Yao Qi <yao.qi@linaro.org>
Date: Fri Apr 28 22:48:42 2017 +0100
Simplify regcache_dup
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-28 Yao Qi <yao.qi@linaro.org>
* regcache.c (regcache_dup): Assert !src->m_readonly_p and
call method save instead of regcache_cpy.
* regcache.h (struct regcache): Make regcache_dup a friend.
Diff:
---
gdb/ChangeLog | 6 ++++++
gdb/regcache.c | 3 ++-
gdb/regcache.h | 3 +++
3 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 537213d..7e89c74 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
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.
+ * regcache.h (struct regcache): Make regcache_dup a friend.
+
+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.
diff --git a/gdb/regcache.c b/gdb/regcache.c
index 11f6a87..c30d1c7 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -422,8 +422,9 @@ regcache_dup (struct regcache *src)
{
struct regcache *newbuf;
+ gdb_assert (!src->m_readonly_p);
newbuf = regcache_xmalloc (src->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 e03a39f..c5d21f7 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