Fix build failure in inf-ptrace.c.
[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
3 Copyright 2008, 2009 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
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
fbb8f299
PM
32struct ns {
33 const char *null_str;
34 int length;
35};
36
a6bac58e
TT
37#ifdef __cplusplus
38struct S : public s {
39 int zs;
40};
41
42struct SS {
43 int zss;
44 S s;
45};
46
47struct SSS
48{
49 SSS (int x, const S& r);
50 int a;
51 const S &b;
52};
53SSS::SSS (int x, const S& r) : a(x), b(r) { }
54
55class VirtualTest
56{
57 private:
58 int value;
59
60 public:
61 VirtualTest ()
62 {
63 value = 1;
64 }
65};
66
67class Vbase1 : public virtual VirtualTest { };
68class Vbase2 : public virtual VirtualTest { };
69class Vbase3 : public virtual VirtualTest { };
70
71class Derived : public Vbase1, public Vbase2, public Vbase3
72{
73 private:
74 int value;
75
76 public:
77 Derived ()
78 {
79 value = 2;
80 }
81};
82
83#endif
84
0cc7d26f
TT
85struct substruct {
86 int a;
87 int b;
88};
89
90struct outerstruct {
91 struct substruct s;
92 int x;
93};
94
95struct outerstruct
96substruct_test (void)
97{
98 struct outerstruct outer;
99 outer.s.a = 0;
100 outer.s.b = 0;
101 outer.x = 0;
102
103 outer.s.a = 3; /* MI outer breakpoint here */
104
105 return outer;
106}
107
a6bac58e
TT
108typedef struct string_repr
109{
110 struct whybother
111 {
112 const char *contents;
113 } whybother;
114} string;
115
116/* This lets us avoid malloc. */
117int array[100];
118
119struct container
120{
121 string name;
122 int len;
123 int *elements;
124};
125
126typedef struct container zzz_type;
127
128string
129make_string (const char *s)
130{
131 string result;
132 result.whybother.contents = s;
133 return result;
134}
135
136zzz_type
137make_container (const char *s)
138{
139 zzz_type result;
140
141 result.name = make_string (s);
142 result.len = 0;
143 result.elements = 0;
144
145 return result;
146}
147
148void
149add_item (zzz_type *c, int val)
150{
151 if (c->len == 0)
152 c->elements = array;
153 c->elements[c->len] = val;
154 ++c->len;
155}
156
157void init_s(struct s *s, int a)
158{
159 s->a = a;
160 s->b = &s->a;
161}
162
163void init_ss(struct ss *s, int a, int b)
164{
165 init_s(&s->a, a);
166 init_s(&s->b, b);
167}
168
169void do_nothing(void)
170{
171 int c;
172
173 c = 23; /* Another MI breakpoint */
174}
175
0cc7d26f
TT
176struct nullstr
177{
178 char *s;
179};
180
181struct string_repr string_1 = { { "one" } };
182struct string_repr string_2 = { { "two" } };
183
a6bac58e
TT
184int
185main ()
186{
187 struct ss ss;
188 struct ss ssa[2];
189 string x = make_string ("this is x");
190 zzz_type c = make_container ("container");
0cc7d26f 191 zzz_type c2 = make_container ("container2");
a6bac58e 192 const struct string_repr cstring = { { "const string" } };
0cc7d26f
TT
193 /* Clearing by being `static' could invoke an other GDB C++ bug. */
194 struct nullstr nullstr;
a6bac58e
TT
195
196 init_ss(&ss, 1, 2);
197 init_ss(ssa+0, 3, 4);
198 init_ss(ssa+1, 5, 6);
0cc7d26f 199 memset (&nullstr, 0, sizeof nullstr);
a6bac58e 200
fbb8f299
PM
201 struct ns ns;
202 ns.null_str = "embedded\0null\0string";
203 ns.length = 20;
204
a6bac58e
TT
205#ifdef __cplusplus
206 S cps;
207
208 cps.zs = 7;
209 init_s(&cps, 8);
210
211 SS cpss;
212 cpss.zss = 9;
213 init_s(&cpss.s, 10);
214
215 SS cpssa[2];
216 cpssa[0].zss = 11;
217 init_s(&cpssa[0].s, 12);
218 cpssa[1].zss = 13;
219 init_s(&cpssa[1].s, 14);
220
221 SSS sss(15, cps);
222
223 SSS& ref (sss);
224
225 Derived derived;
226
227#endif
228
229 add_item (&c, 23); /* MI breakpoint here */
230 add_item (&c, 72);
231
232#ifdef MI
0cc7d26f
TT
233 add_item (&c, 1011);
234 c.elements[0] = 1023;
235 c.elements[0] = 2323;
236
237 add_item (&c2, 2222);
238 add_item (&c2, 3333);
239
240 substruct_test ();
a6bac58e
TT
241 do_nothing ();
242#endif
243
244 return 0; /* break to inspect struct and union */
245}
This page took 0.092536 seconds and 4 git commands to generate.