[binutils-gdb] Printing of Fortran arrays with dynamic elements
Tom Tromey via Gdb-cvs <[email protected]> Fri, 26 Jun 2026 16:48:53 +0000 (GMT)
| Newsgroups | gmane.comp.gdb.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=108db853326a1335fadb6d0ad9955dd7714b1ce1 commit 108db853326a1335fadb6d0ad9955dd7714b1ce1 Author: Tom Tromey <[email protected]> Date: Fri Jun 19 15:23:47 2026 -0600 Printing of Fortran arrays with dynamic elements This bug points out a case where a Fortran array has dynamic elements, and each element must have its dynamic type resolved separately. I took the test case directly from the bug, figuring it was ok as the author is at AMD and has some tags in the repository already. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34276 Reviewed-By: Tom de Vries <[email protected]> Diff: --- gdb/f-array-walker.h | 9 ++++--- gdb/testsuite/gdb.fortran/dynamic-elements.exp | 37 ++++++++++++++++++++++++++ gdb/testsuite/gdb.fortran/dynamic-elements.f90 | 34 +++++++++++++++++++++++ 3 files changed, 77 insertions(+), 3 deletions(-) diff --git a/gdb/f-array-walker.h b/gdb/f-array-walker.h index bb8cb0ca599..4392e54013b 100644 --- a/gdb/f-array-walker.h +++ b/gdb/f-array-walker.h @@ -267,13 +267,16 @@ private: { LONGEST elt_off = offset + calc.index_offset (i); - if (is_dynamic_type (elt_type)) + struct type *this_elt_type = elt_type; + if (is_dynamic_type (this_elt_type)) { CORE_ADDR e_address = m_address + elt_off; - elt_type = resolve_dynamic_type (elt_type, {}, e_address); + this_elt_type = resolve_dynamic_type (this_elt_type, {}, + e_address); } - m_impl.process_element (elt_type, elt_off, i, i == upperbound); + m_impl.process_element (this_elt_type, elt_off, i, + i == upperbound); } } diff --git a/gdb/testsuite/gdb.fortran/dynamic-elements.exp b/gdb/testsuite/gdb.fortran/dynamic-elements.exp new file mode 100644 index 00000000000..4a83ad09438 --- /dev/null +++ b/gdb/testsuite/gdb.fortran/dynamic-elements.exp @@ -0,0 +1,37 @@ +# Copyright 2026 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 where an array has elements of dynamic type, where each element +# is different. + +require allow_fortran_tests + +standard_testfile .f90 +load_lib "fortran.exp" + +if {[prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \ + {debug f90}]} { + return +} + +if {![fortran_runto_main]} { + return +} + +gdb_breakpoint [gdb_get_line_number "stop"] +gdb_continue_to_breakpoint "stop" + +gdb_test "print keys" \ + [quotemeta "@DECIMAL = (( f = (1, 2) ), ( f = (3, 4, 5) ))"] diff --git a/gdb/testsuite/gdb.fortran/dynamic-elements.f90 b/gdb/testsuite/gdb.fortran/dynamic-elements.f90 new file mode 100644 index 00000000000..61a2b6edb3c --- /dev/null +++ b/gdb/testsuite/gdb.fortran/dynamic-elements.f90 @@ -0,0 +1,34 @@ +! Copyright 2026 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/>. + +program test + implicit none + + type :: arr + integer, allocatable :: f (:) + end type + + type(arr), dimension(2) :: keys + allocate (keys(1)%f(2)) + allocate (keys(2)%f(3)) + keys(1)%f(1) = 1 + keys(1)%f(2) = 2 + keys(2)%f(1) = 3 + keys(2)%f(2) = 4 + keys(2)%f(3) = 5 + print *, keys(1)%f(1) ! stop + print *, keys(2)%f(1) + +end program test