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