gdb/testsuite/
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / solib.exp
CommitLineData
0fb0cc75
JB
1# Copyright 1997, 1998, 1999, 2007, 2008, 2009
2# Free Software Foundation, Inc.
c906108c
SS
3
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
e22f8b7c 6# the Free Software Foundation; either version 3 of the License, or
c906108c 7# (at your option) any later version.
e22f8b7c 8#
c906108c
SS
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.
e22f8b7c 13#
c906108c 14# You should have received a copy of the GNU General Public License
e22f8b7c 15# along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c 16
c906108c
SS
17if $tracelevel then {
18 strace $tracelevel
19 }
20
21set prms_id 0
22set bug_id 0
23
24# are we on a target board
25if ![isnative] then {
26 return
27}
28
29# This test is presently only valid on HP-UX. It verifies GDB's
30# ability to catch loads and unloads of shared libraries.
31#
32
33#setup_xfail "*-*-*"
34#clear_xfail "hppa*-*-*hpux*"
35if {![istarget "hppa*-*-hpux*"]} {
36 return 0
37}
38
39set testfile "solib"
40set srcfile ${testfile}.c
41set binfile ${objdir}/${subdir}/${testfile}
42
43# build the first test case
44if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
b60f0898
JB
45 untested solib.exp
46 return -1
c906108c
SS
47}
48
49if [get_compiler_info ${binfile}] {
50 return -1
51}
52
53# Build the shared libraries this test case needs.
54#
55#cd ${subdir}
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"
58
59if {$gcc_compiled == 0} {
60 if [istarget "hppa*-hp-hpux*"] then {
61 set additional_flags "additional_flags=+z"
62 } else {
63 # don't know what the compiler is...
64 set additional_flags ""
65 }
66} else {
67 set additional_flags "additional_flags=-fpic"
68}
69
70if {[gdb_compile "${srcdir}/${subdir}/${testfile}1.c" "${binfile}1.o" object [list debug $additional_flags]] != ""} {
71 perror "Couldn't compile ${testfile}1.c"
72 #return -1
73}
74if {[gdb_compile "${srcdir}/${subdir}/${testfile}2.c" "${binfile}2.o" object [list debug, $additional_flags]] != ""} {
75 perror "Couldn't compile ${testfile}2.c"
76 #return -1
77}
78
79if [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"
82} else {
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]
86}
085dd6e6
JM
87
88# Build a version where the main program is in a shared library. For
89# testing an indirect call made in a shared library.
90
91if {[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"
93 #return -1
94}
95
96if { [istarget "hppa*-*-hpux*"] } {
97 remote_exec build "ld -b ${binfile}_sl.o -o ${binfile}_sl.sl"
98} else {
99 set additional_flags "additional_flags=-shared"
100 gdb_compile "${binfile}_sl.o" "${binfile}_sl.sl" executable [list debug $additional_flags]
101}
102
103if { [istarget "hppa*-*-hpux*"] } {
104 set additional_flags "-Wl,-u,main"
105 if { [gdb_compile "${binfile}_sl.sl" "${binfile}_sl" executable [list debug $additional_flags]] != "" } {
b60f0898
JB
106 untested solib.exp
107 return -1
085dd6e6
JM
108 }
109} else {
110 # FIXME: need to fill this part in for non-HP build
111}
112
c906108c
SS
113#cd ..
114
115# Start with a fresh gdb
116
117gdb_exit
118gdb_start
119gdb_reinitialize_dir $srcdir/$subdir
120gdb_load ${binfile}
121
122# This program manually loads and unloads SOM shared libraries, via calls
123# to shl_load and shl_unload.
124#
125if ![runto_main] then { fail "catch load/unload tests suppressed" }
126
127# Verify that we complain if the user tells us to catch something we
128# don't understand.
129#
130send_gdb "catch a_cold\n"
131gdb_expect {
132 -re "Unknown event kind specified for catch.*$gdb_prompt $"\
133 {pass "bogus catch kind is disallowed"}
134 -re "$gdb_prompt $"\
135 {fail "bogus catch kind is disallowed"}
136 timeout {fail "(timeout) bogus catch kind is disallowed"}
137}
138
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.
141#
142send_gdb "catch load\n"
143gdb_expect {
144 -re "Catchpoint \[0-9\]* .load <any library>.*$gdb_prompt $"\
145 {pass "set generic catch load"}
146 -re "$gdb_prompt $"\
147 {fail "set generic catch load"}
148 timeout {fail "(timeout) set generic catch load"}
149}
150
151send_gdb "continue\n"
152gdb_expect {
153 -re "Catchpoint \[0-9\] .loaded gdb.base/solib1.sl.*$gdb_prompt $"\
154 {pass "caught generic solib load"}
155 -re "$gdb_prompt $"\
156 {fail "caught generic solib load"}
157 timeout {fail "(timeout) caught generic solib load"}
158}
159
160# Set a breakpoint on the line following the shl_load call, and
161# continue.
162#
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.
165#
166send_gdb "break 27\n"
167gdb_expect {
168 -re "Breakpoint \[0-9\]* at.*$gdb_prompt $"\
169 {pass "set break after shl_load"}
170 -re "$gdb_prompt $"\
171 {fail "set break after shl_load"}
172 timeout {fail "(timeout) set break after shl_load"}
173}
174
175send_gdb "continue\n"
176gdb_expect {
177 -re "Breakpoint \[0-9\]*, main .. at .*solib.c:27.*$gdb_prompt $"\
178 {pass "continue after generic catch load"}
179 -re "$gdb_prompt $"\
180 {fail "continue after generic catch load"}
181 timeout {fail "(timeout) continue after generic catch load"}
182}
183
184# Step over the call to shl_findsym.
185#
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
193# this case...
194#
195send_gdb "next\n"
196gdb_expect {
197 -re "$gdb_prompt $"\
198 {pass "step over shl_findsym"}
199 timeout {fail "(timeout) step over shl_findsym"}
200}
201
202# Verify that we can catch an unload of any library.
203#
204send_gdb "catch unload\n"
205gdb_expect {
206 -re "Catchpoint \[0-9\]* .unload <any library>.*$gdb_prompt $"\
207 {pass "set generic catch unload"}
208 -re "$gdb_prompt $"\
209 {fail "set generic catch unload"}
210 timeout {fail "(timeout) set generic catch load"}
211}
212
213send_gdb "continue\n"
214gdb_expect {
215 -re "Catchpoint \[0-9\] .unloaded gdb.base/solib1.sl.*$gdb_prompt $"\
216 {pass "caught generic solib unload"}
217 -re "$gdb_prompt $"\
218 {fail "caught generic solib unload"}
219 timeout {fail "(timeout) caught generic solib unload"}
220}
221
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.)
225#
226send_gdb "delete\n"
227gdb_expect {
228 -re "Delete all breakpoints.*y or n.*"\
229 {send_gdb "y\n"
230 gdb_expect {
231 -re "$gdb_prompt $"\
232 {pass "delete all catchpoints"}
233 timeout {fail "(timeout) delete all catchpoints"}
234 }
235 }
236 -re "$gdb_prompt $"\
237 {fail "delete all catchpoints"}
238 timeout {fail "(timeout) delete all catchpoints"}
239}
240
241send_gdb "catch load gdb.base/solib2.sl\n"
242gdb_expect {
243 -re "Catchpoint \[0-9\]* .load gdb.base/solib2.sl.*$gdb_prompt $"\
244 {pass "set specific catch load"}
245 -re "$gdb_prompt $"\
246 {fail "set specific catch load"}
247 timeout {fail "(timeout) set specific catch load"}
248}
249
250send_gdb "continue\n"
251gdb_expect {
252 -re "Catchpoint \[0-9\] .loaded gdb.base/solib2.sl.*$gdb_prompt $"\
253 {pass "caught specific solib load"}
254 -re "$gdb_prompt $"\
255 {fail "caught specific solib load"}
256 timeout {fail "(timeout) caught specific solib load"}
257}
258
259# Verify that we can catch an unload of a specific library.
260#
261send_gdb "catch unload gdb.base/solib2.sl\n"
262gdb_expect {
263 -re "Catchpoint \[0-9\]* .unload gdb.base/solib2.sl.*$gdb_prompt $"\
264 {pass "set specific catch unload"}
265 -re "$gdb_prompt $"\
266 {fail "set specific catch unload"}
267 timeout {fail "(timeout) set specific catch unload"}
268}
269
270send_gdb "continue\n"
271gdb_expect {
272 -re "Catchpoint \[0-9\] .unloaded gdb.base/solib2.sl.*$gdb_prompt $"\
273 {pass "caught specific solib unload"}
274 -re "$gdb_prompt $"\
275 {fail "caught specific solib unload"}
276 timeout {fail "(timeout) caught specific solib unload"}
277}
278
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.
282#
283send_gdb "break 55\n"
284gdb_expect {
285 -re "Breakpoint \[0-9\]* at.*$gdb_prompt $"\
286 {pass "set break on shl_unload"}
287 -re "$gdb_prompt $"\
288 {fail "set break on shl_unload"}
289 timeout {fail "(timeout) set break on shl_unload"}
290}
291
292send_gdb "break 58\n"
293gdb_expect {
294 -re "Breakpoint \[0-9\]* at.*$gdb_prompt $"\
295 {pass "set break after shl_unload"}
296 -re "$gdb_prompt $"\
297 {fail "set break after shl_unload"}
298 timeout {fail "(timeout) set break after shl_unload"}
299}
300
301send_gdb "catch load foobar.sl\n"
302gdb_expect {
303 -re "Catchpoint \[0-9\]* .load foobar.sl.*$gdb_prompt $"\
304 {pass "set specific catch load for nonloaded shlib"}
305 -re "$gdb_prompt $"\
306 {fail "set specific catch load for nonloaded shlib"}
307 timeout {fail "(timeout) set specific catch load for nonloaded shlib"}
308}
309
310send_gdb "catch unload foobar.sl\n"
311gdb_expect {
312 -re "Catchpoint \[0-9\]* .unload foobar.sl.*$gdb_prompt $"\
313 {pass "set specific catch unload for nonloaded shlib"}
314 -re "$gdb_prompt $"\
315 {fail "set specific catch unload for nonloaded shlib"}
316 timeout {fail "(timeout) set specific catch unload for nonloaded shlib"}
317}
318
319send_gdb "continue\n"
320gdb_expect {
321 -re "Breakpoint \[0-9\]*.*$gdb_prompt $"\
322 {pass "specific catch load doesn't trigger inappropriately"}
323 -re "$gdb_prompt $"\
324 {fail "specific catch load doesn't trigger inappropriately"}
325 timeout {fail "(timeout) specific catch load doesn't trigger inappropriately"}
326}
327
328send_gdb "continue\n"
329gdb_expect {
330 -re "Breakpoint \[0-9\]*.*$gdb_prompt $"\
331 {pass "specific catch unload doesn't trigger inappropriately"}
332 -re "$gdb_prompt $"\
333 {fail "specific catch unload doesn't trigger inappropriately"}
334 timeout {fail "(timeout) specific catch unload doesn't trigger inappropriately"}
335}
336
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.
340#
341
342gdb_exit
085dd6e6
JM
343
344#
345# Test stepping into an indirect call in a shared library.
346#
347
348gdb_start
349gdb_load ${binfile}_sl
350gdb_test "break main" ".*deferred. at .main..*" "break on main"
351gdb_test "run" ".*Breakpoint.*main.*solib.c.*" "hit breakpoint at main"
352gdb_test "break 45" "Breakpoint.*solib.c, line 45.*" "break on indirect call"
353gdb_test "continue" "Continuing.*solib.c:45.*" \
354 "continue to break on indirect call"
355gdb_test "step" "solib_main.*solib1.c:17.*return arg.arg.*" \
356 "step into indirect call from a shared library"
357gdb_exit
358
c906108c 359return 0
This page took 0.930542 seconds and 4 git commands to generate.