]>
Commit | Line | Data |
---|---|---|
a6bac58e TT |
1 | /* This testcase is part of GDB, the GNU debugger. |
2 | ||
d01e8234 | 3 | Copyright 2008-2025 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; | |
4ea6efe9 DE |
45 | /* If -1, don't pass length to gdb.lazy_string(). */ |
46 | int len; | |
be759fcf PM |
47 | }; |
48 | ||
e1ab1f9c JK |
49 | struct hint_error { |
50 | int x; | |
51 | }; | |
52 | ||
2c12abee TT |
53 | struct children_as_list { |
54 | int x; | |
55 | }; | |
56 | ||
a6bac58e TT |
57 | #ifdef __cplusplus |
58 | struct S : public s { | |
59 | int zs; | |
60 | }; | |
61 | ||
62 | struct SS { | |
63 | int zss; | |
64 | S s; | |
65 | }; | |
66 | ||
67 | struct SSS | |
68 | { | |
69 | SSS (int x, const S& r); | |
70 | int a; | |
71 | const S &b; | |
72 | }; | |
73 | SSS::SSS (int x, const S& r) : a(x), b(r) { } | |
74 | ||
75 | class VirtualTest | |
76 | { | |
77 | private: | |
78 | int value; | |
79 | ||
80 | public: | |
81 | VirtualTest () | |
82 | { | |
83 | value = 1; | |
84 | } | |
85 | }; | |
86 | ||
87 | class Vbase1 : public virtual VirtualTest { }; | |
88 | class Vbase2 : public virtual VirtualTest { }; | |
89 | class Vbase3 : public virtual VirtualTest { }; | |
90 | ||
91 | class Derived : public Vbase1, public Vbase2, public Vbase3 | |
92 | { | |
93 | private: | |
94 | int value; | |
95 | ||
96 | public: | |
97 | Derived () | |
98 | { | |
99 | value = 2; | |
100 | } | |
101 | }; | |
102 | ||
d65aec65 PM |
103 | class Fake |
104 | { | |
105 | int sname; | |
106 | ||
107 | public: | |
108 | Fake (const int name = 0): | |
109 | sname (name) | |
110 | { | |
111 | } | |
112 | }; | |
3c0e3120 TT |
113 | |
114 | struct has_static_member | |
115 | { | |
116 | static s global; | |
117 | }; | |
118 | ||
119 | s has_static_member::global; | |
120 | ||
a6bac58e TT |
121 | #endif |
122 | ||
0625771b LS |
123 | struct to_string_returns_value_inner |
124 | { | |
125 | int val; | |
126 | }; | |
127 | ||
128 | struct to_string_returns_value_wrapper | |
129 | { | |
130 | struct to_string_returns_value_inner inner; | |
131 | }; | |
132 | ||
0cc7d26f TT |
133 | struct substruct { |
134 | int a; | |
135 | int b; | |
136 | }; | |
137 | ||
138 | struct outerstruct { | |
139 | struct substruct s; | |
140 | int x; | |
141 | }; | |
142 | ||
143 | struct outerstruct | |
144 | substruct_test (void) | |
145 | { | |
146 | struct outerstruct outer; | |
147 | outer.s.a = 0; | |
148 | outer.s.b = 0; | |
149 | outer.x = 0; | |
150 | ||
151 | outer.s.a = 3; /* MI outer breakpoint here */ | |
152 | ||
153 | return outer; | |
154 | } | |
155 | ||
a6bac58e TT |
156 | typedef struct string_repr |
157 | { | |
158 | struct whybother | |
159 | { | |
160 | const char *contents; | |
161 | } whybother; | |
162 | } string; | |
163 | ||
164 | /* This lets us avoid malloc. */ | |
165 | int array[100]; | |
79f283fe PM |
166 | int narray[10]; |
167 | ||
168 | struct justchildren | |
169 | { | |
170 | int len; | |
171 | int *elements; | |
172 | }; | |
173 | ||
174 | typedef struct justchildren nostring_type; | |
a6bac58e | 175 | |
00bd41d6 PM |
176 | struct memory_error |
177 | { | |
178 | const char *s; | |
179 | }; | |
180 | ||
a6bac58e TT |
181 | struct container |
182 | { | |
183 | string name; | |
184 | int len; | |
185 | int *elements; | |
9f9aa852 | 186 | int is_map_p; |
b1f3973b | 187 | int is_array_p; |
a6bac58e TT |
188 | }; |
189 | ||
190 | typedef struct container zzz_type; | |
191 | ||
192 | string | |
193 | make_string (const char *s) | |
194 | { | |
195 | string result; | |
196 | result.whybother.contents = s; | |
197 | return result; | |
198 | } | |
199 | ||
200 | zzz_type | |
201 | make_container (const char *s) | |
202 | { | |
203 | zzz_type result; | |
204 | ||
205 | result.name = make_string (s); | |
206 | result.len = 0; | |
207 | result.elements = 0; | |
9f9aa852 | 208 | result.is_map_p = 0; |
b1f3973b | 209 | result.is_array_p = 0; |
a6bac58e TT |
210 | |
211 | return result; | |
212 | } | |
213 | ||
214 | void | |
215 | add_item (zzz_type *c, int val) | |
216 | { | |
217 | if (c->len == 0) | |
218 | c->elements = array; | |
219 | c->elements[c->len] = val; | |
220 | ++c->len; | |
221 | } | |
222 | ||
731145cb TT |
223 | void |
224 | set_item(zzz_type *c, int i, int val) | |
225 | { | |
226 | if (i < c->len) | |
227 | c->elements[i] = val; | |
228 | } | |
229 | ||
a6bac58e TT |
230 | void init_s(struct s *s, int a) |
231 | { | |
232 | s->a = a; | |
233 | s->b = &s->a; | |
234 | } | |
235 | ||
236 | void init_ss(struct ss *s, int a, int b) | |
237 | { | |
238 | init_s(&s->a, a); | |
239 | init_s(&s->b, b); | |
240 | } | |
241 | ||
242 | void do_nothing(void) | |
243 | { | |
244 | int c; | |
245 | ||
246 | c = 23; /* Another MI breakpoint */ | |
247 | } | |
248 | ||
0cc7d26f TT |
249 | struct nullstr |
250 | { | |
251 | char *s; | |
252 | }; | |
253 | ||
254 | struct string_repr string_1 = { { "one" } }; | |
255 | struct string_repr string_2 = { { "two" } }; | |
256 | ||
2abc3f8d | 257 | int |
8f043999 JK |
258 | eval_func (int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8) |
259 | { | |
260 | return p1; | |
261 | } | |
262 | ||
263 | static void | |
264 | eval_sub (void) | |
265 | { | |
266 | struct eval_type_s { int x; } eval1 = { 1 }, eval2 = { 2 }, eval3 = { 3 }, | |
267 | eval4 = { 4 }, eval5 = { 5 }, eval6 = { 6 }, | |
268 | eval7 = { 7 }, eval8 = { 8 }, eval9 = { 9 }; | |
269 | ||
270 | eval1.x++; /* eval-break */ | |
271 | } | |
272 | ||
731145cb TT |
273 | static void |
274 | bug_14741() | |
275 | { | |
276 | zzz_type c = make_container ("bug_14741"); | |
277 | add_item (&c, 71); | |
278 | set_item(&c, 0, 42); /* breakpoint bug 14741 */ | |
279 | set_item(&c, 0, 5); | |
280 | } | |
281 | ||
c973d0aa PA |
282 | /* Some typedefs/variables for checking that GDB doesn't lose typedefs |
283 | when looking for a printer. */ | |
284 | typedef int int_type; | |
285 | typedef int_type int_type2; | |
332cf4c9 | 286 | typedef int_type int_type3; |
c973d0aa PA |
287 | |
288 | int an_int = -1; | |
289 | int_type an_int_type = 1; | |
290 | int_type2 an_int_type2 = 2; | |
332cf4c9 | 291 | int_type3 an_int_type3 = 3; |
c973d0aa | 292 | |
a6bac58e TT |
293 | int |
294 | main () | |
295 | { | |
296 | struct ss ss; | |
297 | struct ss ssa[2]; | |
91158a56 | 298 | struct arraystruct arraystruct; |
a6bac58e TT |
299 | string x = make_string ("this is x"); |
300 | zzz_type c = make_container ("container"); | |
0cc7d26f | 301 | zzz_type c2 = make_container ("container2"); |
a6bac58e | 302 | const struct string_repr cstring = { { "const string" } }; |
0cc7d26f TT |
303 | /* Clearing by being `static' could invoke an other GDB C++ bug. */ |
304 | struct nullstr nullstr; | |
a4c8e806 | 305 | nostring_type nstype, nstype2; |
00bd41d6 | 306 | struct memory_error me; |
621c8364 | 307 | struct ns ns, ns2; |
4ea6efe9 | 308 | struct lazystring estring, estring2, estring3; |
e1ab1f9c | 309 | struct hint_error hint_error; |
2c12abee | 310 | struct children_as_list children_as_list; |
0625771b | 311 | struct to_string_returns_value_wrapper tsrvw = { { 1989 } }; |
3a772aa4 | 312 | |
79f283fe PM |
313 | nstype.elements = narray; |
314 | nstype.len = 0; | |
be759fcf | 315 | |
00bd41d6 PM |
316 | me.s = "blah"; |
317 | ||
a6bac58e TT |
318 | init_ss(&ss, 1, 2); |
319 | init_ss(ssa+0, 3, 4); | |
320 | init_ss(ssa+1, 5, 6); | |
0cc7d26f | 321 | memset (&nullstr, 0, sizeof nullstr); |
a6bac58e | 322 | |
91158a56 TT |
323 | arraystruct.y = 7; |
324 | init_s (&arraystruct.x[0], 23); | |
325 | init_s (&arraystruct.x[1], 24); | |
326 | ||
fbb8f299 PM |
327 | ns.null_str = "embedded\0null\0string"; |
328 | ns.length = 20; | |
329 | ||
621c8364 TT |
330 | /* Make a "corrupted" string. */ |
331 | ns2.null_str = NULL; | |
332 | ns2.length = 20; | |
333 | ||
4ea6efe9 DE |
334 | estring.lazy_str = "embedded x\201\202\203\204"; |
335 | estring.len = -1; | |
be759fcf | 336 | |
3a772aa4 TT |
337 | /* Incomplete UTF-8, but ok Latin-1. */ |
338 | estring2.lazy_str = "embedded x\302"; | |
4ea6efe9 DE |
339 | estring2.len = -1; |
340 | ||
341 | estring3.lazy_str = NULL; | |
342 | estring3.len = 42; | |
3a772aa4 | 343 | |
a6bac58e TT |
344 | #ifdef __cplusplus |
345 | S cps; | |
346 | ||
347 | cps.zs = 7; | |
348 | init_s(&cps, 8); | |
349 | ||
350 | SS cpss; | |
351 | cpss.zss = 9; | |
352 | init_s(&cpss.s, 10); | |
353 | ||
354 | SS cpssa[2]; | |
355 | cpssa[0].zss = 11; | |
356 | init_s(&cpssa[0].s, 12); | |
357 | cpssa[1].zss = 13; | |
358 | init_s(&cpssa[1].s, 14); | |
359 | ||
360 | SSS sss(15, cps); | |
361 | ||
362 | SSS& ref (sss); | |
363 | ||
364 | Derived derived; | |
365 | ||
d65aec65 | 366 | Fake fake (42); |
3c0e3120 TT |
367 | |
368 | init_s (&has_static_member::global, 23); | |
369 | has_static_member has_member; | |
a6bac58e TT |
370 | #endif |
371 | ||
372 | add_item (&c, 23); /* MI breakpoint here */ | |
373 | add_item (&c, 72); | |
374 | ||
375 | #ifdef MI | |
0cc7d26f TT |
376 | add_item (&c, 1011); |
377 | c.elements[0] = 1023; | |
378 | c.elements[0] = 2323; | |
379 | ||
380 | add_item (&c2, 2222); | |
381 | add_item (&c2, 3333); | |
382 | ||
383 | substruct_test (); | |
a6bac58e TT |
384 | do_nothing (); |
385 | #endif | |
386 | ||
79f283fe PM |
387 | nstype.elements[0] = 7; |
388 | nstype.elements[1] = 42; | |
389 | nstype.len = 2; | |
390 | ||
a4c8e806 TT |
391 | nstype2 = nstype; |
392 | ||
8f043999 JK |
393 | eval_sub (); |
394 | ||
731145cb TT |
395 | bug_14741(); /* break to inspect struct and union */ |
396 | return 0; | |
a6bac58e | 397 | } |