1 # Copyright 1997, 1998, 1999, 2007, 2008 Free Software Foundation, Inc.
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.
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.
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/>. */
23 # are we on a target board
28 # This test is presently only valid on HP-UX. It verifies GDB's
29 # ability to catch loads and unloads of shared libraries.
33 #clear_xfail "hppa*-*-*hpux*"
34 if {![istarget "hppa*-*-hpux*"]} {
39 set srcfile ${testfile}.c
40 set binfile ${objdir}/${subdir}/${testfile}
42 # build the first test case
43 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
48 if [get_compiler_info ${binfile}] {
52 # Build the shared libraries this test case needs.
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"
58 if {$gcc_compiled == 0} {
59 if [istarget "hppa*-hp-hpux*"] then {
60 set additional_flags "additional_flags=+z"
62 # don't know what the compiler is...
63 set additional_flags ""
66 set additional_flags "additional_flags=-fpic"
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"
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"
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"
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]
87 # Build a version where the main program is in a shared library. For
88 # testing an indirect call made in a shared library.
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"
95 if { [istarget "hppa*-*-hpux*"] } {
96 remote_exec build "ld -b ${binfile}_sl.o -o ${binfile}_sl.sl"
98 set additional_flags "additional_flags=-shared"
99 gdb_compile "${binfile}_sl.o" "${binfile}_sl.sl" executable [list debug $additional_flags]
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]] != "" } {
109 # FIXME: need to fill this part in for non-HP build
114 # Start with a fresh gdb
118 gdb_reinitialize_dir $srcdir/$subdir
121 # This program manually loads and unloads SOM shared libraries, via calls
122 # to shl_load and shl_unload.
124 if ![runto_main] then { fail "catch load/unload tests suppressed" }
126 # Verify that we complain if the user tells us to catch something we
129 send_gdb "catch a_cold\n"
131 -re "Unknown event kind specified for catch.*$gdb_prompt $"\
132 {pass "bogus catch kind is disallowed"}
134 {fail "bogus catch kind is disallowed"}
135 timeout {fail "(timeout) bogus catch kind is disallowed"}
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.
141 send_gdb "catch load\n"
143 -re "Catchpoint \[0-9\]* .load <any library>.*$gdb_prompt $"\
144 {pass "set generic catch load"}
146 {fail "set generic catch load"}
147 timeout {fail "(timeout) set generic catch load"}
150 send_gdb "continue\n"
152 -re "Catchpoint \[0-9\] .loaded gdb.base/solib1.sl.*$gdb_prompt $"\
153 {pass "caught generic solib load"}
155 {fail "caught generic solib load"}
156 timeout {fail "(timeout) caught generic solib load"}
159 # Set a breakpoint on the line following the shl_load call, and
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.
165 send_gdb "break 27\n"
167 -re "Breakpoint \[0-9\]* at.*$gdb_prompt $"\
168 {pass "set break after shl_load"}
170 {fail "set break after shl_load"}
171 timeout {fail "(timeout) set break after shl_load"}
174 send_gdb "continue\n"
176 -re "Breakpoint \[0-9\]*, main .. at .*solib.c:27.*$gdb_prompt $"\
177 {pass "continue after generic catch load"}
179 {fail "continue after generic catch load"}
180 timeout {fail "(timeout) continue after generic catch load"}
183 # Step over the call to shl_findsym.
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
197 {pass "step over shl_findsym"}
198 timeout {fail "(timeout) step over shl_findsym"}
201 # Verify that we can catch an unload of any library.
203 send_gdb "catch unload\n"
205 -re "Catchpoint \[0-9\]* .unload <any library>.*$gdb_prompt $"\
206 {pass "set generic catch unload"}
208 {fail "set generic catch unload"}
209 timeout {fail "(timeout) set generic catch load"}
212 send_gdb "continue\n"
214 -re "Catchpoint \[0-9\] .unloaded gdb.base/solib1.sl.*$gdb_prompt $"\
215 {pass "caught generic solib unload"}
217 {fail "caught generic solib unload"}
218 timeout {fail "(timeout) caught generic solib unload"}
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.)
227 -re "Delete all breakpoints.*y or n.*"\
231 {pass "delete all catchpoints"}
232 timeout {fail "(timeout) delete all catchpoints"}
236 {fail "delete all catchpoints"}
237 timeout {fail "(timeout) delete all catchpoints"}
240 send_gdb "catch load gdb.base/solib2.sl\n"
242 -re "Catchpoint \[0-9\]* .load gdb.base/solib2.sl.*$gdb_prompt $"\
243 {pass "set specific catch load"}
245 {fail "set specific catch load"}
246 timeout {fail "(timeout) set specific catch load"}
249 send_gdb "continue\n"
251 -re "Catchpoint \[0-9\] .loaded gdb.base/solib2.sl.*$gdb_prompt $"\
252 {pass "caught specific solib load"}
254 {fail "caught specific solib load"}
255 timeout {fail "(timeout) caught specific solib load"}
258 # Verify that we can catch an unload of a specific library.
260 send_gdb "catch unload gdb.base/solib2.sl\n"
262 -re "Catchpoint \[0-9\]* .unload gdb.base/solib2.sl.*$gdb_prompt $"\
263 {pass "set specific catch unload"}
265 {fail "set specific catch unload"}
266 timeout {fail "(timeout) set specific catch unload"}
269 send_gdb "continue\n"
271 -re "Catchpoint \[0-9\] .unloaded gdb.base/solib2.sl.*$gdb_prompt $"\
272 {pass "caught specific solib unload"}
274 {fail "caught specific solib unload"}
275 timeout {fail "(timeout) caught specific solib unload"}
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.
282 send_gdb "break 55\n"
284 -re "Breakpoint \[0-9\]* at.*$gdb_prompt $"\
285 {pass "set break on shl_unload"}
287 {fail "set break on shl_unload"}
288 timeout {fail "(timeout) set break on shl_unload"}
291 send_gdb "break 58\n"
293 -re "Breakpoint \[0-9\]* at.*$gdb_prompt $"\
294 {pass "set break after shl_unload"}
296 {fail "set break after shl_unload"}
297 timeout {fail "(timeout) set break after shl_unload"}
300 send_gdb "catch load foobar.sl\n"
302 -re "Catchpoint \[0-9\]* .load foobar.sl.*$gdb_prompt $"\
303 {pass "set specific catch load for nonloaded shlib"}
305 {fail "set specific catch load for nonloaded shlib"}
306 timeout {fail "(timeout) set specific catch load for nonloaded shlib"}
309 send_gdb "catch unload foobar.sl\n"
311 -re "Catchpoint \[0-9\]* .unload foobar.sl.*$gdb_prompt $"\
312 {pass "set specific catch unload for nonloaded shlib"}
314 {fail "set specific catch unload for nonloaded shlib"}
315 timeout {fail "(timeout) set specific catch unload for nonloaded shlib"}
318 send_gdb "continue\n"
320 -re "Breakpoint \[0-9\]*.*$gdb_prompt $"\
321 {pass "specific catch load doesn't trigger inappropriately"}
323 {fail "specific catch load doesn't trigger inappropriately"}
324 timeout {fail "(timeout) specific catch load doesn't trigger inappropriately"}
327 send_gdb "continue\n"
329 -re "Breakpoint \[0-9\]*.*$gdb_prompt $"\
330 {pass "specific catch unload doesn't trigger inappropriately"}
332 {fail "specific catch unload doesn't trigger inappropriately"}
333 timeout {fail "(timeout) specific catch unload doesn't trigger inappropriately"}
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.
344 # Test stepping into an indirect call in a shared library.
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"