]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.dwarf2/count.exp
Automatic Copyright Year update after running gdb/copyright.py
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / count.exp
CommitLineData
4a94e368 1# Copyright 2014-2022 Free Software Foundation, Inc.
3dd170be
SA
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# Tests to cover DW_AT_count attribute in subranges.
17
18load_lib dwarf.exp
19
20# Only run on targets which support dwarf and gas.
21if { ![dwarf2_support] } {
22 return 0
23}
24
d1c8a76d 25standard_testfile main.c .S
3dd170be
SA
26
27set asm_file [standard_output_file $srcfile2]
28Dwarf::assemble $asm_file {
29 cu {} {
30 compile_unit {{language @DW_LANG_C99}} {
117c628d
GB
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
3dd170be
SA
35
36 char_label: base_type {
37 {name char}
38 {encoding @DW_ATE_signed}
39 {byte_size 1 DW_FORM_sdata}
40 }
41
117c628d
GB
42 array_size_type_label: base_type {
43 {byte_size 8 DW_FORM_sdata}
44 {encoding @DW_ATE_unsigned}
45 {name __ARRAY_SIZE_TYPE__}
46 }
47
48 long_unsigned_int_label: base_type {
49 {byte_size 8 DW_FORM_sdata}
50 {encoding @DW_ATE_unsigned}
51 {name "long unsigned int"}
52 }
53
3dd170be
SA
54 array_label: array_type {
55 {type :$char_label}
56 } {
57 subrange_type {
58 {count {DW_OP_lit5} SPECIAL_expr}
59 {type :$char_label}
60 }
61 }
62
63 array_label2: array_type {
64 {type :$char_label}
65 } {
66 subrange_type {
67 {count {DW_OP_lit1} SPECIAL_expr}
68 {type :$char_label}
69 }
70 }
71
72 static_array_label: array_type {
73 {type :$char_label}
74 } {
75 subrange_type {
76 {count 5 DW_FORM_sdata}
77 {type :$char_label}
78 }
79 }
80
117c628d
GB
81 vla_length_label:
82 DW_TAG_variable {
83 {location
84 {
85 lit6
86 stack_value
87 } SPECIAL_expr}
88 {name "__vla_array_length"}
89 {type :$long_unsigned_int_label}
90 {artificial 1 DW_FORM_flag_present}
91 }
92
93 vla_array_label: array_type {
94 {type :$char_label}
95 } {
96 subrange_type {
97 {type :$array_size_type_label}
98 {count :$vla_length_label}
99 }
100 }
101
3dd170be
SA
102 DW_TAG_variable {
103 {name array2}
104 {type :$array_label2}
105 {const_value 65 DW_FORM_udata}
106 }
107
108 DW_TAG_variable {
109 {name array}
110 {type :$array_label}
111 {const_value hello DW_FORM_block1}
112 }
113
114 DW_TAG_variable {
115 {name static_array}
116 {type :$static_array_label}
117 {const_value world DW_FORM_block1}
118 }
117c628d
GB
119
120 DW_TAG_variable {
121 {name vla_array}
122 {type :$vla_array_label}
123 {const_value saluton DW_FORM_block1}
124 }
3dd170be
SA
125 }
126 }
127}
128
129if { [gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile}1.o \
130 object {nodebug}] != "" } {
131 return -1
132}
133
134if { [gdb_compile $asm_file ${binfile}2.o object {nodebug}] != "" } {
135 return -1
136}
137
138if { [gdb_compile [list ${binfile}1.o ${binfile}2.o] \
139 "${binfile}" executable {}] != "" } {
140 return -1
141}
142
143global GDBFLAGS
144set saved_gdbflags $GDBFLAGS
145set GDBFLAGS [concat $GDBFLAGS " -readnow"]
146clean_restart ${testfile}
147set GDBFLAGS $saved_gdbflags
148
149if ![runto_main] {
150 perror "couldn't run to main"
151 return -1
152}
153
d1e36019
TV
154gdb_test "ptype array" "type = char \\\[5\\\]"
155gdb_test "whatis array" "type = char \\\[5\\\]"
156gdb_test "print array" " = \"hello\""
157gdb_test "print sizeof array" " = 5"
158
159gdb_test "ptype array2" "type = char \\\[1\\\]"
160gdb_test "whatis array2" "type = char \\\[1\\\]"
161gdb_test "print array2" " = \"A\""
162gdb_test "print sizeof array2" " = 1"
163
164gdb_test "ptype static_array" "type = char \\\[5\\\]"
165gdb_test "whatis static_array" "type = char \\\[5\\\]"
166gdb_test "print static_array" " = \"world\""
167gdb_test "print sizeof static_array" " = 5"
117c628d 168
117c628d 169gdb_test "ptype vla_array" "type = char \\\[6\\\]"
117c628d 170gdb_test "whatis vla_array" "type = char \\\[6\\\]"
117c628d 171gdb_test "print vla_array" " = \"saluto\""
117c628d 172gdb_test "print sizeof vla_array" " = 6"