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