1# Copyright (C) 1992, 1997, 2007, 2008, 2009, 2010, 2011 2# Free Software Foundation, 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 3 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, see <http://www.gnu.org/licenses/>. 16 17# This file was written by Fred Fish. (fnf@cygnus.com) 18 19if $tracelevel then { 20 strace $tracelevel 21} 22 23 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 33proc test_convenience_variables {} { 34 global gdb_prompt 35 36 gdb_test_no_output "set \$foo = 101" \ 37 "Set a new convenience variable" 38 39 gdb_test "print \$foo" " = 101" \ 40 "Print contents of new convenience variable" 41 42 gdb_test_no_output "set \$foo = 301" \ 43 "Set convenience variable to a new value" 44 45 gdb_test "print \$foo" " = 301" \ 46 "Print new contents of convenience variable" 47 48 gdb_test_no_output "set \$_ = 11" \ 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 91 gdb_test "print 108" "\\\$9 = 108" 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 112proc test_with_program {} { 113 global hex 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" 118} 119 120# Start with a fresh gdb. 121 122gdb_exit 123gdb_start 124gdb_reinitialize_dir $srcdir/$subdir 125gdb_load ${binfile} 126 127gdb_test_no_output "set print sevenbit-strings" 128 129test_value_history 130test_convenience_variables 131test_with_program 132