1 # Copyright 2012-2024 Free Software Foundation, Inc.
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.
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.
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/>.
16 require allow_shlib_tests
20 set lib1name $testfile-solib1
21 set srcfile_lib1 $srcdir/$subdir/$lib1name.c
22 set binfile_lib1 [standard_output_file $lib1name.so]
24 set lib2name $testfile-solib2
25 set srcfile_lib2 $srcdir/$subdir/$lib2name.c
26 set binfile_lib2 [standard_output_file $lib2name.so]
28 if { [gdb_compile_shlib $srcfile_lib1 $binfile_lib1 {}] != "" } {
29 untested "failed to compile shared library 1"
33 if { [gdb_compile_shlib $srcfile_lib2 $binfile_lib2 {}] != "" } {
34 untested "failed to compile shared library 2"
38 set binfile_lib1_target [gdb_download_shlib $binfile_lib1]
39 set binfile_lib2_target [gdb_download_shlib $binfile_lib2]
41 set define2 -DSHLIB2_NAME=\"$binfile_lib2_target\"
42 set define1 -DSHLIB1_NAME=\"$binfile_lib1_target\"
44 set cflags "$define1 $define2"
45 if { [prepare_for_testing "failed to prepare" $testfile $srcfile \
46 [list additional_flags=$cflags shlib_load]] } {
50 gdb_locate_shlib $binfile_lib1
51 gdb_locate_shlib $binfile_lib2
53 # Run "info sharedlibrary" and check for the presence or absence of
55 proc check_info_shared { test expect1 expect2 } {
63 gdb_test_multiple "info sharedlibrary" $test {
72 -re "\r\n$gdb_prompt $" {
73 if { $actual1 == $expect1 && $actual2 == $expect2 } {
82 # Start the inferior, and check neither of the libraries are loaded at
87 check_info_shared "info sharedlibrary #1" 0 0
91 gdb_breakpoint "foo" allow-pending
92 gdb_breakpoint "bar" allow-pending
94 # Run to the first stop and check that only the first library is loaded.
95 gdb_continue_to_breakpoint "library load #1" "\\.?stop .*"
96 check_info_shared "info sharedlibrary #2" 1 0
98 # Run to the second stop and check that both libraries are loaded.
99 gdb_continue_to_breakpoint "library load #2" "\\.?stop .*"
100 check_info_shared "info sharedlibrary #3" 1 1
102 # Check that the next stop is in foo.
103 gdb_continue_to_breakpoint "library function #1" "\\.?foo .*"
105 # Check that the next stop is in bar.
106 gdb_continue_to_breakpoint "library function #2" "\\.?bar .*"
108 # Restart the inferior and make sure there are no breakpoint reset
109 # errors. These can happen with the probes-based runtime linker
110 # interface if the cache is not cleared correctly.
113 gdb_test_multiple "" $test {
114 -re {Start it from the beginning\? \(y or n\) $} {
118 -re {Error in re-setting breakpoint} {
121 -re "\r\n$gdb_prompt $" {
126 # Check that neither library is loaded.
127 check_info_shared "info sharedlibrary #4" 0 0
129 # Run to the first stop and check that only the first library is loaded.
130 gdb_continue_to_breakpoint "library load #3" "\\.?stop .*"
131 check_info_shared "info sharedlibrary #5" 1 0
133 # Run to the second stop and check that both libraries are loaded.
134 gdb_continue_to_breakpoint "library load #4" "\\.?stop .*"
135 check_info_shared "info sharedlibrary #6" 1 1
137 # Check that the next stop is in foo.
138 gdb_continue_to_breakpoint "library function #3" "\\.?foo .*"
140 # Check that the next stop is in bar.
141 gdb_continue_to_breakpoint "library function #4" "\\.?bar .*"
143 # Run to the next stop and check that the first library has been unloaded.
144 gdb_continue_to_breakpoint "library unload #1" "\\.?stop .*"
145 check_info_shared "info sharedlibrary #7" 0 1
147 # Run to the last stop and check that both libraries are gone.
148 gdb_continue_to_breakpoint "library unload #2" "\\.?stop .*"
149 check_info_shared "info sharedlibrary #8" 0 0
151 with_test_prefix styled {
152 save_vars { env(TERM) } {
153 # We need an ANSI-capable terminal to get the output.
156 clean_restart $testfile
158 gdb_test_no_output "set style enabled off"
162 gdb_breakpoint "stop"
163 gdb_continue_to_breakpoint "library load #1" "\\.?stop .*"
165 # Simple test for "info sharedlibrary" styling. Look for styled
166 # addresses and file name.
167 set addr [style $hex address]
168 # Use a non-greedy match here to avoid accidentally picking up
169 # other escape sequences.
170 set sofile [style ".*?" file]
171 gdb_test_no_output "set style enabled on"
172 gdb_test "info sharedlibrary" \
173 "$addr\[ \t\]+$addr.*$sofile\r\n.*"