[v2,05/11] gdbserver: convert free_register_cache into a destructor of regcache
Commit Message
Convert the `free_register_cache` function into a destructor of the
regcache struct. In one place, we completely remove the call to free
the regcache object by stack-allocating the object.
---
gdbserver/gdbthread.h | 2 +-
gdbserver/regcache.cc | 15 +++++----------
gdbserver/regcache.h | 7 +++----
gdbserver/server.cc | 8 +++-----
4 files changed, 12 insertions(+), 20 deletions(-)
Comments
On 2024-12-30 05:49, Tankut Baris Aktemur wrote:
> Convert the `free_register_cache` function into a destructor of the
> regcache struct. In one place, we completely remove the call to free
> the regcache object by stack-allocating the object.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Simon
On 2024-12-30 05:49, Tankut Baris Aktemur wrote:
> Convert the `free_register_cache` function into a destructor of the
> regcache struct. In one place, we completely remove the call to free
> the regcache object by stack-allocating the object.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Simon
@@ -33,7 +33,7 @@ struct thread_info : public intrusive_list_node<thread_info>
~thread_info ()
{
- free_register_cache (m_regcache);
+ delete m_regcache;
}
/* Return the process owning this thread. */
@@ -146,16 +146,11 @@ regcache::regcache (const target_desc *tdesc)
tdesc->reg_defs.size ());
}
-void
-free_register_cache (struct regcache *regcache)
+regcache::~regcache ()
{
- if (regcache)
- {
- if (regcache->registers_owned)
- free (regcache->registers);
- free (regcache->register_status);
- delete regcache;
- }
+ if (registers_owned)
+ free (registers);
+ free (register_status);
}
#endif
@@ -250,7 +245,7 @@ free_register_cache_thread (thread_info *thread)
if (regcache != NULL)
{
regcache_invalidate_thread (thread);
- free_register_cache (regcache);
+ delete regcache;
thread->set_regcache (nullptr);
}
}
@@ -48,6 +48,9 @@ struct regcache : public reg_buffer_common
/* Constructors. */
regcache (const target_desc *tdesc);
+
+ /* Destructor. */
+ ~regcache ();
#endif
regcache (const target_desc *tdesc, unsigned char *regbuf);
@@ -74,10 +77,6 @@ struct regcache : public reg_buffer_common
regcache *get_thread_regcache (thread_info *thread, bool fetch = true);
-/* Release all memory associated with the register cache for INFERIOR. */
-
-void free_register_cache (struct regcache *regcache);
-
/* Invalidate cached registers for one thread. */
void regcache_invalidate_thread (thread_info *);
@@ -4703,15 +4703,13 @@ process_serial_event (void)
require_running_or_break (cs.own_buf);
if (cs.current_traceframe >= 0)
{
- struct regcache *regcache
- = new struct regcache (current_target_desc ());
+ regcache a_regcache (current_target_desc ());
if (fetch_traceframe_registers (cs.current_traceframe,
- regcache, -1) == 0)
- registers_to_string (regcache, cs.own_buf);
+ &a_regcache, -1) == 0)
+ registers_to_string (&a_regcache, cs.own_buf);
else
write_enn (cs.own_buf);
- free_register_cache (regcache);
}
else
{