Skip to content

Commit

Permalink
Introduce ada_simple_compile
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tromey committed Mar 4, 2025
1 parent be382ec commit 6a509dd
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 11 deletions.
22 changes: 22 additions & 0 deletions gdb/testsuite/lib/ada.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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}]
}
45 changes: 34 additions & 11 deletions gdb/testsuite/lib/gdb.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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++.
Expand Down

0 comments on commit 6a509dd

Please sign in to comment.