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