From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1256) id C020D385800A; Wed, 19 Jan 2022 21:57:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C020D385800A Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Maciej W. Rozycki To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Add `set print repeats' tests for C/C++ arrays X-Act-Checkin: binutils-gdb X-Git-Author: Maciej W. Rozycki X-Git-Refname: refs/heads/master X-Git-Oldrev: 476f77a94cd51aede979e1b54c46cebe2ec9dde9 X-Git-Newrev: 6b4338c868e96a549af44fdf17141f4eac77e225 Message-Id: <20220119215714.C020D385800A@sourceware.org> Date: Wed, 19 Jan 2022 21:57:14 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 Jan 2022 21:57:14 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D6b4338c868e9= 6a549af44fdf17141f4eac77e225 commit 6b4338c868e96a549af44fdf17141f4eac77e225 Author: Maciej W. Rozycki Date: Wed Jan 19 21:55:10 2022 +0000 Add `set print repeats' tests for C/C++ arrays =20 Add `set print repeats' tests for C/C++ arrays, complementing one for Fortran arrays and covering the different interpretation of the `set print elements' setting in particular where the per-dimension count of the elements handled is matched against the trigger rather than the total element count as with Fortran arrays. Diff: --- gdb/testsuite/gdb.base/array-repeat.c | 63 +++++++++++++ gdb/testsuite/gdb.base/array-repeat.exp | 20 ++++ gdb/testsuite/gdb.base/array-repeat.exp.tcl | 138 ++++++++++++++++++++++++= ++++ gdb/testsuite/gdb.cp/array-repeat.exp | 22 +++++ 4 files changed, 243 insertions(+) diff --git a/gdb/testsuite/gdb.base/array-repeat.c b/gdb/testsuite/gdb.base= /array-repeat.c new file mode 100644 index 00000000000..6682b8c3e30 --- /dev/null +++ b/gdb/testsuite/gdb.base/array-repeat.c @@ -0,0 +1,63 @@ +/* Copyright 2022 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . = */ + +#include + +int +main (void) +{ + int array_1d[5]; + int array_1d9[6]; + int array_2d[5][5]; + int array_2d9[6][6]; + int array_3d[5][5][5]; + int array_3d9[6][6][6]; + int i; + + for (i =3D 0; i < sizeof (array_1d) / sizeof (int); i++) + *(array_1d + i) =3D 1; + for (i =3D 0; i < sizeof (array_1d9) / sizeof (int); i++) + *(array_1d9 + i) =3D i % 6 =3D=3D 5 ? 9 : 1; + for (i =3D 0; i < sizeof (array_2d) / sizeof (int); i++) + *(*array_2d + i) =3D 2; + for (i =3D 0; i < sizeof (array_2d9) / sizeof (int); i++) + *(*array_2d9 + i) =3D i / 6 =3D=3D 5 || i % 6 =3D=3D 5 ? 9 : 2; + for (i =3D 0; i < sizeof (array_3d) / sizeof (int); i++) + *(**array_3d + i) =3D 3; + for (i =3D 0; i < sizeof (array_3d9) / sizeof (int); i++) + *(**array_3d9 + i) =3D i / 6 / 6 =3D=3D 5 || i / 6 % 6 =3D=3D 5 || i %= 6 =3D=3D 5 ? 9 : 3; + + printf("\n"); /* Break here */ + for (i =3D 0; i < sizeof (array_1d) / sizeof (int); i++) + printf(" %d", *(array_1d + i)); + printf("\n"); + for (i =3D 0; i < sizeof (array_1d9) / sizeof (int); i++) + printf(" %d", *(array_1d9 + i)); + printf("\n"); + for (i =3D 0; i < sizeof (array_2d) / sizeof (int); i++) + printf(" %d", *(*array_2d + i)); + printf("\n"); + for (i =3D 0; i < sizeof (array_2d9) / sizeof (int); i++) + printf(" %d", *(*array_2d9 + i)); + printf("\n"); + for (i =3D 0; i < sizeof (array_3d) / sizeof (int); i++) + printf(" %d", *(**array_3d + i)); + printf("\n"); + for (i =3D 0; i < sizeof (array_3d9) / sizeof (int); i++) + printf(" %d", *(**array_3d9 + i)); + printf("\n"); + + return 0; +} diff --git a/gdb/testsuite/gdb.base/array-repeat.exp b/gdb/testsuite/gdb.ba= se/array-repeat.exp new file mode 100644 index 00000000000..685d520109e --- /dev/null +++ b/gdb/testsuite/gdb.base/array-repeat.exp @@ -0,0 +1,20 @@ +# Copyright 2022 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test the detection and printing of repeated elements in C arrays. + +set lang c + +source $srcdir/$subdir/array-repeat.exp.tcl diff --git a/gdb/testsuite/gdb.base/array-repeat.exp.tcl b/gdb/testsuite/gd= b.base/array-repeat.exp.tcl new file mode 100644 index 00000000000..2a8c0887283 --- /dev/null +++ b/gdb/testsuite/gdb.base/array-repeat.exp.tcl @@ -0,0 +1,138 @@ +# Copyright 2022 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test the detection and printing of repeated elements in C/C++ arrays. + +standard_testfile ${srcdir}/gdb.base/array-repeat.c + +if {[prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \ + [list debug ${lang}]]} { + return -1 +} + +if {![runto_main]} { + perror "Could not run to main." + continue +} + +gdb_breakpoint [gdb_get_line_number "Break here"] +gdb_continue_to_breakpoint "Break here" + +# Build up the expected output for each array. +set a9p9o "{9, 9, 9, 9, 9, 9}" +set a1p "{1, 1, 1, 1, 1}" +set a1p9 "{1, 1, 1, 1, 1, 9}" +set a2po "{2, 2, 2, 2, 2}" +set a2p "{${a2po}, ${a2po}, ${a2po}, ${a2po}, ${a2po}}" +set a2p9o "{2, 2, 2, 2, 2, 9}" +set a2p9 "{${a2p9o}, ${a2p9o}, ${a2p9o}, ${a2p9o}, ${a2p9o}, ${a9p9o}}" +set a3po "{3, 3, 3, 3, 3}" +set a3p "{${a3po}, ${a3po}, ${a3po}, ${a3po}, ${a3po}}" +set a3p "{${a3p}, ${a3p}, ${a3p}, ${a3p}, ${a3p}}" +set a3p9o "{3, 3, 3, 3, 3, 9}" +set a3p9 "{${a3p9o}, ${a3p9o}, ${a3p9o}, ${a3p9o}, ${a3p9o}, ${a9p9o}}" +set a9p9 "{${a9p9o}, ${a9p9o}, ${a9p9o}, ${a9p9o}, ${a9p9o}, ${a9p9o}}" +set a3p9 "{${a3p9}, ${a3p9}, ${a3p9}, ${a3p9}, ${a3p9}, ${a9p9}}" + +# Convert the output into a regexp. +set r1p [string_to_regexp $a1p] +set r1p9 [string_to_regexp $a1p9] +set r2po [string_to_regexp $a2po] +set r2p9o [string_to_regexp $a2p9o] +set r2p [string_to_regexp $a2p] +set r2p9 [string_to_regexp $a2p9] +set r3po [string_to_regexp $a3po] +set r3p9o [string_to_regexp $a3p9o] +set r3p [string_to_regexp $a3p] +set r3p9 [string_to_regexp $a3p9] + +set rep5 "" +set rep6 "" + +with_test_prefix "repeats=3Dunlimited, elements=3Dunlimited" { + # Check the arrays print as expected. + gdb_test_no_output "set print repeats unlimited" + gdb_test_no_output "set print elements unlimited" + + gdb_test "print array_1d" "${r1p}" + gdb_test "print array_1d9" "${r1p9}" + gdb_test "print array_2d" "${r2p}" + gdb_test "print array_2d9" "${r2p9}" + gdb_test "print array_3d" "${r3p}" + gdb_test "print array_3d9" "${r3p9}" +} + +with_test_prefix "repeats=3D4, elements=3Dunlimited" { + # Now set the repeat limit. + gdb_test_no_output "set print repeats 4" + gdb_test_no_output "set print elements unlimited" + + gdb_test "print array_1d" \ + [string_to_regexp "{1 ${rep5}}"] + gdb_test "print array_1d9" \ + [string_to_regexp "{1 ${rep5}, 9}"] + gdb_test "print array_2d" \ + [string_to_regexp "{{2 ${rep5}} ${rep5}}"] + gdb_test "print array_2d9" \ + [string_to_regexp "{{2 ${rep5}, 9} ${rep5}, {9 ${rep6}}}"] + gdb_test "print array_3d" \ + [string_to_regexp "{{{3 ${rep5}} ${rep5}} ${rep5}}"] + gdb_test "print array_3d9" \ + [string_to_regexp "{{{3 ${rep5}, 9} ${rep5}, {9 ${rep6}}} ${rep5},\ + {{9 ${rep6}} ${rep6}}}"] +} + +with_test_prefix "repeats=3Dunlimited, elements=3D3" { + # Now set the element limit. + gdb_test_no_output "set print repeats unlimited" + gdb_test_no_output "set print elements 3" + + gdb_test "print array_1d" \ + [string_to_regexp "{1, 1, 1...}"] + gdb_test "print array_1d9" \ + [string_to_regexp "{1, 1, 1...}"] + gdb_test "print array_2d" \ + [string_to_regexp "{{2, 2, 2...}, {2, 2, 2...}, {2, 2, 2...}...}"] + gdb_test "print array_2d9" \ + [string_to_regexp "{{2, 2, 2...}, {2, 2, 2...}, {2, 2, 2...}...}"] + gdb_test "print array_3d" \ + [string_to_regexp "{{{3, 3, 3...}, {3, 3, 3...}, {3, 3, 3...}...},\ + {{3, 3, 3...}, {3, 3, 3...}, {3, 3, 3...}...},\ + {{3, 3, 3...}, {3, 3, 3...}, {3, 3, 3...}...}...}"] + gdb_test "print array_3d9" \ + [string_to_regexp "{{{3, 3, 3...}, {3, 3, 3...}, {3, 3, 3...}...},\ + {{3, 3, 3...}, {3, 3, 3...}, {3, 3, 3...}...},\ + {{3, 3, 3...}, {3, 3, 3...}, {3, 3, 3...}...}...}"] +} + +with_test_prefix "repeats=3D4, elements=3D12" { + # Now set both limits. + gdb_test_no_output "set print repeats 4" + gdb_test_no_output "set print elements 12" + + gdb_test "print array_1d" \ + [string_to_regexp "{1 ${rep5}}"] + gdb_test "print array_1d9" \ + [string_to_regexp "{1 ${rep5}, 9}"] + gdb_test "print array_2d" \ + [string_to_regexp "{{2 ${rep5}} ${rep5}}"] + gdb_test "print array_2d9" \ + [string_to_regexp "{{2 ${rep5}, 9} ${rep5}, {9 ${rep6}}}"] + gdb_test "print array_3d" \ + [string_to_regexp "{{{3 ${rep5}} ${rep5}} ${rep5}}"] + gdb_test "print array_3d9" \ + [string_to_regexp "{{{3 ${rep5}, 9} ${rep5}, {9 ${rep6}}} ${rep5},\ + {{9 ${rep6}} ${rep6}}}"] +} diff --git a/gdb/testsuite/gdb.cp/array-repeat.exp b/gdb/testsuite/gdb.cp/a= rray-repeat.exp new file mode 100644 index 00000000000..d631bb47e4f --- /dev/null +++ b/gdb/testsuite/gdb.cp/array-repeat.exp @@ -0,0 +1,22 @@ +# Copyright 2022 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test the detection and printing of repeated elements in C++ arrays. + +if {[skip_cplus_tests]} { continue } + +set lang c++ + +source ${srcdir}/gdb.base/array-repeat.exp.tcl