xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.fortran/vla-value.exp (revision 6881a4007f077b54e5f51159c52b9b25f57deb0d)
1# Copyright 2015-2023 Free Software Foundation, Inc.
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16standard_testfile "vla.f90"
17load_lib "fortran.exp"
18
19if {[skip_fortran_tests]} { return -1 }
20
21if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
22     {debug f90 quiet}] } {
23    return -1
24}
25
26if ![fortran_runto_main] {
27    return -1
28}
29
30# Depending on the compiler being used,
31# the type names can be printed differently.
32set real [fortran_real4]
33
34# Try to access values in non allocated VLA
35gdb_breakpoint [gdb_get_line_number "vla1-init"]
36gdb_continue_to_breakpoint "vla1-init"
37gdb_test "print vla1" " = <not allocated>" "print non-allocated vla1"
38gdb_test "print &vla1" \
39  " = \\\(PTR TO -> \\\( $real, allocatable \\\(:,:,:\\\) \\\)\\\) $hex" \
40  "print non-allocated &vla1"
41gdb_test "print vla1(1,1,1)" "no such vector element \\\(vector not allocated\\\)" \
42  "print member in non-allocated vla1 (1)"
43gdb_test "print vla1(101,202,303)" \
44  "no such vector element \\\(vector not allocated\\\)" \
45  "print member in non-allocated vla1 (2)"
46gdb_test "print vla1(5,2,18)=1" "no such vector element \\\(vector not allocated\\\)" \
47  "set member in non-allocated vla1"
48
49# Try to access value in allocated VLA
50gdb_breakpoint [gdb_get_line_number "vla2-allocated"]
51gdb_continue_to_breakpoint "vla2-allocated"
52# Many instructions to be executed when step over this line, and it is
53# slower in remote debugging.  Increase the timeout to avoid timeout
54# fail.
55with_timeout_factor 15 {
56    gdb_test "next" "\\d+(\\t|\\s)+vla1\\\(3, 6, 9\\\) = 42" \
57	"step over value assignment of vla1"
58}
59gdb_test "print &vla1" \
60  " = \\\(PTR TO -> \\\( $real, allocatable \\\(10,10,10\\\) \\\)\\\) $hex" \
61  "print allocated &vla1"
62gdb_test "print vla1(3, 6, 9)" " = 1311" "print allocated vla1(3,6,9)"
63gdb_test "print vla1(1, 3, 8)" " = 1311" "print allocated vla1(1,3,8)"
64gdb_test "print vla1(9, 9, 9) = 999" " = 999" \
65  "print allocated vla1(9,9,9)=999"
66
67# Try to access values in allocated VLA after specific assignment
68gdb_breakpoint [gdb_get_line_number "vla1-filled"]
69gdb_continue_to_breakpoint "vla1-filled"
70gdb_test "print vla1(3, 6, 9)" " = 42" \
71  "print allocated vla1(3,6,9) after specific assignment (filled)"
72gdb_test "print vla1(1, 3, 8)" " = 1001" \
73  "print allocated vla1(1,3,8) after specific assignment (filled)"
74gdb_test "print vla1(9, 9, 9)" " = 999" \
75  "print allocated vla1(9,9,9) after assignment in debugger (filled)"
76
77# Try to access values in undefined pointer to VLA (dangling)
78gdb_test "print pvla" " = <not associated>" "print undefined pvla"
79gdb_test "print &pvla" \
80  " = \\\(PTR TO -> \\\( $real \\\(:,:,:\\\) \\\)\\\) $hex" \
81  "print non-associated &pvla"
82gdb_test "print pvla(1, 3, 8)" "no such vector element \\\(vector not associated\\\)" \
83  "print undefined pvla(1,3,8)"
84
85# Try to access values in pointer to VLA and compare them
86gdb_breakpoint [gdb_get_line_number "pvla-associated"]
87gdb_continue_to_breakpoint "pvla-associated"
88gdb_test "print &pvla" \
89  " = \\\(PTR TO -> \\\( $real \\\(10,10,10\\\) \\\)\\\) $hex" \
90  "print associated &pvla"
91gdb_test "print pvla(3, 6, 9)" " = 42" "print associated pvla(3,6,9)"
92gdb_test "print pvla(1, 3, 8)" " = 1001" "print associated pvla(1,3,8)"
93gdb_test "print pvla(9, 9, 9)" " = 999" "print associated pvla(9,9,9)"
94
95# Fill values to VLA using pointer and check
96gdb_breakpoint [gdb_get_line_number "pvla-re-associated"]
97gdb_continue_to_breakpoint "pvla-re-associated"
98gdb_test "print pvla(5, 45, 20)" \
99  " = 1" "print pvla(5, 45, 20) after filled using pointer"
100gdb_test "print vla2(5, 45, 20)" \
101  " = 1" "print vla2(5, 45, 20) after filled using pointer"
102gdb_test "print pvla(7, 45, 14)" " = 2" \
103  "print pvla(7, 45, 14) after filled using pointer"
104gdb_test "print vla2(7, 45, 14)" " = 2" \
105  "print vla2(7, 45, 14) after filled using pointer"
106
107# Try to access values of deassociated VLA pointer
108gdb_breakpoint [gdb_get_line_number "pvla-deassociated"]
109gdb_continue_to_breakpoint "pvla-deassociated"
110gdb_test "print pvla(5, 45, 20)" \
111  "no such vector element \\\(vector not associated\\\)" \
112  "print pvla(5, 45, 20) after deassociated"
113gdb_test "print pvla(7, 45, 14)" \
114  "no such vector element \\\(vector not associated\\\)" \
115  "print pvla(7, 45, 14) after dissasociated"
116gdb_test "print pvla" " = <not associated>" \
117  "print vla1 after deassociated"
118
119# Try to access values of deallocated VLA
120gdb_breakpoint [gdb_get_line_number "vla1-deallocated"]
121gdb_continue_to_breakpoint "vla1-deallocated"
122gdb_test "print vla1(3, 6, 9)" "no such vector element \\\(vector not allocated\\\)" \
123  "print allocated vla1(3,6,9) after specific assignment (deallocated)"
124gdb_test "print vla1(1, 3, 8)" "no such vector element \\\(vector not allocated\\\)" \
125  "print allocated vla1(1,3,8) after specific assignment (deallocated)"
126gdb_test "print vla1(9, 9, 9)" "no such vector element \\\(vector not allocated\\\)" \
127  "print allocated vla1(9,9,9) after assignment in debugger (deallocated)"
128
129
130# Try to assign VLA to user variable
131clean_restart ${testfile}
132
133if {![fortran_runto_main]} {
134    return
135}
136gdb_breakpoint [gdb_get_line_number "vla2-allocated"]
137gdb_continue_to_breakpoint "vla2-allocated, second time"
138# Many instructions to be executed when step over this line, and it is
139# slower in remote debugging.  Increase the timeout to avoid timeout
140# fail.
141with_timeout_factor 15 {
142    gdb_test "next" "\\d+.*vla1\\(3, 6, 9\\) = 42" "next (1)"
143}
144
145gdb_test_no_output "set \$myvar = vla1" "set \$myvar = vla1"
146gdb_test "print \$myvar" \
147  " = \\( *\\( *\\( *1311, *1311, *1311,\[()1311, .\]*\\)" \
148  "print \$myvar set to vla1"
149
150gdb_test "next" "\\d+.*vla1\\(1, 3, 8\\) = 1001" "next (2)"
151gdb_test "print \$myvar(3,6,9)" " = 1311"
152
153gdb_breakpoint [gdb_get_line_number "pvla-associated"]
154gdb_continue_to_breakpoint "pvla-associated, second time"
155gdb_test_no_output "set \$mypvar = pvla" "set \$mypvar = pvla"
156gdb_test "print \$mypvar(1,3,8)" " = 1001"
157
158# deallocate pointer and make sure user defined variable still has the
159# right value.
160gdb_breakpoint [gdb_get_line_number "pvla-deassociated"]
161gdb_continue_to_breakpoint "pvla-deassociated, second time"
162gdb_test "print \$mypvar(1,3,8)" " = 1001" \
163  "print \$mypvar(1,3,8) after deallocated"
164
165gdb_breakpoint [gdb_get_line_number "vla1-neg-bounds-v1"]
166gdb_continue_to_breakpoint "vla1-neg-bounds-v1"
167with_test_prefix "negative bounds" {
168    gdb_test "print vla1(-2,-5,-3)" " = 1"
169    gdb_test "print vla1(-2,-3,-1)" " = -231"
170    gdb_test "print vla1(-3,-5,-3)" "no such vector element"
171    gdb_test "print vla1(-2,-6,-3)" "no such vector element"
172    gdb_test "print vla1(-2,-5,-4)" "no such vector element"
173    gdb_test "print vla1(0,-2,-1)" "no such vector element"
174    gdb_test "print vla1(-1,-1,-1)" "no such vector element"
175    gdb_test "print vla1(-1,-2,0)" "no such vector element"
176}
177
178gdb_breakpoint [gdb_get_line_number "vla1-neg-bounds-v2"]
179gdb_continue_to_breakpoint "vla1-neg-bounds-v2"
180with_test_prefix "negative lower bounds, positive upper bounds" {
181    gdb_test "print vla1(-2,-5,-3)" " = 2"
182    gdb_test "print vla1(-2,-3,-1)" " = 2"
183    gdb_test "print vla1(-2,-4,-2)" " = -242"
184    gdb_test "print vla1(-3,-5,-3)" "no such vector element"
185    gdb_test "print vla1(-2,-6,-3)" "no such vector element"
186    gdb_test "print vla1(-2,-5,-4)" "no such vector element"
187    gdb_test "print vla1(2,2,1)" "no such vector element"
188    gdb_test "print vla1(1,3,1)" "no such vector element"
189    gdb_test "print vla1(1,2,2)" "no such vector element"
190}
191