]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdbserver: refactor the definition and uses of supply_regblock
authorTankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Wed, 29 Jan 2025 09:50:31 +0000 (10:50 +0100)
committerTankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Wed, 29 Jan 2025 10:17:35 +0000 (11:17 +0100)
The supply_regblock function takes a pointer to a buffer as an
argument and implements two different behavior based on the pointer
being null.  There are two cases where we pass nullptr, all in
tracepoint.cc, where we are essentially doing a reset on the regcache.

In fast_tracepoint_ctx::regcache, register_status array does not
even exist.  Hence, that use simply boils down to zeroing of register
data.  Do this at the time of creating the buffer and remove the call
to supply_regblock.

In fetch_traceframe_registers, inline the use with a call to `reset`.

Hence, there are no more cases left, where a nullptr would be passed
to supply_regblock.  Assert that the buffer argument is non-null and
simplify the implementation.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
gdbserver/regcache.cc
gdbserver/tracepoint.cc

index bd053c058ecd0399a5eeff929bd044e962840a2b..06ac372d37bf6f6b2ed17f9b8ff6823dad7f64cf 100644 (file)
@@ -360,18 +360,14 @@ supply_register_by_name_zeroed (struct regcache *regcache,
 void
 supply_regblock (struct regcache *regcache, const void *buf)
 {
-  if (buf)
-    {
-      const struct target_desc *tdesc = regcache->tdesc;
+  gdb_assert (buf != nullptr);
+  const struct target_desc *tdesc = regcache->tdesc;
 
-      memcpy (regcache->registers, buf, tdesc->registers_size);
+  memcpy (regcache->registers, buf, tdesc->registers_size);
 #ifndef IN_PROCESS_AGENT
-      for (int i = 0; i < tdesc->reg_defs.size (); i++)
-       regcache->set_register_status (i, REG_VALID);
+  for (int i = 0; i < tdesc->reg_defs.size (); i++)
+    regcache->set_register_status (i, REG_VALID);
 #endif
-    }
-  else
-    regcache->reset (REG_UNAVAILABLE);
 }
 
 #ifndef IN_PROCESS_AGENT
index 0ed8e8f99948fb5047940a5369c27187152b6922..5e3792e1d2f5143496af4b31000652e6d7b8858c 100644 (file)
@@ -1198,7 +1198,6 @@ struct fast_tracepoint_ctx : public tracepoint_hit_ctx
     if (!this->m_regcache.has_value ())
       {
        this->m_regcache.emplace (ipa_tdesc, this->regspace);
-       supply_regblock (&this->m_regcache.value (), nullptr);
        supply_fast_tracepoint_registers (&this->m_regcache.value (),
                                          this->regs);
       }
@@ -4815,7 +4814,7 @@ fetch_traceframe_registers (int tfnum, struct regcache *regcache, int regnum)
   if (dataptr == NULL)
     {
       /* Mark registers unavailable.  */
-      supply_regblock (regcache, NULL);
+      regcache->reset (REG_UNAVAILABLE);
 
       /* We can generally guess at a PC, although this will be
         misleading for while-stepping frames and multi-location
@@ -5370,6 +5369,8 @@ gdb_collect (struct tracepoint *tpoint, unsigned char *regs)
       return;
     }
 
+  memset (ctx.regspace, 0, ipa_tdesc->registers_size);
+
   for (ctx.tpoint = tpoint;
        ctx.tpoint != NULL && ctx.tpoint->address == tpoint->address;
        ctx.tpoint = ctx.tpoint->next)