mirror of
https://github.com/bminor/binutils-gdb.git
synced 2025-11-16 12:34:43 +00:00
gdbserver: define and use regcache::reset
Define a `reset` method for a regcache and use it for code simplification. This patch allows further simplification in the next patch. The reset method fills the register data with zeroes. For the use in get_thread_regcache, this is added behavior, making the patch not a pure refactoring, and may look like extra overhead. However, it is better to avoid having arbitrary values left in the data buffer. Hence, it is considered a behavioral improvement. Approved-By: Simon Marchi <simon.marchi@efficios.com>
This commit is contained in:
@@ -52,8 +52,7 @@ get_thread_regcache (thread_info *thread, bool fetch)
|
||||
|
||||
switch_to_thread (thread);
|
||||
/* Invalidate all registers, to prevent stale left-overs. */
|
||||
memset (regcache->register_status, REG_UNKNOWN,
|
||||
regcache->tdesc->reg_defs.size ());
|
||||
regcache->reset (REG_UNKNOWN);
|
||||
fetch_inferior_registers (regcache, -1);
|
||||
regcache->registers_fetched = true;
|
||||
}
|
||||
@@ -130,11 +129,10 @@ regcache::regcache (const target_desc *tdesc)
|
||||
fetches. This way they'll read as zero instead of
|
||||
garbage. */
|
||||
this->registers
|
||||
= (unsigned char *) xcalloc (1, tdesc->registers_size);
|
||||
= (unsigned char *) xmalloc (tdesc->registers_size);
|
||||
this->register_status
|
||||
= (unsigned char *) xmalloc (tdesc->reg_defs.size ());
|
||||
memset ((void *) this->register_status, REG_UNKNOWN,
|
||||
tdesc->reg_defs.size ());
|
||||
reset (REG_UNKNOWN);
|
||||
}
|
||||
|
||||
regcache::~regcache ()
|
||||
@@ -146,6 +144,19 @@ regcache::~regcache ()
|
||||
|
||||
#endif
|
||||
|
||||
void
|
||||
regcache::reset (enum register_status status)
|
||||
{
|
||||
/* Zero-initialize the register cache, in case there are registers
|
||||
the target never fetches. This way they'll read as zero instead
|
||||
of garbage. */
|
||||
memset (this->registers, 0, this->tdesc->registers_size);
|
||||
#ifndef IN_PROCESS_AGENT
|
||||
if (this->register_status != nullptr)
|
||||
memset (this->register_status, status, this->tdesc->reg_defs.size ());
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
regcache::copy_from (regcache *src)
|
||||
{
|
||||
@@ -360,15 +371,7 @@ supply_regblock (struct regcache *regcache, const void *buf)
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
const struct target_desc *tdesc = regcache->tdesc;
|
||||
|
||||
memset (regcache->registers, 0, tdesc->registers_size);
|
||||
#ifndef IN_PROCESS_AGENT
|
||||
for (int i = 0; i < tdesc->reg_defs.size (); i++)
|
||||
regcache->set_register_status (i, REG_UNAVAILABLE);
|
||||
#endif
|
||||
}
|
||||
regcache->reset (REG_UNAVAILABLE);
|
||||
}
|
||||
|
||||
#ifndef IN_PROCESS_AGENT
|
||||
|
||||
@@ -63,6 +63,10 @@ struct regcache : public reg_buffer_common
|
||||
|
||||
DISABLE_COPY_AND_ASSIGN (regcache);
|
||||
|
||||
/* Clear the register values to all zeros and set the register
|
||||
statuses to STATUS. */
|
||||
void reset (enum register_status status);
|
||||
|
||||
/* See gdbsupport/common-regcache.h. */
|
||||
enum register_status get_register_status (int regnum) const override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user