+2018-10-03 Tom Tromey <tom@tromey.com>
+
+ * dwarf2-frame.h (dwarf2_frame_state_reg_info)
+ <~dwarf2_frame_state_reg_info>: Update.
+ <dwarf2_frame_state_reg_info>: Update.
+ <alloc_regs>: Add assertion. Update.
+ <reg>: Now a std::vector.
+ <num_regs>: Remove.
+ <swap>: Update.
+ * dwarf2-frame.c (dwarf2_restore_rule, execute_cfa_program)
+ (execute_cfa_program_test, dwarf2_frame_cache): Update.
+
2018-10-03 Tom Tromey <tom@tromey.com>
* namespace.c (add_using_directive): Don't pass NULL to memcpy.
{
ULONGEST reg;
- gdb_assert (fs->initial.reg);
reg = dwarf2_frame_adjust_regnum (gdbarch, reg_num, eh_frame_p);
fs->regs.alloc_regs (reg + 1);
/* Check if this register was explicitly initialized in the
CIE initial instructions. If not, default the rule to
UNSPECIFIED. */
- if (reg < fs->initial.num_regs)
+ if (reg < fs->initial.reg.size ())
fs->regs.reg[reg] = fs->initial.reg[reg];
else
fs->regs.reg[reg].how = DWARF2_FRAME_REG_UNSPECIFIED;
}
}
- if (fs->initial.reg == NULL)
+ if (fs->initial.reg.empty ())
{
/* Don't allow remember/restore between CIE and FDE programs. */
delete fs->regs.prev;
auto r1 = dwarf2_frame_adjust_regnum (gdbarch, 1, fde.eh_frame_p);
auto r2 = dwarf2_frame_adjust_regnum (gdbarch, 2, fde.eh_frame_p);
- SELF_CHECK (fs.regs.num_regs == (std::max (r1, r2) + 1));
+ SELF_CHECK (fs.regs.reg.size () == (std::max (r1, r2) + 1));
SELF_CHECK (fs.regs.reg[r2].how == DWARF2_FRAME_REG_SAVED_OFFSET);
SELF_CHECK (fs.regs.reg[r2].loc.offset == -4);
- for (auto i = 0; i < fs.regs.num_regs; i++)
+ for (auto i = 0; i < fs.regs.reg.size (); i++)
if (i != r2)
SELF_CHECK (fs.regs.reg[i].how == DWARF2_FRAME_REG_UNSPECIFIED);
{
int column; /* CFI speak for "register number". */
- for (column = 0; column < fs.regs.num_regs; column++)
+ for (column = 0; column < fs.regs.reg.size (); column++)
{
/* Use the GDB register number as the destination index. */
int regnum = dwarf_reg_to_regnum (gdbarch, column);
if (cache->reg[regnum].how == DWARF2_FRAME_REG_RA
|| cache->reg[regnum].how == DWARF2_FRAME_REG_RA_OFFSET)
{
- struct dwarf2_frame_state_reg *retaddr_reg =
- &fs.regs.reg[fs.retaddr_column];
+ const std::vector<struct dwarf2_frame_state_reg> ®s
+ = fs.regs.reg;
+ ULONGEST retaddr_column = fs.retaddr_column;
/* It seems rather bizarre to specify an "empty" column as
the return adress column. However, this is exactly
register corresponding to the return address column.
Incidentally, that's how we should treat a return
address column specifying "same value" too. */
- if (fs.retaddr_column < fs.regs.num_regs
- && retaddr_reg->how != DWARF2_FRAME_REG_UNSPECIFIED
- && retaddr_reg->how != DWARF2_FRAME_REG_SAME_VALUE)
+ if (fs.retaddr_column < fs.regs.reg.size ()
+ && regs[retaddr_column].how != DWARF2_FRAME_REG_UNSPECIFIED
+ && regs[retaddr_column].how != DWARF2_FRAME_REG_SAME_VALUE)
{
if (cache->reg[regnum].how == DWARF2_FRAME_REG_RA)
- cache->reg[regnum] = *retaddr_reg;
+ cache->reg[regnum] = regs[retaddr_column];
else
- cache->retaddr_reg = *retaddr_reg;
+ cache->retaddr_reg = regs[retaddr_column];
}
else
{
}
}
- if (fs.retaddr_column < fs.regs.num_regs
+ if (fs.retaddr_column < fs.regs.reg.size ()
&& fs.regs.reg[fs.retaddr_column].how == DWARF2_FRAME_REG_UNDEFINED)
cache->undefined_retaddr = 1;
~dwarf2_frame_state_reg_info ()
{
delete prev;
- xfree (reg);
}
/* Copy constructor. */
dwarf2_frame_state_reg_info (const dwarf2_frame_state_reg_info &src)
- : num_regs (src.num_regs), cfa_offset (src.cfa_offset),
+ : reg (src.reg), cfa_offset (src.cfa_offset),
cfa_reg (src.cfa_reg), cfa_how (src.cfa_how), cfa_exp (src.cfa_exp),
prev (src.prev)
{
- size_t size = src.num_regs * sizeof (struct dwarf2_frame_state_reg);
-
- reg = (struct dwarf2_frame_state_reg *) xmalloc (size);
- memcpy (reg, src.reg, size);
}
/* Assignment operator for both move-assignment and copy-assignment. */
/* Move constructor. */
dwarf2_frame_state_reg_info (dwarf2_frame_state_reg_info &&rhs) noexcept
- : reg (rhs.reg), num_regs (rhs.num_regs), cfa_offset (rhs.cfa_offset),
+ : reg (std::move (rhs.reg)), cfa_offset (rhs.cfa_offset),
cfa_reg (rhs.cfa_reg), cfa_how (rhs.cfa_how), cfa_exp (rhs.cfa_exp),
prev (rhs.prev)
{
rhs.prev = nullptr;
- rhs.reg = nullptr;
}
-/* Assert that the register set RS is large enough to store gdbarch_num_regs
- columns. If necessary, enlarge the register set. */
+ /* If necessary, enlarge the register set to hold NUM_REGS_REQUESTED
+ registers. */
void alloc_regs (int num_regs_requested)
{
- if (num_regs_requested <= num_regs)
- return;
+ gdb_assert (num_regs_requested > 0);
- size_t size = sizeof (struct dwarf2_frame_state_reg);
-
- reg = (struct dwarf2_frame_state_reg *)
- xrealloc (reg, num_regs_requested * size);
+ if (num_regs_requested <= reg.size ())
+ return;
- /* Initialize newly allocated registers. */
- memset (reg + num_regs, 0, (num_regs_requested - num_regs) * size);
- num_regs = num_regs_requested;
+ reg.resize (num_regs_requested);
}
- struct dwarf2_frame_state_reg *reg = NULL;
- int num_regs = 0;
+ std::vector<struct dwarf2_frame_state_reg> reg;
LONGEST cfa_offset = 0;
ULONGEST cfa_reg = 0;
using std::swap;
swap (lhs.reg, rhs.reg);
- swap (lhs.num_regs, rhs.num_regs);
swap (lhs.cfa_offset, rhs.cfa_offset);
swap (lhs.cfa_reg, rhs.cfa_reg);
swap (lhs.cfa_how, rhs.cfa_how);