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

861f93
http://sourceware.org/ml/gdb-cvs/2013-06/msg00020.html
861f93
861f93
### src/gdb/testsuite/ChangeLog	2013/06/04 13:23:31	1.3683
861f93
### src/gdb/testsuite/ChangeLog	2013/06/04 13:31:00	1.3684
861f93
## -1,3 +1,13 @@
861f93
+2013-06-04  Gary Benson  <gbenson@redhat.com>
861f93
+
861f93
+	* gdb.base/break-probes.exp: New file.
861f93
+	* gdb.base/break-probes.c: Likewise.
861f93
+	* gdb.base/break-probes-solib.c: Likewise.
861f93
+	* gdb.base/info-shared.exp: New file.
861f93
+	* gdb.base/info-shared.c: Likewise.
861f93
+	* gdb.base/info-shared-solib1.c: Likewise.
861f93
+	* gdb.base/info-shared-solib2.c: Likewise.
861f93
+
861f93
 2013-06-04  Jan Kratochvil  <jan.kratochvil@redhat.com>
861f93
 	    Gary Benson  <gbenson@redhat.com>
861f93
 
861f93
--- src/gdb/testsuite/gdb.base/break-probes-solib.c
861f93
+++ src/gdb/testsuite/gdb.base/break-probes-solib.c	2013-06-10 12:15:11.548935413 +0000
861f93
@@ -0,0 +1,22 @@
861f93
+/* Copyright 2012-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 <stdio.h>
861f93
+
861f93
+int
861f93
+foo (int n)
861f93
+{
861f93
+  return n * n / 17;
861f93
+}
861f93
--- src/gdb/testsuite/gdb.base/break-probes.c
861f93
+++ src/gdb/testsuite/gdb.base/break-probes.c	2013-06-10 12:15:12.047717383 +0000
861f93
@@ -0,0 +1,30 @@
861f93
+/* Copyright 2012-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 <assert.h>
861f93
+#include <stddef.h>
861f93
+
861f93
+int
861f93
+main (void)
861f93
+{
861f93
+  void *handle = dlopen (SHLIB_NAME, RTLD_LAZY);
861f93
+
861f93
+  assert (handle != NULL);
861f93
+
861f93
+  dlclose (handle);
861f93
+
861f93
+  return 0;
861f93
+}
861f93
--- src/gdb/testsuite/gdb.base/break-probes.exp
861f93
+++ src/gdb/testsuite/gdb.base/break-probes.exp	2013-06-10 12:15:12.620368040 +0000
861f93
@@ -0,0 +1,78 @@
861f93
+# Copyright 2012-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 { [skip_shlib_tests] } {
861f93
+    return 0
861f93
+}
861f93
+
861f93
+standard_testfile
861f93
+
861f93
+set libname $testfile-solib
861f93
+set srcfile_lib $srcdir/$subdir/$libname.c
861f93
+set binfile_lib [standard_output_file $libname.so]
861f93
+
861f93
+set normal_bp "_dl_debug_state"
861f93
+set probes_bp "dl_main"
861f93
+
861f93
+if { [gdb_compile_shlib $srcfile_lib $binfile_lib \
861f93
+	  [list additional_flags=-fPIC]] != "" } {
861f93
+    untested "Could not compile $binfile_lib."
861f93
+    return -1
861f93
+}
861f93
+
861f93
+if { [prepare_for_testing $testfile.exp $testfile $srcfile \
861f93
+	  [list additional_flags=-DSHLIB_NAME=\"$binfile_lib\" libs=-ldl]] } {
861f93
+    return -1
861f93
+}
861f93
+
861f93
+# Enable stop-on-solib-events
861f93
+gdb_test_no_output "set stop-on-solib-events 1"
861f93
+
861f93
+# Start the inferior and run to the first stop
861f93
+gdb_run_cmd
861f93
+gdb_test "" ".*Stopped due to shared library event.*"
861f93
+
861f93
+# XFAIL if we are not using probes
861f93
+set test "ensure using probes"
861f93
+set using_probes 0
861f93
+gdb_test_multiple "bt" $test {
861f93
+    -re "#0 +\[^\r\n\]*\\m(__GI_)?$normal_bp\\M.*$gdb_prompt $" {
861f93
+	untested "probes not present on this system"
861f93
+    }
861f93
+    -re "#0 +\[^\r\n\]*\\m(__GI_)?$probes_bp\\M.*$gdb_prompt $" {
861f93
+	pass $test
861f93
+	set using_probes 1
861f93
+    }
861f93
+}
861f93
+
861f93
+if { $using_probes } {
861f93
+    # Run til it loads our library
861f93
+    set test "run til our library loads"
861f93
+    set not_loaded_library 1
861f93
+    while { $not_loaded_library } {
861f93
+	set not_loaded_library 0
861f93
+	gdb_test_multiple "c" $test {
861f93
+	    -re "Inferior loaded $binfile_lib\\M.*$gdb_prompt $" {
861f93
+		pass $test
861f93
+	    }
861f93
+	    -re "Stopped due to shared library event\\M.*$gdb_prompt $" {
861f93
+		set not_loaded_library 1
861f93
+	    }
861f93
+	}
861f93
+    }
861f93
+
861f93
+    # Call something to ensure that relocation occurred
861f93
+    gdb_test "call foo(23)" "\\\$.* = 31.*\\\M.*"
861f93
+}
861f93
--- src/gdb/testsuite/gdb.base/info-shared-solib1.c
861f93
+++ src/gdb/testsuite/gdb.base/info-shared-solib1.c	2013-06-10 12:15:14.399129288 +0000
861f93
@@ -0,0 +1,24 @@
861f93
+/* Copyright 2012-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 <stdio.h>
861f93
+
861f93
+int
861f93
+foo (int n)
861f93
+{
861f93
+  printf ("foo %d\n", n);
861f93
+
861f93
+  return 0;
861f93
+}
861f93
--- src/gdb/testsuite/gdb.base/info-shared-solib2.c
861f93
+++ src/gdb/testsuite/gdb.base/info-shared-solib2.c	2013-06-10 12:15:14.930135742 +0000
861f93
@@ -0,0 +1,24 @@
861f93
+/* Copyright 2012-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 <stdio.h>
861f93
+
861f93
+int
861f93
+bar (int n)
861f93
+{
861f93
+  printf ("bar %d\n", n);
861f93
+
861f93
+  return 0;
861f93
+}
861f93
--- src/gdb/testsuite/gdb.base/info-shared.c
861f93
+++ src/gdb/testsuite/gdb.base/info-shared.c	2013-06-10 12:15:15.395474819 +0000
861f93
@@ -0,0 +1,52 @@
861f93
+/* Copyright 2012-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 <assert.h>
861f93
+#include <stddef.h>
861f93
+
861f93
+void
861f93
+stop (void)
861f93
+{
861f93
+}
861f93
+
861f93
+int
861f93
+main (void)
861f93
+{
861f93
+  void *handle1, *handle2;
861f93
+  void (*func)(int);
861f93
+
861f93
+  handle1 = dlopen (SHLIB1_NAME, RTLD_LAZY);
861f93
+  assert (handle1 != NULL);
861f93
+  stop ();
861f93
+
861f93
+  handle2 = dlopen (SHLIB2_NAME, RTLD_LAZY);
861f93
+  assert (handle2 != NULL);
861f93
+  stop ();
861f93
+
861f93
+  func = (void (*)(int)) dlsym (handle1, "foo");
861f93
+  func (1);
861f93
+
861f93
+  func = (void (*)(int)) dlsym (handle2, "bar");
861f93
+  func (2);
861f93
+
861f93
+  dlclose (handle1);
861f93
+  stop ();
861f93
+
861f93
+  dlclose (handle2);
861f93
+  stop ();
861f93
+
861f93
+  return 0;
861f93
+}
861f93
--- src/gdb/testsuite/gdb.base/info-shared.exp
861f93
+++ src/gdb/testsuite/gdb.base/info-shared.exp	2013-06-10 12:15:15.891450285 +0000
861f93
@@ -0,0 +1,146 @@
861f93
+# Copyright 2012-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 { [skip_shlib_tests] } {
861f93
+    return 0
861f93
+}
861f93
+
861f93
+standard_testfile
861f93
+
861f93
+set lib1name $testfile-solib1
861f93
+set srcfile_lib1 $srcdir/$subdir/$lib1name.c
861f93
+set binfile_lib1 [standard_output_file $lib1name.so]
861f93
+set define1 -DSHLIB1_NAME=\"$binfile_lib1\"
861f93
+
861f93
+set lib2name $testfile-solib2
861f93
+set srcfile_lib2 $srcdir/$subdir/$lib2name.c
861f93
+set binfile_lib2 [standard_output_file $lib2name.so]
861f93
+set define2 -DSHLIB2_NAME=\"$binfile_lib2\"
861f93
+
861f93
+if { [gdb_compile_shlib $srcfile_lib1 $binfile_lib1 \
861f93
+	  [list additional_flags=-fPIC]] != "" } {
861f93
+    untested "Could not compile $binfile_lib1."
861f93
+    return -1
861f93
+}
861f93
+
861f93
+if { [gdb_compile_shlib $srcfile_lib2 $binfile_lib2 \
861f93
+	  [list additional_flags=-fPIC]] != "" } {
861f93
+    untested "Could not compile $binfile_lib2."
861f93
+    return -1
861f93
+}
861f93
+
861f93
+set cflags "$define1 $define2"
861f93
+if { [prepare_for_testing $testfile.exp $testfile $srcfile \
861f93
+	  [list additional_flags=$cflags libs=-ldl]] } {
861f93
+    return -1
861f93
+}
861f93
+
861f93
+# Run "info sharedlibrary" and check for the presence or absence of
861f93
+# our libraries.
861f93
+proc check_info_shared { test expect1 expect2 } {
861f93
+    global lib1name
861f93
+    global lib2name
861f93
+    global gdb_prompt
861f93
+
861f93
+    set actual1 0
861f93
+    set actual2 0
861f93
+
861f93
+    gdb_test_multiple "info sharedlibrary" $test {
861f93
+	-re $lib1name {
861f93
+	    set actual1 1
861f93
+	    exp_continue
861f93
+	}
861f93
+	-re $lib2name {
861f93
+	    set actual2 1
861f93
+	    exp_continue
861f93
+	}
861f93
+	-re "\r\n$gdb_prompt $" {
861f93
+	    if { $actual1 == $expect1 && $actual2 == $expect2 } {
861f93
+		pass $test
861f93
+	    } else {
861f93
+		fail $test
861f93
+	    }
861f93
+	}
861f93
+    }
861f93
+}
861f93
+
861f93
+# Start the inferior, and check neither of the libraries are loaded at
861f93
+# the start.
861f93
+if ![runto_main] {
861f93
+    return 0
861f93
+}
861f93
+check_info_shared "info sharedlibrary #1" 0 0
861f93
+
861f93
+# Set up breakpoints.
861f93
+gdb_breakpoint "stop"
861f93
+gdb_breakpoint "foo" allow-pending
861f93
+gdb_breakpoint "bar" allow-pending
861f93
+
861f93
+# Run to the first stop and check that only the first library is loaded.
861f93
+gdb_continue_to_breakpoint "library load #1" "stop .*"
861f93
+check_info_shared "info sharedlibrary #2" 1 0
861f93
+
861f93
+# Run to the second stop and check that both libraries are loaded.
861f93
+gdb_continue_to_breakpoint "library load #2" "stop .*"
861f93
+check_info_shared "info sharedlibrary #3" 1 1
861f93
+
861f93
+# Check that the next stop is in foo.
861f93
+gdb_continue_to_breakpoint "library function #1" "foo .*"
861f93
+
861f93
+# Check that the next stop is in bar.
861f93
+gdb_continue_to_breakpoint "library function #2" "bar .*"
861f93
+
861f93
+# Restart the inferior and make sure there are no breakpoint reset
861f93
+# errors.  These can happen with the probes-based runtime linker
861f93
+# interface if the cache is not cleared correctly.
861f93
+set test "restart"
861f93
+gdb_run_cmd
861f93
+gdb_test_multiple "" $test {
861f93
+    -re {Start it from the beginning\? \(y or n\) $} {
861f93
+	send_gdb "y\n"
861f93
+	exp_continue
861f93
+    }
861f93
+    -re {Error in re-setting breakpoint} {
861f93
+	fail $test
861f93
+    }
861f93
+    -re "\r\n$gdb_prompt $" {
861f93
+	pass $test
861f93
+    }
861f93
+}
861f93
+
861f93
+# Check that neither library is loaded.
861f93
+check_info_shared "info sharedlibrary #4" 0 0
861f93
+
861f93
+# Run to the first stop and check that only the first library is loaded.
861f93
+gdb_continue_to_breakpoint "library load #3" "stop .*"
861f93
+check_info_shared "info sharedlibrary #5" 1 0
861f93
+
861f93
+# Run to the second stop and check that both libraries are loaded.
861f93
+gdb_continue_to_breakpoint "library load #4" "stop .*"
861f93
+check_info_shared "info sharedlibrary #6" 1 1
861f93
+
861f93
+# Check that the next stop is in foo.
861f93
+gdb_continue_to_breakpoint "library function #3" "foo .*"
861f93
+
861f93
+# Check that the next stop is in bar.
861f93
+gdb_continue_to_breakpoint "library function #4" "bar .*"
861f93
+
861f93
+# Run to the next stop and check that the first library has been unloaded.
861f93
+gdb_continue_to_breakpoint "library unload #1" "stop .*"
861f93
+check_info_shared "info sharedlibrary #7" 0 1
861f93
+
861f93
+# Run to the last stop and check that both libraries are gone.
861f93
+gdb_continue_to_breakpoint "library unload #2" "stop .*"
861f93
+check_info_shared "info sharedlibrary #8" 0 0