[05/26] gdbserver: add a pointer to the owner thread in regcache
Commit Message
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(+)
Comments
On 2/28/23 06:28, Tankut Baris Aktemur via Gdb-patches wrote:
> 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.
I'm a bit hesitant with this change as-is, because it sets the thread
field only in some instances of regcache. There are code paths that
create regcaches but don't set it. It adds a bit of cognitive load to
have to think about when it is set and when it isn't.
I'll have to see how it's used in the rest of the series. Perhaps that
doesn't work, but intuitively I'm thinking that it might be better to
get the thread from the context in another way, like passing it down to
functions as an argument.
Simon
@@ -45,6 +45,7 @@ get_thread_regcache (struct thread_info *thread, bool fetch)
regcache = new struct regcache (proc->tdesc);
set_thread_regcache_data (thread, regcache);
+ regcache->thread = thread;
}
if (fetch && regcache->registers_valid == 0)
@@ -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