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