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