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>
51 lines
1.4 KiB
Fortran
51 lines
1.4 KiB
Fortran
! 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/>.
|
|
|
|
!
|
|
! Start of test program.
|
|
!
|
|
program test
|
|
|
|
! Declare variables used in this test.
|
|
integer, dimension (-2:2) :: array_1d
|
|
integer, dimension (-2:3) :: array_1d9
|
|
integer, dimension (-2:2, -2:2) :: array_2d
|
|
integer, dimension (-2:3, -2:3) :: array_2d9
|
|
integer, dimension (-2:2, -2:2, -2:2) :: array_3d
|
|
integer, dimension (-2:3, -2:3, -2:3) :: array_3d9
|
|
|
|
array_1d = 1
|
|
array_1d9 = 1
|
|
array_1d9 (3) = 9
|
|
array_2d = 2
|
|
array_2d9 = 2
|
|
array_2d9 (3, :) = 9
|
|
array_2d9 (:, 3) = 9
|
|
array_3d = 3
|
|
array_3d9 = 3
|
|
array_3d9 (3, :, :) = 9
|
|
array_3d9 (:, 3, :) = 9
|
|
array_3d9 (:, :, 3) = 9
|
|
|
|
print *, "" ! Break here
|
|
print *, array_1d
|
|
print *, array_1d9
|
|
print *, array_2d
|
|
print *, array_2d9
|
|
print *, array_3d
|
|
print *, array_3d9
|
|
|
|
end program test
|