]> 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)
committerJohn Baldwin <jhb@FreeBSD.org>
Thu, 1 Sep 2022 22:53:22 +0000 (15:53 -0700)
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/valops.c

index d4e89a3cfa6840ef4988f53cd36f930c40025fd9..d1fe6d1024d359ef52f3e80e113b9d625cafd4aa 100644 (file)
@@ -529,14 +529,20 @@ value_cast (struct type *type, struct value *arg2)
            || code2 == TYPE_CODE_RANGE
            || is_fixed_point_type (type2));
 
-  /* 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)