]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[Morello] Add support for capability/pointer/integer conversions
authorLuis Machado <luis.machado@arm.com>
Wed, 9 Sep 2020 20:20:15 +0000 (17:20 -0300)
committerLuis Machado <luis.machado@linaro.org>
Tue, 20 Oct 2020 18:05:47 +0000 (15:05 -0300)
Enable hooks to allow custom conversions of capability/pointer/integer values.

gdb/ChangeLog:

2020-10-20  Luis Machado  <luis.machado@arm.com>

* aarch64-tdep.c: Include inferior.h.
(aarch64_pointer_to_address, aarch64_address_to_pointer)
(aarch64_integer_to_address): New functions.
(aarch64_gdbarch_init): Register hooks.

gdb/ChangeLog
gdb/aarch64-tdep.c

index 59b06a9c81d31f94261a07cfffc455e3821ada09..61ca19b468daeea9e2f9f5bd2f042de6a7dc791f 100644 (file)
@@ -1,3 +1,10 @@
+2020-10-20  Luis Machado  <luis.machado@arm.com>
+
+       * aarch64-tdep.c: Include inferior.h.
+       (aarch64_pointer_to_address, aarch64_address_to_pointer)
+       (aarch64_integer_to_address): New functions.
+       (aarch64_gdbarch_init): Register hooks.
+
 2020-10-20  Luis Machado  <luis.machado@arm.com>
 
        * aarch64-linux-tdep.c: Include value.h.
index f882a0a465244ee681aecb0fe4545d46ef52736e..47b435b888dcf9d89fffd32c806bff24bb26f154 100644 (file)
@@ -55,6 +55,9 @@
 
 #include "gdbsupport/capability.h"
 
+/* For address/int to pointer conversions.  */
+#include "inferior.h"
+
 #define submask(x) ((1L << ((x) + 1)) - 1)
 #define bit(obj,st) (((obj) >> (st)) & 1)
 #define bits(obj,st,fn) (((obj) >> (st)) & submask ((fn) - (st)))
@@ -3491,6 +3494,51 @@ aarch64_address_class_name_to_type_flags (struct gdbarch *gdbarch,
     return false;
 }
 
+/* Implements the gdbarch_pointer_to_address hook.  */
+
+static CORE_ADDR
+aarch64_pointer_to_address (struct gdbarch *gdbarch, struct type *type,
+                           const gdb_byte *buf)
+{
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+
+  if (type->length <= 8)
+    return signed_pointer_to_address (gdbarch, type, buf);
+  else
+    {
+      /* Convert a capability to a regular 64-bit address, discarding
+        the extra information.  */
+      return extract_unsigned_integer (buf, 8, byte_order);
+    }
+}
+
+/* Implements the gdbarch_address_to_pointer hook.  */
+
+static void
+aarch64_address_to_pointer (struct gdbarch *gdbarch, struct type *type,
+                           gdb_byte *buf, CORE_ADDR addr)
+{
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+
+  if (type->length <= 8)
+    address_to_signed_pointer (gdbarch, type, buf, addr);
+  else
+    {
+      /* Create a fake capability with only the address part.  */
+      memset (buf, 0, type->length);
+      store_unsigned_integer (buf, 8, byte_order, addr);
+    }
+}
+
+/* Implements the gdbarch_integer_to_address hook.  */
+
+static CORE_ADDR
+aarch64_integer_to_address (struct gdbarch *gdbarch,
+                           struct type *type, const gdb_byte *buf)
+{
+  return aarch64_pointer_to_address (gdbarch, type, buf);
+}
+
 /* Initialize the current architecture based on INFO.  If possible,
    re-use an architecture from ARCHES, which is a list of
    architectures already created during this debugging session.
@@ -3773,6 +3821,11 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        (gdbarch, aarch64_address_class_name_to_type_flags);
       set_gdbarch_address_class_type_flags_to_name
        (gdbarch, aarch64_address_class_type_flags_to_name);
+
+      /* For converting between pointer/capability.  */
+      set_gdbarch_pointer_to_address (gdbarch, aarch64_pointer_to_address);
+      set_gdbarch_address_to_pointer (gdbarch, aarch64_address_to_pointer);
+      set_gdbarch_integer_to_address (gdbarch, aarch64_integer_to_address);
     }
 
   return gdbarch;