aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base
diff options
context:
space:
mode:
authorMarkus Metzger <markus.t.metzger@intel.com>2022-03-28 11:20:10 +0200
committerMarkus Metzger <markus.t.metzger@intel.com>2022-10-18 14:16:11 +0200
commitaebb370bae3f511df8afb68a01a79c54e2066650 (patch)
tree8e9e25276a2768eb2352ea514377f08c662c7c4f /gdb/testsuite/gdb.base
parent1dc9084f5e95fd9a1f2f0e9baf9c6e52c5a5ee29 (diff)
downloadgdb-aebb370bae3f511df8afb68a01a79c54e2066650.zip
gdb-aebb370bae3f511df8afb68a01a79c54e2066650.tar.gz
gdb-aebb370bae3f511df8afb68a01a79c54e2066650.tar.bz2
gdb, solib-svr4: support namespaces in DSO iteration
When looking up names, GDB needs to stay within one linker namespace to find the correct instance in case the same name is provided in more than one namespace. Modify svr4_iterate_over_objfiles_in_search_order() to stay within the namespace of the current_objfile argument. If no current_objfile is provided (i.e. it is nullptr), iterate over objfiles in the initial namespace. For objfiles that do not have a corresponding so_list to provide the namespace, assume that the objfile was loaded into the initial namespace. This would cover the main executable objfile (which is indeed loaded into the initial namespace) as well as manually added symbol files. Expected fails: - gdb.base/non-lazy-array-index.exp: the expression parser may lookup global symbols, which may result in xfers to read auxv for determining the debug base as part of svr4_iterate_over_objfiles_in_search_order(). - gdb.server/non-lazy-array-index.exp: symbol lookup may access the target to read AUXV in order to determine the debug base for SVR4 linker namespaces. Known issues: - get_symbol_address() and get_msymbol_address() search objfiles for a 'better' match. This was introduced by 4b610737f02 Handle copy relocations to handle copy relocations but it now causes a wrong address to be read after symbol lookup actually cound the correct symbol. This can be seen, for example, with gdb.base/dlmopen.exp when compiled with clang. - gnu ifuncs are only looked up in the initial namespace. - lookup_minimal_symbol() and lookup_minimal_symbol_text() directly iterate over objfiles and are not aware of linker namespaces.
Diffstat (limited to 'gdb/testsuite/gdb.base')
-rw-r--r--gdb/testsuite/gdb.base/dlmopen-lib-dep.c21
-rw-r--r--gdb/testsuite/gdb.base/dlmopen-lib.c5
-rw-r--r--gdb/testsuite/gdb.base/dlmopen.exp40
-rw-r--r--gdb/testsuite/gdb.base/non-lazy-array-index.exp18
4 files changed, 74 insertions, 10 deletions
diff --git a/gdb/testsuite/gdb.base/dlmopen-lib-dep.c b/gdb/testsuite/gdb.base/dlmopen-lib-dep.c
new file mode 100644
index 0000000..c996d76
--- /dev/null
+++ b/gdb/testsuite/gdb.base/dlmopen-lib-dep.c
@@ -0,0 +1,21 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2021-2022 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/>.
+
+*/
+
+__attribute__((visibility ("default")))
+int gdb_dlmopen_glob = 1;
diff --git a/gdb/testsuite/gdb.base/dlmopen-lib.c b/gdb/testsuite/gdb.base/dlmopen-lib.c
index 616bf97..4645bfd 100644
--- a/gdb/testsuite/gdb.base/dlmopen-lib.c
+++ b/gdb/testsuite/gdb.base/dlmopen-lib.c
@@ -17,9 +17,12 @@
*/
+extern int gdb_dlmopen_glob;
+
__attribute__((visibility ("default")))
int
inc (int n)
{
- return n + 1; /* bp.inc. */
+ int amount = gdb_dlmopen_glob;
+ return n + amount; /* bp.inc. */
}
diff --git a/gdb/testsuite/gdb.base/dlmopen.exp b/gdb/testsuite/gdb.base/dlmopen.exp
index 8e86d5d..a80db75 100644
--- a/gdb/testsuite/gdb.base/dlmopen.exp
+++ b/gdb/testsuite/gdb.base/dlmopen.exp
@@ -32,13 +32,22 @@ set basename_lib dlmopen-lib
set srcfile_lib $srcdir/$subdir/$basename_lib.c
set binfile_lib1 [standard_output_file $basename_lib.1.so]
set binfile_lib2 [standard_output_file $basename_lib.2.so]
+set srcfile_lib_dep $srcdir/$subdir/$basename_lib-dep.c
+set binfile_lib_dep [standard_output_file $basename_lib-dep.so]
-if { [gdb_compile_shlib $srcfile_lib $binfile_lib1 {debug}] != "" } {
+if { [gdb_compile_shlib $srcfile_lib_dep $binfile_lib_dep {debug}] != "" } {
untested "failed to prepare shlib"
return -1
}
-if { [gdb_compile_shlib $srcfile_lib $binfile_lib2 {debug}] != "" } {
+if { [gdb_compile_shlib $srcfile_lib $binfile_lib1 \
+ [list debug shlib_load libs=$binfile_lib_dep]] != "" } {
+ untested "failed to prepare shlib"
+ return -1
+}
+
+if { [gdb_compile_shlib $srcfile_lib $binfile_lib2 \
+ [list debug shlib_load libs=$binfile_lib_dep]] != "" } {
untested "failed to prepare shlib"
return -1
}
@@ -46,7 +55,7 @@ if { [gdb_compile_shlib $srcfile_lib $binfile_lib2 {debug}] != "" } {
if { [prepare_for_testing "failed to prepare" $testfile $srcfile \
[list additional_flags=-DDSO1_NAME=\"$binfile_lib1\" \
additional_flags=-DDSO2_NAME=\"$binfile_lib2\" \
- libs=-ldl debug]] } {
+ shlib_load debug]] } {
return -1
}
@@ -73,7 +82,7 @@ proc check_dso_count { dso num } {
}
# The DSO part of the test. We run it once per DSO call.
-proc test_dlmopen_one { ndso1 ndso2 } {
+proc test_dlmopen_one { ndso1 ndso2 exp_glob } {
global srcfile_lib srcfile_lib basename_lib bp_inc
# Try to reach the breakpoint in the dynamically loaded library.
@@ -87,16 +96,31 @@ proc test_dlmopen_one { ndso1 ndso2 } {
# This might help debugging.
gdb_test "info breakpoints" ".*"
gdb_test "print \$pc" ".*"
+
+ # We expect different instances of GDB_DLMOPEN_GLOB per DSO.
+ gdb_test "print amount" "= $exp_glob"
+ gdb_test "print gdb_dlmopen_glob" "= $exp_glob"
+
+ # Modify that DSO's instance, which should leave the others intact.
+ gdb_test "print &gdb_dlmopen_glob" "= .*"
+ gdb_test "print gdb_dlmopen_glob = -1" "= -1"
}
# The actual test. We run it twice.
proc test_dlmopen {} {
global srcfile basename_lib bp_main
- with_test_prefix "dlmopen 1" { test_dlmopen_one 3 1 }
- with_test_prefix "dlmopen 2" { test_dlmopen_one 2 1 }
- with_test_prefix "dlmopen 3" { test_dlmopen_one 1 1 }
- with_test_prefix "dlmopen 4" { test_dlmopen_one 0 1 }
+ # Note that when loading dlmopen-lib.1.so and dlmopen-lib.2.so into
+ # the same namespace, dlmopen-lib-dep.so is loaded only once, so in
+ # this case, the changes to gdb_dlmopen_glob inside test_dlmopen_one
+ # will actually be visible.
+ #
+ # Hence, we supply the expected value of this variable as argument to
+ # test_dlmopen_one.
+ with_test_prefix "dlmopen 1" { test_dlmopen_one 3 1 1 }
+ with_test_prefix "dlmopen 2" { test_dlmopen_one 2 1 1 }
+ with_test_prefix "dlmopen 3" { test_dlmopen_one 1 1 1 }
+ with_test_prefix "dlmopen 4" { test_dlmopen_one 0 1 -1 }
with_test_prefix "main" {
# Try to reach the breakpoint in the dynamically loaded library.
diff --git a/gdb/testsuite/gdb.base/non-lazy-array-index.exp b/gdb/testsuite/gdb.base/non-lazy-array-index.exp
index 6b596eb..66686cf 100644
--- a/gdb/testsuite/gdb.base/non-lazy-array-index.exp
+++ b/gdb/testsuite/gdb.base/non-lazy-array-index.exp
@@ -40,6 +40,7 @@ gdb_test_no_output "set debug target 1"
# To check this we 'set debug target 1' (above), and then look for any
# xfer_partial calls; there shouldn't be any.
set saw_memory_access false
+set saw_auxv_parse false
gdb_test_multiple "p \$.array\[1\]" "" {
-re "^p \\\$\\.array\\\[1\\\]\r\n" {
exp_continue
@@ -48,6 +49,10 @@ gdb_test_multiple "p \$.array\[1\]" "" {
set saw_memory_access true
exp_continue
}
+ -re "^->\[^\r\n\]+auxv_parse\[^\r\n\]+\r\n" {
+ set saw_auxv_parse true
+ exp_continue
+ }
-re "^->\[^\r\n\]+\r\n" {
exp_continue
}
@@ -58,7 +63,18 @@ gdb_test_multiple "p \$.array\[1\]" "" {
exp_continue
}
-re "^\\\$${decimal} = 2\r\n$gdb_prompt " {
- gdb_assert { ! $saw_memory_access }
+ if { $saw_memory_access } {
+ if { $saw_auxv_parse } {
+ # The expression parser may look up global symbols, which
+ # may require reading AUXV in order to determine the debug
+ # base for SVR4 linker namespaces.
+ xfail "$gdb_test_name"
+ } else {
+ fail "$gdb_test_name"
+ }
+ } else {
+ pass "$gdb_test_name"
+ }
}
}