1 # Varobj Tests (C++ language)
2 # Copyright (C) 1998, 2003 Red Hat, Inc.
4 # This Program Is Free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 # Please email any bugs, comments, and/or additions to this file to:
19 # insight@sources.redhat.com
21 # This file was written by Keith Seitz (keiths@cygnus.com)
23 # Read in the standard defs file
24 if {![gdbtk_read_defs]} {
28 global objdir test_ran
31 set program [file join $objdir cpp_variable]
32 if {[catch {gdbtk_test_file $program} t]} {
33 # This isn't a test case, since if this fails, we're hosed.
34 gdbtk_test_error "loading \"$program\": $t"
37 # The variables that are created are stored in an array called "var".
39 # proc to tell us which of the variables are changed/out of scope
40 proc check_update {} {
45 foreach ind [array names var] {
46 set ret [$var($ind) update]
49 } elseif {$ret != ""} {
53 return [list $changed $out]
57 # proc to create a variable
58 proc create_variable {expr} {
61 set err [catch {gdb_variable create "$expr" -expr $expr} v]
69 # proc to get the children
70 # Children are stored in the global "var" as
71 # PARENT.child. So for struct _foo {int a; int b} bar;,
72 # the children returned are {a b} and var(bar.a) and var(bar.b)
73 # map the actual objects to their names.
74 proc get_children {parent} {
77 set kiddies [$var($parent) children]
79 foreach child $kiddies {
80 set name [lindex [split $child .] end]
81 lappend children $name
82 set var($parent.$name) $child
88 proc delete_variable {varname} {
91 if {[info exists var($varname)]} {
92 # This has to be caught, since deleting a parent
93 # will erase all children.
95 set vars [array names var $varname*]
97 if {[info exists var($v)]} {
104 # Compare the values of variable V in format FMT with value of OBJ
106 proc cppvalue {obj v fmt} {
110 puts $_test(logfile) "obj=$obj v=$v fmt=$fmt"
111 puts $_test(logfile) "var(\$obj)=$var($obj)"
113 set value [$var($obj) value]
114 set gdb [gdb_cmd "output/$fmt $v"]
115 puts $_test(logfile) "output/$fmt $v"
116 if {$value == $gdb} {
117 puts $_test(logfile) "gdbtk: $value == gdb: $gdb"
121 puts $_test(logfile) "gdbtk: $value <> gdb: $gdb"
127 proc delete_all_variables {} {
130 foreach variable [array names var] {
131 delete_variable $variable
137 # Simple Class Tests #
141 # run to "do_simple_class_tests"
142 gdb_cmd "break do_simple_class_tests"
145 # Test: cpp_variable-1.1
146 # Desc: stopped in do_simple_class_tests
147 gdbtk_test cpp_variable-1.1 {stopped in do_simple_class_tests} {
148 # G++ can output "do_simple_class_tests(void)". Strip the "(void)" part.
149 set loc [lindex [gdb_loc] 1]
150 set index [string first \( $loc]
152 set loc [string range $loc 0 [expr {$index-1}]]
155 } {do_simple_class_tests}
157 # Test: cpp_variable-1.2
158 # Desc: create variable v
159 gdbtk_test cpp_variable-1.2 {create variable v} {
163 # Test: cpp_variable-1.3
164 # Desc: number of children of v
165 gdbtk_test cpp_variable-1.3 {number of children of v} {
169 # Test: cpp_variable-1.4a
170 # Desc: children of v
171 gdbtk_test cpp_variable-1.4a {children of v} {
173 } {VA VB VC public private}
175 # Test: cpp_variable-1.4b
176 # Desc: public children of v
177 gdbtk_test cpp_variable-1.4b {public children of v} {
178 get_children v.public
179 } {v_pub_int v_pub_charp}
181 # Test: cpp_variable-1.4c
182 # Desc: private children of v
183 gdbtk_test cpp_variable-1.4c {private children of v} {
184 get_children v.private
185 } {v_priv_int v_priv_charp}
187 # Test: cpp_variable-1.5
189 gdbtk_test cpp_variable-1.5 {type of v} {
193 # Test: cpp_variable-1.6
195 gdbtk_test cpp_variable-1.6 {format of v} {
200 catch {$var(v) value} value
202 # Test: cpp_variable-1.6a
203 # Desc: Step over "V *v = new V;"
204 gdbtk_test cpp_variable-1.6a {step over "V *v = new V;"} {
205 catch {gdb_cmd "next"}
208 # Test: cpp_variable-1.7
209 # Desc: check value of v changed
210 gdbtk_test cpp_variable-1.7 {check value of v changed} {
211 set changes [check_update]
212 # It is undefined whether the children will change values
213 # or not, so ignore them.
214 expr {[lsearch [lindex [lindex $changes 0] 0] v] != -1}
217 # Test: cpp_variable-1.8
218 # Desc: check values of v
219 gdbtk_test cpp_variable-1.8 {check values of v} {
220 set new [$var(v) value]
221 expr {$new != $value}
224 # Test: cpp_variable-1.9
226 gdbtk_test cpp_variable-1.9 {v editable} {
232 # Children of v tests #
236 # Test: cpp_variable-2.1
237 # Desc: type of v.v_pub_int
238 gdbtk_test cpp_variable-2.1 {type of v.v_pub_int} {
239 $var(v.public.v_pub_int) type
242 # Test: cpp_variable-2.2
243 # Desc: format of v.v_pub_int
244 gdbtk_test cpp_variable-2.2 {format of v.v_pub_int} {
245 $var(v.public.v_pub_int) format
248 # Test: cpp_variable-2.2a
249 # Desc: set variable v->v_pub_int=2112
250 gdbtk_test cpp_variable-2.2a {set variable v.v_pub_int=2112} {
251 set err [catch {gdb_cmd "set variable v.v_pub_int=2112"} txt]
259 # Test: cpp_variable-2.3
260 # Desc: value of v.v_pub_int changed
261 gdbtk_test cpp_variable-2.3 {value of v.v_pub_int changed} {
263 } {v.public.v_pub_int {v.private.v_priv_charp v.VB v.private.v_priv_int v.VC v.public.v_pub_charp v.public.v_pub_int v.private v.public v.VA}}
265 # Test: cpp_variable-2.4
266 # Desc: value of v.v_pub_int
267 gdbtk_test cpp_variable-2.4 {value of v.v_pub_int} {
268 $var(v.public.v_pub_int) value
271 # Test: cpp_variable-2.5
272 # Desc: changed format of v.v_pub_int
273 gdbtk_test cpp_variable-2.5 {changed format of v.v_pub_int} {
274 $var(v.public.v_pub_int) format octal
275 $var(v.public.v_pub_int) format
278 # Test: cpp_variable-2.6
279 # Desc: value of v.v_pub_int with new format
280 gdbtk_test cpp_variable-2.6 {value of v.v_pub_int with new format} {
281 $var(v.public.v_pub_int) value
284 # Test: cpp_variable-2.7
285 # Desc: change value of v.v_pub_int (decimal)
286 gdbtk_test cpp_variable-2.7 {change value of v.v_pub_int (decimal)} {
287 $var(v.public.v_pub_int) value 3
288 cppvalue v.public.v_pub_int v.v_pub_int o
291 # Test: cpp_variable-2.8
292 # Desc: change value of v.v_pub_int (hexadecimal)
293 gdbtk_test cpp_variable-2.8 {change value of v.v_pub_int (hexadecimal)} {
294 $var(v.public.v_pub_int) value 0x21
295 cppvalue v.public.v_pub_int v.v_pub_int o
298 # Test: cpp_variable-2.9
299 # Desc: number of children of v_pub_int
300 gdbtk_test cpp_variable-2.9 {number of children of v_pub_int} {
301 $var(v.public.v_pub_int) numChildren
304 # Test: cpp_variable-2.10
305 # Desc: children of v.v_pub_int
306 gdbtk_test cpp_variable-2.10 {children of v.v_pub_int} {
307 get_children v.public.v_pub_int
310 # Test: cpp_variable-2.11
311 # Desc: v.v_pub_int editable
312 gdbtk_test cpp_variable-2.11 {v.v_pub_int editable} {
313 $var(v.public.v_pub_int) editable
316 # Test: cpp_variable-2.21
317 # Desc: type of v.v_priv_charp
318 gdbtk_test cpp_variable-2.21 {type of v.v_priv_charp} {
319 $var(v.private.v_priv_charp) type
322 # Test: cpp_variable-2.22
323 # Desc: format of v.v_priv_charp
324 gdbtk_test cpp_variable-2.22 {format of v.v_priv_charp} {
325 $var(v.private.v_priv_charp) format
328 # Test: cpp_variable-2.22a
329 # Desc: set variable v->v_priv_charp=2112
330 gdbtk_test cpp_variable-2.22a {set variable v->v_priv_charp=2112} {
331 set err [catch {gdb_cmd "set variable v->v_priv_charp=2112"} txt]
339 # Test: cpp_variable-2.23
340 # Desc: value of v.v_priv_charp changed
341 gdbtk_test cpp_variable-2.23 {value of v.v_priv_charp changed} {
343 } {{{v.public.v_pub_int v.private.v_priv_charp}} {v.private.v_priv_charp v.VB v.private.v_priv_int v.VC v.public.v_pub_charp v.public.v_pub_int v.private v.public v.VA}}
345 # Test: cpp_variable-2.24
346 # Desc: value of v.v_priv_charp
347 gdbtk_test cpp_variable-2.24 {value of v.v_priv_charp} {
348 $var(v.private.v_priv_charp) format hexadecimal
349 $var(v.private.v_priv_charp) value
352 # Test: cpp_variable-2.25
353 # Desc: changed format of v.v_priv_charp
354 gdbtk_test cpp_variable-2.25 {changed format of v.v_priv_charp} {
355 $var(v.private.v_priv_charp) format octal
356 $var(v.private.v_priv_charp) format
359 # Test: cpp_variable-2.26
360 # Desc: value of v.v_priv_charp with new format
361 gdbtk_test cpp_variable-2.26 {value of v.v_priv_charp with new format} {
362 $var(v.private.v_priv_charp) value
365 # Test: cpp_variable-2.27
366 # Desc: change value of v.v_priv_charp (decimal)
367 gdbtk_test cpp_variable-2.27 {change value of v.v_priv_charp (decimal)} {
368 $var(v.private.v_priv_charp) value 3
369 cppvalue v.private.v_priv_charp v.v_priv_charp o
372 # Test: cpp_variable-2.28
373 # Desc: change value of v.v_priv_charp (hexadecimal)
374 gdbtk_test cpp_variable-2.28 {change value of v.v_priv_charp (hexadecimal)} {
375 $var(v.private.v_priv_charp) value 0x21
376 cppvalue v.private.v_priv_charp v.v_priv_charp o
379 # Test: cpp_variable-2.29
380 # Desc: number of children of v_priv_charp
381 gdbtk_test cpp_variable-2.29 {number of children of v_priv_charp} {
382 $var(v.private.v_priv_charp) numChildren
385 # Test: cpp_variable-2.30
386 # Desc: children of v.v_priv_charp
387 gdbtk_test cpp_variable-2.30 {children of v.v_priv_charp} {
388 get_children v.private.v_priv_charp
391 # Test: cpp_variable-2.31
392 # Desc: v.v_priv_int editable
393 gdbtk_test cpp_variable-2.31 {v.v_priv_int editable} {
394 $var(v.private.v_priv_int) editable
397 # Test: cpp_variable-2.41
399 gdbtk_test cpp_variable-2.41 {type of v.VA} {
403 # Test: cpp_variable-2.42
404 # Desc: format of v.VA
405 gdbtk_test cpp_variable-2.42 {format of v.VA} {
409 # Test: cpp_variable-2.43
410 # Desc: value of v.VA changed
411 gdbtk_test cpp_variable-2.43 {value of v.VA changed} {
413 } {v.private.v_priv_charp {v.private.v_priv_charp v.VB v.private.v_priv_int v.VC v.public.v_pub_charp v.private.v_priv_charp.*v_priv_charp v.public.v_pub_int v.private v.public v.VA}}
415 # Test: cpp_variable-2.44
416 # Desc: value of v.VA
417 gdbtk_test cpp_variable-2.44 {value of v.VA} {
421 # Test: cpp_variable-2.45
422 # Desc: changed format of v.VA
423 gdbtk_test cpp_variable-2.45 {changed format of v.VA} {
424 $var(v.VA) format octal
428 # Test: cpp_variable-2.46
429 # Desc: value of v.VA with new format
430 gdbtk_test cpp_variable-2.46 {value of v.VA with new format} {
434 # Test: cpp_variable-2.47
435 # Desc: number of children of VA
436 gdbtk_test cpp_variable-2.47 {number of children of VA} {
437 $var(v.VA) numChildren
440 # Test: cpp_variable-2.48a
441 # Desc: children of v.VA
442 gdbtk_test cpp_variable-2.48a {children of v.VA} {
444 } {public private protected}
446 # Test: cpp_variable-2.48b
447 # Desc: public children of v.VA
448 gdbtk_test cpp_variable-2.48b {children of v.VA} {
449 get_children v.VA.public
450 } {va_pub_int va_pub_charp}
452 # Test: cpp_variable-2.48c
453 # Desc: private children of v.VA
454 gdbtk_test cpp_variable-2.48c {children of v.VA} {
455 get_children v.VA.private
456 } {va_priv_int va_priv_charp}
458 # Test: cpp_variable-2.48d
459 # Desc: protected children of v.VA
460 gdbtk_test cpp_variable-2.48d {children of v.VA} {
461 get_children v.VA.protected
464 # Test: cpp_variable-2.49
465 # Desc: v.VA editable
466 gdbtk_test cpp_variable-2.49 {v.VA editable} {
470 # Test: cpp_variable-2.61
472 gdbtk_test cpp_variable-2.61 {type of v.VB} {
476 # Test: cpp_variable-2.62
477 # Desc: format of v.VB
478 gdbtk_test cpp_variable-2.62 {format of v.VB} {
482 # Test: cpp_variable-2.63
483 # Desc: value of v.VB changed
484 gdbtk_test cpp_variable-2.63 {value of v.VB changed} {
486 } {{} {v.VA.protected v.private.v_priv_charp.*v_priv_charp v.VA.private v.VA.public.va_pub_int v.private.v_priv_int v.public.v_pub_int v.VA.public.va_pub_charp v.private.v_priv_charp v.VA.public v.public.v_pub_charp v.VA.private.va_priv_int v.VA v.public v.VB v.VC v.VA.protected.bar v.VA.private.va_priv_charp v.private}}
488 # Test: cpp_variable-2.64
489 # Desc: value of v.VB
490 gdbtk_test cpp_variable-2.64 {value of v.VB} {
494 # Test: cpp_variable-2.65
495 # Desc: changed format of v.VB
496 gdbtk_test cpp_variable-2.65 {changed format of v.VB} {
497 $var(v.VB) format octal
501 # Test: cpp_variable-2.66
502 # Desc: value of v.VB with new format
503 gdbtk_test cpp_variable-2.66 {value of v.VB with new format} {
507 # Note: The next two tests show whether or not the logic
508 # concerning vptr tables is working.
509 # Test: cpp_variable-2.67
510 # Desc: number of children of VB
511 gdbtk_test cpp_variable-2.67 {number of children of VB} {
512 $var(v.VB) numChildren
515 # Test: cpp_variable-2.68a
516 # Desc: children of v.VB
517 gdbtk_test cpp_variable-2.68a {children of v.VB} {
521 # Test: cpp_variable-2.68b
522 # Desc: public children of v.VB
523 gdbtk_test cpp_variable-2.68b {children of v.VB} {
524 get_children v.VB.public
527 # Test: cpp_variable-2.68c
528 # Desc: private children of v.VB
529 gdbtk_test cpp_variable-2.68c {children of v.VB} {
530 get_children v.VB.private
531 } {vb_priv_int vb_priv_charp}
533 # Test: cpp_variable-2.69
534 # Desc: v.VB editable
535 gdbtk_test cpp_variable-2.69 {v.VB editable} {
539 # Test: cpp_variable-2.70
540 # Desc: v.VB.public editable
541 gdbtk_test cpp_variable-2.70 {v.VB.public editable} {
542 $var(v.VB.public) editable
545 # Test: cpp_variable-2.71
546 # Desc: v.VB.vb_pub_int editable
547 gdbtk_test cpp_variable-2.71 {v.VB.vb_pub_int editable} {
548 $var(v.VB.public.vb_pub_int) editable
551 # Test: cpp_variable-2.71a
552 # Desc: set variable v->vb_pub_int=2112
553 gdbtk_test cpp_variable-2.71a {set variable v->v_pub_int=2112} {
554 set err [catch {gdb_cmd "set variable v->vb_pub_int=2112"} txt]
562 # Test: cpp_variable-2.72
563 # Desc: value of v.vb_pub_int changed
564 gdbtk_test cpp_variable-2.72 {value of v.vb_pub_int changed} {
566 } {v.VB.public.vb_pub_int {v.VB.public v.VA.protected v.private.v_priv_charp.*v_priv_charp v.VA.private v.VB.private.vb_priv_int v.VB.private v.VA.public.va_pub_int v.private.v_priv_int v.VB.public.vb_pub_int v.public.v_pub_int v.VB.private.vb_priv_charp v.VA.public.va_pub_charp v.private.v_priv_charp v.VA.public v.public.v_pub_charp v.VA.private.va_priv_int v.VA v.public v.VB v.VC v.VA.protected.bar v.VA.private.va_priv_charp v.private}}
568 # Test: cpp_variable-2.73
569 # Desc: value of v.VB.vb_pub_int
570 gdbtk_test cpp_variable-2.73 {changed value of v.vb_pub_int} {
571 $var(v.VB.public.vb_pub_int) value
574 # Test: cpp_variable-2.74
575 # Desc: change value of v.VB.vb_pub_int
576 gdbtk_test cpp_variable-2.74 {change value of v.VB.public.vb_pub_int} {
577 $var(v.VB.public.vb_pub_int) value 3
578 cppvalue v.VB.public.vb_pub_int v.vb_pub_int d
581 # Test: cpp_variable-2.75
582 # Desc: value of v.VB.vb_pub_int
583 gdbtk_test cpp_variable-2.75 {changed value of v.VB.public.vb_pub_int} {
584 $var(v.VB.public.vb_pub_int) value