Patchwork [RFC,3/6] Add scoped_restore_regcache_ptid

login
register
mail settings
Submitter Omair Javaid
Date Jan. 29, 2019, 5:03 a.m.
Message ID <1548738199-9403-4-git-send-email-omair.javaid@linaro.org>
Download mbox | patch
Permalink /patch/31238/
State New
Headers show

Comments

Omair Javaid - Jan. 29, 2019, 5:03 a.m.
From: Philipp Rudo <prudo@linux.ibm.com>

When a target and its target beneath use different ptids to identify a
thread the regcaches ptid has to be set/restored when calls are passed down
to the target beneath to e.g. fetch_registers.  Add a scoped_restore to
simplify this.

gdb/ChangeLog:

	regcache.h (scoped_restore_regcache_ptid): New class.
---
 gdb/regcache.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

Patch

diff --git a/gdb/regcache.h b/gdb/regcache.h
index 2b703ea..389d220 100644
--- a/gdb/regcache.h
+++ b/gdb/regcache.h
@@ -429,6 +429,27 @@  private:
   registers_changed_ptid (ptid_t ptid);
 };
 
+/* Save/restore the current ptid of REGCACHE.  */
+
+class scoped_restore_regcache_ptid
+{
+public:
+  scoped_restore_regcache_ptid (regcache *regcache)
+    : m_regcache (regcache), m_ptid (regcache->ptid ())
+  {}
+
+  ~scoped_restore_regcache_ptid ()
+    {
+      m_regcache->set_ptid (m_ptid);
+    }
+
+  DISABLE_COPY_AND_ASSIGN (scoped_restore_regcache_ptid);
+
+private:
+  regcache *m_regcache;
+  ptid_t m_ptid;
+};
+
 class readonly_detached_regcache : public readable_regcache
 {
 public: