]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdbserver: convert free_register_cache into a destructor of regcache
authorTankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Wed, 29 Jan 2025 09:50:30 +0000 (10:50 +0100)
committerTankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Wed, 29 Jan 2025 10:17:34 +0000 (11:17 +0100)
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>
gdbserver/gdbthread.h
gdbserver/regcache.cc
gdbserver/regcache.h
gdbserver/server.cc

index d7b5bc3e1538bde8eafd0f3253706924d7330a21..d3459582a1fa503ad2c4a0d5bb448e920c36b2e3 100644 (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.  */
index 557e38572a88d97d6652f55801a75a2cb3220ff8..0b451acc0f0ba72b199125f1685b95a51ec0dc10 100644 (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);
     }
 }
index 2fab5d01fc4fc3cbed7735151989d7ca98ec45c8..1a252d40255017100dd86c532f4a22f937e7f7d9 100644 (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 *);
index 779af6d4e1107f00c75fd56d84c0d6c3ed76403f..fb1a3f8b4152bfdec593c3fb0d7f7121597a77b7 100644 (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
        {