Re: [RFC/RFA] (testsuite/Ada) Add gdb_compile_ada

Joel Brobecker
2004-02-24T23:08:31Z

[-- Attachment #1: Type: text/plain, Size: 3753 bytes --]

Here is a new patch that takes into account the remarks I made
earlier:

- There is a problem with gdb_compile_ada. In Ada target_compile
always returns some output, so the current implementation thinks
the compilation fails, while it is not necessarily the case.
I changed the test to check for the dest file, rather than
analyzing the output.

Done.

- Object files are placed in the testsuite directory. I'd rather
see them being placed in gdb.ada.

I managed to do this, but I a not completely sure that it's such
a good idea after all. See patch below. On the one hand, the object
files et al are placed in gdb.ada rather than gdb/testsuite, but
on the other hand this has a slight impact in the debug info generated
by the compiler, since the source file name is no longer absolute.
So this change is not completely transparent for the debugger...
What do you think?

I am also copying my previous message, in case you would have some
comments about it as well.

On Tue, Feb 24, 2004 at 11:56:15AM -0800, Joel Brobecker wrote:
> Hmmm, dejagnu is still quite obscure for me, so I don't think I'll come
> up with the perfect universal solution to add support for Ada testcases
> right from the start... So instead I'll proceed tiny steps at a time...
>
> First step: Being able to build most Ada programs. Let's first restrict
> ourselves to Ada-only programs. Such a program necessarily have its
> main program written in Ada. With GNAT, this main program must be
> located in its own file. And to build the entire application, one
> usually does:
>
> % gnatmake -g <filename>
>
> where <filename> is the name of the file containing the main subprogram.
> The extension may be omitted. Dependencies are automatically handled
> by gnatmake.
>
> In this patch, I suggest we defined a new function gdb_compile_ada in
> lib/gdb.exp which will allow us to build Ada programs using the command
> above.
>
> I have a question: I am uncertain as to how cross targets are handled.
> Suppose we built a powerpc-elf debugger. How does the testsuite know
> which compiler to use. Does it have so machinery that will translate
> gcc into powerpc-elf-gcc by default? Would the same apply to gnatmake
> in gdb_compile_ada via target_compile?
>
> In the medium term, we will want to improve gdb_compile_ada to allow
> the testsuite to use different runtimes (we have sjlj exceptions vs
> ZCX exceptions, longcall vs no-longcall, shared vs static) or different
> options (we want to use -mieee on tru64 for instance). I believe this
> should be easily done via the options field.
>
> As for multilanguage examples, I'll leave that for later as well, but
> I don't think that would be too big a problem.

2004-02-24 J. Brobecker <brobecker@gnat.com>

* lib/gdb.exp (gdb_compile_ada): New function.

Tested on x86-linux using the following little dejagnu testcase:

if $tracelevel then {
strace $tracelevel
}

load_lib "ada.exp"

set testfile "null_record"
set srcfile ${testfile}.adb
set binfile ${objdir}/${subdir}/${testfile}

if {[gdb_compile_ada "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug ]] != "" } {
return -1
}

gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}

gdb_begin "" "Breakpoint \[0-9\]+ at .*null_record.adb.*"

gdb_test "ptype empty" \
"type = record null; end record" \
"ptype on null record"

The result are:

# of expected passes 2

Yay! :-)

Comments? Ok to apply?

--
Joel

[-- Attachment #2: gdb.exp.diff --]
[-- Type: text/plain, Size: 1543 bytes --]

Index: gdb.exp
===================================================================
RCS file: /nile.c/cvs/Dev/gdb/gdb-6.0/gdb/testsuite/lib/gdb.exp,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 gdb.exp
--- gdb.exp 5 Oct 2003 10:40:20 -0000 1.1.1.1
+++ gdb.exp 24 Feb 2004 23:07:52 -0000
@@ -1323,6 +1323,39 @@ proc gdb_compile_objc {source dest type
}
}

+#
+# Compile some Ada code.
+#
+proc gdb_compile_ada {source dest type options} {
+
+ lappend options "compiler=gnatmake"
+
+ # gnatmake leaves some compilation artifacts behind, such as
+ # .o or .ali files. We want them to be placed besides the dest
+ # file to avoid having them pollute the current directory. So
+ # we temporarily change directory while compiling.
+ #
+ # As a consequence, we need to adjust the source path to become
+ # absolute. Otherwise, the compiler will not find it. We assume
+ # that the dest path is already absolute.
+
+ regsub "^.*/" "$source" "" source_basename
+ set source_dirname [absolute [file dirname $source]]
+ set source $source_dirname/$source_basename
+
+ set cwd [pwd]
+ cd [file dirname $dest]
+ set result [target_compile $source $dest $type $options]
+ cd $cwd
+
+ # Make sure that the dest file has been created. Otherwise,
+ # the build has failed.
+ if ![file exists $dest] {
+ verbose "Ada compilation failed: $result"
+ return "Ada compilation failed."
+ }
+}
+
proc send_gdb { string } {
global suppress_flag;
if { $suppress_flag } {