* lib/gdb.exp (gdbtk_initialize_display): New proc which will
[deliverable/binutils-gdb.git] / gdb / testsuite / lib / gdb.exp
1 # Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000
2 # Free Software Foundation, Inc.
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
60 # The variable gdb_prompt is a regexp which matches the gdb prompt.
61 # Set it if it is not already set.
62 global gdb_prompt
63 if ![info exists gdb_prompt] then {
64 set gdb_prompt "\[(\]gdb\[)\]"
65 }
66
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
77 ### Only procedures should come after this point.
78
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
145 # we need a larger timeout value here or this thing just confuses
146 # itself. May need a better implementation if possible. - guo
147 #
148 send_gdb "delete breakpoints\n"
149 gdb_expect 100 {
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"
159 gdb_expect 100 {
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] {
194 # Specifying no file, defaults to the executable
195 # currently being debugged.
196 if { [gdb_load ""] < 0 } {
197 return;
198 }
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"
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)";
220 return;
221 }
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 }
250 }
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
348
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
374 # gdb_test COMMAND PATTERN MESSAGE -- send a command to gdb; test the result.
375 #
376 # COMMAND is the command to execute, send to GDB with send_gdb. If
377 # this is the null string no command is sent.
378 # PATTERN is the pattern to match for a PASS, and must NOT include
379 # the \r\n sequence immediately before the gdb prompt.
380 # MESSAGE is an optional message to be printed. If this is
381 # omitted, then the pass/fail messages use the command string as the
382 # message. (If this is the empty string, then sometimes we don't
383 # call pass or fail at all; I don't understand this at all.)
384 #
385 # Returns:
386 # 1 if the test failed,
387 # 0 if the test passes,
388 # -1 if there was an internal error.
389 #
390 proc gdb_test { args } {
391 global verbose
392 global gdb_prompt
393 global GDB
394 upvar timeout timeout
395
396 if [llength $args]>2 then {
397 set message [lindex $args 2]
398 } else {
399 set message [lindex $args 0]
400 }
401 set command [lindex $args 0]
402 set pattern [lindex $args 1]
403
404 if [llength $args]==5 {
405 set question_string [lindex $args 3];
406 set response_string [lindex $args 4];
407 } else {
408 set question_string "^FOOBAR$"
409 }
410
411 if $verbose>2 then {
412 send_user "Sending \"$command\" to gdb\n"
413 send_user "Looking to match \"$pattern\"\n"
414 send_user "Message is \"$message\"\n"
415 }
416
417 set result -1
418 set string "${command}\n";
419 if { $command != "" } {
420 while { "$string" != "" } {
421 set foo [string first "\n" "$string"];
422 set len [string length "$string"];
423 if { $foo < [expr $len - 1] } {
424 set str [string range "$string" 0 $foo];
425 if { [send_gdb "$str"] != "" } {
426 global suppress_flag;
427
428 if { ! $suppress_flag } {
429 perror "Couldn't send $command to GDB.";
430 }
431 fail "$message";
432 return $result;
433 }
434 # since we're checking if each line of the multi-line
435 # command are 'accepted' by GDB here,
436 # we need to set -notransfer expect option so that
437 # command output is not lost for pattern matching
438 # - guo
439 gdb_expect -notransfer 2 {
440 -re "\[\r\n\]" { }
441 timeout { }
442 }
443 set string [string range "$string" [expr $foo + 1] end];
444 } else {
445 break;
446 }
447 }
448 if { "$string" != "" } {
449 if { [send_gdb "$string"] != "" } {
450 global suppress_flag;
451
452 if { ! $suppress_flag } {
453 perror "Couldn't send $command to GDB.";
454 }
455 fail "$message";
456 return $result;
457 }
458 }
459 }
460
461 if [target_info exists gdb,timeout] {
462 set tmt [target_info gdb,timeout];
463 } else {
464 if [info exists timeout] {
465 set tmt $timeout;
466 } else {
467 global timeout;
468 if [info exists timeout] {
469 set tmt $timeout;
470 } else {
471 set tmt 60;
472 }
473 }
474 }
475 gdb_expect $tmt {
476 -re "\\*\\*\\* DOSEXIT code.*" {
477 if { $message != "" } {
478 fail "$message";
479 }
480 gdb_suppress_entire_file "GDB died";
481 return -1;
482 }
483 -re "Ending remote debugging.*$gdb_prompt $" {
484 if ![isnative] then {
485 warning "Can`t communicate to remote target."
486 }
487 gdb_exit
488 gdb_start
489 set result -1
490 }
491 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
492 if ![string match "" $message] then {
493 pass "$message"
494 }
495 set result 0
496 }
497 -re "(${question_string})$" {
498 send_gdb "$response_string\n";
499 exp_continue;
500 }
501 -re "Undefined\[a-z\]* command:.*$gdb_prompt $" {
502 perror "Undefined command \"$command\"."
503 fail "$message"
504 set result 1
505 }
506 -re "Ambiguous command.*$gdb_prompt $" {
507 perror "\"$command\" is not a unique command name."
508 fail "$message"
509 set result 1
510 }
511 -re "Program exited with code \[0-9\]+.*$gdb_prompt $" {
512 if ![string match "" $message] then {
513 set errmsg "$message: the program exited"
514 } else {
515 set errmsg "$command: the program exited"
516 }
517 fail "$errmsg"
518 return -1
519 }
520 -re "The program is not being run.*$gdb_prompt $" {
521 if ![string match "" $message] then {
522 set errmsg "$message: the program is no longer running"
523 } else {
524 set errmsg "$command: the program is no longer running"
525 }
526 fail "$errmsg"
527 return -1
528 }
529 -re ".*$gdb_prompt $" {
530 if ![string match "" $message] then {
531 fail "$message"
532 }
533 set result 1
534 }
535 "<return>" {
536 send_gdb "\n"
537 perror "Window too small."
538 fail "$message"
539 }
540 -re "\\(y or n\\) " {
541 send_gdb "n\n"
542 perror "Got interactive prompt."
543 fail "$message"
544 }
545 eof {
546 perror "Process no longer exists"
547 if { $message != "" } {
548 fail "$message"
549 }
550 return -1
551 }
552 full_buffer {
553 perror "internal buffer is full."
554 fail "$message"
555 }
556 timeout {
557 if ![string match "" $message] then {
558 fail "$message (timeout)"
559 }
560 set result 1
561 }
562 }
563 return $result
564 }
565 \f
566 # Test that a command gives an error. For pass or fail, return
567 # a 1 to indicate that more tests can proceed. However a timeout
568 # is a serious error, generates a special fail message, and causes
569 # a 0 to be returned to indicate that more tests are likely to fail
570 # as well.
571
572 proc test_print_reject { args } {
573 global gdb_prompt
574 global verbose
575
576 if [llength $args]==2 then {
577 set expectthis [lindex $args 1]
578 } else {
579 set expectthis "should never match this bogus string"
580 }
581 set sendthis [lindex $args 0]
582 if $verbose>2 then {
583 send_user "Sending \"$sendthis\" to gdb\n"
584 send_user "Looking to match \"$expectthis\"\n"
585 }
586 send_gdb "$sendthis\n"
587 #FIXME: Should add timeout as parameter.
588 gdb_expect {
589 -re "A .* in expression.*\\.*$gdb_prompt $" {
590 pass "reject $sendthis"
591 return 1
592 }
593 -re "Invalid syntax in expression.*$gdb_prompt $" {
594 pass "reject $sendthis"
595 return 1
596 }
597 -re "Junk after end of expression.*$gdb_prompt $" {
598 pass "reject $sendthis"
599 return 1
600 }
601 -re "Invalid number.*$gdb_prompt $" {
602 pass "reject $sendthis"
603 return 1
604 }
605 -re "Invalid character constant.*$gdb_prompt $" {
606 pass "reject $sendthis"
607 return 1
608 }
609 -re "No symbol table is loaded.*$gdb_prompt $" {
610 pass "reject $sendthis"
611 return 1
612 }
613 -re "No symbol .* in current context.*$gdb_prompt $" {
614 pass "reject $sendthis"
615 return 1
616 }
617 -re "$expectthis.*$gdb_prompt $" {
618 pass "reject $sendthis"
619 return 1
620 }
621 -re ".*$gdb_prompt $" {
622 fail "reject $sendthis"
623 return 1
624 }
625 default {
626 fail "reject $sendthis (eof or timeout)"
627 return 0
628 }
629 }
630 }
631 \f
632 # Given an input string, adds backslashes as needed to create a
633 # regexp that will match the string.
634
635 proc string_to_regexp {str} {
636 set result $str
637 regsub -all {[]*+.|()^$\[]} $str {\\&} result
638 return $result
639 }
640
641 # Same as gdb_test, but the second parameter is not a regexp,
642 # but a string that must match exactly.
643
644 proc gdb_test_exact { args } {
645 upvar timeout timeout
646
647 set command [lindex $args 0]
648
649 # This applies a special meaning to a null string pattern. Without
650 # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
651 # messages from commands that should have no output except a new
652 # prompt. With this, only results of a null string will match a null
653 # string pattern.
654
655 set pattern [lindex $args 1]
656 if [string match $pattern ""] {
657 set pattern [string_to_regexp [lindex $args 0]]
658 } else {
659 set pattern [string_to_regexp [lindex $args 1]]
660 }
661
662 # It is most natural to write the pattern argument with only
663 # embedded \n's, especially if you are trying to avoid Tcl quoting
664 # problems. But gdb_expect really wants to see \r\n in patterns. So
665 # transform the pattern here. First transform \r\n back to \n, in
666 # case some users of gdb_test_exact already do the right thing.
667 regsub -all "\r\n" $pattern "\n" pattern
668 regsub -all "\n" $pattern "\r\n" pattern
669 if [llength $args]==3 then {
670 set message [lindex $args 2]
671 } else {
672 set message $command
673 }
674
675 return [gdb_test $command $pattern $message]
676 }
677 \f
678 proc gdb_reinitialize_dir { subdir } {
679 global gdb_prompt
680
681 if [is_remote host] {
682 return "";
683 }
684 send_gdb "dir\n"
685 gdb_expect 60 {
686 -re "Reinitialize source path to empty.*y or n. " {
687 send_gdb "y\n"
688 gdb_expect 60 {
689 -re "Source directories searched.*$gdb_prompt $" {
690 send_gdb "dir $subdir\n"
691 gdb_expect 60 {
692 -re "Source directories searched.*$gdb_prompt $" {
693 verbose "Dir set to $subdir"
694 }
695 -re "$gdb_prompt $" {
696 perror "Dir \"$subdir\" failed."
697 }
698 }
699 }
700 -re "$gdb_prompt $" {
701 perror "Dir \"$subdir\" failed."
702 }
703 }
704 }
705 -re "$gdb_prompt $" {
706 perror "Dir \"$subdir\" failed."
707 }
708 }
709 }
710
711 #
712 # gdb_exit -- exit the GDB, killing the target program if necessary
713 #
714 proc default_gdb_exit {} {
715 global GDB
716 global GDBFLAGS
717 global verbose
718 global gdb_spawn_id;
719
720 gdb_stop_suppressing_tests;
721
722 if ![info exists gdb_spawn_id] {
723 return;
724 }
725
726 verbose "Quitting $GDB $GDBFLAGS"
727
728 if { [is_remote host] && [board_info host exists fileid] } {
729 send_gdb "quit\n";
730 gdb_expect 10 {
731 -re "y or n" {
732 send_gdb "y\n";
733 exp_continue;
734 }
735 -re "DOSEXIT code" { }
736 default { }
737 }
738 }
739
740 if ![is_remote host] {
741 remote_close host;
742 }
743 unset gdb_spawn_id
744 }
745
746 #
747 # load a file into the debugger.
748 # return a -1 if anything goes wrong.
749 #
750 proc gdb_file_cmd { arg } {
751 global verbose
752 global loadpath
753 global loadfile
754 global GDB
755 global gdb_prompt
756 upvar timeout timeout
757
758 if [is_remote host] {
759 set arg [remote_download host $arg];
760 if { $arg == "" } {
761 error "download failed"
762 return -1;
763 }
764 }
765
766 send_gdb "file $arg\n"
767 gdb_expect 120 {
768 -re "Reading symbols from.*done.*$gdb_prompt $" {
769 verbose "\t\tLoaded $arg into the $GDB"
770 return 0
771 }
772 -re "has no symbol-table.*$gdb_prompt $" {
773 perror "$arg wasn't compiled with \"-g\""
774 return -1
775 }
776 -re "A program is being debugged already.*Kill it.*y or n. $" {
777 send_gdb "y\n"
778 verbose "\t\tKilling previous program being debugged"
779 exp_continue
780 }
781 -re "Load new symbol table from \".*\".*y or n. $" {
782 send_gdb "y\n"
783 gdb_expect 120 {
784 -re "Reading symbols from.*done.*$gdb_prompt $" {
785 verbose "\t\tLoaded $arg with new symbol table into $GDB"
786 return 0
787 }
788 timeout {
789 perror "(timeout) Couldn't load $arg, other program already loaded."
790 return -1
791 }
792 }
793 }
794 -re "No such file or directory.*$gdb_prompt $" {
795 perror "($arg) No such file or directory\n"
796 return -1
797 }
798 -re "$gdb_prompt $" {
799 perror "couldn't load $arg into $GDB."
800 return -1
801 }
802 timeout {
803 perror "couldn't load $arg into $GDB (timed out)."
804 return -1
805 }
806 eof {
807 # This is an attempt to detect a core dump, but seems not to
808 # work. Perhaps we need to match .* followed by eof, in which
809 # gdb_expect does not seem to have a way to do that.
810 perror "couldn't load $arg into $GDB (end of file)."
811 return -1
812 }
813 }
814 }
815
816 #
817 # start gdb -- start gdb running, default procedure
818 #
819 # When running over NFS, particularly if running many simultaneous
820 # tests on different hosts all using the same server, things can
821 # get really slow. Give gdb at least 3 minutes to start up.
822 #
823 proc default_gdb_start { } {
824 global verbose
825 global GDB
826 global GDBFLAGS
827 global gdb_prompt
828 global timeout
829 global gdb_spawn_id;
830
831 gdb_stop_suppressing_tests;
832
833 verbose "Spawning $GDB -nw $GDBFLAGS"
834
835 if [info exists gdb_spawn_id] {
836 return 0;
837 }
838
839 if ![is_remote host] {
840 if { [which $GDB] == 0 } then {
841 perror "$GDB does not exist."
842 exit 1
843 }
844 }
845 set res [remote_spawn host "$GDB -nw $GDBFLAGS [host_info gdb_opts]"];
846 if { $res < 0 || $res == "" } {
847 perror "Spawning $GDB failed."
848 return 1;
849 }
850 gdb_expect 360 {
851 -re "\[\r\n\]$gdb_prompt $" {
852 verbose "GDB initialized."
853 }
854 -re "$gdb_prompt $" {
855 perror "GDB never initialized."
856 return -1
857 }
858 timeout {
859 perror "(timeout) GDB never initialized after 10 seconds."
860 remote_close host;
861 return -1
862 }
863 }
864 set gdb_spawn_id -1;
865 # force the height to "unlimited", so no pagers get used
866
867 send_gdb "set height 0\n"
868 gdb_expect 10 {
869 -re "$gdb_prompt $" {
870 verbose "Setting height to 0." 2
871 }
872 timeout {
873 warning "Couldn't set the height to 0"
874 }
875 }
876 # force the width to "unlimited", so no wraparound occurs
877 send_gdb "set width 0\n"
878 gdb_expect 10 {
879 -re "$gdb_prompt $" {
880 verbose "Setting width to 0." 2
881 }
882 timeout {
883 warning "Couldn't set the width to 0."
884 }
885 }
886 return 0;
887 }
888
889 # Return a 1 for configurations for which we don't even want to try to
890 # test C++.
891
892 proc skip_cplus_tests {} {
893 if { [istarget "d10v-*-*"] } {
894 return 1
895 }
896 if { [istarget "h8300-*-*"] } {
897 return 1
898 }
899 return 0
900 }
901
902 # * For crosses, the CHILL runtime doesn't build because it can't find
903 # setjmp.h, stdio.h, etc.
904 # * For AIX (as of 16 Mar 95), (a) there is no language code for
905 # CHILL in output_epilog in gcc/config/rs6000/rs6000.c, (b) collect2
906 # does not get along with AIX's too-clever linker.
907 # * On Irix5, there is a bug whereby set of bool, etc., don't get
908 # TYPE_LOW_BOUND for the bool right because force_to_range_type doesn't
909 # work with stub types.
910 # Lots of things seem to fail on the PA, and since it's not a supported
911 # chill target at the moment, don't run the chill tests.
912
913 proc skip_chill_tests {} {
914 if ![info exists do_chill_tests] {
915 return 1;
916 }
917 eval set skip_chill [expr ![isnative] || [istarget "*-*-aix*"] || [istarget "*-*-irix5*"] || [istarget "*-*-irix6*"] || [istarget "alpha-*-osf*"] || [istarget "hppa*-*-*"]]
918 verbose "Skip chill tests is $skip_chill"
919 return $skip_chill
920 }
921
922 # Skip all the tests in the file if you are not on an hppa running
923 # hpux target.
924
925 proc skip_hp_tests {} {
926 eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ]
927 verbose "Skip hp tests is $skip_hp"
928 return $skip_hp
929 }
930
931 proc get_compiler_info {binfile args} {
932 # Create and source the file that provides information about the compiler
933 # used to compile the test case.
934 # Compiler_type can be null or c++. If null we assume c.
935 global srcdir
936 global subdir
937 # These two come from compiler.c.
938 global signed_keyword_not_used
939 global gcc_compiled
940
941 if {![istarget "hppa*-*-hpux*"]} {
942 if { [llength $args] > 0 } {
943 if {$args == "c++"} {
944 if { [gdb_compile "${srcdir}/lib/compiler.cc" "${binfile}.ci" preprocess {}] != "" } {
945 perror "Couldn't make ${binfile}.ci file"
946 return 1;
947 }
948 }
949 } else {
950 if { [gdb_compile "${srcdir}/lib/compiler.c" "${binfile}.ci" preprocess {}] != "" } {
951 perror "Couldn't make ${binfile}.ci file"
952 return 1;
953 }
954 }
955 } else {
956 if { [llength $args] > 0 } {
957 if {$args == "c++"} {
958 if { [eval gdb_preprocess \
959 [list "${srcdir}/lib/compiler.cc" "${binfile}.ci"] \
960 $args] != "" } {
961 perror "Couldn't make ${binfile}.ci file"
962 return 1;
963 }
964 }
965 } elseif { $args != "f77" } {
966 if { [eval gdb_preprocess \
967 [list "${srcdir}/lib/compiler.c" "${binfile}.ci"] \
968 $args] != "" } {
969 perror "Couldn't make ${binfile}.ci file"
970 return 1;
971 }
972 }
973 }
974
975 uplevel \#0 { set gcc_compiled 0 }
976
977 if { [llength $args] == 0 || $args != "f77" } {
978 source ${binfile}.ci
979 }
980
981 # Most compilers will evaluate comparisons and other boolean
982 # operations to 0 or 1.
983 uplevel \#0 { set true 1 }
984 uplevel \#0 { set false 0 }
985
986 uplevel \#0 { set hp_cc_compiler 0 }
987 uplevel \#0 { set hp_aCC_compiler 0 }
988 uplevel \#0 { set hp_f77_compiler 0 }
989 uplevel \#0 { set hp_f90_compiler 0 }
990 if { !$gcc_compiled && [istarget "hppa*-*-hpux*"] } {
991 # Check for the HP compilers
992 set compiler [lindex [split [get_compiler $args] " "] 0]
993 catch "exec what $compiler" output
994 if [regexp ".*HP aC\\+\\+.*" $output] {
995 uplevel \#0 { set hp_aCC_compiler 1 }
996 # Use of aCC results in boolean results being displayed as
997 # "true" or "false"
998 uplevel \#0 { set true true }
999 uplevel \#0 { set false false }
1000 } elseif [regexp ".*HP C Compiler.*" $output] {
1001 uplevel \#0 { set hp_cc_compiler 1 }
1002 } elseif [regexp ".*HP-UX f77.*" $output] {
1003 uplevel \#0 { set hp_f77_compiler 1 }
1004 } elseif [regexp ".*HP-UX f90.*" $output] {
1005 uplevel \#0 { set hp_f90_compiler 1 }
1006 }
1007 }
1008
1009 return 0;
1010 }
1011
1012 proc get_compiler {args} {
1013 global CC CC_FOR_TARGET CXX CXX_FOR_TARGET F77_FOR_TARGET
1014
1015 if { [llength $args] == 0
1016 || ([llength $args] == 1 && [lindex $args 0] == "") } {
1017 set which_compiler "c"
1018 } else {
1019 if { $args =="c++" } {
1020 set which_compiler "c++"
1021 } elseif { $args =="f77" } {
1022 set which_compiler "f77"
1023 } else {
1024 perror "Unknown compiler type supplied to gdb_preprocess"
1025 return ""
1026 }
1027 }
1028
1029 if [info exists CC_FOR_TARGET] {
1030 if {$which_compiler == "c"} {
1031 set compiler $CC_FOR_TARGET
1032 }
1033 }
1034
1035 if [info exists CXX_FOR_TARGET] {
1036 if {$which_compiler == "c++"} {
1037 set compiler $CXX_FOR_TARGET
1038 }
1039 }
1040
1041 if [info exists F77_FOR_TARGET] {
1042 if {$which_compiler == "f77"} {
1043 set compiler $F77_FOR_TARGET
1044 }
1045 }
1046
1047 if { ![info exists compiler] } {
1048 if { $which_compiler == "c" } {
1049 if {[info exists CC]} {
1050 set compiler $CC
1051 }
1052 }
1053 if { $which_compiler == "c++" } {
1054 if {[info exists CXX]} {
1055 set compiler $CXX
1056 }
1057 }
1058 if {![info exists compiler]} {
1059 set compiler [board_info [target_info name] compiler];
1060 if { $compiler == "" } {
1061 perror "get_compiler: No compiler found"
1062 return ""
1063 }
1064 }
1065 }
1066
1067 return $compiler
1068 }
1069
1070 proc gdb_preprocess {source dest args} {
1071 set compiler [get_compiler "$args"]
1072 if { $compiler == "" } {
1073 return 1
1074 }
1075
1076 set cmdline "$compiler -E $source > $dest"
1077
1078 verbose "Invoking $compiler -E $source > $dest"
1079 verbose -log "Executing on local host: $cmdline" 2
1080 set status [catch "exec ${cmdline}" exec_output]
1081
1082 set result [prune_warnings $exec_output]
1083 regsub "\[\r\n\]*$" "$result" "" result;
1084 regsub "^\[\r\n\]*" "$result" "" result;
1085 if { $result != "" } {
1086 clone_output "gdb compile failed, $result"
1087 }
1088 return $result;
1089 }
1090
1091 proc gdb_compile {source dest type options} {
1092 global GDB_TESTCASE_OPTIONS;
1093
1094 if [target_info exists gdb_stub] {
1095 set options2 { "additional_flags=-Dusestubs" }
1096 lappend options "libs=[target_info gdb_stub]";
1097 set options [concat $options2 $options]
1098 }
1099 if [target_info exists is_vxworks] {
1100 set options2 { "additional_flags=-Dvxworks" }
1101 lappend options "libs=[target_info gdb_stub]";
1102 set options [concat $options2 $options]
1103 }
1104 if [info exists GDB_TESTCASE_OPTIONS] {
1105 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS";
1106 }
1107 verbose "options are $options"
1108 verbose "source is $source $dest $type $options"
1109
1110 set result [target_compile $source $dest $type $options];
1111 regsub "\[\r\n\]*$" "$result" "" result;
1112 regsub "^\[\r\n\]*" "$result" "" result;
1113 if { $result != "" } {
1114 clone_output "gdb compile failed, $result"
1115 }
1116 return $result;
1117 }
1118
1119 proc send_gdb { string } {
1120 global suppress_flag;
1121 if { $suppress_flag } {
1122 return "suppressed";
1123 }
1124 return [remote_send host "$string"];
1125 }
1126
1127 #
1128 #
1129
1130 proc gdb_expect { args } {
1131 # allow -notransfer expect flag specification,
1132 # used by gdb_test routine for multi-line commands.
1133 # packed with gtimeout when fed to remote_expect routine,
1134 # which is a hack but due to what looks like a res and orig
1135 # parsing problem in remote_expect routine (dejagnu/lib/remote.exp):
1136 # what's fed into res is not removed from orig.
1137 # - guo
1138 if { [lindex $args 0] == "-notransfer" } {
1139 set notransfer -notransfer;
1140 set args [lrange $args 1 end];
1141 } else {
1142 set notransfer "";
1143 }
1144
1145 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
1146 set gtimeout [lindex $args 0];
1147 set expcode [list [lindex $args 1]];
1148 } else {
1149 upvar timeout timeout;
1150
1151 set expcode $args;
1152 if [target_info exists gdb,timeout] {
1153 if [info exists timeout] {
1154 if { $timeout < [target_info gdb,timeout] } {
1155 set gtimeout [target_info gdb,timeout];
1156 } else {
1157 set gtimeout $timeout;
1158 }
1159 } else {
1160 set gtimeout [target_info gdb,timeout];
1161 }
1162 }
1163
1164 if ![info exists gtimeout] {
1165 global timeout;
1166 if [info exists timeout] {
1167 set gtimeout $timeout;
1168 } else {
1169 # Eeeeew.
1170 set gtimeout 60;
1171 }
1172 }
1173 }
1174 global suppress_flag;
1175 global remote_suppress_flag;
1176 if [info exists remote_suppress_flag] {
1177 set old_val $remote_suppress_flag;
1178 }
1179 if [info exists suppress_flag] {
1180 if { $suppress_flag } {
1181 set remote_suppress_flag 1;
1182 }
1183 }
1184 set code [catch \
1185 {uplevel remote_expect host "$gtimeout $notransfer" $expcode} string];
1186 if [info exists old_val] {
1187 set remote_suppress_flag $old_val;
1188 } else {
1189 if [info exists remote_suppress_flag] {
1190 unset remote_suppress_flag;
1191 }
1192 }
1193
1194 if {$code == 1} {
1195 global errorInfo errorCode;
1196
1197 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
1198 } elseif {$code == 2} {
1199 return -code return $string
1200 } elseif {$code == 3} {
1201 return
1202 } elseif {$code > 4} {
1203 return -code $code $string
1204 }
1205 }
1206
1207 # gdb_expect_list MESSAGE SENTINEL LIST -- expect a sequence of outputs
1208 #
1209 # Check for long sequence of output by parts.
1210 # MESSAGE: is the test message to be printed with the test success/fail.
1211 # SENTINEL: Is the terminal pattern indicating that output has finished.
1212 # LIST: is the sequence of outputs to match.
1213 # If the sentinel is recognized early, it is considered an error.
1214 #
1215 # Returns:
1216 # 1 if the test failed,
1217 # 0 if the test passes,
1218 # -1 if there was an internal error.
1219 #
1220 proc gdb_expect_list {test sentinel list} {
1221 global gdb_prompt
1222 global suppress_flag
1223 set index 0
1224 set ok 1
1225 if { $suppress_flag } {
1226 set ok 0
1227 }
1228 while { ${index} < [llength ${list}] } {
1229 set pattern [lindex ${list} ${index}]
1230 set index [expr ${index} + 1]
1231 if { ${index} == [llength ${list}] } {
1232 if { ${ok} } {
1233 gdb_expect {
1234 -re "${pattern}${sentinel}" {
1235 pass "${test}, pattern ${index} + sentinel"
1236 }
1237 -re "${sentinel}" {
1238 fail "${test}, pattern ${index} + sentinel"
1239 set ok 0
1240 }
1241 timeout {
1242 fail "${test}, pattern ${index} + sentinel (timeout)"
1243 set ok 0
1244 }
1245 }
1246 } else {
1247 unresolved "${test}, pattern ${index} + sentinel"
1248 }
1249 } else {
1250 if { ${ok} } {
1251 gdb_expect {
1252 -re "${pattern}" {
1253 pass "${test}, pattern ${index}"
1254 }
1255 -re "${sentinel}" {
1256 fail "${test}, pattern ${index}"
1257 set ok 0
1258 }
1259 timeout {
1260 fail "${test}, pattern ${index} (timeout)"
1261 set ok 0
1262 }
1263 }
1264 } else {
1265 unresolved "${test}, pattern ${index}"
1266 }
1267 }
1268 }
1269 if { ${ok} } {
1270 return 0
1271 } else {
1272 return 1
1273 }
1274 }
1275
1276 #
1277 #
1278 proc gdb_suppress_entire_file { reason } {
1279 global suppress_flag;
1280
1281 warning "$reason\n";
1282 set suppress_flag -1;
1283 }
1284
1285 #
1286 # Set suppress_flag, which will cause all subsequent calls to send_gdb and
1287 # gdb_expect to fail immediately (until the next call to
1288 # gdb_stop_suppressing_tests).
1289 #
1290 proc gdb_suppress_tests { args } {
1291 global suppress_flag;
1292
1293 return; # fnf - disable pending review of results where
1294 # testsuite ran better without this
1295 incr suppress_flag;
1296
1297 if { $suppress_flag == 1 } {
1298 if { [llength $args] > 0 } {
1299 warning "[lindex $args 0]\n";
1300 } else {
1301 warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n";
1302 }
1303 }
1304 }
1305
1306 #
1307 # Clear suppress_flag.
1308 #
1309 proc gdb_stop_suppressing_tests { } {
1310 global suppress_flag;
1311
1312 if [info exists suppress_flag] {
1313 if { $suppress_flag > 0 } {
1314 set suppress_flag 0;
1315 clone_output "Tests restarted.\n";
1316 }
1317 } else {
1318 set suppress_flag 0;
1319 }
1320 }
1321
1322 proc gdb_clear_suppressed { } {
1323 global suppress_flag;
1324
1325 set suppress_flag 0;
1326 }
1327
1328 proc gdb_start { } {
1329 default_gdb_start
1330 }
1331
1332 proc gdb_exit { } {
1333 catch default_gdb_exit
1334 }
1335
1336 #
1337 # gdb_load -- load a file into the debugger.
1338 # return a -1 if anything goes wrong.
1339 #
1340 proc gdb_load { arg } {
1341 return [gdb_file_cmd $arg]
1342 }
1343
1344 proc gdb_continue { function } {
1345 global decimal
1346
1347 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"];
1348 }
1349
1350 proc default_gdb_init { args } {
1351 gdb_clear_suppressed;
1352
1353 # Uh, this is lame. Really, really, really lame. But there's this *one*
1354 # testcase that will fail in random places if we don't increase this.
1355 match_max -d 20000
1356
1357 # We want to add the name of the TCL testcase to the PASS/FAIL messages.
1358 if { [llength $args] > 0 } {
1359 global pf_prefix
1360
1361 set file [lindex $args 0];
1362
1363 set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:";
1364 }
1365 global gdb_prompt;
1366 if [target_info exists gdb_prompt] {
1367 set gdb_prompt [target_info gdb_prompt];
1368 } else {
1369 set gdb_prompt "\\(gdb\\)"
1370 }
1371 }
1372
1373 proc gdb_init { args } {
1374 return [eval default_gdb_init $args];
1375 }
1376
1377 proc gdb_finish { } {
1378 gdb_exit;
1379 }
1380
1381 global debug_format
1382 set debug_format "unknown"
1383
1384 # Run the gdb command "info source" and extract the debugging format
1385 # information from the output and save it in debug_format.
1386
1387 proc get_debug_format { } {
1388 global gdb_prompt
1389 global verbose
1390 global expect_out
1391 global debug_format
1392
1393 set debug_format "unknown"
1394 send_gdb "info source\n"
1395 gdb_expect 10 {
1396 -re "Compiled with (.*) debugging format.\r\n$gdb_prompt $" {
1397 set debug_format $expect_out(1,string)
1398 verbose "debug format is $debug_format"
1399 return 1;
1400 }
1401 -re "No current source file.\r\n$gdb_prompt $" {
1402 perror "get_debug_format used when no current source file"
1403 return 0;
1404 }
1405 -re "$gdb_prompt $" {
1406 warning "couldn't check debug format (no valid response)."
1407 return 1;
1408 }
1409 timeout {
1410 warning "couldn't check debug format (timed out)."
1411 return 1;
1412 }
1413 }
1414 }
1415
1416 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
1417 # COFF, stabs, etc). If that format matches the format that the
1418 # current test was compiled with, then the next test is expected to
1419 # fail for any target. Returns 1 if the next test or set of tests is
1420 # expected to fail, 0 otherwise (or if it is unknown). Must have
1421 # previously called get_debug_format.
1422
1423 proc setup_xfail_format { format } {
1424 global debug_format
1425
1426 if [string match $debug_format $format] then {
1427 setup_xfail "*-*-*"
1428 return 1;
1429 }
1430 return 0
1431 }
1432
1433 proc gdb_step_for_stub { } {
1434 global gdb_prompt;
1435
1436 if ![target_info exists gdb,use_breakpoint_for_stub] {
1437 if [target_info exists gdb_stub_step_command] {
1438 set command [target_info gdb_stub_step_command];
1439 } else {
1440 set command "step";
1441 }
1442 send_gdb "${command}\n";
1443 set tries 0;
1444 gdb_expect 60 {
1445 -re "(main.* at |.*in .*start).*$gdb_prompt" {
1446 return;
1447 }
1448 -re ".*$gdb_prompt" {
1449 incr tries;
1450 if { $tries == 5 } {
1451 fail "stepping out of breakpoint function";
1452 return;
1453 }
1454 send_gdb "${command}\n";
1455 exp_continue;
1456 }
1457 default {
1458 fail "stepping out of breakpoint function";
1459 return;
1460 }
1461 }
1462 }
1463 send_gdb "where\n";
1464 gdb_expect {
1465 -re "main\[^\r\n\]*at \(\[^:]+\):\(\[0-9\]+\)" {
1466 set file $expect_out(1,string);
1467 set linenum [expr $expect_out(2,string) + 1];
1468 set breakplace "${file}:${linenum}";
1469 }
1470 default {}
1471 }
1472 send_gdb "break ${breakplace}\n";
1473 gdb_expect 60 {
1474 -re "Breakpoint (\[0-9\]+) at.*$gdb_prompt" {
1475 set breakpoint $expect_out(1,string);
1476 }
1477 -re "Breakpoint (\[0-9\]+): file.*$gdb_prompt" {
1478 set breakpoint $expect_out(1,string);
1479 }
1480 default {}
1481 }
1482 send_gdb "continue\n";
1483 gdb_expect 60 {
1484 -re "Breakpoint ${breakpoint},.*$gdb_prompt" {
1485 gdb_test "delete $breakpoint" ".*" "";
1486 return;
1487 }
1488 default {}
1489 }
1490 }
1491
1492 ### gdb_get_line_number TEXT [FILE]
1493 ###
1494 ### Search the source file FILE, and return the line number of a line
1495 ### containing TEXT. Use this function instead of hard-coding line
1496 ### numbers into your test script.
1497 ###
1498 ### Specifically, this function uses GDB's "search" command to search
1499 ### FILE for the first line containing TEXT, and returns its line
1500 ### number. Thus, FILE must be a source file, compiled into the
1501 ### executable you are running. If omitted, FILE defaults to the
1502 ### value of the global variable `srcfile'; most test scripts set
1503 ### `srcfile' appropriately at the top anyway.
1504 ###
1505 ### Use this function to keep your test scripts independent of the
1506 ### exact line numbering of the source file. Don't write:
1507 ###
1508 ### send_gdb "break 20"
1509 ###
1510 ### This means that if anyone ever edits your test's source file,
1511 ### your test could break. Instead, put a comment like this on the
1512 ### source file line you want to break at:
1513 ###
1514 ### /* breakpoint spot: frotz.exp: test name */
1515 ###
1516 ### and then write, in your test script (which we assume is named
1517 ### frotz.exp):
1518 ###
1519 ### send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
1520 ###
1521 ### (Yes, Tcl knows how to handle the nested quotes and brackets.
1522 ### Try this:
1523 ### $ tclsh
1524 ### % puts "foo [lindex "bar baz" 1]"
1525 ### foo baz
1526 ### %
1527 ### Tcl is quite clever, for a little stringy language.)
1528
1529 proc gdb_get_line_number {text {file /omitted/}} {
1530 global gdb_prompt;
1531 global srcfile;
1532
1533 if {! [string compare $file /omitted/]} {
1534 set file $srcfile
1535 }
1536
1537 set result -1;
1538 gdb_test "list ${file}:1,1" ".*" ""
1539 send_gdb "search ${text}\n"
1540 gdb_expect {
1541 -re "\[\r\n\]+(\[0-9\]+)\[ \t\].*${text}.*$gdb_prompt $" {
1542 set result $expect_out(1,string)
1543 }
1544 -re ".*$gdb_prompt $" {
1545 fail "find line number containing \"${text}\""
1546 }
1547 timeout {
1548 fail "find line number containing \"${text}\" (timeout)"
1549 }
1550 }
1551 return $result;
1552 }
1553
1554 # gdb_continue_to_end:
1555 # The case where the target uses stubs has to be handled specially. If a
1556 # stub is used, we set a breakpoint at exit because we cannot rely on
1557 # exit() behavior of a remote target.
1558 #
1559 # mssg is the error message that gets printed.
1560
1561 proc gdb_continue_to_end {mssg} {
1562 if [target_info exists use_gdb_stub] {
1563 if {![gdb_breakpoint "exit"]} {
1564 return 0
1565 }
1566 gdb_test "continue" "Continuing..*Breakpoint .*exit.*" \
1567 "continue until exit at $mssg"
1568 } else {
1569 # Continue until we exit. Should not stop again.
1570 # Don't bother to check the output of the program, that may be
1571 # extremely tough for some remote systems.
1572 gdb_test "continue"\
1573 "Continuing.\[\r\n0-9\]+Program exited normally\\..*"\
1574 "continue until exit at $mssg"
1575 }
1576 }
1577
1578 proc rerun_to_main {} {
1579 global gdb_prompt
1580
1581 if [target_info exists use_gdb_stub] {
1582 gdb_run_cmd
1583 gdb_expect {
1584 -re ".*Breakpoint .*main .*$gdb_prompt $"\
1585 {pass "rerun to main" ; return 0}
1586 -re "$gdb_prompt $"\
1587 {fail "rerun to main" ; return 0}
1588 timeout {fail "(timeout) rerun to main" ; return 0}
1589 }
1590 } else {
1591 send_gdb "run\n"
1592 gdb_expect {
1593 -re "Starting program.*$gdb_prompt $"\
1594 {pass "rerun to main" ; return 0}
1595 -re "$gdb_prompt $"\
1596 {fail "rerun to main" ; return 0}
1597 timeout {fail "(timeout) rerun to main" ; return 0}
1598 }
1599 }
1600 }
1601
1602 # Initializes the display for gdbtk testing.
1603 # Returns 1 if tests should run, 0 otherwise.
1604 proc gdbtk_initialize_display {} {
1605 global _using_windows
1606
1607 # This is hacky, but, we don't have much choice. When running
1608 # expect under Windows, tcl_platform(platform) is "unix".
1609 if {![info exists _using_windows]} {
1610 set _using_windows [expr {![catch {exec cygpath --help}]}]
1611 }
1612
1613 if {![_gdbtk_xvfb_init]} {
1614 if {$_using_windows} {
1615 untested "No GDB_DISPLAY -- skipping tests"
1616 } else {
1617 untested "No GDB_DISPLAY or Xvfb -- skipping tests"
1618 }
1619
1620 return 0
1621 }
1622
1623 return 1
1624 }
1625
1626 # From dejagnu:
1627 # srcdir = testsuite src dir (e.g., devo/gdb/testsuite)
1628 # objdir = testsuite obj dir (e.g., gdb/testsuite)
1629 # subdir = subdir of testsuite (e.g., gdb.gdbtk)
1630 #
1631 # To gdbtk:
1632 # env(DEFS)=the "defs" files (e.g., devo/gdb/testsuite/gdb.gdbtk/defs)
1633 # env(SRCDIR)=directory containing the test code (e.g., *.test)
1634 # env(OBJDIR)=directory which contains any executables
1635 # (e.g., gdb/testsuite/gdb.gdbtk)
1636 proc gdbtk_start {test} {
1637 global verbose
1638 global GDB
1639 global GDBFLAGS
1640 global env srcdir subdir objdir
1641
1642 gdb_stop_suppressing_tests;
1643
1644 verbose "Starting $GDB -nx -q --tclcommand=$test"
1645
1646 set real_test [which $test]
1647 if {$real_test == 0} {
1648 perror "$test is not found"
1649 exit 1
1650 }
1651
1652 if {![is_remote host]} {
1653 if { [which $GDB] == 0 } {
1654 perror "$GDB does not exist."
1655 exit 1
1656 }
1657 }
1658
1659 set wd [pwd]
1660
1661 # Find absolute path to test
1662 set test [to_tcl_path -abs $test]
1663
1664 # Set environment variables for tcl libraries and such
1665 cd $srcdir
1666 set abs_srcdir [pwd]
1667 set env(GDBTK_LIBRARY) [to_tcl_path -abs [file join $abs_srcdir .. gdbtk library]]
1668 set env(TCL_LIBRARY) [to_tcl_path -abs [file join $abs_srcdir .. .. tcl library]]
1669 set env(TK_LIBRARY) [to_tcl_path -abs [file join $abs_srcdir .. .. tk library]]
1670 set env(TIX_LIBRARY) [to_tcl_path -abs [file join $abs_srcdir .. .. tix library]]
1671 set env(ITCL_LIBRARY) [to_tcl_path -abs [file join $abs_srcdir .. .. itcl itcl library]]
1672 set env(CYGNUS_GUI_LIBRARY) [to_tcl_path -abs [file join .. $abs_srcdir .. .. libgui library]]
1673 set env(DEFS) [to_tcl_path -abs [file join $abs_srcdir $subdir defs]]
1674
1675 cd $wd
1676 cd [file join $objdir $subdir]
1677 set env(OBJDIR) [pwd]
1678 cd $wd
1679
1680 # Set info about target into env
1681 _gdbtk_export_target_info
1682
1683 set env(SRCDIR) $abs_srcdir
1684 set env(GDBTK_VERBOSE) 1
1685 set env(GDBTK_LOGFILE) [to_tcl_path [file join $objdir gdb.log]]
1686
1687 set err [catch {exec $GDB -nx -q --tclcommand=$test} res]
1688 if { $err } {
1689 perror "Execing $GDB failed: $res"
1690 exit 1;
1691 }
1692 return $res
1693 }
1694
1695 # Start xvfb when using it.
1696 # The precedence is:
1697 # 1. If GDB_DISPLAY is set, use it
1698 # 2. If Xvfb exists, use it (not on cygwin)
1699 # 3. Skip tests
1700 proc _gdbtk_xvfb_init {} {
1701 global env spawn_id _xvfb_spawn_id _using_windows
1702
1703 if {[info exists env(GDB_DISPLAY)]} {
1704 set env(DISPLAY) $env(GDB_DISPLAY)
1705 } elseif {!$_using_windows && [which Xvfb] != 0} {
1706 set screen ":[getpid]"
1707 set pid [spawn Xvfb $screen]
1708 set _xvfb_spawn_id $spawn_id
1709 set env(DISPLAY) $screen
1710 } else {
1711 # No Xvfb found -- skip test
1712 return 0
1713 }
1714
1715 return 1
1716 }
1717
1718 # Kill xvfb
1719 proc _gdbtk_xvfb_exit {} {
1720 global objdir subdir env _xvfb_spawn_id
1721
1722 if {[info exists _xvfb_spawn_id]} {
1723 exec kill [exp_pid -i $_xvfb_spawn_id]
1724 wait -i $_xvfb_spawn_id
1725 }
1726 }
1727
1728 # help proc for setting tcl-style paths from unix-style paths
1729 # pass "-abs" to make it an absolute path
1730 proc to_tcl_path {unix_path {arg {}}} {
1731 global _using_windows
1732
1733 if {[string compare $unix_path "-abs"] == 0} {
1734 set unix_path $arg
1735 set wd [pwd]
1736 cd [file dirname $unix_path]
1737 set dirname [pwd]
1738 set unix_name [file join $dirname [file tail $unix_path]]
1739 cd $wd
1740 }
1741
1742 if {$_using_windows} {
1743 set unix_path [exec cygpath -aw $unix_path]
1744 set unix_path [join [split $unix_path \\] /]
1745 }
1746
1747 return $unix_path
1748 }
1749
1750 # Set information about the target into the environment
1751 # variable TARGET_INFO. This array will contain a list
1752 # of commands that are necessary to run a target.
1753 #
1754 # This is mostly devined from how dejagnu works, what
1755 # procs are defined, and analyzing unix.exp, monitor.exp,
1756 # and sim.exp.
1757 #
1758 # Array elements exported:
1759 # Index Meaning
1760 # ----- -------
1761 # init list of target/board initialization commands
1762 # target target command for target/board
1763 # load load command for target/board
1764 # run run command for target_board
1765 proc _gdbtk_export_target_info {} {
1766 global env
1767
1768 # Figure out what "target class" the testsuite is using,
1769 # i.e., sim, monitor, native
1770 if {[string compare [info proc gdb_target_monitor] gdb_target_monitor] == 0} {
1771 # Using a monitor/remote target
1772 set target monitor
1773 } elseif {[string compare [info proc gdb_target_sim] gdb_target_sim] == 0} {
1774 # Using a simulator target
1775 set target simulator
1776 } else {
1777 # Assume native
1778 set target native
1779 }
1780
1781 # Now setup the array to be exported.
1782 set info(init) {}
1783 set info(target) {}
1784 set info(load) {}
1785 set info(run) {}
1786
1787 switch $target {
1788 simulator {
1789 set opts "[target_info gdb,target_sim_options]"
1790 set info(target) "target sim $opts"
1791 set info(load) "load"
1792 set info(run) "run"
1793 }
1794
1795 monitor {
1796 # Setup options for the connection
1797 if {[target_info exists baud]} {
1798 lappend info(init) "set remotebaud [target_info baud]"
1799 }
1800 if {[target_info exists binarydownload]} {
1801 lappend info(init) "set remotebinarydownload [target_info binarydownload]"
1802 }
1803 if {[target_info exists disable_x_packet]} {
1804 lappend info(init) "set remote X-packet disable"
1805 }
1806 if {[target_info exists disable_z_packet]} {
1807 lappend info(init) "set remote Z-packet disable"
1808 }
1809
1810 # Get target name and connection info
1811 if {[target_info exists gdb_protocol]} {
1812 set targetname "[target_info gdb_protocol]"
1813 } else {
1814 set targetname "not_specified"
1815 }
1816 if {[target_info exists gdb_serial]} {
1817 set serialport "[target_info gdb_serial]"
1818 } elseif {[target_info exists netport]} {
1819 set serialport "[target_info netport]"
1820 } else {
1821 set serialport "[target_info serial]"
1822 }
1823
1824 set info(target) "target $targetname $serialport"
1825 set info(load) "load"
1826 set info(run) "continue"
1827 }
1828
1829 native {
1830 set info(run) "run"
1831 }
1832 }
1833
1834 # Export the array to the environment
1835 set env(TARGET_INFO) [array get info]
1836 }
1837
1838 # gdbtk tests call this function to print out the results of the
1839 # tests. The argument is a proper list of lists of the form:
1840 # {status name description msg}. All of these things typically
1841 # come from the testsuite harness.
1842 proc gdbtk_analyze_results {results} {
1843 foreach test $results {
1844 set status [lindex $test 0]
1845 set name [lindex $test 1]
1846 set description [lindex $test 2]
1847 set msg [lindex $test 3]
1848
1849 switch $status {
1850 PASS {
1851 pass "$description ($name)"
1852 }
1853
1854 FAIL {
1855 fail "$description ($name)"
1856 }
1857
1858 ERROR {
1859 perror "$name"
1860 }
1861
1862 XFAIL {
1863 xfail "$description ($name)"
1864 }
1865
1866 XPASS {
1867 xpass "$description ($name)"
1868 }
1869 }
1870 }
1871 }
1872
1873 proc gdbtk_done {{results {}}} {
1874 global _xvfb_spawn_id
1875 gdbtk_analyze_results $results
1876
1877 # Kill off xvfb if using it
1878 if {[info exists _xvfb_spawn_id]} {
1879 _gdbtk_xvfb_exit
1880 }
1881 }
1882
1883 # Print a message and return true if a test should be skipped
1884 # due to lack of floating point suport.
1885
1886 proc gdb_skip_float_test { msg } {
1887 if [target_info exists gdb,skip_float_tests] {
1888 verbose "Skipping test '$msg': no float tests.";
1889 return 1;
1890 }
1891 return 0;
1892 }
1893
1894 # Print a message and return true if a test should be skipped
1895 # due to lack of stdio support.
1896
1897 proc gdb_skip_stdio_test { msg } {
1898 if [target_info exists gdb,noinferiorio] {
1899 verbose "Skipping test '$msg': no inferior i/o.";
1900 return 1;
1901 }
1902 return 0;
1903 }
1904
1905 proc gdb_skip_bogus_test { msg } {
1906 return 0;
1907 }
1908
This page took 0.08709 seconds and 5 git commands to generate.