1 # Copyright 1997, 1998, 1999, 2007, 2008, 2009, 2010
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/>. */
22 # are we on a target board
27 # This test is presently only valid on HP-UX. It verifies GDB's
28 # ability to catch loads and unloads of shared libraries.
32 #clear_xfail "hppa*-*-*hpux*"
33 if {![istarget "hppa*-*-hpux*"]} {
38 set srcfile ${testfile}.c
39 set binfile ${objdir}/${subdir}/${testfile}
41 # build the first test case
42 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
47 if [get_compiler_info ${binfile}] {
51 # Build the shared libraries this test case needs.
54 #remote_exec build "$CC -g +z -c ${testfile}1.c -o ${testfile}1.o"
55 #remote_exec build "$CC -g +z -c ${testfile}2.c -o ${testfile}2.o"
57 if {$gcc_compiled == 0} {
58 if [istarget "hppa*-hp-hpux*"] then {
59 set additional_flags "additional_flags=+z"
61 # don't know what the compiler is...
62 set additional_flags ""
65 set additional_flags "additional_flags=-fpic"
68 if {[gdb_compile "${srcdir}/${subdir}/${testfile}1.c" "${binfile}1.o" object [list debug $additional_flags]] != ""} {
69 perror "Couldn't compile ${testfile}1.c"
72 if {[gdb_compile "${srcdir}/${subdir}/${testfile}2.c" "${binfile}2.o" object [list debug, $additional_flags]] != ""} {
73 perror "Couldn't compile ${testfile}2.c"
77 if [istarget "hppa*-*-hpux*"] {
78 remote_exec build "ld -b ${binfile}1.o -o ${binfile}1.sl"
79 remote_exec build "ld -b ${binfile}2.o -o ${binfile}2.sl"
81 set additional_flags "additional_flags=-shared"
82 gdb_compile "${binfile}1.o" "${binfile}1.sl" executable [list debug $additional_flags]
83 gdb_compile "${binfile}2.o" "${binfile}2.sl" executable [list debug $additional_flags]
86 # Build a version where the main program is in a shared library. For
87 # testing an indirect call made in a shared library.
89 if {[gdb_compile "${srcdir}/${subdir}/${testfile}.c" "${binfile}_sl.o" object [list debug $additional_flags]] != ""} {
90 perror "Couldn't compile ${testfile}.c for ${binfile}_sl.o"
94 if { [istarget "hppa*-*-hpux*"] } {
95 remote_exec build "ld -b ${binfile}_sl.o -o ${binfile}_sl.sl"
97 set additional_flags "additional_flags=-shared"
98 gdb_compile "${binfile}_sl.o" "${binfile}_sl.sl" executable [list debug $additional_flags]
101 if { [istarget "hppa*-*-hpux*"] } {
102 set additional_flags "-Wl,-u,main"
103 if { [gdb_compile "${binfile}_sl.sl" "${binfile}_sl" executable [list debug $additional_flags]] != "" } {
108 # FIXME: need to fill this part in for non-HP build
113 # Start with a fresh gdb
117 gdb_reinitialize_dir $srcdir/$subdir
120 # This program manually loads and unloads SOM shared libraries, via calls
121 # to shl_load and shl_unload.
123 if ![runto_main] then { fail "catch load/unload tests suppressed" }
125 # Verify that we complain if the user tells us to catch something we
128 send_gdb "catch a_cold\n"
130 -re "Unknown event kind specified for catch.*$gdb_prompt $"\
131 {pass "bogus catch kind is disallowed"}
133 {fail "bogus catch kind is disallowed"}
134 timeout {fail "(timeout) bogus catch kind is disallowed"}
137 # Verify that we can set a generic catchpoint on shlib loads. I.e., that
138 # we can catch any shlib load, without specifying the name.
140 send_gdb "catch load\n"
142 -re "Catchpoint \[0-9\]* .load <any library>.*$gdb_prompt $"\
143 {pass "set generic catch load"}
145 {fail "set generic catch load"}
146 timeout {fail "(timeout) set generic catch load"}
149 send_gdb "continue\n"
151 -re "Catchpoint \[0-9\] .loaded gdb.base/solib1.sl.*$gdb_prompt $"\
152 {pass "caught generic solib load"}
154 {fail "caught generic solib load"}
155 timeout {fail "(timeout) caught generic solib load"}
158 # Set a breakpoint on the line following the shl_load call, and
161 # ??rehrauer: It appears that we can't just say "finish" from here;
162 # GDB is getting confused by the dld's presense on the stack.
164 send_gdb "break 27\n"
166 -re "Breakpoint \[0-9\]* at.*$gdb_prompt $"\
167 {pass "set break after shl_load"}
169 {fail "set break after shl_load"}
170 timeout {fail "(timeout) set break after shl_load"}
173 send_gdb "continue\n"
175 -re "Breakpoint \[0-9\]*, main .. at .*solib.c:27.*$gdb_prompt $"\
176 {pass "continue after generic catch load"}
178 {fail "continue after generic catch load"}
179 timeout {fail "(timeout) continue after generic catch load"}
182 # Step over the call to shl_findsym.
184 # ??rehrauer: In theory, since the call to shl_load asked for
185 # immediate binding of the shlib's symbols, and since the
186 # shlib's symbols should have been auto-loaded, we ought to
187 # be able to set a breakpoint on solib_main now. However,
188 # that seems not to be the case. Dunno why for sure; perhaps
189 # the breakpoint wants to be set on an import stub in the
190 # main program for solib_main? There wouldn't be one, in
196 {pass "step over shl_findsym"}
197 timeout {fail "(timeout) step over shl_findsym"}
200 # Verify that we can catch an unload of any library.
202 send_gdb "catch unload\n"
204 -re "Catchpoint \[0-9\]* .unload <any library>.*$gdb_prompt $"\
205 {pass "set generic catch unload"}
207 {fail "set generic catch unload"}
208 timeout {fail "(timeout) set generic catch load"}
211 send_gdb "continue\n"
213 -re "Catchpoint \[0-9\] .unloaded gdb.base/solib1.sl.*$gdb_prompt $"\
214 {pass "caught generic solib unload"}
216 {fail "caught generic solib unload"}
217 timeout {fail "(timeout) caught generic solib unload"}
220 # Verify that we can catch a load of a specific library. (Delete
221 # all the other catchpoints first, so that the generic catchpoints
222 # we've previously set don't trigger.)
226 -re "Delete all breakpoints.*y or n.*"\
230 {pass "delete all catchpoints"}
231 timeout {fail "(timeout) delete all catchpoints"}
235 {fail "delete all catchpoints"}
236 timeout {fail "(timeout) delete all catchpoints"}
239 send_gdb "catch load gdb.base/solib2.sl\n"
241 -re "Catchpoint \[0-9\]* .load gdb.base/solib2.sl.*$gdb_prompt $"\
242 {pass "set specific catch load"}
244 {fail "set specific catch load"}
245 timeout {fail "(timeout) set specific catch load"}
248 send_gdb "continue\n"
250 -re "Catchpoint \[0-9\] .loaded gdb.base/solib2.sl.*$gdb_prompt $"\
251 {pass "caught specific solib load"}
253 {fail "caught specific solib load"}
254 timeout {fail "(timeout) caught specific solib load"}
257 # Verify that we can catch an unload of a specific library.
259 send_gdb "catch unload gdb.base/solib2.sl\n"
261 -re "Catchpoint \[0-9\]* .unload gdb.base/solib2.sl.*$gdb_prompt $"\
262 {pass "set specific catch unload"}
264 {fail "set specific catch unload"}
265 timeout {fail "(timeout) set specific catch unload"}
268 send_gdb "continue\n"
270 -re "Catchpoint \[0-9\] .unloaded gdb.base/solib2.sl.*$gdb_prompt $"\
271 {pass "caught specific solib unload"}
273 {fail "caught specific solib unload"}
274 timeout {fail "(timeout) caught specific solib unload"}
277 # Verify that we can set a catchpoint on a specific library that
278 # happens not to be loaded by the program. And, that this catchpoint
279 # won't trigger inappropriately when other shlibs are loaded.
281 send_gdb "break 55\n"
283 -re "Breakpoint \[0-9\]* at.*$gdb_prompt $"\
284 {pass "set break on shl_unload"}
286 {fail "set break on shl_unload"}
287 timeout {fail "(timeout) set break on shl_unload"}
290 send_gdb "break 58\n"
292 -re "Breakpoint \[0-9\]* at.*$gdb_prompt $"\
293 {pass "set break after shl_unload"}
295 {fail "set break after shl_unload"}
296 timeout {fail "(timeout) set break after shl_unload"}
299 send_gdb "catch load foobar.sl\n"
301 -re "Catchpoint \[0-9\]* .load foobar.sl.*$gdb_prompt $"\
302 {pass "set specific catch load for nonloaded shlib"}
304 {fail "set specific catch load for nonloaded shlib"}
305 timeout {fail "(timeout) set specific catch load for nonloaded shlib"}
308 send_gdb "catch unload foobar.sl\n"
310 -re "Catchpoint \[0-9\]* .unload foobar.sl.*$gdb_prompt $"\
311 {pass "set specific catch unload for nonloaded shlib"}
313 {fail "set specific catch unload for nonloaded shlib"}
314 timeout {fail "(timeout) set specific catch unload for nonloaded shlib"}
317 send_gdb "continue\n"
319 -re "Breakpoint \[0-9\]*.*$gdb_prompt $"\
320 {pass "specific catch load doesn't trigger inappropriately"}
322 {fail "specific catch load doesn't trigger inappropriately"}
323 timeout {fail "(timeout) specific catch load doesn't trigger inappropriately"}
326 send_gdb "continue\n"
328 -re "Breakpoint \[0-9\]*.*$gdb_prompt $"\
329 {pass "specific catch unload doesn't trigger inappropriately"}
331 {fail "specific catch unload doesn't trigger inappropriately"}
332 timeout {fail "(timeout) specific catch unload doesn't trigger inappropriately"}
335 # ??rehrauer: There ought to be testpoints here that verify that
336 # load/unload catchpoints can use conditionals, can be temporary,
337 # self-disabling, etc etc.
343 # Test stepping into an indirect call in a shared library.
347 gdb_load ${binfile}_sl
348 gdb_test "break main" ".*deferred. at .main..*" "break on main"
349 gdb_test "run" ".*Breakpoint.*main.*solib.c.*" "hit breakpoint at main"
350 gdb_test "break 45" "Breakpoint.*solib.c, line 45.*" "break on indirect call"
351 gdb_test "continue" "Continuing.*solib.c:45.*" \
352 "continue to break on indirect call"
353 gdb_test "step" "solib_main.*solib1.c:17.*return arg.arg.*" \
354 "step into indirect call from a shared library"