aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTankut Baris Aktemur <tankut.baris.aktemur@intel.com>2025-01-29 10:50:32 +0100
committerTankut Baris Aktemur <tankut.baris.aktemur@intel.com>2025-01-29 11:17:35 +0100
commit0cefb59c18b5ceaa5e53d8576b3a653f42ab6ada (patch)
treef8612d436f1d4bb4493ac359873a877d37c25c68
parent84da4a1ea0ae58ef13ce81586f031ca53eb40112 (diff)
downloadgdb-0cefb59c18b5ceaa5e53d8576b3a653f42ab6ada.zip
gdb-0cefb59c18b5ceaa5e53d8576b3a653f42ab6ada.tar.gz
gdb-0cefb59c18b5ceaa5e53d8576b3a653f42ab6ada.tar.bz2
gdbserver: fix the declared type of register_status in regcache
The register_status field of regcache is declared as `unsigned char *`. This is incorrect, because `enum register_status` from gdbsupport/common-regcache.h is based on signed char and REG_UNAVAILABLE is defined as -1. Fix the declared type. Now that we are modifying the declaration, also use a unique_ptr and make the field private. The get/set methods already use the correct type, but we update cast operations in two places. Approved-By: Simon Marchi <simon.marchi@efficios.com>
-rw-r--r--gdbserver/regcache.cc21
-rw-r--r--gdbserver/regcache.h11
2 files changed, 18 insertions, 14 deletions
diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc
index 06ac372..ee0c1b3 100644
--- a/gdbserver/regcache.cc
+++ b/gdbserver/regcache.cc
@@ -130,8 +130,8 @@ regcache::regcache (const target_desc *tdesc)
garbage. */
this->registers
= (unsigned char *) xmalloc (tdesc->registers_size);
- this->register_status
- = (unsigned char *) xmalloc (tdesc->reg_defs.size ());
+ size_t num_regs = tdesc->reg_defs.size ();
+ m_register_status.reset (new enum register_status[num_regs]);
reset (REG_UNKNOWN);
}
@@ -139,7 +139,6 @@ regcache::~regcache ()
{
if (registers_owned)
free (registers);
- free (register_status);
}
#endif
@@ -152,8 +151,8 @@ regcache::reset (enum register_status status)
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 ());
+ for (int i = 0; i < this->tdesc->reg_defs.size (); i++)
+ set_register_status (i, status);
#endif
}
@@ -166,8 +165,8 @@ regcache::copy_from (regcache *src)
memcpy (this->registers, src->registers, src->tdesc->registers_size);
#ifndef IN_PROCESS_AGENT
- if (this->register_status != nullptr && src->register_status != nullptr)
- memcpy (this->register_status, src->register_status,
+ if (m_register_status != nullptr && src->m_register_status != nullptr)
+ memcpy (m_register_status.get (), src->m_register_status.get (),
src->tdesc->reg_defs.size ());
#endif
this->registers_fetched = src->registers_fetched;
@@ -477,8 +476,8 @@ regcache::get_register_status (int regnum) const
{
#ifndef IN_PROCESS_AGENT
gdb_assert (regnum >= 0 && regnum < tdesc->reg_defs.size ());
- if (register_status != nullptr)
- return (enum register_status) (register_status[regnum]);
+ if (m_register_status != nullptr)
+ return m_register_status[regnum];
else
return REG_VALID;
#else
@@ -491,8 +490,8 @@ regcache::set_register_status (int regnum, enum register_status status)
{
#ifndef IN_PROCESS_AGENT
gdb_assert (regnum >= 0 && regnum < tdesc->reg_defs.size ());
- if (register_status != nullptr)
- register_status[regnum] = status;
+ if (m_register_status != nullptr)
+ m_register_status[regnum] = status;
#endif
}
diff --git a/gdbserver/regcache.h b/gdbserver/regcache.h
index f5db119..96d2a4d 100644
--- a/gdbserver/regcache.h
+++ b/gdbserver/regcache.h
@@ -20,6 +20,7 @@
#define GDBSERVER_REGCACHE_H
#include "gdbsupport/common-regcache.h"
+#include <memory>
struct thread_info;
struct target_desc;
@@ -43,9 +44,6 @@ struct regcache : public reg_buffer_common
bool registers_owned = false;
unsigned char *registers = nullptr;
#ifndef IN_PROCESS_AGENT
- /* See gdbsupport/common-regcache.h. */
- unsigned char *register_status = nullptr;
-
/* Construct a regcache using the register layout described by TDESC.
The regcache dynamically allocates its register buffer. */
@@ -90,6 +88,13 @@ struct regcache : public reg_buffer_common
/* Copy the contents of SRC into this regcache. */
void copy_from (regcache *src);
+
+private:
+
+#ifndef IN_PROCESS_AGENT
+ /* See gdbsupport/common-regcache.h. */
+ std::unique_ptr<enum register_status[]> m_register_status;
+#endif
};
regcache *get_thread_regcache (thread_info *thread, bool fetch = true);