OSDN Git Service

Update copyright year in most headers.
[pf3gnuchains/pf3gnuchains3x.git] / gdb / testsuite / gdb.base / bitfields2.exp
1 # Copyright 1992, 1994, 1995, 1997, 2004, 2007, 2008, 2009, 2010
2 # Free Software Foundation, Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 # This file was adapted from bitfields.exp by Paul Hilfinger 
18 # (Hilfinger@gnat.com)
19
20 #
21 # Tests for bit-fields that do not fit in type (unsigned) int, but do fit 
22 # in type (unsigned) long long.  We perform essentially the same tests as
23 # in bitfields.c, which considers only bit-fields that are <= 9 bits long.
24 #
25
26 if $tracelevel then {
27         strace $tracelevel
28 }
29
30 set prms_id 0
31 set bug_id 0
32
33 set testfile "bitfields2"
34 set srcfile ${testfile}.c
35 set binfile ${objdir}/${subdir}/${testfile}
36 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
37     untested bitfields2.exp
38     return -1
39 }
40
41 set has_signed_bitfields 1
42
43 #
44 # Continue to expected breakpoint at FUNCTION.  Append TAG to make pass/fail 
45 # messages (to make them unique).  Suppress tests on failure.
46 #
47 proc continue_test { function tag } {
48     global decimal
49     global srcfile
50
51     if [gdb_test "cont" "Break.*$function \\(\\) at .*$srcfile:$decimal.*" "continuing to $function $tag"] {
52         gdb_suppress_tests
53     }
54 }
55
56 #
57 # Start next test by running to tester and then to FUNCTION.   Suppresses
58 # tests on failure.
59 #
60 proc start_test { function } {
61     delete_breakpoints
62     if [gdb_test "break tester" "" "break tester prior to $function"] {
63         gdb_suppress_tests
64     }
65     continue_test "tester" "prior to $function"
66     if ![gdb_breakpoint $function] {
67         gdb_suppress_tests
68     }
69     continue_test $function "#0"
70 }
71     
72
73 #
74 # Test bitfield locating and uniqueness.
75 # For each member, set that member to 1 and verify that the member (and only
76 # that member) is 1, then reset it back to 0.
77 #
78
79 proc bitfield_uniqueness {} {
80     global decimal
81     global hex
82     global gdb_prompt
83     global srcfile
84
85     start_test break1
86         
87     if [gdb_test "print flags" ".*u1 = 0, u2 = 0, u3 = 0, s1 = 1, s2 = 0, s3 = 0.*" "bitfield uniqueness; flags.s1 = 1"] {
88         gdb_suppress_tests;
89     }
90     continue_test break1 "#1"
91     if [gdb_test "print flags" ".*u1 = 1, u2 = 0, u3 = 0, s1 = 0, s2 = 0, s3 = 0.*" "bitfield uniqueness; flags.u1 = 1"] {
92         gdb_suppress_tests;
93     }
94     continue_test break1 "#2"
95     if [gdb_test "print flags" ".*u1 = 0, u2 = 0, u3 = 0, s1 = 0, s2 = 1, s3 = 0.*" "bitfield uniqueness; flags.s2 = 1"] {
96         gdb_suppress_tests;
97     }
98     continue_test break1 "#3"
99     if [gdb_test "print flags" ".*u1 = 0, u2 = 1, u3 = 0, s1 = 0, s2 = 0, s3 = 0.*" "bitfield uniqueness; flags.u2 = 1"] {
100         gdb_suppress_tests;
101     }
102     continue_test break1 "#4"
103     if [gdb_test "print flags" ".*u1 = 0, u2 = 0, u3 = 0, s1 = 0, s2 = 0, s3 = 1.*" "bitfield uniqueness; flags.s3 = 1"] {
104         gdb_suppress_tests;
105     }
106     continue_test break1 "#5"
107     if [gdb_test "print flags" ".*u1 = 0, u2 = 0, u3 = 1, s1 = 0, s2 = 0, s3 = 0.*" "bitfield uniqueness; flags.u3 = 1"] {
108         gdb_suppress_tests
109     }
110     gdb_stop_suppressing_tests;
111 }
112
113
114 #
115 # Test bitfield containment.
116 # Fill alternating fields with all 1's and verify that none of the bits
117 # "bleed over" to the other fields.
118 #
119
120 proc bitfield_containment {} {
121     global decimal
122     global hex
123     global gdb_prompt
124     global srcfile
125
126     start_test break2
127
128     # If program is compiled with Sun CC, signed fields print out as their
129     # actual sizes; if compiled with gcc, they print out as 0xffffffff.
130     if [gdb_test "print/x flags" "= {u1 = 0x7fff, u2 = 0x0, u3 = 0xffff, s1 = 0x0, s2 = 0x(1ffffffff|f*), s3 = 0x0}" "bitfield containment; flags.u1, flags.u3, and flags.s3 to all 1s"] {
131         gdb_suppress_tests
132     }
133
134     continue_test break2 "#1"
135
136     if [gdb_test "print/x flags" "= {u1 = 0x0, u2 = 0x1ffffffff, u3 = 0x0, s1 = 0x(7fff|f*), s2 = 0x0, s3 = 0xf*}" "bitfield containment; flags.u2, flags.s1, flags.s2 to all 1s"] {
137         gdb_suppress_tests
138     }
139     gdb_stop_suppressing_tests;
140 }
141
142 # Test unsigned bitfields for unsignedness and range.
143 # Fill the unsigned fields with the maximum positive value and verify that
144 # the values are printed correctly.
145
146 proc bitfield_unsignedness {} {
147     global decimal
148     global hex
149     global gdb_prompt
150     global srcfile
151
152     start_test break3
153
154     if [gdb_test "print flags" ".*u1 = 32767, u2 = 8589934591, u3 = 65535, s1 = 0, s2 = 0, s3 = 0.*" "maximum unsigned bitfield values"] {
155         gdb_suppress_tests
156     }
157     gdb_stop_suppressing_tests;
158 }
159
160 #
161 # Test signed bitfields for signedness and range.
162 # Fill the signed fields with the maximum positive value, then the maximally
163 # negative value, then -1, and verify in each case that the values are
164 # printed correctly.
165 #
166
167 proc bitfield_signedness {} {
168     global decimal
169     global hex
170     global gdb_prompt
171     global srcfile
172     global has_signed_bitfields
173
174     start_test break4
175
176     if [gdb_test "print flags" "= {.*u1 = 0, u2 = 0, u3 = 0, s1 = 16383, s2 = 4294967295, s3 = 32767.*}" "maximum signed bitfield values"] {
177         gdb_suppress_tests
178     }
179
180     continue_test break4 "#1"
181
182     # Determine if the target has signed bitfields so we can skip
183     # the signed bitfield tests if it doesn't.
184     set test "determining signed-ness of bitfields"
185     set has_signed_bitfields 0
186     gdb_test_multiple "print i" $test {
187         -re ".* = -32768.*$gdb_prompt $" {
188             set has_signed_bitfields 1
189             pass "determining signed-ness of bitfields"
190         }
191         -re ".* = 32768.*$gdb_prompt $" {
192             pass "determining signed-ness of bitfields"
193         }
194         -re ".*$gdb_prompt $" {
195             fail "determining signed-ness of bitfields"
196             gdb_suppress_tests
197         }
198     }
199
200     set test "most negative signed bitfield values"
201     if $has_signed_bitfields then {
202         if [gdb_test "print flags" "u1 = 0, u2 = 0, u3 = 0, s1 = -16384, s2 = -4294967296, s3 = -32768.*" $test ] {
203             gdb_suppress_tests
204         }
205     } else {
206         unsupported $test
207     }
208
209     continue_test break4 "#2"
210
211     set test "signed bitfields containing -1"
212     if $has_signed_bitfields then {
213         if [gdb_test "print flags" "u1 = 0, u2 = 0, u3 = 0, s1 = -1, s2 = -1, s3 = -1.*" $test ] {
214             gdb_suppress_tests
215         }
216     } else {
217         unsupported $test
218     }
219
220     gdb_stop_suppressing_tests;
221 }
222
223
224 # Test setting of long long bit fields from within GDB.
225
226 proc bitfield_set {} {
227     global decimal
228     global hex
229     global gdb_prompt
230     global srcfile
231     global has_signed_bitfields
232
233     start_test break5
234
235     set big_set_failed 0
236     set test "set long long unsigned bitfield"
237     gdb_test_multiple "print flags.u2 = 0x100000000" $test {
238         -re "warning: Value does not fit.*$gdb_prompt $" {
239             fail "$test"
240             gdb_suppress_tests
241         }
242         -re "= 4294967296.*$gdb_prompt $" {
243             pass "$test"
244         }
245     }
246
247     set test "set long long signed bitfield positive"
248     gdb_test_multiple "print flags.s2 = 0x80000000" $test {
249         -re "warning: Value does not fit.*$gdb_prompt $" {
250             fail "$test"
251             gdb_suppress_tests
252         }
253         -re "= 2147483648.*$gdb_prompt $" {
254             pass "$test"
255         }
256     }
257
258     if [gdb_test "print flags" "u1 = 0, u2 = 4294967296, u3 = 0, s1 = 0, s2 = 2147483648, s3 = 0.*" "long long bitfield values after set"] {
259         gdb_suppress_tests
260     }
261
262     set test "set long long signed bitfield negative"
263     if $has_signed_bitfields then {
264         gdb_test_multiple "print flags.s2 = -1" $test {
265             -re "warning: Value does not fit.*$gdb_prompt $" {
266                 fail "$test"
267                 gdb_suppress_tests
268             }
269             -re "= -1.*$gdb_prompt $" {
270                 pass "$test"
271             }
272         }
273     } else {
274         unsupported $test
275     }
276
277     set test  "long long bitfield values after set negative"
278     if $has_signed_bitfields then {
279         if [gdb_test "print flags" "u1 = 0, u2 = 4294967296, u3 = 0, s1 = 0, s2 = -1, s3 = 0.*" $test] {
280             gdb_suppress_tests
281         }
282     } else {
283         unsupported $test
284     }
285
286     gdb_stop_suppressing_tests;
287 }
288
289 gdb_start
290 gdb_reinitialize_dir $srcdir/$subdir
291 gdb_load ${binfile}
292
293 send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
294 runto_main
295
296 bitfield_uniqueness
297 bitfield_containment
298 bitfield_unsignedness
299 bitfield_signedness
300 bitfield_set
301