* 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.
This commit is contained in:
Doug Evans 2013-05-06 22:20:18 +00:00
parent 0892cb63bd
commit b903e17e96
6 changed files with 355 additions and 0 deletions

View File

@ -1,5 +1,11 @@
2013-05-06 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.
* lib/gdb.exp (gdb_core_cmd): New function.
* gdb.arch/system-gcore.exp: Use it.
* gdb.arch/vsx-regs.exp: Ditto.

View File

@ -0,0 +1,51 @@
/* 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 ();
}
/* Make the relative address of func3 different b/w the "wrong" and "right"
versions of the library" to further ensure backtrace doesn't work with
the "wrong" version. */
#ifdef RIGHT
void
lib1_spacer (void)
{
}
#endif
void
lib1_func3 (void)
{
lib2_func4 ();
}

View File

@ -0,0 +1,51 @@
/* 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 ();
}
/* Make the relative address of func4 different b/w the "wrong" and "right"
versions of the library" to further ensure backtrace doesn't work with
the "wrong" version. */
#ifdef RIGHT
void
lib2_spacer (void)
{
}
#endif
void
lib2_func4 (void)
{
break_here ();
}

View File

@ -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 ()
{
}

View File

@ -0,0 +1,184 @@
# 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 lib_flags [list debug ldflags=-Wl,-Bsymbolic]
set wrong_lib_flags "$lib_flags additional_flags=-DARRAY_SIZE=1"
set right_lib_flags "$lib_flags additional_flags=-DARRAY_SIZE=8192 -DRIGHT"
# 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_lib_flags] != ""
|| [gdb_compile_shlib ${srcfile2_lib} ${wrong_binfile2_lib} $wrong_lib_flags] != ""
|| [gdb_compile_shlib ${srcfile1_lib} ${right_binfile1_lib} $right_lib_flags] != ""
|| [gdb_compile_shlib ${srcfile2_lib} ${right_binfile2_lib} $right_lib_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 the backtrace output is correct the test 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"

View File

@ -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 */