aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.dwarf2/dw2-fixed-point.exp
blob: 28381791c76a973d40db2c2770779a4ce373792f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# Copyright 2016-2023 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
load_lib dwarf.exp

# This test can only be run on targets which support DWARF-2 and use gas.
require dwarf2_support

standard_testfile dw2-fixed-point.c dw2-fixed-point-dw.S

# Make some DWARF for the test.
set asm_file [standard_output_file $srcfile2]
Dwarf::assemble $asm_file {
    cu {} {
 	DW_TAG_compile_unit {
                {DW_AT_language @DW_LANG_Ada95}
                {DW_AT_name     pck.ads}
                {DW_AT_comp_dir /tmp}
        } {
            declare_labels fp1_base_type fp2_base_type fp3_small \
                fp3_base_type fp1_range_type

            fp1_base_type: DW_TAG_base_type {
                {DW_AT_byte_size     1 DW_FORM_sdata}
                {DW_AT_encoding      @DW_ATE_signed_fixed}
                {DW_AT_name          pck__fp1_type}
                {DW_AT_binary_scale  -4 DW_FORM_sdata}
            }

            DW_TAG_variable {
                {DW_AT_name pck__fp1_var}
                {DW_AT_type :$fp1_base_type}
                {DW_AT_location {
                    DW_OP_addr [gdb_target_symbol pck__fp1_var]
                } SPECIAL_expr}
                {external 1 flag}
            }

            DW_TAG_variable {
                {DW_AT_name pck__fp1_var2}
                {DW_AT_type :$fp1_base_type}
                {DW_AT_location {
                    DW_OP_addr [gdb_target_symbol pck__fp1_var2]
                } SPECIAL_expr}
                {external 1 flag}
            }

            fp2_base_type: DW_TAG_base_type {
                {DW_AT_byte_size     1 DW_FORM_sdata}
                {DW_AT_encoding      @DW_ATE_signed_fixed}
                {DW_AT_name          pck__fp2_type}
                {DW_AT_decimal_scale -2 DW_FORM_sdata}
            }

            DW_TAG_variable {
                {DW_AT_name pck__fp2_var}
                {DW_AT_type :$fp2_base_type}
                {DW_AT_location {
                    DW_OP_addr [gdb_target_symbol pck__fp2_var]
                } SPECIAL_expr}
                {external 1 flag}
            }

            fp3_small: DW_TAG_constant {
                {DW_AT_GNU_numerator   1 DW_FORM_data1}
                {DW_AT_GNU_denominator 30 DW_FORM_sdata}
            }

            fp3_base_type: DW_TAG_base_type {
                {DW_AT_byte_size     1 DW_FORM_sdata}
                {DW_AT_encoding      @DW_ATE_signed_fixed}
                {DW_AT_name          pck__fp3_type}
                {DW_AT_small         :$fp3_small}
            }

            DW_TAG_variable {
                {DW_AT_name pck__fp3_var}
                {DW_AT_type :$fp3_base_type}
                {DW_AT_location {
                    DW_OP_addr [gdb_target_symbol pck__fp3_var]
                } SPECIAL_expr}
                {external 1 flag}
            }

            fp1_range_type: DW_TAG_subrange_type {
                 {DW_AT_lower_bound 0xf0 DW_FORM_data1}
                 {DW_AT_upper_bound 0x10 DW_FORM_data1}
                 {DW_AT_name foo__fp1_range_type}
                 {DW_AT_type :$fp1_base_type}
             }

             DW_TAG_variable {
                 {DW_AT_name pck__fp1_range_var}
                 {DW_AT_type :$fp1_range_type}
                 {DW_AT_location {
                     DW_OP_addr [gdb_target_symbol pck__fp1_range_var]
                 } SPECIAL_expr}
                 {external 1 flag}
             }
	}
    }
}

if { [prepare_for_testing ${testfile}.exp ${testfile} \
	  [list $srcfile $asm_file] {nodebug}] } {
    return -1
}

if ![runto_main] {
    return -1
}

# Do the testing in Ada mode, since this is the language for which
# this feature has been implemented, and where we know the language
# has the concept of fixed-point types.
gdb_test_no_output "set lang ada"

gdb_test "print pck.fp1_var" \
         " = 0.25"

gdb_test "print /x pck.fp1_var" \
         " = 0x0"

gdb_test "print pck.fp2_var" \
         " = -0.01"

gdb_test "print /x pck.fp2_var" \
         " = 0x0"

gdb_test "print pck.fp3_var" \
         " = 0.1"

gdb_test "print /x pck.fp3_var" \
         " = 0x0"

gdb_test "print pck.fp1_range_var" \
         " = 1"

gdb_test "print /x pck.fp1_range_var" \
         " = 0x1"

gdb_test "print pck.fp1_var + 0.25" \
         " = 0.5"

gdb_test "print pck.fp2_var - pck.fp2_var" \
         " = 0"

gdb_test "print pck.fp3_var * 1" \
         " = 0.1"

gdb_test "print pck.fp3_var / pck.fp3_var" \
         " = 1"

gdb_test "print pck.fp3_var / 0" \
         "Division by zero"

gdb_test "print pck.fp1_range_var - 0.5" \
         " = 0.5"

gdb_test "print -pck.fp1_var" \
         " = -0.25"

gdb_test "print pck.fp1_var = pck.fp1_var" \
         " = true"

gdb_test "print pck.fp1_var = pck.fp1_var2" \
         " = false"

gdb_test "print pck.fp1_var /= pck.fp1_var" \
         " = false"

gdb_test "print pck.fp1_var /= pck.fp1_var2" \
         " = true"

gdb_test "print pck.fp1_var < pck.fp1_var" \
         " = false"

gdb_test "print pck.fp1_var < pck.fp1_var2" \
         " = true"

gdb_test "print pck.fp1_var <= pck.fp1_var2" \
         " = true"

gdb_test "print pck.fp1_var <= pck.fp1_var" \
         " = true"

gdb_test "print pck.fp1_var > pck.fp1_var2" \
         " = false"

gdb_test "print pck.fp1_var2 > pck.fp1_var" \
         " = true"

gdb_test "print pck.fp1_var >= pck.fp1_var" \
         " = true"

gdb_test "print pck.fp1_var >= pck.fp1_var2" \
         " = false"

# Same as above, but with litterals...

gdb_test "print pck.fp1_var = 0.25" \
         " = true"

gdb_test "print pck.fp1_var = 0.5" \
         " = false"

gdb_test "print pck.fp1_var = 1" \
         " = false"

gdb_test "print pck.fp1_var /= 0.25" \
         " = false"

gdb_test "print pck.fp1_var /= 0.5" \
         " = true"

gdb_test "print pck.fp1_var /= 1" \
         " = true"

gdb_test "print pck.fp1_var < 0.25" \
         " = false"

gdb_test "print pck.fp1_var <  0.5" \
         " = true"

gdb_test "print pck.fp1_var <  1" \
         " = true"

gdb_test "print pck.fp1_var <= 0.25" \
         " = true"

gdb_test "print pck.fp1_var <= 0.5" \
         " = true"

gdb_test "print pck.fp1_var <= 1" \
         " = true"

gdb_test "print pck.fp1_var > 0.25" \
         " = false"

gdb_test "print pck.fp1_var > 0.5" \
         " = false"

gdb_test "print pck.fp1_var > 1" \
         " = false"

gdb_test "print pck.fp1_var >= 0.25" \
         " = true"

gdb_test "print pck.fp1_var >= 0.5" \
         " = false"

gdb_test "print pck.fp1_var >= 1" \
         " = false"


# Set the language to LANG and do a ptype test on pck__fp1_var,
# pck__fp2_var and pck__fp3_var, verifying that the output matches
# FP1_RE, FP2_RE, FP2_RE (resp.).

proc do_ptype_test {lang fp1_re fp2_re fp3_re fp1_range_re} {
    with_test_prefix "lang=$lang" {
        gdb_test_no_output "set language $lang" \
            "set language to $lang for ptype test"

        gdb_test "ptype pck__fp1_var" $fp1_re

        gdb_test "ptype pck__fp2_var" $fp2_re

        gdb_test "ptype pck__fp3_var" $fp3_re

        gdb_test "ptype pck__fp1_range_var" $fp1_range_re
    }
}

do_ptype_test "ada" \
              " = <1-byte fixed point \\(small = 1/16\\)>" \
              " = <1-byte fixed point \\(small = 1/100\\)>" \
              " = <1-byte fixed point \\(small = 1/30\\)>" \
              " = <1-byte fixed point \\(small = 1/16\\)>"

foreach lang [list "c" "d" "go" "objective-c" "opencl" ] {
    do_ptype_test $lang \
                  " = 1-byte fixed point \\(small = 1/16\\)" \
                  " = 1-byte fixed point \\(small = 1/100\\)" \
                  " = 1-byte fixed point \\(small = 1/30\\)" \
                  " = <range type>"
}

do_ptype_test "fortran" \
          " = pck__fp1_type" \
          " = pck__fp2_type" \
          " = pck__fp3_type" \
          " = <range type>"

do_ptype_test "modula-2" \
          " = pck__fp1_type" \
          " = pck__fp2_type" \
          " = pck__fp3_type" \
          " = \\\[1-byte fixed point \\(small = 1/16\\)\\.\\.1-byte fixed point \\(small = 1/16\\)\\\]"

do_ptype_test "pascal" \
          " = pck__fp1_type" \
          " = pck__fp2_type" \
          " = pck__fp3_type" \
          " = 1-byte fixed point \\(small = 1/16\\)\\.\\.1-byte fixed point \\(small = 1/16\\)"