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