]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Support casting capabilities/capability pointers to other types
authorLuis Machado <luis.machado@arm.com>
Wed, 4 Nov 2020 19:13:05 +0000 (16:13 -0300)
committerLuis Machado <luis.machado@linaro.org>
Tue, 8 Dec 2020 18:02:58 +0000 (15:02 -0300)
When casting capabilities and capability pointers to other types, we truncate
the value to the appropriate size, given some capabilities are greater than
8 bytes in size.

gdb/ChangeLog:

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

* valops.c (value_cast): Handle casting from capabilities and
capability pointers.

gdb/ChangeLog
gdb/valops.c

index 772b93fd06cb89fa3b598477324632d68de3ac40..c1a4f45d9c829cec17cca860eb2ea7a5f7a02679 100644 (file)
@@ -1,3 +1,8 @@
+2020-11-11  Luis Machado  <luis.machado@arm.com>
+
+       * valops.c (value_cast): Handle casting from capabilities and
+       capability pointers.
+
 2020-11-11  Luis Machado  <luis.machado@arm.com>
 
        * aarch64-tdep.c (aarch64_address_class_type_flags)
index 3c0ed38a97f3b856e439f633d1594aa57e2f8bf7..d0f1a1ed60441c8cd32f74cbd325b446f1429ca3 100644 (file)
@@ -441,14 +441,20 @@ value_cast (struct type *type, struct value *arg2)
            || code2 == TYPE_CODE_DECFLOAT || code2 == TYPE_CODE_ENUM
            || code2 == TYPE_CODE_RANGE);
 
-  /* Handle casting capabilities to other scalar types.  For now we truncate
-     the capability value to the size of the target type.  */
-  if (scalar && code2 == TYPE_CODE_CAPABILITY)
+  int to_scalar = (code1 == TYPE_CODE_INT || code1 == TYPE_CODE_FLT
+           || code1 == TYPE_CODE_DECFLOAT || code1 == TYPE_CODE_ENUM
+           || code1 == TYPE_CODE_RANGE);
+
+  /* Handle casting capabilities/capability pointers to other scalar types.
+     For now we truncate the capability value to the size of the target
+     type.  */
+  if (to_scalar && (code2 == TYPE_CODE_CAPABILITY
+      || (code2 == TYPE_CODE_PTR && TYPE_CAPABILITY (type2))))
     {
       if (type->is_unsigned ())
-       value_from_ulongest (to_type, value_as_long (arg2));
+       return value_from_ulongest (to_type, value_as_long (arg2));
       else
-       value_from_longest (to_type, value_as_long (arg2));
+       return value_from_longest (to_type, value_as_long (arg2));
     }
 
   if ((code1 == TYPE_CODE_STRUCT || code1 == TYPE_CODE_UNION)