gdb_assert (proc->tdesc != NULL);
- regcache = new_register_cache (proc->tdesc);
+ regcache = new struct regcache (proc->tdesc);
thread->set_regcache (regcache);
}
#endif
-struct regcache *
-init_register_cache (struct regcache *regcache,
- const struct target_desc *tdesc,
- unsigned char *regbuf)
+regcache::regcache (const target_desc *tdesc, unsigned char *regbuf)
+ : tdesc (tdesc), registers (regbuf)
{
- if (regbuf == NULL)
- {
-#ifndef IN_PROCESS_AGENT
- /* Make sure to zero-initialize the register cache when it is
- 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
- = (unsigned char *) xcalloc (1, tdesc->registers_size);
- regcache->registers_owned = true;
- regcache->register_status
- = (unsigned char *) xmalloc (tdesc->reg_defs.size ());
- memset ((void *) regcache->register_status, REG_UNAVAILABLE,
- tdesc->reg_defs.size ());
-#else
- gdb_assert_not_reached ("can't allocate memory from the heap");
-#endif
- }
- else
- {
- regcache->tdesc = tdesc;
- regcache->registers = regbuf;
- regcache->registers_owned = false;
-#ifndef IN_PROCESS_AGENT
- regcache->register_status = NULL;
-#endif
- }
-
- regcache->registers_fetched = false;
-
- return regcache;
+ gdb_assert (regbuf != nullptr);
}
#ifndef IN_PROCESS_AGENT
-struct regcache *
-new_register_cache (const struct target_desc *tdesc)
+regcache::regcache (const target_desc *tdesc)
+ : tdesc (tdesc), registers_owned (true)
{
- struct regcache *regcache = new struct regcache;
-
gdb_assert (tdesc->registers_size != 0);
- return init_register_cache (regcache, tdesc, NULL);
+ /* Make sure to zero-initialize the register cache when it is
+ created, in case there are registers the target never
+ fetches. This way they'll read as zero instead of
+ garbage. */
+ this->registers
+ = (unsigned char *) xcalloc (1, tdesc->registers_size);
+ this->register_status
+ = (unsigned char *) xmalloc (tdesc->reg_defs.size ());
+ memset ((void *) this->register_status, REG_UNAVAILABLE,
+ tdesc->reg_defs.size ());
}
void
#ifndef IN_PROCESS_AGENT
/* One of REG_UNAVAILABLE or REG_VALID. */
unsigned char *register_status = nullptr;
+
+ /* Construct a regcache using the register layout described by TDESC.
+
+ The regcache dynamically allocates its register buffer. */
+ regcache (const target_desc *tdesc);
#endif
+ /* Construct a regcache using the register layout described by TDESC
+ and REGBUF as the register buffer.
+
+ The regcache does *not* take ownership of the buffer. */
+ regcache (const target_desc *tdesc, unsigned char *regbuf);
+
+ DISABLE_COPY_AND_ASSIGN (regcache);
+
/* See gdbsupport/common-regcache.h. */
enum register_status get_register_status (int regnum) const override;
void copy_from (regcache *src);
};
-struct regcache *init_register_cache (struct regcache *regcache,
- const struct target_desc *tdesc,
- unsigned char *regbuf);
-
-/* Create a new register cache for INFERIOR. */
-
-struct regcache *new_register_cache (const struct target_desc *tdesc);
-
regcache *get_thread_regcache (thread_info *thread, bool fetch = true);
/* Release all memory associated with the register cache for INFERIOR. */
if (cs.current_traceframe >= 0)
{
struct regcache *regcache
- = new_register_cache (current_target_desc ());
+ = new struct regcache (current_target_desc ());
if (fetch_traceframe_registers (cs.current_traceframe,
regcache, -1) == 0)
{
const struct target_desc *ipa_tdesc = get_ipa_tdesc (ipa_tdesc_idx);
- if (!this->m_regcache_initted)
+ if (!this->m_regcache.has_value ())
{
- this->m_regcache_initted = 1;
- init_register_cache (&this->m_regcache, ipa_tdesc, this->regspace);
- supply_regblock (&this->m_regcache, nullptr);
- supply_fast_tracepoint_registers (&this->m_regcache, this->regs);
+ 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);
}
- return &this->m_regcache;
+ return &this->m_regcache.value ();
}
/* The buffer space M_REGCACHE uses. We use a separate buffer
/* The regcache corresponding to the registers state at the time of
the tracepoint hit. Initialized lazily, from REGS. */
- struct regcache m_regcache;
- int m_regcache_initted = 0;
+ std::optional<struct regcache> m_regcache;
};
#else
case 'R':
{
unsigned char *regspace;
- struct regcache tregcache;
int regcache_size;
trace_debug ("Want to collect registers");
/* 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);
+ regcache tregcache (context_regcache->tdesc, regspace + 1);
/* Copy the register data to the regblock. */
tregcache.copy_from (context_regcache);
static CORE_ADDR
traceframe_get_pc (struct traceframe *tframe)
{
- struct regcache regcache;
unsigned char *dataptr;
const struct target_desc *tdesc = current_target_desc ();
if (dataptr == NULL)
return 0;
- init_register_cache (®cache, tdesc, dataptr);
+ regcache regcache (tdesc, dataptr);
return regcache_read_pc (®cache);
}