[gdb/testsuite] Add string_list_to_regexp

A regexp pattern with escapes like this is hard to read:
...
set re "~\"\[$\]$decimal = 1\\\\n\"\r\n\\^done"
...

We can make it more readable by spacing out parts (which allows us to also use
the curly braces where that's convenient):
...
set re [list "~" {"} {[$]} $decimal " = 1" "\\\\" "n" {"} "\r\n" "\\^" "done"]
set re [join $re ""]
...
or by using string_to_regexp:
...
set re [list \
            [string_to_regexp {~"$}] \
            $decimal \
            [string_to_regexp " = 1\\n\"\r\n^done"]]
set re [join $re ""]
...
Note: we have to avoid applying string_to_list to decimal, which is already a
regexp.

Add a proc string_list_to_regexp to make it easy to do both:
...
set re [list \
            [string_list_to_regexp ~ {"} $] \
            $decimal \
            [string_list_to_regexp " = 1" \\ n {"} \r\n ^ done]]
...

Also add a test-case gdb.testsuite/string_to_regexp.exp.
2 files changed