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