From: Luis Machado Date: Wed, 4 Nov 2020 19:13:05 +0000 (-0300) Subject: Support casting capabilities/capability pointers to other types X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=951515fc160181ca03902b17f1aac9e85b38b098;p=thirdparty%2Fbinutils-gdb.git Support casting capabilities/capability pointers to other types 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 * valops.c (value_cast): Handle casting from capabilities and capability pointers. --- diff --git a/gdb/valops.c b/gdb/valops.c index d4e89a3cfa6..d1fe6d1024d 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -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)