Improve target description check for SVE in gdbserver
authorLuis Machado <luis.machado@linaro.org>
Mon, 18 Nov 2019 19:36:53 +0000 (16:36 -0300)
committerLuis Machado <luis.machado@linaro.org>
Wed, 20 Nov 2019 16:57:34 +0000 (13:57 -0300)
The current code checks for the presence of a SVE target description by
comparing the number of registers.  This is a bit fragile since the number
of registers can change whenever we add new sets. Like PAC, for example.

If the comparison breaks, then we're left with SVE registers in the
description, but gdbserver doesn't send the registers to GDB, which in
turn displays stale information to the user.

The following patch changes the check to use the SVE feature string instead,
which hopefully should be more stable.

gdb/gdbserver/ChangeLog:

2019-11-20  Luis Machado  <luis.machado@linaro.org>

* linux-aarch64-low.c (is_sve_tdesc): Check against target feature
instead of register count.
* tdesc.c (tdesc_contains_feature): New function.
* tdesc.h (tdesc_contains_feature): New prototype.

Change-Id: I28b782cb1677560ca9a06a1be442974b25aabae4

gdb/gdbserver/ChangeLog
gdb/gdbserver/linux-aarch64-low.c
gdb/gdbserver/tdesc.c
gdb/gdbserver/tdesc.h

index fde6abbecb3bbf15fc3eccce29df9e949856636d..a5da6b584deab36ea1614d5e24e45be828cbfb91 100644 (file)
@@ -1,3 +1,10 @@
+2019-11-20  Luis Machado  <luis.machado@linaro.org>
+
+       * linux-aarch64-low.c (is_sve_tdesc): Check against target feature
+       instead of register count.
+       * tdesc.c (tdesc_contains_feature): New function.
+       * tdesc.h (tdesc_contains_feature): New prototype.
+
 2019-11-15  Christian Biesinger  <cbiesinger@google.com>
 
        * Makefile.in: Add safe-strerror.c.
index 87a21a0e7745e8e865267129cd37ab6dd1f8dd34..9e234e0578bfd8017d58a5c8e24c8c7bda70fc5f 100644 (file)
@@ -83,7 +83,7 @@ is_sve_tdesc (void)
 {
   struct regcache *regcache = get_thread_regcache (current_thread, 0);
 
-  return regcache->tdesc->reg_defs.size () == AARCH64_SVE_NUM_REGS;
+  return tdesc_contains_feature (regcache->tdesc, "org.gnu.gdb.aarch64.sve");
 }
 
 static void
index 92a0a6005f3f4fccdca964f7e981d26deb07ae04..817e69a58f24ba2b870df75b64554754d5691d90 100644 (file)
@@ -186,3 +186,19 @@ tdesc_create_feature (struct target_desc *tdesc, const char *name)
   tdesc->features.emplace_back (new_feature);
   return new_feature;
 }
+
+/* See gdbsupport/tdesc.h.  */
+
+bool
+tdesc_contains_feature (const target_desc *tdesc, const std::string &feature)
+{
+  gdb_assert (tdesc != nullptr);
+
+  for (const tdesc_feature_up &f : tdesc->features)
+    {
+      if (f->name == feature)
+       return true;
+    }
+
+  return false;
+}
index b93f53c8d44592b95bbe1cf23c712709736f7a33..da21cdaad47f14f29a647ec7f6ce351115330074 100644 (file)
@@ -93,4 +93,9 @@ void init_target_desc (struct target_desc *tdesc,
 
 const struct target_desc *current_target_desc (void);
 
+/* Return true if TDESC contains the feature described by string FEATURE.
+   Return false otherwise.  */
+bool tdesc_contains_feature (const target_desc *tdesc,
+                            const std::string &feature);
+
 #endif /* GDBSERVER_TDESC_H */
This page took 0.034472 seconds and 4 git commands to generate.