]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/info-shared.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / info-shared.exp
CommitLineData
1d506c26 1# Copyright 2012-2024 Free Software Foundation, Inc.
afacd7f3
GB
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
d6195dc9 16require allow_shlib_tests
afacd7f3
GB
17
18standard_testfile
19
20set lib1name $testfile-solib1
21set srcfile_lib1 $srcdir/$subdir/$lib1name.c
22set binfile_lib1 [standard_output_file $lib1name.so]
afacd7f3
GB
23
24set lib2name $testfile-solib2
25set srcfile_lib2 $srcdir/$subdir/$lib2name.c
26set binfile_lib2 [standard_output_file $lib2name.so]
afacd7f3 27
2f413264 28if { [gdb_compile_shlib $srcfile_lib1 $binfile_lib1 {}] != "" } {
84c93cd5 29 untested "failed to compile shared library 1"
afacd7f3
GB
30 return -1
31}
32
2f413264 33if { [gdb_compile_shlib $srcfile_lib2 $binfile_lib2 {}] != "" } {
84c93cd5 34 untested "failed to compile shared library 2"
afacd7f3
GB
35 return -1
36}
37
e27e0e5d
TV
38set binfile_lib1_target [gdb_download_shlib $binfile_lib1]
39set binfile_lib2_target [gdb_download_shlib $binfile_lib2]
40
41set define2 -DSHLIB2_NAME=\"$binfile_lib2_target\"
42set define1 -DSHLIB1_NAME=\"$binfile_lib1_target\"
43
afacd7f3 44set cflags "$define1 $define2"
5b362f04 45if { [prepare_for_testing "failed to prepare" $testfile $srcfile \
0a8ddac4 46 [list additional_flags=$cflags shlib_load]] } {
afacd7f3
GB
47 return -1
48}
49
e27e0e5d
TV
50gdb_locate_shlib $binfile_lib1
51gdb_locate_shlib $binfile_lib2
52
afacd7f3
GB
53# Run "info sharedlibrary" and check for the presence or absence of
54# our libraries.
55proc check_info_shared { test expect1 expect2 } {
56 global lib1name
57 global lib2name
58 global gdb_prompt
59
60 set actual1 0
61 set actual2 0
62
63 gdb_test_multiple "info sharedlibrary" $test {
64 -re $lib1name {
65 set actual1 1
66 exp_continue
67 }
68 -re $lib2name {
69 set actual2 1
70 exp_continue
71 }
72 -re "\r\n$gdb_prompt $" {
73 if { $actual1 == $expect1 && $actual2 == $expect2 } {
74 pass $test
75 } else {
76 fail $test
77 }
78 }
79 }
80}
81
82# Start the inferior, and check neither of the libraries are loaded at
83# the start.
84if ![runto_main] {
85 return 0
86}
87check_info_shared "info sharedlibrary #1" 0 0
88
89# Set up breakpoints.
90gdb_breakpoint "stop"
91gdb_breakpoint "foo" allow-pending
92gdb_breakpoint "bar" allow-pending
93
94# Run to the first stop and check that only the first library is loaded.
8b924729 95gdb_continue_to_breakpoint "library load #1" "\\.?stop .*"
afacd7f3
GB
96check_info_shared "info sharedlibrary #2" 1 0
97
98# Run to the second stop and check that both libraries are loaded.
8b924729 99gdb_continue_to_breakpoint "library load #2" "\\.?stop .*"
afacd7f3
GB
100check_info_shared "info sharedlibrary #3" 1 1
101
102# Check that the next stop is in foo.
8b924729 103gdb_continue_to_breakpoint "library function #1" "\\.?foo .*"
afacd7f3
GB
104
105# Check that the next stop is in bar.
8b924729 106gdb_continue_to_breakpoint "library function #2" "\\.?bar .*"
afacd7f3
GB
107
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.
111set test "restart"
112gdb_run_cmd
113gdb_test_multiple "" $test {
114 -re {Start it from the beginning\? \(y or n\) $} {
115 send_gdb "y\n"
116 exp_continue
117 }
118 -re {Error in re-setting breakpoint} {
119 fail $test
120 }
121 -re "\r\n$gdb_prompt $" {
122 pass $test
123 }
124}
125
126# Check that neither library is loaded.
127check_info_shared "info sharedlibrary #4" 0 0
128
129# Run to the first stop and check that only the first library is loaded.
8b924729 130gdb_continue_to_breakpoint "library load #3" "\\.?stop .*"
afacd7f3
GB
131check_info_shared "info sharedlibrary #5" 1 0
132
133# Run to the second stop and check that both libraries are loaded.
8b924729 134gdb_continue_to_breakpoint "library load #4" "\\.?stop .*"
afacd7f3
GB
135check_info_shared "info sharedlibrary #6" 1 1
136
137# Check that the next stop is in foo.
8b924729 138gdb_continue_to_breakpoint "library function #3" "\\.?foo .*"
afacd7f3
GB
139
140# Check that the next stop is in bar.
8b924729 141gdb_continue_to_breakpoint "library function #4" "\\.?bar .*"
afacd7f3
GB
142
143# Run to the next stop and check that the first library has been unloaded.
8b924729 144gdb_continue_to_breakpoint "library unload #1" "\\.?stop .*"
afacd7f3
GB
145check_info_shared "info sharedlibrary #7" 0 1
146
147# Run to the last stop and check that both libraries are gone.
8b924729 148gdb_continue_to_breakpoint "library unload #2" "\\.?stop .*"
afacd7f3 149check_info_shared "info sharedlibrary #8" 0 0
e7bd7fba
TT
150
151with_test_prefix styled {
152 save_vars { env(TERM) } {
153 # We need an ANSI-capable terminal to get the output.
154 setenv TERM ansi
155
156 clean_restart $testfile
157
158 gdb_test_no_output "set style enabled off"
159 if {![runto_main]} {
160 return 0
161 }
162 gdb_breakpoint "stop"
163 gdb_continue_to_breakpoint "library load #1" "\\.?stop .*"
164
165 # Simple test for "info sharedlibrary" styling. Look for styled
166 # addresses and file name.
18125b16
TT
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]
e7bd7fba
TT
171 gdb_test_no_output "set style enabled on"
172 gdb_test "info sharedlibrary" \
173 "$addr\[ \t\]+$addr.*$sofile\r\n.*"
174 }
175}