Update copyright year in most headers.
[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 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 ns {
33 const char *null_str;
34 int length;
35 };
36
37 #ifdef __cplusplus
38 struct S : public s {
39 int zs;
40 };
41
42 struct SS {
43 int zss;
44 S s;
45 };
46
47 struct SSS
48 {
49 SSS (int x, const S& r);
50 int a;
51 const S &b;
52 };
53 SSS::SSS (int x, const S& r) : a(x), b(r) { }
54
55 class VirtualTest
56 {
57 private:
58 int value;
59
60 public:
61 VirtualTest ()
62 {
63 value = 1;
64 }
65 };
66
67 class Vbase1 : public virtual VirtualTest { };
68 class Vbase2 : public virtual VirtualTest { };
69 class Vbase3 : public virtual VirtualTest { };
70
71 class 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
85 struct substruct {
86 int a;
87 int b;
88 };
89
90 struct outerstruct {
91 struct substruct s;
92 int x;
93 };
94
95 struct outerstruct
96 substruct_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
108 typedef struct string_repr
109 {
110 struct whybother
111 {
112 const char *contents;
113 } whybother;
114 } string;
115
116 /* This lets us avoid malloc. */
117 int array[100];
118
119 struct container
120 {
121 string name;
122 int len;
123 int *elements;
124 };
125
126 typedef struct container zzz_type;
127
128 string
129 make_string (const char *s)
130 {
131 string result;
132 result.whybother.contents = s;
133 return result;
134 }
135
136 zzz_type
137 make_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
148 void
149 add_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
157 void init_s(struct s *s, int a)
158 {
159 s->a = a;
160 s->b = &s->a;
161 }
162
163 void init_ss(struct ss *s, int a, int b)
164 {
165 init_s(&s->a, a);
166 init_s(&s->b, b);
167 }
168
169 void do_nothing(void)
170 {
171 int c;
172
173 c = 23; /* Another MI breakpoint */
174 }
175
176 struct nullstr
177 {
178 char *s;
179 };
180
181 struct string_repr string_1 = { { "one" } };
182 struct string_repr string_2 = { { "two" } };
183
184 int
185 main ()
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");
191 zzz_type c2 = make_container ("container2");
192 const struct string_repr cstring = { { "const string" } };
193 /* Clearing by being `static' could invoke an other GDB C++ bug. */
194 struct nullstr nullstr;
195
196 init_ss(&ss, 1, 2);
197 init_ss(ssa+0, 3, 4);
198 init_ss(ssa+1, 5, 6);
199 memset (&nullstr, 0, sizeof nullstr);
200
201 struct ns ns;
202 ns.null_str = "embedded\0null\0string";
203 ns.length = 20;
204
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
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 ();
241 do_nothing ();
242 #endif
243
244 return 0; /* break to inspect struct and union */
245 }
This page took 0.035415 seconds and 4 git commands to generate.