From: Tom Tromey Date: Wed, 12 Feb 2025 17:28:14 +0000 (-0700) Subject: Introduce ada_simple_compile X-Git-Tag: binutils-2_45~1400 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6a509dd70f0c4c124147eac4b58e15e94b34e5fd;p=thirdparty%2Fbinutils-gdb.git Introduce ada_simple_compile 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. --- diff --git a/gdb/testsuite/lib/ada.exp b/gdb/testsuite/lib/ada.exp index 83b419ae210..d9ecb60077e 100644 --- a/gdb/testsuite/lib/ada.exp +++ b/gdb/testsuite/lib/ada.exp @@ -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}] +} diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 435a6f8404f..481f9ecdf3d 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -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++.