]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Introduce ada_simple_compile
authorTom Tromey <tromey@adacore.com>
Wed, 12 Feb 2025 17:28:14 +0000 (10:28 -0700)
committerTom Tromey <tromey@adacore.com>
Tue, 4 Mar 2025 14:42:53 +0000 (07:42 -0700)
This introduces ada_simple_compile, an Ada-specific analog of
gdb_simple_compile.  gdb_compile_test is split into two procs to make
this possible.  ada_simple_compile isn't used in this patch but will
be by later patches in this series.

gdb/testsuite/lib/ada.exp
gdb/testsuite/lib/gdb.exp

index 83b419ae210c2ff6d6364a5139d2172681434a11..d9ecb60077e5552b8122245777823fb1170ceed8 100644 (file)
@@ -241,3 +241,25 @@ gdb_caching_proc gnat_runtime_has_debug_info {} {
 gdb_caching_proc shared_gnat_runtime_has_debug_info {} {
     return [gnat_runtime_has_debug_info_1 1]
 }
+
+# A helper that writes an Ada source file, then tries to compile it
+# with the given compiler options (a list like one accepted by
+# gdb_compile_ada).  Returns 1 if the flags are supported, 0
+# otherwise.
+proc ada_simple_compile {name options} {
+    set src [standard_temp_file $name.adb]
+    set dest [standard_temp_file $name.x]
+    set f [open $src w]
+    puts $f "procedure $name is"
+    puts $f "begin"
+    puts $f "  null;"
+    puts $f "end $name;"
+    close $f
+
+    # Note that we create an executable here.  For -fvar-tracking, at
+    # least, the option is supported and ignored by llvm-gnatmake --
+    # but then is passed to clang during further compilation, and this
+    # fails.  So to detect it we can't just stop with a .o file.
+    set output [gdb_compile_ada_1 $src $dest executable $options]
+    return [expr {[gdb_compile_test_nofail $output] == 1}]
+}
index 435a6f8404f2371f182ef60eb16564aeea54b524..481f9ecdf3d873c046b7ea3f360a11ae0ac02d01 100644 (file)
@@ -2639,6 +2639,35 @@ proc gdb_interact { } {
     }
 }
 
+# Examine the output of compilation to determine whether compilation
+# failed or not.  If it failed determine whether it is due to missing
+# compiler or due to compiler error.  Return 1 for pass, 0 for fail,
+# -1 for unsupported (missing compiler), and -2 for unsupported (bad
+# option) -- but do not issue a pass/fail directly.
+
+proc gdb_compile_test_nofail {output} {
+    if { $output == "" } {
+       return 1
+    }
+
+    if { [regexp {^[a-zA-Z_0-9]+: Can't find [^ ]+\.$} $output]
+        || [regexp {.*: command not found[\r|\n]*$} $output]
+        || [regexp {.*: [^\r\n]*compiler not installed[^\r\n]*[\r|\n]*$} $output] } {
+       return -1
+    }
+
+    set gcc_re ".*: error: unrecognized command line option "
+    set clang_re ".*: error: unsupported option "
+    if { [regexp "(?:$gcc_re|$clang_re)(\[^ \t;\r\n\]*)" $output dummy option]
+        && $option != "" } {
+       return -2
+    }
+
+    # Unclassified compilation failure, be more verbose.
+    verbose -log "compilation failed: $output" 2
+    return 0
+}
+
 # Examine the output of compilation to determine whether compilation
 # failed or not.  If it failed determine whether it is due to missing
 # compiler or due to compiler error.  Report pass, fail or unsupported
@@ -2647,29 +2676,23 @@ proc gdb_interact { } {
 proc gdb_compile_test {src output} {
     set msg "compilation [file tail $src]"
 
-    if { $output == "" } {
+    set result [gdb_compile_test_nofail $output]
+    if {$result == 1} {
        pass $msg
        return
     }
 
-    if { [regexp {^[a-zA-Z_0-9]+: Can't find [^ ]+\.$} $output]
-        || [regexp {.*: command not found[\r|\n]*$} $output]
-        || [regexp {.*: [^\r\n]*compiler not installed[^\r\n]*[\r|\n]*$} $output] } {
+    if {$result == -1} {
        unsupported "$msg (missing compiler)"
        return
     }
 
-    set gcc_re ".*: error: unrecognized command line option "
-    set clang_re ".*: error: unsupported option "
-    if { [regexp "(?:$gcc_re|$clang_re)(\[^ \t;\r\n\]*)" $output dummy option]
-        && $option != "" } {
+    if {$result == -2} {
        unsupported "$msg (unsupported option $option)"
        return
     }
 
-    # Unclassified compilation failure, be more verbose.
-    verbose -log "compilation failed: $output" 2
-    fail "$msg"
+    fail $msg
 }
 
 # Return a 1 for configurations for which we want to try to test C++.