[v2,06/11] gdbserver: use unique_ptr for thread_info's regcache

Message ID 20241230-upstream-gdbserver-regcache-v2-6-020a9514fcf0@intel.com
State New
Headers
Series gdbserver: refactor regcache |

Commit Message

Aktemur, Tankut Baris Dec. 30, 2024, 10:49 a.m. UTC
  Store the regcache pointer in thread_info as a unique_ptr.  This
allows us delete the thread_info destructor.
---
 gdbserver/gdbthread.h | 12 ++++--------
 gdbserver/regcache.cc |  1 -
 2 files changed, 4 insertions(+), 9 deletions(-)
  

Patch

diff --git a/gdbserver/gdbthread.h b/gdbserver/gdbthread.h
index d3459582a1fa503ad2c4a0d5bb448e920c36b2e3..33ebf0e3679eaea8b8f38945986813f46f1dcff8 100644
--- a/gdbserver/gdbthread.h
+++ b/gdbserver/gdbthread.h
@@ -21,6 +21,7 @@ 
 
 #include "gdbsupport/function-view.h"
 #include "gdbsupport/intrusive_list.h"
+#include <memory>
 
 struct btrace_target_info;
 struct regcache;
@@ -31,20 +32,15 @@  struct thread_info : public intrusive_list_node<thread_info>
     : id (id), m_process (process), m_target_data (target_data)
   {}
 
-  ~thread_info ()
-  {
-    delete m_regcache;
-  }
-
   /* Return the process owning this thread.  */
   process_info *process () const
   { return m_process; }
 
   struct regcache *regcache ()
-  { return m_regcache; }
+  { return m_regcache.get (); }
 
   void set_regcache (struct regcache *regcache)
-  { m_regcache = regcache; }
+  { m_regcache.reset (regcache); }
 
   void *target_data ()
   { return m_target_data; }
@@ -94,7 +90,7 @@  struct thread_info : public intrusive_list_node<thread_info>
   
 private:
   process_info *m_process;
-  struct regcache *m_regcache = nullptr;
+  std::unique_ptr<struct regcache> m_regcache = nullptr;
   void *m_target_data;
 };
 
diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc
index e33c0c650dbcb7c3d28930d5bc4099932e13ec13..bd2f5a6af8298d2961c1f589a52a8fbf9c9a6c8a 100644
--- a/gdbserver/regcache.cc
+++ b/gdbserver/regcache.cc
@@ -245,7 +245,6 @@  free_register_cache_thread (thread_info *thread)
   if (regcache != NULL)
     {
       regcache_invalidate_thread (thread);
-      delete regcache;
       thread->set_regcache (nullptr);
     }
 }