xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.base/arrayidx.exp (revision 8b657b0747480f8989760d71343d6dd33f8d4cf9)
1# Copyright 2005-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# This file is part of the gdb testsuite.  It is intended to test that
17# gdb can correctly print arrays with indexes for each element of the
18# array.
19
20standard_testfile .c
21
22if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
23    untested "failed to compile"
24    return -1
25}
26
27clean_restart ${binfile}
28
29if {![runto_main]} {
30    return
31}
32
33# First, print the array without the indexes
34
35gdb_test_no_output "set print array-indexes off" \
36         "set print array-indexes to off"
37
38gdb_test "show print array-indexes" \
39         "Printing of array indexes is off\\." \
40         "show print array-indexes is off"
41
42gdb_test "print array" \
43         "\\{1, 2, 3, 4\\}" \
44         "print array with array-indexes off"
45
46# Second, print the same array with the indexes
47
48gdb_test_no_output "set print array-indexes on" \
49         "set print array-indexes to on"
50
51gdb_test "show print array-indexes" \
52         "Printing of array indexes is on\\." \
53         "show print array-indexes is on"
54
55gdb_test "print array" \
56         "\\{\\\[0\\\] = 1, \\\[1\\\] = 2, \\\[2\\\] = 3, \\\[3\\\] = 4\\}" \
57         "print array with array-indexes on"
58
59
60