]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/testsuite: remove trailing \r from rust_llvm_version result
authorAndrew Burgess <aburgess@redhat.com>
Fri, 31 May 2024 21:03:06 +0000 (22:03 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Wed, 5 Jun 2024 09:19:35 +0000 (10:19 +0100)
I noticed that the value returned by rust_llvm_version had a trailing
carriage return.  I don't think this is causing any problems right
now, but looking at the code I don't think this was the desired
behaviour.

The current code runs 'rustc --version --verbose', splits the output
at each '\n' and then loops over every line looking for the line that
contains the LLVM version.

There are two problems here.  First, at the end of each captured line
we have '\r\n', so when we split the lines on '\n', each of the lines
will still end with a '\r' character.

Second, though we loop over the lines, when we try to compare the line
contents we actually compare the unsplit full output.  Luckily this
still finds the match, but this renders the loop over lines redundant.

This commit makes two fixes:

 1. I use regsub to convert all '\r\n' sequences to '\n'; now when we
    split on '\n' the lines will not end in '\r'.

 2. Within the loop over lines block I now check the line contents
    rather than the unsplit full output; now we capture a value
    without a trailing '\r'.

There's only one test (gdb.rust/simple.exp) that uses
rust_llvm_version, and it doesn't care if there's a trailing '\r' or
not, so this change should make no difference there.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/testsuite/lib/rust-support.exp

index 6b3da2a69e40e44f6e9baa866da5b103a23893e2..971a4a6c29886712117643edc2a59bb3938d3a9b 100644 (file)
@@ -86,8 +86,9 @@ gdb_caching_proc rust_llvm_version {} {
        verbose "could not find rustc"
     } else {
        set output [lindex [remote_exec host "$rustc --version --verbose"] 1]
+       set output [regsub -all "\r\n" $output "\n"]
        foreach line [split $output \n] {
-           if {[regexp "LLVM version: (.+)\$" $output ignore version]} {
+           if {[regexp "LLVM version: (.+)\$" $line ignore version]} {
                return $version
            }
        }