aboutsummaryrefslogtreecommitdiff
path: root/gdb/valops.c
diff options
context:
space:
mode:
authorMartin Galvan <martin.galvan@tallertechnologies.com>2016-04-18 10:58:14 -0300
committerMartin Galvan <martin.galvan@tallertechnologies.com>2016-04-18 10:58:14 -0300
commita22df60ad216517bbca4b391bec09f9ded06ab7b (patch)
treeed1d096713275c5bbe3a117a669bb5f943b9a049 /gdb/valops.c
parent0c13f7e559afe5f973a59311b0e401296c48d96c (diff)
downloadfsf-binutils-gdb-a22df60ad216517bbca4b391bec09f9ded06ab7b.zip
fsf-binutils-gdb-a22df60ad216517bbca4b391bec09f9ded06ab7b.tar.gz
fsf-binutils-gdb-a22df60ad216517bbca4b391bec09f9ded06ab7b.tar.bz2
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.
Diffstat (limited to 'gdb/valops.c')
-rw-r--r--gdb/valops.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/gdb/valops.c b/gdb/valops.c
index 5a244a9..8a555f3 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -1463,11 +1463,20 @@ value_addr (struct value *arg1)
if (TYPE_CODE (type) == TYPE_CODE_REF)
{
/* Copy the value, but change the type from (T&) to (T*). We
- keep the same location information, which is efficient, and
- allows &(&X) to get the location containing the reference. */
+ keep the same location information, which is efficient, and
+ allows &(&X) to get the location containing the reference.
+ Do the same to its enclosing type for consistency. */
+ struct type *type_ptr
+ = lookup_pointer_type (TYPE_TARGET_TYPE (type));
+ struct type *enclosing_type
+ = check_typedef (value_enclosing_type (arg1));
+ struct type *enclosing_type_ptr
+ = lookup_pointer_type (TYPE_TARGET_TYPE (enclosing_type));
+
arg2 = value_copy (arg1);
- deprecated_set_value_type (arg2,
- lookup_pointer_type (TYPE_TARGET_TYPE (type)));
+ deprecated_set_value_type (arg2, type_ptr);
+ set_value_enclosing_type (arg2, enclosing_type_ptr);
+
return arg2;
}
if (TYPE_CODE (type) == TYPE_CODE_FUNC)