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