Update copyright year range in header of all files managed by GDB
[binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / dw2-fixed-point.exp
blobb172ef5e10334708ee319209e4d03495af1bcc35
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/>.
15 load_lib dwarf.exp
17 # This test can only be run on targets which support DWARF-2 and use gas.
18 if {![dwarf2_support]} {
19     return 0
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 {
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
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             }
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             }
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             }
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             }
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             }
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             }
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             }
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             }
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              }
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     }
117 if { [prepare_for_testing ${testfile}.exp ${testfile} \
118           [list $srcfile $asm_file] {nodebug}] } {
119     return -1
122 if ![runto_main] {
123     return -1
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" \
132          " = 0.25"
134 gdb_test "print /x pck.fp1_var" \
135          " = 0x0"
137 gdb_test "print pck.fp2_var" \
138          " = -0.01"
140 gdb_test "print /x pck.fp2_var" \
141          " = 0x0"
143 gdb_test "print pck.fp3_var" \
144          " = 0.1"
146 gdb_test "print /x pck.fp3_var" \
147          " = 0x0"
149 gdb_test "print pck.fp1_range_var" \
150          " = 1"
152 gdb_test "print /x pck.fp1_range_var" \
153          " = 0x1"
155 gdb_test "print pck.fp1_var + 0.25" \
156          " = 0.5"
158 gdb_test "print pck.fp2_var - pck.fp2_var" \
159          " = 0"
161 gdb_test "print pck.fp3_var * 1" \
162          " = 0.1"
164 gdb_test "print pck.fp3_var / pck.fp3_var" \
165          " = 1"
167 gdb_test "print pck.fp3_var / 0" \
168          "Division by zero"
170 gdb_test "print pck.fp1_range_var - 0.5" \
171          " = 0.5"
173 gdb_test "print -pck.fp1_var" \
174          " = -0.25"
176 gdb_test "print pck.fp1_var = pck.fp1_var" \
177          " = true"
179 gdb_test "print pck.fp1_var = pck.fp1_var2" \
180          " = false"
182 gdb_test "print pck.fp1_var /= pck.fp1_var" \
183          " = false"
185 gdb_test "print pck.fp1_var /= pck.fp1_var2" \
186          " = true"
188 gdb_test "print pck.fp1_var < pck.fp1_var" \
189          " = false"
191 gdb_test "print pck.fp1_var < pck.fp1_var2" \
192          " = true"
194 gdb_test "print pck.fp1_var <= pck.fp1_var2" \
195          " = true"
197 gdb_test "print pck.fp1_var <= pck.fp1_var" \
198          " = true"
200 gdb_test "print pck.fp1_var > pck.fp1_var2" \
201          " = false"
203 gdb_test "print pck.fp1_var2 > pck.fp1_var" \
204          " = true"
206 gdb_test "print pck.fp1_var >= pck.fp1_var" \
207          " = true"
209 gdb_test "print pck.fp1_var >= pck.fp1_var2" \
210          " = false"
212 # Same as above, but with litterals...
214 gdb_test "print pck.fp1_var = 0.25" \
215          " = true"
217 gdb_test "print pck.fp1_var = 0.5" \
218          " = false"
220 gdb_test "print pck.fp1_var = 1" \
221          " = false"
223 gdb_test "print pck.fp1_var /= 0.25" \
224          " = false"
226 gdb_test "print pck.fp1_var /= 0.5" \
227          " = true"
229 gdb_test "print pck.fp1_var /= 1" \
230          " = true"
232 gdb_test "print pck.fp1_var < 0.25" \
233          " = false"
235 gdb_test "print pck.fp1_var <  0.5" \
236          " = true"
238 gdb_test "print pck.fp1_var <  1" \
239          " = true"
241 gdb_test "print pck.fp1_var <= 0.25" \
242          " = true"
244 gdb_test "print pck.fp1_var <= 0.5" \
245          " = true"
247 gdb_test "print pck.fp1_var <= 1" \
248          " = true"
250 gdb_test "print pck.fp1_var > 0.25" \
251          " = false"
253 gdb_test "print pck.fp1_var > 0.5" \
254          " = false"
256 gdb_test "print pck.fp1_var > 1" \
257          " = false"
259 gdb_test "print pck.fp1_var >= 0.25" \
260          " = true"
262 gdb_test "print pck.fp1_var >= 0.5" \
263          " = false"
265 gdb_test "print pck.fp1_var >= 1" \
266          " = false"
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
285     }
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\\)" \
299                   " = <range type>"
302 do_ptype_test "fortran" \
303           " = pck__fp1_type" \
304           " = pck__fp2_type" \
305           " = pck__fp3_type" \
306           " = <range type>"
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\\)\\\]"
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\\)"