Re: Ada compile with -fvar-tracking

Carl Love
2023-11-15T23:00:17Z

Keith, Tom:

Well, fortunately debugging the expect script went fairly fast. I did
find the error. There are a million ways to shoot yourself in the foot
and I found yet another way... :-)

This is actually rather educational.

Starting with the patch...

--- a/gdb/testsuite/gdb.ada/finish-large.exp
+++ b/gdb/testsuite/gdb.ada/finish-large.exp
@@ -19,7 +19,9 @@ require allow_ada_tests

standard_ada_testfile p

-if {[gdb_compile_ada "${srcfile}" "${binfile}" executable debug] !=
""} {
+set flags {debug additional_flags=-cargs additional_flags=-fvar-
tracking additional_flags=-margs}
+
+if {[gdb_compile_ada "${srcfile}" "${binfile} " executable $flags] !=
""} {
return -1
}

If you notice in the new line we have "${binfile} ", notice the space
before the closing quote. That is the root cause of the compilation
failing!!

So looking at gdb/testsuite/lib/ada.exp we have

proc gdb_compile_ada {source dest type options} {
set result [gdb_compile_ada_1 $source $dest $type $options]

gdb_compile_test $source $result
return $result
}

Note, gdb_compile_test expects $result to be empty. If not it will be
interpreted as a compile failure.

So the second argument "${binfile} " is passed in as dest which is
passed to gdb_compile_ada_1. There is a very interesting comment at
the bottom of proc gdb_compile_ada_1.

proc gdb_compile_ada_1 {source dest type options} {

set srcdir [file dirname $source]
set gprdir [file dirname $srcdir]
set objdir [file dirname $dest]

file delete $dest

# Although strictly not necessary, we force the recompilation
# of all units (additional_flags=-f). This is what is done
# when using GCC to build programs in the other languages,
# and it avoids using a stray objfile file from a long-past
# run, for instance.
append options " ada"
if {[lsearch -exact $options no-force] == -1} {
append options " additional_flags=-f"
}
append options " additional_flags=-I$srcdir"

set result [target_compile_ada_from_dir \
$objdir [file tail $source] $dest $type $options]

# The Ada build always produces some output, even when the build
# succeeds. Thus, we can not use the output the same way we do in
# gdb_compile to determine whether the build has succeeded or not.
# We therefore simply check whether the dest file has been created
# or not. Unless not present, the build has succeeded.

puts "CARLL, dest = $dest.\n" ##Carl added this for debugging

if [file exists $dest] { set result "" }
return $result
}

So we have a test to see if file $dest exists or not. Well initially
with out my patch the value of $dest is printed by my debugging
statemet as

CARLL, dest = /home/carll/GDB/build-ada/gdb/testsuite/outputs/gdb.ada/finish-large/p.

The file exists so $result is cleared and gdb_compile_test sees and
empty and thus the compile succeeds.

However, that extra space in my patch file argument "${binfile} "
results in the value of $dest being:

CARLL, dest = /home/carll/GDB/build-ada/gdb/testsuite/outputs/gdb.ada/finish-large/p .

Again, note the space after p and before the period. Well the if [file
exists $dest] fails for this file name. Apparently it thinks the extra
space is a valid file name character so result is not cleared and
gdb_compile_test reports the compile failed.

So by removing that extra space in my original patch, the test now
compiles and passes since the DW_TAG_call_site information is available
so gdb can determine what the value of r3 was on entry to the test
program function.

Thanks to Tom for helping get the correct options passed to the ada
compiler to get the -fvar-tracking option to work. I am sure I didn't
have the additional arguments when I initially worked on this.

So, with the fixed patch test finish-large.exp works. There are a
couple other tests that I think will need the same fix to enable the
-fvar-tracking since the functions return a structure. Will have to
look at them next.

Thanks to both of you for your help with this.

Carl