Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / dw2-fixed-point.exp
1 # Copyright 2016-2022 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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/>.
15 load_lib dwarf.exp
16
17 # This test can only be run on targets which support DWARF-2 and use gas.
18 if {![dwarf2_support]} {
19 return 0
20 }
21
22 standard_testfile dw2-fixed-point.c dw2-fixed-point-dw.S
23
24 # Make some DWARF for the test.
25 set asm_file [standard_output_file $srcfile2]
26 Dwarf::assemble $asm_file {
27 cu {} {
28 DW_TAG_compile_unit {
29 {DW_AT_language @DW_LANG_Ada95}
30 {DW_AT_name pck.ads}
31 {DW_AT_comp_dir /tmp}
32 } {
33 declare_labels fp1_base_type fp2_base_type fp3_small \
34 fp3_base_type fp1_range_type
35
36 fp1_base_type: DW_TAG_base_type {
37 {DW_AT_byte_size 1 DW_FORM_sdata}
38 {DW_AT_encoding @DW_ATE_signed_fixed}
39 {DW_AT_name pck__fp1_type}
40 {DW_AT_binary_scale -4 DW_FORM_sdata}
41 }
42
43 DW_TAG_variable {
44 {DW_AT_name pck__fp1_var}
45 {DW_AT_type :$fp1_base_type}
46 {DW_AT_location {
47 DW_OP_addr [gdb_target_symbol pck__fp1_var]
48 } SPECIAL_expr}
49 {external 1 flag}
50 }
51
52 DW_TAG_variable {
53 {DW_AT_name pck__fp1_var2}
54 {DW_AT_type :$fp1_base_type}
55 {DW_AT_location {
56 DW_OP_addr [gdb_target_symbol pck__fp1_var2]
57 } SPECIAL_expr}
58 {external 1 flag}
59 }
60
61 fp2_base_type: DW_TAG_base_type {
62 {DW_AT_byte_size 1 DW_FORM_sdata}
63 {DW_AT_encoding @DW_ATE_signed_fixed}
64 {DW_AT_name pck__fp2_type}
65 {DW_AT_decimal_scale -2 DW_FORM_sdata}
66 }
67
68 DW_TAG_variable {
69 {DW_AT_name pck__fp2_var}
70 {DW_AT_type :$fp2_base_type}
71 {DW_AT_location {
72 DW_OP_addr [gdb_target_symbol pck__fp2_var]
73 } SPECIAL_expr}
74 {external 1 flag}
75 }
76
77 fp3_small: DW_TAG_constant {
78 {DW_AT_GNU_numerator 1 DW_FORM_data1}
79 {DW_AT_GNU_denominator 30 DW_FORM_sdata}
80 }
81
82 fp3_base_type: DW_TAG_base_type {
83 {DW_AT_byte_size 1 DW_FORM_sdata}
84 {DW_AT_encoding @DW_ATE_signed_fixed}
85 {DW_AT_name pck__fp3_type}
86 {DW_AT_small :$fp3_small}
87 }
88
89 DW_TAG_variable {
90 {DW_AT_name pck__fp3_var}
91 {DW_AT_type :$fp3_base_type}
92 {DW_AT_location {
93 DW_OP_addr [gdb_target_symbol pck__fp3_var]
94 } SPECIAL_expr}
95 {external 1 flag}
96 }
97
98 fp1_range_type: DW_TAG_subrange_type {
99 {DW_AT_lower_bound 0xf0 DW_FORM_data1}
100 {DW_AT_upper_bound 0x10 DW_FORM_data1}
101 {DW_AT_name foo__fp1_range_type}
102 {DW_AT_type :$fp1_base_type}
103 }
104
105 DW_TAG_variable {
106 {DW_AT_name pck__fp1_range_var}
107 {DW_AT_type :$fp1_range_type}
108 {DW_AT_location {
109 DW_OP_addr [gdb_target_symbol pck__fp1_range_var]
110 } SPECIAL_expr}
111 {external 1 flag}
112 }
113 }
114 }
115 }
116
117 if { [prepare_for_testing ${testfile}.exp ${testfile} \
118 [list $srcfile $asm_file] {nodebug}] } {
119 return -1
120 }
121
122 if ![runto_main] {
123 return -1
124 }
125
126 # Do the testing in Ada mode, since this is the language for which
127 # this feature has been implemented, and where we know the language
128 # has the concept of fixed-point types.
129 gdb_test_no_output "set lang ada"
130
131 gdb_test "print pck.fp1_var" \
132 " = 0.25"
133
134 gdb_test "print /x pck.fp1_var" \
135 " = 0x0"
136
137 gdb_test "print pck.fp2_var" \
138 " = -0.01"
139
140 gdb_test "print /x pck.fp2_var" \
141 " = 0x0"
142
143 gdb_test "print pck.fp3_var" \
144 " = 0.1"
145
146 gdb_test "print /x pck.fp3_var" \
147 " = 0x0"
148
149 gdb_test "print pck.fp1_range_var" \
150 " = 1"
151
152 gdb_test "print /x pck.fp1_range_var" \
153 " = 0x1"
154
155 gdb_test "print pck.fp1_var + 0.25" \
156 " = 0.5"
157
158 gdb_test "print pck.fp2_var - pck.fp2_var" \
159 " = 0"
160
161 gdb_test "print pck.fp3_var * 1" \
162 " = 0.1"
163
164 gdb_test "print pck.fp3_var / pck.fp3_var" \
165 " = 1"
166
167 gdb_test "print pck.fp3_var / 0" \
168 "Division by zero"
169
170 gdb_test "print pck.fp1_range_var - 0.5" \
171 " = 0.5"
172
173 gdb_test "print -pck.fp1_var" \
174 " = -0.25"
175
176 gdb_test "print pck.fp1_var = pck.fp1_var" \
177 " = true"
178
179 gdb_test "print pck.fp1_var = pck.fp1_var2" \
180 " = false"
181
182 gdb_test "print pck.fp1_var /= pck.fp1_var" \
183 " = false"
184
185 gdb_test "print pck.fp1_var /= pck.fp1_var2" \
186 " = true"
187
188 gdb_test "print pck.fp1_var < pck.fp1_var" \
189 " = false"
190
191 gdb_test "print pck.fp1_var < pck.fp1_var2" \
192 " = true"
193
194 gdb_test "print pck.fp1_var <= pck.fp1_var2" \
195 " = true"
196
197 gdb_test "print pck.fp1_var <= pck.fp1_var" \
198 " = true"
199
200 gdb_test "print pck.fp1_var > pck.fp1_var2" \
201 " = false"
202
203 gdb_test "print pck.fp1_var2 > pck.fp1_var" \
204 " = true"
205
206 gdb_test "print pck.fp1_var >= pck.fp1_var" \
207 " = true"
208
209 gdb_test "print pck.fp1_var >= pck.fp1_var2" \
210 " = false"
211
212 # Same as above, but with litterals...
213
214 gdb_test "print pck.fp1_var = 0.25" \
215 " = true"
216
217 gdb_test "print pck.fp1_var = 0.5" \
218 " = false"
219
220 gdb_test "print pck.fp1_var = 1" \
221 " = false"
222
223 gdb_test "print pck.fp1_var /= 0.25" \
224 " = false"
225
226 gdb_test "print pck.fp1_var /= 0.5" \
227 " = true"
228
229 gdb_test "print pck.fp1_var /= 1" \
230 " = true"
231
232 gdb_test "print pck.fp1_var < 0.25" \
233 " = false"
234
235 gdb_test "print pck.fp1_var < 0.5" \
236 " = true"
237
238 gdb_test "print pck.fp1_var < 1" \
239 " = true"
240
241 gdb_test "print pck.fp1_var <= 0.25" \
242 " = true"
243
244 gdb_test "print pck.fp1_var <= 0.5" \
245 " = true"
246
247 gdb_test "print pck.fp1_var <= 1" \
248 " = true"
249
250 gdb_test "print pck.fp1_var > 0.25" \
251 " = false"
252
253 gdb_test "print pck.fp1_var > 0.5" \
254 " = false"
255
256 gdb_test "print pck.fp1_var > 1" \
257 " = false"
258
259 gdb_test "print pck.fp1_var >= 0.25" \
260 " = true"
261
262 gdb_test "print pck.fp1_var >= 0.5" \
263 " = false"
264
265 gdb_test "print pck.fp1_var >= 1" \
266 " = false"
267
268
269 # Set the language to LANG and do a ptype test on pck__fp1_var,
270 # pck__fp2_var and pck__fp3_var, verifying that the output matches
271 # FP1_RE, FP2_RE, FP2_RE (resp.).
272
273 proc do_ptype_test {lang fp1_re fp2_re fp3_re fp1_range_re} {
274 with_test_prefix "lang=$lang" {
275 gdb_test_no_output "set language $lang" \
276 "set language to $lang for ptype test"
277
278 gdb_test "ptype pck__fp1_var" $fp1_re
279
280 gdb_test "ptype pck__fp2_var" $fp2_re
281
282 gdb_test "ptype pck__fp3_var" $fp3_re
283
284 gdb_test "ptype pck__fp1_range_var" $fp1_range_re
285 }
286 }
287
288 do_ptype_test "ada" \
289 " = <1-byte fixed point \\(small = 1/16\\)>" \
290 " = <1-byte fixed point \\(small = 1/100\\)>" \
291 " = <1-byte fixed point \\(small = 1/30\\)>" \
292 " = <1-byte fixed point \\(small = 1/16\\)>"
293
294 foreach lang [list "c" "d" "go" "objective-c" "opencl" ] {
295 do_ptype_test $lang \
296 " = 1-byte fixed point \\(small = 1/16\\)" \
297 " = 1-byte fixed point \\(small = 1/100\\)" \
298 " = 1-byte fixed point \\(small = 1/30\\)" \
299 " = <range type>"
300 }
301
302 do_ptype_test "fortran" \
303 " = pck__fp1_type" \
304 " = pck__fp2_type" \
305 " = pck__fp3_type" \
306 " = <range type>"
307
308 do_ptype_test "modula-2" \
309 " = pck__fp1_type" \
310 " = pck__fp2_type" \
311 " = pck__fp3_type" \
312 " = \\\[1-byte fixed point \\(small = 1/16\\)\\.\\.1-byte fixed point \\(small = 1/16\\)\\\]"
313
314 do_ptype_test "pascal" \
315 " = pck__fp1_type" \
316 " = pck__fp2_type" \
317 " = pck__fp3_type" \
318 " = 1-byte fixed point \\(small = 1/16\\)\\.\\.1-byte fixed point \\(small = 1/16\\)"
319
This page took 0.036078 seconds and 4 git commands to generate.