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