aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@ericsson.com>2018-05-28 11:04:27 -0400
committerSimon Marchi <simon.marchi@ericsson.com>2018-05-31 15:14:32 -0400
commitca9f66e37913be55abaea44813a768b40673a39a (patch)
tree219e63369b91bfc3d01e62ffd7ab1b06a8784e1e
parente8b8d8255c78db77e72169a1a5d56f8e395e04ea (diff)
downloadgdb-ca9f66e37913be55abaea44813a768b40673a39a.zip
gdb-ca9f66e37913be55abaea44813a768b40673a39a.tar.gz
gdb-ca9f66e37913be55abaea44813a768b40673a39a.tar.bz2
Use unique_ptr in reg-buffer
-rw-r--r--gdb/regcache.c18
-rw-r--r--gdb/regcache.h11
2 files changed, 13 insertions, 16 deletions
diff --git a/gdb/regcache.c b/gdb/regcache.c
index 0e03071..7d950ff 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -185,18 +185,18 @@ reg_buffer::reg_buffer (gdbarch *gdbarch, bool has_pseudo)
if (has_pseudo)
{
- m_registers = XCNEWVEC (gdb_byte, m_descr->sizeof_cooked_registers);
- m_register_status
- = XCNEWVEC (register_status, m_descr->nr_cooked_registers);
+ m_registers.reset (new gdb_byte[m_descr->sizeof_cooked_registers] ());
+ m_register_status.reset (new register_status[m_descr->nr_cooked_registers] ());
}
else
{
- m_registers = XCNEWVEC (gdb_byte, m_descr->sizeof_raw_registers);
- m_register_status
- = XCNEWVEC (register_status, gdbarch_num_regs (gdbarch));
+ m_registers.reset (new gdb_byte[m_descr->sizeof_raw_registers] ());
+ m_register_status.reset (new register_status[gdbarch_num_regs (gdbarch)] ());
}
}
+reg_buffer::~reg_buffer () = default;
+
regcache::regcache (gdbarch *gdbarch, const address_space *aspace_)
/* The register buffers. A read/write register cache can only hold
[0 .. gdbarch_num_regs). */
@@ -260,7 +260,7 @@ private:
gdb_byte *
reg_buffer::register_buffer (int regnum) const
{
- return m_registers + m_descr->register_offset[regnum];
+ return m_registers.get () + m_descr->register_offset[regnum];
}
void
@@ -273,8 +273,8 @@ reg_buffer::save (regcache_cooked_read_ftype *cooked_read,
/* It should have pseudo registers. */
gdb_assert (m_has_pseudo);
/* Clear the dest. */
- memset (m_registers, 0, m_descr->sizeof_cooked_registers);
- memset (m_register_status, REG_UNKNOWN, m_descr->nr_cooked_registers);
+ memset (m_registers.get (), 0, m_descr->sizeof_cooked_registers);
+ memset (m_register_status.get (), REG_UNKNOWN, m_descr->nr_cooked_registers);
/* Copy over any registers (identified by their membership in the
save_reggroup) and mark them as valid. The full [0 .. gdbarch_num_regs +
gdbarch_num_pseudo_regs) range is checked since some architectures need
diff --git a/gdb/regcache.h b/gdb/regcache.h
index 1001eed..bf2e0c9 100644
--- a/gdb/regcache.h
+++ b/gdb/regcache.h
@@ -153,11 +153,8 @@ public:
buffer. */
enum register_status get_register_status (int regnum) const;
- virtual ~reg_buffer ()
- {
- xfree (m_registers);
- xfree (m_register_status);
- }
+ virtual ~reg_buffer () = 0;
+
protected:
/* Assert on the range of REGNUM. */
void assert_regnum (int regnum) const;
@@ -175,9 +172,9 @@ protected:
bool m_has_pseudo;
/* The register buffers. */
- gdb_byte *m_registers;
+ std::unique_ptr<gdb_byte[]> m_registers;
/* Register cache status. */
- register_status *m_register_status;
+ std::unique_ptr<register_status[]> m_register_status;
friend class regcache;
friend class detached_regcache;