1# Copyright 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
2#
3# This Program Is Free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 2 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program; if not, write to the Free Software
15# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17# Test essential Machine interface (MI) operations
18#
19# Verify that, using the MI, we can create, update, delete variables.
20#
21
22
23load_lib mi-support.exp
24set MIFLAGS "-i=mi2"
25
26gdb_exit
27if [mi_gdb_start] {
28    continue
29}
30
31set testfile "var-cmd"
32set srcfile ${testfile}.c
33set binfile ${objdir}/${subdir}/${testfile}
34if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DFAKEARGV}] != "" } {
35    gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
36}
37
38mi_delete_breakpoints
39mi_gdb_reinitialize_dir $srcdir/$subdir
40mi_gdb_load ${binfile}
41
42mi_runto do_block_tests
43
44# Test: c_variable-3.2
45# Desc: create cb and foo
46mi_gdb_test "-var-create cb * cb" \
47	"\\^done,name=\"cb\",numchild=\"0\",type=\"int\"" \
48	"create local variable cb"
49
50mi_gdb_test "-var-create foo * foo" \
51	"&\"mi_cmd_var_create: unable to create variable object\\\\n\".*\\^error,msg=\"mi_cmd_var_create: unable to create variable object\"" \
52	"create local variable foo"
53
54# step to "foo = 123;"
55mi_step_to "do_block_tests" "" "var-cmd.c" \
56    [gdb_get_line_number "foo = 123;"] \
57    "step at do_block_test"
58
59
60# Be paranoid and assume 3.2 created foo
61mi_gdb_test "-var-delete foo" \
62	"&\"Variable object not found\\\\n\".*\\^error,msg=\"Variable object not found\"" \
63	"delete var foo"
64
65
66# Test: c_variable-3.3
67# Desc: create foo
68mi_gdb_test "-var-create foo * foo" \
69	"\\^done,name=\"foo\",numchild=\"0\",type=\"int\"" \
70	"create local variable foo"
71
72# step to "foo2 = 123;"
73mi_step_to "do_block_tests" "" "var-cmd.c" \
74    [gdb_get_line_number "foo2 = 123;"] \
75    "step at do_block_test"
76
77# Test: c_variable-3.4
78# Desc: check foo, cb changed
79mi_gdb_test "-var-update *" \
80	"\\^done,changelist=\\\[\{name=\"foo\",in_scope=\"true\",type_changed=\"false\"\},\{name=\"cb\",in_scope=\"true\",type_changed=\"false\"\}\\\]" \
81	"update all vars: cb foo changed"
82
83# step to "foo = 321;"
84mi_step_to "do_block_tests" "" "var-cmd.c" \
85    [gdb_get_line_number "foo = 321;"] \
86    "step at do_block_test"
87
88# Test: c_variable-3.5
89# Desc: create inner block foo
90mi_gdb_test "-var-create inner_foo * foo" \
91	"\\^done,name=\"inner_foo\",numchild=\"0\",type=\"int\"" \
92	"create local variable inner_foo"
93
94# step to "foo2 = 0;"
95mi_step_to "do_block_tests" "" "var-cmd.c" \
96    [gdb_get_line_number "foo2 = 0;"] \
97    "step at do_block_test"
98
99# Test: c_variable-3.6
100# Desc: create foo2
101mi_gdb_test "-var-create foo2 * foo2" \
102	"\\^done,name=\"foo2\",numchild=\"0\",type=\"int\"" \
103	"create local variable foo2"
104
105# Test: c_variable-3.7
106# Desc: check that outer foo in scope and inner foo out of scope
107# Note: also a known gdb problem
108setup_xfail *-*-*
109mi_gdb_test "-var-update inner_foo" \
110	"\\^done,changelist=\{FIXME\}" \
111	"update inner_foo: should be out of scope: KNOWN PROBLEM"
112clear_xfail *-*-*
113
114setup_xfail *-*-*
115mi_gdb_test "-var-evaluate-expression inner_foo" \
116	"\\^done,value=\{FIXME\}" \
117	"evaluate inner_foo: should be out of scope: KNOWN PROBLEM"
118clear_xfail *-*-*
119
120mi_gdb_test "-var-update foo" \
121	"\\^done,changelist=\\\[\\\]" \
122	"update foo: did not change"
123
124mi_gdb_test "-var-delete inner_foo" \
125	"\\^done,ndeleted=\"1\"" \
126	"delete var inner_foo"
127
128# step to "foo = 0;"
129mi_step_to "do_block_tests" "" "var-cmd.c" \
130    [gdb_get_line_number "foo = 0;"] \
131    "step at do_block_test"
132
133# Test: c_variable-3.8
134# Desc: check that foo2 out of scope (known gdb problem)
135setup_xfail *-*-*
136mi_gdb_test "-var-update foo2" \
137	"\\^done,changelist=\{FIXME\}" \
138	"update foo2: should be out of scope: KNOWN PROBLEM"
139clear_xfail *-*-*
140
141# step to "cb = 21;"
142mi_step_to "do_block_tests" "" "var-cmd.c" \
143    [gdb_get_line_number "cb = 21;"] \
144    "step at do_block_test"
145
146# Test: c_variable-3.9
147# Desc: check that only cb is in scope (known gdb problem)
148setup_xfail *-*-*
149mi_gdb_test "-var-update foo2" \
150	"\\^done,changelist=\\\[FIXME\\\]" \
151	"update foo2 should be out of scope: KNOWN PROBLEM"
152clear_xfail *-*-*
153setup_xfail *-*-*
154mi_gdb_test "-var-update foo" \
155	"\\^done,changelist=\{FIXME\}" \
156	"update foo should be out of scope: KNOWN PROBLEM"
157clear_xfail *-*-*
158mi_gdb_test "-var-update cb" \
159	"\\^done,changelist=\\\[\\\]" \
160	"update cb"
161
162# Test: c_variable-3.10
163# Desc: names of editable variables
164#gdbtk_test c_variable-3.10 {names of editable variables} {
165#  editable_variables
166#} {{foo cb foo2} {}}
167
168# Done with block tests
169mi_gdb_test "-var-delete foo" \
170	"\\^done,ndeleted=\"1\"" \
171	"delete var foo"
172
173mi_gdb_test "-var-delete foo2" \
174	"\\^done,ndeleted=\"1\"" \
175	"delete var foo2"
176
177mi_gdb_test "-var-delete cb" \
178	"\\^done,ndeleted=\"1\"" \
179	"delete var cb"
180
181mi_gdb_exit
182return 0
183