Sync usage with man page.
[netbsd-mini2440.git] / gnu / dist / gdb6 / gdb / testsuite / gdb.base / bitfields.c
blobbd411f7b647c67820fe6eb7ea0750e9edc3a01ee
1 /* Test program to test bit field operations */
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... */
8 #if !defined(__STDC__) && !defined(__cplusplus)
9 #define signed /**/
10 #endif
12 struct fields
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;
26 void break1 ()
30 void break2 ()
34 void break3 ()
38 void break4 ()
42 void break5 ()
46 void break6 ()
50 void break7 ()
54 void break8 ()
58 void break9 ()
62 void break10 ()
66 /* This is used by bitfields.exp to determine if the target understands
67 signed bitfields. */
68 int i;
70 int main ()
72 /* For each member, set that member to 1, allow gdb to verify that the
73 member (and only that member) is 1, and then reset it back to 0. */
75 #ifdef usestubs
76 set_debug_traps();
77 breakpoint();
78 #endif
79 flags.uc = 1;
80 break1 ();
81 flags.uc = 0;
83 flags.s1 = -1;
84 break1 ();
85 flags.s1 = 0;
87 flags.u1 = 1;
88 break1 ();
89 flags.u1 = 0;
91 flags.s2 = 1;
92 break1 ();
93 flags.s2 = 0;
95 flags.u2 = 1;
96 break1 ();
97 flags.u2 = 0;
99 flags.s3 = 1;
100 break1 ();
101 flags.s3 = 0;
103 flags.u3 = 1;
104 break1 ();
105 flags.u3 = 0;
107 flags.s9 = 1;
108 break1 ();
109 flags.s9 = 0;
111 flags.u9 = 1;
112 break1 ();
113 flags.u9 = 0;
115 flags.sc = 1;
116 break1 ();
117 flags.sc = 0;
119 /* Fill alternating fields with all 1's and verify that none of the bits
120 "bleed over" to the other fields. */
122 flags.uc = 0xFF;
123 flags.u1 = 0x1;
124 flags.u2 = 0x3;
125 flags.u3 = 0x7;
126 flags.u9 = 0x1FF;
127 break2 ();
128 flags.uc = 0;
129 flags.u1 = 0;
130 flags.u2 = 0;
131 flags.u3 = 0;
132 flags.u9 = 0;
134 flags.s1 = -1;
135 flags.s2 = -1;
136 flags.s3 = -1;
137 flags.s9 = -1;
138 flags.sc = 0xFF;
139 break2 ();
140 flags.s1 = 0;
141 flags.s2 = 0;
142 flags.s3 = 0;
143 flags.s9 = 0;
144 flags.sc = 0;
146 /* Fill the unsigned fields with the maximum positive value and verify
147 that the values are printed correctly. */
149 /* Maximum positive values */
150 flags.u1 = 0x1;
151 flags.u2 = 0x3;
152 flags.u3 = 0x7;
153 flags.u9 = 0x1FF;
154 break3 ();
155 flags.u1 = 0;
156 flags.u2 = 0;
157 flags.u3 = 0;
158 flags.u9 = 0;
160 /* Fill the signed fields with the maximum positive value, then the maximally
161 negative value, then -1, and verify in each case that the values are
162 printed correctly. */
164 /* Maximum positive values */
165 flags.s1 = 0x0;
166 flags.s2 = 0x1;
167 flags.s3 = 0x3;
168 flags.s9 = 0xFF;
169 break4 ();
171 /* Maximally negative values */
172 flags.s1 = -0x1;
173 flags.s2 = -0x2;
174 flags.s3 = -0x4;
175 flags.s9 = -0x100;
176 /* Extract bitfield value so that bitfield.exp can check if the target
177 understands signed bitfields. */
178 i = flags.s9;
179 break4 ();
181 /* -1 */
182 flags.s1 = -1;
183 flags.s2 = -1;
184 flags.s3 = -1;
185 flags.s9 = -1;
186 break4 ();
188 flags.s1 = 0;
189 flags.s2 = 0;
190 flags.s3 = 0;
191 flags.s9 = 0;
193 return 0;