Avoid quadratic behavior when computing the value of a register.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / python-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
18struct s
19{
20 int a;
21 int *b;
22};
23
24struct ss
25{
26 struct s a;
27 struct s b;
28};
29
fbb8f299
PM
30struct ns {
31 const char *null_str;
32 int length;
33};
34
a6bac58e
TT
35#ifdef __cplusplus
36struct S : public s {
37 int zs;
38};
39
40struct SS {
41 int zss;
42 S s;
43};
44
45struct SSS
46{
47 SSS (int x, const S& r);
48 int a;
49 const S &b;
50};
51SSS::SSS (int x, const S& r) : a(x), b(r) { }
52
53class VirtualTest
54{
55 private:
56 int value;
57
58 public:
59 VirtualTest ()
60 {
61 value = 1;
62 }
63};
64
65class Vbase1 : public virtual VirtualTest { };
66class Vbase2 : public virtual VirtualTest { };
67class Vbase3 : public virtual VirtualTest { };
68
69class Derived : public Vbase1, public Vbase2, public Vbase3
70{
71 private:
72 int value;
73
74 public:
75 Derived ()
76 {
77 value = 2;
78 }
79};
80
81#endif
82
83typedef struct string_repr
84{
85 struct whybother
86 {
87 const char *contents;
88 } whybother;
89} string;
90
91/* This lets us avoid malloc. */
92int array[100];
93
94struct container
95{
96 string name;
97 int len;
98 int *elements;
99};
100
101typedef struct container zzz_type;
102
103string
104make_string (const char *s)
105{
106 string result;
107 result.whybother.contents = s;
108 return result;
109}
110
111zzz_type
112make_container (const char *s)
113{
114 zzz_type result;
115
116 result.name = make_string (s);
117 result.len = 0;
118 result.elements = 0;
119
120 return result;
121}
122
123void
124add_item (zzz_type *c, int val)
125{
126 if (c->len == 0)
127 c->elements = array;
128 c->elements[c->len] = val;
129 ++c->len;
130}
131
132void init_s(struct s *s, int a)
133{
134 s->a = a;
135 s->b = &s->a;
136}
137
138void init_ss(struct ss *s, int a, int b)
139{
140 init_s(&s->a, a);
141 init_s(&s->b, b);
142}
143
144void do_nothing(void)
145{
146 int c;
147
148 c = 23; /* Another MI breakpoint */
149}
150
151int
152main ()
153{
154 struct ss ss;
155 struct ss ssa[2];
156 string x = make_string ("this is x");
157 zzz_type c = make_container ("container");
158 const struct string_repr cstring = { { "const string" } };
159
160 init_ss(&ss, 1, 2);
161 init_ss(ssa+0, 3, 4);
162 init_ss(ssa+1, 5, 6);
163
fbb8f299
PM
164 struct ns ns;
165 ns.null_str = "embedded\0null\0string";
166 ns.length = 20;
167
a6bac58e
TT
168#ifdef __cplusplus
169 S cps;
170
171 cps.zs = 7;
172 init_s(&cps, 8);
173
174 SS cpss;
175 cpss.zss = 9;
176 init_s(&cpss.s, 10);
177
178 SS cpssa[2];
179 cpssa[0].zss = 11;
180 init_s(&cpssa[0].s, 12);
181 cpssa[1].zss = 13;
182 init_s(&cpssa[1].s, 14);
183
184 SSS sss(15, cps);
185
186 SSS& ref (sss);
187
188 Derived derived;
189
190#endif
191
192 add_item (&c, 23); /* MI breakpoint here */
193 add_item (&c, 72);
194
195#ifdef MI
196 do_nothing ();
197#endif
198
199 return 0; /* break to inspect struct and union */
200}
This page took 0.064881 seconds and 4 git commands to generate.