[3/4] gdbserver: make thread_regcache_data / set_thread_regcache_data methods of thread_info

Message ID 20241204163101.2294833-4-simark@simark.ca
State New
Headers
Series Some (hopefully) harmless cleanups |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_build--master-arm fail Patch failed to apply

Commit Message

Simon Marchi Dec. 4, 2024, 4:30 p.m. UTC
  From: Simon Marchi <simon.marchi@polymtl.ca>

Make the field private, change the free functions to be methods.

Change-Id: Ifd8ed2775dddefc73a0e00126182e1db02688af4
---
 gdbserver/gdbthread.h  | 10 ++++++++--
 gdbserver/inferiors.cc | 12 ------------
 gdbserver/inferiors.h  |  2 --
 gdbserver/regcache.cc  | 14 +++++---------
 4 files changed, 13 insertions(+), 25 deletions(-)
  

Patch

diff --git a/gdbserver/gdbthread.h b/gdbserver/gdbthread.h
index 11ab7f49adbf..2f06be9101da 100644
--- a/gdbserver/gdbthread.h
+++ b/gdbserver/gdbthread.h
@@ -33,18 +33,23 @@  struct thread_info : public intrusive_list_node<thread_info>
 
   ~thread_info ()
   {
-    free_register_cache (this->regcache_data);
+    free_register_cache (m_regcache);
   }
 
   /* Return the process owning this thread.  */
   process_info *process () const
   { return m_process; }
 
+  struct regcache *regcache ()
+  { return m_regcache; }
+
+  void set_regcache (struct regcache *regcache)
+  { m_regcache = regcache; }
+
   /* The id of this thread.  */
   ptid_t id;
 
   void *target_data;
-  struct regcache *regcache_data = nullptr;
 
   /* The last resume GDB requested on this thread.  */
   enum resume_kind last_resume_kind = resume_continue;
@@ -88,6 +93,7 @@  struct thread_info : public intrusive_list_node<thread_info>
   
 private:
   process_info *m_process;
+  struct regcache *m_regcache = nullptr;
 };
 
 /* Return a pointer to the first thread, or NULL if there isn't one.  */
diff --git a/gdbserver/inferiors.cc b/gdbserver/inferiors.cc
index e72b1c9bfc25..96fb7530ebc6 100644
--- a/gdbserver/inferiors.cc
+++ b/gdbserver/inferiors.cc
@@ -124,18 +124,6 @@  thread_target_data (struct thread_info *thread)
   return thread->target_data;
 }
 
-struct regcache *
-thread_regcache_data (struct thread_info *thread)
-{
-  return thread->regcache_data;
-}
-
-void
-set_thread_regcache_data (struct thread_info *thread, struct regcache *data)
-{
-  thread->regcache_data = data;
-}
-
 void
 clear_inferiors (void)
 {
diff --git a/gdbserver/inferiors.h b/gdbserver/inferiors.h
index 5372a3cd5b78..cdf1006a091a 100644
--- a/gdbserver/inferiors.h
+++ b/gdbserver/inferiors.h
@@ -155,8 +155,6 @@  void switch_to_process (process_info *proc);
 void clear_inferiors (void);
 
 void *thread_target_data (struct thread_info *);
-struct regcache *thread_regcache_data (struct thread_info *);
-void set_thread_regcache_data (struct thread_info *, struct regcache *);
 
 /* Set the inferior current working directory.  If CWD is empty, unset
    the directory.  */
diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc
index ef235b18c413..d750668b192c 100644
--- a/gdbserver/regcache.cc
+++ b/gdbserver/regcache.cc
@@ -27,9 +27,7 @@ 
 struct regcache *
 get_thread_regcache (struct thread_info *thread, int fetch)
 {
-  struct regcache *regcache;
-
-  regcache = thread_regcache_data (thread);
+  regcache *regcache = thread->regcache ();
 
   /* Threads' regcaches are created lazily, because biarch targets add
      the main thread/lwp before seeing it stop for the first time, and
@@ -45,7 +43,7 @@  get_thread_regcache (struct thread_info *thread, int fetch)
       gdb_assert (proc->tdesc != NULL);
 
       regcache = new_register_cache (proc->tdesc);
-      set_thread_regcache_data (thread, regcache);
+      thread->set_regcache (regcache);
     }
 
   if (fetch && regcache->registers_valid == 0)
@@ -74,9 +72,7 @@  get_thread_regcache_for_ptid (ptid_t ptid)
 void
 regcache_invalidate_thread (struct thread_info *thread)
 {
-  struct regcache *regcache;
-
-  regcache = thread_regcache_data (thread);
+  regcache *regcache = thread->regcache ();
 
   if (regcache == NULL)
     return;
@@ -277,13 +273,13 @@  find_regno (const struct target_desc *tdesc, const char *name)
 static void
 free_register_cache_thread (struct thread_info *thread)
 {
-  struct regcache *regcache = thread_regcache_data (thread);
+  regcache *regcache = thread->regcache ();
 
   if (regcache != NULL)
     {
       regcache_invalidate_thread (thread);
       free_register_cache (regcache);
-      set_thread_regcache_data (thread, NULL);
+      thread->set_regcache (nullptr);
     }
 }