| 1 | # Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000 |
| 2 | # 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 2 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, write to the Free Software |
| 16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | |
| 18 | # Please email any bugs, comments, and/or additions to this file to: |
| 19 | # bug-gdb@prep.ai.mit.edu |
| 20 | |
| 21 | # This file was written by Fred Fish. (fnf@cygnus.com) |
| 22 | |
| 23 | # Generic gdb subroutines that should work for any target. If these |
| 24 | # need to be modified for any target, it can be done with a variable |
| 25 | # or by passing arguments. |
| 26 | |
| 27 | load_lib libgloss.exp |
| 28 | |
| 29 | global GDB |
| 30 | # OBSOLETE global CHILL_LIB |
| 31 | # OBSOLETE global CHILL_RT0 |
| 32 | |
| 33 | # OBSOLETE if ![info exists CHILL_LIB] { |
| 34 | # OBSOLETE set CHILL_LIB [findfile $base_dir/../../gcc/ch/runtime/libchill.a "$base_dir/../../gcc/ch/runtime/libchill.a" [transform -lchill]] |
| 35 | # OBSOLETE } |
| 36 | # OBSOLETE verbose "using CHILL_LIB = $CHILL_LIB" 2 |
| 37 | # OBSOLETE if ![info exists CHILL_RT0] { |
| 38 | # OBSOLETE set CHILL_RT0 [findfile $base_dir/../../gcc/ch/runtime/chillrt0.o "$base_dir/../../gcc/ch/runtime/chillrt0.o" ""] |
| 39 | # OBSOLETE } |
| 40 | # OBSOLETE verbose "using CHILL_RT0 = $CHILL_RT0" 2 |
| 41 | |
| 42 | if [info exists TOOL_EXECUTABLE] { |
| 43 | set GDB $TOOL_EXECUTABLE; |
| 44 | } |
| 45 | if ![info exists GDB] { |
| 46 | if ![is_remote host] { |
| 47 | set GDB [findfile $base_dir/../../gdb/gdb "$base_dir/../../gdb/gdb" [transform gdb]] |
| 48 | } else { |
| 49 | set GDB [transform gdb]; |
| 50 | } |
| 51 | } |
| 52 | verbose "using GDB = $GDB" 2 |
| 53 | |
| 54 | global GDBFLAGS |
| 55 | if ![info exists GDBFLAGS] { |
| 56 | set GDBFLAGS "-nx" |
| 57 | } |
| 58 | verbose "using GDBFLAGS = $GDBFLAGS" 2 |
| 59 | |
| 60 | # The variable gdb_prompt is a regexp which matches the gdb prompt. |
| 61 | # Set it if it is not already set. |
| 62 | global gdb_prompt |
| 63 | if ![info exists gdb_prompt] then { |
| 64 | set gdb_prompt "\[(\]gdb\[)\]" |
| 65 | } |
| 66 | |
| 67 | # Needed for some tests under Cygwin. |
| 68 | global EXEEXT |
| 69 | global env |
| 70 | |
| 71 | if ![info exists env(EXEEXT)] { |
| 72 | set EXEEXT "" |
| 73 | } else { |
| 74 | set EXEEXT $env(EXEEXT) |
| 75 | } |
| 76 | |
| 77 | ### Only procedures should come after this point. |
| 78 | |
| 79 | # |
| 80 | # gdb_version -- extract and print the version number of GDB |
| 81 | # |
| 82 | proc default_gdb_version {} { |
| 83 | global GDB |
| 84 | global GDBFLAGS |
| 85 | global gdb_prompt |
| 86 | set fileid [open "gdb_cmd" w]; |
| 87 | puts $fileid "q"; |
| 88 | close $fileid; |
| 89 | set cmdfile [remote_download host "gdb_cmd"]; |
| 90 | set output [remote_exec host "$GDB -nw --command $cmdfile"] |
| 91 | remote_file build delete "gdb_cmd"; |
| 92 | remote_file host delete "$cmdfile"; |
| 93 | set tmp [lindex $output 1]; |
| 94 | set version "" |
| 95 | regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version |
| 96 | if ![is_remote host] { |
| 97 | clone_output "[which $GDB] version $version $GDBFLAGS\n" |
| 98 | } else { |
| 99 | clone_output "$GDB on remote host version $version $GDBFLAGS\n" |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | proc gdb_version { } { |
| 104 | return [default_gdb_version]; |
| 105 | } |
| 106 | |
| 107 | # |
| 108 | # gdb_unload -- unload a file if one is loaded |
| 109 | # |
| 110 | |
| 111 | proc gdb_unload {} { |
| 112 | global verbose |
| 113 | global GDB |
| 114 | global gdb_prompt |
| 115 | send_gdb "file\n" |
| 116 | gdb_expect 60 { |
| 117 | -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue } |
| 118 | -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue } |
| 119 | -re "A program is being debugged already..*Kill it.*y or n. $"\ |
| 120 | { send_gdb "y\n" |
| 121 | verbose "\t\tKilling previous program being debugged" |
| 122 | exp_continue |
| 123 | } |
| 124 | -re "Discard symbol table from .*y or n.*$" { |
| 125 | send_gdb "y\n" |
| 126 | exp_continue |
| 127 | } |
| 128 | -re "$gdb_prompt $" {} |
| 129 | timeout { |
| 130 | perror "couldn't unload file in $GDB (timed out)." |
| 131 | return -1 |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | # Many of the tests depend on setting breakpoints at various places and |
| 137 | # running until that breakpoint is reached. At times, we want to start |
| 138 | # with a clean-slate with respect to breakpoints, so this utility proc |
| 139 | # lets us do this without duplicating this code everywhere. |
| 140 | # |
| 141 | |
| 142 | proc delete_breakpoints {} { |
| 143 | global gdb_prompt |
| 144 | |
| 145 | # we need a larger timeout value here or this thing just confuses |
| 146 | # itself. May need a better implementation if possible. - guo |
| 147 | # |
| 148 | send_gdb "delete breakpoints\n" |
| 149 | gdb_expect 100 { |
| 150 | -re "Delete all breakpoints.*y or n.*$" { |
| 151 | send_gdb "y\n"; |
| 152 | exp_continue |
| 153 | } |
| 154 | -re "$gdb_prompt $" { # This happens if there were no breakpoints |
| 155 | } |
| 156 | timeout { perror "Delete all breakpoints in delete_breakpoints (timeout)" ; return } |
| 157 | } |
| 158 | send_gdb "info breakpoints\n" |
| 159 | gdb_expect 100 { |
| 160 | -re "No breakpoints or watchpoints..*$gdb_prompt $" {} |
| 161 | -re "$gdb_prompt $" { perror "breakpoints not deleted" ; return } |
| 162 | -re "Delete all breakpoints.*or n.*$" { |
| 163 | send_gdb "y\n"; |
| 164 | exp_continue |
| 165 | } |
| 166 | timeout { perror "info breakpoints (timeout)" ; return } |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | |
| 171 | # |
| 172 | # Generic run command. |
| 173 | # |
| 174 | # The second pattern below matches up to the first newline *only*. |
| 175 | # Using ``.*$'' could swallow up output that we attempt to match |
| 176 | # elsewhere. |
| 177 | # |
| 178 | proc gdb_run_cmd {args} { |
| 179 | global gdb_prompt |
| 180 | |
| 181 | if [target_info exists gdb_init_command] { |
| 182 | send_gdb "[target_info gdb_init_command]\n"; |
| 183 | gdb_expect 30 { |
| 184 | -re "$gdb_prompt $" { } |
| 185 | default { |
| 186 | perror "gdb_init_command for target failed"; |
| 187 | return; |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | if [target_info exists use_gdb_stub] { |
| 193 | if [target_info exists gdb,do_reload_on_run] { |
| 194 | # Specifying no file, defaults to the executable |
| 195 | # currently being debugged. |
| 196 | if { [gdb_load ""] < 0 } { |
| 197 | return; |
| 198 | } |
| 199 | send_gdb "continue\n"; |
| 200 | gdb_expect 60 { |
| 201 | -re "Continu\[^\r\n\]*\[\r\n\]" {} |
| 202 | default {} |
| 203 | } |
| 204 | return; |
| 205 | } |
| 206 | |
| 207 | if [target_info exists gdb,start_symbol] { |
| 208 | set start [target_info gdb,start_symbol]; |
| 209 | } else { |
| 210 | set start "start"; |
| 211 | } |
| 212 | send_gdb "jump *$start\n" |
| 213 | set start_attempt 1; |
| 214 | while { $start_attempt } { |
| 215 | # Cap (re)start attempts at three to ensure that this loop |
| 216 | # always eventually fails. Don't worry about trying to be |
| 217 | # clever and not send a command when it has failed. |
| 218 | if [expr $start_attempt > 3] { |
| 219 | perror "Jump to start() failed (retry count exceeded)"; |
| 220 | return; |
| 221 | } |
| 222 | set start_attempt [expr $start_attempt + 1]; |
| 223 | gdb_expect 30 { |
| 224 | -re "Continuing at \[^\r\n\]*\[\r\n\]" { |
| 225 | set start_attempt 0; |
| 226 | } |
| 227 | -re "No symbol \"_start\" in current.*$gdb_prompt $" { |
| 228 | perror "Can't find start symbol to run in gdb_run"; |
| 229 | return; |
| 230 | } |
| 231 | -re "No symbol \"start\" in current.*$gdb_prompt $" { |
| 232 | send_gdb "jump *_start\n"; |
| 233 | } |
| 234 | -re "No symbol.*context.*$gdb_prompt $" { |
| 235 | set start_attempt 0; |
| 236 | } |
| 237 | -re "Line.* Jump anyway.*y or n. $" { |
| 238 | send_gdb "y\n" |
| 239 | } |
| 240 | -re "The program is not being run.*$gdb_prompt $" { |
| 241 | if { [gdb_load ""] < 0 } { |
| 242 | return; |
| 243 | } |
| 244 | send_gdb "jump *$start\n"; |
| 245 | } |
| 246 | timeout { |
| 247 | perror "Jump to start() failed (timeout)"; |
| 248 | return |
| 249 | } |
| 250 | } |
| 251 | } |
| 252 | if [target_info exists gdb_stub] { |
| 253 | gdb_expect 60 { |
| 254 | -re "$gdb_prompt $" { |
| 255 | send_gdb "continue\n" |
| 256 | } |
| 257 | } |
| 258 | } |
| 259 | return |
| 260 | } |
| 261 | send_gdb "run $args\n" |
| 262 | # This doesn't work quite right yet. |
| 263 | gdb_expect 60 { |
| 264 | -re "The program .* has been started already.*y or n. $" { |
| 265 | send_gdb "y\n" |
| 266 | exp_continue |
| 267 | } |
| 268 | -re "Starting program: \[^\r\n\]*" {} |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | proc gdb_breakpoint { function } { |
| 273 | global gdb_prompt |
| 274 | global decimal |
| 275 | |
| 276 | send_gdb "break $function\n" |
| 277 | # The first two regexps are what we get with -g, the third is without -g. |
| 278 | gdb_expect 30 { |
| 279 | -re "Breakpoint \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {} |
| 280 | -re "Breakpoint \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {} |
| 281 | -re "Breakpoint \[0-9\]* at .*$gdb_prompt $" {} |
| 282 | -re "$gdb_prompt $" { fail "setting breakpoint at $function" ; return 0 } |
| 283 | timeout { fail "setting breakpoint at $function (timeout)" ; return 0 } |
| 284 | } |
| 285 | return 1; |
| 286 | } |
| 287 | |
| 288 | # Set breakpoint at function and run gdb until it breaks there. |
| 289 | # Since this is the only breakpoint that will be set, if it stops |
| 290 | # at a breakpoint, we will assume it is the one we want. We can't |
| 291 | # just compare to "function" because it might be a fully qualified, |
| 292 | # single quoted C++ function specifier. |
| 293 | |
| 294 | proc runto { function } { |
| 295 | global gdb_prompt |
| 296 | global decimal |
| 297 | |
| 298 | delete_breakpoints |
| 299 | |
| 300 | if ![gdb_breakpoint $function] { |
| 301 | return 0; |
| 302 | } |
| 303 | |
| 304 | gdb_run_cmd |
| 305 | |
| 306 | # the "at foo.c:36" output we get with -g. |
| 307 | # the "in func" output we get without -g. |
| 308 | gdb_expect 30 { |
| 309 | -re "Break.* at .*:$decimal.*$gdb_prompt $" { |
| 310 | return 1 |
| 311 | } |
| 312 | -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" { |
| 313 | return 1 |
| 314 | } |
| 315 | -re "$gdb_prompt $" { |
| 316 | fail "running to $function in runto" |
| 317 | return 0 |
| 318 | } |
| 319 | timeout { |
| 320 | fail "running to $function in runto (timeout)" |
| 321 | return 0 |
| 322 | } |
| 323 | } |
| 324 | return 1 |
| 325 | } |
| 326 | |
| 327 | # |
| 328 | # runto_main -- ask gdb to run until we hit a breakpoint at main. |
| 329 | # The case where the target uses stubs has to be handled |
| 330 | # specially--if it uses stubs, assuming we hit |
| 331 | # breakpoint() and just step out of the function. |
| 332 | # |
| 333 | proc runto_main { } { |
| 334 | global gdb_prompt |
| 335 | global decimal |
| 336 | |
| 337 | if ![target_info exists gdb_stub] { |
| 338 | return [runto main] |
| 339 | } |
| 340 | |
| 341 | delete_breakpoints |
| 342 | |
| 343 | gdb_step_for_stub; |
| 344 | |
| 345 | return 1 |
| 346 | } |
| 347 | |
| 348 | |
| 349 | ### Continue, and expect to hit a breakpoint. |
| 350 | ### Report a pass or fail, depending on whether it seems to have |
| 351 | ### worked. Use NAME as part of the test name; each call to |
| 352 | ### continue_to_breakpoint should use a NAME which is unique within |
| 353 | ### that test file. |
| 354 | proc gdb_continue_to_breakpoint {name} { |
| 355 | global gdb_prompt |
| 356 | set full_name "continue to breakpoint: $name" |
| 357 | |
| 358 | send_gdb "continue\n" |
| 359 | gdb_expect { |
| 360 | -re "Breakpoint .* at .*\r\n$gdb_prompt $" { |
| 361 | pass $full_name |
| 362 | } |
| 363 | -re ".*$gdb_prompt $" { |
| 364 | fail $full_name |
| 365 | } |
| 366 | timeout { |
| 367 | fail "$full_name (timeout)" |
| 368 | } |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | |
| 373 | |
| 374 | # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE |
| 375 | # Send a command to gdb; test the result. |
| 376 | # |
| 377 | # COMMAND is the command to execute, send to GDB with send_gdb. If |
| 378 | # this is the null string no command is sent. |
| 379 | # PATTERN is the pattern to match for a PASS, and must NOT include |
| 380 | # the \r\n sequence immediately before the gdb prompt. |
| 381 | # MESSAGE is an optional message to be printed. If this is |
| 382 | # omitted, then the pass/fail messages use the command string as the |
| 383 | # message. (If this is the empty string, then sometimes we don't |
| 384 | # call pass or fail at all; I don't understand this at all.) |
| 385 | # QUESTION is a question GDB may ask in response to COMMAND, like |
| 386 | # "are you sure?" |
| 387 | # RESPONSE is the response to send if QUESTION appears. |
| 388 | # |
| 389 | # Returns: |
| 390 | # 1 if the test failed, |
| 391 | # 0 if the test passes, |
| 392 | # -1 if there was an internal error. |
| 393 | # |
| 394 | proc gdb_test { args } { |
| 395 | global verbose |
| 396 | global gdb_prompt |
| 397 | global GDB |
| 398 | upvar timeout timeout |
| 399 | |
| 400 | if [llength $args]>2 then { |
| 401 | set message [lindex $args 2] |
| 402 | } else { |
| 403 | set message [lindex $args 0] |
| 404 | } |
| 405 | set command [lindex $args 0] |
| 406 | set pattern [lindex $args 1] |
| 407 | |
| 408 | if [llength $args]==5 { |
| 409 | set question_string [lindex $args 3]; |
| 410 | set response_string [lindex $args 4]; |
| 411 | } else { |
| 412 | set question_string "^FOOBAR$" |
| 413 | } |
| 414 | |
| 415 | if $verbose>2 then { |
| 416 | send_user "Sending \"$command\" to gdb\n" |
| 417 | send_user "Looking to match \"$pattern\"\n" |
| 418 | send_user "Message is \"$message\"\n" |
| 419 | } |
| 420 | |
| 421 | set result -1 |
| 422 | set string "${command}\n"; |
| 423 | if { $command != "" } { |
| 424 | while { "$string" != "" } { |
| 425 | set foo [string first "\n" "$string"]; |
| 426 | set len [string length "$string"]; |
| 427 | if { $foo < [expr $len - 1] } { |
| 428 | set str [string range "$string" 0 $foo]; |
| 429 | if { [send_gdb "$str"] != "" } { |
| 430 | global suppress_flag; |
| 431 | |
| 432 | if { ! $suppress_flag } { |
| 433 | perror "Couldn't send $command to GDB."; |
| 434 | } |
| 435 | fail "$message"; |
| 436 | return $result; |
| 437 | } |
| 438 | # since we're checking if each line of the multi-line |
| 439 | # command are 'accepted' by GDB here, |
| 440 | # we need to set -notransfer expect option so that |
| 441 | # command output is not lost for pattern matching |
| 442 | # - guo |
| 443 | gdb_expect 2 { |
| 444 | -notransfer -re "\[\r\n\]" { verbose "partial: match" 3 } |
| 445 | timeout { verbose "partial: timeout" 3 } |
| 446 | } |
| 447 | set string [string range "$string" [expr $foo + 1] end]; |
| 448 | } else { |
| 449 | break; |
| 450 | } |
| 451 | } |
| 452 | if { "$string" != "" } { |
| 453 | if { [send_gdb "$string"] != "" } { |
| 454 | global suppress_flag; |
| 455 | |
| 456 | if { ! $suppress_flag } { |
| 457 | perror "Couldn't send $command to GDB."; |
| 458 | } |
| 459 | fail "$message"; |
| 460 | return $result; |
| 461 | } |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | if [target_info exists gdb,timeout] { |
| 466 | set tmt [target_info gdb,timeout]; |
| 467 | } else { |
| 468 | if [info exists timeout] { |
| 469 | set tmt $timeout; |
| 470 | } else { |
| 471 | global timeout; |
| 472 | if [info exists timeout] { |
| 473 | set tmt $timeout; |
| 474 | } else { |
| 475 | set tmt 60; |
| 476 | } |
| 477 | } |
| 478 | } |
| 479 | gdb_expect $tmt { |
| 480 | -re "\\*\\*\\* DOSEXIT code.*" { |
| 481 | if { $message != "" } { |
| 482 | fail "$message"; |
| 483 | } |
| 484 | gdb_suppress_entire_file "GDB died"; |
| 485 | return -1; |
| 486 | } |
| 487 | -re "Ending remote debugging.*$gdb_prompt $" { |
| 488 | if ![isnative] then { |
| 489 | warning "Can`t communicate to remote target." |
| 490 | } |
| 491 | gdb_exit |
| 492 | gdb_start |
| 493 | set result -1 |
| 494 | } |
| 495 | -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" { |
| 496 | if ![string match "" $message] then { |
| 497 | pass "$message" |
| 498 | } |
| 499 | set result 0 |
| 500 | } |
| 501 | -re "(${question_string})$" { |
| 502 | send_gdb "$response_string\n"; |
| 503 | exp_continue; |
| 504 | } |
| 505 | -re "Undefined\[a-z\]* command:.*$gdb_prompt $" { |
| 506 | perror "Undefined command \"$command\"." |
| 507 | fail "$message" |
| 508 | set result 1 |
| 509 | } |
| 510 | -re "Ambiguous command.*$gdb_prompt $" { |
| 511 | perror "\"$command\" is not a unique command name." |
| 512 | fail "$message" |
| 513 | set result 1 |
| 514 | } |
| 515 | -re "Program exited with code \[0-9\]+.*$gdb_prompt $" { |
| 516 | if ![string match "" $message] then { |
| 517 | set errmsg "$message: the program exited" |
| 518 | } else { |
| 519 | set errmsg "$command: the program exited" |
| 520 | } |
| 521 | fail "$errmsg" |
| 522 | return -1 |
| 523 | } |
| 524 | -re "EXIT code \[0-9\r\n\]+Program exited normally.*$gdb_prompt $" { |
| 525 | if ![string match "" $message] then { |
| 526 | set errmsg "$message: the program exited" |
| 527 | } else { |
| 528 | set errmsg "$command: the program exited" |
| 529 | } |
| 530 | fail "$errmsg" |
| 531 | return -1 |
| 532 | } |
| 533 | -re "The program is not being run.*$gdb_prompt $" { |
| 534 | if ![string match "" $message] then { |
| 535 | set errmsg "$message: the program is no longer running" |
| 536 | } else { |
| 537 | set errmsg "$command: the program is no longer running" |
| 538 | } |
| 539 | fail "$errmsg" |
| 540 | return -1 |
| 541 | } |
| 542 | -re ".*$gdb_prompt $" { |
| 543 | if ![string match "" $message] then { |
| 544 | fail "$message" |
| 545 | } |
| 546 | set result 1 |
| 547 | } |
| 548 | "<return>" { |
| 549 | send_gdb "\n" |
| 550 | perror "Window too small." |
| 551 | fail "$message" |
| 552 | } |
| 553 | -re "\\(y or n\\) " { |
| 554 | send_gdb "n\n" |
| 555 | perror "Got interactive prompt." |
| 556 | fail "$message" |
| 557 | } |
| 558 | eof { |
| 559 | perror "Process no longer exists" |
| 560 | if { $message != "" } { |
| 561 | fail "$message" |
| 562 | } |
| 563 | return -1 |
| 564 | } |
| 565 | full_buffer { |
| 566 | perror "internal buffer is full." |
| 567 | fail "$message" |
| 568 | } |
| 569 | timeout { |
| 570 | if ![string match "" $message] then { |
| 571 | fail "$message (timeout)" |
| 572 | } |
| 573 | set result 1 |
| 574 | } |
| 575 | } |
| 576 | return $result |
| 577 | } |
| 578 | \f |
| 579 | # Test that a command gives an error. For pass or fail, return |
| 580 | # a 1 to indicate that more tests can proceed. However a timeout |
| 581 | # is a serious error, generates a special fail message, and causes |
| 582 | # a 0 to be returned to indicate that more tests are likely to fail |
| 583 | # as well. |
| 584 | |
| 585 | proc test_print_reject { args } { |
| 586 | global gdb_prompt |
| 587 | global verbose |
| 588 | |
| 589 | if [llength $args]==2 then { |
| 590 | set expectthis [lindex $args 1] |
| 591 | } else { |
| 592 | set expectthis "should never match this bogus string" |
| 593 | } |
| 594 | set sendthis [lindex $args 0] |
| 595 | if $verbose>2 then { |
| 596 | send_user "Sending \"$sendthis\" to gdb\n" |
| 597 | send_user "Looking to match \"$expectthis\"\n" |
| 598 | } |
| 599 | send_gdb "$sendthis\n" |
| 600 | #FIXME: Should add timeout as parameter. |
| 601 | gdb_expect { |
| 602 | -re "A .* in expression.*\\.*$gdb_prompt $" { |
| 603 | pass "reject $sendthis" |
| 604 | return 1 |
| 605 | } |
| 606 | -re "Invalid syntax in expression.*$gdb_prompt $" { |
| 607 | pass "reject $sendthis" |
| 608 | return 1 |
| 609 | } |
| 610 | -re "Junk after end of expression.*$gdb_prompt $" { |
| 611 | pass "reject $sendthis" |
| 612 | return 1 |
| 613 | } |
| 614 | -re "Invalid number.*$gdb_prompt $" { |
| 615 | pass "reject $sendthis" |
| 616 | return 1 |
| 617 | } |
| 618 | -re "Invalid character constant.*$gdb_prompt $" { |
| 619 | pass "reject $sendthis" |
| 620 | return 1 |
| 621 | } |
| 622 | -re "No symbol table is loaded.*$gdb_prompt $" { |
| 623 | pass "reject $sendthis" |
| 624 | return 1 |
| 625 | } |
| 626 | -re "No symbol .* in current context.*$gdb_prompt $" { |
| 627 | pass "reject $sendthis" |
| 628 | return 1 |
| 629 | } |
| 630 | -re "Unmatched single quote.*$gdb_prompt $" { |
| 631 | pass "reject $sendthis" |
| 632 | return 1 |
| 633 | } |
| 634 | -re "A character constant must contain at least one character.*$gdb_prompt $" { |
| 635 | pass "reject $sendthis" |
| 636 | return 1 |
| 637 | } |
| 638 | -re "$expectthis.*$gdb_prompt $" { |
| 639 | pass "reject $sendthis" |
| 640 | return 1 |
| 641 | } |
| 642 | -re ".*$gdb_prompt $" { |
| 643 | fail "reject $sendthis" |
| 644 | return 1 |
| 645 | } |
| 646 | default { |
| 647 | fail "reject $sendthis (eof or timeout)" |
| 648 | return 0 |
| 649 | } |
| 650 | } |
| 651 | } |
| 652 | \f |
| 653 | # Given an input string, adds backslashes as needed to create a |
| 654 | # regexp that will match the string. |
| 655 | |
| 656 | proc string_to_regexp {str} { |
| 657 | set result $str |
| 658 | regsub -all {[]*+.|()^$\[]} $str {\\&} result |
| 659 | return $result |
| 660 | } |
| 661 | |
| 662 | # Same as gdb_test, but the second parameter is not a regexp, |
| 663 | # but a string that must match exactly. |
| 664 | |
| 665 | proc gdb_test_exact { args } { |
| 666 | upvar timeout timeout |
| 667 | |
| 668 | set command [lindex $args 0] |
| 669 | |
| 670 | # This applies a special meaning to a null string pattern. Without |
| 671 | # this, "$pattern\r\n$gdb_prompt $" will match anything, including error |
| 672 | # messages from commands that should have no output except a new |
| 673 | # prompt. With this, only results of a null string will match a null |
| 674 | # string pattern. |
| 675 | |
| 676 | set pattern [lindex $args 1] |
| 677 | if [string match $pattern ""] { |
| 678 | set pattern [string_to_regexp [lindex $args 0]] |
| 679 | } else { |
| 680 | set pattern [string_to_regexp [lindex $args 1]] |
| 681 | } |
| 682 | |
| 683 | # It is most natural to write the pattern argument with only |
| 684 | # embedded \n's, especially if you are trying to avoid Tcl quoting |
| 685 | # problems. But gdb_expect really wants to see \r\n in patterns. So |
| 686 | # transform the pattern here. First transform \r\n back to \n, in |
| 687 | # case some users of gdb_test_exact already do the right thing. |
| 688 | regsub -all "\r\n" $pattern "\n" pattern |
| 689 | regsub -all "\n" $pattern "\r\n" pattern |
| 690 | if [llength $args]==3 then { |
| 691 | set message [lindex $args 2] |
| 692 | } else { |
| 693 | set message $command |
| 694 | } |
| 695 | |
| 696 | return [gdb_test $command $pattern $message] |
| 697 | } |
| 698 | \f |
| 699 | proc gdb_reinitialize_dir { subdir } { |
| 700 | global gdb_prompt |
| 701 | |
| 702 | if [is_remote host] { |
| 703 | return ""; |
| 704 | } |
| 705 | send_gdb "dir\n" |
| 706 | gdb_expect 60 { |
| 707 | -re "Reinitialize source path to empty.*y or n. " { |
| 708 | send_gdb "y\n" |
| 709 | gdb_expect 60 { |
| 710 | -re "Source directories searched.*$gdb_prompt $" { |
| 711 | send_gdb "dir $subdir\n" |
| 712 | gdb_expect 60 { |
| 713 | -re "Source directories searched.*$gdb_prompt $" { |
| 714 | verbose "Dir set to $subdir" |
| 715 | } |
| 716 | -re "$gdb_prompt $" { |
| 717 | perror "Dir \"$subdir\" failed." |
| 718 | } |
| 719 | } |
| 720 | } |
| 721 | -re "$gdb_prompt $" { |
| 722 | perror "Dir \"$subdir\" failed." |
| 723 | } |
| 724 | } |
| 725 | } |
| 726 | -re "$gdb_prompt $" { |
| 727 | perror "Dir \"$subdir\" failed." |
| 728 | } |
| 729 | } |
| 730 | } |
| 731 | |
| 732 | # |
| 733 | # gdb_exit -- exit the GDB, killing the target program if necessary |
| 734 | # |
| 735 | proc default_gdb_exit {} { |
| 736 | global GDB |
| 737 | global GDBFLAGS |
| 738 | global verbose |
| 739 | global gdb_spawn_id; |
| 740 | |
| 741 | gdb_stop_suppressing_tests; |
| 742 | |
| 743 | if ![info exists gdb_spawn_id] { |
| 744 | return; |
| 745 | } |
| 746 | |
| 747 | verbose "Quitting $GDB $GDBFLAGS" |
| 748 | |
| 749 | if { [is_remote host] && [board_info host exists fileid] } { |
| 750 | send_gdb "quit\n"; |
| 751 | gdb_expect 10 { |
| 752 | -re "y or n" { |
| 753 | send_gdb "y\n"; |
| 754 | exp_continue; |
| 755 | } |
| 756 | -re "DOSEXIT code" { } |
| 757 | default { } |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | if ![is_remote host] { |
| 762 | remote_close host; |
| 763 | } |
| 764 | unset gdb_spawn_id |
| 765 | } |
| 766 | |
| 767 | # |
| 768 | # load a file into the debugger. |
| 769 | # return a -1 if anything goes wrong. |
| 770 | # |
| 771 | proc gdb_file_cmd { arg } { |
| 772 | global verbose |
| 773 | global loadpath |
| 774 | global loadfile |
| 775 | global GDB |
| 776 | global gdb_prompt |
| 777 | upvar timeout timeout |
| 778 | |
| 779 | if [is_remote host] { |
| 780 | set arg [remote_download host $arg]; |
| 781 | if { $arg == "" } { |
| 782 | error "download failed" |
| 783 | return -1; |
| 784 | } |
| 785 | } |
| 786 | |
| 787 | send_gdb "file $arg\n" |
| 788 | gdb_expect 120 { |
| 789 | -re "Reading symbols from.*done.*$gdb_prompt $" { |
| 790 | verbose "\t\tLoaded $arg into the $GDB" |
| 791 | return 0 |
| 792 | } |
| 793 | -re "has no symbol-table.*$gdb_prompt $" { |
| 794 | perror "$arg wasn't compiled with \"-g\"" |
| 795 | return -1 |
| 796 | } |
| 797 | -re "A program is being debugged already.*Kill it.*y or n. $" { |
| 798 | send_gdb "y\n" |
| 799 | verbose "\t\tKilling previous program being debugged" |
| 800 | exp_continue |
| 801 | } |
| 802 | -re "Load new symbol table from \".*\".*y or n. $" { |
| 803 | send_gdb "y\n" |
| 804 | gdb_expect 120 { |
| 805 | -re "Reading symbols from.*done.*$gdb_prompt $" { |
| 806 | verbose "\t\tLoaded $arg with new symbol table into $GDB" |
| 807 | return 0 |
| 808 | } |
| 809 | timeout { |
| 810 | perror "(timeout) Couldn't load $arg, other program already loaded." |
| 811 | return -1 |
| 812 | } |
| 813 | } |
| 814 | } |
| 815 | -re "No such file or directory.*$gdb_prompt $" { |
| 816 | perror "($arg) No such file or directory\n" |
| 817 | return -1 |
| 818 | } |
| 819 | -re "$gdb_prompt $" { |
| 820 | perror "couldn't load $arg into $GDB." |
| 821 | return -1 |
| 822 | } |
| 823 | timeout { |
| 824 | perror "couldn't load $arg into $GDB (timed out)." |
| 825 | return -1 |
| 826 | } |
| 827 | eof { |
| 828 | # This is an attempt to detect a core dump, but seems not to |
| 829 | # work. Perhaps we need to match .* followed by eof, in which |
| 830 | # gdb_expect does not seem to have a way to do that. |
| 831 | perror "couldn't load $arg into $GDB (end of file)." |
| 832 | return -1 |
| 833 | } |
| 834 | } |
| 835 | } |
| 836 | |
| 837 | # |
| 838 | # start gdb -- start gdb running, default procedure |
| 839 | # |
| 840 | # When running over NFS, particularly if running many simultaneous |
| 841 | # tests on different hosts all using the same server, things can |
| 842 | # get really slow. Give gdb at least 3 minutes to start up. |
| 843 | # |
| 844 | proc default_gdb_start { } { |
| 845 | global verbose |
| 846 | global GDB |
| 847 | global GDBFLAGS |
| 848 | global gdb_prompt |
| 849 | global timeout |
| 850 | global gdb_spawn_id; |
| 851 | |
| 852 | gdb_stop_suppressing_tests; |
| 853 | |
| 854 | verbose "Spawning $GDB -nw $GDBFLAGS" |
| 855 | |
| 856 | if [info exists gdb_spawn_id] { |
| 857 | return 0; |
| 858 | } |
| 859 | |
| 860 | if ![is_remote host] { |
| 861 | if { [which $GDB] == 0 } then { |
| 862 | perror "$GDB does not exist." |
| 863 | exit 1 |
| 864 | } |
| 865 | } |
| 866 | set res [remote_spawn host "$GDB -nw $GDBFLAGS [host_info gdb_opts]"]; |
| 867 | if { $res < 0 || $res == "" } { |
| 868 | perror "Spawning $GDB failed." |
| 869 | return 1; |
| 870 | } |
| 871 | gdb_expect 360 { |
| 872 | -re "\[\r\n\]$gdb_prompt $" { |
| 873 | verbose "GDB initialized." |
| 874 | } |
| 875 | -re "$gdb_prompt $" { |
| 876 | perror "GDB never initialized." |
| 877 | return -1 |
| 878 | } |
| 879 | timeout { |
| 880 | perror "(timeout) GDB never initialized after 10 seconds." |
| 881 | remote_close host; |
| 882 | return -1 |
| 883 | } |
| 884 | } |
| 885 | set gdb_spawn_id -1; |
| 886 | # force the height to "unlimited", so no pagers get used |
| 887 | |
| 888 | send_gdb "set height 0\n" |
| 889 | gdb_expect 10 { |
| 890 | -re "$gdb_prompt $" { |
| 891 | verbose "Setting height to 0." 2 |
| 892 | } |
| 893 | timeout { |
| 894 | warning "Couldn't set the height to 0" |
| 895 | } |
| 896 | } |
| 897 | # force the width to "unlimited", so no wraparound occurs |
| 898 | send_gdb "set width 0\n" |
| 899 | gdb_expect 10 { |
| 900 | -re "$gdb_prompt $" { |
| 901 | verbose "Setting width to 0." 2 |
| 902 | } |
| 903 | timeout { |
| 904 | warning "Couldn't set the width to 0." |
| 905 | } |
| 906 | } |
| 907 | return 0; |
| 908 | } |
| 909 | |
| 910 | # Return a 1 for configurations for which we don't even want to try to |
| 911 | # test C++. |
| 912 | |
| 913 | proc skip_cplus_tests {} { |
| 914 | if { [istarget "d10v-*-*"] } { |
| 915 | return 1 |
| 916 | } |
| 917 | if { [istarget "h8300-*-*"] } { |
| 918 | return 1 |
| 919 | } |
| 920 | return 0 |
| 921 | } |
| 922 | |
| 923 | # OBSOLETE # * For crosses, the CHILL runtime doesn't build because it |
| 924 | # OBSOLETE # can't find setjmp.h, stdio.h, etc. |
| 925 | # OBSOLETE # * For AIX (as of 16 Mar 95), (a) there is no language code for |
| 926 | # OBSOLETE # CHILL in output_epilog in gcc/config/rs6000/rs6000.c, (b) collect2 |
| 927 | # OBSOLETE # does not get along with AIX's too-clever linker. |
| 928 | # OBSOLETE # * On Irix5, there is a bug whereby set of bool, etc., don't get |
| 929 | # OBSOLETE # TYPE_LOW_BOUND for the bool right because force_to_range_type doesn't |
| 930 | # OBSOLETE # work with stub types. |
| 931 | # OBSOLETE # Lots of things seem to fail on the PA, and since it's not a supported |
| 932 | # OBSOLETE # chill target at the moment, don't run the chill tests. |
| 933 | |
| 934 | # OBSOLETE proc skip_chill_tests {} { |
| 935 | # OBSOLETE if ![info exists do_chill_tests] { |
| 936 | # OBSOLETE return 1; |
| 937 | # OBSOLETE } |
| 938 | # OBSOLETE eval set skip_chill [expr ![isnative] || [istarget "*-*-aix*"] || [istarget "*-*-irix5*"] || [istarget "*-*-irix6*"] || [istarget "alpha-*-osf*"] || [istarget "hppa*-*-*"]] |
| 939 | # OBSOLETE verbose "Skip chill tests is $skip_chill" |
| 940 | # OBSOLETE return $skip_chill |
| 941 | # OBSOLETE } |
| 942 | |
| 943 | # Skip all the tests in the file if you are not on an hppa running |
| 944 | # hpux target. |
| 945 | |
| 946 | proc skip_hp_tests {} { |
| 947 | eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ] |
| 948 | verbose "Skip hp tests is $skip_hp" |
| 949 | return $skip_hp |
| 950 | } |
| 951 | |
| 952 | proc get_compiler_info {binfile args} { |
| 953 | # Create and source the file that provides information about the compiler |
| 954 | # used to compile the test case. |
| 955 | # Compiler_type can be null or c++. If null we assume c. |
| 956 | global srcdir |
| 957 | global subdir |
| 958 | # These two come from compiler.c. |
| 959 | global signed_keyword_not_used |
| 960 | global gcc_compiled |
| 961 | |
| 962 | if {![istarget "hppa*-*-hpux*"] && ![istarget "mips*-*-irix*"]} { |
| 963 | if { [llength $args] > 0 } { |
| 964 | if {$args == "c++"} { |
| 965 | if { [gdb_compile "${srcdir}/lib/compiler.cc" "${binfile}.ci" preprocess {}] != "" } { |
| 966 | perror "Couldn't make ${binfile}.ci file" |
| 967 | return 1; |
| 968 | } |
| 969 | } |
| 970 | } else { |
| 971 | if { [gdb_compile "${srcdir}/lib/compiler.c" "${binfile}.ci" preprocess {}] != "" } { |
| 972 | perror "Couldn't make ${binfile}.ci file" |
| 973 | return 1; |
| 974 | } |
| 975 | } |
| 976 | } else { |
| 977 | if { [llength $args] > 0 } { |
| 978 | if {$args == "c++"} { |
| 979 | if { [eval gdb_preprocess \ |
| 980 | [list "${srcdir}/lib/compiler.cc" "${binfile}.ci"] \ |
| 981 | $args] != "" } { |
| 982 | perror "Couldn't make ${binfile}.ci file" |
| 983 | return 1; |
| 984 | } |
| 985 | } |
| 986 | } elseif { $args != "f77" } { |
| 987 | if { [eval gdb_preprocess \ |
| 988 | [list "${srcdir}/lib/compiler.c" "${binfile}.ci"] \ |
| 989 | $args] != "" } { |
| 990 | perror "Couldn't make ${binfile}.ci file" |
| 991 | return 1; |
| 992 | } |
| 993 | } |
| 994 | } |
| 995 | |
| 996 | uplevel \#0 { set gcc_compiled 0 } |
| 997 | |
| 998 | if { [llength $args] == 0 || $args != "f77" } { |
| 999 | source ${binfile}.ci |
| 1000 | } |
| 1001 | |
| 1002 | # Most compilers will evaluate comparisons and other boolean |
| 1003 | # operations to 0 or 1. |
| 1004 | uplevel \#0 { set true 1 } |
| 1005 | uplevel \#0 { set false 0 } |
| 1006 | |
| 1007 | uplevel \#0 { set hp_cc_compiler 0 } |
| 1008 | uplevel \#0 { set hp_aCC_compiler 0 } |
| 1009 | uplevel \#0 { set hp_f77_compiler 0 } |
| 1010 | uplevel \#0 { set hp_f90_compiler 0 } |
| 1011 | if { !$gcc_compiled && [istarget "hppa*-*-hpux*"] } { |
| 1012 | # Check for the HP compilers |
| 1013 | set compiler [lindex [split [get_compiler $args] " "] 0] |
| 1014 | catch "exec what $compiler" output |
| 1015 | if [regexp ".*HP aC\\+\\+.*" $output] { |
| 1016 | uplevel \#0 { set hp_aCC_compiler 1 } |
| 1017 | # Use of aCC results in boolean results being displayed as |
| 1018 | # "true" or "false" |
| 1019 | uplevel \#0 { set true true } |
| 1020 | uplevel \#0 { set false false } |
| 1021 | } elseif [regexp ".*HP C Compiler.*" $output] { |
| 1022 | uplevel \#0 { set hp_cc_compiler 1 } |
| 1023 | } elseif [regexp ".*HP-UX f77.*" $output] { |
| 1024 | uplevel \#0 { set hp_f77_compiler 1 } |
| 1025 | } elseif [regexp ".*HP-UX f90.*" $output] { |
| 1026 | uplevel \#0 { set hp_f90_compiler 1 } |
| 1027 | } |
| 1028 | } |
| 1029 | |
| 1030 | return 0; |
| 1031 | } |
| 1032 | |
| 1033 | proc get_compiler {args} { |
| 1034 | global CC CC_FOR_TARGET CXX CXX_FOR_TARGET F77_FOR_TARGET |
| 1035 | |
| 1036 | if { [llength $args] == 0 |
| 1037 | || ([llength $args] == 1 && [lindex $args 0] == "") } { |
| 1038 | set which_compiler "c" |
| 1039 | } else { |
| 1040 | if { $args =="c++" } { |
| 1041 | set which_compiler "c++" |
| 1042 | } elseif { $args =="f77" } { |
| 1043 | set which_compiler "f77" |
| 1044 | } else { |
| 1045 | perror "Unknown compiler type supplied to gdb_preprocess" |
| 1046 | return "" |
| 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | if [info exists CC_FOR_TARGET] { |
| 1051 | if {$which_compiler == "c"} { |
| 1052 | set compiler $CC_FOR_TARGET |
| 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | if [info exists CXX_FOR_TARGET] { |
| 1057 | if {$which_compiler == "c++"} { |
| 1058 | set compiler $CXX_FOR_TARGET |
| 1059 | } |
| 1060 | } |
| 1061 | |
| 1062 | if [info exists F77_FOR_TARGET] { |
| 1063 | if {$which_compiler == "f77"} { |
| 1064 | set compiler $F77_FOR_TARGET |
| 1065 | } |
| 1066 | } |
| 1067 | |
| 1068 | if { ![info exists compiler] } { |
| 1069 | if { $which_compiler == "c" } { |
| 1070 | if {[info exists CC]} { |
| 1071 | set compiler $CC |
| 1072 | } |
| 1073 | } |
| 1074 | if { $which_compiler == "c++" } { |
| 1075 | if {[info exists CXX]} { |
| 1076 | set compiler $CXX |
| 1077 | } |
| 1078 | } |
| 1079 | if {![info exists compiler]} { |
| 1080 | set compiler [board_info [target_info name] compiler]; |
| 1081 | if { $compiler == "" } { |
| 1082 | perror "get_compiler: No compiler found" |
| 1083 | return "" |
| 1084 | } |
| 1085 | } |
| 1086 | } |
| 1087 | |
| 1088 | return $compiler |
| 1089 | } |
| 1090 | |
| 1091 | proc gdb_preprocess {source dest args} { |
| 1092 | set compiler [get_compiler "$args"] |
| 1093 | if { $compiler == "" } { |
| 1094 | return 1 |
| 1095 | } |
| 1096 | |
| 1097 | set cmdline "$compiler -E $source > $dest" |
| 1098 | |
| 1099 | verbose "Invoking $compiler -E $source > $dest" |
| 1100 | verbose -log "Executing on local host: $cmdline" 2 |
| 1101 | set status [catch "exec ${cmdline}" exec_output] |
| 1102 | |
| 1103 | set result [prune_warnings $exec_output] |
| 1104 | regsub "\[\r\n\]*$" "$result" "" result; |
| 1105 | regsub "^\[\r\n\]*" "$result" "" result; |
| 1106 | if { $result != "" } { |
| 1107 | clone_output "gdb compile failed, $result" |
| 1108 | } |
| 1109 | return $result; |
| 1110 | } |
| 1111 | |
| 1112 | set gdb_wrapper_initialized 0 |
| 1113 | |
| 1114 | proc gdb_wrapper_init { args } { |
| 1115 | global gdb_wrapper_initialized; |
| 1116 | global gdb_wrapper_file; |
| 1117 | global gdb_wrapper_flags; |
| 1118 | |
| 1119 | if { $gdb_wrapper_initialized == 1 } { return; } |
| 1120 | |
| 1121 | if {[target_info exists needs_status_wrapper] && \ |
| 1122 | [target_info needs_status_wrapper] != "0"} { |
| 1123 | set result [build_wrapper "testglue.o"]; |
| 1124 | if { $result != "" } { |
| 1125 | set gdb_wrapper_file [lindex $result 0]; |
| 1126 | set gdb_wrapper_flags [lindex $result 1]; |
| 1127 | } else { |
| 1128 | warning "Status wrapper failed to build." |
| 1129 | } |
| 1130 | } |
| 1131 | set gdb_wrapper_initialized 1 |
| 1132 | } |
| 1133 | |
| 1134 | proc gdb_compile {source dest type options} { |
| 1135 | global GDB_TESTCASE_OPTIONS; |
| 1136 | global gdb_wrapper_file; |
| 1137 | global gdb_wrapper_flags; |
| 1138 | global gdb_wrapper_initialized; |
| 1139 | |
| 1140 | if [target_info exists gdb_stub] { |
| 1141 | set options2 { "additional_flags=-Dusestubs" } |
| 1142 | lappend options "libs=[target_info gdb_stub]"; |
| 1143 | set options [concat $options2 $options] |
| 1144 | } |
| 1145 | if [target_info exists is_vxworks] { |
| 1146 | set options2 { "additional_flags=-Dvxworks" } |
| 1147 | lappend options "libs=[target_info gdb_stub]"; |
| 1148 | set options [concat $options2 $options] |
| 1149 | } |
| 1150 | if [info exists GDB_TESTCASE_OPTIONS] { |
| 1151 | lappend options "additional_flags=$GDB_TESTCASE_OPTIONS"; |
| 1152 | } |
| 1153 | verbose "options are $options" |
| 1154 | verbose "source is $source $dest $type $options" |
| 1155 | |
| 1156 | if { $gdb_wrapper_initialized == 0 } { gdb_wrapper_init } |
| 1157 | |
| 1158 | if {[target_info exists needs_status_wrapper] && \ |
| 1159 | [target_info needs_status_wrapper] != "0" && \ |
| 1160 | [info exists gdb_wrapper_file]} { |
| 1161 | lappend options "libs=${gdb_wrapper_file}" |
| 1162 | lappend options "ldflags=${gdb_wrapper_flags}" |
| 1163 | } |
| 1164 | |
| 1165 | set result [target_compile $source $dest $type $options]; |
| 1166 | regsub "\[\r\n\]*$" "$result" "" result; |
| 1167 | regsub "^\[\r\n\]*" "$result" "" result; |
| 1168 | if { $result != "" } { |
| 1169 | clone_output "gdb compile failed, $result" |
| 1170 | } |
| 1171 | return $result; |
| 1172 | } |
| 1173 | |
| 1174 | |
| 1175 | # This is just like gdb_compile, above, except that it tries compiling |
| 1176 | # against several different thread libraries, to see which one this |
| 1177 | # system has. |
| 1178 | proc gdb_compile_pthreads {source dest type options} { |
| 1179 | set build_binfile 0 |
| 1180 | set why_msg "unrecognized error" |
| 1181 | foreach lib {-lpthreads -lpthread -lthread} { |
| 1182 | # This kind of wipes out whatever libs the caller may have |
| 1183 | # set. Or maybe theirs will override ours. How infelicitous. |
| 1184 | set options_with_lib [concat $options [list libs=$lib]] |
| 1185 | set ccout [gdb_compile $source $dest $type $options_with_lib] |
| 1186 | switch -regexp -- $ccout { |
| 1187 | ".*no posix threads support.*" { |
| 1188 | set why_msg "missing threads include file" |
| 1189 | break |
| 1190 | } |
| 1191 | ".*cannot open -lpthread.*" { |
| 1192 | set why_msg "missing runtime threads library" |
| 1193 | } |
| 1194 | ".*Can't find library for -lpthread.*" { |
| 1195 | set why_msg "missing runtime threads library" |
| 1196 | } |
| 1197 | {^$} { |
| 1198 | pass "successfully compiled posix threads test case" |
| 1199 | set built_binfile 1 |
| 1200 | break |
| 1201 | } |
| 1202 | } |
| 1203 | } |
| 1204 | if {$built_binfile == "0"} { |
| 1205 | unsupported "Couldn't compile $source: ${why_msg}" |
| 1206 | return -1 |
| 1207 | } |
| 1208 | } |
| 1209 | |
| 1210 | proc send_gdb { string } { |
| 1211 | global suppress_flag; |
| 1212 | if { $suppress_flag } { |
| 1213 | return "suppressed"; |
| 1214 | } |
| 1215 | return [remote_send host "$string"]; |
| 1216 | } |
| 1217 | |
| 1218 | # |
| 1219 | # |
| 1220 | |
| 1221 | proc gdb_expect { args } { |
| 1222 | if { [llength $args] == 2 && [lindex $args 0] != "-re" } { |
| 1223 | set gtimeout [lindex $args 0]; |
| 1224 | set expcode [list [lindex $args 1]]; |
| 1225 | } else { |
| 1226 | upvar timeout timeout; |
| 1227 | |
| 1228 | set expcode $args; |
| 1229 | if [target_info exists gdb,timeout] { |
| 1230 | if [info exists timeout] { |
| 1231 | if { $timeout < [target_info gdb,timeout] } { |
| 1232 | set gtimeout [target_info gdb,timeout]; |
| 1233 | } else { |
| 1234 | set gtimeout $timeout; |
| 1235 | } |
| 1236 | } else { |
| 1237 | set gtimeout [target_info gdb,timeout]; |
| 1238 | } |
| 1239 | } |
| 1240 | |
| 1241 | if ![info exists gtimeout] { |
| 1242 | global timeout; |
| 1243 | if [info exists timeout] { |
| 1244 | set gtimeout $timeout; |
| 1245 | } else { |
| 1246 | # Eeeeew. |
| 1247 | set gtimeout 60; |
| 1248 | } |
| 1249 | } |
| 1250 | } |
| 1251 | global suppress_flag; |
| 1252 | global remote_suppress_flag; |
| 1253 | if [info exists remote_suppress_flag] { |
| 1254 | set old_val $remote_suppress_flag; |
| 1255 | } |
| 1256 | if [info exists suppress_flag] { |
| 1257 | if { $suppress_flag } { |
| 1258 | set remote_suppress_flag 1; |
| 1259 | } |
| 1260 | } |
| 1261 | set code [catch \ |
| 1262 | {uplevel remote_expect host $gtimeout $expcode} string]; |
| 1263 | if [info exists old_val] { |
| 1264 | set remote_suppress_flag $old_val; |
| 1265 | } else { |
| 1266 | if [info exists remote_suppress_flag] { |
| 1267 | unset remote_suppress_flag; |
| 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | if {$code == 1} { |
| 1272 | global errorInfo errorCode; |
| 1273 | |
| 1274 | return -code error -errorinfo $errorInfo -errorcode $errorCode $string |
| 1275 | } elseif {$code == 2} { |
| 1276 | return -code return $string |
| 1277 | } elseif {$code == 3} { |
| 1278 | return |
| 1279 | } elseif {$code > 4} { |
| 1280 | return -code $code $string |
| 1281 | } |
| 1282 | } |
| 1283 | |
| 1284 | # gdb_expect_list MESSAGE SENTINEL LIST -- expect a sequence of outputs |
| 1285 | # |
| 1286 | # Check for long sequence of output by parts. |
| 1287 | # MESSAGE: is the test message to be printed with the test success/fail. |
| 1288 | # SENTINEL: Is the terminal pattern indicating that output has finished. |
| 1289 | # LIST: is the sequence of outputs to match. |
| 1290 | # If the sentinel is recognized early, it is considered an error. |
| 1291 | # |
| 1292 | # Returns: |
| 1293 | # 1 if the test failed, |
| 1294 | # 0 if the test passes, |
| 1295 | # -1 if there was an internal error. |
| 1296 | # |
| 1297 | proc gdb_expect_list {test sentinel list} { |
| 1298 | global gdb_prompt |
| 1299 | global suppress_flag |
| 1300 | set index 0 |
| 1301 | set ok 1 |
| 1302 | if { $suppress_flag } { |
| 1303 | set ok 0 |
| 1304 | unresolved "${test}" |
| 1305 | } |
| 1306 | while { ${index} < [llength ${list}] } { |
| 1307 | set pattern [lindex ${list} ${index}] |
| 1308 | set index [expr ${index} + 1] |
| 1309 | if { ${index} == [llength ${list}] } { |
| 1310 | if { ${ok} } { |
| 1311 | gdb_expect { |
| 1312 | -re "${pattern}${sentinel}" { |
| 1313 | # pass "${test}, pattern ${index} + sentinel" |
| 1314 | } |
| 1315 | -re "${sentinel}" { |
| 1316 | fail "${test} (pattern ${index} + sentinel)" |
| 1317 | set ok 0 |
| 1318 | } |
| 1319 | timeout { |
| 1320 | fail "${test} (pattern ${index} + sentinel) (timeout)" |
| 1321 | set ok 0 |
| 1322 | } |
| 1323 | } |
| 1324 | } else { |
| 1325 | # unresolved "${test}, pattern ${index} + sentinel" |
| 1326 | } |
| 1327 | } else { |
| 1328 | if { ${ok} } { |
| 1329 | gdb_expect { |
| 1330 | -re "${pattern}" { |
| 1331 | # pass "${test}, pattern ${index}" |
| 1332 | } |
| 1333 | -re "${sentinel}" { |
| 1334 | fail "${test} (pattern ${index})" |
| 1335 | set ok 0 |
| 1336 | } |
| 1337 | timeout { |
| 1338 | fail "${test} (pattern ${index}) (timeout)" |
| 1339 | set ok 0 |
| 1340 | } |
| 1341 | } |
| 1342 | } else { |
| 1343 | # unresolved "${test}, pattern ${index}" |
| 1344 | } |
| 1345 | } |
| 1346 | } |
| 1347 | if { ${ok} } { |
| 1348 | pass "${test}" |
| 1349 | return 0 |
| 1350 | } else { |
| 1351 | return 1 |
| 1352 | } |
| 1353 | } |
| 1354 | |
| 1355 | # |
| 1356 | # |
| 1357 | proc gdb_suppress_entire_file { reason } { |
| 1358 | global suppress_flag; |
| 1359 | |
| 1360 | warning "$reason\n"; |
| 1361 | set suppress_flag -1; |
| 1362 | } |
| 1363 | |
| 1364 | # |
| 1365 | # Set suppress_flag, which will cause all subsequent calls to send_gdb and |
| 1366 | # gdb_expect to fail immediately (until the next call to |
| 1367 | # gdb_stop_suppressing_tests). |
| 1368 | # |
| 1369 | proc gdb_suppress_tests { args } { |
| 1370 | global suppress_flag; |
| 1371 | |
| 1372 | return; # fnf - disable pending review of results where |
| 1373 | # testsuite ran better without this |
| 1374 | incr suppress_flag; |
| 1375 | |
| 1376 | if { $suppress_flag == 1 } { |
| 1377 | if { [llength $args] > 0 } { |
| 1378 | warning "[lindex $args 0]\n"; |
| 1379 | } else { |
| 1380 | warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n"; |
| 1381 | } |
| 1382 | } |
| 1383 | } |
| 1384 | |
| 1385 | # |
| 1386 | # Clear suppress_flag. |
| 1387 | # |
| 1388 | proc gdb_stop_suppressing_tests { } { |
| 1389 | global suppress_flag; |
| 1390 | |
| 1391 | if [info exists suppress_flag] { |
| 1392 | if { $suppress_flag > 0 } { |
| 1393 | set suppress_flag 0; |
| 1394 | clone_output "Tests restarted.\n"; |
| 1395 | } |
| 1396 | } else { |
| 1397 | set suppress_flag 0; |
| 1398 | } |
| 1399 | } |
| 1400 | |
| 1401 | proc gdb_clear_suppressed { } { |
| 1402 | global suppress_flag; |
| 1403 | |
| 1404 | set suppress_flag 0; |
| 1405 | } |
| 1406 | |
| 1407 | proc gdb_start { } { |
| 1408 | default_gdb_start |
| 1409 | } |
| 1410 | |
| 1411 | proc gdb_exit { } { |
| 1412 | catch default_gdb_exit |
| 1413 | } |
| 1414 | |
| 1415 | # |
| 1416 | # gdb_load -- load a file into the debugger. |
| 1417 | # return a -1 if anything goes wrong. |
| 1418 | # |
| 1419 | proc gdb_load { arg } { |
| 1420 | return [gdb_file_cmd $arg] |
| 1421 | } |
| 1422 | |
| 1423 | proc gdb_continue { function } { |
| 1424 | global decimal |
| 1425 | |
| 1426 | return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"]; |
| 1427 | } |
| 1428 | |
| 1429 | proc default_gdb_init { args } { |
| 1430 | global gdb_wrapper_initialized |
| 1431 | |
| 1432 | gdb_clear_suppressed; |
| 1433 | |
| 1434 | # Make sure that the wrapper is rebuilt |
| 1435 | # with the appropriate multilib option. |
| 1436 | set gdb_wrapper_initialized 0 |
| 1437 | |
| 1438 | # Uh, this is lame. Really, really, really lame. But there's this *one* |
| 1439 | # testcase that will fail in random places if we don't increase this. |
| 1440 | match_max -d 20000 |
| 1441 | |
| 1442 | # We want to add the name of the TCL testcase to the PASS/FAIL messages. |
| 1443 | if { [llength $args] > 0 } { |
| 1444 | global pf_prefix |
| 1445 | |
| 1446 | set file [lindex $args 0]; |
| 1447 | |
| 1448 | set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:"; |
| 1449 | } |
| 1450 | global gdb_prompt; |
| 1451 | if [target_info exists gdb_prompt] { |
| 1452 | set gdb_prompt [target_info gdb_prompt]; |
| 1453 | } else { |
| 1454 | set gdb_prompt "\\(gdb\\)" |
| 1455 | } |
| 1456 | } |
| 1457 | |
| 1458 | proc gdb_init { args } { |
| 1459 | return [eval default_gdb_init $args]; |
| 1460 | } |
| 1461 | |
| 1462 | proc gdb_finish { } { |
| 1463 | gdb_exit; |
| 1464 | } |
| 1465 | |
| 1466 | global debug_format |
| 1467 | set debug_format "unknown" |
| 1468 | |
| 1469 | # Run the gdb command "info source" and extract the debugging format |
| 1470 | # information from the output and save it in debug_format. |
| 1471 | |
| 1472 | proc get_debug_format { } { |
| 1473 | global gdb_prompt |
| 1474 | global verbose |
| 1475 | global expect_out |
| 1476 | global debug_format |
| 1477 | |
| 1478 | set debug_format "unknown" |
| 1479 | send_gdb "info source\n" |
| 1480 | gdb_expect 10 { |
| 1481 | -re "Compiled with (.*) debugging format.\r\n.*$gdb_prompt $" { |
| 1482 | set debug_format $expect_out(1,string) |
| 1483 | verbose "debug format is $debug_format" |
| 1484 | return 1; |
| 1485 | } |
| 1486 | -re "No current source file.\r\n$gdb_prompt $" { |
| 1487 | perror "get_debug_format used when no current source file" |
| 1488 | return 0; |
| 1489 | } |
| 1490 | -re "$gdb_prompt $" { |
| 1491 | warning "couldn't check debug format (no valid response)." |
| 1492 | return 1; |
| 1493 | } |
| 1494 | timeout { |
| 1495 | warning "couldn't check debug format (timed out)." |
| 1496 | return 1; |
| 1497 | } |
| 1498 | } |
| 1499 | } |
| 1500 | |
| 1501 | # Return true if FORMAT matches the debug format the current test was |
| 1502 | # compiled with. FORMAT is a shell-style globbing pattern; it can use |
| 1503 | # `*', `[...]', and so on. |
| 1504 | # |
| 1505 | # This function depends on variables set by `get_debug_format', above. |
| 1506 | |
| 1507 | proc test_debug_format {format} { |
| 1508 | global debug_format |
| 1509 | |
| 1510 | return [expr [string match $format $debug_format] != 0] |
| 1511 | } |
| 1512 | |
| 1513 | # Like setup_xfail, but takes the name of a debug format (DWARF 1, |
| 1514 | # COFF, stabs, etc). If that format matches the format that the |
| 1515 | # current test was compiled with, then the next test is expected to |
| 1516 | # fail for any target. Returns 1 if the next test or set of tests is |
| 1517 | # expected to fail, 0 otherwise (or if it is unknown). Must have |
| 1518 | # previously called get_debug_format. |
| 1519 | proc setup_xfail_format { format } { |
| 1520 | set ret [test_debug_format $format]; |
| 1521 | |
| 1522 | if {$ret} then { |
| 1523 | setup_xfail "*-*-*" |
| 1524 | } |
| 1525 | return $ret; |
| 1526 | } |
| 1527 | |
| 1528 | proc gdb_step_for_stub { } { |
| 1529 | global gdb_prompt; |
| 1530 | |
| 1531 | if ![target_info exists gdb,use_breakpoint_for_stub] { |
| 1532 | if [target_info exists gdb_stub_step_command] { |
| 1533 | set command [target_info gdb_stub_step_command]; |
| 1534 | } else { |
| 1535 | set command "step"; |
| 1536 | } |
| 1537 | send_gdb "${command}\n"; |
| 1538 | set tries 0; |
| 1539 | gdb_expect 60 { |
| 1540 | -re "(main.* at |.*in .*start).*$gdb_prompt" { |
| 1541 | return; |
| 1542 | } |
| 1543 | -re ".*$gdb_prompt" { |
| 1544 | incr tries; |
| 1545 | if { $tries == 5 } { |
| 1546 | fail "stepping out of breakpoint function"; |
| 1547 | return; |
| 1548 | } |
| 1549 | send_gdb "${command}\n"; |
| 1550 | exp_continue; |
| 1551 | } |
| 1552 | default { |
| 1553 | fail "stepping out of breakpoint function"; |
| 1554 | return; |
| 1555 | } |
| 1556 | } |
| 1557 | } |
| 1558 | send_gdb "where\n"; |
| 1559 | gdb_expect { |
| 1560 | -re "main\[^\r\n\]*at \(\[^:]+\):\(\[0-9\]+\)" { |
| 1561 | set file $expect_out(1,string); |
| 1562 | set linenum [expr $expect_out(2,string) + 1]; |
| 1563 | set breakplace "${file}:${linenum}"; |
| 1564 | } |
| 1565 | default {} |
| 1566 | } |
| 1567 | send_gdb "break ${breakplace}\n"; |
| 1568 | gdb_expect 60 { |
| 1569 | -re "Breakpoint (\[0-9\]+) at.*$gdb_prompt" { |
| 1570 | set breakpoint $expect_out(1,string); |
| 1571 | } |
| 1572 | -re "Breakpoint (\[0-9\]+): file.*$gdb_prompt" { |
| 1573 | set breakpoint $expect_out(1,string); |
| 1574 | } |
| 1575 | default {} |
| 1576 | } |
| 1577 | send_gdb "continue\n"; |
| 1578 | gdb_expect 60 { |
| 1579 | -re "Breakpoint ${breakpoint},.*$gdb_prompt" { |
| 1580 | gdb_test "delete $breakpoint" ".*" ""; |
| 1581 | return; |
| 1582 | } |
| 1583 | default {} |
| 1584 | } |
| 1585 | } |
| 1586 | |
| 1587 | ### gdb_get_line_number TEXT [FILE] |
| 1588 | ### |
| 1589 | ### Search the source file FILE, and return the line number of a line |
| 1590 | ### containing TEXT. Use this function instead of hard-coding line |
| 1591 | ### numbers into your test script. |
| 1592 | ### |
| 1593 | ### Specifically, this function uses GDB's "search" command to search |
| 1594 | ### FILE for the first line containing TEXT, and returns its line |
| 1595 | ### number. Thus, FILE must be a source file, compiled into the |
| 1596 | ### executable you are running. If omitted, FILE defaults to the |
| 1597 | ### value of the global variable `srcfile'; most test scripts set |
| 1598 | ### `srcfile' appropriately at the top anyway. |
| 1599 | ### |
| 1600 | ### Use this function to keep your test scripts independent of the |
| 1601 | ### exact line numbering of the source file. Don't write: |
| 1602 | ### |
| 1603 | ### send_gdb "break 20" |
| 1604 | ### |
| 1605 | ### This means that if anyone ever edits your test's source file, |
| 1606 | ### your test could break. Instead, put a comment like this on the |
| 1607 | ### source file line you want to break at: |
| 1608 | ### |
| 1609 | ### /* breakpoint spot: frotz.exp: test name */ |
| 1610 | ### |
| 1611 | ### and then write, in your test script (which we assume is named |
| 1612 | ### frotz.exp): |
| 1613 | ### |
| 1614 | ### send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n" |
| 1615 | ### |
| 1616 | ### (Yes, Tcl knows how to handle the nested quotes and brackets. |
| 1617 | ### Try this: |
| 1618 | ### $ tclsh |
| 1619 | ### % puts "foo [lindex "bar baz" 1]" |
| 1620 | ### foo baz |
| 1621 | ### % |
| 1622 | ### Tcl is quite clever, for a little stringy language.) |
| 1623 | |
| 1624 | proc gdb_get_line_number {text {file /omitted/}} { |
| 1625 | global gdb_prompt; |
| 1626 | global srcfile; |
| 1627 | |
| 1628 | if {! [string compare $file /omitted/]} { |
| 1629 | set file $srcfile |
| 1630 | } |
| 1631 | |
| 1632 | set result -1; |
| 1633 | gdb_test "list ${file}:1,1" ".*" "" |
| 1634 | send_gdb "search ${text}\n" |
| 1635 | gdb_expect { |
| 1636 | -re "\[\r\n\]+(\[0-9\]+)\[ \t\].*${text}.*$gdb_prompt $" { |
| 1637 | set result $expect_out(1,string) |
| 1638 | } |
| 1639 | -re ".*$gdb_prompt $" { |
| 1640 | fail "find line number containing \"${text}\"" |
| 1641 | } |
| 1642 | timeout { |
| 1643 | fail "find line number containing \"${text}\" (timeout)" |
| 1644 | } |
| 1645 | } |
| 1646 | return $result; |
| 1647 | } |
| 1648 | |
| 1649 | # gdb_continue_to_end: |
| 1650 | # The case where the target uses stubs has to be handled specially. If a |
| 1651 | # stub is used, we set a breakpoint at exit because we cannot rely on |
| 1652 | # exit() behavior of a remote target. |
| 1653 | # |
| 1654 | # mssg is the error message that gets printed. |
| 1655 | |
| 1656 | proc gdb_continue_to_end {mssg} { |
| 1657 | if [target_info exists use_gdb_stub] { |
| 1658 | if {![gdb_breakpoint "exit"]} { |
| 1659 | return 0 |
| 1660 | } |
| 1661 | gdb_test "continue" "Continuing..*Breakpoint .*exit.*" \ |
| 1662 | "continue until exit at $mssg" |
| 1663 | } else { |
| 1664 | # Continue until we exit. Should not stop again. |
| 1665 | # Don't bother to check the output of the program, that may be |
| 1666 | # extremely tough for some remote systems. |
| 1667 | gdb_test "continue"\ |
| 1668 | "Continuing.\[\r\n0-9\]+(... EXIT code 0\[\r\n\]+|)Program exited normally\\..*"\ |
| 1669 | "continue until exit at $mssg" |
| 1670 | } |
| 1671 | } |
| 1672 | |
| 1673 | proc rerun_to_main {} { |
| 1674 | global gdb_prompt |
| 1675 | |
| 1676 | if [target_info exists use_gdb_stub] { |
| 1677 | gdb_run_cmd |
| 1678 | gdb_expect { |
| 1679 | -re ".*Breakpoint .*main .*$gdb_prompt $"\ |
| 1680 | {pass "rerun to main" ; return 0} |
| 1681 | -re "$gdb_prompt $"\ |
| 1682 | {fail "rerun to main" ; return 0} |
| 1683 | timeout {fail "(timeout) rerun to main" ; return 0} |
| 1684 | } |
| 1685 | } else { |
| 1686 | send_gdb "run\n" |
| 1687 | gdb_expect { |
| 1688 | -re "Starting program.*$gdb_prompt $"\ |
| 1689 | {pass "rerun to main" ; return 0} |
| 1690 | -re "$gdb_prompt $"\ |
| 1691 | {fail "rerun to main" ; return 0} |
| 1692 | timeout {fail "(timeout) rerun to main" ; return 0} |
| 1693 | } |
| 1694 | } |
| 1695 | } |
| 1696 | |
| 1697 | # Print a message and return true if a test should be skipped |
| 1698 | # due to lack of floating point suport. |
| 1699 | |
| 1700 | proc gdb_skip_float_test { msg } { |
| 1701 | if [target_info exists gdb,skip_float_tests] { |
| 1702 | verbose "Skipping test '$msg': no float tests."; |
| 1703 | return 1; |
| 1704 | } |
| 1705 | return 0; |
| 1706 | } |
| 1707 | |
| 1708 | # Print a message and return true if a test should be skipped |
| 1709 | # due to lack of stdio support. |
| 1710 | |
| 1711 | proc gdb_skip_stdio_test { msg } { |
| 1712 | if [target_info exists gdb,noinferiorio] { |
| 1713 | verbose "Skipping test '$msg': no inferior i/o."; |
| 1714 | return 1; |
| 1715 | } |
| 1716 | return 0; |
| 1717 | } |
| 1718 | |
| 1719 | proc gdb_skip_bogus_test { msg } { |
| 1720 | return 0; |
| 1721 | } |
| 1722 | |