]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.gdbtk/cpp_variable.test
* config/sh/tm-sh.h (BELIEVE_PCC_PROMOTION): Define, so that
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.gdbtk / cpp_variable.test
CommitLineData
c98fe0c1
JI
1# Copyright (C) 1998 Cygnus Solutions
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 2 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, write to the Free Software
15# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17# Please email any bugs, comments, and/or additions to this file to:
18# bug-gdb@prep.ai.mit.edu
19
20# This file was written by Keith Seitz (keiths@cygnus.com)
21
22# Read in the standard defs file
23if {![gdbtk_read_defs]} {
24 break
25}
26
27global objdir test_ran
28global tcl_platform
29
30# Load in a file
31if {$tcl_platform(platform) == "windows"} {
32 set program [file join $objdir cpp_variable.exe]
33} else {
34 set program [file join $objdir cpp_variable]
35}
36
37# This isn't a test case, since if this fails, we're hosed.
38if {[catch {gdb_cmd "file $program"} t]} {
39 # an error occured loading the file
40 gdbtk_test_error "loading \"$program\": $t"
41}
42
43# The variables that are created are stored in an array called "var".
44
45# proc to tell us which of the variables are changed/out of scope
46proc check_valueChanged {} {
47 global var
48
49 set changed {}
50 set unchanged {}
51 set out {}
52 foreach ind [array names var] {
53 set val [$var($ind) valueChanged]
54 if {$val == "VARIABLE_CHANGED"} {
55 lappend changed $ind
56 } elseif {$val == "VARIABLE_UNCHANGED"} {
57 lappend unchanged $ind
58 } elseif {$val == "VARIABLE_OUT_OF_SCOPE"} {
59 lappend out $ind
60 } else {
61 error "unknown result from valueChanged"
62 }
63 }
64
65 return [list $changed $unchanged $out]
66}
67
68
69# proc to create a variable
70proc create_variable {expr} {
71 global var
72
73 set err [catch {gdb_variable create -expr $expr} v]
74 if {!$err} {
75 set var($expr) $v
76 }
77
78 return $err
79}
80
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.
86proc get_children {parent} {
87 global var
88
89 set kiddies [$var($parent) children]
90 set children {}
91 foreach child $kiddies {
92 set name [lindex [split $child .] end]
93 lappend children $name
94 set var($parent.$name) $child
95 }
96
97 return $children
98}
99
100proc delete_variable {varname} {
101 global var
102
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*]
108 foreach v $vars {
109 if {[info exists var($v)]} {
110 unset var($v)
111 }
112 }
113 }
114}
115
116# Compare the values of variable V in format FMT
117# with gdb's value.
118proc value {v fmt} {
119 global var
120
121 set value [$var($v) value]
122 set gdb [gdb_cmd "output/$fmt $v"]
123 if {$value == $gdb} {
124 set result ok
125 } else {
126 set result error
127 }
128
129 return $result
130}
131
132proc delete_all_variables {} {
133 global var
134
135 foreach variable [array names var] {
136 delete_variable $variable
137 }
138}
139
140##### #####
141# #
142# Simple Class Tests #
143# #
144##### #####
145
146# run to "do_simple_class_tests"
147gdb_cmd "break do_simple_class_tests"
148gdb_cmd "run"
149
150# Test: cpp_variable-1.1
151# Desc: stopped in do_simple_class_tests
152gdbtk_test cpp_variable-1.1 {stopped in main} {
153 lindex [gdb_loc] 1
154} {do_simple_class_tests}
155
156# Test: cpp_variable-1.2
157# Desc: create variable v
158gdbtk_test cpp_variable-1.2 {create variable v} {
159 create_variable v
160} {0}
161
162# Test: cpp_variable-1.3
163# Desc: number of children of v
164gdbtk_test cpp_variable-1.3 {number of children of v} {
165 $var(v) numChildren
166} {7}
167
168# Test: cpp_variable-1.4
169# Desc: children of v
170gdbtk_test cpp_variable-1.4 {children of v} {
171 get_children v
172} {VA VB VC v_pub_int v_pub_charp v_priv_int v_priv_charp}
173
174# Test: cpp_variable-1.5
175# Desc: type of v
176gdbtk_test cpp_variable-1.5 {type of v} {
177 $var(v) type
178} {V *}
179
180# Test: cpp_variable-1.6
181# Desc: format of v
182gdbtk_test cpp_variable-1.6 {format of v} {
183 $var(v) format
184} {natural}
185
186set value [$var(v) value]
187
188# Step over "V *v = new V;"
189gdb_cmd "next"
190
191# Test: cpp_variable-1.7
192# Desc: check value of v changed
193gdbtk_test cpp_variable-1.7 {check value of v changed} {
194 check_valueChanged
195} {{v.v_priv_int v.v_pub_charp v.v_pub_int v v.v_priv_charp} {v.VB v.VC v.VA} {}}
196
197# Test: cpp_variable-1.8
198# Desc: check values of v
199gdbtk_test cpp_variable-1.8 {check values of v} {
200 set new [$var(v) value]
201 expr {$new != $value}
202} {1}
203
204# Test: cpp_variable-1.9
205# Desc: v editable
206gdbtk_test cpp_variable-1.9 {v editable} {
207 $var(v) editable
208} {1}
209
210##### #####
211# #
212# Children of v tests #
213# #
214##### #####
215
216# Test: cpp_variable-2.1
217# Desc: type of v.v_pub_int
218gdbtk_test cpp_variable-2.1 {type of v.v_pub_int} {
219 $var(v.v_pub_int) type
220} {int}
221
222# Test: cpp_variable-2.2
223# Desc: format of v.v_pub_int
224gdbtk_test cpp_variable-2.2 {format of v.v_pub_int} {
225 $var(v.v_pub_int) format
226} {natural}
227
228gdb_cmd "set variable v.v_pub_int=2112"
229
230# Test: cpp_variable-2.3
231# Desc: value of v.v_pub_int changed
232gdbtk_test cpp_variable-2.3 {value of v.v_pub_int changed} {
233 check_valueChanged
234} {v.v_pub_int {v.v_priv_int v.VB v.v_pub_charp v.VC v v.v_priv_charp v.VA} {}}
235
236# Test: cpp_variable-2.4
237# Desc: value of v.v_pub_int
238gdbtk_test cpp_variable-2.4 {value of v.v_pub_int} {
239 $var(v.v_pub_int) value
240} {2112}
241
242# Test: cpp_variable-2.5
243# Desc: changed format of v.v_pub_int
244gdbtk_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
247} {octal}
248
249# Test: cpp_variable-2.6
250# Desc: value of v.v_pub_int with new format
251gdbtk_test cpp_variable-2.6 {value of v.v_pub_int with new format} {
252 $var(v.v_pub_int) value
253} {04100}
254
255# Test: cpp_variable-2.7
256# Desc: change value of v.v_pub_int (decimal)
257gdbtk_test cpp_variable-2.7 {change value of v.v_pub_int (decimal)} {
258 $var(v.v_pub_int) value 3
259 value v.v_pub_int o
260} {ok}
261
262# Test: cpp_variable-2.8
263# Desc: change value of v.v_pub_int (hexadecimal)
264gdbtk_test cpp_variable-2.9 {change value of v.v_pub_int (hexadecimal)} {
265 $var(v.v_pub_int) value 0x21
266 value v.v_pub_int o
267} {ok}
268
269# Test: cpp_variable-2.9
270# Desc: number of children of v_pub_int
271gdbtk_test cpp_variable-2.9 {number of children of v_pub_int} {
272 $var(v.v_pub_int) numChildren
273} {0}
274
275# Test: cpp_variable-2.10
276# Desc: children of v.v_pub_int
277gdbtk_test cpp_variable-2.10 {children of v.v_pub_int} {
278 get_children v.v_pub_int
279} {}
280
281# Test: cpp_variable-2.11
282# Desc: v.v_pub_int editable
283gdbtk_test cpp_variable-2.11 {v.v_pub_int editable} {
284 $var(v.v_pub_int) editable
285} {1}
286
287# Test: cpp_variable-2.21
288# Desc: type of v.v_priv_charp
289gdbtk_test cpp_variable-2.21 {type of v.v_priv_charp} {
290 $var(v.v_priv_charp) type
291} {char *}
292
293# Test: cpp_variable-2.22
294# Desc: format of v.v_priv_charp
295gdbtk_test cpp_variable-2.22 {format of v.v_priv_charp} {
296 $var(v.v_priv_charp) format
297} {natural}
298
299gdb_cmd "set variable v.v_priv_charp=2112"
300
301# Test: cpp_variable-2.23
302# Desc: value of v.v_priv_charp changed
303gdbtk_test cpp_variable-2.23 {value of v.v_priv_charp changed} {
304 check_valueChanged
305} {v.v_priv_charp {v.v_priv_int v.VB v.v_pub_charp v.VC v.v_pub_int v v.VA} {}}
306
307# Test: cpp_variable-2.24
308# Desc: value of v.v_priv_charp
309gdbtk_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
312} {0x840}
313
314# Test: cpp_variable-2.25
315# Desc: changed format of v.v_priv_charp
316gdbtk_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
319} {octal}
320
321# Test: cpp_variable-2.26
322# Desc: value of v.v_priv_charp with new format
323gdbtk_test cpp_variable-2.26 {value of v.v_priv_charp with new format} {
324 $var(v.v_priv_charp) value
325} {04100}
326
327# Test: cpp_variable-2.27
328# Desc: change value of v.v_priv_charp (decimal)
329gdbtk_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
332} {ok}
333
334# Test: cpp_variable-2.28
335# Desc: change value of v.v_priv_charp (hexadecimal)
336gdbtk_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
339} {ok}
340
341# Test: cpp_variable-2.29
342# Desc: number of children of v_priv_charp
343gdbtk_test cpp_variable-2.29 {number of children of v_priv_charp} {
344 $var(v.v_priv_charp) numChildren
345} {0}
346
347# Test: cpp_variable-2.30
348# Desc: children of v.v_priv_charp
349gdbtk_test cpp_variable-2.30 {children of v.v_priv_charp} {
350 get_children v.v_priv_charp
351} {}
352
353# Test: cpp_variable-2.31
354# Desc: v.v_priv_int editable
355gdbtk_test cpp_variable-2.31 {v.v_priv_int editable} {
356 $var(v.v_priv_int) editable
357} {1}
358
359# Test: cpp_variable-2.41
360# Desc: type of v.VA
361gdbtk_test cpp_variable-2.41 {type of v.VA} {
362 $var(v.VA) type
363} {VA}
364
365# Test: cpp_variable-2.42
366# Desc: format of v.VA
367gdbtk_test cpp_variable-2.42 {format of v.VA} {
368 $var(v.VA) format
369} {natural}
370
371# Test: cpp_variable-2.43
372# Desc: value of v.VA changed
373gdbtk_test cpp_variable-2.43 {value of v.VA changed} {
374 check_valueChanged
375} {{} {v.v_priv_int v.VB v.v_pub_charp v.VC v.v_pub_int v v.v_priv_charp v.VA} {}}
376
377# Test: cpp_variable-2.44
378# Desc: value of v.VA
379gdbtk_test cpp_variable-2.44 {value of v.VA} {
380 $var(v.VA) value
381} {{...}}
382
383# Test: cpp_variable-2.45
384# Desc: changed format of v.VA
385gdbtk_test cpp_variable-2.45 {changed format of v.VA} {
386 $var(v.VA) format octal
387 $var(v.VA) format
388} {octal}
389
390# Test: cpp_variable-2.46
391# Desc: value of v.VA with new format
392gdbtk_test cpp_variable-2.46 {value of v.VA with new format} {
393 $var(v.VA) value
394} {{...}}
395
396# Test: cpp_variable-2.47
397# Desc: number of children of VA
398gdbtk_test cpp_variable-2.47 {number of children of VA} {
399 $var(v.VA) numChildren
400} {5}
401
402# Test: cpp_variable-2.48
403# Desc: children of v.VA
404gdbtk_test cpp_variable-2.48 {children of v.VA} {
405 get_children v.VA
406} {va_pub_int va_pub_charp va_priv_int va_priv_charp bar}
407
408# Test: cpp_variable-2.49
409# Desc: v.VA editable
410gdbtk_test cpp_variable-2.49 {v.VA editable} {
411 $var(v.VA) editable
412} {0}
413
414# Test: cpp_variable-2.61
415# Desc: type of v.VB
416gdbtk_test cpp_variable-2.61 {type of v.VB} {
417 $var(v.VB) type
418} {VB}
419
420# Test: cpp_variable-2.62
421# Desc: format of v.VB
422gdbtk_test cpp_variable-2.62 {format of v.VB} {
423 $var(v.VB) format
424} {natural}
425
426# Test: cpp_variable-2.63
427# Desc: value of v.VB changed
428gdbtk_test cpp_variable-2.63 {value of v.VB changed} {
429 check_valueChanged
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} {}}
431
432# Test: cpp_variable-2.64
433 # Desc: value of v.VB
434gdbtk_test cpp_variable-2.64 {value of v.VB} {
435 $var(v.VB) value
436} {{...}}
437
438# Test: cpp_variable-2.65
439# Desc: changed format of v.VB
440gdbtk_test cpp_variable-2.65 {changed format of v.VB} {
441 $var(v.VB) format octal
442 $var(v.VB) format
443} {octal}
444
445# Test: cpp_variable-2.66
446# Desc: value of v.VB with new format
447gdbtk_test cpp_variable-2.66 {value of v.VB with new format} {
448 $var(v.VB) value
449} {{...}}
450
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
455gdbtk_test cpp_variable-2.67 {number of children of VB} {
456 $var(v.VB) numChildren
457} {3}
458
459# Test: cpp_variable-2.68
460# Desc: children of v.VB
461gdbtk_test cpp_variable-2.68 {children of v.VB} {
462 get_children v.VB
463} {vb_pub_int vb_priv_int vb_priv_charp}
464
465# Test: cpp_variable-2.69
466# Desc: v.VB editable
467gdbtk_test cpp_variable-2.69 {v.VB editable} {
468 $var(v.VB) editable
469} {0}
470
471
472# Exit
473#
474gdbtk_test_done
475
476