446b61b3f9098f0af8bf95a00c06b119241a2831
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / vla-struct-fields.exp
1 # Copyright 2014-2021 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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/>.
15
16 standard_testfile
17
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
22 }
23
24 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
25 return -1
26 }
27
28 if ![runto_main] {
29 return -1
30 }
31
32 gdb_breakpoint [gdb_get_line_number "vlas_filled"]
33 gdb_continue_to_breakpoint "vlas_filled"
34
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\\\}\\\}\\\}"
44
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"
48
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}"
54
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"
62
63 # Fails due to incorrect debugging information generated by GCC.
64 setup_xfail "*-*-*"
65 gdb_test \
66 "print inner_vla_struct_object_size == sizeof(inner_vla_struct_object)" \
67 " = 1" "size of inner_vla_struct_object"
This page took 0.031528 seconds and 3 git commands to generate.