]>
Commit | Line | Data |
---|---|---|
f34c8766 | 1 | # Copyright (C) 1992, 1994, 1995 Free Software Foundation, Inc. |
19fa4a0a MW |
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 | |
4771fe15 | 15 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
19fa4a0a MW |
16 | |
17 | # Please email any bugs, comments, and/or additions to this file to: | |
c79f61db | 18 | # [email protected] |
19fa4a0a MW |
19 | |
20 | # This file was written by Fred Fish. ([email protected]) | |
21 | ||
22 | # Generic gdb subroutines that should work for any target. If these | |
23 | # need to be modified for any target, it can be done with a variable | |
24 | # or by passing arguments. | |
25 | ||
4771fe15 JL |
26 | load_lib libgloss.exp |
27 | ||
9bcc6c3f | 28 | global GDB |
4771fe15 JL |
29 | global CC |
30 | global CXX | |
31 | global CFLAGS | |
32 | global CXXFLAGS | |
33 | global CHILL_LIB | |
34 | global CHILL_RT0 | |
35 | ||
36 | if ![info exists CC] { | |
37 | set CC [findfile $base_dir/../../gcc/xgcc "$base_dir/../../gcc/xgcc -B$base_dir/../../gcc/" [transform gcc]] | |
4771fe15 | 38 | } |
a26fa899 | 39 | verbose "using CC = $CC" 2 |
4771fe15 JL |
40 | if ![info exists CXX] { |
41 | set CXX [findfile $base_dir/../../gcc/xgcc "$base_dir/../../gcc/xgcc -B$base_dir/../../gcc/" [transform g++]] | |
4771fe15 | 42 | } |
a26fa899 | 43 | verbose "using CXX = $CXX" 2 |
4771fe15 JL |
44 | if ![info exists CHILL_LIB] { |
45 | set CHILL_LIB [findfile $base_dir/../../gcc/ch/runtime/libchill.a "$base_dir/../../gcc/ch/runtime/libchill.a" [transform -lchill]] | |
4771fe15 | 46 | } |
a26fa899 | 47 | verbose "using CHILL_LIB = $CHILL_LIB" 2 |
4771fe15 JL |
48 | if ![info exists CHILL_RT0] { |
49 | set CHILL_RT0 [findfile $base_dir/../../gcc/ch/runtime/chillrt0.o "$base_dir/../../gcc/ch/runtime/chillrt0.o" ""] | |
4771fe15 | 50 | } |
a26fa899 | 51 | verbose "using CHILL_RT0 = $CHILL_RT0" 2 |
4771fe15 JL |
52 | |
53 | if ![info exists LDFLAGS] { | |
54 | if [is3way] { | |
55 | append LDFLAGS " [libgloss_flags] [newlib_flags]" | |
f7ef65ff | 56 | } |
4771fe15 | 57 | set LDFLAGS "" |
4771fe15 | 58 | } |
a26fa899 | 59 | verbose "using LDFLAGS = $LDFLAGS" 2 |
4771fe15 JL |
60 | |
61 | if ![info exists GDB] then { | |
62 | set GDB [findfile $base_dir/../../gdb/gdb "$base_dir/../../gdb/gdb" [transform gdb]] | |
9bcc6c3f | 63 | } |
a26fa899 | 64 | verbose "using GDB = $GDB" 2 |
4771fe15 | 65 | |
9bcc6c3f | 66 | global GDBFLAGS |
85174909 | 67 | if ![info exists GDBFLAGS] then { |
65424cda | 68 | set GDBFLAGS "-nx" |
85174909 | 69 | } |
a26fa899 | 70 | verbose "using GDBFLAGS = $GDBFLAGS" 2 |
85174909 | 71 | |
8c7ab5da JK |
72 | # The variable prompt is a regexp which matches the gdb prompt. Set it if it |
73 | # is not already set. | |
90fba5fa BC |
74 | global prompt |
75 | if ![info exists prompt] then { | |
8c7ab5da | 76 | set prompt "\\(gdb\\)" |
90fba5fa BC |
77 | } |
78 | ||
120edc2f KH |
79 | global usestubs |
80 | if [istarget "sparclite-*-*"] then { | |
81 | set usestubs 1 | |
82 | } else { | |
83 | set usestubs 0 | |
84 | } | |
85 | ||
86 | if ![info exists noargs] then { | |
87 | set noargs 0 | |
88 | } | |
89 | ||
4771fe15 JL |
90 | if ![info exists nosignals] then { |
91 | set nosignals 0 | |
92 | } | |
93 | ||
94 | if ![info exists noinferiorio] then { | |
95 | set noinferiorio 0 | |
96 | } | |
97 | ||
a26fa899 FF |
98 | if ![info exists noresults] then { |
99 | set noresults 0 | |
100 | } | |
101 | ||
5019a275 | 102 | # |
f34c8766 | 103 | # gdb_version -- extract and print the version number of GDB |
5019a275 RS |
104 | # |
105 | proc default_gdb_version {} { | |
106 | global GDB | |
107 | global GDBFLAGS | |
108 | if {[which $GDB] != 0} then { | |
4081daa1 | 109 | set tmp [exec echo "q" | $GDB -nw $GDBFLAGS] |
b34b32e7 | 110 | regexp " \[0-9\]\[^ \t\n\]+" $tmp version |
f34c8766 | 111 | clone_output "[which $GDB] version$version -nw $GDBFLAGS \n" |
5019a275 RS |
112 | } else { |
113 | warning "$GDB does not exist" | |
114 | } | |
115 | } | |
116 | ||
19fa4a0a MW |
117 | # |
118 | # gdb_unload -- unload a file if one is loaded | |
119 | # | |
120 | ||
121 | proc gdb_unload {} { | |
122 | global verbose | |
123 | global GDB | |
124 | global prompt | |
125 | send "file\n" | |
126 | expect { | |
9bcc6c3f RS |
127 | -re "No exec file now.*\r" { exp_continue } |
128 | -re "No symbol file now.*\r" { exp_continue } | |
129 | -re "A program is being debugged already..*Kill it.*y or n. $"\ | |
19fa4a0a | 130 | { send "y\n" |
85174909 | 131 | verbose "\t\tKilling previous program being debugged" |
9bcc6c3f | 132 | exp_continue |
19fa4a0a | 133 | } |
9bcc6c3f | 134 | -re "Discard symbol table from .*y or n. $" { |
19fa4a0a | 135 | send "y\n" |
9bcc6c3f | 136 | exp_continue |
19fa4a0a MW |
137 | } |
138 | -re "$prompt $" {} | |
139 | timeout { | |
85174909 | 140 | perror "couldn't unload file in $GDB (timed out)." |
c79f61db | 141 | return -1 |
19fa4a0a MW |
142 | } |
143 | } | |
144 | } | |
145 | ||
146 | # Many of the tests depend on setting breakpoints at various places and | |
147 | # running until that breakpoint is reached. At times, we want to start | |
148 | # with a clean-slate with respect to breakpoints, so this utility proc | |
149 | # lets us do this without duplicating this code everywhere. | |
150 | # | |
151 | ||
152 | proc delete_breakpoints {} { | |
153 | global prompt | |
154 | ||
155 | send "delete breakpoints\n" | |
156 | expect { | |
9bcc6c3f | 157 | -re "Delete all breakpoints.*y or n. $" { |
19fa4a0a | 158 | send "y\n" |
9bcc6c3f | 159 | exp_continue |
19fa4a0a MW |
160 | } |
161 | -re "y\r\n$prompt $" {} | |
31711c69 JK |
162 | -re ".*$prompt $" { # This happens if there were no breakpoints |
163 | } | |
8f07e537 | 164 | timeout { perror "Delete all breakpoints (timeout)" ; return } |
19fa4a0a MW |
165 | } |
166 | send "info breakpoints\n" | |
167 | expect { | |
168 | -re "No breakpoints or watchpoints..*$prompt $" {} | |
9bcc6c3f | 169 | -re ".*$prompt $" { perror "breakpoints not deleted" ; return } |
8f07e537 | 170 | timeout { perror "info breakpoints (timeout)" ; return } |
19fa4a0a MW |
171 | } |
172 | } | |
173 | ||
174 | ||
175 | # | |
70bcd4bc | 176 | # Generic run command. |
809943cf | 177 | # |
70bcd4bc SS |
178 | # The second pattern below matches up to the first newline *only*. |
179 | # Using ``.*$'' could swallow up output that we attempt to match | |
180 | # elsewhere. | |
809943cf C |
181 | # |
182 | proc gdb_run_cmd {} { | |
065924f7 KH |
183 | global usestubs |
184 | global prompt | |
185 | ||
186 | if $usestubs!=0 { | |
187 | send "jump *start\n" | |
188 | expect { | |
189 | -re "Line.* Jump anyway.*y or n. $" { | |
190 | send "y\n" | |
191 | expect { | |
192 | -re "Continuing.*$prompt $" {} | |
a26fa899 | 193 | timeout { perror "Jump to start() failed (timeout)"; return } |
065924f7 KH |
194 | } |
195 | } | |
196 | timeout { perror "Jump to start() failed (timeout)"; return } | |
197 | } | |
198 | send "continue\n" | |
199 | return | |
200 | } | |
809943cf C |
201 | send "run\n" |
202 | expect { | |
203 | -re "The program .* has been started already.*y or n. $" { | |
204 | send "y\n" | |
205 | exp_continue | |
206 | } | |
959fea03 | 207 | -re "Starting program: \[^\n\]*" {} |
809943cf C |
208 | } |
209 | } | |
210 | ||
211 | ||
19fa4a0a MW |
212 | # Set breakpoint at function and run gdb until it breaks there. |
213 | # Since this is the only breakpoint that will be set, if it stops | |
214 | # at a breakpoint, we will assume it is the one we want. We can't | |
215 | # just compare to "function" because it might be a fully qualified, | |
216 | # single quoted C++ function specifier. | |
19fa4a0a MW |
217 | |
218 | proc runto { function } { | |
219 | global prompt | |
220 | global decimal | |
221 | ||
222 | send "delete\n" | |
223 | expect { | |
9bcc6c3f | 224 | -re "delete.*Delete all breakpoints.*y or n. $" { |
19fa4a0a MW |
225 | send "y\n" |
226 | expect { | |
227 | -re "$prompt $" {} | |
228 | timeout { fail "deleting breakpoints (timeout)" ; return 0 } | |
229 | } | |
230 | } | |
231 | -re ".*$prompt $" {} | |
232 | timeout { fail "deleting breakpoints (timeout)" ; return 0 } | |
233 | } | |
234 | ||
235 | send "break $function\n" | |
3e304ddf | 236 | # The first two regexps are what we get with -g, the third is without -g. |
19fa4a0a | 237 | expect { |
f34c8766 | 238 | -re "Breakpoint \[0-9\]* at .*: file .*, line $decimal.\r\n$prompt $" {} |
3e304ddf | 239 | -re "Breakpoint \[0-9\]*: file .*, line $decimal.\r\n$prompt $" {} |
f34c8766 | 240 | -re "Breakpoint \[0-9\]* at .*$prompt $" {} |
19fa4a0a MW |
241 | -re "$prompt $" { fail "setting breakpoint at $function" ; return 0 } |
242 | timeout { fail "setting breakpoint at $function (timeout)" ; return 0 } | |
243 | } | |
244 | ||
4f2ec2ee C |
245 | gdb_run_cmd |
246 | ||
c79f61db RS |
247 | # the "at foo.c:36" output we get with -g. |
248 | # the "in func" output we get without -g. | |
412c988b | 249 | expect { |
4f2ec2ee C |
250 | -re "Break.* at .*:$decimal.*$prompt $" { |
251 | return 1 | |
412c988b | 252 | } |
c79f61db RS |
253 | -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in $function.*$prompt $" { |
254 | return 1 | |
255 | } | |
4f2ec2ee C |
256 | -re "$prompt $" { |
257 | fail "running to $function" | |
258 | return 0 | |
259 | } | |
260 | timeout { | |
261 | fail "running to $function (timeout)" | |
262 | return 0 | |
263 | } | |
19fa4a0a MW |
264 | } |
265 | } | |
266 | ||
120edc2f KH |
267 | # |
268 | # runto_main -- ask gdb to run and untill hit break point at main. | |
269 | # if it uses stubs, assuming we hit breakpoint() and just | |
270 | # step out of the function. | |
271 | # | |
272 | proc runto_main {} { | |
273 | global prompt | |
274 | global decimal | |
275 | global usestubs | |
276 | ||
277 | if $usestubs==0 { | |
f646eef4 | 278 | return [runto main] |
120edc2f KH |
279 | } |
280 | ||
281 | send "delete\n" | |
282 | expect { | |
283 | -re "delete.*Delete all breakpoints.*y or n. $" { | |
284 | send "y\n" | |
285 | expect { | |
286 | -re "$prompt $" {} | |
287 | timeout { fail "deleting breakpoints (timeout)" ; return 0 } | |
288 | } | |
289 | } | |
290 | -re ".*$prompt $" {} | |
291 | timeout { fail "deleting breakpoints (timeout)" ; return 0 } | |
292 | } | |
293 | ||
294 | send "step\n" | |
295 | # if use stubs step out of the breakpoint() function. | |
296 | expect { | |
3c23a941 | 297 | -re "main.* at .*$prompt $" {} |
120edc2f KH |
298 | timeout { fail "single step at breakpoint() (timeout)" ; return 0 } |
299 | } | |
3c23a941 | 300 | return 1 |
120edc2f KH |
301 | } |
302 | ||
19fa4a0a MW |
303 | # |
304 | # gdb_test -- send a command to gdb and test the result. | |
305 | # Takes three parameters. | |
306 | # Parameters: | |
307 | # First one is the command to execute, | |
5fac6a39 FF |
308 | # Second one is the pattern to match for a PASS, and must NOT include |
309 | # the \r\n sequence immediately before the gdb prompt. | |
19fa4a0a MW |
310 | # Third one is an optional message to be printed. If this |
311 | # a null string "", then the pass/fail messages are not printed. | |
312 | # Returns: | |
313 | # 1 if the test failed, | |
314 | # 0 if the test passes, | |
315 | # -1 if there was an internal error. | |
316 | # | |
317 | proc gdb_test { args } { | |
318 | global verbose | |
319 | global prompt | |
320 | global GDB | |
321 | global spawn_id | |
f646eef4 | 322 | global expect_out |
4771fe15 | 323 | upvar timeout timeout |
19fa4a0a MW |
324 | |
325 | if [llength $args]==3 then { | |
326 | set message [lindex $args 2] | |
327 | } else { | |
328 | set message [lindex $args 0] | |
329 | } | |
330 | set command [lindex $args 0] | |
331 | set pattern [lindex $args 1] | |
332 | ||
333 | if $verbose>2 then { | |
334 | send_user "Sending \"$command\" to gdb\n" | |
335 | send_user "Looking to match \"$pattern\"\n" | |
336 | send_user "Message is \"$message\"\n" | |
337 | } | |
338 | ||
339 | set result -1 | |
70bcd4bc | 340 | if ![string match $command ""] { |
65424cda | 341 | send "$command\n" |
19fa4a0a MW |
342 | } |
343 | ||
344 | expect { | |
345 | -re ".*Ending remote debugging.*$prompt$" { | |
346 | if ![isnative] then { | |
347 | warning "Can`t communicate to remote target." | |
348 | } | |
349 | gdb_exit | |
350 | gdb_start | |
351 | set result -1 | |
352 | } | |
4081daa1 | 353 | -re "$pattern\r\n$prompt $" { |
19fa4a0a MW |
354 | if ![string match "" $message] then { |
355 | pass "$message" | |
356 | } | |
357 | set result 0 | |
358 | } | |
359 | -re "Undefined command:.*$prompt" { | |
85174909 | 360 | perror "Undefined command \"$command\"." |
c79f61db | 361 | set result 1 |
19fa4a0a MW |
362 | } |
363 | -re "Ambiguous command.*$prompt $" { | |
85174909 | 364 | perror "\"$command\" is not a unique command name." |
c79f61db | 365 | set result 1 |
19fa4a0a | 366 | } |
f646eef4 FF |
367 | -re "(.*)(Program exited with code \[0-9\]+)(.*$prompt $)" { |
368 | if ![string match "" $message] then { | |
369 | set errmsg "$message: $expect_out(2,string)" | |
370 | } else { | |
371 | set errmsg "$command: $expect_out(2,string)" | |
372 | } | |
373 | perror "$errmsg" | |
374 | return -1 | |
375 | } | |
376 | -re "The program is not being run.*$prompt $" { | |
377 | if ![string match "" $message] then { | |
378 | set errmsg "$message: the program is no longer running" | |
379 | } else { | |
380 | set errmsg "$command: the program is no longer running" | |
381 | } | |
382 | perror "$errmsg" | |
383 | return -1 | |
384 | } | |
19fa4a0a MW |
385 | -re ".*$prompt $" { |
386 | if ![string match "" $message] then { | |
387 | fail "$message" | |
388 | } | |
389 | set result 1 | |
390 | } | |
391 | "<return>" { | |
392 | send "\n" | |
85174909 | 393 | perror "Window too small." |
19fa4a0a | 394 | } |
8c7ab5da | 395 | -re "\\(y or n\\) " { |
19fa4a0a | 396 | send "n\n" |
85174909 | 397 | perror "Got interactive prompt." |
19fa4a0a | 398 | } |
c79f61db | 399 | eof { |
85174909 | 400 | perror "Process no longer exists" |
c79f61db RS |
401 | return -1 |
402 | } | |
f646eef4 | 403 | full_buffer { |
85174909 | 404 | perror "internal buffer is full." |
19fa4a0a | 405 | } |
19fa4a0a | 406 | timeout { |
3e304ddf C |
407 | if ![string match "" $message] then { |
408 | fail "(timeout) $message" | |
409 | } | |
19fa4a0a MW |
410 | set result 1 |
411 | } | |
412 | } | |
413 | return $result | |
414 | } | |
f34c8766 | 415 | \f |
a59f104e | 416 | # Test that a command gives an error. For pass or fail, return |
f34c8766 JK |
417 | # a 1 to indicate that more tests can proceed. However a timeout |
418 | # is a serious error, generates a special fail message, and causes | |
419 | # a 0 to be returned to indicate that more tests are likely to fail | |
420 | # as well. | |
421 | ||
422 | proc test_print_reject { args } { | |
423 | global prompt | |
424 | global verbose | |
425 | ||
426 | if [llength $args]==2 then { | |
427 | set expectthis [lindex $args 1] | |
428 | } else { | |
429 | set expectthis "should never match this bogus string" | |
430 | } | |
431 | set sendthis [lindex $args 0] | |
432 | if $verbose>2 then { | |
433 | send_user "Sending \"$sendthis\" to gdb\n" | |
434 | send_user "Looking to match \"$expectthis\"\n" | |
435 | } | |
436 | send "$sendthis\n" | |
437 | expect { | |
438 | -re ".*A .* in expression.*\\.*$prompt $" { | |
439 | pass "reject $sendthis" | |
440 | return 1 | |
441 | } | |
442 | -re ".*Invalid syntax in expression.*$prompt $" { | |
443 | pass "reject $sendthis" | |
444 | return 1 | |
445 | } | |
446 | -re ".*Junk after end of expression.*$prompt $" { | |
447 | pass "reject $sendthis" | |
448 | return 1 | |
449 | } | |
450 | -re ".*Invalid number.*$prompt $" { | |
451 | pass "reject $sendthis" | |
452 | return 1 | |
453 | } | |
454 | -re ".*Invalid character constant.*$prompt $" { | |
455 | pass "reject $sendthis" | |
456 | return 1 | |
457 | } | |
458 | -re ".*No symbol table is loaded.*$prompt $" { | |
459 | pass "reject $sendthis" | |
460 | return 1 | |
461 | } | |
462 | -re ".*No symbol .* in current context.*$prompt $" { | |
463 | pass "reject $sendthis" | |
464 | return 1 | |
465 | } | |
466 | -re ".*$expectthis.*$prompt $" { | |
467 | pass "reject $sendthis" | |
468 | return 1 | |
469 | } | |
470 | -re ".*$prompt $" { | |
471 | fail "reject $sendthis" | |
472 | return 1 | |
473 | } | |
474 | default { | |
475 | fail "reject $sendthis (eof or timeout)" | |
476 | return 0 | |
477 | } | |
478 | } | |
479 | } | |
480 | \f | |
faa15770 PB |
481 | # Given an input string, adds backslashes as needed to create a |
482 | # regexp that will match the string. | |
3e304ddf | 483 | |
faa15770 | 484 | proc string_to_regexp {str} { |
3e304ddf C |
485 | set result $str |
486 | regsub -all {[]*+.|()^$\[]} $str {\\&} result | |
faa15770 PB |
487 | return $result |
488 | } | |
489 | ||
490 | # Same as gdb_test, but the second parameter is not a regexp, | |
491 | # but a string that must match exactly. | |
492 | ||
493 | proc gdb_test_exact { args } { | |
4771fe15 JL |
494 | upvar timeout timeout |
495 | ||
faa15770 | 496 | set command [lindex $args 0] |
68361314 | 497 | set pattern [string_to_regexp [lindex $args 1]] |
e7dc69ff FF |
498 | # It is most natural to write the pattern argument with only |
499 | # embedded \n's, especially if you are trying to avoid Tcl quoting | |
500 | # problems. But expect really wants to see \r\n in patterns. So | |
501 | # transform the pattern here. First transform \r\n back to \n, in | |
502 | # case some users of gdb_test_exact already do the right thing. | |
503 | regsub -all "\r\n" $pattern "\n" pattern | |
504 | regsub -all "\n" $pattern "\r\n" pattern | |
faa15770 PB |
505 | if [llength $args]==3 then { |
506 | set message [lindex $args 2] | |
507 | } else { | |
508 | set message $command | |
509 | } | |
510 | return [gdb_test $command $pattern $message] | |
511 | } | |
f34c8766 | 512 | \f |
19fa4a0a MW |
513 | proc gdb_reinitialize_dir { subdir } { |
514 | global prompt | |
19fa4a0a | 515 | |
85174909 | 516 | send "dir\n" |
19fa4a0a | 517 | expect { |
4771fe15 | 518 | -re "Reinitialize source path to empty.*y or n. " { |
19fa4a0a MW |
519 | send "y\n" |
520 | expect { | |
521 | -re "Source directories searched.*$prompt $" { | |
522 | send "dir $subdir\n" | |
523 | expect { | |
524 | -re "Source directories searched.*$prompt $" { | |
85174909 | 525 | verbose "Dir set to $subdir" |
19fa4a0a MW |
526 | } |
527 | -re ".*$prompt $" { | |
85174909 | 528 | perror "Dir \"$subdir\" failed." |
19fa4a0a MW |
529 | } |
530 | } | |
531 | } | |
532 | -re ".*$prompt $" { | |
85174909 | 533 | perror "Dir \"$subdir\" failed." |
19fa4a0a MW |
534 | } |
535 | } | |
536 | } | |
537 | -re ".*$prompt $" { | |
85174909 | 538 | perror "Dir \"$subdir\" failed." |
19fa4a0a MW |
539 | } |
540 | } | |
541 | } | |
c79f61db | 542 | |
c79f61db RS |
543 | # |
544 | # gdb_exit -- exit the GDB, killing the target program if necessary | |
545 | # | |
546 | proc default_gdb_exit {} { | |
547 | global GDB | |
548 | global GDBFLAGS | |
549 | global verbose | |
550 | ||
002cc99f | 551 | verbose "Quitting $GDB $GDBFLAGS" |
c79f61db RS |
552 | |
553 | # This used to be 1 for unix-gdb.exp | |
554 | set timeout 5 | |
a26fa899 | 555 | verbose "Timeout is now $timeout seconds" 2 |
c79f61db | 556 | |
90fba5fa BC |
557 | # We used to try to send "quit" to GDB, and wait for it to die. |
558 | # Dealing with all the cases and errors got pretty hairy. Just close it, | |
559 | # that is simpler. | |
560 | close | |
561 | ||
562 | # Omitting this probably would cause strange timing-dependent failures. | |
c79f61db RS |
563 | wait |
564 | } | |
565 | ||
85174909 | 566 | # |
4771fe15 JL |
567 | # load a file into the debugger. |
568 | # return a -1 if anything goes wrong. | |
85174909 RS |
569 | # |
570 | proc gdb_file_cmd { arg } { | |
571 | global verbose | |
572 | global loadpath | |
573 | global loadfile | |
574 | global GDB | |
575 | global prompt | |
9bcc6c3f | 576 | global spawn_id |
4771fe15 | 577 | upvar timeout timeout |
85174909 RS |
578 | |
579 | send "file $arg\n" | |
580 | expect { | |
581 | -re "Reading symbols from.*done.*$prompt $" { | |
582 | verbose "\t\tLoaded $arg into the $GDB" | |
583 | return 0 | |
584 | } | |
585 | -re "has no symbol-table.*$prompt $" { | |
586 | perror "$arg wasn't compiled with \"-g\"" | |
587 | return -1 | |
588 | } | |
9bcc6c3f | 589 | -re "A program is being debugged already.*Kill it.*y or n. $" { |
85174909 RS |
590 | send "y\n" |
591 | verbose "\t\tKilling previous program being debugged" | |
9bcc6c3f | 592 | exp_continue |
85174909 | 593 | } |
9bcc6c3f | 594 | -re "Load new symbol table from \".*\".*y or n. $" { |
85174909 RS |
595 | send "y\n" |
596 | expect { | |
597 | -re "Reading symbols from.*done.*$prompt $" { | |
598 | verbose "\t\tLoaded $arg with new symbol table into $GDB" | |
599 | return 0 | |
600 | } | |
601 | timeout { | |
602 | perror "(timeout) Couldn't load $arg, other program already l | |
603 | oaded." | |
604 | return -1 | |
605 | } | |
606 | } | |
607 | } | |
608 | -re ".*No such file or directory.*$prompt $" { | |
609 | perror "($arg) No such file or directory\n" | |
610 | return -1 | |
611 | } | |
612 | -re "$prompt $" { | |
613 | perror "couldn't load $arg into $GDB." | |
614 | return -1 | |
615 | } | |
616 | timeout { | |
9bcc6c3f | 617 | perror "couldn't load $arg into $GDB (timed out)." |
85174909 RS |
618 | return -1 |
619 | } | |
620 | eof { | |
621 | # This is an attempt to detect a core dump, but seems not to | |
622 | # work. Perhaps we need to match .* followed by eof, in which | |
623 | # expect does not seem to have a way to do that. | |
8f07e537 | 624 | perror "couldn't load $arg into $GDB (end of file)." |
85174909 RS |
625 | return -1 |
626 | } | |
627 | } | |
628 | } | |
c79f61db | 629 | |
0fba9aa2 SS |
630 | # |
631 | # start gdb -- start gdb running, default procedure | |
632 | # | |
302fcffb FF |
633 | # When running over NFS, particularly if running many simultaneous |
634 | # tests on different hosts all using the same server, things can | |
635 | # get really slow. Give gdb at least 3 minutes to start up. | |
636 | # | |
0fba9aa2 SS |
637 | proc default_gdb_start { } { |
638 | global verbose | |
639 | global GDB | |
640 | global GDBFLAGS | |
641 | global prompt | |
642 | global spawn_id | |
643 | global timeout | |
f34c8766 | 644 | verbose "Spawning $GDB -nw $GDBFLAGS" |
3e304ddf C |
645 | |
646 | if { [which $GDB] == 0 } then { | |
647 | perror "$GDB does not exist." | |
648 | exit 1 | |
649 | } | |
0fba9aa2 SS |
650 | |
651 | set oldtimeout $timeout | |
302fcffb FF |
652 | set timeout [expr "$timeout + 180"] |
653 | verbose "Timeout increased to $timeout seconds" 2 | |
f34c8766 | 654 | eval "spawn $GDB -nw $GDBFLAGS" |
0fba9aa2 SS |
655 | expect { |
656 | -re ".*\r\n$prompt $" { | |
3e304ddf | 657 | verbose "GDB initialized." |
0fba9aa2 SS |
658 | } |
659 | -re "$prompt $" { | |
660 | perror "GDB never initialized." | |
302fcffb FF |
661 | set timeout $oldtimeout |
662 | verbose "Timeout restored to $timeout seconds" 2 | |
0fba9aa2 SS |
663 | return -1 |
664 | } | |
665 | timeout { | |
302fcffb FF |
666 | perror "(timeout) GDB never initialized after $timeout seconds." |
667 | set timeout $oldtimeout | |
668 | verbose "Timeout restored to $timeout seconds" 2 | |
0fba9aa2 SS |
669 | return -1 |
670 | } | |
671 | } | |
672 | set timeout $oldtimeout | |
302fcffb | 673 | verbose "Timeout restored to $timeout seconds" 2 |
0fba9aa2 SS |
674 | # force the height to "unlimited", so no pagers get used |
675 | send "set height 0\n" | |
676 | expect { | |
677 | -re ".*$prompt $" { | |
678 | verbose "Setting height to 0." 2 | |
679 | } | |
680 | timeout { | |
681 | warning "Couldn't set the height to 0." | |
682 | } | |
683 | } | |
684 | # force the width to "unlimited", so no wraparound occurs | |
685 | send "set width 0\n" | |
686 | expect { | |
687 | -re ".*$prompt $" { | |
4771fe15 | 688 | verbose "Setting width to 0." 2 |
0fba9aa2 SS |
689 | } |
690 | timeout { | |
691 | warning "Couldn't set the width to 0." | |
692 | } | |
693 | } | |
694 | } | |
695 | ||
9bcc6c3f RS |
696 | # |
697 | # FIXME: this is a copy of the new library procedure, but it's here too | |
698 | # till the new dejagnu gets installed everywhere. I'd hate to break the | |
699 | # gdb tests suite. | |
700 | # | |
002cc99f RS |
701 | global argv0 |
702 | if ![info exists argv0] then { | |
9bcc6c3f RS |
703 | proc exp_continue { } { |
704 | continue -expect | |
705 | } | |
706 | } | |
c79f61db | 707 | |
4771fe15 JL |
708 | # * For crosses, the CHILL runtime doesn't build because it can't find |
709 | # setjmp.h, stdio.h, etc. | |
710 | # * For AIX (as of 16 Mar 95), (a) there is no language code for | |
711 | # CHILL in output_epilog in gcc/config/rs6000/rs6000.c, (b) collect2 | |
712 | # does not get along with AIX's too-clever linker. | |
713 | # * On Irix5, there is a bug whereby set of bool, etc., don't get | |
714 | # TYPE_LOW_BOUND for the bool right because force_to_range_type doesn't | |
715 | # work with stub types. | |
716 | # Lots of things seem to fail on the PA, and since it's not a supported | |
717 | # chill target at the moment, don't run the chill tests. | |
718 | ||
4081daa1 | 719 | proc skip_chill_tests {} { |
4771fe15 JL |
720 | eval set skip_chill [expr ![isnative] || [istarget "*-*-aix*"] || [istarget "*-*-irix5*"] || [istarget "alpha-*-osf*"] || [istarget "hppa*-*-*"]] |
721 | verbose "Skip chill tests is $skip_chill" | |
722 | return $skip_chill | |
4081daa1 | 723 | } |