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