1 # Copyright 2022-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 # Test the detection and printing of repeated elements 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
}]]} {
26 perror
"Could not run to main."
30 gdb_breakpoint
[gdb_get_line_number
"Break here"]
31 gdb_continue_to_breakpoint
"Break here"
33 # Build up the expected output for each array.
34 set a9p9o
"{9, 9, 9, 9, 9, 9}"
35 set a1p
"{1, 1, 1, 1, 1}"
36 set a1p9
"{1, 1, 1, 1, 1, 9}"
37 set a2po
"{2, 2, 2, 2, 2}"
38 set a2p
"{${a2po}, ${a2po}, ${a2po}, ${a2po}, ${a2po}}"
39 set a2p9o
"{2, 2, 2, 2, 2, 9}"
40 set a2p9
"{${a2p9o}, ${a2p9o}, ${a2p9o}, ${a2p9o}, ${a2p9o}, ${a9p9o}}"
41 set a3po
"{3, 3, 3, 3, 3}"
42 set a3p
"{${a3po}, ${a3po}, ${a3po}, ${a3po}, ${a3po}}"
43 set a3p
"{${a3p}, ${a3p}, ${a3p}, ${a3p}, ${a3p}}"
44 set a3p9o
"{3, 3, 3, 3, 3, 9}"
45 set a3p9
"{${a3p9o}, ${a3p9o}, ${a3p9o}, ${a3p9o}, ${a3p9o}, ${a9p9o}}"
46 set a9p9
"{${a9p9o}, ${a9p9o}, ${a9p9o}, ${a9p9o}, ${a9p9o}, ${a9p9o}}"
47 set a3p9
"{${a3p9}, ${a3p9}, ${a3p9}, ${a3p9}, ${a3p9}, ${a9p9}}"
49 # Convert the output into a regexp.
50 set r1p
[string_to_regexp
$a1p]
51 set r1p9
[string_to_regexp
$a1p9]
52 set r2po
[string_to_regexp
$a2po]
53 set r2p9o
[string_to_regexp
$a2p9o]
54 set r2p
[string_to_regexp
$a2p]
55 set r2p9
[string_to_regexp
$a2p9]
56 set r3po
[string_to_regexp
$a3po]
57 set r3p9o
[string_to_regexp
$a3p9o]
58 set r3p
[string_to_regexp
$a3p]
59 set r3p9
[string_to_regexp
$a3p9]
61 set rep5
"<repeats 5 times>"
62 set rep6
"<repeats 6 times>"
64 with_test_prefix
"repeats=unlimited, elements=unlimited" {
65 # Check the arrays print as expected.
66 gdb_test_no_output
"set print repeats unlimited"
67 gdb_test_no_output
"set print elements unlimited"
69 gdb_test
"print array_1d" "${r1p}"
70 gdb_test
"print array_1d9" "${r1p9}"
71 gdb_test
"print array_2d" "${r2p}"
72 gdb_test
"print array_2d9" "${r2p9}"
73 gdb_test
"print array_3d" "${r3p}"
74 gdb_test
"print array_3d9" "${r3p9}"
77 with_test_prefix
"repeats=4, elements=unlimited" {
78 # Now set the repeat limit.
79 gdb_test_no_output
"set print repeats 4"
80 gdb_test_no_output
"set print elements unlimited"
82 gdb_test
"print array_1d" \
83 [string_to_regexp
"{1 ${rep5}}"]
84 gdb_test
"print array_1d9" \
85 [string_to_regexp
"{1 ${rep5}, 9}"]
86 gdb_test
"print array_2d" \
87 [string_to_regexp
"{{2 ${rep5}} ${rep5}}"]
88 gdb_test
"print array_2d9" \
89 [string_to_regexp
"{{2 ${rep5}, 9} ${rep5}, {9 ${rep6}}}"]
90 gdb_test
"print array_3d" \
91 [string_to_regexp
"{{{3 ${rep5}} ${rep5}} ${rep5}}"]
92 gdb_test
"print array_3d9" \
93 [string_to_regexp
"{{{3 ${rep5}, 9} ${rep5}, {9 ${rep6}}} ${rep5},\
94 {{9 ${rep6}} ${rep6}}}"]
97 with_test_prefix
"repeats=unlimited, elements=3" {
98 # Now set the element limit.
99 gdb_test_no_output
"set print repeats unlimited"
100 gdb_test_no_output
"set print elements 3"
102 gdb_test
"print array_1d" \
103 [string_to_regexp
"{1, 1, 1...}"]
104 gdb_test
"print array_1d9" \
105 [string_to_regexp
"{1, 1, 1...}"]
106 gdb_test
"print array_2d" \
107 [string_to_regexp
"{{2, 2, 2...}, {2, 2, 2...}, {2, 2, 2...}...}"]
108 gdb_test
"print array_2d9" \
109 [string_to_regexp
"{{2, 2, 2...}, {2, 2, 2...}, {2, 2, 2...}...}"]
110 gdb_test
"print array_3d" \
111 [string_to_regexp
"{{{3, 3, 3...}, {3, 3, 3...}, {3, 3, 3...}...},\
112 {{3, 3, 3...}, {3, 3, 3...}, {3, 3, 3...}...},\
113 {{3, 3, 3...}, {3, 3, 3...}, {3, 3, 3...}...}...}"]
114 gdb_test
"print array_3d9" \
115 [string_to_regexp
"{{{3, 3, 3...}, {3, 3, 3...}, {3, 3, 3...}...},\
116 {{3, 3, 3...}, {3, 3, 3...}, {3, 3, 3...}...},\
117 {{3, 3, 3...}, {3, 3, 3...}, {3, 3, 3...}...}...}"]
120 with_test_prefix
"repeats=4, elements=12" {
121 # Now set both limits.
122 gdb_test_no_output
"set print repeats 4"
123 gdb_test_no_output
"set print elements 12"
125 gdb_test
"print array_1d" \
126 [string_to_regexp
"{1 ${rep5}}"]
127 gdb_test
"print array_1d9" \
128 [string_to_regexp
"{1 ${rep5}, 9}"]
129 gdb_test
"print array_2d" \
130 [string_to_regexp
"{{2 ${rep5}} ${rep5}}"]
131 gdb_test
"print array_2d9" \
132 [string_to_regexp
"{{2 ${rep5}, 9} ${rep5}, {9 ${rep6}}}"]
133 gdb_test
"print array_3d" \
134 [string_to_regexp
"{{{3 ${rep5}} ${rep5}} ${rep5}}"]
135 gdb_test
"print array_3d9" \
136 [string_to_regexp
"{{{3 ${rep5}, 9} ${rep5}, {9 ${rep6}}} ${rep5},\
137 {{9 ${rep6}} ${rep6}}}"]