1 # Copyright 2014-2021 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 # Tests to cover DW_AT_count attribute in subranges.
20 # Only run on targets which support dwarf and gas.
21 if { ![dwarf2_support] } {
25 standard_testfile main.c .S
27 set asm_file [standard_output_file $srcfile2]
28 Dwarf::assemble $asm_file {
30 compile_unit {{language @DW_LANG_C99}} {
31 declare_labels char_label \
32 array_size_type_label long_unsigned_int_label \
33 array_label array_label2 static_array_label \
34 vla_length_label vla_array_label
36 char_label: base_type {
38 {encoding @DW_ATE_signed}
39 {byte_size 1 DW_FORM_sdata}
42 array_size_type_label: base_type {
43 {byte_size 8 DW_FORM_sdata}
44 {encoding @DW_ATE_unsigned}
45 {name __ARRAY_SIZE_TYPE__}
48 long_unsigned_int_label: base_type {
49 {byte_size 8 DW_FORM_sdata}
50 {encoding @DW_ATE_unsigned}
51 {name "long unsigned int"}
54 array_label: array_type {
58 {count {DW_OP_lit5} SPECIAL_expr}
63 array_label2: array_type {
67 {count {DW_OP_lit1} SPECIAL_expr}
72 static_array_label: array_type {
76 {count 5 DW_FORM_sdata}
88 {name "__vla_array_length"}
89 {type :$long_unsigned_int_label}
90 {artificial 1 DW_FORM_flag_present}
93 vla_array_label: array_type {
97 {type :$array_size_type_label}
98 {count :$vla_length_label}
104 {type :$array_label2}
105 {const_value 65 DW_FORM_udata}
111 {const_value hello DW_FORM_block1}
116 {type :$static_array_label}
117 {const_value world DW_FORM_block1}
122 {type :$vla_array_label}
123 {const_value saluton DW_FORM_block1}
129 if { [gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile}1.o \
130 object {nodebug}] != "" } {
134 if { [gdb_compile $asm_file ${binfile}2.o object {nodebug}] != "" } {
138 if { [gdb_compile [list ${binfile}1.o ${binfile}2.o] \
139 "${binfile}" executable {}] != "" } {
144 set saved_gdbflags $GDBFLAGS
145 set GDBFLAGS [concat $GDBFLAGS " -readnow"]
146 clean_restart ${testfile}
147 set GDBFLAGS $saved_gdbflags
150 perror "couldn't run to main"
154 gdb_test "ptype array" "type = char \\\[5\\\]"
155 gdb_test "whatis array" "type = char \\\[5\\\]"
156 gdb_test "print array" " = \"hello\""
157 gdb_test "print sizeof array" " = 5"
159 gdb_test "ptype array2" "type = char \\\[1\\\]"
160 gdb_test "whatis array2" "type = char \\\[1\\\]"
161 gdb_test "print array2" " = \"A\""
162 gdb_test "print sizeof array2" " = 1"
164 gdb_test "ptype static_array" "type = char \\\[5\\\]"
165 gdb_test "whatis static_array" "type = char \\\[5\\\]"
166 gdb_test "print static_array" " = \"world\""
167 gdb_test "print sizeof static_array" " = 5"
169 gdb_test "ptype vla_array" "type = char \\\[6\\\]"
170 gdb_test "whatis vla_array" "type = char \\\[6\\\]"
171 gdb_test "print vla_array" " = \"saluto\""
172 gdb_test "print sizeof vla_array" " = 6"