Fix gdb crash when trying to print the address of a synthetic C++ reference
authorMartin Galvan <martin.galvan@tallertechnologies.com>
Mon, 18 Apr 2016 13:58:14 +0000 (10:58 -0300)
committerMartin Galvan <martin.galvan@tallertechnologies.com>
Mon, 18 Apr 2016 13:58:14 +0000 (10:58 -0300)
commita22df60ad216517bbca4b391bec09f9ded06ab7b
treeed1d096713275c5bbe3a117a669bb5f943b9a049
parent0c13f7e559afe5f973a59311b0e401296c48d96c
Fix gdb crash when trying to print the address of a synthetic C++ reference

After compiling a program which uses C++ references some optimizations may
convert the references into synthetic "pointers".  Trying to print the address
of one of such synthetic references causes gdb to crash with the following
error:

(gdb) print &ref
/build/buildd/gdb-7.7.1/gdb/dwarf2loc.c:1624: internal-error: Should not be able to create a lazy value with an enclosing type
A problem internal to GDB has been detected,
further debugging may prove unreliable.

Apparently, what was causing it was that value_addr returns a copy of the value
that represents the reference with its type set to T* instead of T&.  However,
its enclosing_type is left untouched, which fails a check made in
read_pieced_value.  We only see the crash happen for references that are
synthetic because they're treated as pieced values, thus the call to
read_pieced_value.

On a related note, it seems that in general there are all sorts of breakage
when working with synthetic references.  This is reported here:

https://sourceware.org/bugzilla/show_bug.cgi?id=19893

gdb/ChangeLog:
2016-04-18  Martin Galvan  <martin.galvan@tallertechnologies.com>

* valops.c (value_addr): For C++ references, set the copied value's
enclosing_type as well.

gdb/testsuite/ChangeLog:
2016-04-18  Martin Galvan  <martin.galvan@tallertechnologies.com>

* gdb.dwarf2/implref.exp: New file.
gdb/ChangeLog
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.dwarf2/implref.exp [new file with mode: 0644]
gdb/valops.c