diff --git a/gdb/gdbserver/linux-amd64-ipa.c b/gdb/gdbserver/linux-amd64-ipa.c
index a6dfb03..78125d7 100644
--- a/gdb/gdbserver/linux-amd64-ipa.c
+++ b/gdb/gdbserver/linux-amd64-ipa.c
@@ -68,15 +68,6 @@ supply_fast_tracepoint_registers (struct regcache *regcache,
 		     ((char *) buf) + x86_64_ft_collect_regmap[i]);
 }
 
-IP_AGENT_EXPORT_FUNC ULONGEST
-gdb_agent_get_raw_reg (const unsigned char *raw_regs, int regnum)
-{
-  if (regnum >= X86_64_NUM_FT_COLLECT_GREGS)
-    return 0;
-
-  return *(ULONGEST *) (raw_regs + x86_64_ft_collect_regmap[regnum]);
-}
-
 #ifdef HAVE_UST
 
 #include <ust/processor.h>
diff --git a/gdb/gdbserver/linux-i386-ipa.c b/gdb/gdbserver/linux-i386-ipa.c
index de8d394..6be87ad 100644
--- a/gdb/gdbserver/linux-i386-ipa.c
+++ b/gdb/gdbserver/linux-i386-ipa.c
@@ -98,21 +98,6 @@ supply_fast_tracepoint_registers (struct regcache *regcache,
     }
 }
 
-IP_AGENT_EXPORT_FUNC ULONGEST
-gdb_agent_get_raw_reg (const unsigned char *raw_regs, int regnum)
-{
-  /* This should maybe be allowed to return an error code, or perhaps
-     better, have the emit_reg detect this, and emit a constant zero,
-     or something.  */
-
-  if (regnum > i386_num_regs)
-    return 0;
-  else if (regnum >= I386_CS_REGNUM && regnum <= I386_GS_REGNUM)
-    return *(short *) (raw_regs + i386_ft_collect_regmap[regnum]);
-  else
-    return *(int *) (raw_regs + i386_ft_collect_regmap[regnum]);
-}
-
 #ifdef HAVE_UST
 
 #include <ust/processor.h>
diff --git a/gdb/gdbserver/linux-x86-low.c b/gdb/gdbserver/linux-x86-low.c
index 20d4257..3fb447d 100644
--- a/gdb/gdbserver/linux-x86-low.c
+++ b/gdb/gdbserver/linux-x86-low.c
@@ -2287,7 +2287,7 @@ amd64_emit_reg (int reg)
   i += 4;
   append_insns (&buildaddr, i, buf);
   current_insn_ptr = buildaddr;
-  amd64_emit_call (get_raw_reg_func_addr ());
+  amd64_emit_call (get_reg_func_addr ());
 }
 
 static void
@@ -2896,7 +2896,7 @@ i386_emit_reg (int reg)
 	    "mov %eax,4(%esp)\n\t"
 	    "mov 8(%ebp),%eax\n\t"
 	    "mov %eax,(%esp)");
-  i386_emit_call (get_raw_reg_func_addr ());
+  i386_emit_call (get_reg_func_addr ());
   EMIT_ASM32 (i386_reg_c,
 	    "xor %ebx,%ebx\n\t"
 	    "lea 0x8(%esp),%esp");
diff --git a/gdb/gdbserver/tracepoint.c b/gdb/gdbserver/tracepoint.c
index fd010ae..113848c 100644
--- a/gdb/gdbserver/tracepoint.c
+++ b/gdb/gdbserver/tracepoint.c
@@ -126,7 +126,7 @@ trace_vdebug (const char *fmt, ...)
 # define traceframe_write_count IPA_SYM_EXPORTED_NAME (traceframe_write_count)
 # define traceframes_created IPA_SYM_EXPORTED_NAME (traceframes_created)
 # define trace_state_variables IPA_SYM_EXPORTED_NAME (trace_state_variables)
-# define get_raw_reg IPA_SYM_EXPORTED_NAME (get_raw_reg)
+# define get_reg IPA_SYM_EXPORTED_NAME (get_reg)
 # define get_trace_state_variable_value \
   IPA_SYM_EXPORTED_NAME (get_trace_state_variable_value)
 # define set_trace_state_variable_value \
@@ -167,7 +167,7 @@ struct ipa_sym_addresses
   CORE_ADDR addr_traceframe_write_count;
   CORE_ADDR addr_traceframes_created;
   CORE_ADDR addr_trace_state_variables;
-  CORE_ADDR addr_get_raw_reg;
+  CORE_ADDR addr_get_reg;
   CORE_ADDR addr_get_trace_state_variable_value;
   CORE_ADDR addr_set_trace_state_variable_value;
   CORE_ADDR addr_ust_loaded;
@@ -203,7 +203,7 @@ static struct
   IPA_SYM(traceframe_write_count),
   IPA_SYM(traceframes_created),
   IPA_SYM(trace_state_variables),
-  IPA_SYM(get_raw_reg),
+  IPA_SYM(get_reg),
   IPA_SYM(get_trace_state_variable_value),
   IPA_SYM(set_trace_state_variable_value),
   IPA_SYM(ust_loaded),
@@ -1306,10 +1306,8 @@ struct fast_tracepoint_ctx
   struct tracepoint_hit_ctx base;
 
   struct regcache regcache;
-  int regcache_initted;
   unsigned char *regspace;
 
-  unsigned char *regs;
   struct tracepoint *tpoint;
 };
 
@@ -4724,13 +4722,6 @@ get_context_regcache (struct tracepoint_hit_ctx *ctx)
   if (ctx->type == fast_tracepoint)
     {
       struct fast_tracepoint_ctx *fctx = (struct fast_tracepoint_ctx *) ctx;
-      if (!fctx->regcache_initted)
-	{
-	  fctx->regcache_initted = 1;
-	  init_register_cache (&fctx->regcache, ipa_tdesc, fctx->regspace);
-	  supply_regblock (&fctx->regcache, NULL);
-	  supply_fast_tracepoint_registers (&fctx->regcache, fctx->regs);
-	}
       regcache = &fctx->regcache;
     }
 #ifdef HAVE_UST
@@ -5796,11 +5787,16 @@ gdb_collect (struct tracepoint *tpoint, unsigned char *regs)
     return;
 
   ctx.base.type = fast_tracepoint;
-  ctx.regs = regs;
-  ctx.regcache_initted = 0;
   /* Wrap the regblock in a register cache (in the stack, we don't
      want to malloc here).  */
   ctx.regspace = alloca (ipa_tdesc->registers_size);
+
+  /* Initialize the regcache with registers from the stack set up by jump
+     pad.  */
+  init_register_cache (&ctx.regcache, ipa_tdesc, ctx.regspace);
+  supply_regblock (&ctx.regcache, NULL);
+  supply_fast_tracepoint_registers (&ctx.regcache, regs);
+
   if (ctx.regspace == NULL)
     {
       trace_debug ("Trace buffer block allocation failed, skipping");
@@ -5853,14 +5849,28 @@ gdb_collect (struct tracepoint *tpoint, unsigned char *regs)
     }
 }
 
+/* This function is called from native code generated for the emit_reg
+   agent expression bytecode.  It returns the value of register number
+   REGNUM read from regcache contained into CTX.  */
+
+IP_AGENT_EXPORT_FUNC ULONGEST
+gdb_agent_get_reg (struct fast_tracepoint_ctx *ctx, int regnum)
+{
+  ULONGEST reg;
+
+  collect_register (&ctx->regcache, regnum, &reg);
+
+  return reg;
+}
+
 #endif
 
 #ifndef IN_PROCESS_AGENT
 
 CORE_ADDR
-get_raw_reg_func_addr (void)
+get_reg_func_addr (void)
 {
-  return ipa_sym_addrs.addr_get_raw_reg;
+  return ipa_sym_addrs.addr_get_reg;
 }
 
 CORE_ADDR
diff --git a/gdb/gdbserver/tracepoint.h b/gdb/gdbserver/tracepoint.h
index 30d0b58..3a96487 100644
--- a/gdb/gdbserver/tracepoint.h
+++ b/gdb/gdbserver/tracepoint.h
@@ -163,13 +163,8 @@ int agent_mem_read_string (struct eval_agent_expr_context *ctx,
 			   CORE_ADDR from,
 			   ULONGEST len);
 
-/* The prototype the get_raw_reg function in the IPA.  Each arch's
-   bytecode compiler emits calls to this function.  */
-IP_AGENT_EXPORT_FUNC ULONGEST gdb_agent_get_raw_reg
-  (const unsigned char *raw_regs, int regnum);
-
-/* Returns the address of the get_raw_reg function in the IPA.  */
-CORE_ADDR get_raw_reg_func_addr (void);
+/* Returns the address of the get_reg function in the IPA.  */
+CORE_ADDR get_reg_func_addr (void);
 /* Returns the address of the get_trace_state_variable_value
    function in the IPA.  */
 CORE_ADDR get_get_tsv_func_addr (void);
