xref: /netbsd-src/external/gpl3/gdb/dist/gdb/testsuite/gdb.base/array-repeat.exp.tcl (revision d16b7486a53dcb8072b60ec6fcb4373a2d0c27b7)
1# Copyright 2022-2023 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# Test the detection and printing of repeated elements in C/C++ arrays.
17
18standard_testfile ${srcdir}/gdb.base/array-repeat.c
19
20if {[prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
21	[list debug ${lang}]]} {
22    return -1
23}
24
25if {![runto_main]} {
26    perror "Could not run to main."
27    continue
28}
29
30gdb_breakpoint [gdb_get_line_number "Break here"]
31gdb_continue_to_breakpoint "Break here"
32
33# Build up the expected output for each array.
34set a9p9o "{9, 9, 9, 9, 9, 9}"
35set a1p   "{1, 1, 1, 1, 1}"
36set a1p9  "{1, 1, 1, 1, 1, 9}"
37set a2po  "{2, 2, 2, 2, 2}"
38set a2p   "{${a2po}, ${a2po}, ${a2po}, ${a2po}, ${a2po}}"
39set a2p9o "{2, 2, 2, 2, 2, 9}"
40set a2p9  "{${a2p9o}, ${a2p9o}, ${a2p9o}, ${a2p9o}, ${a2p9o}, ${a9p9o}}"
41set a3po  "{3, 3, 3, 3, 3}"
42set a3p   "{${a3po}, ${a3po}, ${a3po}, ${a3po}, ${a3po}}"
43set a3p   "{${a3p}, ${a3p}, ${a3p}, ${a3p}, ${a3p}}"
44set a3p9o "{3, 3, 3, 3, 3, 9}"
45set a3p9  "{${a3p9o}, ${a3p9o}, ${a3p9o}, ${a3p9o}, ${a3p9o}, ${a9p9o}}"
46set a9p9  "{${a9p9o}, ${a9p9o}, ${a9p9o}, ${a9p9o}, ${a9p9o}, ${a9p9o}}"
47set a3p9  "{${a3p9}, ${a3p9}, ${a3p9}, ${a3p9}, ${a3p9}, ${a9p9}}"
48
49# Convert the output into a regexp.
50set r1p   [string_to_regexp $a1p]
51set r1p9  [string_to_regexp $a1p9]
52set r2po  [string_to_regexp $a2po]
53set r2p9o [string_to_regexp $a2p9o]
54set r2p   [string_to_regexp $a2p]
55set r2p9  [string_to_regexp $a2p9]
56set r3po  [string_to_regexp $a3po]
57set r3p9o [string_to_regexp $a3p9o]
58set r3p   [string_to_regexp $a3p]
59set r3p9  [string_to_regexp $a3p9]
60
61set rep5  "<repeats 5 times>"
62set rep6  "<repeats 6 times>"
63
64with_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"
68
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}"
75}
76
77with_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"
81
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}}}"]
95}
96
97with_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"
101
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...}...}...}"]
118}
119
120with_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"
124
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}}}"]
138}
139