Commit | Line | Data |
---|---|---|
4c38e0a4 JB |
1 | # Copyright (C) 1992, 1997, 2007, 2008, 2009, 2010 |
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 | ||
23 | set prms_id 0 | |
24 | set bug_id 0 | |
25 | ||
cab0c772 UW |
26 | set testfile "gdbvars" |
27 | set srcfile ${testfile}.c | |
28 | set binfile ${objdir}/${subdir}/${testfile} | |
29 | ||
30 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { | |
31 | untested gdbvars.exp | |
32 | return -1 | |
33 | } | |
34 | ||
c906108c SS |
35 | proc test_convenience_variables {} { |
36 | global gdb_prompt | |
37 | ||
38 | gdb_test "set \$foo = 101" "" \ | |
39 | "Set a new convenience variable" | |
40 | ||
41 | gdb_test "print \$foo" " = 101" \ | |
42 | "Print contents of new convenience variable" | |
43 | ||
44 | gdb_test "set \$foo = 301" "" \ | |
45 | "Set convenience variable to a new value" | |
46 | ||
47 | gdb_test "print \$foo" " = 301" \ | |
48 | "Print new contents of convenience variable" | |
49 | ||
50 | gdb_test "set \$_ = 11" "" \ | |
51 | "Set convenience variable \$_" | |
52 | ||
53 | gdb_test "print \$_" " = 11" \ | |
54 | "Print contents of convenience variable \$_" | |
55 | ||
56 | gdb_test "print \$foo + 10" " = 311" \ | |
57 | "Use convenience variable in arithmetic expression" | |
58 | ||
59 | gdb_test "print (\$foo = 32) + 4" " = 36" \ | |
60 | "Use convenience variable assignment in arithmetic expression" | |
61 | ||
62 | gdb_test "print \$bar" " = void" \ | |
63 | "Print contents of uninitialized convenience variable" | |
64 | } | |
65 | ||
66 | proc test_value_history {} { | |
67 | global gdb_prompt | |
68 | ||
69 | gdb_test "print 101" "\\\$1 = 101" \ | |
70 | "Set value-history\[1\] using \$1" | |
71 | ||
72 | gdb_test "print 102" "\\\$2 = 102" \ | |
73 | "Set value-history\[2\] using \$2" | |
74 | ||
75 | gdb_test "print 103" "\\\$3 = 103" \ | |
76 | "Set value-history\[3\] using \$3" | |
77 | ||
78 | gdb_test "print \$\$" "\\\$4 = 102" \ | |
79 | "Print value-history\[MAX-1\] using inplicit index \$\$" | |
80 | ||
81 | gdb_test "print \$\$" "\\\$5 = 103" \ | |
82 | "Print value-history\[MAX-1\] again using implicit index \$\$" | |
83 | ||
84 | gdb_test "print \$" "\\\$6 = 103" \ | |
85 | "Print value-history\[MAX\] using implicit index \$" | |
86 | ||
87 | gdb_test "print \$\$2" "\\\$7 = 102" \ | |
88 | "Print value-history\[MAX-2\] using explicit index \$\$2" | |
89 | ||
90 | gdb_test "print \$0" "\\\$8 = 102" \ | |
91 | "Print value-history\[MAX\] using explicit index \$0" | |
92 | ||
a0b3c4fd | 93 | gdb_test "print 108" "\\\$9 = 108" |
c906108c SS |
94 | |
95 | gdb_test "print \$\$0" "\\\$10 = 108" \ | |
96 | "Print value-history\[MAX\] using explicit index \$\$0" | |
97 | ||
98 | gdb_test "print \$1" "\\\$11 = 101" \ | |
99 | "Print value-history\[1\] using explicit index \$1" | |
100 | ||
101 | gdb_test "print \$2" "\\\$12 = 102" \ | |
102 | "Print value-history\[2\] using explicit index \$2" | |
103 | ||
104 | gdb_test "print \$3" "\\\$13 = 103" \ | |
105 | "Print value-history\[3\] using explicit index \$3" | |
106 | ||
107 | gdb_test "print \$-3" "\\\$14 = 100" \ | |
108 | "Print (value-history\[MAX\] - 3) using implicit index \$" | |
109 | ||
110 | gdb_test "print \$1 + 3" "\\\$15 = 104" \ | |
111 | "Use value-history element in arithmetic expression" | |
112 | } | |
113 | ||
cab0c772 UW |
114 | proc test_with_program {} { |
115 | global hex | |
116 | gdb_test "set \$prog_var = p" "" \ | |
117 | "Set a new convenience variable to a program variable" | |
118 | gdb_test "print /x \$prog_var" " = $hex" \ | |
119 | "Print contents of new convenience variable of program variable" | |
120 | } | |
121 | ||
c906108c SS |
122 | # Start with a fresh gdb. |
123 | ||
124 | gdb_exit | |
125 | gdb_start | |
126 | gdb_reinitialize_dir $srcdir/$subdir | |
cab0c772 | 127 | gdb_load ${binfile} |
c906108c SS |
128 | |
129 | send_gdb "set print sevenbit-strings\n" ; gdb_expect -re ".*$gdb_prompt $" | |
130 | ||
131 | test_value_history | |
132 | test_convenience_variables | |
cab0c772 | 133 | test_with_program |