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