aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTankut Baris Aktemur <tankut.baris.aktemur@intel.com>2025-01-29 10:50:30 +0100
committerTankut Baris Aktemur <tankut.baris.aktemur@intel.com>2025-01-29 11:17:34 +0100
commit41ef481066787b9c72eda27810959f18ddd84f93 (patch)
treebfc8a6fb44bc6f0edfea46b036493c7511e8a3b5
parent207bcb60ddeccc2c15a9ae91952e191ba7795fbc (diff)
downloadbinutils-41ef481066787b9c72eda27810959f18ddd84f93.zip
binutils-41ef481066787b9c72eda27810959f18ddd84f93.tar.gz
binutils-41ef481066787b9c72eda27810959f18ddd84f93.tar.bz2
gdbserver: use unique_ptr for thread_info's regcache
Store the regcache pointer in thread_info as a unique_ptr. This allows us delete the thread_info destructor. Approved-By: Simon Marchi <simon.marchi@efficios.com>
-rw-r--r--gdbserver/gdbthread.h14
-rw-r--r--gdbserver/regcache.cc5
2 files changed, 7 insertions, 12 deletions
diff --git a/gdbserver/gdbthread.h b/gdbserver/gdbthread.h
index d345958..d6e90b1 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; }
+ void set_regcache (std::unique_ptr<struct regcache> regcache)
+ { m_regcache = std::move (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 0b451ac..99291e4 100644
--- a/gdbserver/regcache.cc
+++ b/gdbserver/regcache.cc
@@ -42,8 +42,8 @@ get_thread_regcache (thread_info *thread, bool fetch)
gdb_assert (proc->tdesc != NULL);
- regcache = new struct regcache (proc->tdesc);
- thread->set_regcache (regcache);
+ thread->set_regcache (std::make_unique<struct regcache> (proc->tdesc));
+ regcache = thread->regcache ();
}
if (fetch && !regcache->registers_fetched)
@@ -236,7 +236,6 @@ free_register_cache_thread (thread_info *thread)
if (regcache != NULL)
{
regcache_invalidate_thread (thread);
- delete regcache;
thread->set_regcache (nullptr);
}
}