2011-07-28 Phil Muldoon <pmuldoon@redhat.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-prettyprint.c
1 /* This testcase is part of GDB, the GNU debugger.
2
3 Copyright 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
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
18 #include <string.h>
19
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
32 struct arraystruct
33 {
34 int y;
35 struct s x[2];
36 };
37
38 struct ns {
39 const char *null_str;
40 int length;
41 };
42
43 struct lazystring {
44 const char *lazy_str;
45 };
46
47 struct hint_error {
48 int x;
49 };
50
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
97 class Fake
98 {
99 int sname;
100
101 public:
102 Fake (const int name = 0):
103 sname (name)
104 {
105 }
106 };
107 #endif
108
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
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];
142 int narray[10];
143
144 struct justchildren
145 {
146 int len;
147 int *elements;
148 };
149
150 typedef struct justchildren nostring_type;
151
152 struct memory_error
153 {
154 const char *s;
155 };
156
157 struct container
158 {
159 string name;
160 int len;
161 int *elements;
162 };
163
164 typedef struct container zzz_type;
165
166 string
167 make_string (const char *s)
168 {
169 string result;
170 result.whybother.contents = s;
171 return result;
172 }
173
174 zzz_type
175 make_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
186 void
187 add_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
195 void init_s(struct s *s, int a)
196 {
197 s->a = a;
198 s->b = &s->a;
199 }
200
201 void init_ss(struct ss *s, int a, int b)
202 {
203 init_s(&s->a, a);
204 init_s(&s->b, b);
205 }
206
207 void do_nothing(void)
208 {
209 int c;
210
211 c = 23; /* Another MI breakpoint */
212 }
213
214 struct nullstr
215 {
216 char *s;
217 };
218
219 struct string_repr string_1 = { { "one" } };
220 struct string_repr string_2 = { { "two" } };
221
222 int
223 main ()
224 {
225 struct ss ss;
226 struct ss ssa[2];
227 struct arraystruct arraystruct;
228 string x = make_string ("this is x");
229 zzz_type c = make_container ("container");
230 zzz_type c2 = make_container ("container2");
231 const struct string_repr cstring = { { "const string" } };
232 /* Clearing by being `static' could invoke an other GDB C++ bug. */
233 struct nullstr nullstr;
234 nostring_type nstype, nstype2;
235 struct memory_error me;
236 struct ns ns, ns2;
237 struct lazystring estring, estring2;
238 struct hint_error hint_error;
239
240 nstype.elements = narray;
241 nstype.len = 0;
242
243 me.s = "blah";
244
245 init_ss(&ss, 1, 2);
246 init_ss(ssa+0, 3, 4);
247 init_ss(ssa+1, 5, 6);
248 memset (&nullstr, 0, sizeof nullstr);
249
250 arraystruct.y = 7;
251 init_s (&arraystruct.x[0], 23);
252 init_s (&arraystruct.x[1], 24);
253
254 ns.null_str = "embedded\0null\0string";
255 ns.length = 20;
256
257 /* Make a "corrupted" string. */
258 ns2.null_str = NULL;
259 ns2.length = 20;
260
261 estring.lazy_str = "embedded x\201\202\203\204" ;
262
263 /* Incomplete UTF-8, but ok Latin-1. */
264 estring2.lazy_str = "embedded x\302";
265
266 #ifdef __cplusplus
267 S cps;
268
269 cps.zs = 7;
270 init_s(&cps, 8);
271
272 SS cpss;
273 cpss.zss = 9;
274 init_s(&cpss.s, 10);
275
276 SS cpssa[2];
277 cpssa[0].zss = 11;
278 init_s(&cpssa[0].s, 12);
279 cpssa[1].zss = 13;
280 init_s(&cpssa[1].s, 14);
281
282 SSS sss(15, cps);
283
284 SSS& ref (sss);
285
286 Derived derived;
287
288 Fake fake (42);
289 #endif
290
291 add_item (&c, 23); /* MI breakpoint here */
292 add_item (&c, 72);
293
294 #ifdef MI
295 add_item (&c, 1011);
296 c.elements[0] = 1023;
297 c.elements[0] = 2323;
298
299 add_item (&c2, 2222);
300 add_item (&c2, 3333);
301
302 substruct_test ();
303 do_nothing ();
304 #endif
305
306 nstype.elements[0] = 7;
307 nstype.elements[1] = 42;
308 nstype.len = 2;
309
310 nstype2 = nstype;
311
312 return 0; /* break to inspect struct and union */
313 }
This page took 0.038242 seconds and 5 git commands to generate.