aboutsummaryrefslogtreecommitdiff
path: root/gdb/nat
diff options
context:
space:
mode:
authorAlan Hayward <alan.hayward@arm.com>2019-04-15 12:31:21 +0100
committerAlan Hayward <alan.hayward@arm.com>2019-04-15 15:12:44 +0100
commit48574d91bf1289074f2c88b1f83aa3cd37d524d9 (patch)
tree8bb9c8cbd7c8c487de165db5fd0fe8914f5036d7 /gdb/nat
parent4da037ef9dba6c17089250d228efdbe6f7d830c9 (diff)
downloadgdb-48574d91bf1289074f2c88b1f83aa3cd37d524d9.zip
gdb-48574d91bf1289074f2c88b1f83aa3cd37d524d9.tar.gz
gdb-48574d91bf1289074f2c88b1f83aa3cd37d524d9.tar.bz2
AArch64 SVE: Support changing vector lengths for ptrace
When writing registers to the kernel, check if regcache VG has been changed. If so then update the thread's vector length, then write back the registers. When reading registers from the kernel, ensure regcache VG register is updated. The regcache registers should already be of the correct length. Remove all the checks that error if the vector length has changed. gdb/ChangeLog: * aarch64-linux-nat.c (store_sveregs_to_thread): Set vector length. * nat/aarch64-sve-linux-ptrace.c (aarch64_sve_set_vq): New function. (aarch64_sve_regs_copy_to_reg_buf): Remove VG checks. (aarch64_sve_regs_copy_from_reg_buf): Likewise. * nat/aarch64-sve-linux-ptrace.h (aarch64_sve_set_vq): New declaration.
Diffstat (limited to 'gdb/nat')
-rw-r--r--gdb/nat/aarch64-sve-linux-ptrace.c92
-rw-r--r--gdb/nat/aarch64-sve-linux-ptrace.h12
2 files changed, 58 insertions, 46 deletions
diff --git a/gdb/nat/aarch64-sve-linux-ptrace.c b/gdb/nat/aarch64-sve-linux-ptrace.c
index 30faab2..635b4c9 100644
--- a/gdb/nat/aarch64-sve-linux-ptrace.c
+++ b/gdb/nat/aarch64-sve-linux-ptrace.c
@@ -27,8 +27,6 @@
#include "common/common-regcache.h"
#include "common/byte-vector.h"
-static bool vq_change_warned = false;
-
/* See nat/aarch64-sve-linux-ptrace.h. */
uint64_t
@@ -63,6 +61,48 @@ aarch64_sve_get_vq (int tid)
/* See nat/aarch64-sve-linux-ptrace.h. */
+bool
+aarch64_sve_set_vq (int tid, uint64_t vq)
+{
+ struct iovec iovec;
+ struct user_sve_header header;
+
+ iovec.iov_len = sizeof (header);
+ iovec.iov_base = &header;
+
+ if (ptrace (PTRACE_GETREGSET, tid, NT_ARM_SVE, &iovec) < 0)
+ {
+ /* SVE is not supported. */
+ return false;
+ }
+
+ header.vl = sve_vl_from_vq (vq);
+
+ if (ptrace (PTRACE_SETREGSET, tid, NT_ARM_SVE, &iovec) < 0)
+ {
+ /* Vector length change failed. */
+ return false;
+ }
+
+ return true;
+}
+
+/* See nat/aarch64-sve-linux-ptrace.h. */
+
+bool
+aarch64_sve_set_vq (int tid, struct reg_buffer_common *reg_buf)
+{
+ if (reg_buf->get_register_status (AARCH64_SVE_VG_REGNUM) != REG_VALID)
+ return false;
+
+ uint64_t reg_vg = 0;
+ reg_buf->raw_collect (AARCH64_SVE_VG_REGNUM, &reg_vg);
+
+ return aarch64_sve_set_vq (tid, sve_vq_from_vg (reg_vg));
+}
+
+/* See nat/aarch64-sve-linux-ptrace.h. */
+
std::unique_ptr<gdb_byte[]>
aarch64_sve_get_sveregs (int tid)
{
@@ -95,37 +135,18 @@ aarch64_sve_regs_copy_to_reg_buf (struct reg_buffer_common *reg_buf,
{
char *base = (char *) buf;
struct user_sve_header *header = (struct user_sve_header *) buf;
- uint64_t vq, vg_reg_buf = 0;
- vq = sve_vq_from_vl (header->vl);
+ uint64_t vq = sve_vq_from_vl (header->vl);
+ uint64_t vg = sve_vg_from_vl (header->vl);
/* Sanity check the data in the header. */
if (!sve_vl_valid (header->vl)
|| SVE_PT_SIZE (vq, header->flags) != header->size)
error (_("Invalid SVE header from kernel."));
- if (REG_VALID == reg_buf->get_register_status (AARCH64_SVE_VG_REGNUM))
- reg_buf->raw_collect (AARCH64_SVE_VG_REGNUM, &vg_reg_buf);
-
- if (vg_reg_buf == 0)
- {
- /* VG has not been set. */
- vg_reg_buf = sve_vg_from_vl (header->vl);
- reg_buf->raw_supply (AARCH64_SVE_VG_REGNUM, &vg_reg_buf);
- }
- else if (vg_reg_buf != sve_vg_from_vl (header->vl) && !vq_change_warned)
- {
- /* Vector length on the running process has changed. GDB currently does
- not support this and will result in GDB showing incorrect partially
- incorrect data for the vector registers. Warn once and continue. We
- do not expect many programs to exhibit this behaviour. To fix this
- we need to spot the change earlier and generate a new target
- descriptor. */
- warning (_("SVE Vector length has changed (%ld to %d). "
- "Vector registers may show incorrect data."),
- vg_reg_buf, sve_vg_from_vl (header->vl));
- vq_change_warned = true;
- }
+ /* Update VG. Note, the registers in the regcache will already be of the
+ correct length. */
+ reg_buf->raw_supply (AARCH64_SVE_VG_REGNUM, &vg);
if (HAS_SVE_STATE (*header))
{
@@ -187,30 +208,13 @@ aarch64_sve_regs_copy_from_reg_buf (const struct reg_buffer_common *reg_buf,
{
struct user_sve_header *header = (struct user_sve_header *) buf;
char *base = (char *) buf;
- uint64_t vq, vg_reg_buf = 0;
-
- vq = sve_vq_from_vl (header->vl);
+ uint64_t vq = sve_vq_from_vl (header->vl);
/* Sanity check the data in the header. */
if (!sve_vl_valid (header->vl)
|| SVE_PT_SIZE (vq, header->flags) != header->size)
error (_("Invalid SVE header from kernel."));
- if (REG_VALID == reg_buf->get_register_status (AARCH64_SVE_VG_REGNUM))
- reg_buf->raw_collect (AARCH64_SVE_VG_REGNUM, &vg_reg_buf);
-
- if (vg_reg_buf != 0 && vg_reg_buf != sve_vg_from_vl (header->vl))
- {
- /* Vector length on the running process has changed. GDB currently does
- not support this and will result in GDB writing invalid data back to
- the vector registers. Error and exit. We do not expect many programs
- to exhibit this behaviour. To fix this we need to spot the change
- earlier and generate a new target descriptor. */
- error (_("SVE Vector length has changed (%ld to %d). "
- "Cannot write back registers."),
- vg_reg_buf, sve_vg_from_vl (header->vl));
- }
-
if (!HAS_SVE_STATE (*header))
{
/* There is no SVE state yet - the register dump contains a fpsimd
diff --git a/gdb/nat/aarch64-sve-linux-ptrace.h b/gdb/nat/aarch64-sve-linux-ptrace.h
index 167fc8e..ee994f2 100644
--- a/gdb/nat/aarch64-sve-linux-ptrace.h
+++ b/gdb/nat/aarch64-sve-linux-ptrace.h
@@ -39,17 +39,25 @@
uint64_t aarch64_sve_get_vq (int tid);
+/* Set VQ in the kernel for the given tid, using either the value VQ or
+ reading from the register VG in the register buffer. */
+
+bool aarch64_sve_set_vq (int tid, uint64_t vq);
+bool aarch64_sve_set_vq (int tid, struct reg_buffer_common *reg_buf);
+
/* Read the current SVE register set using ptrace, allocating space as
required. */
extern std::unique_ptr<gdb_byte[]> aarch64_sve_get_sveregs (int tid);
-/* Put the registers from linux structure buf into register buffer. */
+/* Put the registers from linux structure buf into register buffer. Assumes the
+ vector lengths in the register buffer match the size in the kernel. */
extern void aarch64_sve_regs_copy_to_reg_buf (struct reg_buffer_common *reg_buf,
const void *buf);
-/* Put the registers from register buffer into linux structure buf. */
+/* Put the registers from register buffer into linux structure buf. Assumes the
+ vector lengths in the register buffer match the size in the kernel. */
extern void
aarch64_sve_regs_copy_from_reg_buf (const struct reg_buffer_common *reg_buf,