From 1411185a57ed246558f0f97d7faf0dc050de3708 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 26 Sep 2024 08:48:03 -0600 Subject: [PATCH] Introduce and use gnat_version_compare 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 --- gdb/testsuite/gdb.ada/array_of_variant.exp | 2 +- gdb/testsuite/gdb.ada/arrayidx.exp | 3 +-- gdb/testsuite/gdb.ada/arrayptr.exp | 2 +- gdb/testsuite/gdb.ada/big_packed_array.exp | 2 +- gdb/testsuite/gdb.ada/enum_idx_packed.exp | 5 +++-- gdb/testsuite/gdb.ada/fixed_points.exp | 4 ++-- gdb/testsuite/gdb.ada/fun_renaming.exp | 8 +++---- gdb/testsuite/gdb.ada/mod_from_name.exp | 5 +++-- gdb/testsuite/gdb.ada/null_array.exp | 3 +-- gdb/testsuite/gdb.ada/packed_array_assign.exp | 2 +- gdb/testsuite/gdb.ada/packed_record.exp | 2 +- gdb/testsuite/gdb.ada/pckd_arr_ren.exp | 5 +++-- .../gdb.ada/variant_record_packed_array.exp | 4 ++-- gdb/testsuite/lib/ada.exp | 12 +++++++++++ gdb/testsuite/lib/gdb-utils.exp | 21 +++++++++++++++++-- 15 files changed, 55 insertions(+), 25 deletions(-) diff --git a/gdb/testsuite/gdb.ada/array_of_variant.exp b/gdb/testsuite/gdb.ada/array_of_variant.exp index f93260af940..8b83f4ed22a 100644 --- a/gdb/testsuite/gdb.ada/array_of_variant.exp +++ b/gdb/testsuite/gdb.ada/array_of_variant.exp @@ -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 diff --git a/gdb/testsuite/gdb.ada/arrayidx.exp b/gdb/testsuite/gdb.ada/arrayidx.exp index 051e82d8539..bc76cd35639 100644 --- a/gdb/testsuite/gdb.ada/arrayidx.exp +++ b/gdb/testsuite/gdb.ada/arrayidx.exp @@ -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} diff --git a/gdb/testsuite/gdb.ada/arrayptr.exp b/gdb/testsuite/gdb.ada/arrayptr.exp index 335573b31a7..b8c2eab09c4 100644 --- a/gdb/testsuite/gdb.ada/arrayptr.exp +++ b/gdb/testsuite/gdb.ada/arrayptr.exp @@ -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 } diff --git a/gdb/testsuite/gdb.ada/big_packed_array.exp b/gdb/testsuite/gdb.ada/big_packed_array.exp index 0078c77de6a..33b1dfd7634 100644 --- a/gdb/testsuite/gdb.ada/big_packed_array.exp +++ b/gdb/testsuite/gdb.ada/big_packed_array.exp @@ -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 diff --git a/gdb/testsuite/gdb.ada/enum_idx_packed.exp b/gdb/testsuite/gdb.ada/enum_idx_packed.exp index d56d73bf9bc..cf70e9aea00 100644 --- a/gdb/testsuite/gdb.ada/enum_idx_packed.exp +++ b/gdb/testsuite/gdb.ada/enum_idx_packed.exp @@ -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 diff --git a/gdb/testsuite/gdb.ada/fixed_points.exp b/gdb/testsuite/gdb.ada/fixed_points.exp index ceed34acbc5..b2b3df4453f 100644 --- a/gdb/testsuite/gdb.ada/fixed_points.exp +++ b/gdb/testsuite/gdb.ada/fixed_points.exp @@ -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" } diff --git a/gdb/testsuite/gdb.ada/fun_renaming.exp b/gdb/testsuite/gdb.ada/fun_renaming.exp index 08c44b7df60..21f80db18a9 100644 --- a/gdb/testsuite/gdb.ada/fun_renaming.exp +++ b/gdb/testsuite/gdb.ada/fun_renaming.exp @@ -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 is not a structure or union type\\." { - if {[test_compiler_info {gcc-6*}]} { + if {[gnat_version_compare >= 6]} { fail $test } else { xfail $test diff --git a/gdb/testsuite/gdb.ada/mod_from_name.exp b/gdb/testsuite/gdb.ada/mod_from_name.exp index 33bd854d3ba..99effb012d9 100644 --- a/gdb/testsuite/gdb.ada/mod_from_name.exp +++ b/gdb/testsuite/gdb.ada/mod_from_name.exp @@ -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" \ diff --git a/gdb/testsuite/gdb.ada/null_array.exp b/gdb/testsuite/gdb.ada/null_array.exp index 4a04945c64b..7fa7c19fcb9 100644 --- a/gdb/testsuite/gdb.ada/null_array.exp +++ b/gdb/testsuite/gdb.ada/null_array.exp @@ -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 *-*-* } diff --git a/gdb/testsuite/gdb.ada/packed_array_assign.exp b/gdb/testsuite/gdb.ada/packed_array_assign.exp index ee2b395d2c1..47e48f96dcd 100644 --- a/gdb/testsuite/gdb.ada/packed_array_assign.exp +++ b/gdb/testsuite/gdb.ada/packed_array_assign.exp @@ -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))"] diff --git a/gdb/testsuite/gdb.ada/packed_record.exp b/gdb/testsuite/gdb.ada/packed_record.exp index bbba9b25c54..f3479530841 100644 --- a/gdb/testsuite/gdb.ada/packed_record.exp +++ b/gdb/testsuite/gdb.ada/packed_record.exp @@ -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 diff --git a/gdb/testsuite/gdb.ada/pckd_arr_ren.exp b/gdb/testsuite/gdb.ada/pckd_arr_ren.exp index 18bb84f848a..694cc231131 100644 --- a/gdb/testsuite/gdb.ada/pckd_arr_ren.exp +++ b/gdb/testsuite/gdb.ada/pckd_arr_ren.exp @@ -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" \ diff --git a/gdb/testsuite/gdb.ada/variant_record_packed_array.exp b/gdb/testsuite/gdb.ada/variant_record_packed_array.exp index 8f4192cfd49..22b67ccf2e0 100644 --- a/gdb/testsuite/gdb.ada/variant_record_packed_array.exp +++ b/gdb/testsuite/gdb.ada/variant_record_packed_array.exp @@ -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 diff --git a/gdb/testsuite/lib/ada.exp b/gdb/testsuite/lib/ada.exp index 0544544acbe..05151d3d8f1 100644 --- a/gdb/testsuite/lib/ada.exp +++ b/gdb/testsuite/lib/ada.exp @@ -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 } { diff --git a/gdb/testsuite/lib/gdb-utils.exp b/gdb/testsuite/lib/gdb-utils.exp index a1fdf7381a1..33b56fb3f99 100644 --- a/gdb/testsuite/lib/gdb-utils.exp +++ b/gdb/testsuite/lib/gdb-utils.exp @@ -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" } } -- 2.39.5