OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gdb/] [gdb-6.8/] [gdb/] [testsuite/] [gdb.mi/] [mi-var-child.c] - Blame information for rev 25

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 25 jlechner
/* Copyright 1999, 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
2
 
3
   This file is part of GDB.
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 <stdlib.h>
19
#include <string.h>
20
 
21
struct _simple_struct {
22
  int integer;
23
  unsigned int unsigned_integer;
24
  char character;
25
  signed char signed_character;
26
  char *char_ptr;
27
  int array_of_10[10];
28
};
29
 
30
typedef struct _simple_struct simpleton;
31
 
32
simpleton global_simple;
33
 
34
enum foo {
35
  bar = 1,
36
  baz
37
};
38
 
39
typedef enum foo efoo;
40
 
41
union named_union
42
{
43
  int integer;
44
  char *char_ptr;
45
};
46
 
47
typedef struct _struct_decl {
48
  int   integer;
49
  char  character;
50
  char *char_ptr;
51
  long  long_int;
52
  int  **int_ptr_ptr;
53
  long  long_array[12];
54
 
55
  void (*func_ptr) (void);
56
  struct _struct_decl (*func_ptr_struct) (int, char *, long);
57
  struct _struct_decl *(*func_ptr_ptr) (int, char *, long);
58
  union {
59
    int   a;
60
    char *b;
61
    long  c;
62
    enum foo d;
63
  } u1;
64
 
65
  struct {
66
    union {
67
      struct {
68
        int d;
69
        char e[10];
70
        int *(*func) (void);
71
        efoo foo;
72
      } u1s1;
73
 
74
      long f;
75
      struct {
76
        char array_ptr[2];
77
        int (*func) (int, char *);
78
      } u1s2;
79
    } u2;
80
 
81
    int g;
82
    char h;
83
    long i[10];
84
  } s2;
85
} weird_struct;
86
 
87
struct _struct_n_pointer {
88
  char ****char_ptr;
89
  long ****long_ptr;
90
  struct _struct_n_pointer *ptrs[3];
91
  struct _struct_n_pointer *next;
92
};
93
 
94
void do_locals_tests (void);
95
void do_block_tests (void);
96
void subroutine1 (int, long *);
97
void nothing (void);
98
void do_children_tests (void);
99
void do_special_tests (void);
100
void incr_a (char);
101
 
102
void incr_a (char a)
103
{
104
  int b;
105
  b = a;
106
}
107
 
108
void
109
do_locals_tests ()
110
{
111
  int linteger;
112
  int *lpinteger;
113
  char lcharacter;
114
  char *lpcharacter;
115
  long llong;
116
  long *lplong;
117
  float lfloat;
118
  float *lpfloat;
119
  double ldouble;
120
  double *lpdouble;
121
  struct _simple_struct lsimple;
122
  struct _simple_struct *lpsimple;
123
  void (*func) (void);
124
 
125
  /* Simple assignments */
126
  linteger = 1234;
127
  lpinteger = &linteger;
128
  lcharacter = 'a';
129
  lpcharacter = &lcharacter;
130
  llong = 2121L;
131
  lplong = &llong;
132
  lfloat = 2.1;
133
  lpfloat = &lfloat;
134
  ldouble = 2.718281828459045;
135
  lpdouble = &ldouble;
136
  lsimple.integer = 1234;
137
  lsimple.unsigned_integer = 255;
138
  lsimple.character = 'a';
139
  lsimple.signed_character = 21;
140
  lsimple.char_ptr = &lcharacter;
141
  lpsimple = &lsimple;
142
  func = nothing;
143
 
144
  /* Check pointers */
145
  linteger = 4321;
146
  lcharacter = 'b';
147
  llong = 1212L;
148
  lfloat = 1.2;
149
  ldouble = 5.498548281828172;
150
  lsimple.integer = 255;
151
  lsimple.unsigned_integer = 4321;
152
  lsimple.character = 'b';
153
  lsimple.signed_character = 0;
154
 
155
  subroutine1 (linteger, &llong);
156
}
157
 
158
void
159
nothing ()
160
{
161
}
162
 
163
void
164
subroutine1 (int i, long *l)
165
{
166
  global_simple.integer = i + 3;
167
  i = 212;
168
  *l = 12;
169
}
170
 
171
void
172
do_block_tests ()
173
{
174
  int cb = 12;
175
 
176
  {
177
    int foo;
178
    foo = 123;
179
    {
180
      int foo2;
181
      foo2 = 123;
182
      {
183
        int foo;
184
        foo = 321;
185
      }
186
      foo2 = 0;
187
    }
188
    foo = 0;
189
  }
190
 
191
  cb = 21;
192
}
193
 
194
void
195
do_children_tests (void)
196
{
197
  weird_struct *weird;
198
  struct _struct_n_pointer *psnp;
199
  struct _struct_n_pointer snp0, snp1, snp2;
200
  char a0[2] = {}, *a1, **a2, ***a3;
201
  char b0[2] = {}, *b1, **b2, ***b3;
202
  char c0[2] = {}, *c1, **c2, ***c3;
203
  long z0, *z1, **z2, ***z3;
204
  long y0, *y1, **y2, ***y3;
205
  long x0, *x1, **x2, ***x3;
206
  int *foo;
207
  int bar;
208
 
209
  /* Avoid pointing into NULL, as that is editable on some
210
     systems.  */
211
  int dummy;
212
  int *dummy_ptr = &dummy;
213
 
214
  struct _struct_decl struct_declarations = { 0, 0, NULL, 0, &dummy_ptr };
215
  weird = &struct_declarations;
216
 
217
  struct_declarations.integer = 123;
218
  weird->char_ptr = "hello";
219
  bar = 2121;
220
  foo = &bar;
221
  struct_declarations.int_ptr_ptr = &foo;
222
  weird->long_array[0] = 1234;
223
  struct_declarations.long_array[1] = 2345;
224
  weird->long_array[2] = 3456;
225
  struct_declarations.long_array[3] = 4567;
226
  weird->long_array[4] = 5678;
227
  struct_declarations.long_array[5] = 6789;
228
  weird->long_array[6] = 7890;
229
  struct_declarations.long_array[7] = 8901;
230
  weird->long_array[8] = 9012;
231
  struct_declarations.long_array[9] = 1234;
232
 
233
  weird->func_ptr = nothing;
234
  struct_declarations.long_array[10] = 3456;
235
  struct_declarations.long_array[11] = 5678;
236
 
237
  /* Struct/pointer/array tests */
238
  a0[0] = '0';
239
  a1 = a0;
240
  a2 = &a1;
241
  a3 = &a2;
242
  b0[0] = '1';
243
  b1 = b0;
244
  b2 = &b1;
245
  b3 = &b2;
246
  c0[1] = '2';
247
  c1 = c0;
248
  c2 = &c1;
249
  c3 = &c2;
250
  z0 = 0xdead + 0;
251
  z1 = &z0;
252
  z2 = &z1;
253
  z3 = &z2;
254
  y0 = 0xdead + 1;
255
  y1 = &y0;
256
  y2 = &y1;
257
  y3 = &y2;
258
  x0 = 0xdead + 2;
259
  x1 = &x0;
260
  x2 = &x1;
261
  x3 = &x2;
262
  snp0.char_ptr = &a3;
263
  snp0.long_ptr = &z3;
264
  snp0.ptrs[0] = &snp0;
265
  snp0.ptrs[1] = &snp1;
266
  snp0.ptrs[2] = &snp2;
267
  snp0.next = &snp1;
268
  snp1.char_ptr = &b3;
269
  snp1.long_ptr = &y3;
270
  snp1.ptrs[0] = &snp0;
271
  snp1.ptrs[1] = &snp1;
272
  snp1.ptrs[2] = &snp2;
273
  snp1.next = &snp2;
274
  snp2.char_ptr = &c3;
275
  snp2.long_ptr = &x3;
276
  snp2.ptrs[0] = &snp0;
277
  snp2.ptrs[1] = &snp1;
278
  snp2.ptrs[2] = &snp2;
279
  snp2.next = 0x0;
280
  psnp = &snp0;
281
  snp0.char_ptr = &b3;
282
  snp1.char_ptr = &c3;
283
  snp2.char_ptr = &a3;
284
  snp0.long_ptr = &y3;
285
  snp1.long_ptr = &x3;
286
  snp2.long_ptr = &z3;
287
}
288
 
289
void
290
do_special_tests (void)
291
{
292
  union named_union u;
293
  union {
294
    int a;
295
    char b;
296
    long c;
297
  } anonu;
298
  struct _simple_struct s;
299
  struct {
300
    int a;
301
    char b;
302
    long c;
303
  } anons;
304
  enum foo e;
305
  enum { A, B, C } anone;
306
  int array[21];
307
  int a;
308
 
309
  a = 1;
310
  incr_a(2);
311
}
312
 
313
struct very_simple_struct
314
{
315
  int a;
316
  int b;
317
};
318
 
319
int
320
do_child_deletion (void)
321
{
322
  /*: BEGIN: child_deletion :*/
323
  struct very_simple_struct s = {1, 2};
324
  /*:
325
    mi_create_varobj S s "create varobj for s"
326
    mi_list_varobj_children S {{S.a a 0 int} {S.b b 0 int}}     \
327
       "list children of S"
328
    mi_delete_varobj S.a "delete S.a"
329
    mi_delete_varobj S.b "delete S.b"
330
    mi_delete_varobj S "delete S"
331
    :*/
332
  return 99;
333
  /*: END: child_deletion :*/
334
}
335
 
336
int
337
main (int argc, char *argv [])
338
{
339
  do_locals_tests ();
340
  do_block_tests ();
341
  do_children_tests ();
342
  do_special_tests ();
343
  do_child_deletion ();
344
  exit (0);
345
}
346
 
347
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.