1/* Copyright 1999, 2004, 2005, 2007 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 21struct _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 30typedef struct _simple_struct simpleton; 31 32simpleton global_simple; 33 34enum foo { 35 bar = 1, 36 baz 37}; 38 39typedef enum foo efoo; 40 41union named_union 42{ 43 int integer; 44 char *char_ptr; 45}; 46 47typedef 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 87struct _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 94void do_locals_tests (void); 95void do_block_tests (void); 96void subroutine1 (int, long *); 97void nothing (void); 98void do_children_tests (void); 99void do_special_tests (void); 100void incr_a (char); 101 102void incr_a (char a) 103{ 104 int b; 105 b = a; 106} 107 108void 109do_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 158void 159nothing () 160{ 161} 162 163void 164subroutine1 (int i, long *l) 165{ 166 global_simple.integer = i + 3; 167 i = 212; 168 *l = 12; 169} 170 171void 172do_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 194void 195do_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 struct _struct_decl struct_declarations; 210 memset (&struct_declarations, 0, sizeof (struct_declarations)); 211 weird = &struct_declarations; 212 213 struct_declarations.integer = 123; 214 weird->char_ptr = "hello"; 215 bar = 2121; 216 foo = &bar; 217 struct_declarations.int_ptr_ptr = &foo; 218 weird->long_array[0] = 1234; 219 struct_declarations.long_array[1] = 2345; 220 weird->long_array[2] = 3456; 221 struct_declarations.long_array[3] = 4567; 222 weird->long_array[4] = 5678; 223 struct_declarations.long_array[5] = 6789; 224 weird->long_array[6] = 7890; 225 struct_declarations.long_array[7] = 8901; 226 weird->long_array[8] = 9012; 227 struct_declarations.long_array[9] = 1234; 228 229 weird->func_ptr = nothing; 230 struct_declarations.long_array[10] = 3456; 231 struct_declarations.long_array[11] = 5678; 232 233 /* Struct/pointer/array tests */ 234 a0[0] = '0'; 235 a1 = a0; 236 a2 = &a1; 237 a3 = &a2; 238 b0[0] = '1'; 239 b1 = b0; 240 b2 = &b1; 241 b3 = &b2; 242 c0[1] = '2'; 243 c1 = c0; 244 c2 = &c1; 245 c3 = &c2; 246 z0 = 0xdead + 0; 247 z1 = &z0; 248 z2 = &z1; 249 z3 = &z2; 250 y0 = 0xdead + 1; 251 y1 = &y0; 252 y2 = &y1; 253 y3 = &y2; 254 x0 = 0xdead + 2; 255 x1 = &x0; 256 x2 = &x1; 257 x3 = &x2; 258 snp0.char_ptr = &a3; 259 snp0.long_ptr = &z3; 260 snp0.ptrs[0] = &snp0; 261 snp0.ptrs[1] = &snp1; 262 snp0.ptrs[2] = &snp2; 263 snp0.next = &snp1; 264 snp1.char_ptr = &b3; 265 snp1.long_ptr = &y3; 266 snp1.ptrs[0] = &snp0; 267 snp1.ptrs[1] = &snp1; 268 snp1.ptrs[2] = &snp2; 269 snp1.next = &snp2; 270 snp2.char_ptr = &c3; 271 snp2.long_ptr = &x3; 272 snp2.ptrs[0] = &snp0; 273 snp2.ptrs[1] = &snp1; 274 snp2.ptrs[2] = &snp2; 275 snp2.next = 0x0; 276 psnp = &snp0; 277 snp0.char_ptr = &b3; 278 snp1.char_ptr = &c3; 279 snp2.char_ptr = &a3; 280 snp0.long_ptr = &y3; 281 snp1.long_ptr = &x3; 282 snp2.long_ptr = &z3; 283} 284 285void 286do_special_tests (void) 287{ 288 union named_union u; 289 union { 290 int a; 291 char b; 292 long c; 293 } anonu; 294 struct _simple_struct s; 295 struct { 296 int a; 297 char b; 298 long c; 299 } anons; 300 enum foo e; 301 enum { A, B, C } anone; 302 int array[21]; 303 int a; 304 305 a = 1; 306 incr_a(2); 307} 308 309int 310main (int argc, char *argv []) 311{ 312 do_locals_tests (); 313 do_block_tests (); 314 do_children_tests (); 315 do_special_tests (); 316 exit (0); 317} 318 319 320