Blame SOURCES/gdb-dlopen-stap-probe-8of9.patch

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