Copyright year update in most files of the GDB Project.
[external/binutils.git] / gdb / testsuite / gdb.mi / mi2-basics.exp
1 # Copyright 1999-2005, 2007-2012 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 3 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, see <http://www.gnu.org/licenses/>.
15
16 #
17 # test basic Machine interface (MI) operations
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
28 load_lib mi-support.exp
29 set MIFLAGS "-i=mi2"
30
31 gdb_exit
32 if [mi_gdb_start] {
33     continue
34 }
35
36 set testfile "basics"
37 set srcfile ${testfile}.c
38 set binfile ${objdir}/${subdir}/mi2-basics
39 set escapedobjdir [string_to_regexp ${objdir}]
40 set envirodir [string_to_regexp ${objdir}/${subdir}]
41
42 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DFAKEARGV}] != "" } {
43      untested mi2-basics.exp
44      return -1
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     if ![mi_gdb_test "-gdb-version" "~\"GNU gdb.*" "acceptance of MI operations"] {
63         return 1
64     } 
65     
66     note "Skipping all other MI tests."
67     return 0
68 }
69
70 proc test_exec_and_symbol_mi_operatons {} {
71     global mi_gdb_prompt
72     global binfile
73
74     # Load symbols and specify executable on a single operation
75     # Tests:
76     # -file-exec-and-symbols
77
78     if [mi_gdb_test "-file-exec-and-symbols ${binfile}" "\\\^done" \
79        "file-exec-and-symbols operation"] {
80         note "Skipping all other MI tests."
81         return 0
82     }
83
84     # The following is not used by mi-support.exp, but we test here so
85     # we get done with loading a program basics.
86
87     # Do it again, but now load symbols and specify executable with
88     # two separate operations
89     # Tests:
90     # -file-clear
91     # -file-exec-file
92     # -file-symbol-file
93
94     # FIXME: file-clear is not implemented yet.
95 #   mi_gdb_test "-file-clear" \
96 #            "\\\^done" \
97 #            "file-clear operation"
98
99     mi_gdb_test "-file-exec-file ${binfile}" \
100              "\\\^done" \
101              "file-exec-file operation"
102
103     mi_gdb_test "-file-symbol-file ${binfile}" \
104              "\\\^done" \
105              "file-symbol-file operation"
106
107     # We need to return != 0.
108     return 1
109 }
110
111 proc test_breakpoints_deletion {} {
112     global mi_gdb_prompt
113     global srcfile
114
115     # Clear all breakpoints and list to confirm
116     # Tests:
117     # -break-delete (all)
118     # -break-list
119
120     # The all parameter is actually no parameter.
121     mi_gdb_test "200-break-delete" \
122              "200\\\^done" \
123              "break-delete (all) operation"
124
125     mi_gdb_test "201-break-list" \
126              ".*\\\^done,BreakpointTable=\\\{.*,body=\\\[\\\]\\\}" \
127              "all breakpoints removed"
128 }
129
130 proc test_dir_specification {} {
131     global mi_gdb_prompt
132     global objdir
133     global subdir
134     global envirodir
135
136     # Add to the search directories, display, then reset back to default
137     # Tests:
138     # -environment-directory arg
139     # -environment-directory 
140     # -environment-directory -r
141
142     mi_gdb_test "202-environment-directory ${objdir}/${subdir}" \
143              "202\\\^done,source-path=\"${envirodir}.\\\$cdir.\\\$cwd\"" \
144              "environment-directory arg operation"
145
146     mi_gdb_test "203-environment-directory" \
147              "203\\\^done,source-path=\"${envirodir}.\\\$cdir.\\\$cwd\"" \
148              "environment-directory empty-string operation"
149
150     mi_gdb_test "204-environment-directory -r" \
151              "204\\\^done,source-path=\"\\\$cdir.\\\$cwd\"" \
152              "environment-directory operation"
153
154 #exp_internal 0
155 }
156
157 proc test_cwd_specification {} {
158     global mi_gdb_prompt
159     global objdir
160     global subdir
161     global escapedobjdir
162
163     # Change the working directory, then print the current working directory
164     # Tests:
165     # -environment-cd ${objdir}
166     # -environment-pwd
167
168     mi_gdb_test "205-environment-cd ${objdir}" \
169              "205\\\^done" \
170              "environment-cd arg operation"
171
172     # The canonical name of the working directory may differ on a
173     # remote host from that on the build system.
174     if ![is_remote host] {
175         mi_gdb_test "206-environment-pwd" \
176              "206\\\^done,cwd=\"${escapedobjdir}\"" \
177              "environment-pwd operation"
178     }
179 }
180
181 proc test_path_specification {} {
182     global mi_gdb_prompt
183     global orig_path
184     global objdir
185     global subdir
186     global escapedobjdir
187     global envirodir
188     global expect_out
189
190     # Add to the path, display, then reset 
191     # Tests:
192     # -environment-path 
193     # -environment-path dir1 dir2
194     # -environment-path -r dir
195     # -environment-path -r
196
197     mi_gdb_test "-environment-path" "\\\^done,path=\"(.*)\"" "-environment-path"
198     set orig_path $expect_out(3,string)
199
200     set orig_path [string_to_regexp ${orig_path}]
201     set pathdir [string_to_regexp ${objdir}/${subdir}]
202
203     mi_gdb_test "207-environment-path" \
204              "207\\\^done,path=\"$orig_path\"" \
205              "environment-path no-args operation"
206
207     mi_gdb_test "208-environment-path $objdir ${objdir}/${subdir}" \
208              "208\\\^done,path=\"$escapedobjdir.${envirodir}.$orig_path\"" \
209              "environment-path dir1 dir2 operation"
210
211     mi_gdb_test "209-environment-path -r $objdir" \
212              "209\\\^done,path=\"$escapedobjdir.$orig_path\"" \
213              "environment-path -r dir operation"
214
215     mi_gdb_test "210-environment-path -r" \
216              "210\\\^done,path=\"$orig_path\"" \
217              "environment-path -r operation"
218
219
220
221 if { [test_mi_interpreter_selection]
222       && [test_exec_and_symbol_mi_operatons] } {
223   test_breakpoints_deletion
224   test_dir_specification
225   test_cwd_specification
226   test_path_specification
227 }
228
229 mi_gdb_exit
230 return 0