1# Copyright 1999, 2000, 2001, 2002, 2004, 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# 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=mi"
25
26gdb_exit
27if [mi_gdb_start] {
28    continue
29}
30
31set testfile "var-cmd"
32set srcfile ${testfile}.c
33set binfile ${objdir}/${subdir}/mi-var-block
34if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DFAKEARGV}] != "" } {
35    untested mi-var-block.exp
36    return -1
37}
38
39mi_delete_breakpoints
40mi_gdb_reinitialize_dir $srcdir/$subdir
41mi_gdb_load ${binfile}
42
43mi_runto do_block_tests
44
45# Test: c_variable-3.2
46# Desc: create cb and foo
47mi_create_varobj "cb" "cb" "create local variable cb"
48
49mi_gdb_test "-var-create foo * foo" \
50       "\\^error,msg=\"-var-create: unable to create variable object\"" \
51       "try to create local variable foo"
52
53# step to "foo = 123;"
54mi_step_to "do_block_tests" "" "var-cmd.c" \
55    [gdb_get_line_number "foo = 123;"] \
56    "step at do_block_test"
57
58
59# Be paranoid and assume 3.2 created foo
60mi_gdb_test "-var-delete foo" \
61	"\\^error,msg=\"Variable object not found\"" \
62	"delete var foo"
63
64
65# Test: c_variable-3.3
66# Desc: create foo
67mi_create_varobj "foo" "foo" "create local variable foo"
68
69# step to "foo2 = 123;"
70mi_step_to "do_block_tests" "" "var-cmd.c" \
71    [gdb_get_line_number "foo2 = 123;"] \
72    "step at do_block_test"
73
74# Test: c_variable-3.4
75# Desc: check foo, cb changed
76mi_gdb_test "-var-update *" \
77	"\\^done,changelist=\\\[\{name=\"foo\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\},\{name=\"cb\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\}\\\]" \
78	"update all vars: cb foo changed"
79
80# step to "foo = 321;"
81mi_step_to "do_block_tests" "" "var-cmd.c" \
82    [gdb_get_line_number "foo = 321;"] \
83    "step at do_block_test"
84
85# Test: c_variable-3.5
86# Desc: create inner block foo
87mi_create_varobj "inner_foo" "foo" "create local variable inner_foo"
88
89# step to "foo2 = 0;"
90mi_step_to "do_block_tests" "" "var-cmd.c" \
91    [gdb_get_line_number "foo2 = 0;"] \
92    "step at do_block_test"
93
94# Test: c_variable-3.6
95# Desc: create foo2
96mi_create_varobj "foo2" "foo2" "create local variable foo2"
97
98# Test: c_variable-3.7
99# Desc: check that outer foo in scope and inner foo out of scope
100# Note: also a known gdb problem
101setup_xfail *-*-*
102mi_gdb_test "-var-update inner_foo" \
103	"\\^done,changelist=\{FIXME\}" \
104	"update inner_foo: should be out of scope: KNOWN PROBLEM"
105clear_xfail *-*-*
106
107setup_xfail *-*-*
108mi_gdb_test "-var-evaluate-expression inner_foo" \
109	"\\^done,value=\{FIXME\}" \
110	"evaluate inner_foo: should be out of scope: KNOWN PROBLEM"
111clear_xfail *-*-*
112
113mi_gdb_test "-var-update foo" \
114	"\\^done,changelist=\\\[\\\]" \
115	"update foo: did not change"
116
117mi_gdb_test "-var-delete inner_foo" \
118	"\\^done,ndeleted=\"1\"" \
119	"delete var inner_foo"
120
121# step to "foo = 0;"
122mi_step_to "do_block_tests" "" "var-cmd.c" \
123    [gdb_get_line_number "foo = 0;"] \
124    "step at do_block_test"
125
126# Test: c_variable-3.8
127# Desc: check that foo2 out of scope (known gdb problem)
128setup_xfail *-*-*
129mi_gdb_test "-var-update foo2" \
130	"\\^done,changelist=\{FIXME\}" \
131	"update foo2: should be out of scope: KNOWN PROBLEM"
132clear_xfail *-*-*
133
134# step to "cb = 21;"
135mi_step_to "do_block_tests" "" "var-cmd.c" \
136    [gdb_get_line_number "cb = 21;"] \
137    "step at do_block_test"
138
139# Test: c_variable-3.9
140# Desc: check that only cb is in scope (known gdb problem)
141setup_xfail *-*-*
142mi_gdb_test "-var-update foo2" \
143	"\\^done,changelist=\\\[FIXME\\\]" \
144	"update foo2 should be out of scope: KNOWN PROBLEM"
145clear_xfail *-*-*
146setup_xfail *-*-*
147mi_gdb_test "-var-update foo" \
148	"\\^done,changelist=\{FIXME\}" \
149	"update foo should be out of scope: KNOWN PROBLEM"
150clear_xfail *-*-*
151mi_gdb_test "-var-update cb" \
152	"\\^done,changelist=\\\[\\\]" \
153	"update cb"
154
155# Test: c_variable-3.10
156# Desc: names of editable variables
157#gdbtk_test c_variable-3.10 {names of editable variables} {
158#  editable_variables
159#} {{foo cb foo2} {}}
160
161# Done with block tests
162mi_gdb_test "-var-delete foo" \
163	"\\^done,ndeleted=\"1\"" \
164	"delete var foo"
165
166mi_gdb_test "-var-delete foo2" \
167	"\\^done,ndeleted=\"1\"" \
168	"delete var foo2"
169
170mi_gdb_test "-var-delete cb" \
171	"\\^done,ndeleted=\"1\"" \
172	"delete var cb"
173
174mi_gdb_exit
175return 0
176