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