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