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
28 set srcfile py-prettyprint.c
29 set binfile ${objdir}/${subdir}/${testfile}
30 set pyfile py-prettyprint.py
31 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DMI}] != "" } {
32 untested ${testfile}.exp
37 mi_gdb_reinitialize_dir $srcdir/$subdir
38 mi_gdb_load ${binfile}
40 if {[lsearch -exact [mi_get_features] python] < 0} {
41 unsupported "python support is disabled"
47 set remote_python_file [remote_download host ${srcdir}/${subdir}/${pyfile}]
49 mi_gdb_test "python execfile ('${remote_python_file}')" ""
51 mi_continue_to_line [gdb_get_line_number {MI breakpoint here} ${srcfile}] \
54 mi_create_dynamic_varobj container c \
55 "create container varobj, no pretty-printing"
57 mi_list_varobj_children container {
58 { container.name name 1 string }
59 { container.len len 0 int }
60 { container.elements elements 1 "int ." }
61 } "examine container children=0, no pretty-printing"
63 mi_delete_varobj container "delete varobj"
65 mi_create_dynamic_varobj nscont nstype \
66 "create nscont varobj, no pretty-printing"
68 mi_list_varobj_children nscont {
69 { nscont.len len 0 int }
70 { nscont.elements elements 1 "int ." }
71 } "examine nscont children=0, no pretty-printing"
73 mi_delete_varobj nscont "delete varobj"
75 mi_gdb_test "-enable-pretty-printing" ""
77 mi_create_varobj_checked string string_1 \
78 "struct string_repr" \
79 "create string_1 varobj"
81 mi_create_varobj_checked lstring estring \
83 "create estring varobj"
85 mi_gdb_test "-data-evaluate-expression \"string_1 = string_2\"" ".*" \
86 "assign string_1 from string_2"
88 mi_gdb_test "-var-update string" \
89 "\\^done,changelist=\\\[{name=\"string\",in_scope=\"true\",type_changed=\"false\",dynamic=\"1\",has_more=\"0\"}\\\]" \
90 "update string varobj after assignment"
92 mi_create_dynamic_varobj container c \
93 "create container varobj"
95 mi_list_varobj_children container {
96 } "examine container children=0"
98 mi_next "next over update 1"
100 mi_varobj_update_dynamic container "varobj update 1" {
101 type_changed false new_num_children 1 dynamic 1 has_more 0
104 { name {container.\[0\]} exp {\[0\]} numchild 0 type int thread-id 1 }
107 mi_next "next over update 2"
109 mi_varobj_update_dynamic container "varobj update 2" {
110 type_changed false new_num_children 2 dynamic 1 has_more 0
113 { name {container.\[1\]} exp {\[1\]} numchild 0 type int thread-id 1 }
116 mi_gdb_test "-var-set-visualizer container None" \
120 mi_gdb_test "-var-update container" \
121 "\\^done,changelist=\\\[\\\]" \
122 "varobj update after clearing"
124 mi_gdb_test "-var-set-visualizer container gdb.default_visualizer" \
126 "choose default visualizer"
128 mi_varobj_update_dynamic container "varobj update after choosing default" {
129 type_changed false new_num_children 2 dynamic 1 has_more 0
132 { name {container.\[0\]} exp {\[0\]} numchild 0 type int thread-id 1 }
133 { name {container.\[1\]} exp {\[1\]} numchild 0 type int thread-id 1 }
136 mi_gdb_test "-var-set-visualizer container ContainerPrinter" \
138 "choose visualizer using expression"
140 mi_varobj_update_dynamic container \
141 "varobj update after choosing via expression" {
142 type_changed false new_num_children 2 dynamic 1 has_more 0
145 { name {container.\[0\]} exp {\[0\]} numchild 0 type int thread-id 1 }
146 { name {container.\[1\]} exp {\[1\]} numchild 0 type int thread-id 1 }
149 mi_list_varobj_children_range container 1 2 2 {
150 { {container.\[1\]} {\[1\]} 0 int }
151 } "list varobj children after selecting child range"
153 mi_list_varobj_children_range container -1 -1 2 {
154 { {container.\[0\]} {\[0\]} 0 int }
155 { {container.\[1\]} {\[1\]} 0 int }
156 } "list varobj children after resetting child range"
158 mi_next "next over update 3"
160 mi_gdb_test "-var-set-update-range container 0 1" \
164 # This should truncate the list.
165 mi_list_varobj_children container {
166 { {container.\[0\]} {\[0\]} 0 int }
167 } "list children after setting update range"
169 # This should return just the items in [1,2).
170 mi_list_varobj_children_range container 1 2 2 {
171 { {container.\[1\]} {\[1\]} 0 int }
172 } "list selected children after setting range"
174 # This should not be affected by the previous list-children request.
175 mi_list_varobj_children container {
176 { {container.\[0\]} {\[0\]} 0 int }
177 } "list children after listing selected range"
179 mi_next "next over update 4"
181 # This should only show the first child, because the update range has
183 mi_varobj_update_dynamic container \
184 "update after next with restricted range" {
185 type_changed false new_num_children 1 dynamic 1 has_more 1
187 { name {container.\[0\]} in_scope true type_changed false dynamic 1 has_more 0 }
191 mi_gdb_test "-var-set-update-range container 3 4" \
193 "set update range with non-zero start"
195 # Elements were updated but should not be reported.
196 mi_varobj_update_dynamic container \
197 "update varobj with change outside selected range" {
198 type_changed false new_num_children 3 dynamic 1 has_more 0
203 mi_next "next over update 5"
205 # Regression test: examine an object that has no children, then update
206 # it to ensure that we don't print the children.
207 mi_create_dynamic_varobj container2 c2 \
208 "create second container varobj"
210 mi_gdb_test "-var-update container2" \
211 "\\^done,changelist=.." \
212 "update varobj, no children requested"
214 mi_next "next over update 6"
216 # Now container2 has an element -- and an update should mention that
217 # it has_more. But, because we did not request children, we still
218 # should not actually see them.
219 mi_varobj_update_dynamic container2 \
220 "update varobj 2, no children requested" {
221 type_changed false dynamic 1 has_more 1
224 mi_continue_to_line \
225 [gdb_get_line_number {MI outer breakpoint here} ${srcfile}] \
226 "step to outer breakpoint"
228 mi_create_dynamic_varobj outer outer \
229 "create outer varobj"
231 mi_list_varobj_children outer {
232 { outer.s s 2 "struct substruct" }
233 { outer.x x 0 "int" }
234 } "list children of outer"
236 mi_list_varobj_children outer.s {
237 { outer.s.a a 0 int }
238 { outer.s.b b 0 int }
239 } "list children of outer.s"
241 mi_next "next over outer update"
243 mi_gdb_test "-var-update outer" \
244 ".done,changelist=.{name=\"outer.s.a\",in_scope=\"true\",type_changed=\"false\",dynamic=\"1\",has_more=\"0\"}." \
245 "update after updating element of outer"
247 mi_continue_to_line \
248 [gdb_get_line_number {Another MI breakpoint} ${srcfile}] \
249 "step to second breakpoint"
251 mi_varobj_update_with_type_change container int 0 "update after type change"
254 mi_continue_to_line \
255 [gdb_get_line_number {break to inspect struct and union} ${srcfile}] \
256 "step to outer breakpoint"
258 mi_create_dynamic_varobj nscont nstype \
259 "create nstype varobj"
261 mi_list_varobj_children nscont {
262 { {nscont.\[0\]} {\[0\]} 0 int }
263 { {nscont.\[1\]} {\[1\]} 0 int }
264 } "list children after setting update range"
266 mi_gdb_test "-var-set-visualizer nscont None" \
270 mi_gdb_test "-var-update nscont" \
271 "\\^done,changelist=\\\[\\\]" \
272 "varobj update after clearing"
274 mi_gdb_test "-var-set-visualizer nscont gdb.default_visualizer" \
276 "choose default visualizer"
278 mi_gdb_test "python exception_flag = True" ""
280 mi_create_dynamic_varobj nstype2 nstype2 \
281 "create nstype2 varobj"
283 mi_list_varobj_children nstype2 {
284 { {nstype2.<error at 0>} {<error at 0>} 6 {char \[6\]} }
285 } "list children after setting exception flag"
287 mi_create_varobj me me \
290 mi_gdb_test "-var-evaluate-expression me" \
291 "\\^done,value=\"<error reading variable: Cannot access memory.>.*\"" \
296 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}-cxx" \
297 executable {debug c++ additional_flags=-DMI}] != "" } {
298 untested "Couldn't compile ${srcfile} in c++ mode"
305 mi_delete_breakpoints
306 mi_gdb_reinitialize_dir $srcdir/$subdir
307 mi_gdb_load ${binfile}-cxx
309 if {[lsearch -exact [mi_get_features] python] < 0} {
310 unsupported "python support is disabled"
315 mi_continue_to_line \
316 [gdb_get_line_number {break to inspect struct and union} ${srcfile}] \
319 # Test python/12531. Install visualizer on a cplus_fake_child.
320 mi_create_varobj fake fake \
323 mi_list_varobj_children fake {
324 { fake.private private 1 }
325 } "list children of fake"
327 mi_list_varobj_children fake.private {
328 { fake.private.sname sname 0 int }
329 } "list children fake.private"
331 mi_gdb_test "-var-set-visualizer fake.private gdb.default_visualizer" \
332 "\\^done" "Install visualizer on a cplus_fake_child"
334 remote_file host delete ${remote_python_file}