This commit was generated by cvs2svn to track changes on a CVS vendor
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / dbx.exp
CommitLineData
74cf1395
JM
1# Copyright (C) 1998 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
21if $tracelevel then {
22 strace $tracelevel
23}
24
25set testfile1 "average"
26set testfile2 "sum"
27set testfile "dbx-test"
28set binfile1 ${objdir}/${subdir}/${testfile1}
29set binfile2 ${objdir}/${subdir}/${testfile2}
30set binfile ${objdir}/${subdir}/${testfile}
31
32
33
34if { [gdb_compile "${srcdir}/${subdir}/average.c" "${binfile1}.o" object {debug}] != "" } {
35 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
36}
37
38if { [gdb_compile "${srcdir}/${subdir}/sum.c" "${binfile2}.o" object {debug}] != "" } {
39 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
40}
41
42if { [gdb_compile "${binfile1}.o ${binfile2}.o" ${binfile} executable {debug}] != "" } {
43 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
44}
45
46#
47# start gdb -- start gdb running, default procedure
48#
49proc dbx_gdb_start { } {
50 global verbose
51 global GDB
52 global GDBFLAGS
53 global prompt
54 global spawn_id
55 global timeout
56 verbose "Spawning $GDB -nw $GDBFLAGS"
57
58 if { [which $GDB] == 0 } then {
59 perror "$GDB does not exist."
60 exit 1
61 }
62
63 set oldtimeout $timeout
64 set timeout [expr "$timeout + 60"]
65 eval "spawn $GDB -nw -dbx $GDBFLAGS"
66 gdb_expect {
67 -re ".*\r\n$gdb_prompt $" {
68 verbose "GDB initialized."
69 }
70 -re "$prompt $" {
71 perror "GDB never initialized."
72 return -1
73 }
74 timeout {
75 perror "(timeout) GDB never initialized."
76 return -1
77 }
78 }
79 set timeout $oldtimeout
80 # force the height to "unlimited", so no pagers get used
81 send_gdb "set height 0\n"
82 gdb_expect {
83 -re ".*$prompt $" {
84 verbose "Setting height to 0." 2
85 }
86 timeout {
87 warning "Couldn't set the height to 0."
88 }
89 }
90 # force the width to "unlimited", so no wraparound occurs
91 send_gdb "set width 0\n"
92 gdb_expect {
93 -re ".*$prompt $" {
94 verbose "Setting width to 0." 2
95 }
96 timeout {
97 warning "Couldn't set the width to 0."
98 }
99 }
100}
101
102
103proc dbx_reinitialize_dir { subdir } {
104 global gdb_prompt
105
106 send_gdb "use\n"
107 gdb_expect {
108 -re "Reinitialize source path to empty.*y or n. " {
109 send_gdb "y\n"
110 gdb_expect {
111 -re "Source directories searched.*$gdb_prompt $" {
112 send_gdb "use $subdir\n"
113 gdb_expect {
114 -re "Source directories searched.*$gdb_prompt $" {
115 verbose "Dir set to $subdir"
116 }
117 -re ".*$gdb_prompt $" {
118 perror "Dir \"$subdir\" failed."
119 }
120 }
121 }
122 -re ".*$gdb_prompt $" {
123 perror "Dir \"$subdir\" failed."
124 }
125 }
126 }
127 -re ".*$gdb_prompt $" {
128 perror "Dir \"$subdir\" failed."
129 }
130 }
131}
132
133# In "testsuite/config/unix-gdb.exp", the routine "gdb_load"
134# is defined as "gdb_file_cmd". The binding of "gdb_file_cmd"
135# is done at invocation time. Before this file is processed,
136# it binds to the definition in "testsuite/lib/gdb.exp"; after
137# this file is processed, it binds to this definition.
138# TCL lets us overrides a previous routine definition without a
139# warning (isn't that special?).
140#
141# This means that tests before use "file" to load a target, and
142# tests afterwards use the pair "symbol-file" "exec-file".
143#
144# I'm leaving it as it is for now because at the moment it
145# is the only test we have of the use of the combination of
146# "symbol-file" and "exec-file" to load a debugging target (the
147# other definition uses "file".
148#
149# Symbol-file and exec-file should be tested explicitly, not
150# as a side effect of running a particular test (in this case,
151# "testsuite/gdb.compat/dbx.exp").
152#
153# CM: Renamed the procedure so it does not override the orginal file name.
154# Having the test suite change behavior depending on the tests run makes
155# it extremely difficult to reproduce errors. I've also added a
156# "dbx_gdb_load" procedure. This and only this test will call these
157# procedures now. I also added an "expect" to the "send exec-file" line.
158# The "expect" waits for a prompt to appear. Otherwise, if the tests run
159# too quickly, the caller could send another command before the prompt
160# of this command returns, causing the test to get out of sync and fail
161# seemingly randomly or only on a loaded system.
162#
163proc dbx_gdb_file_cmd {arg } {
164 global verbose
165 global loadpath
166 global loadfile
167 global GDB
168 global gdb_prompt
169 global spawn_id
170 upvar timeout timeout
171
172 send_gdb "symbol-file $arg\n"
173 gdb_expect {
174 -re "Detected 64-bit symbol file.\r\nInvoking.*gdb64.*$gdb_prompt $" {
175 verbose "\t\tLoaded $arg into the $GDB"
176 send_gdb "exec-file $arg\n"
177 gdb_expect {
178 -re ".*$gdb_prompt $" {
179 verbose "\t\tLoaded $arg with new symbol table into $GDB"
180 return 0
181 }
182 timeout {
183 perror "(timeout) Couldn't load $arg"
184 return -1
185 }
186 }
187 return 0
188 }
189 -re "Reading symbols from.*done.*$gdb_prompt $" {
190 verbose "\t\tLoaded $arg into the $GDB"
191 send_gdb "exec-file $arg\n"
192 gdb_expect {
193 -re ".*$gdb_prompt $" {
194 verbose "\t\tLoaded $arg with new symbol table into $GDB"
195 return 0
196 }
197 timeout {
198 perror "(timeout) Couldn't load $arg"
199 return -1
200 }
201 }
202 return 0
203 }
204 -re "has no symbol-table.*$gdb_prompt $" {
205 perror "$arg wasn't compiled with \"-g\""
206 return -1
207 }
208 -re "A program is being debugged already.*Kill it.*y or n. $" {
209 send_gdb "y\n"
210 verbose "\t\tKilling previous program being debugged"
211 exp_continue
212 }
213 -re "Load new symbol table from \".*\".*y or n. $" {
214 send_gdb "y\n"
215 gdb_expect {
216 -re "Reading symbols from.*done.*$gdb_prompt $" {
217 verbose "\t\tLoaded $arg with new symbol table into $GDB"
218 return 0
219 }
220 timeout {
221 perror "(timeout) Couldn't load $arg, other program already loaded."
222 return -1
223 }
224 }
225 }
226 -re ".*No such file or directory.*$gdb_prompt $" {
227 perror "($arg) No such file or directory\n"
228 return -1
229 }
230 -re "$gdb_prompt $" {
231 perror "couldn't load $arg into $GDB."
232 return -1
233 }
234 timeout {
235 perror "couldn't load $arg into $GDB (timed out)."
236 return -1
237 }
238 eof {
239 # This is an attempt to detect a core dump, but seems not to
240 # work. Perhaps we need to match .* followed by eof, in which
241 # expect does not seem to have a way to do that.
242 perror "couldn't load $arg into $GDB (end of file)."
243 return -1
244 }
245 }
246}
247
248proc dbx_gdb_load { arg } {
249 global verbose
250 global loadpath
251 global loadfile
252 global GDB
253 global prompt
254 upvar timeout timeout
255
256 return [dbx_gdb_file_cmd $arg]
257}
258
259#
260#test_breakpoints
261#
262proc test_breakpoints { } {
263 gdb_test "stop in main" "Breakpoint.*at.*: file.*average\.c, line 38\."
264 gdb_test "status" "Num.*Type.*Disp.*Enb.*Address.*What\r\n1\[ \r\]+breakpoint\[ \r\]+keep y.*in main at.*average\.c:38.*"
265 gdb_test "stop at 43" "Breakpoint.*at.*: file.*average\.c, line 43.*"
266 gdb_test "stop in 43" "Usage: stop in <function . address>"
267 gdb_test "stop at main" "Usage: stop at <line>"
268}
269
270#
271#test_assign
272#
273proc test_assign { } {
274 gdb_test "run" ""
275 gdb_test "assign first=1" ""
276 gdb_test "print first" ".1 = 1"
277}
278
279#
280#test_whereis
281#
282proc test_whereis { } {
283 gdb_test "whereis my_list" "All variables matching regular expression \"my_list\":\r\n\r\nFile.*average\.c:\r\nstatic int my_list\\\[10\\\];"
284}
285
286#
287#test_func
288#
289proc test_func { } {
290 gdb_test "cont" ""
291 gdb_test "step" ""
292 gdb_test "func sum" "'sum' not within current stack frame\."
293 gdb_test "stop in sum" "Breakpoint.*at.*: file.*sum\.c, line 11\."
294 gdb_test "cont"
295 gdb_test "func print_average" ".*in print_average.*\\(list=.*, low=0, high=6\\).*at.*average\.c:24\r\n24\[ \t\]+total = sum\\(list, low, high\\);"
296}
297
298# Start with a fresh gdb.
299
300gdb_exit
301global GDBFLAGS
302set saved_gdbflags $GDBFLAGS
303
304set GDBFLAGS "$GDBFLAGS --dbx"
305gdb_start
306dbx_reinitialize_dir $srcdir/$subdir
307dbx_gdb_load ${binfile}
308
309test_breakpoints
310test_assign
311test_whereis
312gdb_test "file average.c:1" "1\[ \t\]+/. This is a sample program.*"
313test_func
314
315#exit and cleanup
316gdb_exit
317
318set GDBFLAGS $saved_gdbflags
319return 0
This page took 0.035447 seconds and 4 git commands to generate.