* gdb.base/gdb1476.exp: Fix typo.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / shlib-call.exp
CommitLineData
b6ba6518 1# Copyright 1997, 1998, 1999, 2000 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
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# file to test calls into shared libraries
21# the source files for this test are:
22#
23# shmain.c
24# shr1.c (shared lib)
25# shr2.c (shared lib)
26# ss.h (header for shr2.c)
27#
28# file written by Elena Zannoni: elz@ch.apollo.com
29#
30
31#debug shmain
32#prop lib shr1.sl
33#prop lib shr2.sl
34
35if $tracelevel then {
36 strace $tracelevel
37}
38
39set prms_id 0
40set bug_id 0
41
42# are we on a target board?
43if ![isnative] then {
44 return 0
45}
46
47set testfile "shmain"
48set libfile "shr"
49set srcfile ${testfile}.c
50set binfile ${objdir}/${subdir}/${testfile}
51
52# build the first test case
53if [get_compiler_info ${binfile}] {
54 return -1
55}
56
57if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}.o" object {debug}] != "" } {
58 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
59}
60
61
62# Build the shared libraries this test case needs.
63#
64
65if {$gcc_compiled == 0} {
66 if [istarget "hppa*-hp-hpux*"] then {
67 set additional_flags "additional_flags=+z"
3e000b18
KB
68 } elseif { [istarget "mips-sgi-irix*"] } {
69 # Disable SGI compiler's implicit -Dsgi
70 set additional_flags "additional_flags=-Usgi"
c906108c
SS
71 } else {
72 # don't know what the compiler is...
73 set additional_flags ""
74 }
75} else {
b03399da
KB
76 if { ([istarget "powerpc*-*-aix*"]
77 || [istarget "rs6000*-*-aix*"]) } {
78 set additional_flags ""
79 } else {
80 set additional_flags "additional_flags=-fpic"
81 }
c906108c
SS
82}
83
84if {[gdb_compile "${srcdir}/${subdir}/${libfile}1.c" "${objdir}/${subdir}/${libfile}1.o" object [list debug $additional_flags]] != ""} {
85 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
86}
87
88if {[gdb_compile "${srcdir}/${subdir}/${libfile}2.c" "${objdir}/${subdir}/${libfile}2.o" object [list debug $additional_flags]] != ""} {
89 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
90}
91
92if [istarget "hppa*-*-hpux*"] {
93 remote_exec build "ld -b ${objdir}/${subdir}/${libfile}1.o -o ${objdir}/${subdir}/${libfile}1.sl"
94 remote_exec build "ld -b ${objdir}/${subdir}/${libfile}2.o -o ${objdir}/${subdir}/${libfile}2.sl"
95} else {
96 set additional_flags "additional_flags=-shared"
97 if {[gdb_compile "${objdir}/${subdir}/${libfile}1.o" "${objdir}/${subdir}/${libfile}1.sl" executable [list debug $additional_flags]] != ""} {
98 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
99 }
100 if {[gdb_compile "${objdir}/${subdir}/${libfile}2.o" "${objdir}/${subdir}/${libfile}2.sl" executable [list debug $additional_flags]] != ""} {
101 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
102 }
103}
b03399da
KB
104
105if { ($gcc_compiled
106 && ([istarget "powerpc*-*-aix*"]
107 || [istarget "rs6000*-*-aix*"] )) } {
108 set additional_flags "additional_flags=-L${objdir}/${subdir}"
3e000b18
KB
109} elseif { [istarget "mips-sgi-irix*"] } {
110 set additional_flags "additional_flags=-rpath ${objdir}/${subdir}"
b03399da
KB
111} else {
112 set additional_flags ""
113}
114if {[gdb_compile "${objdir}/${subdir}/${testfile}.o ${objdir}/${subdir}/${libfile}1.sl ${objdir}/${subdir}/${libfile}2.sl" "${binfile}" executable [list debug $additional_flags]] != ""} {
c906108c
SS
115 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
116}
117
118
119
120# Start with a fresh gdb.
121
122gdb_exit
123gdb_start
124gdb_reinitialize_dir $srcdir/$subdir
125gdb_load ${binfile}
126send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
127send_gdb "set print address off\n" ; gdb_expect -re "$gdb_prompt $"
128send_gdb "set width 0\n" ; gdb_expect -re "$gdb_prompt $"
129
130
131if ![runto_main] then {
132 perror "C function calling tests suppressed"
133}
134
135
136#step -over
137
138 send_gdb "next\n"
139 gdb_expect {
11cf8741
JM
140 -re ".*g = shr1\\(g\\).*$gdb_prompt $" {pass "next to shr1"}
141 -re ".*$gdb_prompt $" { fail "next to shr1" }
142 timeout { fail "next to shr1 (timeout)" }
c906108c
SS
143 }
144
145
146
147#print g
148
149send_gdb "print g\n"
150gdb_expect {
151 -re ".*\[0-9\]* = 1.*$gdb_prompt $" {
152 pass "print g"
153 }
154 -re ".*$gdb_prompt $" { fail "print g" }
155 timeout { fail "(timeout) print g" }
156 }
157
158
159#step -over
13a5e3b8
MS
160 if ![gdb_skip_stdio_test "next over shr1"] {
161 send_gdb "next\n"
162 gdb_expect {
163 -re ".*address of sgs is $hex.*g = shr2\\(g\\).*$gdb_prompt $" {
164 pass "next over shr1"
165 }
166 -re ".*$gdb_prompt $" { fail "next over shr1" }
167 timeout { fail "next over shr1 (timeout)" }
168 }
169 } else {
170 gdb_test "next" "" ""
171 }
172
c906108c
SS
173
174#print g
175send_gdb "print g\n"
176gdb_expect {
177 -re ".*\[0-9\]* = 2.*$gdb_prompt $" {
178 pass "print g" }
179 -re ".*$gdb_prompt $" { fail "print g" }
180 timeout { fail "(timeout) print g" }
181 }
182
183#print shr1(1)
13a5e3b8
MS
184 if ![gdb_skip_stdio_test "print shr1(1)"] {
185 send_gdb "print shr1(1)\n"
186 gdb_expect {
187 -re ".*address of sgs is $hex.*\[0-9\]* = 2.*$gdb_prompt $" {
188 pass "print shr1(1)"
189 }
190 -re ".*$gdb_prompt $" { fail "print shr1(1)" }
191 timeout { fail "(timeout) print shr1(1)" }
192 }
c906108c
SS
193 }
194
195#print shr1(g)
13a5e3b8
MS
196 if ![gdb_skip_stdio_test "print shr1(g)"] {
197 send_gdb "print shr1(g)\n"
198 gdb_expect {
199 -re ".*address of sgs is $hex.*\[0-9\]* = 4.*$gdb_prompt $" {
200 pass "print shr1(g)"
201 }
202 -re ".*$gdb_prompt $" { fail "print shr1(g)" }
203 timeout { fail "(timeout) print shr1(g)" }
204 }
c906108c
SS
205 }
206
207#break shr2
208#go
209gdb_test "break shr2" \
210 "Breakpoint.*file.*shr2.c, line.*" \
211 "breakpoint function shr2"
212
13a5e3b8
MS
213gdb_test "continue" \
214 "Continuing\\..*Breakpoint \[0-9\]+, shr2 \\(.*\\) at.*shr2\\.c:7.*7.*return 2.x;" \
215 "run until breakpoint set at a function"
c906108c
SS
216
217
218#print shr1(1)
13a5e3b8
MS
219if ![gdb_skip_stdio_test "print shr1(1) 2nd time"] {
220 send_gdb "print shr1(1)\n"
221 gdb_expect {
222 -re ".*address of sgs is $hex.*\[0-9\]* = 2.*$gdb_prompt $" {
223 pass "print shr1(1) 2nd time"
224 }
225 -re ".*$gdb_prompt $" { fail "print shr1(1) 2nd time" }
226 timeout { fail "(timeout) print shr1(1) 2nd time" }
227 }
228}
c906108c
SS
229
230#print mainshr1(1)
231send_gdb "print mainshr1(1)\n"
232gdb_expect {
233 -re ".*\[0-9\]* = 2.*$gdb_prompt $" {
234 pass "print mainshr1(1) from shlib func"
235 }
236 -re ".*$gdb_prompt $" { fail "print mainshr1(1) from shlib func" }
237 timeout { fail "(timeout) print mainshr1(1) from shlib func" }
238 }
239
240#step -return
241 send_gdb "step\n"
6fde09ad
KB
242 # A step at this point will either take us entirely out of
243 # the function or into the function's epilogue. The exact
244 # behavior will differ depending upon upon whether or not
245 # the compiler emits line number information for the epilogue.
c906108c 246 gdb_expect {
6fde09ad
KB
247 -re "main \\(\\) at.*g = mainshr1\\(g\\);.*$gdb_prompt $" {
248 pass "step out of shr2 to main"
249 }
250 -re ".*\\\}.*$gdb_prompt $" {
251 pass "step out of shr2 to main (stopped in shr2 epilogue)"
252 send_gdb "step\n"
253 gdb_expect {
254 -re "main \\(\\) at.*g = mainshr1\\(g\\);.*$gdb_prompt $" { pass "step out of shr2 epilogue to main"}
255 -re ".*$gdb_prompt $" { fail "step out of shr2 epilogue to main" }
256 timeout { fail "step out of shr2 epilogue to main (timeout)" }
257 }
258 }
259 -re ".*$gdb_prompt $" { fail "step out of shr2" }
c906108c
SS
260 timeout { fail "step out of shr2 to main (timeout)" }
261 }
6fde09ad 262
c906108c
SS
263
264#print mainshr1(1)
265send_gdb "print mainshr1(1)\n"
266gdb_expect {
267 -re ".*\[0-9\]* = 2.*$gdb_prompt $" {
268 pass "print mainshr1(1)"
269 }
270 -re ".*$gdb_prompt $" { fail "print mainshr1(1) from main" }
271 timeout { fail "(timeout) print mainshr1(1) from main" }
272 }
273
274#step
275 send_gdb "step\n"
276 gdb_expect {
277 -re ".*mainshr1 \\(g=4\\) at.*return 2.g;.*$gdb_prompt $" { pass "step into mainshr1"}
278 -re ".*$gdb_prompt $" { fail "step into mainshr1" }
279 timeout { fail "step into mainshr1 (timeout)" }
280 }
281
282# Start with a fresh gdb.
283
284gdb_exit
285gdb_start
286gdb_reinitialize_dir $srcdir/$subdir
287gdb_load ${binfile}
288send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
289send_gdb "set print address off\n" ; gdb_expect -re "$gdb_prompt $"
290send_gdb "set width 0\n" ; gdb_expect -re "$gdb_prompt $"
291
292# PR's 16495, 18213
293# test that we can re-set breakpoints in shared libraries
085dd6e6 294gdb_test "break shr1" "Breakpoint 1.*" "set bp in shared library"
13a5e3b8
MS
295
296# FIXME: should not send "run" explicitly. Non-portable.
297
676a0442
DJ
298if ![is_remote target] {
299 gdb_test "run" "Starting program:.*Breakpoint 1,.*" \
13a5e3b8
MS
300 "run to bp in shared library"
301
676a0442 302 gdb_test "cont" ".*Program exited normally..*"
13a5e3b8 303
676a0442 304 gdb_test "run" "Starting program:.*Breakpoint 1,.*" \
13a5e3b8
MS
305 "re-run to bp in shared library (PR's 16495, 18213)"
306
676a0442
DJ
307 gdb_test "cont" ".*Program exited normally..*"
308}
c906108c
SS
309
310return 0
This page took 0.406156 seconds and 4 git commands to generate.