This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Testsuite support for shared libraries on remote targets


This patch lets gdbserver testing download shared libraries to the
remote host.  I've used it with SymbianOS, GNU/Linux gdbserver to
localhost, and Cygwin/MinGW32 gdbserver.  It also adds support for
cleaning up after gdbserver testing; it's bugged me for a while that I
didn't delete the binary from the target when we were done with it.

The shared library tests were formerly run if $host = $target.  Now
they are run in that case, and for a list of remote targets which
should support shared libraries.  The Windows targets on this list
have gdbserver support coming up fast; the BSD and Solaris targets
should be fine if you assume the existence of a gdbserver port.

Feel free to add other targets to the list:

+    # An abbreviated list of remote targets where we should be able to
+    # run shared library tests.
+    if {([istarget *-*-linux*]
+	 || [istarget *-*-*bsd*]
+	 || [istarget *-*-solaris2*]
+	 || [istarget arm*-*-symbianelf*]
+	 || [istarget *-*-mingw*]
+	 || [istarget *-*-cygwin*]
+	 || [istarget *-*-pe*])} {
+	return 0

I'm planning to commit this in a couple of days, unless anyone has
feedback.  I should have a chance before then to test the one
interesting configuration I've missed so far (GNU/Linux gdbserver to a
remote target).

-- 
Daniel Jacobowitz
CodeSourcery

2007-05-09  Daniel Jacobowitz  <dan@codesourcery.com>

	* lib/gdb.exp (gdb_compile): Add support for Windows DLLs.
	(gdb_compile_shlib): Likewise.
	(skip_shlib_tests, gdb_download, gdb_load_shlibs): New.
	(default_gdb_init): Clear cleanfiles.
	(gdb_finish): Delete recorded cleanfiles.
	* lib/gdbserver-support.exp (gdbserver_spawn): Use gdb_download.

	* gdb.base/gdb1555.exp: Use skip_shlib_tests and gdb_load_shlibs.
	Do not use isnative.
	* gdb.base/pending.exp, gdb.base/shlib-call.exp, gdb.base/shreloc.exp,
	gdb.base/so-impl-ld.exp: Likewise.
	* gdb.base/solib-weak.exp: Likewise.  Skip for DLL targets.
	* testsuite/gdb.base/unload.exp: Likewise.  Do not pass empty option to
	gdb_compile.

---
 gdb/testsuite/gdb.base/gdb1555.exp      |   11 +---
 gdb/testsuite/gdb.base/pending.exp      |    4 -
 gdb/testsuite/gdb.base/shlib-call.exp   |    5 +
 gdb/testsuite/gdb.base/shreloc.exp      |    4 -
 gdb/testsuite/gdb.base/so-impl-ld.exp   |    6 +-
 gdb/testsuite/gdb.base/solib-weak.exp   |   12 +++-
 gdb/testsuite/gdb.base/unload.exp       |   23 +++++---
 gdb/testsuite/lib/gdb.exp               |   88 ++++++++++++++++++++++++++++++--
 gdb/testsuite/lib/gdbserver-support.exp |    2 
 9 files changed, 125 insertions(+), 30 deletions(-)

Index: gdb/testsuite/gdb.base/gdb1555.exp
===================================================================
--- gdb/testsuite/gdb.base/gdb1555.exp.orig	2007-05-09 10:34:00.000000000 -0400
+++ gdb/testsuite/gdb.base/gdb1555.exp	2007-05-09 10:56:59.000000000 -0400
@@ -25,6 +25,10 @@ if $tracelevel then {
     strace $tracelevel
 }
 
+if {[skip_shlib_tests]} {
+    return 0
+}
+
 set testfile gdb1555-main
 set libfile gdb1555
 set srcfile ${testfile}.c
@@ -36,12 +40,6 @@ set execsrc "${srcdir}/${subdir}/${srcfi
 
 remote_exec build "rm -f ${binfile}"
 
-# Are we on a target board?  No support for downloading shared libraries
-# to a target yet.
-if ![isnative] then {
-    return 0
-}
-
 # get the value of gcc_compiled
 if [get_compiler_info ${binfile}] {
     return -1
@@ -57,6 +55,7 @@ gdb_exit
 gdb_start
 gdb_reinitialize_dir $srcdir/$subdir
 gdb_load ${binfile}
+gdb_load_shlibs $libobj
 
 if ![runto_main] then {
     fail "Can't run to main"
Index: gdb/testsuite/gdb.base/pending.exp
===================================================================
--- gdb/testsuite/gdb.base/pending.exp.orig	2007-05-09 10:34:00.000000000 -0400
+++ gdb/testsuite/gdb.base/pending.exp	2007-05-09 10:56:59.000000000 -0400
@@ -26,8 +26,7 @@ if $tracelevel then {
 set prms_id 0
 set bug_id 0
 
-# are we on a target board?
-if ![isnative] then {
+if {[skip_shlib_tests]} {
     return 0
 }
 
@@ -57,6 +56,7 @@ gdb_exit
 gdb_start
 gdb_reinitialize_dir $srcdir/$subdir
 gdb_load ${binfile}
+gdb_load_shlibs $lib_sl
 
 if [target_info exists gdb_stub] {
     gdb_step_for_stub;
Index: gdb/testsuite/gdb.base/shlib-call.exp
===================================================================
--- gdb/testsuite/gdb.base/shlib-call.exp.orig	2007-05-09 10:34:00.000000000 -0400
+++ gdb/testsuite/gdb.base/shlib-call.exp	2007-05-09 10:56:59.000000000 -0400
@@ -40,8 +40,7 @@ if $tracelevel then {
 set prms_id 0
 set bug_id 0
 
-# are we on a target board?
-if ![isnative] then {
+if {[skip_shlib_tests]} {
     return 0
 }
 
@@ -75,6 +74,8 @@ gdb_exit
 gdb_start
 gdb_reinitialize_dir $srcdir/$subdir
 gdb_load ${binfile}
+gdb_load_shlibs $lib1 $lib2
+
 send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
 send_gdb "set print address off\n" ; gdb_expect -re "$gdb_prompt $"
 send_gdb "set width 0\n" ; gdb_expect -re "$gdb_prompt $"
Index: gdb/testsuite/gdb.base/shreloc.exp
===================================================================
--- gdb/testsuite/gdb.base/shreloc.exp.orig	2007-05-09 10:34:00.000000000 -0400
+++ gdb/testsuite/gdb.base/shreloc.exp	2007-05-09 10:56:59.000000000 -0400
@@ -20,8 +20,7 @@
 # them gets relocated at load-time. Check that gdb gets the right
 # values for the debugging and minimal symbols.
 
-if {[istarget *-elf*] || [istarget *-coff] || [istarget *-aout]} then {
-    verbose "test skipped - shared object files not supported by this target."
+if {[skip_shlib_tests]} {
     return 0
 }
 
@@ -85,6 +84,7 @@ gdb_exit
 gdb_start
 gdb_reinitialize_dir $srcdir/$subdir
 gdb_load ${workdir}/shreloc
+gdb_load_shlibs $lib1_sl $lib2_sl
 
 # Load up the shared objects
 if ![runto_main] then {
Index: gdb/testsuite/gdb.base/so-impl-ld.exp
===================================================================
--- gdb/testsuite/gdb.base/so-impl-ld.exp.orig	2007-05-09 10:34:00.000000000 -0400
+++ gdb/testsuite/gdb.base/so-impl-ld.exp	2007-05-09 10:56:59.000000000 -0400
@@ -22,9 +22,8 @@ if $tracelevel then {
 set prms_id 0
 set bug_id 0
 
-# are we on a target board
-if ![isnative] then {
-    return
+if {[skip_shlib_tests]} {
+    return 0
 }
 
 set testfile "so-impl-ld"
@@ -61,6 +60,7 @@ gdb_exit
 gdb_start
 gdb_reinitialize_dir $srcdir/$subdir
 gdb_load ${binfile}
+gdb_load_shlibs $lib_sl
 
 # This program implicitly loads SOM shared libraries.
 #
Index: gdb/testsuite/gdb.base/solib-weak.exp
===================================================================
--- gdb/testsuite/gdb.base/solib-weak.exp.orig	2007-05-09 10:34:00.000000000 -0400
+++ gdb/testsuite/gdb.base/solib-weak.exp	2007-05-09 10:56:59.000000000 -0400
@@ -18,8 +18,15 @@
 # than one shared library, when one of the implementations is a "weak"
 # symbol.  GDB should set a breakpoint at the first copy it finds.
 
-# Don't try to run shared library test cases on a remote target for now.
-if ![isnative] then {
+if {[skip_shlib_tests]} {
+    return 0
+}
+
+# These targets have shared libraries, but weak symbols are not meaningful.
+if {([istarget arm*-*-symbianelf*]
+     || [istarget *-*-mingw*]
+     || [istarget *-*-cygwin*]
+     || [istarget *-*-pe*])} {
     return 0
 }
 
@@ -81,6 +88,7 @@ proc do_test { lib1opts lib2opts lib1fir
     gdb_start
     gdb_reinitialize_dir $srcdir/$subdir
     gdb_load ${binfile}
+    gdb_load_shlibs $lib1 $lib2
 
     runto_main
 
Index: gdb/testsuite/gdb.base/unload.exp
===================================================================
--- gdb/testsuite/gdb.base/unload.exp.orig	2007-05-09 10:34:00.000000000 -0400
+++ gdb/testsuite/gdb.base/unload.exp	2007-05-09 10:56:59.000000000 -0400
@@ -26,8 +26,15 @@ if $tracelevel then {
 set prms_id 0
 set bug_id 0
 
-# are we on a target board?
-if ![isnative] then {
+if {[skip_shlib_tests]} {
+    return 0
+}
+
+# TODO: Use LoadLibrary on these targets instead of dlopen.
+if {([istarget arm*-*-symbianelf*]
+     || [istarget *-*-mingw*]
+     || [istarget *-*-cygwin*]
+     || [istarget *-*-pe*])} {
     return 0
 }
 
@@ -40,17 +47,16 @@ set shlibdir ${objdir}/${subdir}
 set libsrc  $srcdir/$subdir/$libfile.c
 set lib_sl  $objdir/$subdir/$libfile.sl
 
-set dl_lib_flag ""
+set lib_opts debug
+set exec_opts [list debug additional_flags=-DSHLIB_DIR\=\"${shlibdir}\"]
+
 switch -glob [istarget] {
     "hppa*-hp-hpux*" { }
-    "*-*-linux*"     { set dl_lib_flag "libs=-ldl" }
-    "*-*-solaris*"   { set dl_lib_flag "libs=-ldl" }
+    "*-*-linux*"     { lappend exec_opts "libs=-ldl" }
+    "*-*-solaris*"   { lappend exec_opts "libs=-ldl" }
     default          { }
 }
 
-set lib_opts debug
-set exec_opts [list debug $dl_lib_flag additional_flags=-DSHLIB_DIR\=\"${shlibdir}\"]
-
 if [get_compiler_info ${binfile}] {
     return -1
 }
@@ -67,6 +73,7 @@ gdb_exit
 gdb_start
 gdb_reinitialize_dir $srcdir/$subdir
 gdb_load ${binfile}
+gdb_load_shlibs $lib_sl
 
 if [target_info exists gdb_stub] {
     gdb_step_for_stub;
Index: gdb/testsuite/lib/gdb.exp
===================================================================
--- gdb/testsuite/lib/gdb.exp.orig	2007-05-09 10:34:00.000000000 -0400
+++ gdb/testsuite/lib/gdb.exp	2007-05-09 10:56:59.000000000 -0400
@@ -1212,6 +1212,29 @@ proc skip_fortran_tests {} {
     return 0
 }
 
+# Return a 1 if we should skip shared library tests.
+
+proc skip_shlib_tests {} {
+    # Run the shared library tests on native systems.
+    if {[isnative]} {
+	return 0
+    }
+
+    # An abbreviated list of remote targets where we should be able to
+    # run shared library tests.
+    if {([istarget *-*-linux*]
+	 || [istarget *-*-*bsd*]
+	 || [istarget *-*-solaris2*]
+	 || [istarget arm*-*-symbianelf*]
+	 || [istarget *-*-mingw*]
+	 || [istarget *-*-cygwin*]
+	 || [istarget *-*-pe*])} {
+	return 0
+    }
+
+    return 1
+}
+
 # Run a test on the target to see if it supports vmx hardware.  Return 0 if so, 
 # 1 if it does not.  Based on 'check_vmx_hw_available' from the GCC testsuite.
 
@@ -1500,9 +1523,13 @@ proc gdb_compile {source dest type optio
      foreach opt $options {
         if [regexp {^shlib=(.*)} $opt dummy_var shlib_name] {
             if [test_compiler_info "xlc-*"] {
-               # IBM xlc compiler doesn't accept shared library named other  
-               # than .so: use "-Wl," to bypass this
-               lappend source "-Wl,$shlib_name"
+		# IBM xlc compiler doesn't accept shared library named other
+		# than .so: use "-Wl," to bypass this
+		lappend source "-Wl,$shlib_name"
+	    } elseif { ([istarget "*-*-mingw*"]
+			|| [istarget *-*-cygwin*]
+			|| [istarget *-*-pe*])} {
+		lappend source "${shlib_name}.a"
             } else {
                lappend source $shlib_name
             }
@@ -1560,8 +1587,13 @@ proc gdb_compile {source dest type optio
     }
 
     set result [target_compile $source $dest $type $options];
+
+    # Prune uninteresting compiler (and linker) output.
+    regsub "Creating library file: \[^\r\n\]*\[\r\n\]+" $result "" result
+
     regsub "\[\r\n\]*$" "$result" "" result;
     regsub "^\[\r\n\]*" "$result" "" result;
+
     if { $result != "" && [lsearch $options quiet] == -1} {
 	clone_output "gdb compile failed, $result"
     }
@@ -1657,6 +1689,12 @@ proc gdb_compile_shlib {sources dest opt
           lappend link_options "additional_flags=-qmkshrobj"
        } else {
           lappend link_options "additional_flags=-shared"
+
+	   if { ([istarget "*-*-mingw*"]
+		 || [istarget *-*-cygwin*]
+		 || [istarget *-*-pe*])} {
+	       lappend link_options "additional_flags=-Wl,--out-implib,${dest}.a"
+	   }
        }
        if {[gdb_compile "${objects}" "${dest}" executable $link_options] != ""} {
            return -1
@@ -1963,6 +2001,37 @@ proc gdb_load_cmd { args } {
     return -1
 }
 
+# gdb_download
+#
+# Copy a file to the remote target and return its target filename.
+# Schedule the file to be deleted at the end of this test.
+
+proc gdb_download { filename } {
+    global cleanfiles
+
+    set destname [remote_download target $filename]
+    lappend cleanfiles $destname
+    return $destname
+}
+
+# gdb_load_shlibs LIB...
+#
+# Copy the listed libraries to the target.
+
+proc gdb_load_shlibs { args } {
+    if {![is_remote target]} {
+	return
+    }
+
+    foreach file $args {
+	gdb_download $file
+    }
+
+    # Even if the target supplies full paths for shared libraries,
+    # they may not be paths for this system.
+    gdb_test "set solib-search-path [file dirname [lindex $args 0]]" "" ""
+}
+
 #
 # gdb_load -- load a file into the debugger.
 # Many files in config/*.exp override this procedure.
@@ -1991,7 +2060,10 @@ proc gdb_continue { function } {
 
 proc default_gdb_init { args } {
     global gdb_wrapper_initialized
+    global cleanfiles
     
+    set cleanfiles {}
+
     gdb_clear_suppressed;
 
     # Make sure that the wrapper is rebuilt
@@ -2023,7 +2095,15 @@ proc gdb_init { args } {
 }
 
 proc gdb_finish { } {
-    gdb_exit;
+    global cleanfiles
+
+    # Exit first, so that the files are no longer in use.
+    gdb_exit
+
+    if { [llength $cleanfiles] > 0 } {
+	remote_file target delete $cleanfiles
+	set cleanfiles {}
+    }
 }
 
 global debug_format
Index: gdb/testsuite/lib/gdbserver-support.exp
===================================================================
--- gdb/testsuite/lib/gdbserver-support.exp.orig	2007-05-09 10:34:00.000000000 -0400
+++ gdb/testsuite/lib/gdbserver-support.exp	2007-05-09 10:56:59.000000000 -0400
@@ -164,7 +164,7 @@ proc gdbserver_spawn { child_args } {
 	set gdbserver_host_exec $host_exec
 	set gdbserver_host_mtime [file mtime $host_exec]
 	if [is_remote target] {
-	    set gdbserver_server_exec [remote_download target $host_exec /tmp/[file tail $host_exec].[pid]]
+	    set gdbserver_server_exec [gdb_download $host_exec]
 	} else {
 	    set gdbserver_server_exec $host_exec
 	}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]