[PATCH] [gdb/testsuite] Fix gdb.python/py-selected-context.exp regexp
Tom de Vries <[email protected]> Mon, 3 Aug 2026 10:07:21 +0200
| Newsgroups | gmane.comp.gdb.patches |
|---|---|
| Message-ID | <[email protected]> |
On ppc64-linux, with test-case gdb.python/py-selected-context.exp I run into:
...
(gdb) info inferiors^M
Num Description Connection Executable ^M
1 <null> ^M
* 2 <null> ^M
(gdb) FAIL: $exp: check inferior 2 was selected
...
In contrast, on x86_64-linux, I get:
...
(gdb) info inferiors^M
Num Description Connection Executable ^M
1 <null> ^M
* 2 <null> ^M
(gdb) PASS: $exp: check inferior 2 was selected
...
The output is identical, so it's surprising that there's a different
outcome.
The proc doing the check is:
...
proc check_inferior { inf testname } {
gdb_test "info inferiors" \
"\r\n\\*\\s+[string_to_regexp $inf]\\s+\[^\r\n\]*(?=\r\n)" \
$testname
}
...
The problem seems to be triggered by the lookahead part '(?=\r\n)': removing
it makes the test pass.
By switching on some debugging in gdb_test_multiple, we get this info:
...
Looking to match ""(?:\r\n\*\s+2\s+[^\r\n]*(?=\r\n))\r\n\(gdb\) $""
...
which shows that the lookahead '(?=\r\n)' is immediately followed by a '\r\n',
making the lookahead superfluous.
Still, the test should not fail. This may be an expect bug, or a
miscompilation of expect. I've filed a testsuite PR [1] about it for further
investigation.
But, there's another problem with the regexp.
If we use the same proc to try to match inferior 1, we get a FAIL on both
setups:
...
(gdb) info inferiors^M
Num Description Connection Executable ^M
* 1 <null> ^M
2 <null> ^M
(gdb) FAIL: $exp: check inferior 1 was selected
...
The problem is that the regexp doesn't allow a line after the matching line.
Fix this this by appending '.*' to the regexp.
Doing so also has the effect that we no longer run into the expect problem.
While we're at it, rewrite the regexp to a more modern form, and drop the
unnecessary string_to_regexp:
...
[multi_line \
"" \
[subst_vars {[*]\s+$inf\s+[^\r\n]*(?=\r\n).*}]]
...
Tested on x86_64-linux and ppc64-linux.
[1] https://sourceware.org/pipermail/gdb-prs/2026q3/047709.html
---
gdb/testsuite/gdb.python/py-selected-context.exp | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/gdb/testsuite/gdb.python/py-selected-context.exp b/gdb/testsuite/gdb.python/py-selected-context.exp
index 28b9b456003..07ace151f26 100644
--- a/gdb/testsuite/gdb.python/py-selected-context.exp
+++ b/gdb/testsuite/gdb.python/py-selected-context.exp
@@ -46,7 +46,9 @@ proc event_regexp { inferior {thread "None"} {frame "None"}} {
# inferior. INF should be an inferior number, e.g. '1', '2', etc.
proc check_inferior { inf testname } {
gdb_test "info inferiors" \
- "\r\n\\*\\s+[string_to_regexp $inf]\\s+\[^\r\n\]*(?=\r\n)" \
+ [multi_line \
+ "" \
+ [subst_vars {[*]\s+$inf\s+[^\r\n]*(?=\r\n).*}]] \
$testname
}
base-commit: dde72c6764ecdd5a6af7295c1087c87bbaa7cfec
--
2.51.0