1 # Copyright 2022 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 # Test the printing of element indices in C/C++ arrays.
18 standard_testfile
${srcdir
}/gdb.base
/array-repeat.c
20 if {[prepare_for_testing
${testfile
}.exp
${testfile
} ${srcfile
} \
21 [list debug
${lang
}]]} {
25 gdb_test_no_output
"set print array-indexes on"
28 perror
"Could not run to main."
32 gdb_breakpoint
[gdb_get_line_number
"Break here"]
33 gdb_continue_to_breakpoint
"Break here"
35 # Build up the expected output for each array.
42 set a9p9o
"{$n0 = 9, $n1 = 9, $n2 = 9, $n3 = 9, $n4 = 9, $n5 = 9}"
43 set a1p
"{$n0 = 1, $n1 = 1, $n2 = 1, $n3 = 1, $n4 = 1}"
44 set a1p9
"{$n0 = 1, $n1 = 1, $n2 = 1, $n3 = 1, $n4 = 1, $n5 = 9}"
45 set a2po
"{$n0 = 2, $n1 = 2, $n2 = 2, $n3 = 2, $n4 = 2}"
46 set a2p
"{$n0 = ${a2po}, $n1 = ${a2po}, $n2 = ${a2po}, $n3 = ${a2po},\
48 set a2p9o
"{$n0 = 2, $n1 = 2, $n2 = 2, $n3 = 2, $n4 = 2, $n5 = 9}"
49 set a2p9
"{$n0 = ${a2p9o}, $n1 = ${a2p9o}, $n2 = ${a2p9o}, $n3 = ${a2p9o},\
50 $n4 = ${a2p9o}, $n5 = ${a9p9o}}"
51 set a3po
"{$n0 = 3, $n1 = 3, $n2 = 3, $n3 = 3, $n4 = 3}"
52 set a3p
"{$n0 = ${a3po}, $n1 = ${a3po}, $n2 = ${a3po}, $n3 = ${a3po},\
54 set a3p
"{$n0 = ${a3p}, $n1 = ${a3p}, $n2 = ${a3p}, $n3 = ${a3p},\
56 set a3p9o
"{$n0 = 3, $n1 = 3, $n2 = 3, $n3 = 3, $n4 = 3, $n5 = 9}"
57 set a3p9
"{$n0 = ${a3p9o}, $n1 = ${a3p9o}, $n2 = ${a3p9o}, $n3 = ${a3p9o},\
58 $n4 = ${a3p9o}, $n5 = ${a9p9o}}"
59 set a9p9
"{$n0 = ${a9p9o}, $n1 = ${a9p9o}, $n2 = ${a9p9o}, $n3 = ${a9p9o},\
60 $n4 = ${a9p9o}, $n5 = ${a9p9o}}"
61 set a3p9
"{$n0 = ${a3p9}, $n1 = ${a3p9}, $n2 = ${a3p9}, $n3 = ${a3p9},\
62 $n4 = ${a3p9}, $n5 = ${a9p9}}"
64 # Convert the output into a regexp.
65 set r1p
[string_to_regexp
$a1p]
66 set r1p9
[string_to_regexp
$a1p9]
67 set r2po
[string_to_regexp
$a2po]
68 set r2p9o
[string_to_regexp
$a2p9o]
69 set r2p
[string_to_regexp
$a2p]
70 set r2p9
[string_to_regexp
$a2p9]
71 set r3po
[string_to_regexp
$a3po]
72 set r3p9o
[string_to_regexp
$a3p9o]
73 set r3p
[string_to_regexp
$a3p]
74 set r3p9
[string_to_regexp
$a3p9]
76 set rep5
"<repeats 5 times>"
77 set rep6
"<repeats 6 times>"
79 with_test_prefix
"repeats=unlimited, elements=unlimited" {
80 # Check the arrays print as expected.
81 gdb_test_no_output
"set print repeats unlimited"
82 gdb_test_no_output
"set print elements unlimited"
84 gdb_test
"print array_1d" "${r1p}"
85 gdb_test
"print array_1d9" "${r1p9}"
86 gdb_test
"print array_2d" "${r2p}"
87 gdb_test
"print array_2d9" "${r2p9}"
88 gdb_test
"print array_3d" "${r3p}"
89 gdb_test
"print array_3d9" "${r3p9}"
92 with_test_prefix
"repeats=4, elements=unlimited" {
93 # Now set the repeat limit.
94 gdb_test_no_output
"set print repeats 4"
95 gdb_test_no_output
"set print elements unlimited"
97 gdb_test
"print array_1d" \
98 [string_to_regexp
"{$n0 = 1 ${rep5}}"]
99 gdb_test
"print array_1d9" \
100 [string_to_regexp
"{$n0 = 1 ${rep5}, $n5 = 9}"]
101 gdb_test
"print array_2d" \
102 [string_to_regexp
"{$n0 = {$n0 = 2 ${rep5}} ${rep5}}"]
103 gdb_test
"print array_2d9" \
104 [string_to_regexp
"{$n0 = {$n0 = 2 ${rep5}, $n5 = 9} ${rep5},\
105 $n5 = {$n0 = 9 ${rep6}}}"]
106 gdb_test
"print array_3d" \
107 [string_to_regexp
"{$n0 = {$n0 = {$n0 = 3 ${rep5}} ${rep5}} ${rep5}}"]
108 gdb_test
"print array_3d9" \
109 [string_to_regexp
"{$n0 = {$n0 = {$n0 = 3 ${rep5}, $n5 = 9} ${rep5},\
110 $n5 = {$n0 = 9 ${rep6}}} ${rep5},\
111 $n5 = {$n0 = {$n0 = 9 ${rep6}} ${rep6}}}"]
114 with_test_prefix
"repeats=unlimited, elements=3" {
115 # Now set the element limit.
116 gdb_test_no_output
"set print repeats unlimited"
117 gdb_test_no_output
"set print elements 3"
119 gdb_test
"print array_1d" \
120 [string_to_regexp
"{$n0 = 1, $n1 = 1, $n2 = 1...}"]
121 gdb_test
"print array_1d9" \
122 [string_to_regexp
"{$n0 = 1, $n1 = 1, $n2 = 1...}"]
123 gdb_test
"print array_2d" \
124 [string_to_regexp
"{$n0 = {$n0 = 2, $n1 = 2, $n2 = 2...},\
125 $n1 = {$n0 = 2, $n1 = 2, $n2 = 2...},\
126 $n2 = {$n0 = 2, $n1 = 2, $n2 = 2...}...}"]
127 gdb_test
"print array_2d9" \
128 [string_to_regexp
"{$n0 = {$n0 = 2, $n1 = 2, $n2 = 2...},\
129 $n1 = {$n0 = 2, $n1 = 2, $n2 = 2...},\
130 $n2 = {$n0 = 2, $n1 = 2, $n2 = 2...}...}"]
131 gdb_test
"print array_3d" \
132 [string_to_regexp
"{$n0 = {$n0 = {$n0 = 3, $n1 = 3, $n2 = 3...},\
133 $n1 = {$n0 = 3, $n1 = 3, $n2 = 3...},\
134 $n2 = {$n0 = 3, $n1 = 3, $n2 = 3...}...},\
135 $n1 = {$n0 = {$n0 = 3, $n1 = 3, $n2 = 3...},\
136 $n1 = {$n0 = 3, $n1 = 3, $n2 = 3...},\
137 $n2 = {$n0 = 3, $n1 = 3, $n2 = 3...}...},\
138 $n2 = {$n0 = {$n0 = 3, $n1 = 3, $n2 = 3...},\
139 $n1 = {$n0 = 3, $n1 = 3, $n2 = 3...},\
140 $n2 = {$n0 = 3, $n1 = 3,\
141 $n2 = 3...}...}...}"]
142 gdb_test
"print array_3d9" \
143 [string_to_regexp
"{$n0 = {$n0 = {$n0 = 3, $n1 = 3, $n2 = 3...},\
144 $n1 = {$n0 = 3, $n1 = 3, $n2 = 3...},\
145 $n2 = {$n0 = 3, $n1 = 3, $n2 = 3...}...},\
146 $n1 = {$n0 = {$n0 = 3, $n1 = 3, $n2 = 3...},\
147 $n1 = {$n0 = 3, $n1 = 3, $n2 = 3...},\
148 $n2 = {$n0 = 3, $n1 = 3, $n2 = 3...}...},\
149 $n2 = {$n0 = {$n0 = 3, $n1 = 3, $n2 = 3...},\
150 $n1 = {$n0 = 3, $n1 = 3, $n2 = 3...},\
151 $n2 = {$n0 = 3, $n1 = 3,\
152 $n2 = 3...}...}...}"]
155 with_test_prefix
"repeats=4, elements=12" {
156 # Now set both limits.
157 gdb_test_no_output
"set print repeats 4"
158 gdb_test_no_output
"set print elements 12"
160 gdb_test
"print array_1d" \
161 [string_to_regexp
"{$n0 = 1 ${rep5}}"]
162 gdb_test
"print array_1d9" \
163 [string_to_regexp
"{$n0 = 1 ${rep5}, $n5 = 9}"]
164 gdb_test
"print array_2d" \
165 [string_to_regexp
"{$n0 = {$n0 = 2 ${rep5}} ${rep5}}"]
166 gdb_test
"print array_2d9" \
167 [string_to_regexp
"{$n0 = {$n0 = 2 ${rep5}, $n5 = 9} ${rep5},\
168 $n5 = {$n0 = 9 ${rep6}}}"]
169 gdb_test
"print array_3d" \
170 [string_to_regexp
"{$n0 = {$n0 = {$n0 = 3 ${rep5}} ${rep5}} ${rep5}}"]
171 gdb_test
"print array_3d9" \
172 [string_to_regexp
"{$n0 = {$n0 = {$n0 = 3 ${rep5}, $n5 = 9} ${rep5},\
173 $n5 = {$n0 = 9 ${rep6}}} ${rep5},\
174 $n5 = {$n0 = {$n0 = 9 ${rep6}} ${rep6}}}"]