01917d
http://sourceware.org/ml/gdb-cvs/2013-06/msg00019.html
01917d
01917d
### src/gdb/testsuite/ChangeLog	2013/05/30 00:25:16	1.3682
01917d
### src/gdb/testsuite/ChangeLog	2013/06/04 13:23:31	1.3683
01917d
## -1,3 +1,19 @@
01917d
+2013-06-04  Jan Kratochvil  <jan.kratochvil@redhat.com>
01917d
+	    Gary Benson  <gbenson@redhat.com>
01917d
+
01917d
+	* lib/gdb.exp (build_executable_from_specs): Use gdb_compile_pthread,
01917d
+	gdb_compile_shlib or gdb_compile_shlib_pthreads where appropriate.
01917d
+	* lib/prelink-support.exp (build_executable_own_libs): Allow INTERP
01917d
+	to be set to "no" to indicate that no ld.so copy should be made.
01917d
+	* gdb.base/break-interp.exp (solib_bp): New constant.
01917d
+	(reach_1): Use the above instead of "_dl_debug_state".
01917d
+	(test_attach): Likewise.
01917d
+	(test_ld): Likewise.
01917d
+	* gdb.threads/dlopen-libpthread.exp: New file.
01917d
+	* gdb.threads/dlopen-libpthread.c: Likewise.
01917d
+	* gdb.threads/dlopen-libpthread-lib.c: Likewise.
01917d
+	* gdb.base/solib-corrupted.exp: Disable test if GDB is using probes.
01917d
+
01917d
 2013-05-30  Yao Qi  <yao@codesourcery.com>
01917d
 
01917d
 	* gdb.mi/mi-cmd-param-changed.exp (test_command_param_changed):
01917d
Index: gdb-7.6/gdb/testsuite/gdb.base/break-interp.exp
01917d
===================================================================
01917d
--- gdb-7.6.orig/gdb/testsuite/gdb.base/break-interp.exp	2013-06-10 14:29:24.815123941 +0200
01917d
+++ gdb-7.6/gdb/testsuite/gdb.base/break-interp.exp	2013-06-10 14:30:18.086102375 +0200
01917d
@@ -109,12 +109,19 @@ proc strip_debug {dest} {
01917d
     }
01917d
 }
01917d
 
01917d
+# The marker function for the standard runtime linker interface is
01917d
+# _dl_debug_state.  The probes-based interface has no specific marker
01917d
+# function; the probe we will stop on (init_start) is in dl_main so we
01917d
+# check for that.
01917d
+
01917d
+set solib_bp {(_dl_debug_state|dl_main)}
01917d
+
01917d
 # Implementation of reach.
01917d
 
01917d
 proc reach_1 {func command displacement} {
01917d
-    global gdb_prompt expect_out
01917d
+    global gdb_prompt expect_out solib_bp
01917d
 
01917d
-    if {$func == "_dl_debug_state"} {
01917d
+    if {$func == $solib_bp} {
01917d
 	# Breakpoint on _dl_debug_state can have problems due to its overlap
01917d
 	# with the existing internal breakpoint from GDB.
01917d
 	gdb_test_no_output "set stop-on-solib-events 1"
01917d
@@ -142,21 +149,21 @@ proc reach_1 {func command displacement}
01917d
 	    exp_continue
01917d
 	}
01917d
 	-re "Breakpoint \[0-9\]+, \\.?(__GI_)?$func \\(.*\\) at .*:\[0-9\]+\r\n.*$gdb_prompt $" {
01917d
-	    if {$func == "_dl_debug_state"} {
01917d
+	    if {$func == $solib_bp} {
01917d
 		fail $test
01917d
 	    } else {
01917d
 		pass $test
01917d
 	    }
01917d
 	}
01917d
 	-re "Breakpoint \[0-9\]+, \[0-9xa-f\]+ in \\.?(__GI_)?$func \\(\\).*\r\n$gdb_prompt $" {
01917d
-	    if {$func == "_dl_debug_state"} {
01917d
+	    if {$func == $solib_bp} {
01917d
 		fail $test
01917d
 	    } else {
01917d
 		pass $test
01917d
 	    }
01917d
 	}
01917d
 	-re "Stopped due to (spurious )?shared library event.*\r\n$gdb_prompt $" {
01917d
-	    if {$func == "_dl_debug_state"} {
01917d
+	    if {$func == $solib_bp} {
01917d
 		if {$debug_state_count == 0} {
01917d
 		    # First stop does not yet relocate the _start function
01917d
 		    # descriptor on ppc64.
01917d
@@ -175,7 +182,7 @@ proc reach_1 {func command displacement}
01917d
 	fail $test_displacement
01917d
     }
01917d
 
01917d
-    if {$func == "_dl_debug_state"} {
01917d
+    if {$func == $solib_bp} {
01917d
 	gdb_test_no_output "set stop-on-solib-events 0"
01917d
     }
01917d
 }
01917d
@@ -357,7 +364,7 @@ proc test_attach {file displacement {rel
01917d
 }
01917d
 
01917d
 proc test_ld {file ifmain trynosym displacement} {
01917d
-    global srcdir subdir gdb_prompt expect_out inferior_exited_re
01917d
+    global srcdir subdir gdb_prompt expect_out inferior_exited_re solib_bp
01917d
 
01917d
     # First test normal `file'-command loaded $FILE with symbols.
01917d
 
01917d
@@ -385,9 +392,9 @@ proc test_ld {file ifmain trynosym displ
01917d
 	gdb_test_no_output "set args ${objdir}/${subdir}/$binfile_test" "set args OBJDIR/${subdir}/$binfile_test"
01917d
     }
01917d
 
01917d
-    reach "_dl_debug_state" "run" $displacement
01917d
+    reach $solib_bp "run" $displacement
01917d
 
01917d
-    gdb_test "bt" "#0 +\[^\r\n\]*\\m(__GI_)?_dl_debug_state\\M.*" "dl bt"
01917d
+    gdb_test "bt" "#0 +\[^\r\n\]*\\m(__GI_)?$solib_bp\\M.*" "dl bt"
01917d
 
01917d
     if $ifmain {
01917d
 	reach "main" continue "NONE"
01917d
@@ -399,7 +406,7 @@ proc test_ld {file ifmain trynosym displ
01917d
 
01917d
     # Try re-run if the new PIE displacement takes effect.
01917d
     gdb_test "kill" "" "kill" {Kill the program being debugged\? \(y or n\) } "y"
01917d
-    reach "_dl_debug_state" "run" $displacement
01917d
+    reach $solib_bp "run" $displacement
01917d
 
01917d
     if $ifmain {
01917d
 	test_core $file $displacement
01917d
@@ -431,7 +438,7 @@ proc test_ld {file ifmain trynosym displ
01917d
 	gdb_test "exec-file $file" "exec-file $escapedfile" "load"
01917d
 
01917d
 	if $ifmain {
01917d
-	    reach "_dl_debug_state" run $displacement
01917d
+	    reach $solib_bp run $displacement
01917d
 
01917d
 	    # Use two separate gdb_test_multiple statements to avoid timeouts due
01917d
 	    # to slow processing of wildcard capturing long output
01917d
Index: gdb-7.6/gdb/testsuite/gdb.base/solib-corrupted.exp
01917d
===================================================================
01917d
--- gdb-7.6.orig/gdb/testsuite/gdb.base/solib-corrupted.exp	2013-06-10 14:29:24.816123941 +0200
01917d
+++ gdb-7.6/gdb/testsuite/gdb.base/solib-corrupted.exp	2013-06-10 14:30:18.086102375 +0200
01917d
@@ -36,6 +36,33 @@ if ![runto_main] {
01917d
     return
01917d
 }
01917d
 
01917d
+# With probes interface GDB no longer scans the inferior library list so its
01917d
+# corruption cannot be tested.  There is no way to disable the probes
01917d
+# interface.
01917d
+
01917d
+set probes { init_start init_complete map_start reloc_complete unmap_start
01917d
+	     unmap_complete }
01917d
+set test "info probes"
01917d
+gdb_test_multiple $test $test {
01917d
+    -re "^rtld\[ \t\]+(?:rtld_)?(\[a-z_\]+)\[ \t\]" {
01917d
+	set idx [lsearch -exact $probes $expect_out(1,string)]
01917d
+	if { $idx >= 0 } {
01917d
+	    set probes [lreplace $probes $idx $idx]
01917d
+	}
01917d
+	exp_continue
01917d
+    }
01917d
+    -re "^\[^\r\n\]*\r\n" {
01917d
+	exp_continue
01917d
+    }
01917d
+    -re "^$gdb_prompt $" {
01917d
+    }
01917d
+}
01917d
+if { [llength $probes] == 0 } {
01917d
+    xfail $test
01917d
+    untested "GDB is using probes"
01917d
+    return
01917d
+}
01917d
+
01917d
 gdb_test "info sharedlibrary" "From * To .*" "normal list"
01917d
 
01917d
 # GDB checks there for matching L_PREV.
01917d
Index: gdb-7.6/gdb/testsuite/gdb.threads/dlopen-libpthread-lib.c
01917d
===================================================================
01917d
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
01917d
+++ gdb-7.6/gdb/testsuite/gdb.threads/dlopen-libpthread-lib.c	2013-06-10 14:30:18.086102375 +0200
01917d
@@ -0,0 +1,40 @@
01917d
+/* This testcase is part of GDB, the GNU debugger.
01917d
+
01917d
+   Copyright 2011-2013 Free Software Foundation, Inc.
01917d
+
01917d
+   This program is free software; you can redistribute it and/or modify
01917d
+   it under the terms of the GNU General Public License as published by
01917d
+   the Free Software Foundation; either version 3 of the License, or
01917d
+   (at your option) any later version.
01917d
+
01917d
+   This program is distributed in the hope that it will be useful,
01917d
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
01917d
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
01917d
+   GNU General Public License for more details.
01917d
+
01917d
+   You should have received a copy of the GNU General Public License
01917d
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
01917d
+
01917d
+#include <pthread.h>
01917d
+#include <assert.h>
01917d
+
01917d
+static void *
01917d
+tfunc (void *arg)
01917d
+{
01917d
+  void (*notifyp) (void) = arg;
01917d
+
01917d
+  notifyp ();
01917d
+}
01917d
+
01917d
+void
01917d
+f (void (*notifyp) (void))
01917d
+{
01917d
+  pthread_t t;
01917d
+  int i;
01917d
+
01917d
+  i = pthread_create (&t, NULL, tfunc, notifyp);
01917d
+  assert (i == 0);
01917d
+
01917d
+  i = pthread_join (t, NULL);
01917d
+  assert (i == 0);
01917d
+}
01917d
Index: gdb-7.6/gdb/testsuite/gdb.threads/dlopen-libpthread.c
01917d
===================================================================
01917d
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
01917d
+++ gdb-7.6/gdb/testsuite/gdb.threads/dlopen-libpthread.c	2013-06-10 14:30:18.087102375 +0200
01917d
@@ -0,0 +1,46 @@
01917d
+/* This testcase is part of GDB, the GNU debugger.
01917d
+
01917d
+   Copyright 2011-2013 Free Software Foundation, Inc.
01917d
+
01917d
+   This program is free software; you can redistribute it and/or modify
01917d
+   it under the terms of the GNU General Public License as published by
01917d
+   the Free Software Foundation; either version 3 of the License, or
01917d
+   (at your option) any later version.
01917d
+
01917d
+   This program is distributed in the hope that it will be useful,
01917d
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
01917d
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
01917d
+   GNU General Public License for more details.
01917d
+
01917d
+   You should have received a copy of the GNU General Public License
01917d
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
01917d
+
01917d
+#include <dlfcn.h>
01917d
+#include <stddef.h>
01917d
+#include <assert.h>
01917d
+
01917d
+static const char *volatile filename;
01917d
+
01917d
+static void
01917d
+notify (void)
01917d
+{
01917d
+  filename = NULL; /* notify-here */
01917d
+}
01917d
+
01917d
+int
01917d
+main (void)
01917d
+{
01917d
+  void *h;
01917d
+  void (*fp) (void (*) (void));
01917d
+
01917d
+  assert (filename != NULL);
01917d
+  h = dlopen (filename, RTLD_LAZY);
01917d
+  assert (h != NULL);
01917d
+
01917d
+  fp = dlsym (h, "f");
01917d
+  assert (fp != NULL);
01917d
+
01917d
+  fp (notify);
01917d
+
01917d
+  return 0;
01917d
+}
01917d
Index: gdb-7.6/gdb/testsuite/gdb.threads/dlopen-libpthread.exp
01917d
===================================================================
01917d
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
01917d
+++ gdb-7.6/gdb/testsuite/gdb.threads/dlopen-libpthread.exp	2013-06-10 14:30:18.087102375 +0200
01917d
@@ -0,0 +1,74 @@
01917d
+# Copyright 2011-2013 Free Software Foundation, Inc.
01917d
+#
01917d
+# This program is free software; you can redistribute it and/or modify
01917d
+# it under the terms of the GNU General Public License as published by
01917d
+# the Free Software Foundation; either version 3 of the License, or
01917d
+# (at your option) any later version.
01917d
+#
01917d
+# This program is distributed in the hope that it will be useful,
01917d
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
01917d
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
01917d
+# GNU General Public License for more details.
01917d
+#
01917d
+# You should have received a copy of the GNU General Public License
01917d
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
01917d
+
01917d
+if {![istarget *-linux*] || [skip_shlib_tests]} {
01917d
+    return 0
01917d
+}
01917d
+
01917d
+load_lib prelink-support.exp
01917d
+
01917d
+set testfile "dlopen-libpthread"
01917d
+set srcmainfile ${testfile}.c
01917d
+set srclibfile ${testfile}-lib.c
01917d
+set executable ${testfile}
01917d
+set binfile_lib ${objdir}/${subdir}/${executable}.so
01917d
+set binfile ${objdir}/${subdir}/${executable}
01917d
+set lib_dlopen [shlib_target_file ${executable}.so]
01917d
+
01917d
+# Use build_executable_own_libs as prelinked libpthread.so can produce false
01917d
+# PASS - it is OK if GDB processes it still before relocation.
01917d
+
01917d
+set relink_args [build_executable_own_libs ${testfile}.exp ${executable}.so $srclibfile {debug shlib_pthreads} no]
01917d
+if {$relink_args == "" || ![prelink_no $relink_args]
01917d
+    || [prepare_for_testing ${testfile}.exp ${executable} ${srcmainfile} {debug shlib_load}] } {
01917d
+    return -1
01917d
+}
01917d
+gdb_load_shlibs $binfile_lib
01917d
+
01917d
+if { ![runto_main] } {
01917d
+    return -1
01917d
+}
01917d
+
01917d
+set test "info probes all rtld rtld_map_complete"
01917d
+gdb_test_multiple $test $test {
01917d
+    -re "\[ \t\]rtld_map_complete\[ \t\]+0x\[0-9a-f\]+.*\r\n$gdb_prompt $" {
01917d
+	pass $test
01917d
+    }
01917d
+    -re "No probes matched\\.\r\n$gdb_prompt $" {
01917d
+	xfail $test
01917d
+	untested ${testfile}.exp
01917d
+	return
01917d
+    }
01917d
+}
01917d
+
01917d
+set test "libpthread.so not found"
01917d
+gdb_test_multiple "info sharedlibrary" $test {
01917d
+    -re "/libpthread\\.so.*\r\n$gdb_prompt $" {
01917d
+	fail $test
01917d
+    }
01917d
+    -re "/libc\\.so.*\r\n$gdb_prompt $" {
01917d
+	pass $test
01917d
+    }
01917d
+}
01917d
+
01917d
+gdb_test "set variable filename=\"$lib_dlopen\""
01917d
+
01917d
+gdb_breakpoint "notify"
01917d
+
01917d
+# The error was:
01917d
+# Cannot find new threads: generic error
01917d
+gdb_continue_to_breakpoint "notify" ".* notify-here .*"
01917d
+
01917d
+gdb_test "info sharedlibrary" {/libpthread\.so.*} "libpthread.so found"
01917d
Index: gdb-7.6/gdb/testsuite/lib/gdb.exp
01917d
===================================================================
01917d
--- gdb-7.6.orig/gdb/testsuite/lib/gdb.exp	2013-06-10 14:29:24.819123940 +0200
01917d
+++ gdb-7.6/gdb/testsuite/lib/gdb.exp	2013-06-10 14:30:44.654092140 +0200
01917d
@@ -4011,22 +4011,6 @@ proc build_executable_from_specs {testna
01917d
 
01917d
     set binfile [standard_output_file $executable]
01917d
 
01917d
-    set objects {}
01917d
-    set i 0
01917d
-    foreach {s local_options} $args {
01917d
-        if  { [gdb_compile "${srcdir}/${subdir}/${s}" "${binfile}${i}.o" object $local_options] != "" } {
01917d
-            untested $testname
01917d
-            return -1
01917d
-        }
01917d
-        lappend objects "${binfile}${i}.o"
01917d
-	incr i
01917d
-    }
01917d
-    
01917d
-    if  { [gdb_compile $objects "${binfile}" executable $options] != "" } {
01917d
-        untested $testname
01917d
-        return -1
01917d
-    }
01917d
-
01917d
     set info_options ""
01917d
     if { [lsearch -exact $options "c++"] >= 0 } {
01917d
 	set info_options "c++"
01917d
@@ -4034,6 +4018,42 @@ proc build_executable_from_specs {testna
01917d
     if [get_compiler_info ${info_options}] {
01917d
         return -1
01917d
     }
01917d
+
01917d
+    set binfile [standard_output_file $executable]
01917d
+
01917d
+    set func gdb_compile
01917d
+    set func_index [lsearch -regexp $options {^(pthreads|shlib|shlib_pthreads)$}]
01917d
+    if {$func_index != -1} {
01917d
+	set func "${func}_[lindex $options $func_index]"
01917d
+    }
01917d
+
01917d
+    # gdb_compile_shlib and gdb_compile_shlib_pthreads do not use the 3rd
01917d
+    # parameter.  They also requires $sources while gdb_compile and
01917d
+    # gdb_compile_pthreads require $objects.  Moreover they ignore any options.
01917d
+    if [string match gdb_compile_shlib* $func] {
01917d
+	set sources_path {}
01917d
+	foreach {s local_options} $args {
01917d
+	    lappend sources_path "${srcdir}/${subdir}/${s}"
01917d
+	}
01917d
+	set ret [$func $sources_path "${binfile}" $options]
01917d
+    } else {
01917d
+	set objects {}
01917d
+	set i 0
01917d
+	foreach {s local_options} $args {
01917d
+	    if  { [gdb_compile "${srcdir}/${subdir}/${s}" "${binfile}${i}.o" object $local_options] != "" } {
01917d
+		untested $testname
01917d
+		return -1
01917d
+	    }
01917d
+	    lappend objects "${binfile}${i}.o"
01917d
+	    incr i
01917d
+	}
01917d
+	set ret [$func $objects "${binfile}" executable $options]
01917d
+    }
01917d
+    if  { $ret != "" } {
01917d
+        untested $testname
01917d
+        return -1
01917d
+    }
01917d
+
01917d
     return 0
01917d
 }
01917d
 
01917d
Index: gdb-7.6/gdb/testsuite/lib/prelink-support.exp
01917d
===================================================================
01917d
--- gdb-7.6.orig/gdb/testsuite/lib/prelink-support.exp	2013-06-10 14:29:24.819123940 +0200
01917d
+++ gdb-7.6/gdb/testsuite/lib/prelink-support.exp	2013-06-10 14:30:18.089102374 +0200
01917d
@@ -95,8 +95,9 @@ proc file_copy {src dest} {
01917d
 # Wrap function build_executable so that the resulting executable is fully
01917d
 # self-sufficient (without dependencies on system libraries).  Parameter
01917d
 # INTERP may be used to specify a loader (ld.so) to be used that is
01917d
-# different from the default system one.  Libraries on which the executable
01917d
-# depends are copied into directory DIR.  Default DIR value to
01917d
+# different from the default system one.  INTERP can be set to "no" if no ld.so
01917d
+# copy should be made.  Libraries on which the executable depends are copied
01917d
+# into directory DIR.  Default DIR value to
01917d
 # `${objdir}/${subdir}/${EXECUTABLE}.d'.
01917d
 #
01917d
 # In case of success, return a string containing the arguments to be used
01917d
@@ -151,8 +152,15 @@ proc build_executable_own_libs {testname
01917d
 
01917d
     if {$interp == ""} {
01917d
 	set interp_system [section_get $binfile .interp]
01917d
-	set interp ${dir}/[file tail $interp_system]
01917d
-	file_copy $interp_system $interp
01917d
+	if {$interp_system == ""} {
01917d
+	    fail "$test could not find .interp"
01917d
+	} else {
01917d
+	    set interp ${dir}/[file tail $interp_system]
01917d
+	    file_copy $interp_system $interp
01917d
+	}
01917d
+    }
01917d
+    if {$interp == "no"} {
01917d
+	set interp ""
01917d
     }
01917d
 
01917d
     set dests {}
01917d
@@ -164,13 +172,19 @@ proc build_executable_own_libs {testname
01917d
 
01917d
     # Do not lappend it so that "-rpath $dir" overrides any possible "-rpath"s
01917d
     # specified by the caller to be able to link it for ldd" above.
01917d
-    set options [linsert $options 0 "ldflags=-Wl,--dynamic-linker,$interp,-rpath,$dir"]
01917d
+    set options [linsert $options 0 "ldflags=-Wl,-rpath,$dir"]
01917d
+    if {$interp != ""} {
01917d
+	set options [linsert $options 0 "ldflags=-Wl,--dynamic-linker,$interp"]
01917d
+    }
01917d
 
01917d
     if {[build_executable $testname $executable $sources $options] == -1} {
01917d
 	return ""
01917d
     }
01917d
 
01917d
-    set prelink_args "--dynamic-linker=$interp --ld-library-path=$dir $binfile $interp [concat $dests]"
01917d
+    set prelink_args "--ld-library-path=$dir $binfile [concat $dests]"
01917d
+    if {$interp != ""} {
01917d
+	set prelink_args "--dynamic-linker=$interp $prelink_args $interp"
01917d
+    }
01917d
     return $prelink_args
01917d
 }
01917d