Commit | Line | Data |
---|---|---|
b6313243 TT |
1 | # Copyright (C) 2008, 2009 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 | ||
5172aecb | 27 | set testfile "py-prettyprint" |
b6313243 TT |
28 | set srcfile ${testfile}.c |
29 | set binfile ${objdir}/${subdir}/${testfile} | |
30 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DMI}] != "" } { | |
31 | untested mi2-var-child.exp | |
32 | return -1 | |
33 | } | |
34 | ||
35 | mi_delete_breakpoints | |
36 | mi_gdb_reinitialize_dir $srcdir/$subdir | |
37 | mi_gdb_load ${binfile} | |
38 | ||
39 | if {[lsearch -exact [mi_get_features] python] < 0} { | |
40 | unsupported "python support is disabled" | |
41 | return -1 | |
42 | } | |
43 | ||
44 | mi_runto main | |
45 | ||
f24fce77 NF |
46 | set remote_python_file [remote_download host ${srcdir}/${subdir}/${testfile}.py] |
47 | ||
48 | mi_gdb_test "python execfile ('${remote_python_file}')" "" | |
b6313243 TT |
49 | |
50 | mi_continue_to_line [gdb_get_line_number {MI breakpoint here} ${testfile}.c] \ | |
51 | "step to breakpoint" | |
52 | ||
0cc7d26f TT |
53 | mi_create_dynamic_varobj container c \ |
54 | "create container varobj, no pretty-printing" | |
55 | ||
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" | |
61 | ||
62 | mi_delete_varobj container "delete varobj" | |
63 | ||
64 | mi_gdb_test "-enable-pretty-printing" "" | |
65 | ||
66 | mi_create_varobj_checked string string_1 \ | |
67 | "struct string_repr" \ | |
68 | "create string_1 varobj" | |
69 | ||
70 | mi_gdb_test "-data-evaluate-expression \"string_1 = string_2\"" ".*" \ | |
71 | "assign string_1 from string_2" | |
72 | ||
73 | mi_gdb_test "-var-update string" \ | |
74 | "\\^done,changelist=\\\[{name=\"string\",in_scope=\"true\",type_changed=\"false\",dynamic=\"1\",has_more=\"0\"}\\\]" \ | |
75 | "update string varobj after assignment" | |
76 | ||
77 | mi_create_dynamic_varobj container c \ | |
78 | "create container varobj" | |
b6313243 TT |
79 | |
80 | mi_list_varobj_children container { | |
81 | } "examine container children=0" | |
82 | ||
83 | mi_next "next over update 1" | |
84 | ||
0cc7d26f TT |
85 | mi_varobj_update_dynamic container "varobj update 1" { |
86 | type_changed false new_num_children 1 dynamic 1 has_more 0 | |
87 | } { | |
88 | } { | |
89 | { name {container.\[0\]} exp {\[0\]} numchild 0 type int thread-id 1 } | |
90 | } | |
b6313243 TT |
91 | |
92 | mi_next "next over update 2" | |
93 | ||
0cc7d26f TT |
94 | mi_varobj_update_dynamic container "varobj update 2" { |
95 | type_changed false new_num_children 2 dynamic 1 has_more 0 | |
96 | } { | |
97 | } { | |
98 | { name {container.\[1\]} exp {\[1\]} numchild 0 type int thread-id 1 } | |
99 | } | |
b6313243 TT |
100 | |
101 | mi_gdb_test "-var-set-visualizer container None" \ | |
102 | "\\^done" \ | |
103 | "clear visualizer" | |
104 | ||
105 | mi_gdb_test "-var-update container" \ | |
106 | "\\^done,changelist=\\\[\\\]" \ | |
107 | "varobj update after clearing" | |
108 | ||
109 | mi_gdb_test "-var-set-visualizer container gdb.default_visualizer" \ | |
110 | "\\^done" \ | |
111 | "choose default visualizer" | |
112 | ||
0cc7d26f TT |
113 | mi_varobj_update_dynamic container "varobj update after choosing default" { |
114 | type_changed false new_num_children 2 dynamic 1 has_more 0 | |
115 | } { | |
116 | } { | |
117 | { name {container.\[0\]} exp {\[0\]} numchild 0 type int thread-id 1 } | |
118 | { name {container.\[1\]} exp {\[1\]} numchild 0 type int thread-id 1 } | |
119 | } | |
b6313243 TT |
120 | |
121 | mi_gdb_test "-var-set-visualizer container ContainerPrinter" \ | |
122 | "\\^done" \ | |
123 | "choose visualizer using expression" | |
124 | ||
0cc7d26f TT |
125 | mi_varobj_update_dynamic container \ |
126 | "varobj update after choosing via expression" { | |
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_list_varobj_children_range container 1 2 2 { | |
135 | { {container.\[1\]} {\[1\]} 0 int } | |
136 | } "list varobj children after selecting child range" | |
137 | ||
138 | mi_list_varobj_children_range container -1 -1 2 { | |
b6313243 TT |
139 | { {container.\[0\]} {\[0\]} 0 int } |
140 | { {container.\[1\]} {\[1\]} 0 int } | |
0cc7d26f TT |
141 | } "list varobj children after resetting child range" |
142 | ||
143 | mi_next "next over update 3" | |
144 | ||
145 | mi_gdb_test "-var-set-update-range container 0 1" \ | |
146 | "\\^done" \ | |
147 | "set update range" | |
148 | ||
149 | # This should truncate the list. | |
150 | mi_list_varobj_children container { | |
151 | { {container.\[0\]} {\[0\]} 0 int } | |
152 | } "list children after setting update range" | |
153 | ||
154 | # This should return just the items in [1,2). | |
155 | mi_list_varobj_children_range container 1 2 2 { | |
156 | { {container.\[1\]} {\[1\]} 0 int } | |
157 | } "list selected children after setting range" | |
158 | ||
159 | # This should not be affected by the previous list-children request. | |
160 | mi_list_varobj_children container { | |
161 | { {container.\[0\]} {\[0\]} 0 int } | |
162 | } "list children after listing selected range" | |
163 | ||
164 | mi_next "next over update 4" | |
165 | ||
166 | # This should only show the first child, because the update range has | |
167 | # been set. | |
168 | mi_varobj_update_dynamic container \ | |
169 | "update after next with restricted range" { | |
170 | type_changed false new_num_children 1 dynamic 1 has_more 1 | |
171 | } { | |
172 | { name {container.\[0\]} in_scope true type_changed false dynamic 1 has_more 0 } | |
173 | } { | |
174 | } | |
175 | ||
176 | mi_gdb_test "-var-set-update-range container 3 4" \ | |
177 | "\\^done" \ | |
178 | "set update range with non-zero start" | |
179 | ||
180 | # Elements were updated but should not be reported. | |
181 | mi_varobj_update_dynamic container \ | |
182 | "update varobj with change outside selected range" { | |
183 | type_changed false new_num_children 3 dynamic 1 has_more 0 | |
184 | } { | |
185 | } { | |
186 | } | |
187 | ||
188 | mi_next "next over update 5" | |
189 | ||
190 | # Regression test: examine an object that has no children, then update | |
191 | # it to ensure that we don't print the children. | |
192 | mi_create_dynamic_varobj container2 c2 \ | |
193 | "create second container varobj" | |
194 | ||
195 | mi_gdb_test "-var-update container2" \ | |
196 | "\\^done,changelist=.." \ | |
197 | "update varobj, no children requested" | |
198 | ||
199 | mi_next "next over update 6" | |
200 | ||
201 | # Now container2 has an element -- and an update should mention that | |
202 | # it has_more. But, because we did not request children, we still | |
203 | # should not actually see them. | |
204 | mi_varobj_update_dynamic container2 \ | |
205 | "update varobj 2, no children requested" { | |
206 | type_changed false dynamic 1 has_more 1 | |
207 | } {} {} | |
208 | ||
209 | mi_continue_to_line \ | |
210 | [gdb_get_line_number {MI outer breakpoint here} ${testfile}.c] \ | |
211 | "step to outer breakpoint" | |
212 | ||
213 | mi_create_dynamic_varobj outer outer \ | |
214 | "create outer varobj" | |
215 | ||
216 | mi_list_varobj_children outer { | |
217 | { outer.s s 2 "struct substruct" } | |
218 | { outer.x x 0 "int" } | |
219 | } "list children of outer" | |
220 | ||
221 | mi_list_varobj_children outer.s { | |
222 | { outer.s.a a 0 int } | |
223 | { outer.s.b b 0 int } | |
224 | } "list children of outer.s" | |
225 | ||
226 | mi_next "next over outer update" | |
227 | ||
228 | mi_gdb_test "-var-update outer" \ | |
229 | ".done,changelist=.{name=\"outer.s.a\",in_scope=\"true\",type_changed=\"false\",dynamic=\"1\",has_more=\"0\"}." \ | |
230 | "update after updating element of outer" | |
b6313243 TT |
231 | |
232 | mi_continue_to_line \ | |
233 | [gdb_get_line_number {Another MI breakpoint} ${testfile}.c] \ | |
234 | "step to second breakpoint" | |
235 | ||
236 | mi_varobj_update_with_type_change container int 0 "update after type change" | |
f24fce77 NF |
237 | |
238 | remote_file host delete ${remote_python_file} |