Re: [PATCH v2 42/47] gdb_test_multiple: Anchor prompt match if -lbl

Pedro Alves
2025-05-27T22:42:08Z

[-- Attachment #1: Type: text/plain, Size: 4988 bytes --]

Hi!

On 2025-05-21 16:19, Tom de Vries wrote:
> On 5/19/25 15:23, Pedro Alves wrote:
>> I wrote a test like this:
>>
>>      gdb_test_multiple "command" "" -lbl {
>>         -re "^\r\nprefix foo(?=\r\n)" {
>>             exp_continue
>>         }
>>         -re "^\r\nprefix bar(?=\r\n)" {
>>             exp_continue
>>         }
>>         -re "^\r\prefix (?=\r\n)" {
>
> Hi Pedro,
>
> Missing n in "\r\n".
>
>>             exp_continue
>>         }
>>         -re "^\r\n$::gdb_prompt $" {
>>                pass $gdb_test_name
>>         }
>>      }
>>
>> Anchors are needed in my case to avoid too-eager matching due to the
>> common prefix.
> I'm not saying you don't need anchors, maybe you do or maybe you don't, but I don't understand how a common prefix is a reason to need one.
>
> Also, if you need anchors, you need to match the command as well, so you need a -re "^command(?=\r\n)" clause.

Without anchors, then if the fake GDB outputs this:

echo "prefix "
echo "prefix foo"
echo "prefix bar"
echo "prefix "

and the expect buffer happens to contain at least:

"prefix \r\nprefix foo\r\n"

... then the "prefix foo" pattern consumes the first "prefix " line inadvertently.

E.g., the version of the test that I'm attaching fails exactly like that, with:

(gdb) command
prefix
prefix foo
prefix bar
prefix
meant-to-be-matched-by-lbl-1
(gdb) <COMMAND>
<PREFIX-FOO>
<PREFIX-BAR>
<PREFIX>
<PROMPT>
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 == 2
PASS: gdb.testsuite/gdb-test-multiple.exp: $saw_prefix_foo == 1
PASS: gdb.testsuite/gdb-test-multiple.exp: $saw_prefix_bar == 1
saw_prompt: 1
saw_prefix: 1
saw_prefix_foo: 1
saw_prefix_bar: 1

This version is counting the matches, which notices that we only
saw "prefix" once, while we should have seen it twice.

That is patch #1 in the series I've attached.

>
>> The intent is for the prompt match above to override the built-in
>> prompt match.  However, it doesn't and the test fails with output like
>> this:
>>
>>    (gdb) command
>>    prefix foo
>>    prefix bar
>>    meant-to-be-matched-by-lbl
>>    (gdb)
>>
>> That's because the built-in match for the prompt matches before the
>> -lbl pattern for this expect buffer:
>>
>>    \r\nmeant-to-be-matched-by-lbl\r\n(gdb)
>>
>
> You can fix that by dropping the anchor and using "\r\n$::gdb_prompt $" instead.  Even more simple, use -wrap "".

That doesn't work properly. See the commit logs of the patches I've attached. The series is meant to show the
incremental results as we get to the final fully-passing testcase. One of the steps adds a prompt match like that,
and the slightly tweaked testcase in the same patch fails. Take a look at the commit logs of the patches, in
sequence, please. It is easier to see it incrementally like that, I think.

>
>> This this by anchoring the built-in prompt match if -lbl was
>> requested.
>>
>
> This might be a good idea indeed.
>
> FWIW, the intent of -lbl was to handle except buffers overflows, so the -lbl pattern is meant to match lines in absence of a prompt.

FYI, I needed this for an earlier version of the testcase in patch #44 of this series:

https://inbox.sourceware.org/gdb-patches/20250519132308.3553663-45-pedro@palves.net/T/#u

That is doing "info threads", and extracting the output of every thread. If you search
for ${common_prefix} in there, you'll find it.

I can't trigger the original issue with that version anymore without the gdb_test_multiple fix,
though, I think because the patterns in the current version consume all lines, so there's
no "meant-to-be-matched-by-lbl" anymore. I guess I don't really need -lbl there anymore at all.

Still, this new testcase based on what yours does need it. I can try to combine all of
this in a single patch, including the new testcase and a better description. WDYT?

This idea of replacing GDB with a script is super interesting. Did you consider writing that script
in tcl/expect, though? Seems like it would be a perfect fit. Read input, match against pattern, print
output. :-P Another alternative would be to write a bit of GDB python to register a new command, and
run the real GDB with that. But a script like you came up with mocking GDB completely is nice, it's
very light and more decoupled.

>
> But AFAIU, your patch will make matching more predictable, so that's a good thing.
>
> I created a mockup test-case to emulate the case you describe above. I've left the anchoring in place for the prefix lines, but for the gdb output printed by gdb.sh, it doesn't look necessary. [ The test-case has hardcoded paths in it. ]

[ The version I attached does not hardcode paths any more. ]

Thanks,
Pedro Alves

[-- Attachment #2: 0001-With-no-anchors-in-testcase-patterns-eat-too-much.patch --]
[-- Type: text/x-patch, Size: 7008 bytes --]

From c422a58d258e1a9a14a911c31a492b84518e300c Mon Sep 17 00:00:00 2001
From: Pedro Alves <pedro@palves.net>
Date: Tue, 27 May 2025 20:01:36 +0100
Subject: [PATCH 1/4] With no anchors in testcase, patterns eat too much

Without anchors, then if the fake GDB outputs this:

echo "prefix "
echo "prefix foo"
echo "prefix bar"
echo "prefix "

and the expect buffer happens to contain at least:

"prefix \r\nprefix foo\r\n"

... then the "prefix foo" pattern match may well consume the first "prefix " line.

Full relevant parts of the log:

(gdb) command
prefix
prefix foo
prefix bar
prefix
<COMMAND>
<PREFIX-FOO>
<PREFIX-BAR>
<PREFIX>
meant-to-be-matched-by-lbl-1
(gdb) <PROMPT>
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
PASS: gdb.testsuite/gdb-test-multiple.exp: $saw_prefix_foo == 1
PASS: gdb.testsuite/gdb-test-multiple.exp: $saw_prefix_bar == 1
saw_prompt: 1
saw_prefix: 1
saw_prefix_foo: 1
saw_prefix_bar: 1

Change-Id: Ib59084bad199f3fe945c14fbe1970e730104d3f4
---
.../gdb.testsuite/gdb-test-multiple.exp | 47 ++++++++++++++++++
gdb/testsuite/gdb.testsuite/gdb.sh | 49 +++++++++++++++++++
2 files changed, 96 insertions(+)
create mode 100644 gdb/testsuite/gdb.testsuite/gdb-test-multiple.exp
create mode 100755 gdb/testsuite/gdb.testsuite/gdb.sh

diff --git a/gdb/testsuite/gdb.testsuite/gdb-test-multiple.exp b/gdb/testsuite/gdb.testsuite/gdb-test-multiple.exp
new file mode 100644
index 00000000000..a1c9d95a71c
--- /dev/null
+++ b/gdb/testsuite/gdb.testsuite/gdb-test-multiple.exp
@@ -0,0 +1,47 @@
+set GDB $srcdir/$subdir/gdb.sh
+clean_restart
+
+set saw_prompt 0
+set saw_prefix 0
+set saw_command 0
+set saw_prefix_foo 0
+set saw_prefix_bar 0
+
+gdb_test_multiple "command" "" -lbl {
+ -re "command(?=\r\n)" {
+ verbose -log <COMMAND>
+ incr saw_command
+ exp_continue
+ }
+ -re "\r\nprefix foo(?=\r\n)" {
+ verbose -log <PREFIX-FOO>
+ incr saw_prefix_foo
+ exp_continue
+ }
+ -re "\r\nprefix bar(?=\r\n)" {
+ verbose -log <PREFIX-BAR>
+ incr saw_prefix_bar
+ exp_continue
+ }
+ -re "\r\nprefix (?=\r\n)" {
+ verbose -log <PREFIX>
+ incr saw_prefix
+ exp_continue
+ }
+ -re -wrap "" {
+ verbose -log "<PROMPT>"
+ incr saw_prompt
+ pass $gdb_test_name
+ }
+}
+
+gdb_assert {$saw_command == 1}
+gdb_assert {$saw_prompt == 1}
+gdb_assert {$saw_prefix == 3}
+gdb_assert {$saw_prefix_foo == 1}
+gdb_assert {$saw_prefix_bar == 1}
+
+verbose -log "saw_prompt: $saw_prompt"
+verbose -log "saw_prefix: $saw_prefix"
+verbose -log "saw_prefix_foo: $saw_prefix_foo"
+verbose -log "saw_prefix_bar: $saw_prefix_bar"
diff --git a/gdb/testsuite/gdb.testsuite/gdb.sh b/gdb/testsuite/gdb.testsuite/gdb.sh
new file mode 100755
index 00000000000..1e9ceee8e23
--- /dev/null
+++ b/gdb/testsuite/gdb.testsuite/gdb.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+
+while [ $# -gt 0 ]; do
+ case $1 in
+ --version)
+ echo "gdb.sh"
+ exit 0
+ ;;
+ *)
+ ;;
+ esac
+
+ shift
+done
+
+while true; do
+ echo -n "(gdb) "
+ read line
+
+ if [ "$line" = "set height 0" ]; then
+ continue
+ fi
+
+ if [ "$line" = "set width 0" ]; then
+ continue
+ fi
+
+ if [ "$line" = "dir" ]; then
+ echo -n "Reinitialize source path to empty? (y or n) "
+ read response
+ echo 'Source directories searched: $cdir:$cwd'
+ continue
+ fi
+ case "$line" in
+ dir\ */gdb/testsuite/gdb.testsuite)
+ echo "Source directories searched: ${line#dir }:\$cdir:\$cwd"
+ continue
+ ;;
+ esac
+ if [ "$line" = "command" ]; then
+ echo "prefix "
+ echo "prefix foo"
+ echo "prefix bar"
+ echo "prefix "
+ for n in $(seq 1 1); do
+ echo "meant-to-be-matched-by-lbl-$n"
+ done
+ fi
+done

base-commit: e1ec485cfa29f9c45370b9d0c12480ebb0a0be06
prerequisite-patch-id: 474281ed1de7dcad710a9f1415fe4866fe3e36cb
prerequisite-patch-id: db67eaaae54588f294023b4e09c2b07a2c11bfd0
prerequisite-patch-id: a222a1d72a184652ea37e9dd59e71ff17393ef19
prerequisite-patch-id: bfa3ae2badc22d752f6212df53e48d4bfb1efb6e
prerequisite-patch-id: 8b73964c2d816ebad0bfd0abb7601da7c81f466c
prerequisite-patch-id: b69ea29a21a9839f6e95f297466366237e6edbf1
prerequisite-patch-id: eb9f42ffabf999eedc30abd73e09cf3fd459ba91
prerequisite-patch-id: 8e06340fe19a29e06ffe8d90a9dd19795ce64e27
prerequisite-patch-id: 135991e668bb3fa937e744f3c07e63fa05e878dc
prerequisite-patch-id: 32acbb917d8f602933a20e38dea8b3987769e39f
prerequisite-patch-id: 46e4fac4e94089a99d11209b6ad630a806a2e4d3
prerequisite-patch-id: cbb2bb32051e83248c3825a961678ddc14e6c239
prerequisite-patch-id: e679fb7c98029f6b92b68777ec9a110fc75b593d
prerequisite-patch-id: ef122d379928672ae2fab1d7ee706b90c02c4750
prerequisite-patch-id: 65b0845df2d94f26861ee3357bab6ce92c96c25c
prerequisite-patch-id: a103df53b3ef1a97fdffd820b012bd1c72c82180
prerequisite-patch-id: bd527aeb586e434f7357e5a593bb8dba2cd0878c
prerequisite-patch-id: 832ccaad1c09afe161108daca97458d37bd67dc2
prerequisite-patch-id: 933ca66366195b76de3a95716fcd252e0ccc9ca2
prerequisite-patch-id: 2545f5482ce0a05046a100e3c6bf86f761a06a8d
prerequisite-patch-id: acc9895410e57a61f20c2fcd3d90afa9bd0a0270
prerequisite-patch-id: 783f3bb7bb51ed1edfe331f58f165c49bda913a2
prerequisite-patch-id: 3c6509d96965cb05c145d47e379dcf3de138296c
prerequisite-patch-id: 47c465a5027e5e3f1435868b86995162c3da3667
prerequisite-patch-id: ae032bc2dae31818bc1a3deb0896c896cb6f26f6
prerequisite-patch-id: 5d600a3390848d8f61694d2c54e452f18024c82c
prerequisite-patch-id: 7b0639be8b8cb109e7adc39d1c7cb62d9cd010f9
prerequisite-patch-id: 55c35cb6d45485452f8ceef9cd89de133d8b06ef
prerequisite-patch-id: fdd325cf0e778f4002b70fdfe2750056fd19f183
prerequisite-patch-id: 9c91a5ecdf8cc2a65b44b00605e5ae3b657fd8d6
prerequisite-patch-id: 4af4e9882c7fd57c12179acaac1cae06771840ba
prerequisite-patch-id: 95bd3ddc6c3d9f67601a936bb7ee54611c50eefa
prerequisite-patch-id: 574177f4d00b4112cb32b16d946786fb85fce03e
prerequisite-patch-id: de0addc21c3c5b69f8f2a7bdf6ce40895be33e99
prerequisite-patch-id: 52ec46c9db5b40182ac5594e27c57f967cfff534
prerequisite-patch-id: f0448115f10b26fa6bfdc05f27054b1d1a2eeaca
prerequisite-patch-id: 308662b1ecab531416d03772e121ad70f530fd2e
prerequisite-patch-id: 0dd3962a60a8455b3f29d2be874f89b22613c6e2
prerequisite-patch-id: b1db95b11d47464a51f4dd9341305a1fefbe261a
prerequisite-patch-id: 8e472ea6227d5fe8cfb278475eba364ab349c921
prerequisite-patch-id: 4b0e0479048fa69b9236726c31d4d3a1c4eb8d25
prerequisite-patch-id: 385c15c31aa8164af6d45e1a667448ae34a33eab
prerequisite-patch-id: 54baec47a1e16993889d013307fa76712e1c70fd
prerequisite-patch-id: cb790ccd633dcd7c802038eddf8ee41aa45b91a3
prerequisite-patch-id: 49703c9edd4a081dc8287e87ac0c6badb762e147
prerequisite-patch-id: 72d1db10cd1fa53fe070141bcfbe084d201b96e3
prerequisite-patch-id: 2245f4e6ca9330f3eb216d32e413d7079f3ae1c2
prerequisite-patch-id: 9e823607f8c00be8d064a1206f6f5d3fa996322a
--
2.49.0

[-- Attachment #3: 0002-Testcase-showing-need-for-prompt-anchor-too.patch --]
[-- Type: text/x-patch, Size: 3588 bytes --]

From c6a0aacd51a4f5d72b46a313eba1789aedfc883e Mon Sep 17 00:00:00 2001
From: Pedro Alves <pedro@palves.net>
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
<LBL> 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) <COMMAND>
<PREFIX>
<PROMPT>
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
<PREFIX> 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 <COMMAND>
incr saw_command
exp_continue
}
- -re "\r\nprefix foo(?=\r\n)" {
+ -re "^\r\nprefix foo(?=\r\n)" {
verbose -log <PREFIX-FOO>
incr saw_prefix_foo
exp_continue
}
- -re "\r\nprefix bar(?=\r\n)" {
+ -re "^\r\nprefix bar(?=\r\n)" {
verbose -log <PREFIX-BAR>
incr saw_prefix_bar
exp_continue
}
- -re "\r\nprefix (?=\r\n)" {
+ -re "^\r\nprefix (?=\r\n)" {
verbose -log <PREFIX>
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 "<LBL>"
exp_continue
}
}
--
2.49.0

[-- Attachment #4: 0003-Anchor-prompt-in-testcase.patch --]
[-- Type: text/x-patch, Size: 2151 bytes --]

From 7579b5e08a4d1a0370a5551353e782da15dd936c Mon Sep 17 00:00:00 2001
From: Pedro Alves <pedro@palves.net>
Date: Tue, 27 May 2025 22:46:40 +0100
Subject: [PATCH 3/4] Anchor prompt in testcase

If we anchor the prompt in the testcase, so that it doesn't consume
too much, we now see:

(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) <COMMAND>
<PREFIX>
<BUILT-IN PROMPT>
FAIL: gdb.testsuite/gdb-test-multiple.exp: command
PASS: gdb.testsuite/gdb-test-multiple.exp: $saw_command == 1
FAIL: 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: 0
saw_prefix: 1
saw_prefix_foo: 0
saw_prefix_bar: 0

I.e., the built-in prompt match was not overriden, and that one
consumed too much output, like in the previous patch our prompt match
did.

Change-Id: Id0080b6b04450d6eb5043d682efdbbd67b4139b4
---
gdb/testsuite/gdb.testsuite/gdb-test-multiple.exp | 2 +-
gdb/testsuite/lib/gdb.exp | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/gdb/testsuite/gdb.testsuite/gdb-test-multiple.exp b/gdb/testsuite/gdb.testsuite/gdb-test-multiple.exp
index d593d5dc81a..f6f254ddf8f 100644
--- a/gdb/testsuite/gdb.testsuite/gdb-test-multiple.exp
+++ b/gdb/testsuite/gdb.testsuite/gdb-test-multiple.exp
@@ -28,7 +28,7 @@ gdb_test_multiple "command" "" -lbl {
incr saw_prefix
exp_continue
}
- -re -wrap "" {
+ -re "^\r\n$gdb_prompt $" {
verbose -log "<PROMPT>"
incr saw_prompt
pass $gdb_test_name
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 3515d88bae5..cd920d2624c 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -1392,6 +1392,7 @@ proc gdb_test_multiple { command message args } {
set result -1
}
-re "\r\n$prompt_regexp" {
+ verbose -log "<BUILT-IN PROMPT>"
if {![string match "" $message]} {
fail "$message"
}
--
2.49.0

[-- Attachment #5: 0004-gdb_test_multiple-Anchor-prompt-match-if-lbl.patch --]
[-- Type: text/x-patch, Size: 2255 bytes --]

From 05f32b5c30d52bd46dc671e923c38becdf7227b5 Mon Sep 17 00:00:00 2001
From: Pedro Alves <pedro@palves.net>
Date: Thu, 17 Apr 2025 22:55:25 +0100
Subject: [PATCH 4/4] gdb_test_multiple: Anchor prompt match if -lbl

This is the original patch (rebased on the <BUILT-IN PROMPT> thingy).

If we make the built-in prompt have an anchor as well, then it won't
match prematurely, and our own prompt match overrides it. So now we
get a clean pass:

(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) <COMMAND>
<PREFIX>
<LBL>
<PREFIX-FOO>
<PREFIX-BAR>
<LBL>
<PREFIX>
<PREFIX>
<LBL>
<PROMPT>
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
PASS: gdb.testsuite/gdb-test-multiple.exp: $saw_prefix == 3
PASS: gdb.testsuite/gdb-test-multiple.exp: $saw_prefix_foo == 1
PASS: gdb.testsuite/gdb-test-multiple.exp: $saw_prefix_bar == 1
saw_prompt: 1
saw_prefix: 3
saw_prefix_foo: 1
saw_prefix_bar: 1

Change-Id: Ic2571ec793d856a89ee0d533ec363e2ac6036ea2
---
gdb/testsuite/lib/gdb.exp | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index cd920d2624c..6e97d7a35d9 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -1124,6 +1124,7 @@ proc gdb_test_multiple { command message args } {
global any_spawn_id

set line_by_line 0
+ set lbl_anchor_re ""
set prompt_regexp ""
set prompt_anchor 1
for {set i 0} {$i < [llength $args]} {incr i} {
@@ -1133,6 +1134,7 @@ proc gdb_test_multiple { command message args } {
set prompt_regexp [lindex $args $i]
} elseif { $arg == "-lbl" } {
set line_by_line 1
+ set lbl_anchor_re "^"
} elseif { $arg == "-no-prompt-anchor" } {
set prompt_anchor 0
} else {
@@ -1391,7 +1393,7 @@ proc gdb_test_multiple { command message args } {
fail "$errmsg"
set result -1
}
- -re "\r\n$prompt_regexp" {
+ -re "${lbl_anchor_re}\r\n$prompt_regexp" {
verbose -log "<BUILT-IN PROMPT>"
if {![string match "" $message]} {
fail "$message"
--
2.49.0