Fix "set integer-command unlimited junk"
[deliverable/binutils-gdb.git] / gdb / aarch64-linux-nat.c
index b9e68801dd13dd3b586eae1d1b8eb0468aff9df8..8ca96143013e499cbbfe3eafce9a0b5785884f65 100644 (file)
 
 #include "defs.h"
 
-/* Standard C includes.  */
-#include <asm/ptrace.h>
-#include <sys/utsname.h>
-
-/* Local non-gdb includes.  */
-#include "aarch32-linux-nat.h"
-#include "aarch64-linux-tdep.h"
-#include "aarch64-tdep.h"
-#include "auxv.h"
-#include "elf/common.h"
-#include "elf/external.h"
-#include "gdbcmd.h"
-#include "gdbcore.h"
-#include "gregset.h"
 #include "inferior.h"
+#include "gdbcore.h"
+#include "regcache.h"
 #include "linux-nat.h"
-#include "linux-tdep.h"
-#include "nat/aarch64-linux-hw-point.h"
+#include "target-descriptions.h"
+#include "auxv.h"
+#include "gdbcmd.h"
+#include "aarch64-tdep.h"
+#include "aarch64-linux-tdep.h"
+#include "aarch32-linux-nat.h"
 #include "nat/aarch64-linux.h"
+#include "nat/aarch64-linux-hw-point.h"
 #include "nat/aarch64-sve-linux-ptrace.h"
+
+#include "elf/external.h"
+#include "elf/common.h"
+
 #include "nat/gdb_ptrace.h"
-#include "regcache.h"
-#include "target-descriptions.h"
+#include <sys/utsname.h>
+#include <asm/ptrace.h>
+
+#include "gregset.h"
+#include "linux-tdep.h"
 
 /* Defines ps_err_e, struct ps_prochandle.  */
 #include "gdb_proc_service.h"
+#include "arch-utils.h"
 
 #ifndef TRAP_HWBKPT
 #define TRAP_HWBKPT 0x0004
@@ -95,6 +96,8 @@ public:
   /* Add our siginfo layout converter.  */
   bool low_siginfo_fixup (siginfo_t *ptrace, gdb_byte *inf, int direction)
     override;
+
+  struct gdbarch *thread_architecture (ptid_t) override;
 };
 
 static aarch64_linux_nat_target the_aarch64_linux_nat_target;
@@ -409,6 +412,11 @@ store_sveregs_to_thread (struct regcache *regcache)
   struct iovec iovec;
   int tid = regcache->ptid ().lwp ();
 
+  /* First store vector length to the thread.  This is done first to ensure the
+     ptrace buffers read from the kernel are the correct size.  */
+  if (!aarch64_sve_set_vq (tid, regcache))
+    perror_with_name (_("Unable to set VG register."));
+
   /* Obtain a dump of SVE registers from ptrace.  */
   std::unique_ptr<gdb_byte[]> base = aarch64_sve_get_sveregs (tid);
 
@@ -939,6 +947,34 @@ aarch64_linux_nat_target::can_do_single_step ()
   return 1;
 }
 
+/* Implement the "thread_architecture" target_ops method.  */
+
+struct gdbarch *
+aarch64_linux_nat_target::thread_architecture (ptid_t ptid)
+{
+  /* Return the gdbarch for the current thread.  If the vector length has
+     changed since the last time this was called, then do a further lookup.  */
+
+  uint64_t vq = aarch64_sve_get_vq (ptid.lwp ());
+
+  /* Find the current gdbarch the same way as process_stratum_target.  Only
+     return it if the current vector length matches the one in the tdep.  */
+  inferior *inf = find_inferior_ptid (ptid);
+  gdb_assert (inf != NULL);
+  if (vq == gdbarch_tdep (inf->gdbarch)->vq)
+    return inf->gdbarch;
+
+  /* We reach here if the vector length for the thread is different from its
+     value at process start.  Lookup gdbarch via info (potentially creating a
+     new one), stashing the vector length inside id.  Use -1 for when SVE
+     unavailable, to distinguish from an unset value of 0.  */
+  struct gdbarch_info info;
+  gdbarch_info_init (&info);
+  info.bfd_arch_info = bfd_lookup_arch (bfd_arch_spu, bfd_mach_spu);
+  info.id = (int *) (vq == 0 ? -1 : vq);
+  return gdbarch_find_by_info (info);
+}
+
 /* Define AArch64 maintenance commands.  */
 
 static void
This page took 0.023962 seconds and 4 git commands to generate.