OSDN Git Service

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