aboutsummaryrefslogtreecommitdiff
path: root/gdb/regcache.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@ericsson.com>2018-06-09 22:30:34 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2018-06-09 22:30:42 -0400
commit835dcf92618e294d3c6c2bedd94af712809c96a3 (patch)
tree4c93c85f195721f4d89dd4d85b492d2670a4fe2a /gdb/regcache.c
parentaac0d564cea04b1c5f386e8cea924ca59057e8b4 (diff)
downloadgdb-835dcf92618e294d3c6c2bedd94af712809c96a3.zip
gdb-835dcf92618e294d3c6c2bedd94af712809c96a3.tar.gz
gdb-835dcf92618e294d3c6c2bedd94af712809c96a3.tar.bz2
Use std::unique_ptr in reg_buffer
Using std::unique_ptr allows to remove the manual xfree in the destructor. If I understand correctly, using the () after the new operator will make sure the allocated objects will be value initialized, which for scalars means they are zero-initialized. So it should have the same behavior as XCNEWVEC. gdb/ChangeLog: * regcache.h (reg_buffer) <~reg_buffer>: Use default destructor. <m_registers, m_register_status>: Change type to std::unique_ptr. * regcache.c (reg_buffer::reg_buffer): Use new instead of XCNEWVEC.
Diffstat (limited to 'gdb/regcache.c')
-rw-r--r--gdb/regcache.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/gdb/regcache.c b/gdb/regcache.c
index 626d424..3eed7b6 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -185,15 +185,15 @@ 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)] ());
}
}
@@ -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