]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Introduce and use gnat_version_compare
authorTom Tromey <tromey@adacore.com>
Thu, 26 Sep 2024 14:48:03 +0000 (08:48 -0600)
committerTom Tromey <tromey@adacore.com>
Tue, 15 Oct 2024 19:36:29 +0000 (13:36 -0600)
While testing a modified GNAT, I found that this test in
fun_renaming.exp was returning 0 for GCC 13:

    if {[test_compiler_info {gcc-6*}]}

This patch introduces a new, more robust way to check the GNAT
compiler version, and changes the gda.ada tests to use it.  A small
update to version_compare was also needed.

Note that, in its current form, this new code won't really interact
well with non-GCC compilers (specifically gnat-llvm).  This doesn't
seem like a major issue at this point, though, because gnat-llvm
doesn't properly emit debuginfo yet, and when it does, more changes
will be needed in these tests anyway.

Reviewed-by: Keith Seitz <keiths@redhat.com>
15 files changed:
gdb/testsuite/gdb.ada/array_of_variant.exp
gdb/testsuite/gdb.ada/arrayidx.exp
gdb/testsuite/gdb.ada/arrayptr.exp
gdb/testsuite/gdb.ada/big_packed_array.exp
gdb/testsuite/gdb.ada/enum_idx_packed.exp
gdb/testsuite/gdb.ada/fixed_points.exp
gdb/testsuite/gdb.ada/fun_renaming.exp
gdb/testsuite/gdb.ada/mod_from_name.exp
gdb/testsuite/gdb.ada/null_array.exp
gdb/testsuite/gdb.ada/packed_array_assign.exp
gdb/testsuite/gdb.ada/packed_record.exp
gdb/testsuite/gdb.ada/pckd_arr_ren.exp
gdb/testsuite/gdb.ada/variant_record_packed_array.exp
gdb/testsuite/lib/ada.exp
gdb/testsuite/lib/gdb-utils.exp

index f93260af940f34afb88af60ca2aea2b475a118b8..8b83f4ed22adbc0bb06162348b7ba2e9fc6f2c51 100644 (file)
@@ -20,7 +20,7 @@ require allow_ada_tests
 
 standard_ada_testfile p
 
-set old_gcc [expr [test_compiler_info {gcc-[0-7]-*}]]
+set old_gcc [gnat_version_compare <= 7]
 
 proc gdb_test_with_xfail { cmd re re_xfail msg } {
     global scenario old_gcc
index 051e82d8539aacf1f50368c2027615282a699ac0..bc76cd35639933b414c3306590d4ba52d7a41712 100644 (file)
@@ -23,8 +23,7 @@ if {[gdb_compile_ada "${srcfile}" "${binfile}" executable {debug}] != ""} {
     return -1
 }
 
-set old_gcc [expr [test_compiler_info {gcc-[0-3]-*}] \
-            || [test_compiler_info {gcc-4-[0-6]-*}]]
+set old_gcc [gnat_version_compare <= {4 6}]
 
 clean_restart ${testfile}
 
index 335573b31a7979fd71c0db69061e012f041d4d80..b8c2eab09c4e43a72555b40916cc3f2696bed847 100644 (file)
@@ -55,7 +55,7 @@ foreach_gnat_encoding scenario flags {all minimal} {
 
     # GNAT >= 12.0 has the needed fix here.
     set xfail_expected 0
-    if {$scenario == "minimal" && ![test_compiler_info {gcc-1[2-9]-*}]} {
+    if {$scenario == "minimal" && [gnat_version_compare < 12]} {
        set xfail_expected 1
     }
 
index 0078c77de6af7e9a7eba485061bc6d737645a426..33b1dfd7634d3f256c589e9a23605cd1bfa61c48 100644 (file)
@@ -19,7 +19,7 @@ require allow_ada_tests
 
 standard_ada_testfile foo_ra24_010
 
-set old_gcc [expr [test_compiler_info {gcc-[0-8]-*}]]
+set old_gcc [gnat_version_compare < 9]
 
 foreach_gnat_encoding scenario flags {all minimal} {
     lappend flags debug
index d56d73bf9bc339d3ee8caf9d223bb0880a9f88de..cf70e9aea00959998197b24d63ef9d5297b7e0e4 100644 (file)
@@ -29,8 +29,9 @@ foreach_gnat_encoding scenario flags {all minimal} {
     clean_restart ${testfile}-${scenario}
 
     # GNAT 9 and 10 are known to fail.
-    if {$scenario == "minimal" && ([test_compiler_info {gcc-9-*}] \
-                                      || [test_compiler_info {gcc-10-*}])} {
+    if {$scenario == "minimal"
+       && [gnat_version_compare >= 9]
+       && [gnat_version_compare <= 10]} {
        set old_compiler 1
     } else {
        set old_compiler 0
index ceed34acbc536f03533f2349999c9d3c53098cd7..b2b3df4453f8faa4413159c8d27854b2bf41719c 100644 (file)
@@ -88,12 +88,12 @@ foreach_gnat_encoding scenario flags {all minimal} {
     gdb_test "print fp4_var / 1" $fp4
 
     # This only started working in GCC 11.
-    if {$scenario == "minimal" && [test_compiler_info {gcc-11-*}]} {
+    if {$scenario == "minimal" && [gnat_version_compare >= 11]} {
        gdb_test "print fp5_var" " = 3e-19"
     }
 
     # This failed before GCC 10.
-    if {$scenario == "all" && [test_compiler_info {gcc-10-*}]} {
+    if {$scenario == "all" && [gnat_version_compare < 10]} {
        gdb_test "p Float(Another_Fixed) = Float(Another_Delta * 5)" "true" \
            "value of another_fixed"
     }
index 08c44b7df60befb74f4451db846f6fe53e82c453..21f80db18a96056c4da29438e43b4d2d9d356f91 100644 (file)
@@ -41,7 +41,7 @@ gdb_test_multiple $test $test {
         pass $test
     }
     -wrap -re "No definition of \"fun_rename_test_n\" in current context\\." {
-        if {[test_compiler_info {gcc-6*}]} {
+       if {[gnat_version_compare >= 6]} {
             fail $test
         } else {
             xfail $test
@@ -55,7 +55,7 @@ gdb_test_multiple $test $test {
         pass $test
     }
     -wrap -re "No definition of \"renamed_fun_rename_test_next\" in current context\\." {
-        if {[test_compiler_info {gcc-6*}]} {
+       if {[gnat_version_compare >= 6]} {
             fail $test
         } else {
             xfail $test
@@ -69,14 +69,14 @@ gdb_test_multiple $test $test {
         pass $test
     }
     -wrap -re "No definition of \"pack\\.renamed_fun_rename_test_next\" in current context\\." {
-        if {[test_compiler_info {gcc-6*}]} {
+       if {[gnat_version_compare >= 6]} {
             fail $test
         } else {
             xfail $test
         }
     }
     -wrap -re "Type <data variable, no debug info> is not a structure or union type\\." {
-        if {[test_compiler_info {gcc-6*}]} {
+       if {[gnat_version_compare >= 6]} {
             fail $test
         } else {
             xfail $test
index 33bd854d3ba321ce8b3827032fc95a52f022601e..99effb012d9fd93b113abba02d7d29c655611f62 100644 (file)
@@ -34,8 +34,9 @@ foreach_gnat_encoding scenario flags {all minimal} {
     } 
 
     # GNAT 9 and 10 are known to fail.
-    if {$scenario == "minimal" && ([test_compiler_info {gcc-9-*}] \
-                                      || [test_compiler_info {gcc-10-*}])} {
+    if {$scenario == "minimal"
+       && [gnat_version_compare >= 9]
+       && [gnat_version_compare <= 10]} {
        setup_kfail "minimal encodings" *-*-*
     }
     gdb_test "print xp" \
index 4a04945c64b5cc69b76c939ebc074ca6c0adfc0e..7fa7c19fcb9873dfd207dead89119142a772deed 100644 (file)
@@ -28,8 +28,7 @@ clean_restart ${testfile}
 set bp_location [gdb_get_line_number "START" ${testdir}/foo.adb]
 runto "foo.adb:$bp_location"
 
-if {[test_compiler_info {gcc-[0-3]-*}]
-    || [test_compiler_info {gcc-4-[0-4]-*}]} {
+if {[gnat_version_compare <= 4.4]} {
     # Ada array bounds are missing in older GCCs.
     setup_xfail *-*-* 
 }
index ee2b395d2c1ac321067ff3e8eebeb23826037fec..47e48f96dcd0a61e5a40823c93561edb46ea18f3 100644 (file)
@@ -54,7 +54,7 @@ set re \
         "packed_array_assign_y => 1\\)\\)"]
 
 # GNAT >= 12.0 has the needed fix here.
-set zeros_expected [expr {![test_compiler_info {gcc-1[2-9]-*}]}]
+set zeros_expected [gnat_version_compare >= 12]
 set all_zeros \
     [string_to_regexp "((packed_array_assign_w => 0, packed_array_assign_x => 0, packed_array_assign_y => 0), (packed_array_assign_w => 0, packed_array_assign_x => 0, packed_array_assign_y => 0), (packed_array_assign_w => 0, packed_array_assign_x => 0, packed_array_assign_y => 0))"]
 
index bbba9b25c54a8e0169641ecfa2af5b5df7e1f58b..f347953084166f234e93d51e8072b7a7379fce1b 100644 (file)
@@ -38,7 +38,7 @@ foreach_gnat_encoding scenario flags {all minimal} {
        }
        -re " = .*more than max-value-size.*\[\r\n\]+$gdb_prompt $" {
            # GNAT >= 12.0 has the needed fix here.
-           if {$scenario == "minimal" && ![test_compiler_info {gcc-1[2-9]-*}]} {
+           if {$scenario == "minimal" && [gnat_version_compare >= 12]} {
                setup_kfail "minimal encodings" *-*-*
            }
            fail $test
index 18bb84f848a204ecaf75b96f040a69a6ab5222fd..694cc231131547c9453b4211905246b81fb004df 100644 (file)
@@ -32,8 +32,9 @@ foreach_gnat_encoding scenario flags {all minimal} {
     runto "foo.adb:$bp_location"
 
     # GNAT 9 and 10 are known to fail.
-    if {$scenario == "minimal" && ([test_compiler_info {gcc-9-*}] \
-                                      || [test_compiler_info {gcc-10-*}])} {
+    if {$scenario == "minimal"
+       && [gnat_version_compare >= 9]
+       && [gnat_version_compare <= 10]} {
        setup_kfail "minimal encodings" *-*-*
     }
     gdb_test "print A2" \
index 8f4192cfd4909263f49305b7a647e3f691aa9917..22b67ccf2e037442ade8b483e037251c8cc3abf3 100644 (file)
@@ -41,7 +41,7 @@ foreach_gnat_encoding scenario flags {all minimal} {
        }
        -re " = \\(size => 8, length => 8, buffer => warning: could not find bounds information on packed array.*$gdb_prompt $" {
            # GNAT >= 11.0 has the needed fix here.
-           if {$scenario == "minimal" && ![test_compiler_info {gcc-1[1-9]-*}]} {
+           if {$scenario == "minimal" && [gnat_version_compare >= 11]} {
                setup_kfail "minimal encodings" *-*-*
            }
            fail $test
@@ -62,7 +62,7 @@ foreach_gnat_encoding scenario flags {all minimal} {
        }
        -re " = \\(size => 8, length => 8, buffer => warning: could not find bounds information on packed array.*$gdb_prompt $" {
            # GNAT >= 11.0 has the needed fix here.
-           if {$scenario == "minimal" && ![test_compiler_info {gcc-1[1-9]-*}]} {
+           if {$scenario == "minimal" && [gnat_version_compare >= 11]} {
                setup_kfail "minimal encodings" *-*-*
            }
            fail $test
index 0544544acbe54589c836ca0ce8ddc9025c2817ae..05151d3d8f1bfb5db91c10434dfd4bff6f67a407 100644 (file)
@@ -188,6 +188,18 @@ proc gnatmake_version_at_least { major } {
     return 1
 }
 
+# Compare the GNAT version against L2 using version_compare.  If the
+# compiler does not appear to be GCC, this will always return false.
+
+proc gnat_version_compare {op l2} {
+    set gccvers [gcc_major_version]
+    if {$gccvers == -1} {
+       return 0
+    }
+
+    return [version_compare [split $gccvers .] $op $l2]
+}
+
 # Return 1 if the GNAT runtime appears to have debug info.
 
 proc gnat_runtime_has_debug_info_1 { shared } {
index a1fdf7381a152ab9abc0f8cf4f1e1c7c0235e22c..33b56fb3f99dcf1ba02d492d358ebd509cd85f9d 100644 (file)
@@ -111,14 +111,31 @@ proc gdb_get_bp_addr { num } {
 }
 
 # 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.
+# 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 } {
     switch -exact $op {
        "=="    -
        "<="    -
        "<"     {}
+
+       ">=" {
+           # a >= b => b <= a
+           set x $l2
+           set l2 $l1
+           set l1 $x
+           set op "<="
+       }
+
+       ">" {
+           # a > b => b < a
+           set x $l2
+           set l2 $l1
+           set l1 $x
+           set op "<"
+       }
+
        default { error "unsupported op: $op" }
     }