]>
Commit | Line | Data |
---|---|---|
42a4f53d | 1 | # Copyright 2015-2019 Free Software Foundation, Inc. |
3f2f83dd KB |
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 | ||
16 | standard_testfile "vla.f90" | |
9e9af4be | 17 | load_lib "fortran.exp" |
3f2f83dd | 18 | |
5b362f04 | 19 | if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \ |
3f2f83dd KB |
20 | {debug f90 quiet}] } { |
21 | return -1 | |
22 | } | |
23 | ||
24 | if ![runto_main] { | |
25 | untested "could not run to main" | |
26 | return -1 | |
27 | } | |
28 | ||
9e9af4be BH |
29 | # Depending on the compiler being used, |
30 | # the type names can be printed differently. | |
31 | set real [fortran_real4] | |
32 | ||
3f2f83dd KB |
33 | # Try to access values in non allocated VLA |
34 | gdb_breakpoint [gdb_get_line_number "vla1-init"] | |
35 | gdb_continue_to_breakpoint "vla1-init" | |
36 | gdb_test "print vla1" " = <not allocated>" "print non-allocated vla1" | |
37 | gdb_test "print &vla1" \ | |
584a927c | 38 | " = \\\(PTR TO -> \\\( $real, allocatable \\\(:,:,:\\\) \\\)\\\) $hex" \ |
3f2f83dd KB |
39 | "print non-allocated &vla1" |
40 | gdb_test "print vla1(1,1,1)" "no such vector element \\\(vector not allocated\\\)" \ | |
41 | "print member in non-allocated vla1 (1)" | |
42 | gdb_test "print vla1(101,202,303)" \ | |
43 | "no such vector element \\\(vector not allocated\\\)" \ | |
44 | "print member in non-allocated vla1 (2)" | |
45 | gdb_test "print vla1(5,2,18)=1" "no such vector element \\\(vector not allocated\\\)" \ | |
46 | "set member in non-allocated vla1" | |
47 | ||
48 | # Try to access value in allocated VLA | |
49 | gdb_breakpoint [gdb_get_line_number "vla2-allocated"] | |
50 | gdb_continue_to_breakpoint "vla2-allocated" | |
7fe8399d YQ |
51 | # Many instructions to be executed when step over this line, and it is |
52 | # slower in remote debugging. Increase the timeout to avoid timeout | |
53 | # fail. | |
54 | with_timeout_factor 15 { | |
55 | gdb_test "next" "\\d+(\\t|\\s)+vla1\\\(3, 6, 9\\\) = 42" \ | |
56 | "step over value assignment of vla1" | |
57 | } | |
3f2f83dd | 58 | gdb_test "print &vla1" \ |
bc68014d | 59 | " = \\\(PTR TO -> \\\( $real, allocatable \\\(10,10,10\\\) \\\)\\\) $hex" \ |
3f2f83dd KB |
60 | "print allocated &vla1" |
61 | gdb_test "print vla1(3, 6, 9)" " = 1311" "print allocated vla1(3,6,9)" | |
62 | gdb_test "print vla1(1, 3, 8)" " = 1311" "print allocated vla1(1,3,8)" | |
63 | gdb_test "print vla1(9, 9, 9) = 999" " = 999" \ | |
e0f86435 | 64 | "print allocated vla1(9,9,9)=999" |
3f2f83dd KB |
65 | |
66 | # Try to access values in allocated VLA after specific assignment | |
67 | gdb_breakpoint [gdb_get_line_number "vla1-filled"] | |
68 | gdb_continue_to_breakpoint "vla1-filled" | |
69 | gdb_test "print vla1(3, 6, 9)" " = 42" \ | |
70 | "print allocated vla1(3,6,9) after specific assignment (filled)" | |
71 | gdb_test "print vla1(1, 3, 8)" " = 1001" \ | |
72 | "print allocated vla1(1,3,8) after specific assignment (filled)" | |
73 | gdb_test "print vla1(9, 9, 9)" " = 999" \ | |
74 | "print allocated vla1(9,9,9) after assignment in debugger (filled)" | |
75 | ||
76 | # Try to access values in undefined pointer to VLA (dangling) | |
77 | gdb_test "print pvla" " = <not associated>" "print undefined pvla" | |
78 | gdb_test "print &pvla" \ | |
584a927c | 79 | " = \\\(PTR TO -> \\\( $real \\\(:,:,:\\\) \\\)\\\) $hex" \ |
3f2f83dd KB |
80 | "print non-associated &pvla" |
81 | gdb_test "print pvla(1, 3, 8)" "no such vector element \\\(vector not associated\\\)" \ | |
82 | "print undefined pvla(1,3,8)" | |
83 | ||
84 | # Try to access values in pointer to VLA and compare them | |
85 | gdb_breakpoint [gdb_get_line_number "pvla-associated"] | |
86 | gdb_continue_to_breakpoint "pvla-associated" | |
87 | gdb_test "print &pvla" \ | |
f1fdc960 | 88 | " = \\\(PTR TO -> \\\( $real \\\(10,10,10\\\) \\\)\\\) $hex" \ |
3f2f83dd KB |
89 | "print associated &pvla" |
90 | gdb_test "print pvla(3, 6, 9)" " = 42" "print associated pvla(3,6,9)" | |
91 | gdb_test "print pvla(1, 3, 8)" " = 1001" "print associated pvla(1,3,8)" | |
92 | gdb_test "print pvla(9, 9, 9)" " = 999" "print associated pvla(9,9,9)" | |
93 | ||
94 | # Fill values to VLA using pointer and check | |
95 | gdb_breakpoint [gdb_get_line_number "pvla-re-associated"] | |
96 | gdb_continue_to_breakpoint "pvla-re-associated" | |
97 | gdb_test "print pvla(5, 45, 20)" \ | |
98 | " = 1" "print pvla(5, 45, 20) after filled using pointer" | |
99 | gdb_test "print vla2(5, 45, 20)" \ | |
100 | " = 1" "print vla2(5, 45, 20) after filled using pointer" | |
101 | gdb_test "print pvla(7, 45, 14)" " = 2" \ | |
102 | "print pvla(7, 45, 14) after filled using pointer" | |
103 | gdb_test "print vla2(7, 45, 14)" " = 2" \ | |
104 | "print vla2(7, 45, 14) after filled using pointer" | |
105 | ||
106 | # Try to access values of deassociated VLA pointer | |
107 | gdb_breakpoint [gdb_get_line_number "pvla-deassociated"] | |
108 | gdb_continue_to_breakpoint "pvla-deassociated" | |
109 | gdb_test "print pvla(5, 45, 20)" \ | |
110 | "no such vector element \\\(vector not associated\\\)" \ | |
111 | "print pvla(5, 45, 20) after deassociated" | |
112 | gdb_test "print pvla(7, 45, 14)" \ | |
113 | "no such vector element \\\(vector not associated\\\)" \ | |
114 | "print pvla(7, 45, 14) after dissasociated" | |
115 | gdb_test "print pvla" " = <not associated>" \ | |
116 | "print vla1 after deassociated" | |
117 | ||
118 | # Try to access values of deallocated VLA | |
119 | gdb_breakpoint [gdb_get_line_number "vla1-deallocated"] | |
120 | gdb_continue_to_breakpoint "vla1-deallocated" | |
121 | gdb_test "print vla1(3, 6, 9)" "no such vector element \\\(vector not allocated\\\)" \ | |
122 | "print allocated vla1(3,6,9) after specific assignment (deallocated)" | |
123 | gdb_test "print vla1(1, 3, 8)" "no such vector element \\\(vector not allocated\\\)" \ | |
124 | "print allocated vla1(1,3,8) after specific assignment (deallocated)" | |
125 | gdb_test "print vla1(9, 9, 9)" "no such vector element \\\(vector not allocated\\\)" \ | |
126 | "print allocated vla1(9,9,9) after assignment in debugger (deallocated)" | |
127 | ||
128 | ||
129 | # Try to assign VLA to user variable | |
130 | clean_restart ${testfile} | |
131 | ||
132 | if ![runto MAIN__] then { | |
133 | perror "couldn't run to breakpoint MAIN__" | |
134 | continue | |
135 | } | |
136 | gdb_breakpoint [gdb_get_line_number "vla2-allocated"] | |
584a927c | 137 | gdb_continue_to_breakpoint "vla2-allocated, second time" |
7fe8399d YQ |
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. | |
141 | with_timeout_factor 15 { | |
142 | gdb_test "next" "\\d+.*vla1\\(3, 6, 9\\) = 42" "next (1)" | |
143 | } | |
3f2f83dd KB |
144 | |
145 | gdb_test_no_output "set \$myvar = vla1" "set \$myvar = vla1" | |
146 | gdb_test "print \$myvar" \ | |
147 | " = \\( *\\( *\\( *1311, *1311, *1311,\[()1311, .\]*\\)" \ | |
148 | "print \$myvar set to vla1" | |
149 | ||
150 | gdb_test "next" "\\d+.*vla1\\(1, 3, 8\\) = 1001" "next (2)" | |
151 | gdb_test "print \$myvar(3,6,9)" " = 1311" "print \$myvar(3,6,9)" | |
152 | ||
153 | gdb_breakpoint [gdb_get_line_number "pvla-associated"] | |
584a927c | 154 | gdb_continue_to_breakpoint "pvla-associated, second time" |
3f2f83dd KB |
155 | gdb_test_no_output "set \$mypvar = pvla" "set \$mypvar = pvla" |
156 | gdb_test "print \$mypvar(1,3,8)" " = 1001" "print \$mypvar(1,3,8)" | |
157 | ||
158 | # deallocate pointer and make sure user defined variable still has the | |
159 | # right value. | |
160 | gdb_breakpoint [gdb_get_line_number "pvla-deassociated"] | |
584a927c | 161 | gdb_continue_to_breakpoint "pvla-deassociated, second time" |
3f2f83dd KB |
162 | gdb_test "print \$mypvar(1,3,8)" " = 1001" \ |
163 | "print \$mypvar(1,3,8) after deallocated" | |
0d4e84ed AB |
164 | |
165 | gdb_breakpoint [gdb_get_line_number "vla1-neg-bounds-v1"] | |
166 | gdb_continue_to_breakpoint "vla1-neg-bounds-v1" | |
167 | with_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 | ||
178 | gdb_breakpoint [gdb_get_line_number "vla1-neg-bounds-v2"] | |
179 | gdb_continue_to_breakpoint "vla1-neg-bounds-v2" | |
180 | with_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 | } |