1 # Copyright 1997, 1998, 1999, 2007, 2008, 2009
2 # Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 # are we on a target board
29 # This test is presently only valid on HP-UX. It verifies GDB's
30 # ability to catch loads and unloads of shared libraries.
34 #clear_xfail "hppa*-*-*hpux*"
35 if {![istarget "hppa*-*-hpux*"]} {
40 set srcfile ${testfile}.c
41 set binfile ${objdir}/${subdir}/${testfile}
43 # build the first test case
44 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
49 if [get_compiler_info ${binfile}] {
53 # Build the shared libraries this test case needs.
56 #remote_exec build "$CC -g +z -c ${testfile}1.c -o ${testfile}1.o"
57 #remote_exec build "$CC -g +z -c ${testfile}2.c -o ${testfile}2.o"
59 if {$gcc_compiled == 0} {
60 if [istarget "hppa*-hp-hpux*"] then {
61 set additional_flags "additional_flags=+z"
63 # don't know what the compiler is...
64 set additional_flags ""
67 set additional_flags "additional_flags=-fpic"
70 if {[gdb_compile "${srcdir}/${subdir}/${testfile}1.c" "${binfile}1.o" object [list debug $additional_flags]] != ""} {
71 perror "Couldn't compile ${testfile}1.c"
74 if {[gdb_compile "${srcdir}/${subdir}/${testfile}2.c" "${binfile}2.o" object [list debug, $additional_flags]] != ""} {
75 perror "Couldn't compile ${testfile}2.c"
79 if [istarget "hppa*-*-hpux*"] {
80 remote_exec build "ld -b ${binfile}1.o -o ${binfile}1.sl"
81 remote_exec build "ld -b ${binfile}2.o -o ${binfile}2.sl"
83 set additional_flags "additional_flags=-shared"
84 gdb_compile "${binfile}1.o" "${binfile}1.sl" executable [list debug $additional_flags]
85 gdb_compile "${binfile}2.o" "${binfile}2.sl" executable [list debug $additional_flags]
88 # Build a version where the main program is in a shared library. For
89 # testing an indirect call made in a shared library.
91 if {[gdb_compile "${srcdir}/${subdir}/${testfile}.c" "${binfile}_sl.o" object [list debug $additional_flags]] != ""} {
92 perror "Couldn't compile ${testfile}.c for ${binfile}_sl.o"
96 if { [istarget "hppa*-*-hpux*"] } {
97 remote_exec build "ld -b ${binfile}_sl.o -o ${binfile}_sl.sl"
99 set additional_flags "additional_flags=-shared"
100 gdb_compile "${binfile}_sl.o" "${binfile}_sl.sl" executable [list debug $additional_flags]
103 if { [istarget "hppa*-*-hpux*"] } {
104 set additional_flags "-Wl,-u,main"
105 if { [gdb_compile "${binfile}_sl.sl" "${binfile}_sl" executable [list debug $additional_flags]] != "" } {
110 # FIXME: need to fill this part in for non-HP build
115 # Start with a fresh gdb
119 gdb_reinitialize_dir $srcdir/$subdir
122 # This program manually loads and unloads SOM shared libraries, via calls
123 # to shl_load and shl_unload.
125 if ![runto_main] then { fail "catch load/unload tests suppressed" }
127 # Verify that we complain if the user tells us to catch something we
130 send_gdb "catch a_cold\n"
132 -re "Unknown event kind specified for catch.*$gdb_prompt $"\
133 {pass "bogus catch kind is disallowed"}
135 {fail "bogus catch kind is disallowed"}
136 timeout {fail "(timeout) bogus catch kind is disallowed"}
139 # Verify that we can set a generic catchpoint on shlib loads. I.e., that
140 # we can catch any shlib load, without specifying the name.
142 send_gdb "catch load\n"
144 -re "Catchpoint \[0-9\]* .load <any library>.*$gdb_prompt $"\
145 {pass "set generic catch load"}
147 {fail "set generic catch load"}
148 timeout {fail "(timeout) set generic catch load"}
151 send_gdb "continue\n"
153 -re "Catchpoint \[0-9\] .loaded gdb.base/solib1.sl.*$gdb_prompt $"\
154 {pass "caught generic solib load"}
156 {fail "caught generic solib load"}
157 timeout {fail "(timeout) caught generic solib load"}
160 # Set a breakpoint on the line following the shl_load call, and
163 # ??rehrauer: It appears that we can't just say "finish" from here;
164 # GDB is getting confused by the dld's presense on the stack.
166 send_gdb "break 27\n"
168 -re "Breakpoint \[0-9\]* at.*$gdb_prompt $"\
169 {pass "set break after shl_load"}
171 {fail "set break after shl_load"}
172 timeout {fail "(timeout) set break after shl_load"}
175 send_gdb "continue\n"
177 -re "Breakpoint \[0-9\]*, main .. at .*solib.c:27.*$gdb_prompt $"\
178 {pass "continue after generic catch load"}
180 {fail "continue after generic catch load"}
181 timeout {fail "(timeout) continue after generic catch load"}
184 # Step over the call to shl_findsym.
186 # ??rehrauer: In theory, since the call to shl_load asked for
187 # immediate binding of the shlib's symbols, and since the
188 # shlib's symbols should have been auto-loaded, we ought to
189 # be able to set a breakpoint on solib_main now. However,
190 # that seems not to be the case. Dunno why for sure; perhaps
191 # the breakpoint wants to be set on an import stub in the
192 # main program for solib_main? There wouldn't be one, in
198 {pass "step over shl_findsym"}
199 timeout {fail "(timeout) step over shl_findsym"}
202 # Verify that we can catch an unload of any library.
204 send_gdb "catch unload\n"
206 -re "Catchpoint \[0-9\]* .unload <any library>.*$gdb_prompt $"\
207 {pass "set generic catch unload"}
209 {fail "set generic catch unload"}
210 timeout {fail "(timeout) set generic catch load"}
213 send_gdb "continue\n"
215 -re "Catchpoint \[0-9\] .unloaded gdb.base/solib1.sl.*$gdb_prompt $"\
216 {pass "caught generic solib unload"}
218 {fail "caught generic solib unload"}
219 timeout {fail "(timeout) caught generic solib unload"}
222 # Verify that we can catch a load of a specific library. (Delete
223 # all the other catchpoints first, so that the generic catchpoints
224 # we've previously set don't trigger.)
228 -re "Delete all breakpoints.*y or n.*"\
232 {pass "delete all catchpoints"}
233 timeout {fail "(timeout) delete all catchpoints"}
237 {fail "delete all catchpoints"}
238 timeout {fail "(timeout) delete all catchpoints"}
241 send_gdb "catch load gdb.base/solib2.sl\n"
243 -re "Catchpoint \[0-9\]* .load gdb.base/solib2.sl.*$gdb_prompt $"\
244 {pass "set specific catch load"}
246 {fail "set specific catch load"}
247 timeout {fail "(timeout) set specific catch load"}
250 send_gdb "continue\n"
252 -re "Catchpoint \[0-9\] .loaded gdb.base/solib2.sl.*$gdb_prompt $"\
253 {pass "caught specific solib load"}
255 {fail "caught specific solib load"}
256 timeout {fail "(timeout) caught specific solib load"}
259 # Verify that we can catch an unload of a specific library.
261 send_gdb "catch unload gdb.base/solib2.sl\n"
263 -re "Catchpoint \[0-9\]* .unload gdb.base/solib2.sl.*$gdb_prompt $"\
264 {pass "set specific catch unload"}
266 {fail "set specific catch unload"}
267 timeout {fail "(timeout) set specific catch unload"}
270 send_gdb "continue\n"
272 -re "Catchpoint \[0-9\] .unloaded gdb.base/solib2.sl.*$gdb_prompt $"\
273 {pass "caught specific solib unload"}
275 {fail "caught specific solib unload"}
276 timeout {fail "(timeout) caught specific solib unload"}
279 # Verify that we can set a catchpoint on a specific library that
280 # happens not to be loaded by the program. And, that this catchpoint
281 # won't trigger inappropriately when other shlibs are loaded.
283 send_gdb "break 55\n"
285 -re "Breakpoint \[0-9\]* at.*$gdb_prompt $"\
286 {pass "set break on shl_unload"}
288 {fail "set break on shl_unload"}
289 timeout {fail "(timeout) set break on shl_unload"}
292 send_gdb "break 58\n"
294 -re "Breakpoint \[0-9\]* at.*$gdb_prompt $"\
295 {pass "set break after shl_unload"}
297 {fail "set break after shl_unload"}
298 timeout {fail "(timeout) set break after shl_unload"}
301 send_gdb "catch load foobar.sl\n"
303 -re "Catchpoint \[0-9\]* .load foobar.sl.*$gdb_prompt $"\
304 {pass "set specific catch load for nonloaded shlib"}
306 {fail "set specific catch load for nonloaded shlib"}
307 timeout {fail "(timeout) set specific catch load for nonloaded shlib"}
310 send_gdb "catch unload foobar.sl\n"
312 -re "Catchpoint \[0-9\]* .unload foobar.sl.*$gdb_prompt $"\
313 {pass "set specific catch unload for nonloaded shlib"}
315 {fail "set specific catch unload for nonloaded shlib"}
316 timeout {fail "(timeout) set specific catch unload for nonloaded shlib"}
319 send_gdb "continue\n"
321 -re "Breakpoint \[0-9\]*.*$gdb_prompt $"\
322 {pass "specific catch load doesn't trigger inappropriately"}
324 {fail "specific catch load doesn't trigger inappropriately"}
325 timeout {fail "(timeout) specific catch load doesn't trigger inappropriately"}
328 send_gdb "continue\n"
330 -re "Breakpoint \[0-9\]*.*$gdb_prompt $"\
331 {pass "specific catch unload doesn't trigger inappropriately"}
333 {fail "specific catch unload doesn't trigger inappropriately"}
334 timeout {fail "(timeout) specific catch unload doesn't trigger inappropriately"}
337 # ??rehrauer: There ought to be testpoints here that verify that
338 # load/unload catchpoints can use conditionals, can be temporary,
339 # self-disabling, etc etc.
345 # Test stepping into an indirect call in a shared library.
349 gdb_load ${binfile}_sl
350 gdb_test "break main" ".*deferred. at .main..*" "break on main"
351 gdb_test "run" ".*Breakpoint.*main.*solib.c.*" "hit breakpoint at main"
352 gdb_test "break 45" "Breakpoint.*solib.c, line 45.*" "break on indirect call"
353 gdb_test "continue" "Continuing.*solib.c:45.*" \
354 "continue to break on indirect call"
355 gdb_test "step" "solib_main.*solib1.c:17.*return arg.arg.*" \
356 "step into indirect call from a shared library"