diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc
index 0b1141662ac..7987c406ab4 100644
--- a/gdbserver/regcache.cc
+++ b/gdbserver/regcache.cc
@@ -113,10 +113,9 @@ regcache_invalidate (void)
 
 #endif
 
-struct regcache *
-init_register_cache (struct regcache *regcache,
-		     const struct target_desc *tdesc,
-		     unsigned char *regbuf)
+void
+regcache::initialize (const target_desc *tdesc,
+		      unsigned char *regbuf)
 {
   if (regbuf == NULL)
     {
@@ -125,13 +124,13 @@ init_register_cache (struct regcache *regcache,
 	 created, in case there are registers the target never
 	 fetches.  This way they'll read as zero instead of
 	 garbage.  */
-      regcache->tdesc = tdesc;
-      regcache->registers
+      this->tdesc = tdesc;
+      this->registers
 	= (unsigned char *) xcalloc (1, tdesc->registers_size);
-      regcache->registers_owned = 1;
-      regcache->register_status
+      this->registers_owned = 1;
+      this->register_status
 	= (unsigned char *) xmalloc (tdesc->reg_defs.size ());
-      memset ((void *) regcache->register_status, REG_UNAVAILABLE,
+      memset ((void *) this->register_status, REG_UNAVAILABLE,
 	      tdesc->reg_defs.size ());
 #else
       gdb_assert_not_reached ("can't allocate memory from the heap");
@@ -139,17 +138,15 @@ init_register_cache (struct regcache *regcache,
     }
   else
     {
-      regcache->tdesc = tdesc;
-      regcache->registers = regbuf;
-      regcache->registers_owned = 0;
+      this->tdesc = tdesc;
+      this->registers = regbuf;
+      this->registers_owned = 0;
 #ifndef IN_PROCESS_AGENT
-      regcache->register_status = NULL;
+      this->register_status = nullptr;
 #endif
     }
 
-  regcache->registers_valid = 0;
-
-  return regcache;
+  this->registers_valid = 0;
 }
 
 #ifndef IN_PROCESS_AGENT
@@ -160,8 +157,9 @@ new_register_cache (const struct target_desc *tdesc)
   struct regcache *regcache = new struct regcache;
 
   gdb_assert (tdesc->registers_size != 0);
+  regcache->initialize (tdesc, nullptr);
 
-  return init_register_cache (regcache, tdesc, NULL);
+  return regcache;
 }
 
 void
diff --git a/gdbserver/regcache.h b/gdbserver/regcache.h
index 7248bcf5808..15b7e2b4dff 100644
--- a/gdbserver/regcache.h
+++ b/gdbserver/regcache.h
@@ -46,6 +46,9 @@ struct regcache : public reg_buffer_common
   unsigned char *register_status = nullptr;
 #endif
 
+  /* Init the regcache data.  */
+  void initialize (const target_desc *tdesc, unsigned char *regbuf);
+
   /* See gdbsupport/common-regcache.h.  */
   enum register_status get_register_status (int regnum) const override;
 
@@ -59,10 +62,6 @@ struct regcache : public reg_buffer_common
   bool raw_compare (int regnum, const void *buf, int offset) const override;
 };
 
-struct regcache *init_register_cache (struct regcache *regcache,
-				      const struct target_desc *tdesc,
-				      unsigned char *regbuf);
-
 void regcache_cpy (struct regcache *dst, struct regcache *src);
 
 /* Create a new register cache for INFERIOR.  */
diff --git a/gdbserver/tracepoint.cc b/gdbserver/tracepoint.cc
index 3f60989e4c7..e4715b95eb3 100644
--- a/gdbserver/tracepoint.cc
+++ b/gdbserver/tracepoint.cc
@@ -4706,7 +4706,7 @@ get_context_regcache (struct tracepoint_hit_ctx *ctx)
       if (!fctx->regcache_initted)
 	{
 	  fctx->regcache_initted = 1;
-	  init_register_cache (&fctx->regcache, ipa_tdesc, fctx->regspace);
+	  fctx->regcache.initialize (ipa_tdesc, fctx->regspace);
 	  supply_regblock (&fctx->regcache, NULL);
 	  supply_fast_tracepoint_registers (&fctx->regcache, fctx->regs);
 	}
@@ -4721,7 +4721,7 @@ get_context_regcache (struct tracepoint_hit_ctx *ctx)
       if (!sctx->regcache_initted)
 	{
 	  sctx->regcache_initted = 1;
-	  init_register_cache (&sctx->regcache, ipa_tdesc, sctx->regspace);
+	  sctx->regcache.initialize (ipa_tdesc, sctx->regspace);
 	  supply_regblock (&sctx->regcache, NULL);
 	  /* Pass down the tracepoint address, because REGS doesn't
 	     include the PC, but we know what it must have been.  */
@@ -4799,8 +4799,7 @@ do_action_at_tracepoint (struct tracepoint_hit_ctx *ctx,
 
 	/* Wrap the regblock in a register cache (in the stack, we
 	   don't want to malloc here).  */
-	init_register_cache (&tregcache, context_regcache->tdesc,
-			     regspace + 1);
+	tregcache.initialize (context_regcache->tdesc, regspace + 1);
 
 	/* Copy the register data to the regblock.  */
 	regcache_cpy (&tregcache, context_regcache);
@@ -5207,7 +5206,7 @@ traceframe_get_pc (struct traceframe *tframe)
   if (dataptr == NULL)
     return 0;
 
-  init_register_cache (&regcache, tdesc, dataptr);
+  regcache.initialize (tdesc, dataptr);
   return regcache_read_pc (&regcache);
 }
 
