Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH][gdb/testsuite] Handle ada in gdb_compile_shlib
Date: Mon, 7 Dec 2020 13:19:43 +0100	[thread overview]
Message-ID: <20201207121942.GA14289@delia> (raw)

Hi,

The single test-case in the testsuite that creates an ada shared library is
gdb.ada/catch_ex_std.exp.

The test-case does use gdb_compile_shlib, but with a few tweaks that make sure
things are properly handled for ada.

Move the ada-specific code to gdb_compile_shlib, such that gdb_compile_sh can
be used for ada shared libs without tweaks.

Tested on x86_64-linux.

Any comments?

Thanks,
- Tom

[gdb/testsuite] Handle ada in gdb_compile_shlib

gdb/testsuite/ChangeLog:

2020-12-07  Tom de Vries  <tdevries@suse.de>

	* lib/gdb.exp (gdb_compile_shlib): Handle ada.
	* gdb.ada/catch_ex_std.exp: Use gdb_compile_shlib to compile from
	source to shared lib.  Add ada to options.

---
 gdb/testsuite/gdb.ada/catch_ex_std.exp | 21 +++--------------
 gdb/testsuite/lib/gdb.exp              | 41 +++++++++++++++++++++++++++++-----
 2 files changed, 39 insertions(+), 23 deletions(-)

diff --git a/gdb/testsuite/gdb.ada/catch_ex_std.exp b/gdb/testsuite/gdb.ada/catch_ex_std.exp
index 31f062425b..c8acd70241 100644
--- a/gdb/testsuite/gdb.ada/catch_ex_std.exp
+++ b/gdb/testsuite/gdb.ada/catch_ex_std.exp
@@ -24,28 +24,13 @@ if { [skip_ada_tests] } { return -1 }
 standard_ada_testfile foo
 
 set srcfile2 [file join [file dirname $srcfile] some_package.adb]
-set ofile2 [standard_output_file some_package.o]
 set sofile [standard_output_file libsome_package.so]
 
 set outdir [file dirname $binfile]
 
-# To make an Ada shared library we have to jump through a number of
-# hoops.
-
-# First compile to a .o.  We can't compile directly to a .so because
-# GCC rejects that:
-#    $ gcc -g -shared -fPIC -o qqz.o some_package.adb
-#    gcc: error: -c or -S required for Ada
-# And, we can't compile in "ada" mode because dejagnu will try to
-# invoke gnatmake, which we don't want.
-if {[target_compile_ada_from_dir $outdir $srcfile2 $ofile2 \
-	 object {debug additional_flags=-fPIC}] != ""} {
-    return -1
-}
-
-# Now turn the .o into a shared library.
-if {[gdb_compile_shlib $ofile2 $sofile \
-	 {debug additional_flags=-fPIC}] != ""} {
+# Create the shared library.
+if {[gdb_compile_shlib $srcfile2 $sofile \
+	 {ada debug additional_flags=-fPIC}] != ""} {
     return -1
 }
 
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index f2954fd519..e413bab93c 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -4286,6 +4286,11 @@ proc gdb_compile_pthreads {source dest type options} {
 proc gdb_compile_shlib {sources dest options} {
     set obj_options $options
 
+    set ada 0
+    if { [lsearch -exact $options "ada"] >= 0 } {
+	set ada 1
+    }
+
     set info_options ""
     if { [lsearch -exact $options "c++"] >= 0 } {
 	set info_options "c++"
@@ -4324,19 +4329,45 @@ proc gdb_compile_shlib {sources dest options} {
     set outdir [file dirname $dest]
     set objects ""
     foreach source $sources {
-	set sourcebase [file tail $source]
 	if {[file extension $source] == ".o"} {
 	    # Already a .o file.
 	    lappend objects $source
-	} elseif {[gdb_compile $source "${outdir}/${sourcebase}.o" object \
-		       $obj_options] != ""} {
-	    return -1
+	    continue
+	}
+	
+	set sourcebase [file tail $source]
+
+	if { $ada } {
+	    # Gnatmake doesn't like object name foo.adb.o, use foo.o.
+	    set sourcebase [file rootname $sourcebase]
+	}
+	set object ${outdir}/${sourcebase}.o
+
+	if { $ada } {
+	    # Use gdb_compile_ada_1 instead of gdb_compile_ada to avoid the
+	    # PASS message.
+	    if {[gdb_compile_ada_1 $source $object object \
+		     $obj_options] != ""} {
+		return -1
+	    }
 	} else {
-	    lappend objects ${outdir}/${sourcebase}.o
+	    if {[gdb_compile $source $object object \
+		     $obj_options] != ""} {
+		return -1
+	    }
 	}
+
+	lappend objects $object
     }
 
     set link_options $options
+    if { $ada } {
+	# If we try to use gnatmake for the link, it will interpret the
+	# object file as an .adb file.  Remove ada from the options to
+	# avoid it.
+	set idx [lsearch $link_options "ada"]
+	set link_options [lreplace $link_options $idx $idx]
+    }
     if [test_compiler_info "xlc-*"] {
 	lappend link_options "additional_flags=-qmkshrobj"
     } else {

             reply	other threads:[~2020-12-07 12:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-07 12:19 Tom de Vries [this message]
2020-12-13 13:29 ` Joel Brobecker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201207121942.GA14289@delia \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox