[05/26] gdbserver: add a pointer to the owner thread in regcache

Message ID 5e9fc384d9456c05d12037a4f2f1999b675c19f5.1677582744.git.tankut.baris.aktemur@intel.com
State New
Headers
Series gdbserver: refactor regcache and allow gradually populating |

Commit Message

Tankut Baris Aktemur Feb. 28, 2023, 11:28 a.m. UTC
  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

Simon Marchi Dec. 21, 2023, 8:28 p.m. UTC | #1
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
  

Patch

diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc
index 21c2207822c..2a8dc17ed6a 100644
--- a/gdbserver/regcache.cc
+++ b/gdbserver/regcache.cc
@@ -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)
diff --git a/gdbserver/regcache.h b/gdbserver/regcache.h
index 5b2066ced4d..053ed08b20f 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