Commit | Line | Data |
---|---|---|
b6ba6518 KB |
1 | # Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000 |
2 | # Free Software Foundation, Inc. | |
c906108c SS |
3 | |
4 | # This program is free software; you can redistribute it and/or modify | |
5 | # it under the terms of the GNU General Public License as published by | |
6 | # the Free Software Foundation; either version 2 of the License, or | |
7 | # (at your option) any later version. | |
8 | # | |
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. | |
13 | # | |
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
17 | ||
18 | # Please email any bugs, comments, and/or additions to this file to: | |
19 | # bug-gdb@prep.ai.mit.edu | |
20 | ||
21 | # This file was written by Fred Fish. (fnf@cygnus.com) | |
22 | ||
23 | # Generic gdb subroutines that should work for any target. If these | |
24 | # need to be modified for any target, it can be done with a variable | |
25 | # or by passing arguments. | |
26 | ||
27 | load_lib libgloss.exp | |
28 | ||
29 | global GDB | |
30 | global CHILL_LIB | |
31 | global CHILL_RT0 | |
32 | ||
33 | if ![info exists CHILL_LIB] { | |
34 | set CHILL_LIB [findfile $base_dir/../../gcc/ch/runtime/libchill.a "$base_dir/../../gcc/ch/runtime/libchill.a" [transform -lchill]] | |
35 | } | |
36 | verbose "using CHILL_LIB = $CHILL_LIB" 2 | |
37 | if ![info exists CHILL_RT0] { | |
38 | set CHILL_RT0 [findfile $base_dir/../../gcc/ch/runtime/chillrt0.o "$base_dir/../../gcc/ch/runtime/chillrt0.o" ""] | |
39 | } | |
40 | verbose "using CHILL_RT0 = $CHILL_RT0" 2 | |
41 | ||
42 | if [info exists TOOL_EXECUTABLE] { | |
43 | set GDB $TOOL_EXECUTABLE; | |
44 | } | |
45 | if ![info exists GDB] { | |
46 | if ![is_remote host] { | |
47 | set GDB [findfile $base_dir/../../gdb/gdb "$base_dir/../../gdb/gdb" [transform gdb]] | |
48 | } else { | |
49 | set GDB [transform gdb]; | |
50 | } | |
51 | } | |
52 | verbose "using GDB = $GDB" 2 | |
53 | ||
54 | global GDBFLAGS | |
55 | if ![info exists GDBFLAGS] { | |
56 | set GDBFLAGS "-nx" | |
57 | } | |
58 | verbose "using GDBFLAGS = $GDBFLAGS" 2 | |
59 | ||
9e0b60a8 JM |
60 | # The variable gdb_prompt is a regexp which matches the gdb prompt. |
61 | # Set it if it is not already set. | |
c906108c | 62 | global gdb_prompt |
9e0b60a8 | 63 | if ![info exists gdb_prompt] then { |
c906108c SS |
64 | set gdb_prompt "\[(\]gdb\[)\]" |
65 | } | |
66 | ||
93076499 ND |
67 | # Needed for some tests under Cygwin. |
68 | global EXEEXT | |
69 | global env | |
70 | ||
71 | if ![info exists env(EXEEXT)] { | |
72 | set EXEEXT "" | |
73 | } else { | |
74 | set EXEEXT $env(EXEEXT) | |
75 | } | |
76 | ||
085dd6e6 JM |
77 | ### Only procedures should come after this point. |
78 | ||
c906108c SS |
79 | # |
80 | # gdb_version -- extract and print the version number of GDB | |
81 | # | |
82 | proc default_gdb_version {} { | |
83 | global GDB | |
84 | global GDBFLAGS | |
85 | global gdb_prompt | |
86 | set fileid [open "gdb_cmd" w]; | |
87 | puts $fileid "q"; | |
88 | close $fileid; | |
89 | set cmdfile [remote_download host "gdb_cmd"]; | |
90 | set output [remote_exec host "$GDB -nw --command $cmdfile"] | |
91 | remote_file build delete "gdb_cmd"; | |
92 | remote_file host delete "$cmdfile"; | |
93 | set tmp [lindex $output 1]; | |
94 | set version "" | |
95 | regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version | |
96 | if ![is_remote host] { | |
97 | clone_output "[which $GDB] version $version $GDBFLAGS\n" | |
98 | } else { | |
99 | clone_output "$GDB on remote host version $version $GDBFLAGS\n" | |
100 | } | |
101 | } | |
102 | ||
103 | proc gdb_version { } { | |
104 | return [default_gdb_version]; | |
105 | } | |
106 | ||
107 | # | |
108 | # gdb_unload -- unload a file if one is loaded | |
109 | # | |
110 | ||
111 | proc gdb_unload {} { | |
112 | global verbose | |
113 | global GDB | |
114 | global gdb_prompt | |
115 | send_gdb "file\n" | |
116 | gdb_expect 60 { | |
117 | -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue } | |
118 | -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue } | |
119 | -re "A program is being debugged already..*Kill it.*y or n. $"\ | |
120 | { send_gdb "y\n" | |
121 | verbose "\t\tKilling previous program being debugged" | |
122 | exp_continue | |
123 | } | |
124 | -re "Discard symbol table from .*y or n.*$" { | |
125 | send_gdb "y\n" | |
126 | exp_continue | |
127 | } | |
128 | -re "$gdb_prompt $" {} | |
129 | timeout { | |
130 | perror "couldn't unload file in $GDB (timed out)." | |
131 | return -1 | |
132 | } | |
133 | } | |
134 | } | |
135 | ||
136 | # Many of the tests depend on setting breakpoints at various places and | |
137 | # running until that breakpoint is reached. At times, we want to start | |
138 | # with a clean-slate with respect to breakpoints, so this utility proc | |
139 | # lets us do this without duplicating this code everywhere. | |
140 | # | |
141 | ||
142 | proc delete_breakpoints {} { | |
143 | global gdb_prompt | |
144 | ||
a0b3c4fd JM |
145 | # we need a larger timeout value here or this thing just confuses |
146 | # itself. May need a better implementation if possible. - guo | |
147 | # | |
c906108c | 148 | send_gdb "delete breakpoints\n" |
a0b3c4fd | 149 | gdb_expect 100 { |
c906108c SS |
150 | -re "Delete all breakpoints.*y or n.*$" { |
151 | send_gdb "y\n"; | |
152 | exp_continue | |
153 | } | |
154 | -re "$gdb_prompt $" { # This happens if there were no breakpoints | |
155 | } | |
156 | timeout { perror "Delete all breakpoints in delete_breakpoints (timeout)" ; return } | |
157 | } | |
158 | send_gdb "info breakpoints\n" | |
a0b3c4fd | 159 | gdb_expect 100 { |
c906108c SS |
160 | -re "No breakpoints or watchpoints..*$gdb_prompt $" {} |
161 | -re "$gdb_prompt $" { perror "breakpoints not deleted" ; return } | |
162 | -re "Delete all breakpoints.*or n.*$" { | |
163 | send_gdb "y\n"; | |
164 | exp_continue | |
165 | } | |
166 | timeout { perror "info breakpoints (timeout)" ; return } | |
167 | } | |
168 | } | |
169 | ||
170 | ||
171 | # | |
172 | # Generic run command. | |
173 | # | |
174 | # The second pattern below matches up to the first newline *only*. | |
175 | # Using ``.*$'' could swallow up output that we attempt to match | |
176 | # elsewhere. | |
177 | # | |
178 | proc gdb_run_cmd {args} { | |
179 | global gdb_prompt | |
180 | ||
181 | if [target_info exists gdb_init_command] { | |
182 | send_gdb "[target_info gdb_init_command]\n"; | |
183 | gdb_expect 30 { | |
184 | -re "$gdb_prompt $" { } | |
185 | default { | |
186 | perror "gdb_init_command for target failed"; | |
187 | return; | |
188 | } | |
189 | } | |
190 | } | |
191 | ||
192 | if [target_info exists use_gdb_stub] { | |
193 | if [target_info exists gdb,do_reload_on_run] { | |
917317f4 JM |
194 | # Specifying no file, defaults to the executable |
195 | # currently being debugged. | |
196 | if { [gdb_load ""] < 0 } { | |
197 | return; | |
198 | } | |
c906108c SS |
199 | send_gdb "continue\n"; |
200 | gdb_expect 60 { | |
201 | -re "Continu\[^\r\n\]*\[\r\n\]" {} | |
202 | default {} | |
203 | } | |
204 | return; | |
205 | } | |
206 | ||
207 | if [target_info exists gdb,start_symbol] { | |
208 | set start [target_info gdb,start_symbol]; | |
209 | } else { | |
210 | set start "start"; | |
211 | } | |
212 | send_gdb "jump *$start\n" | |
917317f4 JM |
213 | set start_attempt 1; |
214 | while { $start_attempt } { | |
215 | # Cap (re)start attempts at three to ensure that this loop | |
216 | # always eventually fails. Don't worry about trying to be | |
217 | # clever and not send a command when it has failed. | |
218 | if [expr $start_attempt > 3] { | |
219 | perror "Jump to start() failed (retry count exceeded)"; | |
c906108c SS |
220 | return; |
221 | } | |
917317f4 JM |
222 | set start_attempt [expr $start_attempt + 1]; |
223 | gdb_expect 30 { | |
224 | -re "Continuing at \[^\r\n\]*\[\r\n\]" { | |
225 | set start_attempt 0; | |
226 | } | |
227 | -re "No symbol \"_start\" in current.*$gdb_prompt $" { | |
228 | perror "Can't find start symbol to run in gdb_run"; | |
229 | return; | |
230 | } | |
231 | -re "No symbol \"start\" in current.*$gdb_prompt $" { | |
232 | send_gdb "jump *_start\n"; | |
233 | } | |
234 | -re "No symbol.*context.*$gdb_prompt $" { | |
235 | set start_attempt 0; | |
236 | } | |
237 | -re "Line.* Jump anyway.*y or n. $" { | |
238 | send_gdb "y\n" | |
239 | } | |
240 | -re "The program is not being run.*$gdb_prompt $" { | |
241 | if { [gdb_load ""] < 0 } { | |
242 | return; | |
243 | } | |
244 | send_gdb "jump *$start\n"; | |
245 | } | |
246 | timeout { | |
247 | perror "Jump to start() failed (timeout)"; | |
248 | return | |
249 | } | |
c906108c | 250 | } |
c906108c SS |
251 | } |
252 | if [target_info exists gdb_stub] { | |
253 | gdb_expect 60 { | |
254 | -re "$gdb_prompt $" { | |
255 | send_gdb "continue\n" | |
256 | } | |
257 | } | |
258 | } | |
259 | return | |
260 | } | |
261 | send_gdb "run $args\n" | |
262 | # This doesn't work quite right yet. | |
263 | gdb_expect 60 { | |
264 | -re "The program .* has been started already.*y or n. $" { | |
265 | send_gdb "y\n" | |
266 | exp_continue | |
267 | } | |
268 | -re "Starting program: \[^\r\n\]*" {} | |
269 | } | |
270 | } | |
271 | ||
272 | proc gdb_breakpoint { function } { | |
273 | global gdb_prompt | |
274 | global decimal | |
275 | ||
276 | send_gdb "break $function\n" | |
277 | # The first two regexps are what we get with -g, the third is without -g. | |
278 | gdb_expect 30 { | |
279 | -re "Breakpoint \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {} | |
280 | -re "Breakpoint \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {} | |
281 | -re "Breakpoint \[0-9\]* at .*$gdb_prompt $" {} | |
282 | -re "$gdb_prompt $" { fail "setting breakpoint at $function" ; return 0 } | |
283 | timeout { fail "setting breakpoint at $function (timeout)" ; return 0 } | |
284 | } | |
285 | return 1; | |
286 | } | |
287 | ||
288 | # Set breakpoint at function and run gdb until it breaks there. | |
289 | # Since this is the only breakpoint that will be set, if it stops | |
290 | # at a breakpoint, we will assume it is the one we want. We can't | |
291 | # just compare to "function" because it might be a fully qualified, | |
292 | # single quoted C++ function specifier. | |
293 | ||
294 | proc runto { function } { | |
295 | global gdb_prompt | |
296 | global decimal | |
297 | ||
298 | delete_breakpoints | |
299 | ||
300 | if ![gdb_breakpoint $function] { | |
301 | return 0; | |
302 | } | |
303 | ||
304 | gdb_run_cmd | |
305 | ||
306 | # the "at foo.c:36" output we get with -g. | |
307 | # the "in func" output we get without -g. | |
308 | gdb_expect 30 { | |
309 | -re "Break.* at .*:$decimal.*$gdb_prompt $" { | |
310 | return 1 | |
311 | } | |
312 | -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" { | |
313 | return 1 | |
314 | } | |
315 | -re "$gdb_prompt $" { | |
316 | fail "running to $function in runto" | |
317 | return 0 | |
318 | } | |
319 | timeout { | |
320 | fail "running to $function in runto (timeout)" | |
321 | return 0 | |
322 | } | |
323 | } | |
324 | return 1 | |
325 | } | |
326 | ||
327 | # | |
328 | # runto_main -- ask gdb to run until we hit a breakpoint at main. | |
329 | # The case where the target uses stubs has to be handled | |
330 | # specially--if it uses stubs, assuming we hit | |
331 | # breakpoint() and just step out of the function. | |
332 | # | |
333 | proc runto_main { } { | |
334 | global gdb_prompt | |
335 | global decimal | |
336 | ||
337 | if ![target_info exists gdb_stub] { | |
338 | return [runto main] | |
339 | } | |
340 | ||
341 | delete_breakpoints | |
342 | ||
343 | gdb_step_for_stub; | |
344 | ||
345 | return 1 | |
346 | } | |
347 | ||
7a292a7a | 348 | |
4ce44c66 JM |
349 | ### Continue, and expect to hit a breakpoint. |
350 | ### Report a pass or fail, depending on whether it seems to have | |
351 | ### worked. Use NAME as part of the test name; each call to | |
352 | ### continue_to_breakpoint should use a NAME which is unique within | |
353 | ### that test file. | |
354 | proc gdb_continue_to_breakpoint {name} { | |
355 | global gdb_prompt | |
356 | set full_name "continue to breakpoint: $name" | |
357 | ||
358 | send_gdb "continue\n" | |
359 | gdb_expect { | |
360 | -re "Breakpoint .* at .*\r\n$gdb_prompt $" { | |
361 | pass $full_name | |
362 | } | |
363 | -re ".*$gdb_prompt $" { | |
364 | fail $full_name | |
365 | } | |
366 | timeout { | |
367 | fail "$full_name (timeout)" | |
368 | } | |
369 | } | |
370 | } | |
371 | ||
372 | ||
373 | ||
8dbfb380 JB |
374 | # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE |
375 | # Send a command to gdb; test the result. | |
c906108c SS |
376 | # |
377 | # COMMAND is the command to execute, send to GDB with send_gdb. If | |
378 | # this is the null string no command is sent. | |
379 | # PATTERN is the pattern to match for a PASS, and must NOT include | |
380 | # the \r\n sequence immediately before the gdb prompt. | |
381 | # MESSAGE is an optional message to be printed. If this is | |
382 | # omitted, then the pass/fail messages use the command string as the | |
383 | # message. (If this is the empty string, then sometimes we don't | |
384 | # call pass or fail at all; I don't understand this at all.) | |
8dbfb380 JB |
385 | # QUESTION is a question GDB may ask in response to COMMAND, like |
386 | # "are you sure?" | |
387 | # RESPONSE is the response to send if QUESTION appears. | |
c906108c SS |
388 | # |
389 | # Returns: | |
390 | # 1 if the test failed, | |
391 | # 0 if the test passes, | |
392 | # -1 if there was an internal error. | |
393 | # | |
394 | proc gdb_test { args } { | |
395 | global verbose | |
396 | global gdb_prompt | |
397 | global GDB | |
398 | upvar timeout timeout | |
399 | ||
400 | if [llength $args]>2 then { | |
401 | set message [lindex $args 2] | |
402 | } else { | |
403 | set message [lindex $args 0] | |
404 | } | |
405 | set command [lindex $args 0] | |
406 | set pattern [lindex $args 1] | |
407 | ||
408 | if [llength $args]==5 { | |
409 | set question_string [lindex $args 3]; | |
410 | set response_string [lindex $args 4]; | |
411 | } else { | |
412 | set question_string "^FOOBAR$" | |
413 | } | |
414 | ||
415 | if $verbose>2 then { | |
416 | send_user "Sending \"$command\" to gdb\n" | |
417 | send_user "Looking to match \"$pattern\"\n" | |
418 | send_user "Message is \"$message\"\n" | |
419 | } | |
420 | ||
421 | set result -1 | |
422 | set string "${command}\n"; | |
423 | if { $command != "" } { | |
424 | while { "$string" != "" } { | |
425 | set foo [string first "\n" "$string"]; | |
426 | set len [string length "$string"]; | |
427 | if { $foo < [expr $len - 1] } { | |
428 | set str [string range "$string" 0 $foo]; | |
429 | if { [send_gdb "$str"] != "" } { | |
430 | global suppress_flag; | |
431 | ||
432 | if { ! $suppress_flag } { | |
433 | perror "Couldn't send $command to GDB."; | |
434 | } | |
435 | fail "$message"; | |
436 | return $result; | |
437 | } | |
a0b3c4fd JM |
438 | # since we're checking if each line of the multi-line |
439 | # command are 'accepted' by GDB here, | |
440 | # we need to set -notransfer expect option so that | |
441 | # command output is not lost for pattern matching | |
442 | # - guo | |
5f279fa6 DJ |
443 | gdb_expect 2 { |
444 | -notransfer -re "\[\r\n\]" { verbose "partial: match" 3 } | |
445 | timeout { verbose "partial: timeout" 3 } | |
c906108c SS |
446 | } |
447 | set string [string range "$string" [expr $foo + 1] end]; | |
448 | } else { | |
449 | break; | |
450 | } | |
451 | } | |
452 | if { "$string" != "" } { | |
453 | if { [send_gdb "$string"] != "" } { | |
454 | global suppress_flag; | |
455 | ||
456 | if { ! $suppress_flag } { | |
457 | perror "Couldn't send $command to GDB."; | |
458 | } | |
459 | fail "$message"; | |
460 | return $result; | |
461 | } | |
462 | } | |
463 | } | |
464 | ||
9d2e1bab ND |
465 | if [target_info exists gdb,timeout] { |
466 | set tmt [target_info gdb,timeout]; | |
c906108c | 467 | } else { |
c906108c SS |
468 | if [info exists timeout] { |
469 | set tmt $timeout; | |
470 | } else { | |
9d2e1bab ND |
471 | global timeout; |
472 | if [info exists timeout] { | |
473 | set tmt $timeout; | |
474 | } else { | |
475 | set tmt 60; | |
476 | } | |
c906108c SS |
477 | } |
478 | } | |
479 | gdb_expect $tmt { | |
480 | -re "\\*\\*\\* DOSEXIT code.*" { | |
481 | if { $message != "" } { | |
482 | fail "$message"; | |
483 | } | |
484 | gdb_suppress_entire_file "GDB died"; | |
485 | return -1; | |
486 | } | |
9e0b60a8 | 487 | -re "Ending remote debugging.*$gdb_prompt $" { |
c906108c SS |
488 | if ![isnative] then { |
489 | warning "Can`t communicate to remote target." | |
490 | } | |
491 | gdb_exit | |
492 | gdb_start | |
493 | set result -1 | |
494 | } | |
495 | -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" { | |
496 | if ![string match "" $message] then { | |
497 | pass "$message" | |
498 | } | |
499 | set result 0 | |
500 | } | |
501 | -re "(${question_string})$" { | |
502 | send_gdb "$response_string\n"; | |
503 | exp_continue; | |
504 | } | |
9e0b60a8 | 505 | -re "Undefined\[a-z\]* command:.*$gdb_prompt $" { |
c906108c | 506 | perror "Undefined command \"$command\"." |
9e0b60a8 | 507 | fail "$message" |
c906108c SS |
508 | set result 1 |
509 | } | |
510 | -re "Ambiguous command.*$gdb_prompt $" { | |
511 | perror "\"$command\" is not a unique command name." | |
9e0b60a8 | 512 | fail "$message" |
c906108c SS |
513 | set result 1 |
514 | } | |
515 | -re "Program exited with code \[0-9\]+.*$gdb_prompt $" { | |
516 | if ![string match "" $message] then { | |
517 | set errmsg "$message: the program exited" | |
518 | } else { | |
519 | set errmsg "$command: the program exited" | |
520 | } | |
521 | fail "$errmsg" | |
522 | return -1 | |
cb9a9d3e MS |
523 | } |
524 | -re "EXIT code \[0-9\r\n\]+Program exited normally.*$gdb_prompt $" { | |
525 | if ![string match "" $message] then { | |
526 | set errmsg "$message: the program exited" | |
527 | } else { | |
528 | set errmsg "$command: the program exited" | |
529 | } | |
530 | fail "$errmsg" | |
531 | return -1 | |
c906108c SS |
532 | } |
533 | -re "The program is not being run.*$gdb_prompt $" { | |
534 | if ![string match "" $message] then { | |
535 | set errmsg "$message: the program is no longer running" | |
536 | } else { | |
537 | set errmsg "$command: the program is no longer running" | |
538 | } | |
539 | fail "$errmsg" | |
540 | return -1 | |
541 | } | |
542 | -re ".*$gdb_prompt $" { | |
543 | if ![string match "" $message] then { | |
544 | fail "$message" | |
545 | } | |
546 | set result 1 | |
547 | } | |
548 | "<return>" { | |
549 | send_gdb "\n" | |
550 | perror "Window too small." | |
9e0b60a8 | 551 | fail "$message" |
c906108c SS |
552 | } |
553 | -re "\\(y or n\\) " { | |
554 | send_gdb "n\n" | |
555 | perror "Got interactive prompt." | |
9e0b60a8 | 556 | fail "$message" |
c906108c SS |
557 | } |
558 | eof { | |
559 | perror "Process no longer exists" | |
560 | if { $message != "" } { | |
561 | fail "$message" | |
562 | } | |
563 | return -1 | |
564 | } | |
565 | full_buffer { | |
566 | perror "internal buffer is full." | |
9e0b60a8 | 567 | fail "$message" |
c906108c SS |
568 | } |
569 | timeout { | |
570 | if ![string match "" $message] then { | |
571 | fail "$message (timeout)" | |
572 | } | |
573 | set result 1 | |
574 | } | |
575 | } | |
576 | return $result | |
577 | } | |
578 | \f | |
579 | # Test that a command gives an error. For pass or fail, return | |
580 | # a 1 to indicate that more tests can proceed. However a timeout | |
581 | # is a serious error, generates a special fail message, and causes | |
582 | # a 0 to be returned to indicate that more tests are likely to fail | |
583 | # as well. | |
584 | ||
585 | proc test_print_reject { args } { | |
586 | global gdb_prompt | |
587 | global verbose | |
588 | ||
589 | if [llength $args]==2 then { | |
590 | set expectthis [lindex $args 1] | |
591 | } else { | |
592 | set expectthis "should never match this bogus string" | |
593 | } | |
594 | set sendthis [lindex $args 0] | |
595 | if $verbose>2 then { | |
596 | send_user "Sending \"$sendthis\" to gdb\n" | |
597 | send_user "Looking to match \"$expectthis\"\n" | |
598 | } | |
599 | send_gdb "$sendthis\n" | |
600 | #FIXME: Should add timeout as parameter. | |
601 | gdb_expect { | |
602 | -re "A .* in expression.*\\.*$gdb_prompt $" { | |
603 | pass "reject $sendthis" | |
604 | return 1 | |
605 | } | |
606 | -re "Invalid syntax in expression.*$gdb_prompt $" { | |
607 | pass "reject $sendthis" | |
608 | return 1 | |
609 | } | |
610 | -re "Junk after end of expression.*$gdb_prompt $" { | |
611 | pass "reject $sendthis" | |
612 | return 1 | |
613 | } | |
614 | -re "Invalid number.*$gdb_prompt $" { | |
615 | pass "reject $sendthis" | |
616 | return 1 | |
617 | } | |
618 | -re "Invalid character constant.*$gdb_prompt $" { | |
619 | pass "reject $sendthis" | |
620 | return 1 | |
621 | } | |
622 | -re "No symbol table is loaded.*$gdb_prompt $" { | |
623 | pass "reject $sendthis" | |
624 | return 1 | |
625 | } | |
626 | -re "No symbol .* in current context.*$gdb_prompt $" { | |
627 | pass "reject $sendthis" | |
628 | return 1 | |
629 | } | |
630 | -re "$expectthis.*$gdb_prompt $" { | |
631 | pass "reject $sendthis" | |
632 | return 1 | |
633 | } | |
634 | -re ".*$gdb_prompt $" { | |
635 | fail "reject $sendthis" | |
636 | return 1 | |
637 | } | |
638 | default { | |
639 | fail "reject $sendthis (eof or timeout)" | |
640 | return 0 | |
641 | } | |
642 | } | |
643 | } | |
644 | \f | |
645 | # Given an input string, adds backslashes as needed to create a | |
646 | # regexp that will match the string. | |
647 | ||
648 | proc string_to_regexp {str} { | |
649 | set result $str | |
650 | regsub -all {[]*+.|()^$\[]} $str {\\&} result | |
651 | return $result | |
652 | } | |
653 | ||
654 | # Same as gdb_test, but the second parameter is not a regexp, | |
655 | # but a string that must match exactly. | |
656 | ||
657 | proc gdb_test_exact { args } { | |
658 | upvar timeout timeout | |
659 | ||
660 | set command [lindex $args 0] | |
661 | ||
662 | # This applies a special meaning to a null string pattern. Without | |
663 | # this, "$pattern\r\n$gdb_prompt $" will match anything, including error | |
664 | # messages from commands that should have no output except a new | |
665 | # prompt. With this, only results of a null string will match a null | |
666 | # string pattern. | |
667 | ||
668 | set pattern [lindex $args 1] | |
669 | if [string match $pattern ""] { | |
670 | set pattern [string_to_regexp [lindex $args 0]] | |
671 | } else { | |
672 | set pattern [string_to_regexp [lindex $args 1]] | |
673 | } | |
674 | ||
675 | # It is most natural to write the pattern argument with only | |
676 | # embedded \n's, especially if you are trying to avoid Tcl quoting | |
677 | # problems. But gdb_expect really wants to see \r\n in patterns. So | |
678 | # transform the pattern here. First transform \r\n back to \n, in | |
679 | # case some users of gdb_test_exact already do the right thing. | |
680 | regsub -all "\r\n" $pattern "\n" pattern | |
681 | regsub -all "\n" $pattern "\r\n" pattern | |
682 | if [llength $args]==3 then { | |
683 | set message [lindex $args 2] | |
684 | } else { | |
685 | set message $command | |
686 | } | |
687 | ||
688 | return [gdb_test $command $pattern $message] | |
689 | } | |
690 | \f | |
691 | proc gdb_reinitialize_dir { subdir } { | |
692 | global gdb_prompt | |
693 | ||
694 | if [is_remote host] { | |
695 | return ""; | |
696 | } | |
697 | send_gdb "dir\n" | |
698 | gdb_expect 60 { | |
699 | -re "Reinitialize source path to empty.*y or n. " { | |
700 | send_gdb "y\n" | |
701 | gdb_expect 60 { | |
702 | -re "Source directories searched.*$gdb_prompt $" { | |
703 | send_gdb "dir $subdir\n" | |
704 | gdb_expect 60 { | |
705 | -re "Source directories searched.*$gdb_prompt $" { | |
706 | verbose "Dir set to $subdir" | |
707 | } | |
708 | -re "$gdb_prompt $" { | |
709 | perror "Dir \"$subdir\" failed." | |
710 | } | |
711 | } | |
712 | } | |
713 | -re "$gdb_prompt $" { | |
714 | perror "Dir \"$subdir\" failed." | |
715 | } | |
716 | } | |
717 | } | |
718 | -re "$gdb_prompt $" { | |
719 | perror "Dir \"$subdir\" failed." | |
720 | } | |
721 | } | |
722 | } | |
723 | ||
724 | # | |
725 | # gdb_exit -- exit the GDB, killing the target program if necessary | |
726 | # | |
727 | proc default_gdb_exit {} { | |
728 | global GDB | |
729 | global GDBFLAGS | |
730 | global verbose | |
731 | global gdb_spawn_id; | |
732 | ||
733 | gdb_stop_suppressing_tests; | |
734 | ||
735 | if ![info exists gdb_spawn_id] { | |
736 | return; | |
737 | } | |
738 | ||
739 | verbose "Quitting $GDB $GDBFLAGS" | |
740 | ||
741 | if { [is_remote host] && [board_info host exists fileid] } { | |
742 | send_gdb "quit\n"; | |
743 | gdb_expect 10 { | |
744 | -re "y or n" { | |
745 | send_gdb "y\n"; | |
746 | exp_continue; | |
747 | } | |
748 | -re "DOSEXIT code" { } | |
749 | default { } | |
750 | } | |
751 | } | |
752 | ||
753 | if ![is_remote host] { | |
754 | remote_close host; | |
755 | } | |
756 | unset gdb_spawn_id | |
757 | } | |
758 | ||
759 | # | |
760 | # load a file into the debugger. | |
761 | # return a -1 if anything goes wrong. | |
762 | # | |
763 | proc gdb_file_cmd { arg } { | |
764 | global verbose | |
765 | global loadpath | |
766 | global loadfile | |
767 | global GDB | |
768 | global gdb_prompt | |
769 | upvar timeout timeout | |
770 | ||
771 | if [is_remote host] { | |
772 | set arg [remote_download host $arg]; | |
773 | if { $arg == "" } { | |
774 | error "download failed" | |
775 | return -1; | |
776 | } | |
777 | } | |
778 | ||
779 | send_gdb "file $arg\n" | |
780 | gdb_expect 120 { | |
781 | -re "Reading symbols from.*done.*$gdb_prompt $" { | |
782 | verbose "\t\tLoaded $arg into the $GDB" | |
783 | return 0 | |
784 | } | |
785 | -re "has no symbol-table.*$gdb_prompt $" { | |
786 | perror "$arg wasn't compiled with \"-g\"" | |
787 | return -1 | |
788 | } | |
789 | -re "A program is being debugged already.*Kill it.*y or n. $" { | |
790 | send_gdb "y\n" | |
791 | verbose "\t\tKilling previous program being debugged" | |
792 | exp_continue | |
793 | } | |
794 | -re "Load new symbol table from \".*\".*y or n. $" { | |
795 | send_gdb "y\n" | |
796 | gdb_expect 120 { | |
797 | -re "Reading symbols from.*done.*$gdb_prompt $" { | |
798 | verbose "\t\tLoaded $arg with new symbol table into $GDB" | |
799 | return 0 | |
800 | } | |
801 | timeout { | |
802 | perror "(timeout) Couldn't load $arg, other program already loaded." | |
803 | return -1 | |
804 | } | |
805 | } | |
806 | } | |
807 | -re "No such file or directory.*$gdb_prompt $" { | |
808 | perror "($arg) No such file or directory\n" | |
809 | return -1 | |
810 | } | |
811 | -re "$gdb_prompt $" { | |
812 | perror "couldn't load $arg into $GDB." | |
813 | return -1 | |
814 | } | |
815 | timeout { | |
816 | perror "couldn't load $arg into $GDB (timed out)." | |
817 | return -1 | |
818 | } | |
819 | eof { | |
820 | # This is an attempt to detect a core dump, but seems not to | |
821 | # work. Perhaps we need to match .* followed by eof, in which | |
822 | # gdb_expect does not seem to have a way to do that. | |
823 | perror "couldn't load $arg into $GDB (end of file)." | |
824 | return -1 | |
825 | } | |
826 | } | |
827 | } | |
828 | ||
829 | # | |
830 | # start gdb -- start gdb running, default procedure | |
831 | # | |
832 | # When running over NFS, particularly if running many simultaneous | |
833 | # tests on different hosts all using the same server, things can | |
834 | # get really slow. Give gdb at least 3 minutes to start up. | |
835 | # | |
836 | proc default_gdb_start { } { | |
837 | global verbose | |
838 | global GDB | |
839 | global GDBFLAGS | |
840 | global gdb_prompt | |
841 | global timeout | |
842 | global gdb_spawn_id; | |
843 | ||
844 | gdb_stop_suppressing_tests; | |
845 | ||
846 | verbose "Spawning $GDB -nw $GDBFLAGS" | |
847 | ||
848 | if [info exists gdb_spawn_id] { | |
849 | return 0; | |
850 | } | |
851 | ||
852 | if ![is_remote host] { | |
853 | if { [which $GDB] == 0 } then { | |
854 | perror "$GDB does not exist." | |
855 | exit 1 | |
856 | } | |
857 | } | |
858 | set res [remote_spawn host "$GDB -nw $GDBFLAGS [host_info gdb_opts]"]; | |
859 | if { $res < 0 || $res == "" } { | |
860 | perror "Spawning $GDB failed." | |
861 | return 1; | |
862 | } | |
863 | gdb_expect 360 { | |
864 | -re "\[\r\n\]$gdb_prompt $" { | |
865 | verbose "GDB initialized." | |
866 | } | |
867 | -re "$gdb_prompt $" { | |
868 | perror "GDB never initialized." | |
869 | return -1 | |
870 | } | |
871 | timeout { | |
872 | perror "(timeout) GDB never initialized after 10 seconds." | |
873 | remote_close host; | |
874 | return -1 | |
875 | } | |
876 | } | |
877 | set gdb_spawn_id -1; | |
878 | # force the height to "unlimited", so no pagers get used | |
879 | ||
880 | send_gdb "set height 0\n" | |
881 | gdb_expect 10 { | |
882 | -re "$gdb_prompt $" { | |
883 | verbose "Setting height to 0." 2 | |
884 | } | |
885 | timeout { | |
886 | warning "Couldn't set the height to 0" | |
887 | } | |
888 | } | |
889 | # force the width to "unlimited", so no wraparound occurs | |
890 | send_gdb "set width 0\n" | |
891 | gdb_expect 10 { | |
892 | -re "$gdb_prompt $" { | |
893 | verbose "Setting width to 0." 2 | |
894 | } | |
895 | timeout { | |
896 | warning "Couldn't set the width to 0." | |
897 | } | |
898 | } | |
899 | return 0; | |
900 | } | |
901 | ||
d4f3574e SS |
902 | # Return a 1 for configurations for which we don't even want to try to |
903 | # test C++. | |
904 | ||
905 | proc skip_cplus_tests {} { | |
906 | if { [istarget "d10v-*-*"] } { | |
907 | return 1 | |
908 | } | |
909 | if { [istarget "h8300-*-*"] } { | |
910 | return 1 | |
911 | } | |
912 | return 0 | |
913 | } | |
914 | ||
c906108c SS |
915 | # * For crosses, the CHILL runtime doesn't build because it can't find |
916 | # setjmp.h, stdio.h, etc. | |
917 | # * For AIX (as of 16 Mar 95), (a) there is no language code for | |
918 | # CHILL in output_epilog in gcc/config/rs6000/rs6000.c, (b) collect2 | |
919 | # does not get along with AIX's too-clever linker. | |
920 | # * On Irix5, there is a bug whereby set of bool, etc., don't get | |
921 | # TYPE_LOW_BOUND for the bool right because force_to_range_type doesn't | |
922 | # work with stub types. | |
923 | # Lots of things seem to fail on the PA, and since it's not a supported | |
924 | # chill target at the moment, don't run the chill tests. | |
925 | ||
926 | proc skip_chill_tests {} { | |
927 | if ![info exists do_chill_tests] { | |
928 | return 1; | |
929 | } | |
930 | eval set skip_chill [expr ![isnative] || [istarget "*-*-aix*"] || [istarget "*-*-irix5*"] || [istarget "*-*-irix6*"] || [istarget "alpha-*-osf*"] || [istarget "hppa*-*-*"]] | |
931 | verbose "Skip chill tests is $skip_chill" | |
932 | return $skip_chill | |
933 | } | |
934 | ||
7a292a7a SS |
935 | # Skip all the tests in the file if you are not on an hppa running |
936 | # hpux target. | |
937 | ||
938 | proc skip_hp_tests {} { | |
939 | eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ] | |
c906108c SS |
940 | verbose "Skip hp tests is $skip_hp" |
941 | return $skip_hp | |
942 | } | |
943 | ||
944 | proc get_compiler_info {binfile args} { | |
945 | # Create and source the file that provides information about the compiler | |
946 | # used to compile the test case. | |
947 | # Compiler_type can be null or c++. If null we assume c. | |
948 | global srcdir | |
949 | global subdir | |
950 | # These two come from compiler.c. | |
951 | global signed_keyword_not_used | |
952 | global gcc_compiled | |
953 | ||
954 | if {![istarget "hppa*-*-hpux*"]} { | |
955 | if { [llength $args] > 0 } { | |
956 | if {$args == "c++"} { | |
4ce44c66 | 957 | if { [gdb_compile "${srcdir}/lib/compiler.cc" "${binfile}.ci" preprocess {}] != "" } { |
c906108c SS |
958 | perror "Couldn't make ${binfile}.ci file" |
959 | return 1; | |
960 | } | |
961 | } | |
962 | } else { | |
4ce44c66 | 963 | if { [gdb_compile "${srcdir}/lib/compiler.c" "${binfile}.ci" preprocess {}] != "" } { |
c906108c SS |
964 | perror "Couldn't make ${binfile}.ci file" |
965 | return 1; | |
966 | } | |
967 | } | |
968 | } else { | |
969 | if { [llength $args] > 0 } { | |
970 | if {$args == "c++"} { | |
971 | if { [eval gdb_preprocess \ | |
4ce44c66 | 972 | [list "${srcdir}/lib/compiler.cc" "${binfile}.ci"] \ |
c906108c SS |
973 | $args] != "" } { |
974 | perror "Couldn't make ${binfile}.ci file" | |
975 | return 1; | |
976 | } | |
977 | } | |
a0b3c4fd | 978 | } elseif { $args != "f77" } { |
c906108c | 979 | if { [eval gdb_preprocess \ |
4ce44c66 | 980 | [list "${srcdir}/lib/compiler.c" "${binfile}.ci"] \ |
c906108c SS |
981 | $args] != "" } { |
982 | perror "Couldn't make ${binfile}.ci file" | |
983 | return 1; | |
984 | } | |
985 | } | |
986 | } | |
987 | ||
085dd6e6 JM |
988 | uplevel \#0 { set gcc_compiled 0 } |
989 | ||
990 | if { [llength $args] == 0 || $args != "f77" } { | |
991 | source ${binfile}.ci | |
992 | } | |
993 | ||
994 | # Most compilers will evaluate comparisons and other boolean | |
995 | # operations to 0 or 1. | |
996 | uplevel \#0 { set true 1 } | |
997 | uplevel \#0 { set false 0 } | |
998 | ||
999 | uplevel \#0 { set hp_cc_compiler 0 } | |
1000 | uplevel \#0 { set hp_aCC_compiler 0 } | |
1001 | uplevel \#0 { set hp_f77_compiler 0 } | |
1002 | uplevel \#0 { set hp_f90_compiler 0 } | |
1003 | if { !$gcc_compiled && [istarget "hppa*-*-hpux*"] } { | |
1004 | # Check for the HP compilers | |
1005 | set compiler [lindex [split [get_compiler $args] " "] 0] | |
1006 | catch "exec what $compiler" output | |
1007 | if [regexp ".*HP aC\\+\\+.*" $output] { | |
1008 | uplevel \#0 { set hp_aCC_compiler 1 } | |
1009 | # Use of aCC results in boolean results being displayed as | |
1010 | # "true" or "false" | |
1011 | uplevel \#0 { set true true } | |
1012 | uplevel \#0 { set false false } | |
1013 | } elseif [regexp ".*HP C Compiler.*" $output] { | |
1014 | uplevel \#0 { set hp_cc_compiler 1 } | |
1015 | } elseif [regexp ".*HP-UX f77.*" $output] { | |
1016 | uplevel \#0 { set hp_f77_compiler 1 } | |
1017 | } elseif [regexp ".*HP-UX f90.*" $output] { | |
1018 | uplevel \#0 { set hp_f90_compiler 1 } | |
1019 | } | |
1020 | } | |
1021 | ||
c906108c SS |
1022 | return 0; |
1023 | } | |
1024 | ||
a0b3c4fd JM |
1025 | proc get_compiler {args} { |
1026 | global CC CC_FOR_TARGET CXX CXX_FOR_TARGET F77_FOR_TARGET | |
c906108c | 1027 | |
a0b3c4fd JM |
1028 | if { [llength $args] == 0 |
1029 | || ([llength $args] == 1 && [lindex $args 0] == "") } { | |
c906108c SS |
1030 | set which_compiler "c" |
1031 | } else { | |
1032 | if { $args =="c++" } { | |
1033 | set which_compiler "c++" | |
a0b3c4fd JM |
1034 | } elseif { $args =="f77" } { |
1035 | set which_compiler "f77" | |
c906108c SS |
1036 | } else { |
1037 | perror "Unknown compiler type supplied to gdb_preprocess" | |
a0b3c4fd | 1038 | return "" |
c906108c SS |
1039 | } |
1040 | } | |
1041 | ||
1042 | if [info exists CC_FOR_TARGET] { | |
a0b3c4fd JM |
1043 | if {$which_compiler == "c"} { |
1044 | set compiler $CC_FOR_TARGET | |
c906108c SS |
1045 | } |
1046 | } | |
1047 | ||
1048 | if [info exists CXX_FOR_TARGET] { | |
a0b3c4fd JM |
1049 | if {$which_compiler == "c++"} { |
1050 | set compiler $CXX_FOR_TARGET | |
1051 | } | |
1052 | } | |
1053 | ||
1054 | if [info exists F77_FOR_TARGET] { | |
1055 | if {$which_compiler == "f77"} { | |
1056 | set compiler $F77_FOR_TARGET | |
c906108c SS |
1057 | } |
1058 | } | |
1059 | ||
1060 | if { ![info exists compiler] } { | |
1061 | if { $which_compiler == "c" } { | |
1062 | if {[info exists CC]} { | |
a0b3c4fd | 1063 | set compiler $CC |
c906108c SS |
1064 | } |
1065 | } | |
1066 | if { $which_compiler == "c++" } { | |
1067 | if {[info exists CXX]} { | |
a0b3c4fd | 1068 | set compiler $CXX |
c906108c SS |
1069 | } |
1070 | } | |
1071 | if {![info exists compiler]} { | |
1072 | set compiler [board_info [target_info name] compiler]; | |
1073 | if { $compiler == "" } { | |
a0b3c4fd JM |
1074 | perror "get_compiler: No compiler found" |
1075 | return "" | |
c906108c SS |
1076 | } |
1077 | } | |
1078 | } | |
1079 | ||
a0b3c4fd JM |
1080 | return $compiler |
1081 | } | |
1082 | ||
1083 | proc gdb_preprocess {source dest args} { | |
1084 | set compiler [get_compiler "$args"] | |
1085 | if { $compiler == "" } { | |
1086 | return 1 | |
1087 | } | |
1088 | ||
c906108c SS |
1089 | set cmdline "$compiler -E $source > $dest" |
1090 | ||
1091 | verbose "Invoking $compiler -E $source > $dest" | |
1092 | verbose -log "Executing on local host: $cmdline" 2 | |
1093 | set status [catch "exec ${cmdline}" exec_output] | |
1094 | ||
1095 | set result [prune_warnings $exec_output] | |
1096 | regsub "\[\r\n\]*$" "$result" "" result; | |
1097 | regsub "^\[\r\n\]*" "$result" "" result; | |
1098 | if { $result != "" } { | |
1099 | clone_output "gdb compile failed, $result" | |
1100 | } | |
1101 | return $result; | |
1102 | } | |
1103 | ||
f1c47eb2 MS |
1104 | set gdb_wrapper_initialized 0 |
1105 | ||
1106 | proc gdb_wrapper_init { args } { | |
1107 | global gdb_wrapper_initialized; | |
1108 | global gdb_wrapper_file; | |
1109 | global gdb_wrapper_flags; | |
1110 | ||
1111 | if { $gdb_wrapper_initialized == 1 } { return; } | |
1112 | ||
1113 | if {[target_info exists needs_status_wrapper] && \ | |
1114 | [target_info needs_status_wrapper] != "0" && \ | |
1115 | ![info exists gdb_wrapper_file]} { | |
1116 | set result [build_wrapper "testglue.o"]; | |
1117 | if { $result != "" } { | |
1118 | set gdb_wrapper_file [lindex $result 0]; | |
1119 | set gdb_wrapper_flags [lindex $result 1]; | |
1120 | } else { | |
1121 | warning "Status wrapper failed to build." | |
1122 | } | |
1123 | } | |
1124 | set gdb_wrapper_initialized 1 | |
1125 | } | |
1126 | ||
c906108c SS |
1127 | proc gdb_compile {source dest type options} { |
1128 | global GDB_TESTCASE_OPTIONS; | |
f1c47eb2 MS |
1129 | global gdb_wrapper_file; |
1130 | global gdb_wrapper_flags; | |
1131 | global gdb_wrapper_initialized; | |
c906108c SS |
1132 | |
1133 | if [target_info exists gdb_stub] { | |
1134 | set options2 { "additional_flags=-Dusestubs" } | |
1135 | lappend options "libs=[target_info gdb_stub]"; | |
1136 | set options [concat $options2 $options] | |
1137 | } | |
1138 | if [target_info exists is_vxworks] { | |
1139 | set options2 { "additional_flags=-Dvxworks" } | |
1140 | lappend options "libs=[target_info gdb_stub]"; | |
1141 | set options [concat $options2 $options] | |
1142 | } | |
1143 | if [info exists GDB_TESTCASE_OPTIONS] { | |
1144 | lappend options "additional_flags=$GDB_TESTCASE_OPTIONS"; | |
1145 | } | |
1146 | verbose "options are $options" | |
1147 | verbose "source is $source $dest $type $options" | |
1148 | ||
f1c47eb2 MS |
1149 | if { $gdb_wrapper_initialized == 0 } { gdb_wrapper_init } |
1150 | ||
1151 | if {[target_info exists needs_status_wrapper] && \ | |
1152 | [target_info needs_status_wrapper] != "0" && \ | |
1153 | [info exists gdb_wrapper_file]} { | |
1154 | lappend options "libs=${gdb_wrapper_file}" | |
1155 | lappend options "ldflags=${gdb_wrapper_flags}" | |
1156 | } | |
1157 | ||
c906108c SS |
1158 | set result [target_compile $source $dest $type $options]; |
1159 | regsub "\[\r\n\]*$" "$result" "" result; | |
1160 | regsub "^\[\r\n\]*" "$result" "" result; | |
1161 | if { $result != "" } { | |
1162 | clone_output "gdb compile failed, $result" | |
1163 | } | |
1164 | return $result; | |
1165 | } | |
1166 | ||
1167 | proc send_gdb { string } { | |
1168 | global suppress_flag; | |
1169 | if { $suppress_flag } { | |
1170 | return "suppressed"; | |
1171 | } | |
1172 | return [remote_send host "$string"]; | |
1173 | } | |
1174 | ||
1175 | # | |
1176 | # | |
1177 | ||
1178 | proc gdb_expect { args } { | |
1179 | if { [llength $args] == 2 && [lindex $args 0] != "-re" } { | |
1180 | set gtimeout [lindex $args 0]; | |
1181 | set expcode [list [lindex $args 1]]; | |
1182 | } else { | |
1183 | upvar timeout timeout; | |
1184 | ||
1185 | set expcode $args; | |
1186 | if [target_info exists gdb,timeout] { | |
1187 | if [info exists timeout] { | |
1188 | if { $timeout < [target_info gdb,timeout] } { | |
1189 | set gtimeout [target_info gdb,timeout]; | |
1190 | } else { | |
1191 | set gtimeout $timeout; | |
1192 | } | |
1193 | } else { | |
1194 | set gtimeout [target_info gdb,timeout]; | |
1195 | } | |
1196 | } | |
1197 | ||
1198 | if ![info exists gtimeout] { | |
1199 | global timeout; | |
1200 | if [info exists timeout] { | |
1201 | set gtimeout $timeout; | |
1202 | } else { | |
1203 | # Eeeeew. | |
1204 | set gtimeout 60; | |
1205 | } | |
1206 | } | |
1207 | } | |
1208 | global suppress_flag; | |
1209 | global remote_suppress_flag; | |
1210 | if [info exists remote_suppress_flag] { | |
1211 | set old_val $remote_suppress_flag; | |
1212 | } | |
1213 | if [info exists suppress_flag] { | |
1214 | if { $suppress_flag } { | |
1215 | set remote_suppress_flag 1; | |
1216 | } | |
1217 | } | |
a0b3c4fd | 1218 | set code [catch \ |
5f279fa6 | 1219 | {uplevel remote_expect host $gtimeout $expcode} string]; |
c906108c SS |
1220 | if [info exists old_val] { |
1221 | set remote_suppress_flag $old_val; | |
1222 | } else { | |
1223 | if [info exists remote_suppress_flag] { | |
1224 | unset remote_suppress_flag; | |
1225 | } | |
1226 | } | |
1227 | ||
1228 | if {$code == 1} { | |
1229 | global errorInfo errorCode; | |
1230 | ||
1231 | return -code error -errorinfo $errorInfo -errorcode $errorCode $string | |
1232 | } elseif {$code == 2} { | |
1233 | return -code return $string | |
1234 | } elseif {$code == 3} { | |
1235 | return | |
1236 | } elseif {$code > 4} { | |
1237 | return -code $code $string | |
1238 | } | |
1239 | } | |
1240 | ||
c2d11a7d | 1241 | # gdb_expect_list MESSAGE SENTINEL LIST -- expect a sequence of outputs |
085dd6e6 JM |
1242 | # |
1243 | # Check for long sequence of output by parts. | |
11cf8741 | 1244 | # MESSAGE: is the test message to be printed with the test success/fail. |
085dd6e6 JM |
1245 | # SENTINEL: Is the terminal pattern indicating that output has finished. |
1246 | # LIST: is the sequence of outputs to match. | |
1247 | # If the sentinel is recognized early, it is considered an error. | |
1248 | # | |
11cf8741 JM |
1249 | # Returns: |
1250 | # 1 if the test failed, | |
1251 | # 0 if the test passes, | |
1252 | # -1 if there was an internal error. | |
1253 | # | |
c2d11a7d | 1254 | proc gdb_expect_list {test sentinel list} { |
085dd6e6 | 1255 | global gdb_prompt |
11cf8741 | 1256 | global suppress_flag |
085dd6e6 | 1257 | set index 0 |
43ff13b4 | 1258 | set ok 1 |
11cf8741 JM |
1259 | if { $suppress_flag } { |
1260 | set ok 0 | |
1261 | } | |
43ff13b4 | 1262 | while { ${index} < [llength ${list}] } { |
085dd6e6 JM |
1263 | set pattern [lindex ${list} ${index}] |
1264 | set index [expr ${index} + 1] | |
1265 | if { ${index} == [llength ${list}] } { | |
43ff13b4 JM |
1266 | if { ${ok} } { |
1267 | gdb_expect { | |
c2d11a7d JM |
1268 | -re "${pattern}${sentinel}" { |
1269 | pass "${test}, pattern ${index} + sentinel" | |
1270 | } | |
1271 | -re "${sentinel}" { | |
1272 | fail "${test}, pattern ${index} + sentinel" | |
1273 | set ok 0 | |
43ff13b4 JM |
1274 | } |
1275 | timeout { | |
c2d11a7d | 1276 | fail "${test}, pattern ${index} + sentinel (timeout)" |
43ff13b4 JM |
1277 | set ok 0 |
1278 | } | |
085dd6e6 | 1279 | } |
43ff13b4 | 1280 | } else { |
c2d11a7d | 1281 | unresolved "${test}, pattern ${index} + sentinel" |
085dd6e6 JM |
1282 | } |
1283 | } else { | |
43ff13b4 JM |
1284 | if { ${ok} } { |
1285 | gdb_expect { | |
1286 | -re "${pattern}" { | |
1287 | pass "${test}, pattern ${index}" | |
1288 | } | |
c2d11a7d | 1289 | -re "${sentinel}" { |
43ff13b4 JM |
1290 | fail "${test}, pattern ${index}" |
1291 | set ok 0 | |
1292 | } | |
1293 | timeout { | |
1294 | fail "${test}, pattern ${index} (timeout)" | |
1295 | set ok 0 | |
1296 | } | |
085dd6e6 | 1297 | } |
43ff13b4 | 1298 | } else { |
c2d11a7d | 1299 | unresolved "${test}, pattern ${index}" |
085dd6e6 JM |
1300 | } |
1301 | } | |
1302 | } | |
11cf8741 JM |
1303 | if { ${ok} } { |
1304 | return 0 | |
1305 | } else { | |
1306 | return 1 | |
1307 | } | |
085dd6e6 JM |
1308 | } |
1309 | ||
1310 | # | |
1311 | # | |
c906108c SS |
1312 | proc gdb_suppress_entire_file { reason } { |
1313 | global suppress_flag; | |
1314 | ||
1315 | warning "$reason\n"; | |
1316 | set suppress_flag -1; | |
1317 | } | |
1318 | ||
1319 | # | |
1320 | # Set suppress_flag, which will cause all subsequent calls to send_gdb and | |
1321 | # gdb_expect to fail immediately (until the next call to | |
1322 | # gdb_stop_suppressing_tests). | |
1323 | # | |
1324 | proc gdb_suppress_tests { args } { | |
1325 | global suppress_flag; | |
1326 | ||
1327 | return; # fnf - disable pending review of results where | |
1328 | # testsuite ran better without this | |
1329 | incr suppress_flag; | |
1330 | ||
1331 | if { $suppress_flag == 1 } { | |
1332 | if { [llength $args] > 0 } { | |
1333 | warning "[lindex $args 0]\n"; | |
1334 | } else { | |
1335 | warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n"; | |
1336 | } | |
1337 | } | |
1338 | } | |
1339 | ||
1340 | # | |
1341 | # Clear suppress_flag. | |
1342 | # | |
1343 | proc gdb_stop_suppressing_tests { } { | |
1344 | global suppress_flag; | |
1345 | ||
1346 | if [info exists suppress_flag] { | |
1347 | if { $suppress_flag > 0 } { | |
1348 | set suppress_flag 0; | |
1349 | clone_output "Tests restarted.\n"; | |
1350 | } | |
1351 | } else { | |
1352 | set suppress_flag 0; | |
1353 | } | |
1354 | } | |
1355 | ||
1356 | proc gdb_clear_suppressed { } { | |
1357 | global suppress_flag; | |
1358 | ||
1359 | set suppress_flag 0; | |
1360 | } | |
1361 | ||
1362 | proc gdb_start { } { | |
1363 | default_gdb_start | |
1364 | } | |
1365 | ||
1366 | proc gdb_exit { } { | |
1367 | catch default_gdb_exit | |
1368 | } | |
1369 | ||
1370 | # | |
1371 | # gdb_load -- load a file into the debugger. | |
1372 | # return a -1 if anything goes wrong. | |
1373 | # | |
1374 | proc gdb_load { arg } { | |
1375 | return [gdb_file_cmd $arg] | |
1376 | } | |
1377 | ||
1378 | proc gdb_continue { function } { | |
1379 | global decimal | |
1380 | ||
1381 | return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"]; | |
1382 | } | |
1383 | ||
1384 | proc default_gdb_init { args } { | |
1385 | gdb_clear_suppressed; | |
1386 | ||
1387 | # Uh, this is lame. Really, really, really lame. But there's this *one* | |
1388 | # testcase that will fail in random places if we don't increase this. | |
1389 | match_max -d 20000 | |
1390 | ||
1391 | # We want to add the name of the TCL testcase to the PASS/FAIL messages. | |
1392 | if { [llength $args] > 0 } { | |
1393 | global pf_prefix | |
1394 | ||
1395 | set file [lindex $args 0]; | |
1396 | ||
1397 | set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:"; | |
1398 | } | |
1399 | global gdb_prompt; | |
1400 | if [target_info exists gdb_prompt] { | |
1401 | set gdb_prompt [target_info gdb_prompt]; | |
1402 | } else { | |
1403 | set gdb_prompt "\\(gdb\\)" | |
1404 | } | |
1405 | } | |
1406 | ||
1407 | proc gdb_init { args } { | |
1408 | return [eval default_gdb_init $args]; | |
1409 | } | |
1410 | ||
1411 | proc gdb_finish { } { | |
1412 | gdb_exit; | |
1413 | } | |
1414 | ||
1415 | global debug_format | |
7a292a7a | 1416 | set debug_format "unknown" |
c906108c SS |
1417 | |
1418 | # Run the gdb command "info source" and extract the debugging format | |
1419 | # information from the output and save it in debug_format. | |
1420 | ||
1421 | proc get_debug_format { } { | |
1422 | global gdb_prompt | |
1423 | global verbose | |
1424 | global expect_out | |
1425 | global debug_format | |
1426 | ||
1427 | set debug_format "unknown" | |
1428 | send_gdb "info source\n" | |
1429 | gdb_expect 10 { | |
1430 | -re "Compiled with (.*) debugging format.\r\n$gdb_prompt $" { | |
1431 | set debug_format $expect_out(1,string) | |
1432 | verbose "debug format is $debug_format" | |
1433 | return 1; | |
1434 | } | |
1435 | -re "No current source file.\r\n$gdb_prompt $" { | |
1436 | perror "get_debug_format used when no current source file" | |
1437 | return 0; | |
1438 | } | |
1439 | -re "$gdb_prompt $" { | |
1440 | warning "couldn't check debug format (no valid response)." | |
1441 | return 1; | |
1442 | } | |
1443 | timeout { | |
1444 | warning "couldn't check debug format (timed out)." | |
1445 | return 1; | |
1446 | } | |
1447 | } | |
1448 | } | |
1449 | ||
838ae6c4 JB |
1450 | # Return true if FORMAT matches the debug format the current test was |
1451 | # compiled with. FORMAT is a shell-style globbing pattern; it can use | |
1452 | # `*', `[...]', and so on. | |
1453 | # | |
1454 | # This function depends on variables set by `get_debug_format', above. | |
1455 | ||
1456 | proc test_debug_format {format} { | |
1457 | global debug_format | |
1458 | ||
1459 | return [expr [string match $format $debug_format] != 0] | |
1460 | } | |
1461 | ||
c906108c SS |
1462 | # Like setup_xfail, but takes the name of a debug format (DWARF 1, |
1463 | # COFF, stabs, etc). If that format matches the format that the | |
1464 | # current test was compiled with, then the next test is expected to | |
1465 | # fail for any target. Returns 1 if the next test or set of tests is | |
1466 | # expected to fail, 0 otherwise (or if it is unknown). Must have | |
1467 | # previously called get_debug_format. | |
b55a4771 | 1468 | proc setup_xfail_format { format } { |
838ae6c4 | 1469 | set ret [test_debug_format $format]; |
b55a4771 | 1470 | |
838ae6c4 | 1471 | if {$ret} then { |
b55a4771 MS |
1472 | setup_xfail "*-*-*" |
1473 | } | |
1474 | return $ret; | |
1475 | } | |
c906108c SS |
1476 | |
1477 | proc gdb_step_for_stub { } { | |
1478 | global gdb_prompt; | |
1479 | ||
1480 | if ![target_info exists gdb,use_breakpoint_for_stub] { | |
1481 | if [target_info exists gdb_stub_step_command] { | |
1482 | set command [target_info gdb_stub_step_command]; | |
1483 | } else { | |
1484 | set command "step"; | |
1485 | } | |
1486 | send_gdb "${command}\n"; | |
1487 | set tries 0; | |
1488 | gdb_expect 60 { | |
1489 | -re "(main.* at |.*in .*start).*$gdb_prompt" { | |
1490 | return; | |
1491 | } | |
1492 | -re ".*$gdb_prompt" { | |
1493 | incr tries; | |
1494 | if { $tries == 5 } { | |
1495 | fail "stepping out of breakpoint function"; | |
1496 | return; | |
1497 | } | |
1498 | send_gdb "${command}\n"; | |
1499 | exp_continue; | |
1500 | } | |
1501 | default { | |
1502 | fail "stepping out of breakpoint function"; | |
1503 | return; | |
1504 | } | |
1505 | } | |
1506 | } | |
1507 | send_gdb "where\n"; | |
1508 | gdb_expect { | |
1509 | -re "main\[^\r\n\]*at \(\[^:]+\):\(\[0-9\]+\)" { | |
1510 | set file $expect_out(1,string); | |
1511 | set linenum [expr $expect_out(2,string) + 1]; | |
1512 | set breakplace "${file}:${linenum}"; | |
1513 | } | |
1514 | default {} | |
1515 | } | |
1516 | send_gdb "break ${breakplace}\n"; | |
1517 | gdb_expect 60 { | |
1518 | -re "Breakpoint (\[0-9\]+) at.*$gdb_prompt" { | |
1519 | set breakpoint $expect_out(1,string); | |
1520 | } | |
1521 | -re "Breakpoint (\[0-9\]+): file.*$gdb_prompt" { | |
1522 | set breakpoint $expect_out(1,string); | |
1523 | } | |
1524 | default {} | |
1525 | } | |
1526 | send_gdb "continue\n"; | |
1527 | gdb_expect 60 { | |
1528 | -re "Breakpoint ${breakpoint},.*$gdb_prompt" { | |
1529 | gdb_test "delete $breakpoint" ".*" ""; | |
1530 | return; | |
1531 | } | |
1532 | default {} | |
1533 | } | |
1534 | } | |
1535 | ||
1536 | ### gdb_get_line_number TEXT [FILE] | |
1537 | ### | |
1538 | ### Search the source file FILE, and return the line number of a line | |
1539 | ### containing TEXT. Use this function instead of hard-coding line | |
1540 | ### numbers into your test script. | |
1541 | ### | |
1542 | ### Specifically, this function uses GDB's "search" command to search | |
1543 | ### FILE for the first line containing TEXT, and returns its line | |
1544 | ### number. Thus, FILE must be a source file, compiled into the | |
1545 | ### executable you are running. If omitted, FILE defaults to the | |
1546 | ### value of the global variable `srcfile'; most test scripts set | |
1547 | ### `srcfile' appropriately at the top anyway. | |
1548 | ### | |
1549 | ### Use this function to keep your test scripts independent of the | |
1550 | ### exact line numbering of the source file. Don't write: | |
1551 | ### | |
1552 | ### send_gdb "break 20" | |
1553 | ### | |
1554 | ### This means that if anyone ever edits your test's source file, | |
1555 | ### your test could break. Instead, put a comment like this on the | |
1556 | ### source file line you want to break at: | |
1557 | ### | |
1558 | ### /* breakpoint spot: frotz.exp: test name */ | |
1559 | ### | |
1560 | ### and then write, in your test script (which we assume is named | |
1561 | ### frotz.exp): | |
1562 | ### | |
1563 | ### send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n" | |
1564 | ### | |
1565 | ### (Yes, Tcl knows how to handle the nested quotes and brackets. | |
1566 | ### Try this: | |
1567 | ### $ tclsh | |
1568 | ### % puts "foo [lindex "bar baz" 1]" | |
1569 | ### foo baz | |
1570 | ### % | |
1571 | ### Tcl is quite clever, for a little stringy language.) | |
1572 | ||
1573 | proc gdb_get_line_number {text {file /omitted/}} { | |
1574 | global gdb_prompt; | |
1575 | global srcfile; | |
1576 | ||
1577 | if {! [string compare $file /omitted/]} { | |
1578 | set file $srcfile | |
1579 | } | |
1580 | ||
1581 | set result -1; | |
1582 | gdb_test "list ${file}:1,1" ".*" "" | |
1583 | send_gdb "search ${text}\n" | |
1584 | gdb_expect { | |
1585 | -re "\[\r\n\]+(\[0-9\]+)\[ \t\].*${text}.*$gdb_prompt $" { | |
1586 | set result $expect_out(1,string) | |
1587 | } | |
1588 | -re ".*$gdb_prompt $" { | |
1589 | fail "find line number containing \"${text}\"" | |
1590 | } | |
1591 | timeout { | |
1592 | fail "find line number containing \"${text}\" (timeout)" | |
1593 | } | |
1594 | } | |
1595 | return $result; | |
1596 | } | |
1597 | ||
7a292a7a SS |
1598 | # gdb_continue_to_end: |
1599 | # The case where the target uses stubs has to be handled specially. If a | |
1600 | # stub is used, we set a breakpoint at exit because we cannot rely on | |
1601 | # exit() behavior of a remote target. | |
1602 | # | |
1603 | # mssg is the error message that gets printed. | |
1604 | ||
1605 | proc gdb_continue_to_end {mssg} { | |
1606 | if [target_info exists use_gdb_stub] { | |
1607 | if {![gdb_breakpoint "exit"]} { | |
1608 | return 0 | |
1609 | } | |
1610 | gdb_test "continue" "Continuing..*Breakpoint .*exit.*" \ | |
1611 | "continue until exit at $mssg" | |
1612 | } else { | |
1613 | # Continue until we exit. Should not stop again. | |
1614 | # Don't bother to check the output of the program, that may be | |
1615 | # extremely tough for some remote systems. | |
1616 | gdb_test "continue"\ | |
cb9a9d3e | 1617 | "Continuing.\[\r\n0-9\]+(... EXIT code 0\[\r\n\]+|)Program exited normally\\..*"\ |
7a292a7a SS |
1618 | "continue until exit at $mssg" |
1619 | } | |
1620 | } | |
1621 | ||
1622 | proc rerun_to_main {} { | |
1623 | global gdb_prompt | |
1624 | ||
1625 | if [target_info exists use_gdb_stub] { | |
1626 | gdb_run_cmd | |
1627 | gdb_expect { | |
1628 | -re ".*Breakpoint .*main .*$gdb_prompt $"\ | |
1629 | {pass "rerun to main" ; return 0} | |
1630 | -re "$gdb_prompt $"\ | |
1631 | {fail "rerun to main" ; return 0} | |
1632 | timeout {fail "(timeout) rerun to main" ; return 0} | |
1633 | } | |
1634 | } else { | |
1635 | send_gdb "run\n" | |
1636 | gdb_expect { | |
1637 | -re "Starting program.*$gdb_prompt $"\ | |
1638 | {pass "rerun to main" ; return 0} | |
1639 | -re "$gdb_prompt $"\ | |
1640 | {fail "rerun to main" ; return 0} | |
1641 | timeout {fail "(timeout) rerun to main" ; return 0} | |
1642 | } | |
1643 | } | |
1644 | } | |
c906108c | 1645 | |
13a5e3b8 MS |
1646 | # Print a message and return true if a test should be skipped |
1647 | # due to lack of floating point suport. | |
1648 | ||
1649 | proc gdb_skip_float_test { msg } { | |
1650 | if [target_info exists gdb,skip_float_tests] { | |
1651 | verbose "Skipping test '$msg': no float tests."; | |
1652 | return 1; | |
1653 | } | |
1654 | return 0; | |
1655 | } | |
1656 | ||
1657 | # Print a message and return true if a test should be skipped | |
1658 | # due to lack of stdio support. | |
1659 | ||
1660 | proc gdb_skip_stdio_test { msg } { | |
1661 | if [target_info exists gdb,noinferiorio] { | |
1662 | verbose "Skipping test '$msg': no inferior i/o."; | |
1663 | return 1; | |
1664 | } | |
1665 | return 0; | |
1666 | } | |
1667 | ||
1668 | proc gdb_skip_bogus_test { msg } { | |
1669 | return 0; | |
1670 | } | |
1671 |