1# Copyright 2015-2020 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 untested "could not run to main" 28 return -1 29} 30 31# Depending on the compiler being used, 32# the type names can be printed differently. 33set real [fortran_real4] 34 35# Try to access values in non allocated VLA 36gdb_breakpoint [gdb_get_line_number "vla1-init"] 37gdb_continue_to_breakpoint "vla1-init" 38gdb_test "print vla1" " = <not allocated>" "print non-allocated vla1" 39gdb_test "print &vla1" \ 40 " = \\\(PTR TO -> \\\( $real, allocatable \\\(:,:,:\\\) \\\)\\\) $hex" \ 41 "print non-allocated &vla1" 42gdb_test "print vla1(1,1,1)" "no such vector element \\\(vector not allocated\\\)" \ 43 "print member in non-allocated vla1 (1)" 44gdb_test "print vla1(101,202,303)" \ 45 "no such vector element \\\(vector not allocated\\\)" \ 46 "print member in non-allocated vla1 (2)" 47gdb_test "print vla1(5,2,18)=1" "no such vector element \\\(vector not allocated\\\)" \ 48 "set member in non-allocated vla1" 49 50# Try to access value in allocated VLA 51gdb_breakpoint [gdb_get_line_number "vla2-allocated"] 52gdb_continue_to_breakpoint "vla2-allocated" 53# Many instructions to be executed when step over this line, and it is 54# slower in remote debugging. Increase the timeout to avoid timeout 55# fail. 56with_timeout_factor 15 { 57 gdb_test "next" "\\d+(\\t|\\s)+vla1\\\(3, 6, 9\\\) = 42" \ 58 "step over value assignment of vla1" 59} 60gdb_test "print &vla1" \ 61 " = \\\(PTR TO -> \\\( $real, allocatable \\\(10,10,10\\\) \\\)\\\) $hex" \ 62 "print allocated &vla1" 63gdb_test "print vla1(3, 6, 9)" " = 1311" "print allocated vla1(3,6,9)" 64gdb_test "print vla1(1, 3, 8)" " = 1311" "print allocated vla1(1,3,8)" 65gdb_test "print vla1(9, 9, 9) = 999" " = 999" \ 66 "print allocated vla1(9,9,9)=999" 67 68# Try to access values in allocated VLA after specific assignment 69gdb_breakpoint [gdb_get_line_number "vla1-filled"] 70gdb_continue_to_breakpoint "vla1-filled" 71gdb_test "print vla1(3, 6, 9)" " = 42" \ 72 "print allocated vla1(3,6,9) after specific assignment (filled)" 73gdb_test "print vla1(1, 3, 8)" " = 1001" \ 74 "print allocated vla1(1,3,8) after specific assignment (filled)" 75gdb_test "print vla1(9, 9, 9)" " = 999" \ 76 "print allocated vla1(9,9,9) after assignment in debugger (filled)" 77 78# Try to access values in undefined pointer to VLA (dangling) 79gdb_test "print pvla" " = <not associated>" "print undefined pvla" 80gdb_test "print &pvla" \ 81 " = \\\(PTR TO -> \\\( $real \\\(:,:,:\\\) \\\)\\\) $hex" \ 82 "print non-associated &pvla" 83gdb_test "print pvla(1, 3, 8)" "no such vector element \\\(vector not associated\\\)" \ 84 "print undefined pvla(1,3,8)" 85 86# Try to access values in pointer to VLA and compare them 87gdb_breakpoint [gdb_get_line_number "pvla-associated"] 88gdb_continue_to_breakpoint "pvla-associated" 89gdb_test "print &pvla" \ 90 " = \\\(PTR TO -> \\\( $real \\\(10,10,10\\\) \\\)\\\) $hex" \ 91 "print associated &pvla" 92gdb_test "print pvla(3, 6, 9)" " = 42" "print associated pvla(3,6,9)" 93gdb_test "print pvla(1, 3, 8)" " = 1001" "print associated pvla(1,3,8)" 94gdb_test "print pvla(9, 9, 9)" " = 999" "print associated pvla(9,9,9)" 95 96# Fill values to VLA using pointer and check 97gdb_breakpoint [gdb_get_line_number "pvla-re-associated"] 98gdb_continue_to_breakpoint "pvla-re-associated" 99gdb_test "print pvla(5, 45, 20)" \ 100 " = 1" "print pvla(5, 45, 20) after filled using pointer" 101gdb_test "print vla2(5, 45, 20)" \ 102 " = 1" "print vla2(5, 45, 20) after filled using pointer" 103gdb_test "print pvla(7, 45, 14)" " = 2" \ 104 "print pvla(7, 45, 14) after filled using pointer" 105gdb_test "print vla2(7, 45, 14)" " = 2" \ 106 "print vla2(7, 45, 14) after filled using pointer" 107 108# Try to access values of deassociated VLA pointer 109gdb_breakpoint [gdb_get_line_number "pvla-deassociated"] 110gdb_continue_to_breakpoint "pvla-deassociated" 111gdb_test "print pvla(5, 45, 20)" \ 112 "no such vector element \\\(vector not associated\\\)" \ 113 "print pvla(5, 45, 20) after deassociated" 114gdb_test "print pvla(7, 45, 14)" \ 115 "no such vector element \\\(vector not associated\\\)" \ 116 "print pvla(7, 45, 14) after dissasociated" 117gdb_test "print pvla" " = <not associated>" \ 118 "print vla1 after deassociated" 119 120# Try to access values of deallocated VLA 121gdb_breakpoint [gdb_get_line_number "vla1-deallocated"] 122gdb_continue_to_breakpoint "vla1-deallocated" 123gdb_test "print vla1(3, 6, 9)" "no such vector element \\\(vector not allocated\\\)" \ 124 "print allocated vla1(3,6,9) after specific assignment (deallocated)" 125gdb_test "print vla1(1, 3, 8)" "no such vector element \\\(vector not allocated\\\)" \ 126 "print allocated vla1(1,3,8) after specific assignment (deallocated)" 127gdb_test "print vla1(9, 9, 9)" "no such vector element \\\(vector not allocated\\\)" \ 128 "print allocated vla1(9,9,9) after assignment in debugger (deallocated)" 129 130 131# Try to assign VLA to user variable 132clean_restart ${testfile} 133 134if ![fortran_runto_main] then { 135 perror "couldn't run to main" 136 continue 137} 138gdb_breakpoint [gdb_get_line_number "vla2-allocated"] 139gdb_continue_to_breakpoint "vla2-allocated, second time" 140# Many instructions to be executed when step over this line, and it is 141# slower in remote debugging. Increase the timeout to avoid timeout 142# fail. 143with_timeout_factor 15 { 144 gdb_test "next" "\\d+.*vla1\\(3, 6, 9\\) = 42" "next (1)" 145} 146 147gdb_test_no_output "set \$myvar = vla1" "set \$myvar = vla1" 148gdb_test "print \$myvar" \ 149 " = \\( *\\( *\\( *1311, *1311, *1311,\[()1311, .\]*\\)" \ 150 "print \$myvar set to vla1" 151 152gdb_test "next" "\\d+.*vla1\\(1, 3, 8\\) = 1001" "next (2)" 153gdb_test "print \$myvar(3,6,9)" " = 1311" 154 155gdb_breakpoint [gdb_get_line_number "pvla-associated"] 156gdb_continue_to_breakpoint "pvla-associated, second time" 157gdb_test_no_output "set \$mypvar = pvla" "set \$mypvar = pvla" 158gdb_test "print \$mypvar(1,3,8)" " = 1001" 159 160# deallocate pointer and make sure user defined variable still has the 161# right value. 162gdb_breakpoint [gdb_get_line_number "pvla-deassociated"] 163gdb_continue_to_breakpoint "pvla-deassociated, second time" 164gdb_test "print \$mypvar(1,3,8)" " = 1001" \ 165 "print \$mypvar(1,3,8) after deallocated" 166 167gdb_breakpoint [gdb_get_line_number "vla1-neg-bounds-v1"] 168gdb_continue_to_breakpoint "vla1-neg-bounds-v1" 169with_test_prefix "negative bounds" { 170 gdb_test "print vla1(-2,-5,-3)" " = 1" 171 gdb_test "print vla1(-2,-3,-1)" " = -231" 172 gdb_test "print vla1(-3,-5,-3)" "no such vector element" 173 gdb_test "print vla1(-2,-6,-3)" "no such vector element" 174 gdb_test "print vla1(-2,-5,-4)" "no such vector element" 175 gdb_test "print vla1(0,-2,-1)" "no such vector element" 176 gdb_test "print vla1(-1,-1,-1)" "no such vector element" 177 gdb_test "print vla1(-1,-2,0)" "no such vector element" 178} 179 180gdb_breakpoint [gdb_get_line_number "vla1-neg-bounds-v2"] 181gdb_continue_to_breakpoint "vla1-neg-bounds-v2" 182with_test_prefix "negative lower bounds, positive upper bounds" { 183 gdb_test "print vla1(-2,-5,-3)" " = 2" 184 gdb_test "print vla1(-2,-3,-1)" " = 2" 185 gdb_test "print vla1(-2,-4,-2)" " = -242" 186 gdb_test "print vla1(-3,-5,-3)" "no such vector element" 187 gdb_test "print vla1(-2,-6,-3)" "no such vector element" 188 gdb_test "print vla1(-2,-5,-4)" "no such vector element" 189 gdb_test "print vla1(2,2,1)" "no such vector element" 190 gdb_test "print vla1(1,3,1)" "no such vector element" 191 gdb_test "print vla1(1,2,2)" "no such vector element" 192} 193