1 # Copyright (C) 1997, 1998 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 2 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, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17 # Please email any bugs, comments, and/or additions to this file to:
27 # are we on a target board
32 # This test is presently only valid on HP-UX. It verifies GDB's
33 # ability to catch loads and unloads of shared libraries.
37 #clear_xfail "hppa*-*-*hpux*"
38 if {![istarget "hppa*-*-hpux*"]} {
43 set srcfile ${testfile}.c
44 set binfile ${objdir}/${subdir}/${testfile}
46 # build the first test case
47 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
48 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
51 if [get_compiler_info ${binfile}] {
55 # Build the shared libraries this test case needs.
58 #remote_exec build "$CC -g +z -c ${testfile}1.c -o ${testfile}1.o"
59 #remote_exec build "$CC -g +z -c ${testfile}2.c -o ${testfile}2.o"
61 if {$gcc_compiled == 0} {
62 if [istarget "hppa*-hp-hpux*"] then {
63 set additional_flags "additional_flags=+z"
65 # don't know what the compiler is...
66 set additional_flags ""
69 set additional_flags "additional_flags=-fpic"
72 if {[gdb_compile "${srcdir}/${subdir}/${testfile}1.c" "${binfile}1.o" object [list debug $additional_flags]] != ""} {
73 perror "Couldn't compile ${testfile}1.c"
76 if {[gdb_compile "${srcdir}/${subdir}/${testfile}2.c" "${binfile}2.o" object [list debug, $additional_flags]] != ""} {
77 perror "Couldn't compile ${testfile}2.c"
81 if [istarget "hppa*-*-hpux*"] {
82 remote_exec build "ld -b ${binfile}1.o -o ${binfile}1.sl"
83 remote_exec build "ld -b ${binfile}2.o -o ${binfile}2.sl"
85 set additional_flags "additional_flags=-shared"
86 gdb_compile "${binfile}1.o" "${binfile}1.sl" executable [list debug $additional_flags]
87 gdb_compile "${binfile}2.o" "${binfile}2.sl" executable [list debug $additional_flags]
90 # Build a version where the main program is in a shared library. For
91 # testing an indirect call made in a shared library.
93 if {[gdb_compile "${srcdir}/${subdir}/${testfile}.c" "${binfile}_sl.o" object [list debug $additional_flags]] != ""} {
94 perror "Couldn't compile ${testfile}.c for ${binfile}_sl.o"
98 if { [istarget "hppa*-*-hpux*"] } {
99 remote_exec build "ld -b ${binfile}_sl.o -o ${binfile}_sl.sl"
101 set additional_flags "additional_flags=-shared"
102 gdb_compile "${binfile}_sl.o" "${binfile}_sl.sl" executable [list debug $additional_flags]
105 if { [istarget "hppa*-*-hpux*"] } {
106 set additional_flags "-Wl,-u,main"
107 if { [gdb_compile "${binfile}_sl.sl" "${binfile}_sl" executable [list debug $additional_flags]] != "" } {
108 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
111 # FIXME: need to fill this part in for non-HP build
116 # Start with a fresh gdb
120 gdb_reinitialize_dir $srcdir/$subdir
123 # This program manually loads and unloads SOM shared libraries, via calls
124 # to shl_load and shl_unload.
126 if ![runto_main] then { fail "catch load/unload tests suppressed" }
128 # Verify that we complain if the user tells us to catch something we
131 send_gdb "catch a_cold\n"
133 -re "Unknown event kind specified for catch.*$gdb_prompt $"\
134 {pass "bogus catch kind is disallowed"}
136 {fail "bogus catch kind is disallowed"}
137 timeout {fail "(timeout) bogus catch kind is disallowed"}
140 # Verify that we can set a generic catchpoint on shlib loads. I.e., that
141 # we can catch any shlib load, without specifying the name.
143 send_gdb "catch load\n"
145 -re "Catchpoint \[0-9\]* .load <any library>.*$gdb_prompt $"\
146 {pass "set generic catch load"}
148 {fail "set generic catch load"}
149 timeout {fail "(timeout) set generic catch load"}
152 send_gdb "continue\n"
154 -re "Catchpoint \[0-9\] .loaded gdb.base/solib1.sl.*$gdb_prompt $"\
155 {pass "caught generic solib load"}
157 {fail "caught generic solib load"}
158 timeout {fail "(timeout) caught generic solib load"}
161 # Set a breakpoint on the line following the shl_load call, and
164 # ??rehrauer: It appears that we can't just say "finish" from here;
165 # GDB is getting confused by the dld's presense on the stack.
167 send_gdb "break 27\n"
169 -re "Breakpoint \[0-9\]* at.*$gdb_prompt $"\
170 {pass "set break after shl_load"}
172 {fail "set break after shl_load"}
173 timeout {fail "(timeout) set break after shl_load"}
176 send_gdb "continue\n"
178 -re "Breakpoint \[0-9\]*, main .. at .*solib.c:27.*$gdb_prompt $"\
179 {pass "continue after generic catch load"}
181 {fail "continue after generic catch load"}
182 timeout {fail "(timeout) continue after generic catch load"}
185 # Step over the call to shl_findsym.
187 # ??rehrauer: In theory, since the call to shl_load asked for
188 # immediate binding of the shlib's symbols, and since the
189 # shlib's symbols should have been auto-loaded, we ought to
190 # be able to set a breakpoint on solib_main now. However,
191 # that seems not to be the case. Dunno why for sure; perhaps
192 # the breakpoint wants to be set on an import stub in the
193 # main program for solib_main? There wouldn't be one, in
199 {pass "step over shl_findsym"}
200 timeout {fail "(timeout) step over shl_findsym"}
203 # Verify that we can catch an unload of any library.
205 send_gdb "catch unload\n"
207 -re "Catchpoint \[0-9\]* .unload <any library>.*$gdb_prompt $"\
208 {pass "set generic catch unload"}
210 {fail "set generic catch unload"}
211 timeout {fail "(timeout) set generic catch load"}
214 send_gdb "continue\n"
216 -re "Catchpoint \[0-9\] .unloaded gdb.base/solib1.sl.*$gdb_prompt $"\
217 {pass "caught generic solib unload"}
219 {fail "caught generic solib unload"}
220 timeout {fail "(timeout) caught generic solib unload"}
223 # Verify that we can catch a load of a specific library. (Delete
224 # all the other catchpoints first, so that the generic catchpoints
225 # we've previously set don't trigger.)
229 -re "Delete all breakpoints.*y or n.*"\
233 {pass "delete all catchpoints"}
234 timeout {fail "(timeout) delete all catchpoints"}
238 {fail "delete all catchpoints"}
239 timeout {fail "(timeout) delete all catchpoints"}
242 send_gdb "catch load gdb.base/solib2.sl\n"
244 -re "Catchpoint \[0-9\]* .load gdb.base/solib2.sl.*$gdb_prompt $"\
245 {pass "set specific catch load"}
247 {fail "set specific catch load"}
248 timeout {fail "(timeout) set specific catch load"}
251 send_gdb "continue\n"
253 -re "Catchpoint \[0-9\] .loaded gdb.base/solib2.sl.*$gdb_prompt $"\
254 {pass "caught specific solib load"}
256 {fail "caught specific solib load"}
257 timeout {fail "(timeout) caught specific solib load"}
260 # Verify that we can catch an unload of a specific library.
262 send_gdb "catch unload gdb.base/solib2.sl\n"
264 -re "Catchpoint \[0-9\]* .unload gdb.base/solib2.sl.*$gdb_prompt $"\
265 {pass "set specific catch unload"}
267 {fail "set specific catch unload"}
268 timeout {fail "(timeout) set specific catch unload"}
271 send_gdb "continue\n"
273 -re "Catchpoint \[0-9\] .unloaded gdb.base/solib2.sl.*$gdb_prompt $"\
274 {pass "caught specific solib unload"}
276 {fail "caught specific solib unload"}
277 timeout {fail "(timeout) caught specific solib unload"}
280 # Verify that we can set a catchpoint on a specific library that
281 # happens not to be loaded by the program. And, that this catchpoint
282 # won't trigger inappropriately when other shlibs are loaded.
284 send_gdb "break 55\n"
286 -re "Breakpoint \[0-9\]* at.*$gdb_prompt $"\
287 {pass "set break on shl_unload"}
289 {fail "set break on shl_unload"}
290 timeout {fail "(timeout) set break on shl_unload"}
293 send_gdb "break 58\n"
295 -re "Breakpoint \[0-9\]* at.*$gdb_prompt $"\
296 {pass "set break after shl_unload"}
298 {fail "set break after shl_unload"}
299 timeout {fail "(timeout) set break after shl_unload"}
302 send_gdb "catch load foobar.sl\n"
304 -re "Catchpoint \[0-9\]* .load foobar.sl.*$gdb_prompt $"\
305 {pass "set specific catch load for nonloaded shlib"}
307 {fail "set specific catch load for nonloaded shlib"}
308 timeout {fail "(timeout) set specific catch load for nonloaded shlib"}
311 send_gdb "catch unload foobar.sl\n"
313 -re "Catchpoint \[0-9\]* .unload foobar.sl.*$gdb_prompt $"\
314 {pass "set specific catch unload for nonloaded shlib"}
316 {fail "set specific catch unload for nonloaded shlib"}
317 timeout {fail "(timeout) set specific catch unload for nonloaded shlib"}
320 send_gdb "continue\n"
322 -re "Breakpoint \[0-9\]*.*$gdb_prompt $"\
323 {pass "specific catch load doesn't trigger inappropriately"}
325 {fail "specific catch load doesn't trigger inappropriately"}
326 timeout {fail "(timeout) specific catch load doesn't trigger inappropriately"}
329 send_gdb "continue\n"
331 -re "Breakpoint \[0-9\]*.*$gdb_prompt $"\
332 {pass "specific catch unload doesn't trigger inappropriately"}
334 {fail "specific catch unload doesn't trigger inappropriately"}
335 timeout {fail "(timeout) specific catch unload doesn't trigger inappropriately"}
338 # ??rehrauer: There ought to be testpoints here that verify that
339 # load/unload catchpoints can use conditionals, can be temporary,
340 # self-disabling, etc etc.
346 # Test stepping into an indirect call in a shared library.
350 gdb_load ${binfile}_sl
351 gdb_test "break main" ".*deferred. at .main..*" "break on main"
352 gdb_test "run" ".*Breakpoint.*main.*solib.c.*" "hit breakpoint at main"
353 gdb_test "break 45" "Breakpoint.*solib.c, line 45.*" "break on indirect call"
354 gdb_test "continue" "Continuing.*solib.c:45.*" \
355 "continue to break on indirect call"
356 gdb_test "step" "solib_main.*solib1.c:17.*return arg.arg.*" \
357 "step into indirect call from a shared library"