gdb/dwarf2: Fix 'rw_pieced_value' for values casted to different type.
The 'rw_pieced_value' function is executed when fetching a (lazy)
variable described by 'DW_OP_piece' or 'DW_OP_bit_piece'. The
function checks the 'type' and 'enclosing_type' fields of the value
for identity.
* The 'type' field describes the type of a value.
* In most cases, the 'enclosing_type' field is identical to the
'type' field.
* Scenarios where the 'type' and 'enclosing_type' of an object
differ are described in 'gdb/value.c'. Possible cases are:
* If a value represents a C++ object, then the 'type' field
gives the object's compile-time type. If the object actually
belongs to some class derived from `type', perhaps with other
base classes and additional members, then `type' is just a
subobject of the real thing, and the full object is probably
larger than `type' would suggest.
* If 'type' is a dynamic class (i.e. one with a vtable), then GDB
can actually determine the object's run-time type by looking at
the run-time type information in the vtable. GDB may then elect
to read the entire object.
* If the user casts a variable to a different type
(e.g. 'print (<type> []) <variable>'), the value's type is
updated before reading the value.
If a lazy value is fetched, GDB allocates space based on the enclosing
type's length and typically reads the 'full' object. This is not
implemented for pieced values and causes an internal error if 'type'
and 'enclosing_type' of a value are not identical.
However, GDB can read the value based on its type. Thus, this patch
fixes the previously mentioned cases by removing the check for identity.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28605
gdb/ChangeLog:
2022-04-13 Stephan Rohr <stephan.rohr@intel.com>
* dwarf2/loc.c (rw_pieced_value): Fix check on 'type' and
'enlcosing_type' when reading pieced value 'v'.
gdb/testsuite/ChangeLog:
2022-04-13 Stephan Rohr <stephan.rohr@intel.com>
* gdb.dwarf2/shortpiece.exp: Added test cases.