summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2019-01-23 18:58:37 +0000
committerPedro Alves <palves@redhat.com>2019-01-23 19:14:44 +0000
commit311dc83a411c83d61cd6cb931289761574ea3ecc (patch)
tree6f6ff3deb4eb5b6fccadd5d3667247c7efca060c
parent296bd123f76d7f8474b5a2937a49fd619748a871 (diff)
downloadbinutils-gdb-311dc83a411c83d61cd6cb931289761574ea3ecc.tar.gz
Use scope_exit in regcache.c
This removes the regcache_invalidator class in favor of a scope_exit. This seems like an improvement (albeit a minor one) because regcache_invalidator is only used in a single spot. gdb/ChangeLog: 2019-01-23 Tom Tromey <tom@tromey.com> Pedro Alves <palves@redhat.com> * regcache.c (class regcache_invalidator): Remove. (regcache::raw_write): Use make_scope_exit.
-rw-r--r--gdb/ChangeLog6
-rw-r--r--gdb/regcache.c34
2 files changed, 8 insertions, 32 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 39d5b580878..e01f5eecb4c 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,4 +1,10 @@
2019-01-23 Tom Tromey <tom@tromey.com>
+ Pedro Alves <palves@redhat.com>
+
+ * regcache.c (class regcache_invalidator): Remove.
+ (regcache::raw_write): Use make_scope_exit.
+
+2019-01-23 Tom Tromey <tom@tromey.com>
* ui-out.h (class ui_out_emit_type): Update comment.
diff --git a/gdb/regcache.c b/gdb/regcache.c
index 4a68390c5f7..a354e15d2d8 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -219,37 +219,6 @@ reg_buffer::arch () const
return m_descr->gdbarch;
}
-/* Cleanup class for invalidating a register. */
-
-class regcache_invalidator
-{
-public:
-
- regcache_invalidator (struct regcache *regcache, int regnum)
- : m_regcache (regcache),
- m_regnum (regnum)
- {
- }
-
- ~regcache_invalidator ()
- {
- if (m_regcache != nullptr)
- m_regcache->invalidate (m_regnum);
- }
-
- DISABLE_COPY_AND_ASSIGN (regcache_invalidator);
-
- void release ()
- {
- m_regcache = nullptr;
- }
-
-private:
-
- struct regcache *m_regcache;
- int m_regnum;
-};
-
/* Return a pointer to register REGNUM's buffer cache. */
gdb_byte *
@@ -769,7 +738,8 @@ regcache::raw_write (int regnum, const gdb_byte *buf)
/* Invalidate the register after it is written, in case of a
failure. */
- regcache_invalidator invalidator (this, regnum);
+ auto invalidator
+ = make_scope_exit ([&] { this->invalidate (regnum); });
target_store_registers (this, regnum);