[PATCH 22/26] gdbserver: zero-out register values in regcache-discard

Tankut Baris Aktemur via Gdb-patches
2023-02-28T11:32:23Z

Zero-out register values when a regcache is discarded so that we avoid
garbage values left in the buffer.
---
gdbserver/regcache.cc | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc
index 2befb30e337..644f436c681 100644
--- a/gdbserver/regcache.cc
+++ b/gdbserver/regcache.cc
@@ -136,6 +136,7 @@ regcache_invalidate (void)
void
regcache::discard ()
{
+ memset (registers, 0, tdesc->registers_size);
#ifndef IN_PROCESS_AGENT
memset ((void *) register_status, REG_UNKNOWN, tdesc->reg_defs.size ());
#endif
@@ -149,16 +150,17 @@ regcache::initialize (const target_desc *tdesc,
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. */
this->tdesc = tdesc;
this->registers
- = (unsigned char *) xcalloc (1, tdesc->registers_size);
+ = (unsigned char *) xmalloc (tdesc->registers_size);
this->registers_owned = true;
this->register_status
= (enum register_status *) xmalloc (tdesc->reg_defs.size ());
+
+ /* 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. */
discard ();
#else
gdb_assert_not_reached ("can't allocate memory from the heap");
--
2.25.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva