Home | History | Annotate | Line # | Download | only in gdb.mi
mi-vla-fortran.exp revision 1.1.1.7
      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 # Verify that, using the MI, we can evaluate a simple Fortran Variable
     17 # Length Array (VLA).
     18 
     19 require allow_fortran_tests
     20 
     21 load_lib mi-support.exp
     22 load_lib fortran.exp
     23 set MIFLAGS "-i=mi"
     24 
     25 standard_testfile vla.f90
     26 
     27 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable \
     28      {debug f90}] != "" } {
     29      untested "failed to compile"
     30      return -1
     31 }
     32 
     33 # Depending on the compiler being used,
     34 # the type names can be printed differently.
     35 set real [fortran_real4]
     36 
     37 if {[mi_clean_restart $binfile]} {
     38     return
     39 }
     40 
     41 set bp_lineno [gdb_get_line_number "vla1-not-allocated"]
     42 mi_create_breakpoint "-t vla.f90:$bp_lineno" \
     43     "insert breakpoint at line $bp_lineno (vla not allocated)" \
     44     -number 1 -disp del -func vla
     45 mi_run_cmd
     46 mi_expect_stop "breakpoint-hit" "vla" "" ".*vla.f90" "$bp_lineno" \
     47   { "" "disp=\"del\"" } "run to breakpoint at line $bp_lineno"
     48 mi_gdb_test "500-data-evaluate-expression vla1" \
     49   "500\\^done,value=\"<not allocated>\"" "evaluate not allocated vla, before allocation"
     50 
     51 mi_create_varobj_checked vla1_not_allocated vla1 "$real, allocatable \\(:\\)" \
     52   "create local variable vla1_not_allocated"
     53 mi_gdb_test "501-var-info-type vla1_not_allocated" \
     54   "501\\^done,type=\"$real, allocatable \\(:\\)\"" \
     55   "info type variable vla1_not_allocated"
     56 mi_gdb_test "502-var-show-format vla1_not_allocated" \
     57   "502\\^done,format=\"natural\"" \
     58   "show format variable vla1_not_allocated"
     59 mi_gdb_test "503-var-evaluate-expression vla1_not_allocated" \
     60   "503\\^done,value=\"\\\[0\\\]\"" \
     61   "eval variable vla1_not_allocated"
     62 mi_list_array_varobj_children_with_index "vla1_not_allocated" "0" "1" \
     63     "$real" "get children of vla1_not_allocated"
     64 
     65 
     66 
     67 set bp_lineno [gdb_get_line_number "vla1-allocated"]
     68 mi_create_breakpoint "-t vla.f90:$bp_lineno" \
     69     "insert breakpoint at line $bp_lineno (vla allocated)" \
     70     -number 2 -disp del -func vla
     71 mi_run_cmd
     72 mi_expect_stop "breakpoint-hit" "vla" "" ".*vla.f90" "$bp_lineno" \
     73   { "" "disp=\"del\"" } "run to breakpoint at line $bp_lineno"
     74 mi_gdb_test "510-data-evaluate-expression vla1" \
     75   "510\\^done,value=\"\\(.*\\)\"" "evaluate allocated vla"
     76 
     77 mi_create_varobj_checked vla1_allocated vla1 "$real, allocatable \\\(5\\\)" \
     78   "create local variable vla1_allocated"
     79 mi_gdb_test "511-var-info-type vla1_allocated" \
     80   "511\\^done,type=\"$real, allocatable \\\(5\\\)\"" \
     81   "info type variable vla1_allocated"
     82 mi_gdb_test "512-var-show-format vla1_allocated" \
     83   "512\\^done,format=\"natural\"" \
     84   "show format variable vla1_allocated"
     85 mi_gdb_test "513-var-evaluate-expression vla1_allocated" \
     86   "513\\^done,value=\"\\\[5\\\]\"" \
     87   "eval variable vla1_allocated"
     88 mi_list_array_varobj_children_with_index "vla1_allocated" "5" "1" \
     89     "$real" "get children of vla1_allocated"
     90 
     91 
     92 set bp_lineno [gdb_get_line_number "vla1-filled"]
     93 mi_create_breakpoint "-t vla.f90:$bp_lineno" \
     94     "insert breakpoint at line $bp_lineno" \
     95     -number 3 -disp del -func vla
     96 mi_run_cmd
     97 mi_expect_stop "breakpoint-hit" "vla" "" ".*vla.f90" "$bp_lineno" \
     98   { "" "disp=\"del\"" } "run to breakpoint at line $bp_lineno"
     99 mi_gdb_test "520-data-evaluate-expression vla1" \
    100   "520\\^done,value=\"\\(1, 1, 1, 1, 1\\)\"" "evaluate filled vla, filled all 1s"
    101 
    102 
    103 set bp_lineno [gdb_get_line_number "vla1-modified"]
    104 mi_create_breakpoint "-t vla.f90:$bp_lineno" \
    105     "insert breakpoint at line $bp_lineno" \
    106     -number 4 -disp del -func vla
    107 mi_run_cmd
    108 mi_expect_stop "breakpoint-hit" "vla" "" ".*vla.f90" "$bp_lineno" \
    109   { "" "disp=\"del\"" } "run to breakpoint at line $bp_lineno"
    110 mi_gdb_test "530-data-evaluate-expression vla1" \
    111   "530\\^done,value=\"\\(1, 42, 1, 24, 1\\)\"" "evaluate filled vla, contents modified"
    112 mi_gdb_test "540-data-evaluate-expression vla1(1)" \
    113   "540\\^done,value=\"1\"" "evaluate filled vla(1)"
    114 mi_gdb_test "550-data-evaluate-expression vla1(2)" \
    115   "550\\^done,value=\"42\"" "evaluate filled vla(2)"
    116 mi_gdb_test "560-data-evaluate-expression vla1(4)" \
    117   "560\\^done,value=\"24\"" "evaluate filled vla(4)"
    118 
    119 
    120 set bp_lineno [gdb_get_line_number "vla1-deallocated"]
    121 mi_create_breakpoint "-t vla.f90:$bp_lineno" \
    122     "insert breakpoint at line $bp_lineno" \
    123     -number 5 -disp del -func vla
    124 mi_run_cmd
    125 mi_expect_stop "breakpoint-hit" "vla" "" ".*vla.f90" "$bp_lineno" \
    126   { "" "disp=\"del\"" } "run to breakpoint at line $bp_lineno"
    127 mi_gdb_test "570-data-evaluate-expression vla1" \
    128   "570\\^done,value=\"<not allocated>\"" "evaluate not allocated vla, after deallocation"
    129 
    130 
    131 set bp_lineno [gdb_get_line_number "pvla2-not-associated"]
    132 mi_create_breakpoint "-t vla.f90:$bp_lineno" \
    133     "insert breakpoint at line $bp_lineno" \
    134     -number 6 -disp "del" -func "vla"
    135 mi_run_cmd
    136 mi_expect_stop "breakpoint-hit" "vla" "" ".*vla.f90" "$bp_lineno" \
    137   { "" "disp=\"del\"" } "run to breakpoint at line $bp_lineno"
    138 
    139 
    140 set test "evaluate not associated vla"
    141 send_gdb "580-data-evaluate-expression pvla2\n"
    142 gdb_expect {
    143     -re "580\\^done,value=\"<not associated>\".*${mi_gdb_prompt}$" {
    144 	pass $test
    145 
    146 	mi_create_varobj_checked pvla2_not_associated pvla2 "$real \\(:,:\\)" \
    147 	    "create local variable pvla2_not_associated"
    148 	mi_gdb_test "581-var-info-type pvla2_not_associated" \
    149 	    "581\\^done,type=\"$real \\(:,:\\)\"" \
    150 	    "info type variable pvla2_not_associated"
    151 	mi_gdb_test "582-var-show-format pvla2_not_associated" \
    152 	    "582\\^done,format=\"natural\"" \
    153 	    "show format variable pvla2_not_associated"
    154 	mi_gdb_test "583-var-evaluate-expression pvla2_not_associated" \
    155 	    "583\\^done,value=\"\\\[0\\\]\"" \
    156 	    "eval variable pvla2_not_associated"
    157 	mi_list_array_varobj_children_with_index "pvla2_not_associated" "0" "1" \
    158 	    "$real" "get children of pvla2_not_associated"
    159     }
    160     -re "580\\^error,msg=\"value contents too large \\(\[0-9\]+ bytes\\).*${mi_gdb_prompt}$" {
    161 	# Undefined behavior in gfortran.
    162 	xfail $test
    163     }
    164     -re "${mi_gdb_prompt}$" {
    165 	fail $test
    166     }
    167     timeout {
    168 	fail "$test (timeout)"
    169     }
    170 }
    171 
    172 set bp_lineno [gdb_get_line_number "pvla2-associated"]
    173 mi_create_breakpoint "-t vla.f90:$bp_lineno" \
    174     "insert breakpoint at line $bp_lineno" \
    175     -number 7 -disp del -func vla
    176 mi_run_cmd
    177 mi_expect_stop "breakpoint-hit" "vla" "" ".*vla.f90" "$bp_lineno" \
    178   { "" "disp=\"del\"" } "run to breakpoint at line $bp_lineno"
    179 mi_gdb_test "590-data-evaluate-expression pvla2" \
    180   "590\\^done,value=\"\\(\\(2, 2, 2, 2, 2\\) \\(2, 2, 2, 2, 2\\)\\)\"" \
    181   "evaluate associated vla"
    182 
    183 mi_create_varobj_checked pvla2_associated pvla2 \
    184   "$real \\\(5,2\\\)" "create local variable pvla2_associated"
    185 mi_gdb_test "591-var-info-type pvla2_associated" \
    186   "591\\^done,type=\"$real \\\(5,2\\\)\"" \
    187   "info type variable pvla2_associated"
    188 mi_gdb_test "592-var-show-format pvla2_associated" \
    189   "592\\^done,format=\"natural\"" \
    190   "show format variable pvla2_associated"
    191 mi_gdb_test "593-var-evaluate-expression pvla2_associated" \
    192   "593\\^done,value=\"\\\[2\\\]\"" \
    193   "eval variable pvla2_associated"
    194 
    195 
    196 set bp_lineno [gdb_get_line_number "pvla2-set-to-null"]
    197 mi_create_breakpoint "-t vla.f90:$bp_lineno" \
    198     "insert breakpoint at line $bp_lineno" \
    199     -number 8 -disp del -func vla
    200 mi_run_cmd
    201 mi_expect_stop "breakpoint-hit" "vla" "" ".*vla.f90" "$bp_lineno" \
    202   { "" "disp=\"del\"" } "run to breakpoint at line $bp_lineno"
    203 mi_gdb_test "600-data-evaluate-expression pvla2" \
    204   "600\\^done,value=\"<not associated>\"" "evaluate vla pointer set to null"
    205 
    206 mi_gdb_exit
    207