Commit | Line | Data |
---|---|---|
09584414 JB |
1 | # Copyright 2016-2020 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 | fp2_base_type: DW_TAG_base_type { | |
53 | {DW_AT_byte_size 1 DW_FORM_sdata} | |
54 | {DW_AT_encoding @DW_ATE_signed_fixed} | |
55 | {DW_AT_name pck__fp2_type} | |
56 | {DW_AT_decimal_scale -2 DW_FORM_sdata} | |
57 | } | |
58 | ||
59 | DW_TAG_variable { | |
60 | {DW_AT_name pck__fp2_var} | |
61 | {DW_AT_type :$fp2_base_type} | |
62 | {DW_AT_location { | |
63 | DW_OP_addr [gdb_target_symbol pck__fp2_var] | |
64 | } SPECIAL_expr} | |
65 | {external 1 flag} | |
66 | } | |
67 | ||
68 | fp3_small: DW_TAG_constant { | |
69 | {DW_AT_GNU_numerator 1 DW_FORM_data1} | |
70 | {DW_AT_GNU_denominator 30 DW_FORM_sdata} | |
71 | } | |
72 | ||
73 | fp3_base_type: DW_TAG_base_type { | |
74 | {DW_AT_byte_size 1 DW_FORM_sdata} | |
75 | {DW_AT_encoding @DW_ATE_signed_fixed} | |
76 | {DW_AT_name pck__fp3_type} | |
77 | {DW_AT_small :$fp3_small} | |
78 | } | |
79 | ||
80 | DW_TAG_variable { | |
81 | {DW_AT_name pck__fp3_var} | |
82 | {DW_AT_type :$fp3_base_type} | |
83 | {DW_AT_location { | |
84 | DW_OP_addr [gdb_target_symbol pck__fp3_var] | |
85 | } SPECIAL_expr} | |
86 | {external 1 flag} | |
87 | } | |
88 | ||
89 | fp1_range_type: DW_TAG_subrange_type { | |
90 | {DW_AT_lower_bound 0xf0 DW_FORM_data1} | |
91 | {DW_AT_upper_bound 0x10 DW_FORM_data1} | |
92 | {DW_AT_name foo__fp1_range_type} | |
93 | {DW_AT_type :$fp1_base_type} | |
94 | } | |
95 | ||
96 | DW_TAG_variable { | |
97 | {DW_AT_name pck__fp1_range_var} | |
98 | {DW_AT_type :$fp1_range_type} | |
99 | {DW_AT_location { | |
100 | DW_OP_addr [gdb_target_symbol pck__fp1_range_var] | |
101 | } SPECIAL_expr} | |
102 | {external 1 flag} | |
103 | } | |
104 | } | |
105 | } | |
106 | } | |
107 | ||
108 | if { [prepare_for_testing ${testfile}.exp ${testfile} \ | |
109 | [list $srcfile $asm_file] {nodebug}] } { | |
110 | return -1 | |
111 | } | |
112 | ||
113 | if ![runto_main] { | |
114 | return -1 | |
115 | } | |
116 | ||
117 | # Do the testing in Ada mode, since this is the language for which | |
118 | # this feature has been implemented, and where we know the language | |
119 | # has the concept of fixed-point types. | |
120 | gdb_test_no_output "set lang ada" | |
121 | ||
122 | gdb_test "print pck.fp1_var" \ | |
123 | " = 0.25" | |
124 | ||
b26daff9 JB |
125 | gdb_test "print /x pck.fp1_var" \ |
126 | " = 0x0" | |
127 | ||
09584414 JB |
128 | gdb_test "print pck.fp2_var" \ |
129 | " = -0.01" | |
130 | ||
b26daff9 JB |
131 | gdb_test "print /x pck.fp2_var" \ |
132 | " = 0x0" | |
133 | ||
09584414 JB |
134 | gdb_test "print pck.fp3_var" \ |
135 | " = 0.1" | |
136 | ||
b26daff9 JB |
137 | gdb_test "print /x pck.fp3_var" \ |
138 | " = 0x0" | |
139 | ||
09584414 JB |
140 | gdb_test "print pck.fp1_range_var" \ |
141 | " = 1" | |
b26daff9 JB |
142 | |
143 | gdb_test "print /x pck.fp1_range_var" \ | |
144 | " = 0x1" | |
0c9150e4 JB |
145 | |
146 | # Set the language to LANG and do a ptype test on pck__fp1_var, | |
147 | # pck__fp2_var and pck__fp3_var, verifying that the output matches | |
148 | # FP1_RE, FP2_RE, FP2_RE (resp.). | |
149 | ||
150 | proc do_ptype_test {lang fp1_re fp2_re fp3_re fp1_range_re} { | |
151 | with_test_prefix "lang=$lang" { | |
152 | gdb_test_no_output "set language $lang" \ | |
153 | "set language to $lang for ptype test" | |
154 | ||
155 | gdb_test "ptype pck__fp1_var" $fp1_re | |
156 | ||
157 | gdb_test "ptype pck__fp2_var" $fp2_re | |
158 | ||
159 | gdb_test "ptype pck__fp3_var" $fp3_re | |
160 | ||
161 | if { $lang == "modula-2" || $lang == "pascal" } { | |
162 | setup_xfail "*-*-*" "not supported by language" | |
163 | } | |
164 | gdb_test "ptype pck__fp1_range_var" $fp1_range_re | |
165 | } | |
166 | } | |
167 | ||
168 | do_ptype_test "ada" \ | |
169 | " = <1-byte fixed point \\(small = 1/16\\)>" \ | |
170 | " = <1-byte fixed point \\(small = 1/100\\)>" \ | |
171 | " = <1-byte fixed point \\(small = 1/30\\)>" \ | |
172 | " = <1-byte fixed point \\(small = 1/16\\)>" | |
173 | ||
174 | foreach lang [list "c" "d" "go" "objective-c" "opencl" ] { | |
175 | do_ptype_test $lang \ | |
176 | " = 1-byte fixed point \\(small = 1/16\\)" \ | |
177 | " = 1-byte fixed point \\(small = 1/100\\)" \ | |
178 | " = 1-byte fixed point \\(small = 1/30\\)" \ | |
179 | " = <range type>" | |
180 | } | |
181 | ||
182 | foreach lang [list "fortran" "modula-2" "pascal" ] { | |
183 | do_ptype_test $lang \ | |
184 | " = pck__fp1_type" \ | |
185 | " = pck__fp2_type" \ | |
186 | " = pck__fp3_type" \ | |
187 | " = <range type>" | |
188 | } |