Update copyright year range in header of all files managed by GDB
[binutils-gdb.git] / gdb / testsuite / gdb.base / vla-struct-fields.exp
blob18837303da19dcd0e095e2bad9099f042c97d5f8
1 # Copyright 2014-2023 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 standard_testfile
18 # Clang says it will never support variable length arrays in structures.
19 if {[test_compiler_info clang*]} {
20     unsupported "compiler does not support variable length arrays in structure"
21     return
24 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
25     return -1
28 if ![runto_main] {
29     return -1
32 gdb_breakpoint [gdb_get_line_number "vlas_filled"]
33 gdb_continue_to_breakpoint "vlas_filled"
35 # Check the values of VLA's.
36 gdb_test "print vla_struct_object" \
37     "\\\{something = 5, vla_field = \\\{0, 2, 4, 6, 8\\\}\\\}"
38 gdb_test "print vla_union_object" \
39     "\\\{vla_field = \\\{0, 2, 4, 6, 8\\\}\\\}"
40 gdb_test "print vla_struct_typedef_struct_member_object" \
41     "\\\{something = 10, vla_object = \\\{something = 15, vla_field = \\\{0, 3, 6, 9, 12\\\}\\\}\\\}"
42 gdb_test "print vla_struct_typedef_union_member_object" \
43     "\\\{something = 6, vla_object = \\\{something = 6, vla_field = \\\{-1, 2, 5, 8, 11\\\}\\\}\\\}"
45 # Check whatis of VLA's.
46 gdb_test "whatis vla_struct_object" "type = vla_struct_typedef"
47 gdb_test "whatis vla_union_object" "type = union vla_union"
49 # Check ptype of VLA's.
50 gdb_test "ptype vla_struct_object" \
51     "type = struct vla_struct {\r\n\\s+int something;\r\n\\s+int vla_field\\\[5\\\];\r\n}"
52 gdb_test "ptype vla_union_object" \
53     "type = union vla_union {\r\n\\s+int vla_field\\\[5\\\];\r\n}"
55 # Check the size of the VLA's.
56 gdb_breakpoint [gdb_get_line_number "break_end_of_vla_factory"]
57 gdb_continue_to_breakpoint "break_end_of_vla_factory"
58 gdb_test "print vla_struct_object_size == sizeof(vla_struct_object)" \
59     " = 1" "size of vla_struct_object"
60 gdb_test "print vla_union_object_size == sizeof(vla_union_object)" \
61     " = 1" "size of vla_union_object"
63 set a -1
64 gdb_test_multiple "print inner_vla_struct_object_size" "" {
65     -re -wrap " = ($decimal)" {
66         set a $expect_out(1,string)
67     }
69 set b -1
70 gdb_test_multiple "print sizeof(inner_vla_struct_object)" "" {
71     -re -wrap " = ($decimal)" {
72         set b $expect_out(1,string)
73     }
75 if { [test_compiler_info "gcc-*"] && [gcc_major_version] <= 11 } {
76     # Fails due to incorrect debugging information generated by GCC.
77     setup_xfail "*-*-*"
79 gdb_assert {$a == $b} "size of inner_vla_struct_object"