OSDN Git Service

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