gdbserver: convert free_register_cache into a destructor of regcache

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>
This commit is contained in:
Tankut Baris Aktemur
2025-01-29 10:50:30 +01:00
parent ddf8e29147
commit 207bcb60dd
4 changed files with 12 additions and 20 deletions

View File

@@ -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. */

View File

@@ -137,16 +137,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
@@ -241,7 +236,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);
}
}

View File

@@ -50,6 +50,9 @@ struct regcache : public reg_buffer_common
The regcache dynamically allocates its register buffer. */
regcache (const target_desc *tdesc);
/* Destructor. */
~regcache ();
#endif
/* Construct a regcache using the register layout described by TDESC
@@ -87,10 +90,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 *);

View File

@@ -4677,15 +4677,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
{