Add "info connections" command, "info inferiors" connection number/string
[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
b811d2c2 3 Copyright 2008-2020 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;
4ea6efe9
DE
45 /* If -1, don't pass length to gdb.lazy_string(). */
46 int len;
be759fcf
PM
47};
48
e1ab1f9c
JK
49struct hint_error {
50 int x;
51};
52
2c12abee
TT
53struct children_as_list {
54 int x;
55};
56
a6bac58e
TT
57#ifdef __cplusplus
58struct S : public s {
59 int zs;
60};
61
62struct SS {
63 int zss;
64 S s;
65};
66
67struct SSS
68{
69 SSS (int x, const S& r);
70 int a;
71 const S &b;
72};
73SSS::SSS (int x, const S& r) : a(x), b(r) { }
74
75class VirtualTest
76{
77 private:
78 int value;
79
80 public:
81 VirtualTest ()
82 {
83 value = 1;
84 }
85};
86
87class Vbase1 : public virtual VirtualTest { };
88class Vbase2 : public virtual VirtualTest { };
89class Vbase3 : public virtual VirtualTest { };
90
91class Derived : public Vbase1, public Vbase2, public Vbase3
92{
93 private:
94 int value;
95
96 public:
97 Derived ()
98 {
99 value = 2;
100 }
101};
102
d65aec65
PM
103class Fake
104{
105 int sname;
106
107 public:
108 Fake (const int name = 0):
109 sname (name)
110 {
111 }
112};
a6bac58e
TT
113#endif
114
0625771b
LS
115struct to_string_returns_value_inner
116{
117 int val;
118};
119
120struct to_string_returns_value_wrapper
121{
122 struct to_string_returns_value_inner inner;
123};
124
0cc7d26f
TT
125struct substruct {
126 int a;
127 int b;
128};
129
130struct outerstruct {
131 struct substruct s;
132 int x;
133};
134
135struct outerstruct
136substruct_test (void)
137{
138 struct outerstruct outer;
139 outer.s.a = 0;
140 outer.s.b = 0;
141 outer.x = 0;
142
143 outer.s.a = 3; /* MI outer breakpoint here */
144
145 return outer;
146}
147
a6bac58e
TT
148typedef struct string_repr
149{
150 struct whybother
151 {
152 const char *contents;
153 } whybother;
154} string;
155
156/* This lets us avoid malloc. */
157int array[100];
79f283fe
PM
158int narray[10];
159
160struct justchildren
161{
162 int len;
163 int *elements;
164};
165
166typedef struct justchildren nostring_type;
a6bac58e 167
00bd41d6
PM
168struct memory_error
169{
170 const char *s;
171};
172
a6bac58e
TT
173struct container
174{
175 string name;
176 int len;
177 int *elements;
9f9aa852 178 int is_map_p;
a6bac58e
TT
179};
180
181typedef struct container zzz_type;
182
183string
184make_string (const char *s)
185{
186 string result;
187 result.whybother.contents = s;
188 return result;
189}
190
191zzz_type
192make_container (const char *s)
193{
194 zzz_type result;
195
196 result.name = make_string (s);
197 result.len = 0;
198 result.elements = 0;
9f9aa852 199 result.is_map_p = 0;
a6bac58e
TT
200
201 return result;
202}
203
204void
205add_item (zzz_type *c, int val)
206{
207 if (c->len == 0)
208 c->elements = array;
209 c->elements[c->len] = val;
210 ++c->len;
211}
212
731145cb
TT
213void
214set_item(zzz_type *c, int i, int val)
215{
216 if (i < c->len)
217 c->elements[i] = val;
218}
219
a6bac58e
TT
220void init_s(struct s *s, int a)
221{
222 s->a = a;
223 s->b = &s->a;
224}
225
226void init_ss(struct ss *s, int a, int b)
227{
228 init_s(&s->a, a);
229 init_s(&s->b, b);
230}
231
232void do_nothing(void)
233{
234 int c;
235
236 c = 23; /* Another MI breakpoint */
237}
238
0cc7d26f
TT
239struct nullstr
240{
241 char *s;
242};
243
244struct string_repr string_1 = { { "one" } };
245struct string_repr string_2 = { { "two" } };
246
2abc3f8d 247int
8f043999
JK
248eval_func (int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8)
249{
250 return p1;
251}
252
253static void
254eval_sub (void)
255{
256 struct eval_type_s { int x; } eval1 = { 1 }, eval2 = { 2 }, eval3 = { 3 },
257 eval4 = { 4 }, eval5 = { 5 }, eval6 = { 6 },
258 eval7 = { 7 }, eval8 = { 8 }, eval9 = { 9 };
259
260 eval1.x++; /* eval-break */
261}
262
731145cb
TT
263static void
264bug_14741()
265{
266 zzz_type c = make_container ("bug_14741");
267 add_item (&c, 71);
268 set_item(&c, 0, 42); /* breakpoint bug 14741 */
269 set_item(&c, 0, 5);
270}
271
c973d0aa
PA
272/* Some typedefs/variables for checking that GDB doesn't lose typedefs
273 when looking for a printer. */
274typedef int int_type;
275typedef int_type int_type2;
332cf4c9 276typedef int_type int_type3;
c973d0aa
PA
277
278int an_int = -1;
279int_type an_int_type = 1;
280int_type2 an_int_type2 = 2;
332cf4c9 281int_type3 an_int_type3 = 3;
c973d0aa 282
a6bac58e
TT
283int
284main ()
285{
286 struct ss ss;
287 struct ss ssa[2];
91158a56 288 struct arraystruct arraystruct;
a6bac58e
TT
289 string x = make_string ("this is x");
290 zzz_type c = make_container ("container");
0cc7d26f 291 zzz_type c2 = make_container ("container2");
a6bac58e 292 const struct string_repr cstring = { { "const string" } };
0cc7d26f
TT
293 /* Clearing by being `static' could invoke an other GDB C++ bug. */
294 struct nullstr nullstr;
a4c8e806 295 nostring_type nstype, nstype2;
00bd41d6 296 struct memory_error me;
621c8364 297 struct ns ns, ns2;
4ea6efe9 298 struct lazystring estring, estring2, estring3;
e1ab1f9c 299 struct hint_error hint_error;
2c12abee 300 struct children_as_list children_as_list;
0625771b 301 struct to_string_returns_value_wrapper tsrvw = { { 1989 } };
3a772aa4 302
79f283fe
PM
303 nstype.elements = narray;
304 nstype.len = 0;
be759fcf 305
00bd41d6
PM
306 me.s = "blah";
307
a6bac58e
TT
308 init_ss(&ss, 1, 2);
309 init_ss(ssa+0, 3, 4);
310 init_ss(ssa+1, 5, 6);
0cc7d26f 311 memset (&nullstr, 0, sizeof nullstr);
a6bac58e 312
91158a56
TT
313 arraystruct.y = 7;
314 init_s (&arraystruct.x[0], 23);
315 init_s (&arraystruct.x[1], 24);
316
fbb8f299
PM
317 ns.null_str = "embedded\0null\0string";
318 ns.length = 20;
319
621c8364
TT
320 /* Make a "corrupted" string. */
321 ns2.null_str = NULL;
322 ns2.length = 20;
323
4ea6efe9
DE
324 estring.lazy_str = "embedded x\201\202\203\204";
325 estring.len = -1;
be759fcf 326
3a772aa4
TT
327 /* Incomplete UTF-8, but ok Latin-1. */
328 estring2.lazy_str = "embedded x\302";
4ea6efe9
DE
329 estring2.len = -1;
330
331 estring3.lazy_str = NULL;
332 estring3.len = 42;
3a772aa4 333
a6bac58e
TT
334#ifdef __cplusplus
335 S cps;
336
337 cps.zs = 7;
338 init_s(&cps, 8);
339
340 SS cpss;
341 cpss.zss = 9;
342 init_s(&cpss.s, 10);
343
344 SS cpssa[2];
345 cpssa[0].zss = 11;
346 init_s(&cpssa[0].s, 12);
347 cpssa[1].zss = 13;
348 init_s(&cpssa[1].s, 14);
349
350 SSS sss(15, cps);
351
352 SSS& ref (sss);
353
354 Derived derived;
355
d65aec65 356 Fake fake (42);
a6bac58e
TT
357#endif
358
359 add_item (&c, 23); /* MI breakpoint here */
360 add_item (&c, 72);
361
362#ifdef MI
0cc7d26f
TT
363 add_item (&c, 1011);
364 c.elements[0] = 1023;
365 c.elements[0] = 2323;
366
367 add_item (&c2, 2222);
368 add_item (&c2, 3333);
369
370 substruct_test ();
a6bac58e
TT
371 do_nothing ();
372#endif
373
79f283fe
PM
374 nstype.elements[0] = 7;
375 nstype.elements[1] = 42;
376 nstype.len = 2;
377
a4c8e806
TT
378 nstype2 = nstype;
379
8f043999
JK
380 eval_sub ();
381
731145cb
TT
382 bug_14741(); /* break to inspect struct and union */
383 return 0;
a6bac58e 384}
This page took 2.434924 seconds and 4 git commands to generate.