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
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
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
a6bac58e
TT
47#ifdef __cplusplus
48struct S : public s {
49 int zs;
50};
51
52struct SS {
53 int zss;
54 S s;
55};
56
57struct SSS
58{
59 SSS (int x, const S& r);
60 int a;
61 const S &b;
62};
63SSS::SSS (int x, const S& r) : a(x), b(r) { }
64
65class VirtualTest
66{
67 private:
68 int value;
69
70 public:
71 VirtualTest ()
72 {
73 value = 1;
74 }
75};
76
77class Vbase1 : public virtual VirtualTest { };
78class Vbase2 : public virtual VirtualTest { };
79class Vbase3 : public virtual VirtualTest { };
80
81class 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
95struct substruct {
96 int a;
97 int b;
98};
99
100struct outerstruct {
101 struct substruct s;
102 int x;
103};
104
105struct outerstruct
106substruct_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
118typedef struct string_repr
119{
120 struct whybother
121 {
122 const char *contents;
123 } whybother;
124} string;
125
126/* This lets us avoid malloc. */
127int array[100];
79f283fe
PM
128int narray[10];
129
130struct justchildren
131{
132 int len;
133 int *elements;
134};
135
136typedef struct justchildren nostring_type;
a6bac58e
TT
137
138struct container
139{
140 string name;
141 int len;
142 int *elements;
143};
144
145typedef struct container zzz_type;
146
147string
148make_string (const char *s)
149{
150 string result;
151 result.whybother.contents = s;
152 return result;
153}
154
155zzz_type
156make_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
167void
168add_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
176void init_s(struct s *s, int a)
177{
178 s->a = a;
179 s->b = &s->a;
180}
181
182void init_ss(struct ss *s, int a, int b)
183{
184 init_s(&s->a, a);
185 init_s(&s->b, b);
186}
187
188void do_nothing(void)
189{
190 int c;
191
192 c = 23; /* Another MI breakpoint */
193}
194
0cc7d26f
TT
195struct nullstr
196{
197 char *s;
198};
199
200struct string_repr string_1 = { { "one" } };
201struct string_repr string_2 = { { "two" } };
202
a6bac58e
TT
203int
204main ()
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 215 nostring_type nstype;
621c8364 216 struct ns ns, ns2;
3a772aa4
TT
217 struct lazystring estring, estring2;
218
79f283fe
PM
219 nstype.elements = narray;
220 nstype.len = 0;
be759fcf 221
a6bac58e
TT
222 init_ss(&ss, 1, 2);
223 init_ss(ssa+0, 3, 4);
224 init_ss(ssa+1, 5, 6);
0cc7d26f 225 memset (&nullstr, 0, sizeof nullstr);
a6bac58e 226
91158a56
TT
227 arraystruct.y = 7;
228 init_s (&arraystruct.x[0], 23);
229 init_s (&arraystruct.x[1], 24);
230
fbb8f299
PM
231 ns.null_str = "embedded\0null\0string";
232 ns.length = 20;
233
621c8364
TT
234 /* Make a "corrupted" string. */
235 ns2.null_str = NULL;
236 ns2.length = 20;
237
be759fcf
PM
238 estring.lazy_str = "embedded x\201\202\203\204" ;
239
3a772aa4
TT
240 /* Incomplete UTF-8, but ok Latin-1. */
241 estring2.lazy_str = "embedded x\302";
242
a6bac58e
TT
243#ifdef __cplusplus
244 S cps;
245
246 cps.zs = 7;
247 init_s(&cps, 8);
248
249 SS cpss;
250 cpss.zss = 9;
251 init_s(&cpss.s, 10);
252
253 SS cpssa[2];
254 cpssa[0].zss = 11;
255 init_s(&cpssa[0].s, 12);
256 cpssa[1].zss = 13;
257 init_s(&cpssa[1].s, 14);
258
259 SSS sss(15, cps);
260
261 SSS& ref (sss);
262
263 Derived derived;
264
265#endif
266
267 add_item (&c, 23); /* MI breakpoint here */
268 add_item (&c, 72);
269
270#ifdef MI
0cc7d26f
TT
271 add_item (&c, 1011);
272 c.elements[0] = 1023;
273 c.elements[0] = 2323;
274
275 add_item (&c2, 2222);
276 add_item (&c2, 3333);
277
278 substruct_test ();
a6bac58e
TT
279 do_nothing ();
280#endif
281
79f283fe
PM
282 nstype.elements[0] = 7;
283 nstype.elements[1] = 42;
284 nstype.len = 2;
285
a6bac58e
TT
286 return 0; /* break to inspect struct and union */
287}
This page took 0.196557 seconds and 4 git commands to generate.