--- gdb/testsuite/lib/mi-support.exp (revision 3040) +++ gdb/testsuite/lib/mi-support.exp (local) @@ -822,7 +822,7 @@ proc mi_run_cmd {args} { return } } - # NOTE: Shortly after this there will be a ``000*stopping,...(gdb)'' + # NOTE: Shortly after this there will be a ``000*stopped,...(gdb)'' } # @@ -1188,32 +1188,65 @@ proc mi_get_inline_test {testcase} { return $result } -# Helper to mi_run_inline_test below. -# Sets a temporary breakpoint at LOCATION and runs -# the program using COMMAND. When the program is stopped -# returns the line at which it. Returns -1 if line cannot -# be determined. -# Does not check that the line is the same as requested. -# The caller can check itself if required. -proc mi_run_to_line {location command} { +# Sets temporary breakpoint at LOCATION. +proc mi_tbreak {location} { global mi_gdb_prompt mi_gdb_test "-break-insert -t $location" \ {\^done,bkpt=.*} \ - "run to $location (set breakpoint)" - + "run to $location (set breakpoint)" +} + +# Send COMMAND that must be a command that resumes +# the inferiour (run/continue/next/etc) and consumes +# the "^running" output from it. +proc mi_send_resuming_command {command test} { + + global mi_gdb_prompt + send_gdb "220-$command\n" gdb_expect { - -re "220\\^running\r\n${mi_gdb_prompt}.*line=\"(.*)\".*\r\n$mi_gdb_prompt$" { - return $expect_out(1,string) + -re "220\\^running\r\n${mi_gdb_prompt}" { } timeout { - return -1 + fail $test } } } +# Helper to mi_run_inline_test below. +# Sets a temporary breakpoint at LOCATION and runs +# the program using COMMAND. When the program is stopped +# returns the line at which it. Returns -1 if line cannot +# be determined. +# Does not check that the line is the same as requested. +# The caller can check itself if required. +proc mi_run_to_line {location command} { + + mi_tbreak $location + mi_send_resuming_command $command "run to $location ($command)" + return [mi_wait_for_stop] +} + +# Wait until gdb prints the current line. +proc mi_wait_for_stop {test} { + + global mi_gdb_prompt + + gdb_expect { + -re ".*line=\"(.*)\".*\r\n$mi_gdb_prompt$" { + return $expect_out(1,string) + } + -re ".*$mi_gdb_prompt$" { + fail "wait for stop ($test)" + } + timeout { + fail "wait for stop ($test)" + } + } +} + # Run a MI test embedded in comments in a C file. # The C file should contain special comments in the following # three forms: @@ -1272,8 +1305,9 @@ proc mi_run_inline_test { testcase } { if {$first==1} { # Start the program afresh. - set line_now [mi_run_to_line "$mi_autotest_source:$line"\ - "exec-run"] + mi_tbreak "$mi_autotest_source:$line" + mi_run_cmd + set line_now [mi_wait_for_stop "$testcase: step to $line"] set first 0 } elseif {$line_now!=$line} { set line_now [mi_run_to_line "$mi_autotest_source:$line"\ @@ -1281,7 +1315,7 @@ proc mi_run_inline_test { testcase } { } if {$line_now!=$line} { - fail "$testcase: step to line $line" + fail "$testcase: go to line $line" } # We're not at the statement right above the comment. @@ -1289,16 +1323,9 @@ proc mi_run_inline_test { testcase } { # the state after the statement is executed. # Single-step past the line. - send_gdb "220-exec-next\n" - gdb_expect { - -re "220\\^running\r\n${mi_gdb_prompt}.*line=\"(.*)\".*\r\n$mi_gdb_prompt$" { - set line_now $expect_out(1,string) - pass "$testcase: step over line $line" - } - timeout { - fail "$testcase: step over line $line" - } - } + mi_send_resuming_command "exec-next" "$testcase: step over $line" + set line_now [mi_wait_for_stop "$testcase: step over $line"] + # We probably want to use 'uplevel' so that statements # have direct access to global variables that the # main 'exp' file has set up. But it's not yet clear,