* gdb.base/dump.exp: Force the correct endianness for binary
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / shlib-call.exp
CommitLineData
6aba47ca
DJ
1# Copyright 1997, 1998, 1999, 2000, 2004, 2007
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
6# the Free Software Foundation; either version 2 of the License, or
7# (at your option) any later version.
8#
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.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program; if not, write to the Free Software
16# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18# Please email any bugs, comments, and/or additions to this file to:
19# bug-gdb@prep.ai.mit.edu
20
21# file to test calls into shared libraries
22# the source files for this test are:
23#
24# shmain.c
25# shr1.c (shared lib)
26# shr2.c (shared lib)
27# ss.h (header for shr2.c)
28#
29# file written by Elena Zannoni: elz@ch.apollo.com
30#
31
32#debug shmain
33#prop lib shr1.sl
34#prop lib shr2.sl
35
36if $tracelevel then {
37 strace $tracelevel
38}
39
40set prms_id 0
41set bug_id 0
42
93f02886 43if {[skip_shlib_tests]} {
c906108c
SS
44 return 0
45}
46
47set testfile "shmain"
f07e55f0
PG
48set libfile1 "shr1"
49set libfile2 "shr2"
50set srcfile ${srcdir}/${subdir}/${testfile}.c
51set lib1src ${srcdir}/${subdir}/${libfile1}.c
52set lib2src ${srcdir}/${subdir}/${libfile2}.c
53set lib1 ${objdir}/${subdir}/${libfile1}.sl
54set lib2 ${objdir}/${subdir}/${libfile2}.sl
55set binfile ${objdir}/${subdir}/${testfile}
56
57set lib_opts "debug"
58set exec_opts [list debug shlib=${lib1} shlib=${lib2}]
c906108c 59
c906108c
SS
60if [get_compiler_info ${binfile}] {
61 return -1
62}
63
f07e55f0
PG
64if { [gdb_compile_shlib ${lib1src} ${lib1} $lib_opts] != ""
65 || [gdb_compile_shlib ${lib2src} ${lib2} $lib_opts] != ""
66 || [gdb_compile ${srcfile} ${binfile} executable $exec_opts] != ""} {
67 untested "Could not compile $lib1, $lib2, or $srcfile."
68 return -1
c906108c
SS
69}
70
c906108c
SS
71# Start with a fresh gdb.
72
73gdb_exit
74gdb_start
75gdb_reinitialize_dir $srcdir/$subdir
76gdb_load ${binfile}
93f02886
DJ
77gdb_load_shlibs $lib1 $lib2
78
c906108c
SS
79send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
80send_gdb "set print address off\n" ; gdb_expect -re "$gdb_prompt $"
81send_gdb "set width 0\n" ; gdb_expect -re "$gdb_prompt $"
82
83
84if ![runto_main] then {
85 perror "C function calling tests suppressed"
86}
87
88
89#step -over
90
91 send_gdb "next\n"
92 gdb_expect {
11cf8741
JM
93 -re ".*g = shr1\\(g\\).*$gdb_prompt $" {pass "next to shr1"}
94 -re ".*$gdb_prompt $" { fail "next to shr1" }
95 timeout { fail "next to shr1 (timeout)" }
c906108c
SS
96 }
97
98
99
100#print g
101
102send_gdb "print g\n"
103gdb_expect {
104 -re ".*\[0-9\]* = 1.*$gdb_prompt $" {
105 pass "print g"
106 }
107 -re ".*$gdb_prompt $" { fail "print g" }
108 timeout { fail "(timeout) print g" }
109 }
110
111
112#step -over
13a5e3b8
MS
113 if ![gdb_skip_stdio_test "next over shr1"] {
114 send_gdb "next\n"
115 gdb_expect {
116 -re ".*address of sgs is $hex.*g = shr2\\(g\\).*$gdb_prompt $" {
117 pass "next over shr1"
118 }
119 -re ".*$gdb_prompt $" { fail "next over shr1" }
120 timeout { fail "next over shr1 (timeout)" }
121 }
122 } else {
123 gdb_test "next" "" ""
124 }
125
c906108c
SS
126
127#print g
128send_gdb "print g\n"
129gdb_expect {
130 -re ".*\[0-9\]* = 2.*$gdb_prompt $" {
131 pass "print g" }
132 -re ".*$gdb_prompt $" { fail "print g" }
133 timeout { fail "(timeout) print g" }
134 }
135
136#print shr1(1)
13a5e3b8
MS
137 if ![gdb_skip_stdio_test "print shr1(1)"] {
138 send_gdb "print shr1(1)\n"
139 gdb_expect {
140 -re ".*address of sgs is $hex.*\[0-9\]* = 2.*$gdb_prompt $" {
141 pass "print shr1(1)"
142 }
143 -re ".*$gdb_prompt $" { fail "print shr1(1)" }
144 timeout { fail "(timeout) print shr1(1)" }
145 }
c906108c
SS
146 }
147
148#print shr1(g)
13a5e3b8
MS
149 if ![gdb_skip_stdio_test "print shr1(g)"] {
150 send_gdb "print shr1(g)\n"
151 gdb_expect {
152 -re ".*address of sgs is $hex.*\[0-9\]* = 4.*$gdb_prompt $" {
153 pass "print shr1(g)"
154 }
155 -re ".*$gdb_prompt $" { fail "print shr1(g)" }
156 timeout { fail "(timeout) print shr1(g)" }
157 }
c906108c
SS
158 }
159
160#break shr2
161#go
162gdb_test "break shr2" \
163 "Breakpoint.*file.*shr2.c, line.*" \
164 "breakpoint function shr2"
165
13a5e3b8
MS
166gdb_test "continue" \
167 "Continuing\\..*Breakpoint \[0-9\]+, shr2 \\(.*\\) at.*shr2\\.c:7.*7.*return 2.x;" \
168 "run until breakpoint set at a function"
c906108c
SS
169
170
171#print shr1(1)
13a5e3b8
MS
172if ![gdb_skip_stdio_test "print shr1(1) 2nd time"] {
173 send_gdb "print shr1(1)\n"
174 gdb_expect {
175 -re ".*address of sgs is $hex.*\[0-9\]* = 2.*$gdb_prompt $" {
176 pass "print shr1(1) 2nd time"
177 }
178 -re ".*$gdb_prompt $" { fail "print shr1(1) 2nd time" }
179 timeout { fail "(timeout) print shr1(1) 2nd time" }
180 }
181}
c906108c
SS
182
183#print mainshr1(1)
184send_gdb "print mainshr1(1)\n"
185gdb_expect {
186 -re ".*\[0-9\]* = 2.*$gdb_prompt $" {
187 pass "print mainshr1(1) from shlib func"
188 }
189 -re ".*$gdb_prompt $" { fail "print mainshr1(1) from shlib func" }
190 timeout { fail "(timeout) print mainshr1(1) from shlib func" }
191 }
192
193#step -return
194 send_gdb "step\n"
6fde09ad
KB
195 # A step at this point will either take us entirely out of
196 # the function or into the function's epilogue. The exact
197 # behavior will differ depending upon upon whether or not
198 # the compiler emits line number information for the epilogue.
c906108c 199 gdb_expect {
6fde09ad
KB
200 -re "main \\(\\) at.*g = mainshr1\\(g\\);.*$gdb_prompt $" {
201 pass "step out of shr2 to main"
202 }
203 -re ".*\\\}.*$gdb_prompt $" {
204 pass "step out of shr2 to main (stopped in shr2 epilogue)"
205 send_gdb "step\n"
206 gdb_expect {
207 -re "main \\(\\) at.*g = mainshr1\\(g\\);.*$gdb_prompt $" { pass "step out of shr2 epilogue to main"}
208 -re ".*$gdb_prompt $" { fail "step out of shr2 epilogue to main" }
209 timeout { fail "step out of shr2 epilogue to main (timeout)" }
210 }
211 }
212 -re ".*$gdb_prompt $" { fail "step out of shr2" }
c906108c
SS
213 timeout { fail "step out of shr2 to main (timeout)" }
214 }
6fde09ad 215
c906108c
SS
216
217#print mainshr1(1)
218send_gdb "print mainshr1(1)\n"
219gdb_expect {
220 -re ".*\[0-9\]* = 2.*$gdb_prompt $" {
221 pass "print mainshr1(1)"
222 }
223 -re ".*$gdb_prompt $" { fail "print mainshr1(1) from main" }
224 timeout { fail "(timeout) print mainshr1(1) from main" }
225 }
226
227#step
228 send_gdb "step\n"
229 gdb_expect {
230 -re ".*mainshr1 \\(g=4\\) at.*return 2.g;.*$gdb_prompt $" { pass "step into mainshr1"}
231 -re ".*$gdb_prompt $" { fail "step into mainshr1" }
232 timeout { fail "step into mainshr1 (timeout)" }
233 }
234
235# Start with a fresh gdb.
236
237gdb_exit
238gdb_start
239gdb_reinitialize_dir $srcdir/$subdir
240gdb_load ${binfile}
241send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
242send_gdb "set print address off\n" ; gdb_expect -re "$gdb_prompt $"
243send_gdb "set width 0\n" ; gdb_expect -re "$gdb_prompt $"
244
245# PR's 16495, 18213
246# test that we can re-set breakpoints in shared libraries
55264cb4 247gdb_breakpoint "shr1" "allow-pending"
13a5e3b8
MS
248
249# FIXME: should not send "run" explicitly. Non-portable.
250
676a0442 251if ![is_remote target] {
55264cb4 252 gdb_test "run" "Starting program:.*Breakpoint .,.*" \
13a5e3b8
MS
253 "run to bp in shared library"
254
676a0442 255 gdb_test "cont" ".*Program exited normally..*"
13a5e3b8 256
55264cb4 257 gdb_test "run" "Starting program:.*Breakpoint .,.*" \
13a5e3b8
MS
258 "re-run to bp in shared library (PR's 16495, 18213)"
259
676a0442
DJ
260 gdb_test "cont" ".*Program exited normally..*"
261}
c906108c
SS
262
263return 0
This page took 0.684774 seconds and 4 git commands to generate.