Re: [PATCH] gdb/testsuite: fix gdb.base/dlmopen-ns-ids.exp racy test

Tom de Vries
2025-04-10T08:11:46Z

On 4/10/25 06:40, Tom de Vries wrote:
> On 4/9/25 20:25, Guinevere Larsen wrote:
>> * using exp_continue caused the value of ns to be overwritten, returning
>>    the last SO_NS, instead of the first
>
> Hi Gwen,
>
> my guess is that this is the right solution, and that you can just check
> for $ns == -1 to make sure only the first value is picked.

I tried this out, and got it working, after fixing the following.

There is a problem with the gdb_test_multiple.

It uses -lbl, which is the style of processing one line at a time, with
\r\n at the start, and (?=\r\n) at the end, which matches but not
consumes it (lookahead), always leaving an \r\n at the start of the next
line.

This matches what -wrap (which is based on gdb_test) does which requires
an \r\n before the prompt.

I got the test-case working using:
...
diff --git a/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp
b/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp
index 03b7a527af5..d3584a0a402 100644
--- a/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp
+++ b/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp
@@ -42,17 +42,17 @@ if { [build_executable "failed to build" $testfile
$srcfile \
proc get_first_so_ns {} {
set ns -1
gdb_test_multiple "info sharedlibrary" "get SO namespace" -lbl {
- -re "From\\s+To\\s+\(NS\\s+\)?Syms\\s+Read\\s+Shared Object Library\r\n" {
+ -re "\r\nFrom\\s+To\\s+\(NS\\s+\)?Syms\\s+Read\\s+Shared Object
Library(?=\r\n)" {
exp_continue
}
- -re
"^$::hex\\s+$::hex\\s+\\\[\\\[($::decimal)\\\]\\\]\\s+\[^\r\n]+$::binfile_lib.*"
{
- set ns $expect_out(1,string)
- }
- -re "^$::gdb_prompt $" {
- }
- -re "^\[^\r\n\]+\r\n" {
+ -re
"\r\n$::hex\\s+$::hex\\s+\\\[\\\[($::decimal)\\\]\\\]\\s+\[^\r\n]+${::binfile_lib}(?=\r\n
)" {
+ if { $ns == -1 } {
+ set ns $expect_out(1,string)
+ }
exp_continue
}
+ -re -wrap "" {
+ }
}
return $ns
}
...

I also think that binfile_lib needs to be wrapped in string_to_regexp.

Thanks,
- Tom