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

Daniel Jacobowitz
2004-03-05T04:18:16Z

On Tue, Mar 02, 2004 at 08:21:07PM -0800, Joel Brobecker wrote:
> "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++.

OK; any interest in breaking out the language-independent bits of this
feature for review and discussion? While it's pretty uninteresting for
C/C++, it should work there. For Java and Fortran this could be
useful, since they also have the concept of a main program. At least
GCJ does, I'm not sure about Java in general.

By the way, there's a problem with gdb_begin: it can only be used once
because it counts as a PASS/FAIL with a specific hardcoded name. It
should either not be a test, or more likely, should have a unique name.
At that point, why have a procedure for it? You're just passing its
arguments to gdb_test.

> 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.

I'm perfectly happy with it in ada.exp. If we do that, let's put
gdb_compile_ada there also.

> - 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
> +}
> +
> >>

Looks plausible to me. Note, we could also put this in ada.exp. TCL
doesn't much care. But if you'll need changes to dejagnu anyway then
libgloss.exp is probably the right place; I hadn't noticed this next
bit:

> - 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] {

How would you feel about adaflags and adacompiler instead, for parallel
with the other languages? Maybe adaflags and gnatmake, since gnatmake
isn't strictly speaking the "compiler".

> @@ -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
> }
> }
> >>

Looks good... these bits will of course have to go to dejagnu@gnu.org
once you have something working. I'd prefer to find a way to bail out
gracefully if the host DejaGNU doesn't have them, too. We can use
[info proc find_gnatmake] for that, in gdb_compile_ada.

> 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.

Please mention explicitly that gnatmake produces output even if
successful.

> 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?

The test itself looks sane.

--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer