aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.dwarf2/implref-const.exp
diff options
context:
space:
mode:
authorMartin Galvan <martin.galvan@tallertechnologies.com>2016-05-31 15:54:01 -0300
committerMartin Galvan <martin.galvan@tallertechnologies.com>2016-05-31 15:56:34 -0300
commit3326303bf5ae4c92f2fbbff387ce231a16c1c8bf (patch)
tree6003faaf0747941817afc8d62f9f2a0bffcd3802 /gdb/testsuite/gdb.dwarf2/implref-const.exp
parentf7433f011ef27838551aded73b8666a86d26b8ec (diff)
downloadgdb-3326303bf5ae4c92f2fbbff387ce231a16c1c8bf.zip
gdb-3326303bf5ae4c92f2fbbff387ce231a16c1c8bf.tar.gz
gdb-3326303bf5ae4c92f2fbbff387ce231a16c1c8bf.tar.bz2
[PR gdb/19893] Fix handling of synthetic C++ references
https://sourceware.org/bugzilla/show_bug.cgi?id=19893 I've traced the main source of the problem to pieced_value_funcs.coerce_ref not being implemented. Since gdb always assumes references are implemented as pointers, this causes it to think that it's dealing with a NULL pointer, thus breaking any operations involving synthetic references. What I did here was implementing pieced_value_funcs.coerce_ref using some of the synthetic pointer handling code from indirect_pieced_value, as Pedro suggested. I also made a few adjustments to the reference printing code so that it correctly shows either the address of the referenced value or (if it's non-addressable) the "<synthetic pointer>" string. I also wrote some unit tests based on Dwarf::assemble; these took a while to make because in most cases I needed a synthetic reference to a physical variable. Additionally, I started working on a unit test for classes that have a vtable, but ran into a few issues so that'll probably go in a future patch. One thing that should definitely be fixed is that proc function_range (called for MACRO_AT_func) will always try to compile/link using gcc with the default options instead of g++, thus breaking C++ compilations that require e.g. libstdc++. gdb/ChangeLog: * dwarf2loc.c (coerce_pieced_ref, indirect_synthetic_pointer, fetch_const_value_from_synthetic_pointer): New functions. (indirect_pieced_value): Move lower half to indirect_synthetic_pointer. (pieced_value_funcs): Implement coerce_ref. * valops.c (value_addr): Call coerce_ref for synthetic references. * valprint.c (valprint_check_validity): Return true for synthetic references. Also, don't show "<synthetic pointer>" if they reference addressable values. (generic_val_print_ref): Handle synthetic references. Also move some code to print_ref_address. (print_ref_address, get_value_addr_contents): New functions. gdb/testsuite/ChangeLog: * gdb.dwarf2/implref.exp: Rename to... * gdb.dwarf2/implref-const.exp: ...this. Also add more test statements. * gdb.dwarf2/implref-array.c: New file. * gdb.dwarf2/implref-array.exp: Likewise. * gdb.dwarf2/implref-global.c: Likewise. * gdb.dwarf2/implref-global.exp: Likewise. * gdb.dwarf2/implref-struct.c: Likewise. * gdb.dwarf2/implref-struct.exp: Likewise.
Diffstat (limited to 'gdb/testsuite/gdb.dwarf2/implref-const.exp')
-rw-r--r--gdb/testsuite/gdb.dwarf2/implref-const.exp119
1 files changed, 119 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.dwarf2/implref-const.exp b/gdb/testsuite/gdb.dwarf2/implref-const.exp
new file mode 100644
index 0000000..9b6d5fe
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/implref-const.exp
@@ -0,0 +1,119 @@
+# Copyright 2016 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test a C++ reference marked with DW_OP_GNU_implicit_pointer.
+# The referenced value is a DW_AT_const_value.
+
+if [skip_cplus_tests] {
+ continue
+}
+
+load_lib dwarf.exp
+
+# This test can only be run on targets which support DWARF-2 and use gas.
+if ![dwarf2_support] {
+ return 0
+}
+
+# We'll place the output of Dwarf::assemble in implref-const.S.
+standard_testfile main.c .S
+
+# ${testfile} is now "implref-const". srcfile2 is "implref-const.S".
+set executable ${testfile}
+set asm_file [standard_output_file ${srcfile2}]
+
+# We need to know the size of integer and address types in order
+# to write some of the debugging info we'd like to generate.
+#
+# For that, we ask GDB by debugging our implref-const program.
+# Any program would do, but since we already have implref-const
+# specifically for this testcase, might as well use that.
+if [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] {
+ untested ${testfile}.exp
+ return -1
+}
+
+# Create the DWARF. We need a regular variable and a reference to it that'll
+# be marked with DW_OP_GNU_implicit_pointer.
+Dwarf::assemble ${asm_file} {
+ global srcdir subdir srcfile
+
+ cu {} {
+ DW_TAG_compile_unit {
+ {DW_AT_language @DW_LANG_C_plus_plus}
+ } {
+ declare_labels int_label const_label variable_label ref_label
+ set int_size [get_sizeof "int" -1]
+
+ # gdb always assumes references are implemented as pointers.
+ set addr_size [get_sizeof "void *" -1]
+ set var_value 42
+
+ int_label: DW_TAG_base_type {
+ {DW_AT_byte_size ${int_size} DW_FORM_udata}
+ {DW_AT_encoding @DW_ATE_signed}
+ {DW_AT_name "int"}
+ }
+
+ ref_label: DW_TAG_reference_type {
+ {DW_AT_byte_size ${addr_size} DW_FORM_udata}
+ {DW_AT_type :${int_label}}
+ }
+
+ const_label: DW_TAG_const_type {
+ {DW_AT_type :${ref_label}}
+ }
+
+ DW_TAG_subprogram {
+ {MACRO_AT_func { "main" "${srcdir}/${subdir}/${srcfile}" }}
+ {DW_AT_type :${int_label}}
+ {DW_AT_external 1 DW_FORM_flag}
+ } {
+ variable_label: DW_TAG_variable {
+ {DW_AT_name "var"}
+ {DW_AT_type :${int_label}}
+ {DW_AT_const_value ${var_value} DW_FORM_udata}
+ }
+
+ DW_TAG_variable {
+ {DW_AT_name "ref"}
+ {DW_AT_type :${const_label}}
+ {DW_AT_location {DW_OP_GNU_implicit_pointer ${variable_label} 0} SPECIAL_expr}
+ }
+ }
+ }
+ }
+}
+
+if [prepare_for_testing ${testfile}.exp ${executable} [list ${asm_file} ${srcfile}] {}] {
+ return -1
+}
+
+# DW_OP_GNU_implicit_pointer implementation requires a valid frame.
+if ![runto_main] {
+ return -1
+}
+
+# Doing 'print ref' should show us e.g. '(int &) <synthetic pointer>: 42'.
+gdb_test "print ref" " = \\(int &\\) <synthetic pointer>: \\\d+"
+
+# The variable isn't located in memory, thus we can't take its address.
+gdb_test "print &var" "Can't take address of \"var\" which isn't an lvalue."
+gdb_test "print &ref" "Attempt to take address of value not located in memory."
+
+# gdb assumes C++ references are implemented as pointers, and print &(&ref)
+# shows us the underlying pointer's address.
+# Since in this case there's no physical pointer, gdb should tell us so.
+gdb_test "print &(&ref)" "Attempt to take address of value not located in memory."