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