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