Sync usage with man page.
[netbsd-mini2440.git] / gnu / dist / gdb6 / gdb / testsuite / gdb.base / bitfields2.exp
blobd4f93c74960cc231b3e31e036d258a6bf4d5bcfe
1 # Copyright 1992, 1994, 1995, 1997, 2004 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 2 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.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 # This file was adapted from bitfields.exp by Paul Hilfinger
18 # (Hilfinger@gnat.com)
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.
26 if $tracelevel then {
27 strace $tracelevel
30 set prms_id 0
31 set bug_id 0
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 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
40 set has_signed_bitfields 1
43 # Continue to expected breakpoint at FUNCTION. Append TAG to make pass/fail
44 # messages (to make them unique). Suppress tests on failure.
46 proc continue_test { function tag } {
47 global decimal
48 global srcfile
50 if [gdb_test "cont" "Break.*$function \\(\\) at .*$srcfile:$decimal.*" "continuing to $function $tag"] {
51 gdb_suppress_tests
56 # Start next test by running to tester and then to FUNCTION. Suppresses
57 # tests on failure.
59 proc start_test { function } {
60 delete_breakpoints
61 if [gdb_test "break tester" "" "break tester prior to $function"] {
62 gdb_suppress_tests
64 continue_test "tester" "prior to $function"
65 if ![gdb_breakpoint $function] {
66 gdb_suppress_tests
68 continue_test $function "#0"
73 # Test bitfield locating and uniqueness.
74 # For each member, set that member to 1 and verify that the member (and only
75 # that member) is 1, then reset it back to 0.
78 proc bitfield_uniqueness {} {
79 global decimal
80 global hex
81 global gdb_prompt
82 global srcfile
84 start_test break1
86 if [gdb_test "print flags" ".*u1 = 0, u2 = 0, u3 = 0, s1 = 1, s2 = 0, s3 = 0.*" "bitfield uniqueness; flags.s1 = 1"] {
87 gdb_suppress_tests;
89 continue_test break1 "#1"
90 if [gdb_test "print flags" ".*u1 = 1, u2 = 0, u3 = 0, s1 = 0, s2 = 0, s3 = 0.*" "bitfield uniqueness; flags.u1 = 1"] {
91 gdb_suppress_tests;
93 continue_test break1 "#2"
94 if [gdb_test "print flags" ".*u1 = 0, u2 = 0, u3 = 0, s1 = 0, s2 = 1, s3 = 0.*" "bitfield uniqueness; flags.s2 = 1"] {
95 gdb_suppress_tests;
97 continue_test break1 "#3"
98 if [gdb_test "print flags" ".*u1 = 0, u2 = 1, u3 = 0, s1 = 0, s2 = 0, s3 = 0.*" "bitfield uniqueness; flags.u2 = 1"] {
99 gdb_suppress_tests;
101 continue_test break1 "#4"
102 if [gdb_test "print flags" ".*u1 = 0, u2 = 0, u3 = 0, s1 = 0, s2 = 0, s3 = 1.*" "bitfield uniqueness; flags.s3 = 1"] {
103 gdb_suppress_tests;
105 continue_test break1 "#5"
106 if [gdb_test "print flags" ".*u1 = 0, u2 = 0, u3 = 1, s1 = 0, s2 = 0, s3 = 0.*" "bitfield uniqueness; flags.u3 = 1"] {
107 gdb_suppress_tests
109 gdb_stop_suppressing_tests;
114 # Test bitfield containment.
115 # Fill alternating fields with all 1's and verify that none of the bits
116 # "bleed over" to the other fields.
119 proc bitfield_containment {} {
120 global decimal
121 global hex
122 global gdb_prompt
123 global srcfile
125 start_test break2
127 # If program is compiled with Sun CC, signed fields print out as their
128 # actual sizes; if compiled with gcc, they print out as 0xffffffff.
129 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"] {
130 gdb_suppress_tests
133 continue_test break2 "#1"
135 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"] {
136 gdb_suppress_tests
138 gdb_stop_suppressing_tests;
141 # Test unsigned bitfields for unsignedness and range.
142 # Fill the unsigned fields with the maximum positive value and verify that
143 # the values are printed correctly.
145 proc bitfield_unsignedness {} {
146 global decimal
147 global hex
148 global gdb_prompt
149 global srcfile
151 start_test break3
153 if [gdb_test "print flags" ".*u1 = 32767, u2 = 8589934591, u3 = 65535, s1 = 0, s2 = 0, s3 = 0.*" "maximum unsigned bitfield values"] {
154 gdb_suppress_tests
156 gdb_stop_suppressing_tests;
160 # Test signed bitfields for signedness and range.
161 # Fill the signed fields with the maximum positive value, then the maximally
162 # negative value, then -1, and verify in each case that the values are
163 # printed correctly.
166 proc bitfield_signedness {} {
167 global decimal
168 global hex
169 global gdb_prompt
170 global srcfile
171 global has_signed_bitfields
173 start_test break4
175 if [gdb_test "print flags" "= {.*u1 = 0, u2 = 0, u3 = 0, s1 = 16383, s2 = 4294967295, s3 = 32767.*}" "maximum signed bitfield values"] {
176 gdb_suppress_tests
179 continue_test break4 "#1"
181 # Determine if the target has signed bitfields so we can skip
182 # the signed bitfield tests if it doesn't.
183 set test "determining signed-ness of bitfields"
184 set has_signed_bitfields 0
185 gdb_test_multiple "print i" $test {
186 -re ".* = -32768.*$gdb_prompt $" {
187 set has_signed_bitfields 1
188 pass "determining signed-ness of bitfields"
190 -re ".* = 32768.*$gdb_prompt $" {
191 pass "determining signed-ness of bitfields"
193 -re ".*$gdb_prompt $" {
194 fail "determining signed-ness of bitfields"
195 gdb_suppress_tests
199 set test "most negative signed bitfield values"
200 if $has_signed_bitfields then {
201 if [gdb_test "print flags" "u1 = 0, u2 = 0, u3 = 0, s1 = -16384, s2 = -4294967296, s3 = -32768.*" $test ] {
202 gdb_suppress_tests
204 } else {
205 unsupported $test
208 continue_test break4 "#2"
210 set test "signed bitfields containing -1"
211 if $has_signed_bitfields then {
212 if [gdb_test "print flags" "u1 = 0, u2 = 0, u3 = 0, s1 = -1, s2 = -1, s3 = -1.*" $test ] {
213 gdb_suppress_tests
215 } else {
216 unsupported $test
219 gdb_stop_suppressing_tests;
223 # Test setting of long long bit fields from within GDB.
225 proc bitfield_set {} {
226 global decimal
227 global hex
228 global gdb_prompt
229 global srcfile
230 global has_signed_bitfields
232 start_test break5
234 set big_set_failed 0
235 set test "set long long unsigned bitfield"
236 gdb_test_multiple "print flags.u2 = 0x100000000" $test {
237 -re "warning: Value does not fit.*$gdb_prompt $" {
238 fail "$test"
239 gdb_suppress_tests
241 -re "= 4294967296.*$gdb_prompt $" {
242 pass "$test"
246 set test "set long long signed bitfield positive"
247 gdb_test_multiple "print flags.s2 = 0x80000000" $test {
248 -re "warning: Value does not fit.*$gdb_prompt $" {
249 fail "$test"
250 gdb_suppress_tests
252 -re "= 2147483648.*$gdb_prompt $" {
253 pass "$test"
257 if [gdb_test "print flags" "u1 = 0, u2 = 4294967296, u3 = 0, s1 = 0, s2 = 2147483648, s3 = 0.*" "long long bitfield values after set"] {
258 gdb_suppress_tests
261 set test "set long long signed bitfield negative"
262 if $has_signed_bitfields then {
263 gdb_test_multiple "print flags.s2 = -1" $test {
264 -re "warning: Value does not fit.*$gdb_prompt $" {
265 fail "$test"
266 gdb_suppress_tests
268 -re "= -1.*$gdb_prompt $" {
269 pass "$test"
272 } else {
273 unsupported $test
276 set test "long long bitfield values after set negative"
277 if $has_signed_bitfields then {
278 if [gdb_test "print flags" "u1 = 0, u2 = 4294967296, u3 = 0, s1 = 0, s2 = -1, s3 = 0.*" $test] {
279 gdb_suppress_tests
281 } else {
282 unsupported $test
285 gdb_stop_suppressing_tests;
288 gdb_start
289 gdb_reinitialize_dir $srcdir/$subdir
290 gdb_load ${binfile}
292 send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
293 runto_main
295 bitfield_uniqueness
296 bitfield_containment
297 bitfield_unsignedness
298 bitfield_signedness
299 bitfield_set