aboutsummaryrefslogtreecommitdiff
path: root/gdbserver/inferiors.cc
diff options
context:
space:
mode:
authorTankut Baris Aktemur <tankut.baris.aktemur@intel.com>2021-12-13 12:22:48 +0100
committerTankut Baris Aktemur <tankut.baris.aktemur@intel.com>2021-12-13 12:22:48 +0100
commitf24791b72e764ada576901c0e866bf7768773a16 (patch)
treed3e09e57eb5a5787b80d78f239fefa4ee27a6e74 /gdbserver/inferiors.cc
parent200fd2874d2c147539f756b29e15ebbafa81dfcf (diff)
downloadgdb-f24791b72e764ada576901c0e866bf7768773a16.zip
gdb-f24791b72e764ada576901c0e866bf7768773a16.tar.gz
gdb-f24791b72e764ada576901c0e866bf7768773a16.tar.bz2
gdbserver: introduce scoped_restore_current_thread and switch_to_thread
Introduce a class for restoring the current thread and a function to switch to the given thread. This is a preparation for a refactoring that aims to remove direct assignments to 'current_thread'.
Diffstat (limited to 'gdbserver/inferiors.cc')
-rw-r--r--gdbserver/inferiors.cc21
1 files changed, 21 insertions, 0 deletions
diff --git a/gdbserver/inferiors.cc b/gdbserver/inferiors.cc
index a636266..d44e40a 100644
--- a/gdbserver/inferiors.cc
+++ b/gdbserver/inferiors.cc
@@ -218,6 +218,14 @@ switch_to_thread (process_stratum_target *ops, ptid_t ptid)
current_thread = find_thread_ptid (ptid);
}
+/* See gdbthread.h. */
+
+void
+switch_to_thread (thread_info *thread)
+{
+ current_thread = thread;
+}
+
/* See inferiors.h. */
void
@@ -243,3 +251,16 @@ set_inferior_cwd (std::string cwd)
{
current_inferior_cwd = std::move (cwd);
}
+
+scoped_restore_current_thread::scoped_restore_current_thread ()
+{
+ m_thread = current_thread;
+}
+
+scoped_restore_current_thread::~scoped_restore_current_thread ()
+{
+ if (m_dont_restore)
+ return;
+
+ switch_to_thread (m_thread);
+}