aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2023-03-14 07:51:45 -0600
committerTom Tromey <tromey@adacore.com>2023-03-29 10:13:12 -0600
commit1fa14231efd56ee77a9d8f66f741e285c0040839 (patch)
treee52dcc9c588d987430a1e7202b435703aad6183a
parent52fcd590bdabebf6cb4baa271cc1208f2541e6d4 (diff)
downloadbinutils-1fa14231efd56ee77a9d8f66f741e285c0040839.zip
binutils-1fa14231efd56ee77a9d8f66f741e285c0040839.tar.gz
binutils-1fa14231efd56ee77a9d8f66f741e285c0040839.tar.bz2
Rewrite version_compare and rust_at_least
This rewrites version_compare to allow the input lists to have different lengths, then rewrites rust_at_least to use version_compare.
-rw-r--r--gdb/testsuite/lib/gdb-utils.exp51
-rw-r--r--gdb/testsuite/lib/rust-support.exp22
2 files changed, 23 insertions, 50 deletions
diff --git a/gdb/testsuite/lib/gdb-utils.exp b/gdb/testsuite/lib/gdb-utils.exp
index fb5c953..a010e14 100644
--- a/gdb/testsuite/lib/gdb-utils.exp
+++ b/gdb/testsuite/lib/gdb-utils.exp
@@ -101,49 +101,40 @@ proc gdb_get_bp_addr { num } {
return ""
}
-# Compare the version numbers in L1 to those in L2 using OP, and return
-# 1 if the comparison is true.
+# Compare the version numbers in L1 to those in L2 using OP, and
+# return 1 if the comparison is true. OP can be "<", "<=", or "==".
+# It is ok if the lengths of the lists differ.
proc version_compare { l1 op l2 } {
- set len [llength $l1]
- if { $len != [llength $l2] } {
- error "l2 not the same length as l1"
- }
-
switch -exact $op {
"==" -
+ "<=" -
"<" {}
- "<=" { return [expr [version_compare $l1 < $l2] \
- || [version_compare $l1 == $l2]]}
default { error "unsupported op: $op" }
}
# Handle ops < and ==.
- set idx 0
- foreach v1 $l1 {
- set v2 [lindex $l2 $idx]
- incr idx
- set last [expr $len == $idx]
-
- set cmp [expr $v1 $op $v2]
- if { $op == "==" } {
- if { $cmp } {
- continue
- } else {
- return 0
- }
- } else {
- # $op == "<".
- if { $cmp } {
+ foreach v1 $l1 v2 $l2 {
+ if {$v1 == ""} {
+ # This is: "1.2 OP 1.2.1".
+ if {$op != "=="} {
return 1
- } else {
- if { !$last && $v1 == $v2 } {
- continue
- }
- return 0
}
+ return 0
}
+ if {$v2 == ""} {
+ # This is: "1.2.1 OP 1.2".
+ return 0
+ }
+ if {$v1 == $v2} {
+ continue
+ }
+ return [expr $v1 $op $v2]
}
+ if {$op == "<"} {
+ # They are equal.
+ return 0
+ }
return 1
}
diff --git a/gdb/testsuite/lib/rust-support.exp b/gdb/testsuite/lib/rust-support.exp
index 381871e..e9a3c5c 100644
--- a/gdb/testsuite/lib/rust-support.exp
+++ b/gdb/testsuite/lib/rust-support.exp
@@ -116,24 +116,6 @@ gdb_caching_proc rust_compiler_version {} {
# A helper that checks that the rust compiler is at least the given
# version. This is handy for use with 'require'.
proc rust_at_least {atleast} {
- foreach n1 [split [rust_compiler_version] .] n2 [split $atleast .] {
- if {$n1 == ""} {
- # Have 1.2, wanted 1.2.1.
- return 0
- }
- if {$n2 == ""} {
- # Have 1.2.1, wanted 1.2.
- return 1
- }
- if {$n1 > $n2} {
- # Have 1.3, wanted 1.2.
- return 1
- }
- if {$n1 < $n2} {
- # Have 1.1, wanted 1.2.
- return 0
- }
- }
- # Completely equal.
- return 1
+ return [version_compare [split $atleast .] \
+ <= [split [rust_compiler_version] .]]
}