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