1 # Copyright 2018-2019 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # Test support for DW_OP_GNU_variable_value.
20 # This test can only be run on targets which support DWARF-2 and use gas.
21 if ![dwarf2_support] {
25 # We'll place the output of Dwarf::assemble in varval.S.
26 standard_testfile .c .S
28 # ${testfile} is now "varval". srcfile2 is "varval.S".
29 set executable ${testfile}
30 set asm_file [standard_output_file ${srcfile2}]
32 # We need to know the size of integer and address types in order
33 # to write some of the debugging info we'd like to generate.
35 # For that, we ask GDB by debugging our varval program.
36 # Any program would do, but since we already have varval
37 # specifically for this testcase, might as well use that.
38 if [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] {
42 proc setup_exec { arg_bad } {
43 global asm_file executable srcfile bad
47 Dwarf::assemble ${asm_file} {
48 global srcdir subdir srcfile bad
52 {DW_AT_language @DW_LANG_C_plus_plus}
54 declare_labels int_label ptr_label struct_label var_a_label \
55 var_b_label var_c_label var_p_label var_bad_label \
56 varval_label var_s_label var_untyped_label \
57 var_a_abstract_label var_a_concrete_label \
60 set int_size [get_sizeof "int" -1]
62 # gdb always assumes references are implemented as pointers.
63 set addr_size [get_sizeof "void *" -1]
65 int_label: DW_TAG_base_type {
66 {DW_AT_byte_size ${int_size} DW_FORM_udata}
67 {DW_AT_encoding @DW_ATE_signed}
71 ptr_label: DW_TAG_pointer_type {
72 {DW_AT_type :$int_label}
75 var_a_label: DW_TAG_variable {
77 {DW_AT_type :${int_label}}
78 {DW_AT_external 1 DW_FORM_flag}
79 {DW_AT_location {DW_OP_addr [gdb_target_symbol "var_a"]} SPECIAL_expr}
82 var_a_abstract_label: DW_TAG_variable {
83 {DW_AT_type :${int_label}}
84 {DW_AT_external 1 DW_FORM_flag}
87 var_b_label: DW_TAG_variable {
89 {DW_AT_type :${int_label}}
90 {DW_AT_external 1 DW_FORM_flag}
91 {DW_AT_location {DW_OP_addr [gdb_target_symbol "var_b"]} SPECIAL_expr}
94 var_c_label: DW_TAG_variable {
96 {DW_AT_type :${int_label}}
97 {DW_AT_external 1 DW_FORM_flag}
98 {DW_AT_const_value 53 DW_FORM_sdata}
101 var_p_label: DW_TAG_variable {
103 {DW_AT_type :${ptr_label}}
104 {DW_AT_external 1 DW_FORM_flag}
105 {DW_AT_location {DW_OP_addr [gdb_target_symbol "var_p"]} SPECIAL_expr}
109 var_bad_label: DW_TAG_variable {
110 {DW_AT_name "var_bad"}
111 {DW_AT_type :${int_label}}
112 {DW_AT_external 1 DW_FORM_flag}
116 struct_label: DW_TAG_structure_type {
117 {DW_AT_byte_size 8*$int_size DW_FORM_sdata}
121 {DW_AT_type :$int_label}
122 {DW_AT_data_member_location 0*$int_size DW_FORM_udata}
126 {DW_AT_type :$int_label}
127 {DW_AT_data_member_location 1*$int_size DW_FORM_udata}
131 {DW_AT_type :$int_label}
132 {DW_AT_data_member_location 2*$int_size DW_FORM_udata}
136 {DW_AT_type :$int_label}
137 {DW_AT_data_member_location 3*$int_size DW_FORM_udata}
141 {DW_AT_type :$int_label}
142 {DW_AT_data_member_location 4*$int_size DW_FORM_udata}
146 {DW_AT_type :$int_label}
147 {DW_AT_data_member_location 5*$int_size DW_FORM_udata}
151 {DW_AT_type :$int_label}
152 {DW_AT_data_member_location 6*$int_size DW_FORM_udata}
156 {DW_AT_type :$int_label}
157 {DW_AT_data_member_location 7*$int_size DW_FORM_udata}
161 var_s_label: DW_TAG_variable {
163 {DW_AT_type :${struct_label}}
164 {DW_AT_external 1 DW_FORM_flag}
165 {DW_AT_location {DW_OP_addr [gdb_target_symbol "var_s"]} SPECIAL_expr}
168 var_untyped_label: DW_TAG_variable {
169 {DW_AT_name "var_untyped"}
170 {DW_AT_external 1 DW_FORM_flag}
171 {DW_AT_location {DW_OP_addr [gdb_target_symbol "var_b"]} SPECIAL_expr}
175 {MACRO_AT_func { "main" "${srcdir}/${subdir}/${srcfile}" }}
176 {DW_AT_type :${int_label}}
177 {DW_AT_external 1 DW_FORM_flag}
179 varval_label: DW_TAG_variable {
180 {DW_AT_name "varval"}
181 {DW_AT_type :${int_label}}
183 DW_OP_GNU_variable_value ${var_a_label}
187 varval2_label: DW_TAG_variable {
188 {DW_AT_name "varval2"}
189 {DW_AT_type :${int_label}}
191 DW_OP_GNU_variable_value ${var_a_abstract_label}
195 var_a_concrete_label: DW_TAG_variable {
196 {DW_AT_abstract_origin :${var_a_abstract_label}}
197 {DW_AT_location {DW_OP_addr [gdb_target_symbol "var_a"]} SPECIAL_expr}
200 {DW_AT_name "constval"}
201 {DW_AT_type :${int_label}}
203 DW_OP_GNU_variable_value ${var_c_label}
208 {DW_AT_name "mixedval"}
209 {DW_AT_type :${int_label}}
211 DW_OP_GNU_variable_value ${var_c_label}
212 DW_OP_GNU_variable_value ${var_b_label}
214 DW_OP_GNU_variable_value ${varval_label}
218 DW_OP_GNU_variable_value ${varval_label}
224 {DW_AT_name "pointerval"}
225 {DW_AT_type :${ptr_label}}
227 DW_OP_GNU_variable_value ${var_p_label}
233 {DW_AT_name "badval"}
234 {DW_AT_type :${int_label}}
236 DW_OP_GNU_variable_value ${var_bad_label}
242 {DW_AT_name "structval"}
243 {DW_AT_type :${struct_label}}
245 DW_OP_GNU_variable_value ${var_s_label}
250 {DW_AT_name "untypedval"}
252 DW_OP_GNU_variable_value ${var_untyped_label}
258 {DW_AT_name "bad_die_val1"}
260 DW_OP_GNU_variable_value 0xabcdef11
265 {DW_AT_name "bad_die_val2"}
267 DW_OP_GNU_variable_value ${ptr_label}+1
277 if [prepare_for_testing "failed to prepare" ${executable} [list ${asm_file} ${srcfile}] {}] {
281 # DW_OP_GNU_variable_value implementation requires a valid frame.
287 if { [setup_exec 0] == -1 } {
291 gdb_test "print varval" "= 8"
292 gdb_test "print varval2" "= 8"
293 gdb_test "print constval" "= 53"
294 gdb_test "print mixedval" "= 42"
295 gdb_test "print pointerval" "= \\(int \\*\\) $hex <var_b>"
296 gdb_test "print *pointerval" "= 3"
298 # Jakub says: "The intended behavior is that the debug info consumer
299 # computes the value of that referenced variable at the current PC,
300 # and if it can compute it and pushes the value as a generic type
301 # integer into the DWARF stack (it is really only meaningful when
302 # referring to integral/pointer typed variables)."
304 gdb_test "print structval" \
305 "Type of DW_OP_GNU_variable_value DIE must be an integer or pointer\\."
307 gdb_test "print untypedval" \
308 "Type of DW_OP_GNU_variable_value DIE must be an integer or pointer\\."
310 if { [setup_exec 1] == -1 } {
314 gdb_test "print badval" "value has been optimized out"
315 gdb_test "print bad_die_val1" \
316 "invalid dwarf2 offset 0xabcdef11"
317 gdb_test "print bad_die_val2" \
318 "Bad DW_OP_GNU_variable_value DIE\\."