Update copyright year range in all GDB files.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-vla-fortran.exp
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
19 load_lib mi-support.exp
20 load_lib fortran.exp
21 set MIFLAGS "-i=mi"
22
23 gdb_exit
24 if [mi_gdb_start] {
25 continue
26 }
27
28 standard_testfile vla.f90
29
30 if { [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.
38 set real [fortran_real4]
39
40 mi_delete_breakpoints
41 mi_gdb_reinitialize_dir $srcdir/$subdir
42 mi_gdb_load ${binfile}
43
44 set bp_lineno [gdb_get_line_number "vla1-not-allocated"]
45 mi_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
48 mi_run_cmd
49 mi_expect_stop "breakpoint-hit" "vla" "" ".*vla.f90" "$bp_lineno" \
50 { "" "disp=\"del\"" } "run to breakpoint at line $bp_lineno"
51 mi_gdb_test "500-data-evaluate-expression vla1" \
52 "500\\^done,value=\"<not allocated>\"" "evaluate not allocated vla, before allocation"
53
54 mi_create_varobj_checked vla1_not_allocated vla1 "$real, allocatable \\(:\\)" \
55 "create local variable vla1_not_allocated"
56 mi_gdb_test "501-var-info-type vla1_not_allocated" \
57 "501\\^done,type=\"$real, allocatable \\(:\\)\"" \
58 "info type variable vla1_not_allocated"
59 mi_gdb_test "502-var-show-format vla1_not_allocated" \
60 "502\\^done,format=\"natural\"" \
61 "show format variable vla1_not_allocated"
62 mi_gdb_test "503-var-evaluate-expression vla1_not_allocated" \
63 "503\\^done,value=\"\\\[0\\\]\"" \
64 "eval variable vla1_not_allocated"
65 mi_list_array_varobj_children_with_index "vla1_not_allocated" "0" "1" \
66 "$real" "get children of vla1_not_allocated"
67
68
69
70 set bp_lineno [gdb_get_line_number "vla1-allocated"]
71 mi_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
74 mi_run_cmd
75 mi_expect_stop "breakpoint-hit" "vla" "" ".*vla.f90" "$bp_lineno" \
76 { "" "disp=\"del\"" } "run to breakpoint at line $bp_lineno"
77 mi_gdb_test "510-data-evaluate-expression vla1" \
78 "510\\^done,value=\"\\(.*\\)\"" "evaluate allocated vla"
79
80 mi_create_varobj_checked vla1_allocated vla1 "$real, allocatable \\\(5\\\)" \
81 "create local variable vla1_allocated"
82 mi_gdb_test "511-var-info-type vla1_allocated" \
83 "511\\^done,type=\"$real, allocatable \\\(5\\\)\"" \
84 "info type variable vla1_allocated"
85 mi_gdb_test "512-var-show-format vla1_allocated" \
86 "512\\^done,format=\"natural\"" \
87 "show format variable vla1_allocated"
88 mi_gdb_test "513-var-evaluate-expression vla1_allocated" \
89 "513\\^done,value=\"\\\[5\\\]\"" \
90 "eval variable vla1_allocated"
91 mi_list_array_varobj_children_with_index "vla1_allocated" "5" "1" \
92 "$real" "get children of vla1_allocated"
93
94
95 set bp_lineno [gdb_get_line_number "vla1-filled"]
96 mi_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
99 mi_run_cmd
100 mi_expect_stop "breakpoint-hit" "vla" "" ".*vla.f90" "$bp_lineno" \
101 { "" "disp=\"del\"" } "run to breakpoint at line $bp_lineno"
102 mi_gdb_test "520-data-evaluate-expression vla1" \
103 "520\\^done,value=\"\\(1, 1, 1, 1, 1\\)\"" "evaluate filled vla, filled all 1s"
104
105
106 set bp_lineno [gdb_get_line_number "vla1-modified"]
107 mi_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
110 mi_run_cmd
111 mi_expect_stop "breakpoint-hit" "vla" "" ".*vla.f90" "$bp_lineno" \
112 { "" "disp=\"del\"" } "run to breakpoint at line $bp_lineno"
113 mi_gdb_test "530-data-evaluate-expression vla1" \
114 "530\\^done,value=\"\\(1, 42, 1, 24, 1\\)\"" "evaluate filled vla, contents modified"
115 mi_gdb_test "540-data-evaluate-expression vla1(1)" \
116 "540\\^done,value=\"1\"" "evaluate filled vla(1)"
117 mi_gdb_test "550-data-evaluate-expression vla1(2)" \
118 "550\\^done,value=\"42\"" "evaluate filled vla(2)"
119 mi_gdb_test "560-data-evaluate-expression vla1(4)" \
120 "560\\^done,value=\"24\"" "evaluate filled vla(4)"
121
122
123 set bp_lineno [gdb_get_line_number "vla1-deallocated"]
124 mi_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
127 mi_run_cmd
128 mi_expect_stop "breakpoint-hit" "vla" "" ".*vla.f90" "$bp_lineno" \
129 { "" "disp=\"del\"" } "run to breakpoint at line $bp_lineno"
130 mi_gdb_test "570-data-evaluate-expression vla1" \
131 "570\\^done,value=\"<not allocated>\"" "evaluate not allocated vla, after deallocation"
132
133
134 set bp_lineno [gdb_get_line_number "pvla2-not-associated"]
135 mi_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
138 mi_run_cmd
139 mi_expect_stop "breakpoint-hit" "vla" "" ".*vla.f90" "$bp_lineno" \
140 { "" "disp=\"del\"" } "run to breakpoint at line $bp_lineno"
141
142
143 set test "evaluate not associated vla"
144 send_gdb "580-data-evaluate-expression pvla2\n"
145 gdb_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
175 set bp_lineno [gdb_get_line_number "pvla2-associated"]
176 mi_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
179 mi_run_cmd
180 mi_expect_stop "breakpoint-hit" "vla" "" ".*vla.f90" "$bp_lineno" \
181 { "" "disp=\"del\"" } "run to breakpoint at line $bp_lineno"
182 mi_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
186 mi_create_varobj_checked pvla2_associated pvla2 \
187 "$real \\\(5,2\\\)" "create local variable pvla2_associated"
188 mi_gdb_test "591-var-info-type pvla2_associated" \
189 "591\\^done,type=\"$real \\\(5,2\\\)\"" \
190 "info type variable pvla2_associated"
191 mi_gdb_test "592-var-show-format pvla2_associated" \
192 "592\\^done,format=\"natural\"" \
193 "show format variable pvla2_associated"
194 mi_gdb_test "593-var-evaluate-expression pvla2_associated" \
195 "593\\^done,value=\"\\\[2\\\]\"" \
196 "eval variable pvla2_associated"
197
198
199 set bp_lineno [gdb_get_line_number "pvla2-set-to-null"]
200 mi_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
203 mi_run_cmd
204 mi_expect_stop "breakpoint-hit" "vla" "" ".*vla.f90" "$bp_lineno" \
205 { "" "disp=\"del\"" } "run to breakpoint at line $bp_lineno"
206 mi_gdb_test "600-data-evaluate-expression pvla2" \
207 "600\\^done,value=\"<not associated>\"" "evaluate vla pointer set to null"
208
209 mi_gdb_exit
210 return 0
This page took 0.033634 seconds and 4 git commands to generate.