Commit | Line | Data |
---|---|---|
3666a048 | 1 | # Copyright 1992-2021 Free Software Foundation, Inc. |
c906108c SS |
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 | |
e22f8b7c | 5 | # the Free Software Foundation; either version 3 of the License, or |
c906108c | 6 | # (at your option) any later version. |
e22f8b7c | 7 | # |
c906108c SS |
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. | |
e22f8b7c | 12 | # |
c906108c | 13 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
c906108c | 15 | |
c906108c SS |
16 | # This file was written by Fred Fish. (fnf@cygnus.com) |
17 | ||
c906108c | 18 | |
a64d2530 TT |
19 | standard_testfile |
20 | ||
5b362f04 | 21 | if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} { |
b60f0898 | 22 | return -1 |
c906108c SS |
23 | } |
24 | ||
25 | # | |
26 | # Test bitfield locating and uniqueness. | |
27 | # For each member, set that member to 1 and verify that the member (and only | |
28 | # that member) is 1, then reset it back to 0. | |
29 | # | |
30 | ||
31 | proc bitfield_uniqueness {} { | |
32 | global decimal | |
33 | global hex | |
34 | global gdb_prompt | |
35 | global srcfile | |
36 | ||
37 | if { ! [runto break1] } { | |
0ac85db5 | 38 | return |
c906108c | 39 | } |
0ac85db5 SM |
40 | |
41 | gdb_test "print flags" ".*uc = 1 .*, s1 = 0, u1 = 0, s2 = 0, u2 = 0, s3 = 0, u3 = 0, s9 = 0, u9 = 0, sc = 0.*" | |
42 | gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #1" | |
43 | ||
c906108c SS |
44 | # Note that we check for s1 as either 1 or -1, so that failure to |
45 | # treat it correctly as a signed 1bit field (values 0 or -1) while | |
46 | # printing its value does not cause a spurious failure. We do the | |
47 | # signedness preservation test later. | |
0ac85db5 SM |
48 | 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)" |
49 | gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #2" | |
50 | 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)" | |
51 | gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #3" | |
52 | 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)" | |
53 | gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #4" | |
54 | 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)" | |
55 | gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #5" | |
56 | 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)" | |
57 | gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #6" | |
58 | 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)" | |
59 | gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #7" | |
60 | 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)" | |
61 | gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #8" | |
62 | 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)" | |
63 | gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #9" | |
64 | 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)" | |
c906108c SS |
65 | } |
66 | ||
67 | ||
68 | # | |
69 | # Test bitfield containment. | |
70 | # Fill alternating fields with all 1's and verify that none of the bits | |
71 | # "bleed over" to the other fields. | |
72 | # | |
73 | ||
74 | proc bitfield_containment {} { | |
75 | global decimal | |
76 | global hex | |
77 | global gdb_prompt | |
78 | global srcfile | |
79 | ||
80 | delete_breakpoints | |
81 | ||
82 | if { ![runto break2] } { | |
0ac85db5 | 83 | return |
c906108c SS |
84 | } |
85 | ||
0ac85db5 SM |
86 | 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" |
87 | gdb_test "cont" "Break.*break2 \\(\\) at .*$srcfile:$decimal.*" "continuing to break2" | |
c906108c SS |
88 | |
89 | # If program is compiled with Sun CC, then these print out as their | |
90 | # actual sizes; if compiled with gcc, they print out as 0xffffffff | |
91 | # (which strikes me as bogus, but accept it at least for now). | |
0ac85db5 | 92 | 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" |
c906108c SS |
93 | } |
94 | ||
95 | # Test unsigned bitfields for unsignedness and range. | |
96 | # Fill the unsigned fields with the maximum positive value and verify that | |
97 | # the values are printed correctly. | |
98 | ||
99 | proc bitfield_unsignedness {} { | |
100 | global decimal | |
101 | global hex | |
102 | global gdb_prompt | |
103 | global srcfile | |
104 | ||
105 | delete_breakpoints | |
106 | ||
107 | if { ![runto break3] } { | |
0ac85db5 | 108 | return |
c906108c SS |
109 | } |
110 | ||
0ac85db5 | 111 | 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" |
c906108c SS |
112 | } |
113 | ||
114 | # | |
115 | # Test signed bitfields for signedness and range. | |
116 | # Fill the signed fields with the maximum positive value, then the maximally | |
117 | # negative value, then -1, and verify in each case that the values are | |
118 | # printed correctly. | |
119 | # | |
120 | ||
121 | proc bitfield_signedness {} { | |
122 | global decimal | |
123 | global hex | |
124 | global gdb_prompt | |
125 | global srcfile | |
126 | ||
127 | delete_breakpoints | |
128 | ||
129 | if { ! [runto break4] } { | |
0ac85db5 | 130 | return |
c906108c SS |
131 | } |
132 | ||
0ac85db5 SM |
133 | 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" |
134 | gdb_test "cont" "Break.*break4 \\(\\) at .*$srcfile:$decimal.*" "continuing to break4 #1" | |
c906108c SS |
135 | |
136 | # Determine if the target has signed bitfields so we can xfail the | |
137 | # the signed bitfield tests if it doesn't. | |
6acb16a2 | 138 | gdb_test_multiple "print i" "determining signed-ness of bitfields" { |
c906108c SS |
139 | -re ".* = -256.*$gdb_prompt $" { |
140 | pass "determining signed-ness of bitfields" | |
141 | } | |
142 | -re ".* = 256.*$gdb_prompt $" { | |
143 | pass "determining signed-ness of bitfields" | |
144 | setup_xfail "*-*-*" | |
145 | } | |
146 | -re ".*$gdb_prompt $" { | |
147 | fail "determining signed-ness of bitfields" | |
c906108c | 148 | } |
0ac85db5 | 149 | default { |
4ec70201 | 150 | fail "determining signed-ness of bitfields" |
c906108c SS |
151 | } |
152 | } | |
153 | ||
0ac85db5 SM |
154 | 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" |
155 | gdb_test "cont" "Break.*break4 \\(\\) at .*$srcfile:$decimal.*" "continuing to break4 #2" | |
156 | 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" | |
c906108c SS |
157 | } |
158 | ||
4a76eae5 DJ |
159 | # Test bitfields at non-zero offsets in a struct. |
160 | ||
161 | proc bitfield_at_offset {} { | |
162 | global decimal | |
163 | global hex | |
164 | global gdb_prompt | |
165 | global srcfile | |
166 | ||
167 | gdb_breakpoint break5 | |
168 | if [gdb_test "cont" "Break.*break5 \\(\\) at .*$srcfile:$decimal.*" "continuing to break5"] { | |
169 | return | |
170 | } | |
171 | ||
172 | set one ".*uc = 0 .*, s1 = 0, u1 = 0, s2 = 0, u2 = 0, s3 = 0, u3 = 5, s9 = 0, u9 = 0, sc = 0.*" | |
173 | set two ".*uc = 0 .*, s1 = 0, u1 = 0, s2 = 0, u2 = 0, s3 = 0, u3 = 3, s9 = 0, u9 = 0, sc = 0.*" | |
174 | gdb_test "print container" "$one$two" "distinct bitfields in container" | |
175 | gdb_test "print container.one.u3" ".* = 5" | |
176 | gdb_test "print container.two.u3" ".* = 3" | |
177 | } | |
178 | ||
d9e98382 SDJ |
179 | proc bitfield_internalvar {} { |
180 | global gdb_prompt | |
181 | ||
182 | # First, we create an internal var holding an instance of | |
183 | # the struct (zeroed out). | |
184 | gdb_test "set \$myvar = (struct internalvartest) \{0\}" "" \ | |
185 | "set internal var" | |
186 | ||
187 | # Now, we set the proper bits. | |
188 | gdb_test_no_output "set \$myvar.a = 0" | |
189 | gdb_test_no_output "set \$myvar.inner.b = 1" | |
190 | gdb_test_no_output "set \$myvar.inner.deep.c = 0" | |
191 | gdb_test_no_output "set \$myvar.inner.deep.d = -1" | |
192 | gdb_test_no_output "set \$myvar.inner.e = 1" | |
193 | gdb_test_no_output "set \$myvar.f = 1" | |
194 | ||
195 | # Here comes the true testing. | |
196 | gdb_test "print \$myvar.a" "\\$\[0-9\]\+ = 0" | |
197 | gdb_test "print \$myvar.inner.b" "\\$\[0-9\]\+ = 1" | |
198 | gdb_test "print \$myvar.inner.deep.c" "\\$\[0-9\]\+ = 0" | |
199 | gdb_test "print \$myvar.inner.deep.d" "\\$\[0-9\]\+ = -1" | |
200 | gdb_test "print \$myvar.inner.e" "\\$\[0-9\]\+ = -1" | |
201 | gdb_test "print \$myvar.f" "\\$\[0-9\]\+ = -1" | |
202 | } | |
203 | ||
6acb16a2 | 204 | gdb_test_no_output "set print sevenbit-strings" |
c906108c SS |
205 | |
206 | bitfield_uniqueness | |
c906108c | 207 | bitfield_containment |
c906108c | 208 | bitfield_unsignedness |
c906108c | 209 | bitfield_signedness |
4a76eae5 | 210 | bitfield_at_offset |
d9e98382 | 211 | bitfield_internalvar |