047bf504faa5e7b0daa5e3c23ad7da7cd95baf4f
[deliverable/binutils-gdb.git] / gdb / testsuite / lib / gdb.exp
1 # Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
2 # 2002, 2003, 2004, 2005
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 2 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, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 # This file was written by Fred Fish. (fnf@cygnus.com)
20
21 # Generic gdb subroutines that should work for any target. If these
22 # need to be modified for any target, it can be done with a variable
23 # or by passing arguments.
24
25 load_lib libgloss.exp
26
27 global GDB
28
29 if [info exists TOOL_EXECUTABLE] {
30 set GDB $TOOL_EXECUTABLE;
31 }
32 if ![info exists GDB] {
33 if ![is_remote host] {
34 set GDB [findfile $base_dir/../../gdb/gdb "$base_dir/../../gdb/gdb" [transform gdb]]
35 } else {
36 set GDB [transform gdb];
37 }
38 }
39 verbose "using GDB = $GDB" 2
40
41 global GDBFLAGS
42 if ![info exists GDBFLAGS] {
43 set GDBFLAGS "-nx"
44 }
45 verbose "using GDBFLAGS = $GDBFLAGS" 2
46
47 # The variable gdb_prompt is a regexp which matches the gdb prompt.
48 # Set it if it is not already set.
49 global gdb_prompt
50 if ![info exists gdb_prompt] then {
51 set gdb_prompt "\[(\]gdb\[)\]"
52 }
53
54 # The variable fullname_syntax_POSIX is a regexp which matches a POSIX
55 # absolute path ie. /foo/
56 set fullname_syntax_POSIX "/.*/"
57 # The variable fullname_syntax_UNC is a regexp which matches a Windows
58 # UNC path ie. \\D\foo\
59 set fullname_syntax_UNC {\\\\[^\\]+\\.+\\}
60 # The variable fullname_syntax_DOS_CASE is a regexp which matches a
61 # particular DOS case that GDB most likely will output
62 # ie. \foo\, but don't match \\.*\
63 set fullname_syntax_DOS_CASE {\\[^\\].*\\}
64 # The variable fullname_syntax_DOS is a regexp which matches a DOS path
65 # ie. a:\foo\ && a:foo\
66 set fullname_syntax_DOS {[a-zA-Z]:.*\\}
67 # The variable fullname_syntax is a regexp which matches what GDB considers
68 # an absolute path. It is currently debatable if the Windows style paths
69 # d:foo and \abc should be considered valid as an absolute path.
70 # Also, the purpse of this regexp is not to recognize a well formed
71 # absolute path, but to say with certainty that a path is absolute.
72 set fullname_syntax "($fullname_syntax_POSIX|$fullname_syntax_UNC|$fullname_syntax_DOS_CASE|$fullname_syntax_DOS)"
73
74 # Needed for some tests under Cygwin.
75 global EXEEXT
76 global env
77
78 if ![info exists env(EXEEXT)] {
79 set EXEEXT ""
80 } else {
81 set EXEEXT $env(EXEEXT)
82 }
83
84 ### Only procedures should come after this point.
85
86 #
87 # gdb_version -- extract and print the version number of GDB
88 #
89 proc default_gdb_version {} {
90 global GDB
91 global GDBFLAGS
92 global gdb_prompt
93 set fileid [open "gdb_cmd" w];
94 puts $fileid "q";
95 close $fileid;
96 set cmdfile [remote_download host "gdb_cmd"];
97 set output [remote_exec host "$GDB -nw --command $cmdfile"]
98 remote_file build delete "gdb_cmd";
99 remote_file host delete "$cmdfile";
100 set tmp [lindex $output 1];
101 set version ""
102 regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version
103 if ![is_remote host] {
104 clone_output "[which $GDB] version $version $GDBFLAGS\n"
105 } else {
106 clone_output "$GDB on remote host version $version $GDBFLAGS\n"
107 }
108 }
109
110 proc gdb_version { } {
111 return [default_gdb_version];
112 }
113
114 #
115 # gdb_unload -- unload a file if one is loaded
116 #
117
118 proc gdb_unload {} {
119 global verbose
120 global GDB
121 global gdb_prompt
122 send_gdb "file\n"
123 gdb_expect 60 {
124 -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue }
125 -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue }
126 -re "A program is being debugged already..*Kill it.*y or n. $"\
127 { send_gdb "y\n"
128 verbose "\t\tKilling previous program being debugged"
129 exp_continue
130 }
131 -re "Discard symbol table from .*y or n.*$" {
132 send_gdb "y\n"
133 exp_continue
134 }
135 -re "$gdb_prompt $" {}
136 timeout {
137 perror "couldn't unload file in $GDB (timed out)."
138 return -1
139 }
140 }
141 }
142
143 # Many of the tests depend on setting breakpoints at various places and
144 # running until that breakpoint is reached. At times, we want to start
145 # with a clean-slate with respect to breakpoints, so this utility proc
146 # lets us do this without duplicating this code everywhere.
147 #
148
149 proc delete_breakpoints {} {
150 global gdb_prompt
151
152 # we need a larger timeout value here or this thing just confuses
153 # itself. May need a better implementation if possible. - guo
154 #
155 send_gdb "delete breakpoints\n"
156 gdb_expect 100 {
157 -re "Delete all breakpoints.*y or n.*$" {
158 send_gdb "y\n";
159 exp_continue
160 }
161 -re "$gdb_prompt $" { # This happens if there were no breakpoints
162 }
163 timeout { perror "Delete all breakpoints in delete_breakpoints (timeout)" ; return }
164 }
165 send_gdb "info breakpoints\n"
166 gdb_expect 100 {
167 -re "No breakpoints or watchpoints..*$gdb_prompt $" {}
168 -re "$gdb_prompt $" { perror "breakpoints not deleted" ; return }
169 -re "Delete all breakpoints.*or n.*$" {
170 send_gdb "y\n";
171 exp_continue
172 }
173 timeout { perror "info breakpoints (timeout)" ; return }
174 }
175 }
176
177
178 #
179 # Generic run command.
180 #
181 # The second pattern below matches up to the first newline *only*.
182 # Using ``.*$'' could swallow up output that we attempt to match
183 # elsewhere.
184 #
185 proc gdb_run_cmd {args} {
186 global gdb_prompt
187
188 if [target_info exists gdb_init_command] {
189 send_gdb "[target_info gdb_init_command]\n";
190 gdb_expect 30 {
191 -re "$gdb_prompt $" { }
192 default {
193 perror "gdb_init_command for target failed";
194 return;
195 }
196 }
197 }
198
199 if [target_info exists use_gdb_stub] {
200 if [target_info exists gdb,do_reload_on_run] {
201 # Specifying no file, defaults to the executable
202 # currently being debugged.
203 if { [gdb_load ""] != 0 } {
204 return;
205 }
206 send_gdb "continue\n";
207 gdb_expect 60 {
208 -re "Continu\[^\r\n\]*\[\r\n\]" {}
209 default {}
210 }
211 return;
212 }
213
214 if [target_info exists gdb,start_symbol] {
215 set start [target_info gdb,start_symbol];
216 } else {
217 set start "start";
218 }
219 send_gdb "jump *$start\n"
220 set start_attempt 1;
221 while { $start_attempt } {
222 # Cap (re)start attempts at three to ensure that this loop
223 # always eventually fails. Don't worry about trying to be
224 # clever and not send a command when it has failed.
225 if [expr $start_attempt > 3] {
226 perror "Jump to start() failed (retry count exceeded)";
227 return;
228 }
229 set start_attempt [expr $start_attempt + 1];
230 gdb_expect 30 {
231 -re "Continuing at \[^\r\n\]*\[\r\n\]" {
232 set start_attempt 0;
233 }
234 -re "No symbol \"_start\" in current.*$gdb_prompt $" {
235 perror "Can't find start symbol to run in gdb_run";
236 return;
237 }
238 -re "No symbol \"start\" in current.*$gdb_prompt $" {
239 send_gdb "jump *_start\n";
240 }
241 -re "No symbol.*context.*$gdb_prompt $" {
242 set start_attempt 0;
243 }
244 -re "Line.* Jump anyway.*y or n. $" {
245 send_gdb "y\n"
246 }
247 -re "The program is not being run.*$gdb_prompt $" {
248 if { [gdb_load ""] != 0 } {
249 return;
250 }
251 send_gdb "jump *$start\n";
252 }
253 timeout {
254 perror "Jump to start() failed (timeout)";
255 return
256 }
257 }
258 }
259 if [target_info exists gdb_stub] {
260 gdb_expect 60 {
261 -re "$gdb_prompt $" {
262 send_gdb "continue\n"
263 }
264 }
265 }
266 return
267 }
268
269 if [target_info exists gdb,do_reload_on_run] {
270 if { [gdb_load ""] != 0 } {
271 return;
272 }
273 }
274 send_gdb "run $args\n"
275 # This doesn't work quite right yet.
276 gdb_expect 60 {
277 -re "The program .* has been started already.*y or n. $" {
278 send_gdb "y\n"
279 exp_continue
280 }
281 -re "Starting program: \[^\r\n\]*" {}
282 }
283 }
284
285 # Set a breakpoint at FUNCTION. If there is an additional argument it is
286 # a list of options; the only currently supported option is allow-pending.
287
288 proc gdb_breakpoint { function args } {
289 global gdb_prompt
290 global decimal
291
292 set pending_response n
293 if {[lsearch -exact [lindex $args 0] allow-pending] != -1} {
294 set pending_response y
295 }
296
297 send_gdb "break $function\n"
298 # The first two regexps are what we get with -g, the third is without -g.
299 gdb_expect 30 {
300 -re "Breakpoint \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {}
301 -re "Breakpoint \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {}
302 -re "Breakpoint \[0-9\]* at .*$gdb_prompt $" {}
303 -re "Breakpoint \[0-9\]* \\(.*\\) pending.*$gdb_prompt $" {
304 if {$pending_response == "n"} {
305 fail "setting breakpoint at $function"
306 return 0
307 }
308 }
309 -re "Make breakpoint pending.*y or \\\[n\\\]. $" {
310 send_gdb "$pending_response\n"
311 exp_continue
312 }
313 -re "$gdb_prompt $" { fail "setting breakpoint at $function" ; return 0 }
314 timeout { fail "setting breakpoint at $function (timeout)" ; return 0 }
315 }
316 return 1;
317 }
318
319 # Set breakpoint at function and run gdb until it breaks there.
320 # Since this is the only breakpoint that will be set, if it stops
321 # at a breakpoint, we will assume it is the one we want. We can't
322 # just compare to "function" because it might be a fully qualified,
323 # single quoted C++ function specifier. If there's an additional argument,
324 # pass it to gdb_breakpoint.
325
326 proc runto { function args } {
327 global gdb_prompt
328 global decimal
329
330 delete_breakpoints
331
332 if ![gdb_breakpoint $function [lindex $args 0]] {
333 return 0;
334 }
335
336 gdb_run_cmd
337
338 # the "at foo.c:36" output we get with -g.
339 # the "in func" output we get without -g.
340 gdb_expect 30 {
341 -re "Break.* at .*:$decimal.*$gdb_prompt $" {
342 return 1
343 }
344 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" {
345 return 1
346 }
347 -re "$gdb_prompt $" {
348 fail "running to $function in runto"
349 return 0
350 }
351 timeout {
352 fail "running to $function in runto (timeout)"
353 return 0
354 }
355 }
356 return 1
357 }
358
359 #
360 # runto_main -- ask gdb to run until we hit a breakpoint at main.
361 # The case where the target uses stubs has to be handled
362 # specially--if it uses stubs, assuming we hit
363 # breakpoint() and just step out of the function.
364 #
365 proc runto_main { } {
366 global gdb_prompt
367 global decimal
368
369 if ![target_info exists gdb_stub] {
370 return [runto main]
371 }
372
373 delete_breakpoints
374
375 gdb_step_for_stub;
376
377 return 1
378 }
379
380
381 ### Continue, and expect to hit a breakpoint.
382 ### Report a pass or fail, depending on whether it seems to have
383 ### worked. Use NAME as part of the test name; each call to
384 ### continue_to_breakpoint should use a NAME which is unique within
385 ### that test file.
386 proc gdb_continue_to_breakpoint {name} {
387 global gdb_prompt
388 set full_name "continue to breakpoint: $name"
389
390 send_gdb "continue\n"
391 gdb_expect {
392 -re "Breakpoint .* at .*\r\n$gdb_prompt $" {
393 pass $full_name
394 }
395 -re ".*$gdb_prompt $" {
396 fail $full_name
397 }
398 timeout {
399 fail "$full_name (timeout)"
400 }
401 }
402 }
403
404
405 # gdb_internal_error_resync:
406 #
407 # Answer the questions GDB asks after it reports an internal error
408 # until we get back to a GDB prompt. Decline to quit the debugging
409 # session, and decline to create a core file. Return non-zero if the
410 # resync succeeds.
411 #
412 # This procedure just answers whatever questions come up until it sees
413 # a GDB prompt; it doesn't require you to have matched the input up to
414 # any specific point. However, it only answers questions it sees in
415 # the output itself, so if you've matched a question, you had better
416 # answer it yourself before calling this.
417 #
418 # You can use this function thus:
419 #
420 # gdb_expect {
421 # ...
422 # -re ".*A problem internal to GDB has been detected" {
423 # gdb_internal_error_resync
424 # }
425 # ...
426 # }
427 #
428 proc gdb_internal_error_resync {} {
429 global gdb_prompt
430
431 set count 0
432 while {$count < 10} {
433 gdb_expect {
434 -re "Quit this debugging session\\? \\(y or n\\) $" {
435 send_gdb "n\n"
436 incr count
437 }
438 -re "Create a core file of GDB\\? \\(y or n\\) $" {
439 send_gdb "n\n"
440 incr count
441 }
442 -re "$gdb_prompt $" {
443 # We're resynchronized.
444 return 1
445 }
446 timeout {
447 perror "Could not resync from internal error (timeout)"
448 return 0
449 }
450 }
451 }
452 perror "Could not resync from internal error (resync count exceeded)"
453 return 0
454 }
455
456
457 # gdb_test_multiple COMMAND MESSAGE EXPECT_ARGUMENTS
458 # Send a command to gdb; test the result.
459 #
460 # COMMAND is the command to execute, send to GDB with send_gdb. If
461 # this is the null string no command is sent.
462 # MESSAGE is a message to be printed with the built-in failure patterns
463 # if one of them matches. If MESSAGE is empty COMMAND will be used.
464 # EXPECT_ARGUMENTS will be fed to expect in addition to the standard
465 # patterns. Pattern elements will be evaluated in the caller's
466 # context; action elements will be executed in the caller's context.
467 # Unlike patterns for gdb_test, these patterns should generally include
468 # the final newline and prompt.
469 #
470 # Returns:
471 # 1 if the test failed, according to a built-in failure pattern
472 # 0 if only user-supplied patterns matched
473 # -1 if there was an internal error.
474 #
475 # You can use this function thus:
476 #
477 # gdb_test_multiple "print foo" "test foo" {
478 # -re "expected output 1" {
479 # pass "print foo"
480 # }
481 # -re "expected output 2" {
482 # fail "print foo"
483 # }
484 # }
485 #
486 # The standard patterns, such as "Program exited..." and "A problem
487 # ...", all being implicitly appended to that list.
488 #
489 proc gdb_test_multiple { command message user_code } {
490 global verbose
491 global gdb_prompt
492 global GDB
493 upvar timeout timeout
494 upvar expect_out expect_out
495
496 if { $message == "" } {
497 set message $command
498 }
499
500 # TCL/EXPECT WART ALERT
501 # Expect does something very strange when it receives a single braced
502 # argument. It splits it along word separators and performs substitutions.
503 # This means that { "[ab]" } is evaluated as "[ab]", but { "\[ab\]" } is
504 # evaluated as "\[ab\]". But that's not how TCL normally works; inside a
505 # double-quoted list item, "\[ab\]" is just a long way of representing
506 # "[ab]", because the backslashes will be removed by lindex.
507
508 # Unfortunately, there appears to be no easy way to duplicate the splitting
509 # that expect will do from within TCL. And many places make use of the
510 # "\[0-9\]" construct, so we need to support that; and some places make use
511 # of the "[func]" construct, so we need to support that too. In order to
512 # get this right we have to substitute quoted list elements differently
513 # from braced list elements.
514
515 # We do this roughly the same way that Expect does it. We have to use two
516 # lists, because if we leave unquoted newlines in the argument to uplevel
517 # they'll be treated as command separators, and if we escape newlines
518 # we mangle newlines inside of command blocks. This assumes that the
519 # input doesn't contain a pattern which contains actual embedded newlines
520 # at this point!
521
522 regsub -all {\n} ${user_code} { } subst_code
523 set subst_code [uplevel list $subst_code]
524
525 set processed_code ""
526 set patterns ""
527 set expecting_action 0
528 foreach item $user_code subst_item $subst_code {
529 if { $item == "-n" || $item == "-notransfer" || $item == "-nocase" } {
530 lappend processed_code $item
531 continue
532 }
533 if {$item == "-indices" || $item == "-re" || $item == "-ex"} {
534 lappend processed_code $item
535 continue
536 }
537 if { $expecting_action } {
538 lappend processed_code "uplevel [list $item]"
539 set expecting_action 0
540 # Cosmetic, no effect on the list.
541 append processed_code "\n"
542 continue
543 }
544 set expecting_action 1
545 lappend processed_code $subst_item
546 if {$patterns != ""} {
547 append patterns "; "
548 }
549 append patterns "\"$subst_item\""
550 }
551
552 # Also purely cosmetic.
553 regsub -all {\r} $patterns {\\r} patterns
554 regsub -all {\n} $patterns {\\n} patterns
555
556 if $verbose>2 then {
557 send_user "Sending \"$command\" to gdb\n"
558 send_user "Looking to match \"$patterns\"\n"
559 send_user "Message is \"$message\"\n"
560 }
561
562 set result -1
563 set string "${command}\n";
564 if { $command != "" } {
565 while { "$string" != "" } {
566 set foo [string first "\n" "$string"];
567 set len [string length "$string"];
568 if { $foo < [expr $len - 1] } {
569 set str [string range "$string" 0 $foo];
570 if { [send_gdb "$str"] != "" } {
571 global suppress_flag;
572
573 if { ! $suppress_flag } {
574 perror "Couldn't send $command to GDB.";
575 }
576 fail "$message";
577 return $result;
578 }
579 # since we're checking if each line of the multi-line
580 # command are 'accepted' by GDB here,
581 # we need to set -notransfer expect option so that
582 # command output is not lost for pattern matching
583 # - guo
584 gdb_expect 2 {
585 -notransfer -re "\[\r\n\]" { verbose "partial: match" 3 }
586 timeout { verbose "partial: timeout" 3 }
587 }
588 set string [string range "$string" [expr $foo + 1] end];
589 } else {
590 break;
591 }
592 }
593 if { "$string" != "" } {
594 if { [send_gdb "$string"] != "" } {
595 global suppress_flag;
596
597 if { ! $suppress_flag } {
598 perror "Couldn't send $command to GDB.";
599 }
600 fail "$message";
601 return $result;
602 }
603 }
604 }
605
606 if [target_info exists gdb,timeout] {
607 set tmt [target_info gdb,timeout];
608 } else {
609 if [info exists timeout] {
610 set tmt $timeout;
611 } else {
612 global timeout;
613 if [info exists timeout] {
614 set tmt $timeout;
615 } else {
616 set tmt 60;
617 }
618 }
619 }
620
621 set code {
622 -re ".*A problem internal to GDB has been detected" {
623 fail "$message (GDB internal error)"
624 gdb_internal_error_resync
625 }
626 -re "\\*\\*\\* DOSEXIT code.*" {
627 if { $message != "" } {
628 fail "$message";
629 }
630 gdb_suppress_entire_file "GDB died";
631 set result -1;
632 }
633 -re "Ending remote debugging.*$gdb_prompt $" {
634 if ![isnative] then {
635 warning "Can`t communicate to remote target."
636 }
637 gdb_exit
638 gdb_start
639 set result -1
640 }
641 }
642 append code $processed_code
643 append code {
644 -re "Undefined\[a-z\]* command:.*$gdb_prompt $" {
645 perror "Undefined command \"$command\"."
646 fail "$message"
647 set result 1
648 }
649 -re "Ambiguous command.*$gdb_prompt $" {
650 perror "\"$command\" is not a unique command name."
651 fail "$message"
652 set result 1
653 }
654 -re "Program exited with code \[0-9\]+.*$gdb_prompt $" {
655 if ![string match "" $message] then {
656 set errmsg "$message (the program exited)"
657 } else {
658 set errmsg "$command (the program exited)"
659 }
660 fail "$errmsg"
661 set result -1
662 }
663 -re "EXIT code \[0-9\r\n\]+Program exited normally.*$gdb_prompt $" {
664 if ![string match "" $message] then {
665 set errmsg "$message (the program exited)"
666 } else {
667 set errmsg "$command (the program exited)"
668 }
669 fail "$errmsg"
670 set result -1
671 }
672 -re "The program is not being run.*$gdb_prompt $" {
673 if ![string match "" $message] then {
674 set errmsg "$message (the program is no longer running)"
675 } else {
676 set errmsg "$command (the program is no longer running)"
677 }
678 fail "$errmsg"
679 set result -1
680 }
681 -re "\r\n$gdb_prompt $" {
682 if ![string match "" $message] then {
683 fail "$message"
684 }
685 set result 1
686 }
687 "<return>" {
688 send_gdb "\n"
689 perror "Window too small."
690 fail "$message"
691 set result -1
692 }
693 -re "\\(y or n\\) " {
694 send_gdb "n\n"
695 perror "Got interactive prompt."
696 fail "$message"
697 set result -1
698 }
699 eof {
700 perror "Process no longer exists"
701 if { $message != "" } {
702 fail "$message"
703 }
704 return -1
705 }
706 full_buffer {
707 perror "internal buffer is full."
708 fail "$message"
709 set result -1
710 }
711 timeout {
712 if ![string match "" $message] then {
713 fail "$message (timeout)"
714 }
715 set result 1
716 }
717 }
718
719 set result 0
720 set code [catch {gdb_expect $tmt $code} string]
721 if {$code == 1} {
722 global errorInfo errorCode;
723 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
724 } elseif {$code == 2} {
725 return -code return $string
726 } elseif {$code == 3} {
727 return
728 } elseif {$code > 4} {
729 return -code $code $string
730 }
731 return $result
732 }
733
734 # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE
735 # Send a command to gdb; test the result.
736 #
737 # COMMAND is the command to execute, send to GDB with send_gdb. If
738 # this is the null string no command is sent.
739 # PATTERN is the pattern to match for a PASS, and must NOT include
740 # the \r\n sequence immediately before the gdb prompt.
741 # MESSAGE is an optional message to be printed. If this is
742 # omitted, then the pass/fail messages use the command string as the
743 # message. (If this is the empty string, then sometimes we don't
744 # call pass or fail at all; I don't understand this at all.)
745 # QUESTION is a question GDB may ask in response to COMMAND, like
746 # "are you sure?"
747 # RESPONSE is the response to send if QUESTION appears.
748 #
749 # Returns:
750 # 1 if the test failed,
751 # 0 if the test passes,
752 # -1 if there was an internal error.
753 #
754 proc gdb_test { args } {
755 global verbose
756 global gdb_prompt
757 global GDB
758 upvar timeout timeout
759
760 if [llength $args]>2 then {
761 set message [lindex $args 2]
762 } else {
763 set message [lindex $args 0]
764 }
765 set command [lindex $args 0]
766 set pattern [lindex $args 1]
767
768 if [llength $args]==5 {
769 set question_string [lindex $args 3];
770 set response_string [lindex $args 4];
771 } else {
772 set question_string "^FOOBAR$"
773 }
774
775 return [gdb_test_multiple $command $message {
776 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
777 if ![string match "" $message] then {
778 pass "$message"
779 }
780 }
781 -re "(${question_string})$" {
782 send_gdb "$response_string\n";
783 exp_continue;
784 }
785 }]
786 }
787 \f
788 # Test that a command gives an error. For pass or fail, return
789 # a 1 to indicate that more tests can proceed. However a timeout
790 # is a serious error, generates a special fail message, and causes
791 # a 0 to be returned to indicate that more tests are likely to fail
792 # as well.
793
794 proc test_print_reject { args } {
795 global gdb_prompt
796 global verbose
797
798 if [llength $args]==2 then {
799 set expectthis [lindex $args 1]
800 } else {
801 set expectthis "should never match this bogus string"
802 }
803 set sendthis [lindex $args 0]
804 if $verbose>2 then {
805 send_user "Sending \"$sendthis\" to gdb\n"
806 send_user "Looking to match \"$expectthis\"\n"
807 }
808 send_gdb "$sendthis\n"
809 #FIXME: Should add timeout as parameter.
810 gdb_expect {
811 -re "A .* in expression.*\\.*$gdb_prompt $" {
812 pass "reject $sendthis"
813 return 1
814 }
815 -re "Invalid syntax in expression.*$gdb_prompt $" {
816 pass "reject $sendthis"
817 return 1
818 }
819 -re "Junk after end of expression.*$gdb_prompt $" {
820 pass "reject $sendthis"
821 return 1
822 }
823 -re "Invalid number.*$gdb_prompt $" {
824 pass "reject $sendthis"
825 return 1
826 }
827 -re "Invalid character constant.*$gdb_prompt $" {
828 pass "reject $sendthis"
829 return 1
830 }
831 -re "No symbol table is loaded.*$gdb_prompt $" {
832 pass "reject $sendthis"
833 return 1
834 }
835 -re "No symbol .* in current context.*$gdb_prompt $" {
836 pass "reject $sendthis"
837 return 1
838 }
839 -re "Unmatched single quote.*$gdb_prompt $" {
840 pass "reject $sendthis"
841 return 1
842 }
843 -re "A character constant must contain at least one character.*$gdb_prompt $" {
844 pass "reject $sendthis"
845 return 1
846 }
847 -re "$expectthis.*$gdb_prompt $" {
848 pass "reject $sendthis"
849 return 1
850 }
851 -re ".*$gdb_prompt $" {
852 fail "reject $sendthis"
853 return 1
854 }
855 default {
856 fail "reject $sendthis (eof or timeout)"
857 return 0
858 }
859 }
860 }
861 \f
862 # Given an input string, adds backslashes as needed to create a
863 # regexp that will match the string.
864
865 proc string_to_regexp {str} {
866 set result $str
867 regsub -all {[]*+.|()^$\[\\]} $str {\\&} result
868 return $result
869 }
870
871 # Same as gdb_test, but the second parameter is not a regexp,
872 # but a string that must match exactly.
873
874 proc gdb_test_exact { args } {
875 upvar timeout timeout
876
877 set command [lindex $args 0]
878
879 # This applies a special meaning to a null string pattern. Without
880 # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
881 # messages from commands that should have no output except a new
882 # prompt. With this, only results of a null string will match a null
883 # string pattern.
884
885 set pattern [lindex $args 1]
886 if [string match $pattern ""] {
887 set pattern [string_to_regexp [lindex $args 0]]
888 } else {
889 set pattern [string_to_regexp [lindex $args 1]]
890 }
891
892 # It is most natural to write the pattern argument with only
893 # embedded \n's, especially if you are trying to avoid Tcl quoting
894 # problems. But gdb_expect really wants to see \r\n in patterns. So
895 # transform the pattern here. First transform \r\n back to \n, in
896 # case some users of gdb_test_exact already do the right thing.
897 regsub -all "\r\n" $pattern "\n" pattern
898 regsub -all "\n" $pattern "\r\n" pattern
899 if [llength $args]==3 then {
900 set message [lindex $args 2]
901 } else {
902 set message $command
903 }
904
905 return [gdb_test $command $pattern $message]
906 }
907 \f
908 proc gdb_reinitialize_dir { subdir } {
909 global gdb_prompt
910
911 if [is_remote host] {
912 return "";
913 }
914 send_gdb "dir\n"
915 gdb_expect 60 {
916 -re "Reinitialize source path to empty.*y or n. " {
917 send_gdb "y\n"
918 gdb_expect 60 {
919 -re "Source directories searched.*$gdb_prompt $" {
920 send_gdb "dir $subdir\n"
921 gdb_expect 60 {
922 -re "Source directories searched.*$gdb_prompt $" {
923 verbose "Dir set to $subdir"
924 }
925 -re "$gdb_prompt $" {
926 perror "Dir \"$subdir\" failed."
927 }
928 }
929 }
930 -re "$gdb_prompt $" {
931 perror "Dir \"$subdir\" failed."
932 }
933 }
934 }
935 -re "$gdb_prompt $" {
936 perror "Dir \"$subdir\" failed."
937 }
938 }
939 }
940
941 #
942 # gdb_exit -- exit the GDB, killing the target program if necessary
943 #
944 proc default_gdb_exit {} {
945 global GDB
946 global GDBFLAGS
947 global verbose
948 global gdb_spawn_id;
949
950 gdb_stop_suppressing_tests;
951
952 if ![info exists gdb_spawn_id] {
953 return;
954 }
955
956 verbose "Quitting $GDB $GDBFLAGS"
957
958 if { [is_remote host] && [board_info host exists fileid] } {
959 send_gdb "quit\n";
960 gdb_expect 10 {
961 -re "y or n" {
962 send_gdb "y\n";
963 exp_continue;
964 }
965 -re "DOSEXIT code" { }
966 default { }
967 }
968 }
969
970 if ![is_remote host] {
971 remote_close host;
972 }
973 unset gdb_spawn_id
974 }
975
976 # Load a file into the debugger.
977 # The return value is 0 for success, -1 for failure.
978 #
979 # This procedure also set the global variable GDB_FILE_CMD_DEBUG_INFO
980 # to one of these values:
981 #
982 # debug file was loaded successfully and has debug information
983 # nodebug file was loaded successfully and has no debug information
984 # fail file was not loaded
985 #
986 # I tried returning this information as part of the return value,
987 # but ran into a mess because of the many re-implementations of
988 # gdb_load in config/*.exp.
989 #
990 # TODO: gdb.base/sepdebug.exp and gdb.stabs/weird.exp might be able to use
991 # this if they can get more information set.
992
993 proc gdb_file_cmd { arg } {
994 global gdb_prompt
995 global verbose
996 global GDB
997
998 # Set whether debug info was found.
999 # Default to "fail".
1000 global gdb_file_cmd_debug_info
1001 set gdb_file_cmd_debug_info "fail"
1002
1003 if [is_remote host] {
1004 set arg [remote_download host $arg]
1005 if { $arg == "" } {
1006 perror "download failed"
1007 return -1
1008 }
1009 }
1010
1011 # The file command used to kill the remote target. For the benefit
1012 # of the testsuite, preserve this behavior.
1013 send_gdb "kill\n"
1014 gdb_expect 120 {
1015 -re "Kill the program being debugged. .y or n. $" {
1016 send_gdb "y\n"
1017 verbose "\t\tKilling previous program being debugged"
1018 exp_continue
1019 }
1020 -re "$gdb_prompt $" {
1021 # OK.
1022 }
1023 }
1024
1025 send_gdb "file $arg\n"
1026 gdb_expect 120 {
1027 -re "Reading symbols from.*no debugging symbols found.*done.*$gdb_prompt $" {
1028 verbose "\t\tLoaded $arg into the $GDB with no debugging symbols"
1029 set gdb_file_cmd_debug_info "nodebug"
1030 return 0
1031 }
1032 -re "Reading symbols from.*done.*$gdb_prompt $" {
1033 verbose "\t\tLoaded $arg into the $GDB"
1034 set gdb_file_cmd_debug_info "debug"
1035 return 0
1036 }
1037 -re "Load new symbol table from \".*\".*y or n. $" {
1038 send_gdb "y\n"
1039 gdb_expect 120 {
1040 -re "Reading symbols from.*done.*$gdb_prompt $" {
1041 verbose "\t\tLoaded $arg with new symbol table into $GDB"
1042 set gdb_file_cmd_debug_info "debug"
1043 return 0
1044 }
1045 timeout {
1046 perror "(timeout) Couldn't load $arg, other program already loaded."
1047 return -1
1048 }
1049 }
1050 }
1051 -re "No such file or directory.*$gdb_prompt $" {
1052 perror "($arg) No such file or directory"
1053 return -1
1054 }
1055 -re "$gdb_prompt $" {
1056 perror "couldn't load $arg into $GDB."
1057 return -1
1058 }
1059 timeout {
1060 perror "couldn't load $arg into $GDB (timed out)."
1061 return -1
1062 }
1063 eof {
1064 # This is an attempt to detect a core dump, but seems not to
1065 # work. Perhaps we need to match .* followed by eof, in which
1066 # gdb_expect does not seem to have a way to do that.
1067 perror "couldn't load $arg into $GDB (end of file)."
1068 return -1
1069 }
1070 }
1071 }
1072
1073 #
1074 # start gdb -- start gdb running, default procedure
1075 #
1076 # When running over NFS, particularly if running many simultaneous
1077 # tests on different hosts all using the same server, things can
1078 # get really slow. Give gdb at least 3 minutes to start up.
1079 #
1080 proc default_gdb_start { } {
1081 global verbose
1082 global GDB
1083 global GDBFLAGS
1084 global gdb_prompt
1085 global timeout
1086 global gdb_spawn_id;
1087
1088 gdb_stop_suppressing_tests;
1089
1090 verbose "Spawning $GDB -nw $GDBFLAGS"
1091
1092 if [info exists gdb_spawn_id] {
1093 return 0;
1094 }
1095
1096 if ![is_remote host] {
1097 if { [which $GDB] == 0 } then {
1098 perror "$GDB does not exist."
1099 exit 1
1100 }
1101 }
1102 set res [remote_spawn host "$GDB -nw $GDBFLAGS [host_info gdb_opts]"];
1103 if { $res < 0 || $res == "" } {
1104 perror "Spawning $GDB failed."
1105 return 1;
1106 }
1107 gdb_expect 360 {
1108 -re "\[\r\n\]$gdb_prompt $" {
1109 verbose "GDB initialized."
1110 }
1111 -re "$gdb_prompt $" {
1112 perror "GDB never initialized."
1113 return -1
1114 }
1115 timeout {
1116 perror "(timeout) GDB never initialized after 10 seconds."
1117 remote_close host;
1118 return -1
1119 }
1120 }
1121 set gdb_spawn_id -1;
1122 # force the height to "unlimited", so no pagers get used
1123
1124 send_gdb "set height 0\n"
1125 gdb_expect 10 {
1126 -re "$gdb_prompt $" {
1127 verbose "Setting height to 0." 2
1128 }
1129 timeout {
1130 warning "Couldn't set the height to 0"
1131 }
1132 }
1133 # force the width to "unlimited", so no wraparound occurs
1134 send_gdb "set width 0\n"
1135 gdb_expect 10 {
1136 -re "$gdb_prompt $" {
1137 verbose "Setting width to 0." 2
1138 }
1139 timeout {
1140 warning "Couldn't set the width to 0."
1141 }
1142 }
1143 return 0;
1144 }
1145
1146 # Return a 1 for configurations for which we don't even want to try to
1147 # test C++.
1148
1149 proc skip_cplus_tests {} {
1150 if { [istarget "d10v-*-*"] } {
1151 return 1
1152 }
1153 if { [istarget "h8300-*-*"] } {
1154 return 1
1155 }
1156
1157 # The C++ IO streams are too large for HC11/HC12 and are thus not
1158 # available. The gdb C++ tests use them and don't compile.
1159 if { [istarget "m6811-*-*"] } {
1160 return 1
1161 }
1162 if { [istarget "m6812-*-*"] } {
1163 return 1
1164 }
1165 return 0
1166 }
1167
1168 # Return a 1 if I don't even want to try to test FORTRAN.
1169
1170 proc skip_fortran_tests {} {
1171 return 0
1172 }
1173
1174 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
1175 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
1176
1177 proc skip_altivec_tests {} {
1178 global skip_vmx_tests_saved
1179 global srcdir subdir gdb_prompt
1180
1181 # Use the cached value, if it exists.
1182 set me "skip_altivec_tests"
1183 if [info exists skip_vmx_tests_saved] {
1184 verbose "$me: returning saved $skip_vmx_tests_saved" 2
1185 return $skip_vmx_tests_saved
1186 }
1187
1188 # Some simulators are known to not support VMX instructions.
1189 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
1190 verbose "$me: target known to not support VMX, returning 1" 2
1191 return [set $skip_vmx_tests_saved 1]
1192 }
1193
1194 # Make sure we have a compiler that understands altivec.
1195 set compile_flags {debug nowarnings}
1196 if [get_compiler_info not-used] {
1197 warning "Could not get compiler info"
1198 return 1
1199 }
1200 if [test_compiler_info gcc*] {
1201 set compile_flags "$compile_flags additional_flags=-maltivec"
1202 } elseif [test_compiler_info xlc*] {
1203 set compile_flags "$compile_flags additional_flags=-qaltivec"
1204 } else {
1205 verbose "Could not compile with altivec support, returning 1" 2
1206 return 1
1207 }
1208
1209 # Set up, compile, and execute a test program containing VMX instructions.
1210 # Include the current process ID in the file names to prevent conflicts
1211 # with invocations for multiple testsuites.
1212 set src vmx[pid].c
1213 set exe vmx[pid].x
1214
1215 set f [open $src "w"]
1216 puts $f "int main() {"
1217 puts $f "#ifdef __MACH__"
1218 puts $f " asm volatile (\"vor v0,v0,v0\");"
1219 puts $f "#else"
1220 puts $f " asm volatile (\"vor 0,0,0\");"
1221 puts $f "#endif"
1222 puts $f " return 0; }"
1223 close $f
1224
1225 verbose "$me: compiling testfile $src" 2
1226 set lines [gdb_compile $src $exe executable $compile_flags]
1227 file delete $src
1228
1229 if ![string match "" $lines] then {
1230 verbose "$me: testfile compilation failed, returning 1" 2
1231 return [set skip_vmx_tests_saved 1]
1232 }
1233
1234 # No error message, compilation succeeded so now run it via gdb.
1235
1236 gdb_exit
1237 gdb_start
1238 gdb_reinitialize_dir $srcdir/$subdir
1239 gdb_load "$exe"
1240 gdb_run_cmd
1241 gdb_expect {
1242 -re ".*Illegal instruction.*${gdb_prompt} $" {
1243 verbose -log "\n$me altivec hardware not detected"
1244 set skip_vmx_tests_saved 1
1245 }
1246 -re ".*Program exited normally.*${gdb_prompt} $" {
1247 verbose -log "\n$me: altivec hardware detected"
1248 set skip_vmx_tests_saved 0
1249 }
1250 default {
1251 warning "\n$me: default case taken"
1252 set skip_vmx_tests_saved 1
1253 }
1254 }
1255 gdb_exit
1256 remote_file build delete $exe
1257
1258 verbose "$me: returning $skip_vmx_tests_saved" 2
1259 return $skip_vmx_tests_saved
1260 }
1261
1262 # Skip all the tests in the file if you are not on an hppa running
1263 # hpux target.
1264
1265 proc skip_hp_tests {} {
1266 eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ]
1267 verbose "Skip hp tests is $skip_hp"
1268 return $skip_hp
1269 }
1270
1271 set compiler_info "unknown"
1272 set gcc_compiled 0
1273 set hp_cc_compiler 0
1274 set hp_aCC_compiler 0
1275
1276 # Figure out what compiler I am using.
1277 #
1278 # BINFILE is a "compiler information" output file. This implementation
1279 # does not use BINFILE.
1280 #
1281 # ARGS can be empty or "C++". If empty, "C" is assumed.
1282 #
1283 # There are several ways to do this, with various problems.
1284 #
1285 # [ gdb_compile -E $ifile -o $binfile.ci ]
1286 # source $binfile.ci
1287 #
1288 # Single Unix Spec v3 says that "-E -o ..." together are not
1289 # specified. And in fact, the native compiler on hp-ux 11 (among
1290 # others) does not work with "-E -o ...". Most targets used to do
1291 # this, and it mostly worked, because it works with gcc.
1292 #
1293 # [ catch "exec $compiler -E $ifile > $binfile.ci" exec_output ]
1294 # source $binfile.ci
1295 #
1296 # This avoids the problem with -E and -o together. This almost works
1297 # if the build machine is the same as the host machine, which is
1298 # usually true of the targets which are not gcc. But this code does
1299 # not figure which compiler to call, and it always ends up using the C
1300 # compiler. Not good for setting hp_aCC_compiler. Targets
1301 # hppa*-*-hpux* and mips*-*-irix* used to do this.
1302 #
1303 # [ gdb_compile -E $ifile > $binfile.ci ]
1304 # source $binfile.ci
1305 #
1306 # dejagnu target_compile says that it supports output redirection,
1307 # but the code is completely different from the normal path and I
1308 # don't want to sweep the mines from that path. So I didn't even try
1309 # this.
1310 #
1311 # set cppout [ gdb_compile $ifile "" preprocess $args quiet ]
1312 # eval $cppout
1313 #
1314 # I actually do this for all targets now. gdb_compile runs the right
1315 # compiler, and TCL captures the output, and I eval the output.
1316 #
1317 # Unfortunately, expect logs the output of the command as it goes by,
1318 # and dejagnu helpfully prints a second copy of it right afterwards.
1319 # So I turn off expect logging for a moment.
1320 #
1321 # [ gdb_compile $ifile $ciexe_file executable $args ]
1322 # [ remote_exec $ciexe_file ]
1323 # [ source $ci_file.out ]
1324 #
1325 # I could give up on -E and just do this.
1326 # I didn't get desperate enough to try this.
1327 #
1328 # -- chastain 2004-01-06
1329
1330 proc get_compiler_info {binfile args} {
1331 # For compiler.c and compiler.cc
1332 global srcdir
1333
1334 # I am going to play with the log to keep noise out.
1335 global outdir
1336 global tool
1337
1338 # These come from compiler.c or compiler.cc
1339 global compiler_info
1340
1341 # Legacy global data symbols.
1342 global gcc_compiled
1343 global hp_cc_compiler
1344 global hp_aCC_compiler
1345
1346 # Choose which file to preprocess.
1347 set ifile "${srcdir}/lib/compiler.c"
1348 if { [llength $args] > 0 && [lindex $args 0] == "c++" } {
1349 set ifile "${srcdir}/lib/compiler.cc"
1350 }
1351
1352 # Run $ifile through the right preprocessor.
1353 # Toggle gdb.log to keep the compiler output out of the log.
1354 log_file
1355 set cppout [ gdb_compile "${ifile}" "" preprocess [list "$args" quiet] ]
1356 log_file -a "$outdir/$tool.log"
1357
1358 # Eval the output.
1359 set unknown 0
1360 foreach cppline [ split "$cppout" "\n" ] {
1361 if { [ regexp "^#" "$cppline" ] } {
1362 # line marker
1363 } elseif { [ regexp "^\[\n\r\t \]*$" "$cppline" ] } {
1364 # blank line
1365 } elseif { [ regexp "^\[\n\r\t \]*set\[\n\r\t \]" "$cppline" ] } {
1366 # eval this line
1367 verbose "get_compiler_info: $cppline" 2
1368 eval "$cppline"
1369 } else {
1370 # unknown line
1371 verbose -log "get_compiler_info: $cppline"
1372 set unknown 1
1373 }
1374 }
1375
1376 # Reset to unknown compiler if any diagnostics happened.
1377 if { $unknown } {
1378 set compiler_info "unknown"
1379 }
1380
1381 # Set the legacy symbols.
1382 set gcc_compiled 0
1383 set hp_cc_compiler 0
1384 set hp_aCC_compiler 0
1385 if { [regexp "^gcc-1-" "$compiler_info" ] } { set gcc_compiled 1 }
1386 if { [regexp "^gcc-2-" "$compiler_info" ] } { set gcc_compiled 2 }
1387 if { [regexp "^gcc-3-" "$compiler_info" ] } { set gcc_compiled 3 }
1388 if { [regexp "^gcc-4-" "$compiler_info" ] } { set gcc_compiled 4 }
1389 if { [regexp "^gcc-5-" "$compiler_info" ] } { set gcc_compiled 5 }
1390 if { [regexp "^hpcc-" "$compiler_info" ] } { set hp_cc_compiler 1 }
1391 if { [regexp "^hpacc-" "$compiler_info" ] } { set hp_aCC_compiler 1 }
1392
1393 # Log what happened.
1394 verbose -log "get_compiler_info: $compiler_info"
1395
1396 # Most compilers will evaluate comparisons and other boolean
1397 # operations to 0 or 1.
1398 uplevel \#0 { set true 1 }
1399 uplevel \#0 { set false 0 }
1400
1401 # Use of aCC results in boolean results being displayed as
1402 # "true" or "false"
1403 if { $hp_aCC_compiler } {
1404 uplevel \#0 { set true true }
1405 uplevel \#0 { set false false }
1406 }
1407
1408 return 0;
1409 }
1410
1411 proc test_compiler_info { {compiler ""} } {
1412 global compiler_info
1413
1414 # if no arg, return the compiler_info string
1415
1416 if [string match "" $compiler] {
1417 if [info exists compiler_info] {
1418 return $compiler_info
1419 } else {
1420 perror "No compiler info found."
1421 }
1422 }
1423
1424 return [string match $compiler $compiler_info]
1425 }
1426
1427 set gdb_wrapper_initialized 0
1428
1429 proc gdb_wrapper_init { args } {
1430 global gdb_wrapper_initialized;
1431 global gdb_wrapper_file;
1432 global gdb_wrapper_flags;
1433
1434 if { $gdb_wrapper_initialized == 1 } { return; }
1435
1436 if {[target_info exists needs_status_wrapper] && \
1437 [target_info needs_status_wrapper] != "0"} {
1438 set result [build_wrapper "testglue.o"];
1439 if { $result != "" } {
1440 set gdb_wrapper_file [lindex $result 0];
1441 set gdb_wrapper_flags [lindex $result 1];
1442 } else {
1443 warning "Status wrapper failed to build."
1444 }
1445 }
1446 set gdb_wrapper_initialized 1
1447 }
1448
1449 proc gdb_compile {source dest type options} {
1450 global GDB_TESTCASE_OPTIONS;
1451 global gdb_wrapper_file;
1452 global gdb_wrapper_flags;
1453 global gdb_wrapper_initialized;
1454
1455 # Add platform-specific options if a shared library was specified using
1456 # "shlib=librarypath" in OPTIONS.
1457 set new_options ""
1458 set shlib_found 0
1459 foreach opt $options {
1460 if [regexp {^shlib=(.*)} $opt dummy_var shlib_name] {
1461 if [test_compiler_info "xlc-*"] {
1462 # IBM xlc compiler doesn't accept shared library named other
1463 # than .so: use "-Wl," to bypass this
1464 lappend source "-Wl,$shlib_name"
1465 } else {
1466 lappend source $shlib_name
1467 }
1468 if {$shlib_found == 0} {
1469 set shlib_found 1
1470 if { ([test_compiler_info "gcc-*"]
1471 && ([istarget "powerpc*-*-aix*"]
1472 || [istarget "rs6000*-*-aix*"] )) } {
1473 lappend options "additional_flags=-L${objdir}/${subdir}"
1474 } elseif { [istarget "mips-sgi-irix*"] } {
1475 lappend options "additional_flags=-rpath ${objdir}/${subdir}"
1476 }
1477 }
1478 } else {
1479 lappend new_options $opt
1480 }
1481 }
1482 set options $new_options
1483
1484 if [target_info exists gdb_stub] {
1485 set options2 { "additional_flags=-Dusestubs" }
1486 lappend options "libs=[target_info gdb_stub]";
1487 set options [concat $options2 $options]
1488 }
1489 if [target_info exists is_vxworks] {
1490 set options2 { "additional_flags=-Dvxworks" }
1491 lappend options "libs=[target_info gdb_stub]";
1492 set options [concat $options2 $options]
1493 }
1494 if [info exists GDB_TESTCASE_OPTIONS] {
1495 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS";
1496 }
1497 verbose "options are $options"
1498 verbose "source is $source $dest $type $options"
1499
1500 if { $gdb_wrapper_initialized == 0 } { gdb_wrapper_init }
1501
1502 if {[target_info exists needs_status_wrapper] && \
1503 [target_info needs_status_wrapper] != "0" && \
1504 [info exists gdb_wrapper_file]} {
1505 lappend options "libs=${gdb_wrapper_file}"
1506 lappend options "ldflags=${gdb_wrapper_flags}"
1507 }
1508
1509 # Replace the "nowarnings" option with the appropriate additional_flags
1510 # to disable compiler warnings.
1511 set nowarnings [lsearch -exact $options nowarnings]
1512 if {$nowarnings != -1} {
1513 if [target_info exists gdb,nowarnings_flag] {
1514 set flag "additional_flags=[target_info gdb,nowarnings_flag]"
1515 } else {
1516 set flag "additional_flags=-w"
1517 }
1518 set options [lreplace $options $nowarnings $nowarnings $flag]
1519 }
1520
1521 set result [target_compile $source $dest $type $options];
1522 regsub "\[\r\n\]*$" "$result" "" result;
1523 regsub "^\[\r\n\]*" "$result" "" result;
1524 if { $result != "" && [lsearch $options quiet] == -1} {
1525 clone_output "gdb compile failed, $result"
1526 }
1527 return $result;
1528 }
1529
1530
1531 # This is just like gdb_compile, above, except that it tries compiling
1532 # against several different thread libraries, to see which one this
1533 # system has.
1534 proc gdb_compile_pthreads {source dest type options} {
1535 set built_binfile 0
1536 set why_msg "unrecognized error"
1537 foreach lib {-lpthreads -lpthread -lthread} {
1538 # This kind of wipes out whatever libs the caller may have
1539 # set. Or maybe theirs will override ours. How infelicitous.
1540 set options_with_lib [concat $options [list libs=$lib quiet]]
1541 set ccout [gdb_compile $source $dest $type $options_with_lib]
1542 switch -regexp -- $ccout {
1543 ".*no posix threads support.*" {
1544 set why_msg "missing threads include file"
1545 break
1546 }
1547 ".*cannot open -lpthread.*" {
1548 set why_msg "missing runtime threads library"
1549 }
1550 ".*Can't find library for -lpthread.*" {
1551 set why_msg "missing runtime threads library"
1552 }
1553 {^$} {
1554 pass "successfully compiled posix threads test case"
1555 set built_binfile 1
1556 break
1557 }
1558 }
1559 }
1560 if {!$built_binfile} {
1561 unsupported "Couldn't compile $source: ${why_msg}"
1562 return -1
1563 }
1564 }
1565
1566 # Build a shared library from SOURCES. You must use get_compiler_info
1567 # first.
1568
1569 proc gdb_compile_shlib {sources dest options} {
1570 set obj_options $options
1571
1572 switch -glob [test_compiler_info] {
1573 "xlc-*" {
1574 lappend obj_options "additional_flags=-qpic"
1575 }
1576 "gcc-*" {
1577 if { !([istarget "powerpc*-*-aix*"]
1578 || [istarget "rs6000*-*-aix*"]) } {
1579 lappend obj_options "additional_flags=-fpic"
1580 }
1581 }
1582 default {
1583 switch -glob [istarget] {
1584 "hppa*-hp-hpux*" {
1585 lappend obj_options "additional_flags=+z"
1586 }
1587 "mips-sgi-irix*" {
1588 # Disable SGI compiler's implicit -Dsgi
1589 lappend obj_options "additional_flags=-Usgi"
1590 }
1591 default {
1592 # don't know what the compiler is...
1593 }
1594 }
1595 }
1596 }
1597
1598 set outdir [file dirname $dest]
1599 set objects ""
1600 foreach source $sources {
1601 set sourcebase [file tail $source]
1602 if {[gdb_compile $source "${outdir}/${sourcebase}.o" object $obj_options] != ""} {
1603 return -1
1604 }
1605 lappend objects ${outdir}/${sourcebase}.o
1606 }
1607
1608 if [istarget "hppa*-*-hpux*"] {
1609 remote_exec build "ld -b ${objects} -o ${dest}"
1610 } else {
1611 set link_options $options
1612 if [test_compiler_info "xlc-*"] {
1613 lappend link_options "additional_flags=-qmkshrobj"
1614 } else {
1615 lappend link_options "additional_flags=-shared"
1616 }
1617 if {[gdb_compile "${objects}" "${dest}" executable $link_options] != ""} {
1618 return -1
1619 }
1620 }
1621 }
1622
1623 # This is just like gdb_compile_pthreads, above, except that we always add the
1624 # objc library for compiling Objective-C programs
1625 proc gdb_compile_objc {source dest type options} {
1626 set built_binfile 0
1627 set why_msg "unrecognized error"
1628 foreach lib {-lobjc -lpthreads -lpthread -lthread solaris} {
1629 # This kind of wipes out whatever libs the caller may have
1630 # set. Or maybe theirs will override ours. How infelicitous.
1631 if { $lib == "solaris" } {
1632 set lib "-lpthread -lposix4"
1633 }
1634 if { $lib != "-lobjc" } {
1635 set lib "-lobjc $lib"
1636 }
1637 set options_with_lib [concat $options [list libs=$lib quiet]]
1638 set ccout [gdb_compile $source $dest $type $options_with_lib]
1639 switch -regexp -- $ccout {
1640 ".*no posix threads support.*" {
1641 set why_msg "missing threads include file"
1642 break
1643 }
1644 ".*cannot open -lpthread.*" {
1645 set why_msg "missing runtime threads library"
1646 }
1647 ".*Can't find library for -lpthread.*" {
1648 set why_msg "missing runtime threads library"
1649 }
1650 {^$} {
1651 pass "successfully compiled objc with posix threads test case"
1652 set built_binfile 1
1653 break
1654 }
1655 }
1656 }
1657 if {!$built_binfile} {
1658 unsupported "Couldn't compile $source: ${why_msg}"
1659 return -1
1660 }
1661 }
1662
1663 proc send_gdb { string } {
1664 global suppress_flag;
1665 if { $suppress_flag } {
1666 return "suppressed";
1667 }
1668 return [remote_send host "$string"];
1669 }
1670
1671 #
1672 #
1673
1674 proc gdb_expect { args } {
1675 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
1676 set gtimeout [lindex $args 0];
1677 set expcode [list [lindex $args 1]];
1678 } else {
1679 upvar timeout timeout;
1680
1681 set expcode $args;
1682 if [target_info exists gdb,timeout] {
1683 if [info exists timeout] {
1684 if { $timeout < [target_info gdb,timeout] } {
1685 set gtimeout [target_info gdb,timeout];
1686 } else {
1687 set gtimeout $timeout;
1688 }
1689 } else {
1690 set gtimeout [target_info gdb,timeout];
1691 }
1692 }
1693
1694 if ![info exists gtimeout] {
1695 global timeout;
1696 if [info exists timeout] {
1697 set gtimeout $timeout;
1698 } else {
1699 # Eeeeew.
1700 set gtimeout 60;
1701 }
1702 }
1703 }
1704 global suppress_flag;
1705 global remote_suppress_flag;
1706 if [info exists remote_suppress_flag] {
1707 set old_val $remote_suppress_flag;
1708 }
1709 if [info exists suppress_flag] {
1710 if { $suppress_flag } {
1711 set remote_suppress_flag 1;
1712 }
1713 }
1714 set code [catch \
1715 {uplevel remote_expect host $gtimeout $expcode} string];
1716 if [info exists old_val] {
1717 set remote_suppress_flag $old_val;
1718 } else {
1719 if [info exists remote_suppress_flag] {
1720 unset remote_suppress_flag;
1721 }
1722 }
1723
1724 if {$code == 1} {
1725 global errorInfo errorCode;
1726
1727 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
1728 } elseif {$code == 2} {
1729 return -code return $string
1730 } elseif {$code == 3} {
1731 return
1732 } elseif {$code > 4} {
1733 return -code $code $string
1734 }
1735 }
1736
1737 # gdb_expect_list MESSAGE SENTINEL LIST -- expect a sequence of outputs
1738 #
1739 # Check for long sequence of output by parts.
1740 # MESSAGE: is the test message to be printed with the test success/fail.
1741 # SENTINEL: Is the terminal pattern indicating that output has finished.
1742 # LIST: is the sequence of outputs to match.
1743 # If the sentinel is recognized early, it is considered an error.
1744 #
1745 # Returns:
1746 # 1 if the test failed,
1747 # 0 if the test passes,
1748 # -1 if there was an internal error.
1749 #
1750 proc gdb_expect_list {test sentinel list} {
1751 global gdb_prompt
1752 global suppress_flag
1753 set index 0
1754 set ok 1
1755 if { $suppress_flag } {
1756 set ok 0
1757 unresolved "${test}"
1758 }
1759 while { ${index} < [llength ${list}] } {
1760 set pattern [lindex ${list} ${index}]
1761 set index [expr ${index} + 1]
1762 if { ${index} == [llength ${list}] } {
1763 if { ${ok} } {
1764 gdb_expect {
1765 -re "${pattern}${sentinel}" {
1766 # pass "${test}, pattern ${index} + sentinel"
1767 }
1768 -re "${sentinel}" {
1769 fail "${test} (pattern ${index} + sentinel)"
1770 set ok 0
1771 }
1772 -re ".*A problem internal to GDB has been detected" {
1773 fail "${test} (GDB internal error)"
1774 set ok 0
1775 gdb_internal_error_resync
1776 }
1777 timeout {
1778 fail "${test} (pattern ${index} + sentinel) (timeout)"
1779 set ok 0
1780 }
1781 }
1782 } else {
1783 # unresolved "${test}, pattern ${index} + sentinel"
1784 }
1785 } else {
1786 if { ${ok} } {
1787 gdb_expect {
1788 -re "${pattern}" {
1789 # pass "${test}, pattern ${index}"
1790 }
1791 -re "${sentinel}" {
1792 fail "${test} (pattern ${index})"
1793 set ok 0
1794 }
1795 -re ".*A problem internal to GDB has been detected" {
1796 fail "${test} (GDB internal error)"
1797 set ok 0
1798 gdb_internal_error_resync
1799 }
1800 timeout {
1801 fail "${test} (pattern ${index}) (timeout)"
1802 set ok 0
1803 }
1804 }
1805 } else {
1806 # unresolved "${test}, pattern ${index}"
1807 }
1808 }
1809 }
1810 if { ${ok} } {
1811 pass "${test}"
1812 return 0
1813 } else {
1814 return 1
1815 }
1816 }
1817
1818 #
1819 #
1820 proc gdb_suppress_entire_file { reason } {
1821 global suppress_flag;
1822
1823 warning "$reason\n";
1824 set suppress_flag -1;
1825 }
1826
1827 #
1828 # Set suppress_flag, which will cause all subsequent calls to send_gdb and
1829 # gdb_expect to fail immediately (until the next call to
1830 # gdb_stop_suppressing_tests).
1831 #
1832 proc gdb_suppress_tests { args } {
1833 global suppress_flag;
1834
1835 return; # fnf - disable pending review of results where
1836 # testsuite ran better without this
1837 incr suppress_flag;
1838
1839 if { $suppress_flag == 1 } {
1840 if { [llength $args] > 0 } {
1841 warning "[lindex $args 0]\n";
1842 } else {
1843 warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n";
1844 }
1845 }
1846 }
1847
1848 #
1849 # Clear suppress_flag.
1850 #
1851 proc gdb_stop_suppressing_tests { } {
1852 global suppress_flag;
1853
1854 if [info exists suppress_flag] {
1855 if { $suppress_flag > 0 } {
1856 set suppress_flag 0;
1857 clone_output "Tests restarted.\n";
1858 }
1859 } else {
1860 set suppress_flag 0;
1861 }
1862 }
1863
1864 proc gdb_clear_suppressed { } {
1865 global suppress_flag;
1866
1867 set suppress_flag 0;
1868 }
1869
1870 proc gdb_start { } {
1871 default_gdb_start
1872 }
1873
1874 proc gdb_exit { } {
1875 catch default_gdb_exit
1876 }
1877
1878 #
1879 # gdb_load_cmd -- load a file into the debugger.
1880 # ARGS - additional args to load command.
1881 # return a -1 if anything goes wrong.
1882 #
1883 proc gdb_load_cmd { args } {
1884 global gdb_prompt
1885
1886 if [target_info exists gdb_load_timeout] {
1887 set loadtimeout [target_info gdb_load_timeout]
1888 } else {
1889 set loadtimeout 1600
1890 }
1891 send_gdb "load $args\n"
1892 verbose "Timeout is now $timeout seconds" 2
1893 gdb_expect $loadtimeout {
1894 -re "Loading section\[^\r\]*\r\n" {
1895 exp_continue
1896 }
1897 -re "Start address\[\r\]*\r\n" {
1898 exp_continue
1899 }
1900 -re "Transfer rate\[\r\]*\r\n" {
1901 exp_continue
1902 }
1903 -re "Memory access error\[^\r\]*\r\n" {
1904 perror "Failed to load program"
1905 return -1
1906 }
1907 -re "$gdb_prompt $" {
1908 return 0
1909 }
1910 -re "(.*)\r\n$gdb_prompt " {
1911 perror "Unexpected reponse from 'load' -- $expect_out(1,string)"
1912 return -1
1913 }
1914 timeout {
1915 perror "Timed out trying to load $arg."
1916 return -1
1917 }
1918 }
1919 return -1
1920 }
1921
1922 #
1923 # gdb_load -- load a file into the debugger.
1924 # Many files in config/*.exp override this procedure.
1925 #
1926 proc gdb_load { arg } {
1927 return [gdb_file_cmd $arg]
1928 }
1929
1930 proc gdb_continue { function } {
1931 global decimal
1932
1933 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"];
1934 }
1935
1936 proc default_gdb_init { args } {
1937 global gdb_wrapper_initialized
1938
1939 gdb_clear_suppressed;
1940
1941 # Make sure that the wrapper is rebuilt
1942 # with the appropriate multilib option.
1943 set gdb_wrapper_initialized 0
1944
1945 # Uh, this is lame. Really, really, really lame. But there's this *one*
1946 # testcase that will fail in random places if we don't increase this.
1947 match_max -d 20000
1948
1949 # We want to add the name of the TCL testcase to the PASS/FAIL messages.
1950 if { [llength $args] > 0 } {
1951 global pf_prefix
1952
1953 set file [lindex $args 0];
1954
1955 set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:";
1956 }
1957 global gdb_prompt;
1958 if [target_info exists gdb_prompt] {
1959 set gdb_prompt [target_info gdb_prompt];
1960 } else {
1961 set gdb_prompt "\\(gdb\\)"
1962 }
1963 }
1964
1965 proc gdb_init { args } {
1966 return [eval default_gdb_init $args];
1967 }
1968
1969 proc gdb_finish { } {
1970 gdb_exit;
1971 }
1972
1973 global debug_format
1974 set debug_format "unknown"
1975
1976 # Run the gdb command "info source" and extract the debugging format
1977 # information from the output and save it in debug_format.
1978
1979 proc get_debug_format { } {
1980 global gdb_prompt
1981 global verbose
1982 global expect_out
1983 global debug_format
1984
1985 set debug_format "unknown"
1986 send_gdb "info source\n"
1987 gdb_expect 10 {
1988 -re "Compiled with (.*) debugging format.\r\n.*$gdb_prompt $" {
1989 set debug_format $expect_out(1,string)
1990 verbose "debug format is $debug_format"
1991 return 1;
1992 }
1993 -re "No current source file.\r\n$gdb_prompt $" {
1994 perror "get_debug_format used when no current source file"
1995 return 0;
1996 }
1997 -re "$gdb_prompt $" {
1998 warning "couldn't check debug format (no valid response)."
1999 return 1;
2000 }
2001 timeout {
2002 warning "couldn't check debug format (timed out)."
2003 return 1;
2004 }
2005 }
2006 }
2007
2008 # Return true if FORMAT matches the debug format the current test was
2009 # compiled with. FORMAT is a shell-style globbing pattern; it can use
2010 # `*', `[...]', and so on.
2011 #
2012 # This function depends on variables set by `get_debug_format', above.
2013
2014 proc test_debug_format {format} {
2015 global debug_format
2016
2017 return [expr [string match $format $debug_format] != 0]
2018 }
2019
2020 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
2021 # COFF, stabs, etc). If that format matches the format that the
2022 # current test was compiled with, then the next test is expected to
2023 # fail for any target. Returns 1 if the next test or set of tests is
2024 # expected to fail, 0 otherwise (or if it is unknown). Must have
2025 # previously called get_debug_format.
2026 proc setup_xfail_format { format } {
2027 set ret [test_debug_format $format];
2028
2029 if {$ret} then {
2030 setup_xfail "*-*-*"
2031 }
2032 return $ret;
2033 }
2034
2035 proc gdb_step_for_stub { } {
2036 global gdb_prompt;
2037
2038 if ![target_info exists gdb,use_breakpoint_for_stub] {
2039 if [target_info exists gdb_stub_step_command] {
2040 set command [target_info gdb_stub_step_command];
2041 } else {
2042 set command "step";
2043 }
2044 send_gdb "${command}\n";
2045 set tries 0;
2046 gdb_expect 60 {
2047 -re "(main.* at |.*in .*start).*$gdb_prompt" {
2048 return;
2049 }
2050 -re ".*$gdb_prompt" {
2051 incr tries;
2052 if { $tries == 5 } {
2053 fail "stepping out of breakpoint function";
2054 return;
2055 }
2056 send_gdb "${command}\n";
2057 exp_continue;
2058 }
2059 default {
2060 fail "stepping out of breakpoint function";
2061 return;
2062 }
2063 }
2064 }
2065 send_gdb "where\n";
2066 gdb_expect {
2067 -re "main\[^\r\n\]*at \(\[^:]+\):\(\[0-9\]+\)" {
2068 set file $expect_out(1,string);
2069 set linenum [expr $expect_out(2,string) + 1];
2070 set breakplace "${file}:${linenum}";
2071 }
2072 default {}
2073 }
2074 send_gdb "break ${breakplace}\n";
2075 gdb_expect 60 {
2076 -re "Breakpoint (\[0-9\]+) at.*$gdb_prompt" {
2077 set breakpoint $expect_out(1,string);
2078 }
2079 -re "Breakpoint (\[0-9\]+): file.*$gdb_prompt" {
2080 set breakpoint $expect_out(1,string);
2081 }
2082 default {}
2083 }
2084 send_gdb "continue\n";
2085 gdb_expect 60 {
2086 -re "Breakpoint ${breakpoint},.*$gdb_prompt" {
2087 gdb_test "delete $breakpoint" ".*" "";
2088 return;
2089 }
2090 default {}
2091 }
2092 }
2093
2094 # gdb_get_line_number TEXT [FILE]
2095 #
2096 # Search the source file FILE, and return the line number of the
2097 # first line containing TEXT. If no match is found, return -1.
2098 #
2099 # TEXT is a string literal, not a regular expression.
2100 #
2101 # The default value of FILE is "$srcdir/$subdir/$srcfile". If FILE is
2102 # specified, and does not start with "/", then it is assumed to be in
2103 # "$srcdir/$subdir". This is awkward, and can be fixed in the future,
2104 # by changing the callers and the interface at the same time.
2105 # In particular: gdb.base/break.exp, gdb.base/condbreak.exp,
2106 # gdb.base/ena-dis-br.exp.
2107 #
2108 # Use this function to keep your test scripts independent of the
2109 # exact line numbering of the source file. Don't write:
2110 #
2111 # send_gdb "break 20"
2112 #
2113 # This means that if anyone ever edits your test's source file,
2114 # your test could break. Instead, put a comment like this on the
2115 # source file line you want to break at:
2116 #
2117 # /* breakpoint spot: frotz.exp: test name */
2118 #
2119 # and then write, in your test script (which we assume is named
2120 # frotz.exp):
2121 #
2122 # send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
2123 #
2124 # (Yes, Tcl knows how to handle the nested quotes and brackets.
2125 # Try this:
2126 # $ tclsh
2127 # % puts "foo [lindex "bar baz" 1]"
2128 # foo baz
2129 # %
2130 # Tcl is quite clever, for a little stringy language.)
2131 #
2132 # ===
2133 #
2134 # The previous implementation of this procedure used the gdb search command.
2135 # This version is different:
2136 #
2137 # . It works with MI, and it also works when gdb is not running.
2138 #
2139 # . It operates on the build machine, not the host machine.
2140 #
2141 # . For now, this implementation fakes a current directory of
2142 # $srcdir/$subdir to be compatible with the old implementation.
2143 # This will go away eventually and some callers will need to
2144 # be changed.
2145 #
2146 # . The TEXT argument is literal text and matches literally,
2147 # not a regular expression as it was before.
2148 #
2149 # . State changes in gdb, such as changing the current file
2150 # and setting $_, no longer happen.
2151 #
2152 # After a bit of time we can forget about the differences from the
2153 # old implementation.
2154 #
2155 # --chastain 2004-08-05
2156
2157 proc gdb_get_line_number { text { file "" } } {
2158 global srcdir
2159 global subdir
2160 global srcfile
2161
2162 if { "$file" == "" } then {
2163 set file "$srcfile"
2164 }
2165 if { ! [regexp "^/" "$file"] } then {
2166 set file "$srcdir/$subdir/$file"
2167 }
2168
2169 if { [ catch { set fd [open "$file"] } message ] } then {
2170 perror "$message"
2171 return -1
2172 }
2173
2174 set found -1
2175 for { set line 1 } { 1 } { incr line } {
2176 if { [ catch { set nchar [gets "$fd" body] } message ] } then {
2177 perror "$message"
2178 return -1
2179 }
2180 if { $nchar < 0 } then {
2181 break
2182 }
2183 if { [string first "$text" "$body"] >= 0 } then {
2184 set found $line
2185 break
2186 }
2187 }
2188
2189 if { [ catch { close "$fd" } message ] } then {
2190 perror "$message"
2191 return -1
2192 }
2193
2194 return $found
2195 }
2196
2197 # gdb_continue_to_end:
2198 # The case where the target uses stubs has to be handled specially. If a
2199 # stub is used, we set a breakpoint at exit because we cannot rely on
2200 # exit() behavior of a remote target.
2201 #
2202 # mssg is the error message that gets printed.
2203
2204 proc gdb_continue_to_end {mssg} {
2205 if [target_info exists use_gdb_stub] {
2206 if {![gdb_breakpoint "exit"]} {
2207 return 0
2208 }
2209 gdb_test "continue" "Continuing..*Breakpoint .*exit.*" \
2210 "continue until exit at $mssg"
2211 } else {
2212 # Continue until we exit. Should not stop again.
2213 # Don't bother to check the output of the program, that may be
2214 # extremely tough for some remote systems.
2215 gdb_test "continue"\
2216 "Continuing.\[\r\n0-9\]+(... EXIT code 0\[\r\n\]+|Program exited normally\\.).*"\
2217 "continue until exit at $mssg"
2218 }
2219 }
2220
2221 proc rerun_to_main {} {
2222 global gdb_prompt
2223
2224 if [target_info exists use_gdb_stub] {
2225 gdb_run_cmd
2226 gdb_expect {
2227 -re ".*Breakpoint .*main .*$gdb_prompt $"\
2228 {pass "rerun to main" ; return 0}
2229 -re "$gdb_prompt $"\
2230 {fail "rerun to main" ; return 0}
2231 timeout {fail "(timeout) rerun to main" ; return 0}
2232 }
2233 } else {
2234 send_gdb "run\n"
2235 gdb_expect {
2236 -re "The program .* has been started already.*y or n. $" {
2237 send_gdb "y\n"
2238 exp_continue
2239 }
2240 -re "Starting program.*$gdb_prompt $"\
2241 {pass "rerun to main" ; return 0}
2242 -re "$gdb_prompt $"\
2243 {fail "rerun to main" ; return 0}
2244 timeout {fail "(timeout) rerun to main" ; return 0}
2245 }
2246 }
2247 }
2248
2249 # Print a message and return true if a test should be skipped
2250 # due to lack of floating point suport.
2251
2252 proc gdb_skip_float_test { msg } {
2253 if [target_info exists gdb,skip_float_tests] {
2254 verbose "Skipping test '$msg': no float tests.";
2255 return 1;
2256 }
2257 return 0;
2258 }
2259
2260 # Print a message and return true if a test should be skipped
2261 # due to lack of stdio support.
2262
2263 proc gdb_skip_stdio_test { msg } {
2264 if [target_info exists gdb,noinferiorio] {
2265 verbose "Skipping test '$msg': no inferior i/o.";
2266 return 1;
2267 }
2268 return 0;
2269 }
2270
2271 proc gdb_skip_bogus_test { msg } {
2272 return 0;
2273 }
2274
2275
2276 # Note: the procedure gdb_gnu_strip_debug will produce an executable called
2277 # ${binfile}.dbglnk, which is just like the executable ($binfile) but without
2278 # the debuginfo. Instead $binfile has a .gnu_debuglink section which contains
2279 # the name of a idebuginfo only file. This file will be stored in the
2280 # gdb.base/.debug subdirectory.
2281
2282 # Functions for separate debug info testing
2283
2284 # starting with an executable:
2285 # foo --> original executable
2286
2287 # at the end of the process we have:
2288 # foo.stripped --> foo w/o debug info
2289 # .debug/foo.debug --> foo's debug info
2290 # foo --> like foo, but with a new .gnu_debuglink section pointing to foo.debug.
2291
2292 # Return the name of the file in which we should stor EXEC's separated
2293 # debug info. EXEC contains the full path.
2294 proc separate_debug_filename { exec } {
2295
2296 # In a .debug subdirectory off the same directory where the testcase
2297 # executable is going to be. Something like:
2298 # <your-path>/gdb/testsuite/gdb.base/.debug/blah.debug.
2299 # This is the default location where gdb expects to findi
2300 # the debug info file.
2301
2302 set exec_dir [file dirname $exec]
2303 set exec_file [file tail $exec]
2304 set debug_dir [file join $exec_dir ".debug"]
2305 set debug_file [file join $debug_dir "${exec_file}.debug"]
2306
2307 return $debug_file
2308 }
2309
2310
2311 proc gdb_gnu_strip_debug { dest } {
2312
2313 set debug_file [separate_debug_filename $dest]
2314 set strip_to_file_program strip
2315 set objcopy_program objcopy
2316
2317 # Make sure the directory that will hold the separated debug
2318 # info actually exists.
2319 set debug_dir [file dirname $debug_file]
2320 if {! [file isdirectory $debug_dir]} {
2321 file mkdir $debug_dir
2322 }
2323
2324 set debug_link [file tail $debug_file]
2325 set stripped_file "${dest}.stripped"
2326
2327 # Get rid of the debug info, and store result in stripped_file
2328 # something like gdb/testsuite/gdb.base/blah.stripped.
2329 set result [catch "exec $strip_to_file_program --strip-debug ${dest} -o ${stripped_file}" output]
2330 verbose "result is $result"
2331 verbose "output is $output"
2332 if {$result == 1} {
2333 return 1
2334 }
2335
2336 # Get rid of everything but the debug info, and store result in debug_file
2337 # This will be in the .debug subdirectory, see above.
2338 set result [catch "exec $strip_to_file_program --only-keep-debug ${dest} -o ${debug_file}" output]
2339 verbose "result is $result"
2340 verbose "output is $output"
2341 if {$result == 1} {
2342 return 1
2343 }
2344
2345 # Link the two previous output files together, adding the .gnu_debuglink
2346 # section to the stripped_file, containing a pointer to the debug_file,
2347 # save the new file in dest.
2348 # This will be the regular executable filename, in the usual location.
2349 set result [catch "exec $objcopy_program --add-gnu-debuglink=${debug_file} ${stripped_file} ${dest}" output]
2350 verbose "result is $result"
2351 verbose "output is $output"
2352 if {$result == 1} {
2353 return 1
2354 }
2355
2356 return 0
2357 }
2358
This page took 0.110922 seconds and 4 git commands to generate.