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