5ee867b68a47abac412cba8eaa3cdad32d8e267c
[external/binutils.git] / gdb / testsuite / gdb.mi / mi-vla-fortran.exp
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
19 load_lib mi-support.exp
20 set MIFLAGS "-i=mi"
21
22 gdb_exit
23 if [mi_gdb_start] {
24     continue
25 }
26
27 standard_testfile vla.f90
28
29 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable \
30      {debug f90}] != "" } {
31      untested "failed to compile"
32      return -1
33 }
34
35 mi_delete_breakpoints
36 mi_gdb_reinitialize_dir $srcdir/$subdir
37 mi_gdb_load ${binfile}
38
39 set bp_lineno [gdb_get_line_number "vla1-not-allocated"]
40 mi_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)"
43 mi_run_cmd
44 mi_expect_stop "breakpoint-hit" "vla" "" ".*vla.f90" "$bp_lineno" \
45   { "" "disp=\"del\"" } "run to breakpoint at line $bp_lineno"
46 mi_gdb_test "500-data-evaluate-expression vla1" \
47   "500\\^done,value=\"<not allocated>\"" "evaluate not allocated vla"
48
49 mi_create_varobj_checked vla1_not_allocated vla1 "<not allocated>" \
50   "create local variable vla1_not_allocated"
51 mi_gdb_test "501-var-info-type vla1_not_allocated" \
52   "501\\^done,type=\"<not allocated>\"" \
53   "info type variable vla1_not_allocated"
54 mi_gdb_test "502-var-show-format vla1_not_allocated" \
55   "502\\^done,format=\"natural\"" \
56   "show format variable vla1_not_allocated"
57 mi_gdb_test "503-var-evaluate-expression vla1_not_allocated" \
58   "503\\^done,value=\"\\\[0\\\]\"" \
59   "eval variable vla1_not_allocated"
60 mi_list_array_varobj_children_with_index "vla1_not_allocated" "0" "1" \
61     "real\\\(kind=4\\\)" "get children of vla1_not_allocated"
62
63
64
65 set bp_lineno [gdb_get_line_number "vla1-allocated"]
66 mi_create_breakpoint "-t vla.f90:$bp_lineno" 2 "del" "vla" ".*vla.f90" \
67   $bp_lineno $hex "insert breakpoint at line $bp_lineno (vla allocated)"
68 mi_run_cmd
69 mi_expect_stop "breakpoint-hit" "vla" "" ".*vla.f90" "$bp_lineno" \
70   { "" "disp=\"del\"" } "run to breakpoint at line $bp_lineno"
71 mi_gdb_test "510-data-evaluate-expression vla1" \
72   "510\\^done,value=\"\\(.*\\)\"" "evaluate allocated vla"
73
74 mi_create_varobj_checked vla1_allocated vla1 "real\\\(kind=4\\\) \\\(5\\\)" \
75   "create local variable vla1_allocated"
76 mi_gdb_test "511-var-info-type vla1_allocated" \
77   "511\\^done,type=\"real\\\(kind=4\\\) \\\(5\\\)\"" \
78   "info type variable vla1_allocated"
79 mi_gdb_test "512-var-show-format vla1_allocated" \
80   "512\\^done,format=\"natural\"" \
81   "show format variable vla1_allocated"
82 mi_gdb_test "513-var-evaluate-expression vla1_allocated" \
83   "513\\^done,value=\"\\\[5\\\]\"" \
84   "eval variable vla1_allocated"
85 mi_list_array_varobj_children_with_index "vla1_allocated" "5" "1" \
86     "real\\\(kind=4\\\)" "get children of vla1_allocated"
87
88
89 set bp_lineno [gdb_get_line_number "vla1-filled"]
90 mi_create_breakpoint "-t vla.f90:$bp_lineno" 3 "del" "vla" ".*vla.f90" \
91   $bp_lineno $hex "insert breakpoint at line $bp_lineno"
92 mi_run_cmd
93 mi_expect_stop "breakpoint-hit" "vla" "" ".*vla.f90" "$bp_lineno" \
94   { "" "disp=\"del\"" } "run to breakpoint at line $bp_lineno"
95 mi_gdb_test "520-data-evaluate-expression vla1" \
96   "520\\^done,value=\"\\(1, 1, 1, 1, 1\\)\"" "evaluate filled vla"
97
98
99 set bp_lineno [gdb_get_line_number "vla1-modified"]
100 mi_create_breakpoint "-t vla.f90:$bp_lineno" 4 "del" "vla" ".*vla.f90" \
101   $bp_lineno $hex "insert breakpoint at line $bp_lineno"
102 mi_run_cmd
103 mi_expect_stop "breakpoint-hit" "vla" "" ".*vla.f90" "$bp_lineno" \
104   { "" "disp=\"del\"" } "run to breakpoint at line $bp_lineno"
105 mi_gdb_test "530-data-evaluate-expression vla1" \
106   "530\\^done,value=\"\\(1, 42, 1, 24, 1\\)\"" "evaluate filled vla"
107 mi_gdb_test "540-data-evaluate-expression vla1(1)" \
108   "540\\^done,value=\"1\"" "evaluate filled vla"
109 mi_gdb_test "550-data-evaluate-expression vla1(2)" \
110   "550\\^done,value=\"42\"" "evaluate filled vla"
111 mi_gdb_test "560-data-evaluate-expression vla1(4)" \
112   "560\\^done,value=\"24\"" "evaluate filled vla"
113
114
115 set bp_lineno [gdb_get_line_number "vla1-deallocated"]
116 mi_create_breakpoint "-t vla.f90:$bp_lineno" 5 "del" "vla" ".*vla.f90" \
117   $bp_lineno $hex "insert breakpoint at line $bp_lineno"
118 mi_run_cmd
119 mi_expect_stop "breakpoint-hit" "vla" "" ".*vla.f90" "$bp_lineno" \
120   { "" "disp=\"del\"" } "run to breakpoint at line $bp_lineno"
121 mi_gdb_test "570-data-evaluate-expression vla1" \
122   "570\\^done,value=\"<not allocated>\"" "evaluate not allocated vla"
123
124
125 set bp_lineno [gdb_get_line_number "pvla2-not-associated"]
126 mi_create_breakpoint "-t vla.f90:$bp_lineno" 6 "del" "vla" ".*vla.f90" \
127   $bp_lineno $hex "insert breakpoint at line $bp_lineno"
128 mi_run_cmd
129 mi_expect_stop "breakpoint-hit" "vla" "" ".*vla.f90" "$bp_lineno" \
130   { "" "disp=\"del\"" } "run to breakpoint at line $bp_lineno"
131
132
133 set test "evaluate not associated vla"
134 send_gdb "580-data-evaluate-expression pvla2\n"
135 gdb_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
165 set bp_lineno [gdb_get_line_number "pvla2-associated"]
166 mi_create_breakpoint "-t vla.f90:$bp_lineno" 7 "del" "vla" ".*vla.f90" \
167   $bp_lineno $hex "insert breakpoint at line $bp_lineno"
168 mi_run_cmd
169 mi_expect_stop "breakpoint-hit" "vla" "" ".*vla.f90" "$bp_lineno" \
170   { "" "disp=\"del\"" } "run to breakpoint at line $bp_lineno"
171 mi_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
175 mi_create_varobj_checked pvla2_associated pvla2 \
176   "real\\\(kind=4\\\) \\\(5,2\\\)" "create local variable pvla2_associated"
177 mi_gdb_test "591-var-info-type pvla2_associated" \
178   "591\\^done,type=\"real\\\(kind=4\\\) \\\(5,2\\\)\"" \
179   "info type variable pvla2_associated"
180 mi_gdb_test "592-var-show-format pvla2_associated" \
181   "592\\^done,format=\"natural\"" \
182   "show format variable pvla2_associated"
183 mi_gdb_test "593-var-evaluate-expression pvla2_associated" \
184   "593\\^done,value=\"\\\[2\\\]\"" \
185   "eval variable pvla2_associated"
186
187
188 set bp_lineno [gdb_get_line_number "pvla2-set-to-null"]
189 mi_create_breakpoint "-t vla.f90:$bp_lineno" 8 "del" "vla" ".*vla.f90" \
190   $bp_lineno $hex "insert breakpoint at line $bp_lineno"
191 mi_run_cmd
192 mi_expect_stop "breakpoint-hit" "vla" "" ".*vla.f90" "$bp_lineno" \
193   { "" "disp=\"del\"" } "run to breakpoint at line $bp_lineno"
194 mi_gdb_test "600-data-evaluate-expression pvla2" \
195   "600\\^done,value=\"<not associated>\"" "evaluate vla pointer set to null"
196
197 mi_gdb_exit
198 return 0