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