1# Copyright 2012-2019 Free Software Foundation, Inc. 2 3# This program is free software; you can redistribute it and/or modify 4# it under the terms of the GNU General Public License as published by 5# the Free Software Foundation; either version 3 of the License, or 6# (at your option) any later version. 7# 8# This program is distributed in the hope that it will be useful, 9# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# GNU General Public License for more details. 12# 13# You should have received a copy of the GNU General Public License 14# along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16if { [skip_shlib_tests] } { 17 return 0 18} 19 20standard_testfile 21 22set libname $testfile-solib 23set srcfile_lib $srcdir/$subdir/$libname.c 24set binfile_lib [standard_output_file $libname.so] 25 26if { [istarget "*bsd*"] } { 27 set normal_bp "r_debug_state" 28} else { 29 set normal_bp "_dl_debug_state" 30} 31set probes_bp "dl_main" 32 33if { [gdb_compile_shlib $srcfile_lib $binfile_lib \ 34 [list additional_flags=-fPIC]] != "" } { 35 untested "failed to compile shared library" 36 return -1 37} 38 39if { [prepare_for_testing "failed to prepare" $testfile $srcfile \ 40 [list debug shlib_load additional_flags=-DSHLIB_NAME=\"$binfile_lib\"]] } { 41 return -1 42} 43 44# Enable stop-on-solib-events 45gdb_test_no_output "set stop-on-solib-events 1" 46 47# Start the inferior and run to the first stop 48gdb_run_cmd 49gdb_test "" ".*Stopped due to shared library event.*" 50 51# XFAIL if we are not using probes 52set test "ensure using probes" 53set using_probes 0 54gdb_test_multiple "bt" $test { 55 -re "#0 +\[^\r\n\]*\\m(__GI_)?$normal_bp\\M.*$gdb_prompt $" { 56 untested "probes not present on this system" 57 } 58 -re "#0 +\[^\r\n\]*\\m(__GI_)?$probes_bp\\M.*$gdb_prompt $" { 59 pass $test 60 set using_probes 1 61 } 62} 63 64if { $using_probes } { 65 set sysroot "" 66 set test "show sysroot" 67 gdb_test_multiple $test $test { 68 -re "The current system root is \"(.*)\"\..*${gdb_prompt} $" { 69 set sysroot $expect_out(1,string) 70 } 71 } 72 73 # GDB strips "target:" from the start of filenames 74 # when operating on the local filesystem 75 regsub "^target:" "$sysroot" "(target:)?" sysroot 76 77 # Run til it loads our library 78 set test "run til our library loads" 79 set not_loaded_library 1 80 while { $not_loaded_library } { 81 set not_loaded_library 0 82 gdb_test_multiple "c" $test { 83 -re "Inferior loaded $sysroot$binfile_lib\\M.*$gdb_prompt $" { 84 pass $test 85 } 86 -re "Stopped due to shared library event\\M.*$gdb_prompt $" { 87 set not_loaded_library 1 88 } 89 } 90 } 91 92 # Call something to ensure that relocation occurred 93 gdb_test "call (int) foo(23)" "\\\$.* = 31.*\\\M.*" 94} 95