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/?a=commitdiff_plain;h=24ba75a5c41ec617dc1ed1b9f996467ff666166f;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/ChangeLog b/gdb/ChangeLog index 772b93fd06c..c1a4f45d9c8 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2020-11-11 Luis Machado + + * valops.c (value_cast): Handle casting from capabilities and + capability pointers. + 2020-11-11 Luis Machado * aarch64-tdep.c (aarch64_address_class_type_flags) diff --git a/gdb/valops.c b/gdb/valops.c index 3c0ed38a97f..d0f1a1ed604 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -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)