Home | History | Annotate | Line # | Download | only in gdb.fortran
      1 # Copyright 2015-2024 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 require allow_fortran_tests
     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     return -1
     28 }
     29 
     30 # Depending on the compiler being used,
     31 # the type names can be printed differently.
     32 set real [fortran_real4]
     33 
     34 # Try to access values in non allocated VLA
     35 gdb_breakpoint [gdb_get_line_number "vla1-init"]
     36 gdb_continue_to_breakpoint "vla1-init"
     37 gdb_test "print vla1" " = <not allocated>" "print non-allocated vla1"
     38 gdb_test "print &vla1" \
     39   " = \\\(PTR TO -> \\\( $real, allocatable \\\(:,:,:\\\) \\\)\\\) $hex" \
     40   "print non-allocated &vla1"
     41 gdb_test "print vla1(1,1,1)" "no such vector element \\\(vector not allocated\\\)" \
     42   "print member in non-allocated vla1, 1"
     43 gdb_test "print vla1(101,202,303)" \
     44   "no such vector element \\\(vector not allocated\\\)" \
     45   "print member in non-allocated vla1, 2"
     46 gdb_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
     50 gdb_breakpoint [gdb_get_line_number "vla2-allocated"]
     51 gdb_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.
     55 with_timeout_factor 15 {
     56     gdb_test "next" "\\d+(\\t|\\s)+vla1\\\(3, 6, 9\\\) = 42" \
     57 	"step over value assignment of vla1"
     58 }
     59 gdb_test "print &vla1" \
     60   " = \\\(PTR TO -> \\\( $real, allocatable \\\(10,10,10\\\) \\\)\\\) $hex" \
     61   "print allocated &vla1"
     62 gdb_test "print vla1(3, 6, 9)" " = 1311" "print allocated vla1(3,6,9)"
     63 gdb_test "print vla1(1, 3, 8)" " = 1311" "print allocated vla1(1,3,8)"
     64 gdb_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
     68 gdb_breakpoint [gdb_get_line_number "vla1-filled"]
     69 gdb_continue_to_breakpoint "vla1-filled"
     70 gdb_test "print vla1(3, 6, 9)" " = 42" \
     71   "print allocated vla1(3,6,9) after specific assignment, filled"
     72 gdb_test "print vla1(1, 3, 8)" " = 1001" \
     73   "print allocated vla1(1,3,8) after specific assignment, filled"
     74 gdb_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)
     78 gdb_test "print pvla" " = <not associated>" "print undefined pvla"
     79 gdb_test "print &pvla" \
     80   " = \\\(PTR TO -> \\\( $real \\\(:,:,:\\\) \\\)\\\) $hex" \
     81   "print non-associated &pvla"
     82 gdb_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
     86 gdb_breakpoint [gdb_get_line_number "pvla-associated"]
     87 gdb_continue_to_breakpoint "pvla-associated"
     88 gdb_test "print &pvla" \
     89   " = \\\(PTR TO -> \\\( $real \\\(10,10,10\\\) \\\)\\\) $hex" \
     90   "print associated &pvla"
     91 gdb_test "print pvla(3, 6, 9)" " = 42" "print associated pvla(3,6,9)"
     92 gdb_test "print pvla(1, 3, 8)" " = 1001" "print associated pvla(1,3,8)"
     93 gdb_test "print pvla(9, 9, 9)" " = 999" "print associated pvla(9,9,9)"
     94 
     95 # Fill values to VLA using pointer and check
     96 gdb_breakpoint [gdb_get_line_number "pvla-re-associated"]
     97 gdb_continue_to_breakpoint "pvla-re-associated"
     98 gdb_test "print pvla(5, 45, 20)" \
     99   " = 1" "print pvla(5, 45, 20) after filled using pointer"
    100 gdb_test "print vla2(5, 45, 20)" \
    101   " = 1" "print vla2(5, 45, 20) after filled using pointer"
    102 gdb_test "print pvla(7, 45, 14)" " = 2" \
    103   "print pvla(7, 45, 14) after filled using pointer"
    104 gdb_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
    108 gdb_breakpoint [gdb_get_line_number "pvla-deassociated"]
    109 gdb_continue_to_breakpoint "pvla-deassociated"
    110 gdb_test "print pvla(5, 45, 20)" \
    111   "no such vector element \\\(vector not associated\\\)" \
    112   "print pvla(5, 45, 20) after deassociated"
    113 gdb_test "print pvla(7, 45, 14)" \
    114   "no such vector element \\\(vector not associated\\\)" \
    115   "print pvla(7, 45, 14) after dissasociated"
    116 gdb_test "print pvla" " = <not associated>" \
    117   "print vla1 after deassociated"
    118 
    119 # Try to access values of deallocated VLA
    120 gdb_breakpoint [gdb_get_line_number "vla1-deallocated"]
    121 gdb_continue_to_breakpoint "vla1-deallocated"
    122 gdb_test "print vla1(3, 6, 9)" "no such vector element \\\(vector not allocated\\\)" \
    123   "print allocated vla1(3,6,9) after specific assignment, deallocated"
    124 gdb_test "print vla1(1, 3, 8)" "no such vector element \\\(vector not allocated\\\)" \
    125   "print allocated vla1(1,3,8) after specific assignment, deallocated"
    126 gdb_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
    131 clean_restart ${testfile}
    132 
    133 if {![fortran_runto_main]} {
    134     return
    135 }
    136 gdb_breakpoint [gdb_get_line_number "vla2-allocated"]
    137 gdb_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.
    141 with_timeout_factor 15 {
    142     gdb_test "next" "\\d+.*vla1\\(3, 6, 9\\) = 42" "next (1)"
    143 }
    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"
    152 
    153 gdb_breakpoint [gdb_get_line_number "pvla-associated"]
    154 gdb_continue_to_breakpoint "pvla-associated, second time"
    155 gdb_test_no_output "set \$mypvar = pvla" "set \$mypvar = pvla"
    156 gdb_test "print \$mypvar(1,3,8)" " = 1001"
    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"]
    161 gdb_continue_to_breakpoint "pvla-deassociated, second time"
    162 gdb_test "print \$mypvar(1,3,8)" " = 1001" \
    163   "print \$mypvar(1,3,8) after deallocated"
    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 }
    191