Home | History | Annotate | Line # | Download | only in gdb.fortran
vla-value.exp revision 1.1.1.4
      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 
     16 standard_testfile "vla.f90"
     17 load_lib "fortran.exp"
     18 
     19 if {[skip_fortran_tests]} { return -1 }
     20 
     21 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
     22      {debug f90 quiet}] } {
     23     return -1
     24 }
     25 
     26 if ![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.
     33 set real [fortran_real4]
     34 
     35 # Try to access values in non allocated VLA
     36 gdb_breakpoint [gdb_get_line_number "vla1-init"]
     37 gdb_continue_to_breakpoint "vla1-init"
     38 gdb_test "print vla1" " = <not allocated>" "print non-allocated vla1"
     39 gdb_test "print &vla1" \
     40   " = \\\(PTR TO -> \\\( $real, allocatable \\\(:,:,:\\\) \\\)\\\) $hex" \
     41   "print non-allocated &vla1"
     42 gdb_test "print vla1(1,1,1)" "no such vector element \\\(vector not allocated\\\)" \
     43   "print member in non-allocated vla1 (1)"
     44 gdb_test "print vla1(101,202,303)" \
     45   "no such vector element \\\(vector not allocated\\\)" \
     46   "print member in non-allocated vla1 (2)"
     47 gdb_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
     51 gdb_breakpoint [gdb_get_line_number "vla2-allocated"]
     52 gdb_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.
     56 with_timeout_factor 15 {
     57     gdb_test "next" "\\d+(\\t|\\s)+vla1\\\(3, 6, 9\\\) = 42" \
     58 	"step over value assignment of vla1"
     59 }
     60 gdb_test "print &vla1" \
     61   " = \\\(PTR TO -> \\\( $real, allocatable \\\(10,10,10\\\) \\\)\\\) $hex" \
     62   "print allocated &vla1"
     63 gdb_test "print vla1(3, 6, 9)" " = 1311" "print allocated vla1(3,6,9)"
     64 gdb_test "print vla1(1, 3, 8)" " = 1311" "print allocated vla1(1,3,8)"
     65 gdb_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
     69 gdb_breakpoint [gdb_get_line_number "vla1-filled"]
     70 gdb_continue_to_breakpoint "vla1-filled"
     71 gdb_test "print vla1(3, 6, 9)" " = 42" \
     72   "print allocated vla1(3,6,9) after specific assignment (filled)"
     73 gdb_test "print vla1(1, 3, 8)" " = 1001" \
     74   "print allocated vla1(1,3,8) after specific assignment (filled)"
     75 gdb_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)
     79 gdb_test "print pvla" " = <not associated>" "print undefined pvla"
     80 gdb_test "print &pvla" \
     81   " = \\\(PTR TO -> \\\( $real \\\(:,:,:\\\) \\\)\\\) $hex" \
     82   "print non-associated &pvla"
     83 gdb_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
     87 gdb_breakpoint [gdb_get_line_number "pvla-associated"]
     88 gdb_continue_to_breakpoint "pvla-associated"
     89 gdb_test "print &pvla" \
     90   " = \\\(PTR TO -> \\\( $real \\\(10,10,10\\\) \\\)\\\) $hex" \
     91   "print associated &pvla"
     92 gdb_test "print pvla(3, 6, 9)" " = 42" "print associated pvla(3,6,9)"
     93 gdb_test "print pvla(1, 3, 8)" " = 1001" "print associated pvla(1,3,8)"
     94 gdb_test "print pvla(9, 9, 9)" " = 999" "print associated pvla(9,9,9)"
     95 
     96 # Fill values to VLA using pointer and check
     97 gdb_breakpoint [gdb_get_line_number "pvla-re-associated"]
     98 gdb_continue_to_breakpoint "pvla-re-associated"
     99 gdb_test "print pvla(5, 45, 20)" \
    100   " = 1" "print pvla(5, 45, 20) after filled using pointer"
    101 gdb_test "print vla2(5, 45, 20)" \
    102   " = 1" "print vla2(5, 45, 20) after filled using pointer"
    103 gdb_test "print pvla(7, 45, 14)" " = 2" \
    104   "print pvla(7, 45, 14) after filled using pointer"
    105 gdb_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
    109 gdb_breakpoint [gdb_get_line_number "pvla-deassociated"]
    110 gdb_continue_to_breakpoint "pvla-deassociated"
    111 gdb_test "print pvla(5, 45, 20)" \
    112   "no such vector element \\\(vector not associated\\\)" \
    113   "print pvla(5, 45, 20) after deassociated"
    114 gdb_test "print pvla(7, 45, 14)" \
    115   "no such vector element \\\(vector not associated\\\)" \
    116   "print pvla(7, 45, 14) after dissasociated"
    117 gdb_test "print pvla" " = <not associated>" \
    118   "print vla1 after deassociated"
    119 
    120 # Try to access values of deallocated VLA
    121 gdb_breakpoint [gdb_get_line_number "vla1-deallocated"]
    122 gdb_continue_to_breakpoint "vla1-deallocated"
    123 gdb_test "print vla1(3, 6, 9)" "no such vector element \\\(vector not allocated\\\)" \
    124   "print allocated vla1(3,6,9) after specific assignment (deallocated)"
    125 gdb_test "print vla1(1, 3, 8)" "no such vector element \\\(vector not allocated\\\)" \
    126   "print allocated vla1(1,3,8) after specific assignment (deallocated)"
    127 gdb_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
    132 clean_restart ${testfile}
    133 
    134 if ![fortran_runto_main] then {
    135     perror "couldn't run to main"
    136     continue
    137 }
    138 gdb_breakpoint [gdb_get_line_number "vla2-allocated"]
    139 gdb_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.
    143 with_timeout_factor 15 {
    144     gdb_test "next" "\\d+.*vla1\\(3, 6, 9\\) = 42" "next (1)"
    145 }
    146 
    147 gdb_test_no_output "set \$myvar = vla1" "set \$myvar = vla1"
    148 gdb_test "print \$myvar" \
    149   " = \\( *\\( *\\( *1311, *1311, *1311,\[()1311, .\]*\\)" \
    150   "print \$myvar set to vla1"
    151 
    152 gdb_test "next" "\\d+.*vla1\\(1, 3, 8\\) = 1001" "next (2)"
    153 gdb_test "print \$myvar(3,6,9)" " = 1311"
    154 
    155 gdb_breakpoint [gdb_get_line_number "pvla-associated"]
    156 gdb_continue_to_breakpoint "pvla-associated, second time"
    157 gdb_test_no_output "set \$mypvar = pvla" "set \$mypvar = pvla"
    158 gdb_test "print \$mypvar(1,3,8)" " = 1001"
    159 
    160 # deallocate pointer and make sure user defined variable still has the
    161 # right value.
    162 gdb_breakpoint [gdb_get_line_number "pvla-deassociated"]
    163 gdb_continue_to_breakpoint "pvla-deassociated, second time"
    164 gdb_test "print \$mypvar(1,3,8)" " = 1001" \
    165   "print \$mypvar(1,3,8) after deallocated"
    166 
    167 gdb_breakpoint [gdb_get_line_number "vla1-neg-bounds-v1"]
    168 gdb_continue_to_breakpoint "vla1-neg-bounds-v1"
    169 with_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 
    180 gdb_breakpoint [gdb_get_line_number "vla1-neg-bounds-v2"]
    181 gdb_continue_to_breakpoint "vla1-neg-bounds-v2"
    182 with_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