Respect `set print repeats' with Fortran arrays
Implement `set print repeats' handling for Fortran arrays. Currently
the setting is ignored and always treated as if no limit was set.
Unlike the generic array walker implemented decades ago the Fortran one
is a proper C++ class. Rather than trying to mimic the old walker then,
which turned out a bit of a challenge where interacting with the `set
print elements' setting, write it entirely from scratch, by adding an
extra specialization handler method for processing dimensions other than
the innermost one and letting the specialization class call the `walk_1'
method from the handler as it sees fit. This way repeats can be tracked
and the next inner dimension recursed into as a need arises only, or
unconditionally in the base class.
Keep track of the dimension number being handled in the class rather as
a parameter to the walker so that it does not have to be passed across
by the specialization class.
Use per-dimension element count tracking, needed to terminate processing
early when the limit set by `set print elements' is hit. This requires
extra care too where the limit triggers exactly where another element
that is a subarray begins. In that case rather than recursing we need
to terminate processing or lone `(...)' would be printed. Additionally
if the skipped element is the last one in the current dimension we need
to print `...' by hand, because `continue_walking' won't print it at the
upper level, because it can see the last element has already been taken
care of.
Preserve the existing semantics of `set print elements' where the total
count of the elements handled is matched against the trigger level which
is unlike with the C/C++ array printer where the per-dimension element
count is used instead.
Output now looks like:
(gdb) set print repeats 4
(gdb) print array_2d
$1 = ((2, <repeats 5 times>) <repeats 5 times>)
(gdb) set print elements 12
(gdb) print array_2d
$2 = ((2, <repeats 5 times>) (2, <repeats 5 times>) (2, 2, ...) ...)
(gdb)
for a 5 by 5 array filled with the value of 2.
Amend existing test cases accordingly that rely on the current incorrect
behavior and explicitly request that there be no limit for printing
repeated elements there.
Add suitable test cases as well covering sliced arrays in particular.
Co-Authored-By: Andrew Burgess <andrew.burgess@embecosm.com>
2022-01-20 05:55:10 +08:00
|
|
|
# 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
# Test the detection and printing of repeated elements in Fortran arrays.
|
|
|
|
|
|
|
|
if {[skip_fortran_tests]} { return -1 }
|
|
|
|
|
|
|
|
load_lib fortran.exp
|
|
|
|
|
|
|
|
# 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 "<repeats 5 times>"
|
|
|
|
set rep6 "<repeats 6 times>"
|
|
|
|
|
|
|
|
proc array_repeat { variant } {
|
|
|
|
global testfile srcfile binfile
|
|
|
|
upvar r1p r1p r1p9 r1p9 r2po r2po r2p9o r2p9o r2p r2p r2p9 r2p9
|
|
|
|
upvar r3po r3po r3p9o r3p9o r3p r3p r3p9 r3p9
|
|
|
|
upvar a2po a2po a2p9o a2p9o a3po a3po a3p9o a3p9o
|
|
|
|
upvar rep5 rep5 rep6 rep6
|
|
|
|
|
|
|
|
standard_testfile "${variant}.f90"
|
|
|
|
|
|
|
|
if {[prepare_for_testing ${testfile}.exp ${variant} ${srcfile} \
|
|
|
|
{debug f90}]} {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
|
|
|
if {![fortran_runto_main]} {
|
|
|
|
perror "Could not run to main."
|
2022-05-14 00:23:57 +08:00
|
|
|
return
|
Respect `set print repeats' with Fortran arrays
Implement `set print repeats' handling for Fortran arrays. Currently
the setting is ignored and always treated as if no limit was set.
Unlike the generic array walker implemented decades ago the Fortran one
is a proper C++ class. Rather than trying to mimic the old walker then,
which turned out a bit of a challenge where interacting with the `set
print elements' setting, write it entirely from scratch, by adding an
extra specialization handler method for processing dimensions other than
the innermost one and letting the specialization class call the `walk_1'
method from the handler as it sees fit. This way repeats can be tracked
and the next inner dimension recursed into as a need arises only, or
unconditionally in the base class.
Keep track of the dimension number being handled in the class rather as
a parameter to the walker so that it does not have to be passed across
by the specialization class.
Use per-dimension element count tracking, needed to terminate processing
early when the limit set by `set print elements' is hit. This requires
extra care too where the limit triggers exactly where another element
that is a subarray begins. In that case rather than recursing we need
to terminate processing or lone `(...)' would be printed. Additionally
if the skipped element is the last one in the current dimension we need
to print `...' by hand, because `continue_walking' won't print it at the
upper level, because it can see the last element has already been taken
care of.
Preserve the existing semantics of `set print elements' where the total
count of the elements handled is matched against the trigger level which
is unlike with the C/C++ array printer where the per-dimension element
count is used instead.
Output now looks like:
(gdb) set print repeats 4
(gdb) print array_2d
$1 = ((2, <repeats 5 times>) <repeats 5 times>)
(gdb) set print elements 12
(gdb) print array_2d
$2 = ((2, <repeats 5 times>) (2, <repeats 5 times>) (2, 2, ...) ...)
(gdb)
for a 5 by 5 array filled with the value of 2.
Amend existing test cases accordingly that rely on the current incorrect
behavior and explicitly request that there be no limit for printing
repeated elements there.
Add suitable test cases as well covering sliced arrays in particular.
Co-Authored-By: Andrew Burgess <andrew.burgess@embecosm.com>
2022-01-20 05:55:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gdb_breakpoint [gdb_get_line_number "Break here"]
|
|
|
|
gdb_continue_to_breakpoint "${variant}"
|
|
|
|
|
|
|
|
with_test_prefix "${variant}: repeats=unlimited, elements=unlimited" {
|
|
|
|
# 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 "${variant}: repeats=4, elements=unlimited" {
|
|
|
|
# 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 "${variant}: repeats=unlimited, elements=12" {
|
|
|
|
# Now set the element limit.
|
|
|
|
gdb_test_no_output "set print repeats unlimited"
|
|
|
|
gdb_test_no_output "set print elements 12"
|
|
|
|
|
|
|
|
gdb_test "print array_1d" "${r1p}"
|
|
|
|
gdb_test "print array_1d9" "${r1p9}"
|
|
|
|
gdb_test "print array_2d" \
|
|
|
|
[string_to_regexp "(${a2po} ${a2po} (2, 2, ...) ...)"]
|
|
|
|
gdb_test "print array_2d9" \
|
|
|
|
[string_to_regexp "(${a2p9o} ${a2p9o} ...)"]
|
|
|
|
gdb_test "print array_3d" \
|
|
|
|
[string_to_regexp "((${a3po} ${a3po} (3, 3, ...) ...) ...)"]
|
|
|
|
gdb_test "print array_3d9" \
|
|
|
|
[string_to_regexp "((${a3p9o} ${a3p9o} ...) ...)"]
|
|
|
|
}
|
|
|
|
|
|
|
|
with_test_prefix "${variant}: repeats=4, elements=12" {
|
|
|
|
# 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}) (2, ${rep5}) (2, 2, ...) ...)"]
|
|
|
|
gdb_test "print array_2d9" \
|
|
|
|
[string_to_regexp "((2, ${rep5}, 9) (2, ${rep5}, 9) ...)"]
|
|
|
|
gdb_test "print array_3d" \
|
|
|
|
[string_to_regexp "(((3, ${rep5}) (3, ${rep5}) (3, 3, ...) ...)\
|
|
|
|
...)"]
|
|
|
|
gdb_test "print array_3d9" \
|
|
|
|
[string_to_regexp "(((3, ${rep5}, 9) (3, ${rep5}, 9) ...) ...)"]
|
|
|
|
}
|
|
|
|
|
|
|
|
with_test_prefix "${variant}: repeats=4, elements=30" {
|
|
|
|
# Now set both limits.
|
|
|
|
gdb_test_no_output "set print repeats 4"
|
|
|
|
gdb_test_no_output "set print elements 30"
|
|
|
|
|
|
|
|
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} ...)"]
|
|
|
|
gdb_test "print array_3d" \
|
|
|
|
[string_to_regexp "(((3, ${rep5}) ${rep5}) ((3, ${rep5}) ...)\
|
|
|
|
...)"]
|
|
|
|
gdb_test "print array_3d9" \
|
|
|
|
[string_to_regexp "(((3, ${rep5}, 9) ${rep5} ...) ...)"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
array_repeat "array-repeat"
|
|
|
|
array_repeat "array-slices-repeat"
|