Commit | Line | Data |
---|---|---|
a6bac58e TT |
1 | /* This testcase is part of GDB, the GNU debugger. |
2 | ||
7b6bb8da | 3 | Copyright 2008, 2009, 2010, 2011 Free Software Foundation, Inc. |
a6bac58e TT |
4 | |
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
7 | the Free Software Foundation; either version 3 of the License, or | |
8 | (at your option) any later version. | |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
17 | ||
0cc7d26f TT |
18 | #include <string.h> |
19 | ||
a6bac58e TT |
20 | struct s |
21 | { | |
22 | int a; | |
23 | int *b; | |
24 | }; | |
25 | ||
26 | struct ss | |
27 | { | |
28 | struct s a; | |
29 | struct s b; | |
30 | }; | |
31 | ||
91158a56 TT |
32 | struct arraystruct |
33 | { | |
34 | int y; | |
35 | struct s x[2]; | |
36 | }; | |
37 | ||
fbb8f299 PM |
38 | struct ns { |
39 | const char *null_str; | |
40 | int length; | |
41 | }; | |
42 | ||
be759fcf PM |
43 | struct lazystring { |
44 | const char *lazy_str; | |
45 | }; | |
46 | ||
e1ab1f9c JK |
47 | struct hint_error { |
48 | int x; | |
49 | }; | |
50 | ||
a6bac58e TT |
51 | #ifdef __cplusplus |
52 | struct S : public s { | |
53 | int zs; | |
54 | }; | |
55 | ||
56 | struct SS { | |
57 | int zss; | |
58 | S s; | |
59 | }; | |
60 | ||
61 | struct SSS | |
62 | { | |
63 | SSS (int x, const S& r); | |
64 | int a; | |
65 | const S &b; | |
66 | }; | |
67 | SSS::SSS (int x, const S& r) : a(x), b(r) { } | |
68 | ||
69 | class VirtualTest | |
70 | { | |
71 | private: | |
72 | int value; | |
73 | ||
74 | public: | |
75 | VirtualTest () | |
76 | { | |
77 | value = 1; | |
78 | } | |
79 | }; | |
80 | ||
81 | class Vbase1 : public virtual VirtualTest { }; | |
82 | class Vbase2 : public virtual VirtualTest { }; | |
83 | class Vbase3 : public virtual VirtualTest { }; | |
84 | ||
85 | class Derived : public Vbase1, public Vbase2, public Vbase3 | |
86 | { | |
87 | private: | |
88 | int value; | |
89 | ||
90 | public: | |
91 | Derived () | |
92 | { | |
93 | value = 2; | |
94 | } | |
95 | }; | |
96 | ||
d65aec65 PM |
97 | class Fake |
98 | { | |
99 | int sname; | |
100 | ||
101 | public: | |
102 | Fake (const int name = 0): | |
103 | sname (name) | |
104 | { | |
105 | } | |
106 | }; | |
a6bac58e TT |
107 | #endif |
108 | ||
0cc7d26f TT |
109 | struct substruct { |
110 | int a; | |
111 | int b; | |
112 | }; | |
113 | ||
114 | struct outerstruct { | |
115 | struct substruct s; | |
116 | int x; | |
117 | }; | |
118 | ||
119 | struct outerstruct | |
120 | substruct_test (void) | |
121 | { | |
122 | struct outerstruct outer; | |
123 | outer.s.a = 0; | |
124 | outer.s.b = 0; | |
125 | outer.x = 0; | |
126 | ||
127 | outer.s.a = 3; /* MI outer breakpoint here */ | |
128 | ||
129 | return outer; | |
130 | } | |
131 | ||
a6bac58e TT |
132 | typedef struct string_repr |
133 | { | |
134 | struct whybother | |
135 | { | |
136 | const char *contents; | |
137 | } whybother; | |
138 | } string; | |
139 | ||
140 | /* This lets us avoid malloc. */ | |
141 | int array[100]; | |
79f283fe PM |
142 | int narray[10]; |
143 | ||
144 | struct justchildren | |
145 | { | |
146 | int len; | |
147 | int *elements; | |
148 | }; | |
149 | ||
150 | typedef struct justchildren nostring_type; | |
a6bac58e TT |
151 | |
152 | struct container | |
153 | { | |
154 | string name; | |
155 | int len; | |
156 | int *elements; | |
157 | }; | |
158 | ||
159 | typedef struct container zzz_type; | |
160 | ||
161 | string | |
162 | make_string (const char *s) | |
163 | { | |
164 | string result; | |
165 | result.whybother.contents = s; | |
166 | return result; | |
167 | } | |
168 | ||
169 | zzz_type | |
170 | make_container (const char *s) | |
171 | { | |
172 | zzz_type result; | |
173 | ||
174 | result.name = make_string (s); | |
175 | result.len = 0; | |
176 | result.elements = 0; | |
177 | ||
178 | return result; | |
179 | } | |
180 | ||
181 | void | |
182 | add_item (zzz_type *c, int val) | |
183 | { | |
184 | if (c->len == 0) | |
185 | c->elements = array; | |
186 | c->elements[c->len] = val; | |
187 | ++c->len; | |
188 | } | |
189 | ||
190 | void init_s(struct s *s, int a) | |
191 | { | |
192 | s->a = a; | |
193 | s->b = &s->a; | |
194 | } | |
195 | ||
196 | void init_ss(struct ss *s, int a, int b) | |
197 | { | |
198 | init_s(&s->a, a); | |
199 | init_s(&s->b, b); | |
200 | } | |
201 | ||
202 | void do_nothing(void) | |
203 | { | |
204 | int c; | |
205 | ||
206 | c = 23; /* Another MI breakpoint */ | |
207 | } | |
208 | ||
0cc7d26f TT |
209 | struct nullstr |
210 | { | |
211 | char *s; | |
212 | }; | |
213 | ||
214 | struct string_repr string_1 = { { "one" } }; | |
215 | struct string_repr string_2 = { { "two" } }; | |
216 | ||
a6bac58e TT |
217 | int |
218 | main () | |
219 | { | |
220 | struct ss ss; | |
221 | struct ss ssa[2]; | |
91158a56 | 222 | struct arraystruct arraystruct; |
a6bac58e TT |
223 | string x = make_string ("this is x"); |
224 | zzz_type c = make_container ("container"); | |
0cc7d26f | 225 | zzz_type c2 = make_container ("container2"); |
a6bac58e | 226 | const struct string_repr cstring = { { "const string" } }; |
0cc7d26f TT |
227 | /* Clearing by being `static' could invoke an other GDB C++ bug. */ |
228 | struct nullstr nullstr; | |
a4c8e806 | 229 | nostring_type nstype, nstype2; |
621c8364 | 230 | struct ns ns, ns2; |
3a772aa4 | 231 | struct lazystring estring, estring2; |
e1ab1f9c | 232 | struct hint_error hint_error; |
3a772aa4 | 233 | |
79f283fe PM |
234 | nstype.elements = narray; |
235 | nstype.len = 0; | |
be759fcf | 236 | |
a6bac58e TT |
237 | init_ss(&ss, 1, 2); |
238 | init_ss(ssa+0, 3, 4); | |
239 | init_ss(ssa+1, 5, 6); | |
0cc7d26f | 240 | memset (&nullstr, 0, sizeof nullstr); |
a6bac58e | 241 | |
91158a56 TT |
242 | arraystruct.y = 7; |
243 | init_s (&arraystruct.x[0], 23); | |
244 | init_s (&arraystruct.x[1], 24); | |
245 | ||
fbb8f299 PM |
246 | ns.null_str = "embedded\0null\0string"; |
247 | ns.length = 20; | |
248 | ||
621c8364 TT |
249 | /* Make a "corrupted" string. */ |
250 | ns2.null_str = NULL; | |
251 | ns2.length = 20; | |
252 | ||
be759fcf PM |
253 | estring.lazy_str = "embedded x\201\202\203\204" ; |
254 | ||
3a772aa4 TT |
255 | /* Incomplete UTF-8, but ok Latin-1. */ |
256 | estring2.lazy_str = "embedded x\302"; | |
257 | ||
a6bac58e TT |
258 | #ifdef __cplusplus |
259 | S cps; | |
260 | ||
261 | cps.zs = 7; | |
262 | init_s(&cps, 8); | |
263 | ||
264 | SS cpss; | |
265 | cpss.zss = 9; | |
266 | init_s(&cpss.s, 10); | |
267 | ||
268 | SS cpssa[2]; | |
269 | cpssa[0].zss = 11; | |
270 | init_s(&cpssa[0].s, 12); | |
271 | cpssa[1].zss = 13; | |
272 | init_s(&cpssa[1].s, 14); | |
273 | ||
274 | SSS sss(15, cps); | |
275 | ||
276 | SSS& ref (sss); | |
277 | ||
278 | Derived derived; | |
279 | ||
d65aec65 | 280 | Fake fake (42); |
a6bac58e TT |
281 | #endif |
282 | ||
283 | add_item (&c, 23); /* MI breakpoint here */ | |
284 | add_item (&c, 72); | |
285 | ||
286 | #ifdef MI | |
0cc7d26f TT |
287 | add_item (&c, 1011); |
288 | c.elements[0] = 1023; | |
289 | c.elements[0] = 2323; | |
290 | ||
291 | add_item (&c2, 2222); | |
292 | add_item (&c2, 3333); | |
293 | ||
294 | substruct_test (); | |
a6bac58e TT |
295 | do_nothing (); |
296 | #endif | |
297 | ||
79f283fe PM |
298 | nstype.elements[0] = 7; |
299 | nstype.elements[1] = 42; | |
300 | nstype.len = 2; | |
301 | ||
a4c8e806 TT |
302 | nstype2 = nstype; |
303 | ||
a6bac58e TT |
304 | return 0; /* break to inspect struct and union */ |
305 | } |