* lib/gdb.exp (gdb_compile_test): New.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-basics.exp
CommitLineData
0fb0cc75 1# Copyright 1999, 2000, 2001, 2002, 2003, 2005, 2007, 2008, 2009
6aba47ca 2# Free Software Foundation, Inc.
fb40c209
AC
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
fb40c209 7# (at your option) any later version.
e22f8b7c 8#
fb40c209
AC
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#
fb40c209 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/>.
fb40c209 16
fb40c209
AC
17#
18# test basic Machine interface (MI) operations
19#
20# Verify that, using the MI, we can load a program and do
21# other basic things that are used by all test files through mi_gdb_exit,
22# mi_gdb_start, mi_delete_breakpoints, mi_gdb_reinitialize_dir and
23# mi_gdb_load, so we can safely use those.
24#
25# The goal is not to test gdb functionality, which is done by other tests,
26# but the command syntax and correct output response to MI operations.
27#
28
29load_lib mi-support.exp
b30bf9ee 30set MIFLAGS "-i=mi"
fb40c209
AC
31
32gdb_exit
ecd3fd0f 33if [mi_gdb_start separate-inferior-tty] {
fb40c209
AC
34 continue
35}
36
37set testfile "basics"
38set srcfile ${testfile}.c
3788363d 39set binfile ${objdir}/${subdir}/mi-basics
e0f353ce 40set escapedobjdir [string_to_regexp ${objdir}]
18ef391a 41set envirodir [string_to_regexp ${objdir}/${subdir}]
e0f353ce 42
fb40c209 43if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DFAKEARGV}] != "" } {
b60f0898
JB
44 untested mi-basics.exp
45 return -1
fb40c209
AC
46}
47
48# In this file we want to test if the operations needed by the following
49# procedures work, so it makes no sense using them here.
50
51# mi_delete_breakpoints
52# mi_gdb_reinitialize_dir $srcdir/$subdir
53# mi_gdb_load ${binfile}
54
55# Test if the MI interpreter has been configured
56
57proc test_mi_interpreter_selection {} {
58 global mi_gdb_prompt
59 global gdb_prompt
60
61 # All this test expects is to get the prompt back
62 # with no syntax error message
63 send_gdb "-gdb-version\n"
64 gdb_expect {
65 -re "GNU gdb .*\r\n$mi_gdb_prompt$" \
66 { pass "acceptance of MI operations"
67 return 1}
68 -re ".*\r\n$mi_gdb_prompt$" \
69 { fail "acceptance of MI operations"
70 note "Skipping all other MI tests." }
71 -re "Undefined command.*$gdb_prompt $" \
72 { fail "acceptance of MI operations"
73 note "Skipping all other MI tests." }
74 -re ".*$gdb_prompt $" \
75 { fail "acceptance of MI operations"
76 note "Skipping all other MI tests." }
77 timeout { fail "acceptance of MI operations (timeout)"
78 note "Skipping all other MI tests." }
79 }
80 return 0
81}
82
83proc test_exec_and_symbol_mi_operatons {} {
84 global mi_gdb_prompt
85 global binfile
86
87 # Load symbols and specify executable on a single operation
88 # Tests:
89 # -file-exec-and-symbols
90
91 # Can't use mi_gdb_test as if this doesn't work,
92 # we must give up on the whole test file
93 send_gdb "-file-exec-and-symbols ${binfile}\n"
94 gdb_expect {
95 -re "\[\r\n\]*\\\^done\r\n$mi_gdb_prompt$" \
96 { pass "file-exec-and-symbols operation" }
97 timeout { fail "file-exec-and-symbols operation (timeout)"
98 note "Skipping all other MI tests."
99 return 0}
100 }
101
102 # The following is not used by mi-support.exp, but we test here so
103 # we get done with loading a program basics.
104
105 # Do it again, but now load symbols and specify executable with
106 # two separate operations
107 # Tests:
108 # -file-clear
109 # -file-exec-file
110 # -file-symbol-file
111
112 # FIXME: file-clear is not implemented yet.
2231a1e8
EZ
113# mi_gdb_test "-file-clear" \
114# "\\\^done" \
115# "file-clear operation"
fb40c209
AC
116
117 mi_gdb_test "-file-exec-file ${binfile}" \
118 "\\\^done" \
119 "file-exec-file operation"
120
121 mi_gdb_test "-file-symbol-file ${binfile}" \
122 "\\\^done" \
123 "file-symbol-file operation"
124
125 # FIXME: if we cannot load we have to skip all other tests.
126}
127
128proc test_breakpoints_deletion {} {
129 global mi_gdb_prompt
130 global srcfile
131
132 # Clear all breakpoints and list to confirm
133 # Tests:
134 # -break-delete (all)
135 # -break-list
136
137 # The all parameter is actually no parameter.
138 mi_gdb_test "200-break-delete" \
39fb8e9e 139 "200\\\^done" \
fb40c209
AC
140 "break-delete (all) operation"
141
142 mi_gdb_test "201-break-list" \
cff22675 143 ".*\\\^done,BreakpointTable=\\\{.*,body=\\\[\\\]\\\}" \
fb40c209
AC
144 "all breakpoints removed"
145}
146
147proc test_dir_specification {} {
148 global mi_gdb_prompt
18ef391a 149 global objdir
fb40c209 150 global subdir
18ef391a 151 global envirodir
fb40c209 152
93ce5efb 153 # Add to the search directories, display, then reset back to default
fb40c209 154 # Tests:
fb40c209 155 # -environment-directory arg
93ce5efb
JJ
156 # -environment-directory
157 # -environment-directory -r
fb40c209 158
18ef391a 159 mi_gdb_test "202-environment-directory ${objdir}/${subdir}" \
540b8a30 160 "202\\\^done,source-path=\"${envirodir}.\\\$cdir.\\\$cwd\"" \
93ce5efb
JJ
161 "environment-directory arg operation"
162
163 mi_gdb_test "203-environment-directory" \
540b8a30 164 "203\\\^done,source-path=\"${envirodir}.\\\$cdir.\\\$cwd\"" \
93ce5efb
JJ
165 "environment-directory empty-string operation"
166
167 mi_gdb_test "204-environment-directory -r" \
39fb8e9e 168 "204\\\^done,source-path=\"\\\$cdir.\\\$cwd\"" \
fb40c209 169 "environment-directory operation"
fb40c209
AC
170}
171
93ce5efb
JJ
172proc test_cwd_specification {} {
173 global mi_gdb_prompt
174 global objdir
e0f353ce 175 global escapedobjdir
93ce5efb
JJ
176 global subdir
177
178 # Change the working directory, then print the current working directory
179 # Tests:
180 # -environment-cd ${objdir}
181 # -environment-pwd
182
183 mi_gdb_test "205-environment-cd ${objdir}" \
39fb8e9e 184 "205\\\^done" \
93ce5efb
JJ
185 "environment-cd arg operation"
186
07ab73a0
JM
187 # The canonical name of the working directory may differ on a
188 # remote host from that on the build system.
189 if ![is_remote host] {
190 mi_gdb_test "206-environment-pwd" \
39fb8e9e 191 "206\\\^done,cwd=\"${escapedobjdir}\"" \
93ce5efb 192 "environment-pwd operation"
07ab73a0 193 }
93ce5efb
JJ
194}
195
196proc test_path_specification {} {
197 global mi_gdb_prompt
198 global orig_path
199 global objdir
18ef391a 200 global subdir
e0f353ce 201 global escapedobjdir
18ef391a 202 global envirodir
93ce5efb
JJ
203
204 # Add to the path, display, then reset
205 # Tests:
206 # -environment-path
207 # -environment-path dir1 dir2
208 # -environment-path -r dir
209 # -environment-path -r
210
93ce5efb
JJ
211 send_gdb "-environment-path\n"
212 gdb_expect 20 {
213 -re "\\\^done,path=\"\(.*\)\"\r\n$mi_gdb_prompt" {
214 set orig_path $expect_out(1,string);
215 }
216 timeout {
217 perror "-environment-path (timeout)" ;
218 return
219 }
220 }
221
041bf30d 222 set orig_path [string_to_regexp ${orig_path}]
18ef391a 223 set pathdir [string_to_regexp ${objdir}/${subdir}]
041bf30d 224
93ce5efb 225 mi_gdb_test "207-environment-path" \
39fb8e9e 226 "207\\\^done,path=\"$orig_path\"" \
93ce5efb
JJ
227 "environment-path no-args operation"
228
18ef391a
NR
229 mi_gdb_test "208-environment-path $objdir ${objdir}/${subdir}" \
230 "208\\\^done,path=\"$escapedobjdir.${envirodir}.$orig_path\"" \
93ce5efb
JJ
231 "environment-path dir1 dir2 operation"
232
233 mi_gdb_test "209-environment-path -r $objdir" \
39fb8e9e 234 "209\\\^done,path=\"$escapedobjdir.$orig_path\"" \
93ce5efb
JJ
235 "environment-path -r dir operation"
236
237 mi_gdb_test "210-environment-path -r" \
39fb8e9e 238 "210\\\^done,path=\"$orig_path\"" \
93ce5efb
JJ
239 "environment-path -r operation"
240
93ce5efb
JJ
241}
242
3cb3b8df
BR
243proc test_setshow_inferior_tty {} {
244 global mi_gdb_prompt
ecd3fd0f 245 global mi_inferior_tty_name
3cb3b8df
BR
246
247 # Test that the commands,
248 # -inferior-tty-set
249 # -inferior-tty-show
250 # are setting/getting the same data in GDB.
251
252 mi_gdb_test "301-inferior-tty-show" \
ecd3fd0f
BR
253 "301\\\^done,inferior_tty_terminal=\"$mi_inferior_tty_name\"" \
254 "initial tty is mi_inferior_tty_name"
3cb3b8df
BR
255
256 mi_gdb_test "302-inferior-tty-set /dev/pts/1" \
257 "302\\\^done" \
258 "set tty to /dev/pts/1"
259
260 mi_gdb_test "303-inferior-tty-show" \
261 "303\\\^done,inferior_tty_terminal=\"/dev/pts/1\"" \
262 "tty was set correctly"
263
264 mi_gdb_test "304-inferior-tty-set" \
265 "304\\\^done" \
266 "set tty to the empty string"
267
268 mi_gdb_test "305-inferior-tty-show" \
269 "305\\\^done" \
ecd3fd0f
BR
270 "make sure tty is empty"
271
272 mi_gdb_test "306-inferior-tty-set $mi_inferior_tty_name" \
273 "306\\\^done" \
274 "set tty to mi_inferior_tty_name (the way it was)"
275
276 mi_gdb_test "307-inferior-tty-show" \
277 "307\\\^done,inferior_tty_terminal=\"$mi_inferior_tty_name\"" \
278 "verify tty is correct"
3cb3b8df
BR
279}
280
fb40c209
AC
281if [test_mi_interpreter_selection] {
282 test_exec_and_symbol_mi_operatons
283 test_breakpoints_deletion
284 test_dir_specification
93ce5efb
JJ
285 test_cwd_specification
286 test_path_specification
3cb3b8df 287 test_setshow_inferior_tty
fb40c209
AC
288}
289
290mi_gdb_exit
291return 0
This page took 0.882095 seconds and 4 git commands to generate.