From 0d4e84ed37c404eb7e691ee9d68ae2ec758d8f66 Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Fri, 1 Mar 2019 11:06:23 +0000 Subject: gdb: Better support for dynamic properties with negative values When the type of a property is smaller than the CORE_ADDR in which the property value has been placed, and if the property is signed, then sign extend the property value from its actual type up to the size of CORE_ADDR. gdb/ChangeLog: * dwarf2loc.c (dwarf2_evaluate_property): Sign extend property value if its desired type is smaller than a CORE_ADDR and signed. gdb/testsuite/ChangeLog: * gdb.fortran/vla-ptype.exp: Print array with negative bounds. * gdb.fortran/vla-sizeof.exp: Print the size of an array with negative bounds. * gdb.fortran/vla-value.exp: Print elements of an array with negative bounds. * gdb.fortran/vla.f90: Setup an array with negative bounds for testing. --- gdb/dwarf2loc.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'gdb/dwarf2loc.c') diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c index 00f3d76..63643cb 100644 --- a/gdb/dwarf2loc.c +++ b/gdb/dwarf2loc.c @@ -2454,6 +2454,29 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop, struct value *val = value_at (baton->property_type, *value); *value = value_as_address (val); } + else + { + gdb_assert (baton->property_type != NULL); + + struct type *type = check_typedef (baton->property_type); + if (TYPE_LENGTH (type) < sizeof (CORE_ADDR) + && !TYPE_UNSIGNED (type)) + { + /* If we have a valid return candidate and it's value + is signed, we have to sign-extend the value because + CORE_ADDR on 64bit machine has 8 bytes but address + size of an 32bit application is bytes. */ + const int addr_size + = (dwarf2_per_cu_addr_size (baton->locexpr.per_cu) + * TARGET_CHAR_BIT); + const CORE_ADDR neg_mask + = (~((CORE_ADDR) 0) << (addr_size - 1)); + + /* Check if signed bit is set and sign-extend values. */ + if (*value & neg_mask) + *value |= neg_mask; + } + } return true; } } -- cgit v1.1