* [PATCH] Printing of Fortran arrays with dynamic elements
@ 2026-06-19 21:42 Tom Tromey
2026-06-20 12:38 ` Tom de Vries
0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2026-06-19 21:42 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
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
---
gdb/f-array-walker.h | 9 +++--
.../gdb.fortran/dynamic-elements.exp | 37 +++++++++++++++++++
.../gdb.fortran/dynamic-elements.f90 | 34 +++++++++++++++++
3 files changed, 77 insertions(+), 3 deletions(-)
create mode 100644 gdb/testsuite/gdb.fortran/dynamic-elements.exp
create mode 100644 gdb/testsuite/gdb.fortran/dynamic-elements.f90
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 @@ class fortran_array_walker
{
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
--
2.49.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Printing of Fortran arrays with dynamic elements
2026-06-19 21:42 [PATCH] Printing of Fortran arrays with dynamic elements Tom Tromey
@ 2026-06-20 12:38 ` Tom de Vries
2026-06-26 16:32 ` Tom Tromey
0 siblings, 1 reply; 3+ messages in thread
From: Tom de Vries @ 2026-06-20 12:38 UTC (permalink / raw)
To: Tom Tromey, gdb-patches
On 6/19/26 11:42 PM, Tom Tromey wrote:
> 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.
>
LGTM.
Reviewed-By: Tom de Vries <tdevries@suse.de>
Thanks,
- Tom
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34276
> ---
> gdb/f-array-walker.h | 9 +++--
> .../gdb.fortran/dynamic-elements.exp | 37 +++++++++++++++++++
> .../gdb.fortran/dynamic-elements.f90 | 34 +++++++++++++++++
> 3 files changed, 77 insertions(+), 3 deletions(-)
> create mode 100644 gdb/testsuite/gdb.fortran/dynamic-elements.exp
> create mode 100644 gdb/testsuite/gdb.fortran/dynamic-elements.f90
>
> 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 @@ class fortran_array_walker
> {
> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Printing of Fortran arrays with dynamic elements
2026-06-20 12:38 ` Tom de Vries
@ 2026-06-26 16:32 ` Tom Tromey
0 siblings, 0 replies; 3+ messages in thread
From: Tom Tromey @ 2026-06-26 16:32 UTC (permalink / raw)
To: Tom de Vries; +Cc: Tom Tromey, gdb-patches
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
Tom> On 6/19/26 11:42 PM, Tom Tromey wrote:
>> 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.
>>
Tom> LGTM.
Tom> Reviewed-By: Tom de Vries <tdevries@suse.de>
I'm checking this in.
Tom
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-06-26 16:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-19 21:42 [PATCH] Printing of Fortran arrays with dynamic elements Tom Tromey
2026-06-20 12:38 ` Tom de Vries
2026-06-26 16:32 ` Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox