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