mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-27 04:52:05 +08:00
476f77a94c
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>
97 lines
3.9 KiB
Plaintext
97 lines
3.9 KiB
Plaintext
# Copyright 2015-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/>.
|
|
|
|
standard_testfile "vla-sub.f90"
|
|
load_lib fortran.exp
|
|
|
|
if {[skip_fortran_tests]} { return -1 }
|
|
|
|
if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
|
|
{debug f90 quiet}] } {
|
|
return -1
|
|
}
|
|
|
|
if ![fortran_runto_main] {
|
|
return -1
|
|
}
|
|
|
|
# Check the values of VLA's in subroutine can be evaluated correctly
|
|
|
|
gdb_test_no_output "set print repeats unlimited"
|
|
|
|
# Try to access values from a fixed array handled as VLA in subroutine.
|
|
gdb_breakpoint [gdb_get_line_number "not-filled"]
|
|
gdb_continue_to_breakpoint "not-filled (1st)"
|
|
gdb_test "print array1" " = \\(\[()1, .\]*\\)" \
|
|
"print passed array1 in foo (passed fixed array)"
|
|
|
|
gdb_breakpoint [gdb_get_line_number "array1-filled"]
|
|
gdb_continue_to_breakpoint "array1-filled (1st)"
|
|
gdb_test "print array1(5, 7)" " = 5" \
|
|
"print array1(5, 7) after filled in foo (passed fixed array)"
|
|
gdb_test "print array1(1, 1)" " = 30" \
|
|
"print array1(1, 1) after filled in foo (passed fixed array)"
|
|
|
|
gdb_breakpoint [gdb_get_line_number "array2-almost-filled"]
|
|
gdb_continue_to_breakpoint "array2-almost-filled (1st)"
|
|
# array2 size is 296352 bytes.
|
|
gdb_test_no_output "set max-value-size 1024*1024"
|
|
gdb_test "print array2" " = \\( *\\( *\\( *30, *3, *3,\[()3, .\]*\\)" \
|
|
"print array2 in foo after it was filled (passed fixed array)"
|
|
gdb_test "print array2(2,1,1)=20" " = 20" \
|
|
"set array(2,2,2) to 20 in subroutine (passed fixed array)"
|
|
gdb_test "print array2" " = \\( *\\( *\\( *30, *20, *3,\[()3, .\]*\\)" \
|
|
"print array2 in foo after it was mofified in debugger (passed fixed array)"
|
|
|
|
|
|
# Try to access values from a fixed sub-array handled as VLA in subroutine.
|
|
gdb_continue_to_breakpoint "not-filled (2nd)"
|
|
gdb_test "print array1" " = \\(\[()5, .\]*\\)" \
|
|
"print passed array1 in foo (passed sub-array)"
|
|
|
|
gdb_continue_to_breakpoint "array1-filled (2nd)"
|
|
gdb_test "print array1(5, 5)" " = 5" \
|
|
"print array1(5, 5) after filled in foo (passed sub-array)"
|
|
gdb_test "print array1(1, 1)" " = 30" \
|
|
"print array1(1, 1) after filled in foo (passed sub-array)"
|
|
|
|
gdb_continue_to_breakpoint "array2-almost-filled (2nd)"
|
|
gdb_test "print array2" " = \\( *\\( *\\( *30, *3, *3,\[()3, .\]*\\)" \
|
|
"print array2 in foo after it was filled (passed sub-array)"
|
|
gdb_test "print array2(2,1,1)=20" " = 20" \
|
|
"set array(2,2,2) to 20 in subroutine (passed sub-array)"
|
|
gdb_test "print array2" " = \\( *\\( *\\( *30, *20, *3,\[()3, .\]*\\)" \
|
|
"print array2 in foo after it was mofified in debugger (passed sub-array)"
|
|
|
|
|
|
# Try to access values from a VLA passed to subroutine.
|
|
gdb_continue_to_breakpoint "not-filled (3rd)"
|
|
gdb_test "print array1" " = \\(\[()42, .\]*\\)" \
|
|
"print passed array1 in foo (passed vla)"
|
|
|
|
gdb_continue_to_breakpoint "array1-filled (3rd)"
|
|
gdb_test "print array1(5, 5)" " = 5" \
|
|
"print array1(5, 5) after filled in foo (passed vla)"
|
|
gdb_test "print array1(1, 1)" " = 30" \
|
|
"print array1(1, 1) after filled in foo (passed vla)"
|
|
|
|
gdb_continue_to_breakpoint "array2-almost-filled (3rd)"
|
|
gdb_test "print array2" " = \\( *\\( *\\( *30, *3, *3,\[()3, .\]*\\)" \
|
|
"print array2 in foo after it was filled (passed vla)"
|
|
gdb_test "print array2(2,1,1)=20" " = 20" \
|
|
"set array(2,2,2) to 20 in subroutine (passed vla)"
|
|
gdb_test "print array2" " = \\( *\\( *\\( *30, *20, *3,\[()3, .\]*\\)" \
|
|
"print array2 in foo after it was mofified in debugger (passed vla)"
|