py-mi.exp revision 1.7 1 1.7 christos # Copyright (C) 2008-2017 Free Software Foundation, Inc.
2 1.1 christos
3 1.1 christos # This program is free software; you can redistribute it and/or modify
4 1.1 christos # it under the terms of the GNU General Public License as published by
5 1.1 christos # the Free Software Foundation; either version 3 of the License, or
6 1.1 christos # (at your option) any later version.
7 1.1 christos #
8 1.1 christos # This program is distributed in the hope that it will be useful,
9 1.1 christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 1.1 christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 1.1 christos # GNU General Public License for more details.
12 1.1 christos #
13 1.1 christos # You should have received a copy of the GNU General Public License
14 1.1 christos # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 1.1 christos
16 1.1 christos # This file is part of the GDB testsuite. It tests Python-based
17 1.1 christos # pretty-printing for MI.
18 1.1 christos
19 1.1 christos load_lib mi-support.exp
20 1.1 christos set MIFLAGS "-i=mi2"
21 1.1 christos
22 1.1 christos gdb_exit
23 1.1 christos if [mi_gdb_start] {
24 1.1 christos continue
25 1.1 christos }
26 1.1 christos
27 1.1 christos standard_testfile py-prettyprint.c
28 1.1 christos set pyfile py-prettyprint.py
29 1.1 christos if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DMI}] != "" } {
30 1.7 christos untested "failed to compile"
31 1.1 christos return -1
32 1.1 christos }
33 1.1 christos
34 1.1 christos mi_delete_breakpoints
35 1.1 christos mi_gdb_reinitialize_dir $srcdir/$subdir
36 1.1 christos mi_gdb_load ${binfile}
37 1.1 christos
38 1.1 christos if {[lsearch -exact [mi_get_features] python] < 0} {
39 1.1 christos unsupported "python support is disabled"
40 1.1 christos return -1
41 1.1 christos }
42 1.1 christos
43 1.1 christos mi_runto main
44 1.1 christos
45 1.1 christos set remote_python_file [gdb_remote_download host ${srcdir}/${subdir}/${pyfile}]
46 1.1 christos
47 1.7 christos mi_gdb_test "source ${remote_python_file}" "load python file"
48 1.1 christos
49 1.1 christos mi_continue_to_line [gdb_get_line_number {MI breakpoint here} ${srcfile}] \
50 1.1 christos "step to breakpoint"
51 1.1 christos
52 1.1 christos mi_create_floating_varobj container c \
53 1.1 christos "create container varobj, no pretty-printing"
54 1.1 christos
55 1.1 christos mi_list_varobj_children container {
56 1.1 christos { container.name name 1 string }
57 1.1 christos { container.len len 0 int }
58 1.1 christos { container.elements elements 1 "int ." }
59 1.1 christos } "examine container children=0, no pretty-printing"
60 1.1 christos
61 1.1 christos mi_delete_varobj container "delete varobj"
62 1.1 christos
63 1.1 christos mi_create_floating_varobj nscont nstype \
64 1.1 christos "create nscont varobj, no pretty-printing"
65 1.1 christos
66 1.1 christos mi_list_varobj_children nscont {
67 1.1 christos { nscont.len len 0 int }
68 1.1 christos { nscont.elements elements 1 "int ." }
69 1.1 christos } "examine nscont children=0, no pretty-printing"
70 1.1 christos
71 1.1 christos mi_delete_varobj nscont "delete varobj"
72 1.1 christos
73 1.1 christos mi_gdb_test "-enable-pretty-printing" ""
74 1.1 christos
75 1.1 christos mi_create_varobj_checked string string_1 \
76 1.1 christos "struct string_repr" \
77 1.1 christos "create string_1 varobj"
78 1.1 christos
79 1.1 christos mi_create_varobj_checked lstring estring \
80 1.1 christos "struct lazystring" \
81 1.1 christos "create estring varobj"
82 1.1 christos
83 1.1 christos mi_gdb_test "-data-evaluate-expression \"string_1 = string_2\"" ".*" \
84 1.1 christos "assign string_1 from string_2"
85 1.1 christos
86 1.1 christos mi_gdb_test "-var-update string" \
87 1.1 christos "\\^done,changelist=\\\[{name=\"string\",in_scope=\"true\",type_changed=\"false\",dynamic=\"1\",has_more=\"0\"}\\\]" \
88 1.1 christos "update string varobj after assignment"
89 1.1 christos
90 1.1 christos # The "elements" field of "c" is still empty, so the attribute
91 1.1 christos # "has_more" is expected to be zero.
92 1.1 christos mi_create_dynamic_varobj container c 0 \
93 1.1 christos "create container varobj"
94 1.1 christos
95 1.1 christos mi_list_varobj_children container {
96 1.1 christos } "examine container children=0"
97 1.1 christos
98 1.1 christos mi_next "next over update 1"
99 1.1 christos
100 1.1 christos mi_varobj_update_dynamic container "varobj update 1" {
101 1.1 christos type_changed false new_num_children 1 dynamic 1 has_more 0
102 1.1 christos } {
103 1.1 christos } {
104 1.1 christos { name {container.\[0\]} exp {\[0\]} numchild 0 type int thread-id 1 }
105 1.1 christos }
106 1.1 christos
107 1.1 christos mi_next "next over update 2"
108 1.1 christos
109 1.1 christos mi_varobj_update_dynamic container "varobj update 2" {
110 1.1 christos type_changed false new_num_children 2 dynamic 1 has_more 0
111 1.1 christos } {
112 1.1 christos } {
113 1.1 christos { name {container.\[1\]} exp {\[1\]} numchild 0 type int thread-id 1 }
114 1.1 christos }
115 1.1 christos
116 1.1 christos mi_gdb_test "-var-set-visualizer container None" \
117 1.1 christos "\\^done" \
118 1.1 christos "clear visualizer"
119 1.1 christos
120 1.1 christos mi_gdb_test "-var-update container" \
121 1.1 christos "\\^done,changelist=\\\[\\\]" \
122 1.1 christos "varobj update after clearing"
123 1.1 christos
124 1.1 christos mi_gdb_test "-var-set-visualizer container gdb.default_visualizer" \
125 1.1 christos "\\^done" \
126 1.1 christos "choose default visualizer"
127 1.1 christos
128 1.1 christos mi_varobj_update_dynamic container "varobj update after choosing default" {
129 1.1 christos type_changed false new_num_children 2 dynamic 1 has_more 0
130 1.1 christos } {
131 1.1 christos } {
132 1.1 christos { name {container.\[0\]} exp {\[0\]} numchild 0 type int thread-id 1 }
133 1.1 christos { name {container.\[1\]} exp {\[1\]} numchild 0 type int thread-id 1 }
134 1.1 christos }
135 1.1 christos
136 1.1 christos mi_gdb_test "-var-set-visualizer container ContainerPrinter" \
137 1.1 christos "\\^done" \
138 1.1 christos "choose visualizer using expression"
139 1.1 christos
140 1.1 christos mi_varobj_update_dynamic container \
141 1.1 christos "varobj update after choosing via expression" {
142 1.1 christos type_changed false new_num_children 2 dynamic 1 has_more 0
143 1.1 christos } {
144 1.1 christos } {
145 1.1 christos { name {container.\[0\]} exp {\[0\]} numchild 0 type int thread-id 1 }
146 1.1 christos { name {container.\[1\]} exp {\[1\]} numchild 0 type int thread-id 1 }
147 1.1 christos }
148 1.1 christos
149 1.1 christos mi_list_varobj_children_range container 1 2 2 {
150 1.1 christos { {container.\[1\]} {\[1\]} 0 int }
151 1.1 christos } "list varobj children after selecting child range"
152 1.1 christos
153 1.1 christos mi_list_varobj_children_range container -1 -1 2 {
154 1.1 christos { {container.\[0\]} {\[0\]} 0 int }
155 1.1 christos { {container.\[1\]} {\[1\]} 0 int }
156 1.1 christos } "list varobj children after resetting child range"
157 1.1 christos
158 1.1 christos mi_next "next over update 3"
159 1.1 christos
160 1.1 christos mi_gdb_test "-var-set-update-range container 0 1" \
161 1.1 christos "\\^done" \
162 1.1 christos "set update range"
163 1.1 christos
164 1.1 christos # This should truncate the list.
165 1.1 christos mi_list_varobj_children container {
166 1.1 christos { {container.\[0\]} {\[0\]} 0 int }
167 1.1 christos } "list children after setting update range"
168 1.1 christos
169 1.1 christos # This should return just the items in [1,2).
170 1.1 christos mi_list_varobj_children_range container 1 2 2 {
171 1.1 christos { {container.\[1\]} {\[1\]} 0 int }
172 1.1 christos } "list selected children after setting range"
173 1.1 christos
174 1.1 christos # This should not be affected by the previous list-children request.
175 1.1 christos mi_list_varobj_children container {
176 1.1 christos { {container.\[0\]} {\[0\]} 0 int }
177 1.1 christos } "list children after listing selected range"
178 1.1 christos
179 1.1 christos mi_next "next over update 4"
180 1.1 christos
181 1.1 christos # This should only show the first child, because the update range has
182 1.1 christos # been set.
183 1.1 christos mi_varobj_update_dynamic container \
184 1.1 christos "update after next with restricted range" {
185 1.1 christos type_changed false new_num_children 1 dynamic 1 has_more 1
186 1.1 christos } {
187 1.1 christos { name {container.\[0\]} in_scope true type_changed false has_more 0 }
188 1.1 christos } {
189 1.1 christos }
190 1.1 christos
191 1.1 christos mi_gdb_test "-var-set-update-range container 3 4" \
192 1.1 christos "\\^done" \
193 1.1 christos "set update range with non-zero start"
194 1.1 christos
195 1.1 christos # Elements were updated but should not be reported.
196 1.1 christos mi_varobj_update_dynamic container \
197 1.1 christos "update varobj with change outside selected range" {
198 1.1 christos type_changed false new_num_children 3 dynamic 1 has_more 0
199 1.1 christos } {
200 1.1 christos } {
201 1.1 christos }
202 1.1 christos
203 1.1 christos mi_next "next over update 5"
204 1.1 christos
205 1.1 christos # Regression test: examine an object that has no children, then update
206 1.1 christos # it to ensure that we don't print the children.
207 1.1 christos mi_create_dynamic_varobj container2 c2 0 \
208 1.1 christos "create second container varobj"
209 1.1 christos
210 1.1 christos mi_gdb_test "-var-update container2" \
211 1.1 christos "\\^done,changelist=.." \
212 1.1 christos "update varobj, no children requested"
213 1.1 christos
214 1.1 christos mi_next "next over update 6"
215 1.1 christos
216 1.1 christos # Now container2 has an element -- and an update should mention that
217 1.1 christos # it has_more. But, because we did not request children, we still
218 1.1 christos # should not actually see them.
219 1.1 christos mi_varobj_update_dynamic container2 \
220 1.1 christos "update varobj 2, no children requested" {
221 1.1 christos type_changed false dynamic 1 has_more 1
222 1.1 christos } {} {}
223 1.1 christos
224 1.1 christos mi_continue_to_line \
225 1.1 christos [gdb_get_line_number {MI outer breakpoint here} ${srcfile}] \
226 1.1 christos "step to outer breakpoint"
227 1.1 christos
228 1.1 christos mi_create_dynamic_varobj outer outer 1 \
229 1.1 christos "create outer varobj"
230 1.1 christos
231 1.1 christos mi_list_varobj_children outer {
232 1.1 christos { outer.s s 2 "struct substruct" }
233 1.1 christos { outer.x x 0 "int" }
234 1.1 christos } "list children of outer"
235 1.1 christos
236 1.1 christos mi_list_varobj_children outer.s {
237 1.1 christos { outer.s.a a 0 int }
238 1.1 christos { outer.s.b b 0 int }
239 1.1 christos } "list children of outer.s"
240 1.1 christos
241 1.1 christos mi_next "next over outer update"
242 1.1 christos
243 1.1 christos mi_gdb_test "-var-update outer" \
244 1.1 christos ".done,changelist=.{name=\"outer.s.a\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"}." \
245 1.1 christos "update after updating element of outer"
246 1.1 christos
247 1.1 christos mi_continue_to_line \
248 1.1 christos [gdb_get_line_number {Another MI breakpoint} ${srcfile}] \
249 1.1 christos "step to second breakpoint"
250 1.1 christos
251 1.1 christos mi_varobj_update_with_type_change container int 0 "update after type change"
252 1.1 christos
253 1.1 christos
254 1.1 christos mi_continue_to_line \
255 1.1 christos [gdb_get_line_number {break to inspect struct and union} ${srcfile}] \
256 1.1 christos "step to outer breakpoint"
257 1.1 christos
258 1.1 christos mi_create_dynamic_varobj nscont nstype 1 \
259 1.1 christos "create nstype varobj"
260 1.1 christos
261 1.1 christos mi_list_varobj_children nscont {
262 1.1 christos { {nscont.\[0\]} {\[0\]} 0 int }
263 1.1 christos { {nscont.\[1\]} {\[1\]} 0 int }
264 1.1 christos } "list children after setting update range"
265 1.1 christos
266 1.1 christos mi_gdb_test "-var-set-visualizer nscont None" \
267 1.1 christos "\\^done" \
268 1.1 christos "clear visualizer"
269 1.1 christos
270 1.1 christos mi_gdb_test "-var-update nscont" \
271 1.1 christos "\\^done,changelist=\\\[\\\]" \
272 1.1 christos "varobj update after clearing"
273 1.1 christos
274 1.1 christos mi_gdb_test "-var-set-visualizer nscont gdb.default_visualizer" \
275 1.1 christos "\\^done" \
276 1.1 christos "choose default visualizer"
277 1.1 christos
278 1.1 christos mi_gdb_test "python exception_flag = True" ""
279 1.1 christos
280 1.1 christos mi_create_dynamic_varobj nstype2 nstype2 1 \
281 1.1 christos "create nstype2 varobj"
282 1.1 christos
283 1.1 christos mi_list_varobj_children nstype2 {
284 1.1 christos { {nstype2.<error at 0>} {<error at 0>} 6 {char \[6\]} }
285 1.1 christos } "list children after setting exception flag"
286 1.1 christos
287 1.1 christos mi_create_varobj me me \
288 1.1 christos "create me varobj"
289 1.1 christos
290 1.1 christos mi_gdb_test "-var-evaluate-expression me" \
291 1.1 christos "\\^done,value=\"<error reading variable: Cannot access memory.>.*\"" \
292 1.1 christos "evaluate me varobj"
293 1.1 christos
294 1.1 christos # Regression test for python/14836.
295 1.1 christos mi_create_dynamic_varobj children_as_list children_as_list 1 \
296 1.1 christos "printer whose children are returned as a list"
297 1.1 christos
298 1.1 christos # Regression test for bug 14741.
299 1.1 christos mi_continue_to_line \
300 1.1 christos [gdb_get_line_number {breakpoint bug 14741} ${srcfile}] \
301 1.1 christos "step to breakpoint for bug 14741"
302 1.1 christos
303 1.1 christos mi_create_dynamic_varobj c c 1 \
304 1.1 christos "create varobj for c"
305 1.1 christos
306 1.1 christos mi_gdb_test "-var-set-visualizer c ArrayPrinter" \
307 1.1 christos "\\^done" \
308 1.1 christos "choose array visualizer for c"
309 1.1 christos
310 1.1 christos mi_list_varobj_children c {
311 1.1 christos { {c.\[0\]} {\[0\]} 0 int }
312 1.1 christos } "list children of c"
313 1.1 christos
314 1.1 christos mi_next "next over change of array element"
315 1.1 christos
316 1.1 christos mi_gdb_test "-var-update c" \
317 1.1 christos "\\^done,changelist=\\\[{name=\"c.\\\[0\\\]\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"}\\\]" \
318 1.1 christos "update varobj after element change"
319 1.1 christos
320 1.1 christos # C++ MI tests
321 1.1 christos gdb_exit
322 1.1 christos if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}-cxx" \
323 1.1 christos executable {debug c++ additional_flags=-DMI}] != "" } {
324 1.7 christos untested "failed to compile in C++ mode"
325 1.1 christos return -1
326 1.1 christos }
327 1.1 christos
328 1.1 christos if [mi_gdb_start] {
329 1.1 christos continue
330 1.1 christos }
331 1.1 christos mi_delete_breakpoints
332 1.1 christos mi_gdb_reinitialize_dir $srcdir/$subdir
333 1.1 christos mi_gdb_load ${binfile}-cxx
334 1.1 christos
335 1.1 christos if {[lsearch -exact [mi_get_features] python] < 0} {
336 1.1 christos unsupported "python support is disabled"
337 1.1 christos return -1
338 1.1 christos }
339 1.1 christos
340 1.1 christos mi_runto main
341 1.1 christos mi_continue_to_line \
342 1.1 christos [gdb_get_line_number {break to inspect struct and union} ${srcfile}] \
343 1.1 christos "step to breakpoint"
344 1.1 christos
345 1.1 christos # Test python/12531. Install visualizer on a cplus_fake_child.
346 1.1 christos mi_create_varobj fake fake \
347 1.1 christos "create fake varobj"
348 1.1 christos
349 1.1 christos mi_list_varobj_children fake {
350 1.1 christos { fake.private private 1 }
351 1.1 christos } "list children of fake"
352 1.1 christos
353 1.1 christos mi_list_varobj_children fake.private {
354 1.1 christos { fake.private.sname sname 0 int }
355 1.1 christos } "list children fake.private"
356 1.1 christos
357 1.1 christos mi_gdb_test "-var-set-visualizer fake.private gdb.default_visualizer" \
358 1.1 christos "\\^done" "Install visualizer on a cplus_fake_child"
359