This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[patch] Test solib-search-path
- From: Doug Evans <dje at google dot com>
- To: gdb-patches at sourceware dot org
- Date: Mon, 22 Apr 2013 16:24:48 -0700
- Subject: [patch] Test solib-search-path
Hi.
This patch tests solib-search-path, and in particular
the patch posted here:
http://sourceware.org/ml/gdb-patches/2013-04/msg00388.html
It requires this patch:
http://sourceware.org/ml/gdb-patches/2013-04/msg00674.html
I will check this in in a few days if there are no objections.
2013-04-22 Doug Evans <dje@google.com>
* gdb.base/solib-search-lib1.c: New file.
* gdb.base/solib-search-lib2.c: New file.
* gdb.base/solib-search.c: New file.
* gdb.base/solib-search.h: New file.
* gdb.base/solib-search.exp: New file.
Index: gdb.base/solib-search-lib1.c
===================================================================
RCS file: gdb.base/solib-search-lib1.c
diff -N gdb.base/solib-search-lib1.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gdb.base/solib-search-lib1.c 22 Apr 2013 23:18:54 -0000
@@ -0,0 +1,38 @@
+/* This test program is part of GDB, the GNU debugger.
+
+ Copyright 2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "solib-search.h"
+
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE 1
+#endif
+
+const int lib1_array[ARRAY_SIZE] = { 42 };
+const int lib1_size = ARRAY_SIZE;
+
+void
+lib1_func1 (void)
+{
+ lib2_func2 ();
+}
+
+void
+lib1_func3 (void)
+{
+ lib2_func4 ();
+}
Index: gdb.base/solib-search-lib2.c
===================================================================
RCS file: gdb.base/solib-search-lib2.c
diff -N gdb.base/solib-search-lib2.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gdb.base/solib-search-lib2.c 22 Apr 2013 23:18:54 -0000
@@ -0,0 +1,38 @@
+/* This test program is part of GDB, the GNU debugger.
+
+ Copyright 2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "solib-search.h"
+
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE 1
+#endif
+
+const int lib2_array[ARRAY_SIZE] = { 42 };
+const int lib2_size = ARRAY_SIZE;
+
+void
+lib2_func2 (void)
+{
+ lib1_func3 ();
+}
+
+void
+lib2_func4 (void)
+{
+ break_here ();
+}
Index: gdb.base/solib-search.c
===================================================================
RCS file: gdb.base/solib-search.c
diff -N gdb.base/solib-search.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gdb.base/solib-search.c 22 Apr 2013 23:18:54 -0000
@@ -0,0 +1,31 @@
+/* This test program is part of GDB, the GNU debugger.
+
+ Copyright 2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "solib-search.h"
+
+int
+main ()
+{
+ lib1_func1 ();
+ return 0;
+}
+
+void
+break_here ()
+{
+}
Index: gdb.base/solib-search.exp
===================================================================
RCS file: gdb.base/solib-search.exp
diff -N gdb.base/solib-search.exp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gdb.base/solib-search.exp 22 Apr 2013 23:18:54 -0000
@@ -0,0 +1,191 @@
+# Copyright 2013 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test solib-search-path, and in the case of solib-svr4.c whether l_addr_p
+# is properly reset when the path is changed.
+
+if {[is_remote target] || [skip_shlib_tests]} {
+ untested solib-search.exp
+ return -1
+}
+
+# This is required by gdb_compile_shlib.
+if {[get_compiler_info]} {
+ warning "Could not get compiler info"
+ untested solib-search.exp
+ return 1
+}
+
+# Build "wrong" and "right" versions of the libraries in separate directories.
+set wrong_lib_subdir "solib-search-wrong"
+set right_lib_subdir "solib-search-right"
+
+# First library file.
+set libname1 "solib-search-lib1"
+set srcfile1_lib ${srcdir}/${subdir}/${libname1}.c
+set wrong_binfile1_lib ${objdir}/${subdir}/${wrong_lib_subdir}/${libname1}.so
+set right_binfile1_lib ${objdir}/${subdir}/${right_lib_subdir}/${libname1}.so
+# Second library file.
+set libname2 "solib-search-lib2"
+set srcfile2_lib ${srcdir}/${subdir}/${libname2}.c
+set wrong_binfile2_lib ${objdir}/${subdir}/${wrong_lib_subdir}/${libname2}.so
+set right_binfile2_lib ${objdir}/${subdir}/${right_lib_subdir}/${libname2}.so
+# Link with the library that lives here.
+# This is so that we can replace what gdb sees with the wrong copy,
+# and then tell gdb to use the right copy that lives someplace else.
+set binfile1_lib ${objdir}/${subdir}/${libname1}.so
+set binfile2_lib ${objdir}/${subdir}/${libname2}.so
+
+# Set soname so that the path to the correct library is not hardcoded
+# in the executable.
+set lib1_flags "" ;#"ldflags=-Wl,-soname,${libname1}.so"
+set lib2_flags "" ;#"ldflags=-Wl,-soname,${libname2}.so"
+set lib_flags [list debug ldflags=-Wl,-Bsymbolic]
+set wrong_lib_flags "$lib_flags additional_flags=-DARRAY_SIZE=1"
+set wrong_lib1_flags "$wrong_lib_flags $lib1_flags"
+set wrong_lib2_flags "$wrong_lib_flags $lib2_flags"
+set right_lib_flags "$lib_flags additional_flags=-DARRAY_SIZE=8192"
+set right_lib1_flags "$right_lib_flags $lib1_flags"
+set right_lib2_flags "$right_lib_flags $lib2_flags"
+
+# Binary file.
+set testfile "solib-search"
+set srcfile ${srcdir}/${subdir}/${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
+set bin_flags [list debug shlib=${binfile1_lib} shlib=${binfile2_lib}]
+
+remote_exec build "rm -rf ${subdir}/${wrong_lib_subdir}"
+remote_exec build "rm -rf ${subdir}/${right_lib_subdir}"
+remote_exec build "mkdir ${subdir}/${wrong_lib_subdir}"
+remote_exec build "mkdir ${subdir}/${right_lib_subdir}"
+
+if { [gdb_compile_shlib ${srcfile1_lib} ${wrong_binfile1_lib} $wrong_lib1_flags] != ""
+ || [gdb_compile_shlib ${srcfile2_lib} ${wrong_binfile2_lib} $wrong_lib2_flags] != ""
+ || [gdb_compile_shlib ${srcfile1_lib} ${right_binfile1_lib} $right_lib1_flags] != ""
+ || [gdb_compile_shlib ${srcfile2_lib} ${right_binfile2_lib} $right_lib2_flags] != "" } {
+ untested "Could not compile libs."
+ return -1
+}
+
+# Build the test binary using the right copies of the libraries.
+remote_exec build "ln -sf ${right_lib_subdir}/${libname1}.so ${binfile1_lib}"
+remote_exec build "ln -sf ${right_lib_subdir}/${libname2}.so ${binfile2_lib}"
+if { [gdb_compile ${srcfile} ${binfile} executable $bin_flags] != "" } {
+ untested "Could not compile $binfile."
+ return -1
+}
+
+clean_restart $testfile
+
+if { ![runto_main] } {
+ fail "Can't run to main"
+ return
+}
+
+gdb_breakpoint "break_here"
+gdb_continue "break_here"
+
+set corefile "${objdir}/${subdir}/solib-search.core"
+set core_supported [gdb_gcore_cmd "$corefile" "save a corefile"]
+
+if {!$core_supported} {
+ return -1
+}
+
+# Before we restart gdb, replace the libs with the "wrong" ones.
+remote_exec build "ln -sf ${wrong_lib_subdir}/${libname1}.so ${binfile1_lib}"
+remote_exec build "ln -sf ${wrong_lib_subdir}/${libname2}.so ${binfile2_lib}"
+
+clean_restart $testfile
+
+set core_loaded [gdb_core_cmd $corefile "re-load generated corefile"]
+if { $core_loaded == -1 } {
+ # No use proceeding from here.
+ return
+}
+
+proc test_backtrace { expect_fail } {
+ global gdb_prompt
+
+ set count 0
+ set total_expected 5
+
+ if { $expect_fail } {
+ set testname "backtrace (with wrong libs)"
+ } else {
+ set testname "backtrace (with right libs)"
+ }
+ # N.B. The order of the tests here is important.
+ # We need to count each function in the backtrace, and expect matches
+ # the first one it finds.
+ gdb_test_multiple "backtrace" $testname {
+ -re "\[^\r\n\]* in lib2_func4 \[^\r\n\]*" {
+ incr count
+ exp_continue
+ }
+ -re "\[^\r\n\]* in lib1_func3 \[^\r\n\]*" {
+ incr count
+ exp_continue
+ }
+ -re "\[^\r\n\]* in lib2_func2 \[^\r\n\]*" {
+ incr count
+ exp_continue
+ }
+ -re "\[^\r\n\]* in lib1_func1 \[^\r\n\]*" {
+ incr count
+ exp_continue
+ }
+ -re "\[^\r\n\]* in main \[^\r\n\]*" {
+ incr count
+ exp_continue
+ }
+ -re "\[\r\n\]$gdb_prompt $" {
+ pass "$testname (data collection)"
+ }
+ }
+
+ set fail 0
+ if { $expect_fail } {
+ # If this works the testcase isn't sufficiently testing what it should.
+ if { $count == $total_expected } {
+ set fail 1
+ }
+ } else {
+ if { $count != $total_expected } {
+ set fail 1
+ }
+ }
+ if { $fail } {
+ fail $testname
+ } else {
+ pass $testname
+ }
+}
+
+# Verify the backtrace is messed up.
+test_backtrace 1
+
+# Remove the copies gdb currently sees: the absolute path is encoded in
+# the core file and we want gdb to find the right copies elsewhere.
+remote_exec build "rm -f ${binfile1_lib}"
+remote_exec build "rm -f ${binfile2_lib}"
+# Set solib-search-path to use the correct copies of libraries.
+gdb_test "set solib-search-path ${objdir}/${subdir}/${right_lib_subdir}"
+
+# Verify gdb has properly updated the location of the libraries.
+test_backtrace 0
+gdb_test "p lib1_size" " = 8192"
+gdb_test "p lib2_size" " = 8192"
+
Index: gdb.base/solib-search.h
===================================================================
RCS file: gdb.base/solib-search.h
diff -N gdb.base/solib-search.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gdb.base/solib-search.h 22 Apr 2013 23:18:54 -0000
@@ -0,0 +1,32 @@
+/* This test program is part of GDB, the GNU debugger.
+
+ Copyright 2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GDB_BASE_SOLIB_SEARCH_H
+#define GDB_BASE_SOLIB_SEARCH_H
+
+/* These functions create a call chain that traverses both libs. */
+
+extern void lib1_func1 (void);
+extern void lib1_func3 (void);
+
+extern void lib2_func2 (void);
+extern void lib2_func4 (void);
+
+extern void break_here (void);
+
+#endif /* GDB_BASE_SOLIB_SEARCH_H */