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