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