2018-01-01 05:43:02 +01:00
|
|
|
# Copyright 2012-2018 Free Software Foundation, Inc.
|
2013-06-04 15:31:00 +02:00
|
|
|
|
|
|
|
# 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/>.
|
|
|
|
|
|
|
|
if { [skip_shlib_tests] } {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
standard_testfile
|
|
|
|
|
|
|
|
set lib1name $testfile-solib1
|
|
|
|
set srcfile_lib1 $srcdir/$subdir/$lib1name.c
|
|
|
|
set binfile_lib1 [standard_output_file $lib1name.so]
|
|
|
|
set define1 -DSHLIB1_NAME=\"$binfile_lib1\"
|
|
|
|
|
|
|
|
set lib2name $testfile-solib2
|
|
|
|
set srcfile_lib2 $srcdir/$subdir/$lib2name.c
|
|
|
|
set binfile_lib2 [standard_output_file $lib2name.so]
|
|
|
|
set define2 -DSHLIB2_NAME=\"$binfile_lib2\"
|
|
|
|
|
|
|
|
if { [gdb_compile_shlib $srcfile_lib1 $binfile_lib1 \
|
|
|
|
[list additional_flags=-fPIC]] != "" } {
|
2016-12-01 21:47:50 +01:00
|
|
|
untested "failed to compile shared library 1"
|
2013-06-04 15:31:00 +02:00
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
|
|
|
if { [gdb_compile_shlib $srcfile_lib2 $binfile_lib2 \
|
|
|
|
[list additional_flags=-fPIC]] != "" } {
|
2016-12-01 21:47:50 +01:00
|
|
|
untested "failed to compile shared library 2"
|
2013-06-04 15:31:00 +02:00
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
|
|
|
set cflags "$define1 $define2"
|
2016-12-23 17:52:18 +01:00
|
|
|
if { [prepare_for_testing "failed to prepare" $testfile $srcfile \
|
2018-04-24 16:14:14 +02:00
|
|
|
[list additional_flags=$cflags shlib_load]] } {
|
2013-06-04 15:31:00 +02:00
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
|
|
|
# Run "info sharedlibrary" and check for the presence or absence of
|
|
|
|
# our libraries.
|
|
|
|
proc check_info_shared { test expect1 expect2 } {
|
|
|
|
global lib1name
|
|
|
|
global lib2name
|
|
|
|
global gdb_prompt
|
|
|
|
|
|
|
|
set actual1 0
|
|
|
|
set actual2 0
|
|
|
|
|
|
|
|
gdb_test_multiple "info sharedlibrary" $test {
|
|
|
|
-re $lib1name {
|
|
|
|
set actual1 1
|
|
|
|
exp_continue
|
|
|
|
}
|
|
|
|
-re $lib2name {
|
|
|
|
set actual2 1
|
|
|
|
exp_continue
|
|
|
|
}
|
|
|
|
-re "\r\n$gdb_prompt $" {
|
|
|
|
if { $actual1 == $expect1 && $actual2 == $expect2 } {
|
|
|
|
pass $test
|
|
|
|
} else {
|
|
|
|
fail $test
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Start the inferior, and check neither of the libraries are loaded at
|
|
|
|
# the start.
|
|
|
|
if ![runto_main] {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
check_info_shared "info sharedlibrary #1" 0 0
|
|
|
|
|
|
|
|
# Set up breakpoints.
|
|
|
|
gdb_breakpoint "stop"
|
|
|
|
gdb_breakpoint "foo" allow-pending
|
|
|
|
gdb_breakpoint "bar" allow-pending
|
|
|
|
|
|
|
|
# Run to the first stop and check that only the first library is loaded.
|
2014-01-28 18:31:23 +01:00
|
|
|
gdb_continue_to_breakpoint "library load #1" "\\.?stop .*"
|
2013-06-04 15:31:00 +02:00
|
|
|
check_info_shared "info sharedlibrary #2" 1 0
|
|
|
|
|
|
|
|
# Run to the second stop and check that both libraries are loaded.
|
2014-01-28 18:31:23 +01:00
|
|
|
gdb_continue_to_breakpoint "library load #2" "\\.?stop .*"
|
2013-06-04 15:31:00 +02:00
|
|
|
check_info_shared "info sharedlibrary #3" 1 1
|
|
|
|
|
|
|
|
# Check that the next stop is in foo.
|
2014-01-28 18:31:23 +01:00
|
|
|
gdb_continue_to_breakpoint "library function #1" "\\.?foo .*"
|
2013-06-04 15:31:00 +02:00
|
|
|
|
|
|
|
# Check that the next stop is in bar.
|
2014-01-28 18:31:23 +01:00
|
|
|
gdb_continue_to_breakpoint "library function #2" "\\.?bar .*"
|
2013-06-04 15:31:00 +02:00
|
|
|
|
|
|
|
# Restart the inferior and make sure there are no breakpoint reset
|
|
|
|
# errors. These can happen with the probes-based runtime linker
|
|
|
|
# interface if the cache is not cleared correctly.
|
|
|
|
set test "restart"
|
|
|
|
gdb_run_cmd
|
|
|
|
gdb_test_multiple "" $test {
|
|
|
|
-re {Start it from the beginning\? \(y or n\) $} {
|
|
|
|
send_gdb "y\n"
|
|
|
|
exp_continue
|
|
|
|
}
|
|
|
|
-re {Error in re-setting breakpoint} {
|
|
|
|
fail $test
|
|
|
|
}
|
|
|
|
-re "\r\n$gdb_prompt $" {
|
|
|
|
pass $test
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check that neither library is loaded.
|
|
|
|
check_info_shared "info sharedlibrary #4" 0 0
|
|
|
|
|
|
|
|
# Run to the first stop and check that only the first library is loaded.
|
2014-01-28 18:31:23 +01:00
|
|
|
gdb_continue_to_breakpoint "library load #3" "\\.?stop .*"
|
2013-06-04 15:31:00 +02:00
|
|
|
check_info_shared "info sharedlibrary #5" 1 0
|
|
|
|
|
|
|
|
# Run to the second stop and check that both libraries are loaded.
|
2014-01-28 18:31:23 +01:00
|
|
|
gdb_continue_to_breakpoint "library load #4" "\\.?stop .*"
|
2013-06-04 15:31:00 +02:00
|
|
|
check_info_shared "info sharedlibrary #6" 1 1
|
|
|
|
|
|
|
|
# Check that the next stop is in foo.
|
2014-01-28 18:31:23 +01:00
|
|
|
gdb_continue_to_breakpoint "library function #3" "\\.?foo .*"
|
2013-06-04 15:31:00 +02:00
|
|
|
|
|
|
|
# Check that the next stop is in bar.
|
2014-01-28 18:31:23 +01:00
|
|
|
gdb_continue_to_breakpoint "library function #4" "\\.?bar .*"
|
2013-06-04 15:31:00 +02:00
|
|
|
|
|
|
|
# Run to the next stop and check that the first library has been unloaded.
|
2014-01-28 18:31:23 +01:00
|
|
|
gdb_continue_to_breakpoint "library unload #1" "\\.?stop .*"
|
2013-06-04 15:31:00 +02:00
|
|
|
check_info_shared "info sharedlibrary #7" 0 1
|
|
|
|
|
|
|
|
# Run to the last stop and check that both libraries are gone.
|
2014-01-28 18:31:23 +01:00
|
|
|
gdb_continue_to_breakpoint "library unload #2" "\\.?stop .*"
|
2013-06-04 15:31:00 +02:00
|
|
|
check_info_shared "info sharedlibrary #8" 0 0
|