Add gdbserver target methods target_validate_tdesc and arch_setup

target_validate_tdesc () is added as a new target function.
This function checks current target description is still valid for the
current inferior, returning false if not. On SVE, we need to check if the
vector length has changed - if it has then the current target descriptor
will need to be switched to a valid one.

The existing arch_setup () is extended to be a target function.
This will later allow it to be called from get_thread_regcache () in
gdbserver/regcache.c. This call is required to generate a new target
descriptor if we have decided the current one is no longer valid.

2018-09-13  Alan Hayward  <alan.hayward@arm.com>

gdbserver/
	* linux-aarch64-low.c (int aarch64_validate_tdesc): New function.
	(struct linux_target_ops): Add aarch64_validate_tdesc.
	* linux-low.c (linux_validate_tdesc): New function.
	(linux_target_ops): Add linux_arch_setup and linux_validate_tdesc.
	* linux-low.h (linux_target_ops): Add validate_tdesc.
	* target.h (struct target_ops): Likewise.
	(target_arch_setup) New macro.
	(target_validate_tdesc) New macro.
diff --git a/gdb/gdbserver/linux-aarch64-low.c b/gdb/gdbserver/linux-aarch64-low.c
index 1d34e31..dcc19ce 100644
--- a/gdb/gdbserver/linux-aarch64-low.c
+++ b/gdb/gdbserver/linux-aarch64-low.c
@@ -3037,6 +3037,14 @@
   return 1;
 }
 
+/* Implementation of the linux_target_ops method "validate_tdesc ".  */
+
+static bool
+aarch64_validate_tdesc (struct thread_info *thread)
+{
+  return true;
+}
+
 struct linux_target_ops the_low_target =
 {
   aarch64_arch_setup,
@@ -3075,6 +3083,8 @@
   aarch64_breakpoint_kind_from_current_state,
   aarch64_supports_hardware_single_step,
   aarch64_get_syscall_trapinfo,
+  NULL, /* get_ipa_tdesc_idx.  */
+  aarch64_validate_tdesc,
 };
 
 void
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 984464f..7153242 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -6576,6 +6576,15 @@
   return (*the_low_target.get_ipa_tdesc_idx) ();
 }
 
+static bool
+linux_validate_tdesc (struct thread_info *thread)
+{
+  if (the_low_target.validate_tdesc == NULL)
+    return true;
+
+  return (*the_low_target.validate_tdesc) (thread);
+}
+
 static int
 linux_supports_tracepoints (void)
 {
@@ -7526,6 +7535,8 @@
 #else
   NULL,
 #endif
+  linux_arch_setup,
+  linux_validate_tdesc,
 };
 
 #ifdef HAVE_LINUX_REGSETS
diff --git a/gdb/gdbserver/linux-low.h b/gdb/gdbserver/linux-low.h
index 79b3311..a99e6fc 100644
--- a/gdb/gdbserver/linux-low.h
+++ b/gdb/gdbserver/linux-low.h
@@ -256,6 +256,9 @@
 
   /* See target.h.  */
   int (*get_ipa_tdesc_idx) (void);
+
+  /* See target.h.  */
+  bool (*validate_tdesc) (struct thread_info *thread);
 };
 
 extern struct linux_target_ops the_low_target;
diff --git a/gdb/gdbserver/target.h b/gdb/gdbserver/target.h
index fce54e0..dfa74ec 100644
--- a/gdb/gdbserver/target.h
+++ b/gdb/gdbserver/target.h
@@ -478,6 +478,16 @@
      false for failure.  Return pointer to thread handle via HANDLE
      and the handle's length via HANDLE_LEN.  */
   bool (*thread_handle) (ptid_t ptid, gdb_byte **handle, int *handle_len);
+
+  /* Call the target arch_setup function on the current thread.  */
+  void (*arch_setup) (void);
+
+  /* Check that the current target description is still valid for the current
+     inferior, returning false if not.  For example, if the size of some
+     registers (see aarch64 SVE), or the number of registers, had changed.
+     This check does not include the contents of the registers.  Default
+     implementation will always return true.  */
+  bool (*validate_tdesc) (struct thread_info *thread);
 };
 
 extern struct target_ops *the_target;
@@ -565,6 +575,14 @@
   (the_target->get_min_fast_tracepoint_insn_len		\
    ? (*the_target->get_min_fast_tracepoint_insn_len) () : 0)
 
+#define target_arch_setup(thread)			\
+  if (the_target->arch_setup)				\
+    (*the_target->arch_setup) ();
+
+#define target_validate_tdesc(thread)			\
+  (the_target->validate_tdesc				\
+    ? (*the_target->validate_tdesc) (thread) : true)
+
 #define thread_stopped(thread) \
   (*the_target->thread_stopped) (thread)