Commit | Line | Data |
---|---|---|
9b254dd1 | 1 | # Copyright 1997, 1998, 1999, 2007, 2008 Free Software Foundation, Inc. |
c906108c SS |
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 | |
e22f8b7c | 5 | # the Free Software Foundation; either version 3 of the License, or |
c906108c | 6 | # (at your option) any later version. |
e22f8b7c | 7 | # |
c906108c SS |
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. | |
e22f8b7c | 12 | # |
c906108c | 13 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c | 15 | |
c906108c SS |
16 | if $tracelevel then { |
17 | strace $tracelevel | |
18 | } | |
19 | ||
20 | set prms_id 0 | |
21 | set bug_id 0 | |
22 | ||
23 | # are we on a target board | |
24 | if ![isnative] then { | |
25 | return | |
26 | } | |
27 | ||
28 | # This test is presently only valid on HP-UX. It verifies GDB's | |
29 | # ability to catch loads and unloads of shared libraries. | |
30 | # | |
31 | ||
32 | #setup_xfail "*-*-*" | |
33 | #clear_xfail "hppa*-*-*hpux*" | |
34 | if {![istarget "hppa*-*-hpux*"]} { | |
35 | return 0 | |
36 | } | |
37 | ||
38 | set testfile "solib" | |
39 | set srcfile ${testfile}.c | |
40 | set binfile ${objdir}/${subdir}/${testfile} | |
41 | ||
42 | # build the first test case | |
43 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { | |
b60f0898 JB |
44 | untested solib.exp |
45 | return -1 | |
c906108c SS |
46 | } |
47 | ||
48 | if [get_compiler_info ${binfile}] { | |
49 | return -1 | |
50 | } | |
51 | ||
52 | # Build the shared libraries this test case needs. | |
53 | # | |
54 | #cd ${subdir} | |
55 | #remote_exec build "$CC -g +z -c ${testfile}1.c -o ${testfile}1.o" | |
56 | #remote_exec build "$CC -g +z -c ${testfile}2.c -o ${testfile}2.o" | |
57 | ||
58 | if {$gcc_compiled == 0} { | |
59 | if [istarget "hppa*-hp-hpux*"] then { | |
60 | set additional_flags "additional_flags=+z" | |
61 | } else { | |
62 | # don't know what the compiler is... | |
63 | set additional_flags "" | |
64 | } | |
65 | } else { | |
66 | set additional_flags "additional_flags=-fpic" | |
67 | } | |
68 | ||
69 | if {[gdb_compile "${srcdir}/${subdir}/${testfile}1.c" "${binfile}1.o" object [list debug $additional_flags]] != ""} { | |
70 | perror "Couldn't compile ${testfile}1.c" | |
71 | #return -1 | |
72 | } | |
73 | if {[gdb_compile "${srcdir}/${subdir}/${testfile}2.c" "${binfile}2.o" object [list debug, $additional_flags]] != ""} { | |
74 | perror "Couldn't compile ${testfile}2.c" | |
75 | #return -1 | |
76 | } | |
77 | ||
78 | if [istarget "hppa*-*-hpux*"] { | |
79 | remote_exec build "ld -b ${binfile}1.o -o ${binfile}1.sl" | |
80 | remote_exec build "ld -b ${binfile}2.o -o ${binfile}2.sl" | |
81 | } else { | |
82 | set additional_flags "additional_flags=-shared" | |
83 | gdb_compile "${binfile}1.o" "${binfile}1.sl" executable [list debug $additional_flags] | |
84 | gdb_compile "${binfile}2.o" "${binfile}2.sl" executable [list debug $additional_flags] | |
85 | } | |
085dd6e6 JM |
86 | |
87 | # Build a version where the main program is in a shared library. For | |
88 | # testing an indirect call made in a shared library. | |
89 | ||
90 | if {[gdb_compile "${srcdir}/${subdir}/${testfile}.c" "${binfile}_sl.o" object [list debug $additional_flags]] != ""} { | |
91 | perror "Couldn't compile ${testfile}.c for ${binfile}_sl.o" | |
92 | #return -1 | |
93 | } | |
94 | ||
95 | if { [istarget "hppa*-*-hpux*"] } { | |
96 | remote_exec build "ld -b ${binfile}_sl.o -o ${binfile}_sl.sl" | |
97 | } else { | |
98 | set additional_flags "additional_flags=-shared" | |
99 | gdb_compile "${binfile}_sl.o" "${binfile}_sl.sl" executable [list debug $additional_flags] | |
100 | } | |
101 | ||
102 | if { [istarget "hppa*-*-hpux*"] } { | |
103 | set additional_flags "-Wl,-u,main" | |
104 | if { [gdb_compile "${binfile}_sl.sl" "${binfile}_sl" executable [list debug $additional_flags]] != "" } { | |
b60f0898 JB |
105 | untested solib.exp |
106 | return -1 | |
085dd6e6 JM |
107 | } |
108 | } else { | |
109 | # FIXME: need to fill this part in for non-HP build | |
110 | } | |
111 | ||
c906108c SS |
112 | #cd .. |
113 | ||
114 | # Start with a fresh gdb | |
115 | ||
116 | gdb_exit | |
117 | gdb_start | |
118 | gdb_reinitialize_dir $srcdir/$subdir | |
119 | gdb_load ${binfile} | |
120 | ||
121 | # This program manually loads and unloads SOM shared libraries, via calls | |
122 | # to shl_load and shl_unload. | |
123 | # | |
124 | if ![runto_main] then { fail "catch load/unload tests suppressed" } | |
125 | ||
126 | # Verify that we complain if the user tells us to catch something we | |
127 | # don't understand. | |
128 | # | |
129 | send_gdb "catch a_cold\n" | |
130 | gdb_expect { | |
131 | -re "Unknown event kind specified for catch.*$gdb_prompt $"\ | |
132 | {pass "bogus catch kind is disallowed"} | |
133 | -re "$gdb_prompt $"\ | |
134 | {fail "bogus catch kind is disallowed"} | |
135 | timeout {fail "(timeout) bogus catch kind is disallowed"} | |
136 | } | |
137 | ||
138 | # Verify that we can set a generic catchpoint on shlib loads. I.e., that | |
139 | # we can catch any shlib load, without specifying the name. | |
140 | # | |
141 | send_gdb "catch load\n" | |
142 | gdb_expect { | |
143 | -re "Catchpoint \[0-9\]* .load <any library>.*$gdb_prompt $"\ | |
144 | {pass "set generic catch load"} | |
145 | -re "$gdb_prompt $"\ | |
146 | {fail "set generic catch load"} | |
147 | timeout {fail "(timeout) set generic catch load"} | |
148 | } | |
149 | ||
150 | send_gdb "continue\n" | |
151 | gdb_expect { | |
152 | -re "Catchpoint \[0-9\] .loaded gdb.base/solib1.sl.*$gdb_prompt $"\ | |
153 | {pass "caught generic solib load"} | |
154 | -re "$gdb_prompt $"\ | |
155 | {fail "caught generic solib load"} | |
156 | timeout {fail "(timeout) caught generic solib load"} | |
157 | } | |
158 | ||
159 | # Set a breakpoint on the line following the shl_load call, and | |
160 | # continue. | |
161 | # | |
162 | # ??rehrauer: It appears that we can't just say "finish" from here; | |
163 | # GDB is getting confused by the dld's presense on the stack. | |
164 | # | |
165 | send_gdb "break 27\n" | |
166 | gdb_expect { | |
167 | -re "Breakpoint \[0-9\]* at.*$gdb_prompt $"\ | |
168 | {pass "set break after shl_load"} | |
169 | -re "$gdb_prompt $"\ | |
170 | {fail "set break after shl_load"} | |
171 | timeout {fail "(timeout) set break after shl_load"} | |
172 | } | |
173 | ||
174 | send_gdb "continue\n" | |
175 | gdb_expect { | |
176 | -re "Breakpoint \[0-9\]*, main .. at .*solib.c:27.*$gdb_prompt $"\ | |
177 | {pass "continue after generic catch load"} | |
178 | -re "$gdb_prompt $"\ | |
179 | {fail "continue after generic catch load"} | |
180 | timeout {fail "(timeout) continue after generic catch load"} | |
181 | } | |
182 | ||
183 | # Step over the call to shl_findsym. | |
184 | # | |
185 | # ??rehrauer: In theory, since the call to shl_load asked for | |
186 | # immediate binding of the shlib's symbols, and since the | |
187 | # shlib's symbols should have been auto-loaded, we ought to | |
188 | # be able to set a breakpoint on solib_main now. However, | |
189 | # that seems not to be the case. Dunno why for sure; perhaps | |
190 | # the breakpoint wants to be set on an import stub in the | |
191 | # main program for solib_main? There wouldn't be one, in | |
192 | # this case... | |
193 | # | |
194 | send_gdb "next\n" | |
195 | gdb_expect { | |
196 | -re "$gdb_prompt $"\ | |
197 | {pass "step over shl_findsym"} | |
198 | timeout {fail "(timeout) step over shl_findsym"} | |
199 | } | |
200 | ||
201 | # Verify that we can catch an unload of any library. | |
202 | # | |
203 | send_gdb "catch unload\n" | |
204 | gdb_expect { | |
205 | -re "Catchpoint \[0-9\]* .unload <any library>.*$gdb_prompt $"\ | |
206 | {pass "set generic catch unload"} | |
207 | -re "$gdb_prompt $"\ | |
208 | {fail "set generic catch unload"} | |
209 | timeout {fail "(timeout) set generic catch load"} | |
210 | } | |
211 | ||
212 | send_gdb "continue\n" | |
213 | gdb_expect { | |
214 | -re "Catchpoint \[0-9\] .unloaded gdb.base/solib1.sl.*$gdb_prompt $"\ | |
215 | {pass "caught generic solib unload"} | |
216 | -re "$gdb_prompt $"\ | |
217 | {fail "caught generic solib unload"} | |
218 | timeout {fail "(timeout) caught generic solib unload"} | |
219 | } | |
220 | ||
221 | # Verify that we can catch a load of a specific library. (Delete | |
222 | # all the other catchpoints first, so that the generic catchpoints | |
223 | # we've previously set don't trigger.) | |
224 | # | |
225 | send_gdb "delete\n" | |
226 | gdb_expect { | |
227 | -re "Delete all breakpoints.*y or n.*"\ | |
228 | {send_gdb "y\n" | |
229 | gdb_expect { | |
230 | -re "$gdb_prompt $"\ | |
231 | {pass "delete all catchpoints"} | |
232 | timeout {fail "(timeout) delete all catchpoints"} | |
233 | } | |
234 | } | |
235 | -re "$gdb_prompt $"\ | |
236 | {fail "delete all catchpoints"} | |
237 | timeout {fail "(timeout) delete all catchpoints"} | |
238 | } | |
239 | ||
240 | send_gdb "catch load gdb.base/solib2.sl\n" | |
241 | gdb_expect { | |
242 | -re "Catchpoint \[0-9\]* .load gdb.base/solib2.sl.*$gdb_prompt $"\ | |
243 | {pass "set specific catch load"} | |
244 | -re "$gdb_prompt $"\ | |
245 | {fail "set specific catch load"} | |
246 | timeout {fail "(timeout) set specific catch load"} | |
247 | } | |
248 | ||
249 | send_gdb "continue\n" | |
250 | gdb_expect { | |
251 | -re "Catchpoint \[0-9\] .loaded gdb.base/solib2.sl.*$gdb_prompt $"\ | |
252 | {pass "caught specific solib load"} | |
253 | -re "$gdb_prompt $"\ | |
254 | {fail "caught specific solib load"} | |
255 | timeout {fail "(timeout) caught specific solib load"} | |
256 | } | |
257 | ||
258 | # Verify that we can catch an unload of a specific library. | |
259 | # | |
260 | send_gdb "catch unload gdb.base/solib2.sl\n" | |
261 | gdb_expect { | |
262 | -re "Catchpoint \[0-9\]* .unload gdb.base/solib2.sl.*$gdb_prompt $"\ | |
263 | {pass "set specific catch unload"} | |
264 | -re "$gdb_prompt $"\ | |
265 | {fail "set specific catch unload"} | |
266 | timeout {fail "(timeout) set specific catch unload"} | |
267 | } | |
268 | ||
269 | send_gdb "continue\n" | |
270 | gdb_expect { | |
271 | -re "Catchpoint \[0-9\] .unloaded gdb.base/solib2.sl.*$gdb_prompt $"\ | |
272 | {pass "caught specific solib unload"} | |
273 | -re "$gdb_prompt $"\ | |
274 | {fail "caught specific solib unload"} | |
275 | timeout {fail "(timeout) caught specific solib unload"} | |
276 | } | |
277 | ||
278 | # Verify that we can set a catchpoint on a specific library that | |
279 | # happens not to be loaded by the program. And, that this catchpoint | |
280 | # won't trigger inappropriately when other shlibs are loaded. | |
281 | # | |
282 | send_gdb "break 55\n" | |
283 | gdb_expect { | |
284 | -re "Breakpoint \[0-9\]* at.*$gdb_prompt $"\ | |
285 | {pass "set break on shl_unload"} | |
286 | -re "$gdb_prompt $"\ | |
287 | {fail "set break on shl_unload"} | |
288 | timeout {fail "(timeout) set break on shl_unload"} | |
289 | } | |
290 | ||
291 | send_gdb "break 58\n" | |
292 | gdb_expect { | |
293 | -re "Breakpoint \[0-9\]* at.*$gdb_prompt $"\ | |
294 | {pass "set break after shl_unload"} | |
295 | -re "$gdb_prompt $"\ | |
296 | {fail "set break after shl_unload"} | |
297 | timeout {fail "(timeout) set break after shl_unload"} | |
298 | } | |
299 | ||
300 | send_gdb "catch load foobar.sl\n" | |
301 | gdb_expect { | |
302 | -re "Catchpoint \[0-9\]* .load foobar.sl.*$gdb_prompt $"\ | |
303 | {pass "set specific catch load for nonloaded shlib"} | |
304 | -re "$gdb_prompt $"\ | |
305 | {fail "set specific catch load for nonloaded shlib"} | |
306 | timeout {fail "(timeout) set specific catch load for nonloaded shlib"} | |
307 | } | |
308 | ||
309 | send_gdb "catch unload foobar.sl\n" | |
310 | gdb_expect { | |
311 | -re "Catchpoint \[0-9\]* .unload foobar.sl.*$gdb_prompt $"\ | |
312 | {pass "set specific catch unload for nonloaded shlib"} | |
313 | -re "$gdb_prompt $"\ | |
314 | {fail "set specific catch unload for nonloaded shlib"} | |
315 | timeout {fail "(timeout) set specific catch unload for nonloaded shlib"} | |
316 | } | |
317 | ||
318 | send_gdb "continue\n" | |
319 | gdb_expect { | |
320 | -re "Breakpoint \[0-9\]*.*$gdb_prompt $"\ | |
321 | {pass "specific catch load doesn't trigger inappropriately"} | |
322 | -re "$gdb_prompt $"\ | |
323 | {fail "specific catch load doesn't trigger inappropriately"} | |
324 | timeout {fail "(timeout) specific catch load doesn't trigger inappropriately"} | |
325 | } | |
326 | ||
327 | send_gdb "continue\n" | |
328 | gdb_expect { | |
329 | -re "Breakpoint \[0-9\]*.*$gdb_prompt $"\ | |
330 | {pass "specific catch unload doesn't trigger inappropriately"} | |
331 | -re "$gdb_prompt $"\ | |
332 | {fail "specific catch unload doesn't trigger inappropriately"} | |
333 | timeout {fail "(timeout) specific catch unload doesn't trigger inappropriately"} | |
334 | } | |
335 | ||
336 | # ??rehrauer: There ought to be testpoints here that verify that | |
337 | # load/unload catchpoints can use conditionals, can be temporary, | |
338 | # self-disabling, etc etc. | |
339 | # | |
340 | ||
341 | gdb_exit | |
085dd6e6 JM |
342 | |
343 | # | |
344 | # Test stepping into an indirect call in a shared library. | |
345 | # | |
346 | ||
347 | gdb_start | |
348 | gdb_load ${binfile}_sl | |
349 | gdb_test "break main" ".*deferred. at .main..*" "break on main" | |
350 | gdb_test "run" ".*Breakpoint.*main.*solib.c.*" "hit breakpoint at main" | |
351 | gdb_test "break 45" "Breakpoint.*solib.c, line 45.*" "break on indirect call" | |
352 | gdb_test "continue" "Continuing.*solib.c:45.*" \ | |
353 | "continue to break on indirect call" | |
354 | gdb_test "step" "solib_main.*solib1.c:17.*return arg.arg.*" \ | |
355 | "step into indirect call from a shared library" | |
356 | gdb_exit | |
357 | ||
c906108c | 358 | return 0 |