]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/gdbvars.exp
run copyright.sh for 2011.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / gdbvars.exp
CommitLineData
7b6bb8da 1# Copyright (C) 1992, 1997, 2007, 2008, 2009, 2010, 2011
4c38e0a4 2# Free Software Foundation, Inc.
c906108c
SS
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
e22f8b7c 6# the Free Software Foundation; either version 3 of the License, or
c906108c 7# (at your option) any later version.
e22f8b7c 8#
c906108c
SS
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.
e22f8b7c 13#
c906108c 14# You should have received a copy of the GNU General Public License
e22f8b7c 15# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 16
c906108c
SS
17# This file was written by Fred Fish. (fnf@cygnus.com)
18
19if $tracelevel then {
20 strace $tracelevel
21}
22
c906108c 23
cab0c772
UW
24set testfile "gdbvars"
25set srcfile ${testfile}.c
26set binfile ${objdir}/${subdir}/${testfile}
27
28if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
29 untested gdbvars.exp
30 return -1
31}
32
c906108c
SS
33proc test_convenience_variables {} {
34 global gdb_prompt
35
27d3a1a2 36 gdb_test_no_output "set \$foo = 101" \
c906108c
SS
37 "Set a new convenience variable"
38
39 gdb_test "print \$foo" " = 101" \
40 "Print contents of new convenience variable"
41
27d3a1a2 42 gdb_test_no_output "set \$foo = 301" \
c906108c
SS
43 "Set convenience variable to a new value"
44
45 gdb_test "print \$foo" " = 301" \
46 "Print new contents of convenience variable"
47
27d3a1a2 48 gdb_test_no_output "set \$_ = 11" \
c906108c
SS
49 "Set convenience variable \$_"
50
51 gdb_test "print \$_" " = 11" \
52 "Print contents of convenience variable \$_"
53
54 gdb_test "print \$foo + 10" " = 311" \
55 "Use convenience variable in arithmetic expression"
56
57 gdb_test "print (\$foo = 32) + 4" " = 36" \
58 "Use convenience variable assignment in arithmetic expression"
59
60 gdb_test "print \$bar" " = void" \
61 "Print contents of uninitialized convenience variable"
62}
63
64proc test_value_history {} {
65 global gdb_prompt
66
67 gdb_test "print 101" "\\\$1 = 101" \
68 "Set value-history\[1\] using \$1"
69
70 gdb_test "print 102" "\\\$2 = 102" \
71 "Set value-history\[2\] using \$2"
72
73 gdb_test "print 103" "\\\$3 = 103" \
74 "Set value-history\[3\] using \$3"
75
76 gdb_test "print \$\$" "\\\$4 = 102" \
77 "Print value-history\[MAX-1\] using inplicit index \$\$"
78
79 gdb_test "print \$\$" "\\\$5 = 103" \
80 "Print value-history\[MAX-1\] again using implicit index \$\$"
81
82 gdb_test "print \$" "\\\$6 = 103" \
83 "Print value-history\[MAX\] using implicit index \$"
84
85 gdb_test "print \$\$2" "\\\$7 = 102" \
86 "Print value-history\[MAX-2\] using explicit index \$\$2"
87
88 gdb_test "print \$0" "\\\$8 = 102" \
89 "Print value-history\[MAX\] using explicit index \$0"
90
a0b3c4fd 91 gdb_test "print 108" "\\\$9 = 108"
c906108c
SS
92
93 gdb_test "print \$\$0" "\\\$10 = 108" \
94 "Print value-history\[MAX\] using explicit index \$\$0"
95
96 gdb_test "print \$1" "\\\$11 = 101" \
97 "Print value-history\[1\] using explicit index \$1"
98
99 gdb_test "print \$2" "\\\$12 = 102" \
100 "Print value-history\[2\] using explicit index \$2"
101
102 gdb_test "print \$3" "\\\$13 = 103" \
103 "Print value-history\[3\] using explicit index \$3"
104
105 gdb_test "print \$-3" "\\\$14 = 100" \
106 "Print (value-history\[MAX\] - 3) using implicit index \$"
107
108 gdb_test "print \$1 + 3" "\\\$15 = 104" \
109 "Use value-history element in arithmetic expression"
110}
111
cab0c772
UW
112proc test_with_program {} {
113 global hex
27d3a1a2 114 gdb_test_no_output "set \$prog_var = p" \
cab0c772
UW
115 "Set a new convenience variable to a program variable"
116 gdb_test "print /x \$prog_var" " = $hex" \
117 "Print contents of new convenience variable of program variable"
118}
119
c906108c
SS
120# Start with a fresh gdb.
121
122gdb_exit
123gdb_start
124gdb_reinitialize_dir $srcdir/$subdir
cab0c772 125gdb_load ${binfile}
c906108c 126
a76e022a 127gdb_test_no_output "set print sevenbit-strings"
c906108c
SS
128
129test_value_history
130test_convenience_variables
cab0c772 131test_with_program