Home | History | Annotate | Line # | Download | only in gdb.fortran
vla-value.exp revision 1.1.1.3
      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 
     16 standard_testfile "vla.f90"
     17 load_lib "fortran.exp"
     18 
     19 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
     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 
     29 # Depending on the compiler being used,
     30 # the type names can be printed differently.
     31 set real [fortran_real4]
     32 
     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" \
     38   " = \\\(PTR TO -> \\\( $real \\\(<not allocated>\\\)\\\)\\\) $hex" \
     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"
     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 }
     58 gdb_test "print &vla1" \
     59   " = \\\(PTR TO -> \\\( $real \\\(10,10,10\\\)\\\)\\\) $hex" \
     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" \
     64   "print allocated vla1(9,9,9)=999"
     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" \
     79   " = \\\(PTR TO -> \\\( $real \\\(<not associated>\\\)\\\)\\\) $hex" \
     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" \
     88   " = \\\(PTR TO -> \\\( $real \\\(10,10,10\\\)\\\)\\\) $hex" \
     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"]
    137 gdb_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.
    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" "print \$myvar(3,6,9)"
    152 
    153 gdb_breakpoint [gdb_get_line_number "pvla-associated"]
    154 gdb_continue_to_breakpoint "pvla-associated"
    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"]
    161 gdb_continue_to_breakpoint "pvla-deassociated"
    162 gdb_test "print \$mypvar(1,3,8)" " = 1001" \
    163   "print \$mypvar(1,3,8) after deallocated"
    164