1 # Copyright (C) 1992, 1997, 2007, 2008, 2009, 2010
2 # Free Software Foundation, 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 3 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, see <http://www.gnu.org/licenses/>.
17 # This file was written by Fred Fish. (fnf@cygnus.com)
24 set testfile "gdbvars"
25 set srcfile ${testfile}.c
26 set binfile ${objdir}/${subdir}/${testfile}
28 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
33 proc test_convenience_variables {} {
36 gdb_test_no_output "set \$foo = 101" \
37 "Set a new convenience variable"
39 gdb_test "print \$foo" " = 101" \
40 "Print contents of new convenience variable"
42 gdb_test_no_output "set \$foo = 301" \
43 "Set convenience variable to a new value"
45 gdb_test "print \$foo" " = 301" \
46 "Print new contents of convenience variable"
48 gdb_test_no_output "set \$_ = 11" \
49 "Set convenience variable \$_"
51 gdb_test "print \$_" " = 11" \
52 "Print contents of convenience variable \$_"
54 gdb_test "print \$foo + 10" " = 311" \
55 "Use convenience variable in arithmetic expression"
57 gdb_test "print (\$foo = 32) + 4" " = 36" \
58 "Use convenience variable assignment in arithmetic expression"
60 gdb_test "print \$bar" " = void" \
61 "Print contents of uninitialized convenience variable"
64 proc test_value_history {} {
67 gdb_test "print 101" "\\\$1 = 101" \
68 "Set value-history\[1\] using \$1"
70 gdb_test "print 102" "\\\$2 = 102" \
71 "Set value-history\[2\] using \$2"
73 gdb_test "print 103" "\\\$3 = 103" \
74 "Set value-history\[3\] using \$3"
76 gdb_test "print \$\$" "\\\$4 = 102" \
77 "Print value-history\[MAX-1\] using inplicit index \$\$"
79 gdb_test "print \$\$" "\\\$5 = 103" \
80 "Print value-history\[MAX-1\] again using implicit index \$\$"
82 gdb_test "print \$" "\\\$6 = 103" \
83 "Print value-history\[MAX\] using implicit index \$"
85 gdb_test "print \$\$2" "\\\$7 = 102" \
86 "Print value-history\[MAX-2\] using explicit index \$\$2"
88 gdb_test "print \$0" "\\\$8 = 102" \
89 "Print value-history\[MAX\] using explicit index \$0"
91 gdb_test "print 108" "\\\$9 = 108"
93 gdb_test "print \$\$0" "\\\$10 = 108" \
94 "Print value-history\[MAX\] using explicit index \$\$0"
96 gdb_test "print \$1" "\\\$11 = 101" \
97 "Print value-history\[1\] using explicit index \$1"
99 gdb_test "print \$2" "\\\$12 = 102" \
100 "Print value-history\[2\] using explicit index \$2"
102 gdb_test "print \$3" "\\\$13 = 103" \
103 "Print value-history\[3\] using explicit index \$3"
105 gdb_test "print \$-3" "\\\$14 = 100" \
106 "Print (value-history\[MAX\] - 3) using implicit index \$"
108 gdb_test "print \$1 + 3" "\\\$15 = 104" \
109 "Use value-history element in arithmetic expression"
112 proc test_with_program {} {
114 gdb_test_no_output "set \$prog_var = p" \
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"
120 # Start with a fresh gdb.
124 gdb_reinitialize_dir $srcdir/$subdir
127 gdb_test_no_output "set print sevenbit-strings"
130 test_convenience_variables