1 # Copyright 2016-2017 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 accessing "non-variable" variables, i.e., variables which are
17 # optimized to a constant DWARF location expression and/or
18 # partially/fully optimized out.
22 if {![dwarf2_support]} { return 0 }
24 standard_testfile main.c nonvar-access-dw.S
26 # Make some DWARF for the test.
27 set asm_file [standard_output_file $srcfile2]
29 Dwarf::assemble $asm_file {
34 declare_labels int_type_label char_type_label \
35 struct_s_label struct_t_label array_a9_label \
36 char_ptr_label implicit_a_label stack_b_label
38 int_type_label: base_type {
40 {encoding @DW_ATE_signed}
41 {byte_size 4 DW_FORM_sdata}
43 char_type_label: base_type {
45 {encoding @DW_ATE_unsigned}
46 {byte_size 1 DW_FORM_sdata}
48 char_ptr_label: pointer_type {
49 {type :$char_type_label}
52 struct_s_label: structure_type {
54 {byte_size 4 DW_FORM_sdata}
58 {type :$int_type_label}
59 {data_member_location 0 DW_FORM_udata}
60 {bit_size 8 DW_FORM_udata}
64 {type :$int_type_label}
65 {data_bit_offset 8 DW_FORM_udata}
66 {bit_size 24 DW_FORM_udata}
70 struct_t_label: structure_type {
72 {byte_size 4 DW_FORM_sdata}
76 {type :$int_type_label}
77 {data_member_location 0 DW_FORM_udata}
78 {bit_size 9 DW_FORM_udata}
82 {type :$int_type_label}
83 {data_bit_offset 9 DW_FORM_udata}
84 {bit_size 23 DW_FORM_udata}
88 array_a9_label: array_type {
89 {type :$char_type_label}
92 {type :$int_type_label}
93 {upper_bound 8 DW_FORM_udata}
99 {DW_AT_external 1 flag}
100 {low_pc [gdb_target_symbol main] DW_FORM_addr}
101 {high_pc [gdb_target_symbol main]+0x10000 DW_FORM_addr}
103 # Simple variable without location.
106 {type :$int_type_label}
108 # Struct variable without location.
111 {type :$struct_s_label}
113 # Composite location: byte-aligned pieces.
116 {type :$struct_s_label}
126 # Composite location: non-byte-aligned pieces.
129 {type :$struct_t_label}
139 # Implicit location: immediate value.
141 {name def_implicit_s}
142 {type :$struct_s_label}
144 implicit_value 0x12 0x34 0x56 0x78
147 # Implicit location: immediate value for whole array, with
149 implicit_a_label: DW_TAG_variable {
150 {name def_implicit_a}
151 {type :$array_a9_label}
153 implicit_value 0x1 0x12 0x23 0x34 0x45 \
154 0x56 0x67 0x78 0x89 0x9a 0xab
157 # Implicit pointer into immediate value.
159 {name implicit_a_ptr}
160 {type :$char_ptr_label}
162 implicit_pointer $implicit_a_label 5
165 # Stack-value location.
166 stack_b_label: DW_TAG_variable {
168 {type :$struct_t_label}
174 # Implicit pointer into stack value.
176 {name implicit_b_ptr}
177 {type :$char_ptr_label}
179 implicit_pointer $stack_b_label 1
187 if { [prepare_for_testing "failed to prepare" ${testfile} \
188 [list $srcfile $asm_file] {nodebug}] } {
196 # Determine endianness.
198 gdb_test_multiple "show endian" "determine endianness" {
199 -re ".* (big|little) endian.*$gdb_prompt $" {
200 set endian $expect_out(1,string)
201 pass "endianness: $endian"
205 # Byte-aligned objects with simple location descriptions.
206 switch $endian { big {set val 0x345678} little {set val 0x785634} }
207 gdb_test "print/x def_implicit_s" " = \\{a = 0x12, b = $val\\}"
208 gdb_test "print/x def_implicit_s.b" " = $val"
209 gdb_test "print/x def_implicit_a" \
210 " = \\{0x1, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, 0x89\\}"
211 gdb_test "print/x def_implicit_a\[5\]" " = 0x56"
212 gdb_test "print/x *(char (*)\[5\]) implicit_a_ptr" \
213 " = \\{0x56, 0x67, 0x78, 0x89, 0x9a\\}"
215 big {set val "a = 52, b = 2833485"}
216 little {set val "a = 77, b = 857502"}
218 gdb_test "print def_stack_b" " = \\{$val\\}"
219 switch $endian {big {set val 0x2b} little {set val 0x3c}}
220 gdb_test "print/x *implicit_b_ptr" " = $val"
222 # Byte-aligned fields, pieced together from DWARF stack values.
223 gdb_test "print def_s" " = \\{a = 0, b = -1\\}"
225 # Non-byte-aligned fields, pieced together from DWARF stack values.
226 gdb_test "print def_t" " = \\{a = 0, b = -1\\}"
228 # Simple variable without location.
229 gdb_test "print undef_int" " = <optimized out>"
231 # Member of a structure without location.
232 gdb_test "print undef_s.a" " = <optimized out>"