* gdb.base/call-signal-resume.exp, gdb.base/unwindonsignal.exp: Skip
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / bitfields.c
1 /* Test program to test bit field operations */
2
3 /* For non-ANSI compilers, use plain ints for the signed bit fields. However,
4 whether they actually end up signed or not is implementation defined, so
5 this may cause some tests to fail. But at least we can still compile
6 the test program and run the tests... */
7
8 #if !defined(__STDC__) && !defined(__cplusplus)
9 #define signed /**/
10 #endif
11
12 struct fields
13 {
14 unsigned char uc ;
15 signed int s1 : 1;
16 unsigned int u1 : 1;
17 signed int s2 : 2;
18 unsigned int u2 : 2;
19 signed int s3 : 3;
20 unsigned int u3 : 3;
21 signed int s9 : 9;
22 unsigned int u9 : 9;
23 signed char sc ;
24 } flags;
25
26 void break1 ()
27 {
28 }
29
30 void break2 ()
31 {
32 }
33
34 void break3 ()
35 {
36 }
37
38 void break4 ()
39 {
40 }
41
42 void break5 ()
43 {
44 }
45
46 void break6 ()
47 {
48 }
49
50 void break7 ()
51 {
52 }
53
54 void break8 ()
55 {
56 }
57
58 void break9 ()
59 {
60 }
61
62 void break10 ()
63 {
64 }
65
66 struct container
67 {
68 struct fields one;
69 struct fields two;
70 } container;
71
72 /* This is used by bitfields.exp to determine if the target understands
73 signed bitfields. */
74 int i;
75
76 int main ()
77 {
78 /* For each member, set that member to 1, allow gdb to verify that the
79 member (and only that member) is 1, and then reset it back to 0. */
80
81 #ifdef usestubs
82 set_debug_traps();
83 breakpoint();
84 #endif
85 flags.uc = 1;
86 break1 ();
87 flags.uc = 0;
88
89 flags.s1 = -1;
90 break1 ();
91 flags.s1 = 0;
92
93 flags.u1 = 1;
94 break1 ();
95 flags.u1 = 0;
96
97 flags.s2 = 1;
98 break1 ();
99 flags.s2 = 0;
100
101 flags.u2 = 1;
102 break1 ();
103 flags.u2 = 0;
104
105 flags.s3 = 1;
106 break1 ();
107 flags.s3 = 0;
108
109 flags.u3 = 1;
110 break1 ();
111 flags.u3 = 0;
112
113 flags.s9 = 1;
114 break1 ();
115 flags.s9 = 0;
116
117 flags.u9 = 1;
118 break1 ();
119 flags.u9 = 0;
120
121 flags.sc = 1;
122 break1 ();
123 flags.sc = 0;
124
125 /* Fill alternating fields with all 1's and verify that none of the bits
126 "bleed over" to the other fields. */
127
128 flags.uc = 0xFF;
129 flags.u1 = 0x1;
130 flags.u2 = 0x3;
131 flags.u3 = 0x7;
132 flags.u9 = 0x1FF;
133 break2 ();
134 flags.uc = 0;
135 flags.u1 = 0;
136 flags.u2 = 0;
137 flags.u3 = 0;
138 flags.u9 = 0;
139
140 flags.s1 = -1;
141 flags.s2 = -1;
142 flags.s3 = -1;
143 flags.s9 = -1;
144 flags.sc = 0xFF;
145 break2 ();
146 flags.s1 = 0;
147 flags.s2 = 0;
148 flags.s3 = 0;
149 flags.s9 = 0;
150 flags.sc = 0;
151
152 /* Fill the unsigned fields with the maximum positive value and verify
153 that the values are printed correctly. */
154
155 /* Maximum positive values */
156 flags.u1 = 0x1;
157 flags.u2 = 0x3;
158 flags.u3 = 0x7;
159 flags.u9 = 0x1FF;
160 break3 ();
161 flags.u1 = 0;
162 flags.u2 = 0;
163 flags.u3 = 0;
164 flags.u9 = 0;
165
166 /* Fill the signed fields with the maximum positive value, then the maximally
167 negative value, then -1, and verify in each case that the values are
168 printed correctly. */
169
170 /* Maximum positive values */
171 flags.s1 = 0x0;
172 flags.s2 = 0x1;
173 flags.s3 = 0x3;
174 flags.s9 = 0xFF;
175 break4 ();
176
177 /* Maximally negative values */
178 flags.s1 = -0x1;
179 flags.s2 = -0x2;
180 flags.s3 = -0x4;
181 flags.s9 = -0x100;
182 /* Extract bitfield value so that bitfield.exp can check if the target
183 understands signed bitfields. */
184 i = flags.s9;
185 break4 ();
186
187 /* -1 */
188 flags.s1 = -1;
189 flags.s2 = -1;
190 flags.s3 = -1;
191 flags.s9 = -1;
192 break4 ();
193
194 flags.s1 = 0;
195 flags.s2 = 0;
196 flags.s3 = 0;
197 flags.s9 = 0;
198
199 /* Bitfields at a non-zero offset in a containing structure. */
200 container.one.u3 = 5;
201 container.two.u3 = 3;
202 break5 ();
203
204 return 0;
205 }
This page took 0.039739 seconds and 4 git commands to generate.