Commit | Line | Data |
---|---|---|
88b9d363 | 1 | # Copyright 2012-2022 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 | ||
16 | if { [skip_shlib_tests] } { | |
17 | return 0 | |
18 | } | |
19 | ||
20 | standard_testfile | |
21 | ||
22 | set lib1name $testfile-solib1 | |
23 | set srcfile_lib1 $srcdir/$subdir/$lib1name.c | |
24 | set binfile_lib1 [standard_output_file $lib1name.so] | |
25 | set define1 -DSHLIB1_NAME=\"$binfile_lib1\" | |
26 | ||
27 | set lib2name $testfile-solib2 | |
28 | set srcfile_lib2 $srcdir/$subdir/$lib2name.c | |
29 | set binfile_lib2 [standard_output_file $lib2name.so] | |
30 | set define2 -DSHLIB2_NAME=\"$binfile_lib2\" | |
31 | ||
2f413264 | 32 | if { [gdb_compile_shlib $srcfile_lib1 $binfile_lib1 {}] != "" } { |
84c93cd5 | 33 | untested "failed to compile shared library 1" |
afacd7f3 GB |
34 | return -1 |
35 | } | |
36 | ||
2f413264 | 37 | if { [gdb_compile_shlib $srcfile_lib2 $binfile_lib2 {}] != "" } { |
84c93cd5 | 38 | untested "failed to compile shared library 2" |
afacd7f3 GB |
39 | return -1 |
40 | } | |
41 | ||
42 | set cflags "$define1 $define2" | |
5b362f04 | 43 | if { [prepare_for_testing "failed to prepare" $testfile $srcfile \ |
0a8ddac4 | 44 | [list additional_flags=$cflags shlib_load]] } { |
afacd7f3 GB |
45 | return -1 |
46 | } | |
47 | ||
48 | # Run "info sharedlibrary" and check for the presence or absence of | |
49 | # our libraries. | |
50 | proc check_info_shared { test expect1 expect2 } { | |
51 | global lib1name | |
52 | global lib2name | |
53 | global gdb_prompt | |
54 | ||
55 | set actual1 0 | |
56 | set actual2 0 | |
57 | ||
58 | gdb_test_multiple "info sharedlibrary" $test { | |
59 | -re $lib1name { | |
60 | set actual1 1 | |
61 | exp_continue | |
62 | } | |
63 | -re $lib2name { | |
64 | set actual2 1 | |
65 | exp_continue | |
66 | } | |
67 | -re "\r\n$gdb_prompt $" { | |
68 | if { $actual1 == $expect1 && $actual2 == $expect2 } { | |
69 | pass $test | |
70 | } else { | |
71 | fail $test | |
72 | } | |
73 | } | |
74 | } | |
75 | } | |
76 | ||
77 | # Start the inferior, and check neither of the libraries are loaded at | |
78 | # the start. | |
79 | if ![runto_main] { | |
80 | return 0 | |
81 | } | |
82 | check_info_shared "info sharedlibrary #1" 0 0 | |
83 | ||
84 | # Set up breakpoints. | |
85 | gdb_breakpoint "stop" | |
86 | gdb_breakpoint "foo" allow-pending | |
87 | gdb_breakpoint "bar" allow-pending | |
88 | ||
89 | # Run to the first stop and check that only the first library is loaded. | |
8b924729 | 90 | gdb_continue_to_breakpoint "library load #1" "\\.?stop .*" |
afacd7f3 GB |
91 | check_info_shared "info sharedlibrary #2" 1 0 |
92 | ||
93 | # Run to the second stop and check that both libraries are loaded. | |
8b924729 | 94 | gdb_continue_to_breakpoint "library load #2" "\\.?stop .*" |
afacd7f3 GB |
95 | check_info_shared "info sharedlibrary #3" 1 1 |
96 | ||
97 | # Check that the next stop is in foo. | |
8b924729 | 98 | gdb_continue_to_breakpoint "library function #1" "\\.?foo .*" |
afacd7f3 GB |
99 | |
100 | # Check that the next stop is in bar. | |
8b924729 | 101 | gdb_continue_to_breakpoint "library function #2" "\\.?bar .*" |
afacd7f3 GB |
102 | |
103 | # Restart the inferior and make sure there are no breakpoint reset | |
104 | # errors. These can happen with the probes-based runtime linker | |
105 | # interface if the cache is not cleared correctly. | |
106 | set test "restart" | |
107 | gdb_run_cmd | |
108 | gdb_test_multiple "" $test { | |
109 | -re {Start it from the beginning\? \(y or n\) $} { | |
110 | send_gdb "y\n" | |
111 | exp_continue | |
112 | } | |
113 | -re {Error in re-setting breakpoint} { | |
114 | fail $test | |
115 | } | |
116 | -re "\r\n$gdb_prompt $" { | |
117 | pass $test | |
118 | } | |
119 | } | |
120 | ||
121 | # Check that neither library is loaded. | |
122 | check_info_shared "info sharedlibrary #4" 0 0 | |
123 | ||
124 | # Run to the first stop and check that only the first library is loaded. | |
8b924729 | 125 | gdb_continue_to_breakpoint "library load #3" "\\.?stop .*" |
afacd7f3 GB |
126 | check_info_shared "info sharedlibrary #5" 1 0 |
127 | ||
128 | # Run to the second stop and check that both libraries are loaded. | |
8b924729 | 129 | gdb_continue_to_breakpoint "library load #4" "\\.?stop .*" |
afacd7f3 GB |
130 | check_info_shared "info sharedlibrary #6" 1 1 |
131 | ||
132 | # Check that the next stop is in foo. | |
8b924729 | 133 | gdb_continue_to_breakpoint "library function #3" "\\.?foo .*" |
afacd7f3 GB |
134 | |
135 | # Check that the next stop is in bar. | |
8b924729 | 136 | gdb_continue_to_breakpoint "library function #4" "\\.?bar .*" |
afacd7f3 GB |
137 | |
138 | # Run to the next stop and check that the first library has been unloaded. | |
8b924729 | 139 | gdb_continue_to_breakpoint "library unload #1" "\\.?stop .*" |
afacd7f3 GB |
140 | check_info_shared "info sharedlibrary #7" 0 1 |
141 | ||
142 | # Run to the last stop and check that both libraries are gone. | |
8b924729 | 143 | gdb_continue_to_breakpoint "library unload #2" "\\.?stop .*" |
afacd7f3 | 144 | check_info_shared "info sharedlibrary #8" 0 0 |
e7bd7fba TT |
145 | |
146 | with_test_prefix styled { | |
147 | save_vars { env(TERM) } { | |
148 | # We need an ANSI-capable terminal to get the output. | |
149 | setenv TERM ansi | |
150 | ||
151 | clean_restart $testfile | |
152 | ||
153 | gdb_test_no_output "set style enabled off" | |
154 | if {![runto_main]} { | |
155 | return 0 | |
156 | } | |
157 | gdb_breakpoint "stop" | |
158 | gdb_continue_to_breakpoint "library load #1" "\\.?stop .*" | |
159 | ||
160 | # Simple test for "info sharedlibrary" styling. Look for styled | |
161 | # addresses and file name. | |
18125b16 TT |
162 | set addr [style $hex address] |
163 | # Use a non-greedy match here to avoid accidentally picking up | |
164 | # other escape sequences. | |
165 | set sofile [style ".*?" file] | |
e7bd7fba TT |
166 | gdb_test_no_output "set style enabled on" |
167 | gdb_test "info sharedlibrary" \ | |
168 | "$addr\[ \t\]+$addr.*$sofile\r\n.*" | |
169 | } | |
170 | } |