[PATCH v2 30/47] gdbserver: add a pointer to the owner thread in regcache

Tankut Baris Aktemur
2024-12-13T16:30:52Z

Add a back-link in regcache to the thread that owns the regcache.
This will help us in future patches to refer to the right thread
object without having to rely on the global current_thread pointer.
---
gdbserver/regcache.cc | 1 +
gdbserver/regcache.h | 3 +++
2 files changed, 4 insertions(+)

diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc
index f1d63eac0ba4c2dccfb3c54910e6cdb768931f61..5e4ef579d0f058220e42460cf81dad18d3f6f868 100644
--- a/gdbserver/regcache.cc
+++ b/gdbserver/regcache.cc
@@ -44,6 +44,7 @@ get_thread_regcache (thread_info *thread, int fetch)

regcache = new_register_cache (proc->tdesc);
thread->set_regcache (regcache);
+ regcache->thread = thread;
}

if (fetch && regcache->registers_valid == 0)
diff --git a/gdbserver/regcache.h b/gdbserver/regcache.h
index 16ee4d0a2e7127127225b72d8e9ef3eab71ce88e..62c014d16d8d184044b803087a26da86b7627e90 100644
--- a/gdbserver/regcache.h
+++ b/gdbserver/regcache.h
@@ -33,6 +33,9 @@ struct regcache : public reg_buffer_common
/* The regcache's target description. */
const struct target_desc *tdesc = nullptr;

+ /* Back-link to the thread to which this regcache belongs. */
+ thread_info *thread = nullptr;
+
/* Whether the REGISTERS buffer's contents are valid. If false, we
haven't fetched the registers from the target yet. Not that this
register cache is _not_ pass-through, unlike GDB's. Note that