From c6a0aacd51a4f5d72b46a313eba1789aedfc883e Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Tue, 27 May 2025 20:01:36 +0100 Subject: [PATCH 2/4] Testcase showing need for prompt anchor too Let's add some interspersed lines meant to be consumed by -lbl, an tag for when the built-in -lbl match triggers, and add anchors to the testcase's "prefix" matches. With that, the prefix matches no longer each too much, but the testcase now fails like so: (gdb) command prefix meant-to-be-matched-by-lbl-1 prefix foo prefix bar meant-to-be-matched-by-lbl-2 prefix prefix meant-to-be-matched-by-lbl-3 (gdb) PASS: gdb.testsuite/gdb-test-multiple.exp: command PASS: gdb.testsuite/gdb-test-multiple.exp: $saw_command == 1 PASS: gdb.testsuite/gdb-test-multiple.exp: $saw_prompt == 1 FAIL: gdb.testsuite/gdb-test-multiple.exp: $saw_prefix == 3 FAIL: gdb.testsuite/gdb-test-multiple.exp: $saw_prefix_foo == 1 FAIL: gdb.testsuite/gdb-test-multiple.exp: $saw_prefix_bar == 1 saw_prompt: 1 saw_prefix: 1 saw_prefix_foo: 0 saw_prefix_bar: 0 What happened was that expect managed to put all the output up to and including the prompt in the expect buffer, and since the testcase's prompt match does not have an ^\r\n anchor, the built-in prompt match consumed all the output in the expected buffer (since the previous match). Change-Id: Ib59084bad199f3fe945c14fbe1970e730104d3f4 --- gdb/testsuite/gdb.testsuite/gdb-test-multiple.exp | 8 ++++---- gdb/testsuite/gdb.testsuite/gdb.sh | 7 ++++--- gdb/testsuite/lib/gdb.exp | 1 + 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/gdb/testsuite/gdb.testsuite/gdb-test-multiple.exp b/gdb/testsuite/gdb.testsuite/gdb-test-multiple.exp index a1c9d95a71c..d593d5dc81a 100644 --- a/gdb/testsuite/gdb.testsuite/gdb-test-multiple.exp +++ b/gdb/testsuite/gdb.testsuite/gdb-test-multiple.exp @@ -8,22 +8,22 @@ set saw_prefix_foo 0 set saw_prefix_bar 0 gdb_test_multiple "command" "" -lbl { - -re "command(?=\r\n)" { + -re "^command(?=\r\n)" { verbose -log incr saw_command exp_continue } - -re "\r\nprefix foo(?=\r\n)" { + -re "^\r\nprefix foo(?=\r\n)" { verbose -log incr saw_prefix_foo exp_continue } - -re "\r\nprefix bar(?=\r\n)" { + -re "^\r\nprefix bar(?=\r\n)" { verbose -log incr saw_prefix_bar exp_continue } - -re "\r\nprefix (?=\r\n)" { + -re "^\r\nprefix (?=\r\n)" { verbose -log incr saw_prefix exp_continue diff --git a/gdb/testsuite/gdb.testsuite/gdb.sh b/gdb/testsuite/gdb.testsuite/gdb.sh index 1e9ceee8e23..55bd6473bf8 100755 --- a/gdb/testsuite/gdb.testsuite/gdb.sh +++ b/gdb/testsuite/gdb.testsuite/gdb.sh @@ -39,11 +39,12 @@ while true; do esac if [ "$line" = "command" ]; then echo "prefix " + echo "meant-to-be-matched-by-lbl-1" echo "prefix foo" echo "prefix bar" + echo "meant-to-be-matched-by-lbl-2" echo "prefix " - for n in $(seq 1 1); do - echo "meant-to-be-matched-by-lbl-$n" - done + echo "prefix " + echo "meant-to-be-matched-by-lbl-3" fi done diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index c51cea86a9d..3515d88bae5 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -1431,6 +1431,7 @@ proc gdb_test_multiple { command message args } { if {$line_by_line} { append code { -re "\r\n\[^\r\n\]*(?=\r\n)" { + verbose -log "" exp_continue } } -- 2.49.0