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)" {
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.
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)
This this by anchoring the built-in prompt match if -lbl was
requested.
Change-Id: Ic2571ec793d856a89ee0d533ec363e2ac6036ea2
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} {
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 {
fail "$errmsg"
set result -1
}
- -re "\r\n$prompt_regexp" {
+ -re "${lbl_anchor_re}\r\n$prompt_regexp" {
if {![string match "" $message]} {
fail "$message"
}