Commit | Line | Data |
---|---|---|
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 | ||
19 | if $tracelevel then { | |
20 | strace $tracelevel | |
21 | } | |
22 | ||
c906108c | 23 | |
cab0c772 UW |
24 | set testfile "gdbvars" |
25 | set srcfile ${testfile}.c | |
26 | set binfile ${objdir}/${subdir}/${testfile} | |
27 | ||
28 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { | |
29 | untested gdbvars.exp | |
30 | return -1 | |
31 | } | |
32 | ||
c906108c SS |
33 | proc 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 | ||
64 | proc 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 |
112 | proc 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 | ||
122 | gdb_exit | |
123 | gdb_start | |
124 | gdb_reinitialize_dir $srcdir/$subdir | |
cab0c772 | 125 | gdb_load ${binfile} |
c906108c | 126 | |
a76e022a | 127 | gdb_test_no_output "set print sevenbit-strings" |
c906108c SS |
128 | |
129 | test_value_history | |
130 | test_convenience_variables | |
cab0c772 | 131 | test_with_program |