Index: ChangeLog
[external/binutils.git] / gdb / testsuite / gdb.mi / mi2-basics.exp
1 #   Copyright 1999, 2000 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 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
19
20 #
21 # test basic Machine interface (MI) operations
22 #
23 # Verify that, using the MI, we can load a program and do
24 # other basic things that are used by all test files through  mi_gdb_exit,
25 # mi_gdb_start, mi_delete_breakpoints, mi_gdb_reinitialize_dir and
26 # mi_gdb_load, so we can safely use those.
27 #
28 # The goal is not to test gdb functionality, which is done by other tests,
29 # but the command syntax and correct output response to MI operations.
30 #
31
32 load_lib mi-support.exp
33 set MIFLAGS "-i=mi2"
34
35 gdb_exit
36 if [mi_gdb_start] {
37     continue
38 }
39
40 set testfile "basics"
41 set srcfile ${testfile}.c
42 set binfile ${objdir}/${subdir}/${testfile}
43 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DFAKEARGV}] != "" } {
44      gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
45 }
46
47 # In this file we want to test if the operations needed by the following
48 # procedures work, so it makes no sense using them here.
49
50 # mi_delete_breakpoints
51 # mi_gdb_reinitialize_dir $srcdir/$subdir
52 # mi_gdb_load ${binfile}
53
54 # Test if the MI interpreter has been configured
55
56 proc test_mi_interpreter_selection {} {
57     global mi_gdb_prompt
58     global gdb_prompt
59
60     # All this test expects is to get the prompt back
61     # with no syntax error message
62     send_gdb "-gdb-version\n"
63     gdb_expect {
64            -re "GNU gdb .*\r\n$mi_gdb_prompt$" \
65                { pass "acceptance of MI operations" 
66                  return 1}
67            -re ".*\r\n$mi_gdb_prompt$" \
68                { fail "acceptance of MI operations"
69                  note "Skipping all other MI tests." }
70            -re "Undefined command.*$gdb_prompt $" \
71                { fail "acceptance of MI operations"
72                  note "Skipping all other MI tests." }
73            -re ".*$gdb_prompt $" \
74                { fail "acceptance of MI operations"
75                  note "Skipping all other MI tests." }
76            timeout { fail "acceptance of MI operations (timeout)"
77                      note "Skipping all other MI tests." }
78     }
79     return 0
80 }
81
82 proc test_exec_and_symbol_mi_operatons {} {
83     global mi_gdb_prompt
84     global binfile
85
86     # Load symbols and specify executable on a single operation
87     # Tests:
88     # -file-exec-and-symbols
89
90     # Can't use mi_gdb_test as if this doesn't work,
91     #  we must give up on the whole test file
92     send_gdb "-file-exec-and-symbols ${binfile}\n"
93     gdb_expect {
94            -re "\[\r\n\]*\\\^done\r\n$mi_gdb_prompt$" \
95                { pass "file-exec-and-symbols operation" }
96            timeout { fail "file-exec-and-symbols operation (timeout)"
97                      note "Skipping all other MI tests."
98                      return 0}
99     }
100
101     # The following is not used by mi-support.exp, but we test here so
102     # we get done with loading a program basics.
103
104     # Do it again, but now load symbols and specify executable with
105     # two separate operations
106     # Tests:
107     # -file-clear
108     # -file-exec-file
109     # -file-symbol-file
110
111     # FIXME: file-clear is not implemented yet.
112 #   mi_gdb_test "-file-clear" \
113 #            "\\\^done" \
114 #            "file-clear operation"
115
116     mi_gdb_test "-file-exec-file ${binfile}" \
117              "\\\^done" \
118              "file-exec-file operation"
119
120     mi_gdb_test "-file-symbol-file ${binfile}" \
121              "\\\^done" \
122              "file-symbol-file operation"
123
124     # FIXME: if we cannot load we have to skip all other tests.
125 }
126
127 proc test_breakpoints_deletion {} {
128     global mi_gdb_prompt
129     global srcfile
130
131     # Clear all breakpoints and list to confirm
132     # Tests:
133     # -break-delete (all)
134     # -break-list
135
136     # The all parameter is actually no parameter.
137     mi_gdb_test "200-break-delete" \
138              "\\\^done" \
139              "break-delete (all) operation"
140
141     mi_gdb_test "201-break-list" \
142              ".*\\\^done,BreakpointTable=\\\{.*,body=\\\[\\\]\\\}" \
143              "all breakpoints removed"
144 }
145
146 proc test_dir_specification {} {
147     global mi_gdb_prompt
148     global srcdir
149     global subdir
150
151     # Add to the search directories, display, then reset back to default
152     # Tests:
153     # -environment-directory arg
154     # -environment-directory 
155     # -environment-directory -r
156
157 #exp_internal 1
158     mi_gdb_test "202-environment-directory ${srcdir}/${subdir}" \
159              "\\\^done,source-path=\"${srcdir}/${subdir}.\\\$cdir.\\\$cwd\"" \
160              "environment-directory arg operation"
161
162     mi_gdb_test "203-environment-directory" \
163              "\\\^done,source-path=\"${srcdir}/${subdir}.\\\$cdir.\\\$cwd\"" \
164              "environment-directory empty-string operation"
165
166     mi_gdb_test "204-environment-directory -r" \
167              "\\\^done,source-path=\"\\\$cdir.\\\$cwd\"" \
168              "environment-directory operation"
169
170 #exp_internal 0
171 }
172
173 proc test_cwd_specification {} {
174     global mi_gdb_prompt
175     global objdir
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}" \
184              "\\\^done" \
185              "environment-cd arg operation"
186
187     mi_gdb_test "206-environment-pwd" \
188              "\\\^done,cwd=\"${objdir}\"" \
189              "environment-pwd operation"
190 }
191
192 proc test_path_specification {} {
193     global mi_gdb_prompt
194     global orig_path
195     global objdir
196     global srcdir
197
198     # Add to the path, display, then reset 
199     # Tests:
200     # -environment-path 
201     # -environment-path dir1 dir2
202     # -environment-path -r dir
203     # -environment-path -r
204
205 #exp_internal 1
206
207     send_gdb "-environment-path\n"
208     gdb_expect 20 {
209         -re "\\\^done,path=\"\(.*\)\"\r\n$mi_gdb_prompt" { 
210           set orig_path $expect_out(1,string); 
211         }
212         timeout { 
213           perror "-environment-path (timeout)" ; 
214           return 
215         }
216     }
217
218     mi_gdb_test "207-environment-path" \
219              "\\\^done,path=\"$orig_path\"" \
220              "environment-path no-args operation"
221
222     mi_gdb_test "208-environment-path $srcdir $objdir" \
223              "\\\^done,path=\"$srcdir.$objdir.$orig_path\"" \
224              "environment-path dir1 dir2 operation"
225
226     mi_gdb_test "209-environment-path -r $objdir" \
227              "\\\^done,path=\"$objdir.$orig_path\"" \
228              "environment-path -r dir operation"
229
230     mi_gdb_test "210-environment-path -r" \
231              "\\\^done,path=\"$orig_path\"" \
232              "environment-path -r operation"
233
234 #exp_internal 0
235
236
237 if [test_mi_interpreter_selection] {
238   test_exec_and_symbol_mi_operatons
239   test_breakpoints_deletion
240   test_dir_specification
241   test_cwd_specification
242   test_path_specification
243 }
244
245 mi_gdb_exit
246 return 0