1 /* Copyright 1999, 2004 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 2 of the License, or (at 8 your option) any later version. 9 10 This program is distributed in the hope that it will be useful, but 11 WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 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, write to the Free Software 17 Foundation, Inc., 59 Temple Place - Suite 330, 18 Boston, MA 02111-1307, USA. */ 19 20 #include <stdlib.h> 21 22 struct _simple_struct { 23 int integer; 24 unsigned int unsigned_integer; 25 char character; 26 signed char signed_character; 27 char *char_ptr; 28 int array_of_10[10]; 29 }; 30 31 typedef struct _simple_struct simpleton; 32 33 simpleton global_simple; 34 35 enum foo { 36 bar = 1, 37 baz 38 }; 39 40 typedef enum foo efoo; 41 42 union named_union 43 { 44 int integer; 45 char *char_ptr; 46 }; 47 48 typedef struct _struct_decl { 49 int integer; 50 char character; 51 char *char_ptr; 52 long long_int; 53 int **int_ptr_ptr; 54 long long_array[10]; 55 56 void (*func_ptr) (void); 57 struct _struct_decl (*func_ptr_struct) (int, char *, long); 58 struct _struct_decl *(*func_ptr_ptr) (int, char *, long); 59 union { 60 int a; 61 char *b; 62 long c; 63 enum foo d; 64 } u1; 65 66 struct { 67 union { 68 struct { 69 int d; 70 char e[10]; 71 int *(*func) (void); 72 efoo foo; 73 } u1s1; 74 75 long f; 76 struct { 77 char array_ptr[2]; 78 int (*func) (int, char *); 79 } u1s2; 80 } u2; 81 82 int g; 83 char h; 84 long i[10]; 85 } s2; 86 } weird_struct; 87 88 struct _struct_n_pointer { 89 char ****char_ptr; 90 long ****long_ptr; 91 struct _struct_n_pointer *ptrs[3]; 92 struct _struct_n_pointer *next; 93 }; 94 95 void do_locals_tests (void); 96 void do_block_tests (void); 97 void subroutine1 (int, long *); 98 void nothing (void); 99 void do_children_tests (void); 100 void do_special_tests (void); 101 void incr_a (char); 102 103 void incr_a (char a) 104 { 105 int b; 106 b = a; 107 } 108 109 void 110 do_locals_tests () 111 { 112 int linteger; 113 int *lpinteger; 114 char lcharacter; 115 char *lpcharacter; 116 long llong; 117 long *lplong; 118 float lfloat; 119 float *lpfloat; 120 double ldouble; 121 double *lpdouble; 122 struct _simple_struct lsimple; 123 struct _simple_struct *lpsimple; 124 void (*func) (void); 125 126 /* Simple assignments */ 127 linteger = 1234; 128 lpinteger = &linteger; 129 lcharacter = 'a'; 130 lpcharacter = &lcharacter; 131 llong = 2121L; 132 lplong = &llong; 133 lfloat = 2.1; 134 lpfloat = &lfloat; 135 ldouble = 2.718281828459045; 136 lpdouble = &ldouble; 137 lsimple.integer = 1234; 138 lsimple.unsigned_integer = 255; 139 lsimple.character = 'a'; 140 lsimple.signed_character = 21; 141 lsimple.char_ptr = &lcharacter; 142 lpsimple = &lsimple; 143 func = nothing; 144 145 /* Check pointers */ 146 linteger = 4321; 147 lcharacter = 'b'; 148 llong = 1212L; 149 lfloat = 1.2; 150 ldouble = 5.498548281828172; 151 lsimple.integer = 255; 152 lsimple.unsigned_integer = 4321; 153 lsimple.character = 'b'; 154 lsimple.signed_character = 0; 155 156 subroutine1 (linteger, &llong); 157 } 158 159 void 160 nothing () 161 { 162 } 163 164 void 165 subroutine1 (int i, long *l) 166 { 167 global_simple.integer = i + 3; 168 i = 212; 169 *l = 12; 170 } 171 172 void 173 do_block_tests () 174 { 175 int cb = 12; 176 177 { 178 int foo; 179 foo = 123; 180 { 181 int foo2; 182 foo2 = 123; 183 { 184 int foo; 185 foo = 321; 186 } 187 foo2 = 0; 188 } 189 foo = 0; 190 } 191 192 cb = 21; 193 } 194 195 void 196 do_children_tests (void) 197 { 198 weird_struct *weird; 199 struct _struct_n_pointer *psnp; 200 struct _struct_n_pointer snp0, snp1, snp2; 201 char a0, *a1, **a2, ***a3; 202 char b0, *b1, **b2, ***b3; 203 char c0, *c1, **c2, ***c3; 204 long z0, *z1, **z2, ***z3; 205 long y0, *y1, **y2, ***y3; 206 long x0, *x1, **x2, ***x3; 207 int *foo; 208 int bar; 209 210 struct _struct_decl 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 231 /* Struct/pointer/array tests */ 232 a0 = '0'; 233 a1 = &a0; 234 a2 = &a1; 235 a3 = &a2; 236 b0 = '1'; 237 b1 = &b0; 238 b2 = &b1; 239 b3 = &b2; 240 c0 = '2'; 241 c1 = &c0; 242 c2 = &c1; 243 c3 = &c2; 244 z0 = 0xdead + 0; 245 z1 = &z0; 246 z2 = &z1; 247 z3 = &z2; 248 y0 = 0xdead + 1; 249 y1 = &y0; 250 y2 = &y1; 251 y3 = &y2; 252 x0 = 0xdead + 2; 253 x1 = &x0; 254 x2 = &x1; 255 x3 = &x2; 256 snp0.char_ptr = &a3; 257 snp0.long_ptr = &z3; 258 snp0.ptrs[0] = &snp0; 259 snp0.ptrs[1] = &snp1; 260 snp0.ptrs[2] = &snp2; 261 snp0.next = &snp1; 262 snp1.char_ptr = &b3; 263 snp1.long_ptr = &y3; 264 snp1.ptrs[0] = &snp0; 265 snp1.ptrs[1] = &snp1; 266 snp1.ptrs[2] = &snp2; 267 snp1.next = &snp2; 268 snp2.char_ptr = &c3; 269 snp2.long_ptr = &x3; 270 snp2.ptrs[0] = &snp0; 271 snp2.ptrs[1] = &snp1; 272 snp2.ptrs[2] = &snp2; 273 snp2.next = 0x0; 274 psnp = &snp0; 275 snp0.char_ptr = &b3; 276 snp1.char_ptr = &c3; 277 snp2.char_ptr = &a3; 278 snp0.long_ptr = &y3; 279 snp1.long_ptr = &x3; 280 snp2.long_ptr = &z3; 281 } 282 283 void 284 do_special_tests (void) 285 { 286 union named_union u; 287 union { 288 int a; 289 char b; 290 long c; 291 } anonu; 292 struct _simple_struct s; 293 struct { 294 int a; 295 char b; 296 long c; 297 } anons; 298 enum foo e; 299 enum { A, B, C } anone; 300 int array[21]; 301 int a; 302 303 a = 1; 304 incr_a(2); 305 } 306 307 int 308 main (int argc, char *argv []) 309 { 310 do_locals_tests (); 311 do_block_tests (); 312 do_children_tests (); 313 do_special_tests (); 314 exit (0); 315 } 316 317 318