From 763ee8502617a60851cf77aef5fb095a9366eb4e Mon Sep 17 00:00:00 2001 From: Bob Rossi Date: Thu, 4 Aug 2005 01:52:31 +0000 Subject: [PATCH] 2005-08-02 Bob Rossi * gdb.mi/mi-basics.exp: Tell mi_gdb_start to use a PTY for inferior. (test_setshow_inferior_tty): Add global mi_inferior_tty_name to scope. Change tests to inferior-tty-set/show. * gdb.mi/mi-console.exp: Tell mi_gdb_start to use a PTY for inferior. (47-exec-next): Use mi_gdb_test to get GDB and Inferior output. * gdb.mi/mi-syn-frame.exp: Tell mi_gdb_start to use a PTY for inferior. Use mi_gdb_test to get GDB and Inferior output. * lib/mi-support.exp (mi_inferior_spawn_id): Add inferior PTY descriptor. (mi_inferior_tty_name): Add inferior PTY file name. (mi_gdb_start): Add INFERIOR_PTY parameter. (mi_gdb_test): Add IPATTERN parameter. --- gdb/testsuite/ChangeLog | 15 ++++++++ gdb/testsuite/gdb.mi/mi-basics.exp | 17 ++++++--- gdb/testsuite/gdb.mi/mi-console.exp | 37 +++---------------- gdb/testsuite/gdb.mi/mi-syn-frame.exp | 37 ++++++++----------- gdb/testsuite/lib/mi-support.exp | 68 +++++++++++++++++++++++++++++++++-- 5 files changed, 112 insertions(+), 62 deletions(-) diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index a787032d57..97e7791390 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,18 @@ +2005-08-02 Bob Rossi + + * gdb.mi/mi-basics.exp: Tell mi_gdb_start to use a PTY for inferior. + (test_setshow_inferior_tty): Add global mi_inferior_tty_name to scope. + Change tests to inferior-tty-set/show. + * gdb.mi/mi-console.exp: Tell mi_gdb_start to use a PTY for inferior. + (47-exec-next): Use mi_gdb_test to get GDB and Inferior output. + * gdb.mi/mi-syn-frame.exp: Tell mi_gdb_start to use a PTY for + inferior. Use mi_gdb_test to get GDB and Inferior output. + * lib/mi-support.exp (mi_inferior_spawn_id): Add inferior PTY + descriptor. + (mi_inferior_tty_name): Add inferior PTY file name. + (mi_gdb_start): Add INFERIOR_PTY parameter. + (mi_gdb_test): Add IPATTERN parameter. + 2005-08-02 Bob Rossi * gdb.mi/mi-syn-frame.exp, gdb.mi/mi2-syn-frame.exp: Add MESSAGE diff --git a/gdb/testsuite/gdb.mi/mi-basics.exp b/gdb/testsuite/gdb.mi/mi-basics.exp index 0d2b06ee98..7e576a7077 100644 --- a/gdb/testsuite/gdb.mi/mi-basics.exp +++ b/gdb/testsuite/gdb.mi/mi-basics.exp @@ -33,7 +33,7 @@ load_lib mi-support.exp set MIFLAGS "-i=mi" gdb_exit -if [mi_gdb_start] { +if [mi_gdb_start separate-inferior-tty] { continue } @@ -238,6 +238,7 @@ proc test_path_specification {} { proc test_setshow_inferior_tty {} { global mi_gdb_prompt + global mi_inferior_tty_name # Test that the commands, # -inferior-tty-set @@ -245,8 +246,8 @@ proc test_setshow_inferior_tty {} { # are setting/getting the same data in GDB. mi_gdb_test "301-inferior-tty-show" \ - "301\\\^done" \ - "initial tty is empty" + "301\\\^done,inferior_tty_terminal=\"$mi_inferior_tty_name\"" \ + "initial tty is mi_inferior_tty_name" mi_gdb_test "302-inferior-tty-set /dev/pts/1" \ "302\\\^done" \ @@ -262,7 +263,15 @@ proc test_setshow_inferior_tty {} { mi_gdb_test "305-inferior-tty-show" \ "305\\\^done" \ - "final tty is empty" + "make sure tty is empty" + + mi_gdb_test "306-inferior-tty-set $mi_inferior_tty_name" \ + "306\\\^done" \ + "set tty to mi_inferior_tty_name (the way it was)" + + mi_gdb_test "307-inferior-tty-show" \ + "307\\\^done,inferior_tty_terminal=\"$mi_inferior_tty_name\"" \ + "verify tty is correct" } if [test_mi_interpreter_selection] { diff --git a/gdb/testsuite/gdb.mi/mi-console.exp b/gdb/testsuite/gdb.mi/mi-console.exp index 2dbfc15937..84ae35fb5d 100644 --- a/gdb/testsuite/gdb.mi/mi-console.exp +++ b/gdb/testsuite/gdb.mi/mi-console.exp @@ -36,7 +36,7 @@ load_lib mi-support.exp set MIFLAGS "-i=mi" gdb_exit -if [mi_gdb_start] { +if [mi_gdb_start separate-inferior-tty] { continue } @@ -54,37 +54,10 @@ mi_gdb_load ${binfile} mi_run_to_main # Next over the hello() call which will produce lots of output -send_gdb "47-exec-next\n" -gdb_expect { - -re "47\\^running\r\n$mi_gdb_prompt" { - pass "Started step over hello" - } - timeout { - fail "Started step over hello (timeout)" - } -} - -if { ![target_info exists gdb,noinferiorio]} { - gdb_expect { - -re "@\"H\"\r\n.*@\"e\"\r\n.*@\"l\"\r\n.*@\"l\"\r\n.*@\"o\"\r\n.*@\" \"\r\n.*@\"\\\\\\\\\"\r\n.*@\"\\\\\"\"\r\n.*@\"!\"\r\n.*@\"\\\\r\"\r\n.*@\"\\\\n\"\r\n" { - pass "Hello message" - } - -re "Hello" { - - # Probably a native system where GDB doesn't have direct # - # control over the inferior console. # For this to work, - # GDB would need to run the inferior process # under a PTY - # and then use the even-loops ability to wait on # - # multiple event sources to channel the output back - # through the # MI. - - kfail "gdb/623" "Hello message" - } - timeout { - fail "Hello message (timeout)" - } - } -} +mi_gdb_test "47-exec-next" \ + "47\\^running" \ + "Testing console output" \ + "Hello \\\\\"!\[\r\n\]+" gdb_expect { -re "47\\*stopped.*$mi_gdb_prompt$" { diff --git a/gdb/testsuite/gdb.mi/mi-syn-frame.exp b/gdb/testsuite/gdb.mi/mi-syn-frame.exp index a5e99651a6..28a2f28b70 100644 --- a/gdb/testsuite/gdb.mi/mi-syn-frame.exp +++ b/gdb/testsuite/gdb.mi/mi-syn-frame.exp @@ -38,7 +38,7 @@ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {deb set my_mi_gdb_prompt "\\(gdb\\)\[ \]*\[\r\n\]*" mi_gdb_exit -mi_gdb_start +mi_gdb_start separate-inferior-tty mi_delete_breakpoints mi_gdb_reinitialize_dir $srcdir/$subdir mi_gdb_load ${binfile} @@ -60,16 +60,10 @@ mi_gdb_test "402-stack-list-frames" "402\\^done,stack=\\\[frame=\{level=\"0\",ad # # Continue back to main() # - -send_gdb "403-exec-continue\n" -gdb_expect { - -re "403\\^running\[\r\n\]+${my_mi_gdb_prompt}hi in foo\[\r\n\]+403\\\*stopped\[\r\n\]+${my_mi_gdb_prompt}$" { - pass "403-exec-continue" - } - timeout { - fail "403-exec-continue" - } -} +mi_gdb_test "403-exec-continue" \ + "403\\^running\[\r\n\]+${my_mi_gdb_prompt}403\\\*stopped" \ + "testing exec continue" \ + "hi in foo\[\r\n\]\+" mi_gdb_test "404-stack-list-frames 0 0" \ "404\\^done,stack=\\\[frame=\{level=\"0\",addr=\"$hex\",func=\"main\",file=\".*mi-syn-frame.c\",fullname=\"${fullname_syntax}${srcfile}\",line=\"$decimal\"\}.*\\\]" \ @@ -85,8 +79,9 @@ mi_gdb_test "405-break-insert subroutine" \ "insert breakpoint subroutine" mi_gdb_test "406-data-evaluate-expression have_a_very_merry_interrupt()" \ - "Waiting to get a signal\[\r\n\]+\\&\"The program being debugged stopped while in a function called from GDB.\\\\n\"\[\r\n\]+\\&\"When the function \\(have_a_very_merry_interrupt\\) is done executing, GDB will silently\\\\n\"\[\r\n\]+\\&\"stop \\(instead of continuing to evaluate the expression containing\\\\n\"\[\r\n\]+\\&\"the function call\\).\\\\n\"\[\r\n\]+406\\^error,msg=\"The program being debugged stopped while in a function called from GDB.\\\\nWhen the function \\(have_a_very_merry_interrupt\\) is done executing, GDB will silently\\\\nstop \\(instead of continuing to evaluate the expression containing\\\\nthe function call\\).\"" \ - "evaluate expression have_a_very_merry_interrupt" + "\\&\"The program being debugged stopped while in a function called from GDB.\\\\n\"\[\r\n\]+\\&\"When the function \\(have_a_very_merry_interrupt\\) is done executing, GDB will silently\\\\n\"\[\r\n\]+\\&\"stop \\(instead of continuing to evaluate the expression containing\\\\n\"\[\r\n\]+\\&\"the function call\\).\\\\n\"\[\r\n\]+406\\^error,msg=\"The program being debugged stopped while in a function called from GDB.\\\\nWhen the function \\(have_a_very_merry_interrupt\\) is done executing, GDB will silently\\\\nstop \\(instead of continuing to evaluate the expression containing\\\\nthe function call\\).\"" \ + "data evaluate expression" \ + "Waiting to get a signal\[\r\n\]+" # We should have both a signal handler and a call dummy frame # in this next output. @@ -96,15 +91,8 @@ mi_gdb_test "407-stack-list-frames" \ "list stack frames" -send_gdb "408-exec-continue\n" -gdb_expect { - -re "408\\^running\[\r\n\]+${my_mi_gdb_prompt}408\\\*stopped\[\r\n\]+${my_mi_gdb_prompt}$" { - pass "408-exec-continue" - } - timeout { - fail "408-exec-continue" - } -} +mi_gdb_test "408-exec-continue" \ + "408\\^running\[\r\n\]+${my_mi_gdb_prompt}408\\\*stopped" mi_gdb_test "409-stack-list-frames 0 0" \ "409\\^done,stack=\\\[frame=\{level=\"0\",addr=\"$hex\",func=\"main\",file=\".*mi-syn-frame.c\",fullname=\"${fullname_syntax}${srcfile}\",line=\"$decimal\"\}.*\\\]" \ @@ -114,7 +102,10 @@ mi_gdb_test "409-stack-list-frames 0 0" \ # Call bar() by hand, which should get an exception while running. # -mi_gdb_test "410-data-evaluate-expression bar()" "hi in bar\[\r\n\]+\\&\"The program being debugged was signaled while in a function called from GDB.\\\\n\"\[\r\n\]+\\&\"GDB remains in the frame where the signal was received.\\\\n\"\[\r\n\]+\\&\"To change this behavior use \\\\\"set unwindonsignal on\\\\\"\\\\n\"\[\r\n\]+\\&\"Evaluation of the expression containing the function \\(bar\\) will be abandoned.\\\\n\"\[\r\n\]+410\\^error,msg=\"The program being debugged was signaled while in a function called from GDB.\\\\nGDB remains in the frame where the signal was received.\\\\nTo change this behavior use \\\\\"set unwindonsignal on\\\\\"\\\\nEvaluation of the expression containing the function \\(bar\\) will be abandoned.\"" "call inferior function which raises exception" +mi_gdb_test "410-data-evaluate-expression bar()" \ + "\\&\"The program being debugged was signaled while in a function called from GDB.\\\\n\"\[\r\n\]+\\&\"GDB remains in the frame where the signal was received.\\\\n\"\[\r\n\]+\\&\"To change this behavior use \\\\\"set unwindonsignal on\\\\\"\\\\n\"\[\r\n\]+\\&\"Evaluation of the expression containing the function \\(bar\\) will be abandoned.\\\\n\"\[\r\n\]+410\\^error,msg=\"The program being debugged was signaled while in a function called from GDB.\\\\nGDB remains in the frame where the signal was received.\\\\nTo change this behavior use \\\\\"set unwindonsignal on\\\\\"\\\\nEvaluation of the expression containing the function \\(bar\\) will be abandoned.\"" \ + "call inferior function which raises exception" \ + "hi in bar\[\r\n\]+" mi_gdb_test "411-stack-list-frames" "411\\^done,stack=\\\[frame=\{level=\"0\",addr=\"$hex\",func=\"bar\",file=\".*mi-syn-frame.c\",fullname=\"${fullname_syntax}${srcfile}\",line=\"$decimal\"},frame=\{level=\"1\",addr=\"$hex\",func=\"\"\},frame=\{level=\"2\",addr=\"$hex\",func=\"main\",file=\".*mi-syn-frame.c\",fullname=\"${fullname_syntax}${srcfile}\",line=\"$decimal\"}.*\\\]" "backtrace from inferior function at exception" diff --git a/gdb/testsuite/lib/mi-support.exp b/gdb/testsuite/lib/mi-support.exp index da4fd34168..64f42b5f2e 100644 --- a/gdb/testsuite/lib/mi-support.exp +++ b/gdb/testsuite/lib/mi-support.exp @@ -28,6 +28,9 @@ if ![info exists mi_gdb_prompt] then { set mi_gdb_prompt "\[(\]gdb\[)\] \r\n" } +global mi_inferior_spawn_id +global mi_inferior_tty_name + set MIFLAGS "-i=mi" # @@ -81,13 +84,17 @@ proc mi_uncatched_gdb_exit {} { } # -# start gdb -- start gdb running, default procedure +# mi_gdb_start [INFERIOR_PTY] -- start gdb running, default procedure +# +# INFERIOR_PTY should be set to separate-inferior-tty to have the inferior work +# with it's own PTY. If set to same-inferior-tty, the inferior shares GDB's PTY. +# The default value is same-inferior-tty. # # When running over NFS, particularly if running many simultaneous # tests on different hosts all using the same server, things can # get really slow. Give gdb at least 3 minutes to start up. # -proc mi_gdb_start { } { +proc mi_gdb_start { args } { global verbose global GDB global GDBFLAGS @@ -98,6 +105,13 @@ proc mi_gdb_start { } { global MIFLAGS gdb_stop_suppressing_tests; + set inferior_pty no-tty + + if { [llength $args] == 1} { + set inferior_pty [lindex $args 0] + } + + set separate_inferior_pty [string match $inferior_pty separate-inferior-tty] # Start SID. if { [info procs sid_start] != "" } { @@ -117,6 +131,16 @@ proc mi_gdb_start { } { exit 1 } } + + # Create the new PTY for the inferior process. + if { $separate_inferior_pty } { + spawn -pty + global mi_inferior_spawn_id + global mi_inferior_tty_name + set mi_inferior_spawn_id $spawn_id + set mi_inferior_tty_name $spawn_out(slave,name) + } + set res [remote_spawn host "$GDB -nw $GDBFLAGS $MIFLAGS [host_info gdb_opts]"]; if { $res < 0 || $res == "" } { perror "Spawning $GDB failed." @@ -189,6 +213,19 @@ proc mi_gdb_start { } { warning "Couldn't set the width to 0." } } + # If allowing the inferior to have its own PTY then assign the inferior + # its own terminal device here. + if { $separate_inferior_pty } { + send_gdb "102-inferior-tty-set $mi_inferior_tty_name\n" + gdb_expect 10 { + -re ".*102\\\^done\r\n$mi_gdb_prompt$" { + verbose "redirect inferior output to new terminal device." + } + timeout { + warning "Couldn't redirect inferior output." 2 + } + } + } return 0; } @@ -511,7 +548,8 @@ proc mi_gdb_load { arg } { return 0 } -# mi_gdb_test COMMAND PATTERN MESSAGE -- send a command to gdb; test the result. +# mi_gdb_test COMMAND PATTERN MESSAGE [IPATTERN] -- send a command to gdb; +# test the result. # # COMMAND is the command to execute, send to GDB with send_gdb. If # this is the null string no command is sent. @@ -520,6 +558,9 @@ proc mi_gdb_load { arg } { # MESSAGE is the message to be printed. (If this is the empty string, # then sometimes we don't call pass or fail at all; I don't # understand this at all.) +# IPATTERN is the pattern to match for the inferior's output. This parameter +# is optional. If present, it will produce a PASS if the match is +# successful, and a FAIL if unsuccessful. # # Returns: # 1 if the test failed, @@ -536,6 +577,10 @@ proc mi_gdb_test { args } { set pattern [lindex $args 1] set message [lindex $args 2] + if [llength $args]==4 { + set ipattern [lindex $args 3] + } + if [llength $args]==5 { set question_string [lindex $args 3]; set response_string [lindex $args 4]; @@ -686,6 +731,23 @@ proc mi_gdb_test { args } { set result 1 } } + + # If the GDB output matched, compare the inferior output. + if { $result == 0 } { + if [ info exists ipattern ] { + global mi_inferior_spawn_id + expect { + -i $mi_inferior_spawn_id -re "$ipattern" { + pass "inferior_output:$message" + } + timeout { + fail "inferior output timeout" + set result 1 + } + } + } + } + return $result } -- 2.11.0