diff --git a/gdb/testsuite/gdb.tui/tuiterm-2.exp b/gdb/testsuite/gdb.tui/tuiterm-2.exp index 599227123bc..becb65ac553 100644 --- a/gdb/testsuite/gdb.tui/tuiterm-2.exp +++ b/gdb/testsuite/gdb.tui/tuiterm-2.exp @@ -106,6 +106,48 @@ with_override Term::accept_gdb_output test_accept_gdb_output { } gdb_assert { [Term::wait_for ""] } } + + with_test_prefix "Term::wait_for 2" { + Term::_setup 4 20 + set send_cnt 0 + set expect_send {} + set action_cnt 0 + set actions { + { + Term::_move_cursor 0 0 + + Term::_insert "${::border}(gdb) " + set pos $Term::_cur_col + + Term::_insert "foo" + + Term::_move_cursor 19 0 + Term::_insert "$::border" + + Term::_move_cursor $pos 0 + } + { + Term::_move_cursor 0 1 + + Term::_insert "${::border}(gdb) " + set pos $Term::_cur_col + + Term::_move_cursor 19 1 + Term::_insert "$::border" + + Term::_move_cursor $pos 1 + } + } + + # Wait for a prompt. + gdb_assert { [Term::wait_for ""] } + + # The first action sets the cursor after the prompt on the + # first line. The second action sets the cursor after the + # prompt on the second line. Check that wait_for returns + # after the second action, not the first. + gdb_assert { $Term::_cur_row == 1 } + } } } } diff --git a/gdb/testsuite/lib/tuiterm.exp b/gdb/testsuite/lib/tuiterm.exp index f4a87023e2c..7b8745ab62b 100644 --- a/gdb/testsuite/lib/tuiterm.exp +++ b/gdb/testsuite/lib/tuiterm.exp @@ -864,16 +864,32 @@ namespace eval Term { } else { set prev [get_line $_cur_row] } - if {[regexp -- $wait_for $prev]} { - debug_tui_matching "$fn: match: '$prev'" - if {$wait_for == "$prompt_wait_for"} { - break - } - set wait_for $prompt_wait_for - debug_tui_matching "$fn: regexp prompt: '$wait_for'" - } else { + + if { ![regexp -- $wait_for $prev] } { debug_tui_matching "$fn: mismatch: '$prev'" + continue } + + if {$wait_for == "$prompt_wait_for"} { + # We've detected that the cursor is just after the prompt. + # Now check that there's nothing else on the line. + set prev [get_line $_cur_row] + if { ![regexp -- "(^|\\|)$gdb_prompt +($|\\||\\+)" $prev] } { + debug_tui_matching "$fn: mismatch: '$prev'" + continue + } + } + + debug_tui_matching "$fn: match: '$prev'" + + if {$wait_for == "$prompt_wait_for"} { + # Matched the prompt, we're done. + break + } + + # Now try to match the prompt. + set wait_for $prompt_wait_for + debug_tui_matching "$fn: regexp prompt: '$wait_for'" } return 1