This commit was generated by cvs2svn to track changes on a CVS vendor
[deliverable/binutils-gdb.git] / gdb / testsuite / lib / gdb.exp
1 # Copyright (C) 1992, 1994, 1995, 1997 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 prompt is a regexp which matches the gdb prompt. Set it if it
60 # is not already set.
61 global gdb_prompt
62 if ![info exists prompt] then {
63 set gdb_prompt "\[(\]gdb\[)\]"
64 }
65
66 #
67 # gdb_version -- extract and print the version number of GDB
68 #
69 proc default_gdb_version {} {
70 global GDB
71 global GDBFLAGS
72 global gdb_prompt
73 set fileid [open "gdb_cmd" w];
74 puts $fileid "q";
75 close $fileid;
76 set cmdfile [remote_download host "gdb_cmd"];
77 set output [remote_exec host "$GDB -nw --command $cmdfile"]
78 remote_file build delete "gdb_cmd";
79 remote_file host delete "$cmdfile";
80 set tmp [lindex $output 1];
81 set version ""
82 regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version
83 if ![is_remote host] {
84 clone_output "[which $GDB] version $version $GDBFLAGS\n"
85 } else {
86 clone_output "$GDB on remote host version $version $GDBFLAGS\n"
87 }
88 }
89
90 proc gdb_version { } {
91 return [default_gdb_version];
92 }
93
94 #
95 # gdb_unload -- unload a file if one is loaded
96 #
97
98 proc gdb_unload {} {
99 global verbose
100 global GDB
101 global gdb_prompt
102 send_gdb "file\n"
103 gdb_expect 60 {
104 -re "No exec file now\[^\r\n\]*\[\r\n\]" { exp_continue }
105 -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue }
106 -re "A program is being debugged already..*Kill it.*y or n. $"\
107 { send_gdb "y\n"
108 verbose "\t\tKilling previous program being debugged"
109 exp_continue
110 }
111 -re "Discard symbol table from .*y or n.*$" {
112 send_gdb "y\n"
113 exp_continue
114 }
115 -re "$gdb_prompt $" {}
116 timeout {
117 perror "couldn't unload file in $GDB (timed out)."
118 return -1
119 }
120 }
121 }
122
123 # Many of the tests depend on setting breakpoints at various places and
124 # running until that breakpoint is reached. At times, we want to start
125 # with a clean-slate with respect to breakpoints, so this utility proc
126 # lets us do this without duplicating this code everywhere.
127 #
128
129 proc delete_breakpoints {} {
130 global gdb_prompt
131
132 send_gdb "delete breakpoints\n"
133 gdb_expect 30 {
134 -re "Delete all breakpoints.*y or n.*$" {
135 send_gdb "y\n";
136 exp_continue
137 }
138 -re "$gdb_prompt $" { # This happens if there were no breakpoints
139 }
140 timeout { perror "Delete all breakpoints in delete_breakpoints (timeout)" ; return }
141 }
142 send_gdb "info breakpoints\n"
143 gdb_expect 30 {
144 -re "No breakpoints or watchpoints..*$gdb_prompt $" {}
145 -re "$gdb_prompt $" { perror "breakpoints not deleted" ; return }
146 -re "Delete all breakpoints.*or n.*$" {
147 send_gdb "y\n";
148 exp_continue
149 }
150 timeout { perror "info breakpoints (timeout)" ; return }
151 }
152 }
153
154
155 #
156 # Generic run command.
157 #
158 # The second pattern below matches up to the first newline *only*.
159 # Using ``.*$'' could swallow up output that we attempt to match
160 # elsewhere.
161 #
162 proc gdb_run_cmd {args} {
163 global gdb_prompt
164
165 if [target_info exists gdb_init_command] {
166 send_gdb "[target_info gdb_init_command]\n";
167 gdb_expect 30 {
168 -re "$gdb_prompt $" { }
169 default {
170 perror "gdb_init_command for target failed";
171 return;
172 }
173 }
174 }
175
176 if [target_info exists use_gdb_stub] {
177 if [target_info exists gdb,do_reload_on_run] {
178 # According to Stu, this will always work.
179 gdb_load "";
180 send_gdb "continue\n";
181 gdb_expect 60 {
182 -re "Continu\[^\r\n\]*\[\r\n\]" {}
183 default {}
184 }
185 return;
186 }
187
188 if [target_info exists gdb,start_symbol] {
189 set start [target_info gdb,start_symbol];
190 } else {
191 set start "start";
192 }
193 send_gdb "jump *$start\n"
194 gdb_expect 30 {
195 -re "Continuing at \[^\r\n\]*\[\r\n\]" {
196 if ![target_info exists gdb_stub] {
197 return;
198 }
199 }
200 -re "No symbol \"start\" in current.*$gdb_prompt $" {
201 send_gdb "jump *_start\n";
202 exp_continue;
203 }
204 -re "No symbol \"_start\" in current.*$gdb_prompt $" {
205 perror "Can't find start symbol to run in gdb_run";
206 return;
207 }
208 -re "Line.* Jump anyway.*y or n. $" {
209 send_gdb "y\n"
210 exp_continue;
211 }
212 -re "No symbol.*context.*$gdb_prompt $" {}
213 -re "The program is not being run.*$gdb_prompt $" {
214 gdb_load "";
215 send_gdb "jump *$start\n";
216 exp_continue;
217 }
218 timeout { perror "Jump to start() failed (timeout)"; return }
219 }
220 if [target_info exists gdb_stub] {
221 gdb_expect 60 {
222 -re "$gdb_prompt $" {
223 send_gdb "continue\n"
224 }
225 }
226 }
227 return
228 }
229 send_gdb "run $args\n"
230 # This doesn't work quite right yet.
231 gdb_expect 60 {
232 -re "The program .* has been started already.*y or n. $" {
233 send_gdb "y\n"
234 exp_continue
235 }
236 -re "Starting program: \[^\r\n\]*" {}
237 }
238 }
239
240 proc gdb_breakpoint { function } {
241 global gdb_prompt
242 global decimal
243
244 send_gdb "break $function\n"
245 # The first two regexps are what we get with -g, the third is without -g.
246 gdb_expect 30 {
247 -re "Breakpoint \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {}
248 -re "Breakpoint \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {}
249 -re "Breakpoint \[0-9\]* at .*$gdb_prompt $" {}
250 -re "$gdb_prompt $" { fail "setting breakpoint at $function" ; return 0 }
251 timeout { fail "setting breakpoint at $function (timeout)" ; return 0 }
252 }
253 return 1;
254 }
255
256 # Set breakpoint at function and run gdb until it breaks there.
257 # Since this is the only breakpoint that will be set, if it stops
258 # at a breakpoint, we will assume it is the one we want. We can't
259 # just compare to "function" because it might be a fully qualified,
260 # single quoted C++ function specifier.
261
262 proc runto { function } {
263 global gdb_prompt
264 global decimal
265
266 delete_breakpoints
267
268 if ![gdb_breakpoint $function] {
269 return 0;
270 }
271
272 gdb_run_cmd
273
274 # the "at foo.c:36" output we get with -g.
275 # the "in func" output we get without -g.
276 gdb_expect 30 {
277 -re "Break.* at .*:$decimal.*$gdb_prompt $" {
278 return 1
279 }
280 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" {
281 return 1
282 }
283 -re "$gdb_prompt $" {
284 fail "running to $function in runto"
285 return 0
286 }
287 timeout {
288 fail "running to $function in runto (timeout)"
289 return 0
290 }
291 }
292 return 1
293 }
294
295 #
296 # runto_main -- ask gdb to run until we hit a breakpoint at main.
297 # The case where the target uses stubs has to be handled
298 # specially--if it uses stubs, assuming we hit
299 # breakpoint() and just step out of the function.
300 #
301 proc runto_main { } {
302 global gdb_prompt
303 global decimal
304
305 if ![target_info exists gdb_stub] {
306 return [runto main]
307 }
308
309 delete_breakpoints
310
311 gdb_step_for_stub;
312
313 return 1
314 }
315
316 #
317 # gdb_test -- send_gdb a command to gdb and test the result.
318 # Takes three parameters.
319 # Parameters:
320 # First one is the command to execute. If this is the null string
321 # then no command is sent.
322 # Second one is the pattern to match for a PASS, and must NOT include
323 # the \r\n sequence immediately before the gdb prompt.
324 # Third one is an optional message to be printed. If this
325 # a null string "", then the pass/fail messages use the command
326 # string as the message.
327 # Returns:
328 # 1 if the test failed,
329 # 0 if the test passes,
330 # -1 if there was an internal error.
331 #
332 proc gdb_test { args } {
333 global verbose
334 global gdb_prompt
335 global GDB
336 upvar timeout timeout
337
338 if [llength $args]>2 then {
339 set message [lindex $args 2]
340 } else {
341 set message [lindex $args 0]
342 }
343 set command [lindex $args 0]
344 set pattern [lindex $args 1]
345
346 if [llength $args]==5 {
347 set question_string [lindex $args 3];
348 set response_string [lindex $args 4];
349 } else {
350 set question_string "^FOOBAR$"
351 }
352
353 if $verbose>2 then {
354 send_user "Sending \"$command\" to gdb\n"
355 send_user "Looking to match \"$pattern\"\n"
356 send_user "Message is \"$message\"\n"
357 }
358
359 set result -1
360 set string "${command}\n";
361 if { $command != "" } {
362 while { "$string" != "" } {
363 set foo [string first "\n" "$string"];
364 set len [string length "$string"];
365 if { $foo < [expr $len - 1] } {
366 set str [string range "$string" 0 $foo];
367 if { [send_gdb "$str"] != "" } {
368 global suppress_flag;
369
370 if { ! $suppress_flag } {
371 perror "Couldn't send $command to GDB.";
372 }
373 fail "$message";
374 return $result;
375 }
376 gdb_expect 2 {
377 -re "\[\r\n\]" { }
378 timeout { }
379 }
380 set string [string range "$string" [expr $foo + 1] end];
381 } else {
382 break;
383 }
384 }
385 if { "$string" != "" } {
386 if { [send_gdb "$string"] != "" } {
387 global suppress_flag;
388
389 if { ! $suppress_flag } {
390 perror "Couldn't send $command to GDB.";
391 }
392 fail "$message";
393 return $result;
394 }
395 }
396 }
397
398 if [info exists timeout] {
399 set tmt $timeout;
400 } else {
401 global timeout;
402 if [info exists timeout] {
403 set tmt $timeout;
404 } else {
405 set tmt 60;
406 }
407 }
408 gdb_expect $tmt {
409 -re "Ending remote debugging.*$gdb_prompt$" {
410 if ![isnative] then {
411 warning "Can`t communicate to remote target."
412 }
413 gdb_exit
414 gdb_start
415 set result -1
416 }
417 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
418 if ![string match "" $message] then {
419 pass "$message"
420 }
421 set result 0
422 }
423 -re "(${question_string})$" {
424 send_gdb "$response_string\n";
425 exp_continue;
426 }
427 -re "Undefined command:.*$gdb_prompt" {
428 perror "Undefined command \"$command\"."
429 set result 1
430 }
431 -re "Ambiguous command.*$gdb_prompt $" {
432 perror "\"$command\" is not a unique command name."
433 set result 1
434 }
435 -re "Program exited with code \[0-9\]+.*$gdb_prompt $" {
436 if ![string match "" $message] then {
437 set errmsg "$message: the program exited"
438 } else {
439 set errmsg "$command: the program exited"
440 }
441 fail "$errmsg"
442 return -1
443 }
444 -re "The program is not being run.*$gdb_prompt $" {
445 if ![string match "" $message] then {
446 set errmsg "$message: the program is no longer running"
447 } else {
448 set errmsg "$command: the program is no longer running"
449 }
450 fail "$errmsg"
451 return -1
452 }
453 -re ".*$gdb_prompt $" {
454 if ![string match "" $message] then {
455 fail "$message"
456 }
457 set result 1
458 }
459 "<return>" {
460 send_gdb "\n"
461 perror "Window too small."
462 }
463 -re "\\(y or n\\) " {
464 send_gdb "n\n"
465 perror "Got interactive prompt."
466 }
467 eof {
468 perror "Process no longer exists"
469 if { $message != "" } {
470 fail "$message"
471 }
472 return -1
473 }
474 full_buffer {
475 perror "internal buffer is full."
476 }
477 timeout {
478 if ![string match "" $message] then {
479 fail "$message (timeout)"
480 }
481 set result 1
482 }
483 }
484 return $result
485 }
486 \f
487 # Test that a command gives an error. For pass or fail, return
488 # a 1 to indicate that more tests can proceed. However a timeout
489 # is a serious error, generates a special fail message, and causes
490 # a 0 to be returned to indicate that more tests are likely to fail
491 # as well.
492
493 proc test_print_reject { args } {
494 global gdb_prompt
495 global verbose
496
497 if [llength $args]==2 then {
498 set expectthis [lindex $args 1]
499 } else {
500 set expectthis "should never match this bogus string"
501 }
502 set sendthis [lindex $args 0]
503 if $verbose>2 then {
504 send_user "Sending \"$sendthis\" to gdb\n"
505 send_user "Looking to match \"$expectthis\"\n"
506 }
507 send_gdb "$sendthis\n"
508 #FIXME: Should add timeout as parameter.
509 gdb_expect {
510 -re "A .* in expression.*\\.*$gdb_prompt $" {
511 pass "reject $sendthis"
512 return 1
513 }
514 -re "Invalid syntax in expression.*$gdb_prompt $" {
515 pass "reject $sendthis"
516 return 1
517 }
518 -re "Junk after end of expression.*$gdb_prompt $" {
519 pass "reject $sendthis"
520 return 1
521 }
522 -re "Invalid number.*$gdb_prompt $" {
523 pass "reject $sendthis"
524 return 1
525 }
526 -re "Invalid character constant.*$gdb_prompt $" {
527 pass "reject $sendthis"
528 return 1
529 }
530 -re "No symbol table is loaded.*$gdb_prompt $" {
531 pass "reject $sendthis"
532 return 1
533 }
534 -re "No symbol .* in current context.*$gdb_prompt $" {
535 pass "reject $sendthis"
536 return 1
537 }
538 -re "$expectthis.*$gdb_prompt $" {
539 pass "reject $sendthis"
540 return 1
541 }
542 -re ".*$gdb_prompt $" {
543 fail "reject $sendthis"
544 return 1
545 }
546 default {
547 fail "reject $sendthis (eof or timeout)"
548 return 0
549 }
550 }
551 }
552 \f
553 # Given an input string, adds backslashes as needed to create a
554 # regexp that will match the string.
555
556 proc string_to_regexp {str} {
557 set result $str
558 regsub -all {[]*+.|()^$\[]} $str {\\&} result
559 return $result
560 }
561
562 # Same as gdb_test, but the second parameter is not a regexp,
563 # but a string that must match exactly.
564
565 proc gdb_test_exact { args } {
566 upvar timeout timeout
567
568 set command [lindex $args 0]
569
570 # This applies a special meaning to a null string pattern. Without
571 # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
572 # messages from commands that should have no output except a new
573 # prompt. With this, only results of a null string will match a null
574 # string pattern.
575
576 set pattern [lindex $args 1]
577 if [string match $pattern ""] {
578 set pattern [string_to_regexp [lindex $args 0]]
579 } else {
580 set pattern [string_to_regexp [lindex $args 1]]
581 }
582
583 # It is most natural to write the pattern argument with only
584 # embedded \n's, especially if you are trying to avoid Tcl quoting
585 # problems. But gdb_expect really wants to see \r\n in patterns. So
586 # transform the pattern here. First transform \r\n back to \n, in
587 # case some users of gdb_test_exact already do the right thing.
588 regsub -all "\r\n" $pattern "\n" pattern
589 regsub -all "\n" $pattern "\r\n" pattern
590 if [llength $args]==3 then {
591 set message [lindex $args 2]
592 } else {
593 set message $command
594 }
595
596 return [gdb_test $command $pattern $message]
597 }
598 \f
599 proc gdb_reinitialize_dir { subdir } {
600 global gdb_prompt
601
602 if [is_remote host] {
603 return "";
604 }
605 send_gdb "dir\n"
606 gdb_expect 60 {
607 -re "Reinitialize source path to empty.*y or n. " {
608 send_gdb "y\n"
609 gdb_expect 60 {
610 -re "Source directories searched.*$gdb_prompt $" {
611 send_gdb "dir $subdir\n"
612 gdb_expect 60 {
613 -re "Source directories searched.*$gdb_prompt $" {
614 verbose "Dir set to $subdir"
615 }
616 -re "$gdb_prompt $" {
617 perror "Dir \"$subdir\" failed."
618 }
619 }
620 }
621 -re "$gdb_prompt $" {
622 perror "Dir \"$subdir\" failed."
623 }
624 }
625 }
626 -re "$gdb_prompt $" {
627 perror "Dir \"$subdir\" failed."
628 }
629 }
630 }
631
632 #
633 # gdb_exit -- exit the GDB, killing the target program if necessary
634 #
635 proc default_gdb_exit {} {
636 global GDB
637 global GDBFLAGS
638 global verbose
639 global gdb_spawn_id;
640
641 gdb_stop_suppressing_tests;
642
643 if ![info exists gdb_spawn_id] {
644 return;
645 }
646
647 verbose "Quitting $GDB $GDBFLAGS"
648
649 if { [is_remote host] && [board_info host exists fileid] } {
650 send_gdb "quit\n";
651 gdb_expect 10 {
652 -re "y or n" {
653 send_gdb "y\n";
654 exp_continue;
655 }
656 -re "DOSEXIT code" { }
657 default { }
658 }
659 }
660
661 if ![is_remote host] {
662 remote_close host;
663 }
664 unset gdb_spawn_id
665 }
666
667 #
668 # load a file into the debugger.
669 # return a -1 if anything goes wrong.
670 #
671 proc gdb_file_cmd { arg } {
672 global verbose
673 global loadpath
674 global loadfile
675 global GDB
676 global gdb_prompt
677 upvar timeout timeout
678
679 if [is_remote host] {
680 set arg [remote_download host $arg];
681 if { $arg == "" } {
682 error "download failed"
683 return -1;
684 }
685 }
686
687 send_gdb "file $arg\n"
688 gdb_expect 120 {
689 -re "Reading symbols from.*done.*$gdb_prompt $" {
690 verbose "\t\tLoaded $arg into the $GDB"
691 return 0
692 }
693 -re "has no symbol-table.*$gdb_prompt $" {
694 perror "$arg wasn't compiled with \"-g\""
695 return -1
696 }
697 -re "A program is being debugged already.*Kill it.*y or n. $" {
698 send_gdb "y\n"
699 verbose "\t\tKilling previous program being debugged"
700 exp_continue
701 }
702 -re "Load new symbol table from \".*\".*y or n. $" {
703 send_gdb "y\n"
704 gdb_expect 120 {
705 -re "Reading symbols from.*done.*$gdb_prompt $" {
706 verbose "\t\tLoaded $arg with new symbol table into $GDB"
707 return 0
708 }
709 timeout {
710 perror "(timeout) Couldn't load $arg, other program already loaded."
711 return -1
712 }
713 }
714 }
715 -re "No such file or directory.*$gdb_prompt $" {
716 perror "($arg) No such file or directory\n"
717 return -1
718 }
719 -re "$gdb_prompt $" {
720 perror "couldn't load $arg into $GDB."
721 return -1
722 }
723 timeout {
724 perror "couldn't load $arg into $GDB (timed out)."
725 return -1
726 }
727 eof {
728 # This is an attempt to detect a core dump, but seems not to
729 # work. Perhaps we need to match .* followed by eof, in which
730 # gdb_expect does not seem to have a way to do that.
731 perror "couldn't load $arg into $GDB (end of file)."
732 return -1
733 }
734 }
735 }
736
737 #
738 # start gdb -- start gdb running, default procedure
739 #
740 # When running over NFS, particularly if running many simultaneous
741 # tests on different hosts all using the same server, things can
742 # get really slow. Give gdb at least 3 minutes to start up.
743 #
744 proc default_gdb_start { } {
745 global verbose
746 global GDB
747 global GDBFLAGS
748 global gdb_prompt
749 global timeout
750 global gdb_spawn_id;
751
752 gdb_stop_suppressing_tests;
753
754 verbose "Spawning $GDB -nw $GDBFLAGS"
755
756 if [info exists gdb_spawn_id] {
757 return 0;
758 }
759
760 if ![is_remote host] {
761 if { [which $GDB] == 0 } then {
762 perror "$GDB does not exist."
763 exit 1
764 }
765 }
766 set res [remote_spawn host "$GDB -nw $GDBFLAGS [host_info gdb_opts]"];
767 if { $res < 0 || $res == "" } {
768 perror "Spawning $GDB failed."
769 return 1;
770 }
771 gdb_expect 360 {
772 -re "\[\r\n\]$gdb_prompt $" {
773 verbose "GDB initialized."
774 }
775 -re "$gdb_prompt $" {
776 perror "GDB never initialized."
777 return -1
778 }
779 timeout {
780 perror "(timeout) GDB never initialized after 10 seconds."
781 remote_close host;
782 return -1
783 }
784 }
785 set gdb_spawn_id -1;
786 # force the height to "unlimited", so no pagers get used
787
788 send_gdb "set height 0\n"
789 gdb_expect 10 {
790 -re "$gdb_prompt $" {
791 verbose "Setting height to 0." 2
792 }
793 timeout {
794 warning "Couldn't set the height to 0"
795 }
796 }
797 # force the width to "unlimited", so no wraparound occurs
798 send_gdb "set width 0\n"
799 gdb_expect 10 {
800 -re "$gdb_prompt $" {
801 verbose "Setting width to 0." 2
802 }
803 timeout {
804 warning "Couldn't set the width to 0."
805 }
806 }
807 return 0;
808 }
809
810 # * For crosses, the CHILL runtime doesn't build because it can't find
811 # setjmp.h, stdio.h, etc.
812 # * For AIX (as of 16 Mar 95), (a) there is no language code for
813 # CHILL in output_epilog in gcc/config/rs6000/rs6000.c, (b) collect2
814 # does not get along with AIX's too-clever linker.
815 # * On Irix5, there is a bug whereby set of bool, etc., don't get
816 # TYPE_LOW_BOUND for the bool right because force_to_range_type doesn't
817 # work with stub types.
818 # Lots of things seem to fail on the PA, and since it's not a supported
819 # chill target at the moment, don't run the chill tests.
820
821 proc skip_chill_tests {} {
822 if ![info exists do_chill_tests] {
823 return 1;
824 }
825 eval set skip_chill [expr ![isnative] || [istarget "*-*-aix*"] || [istarget "*-*-irix5*"] || [istarget "*-*-irix6*"] || [istarget "alpha-*-osf*"] || [istarget "hppa*-*-*"]]
826 verbose "Skip chill tests is $skip_chill"
827 return $skip_chill
828 }
829
830 proc get_compiler_info {binfile} {
831 # Create and source the file that provides information about the compiler
832 # used to compile the test case.
833 global srcdir
834 global subdir
835 # These two come from compiler.c.
836 global signed_keyword_not_used
837 global gcc_compiled
838
839 if { [gdb_compile "${srcdir}/${subdir}/compiler.c" "${binfile}.ci" preprocess {}] != "" } {
840 perror "Couldn't make ${binfile}.ci file"
841 return 1;
842 }
843 source ${binfile}.ci
844 return 0;
845 }
846
847 proc gdb_compile {source dest type options} {
848 global GDB_TESTCASE_OPTIONS;
849
850 if [target_info exists gdb_stub] {
851 set options2 { "additional_flags=-Dusestubs" }
852 lappend options "libs=[target_info gdb_stub]";
853 set options [concat $options2 $options]
854 }
855 if [target_info exists is_vxworks] {
856 set options2 { "additional_flags=-Dvxworks" }
857 lappend options "libs=[target_info gdb_stub]";
858 set options [concat $options2 $options]
859 }
860 if [info exists GDB_TESTCASE_OPTIONS] {
861 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS";
862 }
863 verbose "options are $options"
864 verbose "source is $source $dest $type $options"
865 set result [target_compile $source $dest $type $options];
866 regsub "\[\r\n\]*$" "$result" "" result;
867 regsub "^\[\r\n\]*" "$result" "" result;
868 if { $result != "" } {
869 clone_output "gdb compile failed, $result"
870 }
871 return $result;
872 }
873
874 proc send_gdb { string } {
875 global suppress_flag;
876 if { $suppress_flag } {
877 return "suppressed";
878 }
879 return [remote_send host "$string"];
880 }
881
882 #
883 #
884
885 proc gdb_expect { args } {
886 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
887 set gtimeout [lindex $args 0];
888 set expcode [list [lindex $args 1]];
889 } else {
890 upvar timeout timeout;
891
892 set expcode $args;
893 if [target_info exists gdb,timeout] {
894 if [info exists timeout] {
895 if { $timeout < [target_info gdb,timeout] } {
896 set gtimeout [target_info gdb,timeout];
897 } else {
898 set gtimeout $timeout;
899 }
900 } else {
901 set gtimeout [target_info gdb,timeout];
902 }
903 }
904
905 if ![info exists gtimeout] {
906 global timeout;
907 if [info exists timeout] {
908 set gtimeout $timeout;
909 } else {
910 # Eeeeew.
911 set gtimeout 60;
912 }
913 }
914 }
915 global suppress_flag;
916 global remote_suppress_flag;
917 if [info exists remote_suppress_flag] {
918 set old_val $remote_suppress_flag;
919 }
920 if [info exists suppress_flag] {
921 if { $suppress_flag } {
922 set remote_suppress_flag 1;
923 }
924 }
925 set code [catch {uplevel remote_expect host $gtimeout $expcode} string];
926 if [info exists old_val] {
927 set remote_suppress_flag $old_val;
928 } else {
929 if [info exists remote_suppress_flag] {
930 unset remote_suppress_flag;
931 }
932 }
933
934 if {$code == 1} {
935 global errorInfo errorCode;
936
937 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
938 } elseif {$code == 2} {
939 return -code return $string
940 } elseif {$code == 3} {
941 return
942 } elseif {$code > 4} {
943 return -code $code $string
944 }
945 }
946
947 proc gdb_suppress_entire_file { reason } {
948 global suppress_flag;
949
950 warning "$reason\n";
951 set suppress_flag -1;
952 }
953
954 #
955 # Set suppress_flag, which will cause all subsequent calls to send_gdb and
956 # gdb_expect to fail immediately (until the next call to
957 # gdb_stop_suppressing_tests).
958 #
959 proc gdb_suppress_tests { args } {
960 global suppress_flag;
961
962 return; # fnf - disable pending review of results where testsuite ran better without this
963 incr suppress_flag;
964
965 if { $suppress_flag == 1 } {
966 if { [llength $args] > 0 } {
967 warning "[lindex $args 0]\n";
968 } else {
969 warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n";
970 }
971 }
972 }
973
974 #
975 # Clear suppress_flag.
976 #
977 proc gdb_stop_suppressing_tests { } {
978 global suppress_flag;
979
980 if [info exists suppress_flag] {
981 if { $suppress_flag > 0 } {
982 set suppress_flag 0;
983 clone_output "Tests restarted.\n";
984 }
985 } else {
986 set suppress_flag 0;
987 }
988 }
989
990 proc gdb_clear_suppressed { } {
991 global suppress_flag;
992
993 set suppress_flag 0;
994 }
995
996 proc gdb_start { } {
997 default_gdb_start
998 }
999
1000 proc gdb_exit { } {
1001 catch default_gdb_exit
1002 }
1003
1004 #
1005 # gdb_load -- load a file into the debugger.
1006 # return a -1 if anything goes wrong.
1007 #
1008 proc gdb_load { arg } {
1009 return [gdb_file_cmd $arg]
1010 }
1011
1012 proc gdb_continue { function } {
1013 global decimal
1014
1015 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"];
1016 }
1017
1018 proc default_gdb_init { args } {
1019 gdb_clear_suppressed;
1020
1021 # Uh, this is lame. Really, really, really lame. But there's this *one*
1022 # testcase that will fail in random places if we don't increase this.
1023 match_max -d 20000
1024
1025 # We want to add the name of the TCL testcase to the PASS/FAIL messages.
1026 if { [llength $args] > 0 } {
1027 global pf_prefix
1028
1029 set file [lindex $args 0];
1030
1031 set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:";
1032 }
1033 global gdb_prompt;
1034 if [target_info exists gdb_prompt] {
1035 set gdb_prompt [target_info gdb_prompt];
1036 } else {
1037 set gdb_prompt "\\(gdb\\)"
1038 }
1039 }
1040
1041 proc gdb_init { args } {
1042 return [eval default_gdb_init $args];
1043 }
1044
1045 proc gdb_finish { } {
1046 gdb_exit;
1047 }
1048
1049 global debug_format
1050
1051 # Run the gdb command "info source" and extract the debugging format information
1052 # from the output and save it in debug_format.
1053
1054 proc get_debug_format { } {
1055 global gdb_prompt
1056 global verbose
1057 global expect_out
1058 global debug_format
1059
1060 set debug_format "unknown"
1061 send_gdb "info source\n"
1062 gdb_expect 10 {
1063 -re "Compiled with (.*) debugging format.\r\n$gdb_prompt $" {
1064 set debug_format $expect_out(1,string)
1065 verbose "debug format is $debug_format"
1066 return 1;
1067 }
1068 -re "No current source file.\r\n$gdb_prompt $" {
1069 perror "get_debug_format used when no current source file"
1070 return 0;
1071 }
1072 -re "$gdb_prompt $" {
1073 warning "couldn't check debug format (no valid response)."
1074 return 1;
1075 }
1076 timeout {
1077 warning "couldn't check debug format (timed out)."
1078 return 1;
1079 }
1080 }
1081 }
1082
1083 # Like setup_xfail, but takes the name of a debug format (DWARF 1, COFF, stabs, etc).
1084 # If that format matches the format that the current test was compiled with, then
1085 # the next test is expected to fail for any target. Returns 1 if the next test or
1086 # set of tests is expected to fail, 0 otherwise (or if it is unknown). Must
1087 # have previously called get_debug_format.
1088
1089 proc setup_xfail_format { format } {
1090 global debug_format
1091
1092 if [string match $debug_format $format] then {
1093 setup_xfail "*-*-*"
1094 return 1;
1095 }
1096 return 0
1097 }
1098
1099 proc gdb_step_for_stub { } {
1100 global gdb_prompt;
1101
1102 if ![target_info exists gdb,use_breakpoint_for_stub] {
1103 if [target_info exists gdb_stub_step_command] {
1104 set command [target_info gdb_stub_step_command];
1105 } else {
1106 set command "step";
1107 }
1108 send_gdb "${command}\n";
1109 set tries 0;
1110 gdb_expect 60 {
1111 -re "(main.* at |.*in .*start).*$gdb_prompt" {
1112 return;
1113 }
1114 -re ".*$gdb_prompt" {
1115 incr tries;
1116 if { $tries == 5 } {
1117 fail "stepping out of breakpoint function";
1118 return;
1119 }
1120 send_gdb "${command}\n";
1121 exp_continue;
1122 }
1123 default {
1124 fail "stepping out of breakpoint function";
1125 return;
1126 }
1127 }
1128 }
1129 send_gdb "where\n";
1130 gdb_expect {
1131 -re "main\[^\r\n\]*at \(\[^:]+\):\(\[0-9\]+\)" {
1132 set file $expect_out(1,string);
1133 set linenum [expr $expect_out(2,string) + 1];
1134 set breakplace "${file}:${linenum}";
1135 }
1136 default {}
1137 }
1138 send_gdb "break ${breakplace}\n";
1139 gdb_expect 60 {
1140 -re "Breakpoint (\[0-9\]+) at.*$gdb_prompt" {
1141 set breakpoint $expect_out(1,string);
1142 }
1143 -re "Breakpoint (\[0-9\]+): file.*$gdb_prompt" {
1144 set breakpoint $expect_out(1,string);
1145 }
1146 default {}
1147 }
1148 send_gdb "continue\n";
1149 gdb_expect 60 {
1150 -re "Breakpoint ${breakpoint},.*$gdb_prompt" {
1151 gdb_test "delete $breakpoint" ".*" "";
1152 return;
1153 }
1154 default {}
1155 }
1156 }
This page took 0.054268 seconds and 5 git commands to generate.