1 /* Copyright 1999, 2004, 2007, 2008, 2009 Free Software Foundation, Inc.
3 This file is part of GDB.
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.
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.
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/>. */
21 struct _simple_struct
{
23 unsigned int unsigned_integer
;
25 signed char signed_character
;
30 typedef struct _simple_struct simpleton
;
32 simpleton global_simple
;
39 typedef enum foo efoo
;
47 typedef struct _struct_decl
{
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);
77 int (*func
) (int, char *);
87 struct _struct_n_pointer
{
90 struct _struct_n_pointer
*ptrs
[3];
91 struct _struct_n_pointer
*next
;
94 void do_locals_tests (void);
95 void do_block_tests (void);
96 void subroutine1 (int, long *);
98 void do_children_tests (void);
99 void do_special_tests (void);
108 int array
[] = {1,2,3};
109 int array2
[] = {4,5,6};
110 int *array_ptr
= array
;
117 char lcharacter
[2] = { 0, 0 };
118 char *lpcharacter
= 0;
124 double *lpdouble
= 0;
125 struct _simple_struct lsimple
;
126 struct _simple_struct
*lpsimple
;
129 /* Simple assignments */
131 lpinteger
= &linteger
;
133 lpcharacter
= lcharacter
;
138 ldouble
= 2.718281828459045;
140 lsimple
.integer
= 1234;
141 lsimple
.unsigned_integer
= 255;
142 lsimple
.character
= 'a';
143 lsimple
.signed_character
= 21;
144 lsimple
.char_ptr
= lcharacter
;
153 ldouble
= 5.498548281828172;
154 lsimple
.integer
= 255;
155 lsimple
.unsigned_integer
= 4321;
156 lsimple
.character
= 'b';
157 lsimple
.signed_character
= 0;
159 subroutine1 (linteger
, &llong
);
168 subroutine1 (int i
, long *l
)
170 global_simple
.integer
= i
+ 3;
199 do_children_tests (void)
202 struct _struct_n_pointer
*psnp
;
203 struct _struct_n_pointer snp0
, snp1
, snp2
;
204 char a0
[2] = {}, *a1
, **a2
, ***a3
;
205 char b0
[2] = {}, *b1
, **b2
, ***b3
;
206 char c0
[2] = {}, *c1
, **c2
, ***c3
;
207 long z0
, *z1
, **z2
, ***z3
;
208 long y0
, *y1
, **y2
, ***y3
;
209 long x0
, *x1
, **x2
, ***x3
;
213 /* Avoid pointing into NULL, as that is editable on some
216 int *dummy_ptr
= &dummy
;
218 struct _struct_decl struct_declarations
= { 0, 0, NULL
, 0, &dummy_ptr
};
219 weird
= &struct_declarations
;
221 struct_declarations
.integer
= 123;
222 weird
->char_ptr
= "hello";
225 struct_declarations
.int_ptr_ptr
= &foo
;
226 weird
->long_array
[0] = 1234;
227 struct_declarations
.long_array
[1] = 2345;
228 weird
->long_array
[2] = 3456;
229 struct_declarations
.long_array
[3] = 4567;
230 weird
->long_array
[4] = 5678;
231 struct_declarations
.long_array
[5] = 6789;
232 weird
->long_array
[6] = 7890;
233 struct_declarations
.long_array
[7] = 8901;
234 weird
->long_array
[8] = 9012;
235 struct_declarations
.long_array
[9] = 1234;
237 weird
->func_ptr
= nothing
;
239 /* Struct/pointer/array tests */
266 snp0
.ptrs
[0] = &snp0
;
267 snp0
.ptrs
[1] = &snp1
;
268 snp0
.ptrs
[2] = &snp2
;
272 snp1
.ptrs
[0] = &snp0
;
273 snp1
.ptrs
[1] = &snp1
;
274 snp1
.ptrs
[2] = &snp2
;
278 snp2
.ptrs
[0] = &snp0
;
279 snp2
.ptrs
[1] = &snp1
;
280 snp2
.ptrs
[2] = &snp2
;
293 do_special_tests (void)
301 struct _simple_struct s
;
308 enum { A
, B
, C
} anone
;
322 void do_frozen_tests ()
324 /*: BEGIN: frozen :*/
335 mi_create_varobj V1 v1 "create varobj for v1"
336 mi_create_varobj V2 v2 "create varobj for v2"
338 mi_list_varobj_children "V1" {
339 {"V1.i" "i" "0" "int"}
340 {"V1.nested" "nested" "2" "struct {...}"}
341 } "list children of v1"
343 mi_list_varobj_children "V1.nested" {
344 {"V1.nested.j" "j" "0" "int"}
345 {"V1.nested.k" "k" "0" "int"}
346 } "list children of v1.nested"
348 mi_check_varobj_value V1.i 1 "check V1.i: 1"
349 mi_check_varobj_value V1.nested.j 2 "check V1.nested.j: 2"
350 mi_check_varobj_value V1.nested.k 3 "check V1.nested.k: 3"
351 mi_check_varobj_value V2 4 "check V2: 4"
355 mi_varobj_update * {V2} "update varobjs: V2 changed"
360 mi_varobj_update * {} "update varobjs: nothing changed"
361 mi_check_varobj_value V2 5 "check V2: 5"
362 mi_varobj_update V2 {V2} "update V2 explicitly"
363 mi_check_varobj_value V2 6 "check V2: 6"
370 mi_varobj_update * {} "update varobjs: nothing changed"
371 mi_check_varobj_value V1.i 1 "check V1.i: 1"
372 mi_check_varobj_value V1.nested.j 2 "check V1.nested.j: 2"
373 mi_check_varobj_value V1.nested.k 3 "check V1.nested.k: 3"
374 # Check that explicit update for elements of structures
377 mi_varobj_update V1.nested.j {V1.nested.j} "update V1.nested.j"
378 mi_check_varobj_value V1.i 1 "check V1.i: 1"
379 mi_check_varobj_value V1.nested.j 8 "check V1.nested.j: 8"
380 mi_check_varobj_value V1.nested.k 3 "check V1.nested.k: 3"
381 # Update v1.nested, check that children is updated.
382 mi_varobj_update V1.nested {V1.nested.k} "update V1.nested"
383 mi_check_varobj_value V1.i 1 "check V1.i: 1"
384 mi_check_varobj_value V1.nested.j 8 "check V1.nested.j: 8"
385 mi_check_varobj_value V1.nested.k 9 "check V1.nested.k: 9"
387 mi_varobj_update V1.i {V1.i} "update V1.i"
388 mi_check_varobj_value V1.i 7 "check V1.i: 7"
394 # Check that unfreeze itself does not updates the values.
396 mi_check_varobj_value V1.i 7 "check V1.i: 7"
397 mi_check_varobj_value V1.nested.j 8 "check V1.nested.j: 8"
398 mi_check_varobj_value V1.nested.k 9 "check V1.nested.k: 9"
399 mi_varobj_update V1 {V1.i V1.nested.j V1.nested.k} "update V1"
400 mi_check_varobj_value V1.i 10 "check V1.i: 10"
401 mi_check_varobj_value V1.nested.j 11 "check V1.nested.j: 11"
402 mi_check_varobj_value V1.nested.k 12 "check V1.nested.k: 12"
408 void do_at_tests_callee ()
410 /* This is a test of wrong DWARF data being assigned to expression.
411 The DWARF location expression is bound to symbol when expression
412 is parsed. So, if we create floating varobj in one function,
413 and then try to reevaluate it in other frame without reparsing
414 the expression, we will access local variables using DWARF
415 location expression from the original frame, and are likely
416 to grab wrong symbol. To reliably reproduce this bug, we need
417 to wrap our variable with a bunch of buffers, so that those
418 buffers are accessed instead of the real one. */
426 i
++; /* breakpoint inside callee */
433 /*: BEGIN: floating :*/
437 mi_create_floating_varobj F i "create floating varobj"
441 mi_varobj_update F {F} "update F (1)"
442 mi_check_varobj_value F 11 "check F (1)"
448 mi_varobj_update_with_type_change F "double" "0" "update F (2)"
449 mi_check_varobj_value F 15 "check F (2)"
456 mi_gdb_test "-var-update --all-values F" {.*value="19".*} "update F (--all-values)"
462 mi_varobj_update_with_type_change F "int" "0" "update F (3)"
463 mi_check_varobj_value F 13 "check F (3)"
466 do_at_tests_callee ();
468 /*: END: floating :*/
472 main (int argc
, char *argv
[])
476 do_children_tests ();