gdb/testsuite/
[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 #endif
98
99 struct substruct {
100 int a;
101 int b;
102 };
103
104 struct outerstruct {
105 struct substruct s;
106 int x;
107 };
108
109 struct outerstruct
110 substruct_test (void)
111 {
112 struct outerstruct outer;
113 outer.s.a = 0;
114 outer.s.b = 0;
115 outer.x = 0;
116
117 outer.s.a = 3; /* MI outer breakpoint here */
118
119 return outer;
120 }
121
122 typedef struct string_repr
123 {
124 struct whybother
125 {
126 const char *contents;
127 } whybother;
128 } string;
129
130 /* This lets us avoid malloc. */
131 int array[100];
132 int narray[10];
133
134 struct justchildren
135 {
136 int len;
137 int *elements;
138 };
139
140 typedef struct justchildren nostring_type;
141
142 struct container
143 {
144 string name;
145 int len;
146 int *elements;
147 };
148
149 typedef struct container zzz_type;
150
151 string
152 make_string (const char *s)
153 {
154 string result;
155 result.whybother.contents = s;
156 return result;
157 }
158
159 zzz_type
160 make_container (const char *s)
161 {
162 zzz_type result;
163
164 result.name = make_string (s);
165 result.len = 0;
166 result.elements = 0;
167
168 return result;
169 }
170
171 void
172 add_item (zzz_type *c, int val)
173 {
174 if (c->len == 0)
175 c->elements = array;
176 c->elements[c->len] = val;
177 ++c->len;
178 }
179
180 void init_s(struct s *s, int a)
181 {
182 s->a = a;
183 s->b = &s->a;
184 }
185
186 void init_ss(struct ss *s, int a, int b)
187 {
188 init_s(&s->a, a);
189 init_s(&s->b, b);
190 }
191
192 void do_nothing(void)
193 {
194 int c;
195
196 c = 23; /* Another MI breakpoint */
197 }
198
199 struct nullstr
200 {
201 char *s;
202 };
203
204 struct string_repr string_1 = { { "one" } };
205 struct string_repr string_2 = { { "two" } };
206
207 int
208 main ()
209 {
210 struct ss ss;
211 struct ss ssa[2];
212 struct arraystruct arraystruct;
213 string x = make_string ("this is x");
214 zzz_type c = make_container ("container");
215 zzz_type c2 = make_container ("container2");
216 const struct string_repr cstring = { { "const string" } };
217 /* Clearing by being `static' could invoke an other GDB C++ bug. */
218 struct nullstr nullstr;
219 nostring_type nstype, nstype2;
220 struct ns ns, ns2;
221 struct lazystring estring, estring2;
222 struct hint_error hint_error;
223
224 nstype.elements = narray;
225 nstype.len = 0;
226
227 init_ss(&ss, 1, 2);
228 init_ss(ssa+0, 3, 4);
229 init_ss(ssa+1, 5, 6);
230 memset (&nullstr, 0, sizeof nullstr);
231
232 arraystruct.y = 7;
233 init_s (&arraystruct.x[0], 23);
234 init_s (&arraystruct.x[1], 24);
235
236 ns.null_str = "embedded\0null\0string";
237 ns.length = 20;
238
239 /* Make a "corrupted" string. */
240 ns2.null_str = NULL;
241 ns2.length = 20;
242
243 estring.lazy_str = "embedded x\201\202\203\204" ;
244
245 /* Incomplete UTF-8, but ok Latin-1. */
246 estring2.lazy_str = "embedded x\302";
247
248 #ifdef __cplusplus
249 S cps;
250
251 cps.zs = 7;
252 init_s(&cps, 8);
253
254 SS cpss;
255 cpss.zss = 9;
256 init_s(&cpss.s, 10);
257
258 SS cpssa[2];
259 cpssa[0].zss = 11;
260 init_s(&cpssa[0].s, 12);
261 cpssa[1].zss = 13;
262 init_s(&cpssa[1].s, 14);
263
264 SSS sss(15, cps);
265
266 SSS& ref (sss);
267
268 Derived derived;
269
270 #endif
271
272 add_item (&c, 23); /* MI breakpoint here */
273 add_item (&c, 72);
274
275 #ifdef MI
276 add_item (&c, 1011);
277 c.elements[0] = 1023;
278 c.elements[0] = 2323;
279
280 add_item (&c2, 2222);
281 add_item (&c2, 3333);
282
283 substruct_test ();
284 do_nothing ();
285 #endif
286
287 nstype.elements[0] = 7;
288 nstype.elements[1] = 42;
289 nstype.len = 2;
290
291 nstype2 = nstype;
292
293 return 0; /* break to inspect struct and union */
294 }
This page took 0.037696 seconds and 5 git commands to generate.