1 # Copyright 2016-2023 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/>.
17 # This test can only be run on targets which support DWARF-2 and use gas.
18 if {![dwarf2_support]} {
22 standard_testfile dw2-fixed-point.c dw2-fixed-point-dw.S
24 # Make some DWARF for the test.
25 set asm_file [standard_output_file $srcfile2]
26 Dwarf::assemble $asm_file {
29 {DW_AT_language @DW_LANG_Ada95}
33 declare_labels fp1_base_type fp2_base_type fp3_small \
34 fp3_base_type fp1_range_type
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}
44 {DW_AT_name pck__fp1_var}
45 {DW_AT_type :$fp1_base_type}
47 DW_OP_addr [gdb_target_symbol pck__fp1_var]
53 {DW_AT_name pck__fp1_var2}
54 {DW_AT_type :$fp1_base_type}
56 DW_OP_addr [gdb_target_symbol pck__fp1_var2]
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}
69 {DW_AT_name pck__fp2_var}
70 {DW_AT_type :$fp2_base_type}
72 DW_OP_addr [gdb_target_symbol pck__fp2_var]
77 fp3_small: DW_TAG_constant {
78 {DW_AT_GNU_numerator 1 DW_FORM_data1}
79 {DW_AT_GNU_denominator 30 DW_FORM_sdata}
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}
90 {DW_AT_name pck__fp3_var}
91 {DW_AT_type :$fp3_base_type}
93 DW_OP_addr [gdb_target_symbol pck__fp3_var]
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}
106 {DW_AT_name pck__fp1_range_var}
107 {DW_AT_type :$fp1_range_type}
109 DW_OP_addr [gdb_target_symbol pck__fp1_range_var]
117 if { [prepare_for_testing ${testfile}.exp ${testfile} \
118 [list $srcfile $asm_file] {nodebug}] } {
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"
131 gdb_test "print pck.fp1_var" \
134 gdb_test "print /x pck.fp1_var" \
137 gdb_test "print pck.fp2_var" \
140 gdb_test "print /x pck.fp2_var" \
143 gdb_test "print pck.fp3_var" \
146 gdb_test "print /x pck.fp3_var" \
149 gdb_test "print pck.fp1_range_var" \
152 gdb_test "print /x pck.fp1_range_var" \
155 gdb_test "print pck.fp1_var + 0.25" \
158 gdb_test "print pck.fp2_var - pck.fp2_var" \
161 gdb_test "print pck.fp3_var * 1" \
164 gdb_test "print pck.fp3_var / pck.fp3_var" \
167 gdb_test "print pck.fp3_var / 0" \
170 gdb_test "print pck.fp1_range_var - 0.5" \
173 gdb_test "print -pck.fp1_var" \
176 gdb_test "print pck.fp1_var = pck.fp1_var" \
179 gdb_test "print pck.fp1_var = pck.fp1_var2" \
182 gdb_test "print pck.fp1_var /= pck.fp1_var" \
185 gdb_test "print pck.fp1_var /= pck.fp1_var2" \
188 gdb_test "print pck.fp1_var < pck.fp1_var" \
191 gdb_test "print pck.fp1_var < pck.fp1_var2" \
194 gdb_test "print pck.fp1_var <= pck.fp1_var2" \
197 gdb_test "print pck.fp1_var <= pck.fp1_var" \
200 gdb_test "print pck.fp1_var > pck.fp1_var2" \
203 gdb_test "print pck.fp1_var2 > pck.fp1_var" \
206 gdb_test "print pck.fp1_var >= pck.fp1_var" \
209 gdb_test "print pck.fp1_var >= pck.fp1_var2" \
212 # Same as above, but with litterals...
214 gdb_test "print pck.fp1_var = 0.25" \
217 gdb_test "print pck.fp1_var = 0.5" \
220 gdb_test "print pck.fp1_var = 1" \
223 gdb_test "print pck.fp1_var /= 0.25" \
226 gdb_test "print pck.fp1_var /= 0.5" \
229 gdb_test "print pck.fp1_var /= 1" \
232 gdb_test "print pck.fp1_var < 0.25" \
235 gdb_test "print pck.fp1_var < 0.5" \
238 gdb_test "print pck.fp1_var < 1" \
241 gdb_test "print pck.fp1_var <= 0.25" \
244 gdb_test "print pck.fp1_var <= 0.5" \
247 gdb_test "print pck.fp1_var <= 1" \
250 gdb_test "print pck.fp1_var > 0.25" \
253 gdb_test "print pck.fp1_var > 0.5" \
256 gdb_test "print pck.fp1_var > 1" \
259 gdb_test "print pck.fp1_var >= 0.25" \
262 gdb_test "print pck.fp1_var >= 0.5" \
265 gdb_test "print pck.fp1_var >= 1" \
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.).
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"
278 gdb_test "ptype pck__fp1_var" $fp1_re
280 gdb_test "ptype pck__fp2_var" $fp2_re
282 gdb_test "ptype pck__fp3_var" $fp3_re
284 gdb_test "ptype pck__fp1_range_var" $fp1_range_re
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\\)>"
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\\)" \
302 do_ptype_test "fortran" \
308 do_ptype_test "modula-2" \
312 " = \\\[1-byte fixed point \\(small = 1/16\\)\\.\\.1-byte fixed point \\(small = 1/16\\)\\\]"
314 do_ptype_test "pascal" \
318 " = 1-byte fixed point \\(small = 1/16\\)\\.\\.1-byte fixed point \\(small = 1/16\\)"