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