Blob Blame History Raw
commit 5bfdc32cd3bf373c3b02e1fd864ed8ceab0292b2
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date:   Mon Aug 8 12:08:53 2011 +0200

    +testcase

Index: gdb-7.4.50.20120703/gdb/testsuite/gdb.threads/dlopen-libpthread-lib.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ gdb-7.4.50.20120703/gdb/testsuite/gdb.threads/dlopen-libpthread-lib.c	2012-07-03 17:44:45.797698656 +0200
@@ -0,0 +1,40 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2011 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <pthread.h>
+#include <assert.h>
+
+static void *
+tfunc (void *arg)
+{
+  void (*notifyp) (void) = arg;
+
+  notifyp ();
+}
+
+void
+f (void (*notifyp) (void))
+{
+  pthread_t t;
+  int i;
+
+  i = pthread_create (&t, NULL, tfunc, notifyp);
+  assert (i == 0);
+
+  i = pthread_join (t, NULL);
+  assert (i == 0);
+}
Index: gdb-7.4.50.20120703/gdb/testsuite/gdb.threads/dlopen-libpthread.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ gdb-7.4.50.20120703/gdb/testsuite/gdb.threads/dlopen-libpthread.c	2012-07-03 17:44:45.798698655 +0200
@@ -0,0 +1,46 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2011 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <dlfcn.h>
+#include <stddef.h>
+#include <assert.h>
+
+static const char *volatile filename;
+
+static void
+notify (void)
+{
+  filename = NULL; /* notify-here */
+}
+
+int
+main (void)
+{
+  void *h;
+  void (*fp) (void (*) (void));
+
+  assert (filename != NULL);
+  h = dlopen (filename, RTLD_LAZY);
+  assert (h != NULL);
+
+  fp = dlsym (h, "f");
+  assert (fp != NULL);
+
+  fp (notify);
+
+  return 0;
+}
Index: gdb-7.4.50.20120703/gdb/testsuite/gdb.threads/dlopen-libpthread.exp
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ gdb-7.4.50.20120703/gdb/testsuite/gdb.threads/dlopen-libpthread.exp	2012-07-03 17:44:45.798698655 +0200
@@ -0,0 +1,74 @@
+# Copyright 2011 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+if {![istarget *-linux*] || [skip_shlib_tests]} {
+    return 0
+}
+
+load_lib prelink-support.exp
+
+set testfile "dlopen-libpthread"
+set srcmainfile ${testfile}.c
+set srclibfile ${testfile}-lib.c
+set executable ${testfile}
+set binfile_lib ${objdir}/${subdir}/${executable}.so
+set binfile ${objdir}/${subdir}/${executable}
+set lib_dlopen [shlib_target_file ${executable}.so]
+
+# Use build_executable_own_libs as prelinked libpthread.so can produce false
+# PASS - it is OK if GDB processes it still before relocation.
+
+set relink_args [build_executable_own_libs ${testfile}.exp ${executable}.so $srclibfile {debug shlib_pthreads} no]
+if {$relink_args == "" || ![prelink_no $relink_args]
+    || [prepare_for_testing ${testfile}.exp ${executable} ${srcmainfile} {debug shlib_load}] } {
+    return -1
+}
+gdb_load_shlibs $binfile_lib
+
+if { ![runto_main] } {
+    return -1
+}
+
+set test "print _dl_debug_notify"
+gdb_test_multiple $test $test {
+    -re " 0x\[0-9a-f\]+ <_dl_debug_notify>\r\n$gdb_prompt $" {
+	pass $test
+    }
+    -re "No symbol \"_dl_debug_notify\" in current context\\.\r\n$gdb_prompt $" {
+	xfail $test
+	untested ${testfile}.exp
+	return
+    }
+}
+
+set test "libpthread.so not found"
+gdb_test_multiple "info sharedlibrary" $test {
+    -re "/libpthread\\.so.*\r\n$gdb_prompt $" {
+	fail $test
+    }
+    -re "/libc\\.so.*\r\n$gdb_prompt $" {
+	pass $test
+    }
+}
+
+gdb_test "set variable filename=\"$lib_dlopen\""
+
+gdb_breakpoint "notify"
+
+# The error was:
+# Cannot find new threads: generic error
+gdb_continue_to_breakpoint "notify" ".* notify-here .*"
+
+gdb_test "info sharedlibrary" {/libpthread\.so.*} "libpthread.so found"
Index: gdb-7.4.50.20120703/gdb/testsuite/lib/gdb.exp
===================================================================
--- gdb-7.4.50.20120703.orig/gdb/testsuite/lib/gdb.exp	2012-07-03 17:34:18.000000000 +0200
+++ gdb-7.4.50.20120703/gdb/testsuite/lib/gdb.exp	2012-07-03 17:46:44.316514076 +0200
@@ -3758,23 +3758,7 @@ proc build_executable { testname executa
         set sources ${executable}.c
     }
 
-    set binfile [standard_output_file $executable]
-
-    set objects {}
-    for {set i 0} "\$i<[llength $sources]" {incr i} {
-        set s [lindex $sources $i]
-        if  { [gdb_compile "${srcdir}/${subdir}/${s}" "${binfile}${i}.o" object $options] != "" } {
-            untested $testname
-            return -1
-        }
-        lappend objects "${binfile}${i}.o"
-    }
-    
-    if  { [gdb_compile $objects "${binfile}" executable $options] != "" } {
-        untested $testname
-        return -1
-    }
-
+    # get_compiler_info by gdb_compile_shlib and gdb_compile_shlib_pthreads.
     set info_options ""
     if { [lsearch -exact $options "c++"] >= 0 } {
 	set info_options "c++"
@@ -3782,6 +3766,41 @@ proc build_executable { testname executa
     if [get_compiler_info ${info_options}] {
         return -1
     }
+
+    set binfile [standard_output_file $executable]
+
+    set func gdb_compile
+    set func_index [lsearch -regexp $options {^(pthreads|shlib|shlib_pthreads)$}]
+    if {$func_index != -1} {
+	set func "${func}_[lindex $options $func_index]"
+    }
+
+    # gdb_compile_shlib and gdb_compile_shlib_pthreads do not use the 3rd
+    # parameter.  They also requires $sources while gdb_compile and
+    # gdb_compile_pthreads require $objects.
+    if [string match gdb_compile_shlib* $func] {
+	set sources_path {}
+	foreach s $sources {
+	    lappend sources_path "${srcdir}/${subdir}/${s}"
+	}
+	set ret [$func $sources_path "${binfile}" $options]
+    } else {
+	set objects {}
+	for {set i 0} "\$i<[llength $sources]" {incr i} {
+	    set s [lindex $sources $i]
+	    if  { [gdb_compile "${srcdir}/${subdir}/${s}" "${binfile}${i}.o" object $options] != "" } {
+		untested $testname
+		return -1
+	    }
+	    lappend objects "${binfile}${i}.o"
+	}
+	set ret [$func $objects "${binfile}" executable $options]
+    }
+    if  { $ret != "" } {
+        untested $testname
+        return -1
+    }
+
     return 0
 }
 
Index: gdb-7.4.50.20120703/gdb/testsuite/lib/prelink-support.exp
===================================================================
--- gdb-7.4.50.20120703.orig/gdb/testsuite/lib/prelink-support.exp	2012-01-04 09:27:56.000000000 +0100
+++ gdb-7.4.50.20120703/gdb/testsuite/lib/prelink-support.exp	2012-07-03 17:44:45.803698648 +0200
@@ -95,8 +95,9 @@ proc file_copy {src dest} {
 # Wrap function build_executable so that the resulting executable is fully
 # self-sufficient (without dependencies on system libraries).  Parameter
 # INTERP may be used to specify a loader (ld.so) to be used that is
-# different from the default system one.  Libraries on which the executable
-# depends are copied into directory DIR.  Default DIR value to
+# different from the default system one.  INTERP can be set to "no" if no ld.so
+# copy should be made.  Libraries on which the executable depends are copied
+# into directory DIR.  Default DIR value to
 # `${objdir}/${subdir}/${EXECUTABLE}.d'.
 #
 # In case of success, return a string containing the arguments to be used
@@ -151,8 +152,15 @@ proc build_executable_own_libs {testname
 
     if {$interp == ""} {
 	set interp_system [section_get $binfile .interp]
-	set interp ${dir}/[file tail $interp_system]
-	file_copy $interp_system $interp
+	if {$interp_system == ""} {
+	    fail "$test could not find .interp"
+	} else {
+	    set interp ${dir}/[file tail $interp_system]
+	    file_copy $interp_system $interp
+	}
+    }
+    if {$interp == "no"} {
+	set interp ""
     }
 
     set dests {}
@@ -164,13 +172,19 @@ proc build_executable_own_libs {testname
 
     # Do not lappend it so that "-rpath $dir" overrides any possible "-rpath"s
     # specified by the caller to be able to link it for ldd" above.
-    set options [linsert $options 0 "ldflags=-Wl,--dynamic-linker,$interp,-rpath,$dir"]
+    set options [linsert $options 0 "ldflags=-Wl,-rpath,$dir"]
+    if {$interp != ""} {
+	set options [linsert $options 0 "ldflags=-Wl,--dynamic-linker,$interp"]
+    }
 
     if {[build_executable $testname $executable $sources $options] == -1} {
 	return ""
     }
 
-    set prelink_args "--dynamic-linker=$interp --ld-library-path=$dir $binfile $interp [concat $dests]"
+    set prelink_args "--ld-library-path=$dir $binfile [concat $dests]"
+    if {$interp != ""} {
+	set prelink_args "--dynamic-linker=$interp $prelink_args $interp"
+    }
     return $prelink_args
 }
 
Index: gdb-7.4.50.20120703/gdb/testsuite/gdb.base/break-interp.exp
===================================================================
--- gdb-7.4.50.20120703.orig/gdb/testsuite/gdb.base/break-interp.exp	2012-06-21 22:46:21.000000000 +0200
+++ gdb-7.4.50.20120703/gdb/testsuite/gdb.base/break-interp.exp	2012-07-03 17:44:45.804698647 +0200
@@ -109,14 +109,21 @@ proc strip_debug {dest} {
     }
 }
 
+# Former symbol for solib changes notifications was _dl_debug_state, newer one
+# is dl_main (in fact _dl_debug_notify but it is inlined without any extra
+# debug info), the right one one traps by `set stop-on-solib-events 1'.
+
+set solib_bp {(_dl_debug_state|dl_main)}
+
 # Implementation of reach.
 
 proc reach_1 {func command displacement} {
-    global gdb_prompt expect_out
+    global gdb_prompt expect_out solib_bp
 
-    if {$func == "_dl_debug_state"} {
+    if {$func == $solib_bp} {
 	# Breakpoint on _dl_debug_state can have problems due to its overlap
 	# with the existing internal breakpoint from GDB.
+	# With also _dl_debug_notify we would need even two breakpoints.
 	gdb_test_no_output "set stop-on-solib-events 1"
     } elseif {! [gdb_breakpoint $func allow-pending]} {
 	return
@@ -142,21 +149,21 @@ proc reach_1 {func command displacement}
 	    exp_continue
 	}
 	-re "Breakpoint \[0-9\]+, \\.?(__GI_)?$func \\(.*\\) at .*:\[0-9\]+\r\n.*$gdb_prompt $" {
-	    if {$func == "_dl_debug_state"} {
+	    if {$func == $solib_bp} {
 		fail $test
 	    } else {
 		pass $test
 	    }
 	}
 	-re "Breakpoint \[0-9\]+, \[0-9xa-f\]+ in \\.?(__GI_)?$func \\(\\).*\r\n$gdb_prompt $" {
-	    if {$func == "_dl_debug_state"} {
+	    if {$func == $solib_bp} {
 		fail $test
 	    } else {
 		pass $test
 	    }
 	}
 	-re "Stopped due to (spurious )?shared library event.*\r\n$gdb_prompt $" {
-	    if {$func == "_dl_debug_state"} {
+	    if {$func == $solib_bp} {
 		if {$debug_state_count == 0} {
 		    # First stop does not yet relocate the _start function
 		    # descriptor on ppc64.
@@ -175,7 +182,7 @@ proc reach_1 {func command displacement}
 	fail $test_displacement
     }
 
-    if {$func == "_dl_debug_state"} {
+    if {$func == $solib_bp} {
 	gdb_test_no_output "set stop-on-solib-events 0"
     }
 }
@@ -357,7 +364,7 @@ proc test_attach {file displacement {rel
 }
 
 proc test_ld {file ifmain trynosym displacement} {
-    global srcdir subdir gdb_prompt expect_out inferior_exited_re
+    global srcdir subdir gdb_prompt expect_out inferior_exited_re solib_bp
 
     # First test normal `file'-command loaded $FILE with symbols.
 
@@ -385,9 +392,9 @@ proc test_ld {file ifmain trynosym displ
 	gdb_test_no_output "set args ${objdir}/${subdir}/$binfile_test" "set args OBJDIR/${subdir}/$binfile_test"
     }
 
-    reach "_dl_debug_state" "run" $displacement
+    reach $solib_bp "run" $displacement
 
-    gdb_test "bt" "#0 +\[^\r\n\]*\\m(__GI_)?_dl_debug_state\\M.*" "dl bt"
+    gdb_test "bt" "#0 +\[^\r\n\]*\\m(__GI_)?$solib_bp\\M.*" "dl bt"
 
     if $ifmain {
 	reach "main" continue "NONE"
@@ -399,7 +406,7 @@ proc test_ld {file ifmain trynosym displ
 
     # Try re-run if the new PIE displacement takes effect.
     gdb_test "kill" "" "kill" {Kill the program being debugged\? \(y or n\) } "y"
-    reach "_dl_debug_state" "run" $displacement
+    reach $solib_bp "run" $displacement
 
     if $ifmain {
 	test_core $file $displacement
@@ -431,7 +438,7 @@ proc test_ld {file ifmain trynosym displ
 	gdb_test "exec-file $file" "exec-file $escapedfile" "load"
 
 	if $ifmain {
-	    reach "_dl_debug_state" run $displacement
+	    reach $solib_bp run $displacement
 
 	    # Use two separate gdb_test_multiple statements to avoid timeouts due
 	    # to slow processing of wildcard capturing long output