1 # Copyright (C) 1998 Cygnus Solutions
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 2 of the License, or
6 # (at your option) any later version.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
20 # This file was written by Keith Seitz (keiths@cygnus.com)
22 # Read in the standard defs file
23 if {![gdbtk_read_defs]} {
27 global objdir test_ran
31 if {$tcl_platform(platform) == "windows"} {
32 set program [file join $objdir cpp_variable.exe]
34 set program [file join $objdir cpp_variable]
37 # This isn't a test case, since if this fails, we're hosed.
38 if {[catch {gdb_cmd "file $program"} t]} {
39 # an error occured loading the file
40 gdbtk_test_error "loading \"$program\": $t"
43 # The variables that are created are stored in an array called "var".
45 # proc to tell us which of the variables are changed/out of scope
46 proc check_valueChanged {} {
52 foreach ind [array names var] {
53 set val [$var($ind) valueChanged]
54 if {$val == "VARIABLE_CHANGED"} {
56 } elseif {$val == "VARIABLE_UNCHANGED"} {
57 lappend unchanged $ind
58 } elseif {$val == "VARIABLE_OUT_OF_SCOPE"} {
61 error "unknown result from valueChanged"
65 return [list $changed $unchanged $out]
69 # proc to create a variable
70 proc create_variable {expr} {
73 set err [catch {gdb_variable create -expr $expr} v]
81 # proc to get the children
82 # Children are stored in the global "var" as
83 # PARENT.child. So for struct _foo {int a; int b} bar;,
84 # the children returned are {a b} and var(bar.a) and var(bar.b)
85 # map the actual objects to their names.
86 proc get_children {parent} {
89 set kiddies [$var($parent) children]
91 foreach child $kiddies {
92 set name [lindex [split $child .] end]
93 lappend children $name
94 set var($parent.$name) $child
100 proc delete_variable {varname} {
103 if {[info exists var($varname)]} {
104 # This has to be caught, since deleting a parent
105 # will erase all children.
106 $var($varname) delete
107 set vars [array names var $varname*]
109 if {[info exists var($v)]} {
116 # Compare the values of variable V in format FMT
121 set value [$var($v) value]
122 set gdb [gdb_cmd "output/$fmt $v"]
123 if {$value == $gdb} {
132 proc delete_all_variables {} {
135 foreach variable [array names var] {
136 delete_variable $variable
142 # Simple Class Tests #
146 # run to "do_simple_class_tests"
147 gdb_cmd "break do_simple_class_tests"
150 # Test: cpp_variable-1.1
151 # Desc: stopped in do_simple_class_tests
152 gdbtk_test cpp_variable-1.1 {stopped in main} {
154 } {do_simple_class_tests}
156 # Test: cpp_variable-1.2
157 # Desc: create variable v
158 gdbtk_test cpp_variable-1.2 {create variable v} {
162 # Test: cpp_variable-1.3
163 # Desc: number of children of v
164 gdbtk_test cpp_variable-1.3 {number of children of v} {
168 # Test: cpp_variable-1.4
169 # Desc: children of v
170 gdbtk_test cpp_variable-1.4 {children of v} {
172 } {VA VB VC v_pub_int v_pub_charp v_priv_int v_priv_charp}
174 # Test: cpp_variable-1.5
176 gdbtk_test cpp_variable-1.5 {type of v} {
180 # Test: cpp_variable-1.6
182 gdbtk_test cpp_variable-1.6 {format of v} {
186 set value [$var(v) value]
188 # Step over "V *v = new V;"
191 # Test: cpp_variable-1.7
192 # Desc: check value of v changed
193 gdbtk_test cpp_variable-1.7 {check value of v changed} {
195 } {{v.v_priv_int v.v_pub_charp v.v_pub_int v v.v_priv_charp} {v.VB v.VC v.VA} {}}
197 # Test: cpp_variable-1.8
198 # Desc: check values of v
199 gdbtk_test cpp_variable-1.8 {check values of v} {
200 set new [$var(v) value]
201 expr {$new != $value}
204 # Test: cpp_variable-1.9
206 gdbtk_test cpp_variable-1.9 {v editable} {
212 # Children of v tests #
216 # Test: cpp_variable-2.1
217 # Desc: type of v.v_pub_int
218 gdbtk_test cpp_variable-2.1 {type of v.v_pub_int} {
219 $var(v.v_pub_int) type
222 # Test: cpp_variable-2.2
223 # Desc: format of v.v_pub_int
224 gdbtk_test cpp_variable-2.2 {format of v.v_pub_int} {
225 $var(v.v_pub_int) format
228 gdb_cmd "set variable v.v_pub_int=2112"
230 # Test: cpp_variable-2.3
231 # Desc: value of v.v_pub_int changed
232 gdbtk_test cpp_variable-2.3 {value of v.v_pub_int changed} {
234 } {v.v_pub_int {v.v_priv_int v.VB v.v_pub_charp v.VC v v.v_priv_charp v.VA} {}}
236 # Test: cpp_variable-2.4
237 # Desc: value of v.v_pub_int
238 gdbtk_test cpp_variable-2.4 {value of v.v_pub_int} {
239 $var(v.v_pub_int) value
242 # Test: cpp_variable-2.5
243 # Desc: changed format of v.v_pub_int
244 gdbtk_test cpp_variable-2.5 {changed format of v.v_pub_int} {
245 $var(v.v_pub_int) format octal
246 $var(v.v_pub_int) format
249 # Test: cpp_variable-2.6
250 # Desc: value of v.v_pub_int with new format
251 gdbtk_test cpp_variable-2.6 {value of v.v_pub_int with new format} {
252 $var(v.v_pub_int) value
255 # Test: cpp_variable-2.7
256 # Desc: change value of v.v_pub_int (decimal)
257 gdbtk_test cpp_variable-2.7 {change value of v.v_pub_int (decimal)} {
258 $var(v.v_pub_int) value 3
262 # Test: cpp_variable-2.8
263 # Desc: change value of v.v_pub_int (hexadecimal)
264 gdbtk_test cpp_variable-2.9 {change value of v.v_pub_int (hexadecimal)} {
265 $var(v.v_pub_int) value 0x21
269 # Test: cpp_variable-2.9
270 # Desc: number of children of v_pub_int
271 gdbtk_test cpp_variable-2.9 {number of children of v_pub_int} {
272 $var(v.v_pub_int) numChildren
275 # Test: cpp_variable-2.10
276 # Desc: children of v.v_pub_int
277 gdbtk_test cpp_variable-2.10 {children of v.v_pub_int} {
278 get_children v.v_pub_int
281 # Test: cpp_variable-2.11
282 # Desc: v.v_pub_int editable
283 gdbtk_test cpp_variable-2.11 {v.v_pub_int editable} {
284 $var(v.v_pub_int) editable
287 # Test: cpp_variable-2.21
288 # Desc: type of v.v_priv_charp
289 gdbtk_test cpp_variable-2.21 {type of v.v_priv_charp} {
290 $var(v.v_priv_charp) type
293 # Test: cpp_variable-2.22
294 # Desc: format of v.v_priv_charp
295 gdbtk_test cpp_variable-2.22 {format of v.v_priv_charp} {
296 $var(v.v_priv_charp) format
299 gdb_cmd "set variable v.v_priv_charp=2112"
301 # Test: cpp_variable-2.23
302 # Desc: value of v.v_priv_charp changed
303 gdbtk_test cpp_variable-2.23 {value of v.v_priv_charp changed} {
305 } {v.v_priv_charp {v.v_priv_int v.VB v.v_pub_charp v.VC v.v_pub_int v v.VA} {}}
307 # Test: cpp_variable-2.24
308 # Desc: value of v.v_priv_charp
309 gdbtk_test cpp_variable-2.24 {value of v.v_priv_charp} {
310 $var(v.v_priv_charp) format hexadecimal
311 $var(v.v_priv_charp) value
314 # Test: cpp_variable-2.25
315 # Desc: changed format of v.v_priv_charp
316 gdbtk_test cpp_variable-2.25 {changed format of v.v_priv_charp} {
317 $var(v.v_priv_charp) format octal
318 $var(v.v_priv_charp) format
321 # Test: cpp_variable-2.26
322 # Desc: value of v.v_priv_charp with new format
323 gdbtk_test cpp_variable-2.26 {value of v.v_priv_charp with new format} {
324 $var(v.v_priv_charp) value
327 # Test: cpp_variable-2.27
328 # Desc: change value of v.v_priv_charp (decimal)
329 gdbtk_test cpp_variable-2.27 {change value of v.v_priv_charp (decimal)} {
330 $var(v.v_priv_charp) value 3
331 value v.v_priv_charp o
334 # Test: cpp_variable-2.28
335 # Desc: change value of v.v_priv_charp (hexadecimal)
336 gdbtk_test cpp_variable-2.28 {change value of v.v_priv_charp (hexadecimal)} {
337 $var(v.v_priv_charp) value 0x21
338 value v.v_priv_charp o
341 # Test: cpp_variable-2.29
342 # Desc: number of children of v_priv_charp
343 gdbtk_test cpp_variable-2.29 {number of children of v_priv_charp} {
344 $var(v.v_priv_charp) numChildren
347 # Test: cpp_variable-2.30
348 # Desc: children of v.v_priv_charp
349 gdbtk_test cpp_variable-2.30 {children of v.v_priv_charp} {
350 get_children v.v_priv_charp
353 # Test: cpp_variable-2.31
354 # Desc: v.v_priv_int editable
355 gdbtk_test cpp_variable-2.31 {v.v_priv_int editable} {
356 $var(v.v_priv_int) editable
359 # Test: cpp_variable-2.41
361 gdbtk_test cpp_variable-2.41 {type of v.VA} {
365 # Test: cpp_variable-2.42
366 # Desc: format of v.VA
367 gdbtk_test cpp_variable-2.42 {format of v.VA} {
371 # Test: cpp_variable-2.43
372 # Desc: value of v.VA changed
373 gdbtk_test cpp_variable-2.43 {value of v.VA changed} {
375 } {{} {v.v_priv_int v.VB v.v_pub_charp v.VC v.v_pub_int v v.v_priv_charp v.VA} {}}
377 # Test: cpp_variable-2.44
378 # Desc: value of v.VA
379 gdbtk_test cpp_variable-2.44 {value of v.VA} {
383 # Test: cpp_variable-2.45
384 # Desc: changed format of v.VA
385 gdbtk_test cpp_variable-2.45 {changed format of v.VA} {
386 $var(v.VA) format octal
390 # Test: cpp_variable-2.46
391 # Desc: value of v.VA with new format
392 gdbtk_test cpp_variable-2.46 {value of v.VA with new format} {
396 # Test: cpp_variable-2.47
397 # Desc: number of children of VA
398 gdbtk_test cpp_variable-2.47 {number of children of VA} {
399 $var(v.VA) numChildren
402 # Test: cpp_variable-2.48
403 # Desc: children of v.VA
404 gdbtk_test cpp_variable-2.48 {children of v.VA} {
406 } {va_pub_int va_pub_charp va_priv_int va_priv_charp bar}
408 # Test: cpp_variable-2.49
409 # Desc: v.VA editable
410 gdbtk_test cpp_variable-2.49 {v.VA editable} {
414 # Test: cpp_variable-2.61
416 gdbtk_test cpp_variable-2.61 {type of v.VB} {
420 # Test: cpp_variable-2.62
421 # Desc: format of v.VB
422 gdbtk_test cpp_variable-2.62 {format of v.VB} {
426 # Test: cpp_variable-2.63
427 # Desc: value of v.VB changed
428 gdbtk_test cpp_variable-2.63 {value of v.VB changed} {
430 } {{} {v.VA.va_pub_int v.v_pub_int v.VA.va_priv_int v.VA.va_pub_charp v.v_priv_int v.v_pub_charp v.VA.va_priv_charp v.VA.bar v v.v_priv_charp v.VA v.VB v.VC} {}}
432 # Test: cpp_variable-2.64
433 # Desc: value of v.VB
434 gdbtk_test cpp_variable-2.64 {value of v.VB} {
438 # Test: cpp_variable-2.65
439 # Desc: changed format of v.VB
440 gdbtk_test cpp_variable-2.65 {changed format of v.VB} {
441 $var(v.VB) format octal
445 # Test: cpp_variable-2.66
446 # Desc: value of v.VB with new format
447 gdbtk_test cpp_variable-2.66 {value of v.VB with new format} {
451 # Note: The next two tests show whether or not the logic
452 # concerning vptr tables is working.
453 # Test: cpp_variable-2.67
454 # Desc: number of children of VB
455 gdbtk_test cpp_variable-2.67 {number of children of VB} {
456 $var(v.VB) numChildren
459 # Test: cpp_variable-2.68
460 # Desc: children of v.VB
461 gdbtk_test cpp_variable-2.68 {children of v.VB} {
463 } {vb_pub_int vb_priv_int vb_priv_charp}
465 # Test: cpp_variable-2.69
466 # Desc: v.VB editable
467 gdbtk_test cpp_variable-2.69 {v.VB editable} {