diff options
author | Bob Manson <manson@cygnus> | 1997-01-29 09:40:31 +0000 |
---|---|---|
committer | Bob Manson <manson@cygnus> | 1997-01-29 09:40:31 +0000 |
commit | 787f6220773d9174a9675dedd3bbfc8f070511a6 (patch) | |
tree | 64911c10d46bc93973cc825a730b4173b3367a49 /gdb/testsuite/lib | |
parent | 1a2faf1f1e335ff32c1d8c5c7675cd7ce9055e33 (diff) | |
download | gdb-787f6220773d9174a9675dedd3bbfc8f070511a6.zip gdb-787f6220773d9174a9675dedd3bbfc8f070511a6.tar.gz gdb-787f6220773d9174a9675dedd3bbfc8f070511a6.tar.bz2 |
Major revision to testsuites for cross-testing and DOS testing support.
Diffstat (limited to 'gdb/testsuite/lib')
-rw-r--r-- | gdb/testsuite/lib/gdb.exp | 422 |
1 files changed, 278 insertions, 144 deletions
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index ec3b94e..8889492 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -26,21 +26,9 @@ load_lib libgloss.exp global GDB -global CC -global CXX -global CFLAGS -global CXXFLAGS global CHILL_LIB global CHILL_RT0 -if ![info exists CC] { - set CC [findfile $base_dir/../../gcc/xgcc "$base_dir/../../gcc/xgcc -B$base_dir/../../gcc/" [transform gcc]] -} -verbose "using CC = $CC" 2 -if ![info exists CXX] { - set CXX [findfile $base_dir/../../gcc/xgcc "$base_dir/../../gcc/xgcc -B$base_dir/../../gcc/" [transform g++]] -} -verbose "using CXX = $CXX" 2 if ![info exists CHILL_LIB] { set CHILL_LIB [findfile $base_dir/../../gcc/ch/runtime/libchill.a "$base_dir/../../gcc/ch/runtime/libchill.a" [transform -lchill]] } @@ -50,21 +38,17 @@ if ![info exists CHILL_RT0] { } verbose "using CHILL_RT0 = $CHILL_RT0" 2 -if ![info exists LDFLAGS] { - if [is3way] { - append LDFLAGS " [libgloss_flags] [newlib_flags]" +if ![info exists GDB] { + if ![is_remote host] { + set GDB [findfile $base_dir/../../gdb/gdb "$base_dir/../../gdb/gdb" [transform gdb]] + } else { + set GDB gdb } - set LDFLAGS "" -} -verbose "using LDFLAGS = $LDFLAGS" 2 - -if ![info exists GDB] then { - set GDB [findfile $base_dir/../../gdb/gdb "$base_dir/../../gdb/gdb" [transform gdb]] } verbose "using GDB = $GDB" 2 global GDBFLAGS -if ![info exists GDBFLAGS] then { +if ![info exists GDBFLAGS] { set GDBFLAGS "-nx" } verbose "using GDBFLAGS = $GDBFLAGS" 2 @@ -73,14 +57,7 @@ verbose "using GDBFLAGS = $GDBFLAGS" 2 # is not already set. global prompt if ![info exists prompt] then { - set prompt "\\(gdb\\)" -} - -global usestubs -if [istarget "sparclite-*-*"] then { - set usestubs 1 -} else { - set usestubs 0 + set prompt "\[(\]gdb\[)\]" } if ![info exists noargs] then { @@ -105,15 +82,28 @@ if ![info exists noresults] then { proc default_gdb_version {} { global GDB global GDBFLAGS - if {[which $GDB] != 0} then { - set tmp [exec echo "q" | $GDB -nw $GDBFLAGS] - regexp " \[0-9\]\[^ \t\n\]+" $tmp version - clone_output "[which $GDB] version$version -nw $GDBFLAGS \n" + global prompt + set fileid [open "gdb_cmd" w]; + puts $fileid "q"; + close $fileid; + set cmdfile [remote_download host "gdb_cmd"]; + set output [remote_exec host "$GDB -nw --command $cmdfile"] + remote_file build delete "gdb_cmd"; + remote_file host delete "$cmdfile"; + set tmp [lindex $output 1]; + set version "" + regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version + if ![is_remote host] { + clone_output "[which $GDB] version $version $GDBFLAGS\n" } else { - warning "$GDB does not exist" + clone_output "$GDB on remote host version $version $GDBFLAGS\n" } } +proc gdb_version { } { + return [default_gdb_version]; +} + # # gdb_unload -- unload a file if one is loaded # @@ -122,17 +112,17 @@ proc gdb_unload {} { global verbose global GDB global prompt - send "file\n" + send_gdb "file\n" expect { -re "No exec file now.*\r" { exp_continue } -re "No symbol file now.*\r" { exp_continue } -re "A program is being debugged already..*Kill it.*y or n. $"\ - { send "y\n" + { send_gdb "y\n" verbose "\t\tKilling previous program being debugged" exp_continue } -re "Discard symbol table from .*y or n. $" { - send "y\n" + send_gdb "y\n" exp_continue } -re "$prompt $" {} @@ -151,23 +141,27 @@ proc gdb_unload {} { proc delete_breakpoints {} { global prompt + global gdb_spawn_id - send "delete breakpoints\n" + send_gdb "delete breakpoints\n" expect { - -re "Delete all breakpoints.*y or n. $" { - send "y\n" + -i $gdb_spawn_id -re ".*Delete all breakpoints.*y or n.*$" { + send_gdb "y\n"; exp_continue } - -re "y\r\n$prompt $" {} - -re ".*$prompt $" { # This happens if there were no breakpoints + -i $gdb_spawn_id -re ".*$prompt $" { # This happens if there were no breakpoints } - timeout { perror "Delete all breakpoints (timeout)" ; return } + -i $gdb_spawn_id timeout { perror "Delete all breakpoints in delete_breakpoints (timeout)" ; return } } - send "info breakpoints\n" + send_gdb "info breakpoints\n" expect { - -re "No breakpoints or watchpoints..*$prompt $" {} - -re ".*$prompt $" { perror "breakpoints not deleted" ; return } - timeout { perror "info breakpoints (timeout)" ; return } + -i $gdb_spawn_id -re "No breakpoints or watchpoints..*$prompt $" {} + -i $gdb_spawn_id -re ".*$prompt $" { perror "breakpoints not deleted" ; return } + -i $gdb_spawn_id -re "Delete all breakpoints.*or n.*$" { + send_gdb "y\n"; + exp_continue + } + -i $gdb_spawn_id timeout { perror "info breakpoints (timeout)" ; return } } } @@ -179,35 +173,60 @@ proc delete_breakpoints {} { # Using ``.*$'' could swallow up output that we attempt to match # elsewhere. # -proc gdb_run_cmd {} { - global usestubs +proc gdb_run_cmd {args} { global prompt + global gdb_spawn_id + + set spawn_id $gdb_spawn_id - if $usestubs!=0 { - send "jump *start\n" + if [target_info exists use_gdb_stub] { + send_gdb "jump *start\n" expect { -re "Line.* Jump anyway.*y or n. $" { - send "y\n" + send_gdb "y\n" expect { -re "Continuing.*$prompt $" {} timeout { perror "Jump to start() failed (timeout)"; return } } } + -re "No symbol.*context.*$prompt $" {} + -re "The program is not being run.*$prompt $" { + gdb_load ""; + } timeout { perror "Jump to start() failed (timeout)"; return } } - send "continue\n" + send_gdb "continue\n" return } - send "run\n" + send_gdb "run $args\n" +# This doesn't work quite right yet. expect { -re "The program .* has been started already.*y or n. $" { - send "y\n" + send_gdb "y\n" exp_continue } -re "Starting program: \[^\n\]*" {} } } +proc gdb_breakpoint { function } { + global prompt + global decimal + global gdb_spawn_id + + set spawn_id $gdb_spawn_id + + send_gdb "break $function\n" + # The first two regexps are what we get with -g, the third is without -g. + expect { + -re "Breakpoint \[0-9\]* at .*: file .*, line $decimal.\r\n$prompt $" {} + -re "Breakpoint \[0-9\]*: file .*, line $decimal.\r\n$prompt $" {} + -re "Breakpoint \[0-9\]* at .*$prompt $" {} + -re "$prompt $" { fail "setting breakpoint at $function" ; return 0 } + timeout { fail "setting breakpoint at $function (timeout)" ; return 0 } + } + return 1; +} # Set breakpoint at function and run gdb until it breaks there. # Since this is the only breakpoint that will be set, if it stops @@ -218,28 +237,14 @@ proc gdb_run_cmd {} { proc runto { function } { global prompt global decimal + global gdb_spawn_id - send "delete\n" - expect { - -re "delete.*Delete all breakpoints.*y or n. $" { - send "y\n" - expect { - -re "$prompt $" {} - timeout { fail "deleting breakpoints (timeout)" ; return 0 } - } - } - -re ".*$prompt $" {} - timeout { fail "deleting breakpoints (timeout)" ; return 0 } - } + set spawn_id $gdb_spawn_id - send "break $function\n" - # The first two regexps are what we get with -g, the third is without -g. - expect { - -re "Breakpoint \[0-9\]* at .*: file .*, line $decimal.\r\n$prompt $" {} - -re "Breakpoint \[0-9\]*: file .*, line $decimal.\r\n$prompt $" {} - -re "Breakpoint \[0-9\]* at .*$prompt $" {} - -re "$prompt $" { fail "setting breakpoint at $function" ; return 0 } - timeout { fail "setting breakpoint at $function (timeout)" ; return 0 } + delete_breakpoints + + if ![gdb_breakpoint $function] { + return 0; } gdb_run_cmd @@ -254,61 +259,53 @@ proc runto { function } { return 1 } -re "$prompt $" { - fail "running to $function" + fail "running to $function in runto" return 0 } timeout { - fail "running to $function (timeout)" + fail "running to $function in runto (timeout)" return 0 } } } # -# runto_main -- ask gdb to run and untill hit break point at main. -# if it uses stubs, assuming we hit breakpoint() and just -# step out of the function. +# runto_main -- ask gdb to run until we hit a breakpoint at main. +# The case where the target uses stubs has to be handled +# specially--if it uses stubs, assuming we hit +# breakpoint() and just step out of the function. # proc runto_main {} { global prompt global decimal - global usestubs - if $usestubs==0 { + if ![target_info exists gdb_stub] { return [runto main] } - send "delete\n" - expect { - -re "delete.*Delete all breakpoints.*y or n. $" { - send "y\n" - expect { - -re "$prompt $" {} - timeout { fail "deleting breakpoints (timeout)" ; return 0 } - } - } - -re ".*$prompt $" {} - timeout { fail "deleting breakpoints (timeout)" ; return 0 } - } + delete_breakpoints - send "step\n" + send_gdb "step\n" # if use stubs step out of the breakpoint() function. expect { -re "main.* at .*$prompt $" {} + -re "_start.*$prompt $" {} timeout { fail "single step at breakpoint() (timeout)" ; return 0 } } return 1 } # -# gdb_test -- send a command to gdb and test the result. +# gdb_test -- send_gdb a command to gdb and test the result. # Takes three parameters. # Parameters: -# First one is the command to execute, +# First one is the command to execute. If this is the null string +# then no command is sent. # Second one is the pattern to match for a PASS, and must NOT include # the \r\n sequence immediately before the gdb prompt. # Third one is an optional message to be printed. If this -# a null string "", then the pass/fail messages are not printed. +# a null string "", then the pass/fail messages use the command +# string as the message. # Returns: # 1 if the test failed, # 0 if the test passes, @@ -318,11 +315,10 @@ proc gdb_test { args } { global verbose global prompt global GDB - global spawn_id global expect_out upvar timeout timeout - if [llength $args]==3 then { + if [llength $args]>2 then { set message [lindex $args 2] } else { set message [lindex $args 0] @@ -330,6 +326,13 @@ proc gdb_test { args } { set command [lindex $args 0] set pattern [lindex $args 1] + if [llength $args]==5 { + set question_string [lindex $args 3]; + set response_string [lindex $args 4]; + } else { + set question_string "^FOOBAR$" + } + if $verbose>2 then { send_user "Sending \"$command\" to gdb\n" send_user "Looking to match \"$pattern\"\n" @@ -338,7 +341,7 @@ proc gdb_test { args } { set result -1 if ![string match $command ""] { - send "$command\n" + send_gdb "$command\n" } expect { @@ -350,12 +353,16 @@ proc gdb_test { args } { gdb_start set result -1 } - -re "$pattern\r\n$prompt $" { + -re "\[\r\n\]*$pattern\[\r\n\]+$prompt $" { if ![string match "" $message] then { pass "$message" } set result 0 } + -re "${question_string}$" { + send_gdb "$response_string\n"; + exp_continue; + } -re "Undefined command:.*$prompt" { perror "Undefined command \"$command\"." set result 1 @@ -364,13 +371,13 @@ proc gdb_test { args } { perror "\"$command\" is not a unique command name." set result 1 } - -re "(.*)(Program exited with code \[0-9\]+)(.*$prompt $)" { + -re ".*Program exited with code \[0-9\]+.*$prompt $" { if ![string match "" $message] then { - set errmsg "$message: $expect_out(2,string)" + set errmsg "$message: the program exited" } else { - set errmsg "$command: $expect_out(2,string)" + set errmsg "$command: the program exited" } - perror "$errmsg" + fail "$errmsg" return -1 } -re "The program is not being run.*$prompt $" { @@ -379,7 +386,7 @@ proc gdb_test { args } { } else { set errmsg "$command: the program is no longer running" } - perror "$errmsg" + fail "$errmsg" return -1 } -re ".*$prompt $" { @@ -389,11 +396,11 @@ proc gdb_test { args } { set result 1 } "<return>" { - send "\n" + send_gdb "\n" perror "Window too small." } -re "\\(y or n\\) " { - send "n\n" + send_gdb "n\n" perror "Got interactive prompt." } eof { @@ -433,7 +440,7 @@ proc test_print_reject { args } { send_user "Sending \"$sendthis\" to gdb\n" send_user "Looking to match \"$expectthis\"\n" } - send "$sendthis\n" + send_gdb "$sendthis\n" expect { -re ".*A .* in expression.*\\.*$prompt $" { pass "reject $sendthis" @@ -494,7 +501,20 @@ proc gdb_test_exact { args } { upvar timeout timeout set command [lindex $args 0] - set pattern [string_to_regexp [lindex $args 1]] + + # This applies a special meaning to a null string pattern. Without + # this, "$pattern\r\n$prompt $" will match anything, including error + # messages from commands that should have no output except a new + # prompt. With this, only results of a null string will match a null + # string pattern. + + set pattern [lindex $args 1] + if [string match $pattern ""] { + set pattern [string_to_regexp [lindex $args 0]] + } else { + set pattern [string_to_regexp [lindex $args 1]] + } + # It is most natural to write the pattern argument with only # embedded \n's, especially if you are trying to avoid Tcl quoting # problems. But expect really wants to see \r\n in patterns. So @@ -507,19 +527,25 @@ proc gdb_test_exact { args } { } else { set message $command } + return [gdb_test $command $pattern $message] } proc gdb_reinitialize_dir { subdir } { global prompt + global gdb_spawn_id + set spawn_id $gdb_spawn_id - send "dir\n" + if [is_remote host] { + return ""; + } + send_gdb "dir\n" expect { -re "Reinitialize source path to empty.*y or n. " { - send "y\n" + send_gdb "y\n" expect { -re "Source directories searched.*$prompt $" { - send "dir $subdir\n" + send_gdb "dir $subdir\n" expect { -re "Source directories searched.*$prompt $" { verbose "Dir set to $subdir" @@ -547,6 +573,11 @@ proc default_gdb_exit {} { global GDB global GDBFLAGS global verbose + global gdb_spawn_id + + if ![info exists gdb_spawn_id] { + return; + } verbose "Quitting $GDB $GDBFLAGS" @@ -554,13 +585,27 @@ proc default_gdb_exit {} { set timeout 5 verbose "Timeout is now $timeout seconds" 2 - # We used to try to send "quit" to GDB, and wait for it to die. - # Dealing with all the cases and errors got pretty hairy. Just close it, - # that is simpler. - close + if [is_remote host] { + send_gdb "quit\n"; + expect { + -i $gdb_spawn_id -re ".*and kill it.*y or n. " { + send_gdb "y\n"; + exp_continue; + } + -i $gdb_spawn_id timeout { } + } + remote_close host; + } else { + # We used to try to send_gdb "quit" to GDB, and wait for it to die. + # Dealing with all the cases and errors got pretty hairy. Just close it, + # that is simpler. + close -i $gdb_spawn_id + + # Omitting this probably would cause strange timing-dependent failures. + wait -i $gdb_spawn_id + } - # Omitting this probably would cause strange timing-dependent failures. - wait + unset gdb_spawn_id } # @@ -573,10 +618,19 @@ proc gdb_file_cmd { arg } { global loadfile global GDB global prompt - global spawn_id upvar timeout timeout + global gdb_spawn_id + set spawn_id $gdb_spawn_id + + if [is_remote host] { + set arg [remote_download host $arg]; + if { $arg == "" } { + error "download failed" + return -1; + } + } - send "file $arg\n" + send_gdb "file $arg\n" expect { -re "Reading symbols from.*done.*$prompt $" { verbose "\t\tLoaded $arg into the $GDB" @@ -587,12 +641,12 @@ proc gdb_file_cmd { arg } { return -1 } -re "A program is being debugged already.*Kill it.*y or n. $" { - send "y\n" + send_gdb "y\n" verbose "\t\tKilling previous program being debugged" exp_continue } -re "Load new symbol table from \".*\".*y or n. $" { - send "y\n" + send_gdb "y\n" expect { -re "Reading symbols from.*done.*$prompt $" { verbose "\t\tLoaded $arg with new symbol table into $GDB" @@ -639,30 +693,40 @@ proc default_gdb_start { } { global GDB global GDBFLAGS global prompt - global spawn_id global timeout + global gdb_spawn_id + global spawn_id verbose "Spawning $GDB -nw $GDBFLAGS" - if { [which $GDB] == 0 } then { - perror "$GDB does not exist." - exit 1 + if [info exists gdb_spawn_id] { + return 0; } - + set oldtimeout $timeout set timeout [expr "$timeout + 180"] - verbose "Timeout increased to $timeout seconds" 2 - eval "spawn $GDB -nw $GDBFLAGS" + if [is_remote host] { + set shell_id [remote_spawn host "$GDB -nw $GDBFLAGS --command gdbinit"] + } else { + if { [which $GDB] == 0 } then { + perror "$GDB does not exist." + exit 1 + } + + set shell_id [remote_spawn host "$GDB -nw $GDBFLAGS"] + } + verbose $shell_id + set timeout 10 expect { - -re ".*\r\n$prompt $" { + -i $shell_id -re ".*\[\r\n\]$prompt $" { verbose "GDB initialized." } - -re "$prompt $" { + -i $shell_id -re "$prompt $" { perror "GDB never initialized." set timeout $oldtimeout verbose "Timeout restored to $timeout seconds" 2 return -1 } - timeout { + -i $shell_id timeout { perror "(timeout) GDB never initialized after $timeout seconds." set timeout $oldtimeout verbose "Timeout restored to $timeout seconds" 2 @@ -671,32 +735,35 @@ proc default_gdb_start { } { } set timeout $oldtimeout verbose "Timeout restored to $timeout seconds" 2 + set gdb_spawn_id $shell_id + set spawn_id $gdb_spawn_id # force the height to "unlimited", so no pagers get used - send "set height 0\n" + send_gdb "set height 0\n" expect { - -re ".*$prompt $" { + -i $shell_id -re ".*$prompt $" { verbose "Setting height to 0." 2 } - timeout { - warning "Couldn't set the height to 0." + -i $shell_id timeout { + warning "Couldn't set the height to 0" } } # force the width to "unlimited", so no wraparound occurs - send "set width 0\n" + send_gdb "set width 0\n" expect { - -re ".*$prompt $" { + -i $shell_id -re ".*$prompt $" { verbose "Setting width to 0." 2 } - timeout { + -i $shell_id timeout { warning "Couldn't set the width to 0." } } + return 0; } # # FIXME: this is a copy of the new library procedure, but it's here too # till the new dejagnu gets installed everywhere. I'd hate to break the -# gdb tests suite. +# gdb testsuite. # global argv0 if ![info exists argv0] then { @@ -717,7 +784,74 @@ if ![info exists argv0] then { # chill target at the moment, don't run the chill tests. proc skip_chill_tests {} { - eval set skip_chill [expr ![isnative] || [istarget "*-*-aix*"] || [istarget "*-*-irix5*"] || [istarget "alpha-*-osf*"] || [istarget "hppa*-*-*"]] + if ![info exists do_chill_tests] { + return 1; + } + eval set skip_chill [expr ![isnative] || [istarget "*-*-aix*"] || [istarget "*-*-irix5*"] || [istarget "*-*-irix6*"] || [istarget "alpha-*-osf*"] || [istarget "hppa*-*-*"]] verbose "Skip chill tests is $skip_chill" return $skip_chill } + +proc get_compiler_info {binfile} { + # Create and source the file that provides information about the compiler + # used to compile the test case. + global srcdir + global subdir + # These two come from compiler.c. + global signed_keyword_not_used + global gcc_compiled + + if { [gdb_compile "${srcdir}/${subdir}/compiler.c" "${binfile}.ci" preprocess {}] != "" } { + perror "Couldn't make ${binfile}.ci file" + return 1; + } + source ${binfile}.ci + return 0; +} + +proc gdb_compile {source dest type options} { + if [target_info exists gdb_stub] { + set options2 { "additional_flags=-Dusestubs" } + lappend options "libs=[target_info gdb_stub]"; + set options [concat $options2 $options] + } + verbose "options are $options" + verbose "source is $source $dest $type $options" + set result [target_compile $source $dest $type $options]; + regsub "\[\r\n\]*$" "$result" "" result; + regsub "^\[\r\n\]*" "$result" "" result; + if { $result != "" } { + clone_output "gdb compile failed, $result" + } + return $result; +} + +proc send_gdb { string } { + return [remote_send host "$string"]; +} + +proc gdb_start { } { + default_gdb_start +} + +proc gdb_exit { } { + catch default_gdb_exit +} + +# +# gdb_load -- load a file into the debugger. +# return a -1 if anything goes wrong. +# +proc gdb_load { arg } { + return [gdb_file_cmd $arg] +} + +proc gdb_continue { function } { + global decimal + + return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"]; +} + +proc gdb_finish { } { + gdb_exit; +} |