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