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