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