1 # Copyright (C) 2008-2012 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This file is part of the GDB testsuite. It tests Python-based
17 # pretty-printing for MI.
19 load_lib mi-support.exp
27 standard_testfile py-prettyprint.c
28 set pyfile py-prettyprint.py
29 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DMI}] != "" } {
30 untested ${testfile}.exp
35 mi_gdb_reinitialize_dir $srcdir/$subdir
36 mi_gdb_load ${binfile}
38 if {[lsearch -exact [mi_get_features] python] < 0} {
39 unsupported "python support is disabled"
45 set remote_python_file [remote_download host ${srcdir}/${subdir}/${pyfile}]
47 mi_gdb_test "python execfile ('${remote_python_file}')" ""
49 mi_continue_to_line [gdb_get_line_number {MI breakpoint here} ${srcfile}] \
52 mi_create_dynamic_varobj container c \
53 "create container varobj, no pretty-printing"
55 mi_list_varobj_children container {
56 { container.name name 1 string }
57 { container.len len 0 int }
58 { container.elements elements 1 "int ." }
59 } "examine container children=0, no pretty-printing"
61 mi_delete_varobj container "delete varobj"
63 mi_create_dynamic_varobj nscont nstype \
64 "create nscont varobj, no pretty-printing"
66 mi_list_varobj_children nscont {
67 { nscont.len len 0 int }
68 { nscont.elements elements 1 "int ." }
69 } "examine nscont children=0, no pretty-printing"
71 mi_delete_varobj nscont "delete varobj"
73 mi_gdb_test "-enable-pretty-printing" ""
75 mi_create_varobj_checked string string_1 \
76 "struct string_repr" \
77 "create string_1 varobj"
79 mi_create_varobj_checked lstring estring \
81 "create estring varobj"
83 mi_gdb_test "-data-evaluate-expression \"string_1 = string_2\"" ".*" \
84 "assign string_1 from string_2"
86 mi_gdb_test "-var-update string" \
87 "\\^done,changelist=\\\[{name=\"string\",in_scope=\"true\",type_changed=\"false\",dynamic=\"1\",has_more=\"0\"}\\\]" \
88 "update string varobj after assignment"
90 mi_create_dynamic_varobj container c \
91 "create container varobj"
93 mi_list_varobj_children container {
94 } "examine container children=0"
96 mi_next "next over update 1"
98 mi_varobj_update_dynamic container "varobj update 1" {
99 type_changed false new_num_children 1 dynamic 1 has_more 0
102 { name {container.\[0\]} exp {\[0\]} numchild 0 type int thread-id 1 }
105 mi_next "next over update 2"
107 mi_varobj_update_dynamic container "varobj update 2" {
108 type_changed false new_num_children 2 dynamic 1 has_more 0
111 { name {container.\[1\]} exp {\[1\]} numchild 0 type int thread-id 1 }
114 mi_gdb_test "-var-set-visualizer container None" \
118 mi_gdb_test "-var-update container" \
119 "\\^done,changelist=\\\[\\\]" \
120 "varobj update after clearing"
122 mi_gdb_test "-var-set-visualizer container gdb.default_visualizer" \
124 "choose default visualizer"
126 mi_varobj_update_dynamic container "varobj update after choosing default" {
127 type_changed false new_num_children 2 dynamic 1 has_more 0
130 { name {container.\[0\]} exp {\[0\]} numchild 0 type int thread-id 1 }
131 { name {container.\[1\]} exp {\[1\]} numchild 0 type int thread-id 1 }
134 mi_gdb_test "-var-set-visualizer container ContainerPrinter" \
136 "choose visualizer using expression"
138 mi_varobj_update_dynamic container \
139 "varobj update after choosing via expression" {
140 type_changed false new_num_children 2 dynamic 1 has_more 0
143 { name {container.\[0\]} exp {\[0\]} numchild 0 type int thread-id 1 }
144 { name {container.\[1\]} exp {\[1\]} numchild 0 type int thread-id 1 }
147 mi_list_varobj_children_range container 1 2 2 {
148 { {container.\[1\]} {\[1\]} 0 int }
149 } "list varobj children after selecting child range"
151 mi_list_varobj_children_range container -1 -1 2 {
152 { {container.\[0\]} {\[0\]} 0 int }
153 { {container.\[1\]} {\[1\]} 0 int }
154 } "list varobj children after resetting child range"
156 mi_next "next over update 3"
158 mi_gdb_test "-var-set-update-range container 0 1" \
162 # This should truncate the list.
163 mi_list_varobj_children container {
164 { {container.\[0\]} {\[0\]} 0 int }
165 } "list children after setting update range"
167 # This should return just the items in [1,2).
168 mi_list_varobj_children_range container 1 2 2 {
169 { {container.\[1\]} {\[1\]} 0 int }
170 } "list selected children after setting range"
172 # This should not be affected by the previous list-children request.
173 mi_list_varobj_children container {
174 { {container.\[0\]} {\[0\]} 0 int }
175 } "list children after listing selected range"
177 mi_next "next over update 4"
179 # This should only show the first child, because the update range has
181 mi_varobj_update_dynamic container \
182 "update after next with restricted range" {
183 type_changed false new_num_children 1 dynamic 1 has_more 1
185 { name {container.\[0\]} in_scope true type_changed false has_more 0 }
189 mi_gdb_test "-var-set-update-range container 3 4" \
191 "set update range with non-zero start"
193 # Elements were updated but should not be reported.
194 mi_varobj_update_dynamic container \
195 "update varobj with change outside selected range" {
196 type_changed false new_num_children 3 dynamic 1 has_more 0
201 mi_next "next over update 5"
203 # Regression test: examine an object that has no children, then update
204 # it to ensure that we don't print the children.
205 mi_create_dynamic_varobj container2 c2 \
206 "create second container varobj"
208 mi_gdb_test "-var-update container2" \
209 "\\^done,changelist=.." \
210 "update varobj, no children requested"
212 mi_next "next over update 6"
214 # Now container2 has an element -- and an update should mention that
215 # it has_more. But, because we did not request children, we still
216 # should not actually see them.
217 mi_varobj_update_dynamic container2 \
218 "update varobj 2, no children requested" {
219 type_changed false dynamic 1 has_more 1
222 mi_continue_to_line \
223 [gdb_get_line_number {MI outer breakpoint here} ${srcfile}] \
224 "step to outer breakpoint"
226 mi_create_dynamic_varobj outer outer \
227 "create outer varobj"
229 mi_list_varobj_children outer {
230 { outer.s s 2 "struct substruct" }
231 { outer.x x 0 "int" }
232 } "list children of outer"
234 mi_list_varobj_children outer.s {
235 { outer.s.a a 0 int }
236 { outer.s.b b 0 int }
237 } "list children of outer.s"
239 mi_next "next over outer update"
241 mi_gdb_test "-var-update outer" \
242 ".done,changelist=.{name=\"outer.s.a\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"}." \
243 "update after updating element of outer"
245 mi_continue_to_line \
246 [gdb_get_line_number {Another MI breakpoint} ${srcfile}] \
247 "step to second breakpoint"
249 mi_varobj_update_with_type_change container int 0 "update after type change"
252 mi_continue_to_line \
253 [gdb_get_line_number {break to inspect struct and union} ${srcfile}] \
254 "step to outer breakpoint"
256 mi_create_dynamic_varobj nscont nstype \
257 "create nstype varobj"
259 mi_list_varobj_children nscont {
260 { {nscont.\[0\]} {\[0\]} 0 int }
261 { {nscont.\[1\]} {\[1\]} 0 int }
262 } "list children after setting update range"
264 mi_gdb_test "-var-set-visualizer nscont None" \
268 mi_gdb_test "-var-update nscont" \
269 "\\^done,changelist=\\\[\\\]" \
270 "varobj update after clearing"
272 mi_gdb_test "-var-set-visualizer nscont gdb.default_visualizer" \
274 "choose default visualizer"
276 mi_gdb_test "python exception_flag = True" ""
278 mi_create_dynamic_varobj nstype2 nstype2 \
279 "create nstype2 varobj"
281 mi_list_varobj_children nstype2 {
282 { {nstype2.<error at 0>} {<error at 0>} 6 {char \[6\]} }
283 } "list children after setting exception flag"
285 mi_create_varobj me me \
288 mi_gdb_test "-var-evaluate-expression me" \
289 "\\^done,value=\"<error reading variable: Cannot access memory.>.*\"" \
292 # Regression test for python/14836.
293 mi_create_dynamic_varobj children_as_list children_as_list \
294 "printer whose children are returned as a list"
296 # Regression test for bug 14741.
297 mi_continue_to_line \
298 [gdb_get_line_number {breakpoint bug 14741} ${srcfile}] \
299 "step to breakpoint for bug 14741"
301 mi_create_dynamic_varobj c c \
302 "create varobj for c"
304 mi_gdb_test "-var-set-visualizer c ArrayPrinter" \
306 "choose array visualizer for c"
308 mi_list_varobj_children c {
309 { {c.\[0\]} {\[0\]} 0 int }
310 } "list children of c"
312 mi_next "next over change of array element"
314 mi_gdb_test "-var-update c" \
315 "\\^done,changelist=\\\[{name=\"c.\\\[0\\\]\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"}\\\]" \
316 "update varobj after element change"
320 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}-cxx" \
321 executable {debug c++ additional_flags=-DMI}] != "" } {
322 untested "Couldn't compile ${srcfile} in c++ mode"
329 mi_delete_breakpoints
330 mi_gdb_reinitialize_dir $srcdir/$subdir
331 mi_gdb_load ${binfile}-cxx
333 if {[lsearch -exact [mi_get_features] python] < 0} {
334 unsupported "python support is disabled"
339 mi_continue_to_line \
340 [gdb_get_line_number {break to inspect struct and union} ${srcfile}] \
343 # Test python/12531. Install visualizer on a cplus_fake_child.
344 mi_create_varobj fake fake \
347 mi_list_varobj_children fake {
348 { fake.private private 1 }
349 } "list children of fake"
351 mi_list_varobj_children fake.private {
352 { fake.private.sname sname 0 int }
353 } "list children fake.private"
355 mi_gdb_test "-var-set-visualizer fake.private gdb.default_visualizer" \
356 "\\^done" "Install visualizer on a cplus_fake_child"
358 remote_file host delete ${remote_python_file}