* gdb.python/py-mi.exp: Use different file names for different
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-mi.exp
1 # Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
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
19 load_lib mi-support.exp
20 set MIFLAGS "-i=mi2"
21
22 gdb_exit
23 if [mi_gdb_start] {
24 continue
25 }
26
27 set testfile "py-mi"
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
33 return -1
34 }
35
36 mi_delete_breakpoints
37 mi_gdb_reinitialize_dir $srcdir/$subdir
38 mi_gdb_load ${binfile}
39
40 if {[lsearch -exact [mi_get_features] python] < 0} {
41 unsupported "python support is disabled"
42 return -1
43 }
44
45 mi_runto main
46
47 set remote_python_file [remote_download host ${srcdir}/${subdir}/${pyfile}]
48
49 mi_gdb_test "python execfile ('${remote_python_file}')" ""
50
51 mi_continue_to_line [gdb_get_line_number {MI breakpoint here} ${srcfile}] \
52 "step to breakpoint"
53
54 mi_create_dynamic_varobj container c \
55 "create container varobj, no pretty-printing"
56
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"
62
63 mi_delete_varobj container "delete varobj"
64
65 mi_create_dynamic_varobj nscont nstype \
66 "create nscont varobj, no pretty-printing"
67
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"
72
73 mi_delete_varobj nscont "delete varobj"
74
75 mi_gdb_test "-enable-pretty-printing" ""
76
77 mi_create_varobj_checked string string_1 \
78 "struct string_repr" \
79 "create string_1 varobj"
80
81 mi_create_varobj_checked lstring estring \
82 "struct lazystring" \
83 "create estring varobj"
84
85 mi_gdb_test "-data-evaluate-expression \"string_1 = string_2\"" ".*" \
86 "assign string_1 from string_2"
87
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"
91
92 mi_create_dynamic_varobj container c \
93 "create container varobj"
94
95 mi_list_varobj_children container {
96 } "examine container children=0"
97
98 mi_next "next over update 1"
99
100 mi_varobj_update_dynamic container "varobj update 1" {
101 type_changed false new_num_children 1 dynamic 1 has_more 0
102 } {
103 } {
104 { name {container.\[0\]} exp {\[0\]} numchild 0 type int thread-id 1 }
105 }
106
107 mi_next "next over update 2"
108
109 mi_varobj_update_dynamic container "varobj update 2" {
110 type_changed false new_num_children 2 dynamic 1 has_more 0
111 } {
112 } {
113 { name {container.\[1\]} exp {\[1\]} numchild 0 type int thread-id 1 }
114 }
115
116 mi_gdb_test "-var-set-visualizer container None" \
117 "\\^done" \
118 "clear visualizer"
119
120 mi_gdb_test "-var-update container" \
121 "\\^done,changelist=\\\[\\\]" \
122 "varobj update after clearing"
123
124 mi_gdb_test "-var-set-visualizer container gdb.default_visualizer" \
125 "\\^done" \
126 "choose default visualizer"
127
128 mi_varobj_update_dynamic container "varobj update after choosing default" {
129 type_changed false new_num_children 2 dynamic 1 has_more 0
130 } {
131 } {
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 }
134 }
135
136 mi_gdb_test "-var-set-visualizer container ContainerPrinter" \
137 "\\^done" \
138 "choose visualizer using expression"
139
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
143 } {
144 } {
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 }
147 }
148
149 mi_list_varobj_children_range container 1 2 2 {
150 { {container.\[1\]} {\[1\]} 0 int }
151 } "list varobj children after selecting child range"
152
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"
157
158 mi_next "next over update 3"
159
160 mi_gdb_test "-var-set-update-range container 0 1" \
161 "\\^done" \
162 "set update range"
163
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"
168
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"
173
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"
178
179 mi_next "next over update 4"
180
181 # This should only show the first child, because the update range has
182 # been set.
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
186 } {
187 { name {container.\[0\]} in_scope true type_changed false dynamic 1 has_more 0 }
188 } {
189 }
190
191 mi_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.
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
199 } {
200 } {
201 }
202
203 mi_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.
207 mi_create_dynamic_varobj container2 c2 \
208 "create second container varobj"
209
210 mi_gdb_test "-var-update container2" \
211 "\\^done,changelist=.." \
212 "update varobj, no children requested"
213
214 mi_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.
219 mi_varobj_update_dynamic container2 \
220 "update varobj 2, no children requested" {
221 type_changed false dynamic 1 has_more 1
222 } {} {}
223
224 mi_continue_to_line \
225 [gdb_get_line_number {MI outer breakpoint here} ${srcfile}] \
226 "step to outer breakpoint"
227
228 mi_create_dynamic_varobj outer outer \
229 "create outer varobj"
230
231 mi_list_varobj_children outer {
232 { outer.s s 2 "struct substruct" }
233 { outer.x x 0 "int" }
234 } "list children of outer"
235
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"
240
241 mi_next "next over outer update"
242
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"
246
247 mi_continue_to_line \
248 [gdb_get_line_number {Another MI breakpoint} ${srcfile}] \
249 "step to second breakpoint"
250
251 mi_varobj_update_with_type_change container int 0 "update after type change"
252
253
254 mi_continue_to_line \
255 [gdb_get_line_number {break to inspect struct and union} ${srcfile}] \
256 "step to outer breakpoint"
257
258 mi_create_dynamic_varobj nscont nstype \
259 "create nstype varobj"
260
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"
265
266 mi_gdb_test "-var-set-visualizer nscont None" \
267 "\\^done" \
268 "clear visualizer"
269
270 mi_gdb_test "-var-update nscont" \
271 "\\^done,changelist=\\\[\\\]" \
272 "varobj update after clearing"
273
274 mi_gdb_test "-var-set-visualizer nscont gdb.default_visualizer" \
275 "\\^done" \
276 "choose default visualizer"
277
278 mi_gdb_test "python exception_flag = True" ""
279
280 mi_create_dynamic_varobj nstype2 nstype2 \
281 "create nstype2 varobj"
282
283 mi_list_varobj_children nstype2 {
284 { {nstype2.<error at 0>} {<error at 0>} 6 {char \[6\]} }
285 } "list children after setting exception flag"
286
287 # C++ MI tests
288 gdb_exit
289 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}-c++" \
290 executable {debug c++ additional_flags=-DMI}] != "" } {
291 untested "Couldn't compile ${srcfile} in c++ mode"
292 return -1
293 }
294
295 if [mi_gdb_start] {
296 continue
297 }
298 mi_delete_breakpoints
299 mi_gdb_reinitialize_dir $srcdir/$subdir
300 mi_gdb_load ${binfile}-c++
301
302 if {[lsearch -exact [mi_get_features] python] < 0} {
303 unsupported "python support is disabled"
304 return -1
305 }
306
307 mi_runto main
308 mi_continue_to_line \
309 [gdb_get_line_number {break to inspect struct and union} ${srcfile}] \
310 "step to breakpoint"
311
312 # Test python/12531. Install visualizer on a cplus_fake_child.
313 mi_create_varobj fake fake \
314 "create fake varobj"
315
316 mi_list_varobj_children fake {
317 { fake.private private 1 }
318 } "list children of fake"
319
320 mi_list_varobj_children fake.private {
321 { fake.private.sname sname 0 int }
322 } "list children fake.private"
323
324 mi_gdb_test "-var-set-visualizer fake.private gdb.default_visualizer" \
325 "\\^done" "Install visualizer on a cplus_fake_child"
326
327 remote_file host delete ${remote_python_file}
This page took 0.038255 seconds and 4 git commands to generate.