1 # Copyright 1997-2015 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/>. */
17 # are we on a target board
22 # This test is presently only valid on HP-UX. It verifies GDB's
23 # ability to catch loads and unloads of shared libraries.
27 #clear_xfail "hppa*-*-*hpux*"
28 if {![istarget "hppa*-*-hpux*"]} {
33 set srcfile ${testfile}.c
34 set binfile ${objdir}/${subdir}/${testfile}
36 # build the first test case
37 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
42 if [get_compiler_info] {
46 # Build the shared libraries this test case needs.
49 #remote_exec build "$CC -g +z -c ${testfile}1.c -o ${testfile}1.o"
50 #remote_exec build "$CC -g +z -c ${testfile}2.c -o ${testfile}2.o"
52 if {$gcc_compiled == 0} {
53 if [istarget "hppa*-hp-hpux*"] then {
54 set additional_flags "additional_flags=+z"
56 # don't know what the compiler is...
57 set additional_flags ""
60 set additional_flags "additional_flags=-fpic"
63 if {[gdb_compile "${srcdir}/${subdir}/${testfile}1.c" "${binfile}1.o" object [list debug $additional_flags]] != ""} {
64 perror "Couldn't compile ${testfile}1.c"
67 if {[gdb_compile "${srcdir}/${subdir}/${testfile}2.c" "${binfile}2.o" object [list debug, $additional_flags]] != ""} {
68 perror "Couldn't compile ${testfile}2.c"
72 if [istarget "hppa*-*-hpux*"] {
73 remote_exec build "ld -b ${binfile}1.o -o ${binfile}1.sl"
74 remote_exec build "ld -b ${binfile}2.o -o ${binfile}2.sl"
76 set additional_flags "additional_flags=-shared"
77 gdb_compile "${binfile}1.o" "${binfile}1.sl" executable [list debug $additional_flags]
78 gdb_compile "${binfile}2.o" "${binfile}2.sl" executable [list debug $additional_flags]
81 # Build a version where the main program is in a shared library. For
82 # testing an indirect call made in a shared library.
84 if {[gdb_compile "${srcdir}/${subdir}/${testfile}.c" "${binfile}_sl.o" object [list debug $additional_flags]] != ""} {
85 perror "Couldn't compile ${testfile}.c for ${binfile}_sl.o"
89 if { [istarget "hppa*-*-hpux*"] } {
90 remote_exec build "ld -b ${binfile}_sl.o -o ${binfile}_sl.sl"
92 set additional_flags "additional_flags=-shared"
93 gdb_compile "${binfile}_sl.o" "${binfile}_sl.sl" executable [list debug $additional_flags]
96 if { [istarget "hppa*-*-hpux*"] } {
97 set additional_flags "-Wl,-u,main"
98 if { [gdb_compile "${binfile}_sl.sl" "${binfile}_sl" executable [list debug $additional_flags]] != "" } {
103 # FIXME: need to fill this part in for non-HP build
108 # Start with a fresh gdb
112 gdb_reinitialize_dir $srcdir/$subdir
115 # This program manually loads and unloads SOM shared libraries, via calls
116 # to shl_load and shl_unload.
118 if ![runto_main] then { fail "catch load/unload tests suppressed" }
120 # Verify that we complain if the user tells us to catch something we
123 send_gdb "catch a_cold\n"
125 -re "Unknown event kind specified for catch.*$gdb_prompt $"\
126 {pass "bogus catch kind is disallowed"}
128 {fail "bogus catch kind is disallowed"}
129 timeout {fail "(timeout) bogus catch kind is disallowed"}
132 # Verify that we can set a generic catchpoint on shlib loads. I.e., that
133 # we can catch any shlib load, without specifying the name.
135 send_gdb "catch load\n"
137 -re "Catchpoint \[0-9\]* .load <any library>.*$gdb_prompt $"\
138 {pass "set generic catch load"}
140 {fail "set generic catch load"}
141 timeout {fail "(timeout) set generic catch load"}
144 send_gdb "continue\n"
146 -re "Catchpoint \[0-9\] .loaded gdb.base/solib1.sl.*$gdb_prompt $"\
147 {pass "caught generic solib load"}
149 {fail "caught generic solib load"}
150 timeout {fail "(timeout) caught generic solib load"}
153 # Set a breakpoint on the line following the shl_load call, and
156 # ??rehrauer: It appears that we can't just say "finish" from here;
157 # GDB is getting confused by the dld's presense on the stack.
159 send_gdb "break 27\n"
161 -re "Breakpoint \[0-9\]* at.*$gdb_prompt $"\
162 {pass "set break after shl_load"}
164 {fail "set break after shl_load"}
165 timeout {fail "(timeout) set break after shl_load"}
168 send_gdb "continue\n"
170 -re "Breakpoint \[0-9\]*, main .. at .*solib.c:27.*$gdb_prompt $"\
171 {pass "continue after generic catch load"}
173 {fail "continue after generic catch load"}
174 timeout {fail "(timeout) continue after generic catch load"}
177 # Step over the call to shl_findsym.
179 # ??rehrauer: In theory, since the call to shl_load asked for
180 # immediate binding of the shlib's symbols, and since the
181 # shlib's symbols should have been auto-loaded, we ought to
182 # be able to set a breakpoint on solib_main now. However,
183 # that seems not to be the case. Dunno why for sure; perhaps
184 # the breakpoint wants to be set on an import stub in the
185 # main program for solib_main? There wouldn't be one, in
191 {pass "step over shl_findsym"}
192 timeout {fail "(timeout) step over shl_findsym"}
195 # Verify that we can catch an unload of any library.
197 send_gdb "catch unload\n"
199 -re "Catchpoint \[0-9\]* .unload <any library>.*$gdb_prompt $"\
200 {pass "set generic catch unload"}
202 {fail "set generic catch unload"}
203 timeout {fail "(timeout) set generic catch load"}
206 send_gdb "continue\n"
208 -re "Catchpoint \[0-9\] .unloaded gdb.base/solib1.sl.*$gdb_prompt $"\
209 {pass "caught generic solib unload"}
211 {fail "caught generic solib unload"}
212 timeout {fail "(timeout) caught generic solib unload"}
215 # Verify that we can catch a load of a specific library. (Delete
216 # all the other catchpoints first, so that the generic catchpoints
217 # we've previously set don't trigger.)
221 -re "Delete all breakpoints.*y or n.*"\
225 {pass "delete all catchpoints"}
226 timeout {fail "(timeout) delete all catchpoints"}
230 {fail "delete all catchpoints"}
231 timeout {fail "(timeout) delete all catchpoints"}
234 send_gdb "catch load gdb.base/solib2.sl\n"
236 -re "Catchpoint \[0-9\]* .load gdb.base/solib2.sl.*$gdb_prompt $"\
237 {pass "set specific catch load"}
239 {fail "set specific catch load"}
240 timeout {fail "(timeout) set specific catch load"}
243 send_gdb "continue\n"
245 -re "Catchpoint \[0-9\] .loaded gdb.base/solib2.sl.*$gdb_prompt $"\
246 {pass "caught specific solib load"}
248 {fail "caught specific solib load"}
249 timeout {fail "(timeout) caught specific solib load"}
252 # Verify that we can catch an unload of a specific library.
254 send_gdb "catch unload gdb.base/solib2.sl\n"
256 -re "Catchpoint \[0-9\]* .unload gdb.base/solib2.sl.*$gdb_prompt $"\
257 {pass "set specific catch unload"}
259 {fail "set specific catch unload"}
260 timeout {fail "(timeout) set specific catch unload"}
263 send_gdb "continue\n"
265 -re "Catchpoint \[0-9\] .unloaded gdb.base/solib2.sl.*$gdb_prompt $"\
266 {pass "caught specific solib unload"}
268 {fail "caught specific solib unload"}
269 timeout {fail "(timeout) caught specific solib unload"}
272 # Verify that we can set a catchpoint on a specific library that
273 # happens not to be loaded by the program. And, that this catchpoint
274 # won't trigger inappropriately when other shlibs are loaded.
276 send_gdb "break 55\n"
278 -re "Breakpoint \[0-9\]* at.*$gdb_prompt $"\
279 {pass "set break on shl_unload"}
281 {fail "set break on shl_unload"}
282 timeout {fail "(timeout) set break on shl_unload"}
285 send_gdb "break 58\n"
287 -re "Breakpoint \[0-9\]* at.*$gdb_prompt $"\
288 {pass "set break after shl_unload"}
290 {fail "set break after shl_unload"}
291 timeout {fail "(timeout) set break after shl_unload"}
294 send_gdb "catch load foobar.sl\n"
296 -re "Catchpoint \[0-9\]* .load foobar.sl.*$gdb_prompt $"\
297 {pass "set specific catch load for nonloaded shlib"}
299 {fail "set specific catch load for nonloaded shlib"}
300 timeout {fail "(timeout) set specific catch load for nonloaded shlib"}
303 send_gdb "catch unload foobar.sl\n"
305 -re "Catchpoint \[0-9\]* .unload foobar.sl.*$gdb_prompt $"\
306 {pass "set specific catch unload for nonloaded shlib"}
308 {fail "set specific catch unload for nonloaded shlib"}
309 timeout {fail "(timeout) set specific catch unload for nonloaded shlib"}
312 send_gdb "continue\n"
314 -re "Breakpoint \[0-9\]*.*$gdb_prompt $"\
315 {pass "specific catch load doesn't trigger inappropriately"}
317 {fail "specific catch load doesn't trigger inappropriately"}
318 timeout {fail "(timeout) specific catch load doesn't trigger inappropriately"}
321 send_gdb "continue\n"
323 -re "Breakpoint \[0-9\]*.*$gdb_prompt $"\
324 {pass "specific catch unload doesn't trigger inappropriately"}
326 {fail "specific catch unload doesn't trigger inappropriately"}
327 timeout {fail "(timeout) specific catch unload doesn't trigger inappropriately"}
330 # ??rehrauer: There ought to be testpoints here that verify that
331 # load/unload catchpoints can use conditionals, can be temporary,
332 # self-disabling, etc etc.
338 # Test stepping into an indirect call in a shared library.
342 gdb_load ${binfile}_sl
343 gdb_test "break main" ".*deferred. at .main..*" "break on main"
344 gdb_test "run" ".*Breakpoint.*main.*solib.c.*" "hit breakpoint at main"
345 gdb_test "break 45" "Breakpoint.*solib.c, line 45.*" "break on indirect call"
346 gdb_test "continue" "Continuing.*solib.c:45.*" \
347 "continue to break on indirect call"
348 gdb_test "step" "solib_main.*solib1.c:17.*return arg.arg.*" \
349 "step into indirect call from a shared library"