1 # Copyright
2012-2022 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 if { [skip_shlib_tests
] } {
22 set lib1name $testfile
-solib1
23 set srcfile_lib1 $srcdir
/$subdir
/$lib1name.c
24 set binfile_lib1
[standard_output_file $lib1name.so
]
26 set lib2name $testfile
-solib2
27 set srcfile_lib2 $srcdir
/$subdir
/$lib2name.c
28 set binfile_lib2
[standard_output_file $lib2name.so
]
30 if { [gdb_compile_shlib $srcfile_lib1 $binfile_lib1
{}] != "" } {
31 untested
"failed to compile shared library 1"
35 if { [gdb_compile_shlib $srcfile_lib2 $binfile_lib2
{}] != "" } {
36 untested
"failed to compile shared library 2"
40 set binfile_lib1_target
[gdb_download_shlib $binfile_lib1
]
41 set binfile_lib2_target
[gdb_download_shlib $binfile_lib2
]
43 set define2
-DSHLIB2_NAME
=\"$binfile_lib2_target
\"
44 set define1
-DSHLIB1_NAME
=\"$binfile_lib1_target
\"
46 set cflags
"$define1 $define2"
47 if { [prepare_for_testing
"failed to prepare" $testfile $srcfile \
48 [list additional_flags
=$cflags shlib_load
]] } {
52 gdb_locate_shlib $binfile_lib1
53 gdb_locate_shlib $binfile_lib2
55 # Run
"info sharedlibrary" and check for the presence or absence of
57 proc check_info_shared
{ test expect1 expect2
} {
65 gdb_test_multiple
"info sharedlibrary" $test {
74 -re
"\r\n$gdb_prompt $" {
75 if { $actual1
== $expect1
&& $actual2
== $expect2
} {
84 # Start the inferior
, and check neither of the libraries are loaded at
89 check_info_shared
"info sharedlibrary #1" 0 0
93 gdb_breakpoint
"foo" allow-pending
94 gdb_breakpoint
"bar" allow-pending
96 # Run to the first stop and check that only the first library is loaded.
97 gdb_continue_to_breakpoint
"library load #1" "\\.?stop .*"
98 check_info_shared
"info sharedlibrary #2" 1 0
100 # Run to the second stop and check that both libraries are loaded.
101 gdb_continue_to_breakpoint
"library load #2" "\\.?stop .*"
102 check_info_shared
"info sharedlibrary #3" 1 1
104 # Check that the next stop is in foo.
105 gdb_continue_to_breakpoint
"library function #1" "\\.?foo .*"
107 # Check that the next stop is in bar.
108 gdb_continue_to_breakpoint
"library function #2" "\\.?bar .*"
110 # Restart the inferior and make sure there are no breakpoint reset
111 # errors. These can happen with the probes
-based runtime linker
112 # interface
if the
cache is not cleared correctly.
115 gdb_test_multiple
"" $test {
116 -re
{Start it from the beginning
\? \
(y or n\
) $
} {
120 -re
{Error in re
-setting breakpoint
} {
123 -re
"\r\n$gdb_prompt $" {
128 # Check that neither library is loaded.
129 check_info_shared
"info sharedlibrary #4" 0 0
131 # Run to the first stop and check that only the first library is loaded.
132 gdb_continue_to_breakpoint
"library load #3" "\\.?stop .*"
133 check_info_shared
"info sharedlibrary #5" 1 0
135 # Run to the second stop and check that both libraries are loaded.
136 gdb_continue_to_breakpoint
"library load #4" "\\.?stop .*"
137 check_info_shared
"info sharedlibrary #6" 1 1
139 # Check that the next stop is in foo.
140 gdb_continue_to_breakpoint
"library function #3" "\\.?foo .*"
142 # Check that the next stop is in bar.
143 gdb_continue_to_breakpoint
"library function #4" "\\.?bar .*"
145 # Run to the next stop and check that the first library has been unloaded.
146 gdb_continue_to_breakpoint
"library unload #1" "\\.?stop .*"
147 check_info_shared
"info sharedlibrary #7" 0 1
149 # Run to the last stop and check that both libraries are gone.
150 gdb_continue_to_breakpoint
"library unload #2" "\\.?stop .*"
151 check_info_shared
"info sharedlibrary #8" 0 0
153 with_test_prefix styled
{
154 save_vars
{ env
(TERM
) } {
155 # We need an ANSI
-capable terminal to
get the output.
158 clean_restart $testfile
160 gdb_test_no_output
"set style enabled off"
164 gdb_breakpoint
"stop"
165 gdb_continue_to_breakpoint
"library load #1" "\\.?stop .*"
167 # Simple test
for "info sharedlibrary" styling. Look for styled
168 # addresses and file
name.
169 set addr
[style $hex address
]
170 # Use a non
-greedy match here to avoid accidentally picking up
171 # other escape sequences.
172 set sofile
[style
".*?" file]
173 gdb_test_no_output
"set style enabled on"
174 gdb_test
"info sharedlibrary" \
175 "$addr\[ \t\]+$addr.*$sofile\r\n.*"