1# Copyright 2015-2019 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 { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \ 20 {debug f90 quiet}] } { 21 return -1 22} 23 24if ![runto_main] { 25 untested "could not run to main" 26 return -1 27} 28 29# Depending on the compiler being used, 30# the type names can be printed differently. 31set real [fortran_real4] 32 33# Try to access values in non allocated VLA 34gdb_breakpoint [gdb_get_line_number "vla1-init"] 35gdb_continue_to_breakpoint "vla1-init" 36gdb_test "print vla1" " = <not allocated>" "print non-allocated vla1" 37gdb_test "print &vla1" \ 38 " = \\\(PTR TO -> \\\( $real \\\(<not allocated>\\\)\\\)\\\) $hex" \ 39 "print non-allocated &vla1" 40gdb_test "print vla1(1,1,1)" "no such vector element \\\(vector not allocated\\\)" \ 41 "print member in non-allocated vla1 (1)" 42gdb_test "print vla1(101,202,303)" \ 43 "no such vector element \\\(vector not allocated\\\)" \ 44 "print member in non-allocated vla1 (2)" 45gdb_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 49gdb_breakpoint [gdb_get_line_number "vla2-allocated"] 50gdb_continue_to_breakpoint "vla2-allocated" 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. 54with_timeout_factor 15 { 55 gdb_test "next" "\\d+(\\t|\\s)+vla1\\\(3, 6, 9\\\) = 42" \ 56 "step over value assignment of vla1" 57} 58gdb_test "print &vla1" \ 59 " = \\\(PTR TO -> \\\( $real \\\(10,10,10\\\)\\\)\\\) $hex" \ 60 "print allocated &vla1" 61gdb_test "print vla1(3, 6, 9)" " = 1311" "print allocated vla1(3,6,9)" 62gdb_test "print vla1(1, 3, 8)" " = 1311" "print allocated vla1(1,3,8)" 63gdb_test "print vla1(9, 9, 9) = 999" " = 999" \ 64 "print allocated vla1(9,9,9)=999" 65 66# Try to access values in allocated VLA after specific assignment 67gdb_breakpoint [gdb_get_line_number "vla1-filled"] 68gdb_continue_to_breakpoint "vla1-filled" 69gdb_test "print vla1(3, 6, 9)" " = 42" \ 70 "print allocated vla1(3,6,9) after specific assignment (filled)" 71gdb_test "print vla1(1, 3, 8)" " = 1001" \ 72 "print allocated vla1(1,3,8) after specific assignment (filled)" 73gdb_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) 77gdb_test "print pvla" " = <not associated>" "print undefined pvla" 78gdb_test "print &pvla" \ 79 " = \\\(PTR TO -> \\\( $real \\\(<not associated>\\\)\\\)\\\) $hex" \ 80 "print non-associated &pvla" 81gdb_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 85gdb_breakpoint [gdb_get_line_number "pvla-associated"] 86gdb_continue_to_breakpoint "pvla-associated" 87gdb_test "print &pvla" \ 88 " = \\\(PTR TO -> \\\( $real \\\(10,10,10\\\)\\\)\\\) $hex" \ 89 "print associated &pvla" 90gdb_test "print pvla(3, 6, 9)" " = 42" "print associated pvla(3,6,9)" 91gdb_test "print pvla(1, 3, 8)" " = 1001" "print associated pvla(1,3,8)" 92gdb_test "print pvla(9, 9, 9)" " = 999" "print associated pvla(9,9,9)" 93 94# Fill values to VLA using pointer and check 95gdb_breakpoint [gdb_get_line_number "pvla-re-associated"] 96gdb_continue_to_breakpoint "pvla-re-associated" 97gdb_test "print pvla(5, 45, 20)" \ 98 " = 1" "print pvla(5, 45, 20) after filled using pointer" 99gdb_test "print vla2(5, 45, 20)" \ 100 " = 1" "print vla2(5, 45, 20) after filled using pointer" 101gdb_test "print pvla(7, 45, 14)" " = 2" \ 102 "print pvla(7, 45, 14) after filled using pointer" 103gdb_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 107gdb_breakpoint [gdb_get_line_number "pvla-deassociated"] 108gdb_continue_to_breakpoint "pvla-deassociated" 109gdb_test "print pvla(5, 45, 20)" \ 110 "no such vector element \\\(vector not associated\\\)" \ 111 "print pvla(5, 45, 20) after deassociated" 112gdb_test "print pvla(7, 45, 14)" \ 113 "no such vector element \\\(vector not associated\\\)" \ 114 "print pvla(7, 45, 14) after dissasociated" 115gdb_test "print pvla" " = <not associated>" \ 116 "print vla1 after deassociated" 117 118# Try to access values of deallocated VLA 119gdb_breakpoint [gdb_get_line_number "vla1-deallocated"] 120gdb_continue_to_breakpoint "vla1-deallocated" 121gdb_test "print vla1(3, 6, 9)" "no such vector element \\\(vector not allocated\\\)" \ 122 "print allocated vla1(3,6,9) after specific assignment (deallocated)" 123gdb_test "print vla1(1, 3, 8)" "no such vector element \\\(vector not allocated\\\)" \ 124 "print allocated vla1(1,3,8) after specific assignment (deallocated)" 125gdb_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 130clean_restart ${testfile} 131 132if ![runto MAIN__] then { 133 perror "couldn't run to breakpoint MAIN__" 134 continue 135} 136gdb_breakpoint [gdb_get_line_number "vla2-allocated"] 137gdb_continue_to_breakpoint "vla2-allocated" 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" "print \$myvar(3,6,9)" 152 153gdb_breakpoint [gdb_get_line_number "pvla-associated"] 154gdb_continue_to_breakpoint "pvla-associated" 155gdb_test_no_output "set \$mypvar = pvla" "set \$mypvar = pvla" 156gdb_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. 160gdb_breakpoint [gdb_get_line_number "pvla-deassociated"] 161gdb_continue_to_breakpoint "pvla-deassociated" 162gdb_test "print \$mypvar(1,3,8)" " = 1001" \ 163 "print \$mypvar(1,3,8) after deallocated" 164