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