1/* Copyright 1999, 2004, 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 20struct _simple_struct { 21 int integer; 22 unsigned int unsigned_integer; 23 char character; 24 signed char signed_character; 25 char *char_ptr; 26 int array_of_10[10]; 27}; 28 29typedef struct _simple_struct simpleton; 30 31simpleton global_simple; 32 33enum foo { 34 bar = 1, 35 baz 36}; 37 38typedef enum foo efoo; 39 40union named_union 41{ 42 int integer; 43 char *char_ptr; 44}; 45 46typedef struct _struct_decl { 47 int integer; 48 char character; 49 char *char_ptr; 50 long long_int; 51 int **int_ptr_ptr; 52 long long_array[10]; 53 54 void (*func_ptr) (void); 55 struct _struct_decl (*func_ptr_struct) (int, char *, long); 56 struct _struct_decl *(*func_ptr_ptr) (int, char *, long); 57 union { 58 int a; 59 char *b; 60 long c; 61 enum foo d; 62 } u1; 63 64 struct { 65 union { 66 struct { 67 int d; 68 char e[10]; 69 int *(*func) (void); 70 efoo foo; 71 } u1s1; 72 73 long f; 74 struct { 75 char array_ptr[2]; 76 int (*func) (int, char *); 77 } u1s2; 78 } u2; 79 80 int g; 81 char h; 82 long i[10]; 83 } s2; 84} weird_struct; 85 86struct _struct_n_pointer { 87 char ****char_ptr; 88 long ****long_ptr; 89 struct _struct_n_pointer *ptrs[3]; 90 struct _struct_n_pointer *next; 91}; 92 93void do_locals_tests (void); 94void do_block_tests (void); 95void subroutine1 (int, long *); 96void nothing (void); 97void do_children_tests (void); 98void do_special_tests (void); 99void incr_a (char); 100 101void incr_a (char a) 102{ 103 int b; 104 b = a; 105} 106 107int array[] = {1,2,3}; 108int array2[] = {4,5,6}; 109int *array_ptr = array; 110 111void 112do_locals_tests () 113{ 114 int linteger = 0; 115 int *lpinteger = 0; 116 char lcharacter = 0; 117 char *lpcharacter = 0; 118 long llong = 0; 119 long *lplong = 0; 120 float lfloat = 0; 121 float *lpfloat = 0; 122 double ldouble = 0; 123 double *lpdouble = 0; 124 struct _simple_struct lsimple; 125 struct _simple_struct *lpsimple; 126 void (*func) (void); 127 128 /* Simple assignments */ 129 linteger = 1234; 130 lpinteger = &linteger; 131 lcharacter = 'a'; 132 lpcharacter = &lcharacter; 133 llong = 2121L; 134 lplong = &llong; 135 lfloat = 2.1; 136 lpfloat = &lfloat; 137 ldouble = 2.718281828459045; 138 lpdouble = &ldouble; 139 lsimple.integer = 1234; 140 lsimple.unsigned_integer = 255; 141 lsimple.character = 'a'; 142 lsimple.signed_character = 21; 143 lsimple.char_ptr = &lcharacter; 144 lpsimple = &lsimple; 145 func = nothing; 146 147 /* Check pointers */ 148 linteger = 4321; 149 lcharacter = 'b'; 150 llong = 1212L; 151 lfloat = 1.2; 152 ldouble = 5.498548281828172; 153 lsimple.integer = 255; 154 lsimple.unsigned_integer = 4321; 155 lsimple.character = 'b'; 156 lsimple.signed_character = 0; 157 158 subroutine1 (linteger, &llong); 159} 160 161void 162nothing () 163{ 164} 165 166void 167subroutine1 (int i, long *l) 168{ 169 global_simple.integer = i + 3; 170 i = 212; 171 *l = 12; 172} 173 174void 175do_block_tests () 176{ 177 int cb = 12; 178 179 { 180 int foo; 181 foo = 123; 182 { 183 int foo2; 184 foo2 = 123; 185 { 186 int foo; 187 foo = 321; 188 } 189 foo2 = 0; 190 } 191 foo = 0; 192 } 193 194 cb = 21; 195} 196 197void 198do_children_tests (void) 199{ 200 weird_struct *weird; 201 struct _struct_n_pointer *psnp; 202 struct _struct_n_pointer snp0, snp1, snp2; 203 char a0[2] = {}, *a1, **a2, ***a3; 204 char b0[2] = {}, *b1, **b2, ***b3; 205 char c0[2] = {}, *c1, **c2, ***c3; 206 long z0, *z1, **z2, ***z3; 207 long y0, *y1, **y2, ***y3; 208 long x0, *x1, **x2, ***x3; 209 int *foo; 210 int bar; 211 212 struct _struct_decl struct_declarations; 213 weird = &struct_declarations; 214 215 struct_declarations.integer = 123; 216 weird->char_ptr = "hello"; 217 bar = 2121; 218 foo = &bar; 219 struct_declarations.int_ptr_ptr = &foo; 220 weird->long_array[0] = 1234; 221 struct_declarations.long_array[1] = 2345; 222 weird->long_array[2] = 3456; 223 struct_declarations.long_array[3] = 4567; 224 weird->long_array[4] = 5678; 225 struct_declarations.long_array[5] = 6789; 226 weird->long_array[6] = 7890; 227 struct_declarations.long_array[7] = 8901; 228 weird->long_array[8] = 9012; 229 struct_declarations.long_array[9] = 1234; 230 231 weird->func_ptr = nothing; 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[0] = '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 {int a = 0;} 284} 285 286void 287do_special_tests (void) 288{ 289 union named_union u; 290 union { 291 int a; 292 char b; 293 long c; 294 } anonu; 295 struct _simple_struct s; 296 struct { 297 int a; 298 char b; 299 long c; 300 } anons; 301 enum foo e; 302 enum { A, B, C } anone; 303 int array[21]; 304 int a; 305 306 a = 1; 307 u.integer = a; 308 anonu.a = a; 309 s.integer = a; 310 anons.a = a; 311 e = bar; 312 anone = A; 313 incr_a(2); 314} 315 316void do_frozen_tests () 317{ 318 /*: BEGIN: frozen :*/ 319 struct { 320 int i; 321 struct { 322 int j; 323 int k; 324 } nested; 325 } v1 = {1, {2, 3}}; 326 327 int v2 = 4; 328 /*: 329 mi_create_varobj V1 v1 "create varobj for v1" 330 mi_create_varobj V2 v2 "create varobj for v2" 331 332 mi_list_varobj_children "V1" { 333 {"V1.i" "i" "0" "int"} 334 {"V1.nested" "nested" "2" "struct {...}"} 335 } "list children of v1" 336 337 mi_list_varobj_children "V1.nested" { 338 {"V1.nested.j" "j" "0" "int"} 339 {"V1.nested.k" "k" "0" "int"} 340 } "list children of v1.nested" 341 342 mi_check_varobj_value V1.i 1 "check V1.i: 1" 343 mi_check_varobj_value V1.nested.j 2 "check V1.nested.j: 2" 344 mi_check_varobj_value V1.nested.k 3 "check V1.nested.k: 3" 345 mi_check_varobj_value V2 4 "check V2: 4" 346 :*/ 347 v2 = 5; 348 /*: 349 mi_varobj_update * {V2} "update varobjs: V2 changed" 350 set_frozen V2 1 351 :*/ 352 v2 = 6; 353 /*: 354 mi_varobj_update * {} "update varobjs: nothing changed" 355 mi_check_varobj_value V2 5 "check V2: 5" 356 mi_varobj_update V2 {V2} "update V2 explicitly" 357 mi_check_varobj_value V2 6 "check V2: 6" 358 :*/ 359 v1.i = 7; 360 v1.nested.j = 8; 361 v1.nested.k = 9; 362 /*: 363 set_frozen V1 1 364 mi_varobj_update * {} "update varobjs: nothing changed" 365 mi_check_varobj_value V1.i 1 "check V1.i: 1" 366 mi_check_varobj_value V1.nested.j 2 "check V1.nested.j: 2" 367 mi_check_varobj_value V1.nested.k 3 "check V1.nested.k: 3" 368 # Check that explicit update for elements of structures 369 # works. 370 # Update v1.j 371 mi_varobj_update V1.nested.j {V1.nested.j} "update V1.nested.j" 372 mi_check_varobj_value V1.i 1 "check V1.i: 1" 373 mi_check_varobj_value V1.nested.j 8 "check V1.nested.j: 8" 374 mi_check_varobj_value V1.nested.k 3 "check V1.nested.k: 3" 375 # Update v1.nested, check that children is updated. 376 mi_varobj_update V1.nested {V1.nested.k} "update V1.nested" 377 mi_check_varobj_value V1.i 1 "check V1.i: 1" 378 mi_check_varobj_value V1.nested.j 8 "check V1.nested.j: 8" 379 mi_check_varobj_value V1.nested.k 9 "check V1.nested.k: 9" 380 # Update v1.i 381 mi_varobj_update V1.i {V1.i} "update V1.i" 382 mi_check_varobj_value V1.i 7 "check V1.i: 7" 383 :*/ 384 v1.i = 10; 385 v1.nested.j = 11; 386 v1.nested.k = 12; 387 /*: 388 # Check that unfreeze itself does not updates the values. 389 set_frozen V1 0 390 mi_check_varobj_value V1.i 7 "check V1.i: 7" 391 mi_check_varobj_value V1.nested.j 8 "check V1.nested.j: 8" 392 mi_check_varobj_value V1.nested.k 9 "check V1.nested.k: 9" 393 mi_varobj_update V1 {V1.i V1.nested.j V1.nested.k} "update V1" 394 mi_check_varobj_value V1.i 10 "check V1.i: 10" 395 mi_check_varobj_value V1.nested.j 11 "check V1.nested.j: 11" 396 mi_check_varobj_value V1.nested.k 12 "check V1.nested.k: 12" 397 :*/ 398 399 /*: END: frozen :*/ 400} 401 402int 403main (int argc, char *argv []) 404{ 405 do_locals_tests (); 406 do_block_tests (); 407 do_children_tests (); 408 do_special_tests (); 409 do_frozen_tests (); 410 exit (0); 411} 412 413 414