[rfc] Fix tls-shared.exp remote test

Ulrich Weigand uweigand@de.ibm.com
Thu Jul 7 17:40:00 GMT 2011


Hello,

tls-shared.exp hard-codes a lot of logic how to create and use shared
libraries.  This is not only annoying, it causes the test to still fail
in remote mode even after my previous fix.

The problem is that this test needs to build *both* a shared library
*and* link it against the pthread library, so it required the combined
effects on gdb_compile_pthreads and gdb_compile_shlib -- there was no
helper routine to implement this.

The patch below creates a new gdb_compile_shlib_pthreads helper
and uses it in tls-shared.exp.

Tested on an arm-linux-gnueabi target from an x86 host.

Comments?

Bye,
Ulrich

ChangeLog:

	* lib/gdb.exp (gdb_compile_shlib_pthreads): New helper.
	* gdb.threads/tls-shared.exp: Use it.  Call gdb_load_shlibs.

Index: gdb/testsuite/gdb.threads/tls-shared.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.threads/tls-shared.exp,v
retrieving revision 1.10
diff -u -p -r1.10 tls-shared.exp
--- gdb/testsuite/gdb.threads/tls-shared.exp	1 Jan 2011 15:33:50 -0000	1.10
+++ gdb/testsuite/gdb.threads/tls-shared.exp	7 Jul 2011 13:20:30 -0000
@@ -24,6 +24,8 @@ set testfile tls-main
 set libfile tls-shared
 set srcfile ${testfile}.c
 set binfile ${objdir}/${subdir}/${testfile}
+set srcfile_lib ${libfile}.c
+set binfile_lib ${objdir}/${subdir}/${libfile}.so
 
 remote_exec build "rm -f ${binfile}"
 
@@ -32,48 +34,9 @@ if [get_compiler_info ${binfile}] {
     return -1
 }
 
-if  { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}.o" object {debug}] != "" } {
-    return -1
-}
-
-# Build the shared libraries this test case needs.
-#
-
-if {$gcc_compiled == 0} {
-    if [istarget "hppa*-hp-hpux*"] then {
-        set additional_flags "additional_flags=+z"
-    } elseif { [istarget "mips-sgi-irix*"] } {
-        # Disable SGI compiler's implicit -Dsgi
-        set additional_flags "additional_flags=-Usgi"
-    } else {
-        # don't know what the compiler is...
-        set additional_flags ""
-    }
-} else {
-    if { ([istarget "powerpc*-*-aix*"]
-    || [istarget "rs6000*-*-aix*"]) } {
-        set additional_flags ""
-    } else {
-        set additional_flags "additional_flags=-fpic"
-    }
-}
-
-set additional_flags "$additional_flags -shared"
-if {[gdb_compile_pthreads "${srcdir}/${subdir}/${libfile}.c" "${objdir}/${subdir}/${libfile}.so" executable [list debug $additional_flags "incdir=${objdir}"]] != ""} {
-    return -1
-}
-
-if { ($gcc_compiled 
-&&  ([istarget "powerpc*-*-aix*"]
-|| [istarget "rs6000*-*-aix*"] )) } {
-    set additional_flags "additional_flags=-L${objdir}/${subdir}"
-} elseif { [istarget "mips-sgi-irix*"] } {
-    set additional_flags "additional_flags=-rpath ${objdir}/${subdir}"
-} else {
-    set additional_flags ""
-}
 
-if {[gdb_compile_pthreads "${objdir}/${subdir}/${testfile}.o ${objdir}/${subdir}/${libfile}.so" "${binfile}" executable [list debug $additional_flags]] != ""} {
+if { [gdb_compile_shlib_pthreads ${srcdir}/${subdir}/${srcfile_lib} ${binfile_lib} {debug}] != ""
+     || [gdb_compile_pthreads ${srcdir}/${subdir}/${srcfile} ${binfile} executable [list debug shlib=${binfile_lib}]] != ""} {
     return -1
 }
 
@@ -82,6 +45,7 @@ gdb_exit
 gdb_start
 gdb_reinitialize_dir $srcdir/$subdir
 gdb_load ${binfile}
+gdb_load_shlibs ${binfile_lib}
 
 if ![runto_main] then {
     fail "Can't run to main"
Index: gdb/testsuite/lib/gdb.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/lib/gdb.exp,v
retrieving revision 1.182
diff -u -p -r1.182 gdb.exp
--- gdb/testsuite/lib/gdb.exp	1 Jul 2011 00:19:25 -0000	1.182
+++ gdb/testsuite/lib/gdb.exp	7 Jul 2011 13:20:31 -0000
@@ -2391,6 +2401,41 @@ proc gdb_compile_shlib {sources dest opt
     }
 }
 
+# This is just like gdb_compile_shlib, above, except that it tries compiling
+# against several different thread libraries, to see which one this
+# system has.
+proc gdb_compile_shlib_pthreads {sources dest options} {
+    set built_binfile 0
+    set why_msg "unrecognized error"
+    foreach lib {-lpthreads -lpthread -lthread ""} {
+        # This kind of wipes out whatever libs the caller may have
+        # set.  Or maybe theirs will override ours.  How infelicitous.
+        set options_with_lib [concat $options [list libs=$lib quiet]]
+        set ccout [gdb_compile_shlib $sources $dest $options_with_lib]
+        switch -regexp -- $ccout {
+            ".*no posix threads support.*" {
+                set why_msg "missing threads include file"
+                break
+            }
+            ".*cannot open -lpthread.*" {
+                set why_msg "missing runtime threads library"
+            }
+            ".*Can't find library for -lpthread.*" {
+                set why_msg "missing runtime threads library"
+            }
+            {^$} {
+                pass "successfully compiled posix threads test case"
+                set built_binfile 1
+                break
+            }
+        }
+    }
+    if {!$built_binfile} {
+        unsupported "Couldn't compile $sources: ${why_msg}"
+        return -1
+    }
+}
+
 # This is just like gdb_compile_pthreads, above, except that we always add the
 # objc library for compiling Objective-C programs
 proc gdb_compile_objc {source dest type options} {
-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com



More information about the Gdb-patches mailing list