GDB: trad-frame: Store length of value_bytes in trad_frame_saved_reg

The goal is to ensure that it is available in frame_unwind_got_bytes () to
make sure that the provided buf isn't larger than the size of the register
being provisioned.

In the process, regcache's cached_reg_t::data also needed to be
converted to a gdb::byte_vector, so that the register contents' size can
be tracked.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
This commit is contained in:
Thiago Jung Bauermann
2024-08-22 19:42:45 -03:00
parent 1f493519f7
commit ad59259604
7 changed files with 35 additions and 22 deletions

View File

@@ -313,14 +313,26 @@ frame_unwind_got_constant (const frame_info_ptr &frame, int regnum,
}
struct value *
frame_unwind_got_bytes (const frame_info_ptr &frame, int regnum, const gdb_byte *buf)
frame_unwind_got_bytes (const frame_info_ptr &frame, int regnum,
gdb::array_view<const gdb_byte> buf)
{
struct gdbarch *gdbarch = frame_unwind_arch (frame);
struct value *reg_val;
reg_val = value::zero (register_type (gdbarch, regnum), not_lval);
memcpy (reg_val->contents_raw ().data (), buf,
register_size (gdbarch, regnum));
gdb::array_view<gdb_byte> val_contents = reg_val->contents_raw ();
/* The value's contents buffer is zeroed on allocation so if buf is
smaller, the remaining space will be filled with zero.
This can happen when unwinding through signal frames. For example, if
an AArch64 program doesn't use SVE, then the Linux kernel will only
save in the signal frame the first 128 bits of the vector registers,
which is their minimum size, even if the vector length says they're
bigger. */
gdb_assert (buf.size () <= val_contents.size ());
memcpy (val_contents.data (), buf.data (), buf.size ());
return reg_val;
}