Commit | Line | Data |
---|---|---|
a6bac58e TT |
1 | /* This testcase is part of GDB, the GNU debugger. |
2 | ||
4c38e0a4 | 3 | Copyright 2008, 2009, 2010 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 | ||
a6bac58e TT |
47 | #ifdef __cplusplus |
48 | struct S : public s { | |
49 | int zs; | |
50 | }; | |
51 | ||
52 | struct SS { | |
53 | int zss; | |
54 | S s; | |
55 | }; | |
56 | ||
57 | struct SSS | |
58 | { | |
59 | SSS (int x, const S& r); | |
60 | int a; | |
61 | const S &b; | |
62 | }; | |
63 | SSS::SSS (int x, const S& r) : a(x), b(r) { } | |
64 | ||
65 | class VirtualTest | |
66 | { | |
67 | private: | |
68 | int value; | |
69 | ||
70 | public: | |
71 | VirtualTest () | |
72 | { | |
73 | value = 1; | |
74 | } | |
75 | }; | |
76 | ||
77 | class Vbase1 : public virtual VirtualTest { }; | |
78 | class Vbase2 : public virtual VirtualTest { }; | |
79 | class Vbase3 : public virtual VirtualTest { }; | |
80 | ||
81 | class Derived : public Vbase1, public Vbase2, public Vbase3 | |
82 | { | |
83 | private: | |
84 | int value; | |
85 | ||
86 | public: | |
87 | Derived () | |
88 | { | |
89 | value = 2; | |
90 | } | |
91 | }; | |
92 | ||
93 | #endif | |
94 | ||
0cc7d26f TT |
95 | struct substruct { |
96 | int a; | |
97 | int b; | |
98 | }; | |
99 | ||
100 | struct outerstruct { | |
101 | struct substruct s; | |
102 | int x; | |
103 | }; | |
104 | ||
105 | struct outerstruct | |
106 | substruct_test (void) | |
107 | { | |
108 | struct outerstruct outer; | |
109 | outer.s.a = 0; | |
110 | outer.s.b = 0; | |
111 | outer.x = 0; | |
112 | ||
113 | outer.s.a = 3; /* MI outer breakpoint here */ | |
114 | ||
115 | return outer; | |
116 | } | |
117 | ||
a6bac58e TT |
118 | typedef struct string_repr |
119 | { | |
120 | struct whybother | |
121 | { | |
122 | const char *contents; | |
123 | } whybother; | |
124 | } string; | |
125 | ||
126 | /* This lets us avoid malloc. */ | |
127 | int array[100]; | |
79f283fe PM |
128 | int narray[10]; |
129 | ||
130 | struct justchildren | |
131 | { | |
132 | int len; | |
133 | int *elements; | |
134 | }; | |
135 | ||
136 | typedef struct justchildren nostring_type; | |
a6bac58e TT |
137 | |
138 | struct container | |
139 | { | |
140 | string name; | |
141 | int len; | |
142 | int *elements; | |
143 | }; | |
144 | ||
145 | typedef struct container zzz_type; | |
146 | ||
147 | string | |
148 | make_string (const char *s) | |
149 | { | |
150 | string result; | |
151 | result.whybother.contents = s; | |
152 | return result; | |
153 | } | |
154 | ||
155 | zzz_type | |
156 | make_container (const char *s) | |
157 | { | |
158 | zzz_type result; | |
159 | ||
160 | result.name = make_string (s); | |
161 | result.len = 0; | |
162 | result.elements = 0; | |
163 | ||
164 | return result; | |
165 | } | |
166 | ||
167 | void | |
168 | add_item (zzz_type *c, int val) | |
169 | { | |
170 | if (c->len == 0) | |
171 | c->elements = array; | |
172 | c->elements[c->len] = val; | |
173 | ++c->len; | |
174 | } | |
175 | ||
176 | void init_s(struct s *s, int a) | |
177 | { | |
178 | s->a = a; | |
179 | s->b = &s->a; | |
180 | } | |
181 | ||
182 | void init_ss(struct ss *s, int a, int b) | |
183 | { | |
184 | init_s(&s->a, a); | |
185 | init_s(&s->b, b); | |
186 | } | |
187 | ||
188 | void do_nothing(void) | |
189 | { | |
190 | int c; | |
191 | ||
192 | c = 23; /* Another MI breakpoint */ | |
193 | } | |
194 | ||
0cc7d26f TT |
195 | struct nullstr |
196 | { | |
197 | char *s; | |
198 | }; | |
199 | ||
200 | struct string_repr string_1 = { { "one" } }; | |
201 | struct string_repr string_2 = { { "two" } }; | |
202 | ||
a6bac58e TT |
203 | int |
204 | main () | |
205 | { | |
206 | struct ss ss; | |
207 | struct ss ssa[2]; | |
91158a56 | 208 | struct arraystruct arraystruct; |
a6bac58e TT |
209 | string x = make_string ("this is x"); |
210 | zzz_type c = make_container ("container"); | |
0cc7d26f | 211 | zzz_type c2 = make_container ("container2"); |
a6bac58e | 212 | const struct string_repr cstring = { { "const string" } }; |
0cc7d26f TT |
213 | /* Clearing by being `static' could invoke an other GDB C++ bug. */ |
214 | struct nullstr nullstr; | |
79f283fe PM |
215 | nostring_type nstype; |
216 | nstype.elements = narray; | |
217 | nstype.len = 0; | |
be759fcf | 218 | |
a6bac58e TT |
219 | init_ss(&ss, 1, 2); |
220 | init_ss(ssa+0, 3, 4); | |
221 | init_ss(ssa+1, 5, 6); | |
0cc7d26f | 222 | memset (&nullstr, 0, sizeof nullstr); |
a6bac58e | 223 | |
91158a56 TT |
224 | arraystruct.y = 7; |
225 | init_s (&arraystruct.x[0], 23); | |
226 | init_s (&arraystruct.x[1], 24); | |
227 | ||
fbb8f299 PM |
228 | struct ns ns; |
229 | ns.null_str = "embedded\0null\0string"; | |
230 | ns.length = 20; | |
231 | ||
be759fcf PM |
232 | struct lazystring estring; |
233 | estring.lazy_str = "embedded x\201\202\203\204" ; | |
234 | ||
a6bac58e TT |
235 | #ifdef __cplusplus |
236 | S cps; | |
237 | ||
238 | cps.zs = 7; | |
239 | init_s(&cps, 8); | |
240 | ||
241 | SS cpss; | |
242 | cpss.zss = 9; | |
243 | init_s(&cpss.s, 10); | |
244 | ||
245 | SS cpssa[2]; | |
246 | cpssa[0].zss = 11; | |
247 | init_s(&cpssa[0].s, 12); | |
248 | cpssa[1].zss = 13; | |
249 | init_s(&cpssa[1].s, 14); | |
250 | ||
251 | SSS sss(15, cps); | |
252 | ||
253 | SSS& ref (sss); | |
254 | ||
255 | Derived derived; | |
256 | ||
257 | #endif | |
258 | ||
259 | add_item (&c, 23); /* MI breakpoint here */ | |
260 | add_item (&c, 72); | |
261 | ||
262 | #ifdef MI | |
0cc7d26f TT |
263 | add_item (&c, 1011); |
264 | c.elements[0] = 1023; | |
265 | c.elements[0] = 2323; | |
266 | ||
267 | add_item (&c2, 2222); | |
268 | add_item (&c2, 3333); | |
269 | ||
270 | substruct_test (); | |
a6bac58e TT |
271 | do_nothing (); |
272 | #endif | |
273 | ||
79f283fe PM |
274 | nstype.elements[0] = 7; |
275 | nstype.elements[1] = 42; | |
276 | nstype.len = 2; | |
277 | ||
a6bac58e TT |
278 | return 0; /* break to inspect struct and union */ |
279 | } |