1 /* Copyright 1999-2020 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
;
112 void do_locals_tests (void);
113 void do_block_tests (void);
114 void subroutine1 (int, long *);
116 void do_children_tests (void);
117 void do_special_tests (void);
126 int array
[] = {1,2,3};
127 int array2
[] = {4,5,6};
128 int *array_ptr
= array
;
135 char lcharacter
[2] = { 0, 0 };
136 char *lpcharacter
= 0;
142 double *lpdouble
= 0;
143 struct _simple_struct lsimple
= { 0 };
144 struct _simple_struct
*lpsimple
= 0;
145 void (*func
) (void) = 0;
147 /* Simple assignments */
149 lpinteger
= &linteger
;
151 lpcharacter
= lcharacter
;
156 ldouble
= 2.718281828459045;
158 lsimple
.integer
= 1234;
159 lsimple
.unsigned_integer
= 255;
160 lsimple
.character
= 'a';
161 lsimple
.signed_character
= 21;
162 lsimple
.char_ptr
= lcharacter
;
171 ldouble
= 5.498548281828172;
172 lsimple
.integer
= 255;
173 lsimple
.unsigned_integer
= 4321;
174 lsimple
.character
= 'b';
175 lsimple
.signed_character
= 0;
177 subroutine1 (linteger
, &llong
);
186 nothing1 (int a
, char *b
, long c
)
188 struct _struct_decl foo
;
193 struct _struct_decl
*
194 nothing2 (int a
, char *b
, long c
)
196 return (struct _struct_decl
*) 0;
200 subroutine1 (int i
, long *l
)
202 global_simple
.integer
= i
+ 3;
231 do_children_tests (void)
234 struct _struct_n_pointer
*psnp
;
235 struct _struct_n_pointer snp0
, snp1
, snp2
;
236 char a0
[2] = {}, *a1
, **a2
, ***a3
;
237 char b0
[2] = {}, *b1
, **b2
, ***b3
;
238 char c0
[2] = {}, *c1
, **c2
, ***c3
;
239 long z0
, *z1
, **z2
, ***z3
;
240 long y0
, *y1
, **y2
, ***y3
;
241 long x0
, *x1
, **x2
, ***x3
;
245 /* Avoid pointing into NULL, as that is editable on some
248 int *dummy_ptr
= &dummy
;
250 struct _struct_decl struct_declarations
= { 0, 0, NULL
, 0, &dummy_ptr
};
251 weird
= &struct_declarations
;
253 struct_declarations
.integer
= 123;
254 weird
->char_ptr
= "hello";
257 struct_declarations
.int_ptr_ptr
= &foo
;
258 weird
->long_array
[0] = 1234;
259 struct_declarations
.long_array
[1] = 2345;
260 weird
->long_array
[2] = 3456;
261 struct_declarations
.long_array
[3] = 4567;
262 weird
->long_array
[4] = 5678;
263 struct_declarations
.long_array
[5] = 6789;
264 weird
->long_array
[6] = 7890;
265 struct_declarations
.long_array
[7] = 8901;
266 weird
->long_array
[8] = 9012;
267 struct_declarations
.long_array
[9] = 1234;
269 weird
->func_ptr
= nothing
;
270 weird
->func_ptr_struct
= nothing1
;
271 weird
->func_ptr_ptr
= nothing2
;
273 /* Struct/pointer/array tests */
300 snp0
.ptrs
[0] = &snp0
;
301 snp0
.ptrs
[1] = &snp1
;
302 snp0
.ptrs
[2] = &snp2
;
306 snp1
.ptrs
[0] = &snp0
;
307 snp1
.ptrs
[1] = &snp1
;
308 snp1
.ptrs
[2] = &snp2
;
312 snp2
.ptrs
[0] = &snp0
;
313 snp2
.ptrs
[1] = &snp1
;
314 snp2
.ptrs
[2] = &snp2
;
327 do_special_tests (void)
335 struct _simple_struct s
;
342 enum { A
, B
, C
} anone
;
356 void do_frozen_tests ()
358 /*: BEGIN: frozen :*/
369 with_test_prefix "create varobj V1 and V2" {
370 mi_create_varobj V1 v1 "create varobj for v1"
371 mi_create_varobj V2 v2 "create varobj for v2"
373 mi_list_varobj_children "V1" {
374 {"V1.i" "i" "0" "int"}
375 {"V1.nested" "nested" "2" "struct {...}"}
376 } "list children of v1"
378 mi_list_varobj_children "V1.nested" {
379 {"V1.nested.j" "j" "0" "int"}
380 {"V1.nested.k" "k" "0" "int"}
381 } "list children of v1.nested"
383 mi_check_varobj_value V1.i 1 "check V1.i: 1"
384 mi_check_varobj_value V1.nested.j 2 "check V1.nested.j: 2"
385 mi_check_varobj_value V1.nested.k 3 "check V1.nested.k: 3"
386 mi_check_varobj_value V2 4 "check V2: 4"
391 mi_varobj_update * {V2} "update varobjs: V2 changed"
396 mi_varobj_update * {} "update varobjs: nothing changed"
397 mi_check_varobj_value V2 5 "check V2: 5"
398 mi_varobj_update V2 {V2} "update V2 explicitly"
399 mi_check_varobj_value V2 6 "check V2: 6"
405 with_test_prefix "frozen V1" {
407 mi_varobj_update * {} "update varobjs: nothing changed"
408 mi_check_varobj_value V1.i 1 "check V1.i: 1"
409 mi_check_varobj_value V1.nested.j 2 "check V1.nested.j: 2"
410 mi_check_varobj_value V1.nested.k 3 "check V1.nested.k: 3"
412 # Check that explicit update for elements of structures
414 with_test_prefix "update v1.j" {
416 mi_varobj_update V1.nested.j {V1.nested.j} "update V1.nested.j"
417 mi_check_varobj_value V1.i 1 "check V1.i: 1"
418 mi_check_varobj_value V1.nested.j 8 "check V1.nested.j: 8"
419 mi_check_varobj_value V1.nested.k 3 "check V1.nested.k: 3"
421 with_test_prefix "update v1.nested" {
422 # Update v1.nested, check that children is updated.
423 mi_varobj_update V1.nested {V1.nested.k} "update V1.nested"
424 mi_check_varobj_value V1.i 1 "check V1.i: 1"
425 mi_check_varobj_value V1.nested.j 8 "check V1.nested.j: 8"
426 mi_check_varobj_value V1.nested.k 9 "check V1.nested.k: 9"
428 with_test_prefix "update v1.i" {
430 mi_varobj_update V1.i {V1.i} "update V1.i"
431 mi_check_varobj_value V1.i 7 "check V1.i: 7"
438 # Check that unfreeze itself does not updates the values.
439 with_test_prefix "unfrozen V1" {
441 mi_check_varobj_value V1.i 7 "check V1.i: 7"
442 mi_check_varobj_value V1.nested.j 8 "check V1.nested.j: 8"
443 mi_check_varobj_value V1.nested.k 9 "check V1.nested.k: 9"
444 mi_varobj_update V1 {V1.i V1.nested.j V1.nested.k} "update V1"
445 mi_check_varobj_value V1.i 10 "check V1.i: 10"
446 mi_check_varobj_value V1.nested.j 11 "check V1.nested.j: 11"
447 mi_check_varobj_value V1.nested.k 12 "check V1.nested.k: 12"
454 void do_at_tests_callee ()
456 /* This is a test of wrong DWARF data being assigned to expression.
457 The DWARF location expression is bound to symbol when expression
458 is parsed. So, if we create floating varobj in one function,
459 and then try to reevaluate it in other frame without reparsing
460 the expression, we will access local variables using DWARF
461 location expression from the original frame, and are likely
462 to grab wrong symbol. To reliably reproduce this bug, we need
463 to wrap our variable with a bunch of buffers, so that those
464 buffers are accessed instead of the real one. */
472 i
++; /* breakpoint inside callee */
479 /*: BEGIN: floating :*/
483 mi_create_floating_varobj F i "create floating varobj"
487 mi_varobj_update F {F} "update F (1)"
488 mi_check_varobj_value F 11 "check F (1)"
494 mi_varobj_update_with_type_change F "double" "0" "update F (2)"
495 mi_check_varobj_value F 15 "check F (2)"
502 mi_gdb_test "-var-update --all-values F" {.*value="19".*} "update F (--all-values)"
508 mi_varobj_update_with_type_change F "int" "0" "update F (3)"
509 mi_check_varobj_value F 13 "check F (3)"
512 do_at_tests_callee ();
514 /*: END: floating :*/
517 /* Some header appear to define uint already, so apply some
518 uglification. Note that without uglification, the compile
519 does not fail, rather, we don't test what we want because
520 something else calls check_typedef on 'uint' already. */
521 typedef unsigned int uint_for_mi_testing
;
525 uint_for_mi_testing sharable
: 4;
528 /* Accessing a value of a bitfield whose type is a typed used to
529 result in division by zero. See:
531 http://sourceware.org/bugzilla/show_bug.cgi?id=10884
533 This tests for this bug. */
535 void do_bitfield_tests ()
537 /*: BEGIN: bitfield :*/
538 struct Data d
= {0, 3};
540 mi_create_varobj V d "create varobj for Data"
541 mi_list_varobj_children "V" {
542 {"V.alloc" "alloc" "0" "int"}
543 {"V.sharable" "sharable" "0" "uint_for_mi_testing"}
544 } "list children of Data"
545 mi_check_varobj_value V.sharable 3 "access bitfield"
548 /*: END: bitfield :*/
552 do_anonymous_type_tests (void)
554 struct anonymous
*anon
;
555 struct anonymous
**ptr
;
569 anon
= malloc (sizeof (struct anonymous
));
572 anon
->c
= (char *) 3;
575 anon
->h
= (const char **) 6;
576 anon
->simple
= (simpleton
***) 7;
580 return; /* anonymous type tests breakpoint */
584 do_nested_struct_union_tests (void)
605 /* Anonymous union. */
643 memset (&var
, 0, sizeof (var
));
644 memset (&var2
, 0, sizeof (var2
));
647 return; /* nested struct union tests breakpoint */
651 main (int argc
, char *argv
[])
655 do_children_tests ();
659 do_bitfield_tests ();
660 do_anonymous_type_tests ();
661 do_nested_struct_union_tests ();