Update copyright year range in all GDB files.
[binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / nonvar-access.exp
bloba3705f9514feab036ef391aefb1c3311cebd04c2
1 # Copyright 2016-2020 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.
20 load_lib dwarf.exp
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 {
30     global srcdir subdir srcfile
32     set range [function_range main ${srcdir}/${subdir}/${srcfile}]
33     set main_start [lindex $range 0]
34     set main_length [lindex $range 1]
36     cu {} {
37         compile_unit {
38             {DW_AT_name main.c}
39         } {
40             declare_labels int_type_label char_type_label \
41                 struct_s_label struct_t_label array_a9_label \
42                 char_ptr_label implicit_a_label stack_b_label
44             int_type_label: base_type {
45                 {name "int"}
46                 {encoding @DW_ATE_signed}
47                 {byte_size 4 DW_FORM_sdata}
48             }
49             char_type_label: base_type {
50                 {name "char"}
51                 {encoding @DW_ATE_unsigned}
52                 {byte_size 1 DW_FORM_sdata}
53             }
54             char_ptr_label: pointer_type {
55                 {type :$char_type_label}
56             }
58             struct_s_label: structure_type {
59                 {name s}
60                 {byte_size 4 DW_FORM_sdata}
61             } {
62                 member {
63                     {name a}
64                     {type :$int_type_label}
65                     {data_member_location 0 DW_FORM_udata}
66                     {bit_size 8 DW_FORM_udata}
67                 }
68                 member {
69                     {name b}
70                     {type :$int_type_label}
71                     {data_bit_offset 8 DW_FORM_udata}
72                     {bit_size 24 DW_FORM_udata}
73                 }
74             }
76             struct_t_label: structure_type {
77                 {name t}
78                 {byte_size 4 DW_FORM_sdata}
79             } {
80                 member {
81                     {name a}
82                     {type :$int_type_label}
83                     {data_member_location 0 DW_FORM_udata}
84                     {bit_size 9 DW_FORM_udata}
85                 }
86                 member {
87                     {name b}
88                     {type :$int_type_label}
89                     {data_bit_offset 9 DW_FORM_udata}
90                     {bit_size 23 DW_FORM_udata}
91                 }
92             }
94             array_a9_label: array_type {
95                 {type :$char_type_label}
96             } {
97                 subrange_type {
98                     {type :$int_type_label}
99                     {upper_bound 8 DW_FORM_udata}
100                 }
101             }
103             DW_TAG_subprogram {
104                 {name main}
105                 {DW_AT_external 1 flag}
106                 {low_pc [gdb_target_symbol main] DW_FORM_addr}
107                 {high_pc "$main_start + $main_length" DW_FORM_addr}
108             } {
109                 # Simple variable without location.
110                 DW_TAG_variable {
111                     {name undef_int}
112                     {type :$int_type_label}
113                 }
114                 # Struct variable without location.
115                 DW_TAG_variable {
116                     {name undef_s}
117                     {type :$struct_s_label}
118                 }
119                 # Composite location: byte-aligned pieces.
120                 DW_TAG_variable {
121                     {name def_s}
122                     {type :$struct_s_label}
123                     {location {
124                         const1u 0
125                         stack_value
126                         bit_piece 8 0
127                         const1s -1
128                         stack_value
129                         bit_piece 24 0
130                     } SPECIAL_expr}
131                 }
132                 # Composite location: non-byte-aligned pieces.
133                 DW_TAG_variable {
134                     {name def_t}
135                     {type :$struct_t_label}
136                     {location {
137                         const2s -184
138                         stack_value
139                         bit_piece 9 0
140                         const4u 1752286
141                         stack_value
142                         bit_piece 23 0
143                     } SPECIAL_expr}
144                 }
145                 # Composite location with some empty pieces.
146                 DW_TAG_variable {
147                     {name part_def_a}
148                     {type :$array_a9_label}
149                     {location {
150                         piece 3
151                         const4u 0xf1927314
152                         stack_value
153                         piece 4
154                         piece 2
155                     } SPECIAL_expr}
156                 }
157                 # Implicit location: immediate value.
158                 DW_TAG_variable {
159                     {name def_implicit_s}
160                     {type :$struct_s_label}
161                     {location {
162                         implicit_value 0x12 0x34 0x56 0x78
163                     } SPECIAL_expr}
164                 }
165                 # Implicit location: immediate value for whole array, with
166                 # excess bytes.
167                 implicit_a_label: DW_TAG_variable {
168                     {name def_implicit_a}
169                     {type :$array_a9_label}
170                     {location {
171                         implicit_value 0x1 0x12 0x23 0x34 0x45 \
172                             0x56 0x67 0x78 0x89 0x9a 0xab
173                     } SPECIAL_expr}
174                 }
175                 # Implicit pointer into immediate value.
176                 DW_TAG_variable {
177                     {name implicit_a_ptr}
178                     {type :$char_ptr_label}
179                     {location {
180                         implicit_pointer $implicit_a_label 5
181                     } SPECIAL_expr}
182                 }
183                 # Stack-value location.
184                 stack_b_label: DW_TAG_variable {
185                     {name def_stack_b}
186                     {type :$struct_t_label}
187                     {location {
188                         const4u 0x1a2b3c4d
189                         stack_value
190                     } SPECIAL_expr}
191                 }
192                 # Implicit pointer into stack value.
193                 DW_TAG_variable {
194                     {name implicit_b_ptr}
195                     {type :$char_ptr_label}
196                     {location {
197                         implicit_pointer $stack_b_label 1
198                     } SPECIAL_expr}
199                 }
200             }
201         }
202     }
205 if { [prepare_for_testing "failed to prepare" ${testfile} \
206           [list $srcfile $asm_file] {nodebug}] } {
207     return -1
210 if ![runto_main] {
211     return -1
214 # Determine byte order.
215 set endian [get_endianness]
217 # Byte-aligned objects with simple location descriptions.
218 switch $endian { big {set val 0x345678} little {set val 0x785634} }
219 gdb_test "print/x def_implicit_s" " = \\{a = 0x12, b = $val\\}"
220 gdb_test "print/x def_implicit_s.b" " = $val"
221 gdb_test "print/x def_implicit_a" \
222     " = \\{0x1, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, 0x89\\}"
223 gdb_test "print/x def_implicit_a\[5\]" " = 0x56"
224 gdb_test "print/x *(char (*)\[5\]) implicit_a_ptr" \
225     " = \\{0x56, 0x67, 0x78, 0x89, 0x9a\\}"
226 switch $endian {
227     big {set val "a = 52, b = 2833485"}
228     little {set val "a = 77, b = 857502"}
230 gdb_test "print def_stack_b" " = \\{$val\\}"
231 switch $endian {big {set val 0x2b} little {set val 0x3c}}
232 gdb_test "print/x *implicit_b_ptr" " = $val"
234 # Byte-aligned fields, pieced together from DWARF stack values.
235 gdb_test "print def_s" " = \\{a = 0, b = -1\\}"
236 switch $endian { big {set val 0x92} little {set val 0x73} }
237 gdb_test "print/x part_def_a\[4\]" " = $val"
238 gdb_test "print/x part_def_a\[8\]" " = <optimized out>"
240 # Non-byte-aligned fields, pieced together from DWARF stack values.
241 gdb_test "print def_t" " = \\{a = -184, b = 1752286\\}"
243 # Simple variable without location.
244 gdb_test "print undef_int" " = <optimized out>"
246 # Member of a structure without location.
247 gdb_test "print undef_s.a" " = <optimized out>"