]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/lib/gdb.exp
gdb/testsuite/
[thirdparty/binutils-gdb.git] / gdb / testsuite / lib / gdb.exp
1 # Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
2 # 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
3 # Free Software Foundation, Inc.
4
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 # This file was written by Fred Fish. (fnf@cygnus.com)
19
20 # Generic gdb subroutines that should work for any target. If these
21 # need to be modified for any target, it can be done with a variable
22 # or by passing arguments.
23
24 if {$tool == ""} {
25 # Tests would fail, logs on get_compiler_info() would be missing.
26 send_error "`site.exp' not found, run `make site.exp'!\n"
27 exit 2
28 }
29
30 load_lib libgloss.exp
31
32 global GDB
33
34 if [info exists TOOL_EXECUTABLE] {
35 set GDB $TOOL_EXECUTABLE;
36 }
37 if ![info exists GDB] {
38 if ![is_remote host] {
39 set GDB [findfile $base_dir/../../gdb/gdb "$base_dir/../../gdb/gdb" [transform gdb]]
40 } else {
41 set GDB [transform gdb];
42 }
43 }
44 verbose "using GDB = $GDB" 2
45
46 # GDBFLAGS is available for the user to set on the command line.
47 # E.g. make check RUNTESTFLAGS=GDBFLAGS=mumble
48 # Testcases may use it to add additional flags, but they must:
49 # - append new flags, not overwrite
50 # - restore the original value when done
51 global GDBFLAGS
52 if ![info exists GDBFLAGS] {
53 set GDBFLAGS ""
54 }
55 verbose "using GDBFLAGS = $GDBFLAGS" 2
56
57 # INTERNAL_GDBFLAGS contains flags that the testsuite requires.
58 global INTERNAL_GDBFLAGS
59 if ![info exists INTERNAL_GDBFLAGS] {
60 set INTERNAL_GDBFLAGS "-nw -nx -data-directory [pwd]/../data-directory"
61 }
62
63 # The variable gdb_prompt is a regexp which matches the gdb prompt.
64 # Set it if it is not already set.
65 global gdb_prompt
66 if ![info exists gdb_prompt] then {
67 set gdb_prompt "\[(\]gdb\[)\]"
68 }
69
70 # The variable fullname_syntax_POSIX is a regexp which matches a POSIX
71 # absolute path ie. /foo/
72 set fullname_syntax_POSIX {/[^\n]*/}
73 # The variable fullname_syntax_UNC is a regexp which matches a Windows
74 # UNC path ie. \\D\foo\
75 set fullname_syntax_UNC {\\\\[^\\]+\\[^\n]+\\}
76 # The variable fullname_syntax_DOS_CASE is a regexp which matches a
77 # particular DOS case that GDB most likely will output
78 # ie. \foo\, but don't match \\.*\
79 set fullname_syntax_DOS_CASE {\\[^\\][^\n]*\\}
80 # The variable fullname_syntax_DOS is a regexp which matches a DOS path
81 # ie. a:\foo\ && a:foo\
82 set fullname_syntax_DOS {[a-zA-Z]:[^\n]*\\}
83 # The variable fullname_syntax is a regexp which matches what GDB considers
84 # an absolute path. It is currently debatable if the Windows style paths
85 # d:foo and \abc should be considered valid as an absolute path.
86 # Also, the purpse of this regexp is not to recognize a well formed
87 # absolute path, but to say with certainty that a path is absolute.
88 set fullname_syntax "($fullname_syntax_POSIX|$fullname_syntax_UNC|$fullname_syntax_DOS_CASE|$fullname_syntax_DOS)"
89
90 # Needed for some tests under Cygwin.
91 global EXEEXT
92 global env
93
94 if ![info exists env(EXEEXT)] {
95 set EXEEXT ""
96 } else {
97 set EXEEXT $env(EXEEXT)
98 }
99
100 set octal "\[0-7\]+"
101
102 set inferior_exited_re "(\\\[Inferior \[0-9\]+ \\(.*\\) exited)"
103
104 ### Only procedures should come after this point.
105
106 #
107 # gdb_version -- extract and print the version number of GDB
108 #
109 proc default_gdb_version {} {
110 global GDB
111 global INTERNAL_GDBFLAGS GDBFLAGS
112 global gdb_prompt
113 set output [remote_exec host "$GDB $INTERNAL_GDBFLAGS --version"]
114 set tmp [lindex $output 1];
115 set version ""
116 regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version
117 if ![is_remote host] {
118 clone_output "[which $GDB] version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n"
119 } else {
120 clone_output "$GDB on remote host version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n"
121 }
122 }
123
124 proc gdb_version { } {
125 return [default_gdb_version];
126 }
127
128 #
129 # gdb_unload -- unload a file if one is loaded
130 #
131
132 proc gdb_unload {} {
133 global verbose
134 global GDB
135 global gdb_prompt
136 send_gdb "file\n"
137 gdb_expect 60 {
138 -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue }
139 -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue }
140 -re "A program is being debugged already.*Are you sure you want to change the file.*y or n. $" {
141 send_gdb "y\n"
142 exp_continue
143 }
144 -re "Discard symbol table from .*y or n.*$" {
145 send_gdb "y\n"
146 exp_continue
147 }
148 -re "$gdb_prompt $" {}
149 timeout {
150 perror "couldn't unload file in $GDB (timed out)."
151 return -1
152 }
153 }
154 }
155
156 # Many of the tests depend on setting breakpoints at various places and
157 # running until that breakpoint is reached. At times, we want to start
158 # with a clean-slate with respect to breakpoints, so this utility proc
159 # lets us do this without duplicating this code everywhere.
160 #
161
162 proc delete_breakpoints {} {
163 global gdb_prompt
164
165 # we need a larger timeout value here or this thing just confuses
166 # itself. May need a better implementation if possible. - guo
167 #
168 send_gdb "delete breakpoints\n"
169 gdb_expect 100 {
170 -re "Delete all breakpoints.*y or n.*$" {
171 send_gdb "y\n";
172 exp_continue
173 }
174 -re "$gdb_prompt $" { # This happens if there were no breakpoints
175 }
176 timeout { perror "Delete all breakpoints in delete_breakpoints (timeout)" ; return }
177 }
178 send_gdb "info breakpoints\n"
179 gdb_expect 100 {
180 -re "No breakpoints or watchpoints..*$gdb_prompt $" {}
181 -re "$gdb_prompt $" { perror "breakpoints not deleted" ; return }
182 -re "Delete all breakpoints.*or n.*$" {
183 send_gdb "y\n";
184 exp_continue
185 }
186 timeout { perror "info breakpoints (timeout)" ; return }
187 }
188 }
189
190
191 #
192 # Generic run command.
193 #
194 # The second pattern below matches up to the first newline *only*.
195 # Using ``.*$'' could swallow up output that we attempt to match
196 # elsewhere.
197 #
198 proc gdb_run_cmd {args} {
199 global gdb_prompt
200
201 if [target_info exists gdb_init_command] {
202 send_gdb "[target_info gdb_init_command]\n";
203 gdb_expect 30 {
204 -re "$gdb_prompt $" { }
205 default {
206 perror "gdb_init_command for target failed";
207 return;
208 }
209 }
210 }
211
212 if [target_info exists use_gdb_stub] {
213 if [target_info exists gdb,do_reload_on_run] {
214 if { [gdb_reload] != 0 } {
215 return;
216 }
217 send_gdb "continue\n";
218 gdb_expect 60 {
219 -re "Continu\[^\r\n\]*\[\r\n\]" {}
220 default {}
221 }
222 return;
223 }
224
225 if [target_info exists gdb,start_symbol] {
226 set start [target_info gdb,start_symbol];
227 } else {
228 set start "start";
229 }
230 send_gdb "jump *$start\n"
231 set start_attempt 1;
232 while { $start_attempt } {
233 # Cap (re)start attempts at three to ensure that this loop
234 # always eventually fails. Don't worry about trying to be
235 # clever and not send a command when it has failed.
236 if [expr $start_attempt > 3] {
237 perror "Jump to start() failed (retry count exceeded)";
238 return;
239 }
240 set start_attempt [expr $start_attempt + 1];
241 gdb_expect 30 {
242 -re "Continuing at \[^\r\n\]*\[\r\n\]" {
243 set start_attempt 0;
244 }
245 -re "No symbol \"_start\" in current.*$gdb_prompt $" {
246 perror "Can't find start symbol to run in gdb_run";
247 return;
248 }
249 -re "No symbol \"start\" in current.*$gdb_prompt $" {
250 send_gdb "jump *_start\n";
251 }
252 -re "No symbol.*context.*$gdb_prompt $" {
253 set start_attempt 0;
254 }
255 -re "Line.* Jump anyway.*y or n. $" {
256 send_gdb "y\n"
257 }
258 -re "The program is not being run.*$gdb_prompt $" {
259 if { [gdb_reload] != 0 } {
260 return;
261 }
262 send_gdb "jump *$start\n";
263 }
264 timeout {
265 perror "Jump to start() failed (timeout)";
266 return
267 }
268 }
269 }
270 if [target_info exists gdb_stub] {
271 gdb_expect 60 {
272 -re "$gdb_prompt $" {
273 send_gdb "continue\n"
274 }
275 }
276 }
277 return
278 }
279
280 if [target_info exists gdb,do_reload_on_run] {
281 if { [gdb_reload] != 0 } {
282 return;
283 }
284 }
285 send_gdb "run $args\n"
286 # This doesn't work quite right yet.
287 # Use -notransfer here so that test cases (like chng-sym.exp)
288 # may test for additional start-up messages.
289 gdb_expect 60 {
290 -re "The program .* has been started already.*y or n. $" {
291 send_gdb "y\n"
292 exp_continue
293 }
294 -notransfer -re "Starting program: \[^\r\n\]*" {}
295 -notransfer -re "$gdb_prompt $" {
296 # There is no more input expected.
297 }
298 }
299 }
300
301 # Generic start command. Return 0 if we could start the program, -1
302 # if we could not.
303
304 proc gdb_start_cmd {args} {
305 global gdb_prompt
306
307 if [target_info exists gdb_init_command] {
308 send_gdb "[target_info gdb_init_command]\n";
309 gdb_expect 30 {
310 -re "$gdb_prompt $" { }
311 default {
312 perror "gdb_init_command for target failed";
313 return;
314 }
315 }
316 }
317
318 if [target_info exists use_gdb_stub] {
319 return -1
320 }
321
322 send_gdb "start $args\n"
323 # Use -notransfer here so that test cases (like chng-sym.exp)
324 # may test for additional start-up messages.
325 gdb_expect 60 {
326 -re "The program .* has been started already.*y or n. $" {
327 send_gdb "y\n"
328 exp_continue
329 }
330 -notransfer -re "Starting program: \[^\r\n\]*" {
331 return 0
332 }
333 }
334 return -1
335 }
336
337 # Set a breakpoint at FUNCTION. If there is an additional argument it is
338 # a list of options; the supported options are allow-pending, temporary,
339 # and no-message.
340
341 proc gdb_breakpoint { function args } {
342 global gdb_prompt
343 global decimal
344
345 set pending_response n
346 if {[lsearch -exact [lindex $args 0] allow-pending] != -1} {
347 set pending_response y
348 }
349
350 set break_command "break"
351 set break_message "Breakpoint"
352 if {[lsearch -exact [lindex $args 0] temporary] != -1} {
353 set break_command "tbreak"
354 set break_message "Temporary breakpoint"
355 }
356
357 set no_message 0
358 if {[lsearch -exact [lindex $args 0] no-message] != -1} {
359 set no_message 1
360 }
361
362 send_gdb "$break_command $function\n"
363 # The first two regexps are what we get with -g, the third is without -g.
364 gdb_expect 30 {
365 -re "$break_message \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {}
366 -re "$break_message \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {}
367 -re "$break_message \[0-9\]* at .*$gdb_prompt $" {}
368 -re "$break_message \[0-9\]* \\(.*\\) pending.*$gdb_prompt $" {
369 if {$pending_response == "n"} {
370 if { $no_message == 0 } {
371 fail "setting breakpoint at $function"
372 }
373 return 0
374 }
375 }
376 -re "Make breakpoint pending.*y or \\\[n\\\]. $" {
377 send_gdb "$pending_response\n"
378 exp_continue
379 }
380 -re "A problem internal to GDB has been detected" {
381 fail "setting breakpoint at $function in runto (GDB internal error)"
382 gdb_internal_error_resync
383 return 0
384 }
385 -re "$gdb_prompt $" {
386 if { $no_message == 0 } {
387 fail "setting breakpoint at $function"
388 }
389 return 0
390 }
391 timeout {
392 if { $no_message == 0 } {
393 fail "setting breakpoint at $function (timeout)"
394 }
395 return 0
396 }
397 }
398 return 1;
399 }
400
401 # Set breakpoint at function and run gdb until it breaks there.
402 # Since this is the only breakpoint that will be set, if it stops
403 # at a breakpoint, we will assume it is the one we want. We can't
404 # just compare to "function" because it might be a fully qualified,
405 # single quoted C++ function specifier. If there's an additional argument,
406 # pass it to gdb_breakpoint.
407
408 proc runto { function args } {
409 global gdb_prompt
410 global decimal
411
412 delete_breakpoints
413
414 if ![gdb_breakpoint $function [lindex $args 0]] {
415 return 0;
416 }
417
418 gdb_run_cmd
419
420 # the "at foo.c:36" output we get with -g.
421 # the "in func" output we get without -g.
422 gdb_expect 30 {
423 -re "Break.* at .*:$decimal.*$gdb_prompt $" {
424 return 1
425 }
426 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" {
427 return 1
428 }
429 -re "The target does not support running in non-stop mode.\r\n$gdb_prompt $" {
430 unsupported "Non-stop mode not supported"
431 return 0
432 }
433 -re ".*A problem internal to GDB has been detected" {
434 fail "running to $function in runto (GDB internal error)"
435 gdb_internal_error_resync
436 return 0
437 }
438 -re "$gdb_prompt $" {
439 fail "running to $function in runto"
440 return 0
441 }
442 eof {
443 fail "running to $function in runto (end of file)"
444 return 0
445 }
446 timeout {
447 fail "running to $function in runto (timeout)"
448 return 0
449 }
450 }
451 return 1
452 }
453
454 #
455 # runto_main -- ask gdb to run until we hit a breakpoint at main.
456 # The case where the target uses stubs has to be handled
457 # specially--if it uses stubs, assuming we hit
458 # breakpoint() and just step out of the function.
459 #
460 proc runto_main { } {
461 global gdb_prompt
462 global decimal
463
464 if ![target_info exists gdb_stub] {
465 return [runto main]
466 }
467
468 delete_breakpoints
469
470 gdb_step_for_stub;
471
472 return 1
473 }
474
475
476 ### Continue, and expect to hit a breakpoint.
477 ### Report a pass or fail, depending on whether it seems to have
478 ### worked. Use NAME as part of the test name; each call to
479 ### continue_to_breakpoint should use a NAME which is unique within
480 ### that test file.
481 proc gdb_continue_to_breakpoint {name {location_pattern .*}} {
482 global gdb_prompt
483 set full_name "continue to breakpoint: $name"
484
485 send_gdb "continue\n"
486 gdb_expect {
487 -re "Breakpoint .* (at|in) $location_pattern\r\n$gdb_prompt $" {
488 pass $full_name
489 }
490 -re ".*$gdb_prompt $" {
491 fail $full_name
492 }
493 timeout {
494 fail "$full_name (timeout)"
495 }
496 }
497 }
498
499
500 # gdb_internal_error_resync:
501 #
502 # Answer the questions GDB asks after it reports an internal error
503 # until we get back to a GDB prompt. Decline to quit the debugging
504 # session, and decline to create a core file. Return non-zero if the
505 # resync succeeds.
506 #
507 # This procedure just answers whatever questions come up until it sees
508 # a GDB prompt; it doesn't require you to have matched the input up to
509 # any specific point. However, it only answers questions it sees in
510 # the output itself, so if you've matched a question, you had better
511 # answer it yourself before calling this.
512 #
513 # You can use this function thus:
514 #
515 # gdb_expect {
516 # ...
517 # -re ".*A problem internal to GDB has been detected" {
518 # gdb_internal_error_resync
519 # }
520 # ...
521 # }
522 #
523 proc gdb_internal_error_resync {} {
524 global gdb_prompt
525
526 set count 0
527 while {$count < 10} {
528 gdb_expect {
529 -re "Quit this debugging session\\? \\(y or n\\) $" {
530 send_gdb "n\n"
531 incr count
532 }
533 -re "Create a core file of GDB\\? \\(y or n\\) $" {
534 send_gdb "n\n"
535 incr count
536 }
537 -re "$gdb_prompt $" {
538 # We're resynchronized.
539 return 1
540 }
541 timeout {
542 perror "Could not resync from internal error (timeout)"
543 return 0
544 }
545 }
546 }
547 perror "Could not resync from internal error (resync count exceeded)"
548 return 0
549 }
550
551
552 # gdb_test_multiple COMMAND MESSAGE EXPECT_ARGUMENTS
553 # Send a command to gdb; test the result.
554 #
555 # COMMAND is the command to execute, send to GDB with send_gdb. If
556 # this is the null string no command is sent.
557 # MESSAGE is a message to be printed with the built-in failure patterns
558 # if one of them matches. If MESSAGE is empty COMMAND will be used.
559 # EXPECT_ARGUMENTS will be fed to expect in addition to the standard
560 # patterns. Pattern elements will be evaluated in the caller's
561 # context; action elements will be executed in the caller's context.
562 # Unlike patterns for gdb_test, these patterns should generally include
563 # the final newline and prompt.
564 #
565 # Returns:
566 # 1 if the test failed, according to a built-in failure pattern
567 # 0 if only user-supplied patterns matched
568 # -1 if there was an internal error.
569 #
570 # You can use this function thus:
571 #
572 # gdb_test_multiple "print foo" "test foo" {
573 # -re "expected output 1" {
574 # pass "print foo"
575 # }
576 # -re "expected output 2" {
577 # fail "print foo"
578 # }
579 # }
580 #
581 # The standard patterns, such as "Inferior exited..." and "A problem
582 # ...", all being implicitly appended to that list.
583 #
584 proc gdb_test_multiple { command message user_code } {
585 global verbose
586 global gdb_prompt
587 global GDB
588 global inferior_exited_re
589 upvar timeout timeout
590 upvar expect_out expect_out
591
592 if { $message == "" } {
593 set message $command
594 }
595
596 if [string match "*\[\r\n\]" $command] {
597 error "Invalid trailing newline in \"$message\" test"
598 }
599
600 # TCL/EXPECT WART ALERT
601 # Expect does something very strange when it receives a single braced
602 # argument. It splits it along word separators and performs substitutions.
603 # This means that { "[ab]" } is evaluated as "[ab]", but { "\[ab\]" } is
604 # evaluated as "\[ab\]". But that's not how TCL normally works; inside a
605 # double-quoted list item, "\[ab\]" is just a long way of representing
606 # "[ab]", because the backslashes will be removed by lindex.
607
608 # Unfortunately, there appears to be no easy way to duplicate the splitting
609 # that expect will do from within TCL. And many places make use of the
610 # "\[0-9\]" construct, so we need to support that; and some places make use
611 # of the "[func]" construct, so we need to support that too. In order to
612 # get this right we have to substitute quoted list elements differently
613 # from braced list elements.
614
615 # We do this roughly the same way that Expect does it. We have to use two
616 # lists, because if we leave unquoted newlines in the argument to uplevel
617 # they'll be treated as command separators, and if we escape newlines
618 # we mangle newlines inside of command blocks. This assumes that the
619 # input doesn't contain a pattern which contains actual embedded newlines
620 # at this point!
621
622 regsub -all {\n} ${user_code} { } subst_code
623 set subst_code [uplevel list $subst_code]
624
625 set processed_code ""
626 set patterns ""
627 set expecting_action 0
628 set expecting_arg 0
629 foreach item $user_code subst_item $subst_code {
630 if { $item == "-n" || $item == "-notransfer" || $item == "-nocase" } {
631 lappend processed_code $item
632 continue
633 }
634 if { $item == "-indices" || $item == "-re" || $item == "-ex" } {
635 lappend processed_code $item
636 continue
637 }
638 if { $item == "-timeout" } {
639 set expecting_arg 1
640 lappend processed_code $item
641 continue
642 }
643 if { $expecting_arg } {
644 set expecting_arg 0
645 lappend processed_code $item
646 continue
647 }
648 if { $expecting_action } {
649 lappend processed_code "uplevel [list $item]"
650 set expecting_action 0
651 # Cosmetic, no effect on the list.
652 append processed_code "\n"
653 continue
654 }
655 set expecting_action 1
656 lappend processed_code $subst_item
657 if {$patterns != ""} {
658 append patterns "; "
659 }
660 append patterns "\"$subst_item\""
661 }
662
663 # Also purely cosmetic.
664 regsub -all {\r} $patterns {\\r} patterns
665 regsub -all {\n} $patterns {\\n} patterns
666
667 if $verbose>2 then {
668 send_user "Sending \"$command\" to gdb\n"
669 send_user "Looking to match \"$patterns\"\n"
670 send_user "Message is \"$message\"\n"
671 }
672
673 set result -1
674 set string "${command}\n";
675 if { $command != "" } {
676 while { "$string" != "" } {
677 set foo [string first "\n" "$string"];
678 set len [string length "$string"];
679 if { $foo < [expr $len - 1] } {
680 set str [string range "$string" 0 $foo];
681 if { [send_gdb "$str"] != "" } {
682 global suppress_flag;
683
684 if { ! $suppress_flag } {
685 perror "Couldn't send $command to GDB.";
686 }
687 fail "$message";
688 return $result;
689 }
690 # since we're checking if each line of the multi-line
691 # command are 'accepted' by GDB here,
692 # we need to set -notransfer expect option so that
693 # command output is not lost for pattern matching
694 # - guo
695 gdb_expect 2 {
696 -notransfer -re "\[\r\n\]" { verbose "partial: match" 3 }
697 timeout { verbose "partial: timeout" 3 }
698 }
699 set string [string range "$string" [expr $foo + 1] end];
700 } else {
701 break;
702 }
703 }
704 if { "$string" != "" } {
705 if { [send_gdb "$string"] != "" } {
706 global suppress_flag;
707
708 if { ! $suppress_flag } {
709 perror "Couldn't send $command to GDB.";
710 }
711 fail "$message";
712 return $result;
713 }
714 }
715 }
716
717 if [target_info exists gdb,timeout] {
718 set tmt [target_info gdb,timeout];
719 } else {
720 if [info exists timeout] {
721 set tmt $timeout;
722 } else {
723 global timeout;
724 if [info exists timeout] {
725 set tmt $timeout;
726 } else {
727 set tmt 60;
728 }
729 }
730 }
731
732 set code {
733 -re ".*A problem internal to GDB has been detected" {
734 fail "$message (GDB internal error)"
735 gdb_internal_error_resync
736 }
737 -re "\\*\\*\\* DOSEXIT code.*" {
738 if { $message != "" } {
739 fail "$message";
740 }
741 gdb_suppress_entire_file "GDB died";
742 set result -1;
743 }
744 }
745 append code $processed_code
746 append code {
747 -re "Ending remote debugging.*$gdb_prompt $" {
748 if ![isnative] then {
749 warning "Can`t communicate to remote target."
750 }
751 gdb_exit
752 gdb_start
753 set result -1
754 }
755 -re "Undefined\[a-z\]* command:.*$gdb_prompt $" {
756 perror "Undefined command \"$command\"."
757 fail "$message"
758 set result 1
759 }
760 -re "Ambiguous command.*$gdb_prompt $" {
761 perror "\"$command\" is not a unique command name."
762 fail "$message"
763 set result 1
764 }
765 -re "$inferior_exited_re with code \[0-9\]+.*$gdb_prompt $" {
766 if ![string match "" $message] then {
767 set errmsg "$message (the program exited)"
768 } else {
769 set errmsg "$command (the program exited)"
770 }
771 fail "$errmsg"
772 set result -1
773 }
774 -re "$inferior_exited_re normally.*$gdb_prompt $" {
775 if ![string match "" $message] then {
776 set errmsg "$message (the program exited)"
777 } else {
778 set errmsg "$command (the program exited)"
779 }
780 fail "$errmsg"
781 set result -1
782 }
783 -re "The program is not being run.*$gdb_prompt $" {
784 if ![string match "" $message] then {
785 set errmsg "$message (the program is no longer running)"
786 } else {
787 set errmsg "$command (the program is no longer running)"
788 }
789 fail "$errmsg"
790 set result -1
791 }
792 -re "\r\n$gdb_prompt $" {
793 if ![string match "" $message] then {
794 fail "$message"
795 }
796 set result 1
797 }
798 "<return>" {
799 send_gdb "\n"
800 perror "Window too small."
801 fail "$message"
802 set result -1
803 }
804 -re "\\((y or n|y or \\\[n\\\]|\\\[y\\\] or n)\\) " {
805 send_gdb "n\n"
806 gdb_expect -re "$gdb_prompt $"
807 fail "$message (got interactive prompt)"
808 set result -1
809 }
810 -re "\\\[0\\\] cancel\r\n\\\[1\\\] all.*\r\n> $" {
811 send_gdb "0\n"
812 gdb_expect -re "$gdb_prompt $"
813 fail "$message (got breakpoint menu)"
814 set result -1
815 }
816 eof {
817 perror "Process no longer exists"
818 if { $message != "" } {
819 fail "$message"
820 }
821 return -1
822 }
823 full_buffer {
824 perror "internal buffer is full."
825 fail "$message"
826 set result -1
827 }
828 timeout {
829 if ![string match "" $message] then {
830 fail "$message (timeout)"
831 }
832 set result 1
833 }
834 }
835
836 set result 0
837 set code [catch {gdb_expect $tmt $code} string]
838 if {$code == 1} {
839 global errorInfo errorCode;
840 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
841 } elseif {$code == 2} {
842 return -code return $string
843 } elseif {$code == 3} {
844 return
845 } elseif {$code > 4} {
846 return -code $code $string
847 }
848 return $result
849 }
850
851 # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE
852 # Send a command to gdb; test the result.
853 #
854 # COMMAND is the command to execute, send to GDB with send_gdb. If
855 # this is the null string no command is sent.
856 # PATTERN is the pattern to match for a PASS, and must NOT include
857 # the \r\n sequence immediately before the gdb prompt.
858 # MESSAGE is an optional message to be printed. If this is
859 # omitted, then the pass/fail messages use the command string as the
860 # message. (If this is the empty string, then sometimes we don't
861 # call pass or fail at all; I don't understand this at all.)
862 # QUESTION is a question GDB may ask in response to COMMAND, like
863 # "are you sure?"
864 # RESPONSE is the response to send if QUESTION appears.
865 #
866 # Returns:
867 # 1 if the test failed,
868 # 0 if the test passes,
869 # -1 if there was an internal error.
870 #
871 proc gdb_test { args } {
872 global verbose
873 global gdb_prompt
874 global GDB
875 upvar timeout timeout
876
877 if [llength $args]>2 then {
878 set message [lindex $args 2]
879 } else {
880 set message [lindex $args 0]
881 }
882 set command [lindex $args 0]
883 set pattern [lindex $args 1]
884
885 if [llength $args]==5 {
886 set question_string [lindex $args 3];
887 set response_string [lindex $args 4];
888 } else {
889 set question_string "^FOOBAR$"
890 }
891
892 return [gdb_test_multiple $command $message {
893 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
894 if ![string match "" $message] then {
895 pass "$message"
896 }
897 }
898 -re "(${question_string})$" {
899 send_gdb "$response_string\n";
900 exp_continue;
901 }
902 }]
903 }
904
905 # gdb_test_no_output COMMAND MESSAGE
906 # Send a command to GDB and verify that this command generated no output.
907 #
908 # See gdb_test_multiple for a description of the COMMAND and MESSAGE
909 # parameters. If MESSAGE is ommitted, then COMMAND will be used as
910 # the message. (If MESSAGE is the empty string, then sometimes we do not
911 # call pass or fail at all; I don't understand this at all.)
912
913 proc gdb_test_no_output { args } {
914 global gdb_prompt
915 set command [lindex $args 0]
916 if [llength $args]>1 then {
917 set message [lindex $args 1]
918 } else {
919 set message $command
920 }
921
922 set command_regex [string_to_regexp $command]
923 gdb_test_multiple $command $message {
924 -re "^$command_regex\r\n$gdb_prompt $" {
925 if ![string match "" $message] then {
926 pass "$message"
927 }
928 }
929 }
930 }
931
932 # Send a command and then wait for a sequence of outputs.
933 # This is useful when the sequence is long and contains ".*", a single
934 # regexp to match the entire output can get a timeout much easier.
935 #
936 # COMMAND is the command to send.
937 # TEST_NAME is passed to pass/fail. COMMAND is used if TEST_NAME is "".
938 # EXPECTED_OUTPUT_LIST is a list of regexps of expected output, which are
939 # processed in order, and all must be present in the output.
940 #
941 # It is unnecessary to specify ".*" at the beginning or end of any regexp,
942 # there is an implicit ".*" between each element of EXPECTED_OUTPUT_LIST.
943 # There is also an implicit ".*" between the last regexp and the gdb prompt.
944 #
945 # Like gdb_test and gdb_test_multiple, the output is expected to end with the
946 # gdb prompt, which must not be specified in EXPECTED_OUTPUT_LIST.
947 #
948 # Returns:
949 # 1 if the test failed,
950 # 0 if the test passes,
951 # -1 if there was an internal error.
952
953 proc gdb_test_sequence { command test_name expected_output_list } {
954 global gdb_prompt
955 if { $test_name == "" } {
956 set test_name $command
957 }
958 lappend expected_output_list ""; # implicit ".*" before gdb prompt
959 send_gdb "$command\n"
960 return [gdb_expect_list $test_name "$gdb_prompt $" $expected_output_list]
961 }
962
963 \f
964 # Test that a command gives an error. For pass or fail, return
965 # a 1 to indicate that more tests can proceed. However a timeout
966 # is a serious error, generates a special fail message, and causes
967 # a 0 to be returned to indicate that more tests are likely to fail
968 # as well.
969
970 proc test_print_reject { args } {
971 global gdb_prompt
972 global verbose
973
974 if [llength $args]==2 then {
975 set expectthis [lindex $args 1]
976 } else {
977 set expectthis "should never match this bogus string"
978 }
979 set sendthis [lindex $args 0]
980 if $verbose>2 then {
981 send_user "Sending \"$sendthis\" to gdb\n"
982 send_user "Looking to match \"$expectthis\"\n"
983 }
984 send_gdb "$sendthis\n"
985 #FIXME: Should add timeout as parameter.
986 gdb_expect {
987 -re "A .* in expression.*\\.*$gdb_prompt $" {
988 pass "reject $sendthis"
989 return 1
990 }
991 -re "Invalid syntax in expression.*$gdb_prompt $" {
992 pass "reject $sendthis"
993 return 1
994 }
995 -re "Junk after end of expression.*$gdb_prompt $" {
996 pass "reject $sendthis"
997 return 1
998 }
999 -re "Invalid number.*$gdb_prompt $" {
1000 pass "reject $sendthis"
1001 return 1
1002 }
1003 -re "Invalid character constant.*$gdb_prompt $" {
1004 pass "reject $sendthis"
1005 return 1
1006 }
1007 -re "No symbol table is loaded.*$gdb_prompt $" {
1008 pass "reject $sendthis"
1009 return 1
1010 }
1011 -re "No symbol .* in current context.*$gdb_prompt $" {
1012 pass "reject $sendthis"
1013 return 1
1014 }
1015 -re "Unmatched single quote.*$gdb_prompt $" {
1016 pass "reject $sendthis"
1017 return 1
1018 }
1019 -re "A character constant must contain at least one character.*$gdb_prompt $" {
1020 pass "reject $sendthis"
1021 return 1
1022 }
1023 -re "$expectthis.*$gdb_prompt $" {
1024 pass "reject $sendthis"
1025 return 1
1026 }
1027 -re ".*$gdb_prompt $" {
1028 fail "reject $sendthis"
1029 return 1
1030 }
1031 default {
1032 fail "reject $sendthis (eof or timeout)"
1033 return 0
1034 }
1035 }
1036 }
1037 \f
1038 # Given an input string, adds backslashes as needed to create a
1039 # regexp that will match the string.
1040
1041 proc string_to_regexp {str} {
1042 set result $str
1043 regsub -all {[]*+.|()^$\[\\]} $str {\\&} result
1044 return $result
1045 }
1046
1047 # Same as gdb_test, but the second parameter is not a regexp,
1048 # but a string that must match exactly.
1049
1050 proc gdb_test_exact { args } {
1051 upvar timeout timeout
1052
1053 set command [lindex $args 0]
1054
1055 # This applies a special meaning to a null string pattern. Without
1056 # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
1057 # messages from commands that should have no output except a new
1058 # prompt. With this, only results of a null string will match a null
1059 # string pattern.
1060
1061 set pattern [lindex $args 1]
1062 if [string match $pattern ""] {
1063 set pattern [string_to_regexp [lindex $args 0]]
1064 } else {
1065 set pattern [string_to_regexp [lindex $args 1]]
1066 }
1067
1068 # It is most natural to write the pattern argument with only
1069 # embedded \n's, especially if you are trying to avoid Tcl quoting
1070 # problems. But gdb_expect really wants to see \r\n in patterns. So
1071 # transform the pattern here. First transform \r\n back to \n, in
1072 # case some users of gdb_test_exact already do the right thing.
1073 regsub -all "\r\n" $pattern "\n" pattern
1074 regsub -all "\n" $pattern "\r\n" pattern
1075 if [llength $args]==3 then {
1076 set message [lindex $args 2]
1077 } else {
1078 set message $command
1079 }
1080
1081 return [gdb_test $command $pattern $message]
1082 }
1083
1084 # Wrapper around gdb_test_multiple that looks for a list of expected
1085 # output elements, but which can appear in any order.
1086 # CMD is the gdb command.
1087 # NAME is the name of the test.
1088 # ELM_FIND_REGEXP specifies how to partition the output into elements to
1089 # compare.
1090 # ELM_EXTRACT_REGEXP specifies the part of ELM_FIND_REGEXP to compare.
1091 # RESULT_MATCH_LIST is a list of exact matches for each expected element.
1092 # All elements of RESULT_MATCH_LIST must appear for the test to pass.
1093 #
1094 # A typical use of ELM_FIND_REGEXP/ELM_EXTRACT_REGEXP is to extract one line
1095 # of text per element and then strip trailing \r\n's.
1096 # Example:
1097 # gdb_test_list_exact "foo" "bar" \
1098 # {[^\r\n]+[\r\n]+} \
1099 # {[^\r\n]+} \
1100 # { \
1101 # {expected result 1} \
1102 # {expected result 2} \
1103 # }
1104
1105 proc gdb_test_list_exact { cmd name elm_find_regexp elm_extract_regexp result_match_list } {
1106 global gdb_prompt
1107
1108 set matches [lsort $result_match_list]
1109 set seen {}
1110 gdb_test_multiple $cmd $name {
1111 "$cmd\[\r\n\]" { exp_continue }
1112 -re $elm_find_regexp {
1113 set str $expect_out(0,string)
1114 verbose -log "seen: $str" 3
1115 regexp -- $elm_extract_regexp $str elm_seen
1116 verbose -log "extracted: $elm_seen" 3
1117 lappend seen $elm_seen
1118 exp_continue
1119 }
1120 -re "$gdb_prompt $" {
1121 set failed ""
1122 foreach got [lsort $seen] have $matches {
1123 if {![string equal $got $have]} {
1124 set failed $have
1125 break
1126 }
1127 }
1128 if {[string length $failed] != 0} {
1129 fail "$name ($failed not found)"
1130 } else {
1131 pass $name
1132 }
1133 }
1134 }
1135 }
1136 \f
1137 proc gdb_reinitialize_dir { subdir } {
1138 global gdb_prompt
1139
1140 if [is_remote host] {
1141 return "";
1142 }
1143 send_gdb "dir\n"
1144 gdb_expect 60 {
1145 -re "Reinitialize source path to empty.*y or n. " {
1146 send_gdb "y\n"
1147 gdb_expect 60 {
1148 -re "Source directories searched.*$gdb_prompt $" {
1149 send_gdb "dir $subdir\n"
1150 gdb_expect 60 {
1151 -re "Source directories searched.*$gdb_prompt $" {
1152 verbose "Dir set to $subdir"
1153 }
1154 -re "$gdb_prompt $" {
1155 perror "Dir \"$subdir\" failed."
1156 }
1157 }
1158 }
1159 -re "$gdb_prompt $" {
1160 perror "Dir \"$subdir\" failed."
1161 }
1162 }
1163 }
1164 -re "$gdb_prompt $" {
1165 perror "Dir \"$subdir\" failed."
1166 }
1167 }
1168 }
1169
1170 #
1171 # gdb_exit -- exit the GDB, killing the target program if necessary
1172 #
1173 proc default_gdb_exit {} {
1174 global GDB
1175 global INTERNAL_GDBFLAGS GDBFLAGS
1176 global verbose
1177 global gdb_spawn_id;
1178
1179 gdb_stop_suppressing_tests;
1180
1181 if ![info exists gdb_spawn_id] {
1182 return;
1183 }
1184
1185 verbose "Quitting $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
1186
1187 if { [is_remote host] && [board_info host exists fileid] } {
1188 send_gdb "quit\n";
1189 gdb_expect 10 {
1190 -re "y or n" {
1191 send_gdb "y\n";
1192 exp_continue;
1193 }
1194 -re "DOSEXIT code" { }
1195 default { }
1196 }
1197 }
1198
1199 if ![is_remote host] {
1200 remote_close host;
1201 }
1202 unset gdb_spawn_id
1203 }
1204
1205 # Load a file into the debugger.
1206 # The return value is 0 for success, -1 for failure.
1207 #
1208 # This procedure also set the global variable GDB_FILE_CMD_DEBUG_INFO
1209 # to one of these values:
1210 #
1211 # debug file was loaded successfully and has debug information
1212 # nodebug file was loaded successfully and has no debug information
1213 # fail file was not loaded
1214 #
1215 # I tried returning this information as part of the return value,
1216 # but ran into a mess because of the many re-implementations of
1217 # gdb_load in config/*.exp.
1218 #
1219 # TODO: gdb.base/sepdebug.exp and gdb.stabs/weird.exp might be able to use
1220 # this if they can get more information set.
1221
1222 proc gdb_file_cmd { arg } {
1223 global gdb_prompt
1224 global verbose
1225 global GDB
1226 global last_loaded_file
1227
1228 set last_loaded_file $arg
1229
1230 # Set whether debug info was found.
1231 # Default to "fail".
1232 global gdb_file_cmd_debug_info
1233 set gdb_file_cmd_debug_info "fail"
1234
1235 if [is_remote host] {
1236 set arg [remote_download host $arg]
1237 if { $arg == "" } {
1238 perror "download failed"
1239 return -1
1240 }
1241 }
1242
1243 # The file command used to kill the remote target. For the benefit
1244 # of the testsuite, preserve this behavior.
1245 send_gdb "kill\n"
1246 gdb_expect 120 {
1247 -re "Kill the program being debugged. .y or n. $" {
1248 send_gdb "y\n"
1249 verbose "\t\tKilling previous program being debugged"
1250 exp_continue
1251 }
1252 -re "$gdb_prompt $" {
1253 # OK.
1254 }
1255 }
1256
1257 send_gdb "file $arg\n"
1258 gdb_expect 120 {
1259 -re "Reading symbols from.*no debugging symbols found.*done.*$gdb_prompt $" {
1260 verbose "\t\tLoaded $arg into the $GDB with no debugging symbols"
1261 set gdb_file_cmd_debug_info "nodebug"
1262 return 0
1263 }
1264 -re "Reading symbols from.*done.*$gdb_prompt $" {
1265 verbose "\t\tLoaded $arg into the $GDB"
1266 set gdb_file_cmd_debug_info "debug"
1267 return 0
1268 }
1269 -re "Load new symbol table from \".*\".*y or n. $" {
1270 send_gdb "y\n"
1271 gdb_expect 120 {
1272 -re "Reading symbols from.*done.*$gdb_prompt $" {
1273 verbose "\t\tLoaded $arg with new symbol table into $GDB"
1274 set gdb_file_cmd_debug_info "debug"
1275 return 0
1276 }
1277 timeout {
1278 perror "(timeout) Couldn't load $arg, other program already loaded."
1279 return -1
1280 }
1281 }
1282 }
1283 -re "No such file or directory.*$gdb_prompt $" {
1284 perror "($arg) No such file or directory"
1285 return -1
1286 }
1287 -re "$gdb_prompt $" {
1288 perror "couldn't load $arg into $GDB."
1289 return -1
1290 }
1291 timeout {
1292 perror "couldn't load $arg into $GDB (timed out)."
1293 return -1
1294 }
1295 eof {
1296 # This is an attempt to detect a core dump, but seems not to
1297 # work. Perhaps we need to match .* followed by eof, in which
1298 # gdb_expect does not seem to have a way to do that.
1299 perror "couldn't load $arg into $GDB (end of file)."
1300 return -1
1301 }
1302 }
1303 }
1304
1305 #
1306 # start gdb -- start gdb running, default procedure
1307 #
1308 # When running over NFS, particularly if running many simultaneous
1309 # tests on different hosts all using the same server, things can
1310 # get really slow. Give gdb at least 3 minutes to start up.
1311 #
1312 proc default_gdb_start { } {
1313 global verbose
1314 global GDB
1315 global INTERNAL_GDBFLAGS GDBFLAGS
1316 global gdb_prompt
1317 global timeout
1318 global gdb_spawn_id;
1319
1320 gdb_stop_suppressing_tests;
1321
1322 verbose "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
1323
1324 if [info exists gdb_spawn_id] {
1325 return 0;
1326 }
1327
1328 if ![is_remote host] {
1329 if { [which $GDB] == 0 } then {
1330 perror "$GDB does not exist."
1331 exit 1
1332 }
1333 }
1334 set res [remote_spawn host "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts]"];
1335 if { $res < 0 || $res == "" } {
1336 perror "Spawning $GDB failed."
1337 return 1;
1338 }
1339 gdb_expect 360 {
1340 -re "\[\r\n\]$gdb_prompt $" {
1341 verbose "GDB initialized."
1342 }
1343 -re "$gdb_prompt $" {
1344 perror "GDB never initialized."
1345 return -1
1346 }
1347 timeout {
1348 perror "(timeout) GDB never initialized after 10 seconds."
1349 remote_close host;
1350 return -1
1351 }
1352 }
1353 set gdb_spawn_id -1;
1354 # force the height to "unlimited", so no pagers get used
1355
1356 send_gdb "set height 0\n"
1357 gdb_expect 10 {
1358 -re "$gdb_prompt $" {
1359 verbose "Setting height to 0." 2
1360 }
1361 timeout {
1362 warning "Couldn't set the height to 0"
1363 }
1364 }
1365 # force the width to "unlimited", so no wraparound occurs
1366 send_gdb "set width 0\n"
1367 gdb_expect 10 {
1368 -re "$gdb_prompt $" {
1369 verbose "Setting width to 0." 2
1370 }
1371 timeout {
1372 warning "Couldn't set the width to 0."
1373 }
1374 }
1375 return 0;
1376 }
1377
1378 # Examine the output of compilation to determine whether compilation
1379 # failed or not. If it failed determine whether it is due to missing
1380 # compiler or due to compiler error. Report pass, fail or unsupported
1381 # as appropriate
1382
1383 proc gdb_compile_test {src output} {
1384 if { $output == "" } {
1385 pass "compilation [file tail $src]"
1386 } elseif { [regexp {^[a-zA-Z_0-9]+: Can't find [^ ]+\.$} $output] } {
1387 unsupported "compilation [file tail $src]"
1388 } elseif { [regexp {.*: command not found[\r|\n]*$} $output] } {
1389 unsupported "compilation [file tail $src]"
1390 } elseif { [regexp {.*: [^\r\n]*compiler not installed[^\r\n]*[\r|\n]*$} $output] } {
1391 unsupported "compilation [file tail $src]"
1392 } else {
1393 verbose -log "compilation failed: $output" 2
1394 fail "compilation [file tail $src]"
1395 }
1396 }
1397
1398 # Return a 1 for configurations for which we don't even want to try to
1399 # test C++.
1400
1401 proc skip_cplus_tests {} {
1402 if { [istarget "h8300-*-*"] } {
1403 return 1
1404 }
1405
1406 # The C++ IO streams are too large for HC11/HC12 and are thus not
1407 # available. The gdb C++ tests use them and don't compile.
1408 if { [istarget "m6811-*-*"] } {
1409 return 1
1410 }
1411 if { [istarget "m6812-*-*"] } {
1412 return 1
1413 }
1414 return 0
1415 }
1416
1417 # Return a 1 for configurations for which don't have both C++ and the STL.
1418
1419 proc skip_stl_tests {} {
1420 # Symbian supports the C++ language, but the STL is missing
1421 # (both headers and libraries).
1422 if { [istarget "arm*-*-symbianelf*"] } {
1423 return 1
1424 }
1425
1426 return [skip_cplus_tests]
1427 }
1428
1429 # Return a 1 if I don't even want to try to test FORTRAN.
1430
1431 proc skip_fortran_tests {} {
1432 return 0
1433 }
1434
1435 # Return a 1 if I don't even want to try to test ada.
1436
1437 proc skip_ada_tests {} {
1438 return 0
1439 }
1440
1441 # Return a 1 if I don't even want to try to test java.
1442
1443 proc skip_java_tests {} {
1444 return 0
1445 }
1446
1447 # Return a 1 for configurations that do not support Python scripting.
1448
1449 proc skip_python_tests {} {
1450 global gdb_prompt
1451 gdb_test_multiple "python print 'test'" "verify python support" {
1452 -re "not supported.*$gdb_prompt $" {
1453 unsupported "Python support is disabled."
1454 return 1
1455 }
1456 -re "$gdb_prompt $" {}
1457 }
1458
1459 return 0
1460 }
1461
1462 # Return a 1 if we should skip shared library tests.
1463
1464 proc skip_shlib_tests {} {
1465 # Run the shared library tests on native systems.
1466 if {[isnative]} {
1467 return 0
1468 }
1469
1470 # An abbreviated list of remote targets where we should be able to
1471 # run shared library tests.
1472 if {([istarget *-*-linux*]
1473 || [istarget *-*-*bsd*]
1474 || [istarget *-*-solaris2*]
1475 || [istarget arm*-*-symbianelf*]
1476 || [istarget *-*-mingw*]
1477 || [istarget *-*-cygwin*]
1478 || [istarget *-*-pe*])} {
1479 return 0
1480 }
1481
1482 return 1
1483 }
1484
1485 # Return 1 if target is ILP32.
1486 # This cannot be decided simply from looking at the target string,
1487 # as it might depend on externally passed compiler options like -m64.
1488 proc is_ilp32_target {} {
1489 global is_ilp32_target_saved
1490
1491 # Use the cached value, if it exists. Cache value per "board" to handle
1492 # runs with multiple options (e.g. unix/{-m32,-64}) correctly.
1493 set me "is_ilp32_target"
1494 set board [target_info name]
1495 if [info exists is_ilp32_target_saved($board)] {
1496 verbose "$me: returning saved $is_ilp32_target_saved($board)" 2
1497 return $is_ilp32_target_saved($board)
1498 }
1499
1500
1501 set src ilp32[pid].c
1502 set obj ilp32[pid].o
1503
1504 set f [open $src "w"]
1505 puts $f "int dummy\[sizeof (int) == 4"
1506 puts $f " && sizeof (void *) == 4"
1507 puts $f " && sizeof (long) == 4 ? 1 : -1\];"
1508 close $f
1509
1510 verbose "$me: compiling testfile $src" 2
1511 set lines [gdb_compile $src $obj object {quiet}]
1512 file delete $src
1513 file delete $obj
1514
1515 if ![string match "" $lines] then {
1516 verbose "$me: testfile compilation failed, returning 0" 2
1517 return [set is_ilp32_target_saved($board) 0]
1518 }
1519
1520 verbose "$me: returning 1" 2
1521 return [set is_ilp32_target_saved($board) 1]
1522 }
1523
1524 # Return 1 if target is LP64.
1525 # This cannot be decided simply from looking at the target string,
1526 # as it might depend on externally passed compiler options like -m64.
1527 proc is_lp64_target {} {
1528 global is_lp64_target_saved
1529
1530 # Use the cached value, if it exists. Cache value per "board" to handle
1531 # runs with multiple options (e.g. unix/{-m32,-64}) correctly.
1532 set me "is_lp64_target"
1533 set board [target_info name]
1534 if [info exists is_lp64_target_saved($board)] {
1535 verbose "$me: returning saved $is_lp64_target_saved($board)" 2
1536 return $is_lp64_target_saved($board)
1537 }
1538
1539 set src lp64[pid].c
1540 set obj lp64[pid].o
1541
1542 set f [open $src "w"]
1543 puts $f "int dummy\[sizeof (int) == 4"
1544 puts $f " && sizeof (void *) == 8"
1545 puts $f " && sizeof (long) == 8 ? 1 : -1\];"
1546 close $f
1547
1548 verbose "$me: compiling testfile $src" 2
1549 set lines [gdb_compile $src $obj object {quiet}]
1550 file delete $src
1551 file delete $obj
1552
1553 if ![string match "" $lines] then {
1554 verbose "$me: testfile compilation failed, returning 0" 2
1555 return [set is_lp64_target_saved($board) 0]
1556 }
1557
1558 verbose "$me: returning 1" 2
1559 return [set is_lp64_target_saved($board) 1]
1560 }
1561
1562 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
1563 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
1564
1565 proc skip_altivec_tests {} {
1566 global skip_vmx_tests_saved
1567 global srcdir subdir gdb_prompt inferior_exited_re
1568
1569 # Use the cached value, if it exists.
1570 set me "skip_altivec_tests"
1571 if [info exists skip_vmx_tests_saved] {
1572 verbose "$me: returning saved $skip_vmx_tests_saved" 2
1573 return $skip_vmx_tests_saved
1574 }
1575
1576 # Some simulators are known to not support VMX instructions.
1577 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
1578 verbose "$me: target known to not support VMX, returning 1" 2
1579 return [set skip_vmx_tests_saved 1]
1580 }
1581
1582 # Make sure we have a compiler that understands altivec.
1583 set compile_flags {debug nowarnings}
1584 if [get_compiler_info not-used] {
1585 warning "Could not get compiler info"
1586 return 1
1587 }
1588 if [test_compiler_info gcc*] {
1589 set compile_flags "$compile_flags additional_flags=-maltivec"
1590 } elseif [test_compiler_info xlc*] {
1591 set compile_flags "$compile_flags additional_flags=-qaltivec"
1592 } else {
1593 verbose "Could not compile with altivec support, returning 1" 2
1594 return 1
1595 }
1596
1597 # Set up, compile, and execute a test program containing VMX instructions.
1598 # Include the current process ID in the file names to prevent conflicts
1599 # with invocations for multiple testsuites.
1600 set src vmx[pid].c
1601 set exe vmx[pid].x
1602
1603 set f [open $src "w"]
1604 puts $f "int main() {"
1605 puts $f "#ifdef __MACH__"
1606 puts $f " asm volatile (\"vor v0,v0,v0\");"
1607 puts $f "#else"
1608 puts $f " asm volatile (\"vor 0,0,0\");"
1609 puts $f "#endif"
1610 puts $f " return 0; }"
1611 close $f
1612
1613 verbose "$me: compiling testfile $src" 2
1614 set lines [gdb_compile $src $exe executable $compile_flags]
1615 file delete $src
1616
1617 if ![string match "" $lines] then {
1618 verbose "$me: testfile compilation failed, returning 1" 2
1619 return [set skip_vmx_tests_saved 1]
1620 }
1621
1622 # No error message, compilation succeeded so now run it via gdb.
1623
1624 gdb_exit
1625 gdb_start
1626 gdb_reinitialize_dir $srcdir/$subdir
1627 gdb_load "$exe"
1628 gdb_run_cmd
1629 gdb_expect {
1630 -re ".*Illegal instruction.*${gdb_prompt} $" {
1631 verbose -log "\n$me altivec hardware not detected"
1632 set skip_vmx_tests_saved 1
1633 }
1634 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
1635 verbose -log "\n$me: altivec hardware detected"
1636 set skip_vmx_tests_saved 0
1637 }
1638 default {
1639 warning "\n$me: default case taken"
1640 set skip_vmx_tests_saved 1
1641 }
1642 }
1643 gdb_exit
1644 remote_file build delete $exe
1645
1646 verbose "$me: returning $skip_vmx_tests_saved" 2
1647 return $skip_vmx_tests_saved
1648 }
1649
1650 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
1651 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
1652
1653 proc skip_vsx_tests {} {
1654 global skip_vsx_tests_saved
1655 global srcdir subdir gdb_prompt inferior_exited_re
1656
1657 # Use the cached value, if it exists.
1658 set me "skip_vsx_tests"
1659 if [info exists skip_vsx_tests_saved] {
1660 verbose "$me: returning saved $skip_vsx_tests_saved" 2
1661 return $skip_vsx_tests_saved
1662 }
1663
1664 # Some simulators are known to not support Altivec instructions, so
1665 # they won't support VSX instructions as well.
1666 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
1667 verbose "$me: target known to not support VSX, returning 1" 2
1668 return [set skip_vsx_tests_saved 1]
1669 }
1670
1671 # Make sure we have a compiler that understands altivec.
1672 set compile_flags {debug nowarnings quiet}
1673 if [get_compiler_info not-used] {
1674 warning "Could not get compiler info"
1675 return 1
1676 }
1677 if [test_compiler_info gcc*] {
1678 set compile_flags "$compile_flags additional_flags=-mvsx"
1679 } elseif [test_compiler_info xlc*] {
1680 set compile_flags "$compile_flags additional_flags=-qasm=gcc"
1681 } else {
1682 verbose "Could not compile with vsx support, returning 1" 2
1683 return 1
1684 }
1685
1686 set src vsx[pid].c
1687 set exe vsx[pid].x
1688
1689 set f [open $src "w"]
1690 puts $f "int main() {"
1691 puts $f " double a\[2\] = { 1.0, 2.0 };"
1692 puts $f "#ifdef __MACH__"
1693 puts $f " asm volatile (\"lxvd2x v0,v0,%\[addr\]\" : : \[addr\] \"r\" (a));"
1694 puts $f "#else"
1695 puts $f " asm volatile (\"lxvd2x 0,0,%\[addr\]\" : : \[addr\] \"r\" (a));"
1696 puts $f "#endif"
1697 puts $f " return 0; }"
1698 close $f
1699
1700 verbose "$me: compiling testfile $src" 2
1701 set lines [gdb_compile $src $exe executable $compile_flags]
1702 file delete $src
1703
1704 if ![string match "" $lines] then {
1705 verbose "$me: testfile compilation failed, returning 1" 2
1706 return [set skip_vsx_tests_saved 1]
1707 }
1708
1709 # No error message, compilation succeeded so now run it via gdb.
1710
1711 gdb_exit
1712 gdb_start
1713 gdb_reinitialize_dir $srcdir/$subdir
1714 gdb_load "$exe"
1715 gdb_run_cmd
1716 gdb_expect {
1717 -re ".*Illegal instruction.*${gdb_prompt} $" {
1718 verbose -log "\n$me VSX hardware not detected"
1719 set skip_vsx_tests_saved 1
1720 }
1721 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
1722 verbose -log "\n$me: VSX hardware detected"
1723 set skip_vsx_tests_saved 0
1724 }
1725 default {
1726 warning "\n$me: default case taken"
1727 set skip_vsx_tests_saved 1
1728 }
1729 }
1730 gdb_exit
1731 remote_file build delete $exe
1732
1733 verbose "$me: returning $skip_vsx_tests_saved" 2
1734 return $skip_vsx_tests_saved
1735 }
1736
1737 # Skip all the tests in the file if you are not on an hppa running
1738 # hpux target.
1739
1740 proc skip_hp_tests {} {
1741 eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ]
1742 verbose "Skip hp tests is $skip_hp"
1743 return $skip_hp
1744 }
1745
1746 # Return whether we should skip tests for showing inlined functions in
1747 # backtraces. Requires get_compiler_info and get_debug_format.
1748
1749 proc skip_inline_frame_tests {} {
1750 # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
1751 if { ! [test_debug_format "DWARF 2"] } {
1752 return 1
1753 }
1754
1755 # GCC before 4.1 does not emit DW_AT_call_file / DW_AT_call_line.
1756 if { ([test_compiler_info "gcc-2-*"]
1757 || [test_compiler_info "gcc-3-*"]
1758 || [test_compiler_info "gcc-4-0-*"]) } {
1759 return 1
1760 }
1761
1762 return 0
1763 }
1764
1765 # Return whether we should skip tests for showing variables from
1766 # inlined functions. Requires get_compiler_info and get_debug_format.
1767
1768 proc skip_inline_var_tests {} {
1769 # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
1770 if { ! [test_debug_format "DWARF 2"] } {
1771 return 1
1772 }
1773
1774 return 0
1775 }
1776
1777 # Return a 1 if we should skip tests that require hardware breakpoints
1778
1779 proc skip_hw_breakpoint_tests {} {
1780 # Skip tests if requested by the board (note that no_hardware_watchpoints
1781 # disables both watchpoints and breakpoints)
1782 if { [target_info exists gdb,no_hardware_watchpoints]} {
1783 return 1
1784 }
1785
1786 # These targets support hardware breakpoints natively
1787 if { [istarget "i?86-*-*"]
1788 || [istarget "x86_64-*-*"]
1789 || [istarget "ia64-*-*"]
1790 || [istarget "arm*-*-*"]} {
1791 return 0
1792 }
1793
1794 return 1
1795 }
1796
1797 # Return a 1 if we should skip tests that require hardware watchpoints
1798
1799 proc skip_hw_watchpoint_tests {} {
1800 # Skip tests if requested by the board
1801 if { [target_info exists gdb,no_hardware_watchpoints]} {
1802 return 1
1803 }
1804
1805 # These targets support hardware watchpoints natively
1806 if { [istarget "i?86-*-*"]
1807 || [istarget "x86_64-*-*"]
1808 || [istarget "ia64-*-*"]
1809 || [istarget "arm*-*-*"]
1810 || [istarget "powerpc*-*-linux*"]
1811 || [istarget "s390*-*-*"] } {
1812 return 0
1813 }
1814
1815 return 1
1816 }
1817
1818 # Return a 1 if we should skip tests that require *multiple* hardware
1819 # watchpoints to be active at the same time
1820
1821 proc skip_hw_watchpoint_multi_tests {} {
1822 if { [skip_hw_watchpoint_tests] } {
1823 return 1
1824 }
1825
1826 # These targets support just a single hardware watchpoint
1827 if { [istarget "arm*-*-*"]
1828 || [istarget "powerpc*-*-linux*"] } {
1829 return 1
1830 }
1831
1832 return 0
1833 }
1834
1835 # Return a 1 if we should skip tests that require read/access watchpoints
1836
1837 proc skip_hw_watchpoint_access_tests {} {
1838 if { [skip_hw_watchpoint_tests] } {
1839 return 1
1840 }
1841
1842 # These targets support just write watchpoints
1843 if { [istarget "s390*-*-*"] } {
1844 return 1
1845 }
1846
1847 return 0
1848 }
1849
1850 set compiler_info "unknown"
1851 set gcc_compiled 0
1852 set hp_cc_compiler 0
1853 set hp_aCC_compiler 0
1854
1855 # Figure out what compiler I am using.
1856 #
1857 # BINFILE is a "compiler information" output file. This implementation
1858 # does not use BINFILE.
1859 #
1860 # ARGS can be empty or "C++". If empty, "C" is assumed.
1861 #
1862 # There are several ways to do this, with various problems.
1863 #
1864 # [ gdb_compile -E $ifile -o $binfile.ci ]
1865 # source $binfile.ci
1866 #
1867 # Single Unix Spec v3 says that "-E -o ..." together are not
1868 # specified. And in fact, the native compiler on hp-ux 11 (among
1869 # others) does not work with "-E -o ...". Most targets used to do
1870 # this, and it mostly worked, because it works with gcc.
1871 #
1872 # [ catch "exec $compiler -E $ifile > $binfile.ci" exec_output ]
1873 # source $binfile.ci
1874 #
1875 # This avoids the problem with -E and -o together. This almost works
1876 # if the build machine is the same as the host machine, which is
1877 # usually true of the targets which are not gcc. But this code does
1878 # not figure which compiler to call, and it always ends up using the C
1879 # compiler. Not good for setting hp_aCC_compiler. Targets
1880 # hppa*-*-hpux* and mips*-*-irix* used to do this.
1881 #
1882 # [ gdb_compile -E $ifile > $binfile.ci ]
1883 # source $binfile.ci
1884 #
1885 # dejagnu target_compile says that it supports output redirection,
1886 # but the code is completely different from the normal path and I
1887 # don't want to sweep the mines from that path. So I didn't even try
1888 # this.
1889 #
1890 # set cppout [ gdb_compile $ifile "" preprocess $args quiet ]
1891 # eval $cppout
1892 #
1893 # I actually do this for all targets now. gdb_compile runs the right
1894 # compiler, and TCL captures the output, and I eval the output.
1895 #
1896 # Unfortunately, expect logs the output of the command as it goes by,
1897 # and dejagnu helpfully prints a second copy of it right afterwards.
1898 # So I turn off expect logging for a moment.
1899 #
1900 # [ gdb_compile $ifile $ciexe_file executable $args ]
1901 # [ remote_exec $ciexe_file ]
1902 # [ source $ci_file.out ]
1903 #
1904 # I could give up on -E and just do this.
1905 # I didn't get desperate enough to try this.
1906 #
1907 # -- chastain 2004-01-06
1908
1909 proc get_compiler_info {binfile args} {
1910 # For compiler.c and compiler.cc
1911 global srcdir
1912
1913 # I am going to play with the log to keep noise out.
1914 global outdir
1915 global tool
1916
1917 # These come from compiler.c or compiler.cc
1918 global compiler_info
1919
1920 # Legacy global data symbols.
1921 global gcc_compiled
1922 global hp_cc_compiler
1923 global hp_aCC_compiler
1924
1925 # Choose which file to preprocess.
1926 set ifile "${srcdir}/lib/compiler.c"
1927 if { [llength $args] > 0 && [lindex $args 0] == "c++" } {
1928 set ifile "${srcdir}/lib/compiler.cc"
1929 }
1930
1931 # Run $ifile through the right preprocessor.
1932 # Toggle gdb.log to keep the compiler output out of the log.
1933 log_file
1934 if [is_remote host] {
1935 # We have to use -E and -o together, despite the comments
1936 # above, because of how DejaGnu handles remote host testing.
1937 set ppout "$outdir/compiler.i"
1938 gdb_compile "${ifile}" "$ppout" preprocess [list "$args" quiet]
1939 set file [open $ppout r]
1940 set cppout [read $file]
1941 close $file
1942 } else {
1943 set cppout [ gdb_compile "${ifile}" "" preprocess [list "$args" quiet] ]
1944 }
1945 log_file -a "$outdir/$tool.log"
1946
1947 # Eval the output.
1948 set unknown 0
1949 foreach cppline [ split "$cppout" "\n" ] {
1950 if { [ regexp "^#" "$cppline" ] } {
1951 # line marker
1952 } elseif { [ regexp "^\[\n\r\t \]*$" "$cppline" ] } {
1953 # blank line
1954 } elseif { [ regexp "^\[\n\r\t \]*set\[\n\r\t \]" "$cppline" ] } {
1955 # eval this line
1956 verbose "get_compiler_info: $cppline" 2
1957 eval "$cppline"
1958 } else {
1959 # unknown line
1960 verbose -log "get_compiler_info: $cppline"
1961 set unknown 1
1962 }
1963 }
1964
1965 # Reset to unknown compiler if any diagnostics happened.
1966 if { $unknown } {
1967 set compiler_info "unknown"
1968 }
1969
1970 # Set the legacy symbols.
1971 set gcc_compiled 0
1972 set hp_cc_compiler 0
1973 set hp_aCC_compiler 0
1974 if { [regexp "^gcc-1-" "$compiler_info" ] } { set gcc_compiled 1 }
1975 if { [regexp "^gcc-2-" "$compiler_info" ] } { set gcc_compiled 2 }
1976 if { [regexp "^gcc-3-" "$compiler_info" ] } { set gcc_compiled 3 }
1977 if { [regexp "^gcc-4-" "$compiler_info" ] } { set gcc_compiled 4 }
1978 if { [regexp "^gcc-5-" "$compiler_info" ] } { set gcc_compiled 5 }
1979 if { [regexp "^hpcc-" "$compiler_info" ] } { set hp_cc_compiler 1 }
1980 if { [regexp "^hpacc-" "$compiler_info" ] } { set hp_aCC_compiler 1 }
1981
1982 # Log what happened.
1983 verbose -log "get_compiler_info: $compiler_info"
1984
1985 # Most compilers will evaluate comparisons and other boolean
1986 # operations to 0 or 1.
1987 uplevel \#0 { set true 1 }
1988 uplevel \#0 { set false 0 }
1989
1990 # Use of aCC results in boolean results being displayed as
1991 # "true" or "false"
1992 if { $hp_aCC_compiler } {
1993 uplevel \#0 { set true true }
1994 uplevel \#0 { set false false }
1995 }
1996
1997 return 0;
1998 }
1999
2000 proc test_compiler_info { {compiler ""} } {
2001 global compiler_info
2002
2003 # if no arg, return the compiler_info string
2004
2005 if [string match "" $compiler] {
2006 if [info exists compiler_info] {
2007 return $compiler_info
2008 } else {
2009 perror "No compiler info found."
2010 }
2011 }
2012
2013 return [string match $compiler $compiler_info]
2014 }
2015
2016 proc current_target_name { } {
2017 global target_info
2018 if [info exists target_info(target,name)] {
2019 set answer $target_info(target,name)
2020 } else {
2021 set answer ""
2022 }
2023 return $answer
2024 }
2025
2026 set gdb_wrapper_initialized 0
2027 set gdb_wrapper_target ""
2028
2029 proc gdb_wrapper_init { args } {
2030 global gdb_wrapper_initialized;
2031 global gdb_wrapper_file;
2032 global gdb_wrapper_flags;
2033 global gdb_wrapper_target
2034
2035 if { $gdb_wrapper_initialized == 1 } { return; }
2036
2037 if {[target_info exists needs_status_wrapper] && \
2038 [target_info needs_status_wrapper] != "0"} {
2039 set result [build_wrapper "testglue.o"];
2040 if { $result != "" } {
2041 set gdb_wrapper_file [lindex $result 0];
2042 set gdb_wrapper_flags [lindex $result 1];
2043 } else {
2044 warning "Status wrapper failed to build."
2045 }
2046 }
2047 set gdb_wrapper_initialized 1
2048 set gdb_wrapper_target [current_target_name]
2049 }
2050
2051 # Some targets need to always link a special object in. Save its path here.
2052 global gdb_saved_set_unbuffered_mode_obj
2053 set gdb_saved_set_unbuffered_mode_obj ""
2054
2055 proc gdb_compile {source dest type options} {
2056 global GDB_TESTCASE_OPTIONS;
2057 global gdb_wrapper_file;
2058 global gdb_wrapper_flags;
2059 global gdb_wrapper_initialized;
2060 global srcdir
2061 global objdir
2062 global gdb_saved_set_unbuffered_mode_obj
2063
2064 set outdir [file dirname $dest]
2065
2066 # Add platform-specific options if a shared library was specified using
2067 # "shlib=librarypath" in OPTIONS.
2068 set new_options ""
2069 set shlib_found 0
2070 set shlib_load 0
2071 foreach opt $options {
2072 if [regexp {^shlib=(.*)} $opt dummy_var shlib_name] {
2073 if [test_compiler_info "xlc-*"] {
2074 # IBM xlc compiler doesn't accept shared library named other
2075 # than .so: use "-Wl," to bypass this
2076 lappend source "-Wl,$shlib_name"
2077 } elseif { ([istarget "*-*-mingw*"]
2078 || [istarget *-*-cygwin*]
2079 || [istarget *-*-pe*])} {
2080 lappend source "${shlib_name}.a"
2081 } else {
2082 lappend source $shlib_name
2083 }
2084 if { $shlib_found == 0 } {
2085 set shlib_found 1
2086 if { ([istarget "*-*-mingw*"]
2087 || [istarget *-*-cygwin*]) } {
2088 lappend new_options "additional_flags=-Wl,--enable-auto-import"
2089 }
2090 }
2091 } elseif { $opt == "shlib_load" } {
2092 set shlib_load 1
2093 } else {
2094 lappend new_options $opt
2095 }
2096 }
2097
2098 # We typically link to shared libraries using an absolute path, and
2099 # that's how they are found at runtime. If we are going to
2100 # dynamically load one by basename, we must specify rpath. If we
2101 # are using a remote host, DejaGNU will link to the shared library
2102 # using a relative path, so again we must specify an rpath.
2103 if { $shlib_load || ($shlib_found && [is_remote host]) } {
2104 if { ([istarget "*-*-mingw*"]
2105 || [istarget *-*-cygwin*]
2106 || [istarget *-*-pe*]
2107 || [istarget hppa*-*-hpux*])} {
2108 # Do not need anything.
2109 } elseif { [istarget *-*-openbsd*] } {
2110 lappend new_options "ldflags=-Wl,-rpath,${outdir}"
2111 } elseif { [istarget arm*-*-symbianelf*] } {
2112 if { $shlib_load } {
2113 lappend new_options "libs=-ldl"
2114 }
2115 } else {
2116 if { $shlib_load } {
2117 lappend new_options "libs=-ldl"
2118 }
2119 lappend new_options "ldflags=-Wl,-rpath,\\\$ORIGIN"
2120 }
2121 }
2122 set options $new_options
2123
2124 if [target_info exists gdb_stub] {
2125 set options2 { "additional_flags=-Dusestubs" }
2126 lappend options "libs=[target_info gdb_stub]";
2127 set options [concat $options2 $options]
2128 }
2129 if [target_info exists is_vxworks] {
2130 set options2 { "additional_flags=-Dvxworks" }
2131 lappend options "libs=[target_info gdb_stub]";
2132 set options [concat $options2 $options]
2133 }
2134 if [info exists GDB_TESTCASE_OPTIONS] {
2135 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS";
2136 }
2137 verbose "options are $options"
2138 verbose "source is $source $dest $type $options"
2139
2140 if { $gdb_wrapper_initialized == 0 } { gdb_wrapper_init }
2141
2142 if {[target_info exists needs_status_wrapper] && \
2143 [target_info needs_status_wrapper] != "0" && \
2144 [info exists gdb_wrapper_file]} {
2145 lappend options "libs=${gdb_wrapper_file}"
2146 lappend options "ldflags=${gdb_wrapper_flags}"
2147 }
2148
2149 # Replace the "nowarnings" option with the appropriate additional_flags
2150 # to disable compiler warnings.
2151 set nowarnings [lsearch -exact $options nowarnings]
2152 if {$nowarnings != -1} {
2153 if [target_info exists gdb,nowarnings_flag] {
2154 set flag "additional_flags=[target_info gdb,nowarnings_flag]"
2155 } else {
2156 set flag "additional_flags=-w"
2157 }
2158 set options [lreplace $options $nowarnings $nowarnings $flag]
2159 }
2160
2161 if { $type == "executable" } {
2162 if { ([istarget "*-*-mingw*"]
2163 || [istarget "*-*-*djgpp"]
2164 || [istarget "*-*-cygwin*"])} {
2165 # Force output to unbuffered mode, by linking in an object file
2166 # with a global contructor that calls setvbuf.
2167 #
2168 # Compile the special object seperatelly for two reasons:
2169 # 1) Insulate it from $options.
2170 # 2) Avoid compiling it for every gdb_compile invocation,
2171 # which is time consuming, especially if we're remote
2172 # host testing.
2173 #
2174 if { $gdb_saved_set_unbuffered_mode_obj == "" } {
2175 verbose "compiling gdb_saved_set_unbuffered_obj"
2176 set unbuf_src ${srcdir}/lib/set_unbuffered_mode.c
2177 set unbuf_obj ${objdir}/set_unbuffered_mode.o
2178
2179 set result [gdb_compile "${unbuf_src}" "${unbuf_obj}" object {nowarnings}]
2180 if { $result != "" } {
2181 return $result
2182 }
2183
2184 set gdb_saved_set_unbuffered_mode_obj ${objdir}/set_unbuffered_mode_saved.o
2185 # Link a copy of the output object, because the
2186 # original may be automatically deleted.
2187 remote_exec host "cp -f $unbuf_obj $gdb_saved_set_unbuffered_mode_obj"
2188 } else {
2189 verbose "gdb_saved_set_unbuffered_obj already compiled"
2190 }
2191
2192 # Rely on the internal knowledge that the global ctors are ran in
2193 # reverse link order. In that case, we can use ldflags to
2194 # avoid copying the object file to the host multiple
2195 # times.
2196 # This object can only be added if standard libraries are
2197 # used. Thus, we need to disable it if -nostdlib option is used
2198 if {[lsearch -regexp $options "-nostdlib"] < 0 } {
2199 lappend options "ldflags=$gdb_saved_set_unbuffered_mode_obj"
2200 }
2201 }
2202 }
2203
2204 set result [target_compile $source $dest $type $options];
2205
2206 # Prune uninteresting compiler (and linker) output.
2207 regsub "Creating library file: \[^\r\n\]*\[\r\n\]+" $result "" result
2208
2209 regsub "\[\r\n\]*$" "$result" "" result;
2210 regsub "^\[\r\n\]*" "$result" "" result;
2211
2212 if {[lsearch $options quiet] < 0} {
2213 # We shall update this on a per language basis, to avoid
2214 # changing the entire testsuite in one go.
2215 if {[lsearch $options f77] >= 0} {
2216 gdb_compile_test $source $result
2217 } elseif { $result != "" } {
2218 clone_output "gdb compile failed, $result"
2219 }
2220 }
2221 return $result;
2222 }
2223
2224
2225 # This is just like gdb_compile, above, except that it tries compiling
2226 # against several different thread libraries, to see which one this
2227 # system has.
2228 proc gdb_compile_pthreads {source dest type options} {
2229 set built_binfile 0
2230 set why_msg "unrecognized error"
2231 foreach lib {-lpthreads -lpthread -lthread ""} {
2232 # This kind of wipes out whatever libs the caller may have
2233 # set. Or maybe theirs will override ours. How infelicitous.
2234 set options_with_lib [concat $options [list libs=$lib quiet]]
2235 set ccout [gdb_compile $source $dest $type $options_with_lib]
2236 switch -regexp -- $ccout {
2237 ".*no posix threads support.*" {
2238 set why_msg "missing threads include file"
2239 break
2240 }
2241 ".*cannot open -lpthread.*" {
2242 set why_msg "missing runtime threads library"
2243 }
2244 ".*Can't find library for -lpthread.*" {
2245 set why_msg "missing runtime threads library"
2246 }
2247 {^$} {
2248 pass "successfully compiled posix threads test case"
2249 set built_binfile 1
2250 break
2251 }
2252 }
2253 }
2254 if {!$built_binfile} {
2255 unsupported "Couldn't compile $source: ${why_msg}"
2256 return -1
2257 }
2258 }
2259
2260 # Build a shared library from SOURCES. You must use get_compiler_info
2261 # first.
2262
2263 proc gdb_compile_shlib {sources dest options} {
2264 set obj_options $options
2265
2266 switch -glob [test_compiler_info] {
2267 "xlc-*" {
2268 lappend obj_options "additional_flags=-qpic"
2269 }
2270 "gcc-*" {
2271 if { !([istarget "powerpc*-*-aix*"]
2272 || [istarget "rs6000*-*-aix*"]
2273 || [istarget "*-*-cygwin*"]
2274 || [istarget "*-*-mingw*"]
2275 || [istarget "*-*-pe*"]) } {
2276 lappend obj_options "additional_flags=-fpic"
2277 }
2278 }
2279 default {
2280 switch -glob [istarget] {
2281 "hppa*-hp-hpux*" {
2282 lappend obj_options "additional_flags=+z"
2283 }
2284 "mips-sgi-irix*" {
2285 # Disable SGI compiler's implicit -Dsgi
2286 lappend obj_options "additional_flags=-Usgi"
2287 }
2288 default {
2289 # don't know what the compiler is...
2290 }
2291 }
2292 }
2293 }
2294
2295 set outdir [file dirname $dest]
2296 set objects ""
2297 foreach source $sources {
2298 set sourcebase [file tail $source]
2299 if {[gdb_compile $source "${outdir}/${sourcebase}.o" object $obj_options] != ""} {
2300 return -1
2301 }
2302 lappend objects ${outdir}/${sourcebase}.o
2303 }
2304
2305 if [istarget "hppa*-*-hpux*"] {
2306 remote_exec build "ld -b ${objects} -o ${dest}"
2307 } else {
2308 set link_options $options
2309 if [test_compiler_info "xlc-*"] {
2310 lappend link_options "additional_flags=-qmkshrobj"
2311 } else {
2312 lappend link_options "additional_flags=-shared"
2313
2314 if { ([istarget "*-*-mingw*"]
2315 || [istarget *-*-cygwin*]
2316 || [istarget *-*-pe*])} {
2317 lappend link_options "additional_flags=-Wl,--out-implib,${dest}.a"
2318 }
2319 }
2320 if {[gdb_compile "${objects}" "${dest}" executable $link_options] != ""} {
2321 return -1
2322 }
2323 }
2324 }
2325
2326 # This is just like gdb_compile_pthreads, above, except that we always add the
2327 # objc library for compiling Objective-C programs
2328 proc gdb_compile_objc {source dest type options} {
2329 set built_binfile 0
2330 set why_msg "unrecognized error"
2331 foreach lib {-lobjc -lpthreads -lpthread -lthread solaris} {
2332 # This kind of wipes out whatever libs the caller may have
2333 # set. Or maybe theirs will override ours. How infelicitous.
2334 if { $lib == "solaris" } {
2335 set lib "-lpthread -lposix4"
2336 }
2337 if { $lib != "-lobjc" } {
2338 set lib "-lobjc $lib"
2339 }
2340 set options_with_lib [concat $options [list libs=$lib quiet]]
2341 set ccout [gdb_compile $source $dest $type $options_with_lib]
2342 switch -regexp -- $ccout {
2343 ".*no posix threads support.*" {
2344 set why_msg "missing threads include file"
2345 break
2346 }
2347 ".*cannot open -lpthread.*" {
2348 set why_msg "missing runtime threads library"
2349 }
2350 ".*Can't find library for -lpthread.*" {
2351 set why_msg "missing runtime threads library"
2352 }
2353 {^$} {
2354 pass "successfully compiled objc with posix threads test case"
2355 set built_binfile 1
2356 break
2357 }
2358 }
2359 }
2360 if {!$built_binfile} {
2361 unsupported "Couldn't compile $source: ${why_msg}"
2362 return -1
2363 }
2364 }
2365
2366 proc send_gdb { string } {
2367 global suppress_flag;
2368 if { $suppress_flag } {
2369 return "suppressed";
2370 }
2371 return [remote_send host "$string"];
2372 }
2373
2374 #
2375 #
2376
2377 proc gdb_expect { args } {
2378 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
2379 set atimeout [lindex $args 0];
2380 set expcode [list [lindex $args 1]];
2381 } else {
2382 set expcode $args;
2383 }
2384
2385 upvar timeout timeout;
2386
2387 if [target_info exists gdb,timeout] {
2388 if [info exists timeout] {
2389 if { $timeout < [target_info gdb,timeout] } {
2390 set gtimeout [target_info gdb,timeout];
2391 } else {
2392 set gtimeout $timeout;
2393 }
2394 } else {
2395 set gtimeout [target_info gdb,timeout];
2396 }
2397 }
2398
2399 if ![info exists gtimeout] {
2400 global timeout;
2401 if [info exists timeout] {
2402 set gtimeout $timeout;
2403 }
2404 }
2405
2406 if [info exists atimeout] {
2407 if { ![info exists gtimeout] || $gtimeout < $atimeout } {
2408 set gtimeout $atimeout;
2409 }
2410 } else {
2411 if ![info exists gtimeout] {
2412 # Eeeeew.
2413 set gtimeout 60;
2414 }
2415 }
2416
2417 global suppress_flag;
2418 global remote_suppress_flag;
2419 if [info exists remote_suppress_flag] {
2420 set old_val $remote_suppress_flag;
2421 }
2422 if [info exists suppress_flag] {
2423 if { $suppress_flag } {
2424 set remote_suppress_flag 1;
2425 }
2426 }
2427 set code [catch \
2428 {uplevel remote_expect host $gtimeout $expcode} string];
2429 if [info exists old_val] {
2430 set remote_suppress_flag $old_val;
2431 } else {
2432 if [info exists remote_suppress_flag] {
2433 unset remote_suppress_flag;
2434 }
2435 }
2436
2437 if {$code == 1} {
2438 global errorInfo errorCode;
2439
2440 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
2441 } elseif {$code == 2} {
2442 return -code return $string
2443 } elseif {$code == 3} {
2444 return
2445 } elseif {$code > 4} {
2446 return -code $code $string
2447 }
2448 }
2449
2450 # gdb_expect_list TEST SENTINEL LIST -- expect a sequence of outputs
2451 #
2452 # Check for long sequence of output by parts.
2453 # TEST: is the test message to be printed with the test success/fail.
2454 # SENTINEL: Is the terminal pattern indicating that output has finished.
2455 # LIST: is the sequence of outputs to match.
2456 # If the sentinel is recognized early, it is considered an error.
2457 #
2458 # Returns:
2459 # 1 if the test failed,
2460 # 0 if the test passes,
2461 # -1 if there was an internal error.
2462
2463 proc gdb_expect_list {test sentinel list} {
2464 global gdb_prompt
2465 global suppress_flag
2466 set index 0
2467 set ok 1
2468 if { $suppress_flag } {
2469 set ok 0
2470 unresolved "${test}"
2471 }
2472 while { ${index} < [llength ${list}] } {
2473 set pattern [lindex ${list} ${index}]
2474 set index [expr ${index} + 1]
2475 verbose -log "gdb_expect_list pattern: /$pattern/" 2
2476 if { ${index} == [llength ${list}] } {
2477 if { ${ok} } {
2478 gdb_expect {
2479 -re "${pattern}${sentinel}" {
2480 # pass "${test}, pattern ${index} + sentinel"
2481 }
2482 -re "${sentinel}" {
2483 fail "${test} (pattern ${index} + sentinel)"
2484 set ok 0
2485 }
2486 -re ".*A problem internal to GDB has been detected" {
2487 fail "${test} (GDB internal error)"
2488 set ok 0
2489 gdb_internal_error_resync
2490 }
2491 timeout {
2492 fail "${test} (pattern ${index} + sentinel) (timeout)"
2493 set ok 0
2494 }
2495 }
2496 } else {
2497 # unresolved "${test}, pattern ${index} + sentinel"
2498 }
2499 } else {
2500 if { ${ok} } {
2501 gdb_expect {
2502 -re "${pattern}" {
2503 # pass "${test}, pattern ${index}"
2504 }
2505 -re "${sentinel}" {
2506 fail "${test} (pattern ${index})"
2507 set ok 0
2508 }
2509 -re ".*A problem internal to GDB has been detected" {
2510 fail "${test} (GDB internal error)"
2511 set ok 0
2512 gdb_internal_error_resync
2513 }
2514 timeout {
2515 fail "${test} (pattern ${index}) (timeout)"
2516 set ok 0
2517 }
2518 }
2519 } else {
2520 # unresolved "${test}, pattern ${index}"
2521 }
2522 }
2523 }
2524 if { ${ok} } {
2525 pass "${test}"
2526 return 0
2527 } else {
2528 return 1
2529 }
2530 }
2531
2532 #
2533 #
2534 proc gdb_suppress_entire_file { reason } {
2535 global suppress_flag;
2536
2537 warning "$reason\n";
2538 set suppress_flag -1;
2539 }
2540
2541 #
2542 # Set suppress_flag, which will cause all subsequent calls to send_gdb and
2543 # gdb_expect to fail immediately (until the next call to
2544 # gdb_stop_suppressing_tests).
2545 #
2546 proc gdb_suppress_tests { args } {
2547 global suppress_flag;
2548
2549 return; # fnf - disable pending review of results where
2550 # testsuite ran better without this
2551 incr suppress_flag;
2552
2553 if { $suppress_flag == 1 } {
2554 if { [llength $args] > 0 } {
2555 warning "[lindex $args 0]\n";
2556 } else {
2557 warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n";
2558 }
2559 }
2560 }
2561
2562 #
2563 # Clear suppress_flag.
2564 #
2565 proc gdb_stop_suppressing_tests { } {
2566 global suppress_flag;
2567
2568 if [info exists suppress_flag] {
2569 if { $suppress_flag > 0 } {
2570 set suppress_flag 0;
2571 clone_output "Tests restarted.\n";
2572 }
2573 } else {
2574 set suppress_flag 0;
2575 }
2576 }
2577
2578 proc gdb_clear_suppressed { } {
2579 global suppress_flag;
2580
2581 set suppress_flag 0;
2582 }
2583
2584 proc gdb_start { } {
2585 default_gdb_start
2586 }
2587
2588 proc gdb_exit { } {
2589 catch default_gdb_exit
2590 }
2591
2592 #
2593 # gdb_load_cmd -- load a file into the debugger.
2594 # ARGS - additional args to load command.
2595 # return a -1 if anything goes wrong.
2596 #
2597 proc gdb_load_cmd { args } {
2598 global gdb_prompt
2599
2600 if [target_info exists gdb_load_timeout] {
2601 set loadtimeout [target_info gdb_load_timeout]
2602 } else {
2603 set loadtimeout 1600
2604 }
2605 send_gdb "load $args\n"
2606 verbose "Timeout is now $loadtimeout seconds" 2
2607 gdb_expect $loadtimeout {
2608 -re "Loading section\[^\r\]*\r\n" {
2609 exp_continue
2610 }
2611 -re "Start address\[\r\]*\r\n" {
2612 exp_continue
2613 }
2614 -re "Transfer rate\[\r\]*\r\n" {
2615 exp_continue
2616 }
2617 -re "Memory access error\[^\r\]*\r\n" {
2618 perror "Failed to load program"
2619 return -1
2620 }
2621 -re "$gdb_prompt $" {
2622 return 0
2623 }
2624 -re "(.*)\r\n$gdb_prompt " {
2625 perror "Unexpected reponse from 'load' -- $expect_out(1,string)"
2626 return -1
2627 }
2628 timeout {
2629 perror "Timed out trying to load $args."
2630 return -1
2631 }
2632 }
2633 return -1
2634 }
2635
2636 # Return the filename to download to the target and load on the target
2637 # for this shared library. Normally just LIBNAME, unless shared libraries
2638 # for this target have separate link and load images.
2639
2640 proc shlib_target_file { libname } {
2641 return $libname
2642 }
2643
2644 # Return the filename GDB will load symbols from when debugging this
2645 # shared library. Normally just LIBNAME, unless shared libraries for
2646 # this target have separate link and load images.
2647
2648 proc shlib_symbol_file { libname } {
2649 return $libname
2650 }
2651
2652 # gdb_download
2653 #
2654 # Copy a file to the remote target and return its target filename.
2655 # Schedule the file to be deleted at the end of this test.
2656
2657 proc gdb_download { filename } {
2658 global cleanfiles
2659
2660 set destname [remote_download target $filename]
2661 lappend cleanfiles $destname
2662 return $destname
2663 }
2664
2665 # gdb_load_shlibs LIB...
2666 #
2667 # Copy the listed libraries to the target.
2668
2669 proc gdb_load_shlibs { args } {
2670 if {![is_remote target]} {
2671 return
2672 }
2673
2674 foreach file $args {
2675 gdb_download [shlib_target_file $file]
2676 }
2677
2678 # Even if the target supplies full paths for shared libraries,
2679 # they may not be paths for this system.
2680 gdb_test "set solib-search-path [file dirname [lindex $args 0]]" "" ""
2681 }
2682
2683 #
2684 # gdb_load -- load a file into the debugger.
2685 # Many files in config/*.exp override this procedure.
2686 #
2687 proc gdb_load { arg } {
2688 return [gdb_file_cmd $arg]
2689 }
2690
2691 # gdb_reload -- load a file into the target. Called before "running",
2692 # either the first time or after already starting the program once,
2693 # for remote targets. Most files that override gdb_load should now
2694 # override this instead.
2695
2696 proc gdb_reload { } {
2697 # For the benefit of existing configurations, default to gdb_load.
2698 # Specifying no file defaults to the executable currently being
2699 # debugged.
2700 return [gdb_load ""]
2701 }
2702
2703 proc gdb_continue { function } {
2704 global decimal
2705
2706 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"];
2707 }
2708
2709 proc default_gdb_init { args } {
2710 global gdb_wrapper_initialized
2711 global gdb_wrapper_target
2712 global cleanfiles
2713
2714 set cleanfiles {}
2715
2716 gdb_clear_suppressed;
2717
2718 # Make sure that the wrapper is rebuilt
2719 # with the appropriate multilib option.
2720 if { $gdb_wrapper_target != [current_target_name] } {
2721 set gdb_wrapper_initialized 0
2722 }
2723
2724 # Unlike most tests, we have a small number of tests that generate
2725 # a very large amount of output. We therefore increase the expect
2726 # buffer size to be able to contain the entire test output.
2727 match_max -d 30000
2728 # Also set this value for the currently running GDB.
2729 match_max [match_max -d]
2730
2731 # We want to add the name of the TCL testcase to the PASS/FAIL messages.
2732 if { [llength $args] > 0 } {
2733 global pf_prefix
2734
2735 set file [lindex $args 0];
2736
2737 set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:";
2738 }
2739 global gdb_prompt;
2740 if [target_info exists gdb_prompt] {
2741 set gdb_prompt [target_info gdb_prompt];
2742 } else {
2743 set gdb_prompt "\\(gdb\\)"
2744 }
2745 }
2746
2747 # The default timeout used when testing GDB commands. We want to use
2748 # the same timeout as the default dejagnu timeout, unless the user has
2749 # already provided a specific value (probably through a site.exp file).
2750 global gdb_test_timeout
2751 if ![info exists gdb_test_timeout] {
2752 set gdb_test_timeout $timeout
2753 }
2754
2755 # A list of global variables that GDB testcases should not use.
2756 # We try to prevent their use by monitoring write accesses and raising
2757 # an error when that happens.
2758 set banned_variables { bug_id prms_id }
2759
2760 # gdb_init is called by runtest at start, but also by several
2761 # tests directly; gdb_finish is only called from within runtest after
2762 # each test source execution.
2763 # Placing several traces by repetitive calls to gdb_init leads
2764 # to problems, as only one trace is removed in gdb_finish.
2765 # To overcome this possible problem, we add a variable that records
2766 # if the banned variables are traced.
2767 set banned_variables_traced 0
2768
2769 proc gdb_init { args } {
2770 # Reset the timeout value to the default. This way, any testcase
2771 # that changes the timeout value without resetting it cannot affect
2772 # the timeout used in subsequent testcases.
2773 global gdb_test_timeout
2774 global timeout
2775 set timeout $gdb_test_timeout
2776
2777 # Block writes to all banned variables...
2778 global banned_variables
2779 global banned_variables_traced
2780 if (!$banned_variables_traced) {
2781 foreach banned_var $banned_variables {
2782 global "$banned_var"
2783 trace add variable "$banned_var" write error
2784 }
2785 set banned_variables_traced 1
2786 }
2787
2788 # We set LC_ALL, LC_CTYPE, and LANG to C so that we get the same
2789 # messages as expected.
2790 setenv LC_ALL C
2791 setenv LC_CTYPE C
2792 setenv LANG C
2793
2794 # Don't let a .inputrc file or an existing setting of INPUTRC mess up
2795 # the test results. Even if /dev/null doesn't exist on the particular
2796 # platform, the readline library will use the default setting just by
2797 # failing to open the file. OTOH, opening /dev/null successfully will
2798 # also result in the default settings being used since nothing will be
2799 # read from this file.
2800 setenv INPUTRC "/dev/null"
2801
2802 # The gdb.base/readline.exp arrow key test relies on the standard VT100
2803 # bindings, so make sure that an appropriate terminal is selected.
2804 # The same bug doesn't show up if we use ^P / ^N instead.
2805 setenv TERM "vt100"
2806
2807 # Some tests (for example gdb.base/maint.exp) shell out from gdb to use
2808 # grep. Clear GREP_OPTIONS to make the behavoiur predictable,
2809 # especially having color output turned on can cause tests to fail.
2810 setenv GREP_OPTIONS ""
2811
2812 return [eval default_gdb_init $args];
2813 }
2814
2815 proc gdb_finish { } {
2816 global cleanfiles
2817
2818 # Exit first, so that the files are no longer in use.
2819 gdb_exit
2820
2821 if { [llength $cleanfiles] > 0 } {
2822 eval remote_file target delete $cleanfiles
2823 set cleanfiles {}
2824 }
2825
2826 # Unblock write access to the banned variables. Dejagnu typically
2827 # resets some of them between testcases.
2828 global banned_variables
2829 global banned_variables_traced
2830 if ($banned_variables_traced) {
2831 foreach banned_var $banned_variables {
2832 global "$banned_var"
2833 trace remove variable "$banned_var" write error
2834 }
2835 set banned_variables_traced 0
2836 }
2837 }
2838
2839 global debug_format
2840 set debug_format "unknown"
2841
2842 # Run the gdb command "info source" and extract the debugging format
2843 # information from the output and save it in debug_format.
2844
2845 proc get_debug_format { } {
2846 global gdb_prompt
2847 global verbose
2848 global expect_out
2849 global debug_format
2850
2851 set debug_format "unknown"
2852 send_gdb "info source\n"
2853 gdb_expect 10 {
2854 -re "Compiled with (.*) debugging format.\r\n.*$gdb_prompt $" {
2855 set debug_format $expect_out(1,string)
2856 verbose "debug format is $debug_format"
2857 return 1;
2858 }
2859 -re "No current source file.\r\n$gdb_prompt $" {
2860 perror "get_debug_format used when no current source file"
2861 return 0;
2862 }
2863 -re "$gdb_prompt $" {
2864 warning "couldn't check debug format (no valid response)."
2865 return 1;
2866 }
2867 timeout {
2868 warning "couldn't check debug format (timed out)."
2869 return 1;
2870 }
2871 }
2872 }
2873
2874 # Return true if FORMAT matches the debug format the current test was
2875 # compiled with. FORMAT is a shell-style globbing pattern; it can use
2876 # `*', `[...]', and so on.
2877 #
2878 # This function depends on variables set by `get_debug_format', above.
2879
2880 proc test_debug_format {format} {
2881 global debug_format
2882
2883 return [expr [string match $format $debug_format] != 0]
2884 }
2885
2886 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
2887 # COFF, stabs, etc). If that format matches the format that the
2888 # current test was compiled with, then the next test is expected to
2889 # fail for any target. Returns 1 if the next test or set of tests is
2890 # expected to fail, 0 otherwise (or if it is unknown). Must have
2891 # previously called get_debug_format.
2892 proc setup_xfail_format { format } {
2893 set ret [test_debug_format $format];
2894
2895 if {$ret} then {
2896 setup_xfail "*-*-*"
2897 }
2898 return $ret;
2899 }
2900
2901 proc gdb_step_for_stub { } {
2902 global gdb_prompt;
2903
2904 if ![target_info exists gdb,use_breakpoint_for_stub] {
2905 if [target_info exists gdb_stub_step_command] {
2906 set command [target_info gdb_stub_step_command];
2907 } else {
2908 set command "step";
2909 }
2910 send_gdb "${command}\n";
2911 set tries 0;
2912 gdb_expect 60 {
2913 -re "(main.* at |.*in .*start).*$gdb_prompt" {
2914 return;
2915 }
2916 -re ".*$gdb_prompt" {
2917 incr tries;
2918 if { $tries == 5 } {
2919 fail "stepping out of breakpoint function";
2920 return;
2921 }
2922 send_gdb "${command}\n";
2923 exp_continue;
2924 }
2925 default {
2926 fail "stepping out of breakpoint function";
2927 return;
2928 }
2929 }
2930 }
2931 send_gdb "where\n";
2932 gdb_expect {
2933 -re "main\[^\r\n\]*at \(\[^:]+\):\(\[0-9\]+\)" {
2934 set file $expect_out(1,string);
2935 set linenum [expr $expect_out(2,string) + 1];
2936 set breakplace "${file}:${linenum}";
2937 }
2938 default {}
2939 }
2940 send_gdb "break ${breakplace}\n";
2941 gdb_expect 60 {
2942 -re "Breakpoint (\[0-9\]+) at.*$gdb_prompt" {
2943 set breakpoint $expect_out(1,string);
2944 }
2945 -re "Breakpoint (\[0-9\]+): file.*$gdb_prompt" {
2946 set breakpoint $expect_out(1,string);
2947 }
2948 default {}
2949 }
2950 send_gdb "continue\n";
2951 gdb_expect 60 {
2952 -re "Breakpoint ${breakpoint},.*$gdb_prompt" {
2953 gdb_test "delete $breakpoint" ".*" "";
2954 return;
2955 }
2956 default {}
2957 }
2958 }
2959
2960 # gdb_get_line_number TEXT [FILE]
2961 #
2962 # Search the source file FILE, and return the line number of the
2963 # first line containing TEXT. If no match is found, return -1.
2964 #
2965 # TEXT is a string literal, not a regular expression.
2966 #
2967 # The default value of FILE is "$srcdir/$subdir/$srcfile". If FILE is
2968 # specified, and does not start with "/", then it is assumed to be in
2969 # "$srcdir/$subdir". This is awkward, and can be fixed in the future,
2970 # by changing the callers and the interface at the same time.
2971 # In particular: gdb.base/break.exp, gdb.base/condbreak.exp,
2972 # gdb.base/ena-dis-br.exp.
2973 #
2974 # Use this function to keep your test scripts independent of the
2975 # exact line numbering of the source file. Don't write:
2976 #
2977 # send_gdb "break 20"
2978 #
2979 # This means that if anyone ever edits your test's source file,
2980 # your test could break. Instead, put a comment like this on the
2981 # source file line you want to break at:
2982 #
2983 # /* breakpoint spot: frotz.exp: test name */
2984 #
2985 # and then write, in your test script (which we assume is named
2986 # frotz.exp):
2987 #
2988 # send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
2989 #
2990 # (Yes, Tcl knows how to handle the nested quotes and brackets.
2991 # Try this:
2992 # $ tclsh
2993 # % puts "foo [lindex "bar baz" 1]"
2994 # foo baz
2995 # %
2996 # Tcl is quite clever, for a little stringy language.)
2997 #
2998 # ===
2999 #
3000 # The previous implementation of this procedure used the gdb search command.
3001 # This version is different:
3002 #
3003 # . It works with MI, and it also works when gdb is not running.
3004 #
3005 # . It operates on the build machine, not the host machine.
3006 #
3007 # . For now, this implementation fakes a current directory of
3008 # $srcdir/$subdir to be compatible with the old implementation.
3009 # This will go away eventually and some callers will need to
3010 # be changed.
3011 #
3012 # . The TEXT argument is literal text and matches literally,
3013 # not a regular expression as it was before.
3014 #
3015 # . State changes in gdb, such as changing the current file
3016 # and setting $_, no longer happen.
3017 #
3018 # After a bit of time we can forget about the differences from the
3019 # old implementation.
3020 #
3021 # --chastain 2004-08-05
3022
3023 proc gdb_get_line_number { text { file "" } } {
3024 global srcdir
3025 global subdir
3026 global srcfile
3027
3028 if { "$file" == "" } then {
3029 set file "$srcfile"
3030 }
3031 if { ! [regexp "^/" "$file"] } then {
3032 set file "$srcdir/$subdir/$file"
3033 }
3034
3035 if { [ catch { set fd [open "$file"] } message ] } then {
3036 perror "$message"
3037 return -1
3038 }
3039
3040 set found -1
3041 for { set line 1 } { 1 } { incr line } {
3042 if { [ catch { set nchar [gets "$fd" body] } message ] } then {
3043 perror "$message"
3044 return -1
3045 }
3046 if { $nchar < 0 } then {
3047 break
3048 }
3049 if { [string first "$text" "$body"] >= 0 } then {
3050 set found $line
3051 break
3052 }
3053 }
3054
3055 if { [ catch { close "$fd" } message ] } then {
3056 perror "$message"
3057 return -1
3058 }
3059
3060 return $found
3061 }
3062
3063 # gdb_continue_to_end:
3064 # The case where the target uses stubs has to be handled specially. If a
3065 # stub is used, we set a breakpoint at exit because we cannot rely on
3066 # exit() behavior of a remote target.
3067 #
3068 # MSSG is the error message that gets printed. If not given, a
3069 # default is used.
3070 # COMMAND is the command to invoke. If not given, "continue" is
3071 # used.
3072 # ALLOW_EXTRA is a flag indicating whether the test should expect
3073 # extra output between the "Continuing." line and the program
3074 # exiting. By default it is zero; if nonzero, any extra output
3075 # is accepted.
3076
3077 proc gdb_continue_to_end {{mssg ""} {command continue} {allow_extra 0}} {
3078 global inferior_exited_re
3079
3080 if {$mssg == ""} {
3081 set text "continue until exit"
3082 } else {
3083 set text "continue until exit at $mssg"
3084 }
3085 if {$allow_extra} {
3086 set extra ".*"
3087 } else {
3088 set extra ""
3089 }
3090 if [target_info exists use_gdb_stub] {
3091 if {![gdb_breakpoint "exit"]} {
3092 return 0
3093 }
3094 gdb_test $command "Continuing..*Breakpoint .*exit.*" \
3095 $text
3096 } else {
3097 # Continue until we exit. Should not stop again.
3098 # Don't bother to check the output of the program, that may be
3099 # extremely tough for some remote systems.
3100 gdb_test $command \
3101 "Continuing.\[\r\n0-9\]+${extra}(... EXIT code 0\[\r\n\]+|$inferior_exited_re normally).*"\
3102 $text
3103 }
3104 }
3105
3106 proc rerun_to_main {} {
3107 global gdb_prompt
3108
3109 if [target_info exists use_gdb_stub] {
3110 gdb_run_cmd
3111 gdb_expect {
3112 -re ".*Breakpoint .*main .*$gdb_prompt $"\
3113 {pass "rerun to main" ; return 0}
3114 -re "$gdb_prompt $"\
3115 {fail "rerun to main" ; return 0}
3116 timeout {fail "(timeout) rerun to main" ; return 0}
3117 }
3118 } else {
3119 send_gdb "run\n"
3120 gdb_expect {
3121 -re "The program .* has been started already.*y or n. $" {
3122 send_gdb "y\n"
3123 exp_continue
3124 }
3125 -re "Starting program.*$gdb_prompt $"\
3126 {pass "rerun to main" ; return 0}
3127 -re "$gdb_prompt $"\
3128 {fail "rerun to main" ; return 0}
3129 timeout {fail "(timeout) rerun to main" ; return 0}
3130 }
3131 }
3132 }
3133
3134 # Print a message and return true if a test should be skipped
3135 # due to lack of floating point suport.
3136
3137 proc gdb_skip_float_test { msg } {
3138 if [target_info exists gdb,skip_float_tests] {
3139 verbose "Skipping test '$msg': no float tests.";
3140 return 1;
3141 }
3142 return 0;
3143 }
3144
3145 # Print a message and return true if a test should be skipped
3146 # due to lack of stdio support.
3147
3148 proc gdb_skip_stdio_test { msg } {
3149 if [target_info exists gdb,noinferiorio] {
3150 verbose "Skipping test '$msg': no inferior i/o.";
3151 return 1;
3152 }
3153 return 0;
3154 }
3155
3156 proc gdb_skip_bogus_test { msg } {
3157 return 0;
3158 }
3159
3160 # Return true if a test should be skipped due to lack of XML support
3161 # in the host GDB.
3162 # NOTE: This must be called while gdb is *not* running.
3163
3164 proc gdb_skip_xml_test { } {
3165 global gdb_prompt
3166 global srcdir
3167 global xml_missing_cached
3168
3169 if {[info exists xml_missing_cached]} {
3170 return $xml_missing_cached
3171 }
3172
3173 gdb_start
3174 set xml_missing_cached 0
3175 gdb_test_multiple "set tdesc filename ${srcdir}/gdb.xml/trivial.xml" "" {
3176 -re ".*XML support was disabled at compile time.*$gdb_prompt $" {
3177 set xml_missing_cached 1
3178 }
3179 -re ".*$gdb_prompt $" { }
3180 }
3181 gdb_exit
3182 return $xml_missing_cached
3183 }
3184
3185 # Note: the procedure gdb_gnu_strip_debug will produce an executable called
3186 # ${binfile}.dbglnk, which is just like the executable ($binfile) but without
3187 # the debuginfo. Instead $binfile has a .gnu_debuglink section which contains
3188 # the name of a debuginfo only file. This file will be stored in the same
3189 # subdirectory.
3190
3191 # Functions for separate debug info testing
3192
3193 # starting with an executable:
3194 # foo --> original executable
3195
3196 # at the end of the process we have:
3197 # foo.stripped --> foo w/o debug info
3198 # foo.debug --> foo's debug info
3199 # foo --> like foo, but with a new .gnu_debuglink section pointing to foo.debug.
3200
3201 # Return the build-id hex string (usually 160 bits as 40 hex characters)
3202 # converted to the form: .build-id/ab/cdef1234...89.debug
3203 # Return "" if no build-id found.
3204 proc build_id_debug_filename_get { exec } {
3205 set tmp "${exec}-tmp"
3206 set objcopy_program [transform objcopy]
3207
3208 set result [catch "exec $objcopy_program -j .note.gnu.build-id -O binary $exec $tmp" output]
3209 verbose "result is $result"
3210 verbose "output is $output"
3211 if {$result == 1} {
3212 return ""
3213 }
3214 set fi [open $tmp]
3215 fconfigure $fi -translation binary
3216 # Skip the NOTE header.
3217 read $fi 16
3218 set data [read $fi]
3219 close $fi
3220 file delete $tmp
3221 if ![string compare $data ""] then {
3222 return ""
3223 }
3224 # Convert it to hex.
3225 binary scan $data H* data
3226 regsub {^..} $data {\0/} data
3227 return ".build-id/${data}.debug";
3228 }
3229
3230 # Create stripped files for DEST, replacing it. If ARGS is passed, it is a
3231 # list of optional flags. The only currently supported flag is no-main,
3232 # which removes the symbol entry for main from the separate debug file.
3233 #
3234 # Function returns zero on success. Function will return non-zero failure code
3235 # on some targets not supporting separate debug info (such as i386-msdos).
3236
3237 proc gdb_gnu_strip_debug { dest args } {
3238
3239 # Use the first separate debug info file location searched by GDB so the
3240 # run cannot be broken by some stale file searched with higher precedence.
3241 set debug_file "${dest}.debug"
3242
3243 set strip_to_file_program [transform strip]
3244 set objcopy_program [transform objcopy]
3245
3246 set debug_link [file tail $debug_file]
3247 set stripped_file "${dest}.stripped"
3248
3249 # Get rid of the debug info, and store result in stripped_file
3250 # something like gdb/testsuite/gdb.base/blah.stripped.
3251 set result [catch "exec $strip_to_file_program --strip-debug ${dest} -o ${stripped_file}" output]
3252 verbose "result is $result"
3253 verbose "output is $output"
3254 if {$result == 1} {
3255 return 1
3256 }
3257
3258 # Workaround PR binutils/10802:
3259 # Preserve the 'x' bit also for PIEs (Position Independent Executables).
3260 set perm [file attributes ${dest} -permissions]
3261 file attributes ${stripped_file} -permissions $perm
3262
3263 # Get rid of everything but the debug info, and store result in debug_file
3264 # This will be in the .debug subdirectory, see above.
3265 set result [catch "exec $strip_to_file_program --only-keep-debug ${dest} -o ${debug_file}" output]
3266 verbose "result is $result"
3267 verbose "output is $output"
3268 if {$result == 1} {
3269 return 1
3270 }
3271
3272 # If no-main is passed, strip the symbol for main from the separate
3273 # file. This is to simulate the behavior of elfutils's eu-strip, which
3274 # leaves the symtab in the original file only. There's no way to get
3275 # objcopy or strip to remove the symbol table without also removing the
3276 # debugging sections, so this is as close as we can get.
3277 if { [llength $args] == 1 && [lindex $args 0] == "no-main" } {
3278 set result [catch "exec $objcopy_program -N main ${debug_file} ${debug_file}-tmp" output]
3279 verbose "result is $result"
3280 verbose "output is $output"
3281 if {$result == 1} {
3282 return 1
3283 }
3284 file delete "${debug_file}"
3285 file rename "${debug_file}-tmp" "${debug_file}"
3286 }
3287
3288 # Link the two previous output files together, adding the .gnu_debuglink
3289 # section to the stripped_file, containing a pointer to the debug_file,
3290 # save the new file in dest.
3291 # This will be the regular executable filename, in the usual location.
3292 set result [catch "exec $objcopy_program --add-gnu-debuglink=${debug_file} ${stripped_file} ${dest}" output]
3293 verbose "result is $result"
3294 verbose "output is $output"
3295 if {$result == 1} {
3296 return 1
3297 }
3298
3299 # Workaround PR binutils/10802:
3300 # Preserve the 'x' bit also for PIEs (Position Independent Executables).
3301 set perm [file attributes ${stripped_file} -permissions]
3302 file attributes ${dest} -permissions $perm
3303
3304 return 0
3305 }
3306
3307 # Test the output of GDB_COMMAND matches the pattern obtained
3308 # by concatenating all elements of EXPECTED_LINES. This makes
3309 # it possible to split otherwise very long string into pieces.
3310 # If third argument is not empty, it's used as the name of the
3311 # test to be printed on pass/fail.
3312 proc help_test_raw { gdb_command expected_lines args } {
3313 set message $gdb_command
3314 if [llength $args]>0 then {
3315 set message [lindex $args 0]
3316 }
3317 set expected_output [join $expected_lines ""]
3318 gdb_test "${gdb_command}" "${expected_output}" $message
3319 }
3320
3321 # Test the output of "help COMMNAD_CLASS". EXPECTED_INITIAL_LINES
3322 # are regular expressions that should match the beginning of output,
3323 # before the list of commands in that class. The presence of
3324 # command list and standard epilogue will be tested automatically.
3325 proc test_class_help { command_class expected_initial_lines args } {
3326 set l_stock_body {
3327 "List of commands\:.*\[\r\n\]+"
3328 "Type \"help\" followed by command name for full documentation\.\[\r\n\]+"
3329 "Type \"apropos word\" to search for commands related to \"word\"\.[\r\n\]+"
3330 "Command name abbreviations are allowed if unambiguous\."
3331 }
3332 set l_entire_body [concat $expected_initial_lines $l_stock_body]
3333
3334 eval [list help_test_raw "help ${command_class}" $l_entire_body] $args
3335 }
3336
3337 # COMMAND_LIST should have either one element -- command to test, or
3338 # two elements -- abbreviated command to test, and full command the first
3339 # element is abbreviation of.
3340 # The command must be a prefix command. EXPECTED_INITIAL_LINES
3341 # are regular expressions that should match the beginning of output,
3342 # before the list of subcommands. The presence of
3343 # subcommand list and standard epilogue will be tested automatically.
3344 proc test_prefix_command_help { command_list expected_initial_lines args } {
3345 set command [lindex $command_list 0]
3346 if {[llength $command_list]>1} {
3347 set full_command [lindex $command_list 1]
3348 } else {
3349 set full_command $command
3350 }
3351 # Use 'list' and not just {} because we want variables to
3352 # be expanded in this list.
3353 set l_stock_body [list\
3354 "List of $full_command subcommands\:.*\[\r\n\]+"\
3355 "Type \"help $full_command\" followed by $full_command subcommand name for full documentation\.\[\r\n\]+"\
3356 "Type \"apropos word\" to search for commands related to \"word\"\.\[\r\n\]+"\
3357 "Command name abbreviations are allowed if unambiguous\."]
3358 set l_entire_body [concat $expected_initial_lines $l_stock_body]
3359 if {[llength $args]>0} {
3360 help_test_raw "help ${command}" $l_entire_body [lindex $args 0]
3361 } else {
3362 help_test_raw "help ${command}" $l_entire_body
3363 }
3364 }
3365
3366 # Build executable named EXECUTABLE, from SOURCES. If SOURCES are not
3367 # provided, uses $EXECUTABLE.c. The TESTNAME paramer is the name of test
3368 # to pass to untested, if something is wrong. OPTIONS are passed
3369 # to gdb_compile directly.
3370 proc build_executable { testname executable {sources ""} {options {debug}} } {
3371
3372 global objdir
3373 global subdir
3374 global srcdir
3375 if {[llength $sources]==0} {
3376 set sources ${executable}.c
3377 }
3378
3379 set binfile ${objdir}/${subdir}/${executable}
3380
3381 set objects {}
3382 for {set i 0} "\$i<[llength $sources]" {incr i} {
3383 set s [lindex $sources $i]
3384 if { [gdb_compile "${srcdir}/${subdir}/${s}" "${binfile}${i}.o" object $options] != "" } {
3385 untested $testname
3386 return -1
3387 }
3388 lappend objects "${binfile}${i}.o"
3389 }
3390
3391 if { [gdb_compile $objects "${binfile}" executable $options] != "" } {
3392 untested $testname
3393 return -1
3394 }
3395
3396 set info_options ""
3397 if { [lsearch -exact $options "c++"] >= 0 } {
3398 set info_options "c++"
3399 }
3400 if [get_compiler_info ${binfile} ${info_options}] {
3401 return -1
3402 }
3403 return 0
3404 }
3405
3406 # Starts fresh GDB binary and loads EXECUTABLE into GDB. EXECUTABLE is
3407 # the name of binary in ${objdir}/${subdir}.
3408 proc clean_restart { executable } {
3409 global srcdir
3410 global objdir
3411 global subdir
3412 set binfile ${objdir}/${subdir}/${executable}
3413
3414 gdb_exit
3415 gdb_start
3416 gdb_reinitialize_dir $srcdir/$subdir
3417 gdb_load ${binfile}
3418
3419 if [target_info exists gdb_stub] {
3420 gdb_step_for_stub;
3421 }
3422 }
3423
3424 # Prepares for testing, by calling build_executable, and then clean_restart.
3425 # Please refer to build_executable for parameter description.
3426 proc prepare_for_testing { testname executable {sources ""} {options {debug}}} {
3427
3428 if {[build_executable $testname $executable $sources $options] == -1} {
3429 return -1
3430 }
3431 clean_restart $executable
3432
3433 return 0
3434 }
3435
3436 proc get_valueof { fmt exp default } {
3437 global gdb_prompt
3438
3439 set test "get valueof \"${exp}\""
3440 set val ${default}
3441 gdb_test_multiple "print${fmt} ${exp}" "$test" {
3442 -re "\\$\[0-9\]* = (.*)\[\r\n\]*$gdb_prompt $" {
3443 set val $expect_out(1,string)
3444 pass "$test ($val)"
3445 }
3446 timeout {
3447 fail "$test (timeout)"
3448 }
3449 }
3450 return ${val}
3451 }
3452
3453 proc get_integer_valueof { exp default } {
3454 global gdb_prompt
3455
3456 set test "get integer valueof \"${exp}\""
3457 set val ${default}
3458 gdb_test_multiple "print /d ${exp}" "$test" {
3459 -re "\\$\[0-9\]* = (\[-\]*\[0-9\]*).*$gdb_prompt $" {
3460 set val $expect_out(1,string)
3461 pass "$test ($val)"
3462 }
3463 timeout {
3464 fail "$test (timeout)"
3465 }
3466 }
3467 return ${val}
3468 }
3469
3470 proc get_hexadecimal_valueof { exp default } {
3471 global gdb_prompt
3472 send_gdb "print /x ${exp}\n"
3473 set test "get hexadecimal valueof \"${exp}\""
3474 gdb_expect {
3475 -re "\\$\[0-9\]* = (0x\[0-9a-zA-Z\]+).*$gdb_prompt $" {
3476 set val $expect_out(1,string)
3477 pass "$test"
3478 }
3479 timeout {
3480 set val ${default}
3481 fail "$test (timeout)"
3482 }
3483 }
3484 return ${val}
3485 }
3486
3487 proc get_sizeof { type default } {
3488 return [get_integer_valueof "sizeof (${type})" $default]
3489 }
3490
3491 # Log gdb command line and script if requested.
3492 if {[info exists TRANSCRIPT]} {
3493 rename send_gdb real_send_gdb
3494 rename remote_spawn real_remote_spawn
3495 rename remote_close real_remote_close
3496
3497 global gdb_transcript
3498 set gdb_transcript ""
3499
3500 global gdb_trans_count
3501 set gdb_trans_count 1
3502
3503 proc remote_spawn {args} {
3504 global gdb_transcript gdb_trans_count outdir
3505
3506 if {$gdb_transcript != ""} {
3507 close $gdb_transcript
3508 }
3509 set gdb_transcript [open [file join $outdir transcript.$gdb_trans_count] w]
3510 puts $gdb_transcript [lindex $args 1]
3511 incr gdb_trans_count
3512
3513 return [uplevel real_remote_spawn $args]
3514 }
3515
3516 proc remote_close {args} {
3517 global gdb_transcript
3518
3519 if {$gdb_transcript != ""} {
3520 close $gdb_transcript
3521 set gdb_transcript ""
3522 }
3523
3524 return [uplevel real_remote_close $args]
3525 }
3526
3527 proc send_gdb {args} {
3528 global gdb_transcript
3529
3530 if {$gdb_transcript != ""} {
3531 puts -nonewline $gdb_transcript [lindex $args 0]
3532 }
3533
3534 return [uplevel real_send_gdb $args]
3535 }
3536 }
3537
3538 proc core_find {binfile {deletefiles {}} {arg ""}} {
3539 global objdir subdir
3540
3541 set destcore "$binfile.core"
3542 file delete $destcore
3543
3544 # Create a core file named "$destcore" rather than just "core", to
3545 # avoid problems with sys admin types that like to regularly prune all
3546 # files named "core" from the system.
3547 #
3548 # Arbitrarily try setting the core size limit to "unlimited" since
3549 # this does not hurt on systems where the command does not work and
3550 # allows us to generate a core on systems where it does.
3551 #
3552 # Some systems append "core" to the name of the program; others append
3553 # the name of the program to "core"; still others (like Linux, as of
3554 # May 2003) create cores named "core.PID". In the latter case, we
3555 # could have many core files lying around, and it may be difficult to
3556 # tell which one is ours, so let's run the program in a subdirectory.
3557 set found 0
3558 set coredir "${objdir}/${subdir}/coredir.[getpid]"
3559 file mkdir $coredir
3560 catch "system \"(cd ${coredir}; ulimit -c unlimited; ${binfile} ${arg}; true) >/dev/null 2>&1\""
3561 # remote_exec host "${binfile}"
3562 foreach i "${coredir}/core ${coredir}/core.coremaker.c ${binfile}.core" {
3563 if [remote_file build exists $i] {
3564 remote_exec build "mv $i $destcore"
3565 set found 1
3566 }
3567 }
3568 # Check for "core.PID".
3569 if { $found == 0 } {
3570 set names [glob -nocomplain -directory $coredir core.*]
3571 if {[llength $names] == 1} {
3572 set corefile [file join $coredir [lindex $names 0]]
3573 remote_exec build "mv $corefile $destcore"
3574 set found 1
3575 }
3576 }
3577 if { $found == 0 } {
3578 # The braindamaged HPUX shell quits after the ulimit -c above
3579 # without executing ${binfile}. So we try again without the
3580 # ulimit here if we didn't find a core file above.
3581 # Oh, I should mention that any "braindamaged" non-Unix system has
3582 # the same problem. I like the cd bit too, it's really neat'n stuff.
3583 catch "system \"(cd ${objdir}/${subdir}; ${binfile}; true) >/dev/null 2>&1\""
3584 foreach i "${objdir}/${subdir}/core ${objdir}/${subdir}/core.coremaker.c ${binfile}.core" {
3585 if [remote_file build exists $i] {
3586 remote_exec build "mv $i $destcore"
3587 set found 1
3588 }
3589 }
3590 }
3591
3592 # Try to clean up after ourselves.
3593 foreach deletefile $deletefiles {
3594 remote_file build delete [file join $coredir $deletefile]
3595 }
3596 remote_exec build "rmdir $coredir"
3597
3598 if { $found == 0 } {
3599 warning "can't generate a core file - core tests suppressed - check ulimit -c"
3600 return ""
3601 }
3602 return $destcore
3603 }