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

Joel Brobecker
2004-03-03T04:21:07Z

Hello Daniel,

I think I am starting to slooooowly understand how this is all supposed
to work. Would you mind reviewing what I have done so far, though, to
see if I am heading in the right direction. I modified some files in
dejagnu (used the CVS version from src), modified gdb.exp in gdb/.../lib,
and added some others.

First, some answers to your previous questions:

> > gnatmake will. For instance gnatmake won't recompile the test programs
> > on subsequent runs, unless the sources have changes. Or if we have two
> > test programs depending on the same unit, this unit will only be compiled
> > once. I think we should keep them, they are useful.
>
> Well, I'm not so sure that qualifies as useful for the testsuite, but
> if they go into gdb.ada I don't care :)

Great :)

> > proc gdb_begin {args expected_output} {
> > gdb_test "begin $args" "$expected_output" "begin command"
> > }
>
> What's begin do again in your sources? Also, I'm not sure about the
> need for an ada.exp; what else do you expet to go here?

"begin" is the Ada equivalent of the "break main; run" sequence in
C. Basically, the main function in Ada is not necessarily called main.
In fact, it is almost always never called main. The "begin" command
digs into an Ada executable, finds the function name of the main
routine, puts a temporary breakpoint inside it, and then "run".

proc "gdb_begin" is designed to be the equivalent of "runto_main"
for C and C++.

So far, I don't anticipate anything else in ada.exp, but my little
finger tells me that we will likely need something else one day which
will fit perfectly into that file. Perhaps even our new gdb_compile_ada
procedure should be placed into this file? I am perfectly happy to put
this proc in gdb.exp, however, and drop the idea of a new ada.exp file.

> Aye. You can put find_gnatmake in gdb.exp for now and submit it to
> dejagnu later.
>
> The basic goals of the function are:
> - Find an in-tree gnatmake and pass it appropriate options to run
> from in-tree, for testing a combined tree.
> - Use [transform], which will supply the appropriate cross prefixes.

OK, here is how I understand thigs should be implemented to add support
for Ada.

- In libgloss.exp, I need to add a new function "find_gnatmake"

<<
+proc find_gnatmake {} {
+ global tool_root_dir
+
+ set root "$tool_root_dir/gcc"
+ set GM ""
+
+ if ![is_remote host] {
+ set file [lookfor_file $root gnatmake]
+ if { $file != "" } {
+ set GM "$file -I$root/ada/rts --GCC=$root/xgcc --GNATBIND=$root/gnatbind --GNATLINK=$root/gnatlink -cargs -B$root -largs --GCC=$root/xgcc -margs";
+ }
+ }
+
+ if {$GM == ""} {
+ set GM [transform gnatmake]
+ }
+
+ return $GM
+}
+
>>

- In target.exp (default_target_compile): I need to add handling of
Ada sources via the "ada" option keyword:

<<
@@ -333,6 +333,19 @@ proc default_target_compile {source dest
}

foreach i $options {
+ if { $i == "ada" } {
+ set compiler_type "ada"
+ if [board_info $dest exists gnatmakeflags] {
+ append add_flags " [target_info gnatmakeflags]"
+ }
+ # append add_flags " [gnatmake_include_flags]";
+ if [board_info $dest exists gnatmakecompiler] {
+ set compiler [target_info gnatmakecompiler];
+ } else {
+ set compiler [find_gnatmake];
+ }
+ }
+
if { $i == "c++" } {
set compiler_type "c++"
if [board_info $dest exists cxxflags] {
@@ -412,6 +425,7 @@ proc default_target_compile {source dest
global CC_FOR_TARGET
global CXX_FOR_TARGET
global F77_FOR_TARGET
+ global GNATMAKE_FOR_TARGET

if [info exists CC_FOR_TARGET] {
if { $compiler == "" } {
@@ -428,6 +442,12 @@ proc default_target_compile {source dest
if [info exists F77_FOR_TARGET] {
if { $compiler_type == "f77" } {
set compiler $F77_FOR_TARGET
+ }
+ }
+
+ if [info exists GNATMAKE_FOR_TARGET] {
+ if { $compiler_type == "ada" } {
+ set compiler $GNATMAKE_FOR_TARGET
}
}
>>

Then my new gdb_compile_ada function in gdb.exp simply becomes:

<<
proc gdb_compile_ada {source dest objdir type options} {

append options " ada"
append options " additional_flags=-P${objdir}/gnat_ada"

set result [target_compile $source $dest $type $options]

# 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."
}
}
>>

And a simple testcase checking the null record problem is gone:

<<
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 "${srcfile}" "${binfile}" "${objdir}/${subdir}" 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"
>>

What do you think?

Thanks a lot for you help, Daniel,
--
Joel