aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base/bitfields.exp
blob: 1fa3838469b753df7e3977618b88da6ce7002c2c (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
# Copyright 1992-2019 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/>.

# This file was written by Fred Fish. (fnf@cygnus.com)


standard_testfile

if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
    return -1
}

#
# Test bitfield locating and uniqueness.
# For each member, set that member to 1 and verify that the member (and only
# that member) is 1, then reset it back to 0.
#

proc bitfield_uniqueness {} {
    global decimal
    global hex
    global gdb_prompt
    global srcfile

    if { ! [runto break1] } {
	gdb_suppress_tests
    }
	
    if [gdb_test "print flags" ".*uc = 1 .*, s1 = 0, u1 = 0, s2 = 0, u2 = 0, s3 = 0, u3 = 0, s9 = 0, u9 = 0, sc = 0.*"] {
	gdb_suppress_tests
    }
    if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #1"] {
	gdb_suppress_tests
    }
    # Note that we check for s1 as either 1 or -1, so that failure to
    # treat it correctly as a signed 1bit field (values 0 or -1) while
    # printing its value does not cause a spurious failure.  We do the
    # signedness preservation test later.
    if [gdb_test "print flags" ".*uc = 0 .*, s1 = (1|-1), u1 = 0, s2 = 0, u2 = 0, s3 = 0, u3 = 0, s9 = 0, u9 = 0, sc = 0.*" "bitfield uniqueness (s1)"] {
	gdb_suppress_tests
    }
    if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #2"] {
	gdb_suppress_tests
    }
    if [gdb_test "print flags" ".*uc = 0 .*, s1 = 0, u1 = 1, s2 = 0, u2 = 0, s3 = 0, u3 = 0, s9 = 0, u9 = 0, sc = 0.*" "bitfield uniqueness (u1)"] {
	gdb_suppress_tests
    }
    if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #3"] {
	gdb_suppress_tests
    }
    if [gdb_test "print flags" ".*uc = 0 .*, s1 = 0, u1 = 0, s2 = 1, u2 = 0, s3 = 0, u3 = 0, s9 = 0, u9 = 0, sc = 0.*" "bitfield uniqueness (s2)"] {
	gdb_suppress_tests
    }
    if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #4"] {
	gdb_suppress_tests
    }
    if [gdb_test "print flags" ".*uc = 0 .*, s1 = 0, u1 = 0, s2 = 0, u2 = 1, s3 = 0, u3 = 0, s9 = 0, u9 = 0, sc = 0.*" "bitfield uniqueness (u2)"] {
	gdb_suppress_tests
    }
    if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #5"] {
	gdb_suppress_tests
    }
    if [gdb_test "print flags" ".*uc = 0 .*, s1 = 0, u1 = 0, s2 = 0, u2 = 0, s3 = 1, u3 = 0, s9 = 0, u9 = 0, sc = 0.*" "bitfield uniqueness (s3)"] {
	gdb_suppress_tests
    }
    if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #6"] {
	gdb_suppress_tests
    }
    if [gdb_test "print flags" ".*uc = 0 .*, s1 = 0, u1 = 0, s2 = 0, u2 = 0, s3 = 0, u3 = 1, s9 = 0, u9 = 0, sc = 0.*" "bitfield uniqueness (u3)"] {
	gdb_suppress_tests
    }
    if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #7"] {
	gdb_suppress_tests
    }
    if [gdb_test "print flags" ".*uc = 0 .*, s1 = 0, u1 = 0, s2 = 0, u2 = 0, s3 = 0, u3 = 0, s9 = 1, u9 = 0, sc = 0.*" "bitfield uniqueness (s9)"] {
	gdb_suppress_tests
    }
    if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #8"] {
	gdb_suppress_tests
    }
    if [gdb_test "print flags" ".*uc = 0 .*, s1 = 0, u1 = 0, s2 = 0, u2 = 0, s3 = 0, u3 = 0, s9 = 0, u9 = 1, sc = 0.*" "bitfield uniqueness (u9)"] {
	gdb_suppress_tests
    }
    if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #9"] {
	gdb_suppress_tests
    }
    if [gdb_test "print flags" ".*uc = 0 .*, s1 = 0, u1 = 0, s2 = 0, u2 = 0, s3 = 0, u3 = 0, s9 = 0, u9 = 0, sc = 1.*" "bitfield uniqueness (sc)"] {
	gdb_suppress_tests
    }
    # Hmmmm?
    gdb_stop_suppressing_tests
}


#
# Test bitfield containment.
# Fill alternating fields with all 1's and verify that none of the bits
# "bleed over" to the other fields.
#

proc bitfield_containment {} {
    global decimal
    global hex
    global gdb_prompt
    global srcfile

    delete_breakpoints

    if { ![runto break2] } {
	gdb_suppress_tests
    }

    if [gdb_test "print/x flags" "= {uc = 0xff, s1 = 0x0, u1 = 0x1, s2 = 0x0, u2 = 0x3, s3 = 0x0, u3 = 0x7, s9 = 0x0, u9 = 0x1ff, sc = 0x0}" "bitfield containment #1"] {
	gdb_suppress_tests
    }

    if [gdb_test "cont" "Break.*break2 \\(\\) at .*$srcfile:$decimal.*" "continuing to break2"] {
	gdb_suppress_tests
    }

    # If program is compiled with Sun CC, then these print out as their
    # actual sizes; if compiled with gcc, they print out as 0xffffffff
    # (which strikes me as bogus, but accept it at least for now).
    if [gdb_test "print/x flags" "= {uc = 0x0, s1 = 0x(1|f*), u1 = 0x0, s2 = 0x(3|f*), u2 = 0x0, s3 = 0x(7|f*), u3 = 0x0, s9 = 0x(1ff|f*), u9 = 0x0, sc = 0xff}" "bitfield containment #2"] {
	gdb_suppress_tests
    }
    gdb_stop_suppressing_tests
}

# Test unsigned bitfields for unsignedness and range.
# Fill the unsigned fields with the maximum positive value and verify that
# the values are printed correctly.

proc bitfield_unsignedness {} {
    global decimal
    global hex
    global gdb_prompt
    global srcfile

    delete_breakpoints

    if { ![runto break3] } {
	gdb_suppress_tests
    }

    if [gdb_test "print flags" ".*uc = 0 .*, s1 = 0, u1 = 1, s2 = 0, u2 = 3, s3 = 0, u3 = 7, s9 = 0, u9 = 511, sc = 0.*" "unsigned bitfield ranges"] {
	gdb_suppress_tests
    }
    gdb_stop_suppressing_tests
}

#
# Test signed bitfields for signedness and range.
# Fill the signed fields with the maximum positive value, then the maximally
# negative value, then -1, and verify in each case that the values are
# printed correctly.
#

proc bitfield_signedness {} {
    global decimal
    global hex
    global gdb_prompt
    global srcfile

    delete_breakpoints

    if { ! [runto break4] } {
	gdb_suppress_tests
    }

    if [gdb_test "print flags" "= {uc = 0 .*, s1 = 0, u1 = 0, s2 = 1, u2 = 0, s3 = 3, u3 = 0, s9 = 255, u9 = 0, sc = 0 .*}" "signed bitfields, max positive values"] {
	gdb_suppress_tests
    }

    if [gdb_test "cont" "Break.*break4 \\(\\) at .*$srcfile:$decimal.*" "continuing to break4 #1"] {
	gdb_suppress_tests
    }

    # Determine if the target has signed bitfields so we can xfail the
    # the signed bitfield tests if it doesn't.
    gdb_test_multiple "print i" "determining signed-ness of bitfields" {
	-re ".* = -256.*$gdb_prompt $" {
	    pass "determining signed-ness of bitfields"
	}
	-re ".* = 256.*$gdb_prompt $" {
	    pass "determining signed-ness of bitfields"
	    setup_xfail "*-*-*"
	}
	-re ".*$gdb_prompt $" {
	    fail "determining signed-ness of bitfields"
	    gdb_suppress_tests
	}
	default { 
	    fail "determining signed-ness of bitfields"
	    gdb_suppress_tests
	}
    }

    if [gdb_test "print flags" ".*uc = 0 .*, s1 = -1, u1 = 0, s2 = -2, u2 = 0, s3 = -4, u3 = 0, s9 = -256, u9 = 0, sc = 0.*" "signed bitfields, max negative values"] {
        gdb_suppress_tests
    }

    if [gdb_test "cont" "Break.*break4 \\(\\) at .*$srcfile:$decimal.*" "continuing to break4 #2"] {
	gdb_suppress_tests
    }

    if [gdb_test "print flags" ".*uc = 0 .*, s1 = -1, u1 = 0, s2 = -1, u2 = 0, s3 = -1, u3 = 0, s9 = -1, u9 = 0, sc = 0.*" "signed bitfields with -1"] {
	gdb_suppress_tests
    }
    # Hmmmm???
    gdb_stop_suppressing_tests
}

# Test bitfields at non-zero offsets in a struct.

proc bitfield_at_offset {} {
    global decimal
    global hex
    global gdb_prompt
    global srcfile

    gdb_breakpoint break5
    if [gdb_test "cont" "Break.*break5 \\(\\) at .*$srcfile:$decimal.*" "continuing to break5"] {
	return
    }

    set one ".*uc = 0 .*, s1 = 0, u1 = 0, s2 = 0, u2 = 0, s3 = 0, u3 = 5, s9 = 0, u9 = 0, sc = 0.*"
    set two ".*uc = 0 .*, s1 = 0, u1 = 0, s2 = 0, u2 = 0, s3 = 0, u3 = 3, s9 = 0, u9 = 0, sc = 0.*"
    gdb_test "print container" "$one$two" "distinct bitfields in container"
    gdb_test "print container.one.u3" ".* = 5"
    gdb_test "print container.two.u3" ".* = 3"
}

proc bitfield_internalvar {} {
    global gdb_prompt

    # First, we create an internal var holding an instance of
    # the struct (zeroed out).
    gdb_test "set \$myvar = (struct internalvartest) \{0\}" "" \
      "set internal var"

    # Now, we set the proper bits.
    gdb_test_no_output "set \$myvar.a = 0"
    gdb_test_no_output "set \$myvar.inner.b = 1"
    gdb_test_no_output "set \$myvar.inner.deep.c = 0"
    gdb_test_no_output "set \$myvar.inner.deep.d = -1"
    gdb_test_no_output "set \$myvar.inner.e = 1"
    gdb_test_no_output "set \$myvar.f = 1"

    # Here comes the true testing.
    gdb_test "print \$myvar.a" "\\$\[0-9\]\+ = 0"
    gdb_test "print \$myvar.inner.b" "\\$\[0-9\]\+ = 1"
    gdb_test "print \$myvar.inner.deep.c" "\\$\[0-9\]\+ = 0"
    gdb_test "print \$myvar.inner.deep.d" "\\$\[0-9\]\+ = -1"
    gdb_test "print \$myvar.inner.e" "\\$\[0-9\]\+ = -1"
    gdb_test "print \$myvar.f" "\\$\[0-9\]\+ = -1"
}

gdb_test_no_output "set print sevenbit-strings"

bitfield_uniqueness
bitfield_containment
bitfield_unsignedness
bitfield_signedness
bitfield_at_offset
bitfield_internalvar