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

Guinevere Larsen
2025-04-10T12:43:57Z

On 4/10/25 5:11 AM, Tom de Vries wrote:
> 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
>  }
> ...
>
Ah, ok. I guess there's quite a bit I still need to learn about -lbl.

I was thinking that this could be quite a bit slower, but I noticed that
this also fixes issues with using the lib name in the "info
sharedlibrary" command, so I'll add this to a v2

> I also think that binfile_lib needs to be wrapped in string_to_regexp.
Will also do this for v2.

--
Cheers,
Guinevere Larsen
She/Her/Hers

>
> Thanks,
> - Tom
>