[gdb/tdep] Use raw_supply_part_zeroed for AArch64

In gdb/aarch64-linux-tdep.c we find:
...
      gdb::byte_vector za_zeroed (za_bytes, 0);
      regcache->raw_supply (tdep->sme_za_regnum, za_zeroed);
...

We can't use reg_buffer::raw_supply_zeroed here because only part of the
register is written.

Add raw_supply_part_zeroed, and use it instead.

Likewise elsewhere in AArch64 tdep code.

Tested on aarch64-linux.

Approved-By: Luis Machado <luis.machado@arm.com>
This commit is contained in:
Tom de Vries 2024-11-12 11:37:50 +01:00
parent 510fa4aadb
commit a4a5f05266
7 changed files with 37 additions and 9 deletions

View File

@ -1297,10 +1297,7 @@ aarch64_linux_supply_za_regset (const struct regset *regset,
regcache->raw_supply (tdep->sme_za_regnum, buf);
}
else
{
gdb::byte_vector za_zeroed (za_bytes, 0);
regcache->raw_supply (tdep->sme_za_regnum, za_zeroed);
}
regcache->raw_supply_part_zeroed (tdep->sme_za_regnum, 0, za_bytes);
}
/* Collect register REGNUM from REGCACHE to BUF, using the register

View File

@ -920,8 +920,7 @@ aarch64_za_regs_copy_to_reg_buf (int tid, struct reg_buffer_common *reg_buf,
else
{
size_t za_bytes = header->vl * header->vl;
gdb::byte_vector za_zeroed (za_bytes, 0);
reg_buf->raw_supply (za_regnum, za_zeroed);
reg_buf->raw_supply_part_zeroed (za_regnum, 0, za_bytes);
}
/* Handle the svg and svcr registers separately. We need to calculate
@ -1000,7 +999,7 @@ aarch64_za_regs_copy_from_reg_buf (int tid,
in the thread with the ZA contents from the register cache, and they will
differ in size. */
if (svg_changed)
reg_buf->raw_supply (za_regnum, za_zeroed);
reg_buf->raw_supply_part_zeroed (za_regnum, 0, za_bytes);
/* When we update svg, we don't automatically initialize the ZA buffer. If
we have no ZA state and the ZA register contents in the register cache are
@ -1078,8 +1077,7 @@ aarch64_zt_regs_copy_to_reg_buf (int tid, struct reg_buffer_common *reg_buf,
else
{
/* Zero out ZT. */
gdb::byte_vector zt_zeroed (AARCH64_SME2_ZT0_SIZE, 0);
reg_buf->raw_supply (zt_regnum, zt_zeroed.data ());
reg_buf->raw_supply_part_zeroed (zt_regnum, 0, AARCH64_SME2_ZT0_SIZE);
}
/* The register buffer should now contain the updated copy of the NT_ARM_ZT

View File

@ -1189,6 +1189,16 @@ reg_buffer::raw_supply_zeroed (int regnum)
/* See gdbsupport/common-regcache.h. */
void
reg_buffer::raw_supply_part_zeroed (int regnum, int offset, size_t size)
{
gdb::array_view<gdb_byte> dst = register_buffer (regnum).slice (offset, size);
memset (dst.data (), 0, dst.size ());
m_register_status[regnum] = REG_VALID;
}
/* See gdbsupport/common-regcache.h. */
void
reg_buffer::raw_collect (int regnum, gdb::array_view<gdb_byte> dst) const
{

View File

@ -243,6 +243,9 @@ public:
unavailable). */
void raw_supply_zeroed (int regnum);
/* See gdbsupport/common-regcache.h. */
void raw_supply_part_zeroed (int regnum, int offset, size_t size) override;
/* Supply part of register REGNUM to this register buffer. Start at OFFSET in
the register. The size is given by the size of SRC. The rest of the
register left untouched. */

View File

@ -370,6 +370,17 @@ supply_register_zeroed (struct regcache *regcache, int n)
#endif
}
void
regcache::raw_supply_part_zeroed (int regnum, int offset, size_t size)
{
auto dst = register_data (this, regnum).slice (offset, size);
memset (dst.data (), 0, dst.size ());
#ifndef IN_PROCESS_AGENT
if (register_status != NULL)
register_status[regnum] = REG_VALID;
#endif
}
#ifndef IN_PROCESS_AGENT
/* Supply register called NAME with value zero to REGCACHE. */

View File

@ -52,6 +52,9 @@ struct regcache : public reg_buffer_common
/* See gdbsupport/common-regcache.h. */
void raw_supply (int regnum, gdb::array_view<const gdb_byte> src) override;
/* See gdbsupport/common-regcache.h. */
void raw_supply_part_zeroed (int regnum, int offset, size_t size) override;
/* See gdbsupport/common-regcache.h. */
void raw_collect (int regnum, gdb::array_view<gdb_byte> dst) const override;

View File

@ -96,6 +96,12 @@ struct reg_buffer_common
regcache_register_size (this, regnum)));
}
/* Supply part of register REGNUM with zeroed value. Start at OFFSET in
the register, with size SIZE. The rest of the register is left
untouched. */
virtual void raw_supply_part_zeroed (int regnum, int offset, size_t size)
= 0;
/* Collect register REGNUM from this register buffer and store its contents in
DST. */
virtual void raw_collect (int regnum, gdb::array_view<gdb_byte> dst) const