gdb/
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-prettyprint.c
CommitLineData
a6bac58e
TT
1/* This testcase is part of GDB, the GNU debugger.
2
c5a57081 3 Copyright 2008-2012 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
20struct s
21{
22 int a;
23 int *b;
24};
25
26struct ss
27{
28 struct s a;
29 struct s b;
30};
31
91158a56
TT
32struct arraystruct
33{
34 int y;
35 struct s x[2];
36};
37
fbb8f299
PM
38struct ns {
39 const char *null_str;
40 int length;
41};
42
be759fcf
PM
43struct lazystring {
44 const char *lazy_str;
45};
46
e1ab1f9c
JK
47struct hint_error {
48 int x;
49};
50
a6bac58e
TT
51#ifdef __cplusplus
52struct S : public s {
53 int zs;
54};
55
56struct SS {
57 int zss;
58 S s;
59};
60
61struct SSS
62{
63 SSS (int x, const S& r);
64 int a;
65 const S &b;
66};
67SSS::SSS (int x, const S& r) : a(x), b(r) { }
68
69class VirtualTest
70{
71 private:
72 int value;
73
74 public:
75 VirtualTest ()
76 {
77 value = 1;
78 }
79};
80
81class Vbase1 : public virtual VirtualTest { };
82class Vbase2 : public virtual VirtualTest { };
83class Vbase3 : public virtual VirtualTest { };
84
85class 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
97class 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
109struct substruct {
110 int a;
111 int b;
112};
113
114struct outerstruct {
115 struct substruct s;
116 int x;
117};
118
119struct outerstruct
120substruct_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
132typedef struct string_repr
133{
134 struct whybother
135 {
136 const char *contents;
137 } whybother;
138} string;
139
140/* This lets us avoid malloc. */
141int array[100];
79f283fe
PM
142int narray[10];
143
144struct justchildren
145{
146 int len;
147 int *elements;
148};
149
150typedef struct justchildren nostring_type;
a6bac58e 151
00bd41d6
PM
152struct memory_error
153{
154 const char *s;
155};
156
a6bac58e
TT
157struct container
158{
159 string name;
160 int len;
161 int *elements;
162};
163
164typedef struct container zzz_type;
165
166string
167make_string (const char *s)
168{
169 string result;
170 result.whybother.contents = s;
171 return result;
172}
173
174zzz_type
175make_container (const char *s)
176{
177 zzz_type result;
178
179 result.name = make_string (s);
180 result.len = 0;
181 result.elements = 0;
182
183 return result;
184}
185
186void
187add_item (zzz_type *c, int val)
188{
189 if (c->len == 0)
190 c->elements = array;
191 c->elements[c->len] = val;
192 ++c->len;
193}
194
195void init_s(struct s *s, int a)
196{
197 s->a = a;
198 s->b = &s->a;
199}
200
201void init_ss(struct ss *s, int a, int b)
202{
203 init_s(&s->a, a);
204 init_s(&s->b, b);
205}
206
207void do_nothing(void)
208{
209 int c;
210
211 c = 23; /* Another MI breakpoint */
212}
213
0cc7d26f
TT
214struct nullstr
215{
216 char *s;
217};
218
219struct string_repr string_1 = { { "one" } };
220struct string_repr string_2 = { { "two" } };
221
8f043999
JK
222static int
223eval_func (int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8)
224{
225 return p1;
226}
227
228static void
229eval_sub (void)
230{
231 struct eval_type_s { int x; } eval1 = { 1 }, eval2 = { 2 }, eval3 = { 3 },
232 eval4 = { 4 }, eval5 = { 5 }, eval6 = { 6 },
233 eval7 = { 7 }, eval8 = { 8 }, eval9 = { 9 };
234
235 eval1.x++; /* eval-break */
236}
237
a6bac58e
TT
238int
239main ()
240{
241 struct ss ss;
242 struct ss ssa[2];
91158a56 243 struct arraystruct arraystruct;
a6bac58e
TT
244 string x = make_string ("this is x");
245 zzz_type c = make_container ("container");
0cc7d26f 246 zzz_type c2 = make_container ("container2");
a6bac58e 247 const struct string_repr cstring = { { "const string" } };
0cc7d26f
TT
248 /* Clearing by being `static' could invoke an other GDB C++ bug. */
249 struct nullstr nullstr;
a4c8e806 250 nostring_type nstype, nstype2;
00bd41d6 251 struct memory_error me;
621c8364 252 struct ns ns, ns2;
3a772aa4 253 struct lazystring estring, estring2;
e1ab1f9c 254 struct hint_error hint_error;
3a772aa4 255
79f283fe
PM
256 nstype.elements = narray;
257 nstype.len = 0;
be759fcf 258
00bd41d6
PM
259 me.s = "blah";
260
a6bac58e
TT
261 init_ss(&ss, 1, 2);
262 init_ss(ssa+0, 3, 4);
263 init_ss(ssa+1, 5, 6);
0cc7d26f 264 memset (&nullstr, 0, sizeof nullstr);
a6bac58e 265
91158a56
TT
266 arraystruct.y = 7;
267 init_s (&arraystruct.x[0], 23);
268 init_s (&arraystruct.x[1], 24);
269
fbb8f299
PM
270 ns.null_str = "embedded\0null\0string";
271 ns.length = 20;
272
621c8364
TT
273 /* Make a "corrupted" string. */
274 ns2.null_str = NULL;
275 ns2.length = 20;
276
be759fcf
PM
277 estring.lazy_str = "embedded x\201\202\203\204" ;
278
3a772aa4
TT
279 /* Incomplete UTF-8, but ok Latin-1. */
280 estring2.lazy_str = "embedded x\302";
281
a6bac58e
TT
282#ifdef __cplusplus
283 S cps;
284
285 cps.zs = 7;
286 init_s(&cps, 8);
287
288 SS cpss;
289 cpss.zss = 9;
290 init_s(&cpss.s, 10);
291
292 SS cpssa[2];
293 cpssa[0].zss = 11;
294 init_s(&cpssa[0].s, 12);
295 cpssa[1].zss = 13;
296 init_s(&cpssa[1].s, 14);
297
298 SSS sss(15, cps);
299
300 SSS& ref (sss);
301
302 Derived derived;
303
d65aec65 304 Fake fake (42);
a6bac58e
TT
305#endif
306
307 add_item (&c, 23); /* MI breakpoint here */
308 add_item (&c, 72);
309
310#ifdef MI
0cc7d26f
TT
311 add_item (&c, 1011);
312 c.elements[0] = 1023;
313 c.elements[0] = 2323;
314
315 add_item (&c2, 2222);
316 add_item (&c2, 3333);
317
318 substruct_test ();
a6bac58e
TT
319 do_nothing ();
320#endif
321
79f283fe
PM
322 nstype.elements[0] = 7;
323 nstype.elements[1] = 42;
324 nstype.len = 2;
325
a4c8e806
TT
326 nstype2 = nstype;
327
8f043999
JK
328 eval_sub ();
329
a6bac58e
TT
330 return 0; /* break to inspect struct and union */
331}
This page took 0.636791 seconds and 4 git commands to generate.