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