OSDN Git Service

r288@cf-ppc-macosx: monabuilder | 2008-12-07 13:17:34 +0900
[pf3gnuchains/pf3gnuchains3x.git] / gdb / testsuite / gdb.gdbtk / cpp_variable.test
1 # Varobj Tests (C++ language)
2 # Copyright (C) 1998, 2003 Red Hat, Inc.
3 #
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.
8 #
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.
13 #
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.
17
18 # Please email any bugs, comments, and/or additions to this file to:
19 # insight@sources.redhat.com
20
21 # This file was written by Keith Seitz (keiths@cygnus.com)
22
23 # Read in the standard defs file
24 if {![gdbtk_read_defs]} {
25   break
26 }
27
28 global objdir test_ran
29
30 # Load in a file
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"
35 }
36
37 # The variables that are created are stored in an array called "var".
38
39 # proc to tell us which of the variables are changed/out of scope
40 proc check_update {} {
41   global var
42
43   set out {}
44   set changed {}
45   foreach ind [array names var] {
46     set ret [$var($ind) update]
47     if {$ret == -1} {
48         lappend out $ind
49     } elseif {$ret != ""} {
50         lappend changed $ret
51     }
52   }
53   return [list $changed $out]
54 }
55
56
57 # proc to create a variable
58 proc create_variable {expr} {
59   global var
60
61   set err [catch {gdb_variable create "$expr" -expr $expr} v]
62   if {!$err} {
63     set var($expr) $v
64   }
65
66   return $err
67 }
68
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} {
75   global var
76
77   set kiddies [$var($parent) children]
78   set children {}
79   foreach child $kiddies {
80     set name [lindex [split $child .] end]
81     lappend children $name
82     set var($parent.$name) $child
83   }
84
85   return $children
86 }
87
88 proc delete_variable {varname} {
89   global var
90
91   if {[info exists var($varname)]} {
92     # This has to be caught, since deleting a parent
93     # will erase all children.
94     $var($varname) delete
95     set vars [array names var $varname*]
96     foreach v $vars {
97       if {[info exists var($v)]} {
98         unset var($v)
99       }
100     }
101   }
102 }
103
104 # Compare the values of variable V in format FMT with value of OBJ
105 # with gdb's value.
106 proc cppvalue {obj v fmt} {
107   global var
108   global _test
109
110   puts $_test(logfile) "obj=$obj v=$v fmt=$fmt"
111   puts $_test(logfile) "var(\$obj)=$var($obj)"
112
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"
118     set result ok
119   } else {
120     set result $v
121     puts $_test(logfile) "gdbtk: $value <> gdb: $gdb"
122   }
123
124   return $result
125 }
126
127 proc delete_all_variables {} {
128   global var
129
130   foreach variable [array names var] {
131     delete_variable $variable
132   }
133 }
134
135 #####            #####
136 #                    #
137 # Simple Class Tests #
138 #                    #
139 #####            #####
140
141 # run to "do_simple_class_tests"
142 gdb_cmd "break do_simple_class_tests"
143 gdbtk_test_run
144
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]
151   if {$index > 0} {
152     set loc [string range $loc 0 [expr {$index-1}]]
153   }
154   set loc
155 } {do_simple_class_tests}
156
157 # Test: cpp_variable-1.2
158 # Desc: create variable v
159 gdbtk_test cpp_variable-1.2 {create variable v} {
160   create_variable v
161 } {0}
162
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} {
166   $var(v) numChildren
167 } {5}
168
169 # Test: cpp_variable-1.4a
170 # Desc: children of v
171 gdbtk_test cpp_variable-1.4a {children of v} {
172   get_children v
173 } {VA VB VC public private}
174
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}
180
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}
186
187 # Test: cpp_variable-1.5
188 # Desc: type of v
189 gdbtk_test cpp_variable-1.5 {type of v} {
190   $var(v) type
191 } {V *}
192
193 # Test: cpp_variable-1.6
194 # Desc: format of v
195 gdbtk_test cpp_variable-1.6 {format of v} {
196   $var(v) format
197 } {natural}
198
199 set value {}
200 catch {$var(v) value} value
201
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"}
206 } {0}
207
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}
215 } {1}
216
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}
222 } {1}
223
224 # Test: cpp_variable-1.9
225 # Desc: v editable
226 gdbtk_test cpp_variable-1.9 {v editable} {
227   $var(v) editable
228 } {1}
229
230 #####             #####
231 #                     #
232 # Children of v tests #
233 #                     #
234 #####             #####
235
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
240 } {int}
241
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
246 } {natural}
247
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]
252   if {$err} {
253     set txt
254   } else {
255     set err
256   }
257 } {0}
258
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} {
262   check_update
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}}
264
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
269 } {2112}
270
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
276 } {octal}
277
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
282 } {04100}
283
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
289 } {ok}
290
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
296 } {ok}
297
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
302 } {0}
303
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
308 } {}
309
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
314 } {1}
315
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
320 } {char *}
321
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
326 } {natural}
327
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]
332   if {$err} {
333     set txt
334   } else {
335     set err
336   }
337 } {0}
338
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} {
342   check_update
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}}
344
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
350 } {0x840}
351
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
357 } {octal}
358
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
363 } {04100}
364
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
370 } {ok}
371
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
377 } {ok}
378
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
383 } {1}
384
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
389 } {*v_priv_charp}
390
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
395 } {1}
396
397 # Test: cpp_variable-2.41
398 # Desc: type of v.VA
399 gdbtk_test cpp_variable-2.41 {type of v.VA} {
400   $var(v.VA) type
401 } {VA}
402
403 # Test: cpp_variable-2.42
404 # Desc: format of v.VA
405 gdbtk_test cpp_variable-2.42 {format of v.VA} {
406   $var(v.VA) format
407 } {natural}
408
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} {
412   check_update
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}}
414
415 # Test: cpp_variable-2.44
416 # Desc: value of v.VA
417 gdbtk_test cpp_variable-2.44 {value of v.VA} {
418   $var(v.VA) value
419 } {{...}}
420
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
425   $var(v.VA) format
426 } {octal}
427
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} {
431   $var(v.VA) value
432 } {{...}}
433
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
438 } {3}
439
440 # Test: cpp_variable-2.48a
441 # Desc: children of v.VA
442 gdbtk_test cpp_variable-2.48a {children of v.VA} {
443   get_children v.VA
444 } {public private protected}
445
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}
451
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}
457
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
462 } {bar}
463
464 # Test: cpp_variable-2.49
465 # Desc: v.VA editable
466 gdbtk_test cpp_variable-2.49 {v.VA editable} {
467   $var(v.VA) editable
468 } {0}
469
470 # Test: cpp_variable-2.61
471 # Desc: type of v.VB
472 gdbtk_test cpp_variable-2.61 {type of v.VB} {
473   $var(v.VB) type
474 } {VB}
475
476 # Test: cpp_variable-2.62
477 # Desc: format of v.VB
478 gdbtk_test cpp_variable-2.62 {format of v.VB} {
479   $var(v.VB) format
480 } {natural}
481
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} {
485   check_update
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}}
487
488 # Test: cpp_variable-2.64
489  # Desc: value of v.VB
490 gdbtk_test cpp_variable-2.64 {value of v.VB} {
491   $var(v.VB) value
492 } {{...}}
493
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
498   $var(v.VB) format
499 } {octal}
500
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} {
504   $var(v.VB) value
505 } {{...}}
506
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
513 } {2}
514
515 # Test: cpp_variable-2.68a
516 # Desc: children of v.VB
517 gdbtk_test cpp_variable-2.68a {children of v.VB} {
518   get_children v.VB
519 } {public private}
520
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
525 } {vb_pub_int}
526
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}
532
533 # Test: cpp_variable-2.69
534 # Desc: v.VB editable
535 gdbtk_test cpp_variable-2.69 {v.VB editable} {
536   $var(v.VB) editable
537 } {0}
538
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
543 } {0}
544
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
549 } {1}
550
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]
555   if {$err} {
556     set txt
557   } else {
558     set err
559   }
560 } {0}
561
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} {
565   check_update
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}}
567
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
572 } {2112}
573
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
579 } {ok}
580
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
585 } {3}
586
587
588 #  Exit
589 #
590 gdbtk_test_done
591
592 #Local Variables:
593 #mode: tcl
594