]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/shlib-call.exp
Copyright updates for 2007.
[thirdparty/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
43# are we on a target board?
44if ![isnative] then {
45 return 0
46}
47
48set testfile "shmain"
f07e55f0
PG
49set libfile1 "shr1"
50set libfile2 "shr2"
51set srcfile ${srcdir}/${subdir}/${testfile}.c
52set lib1src ${srcdir}/${subdir}/${libfile1}.c
53set lib2src ${srcdir}/${subdir}/${libfile2}.c
54set lib1 ${objdir}/${subdir}/${libfile1}.sl
55set lib2 ${objdir}/${subdir}/${libfile2}.sl
56set binfile ${objdir}/${subdir}/${testfile}
57
58set lib_opts "debug"
59set exec_opts [list debug shlib=${lib1} shlib=${lib2}]
c906108c 60
c906108c
SS
61if [get_compiler_info ${binfile}] {
62 return -1
63}
64
f07e55f0
PG
65if { [gdb_compile_shlib ${lib1src} ${lib1} $lib_opts] != ""
66 || [gdb_compile_shlib ${lib2src} ${lib2} $lib_opts] != ""
67 || [gdb_compile ${srcfile} ${binfile} executable $exec_opts] != ""} {
68 untested "Could not compile $lib1, $lib2, or $srcfile."
69 return -1
c906108c
SS
70}
71
c906108c
SS
72# Start with a fresh gdb.
73
74gdb_exit
75gdb_start
76gdb_reinitialize_dir $srcdir/$subdir
77gdb_load ${binfile}
78send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
79send_gdb "set print address off\n" ; gdb_expect -re "$gdb_prompt $"
80send_gdb "set width 0\n" ; gdb_expect -re "$gdb_prompt $"
81
82
83if ![runto_main] then {
84 perror "C function calling tests suppressed"
85}
86
87
88#step -over
89
90 send_gdb "next\n"
91 gdb_expect {
11cf8741
JM
92 -re ".*g = shr1\\(g\\).*$gdb_prompt $" {pass "next to shr1"}
93 -re ".*$gdb_prompt $" { fail "next to shr1" }
94 timeout { fail "next to shr1 (timeout)" }
c906108c
SS
95 }
96
97
98
99#print g
100
101send_gdb "print g\n"
102gdb_expect {
103 -re ".*\[0-9\]* = 1.*$gdb_prompt $" {
104 pass "print g"
105 }
106 -re ".*$gdb_prompt $" { fail "print g" }
107 timeout { fail "(timeout) print g" }
108 }
109
110
111#step -over
13a5e3b8
MS
112 if ![gdb_skip_stdio_test "next over shr1"] {
113 send_gdb "next\n"
114 gdb_expect {
115 -re ".*address of sgs is $hex.*g = shr2\\(g\\).*$gdb_prompt $" {
116 pass "next over shr1"
117 }
118 -re ".*$gdb_prompt $" { fail "next over shr1" }
119 timeout { fail "next over shr1 (timeout)" }
120 }
121 } else {
122 gdb_test "next" "" ""
123 }
124
c906108c
SS
125
126#print g
127send_gdb "print g\n"
128gdb_expect {
129 -re ".*\[0-9\]* = 2.*$gdb_prompt $" {
130 pass "print g" }
131 -re ".*$gdb_prompt $" { fail "print g" }
132 timeout { fail "(timeout) print g" }
133 }
134
135#print shr1(1)
13a5e3b8
MS
136 if ![gdb_skip_stdio_test "print shr1(1)"] {
137 send_gdb "print shr1(1)\n"
138 gdb_expect {
139 -re ".*address of sgs is $hex.*\[0-9\]* = 2.*$gdb_prompt $" {
140 pass "print shr1(1)"
141 }
142 -re ".*$gdb_prompt $" { fail "print shr1(1)" }
143 timeout { fail "(timeout) print shr1(1)" }
144 }
c906108c
SS
145 }
146
147#print shr1(g)
13a5e3b8
MS
148 if ![gdb_skip_stdio_test "print shr1(g)"] {
149 send_gdb "print shr1(g)\n"
150 gdb_expect {
151 -re ".*address of sgs is $hex.*\[0-9\]* = 4.*$gdb_prompt $" {
152 pass "print shr1(g)"
153 }
154 -re ".*$gdb_prompt $" { fail "print shr1(g)" }
155 timeout { fail "(timeout) print shr1(g)" }
156 }
c906108c
SS
157 }
158
159#break shr2
160#go
161gdb_test "break shr2" \
162 "Breakpoint.*file.*shr2.c, line.*" \
163 "breakpoint function shr2"
164
13a5e3b8
MS
165gdb_test "continue" \
166 "Continuing\\..*Breakpoint \[0-9\]+, shr2 \\(.*\\) at.*shr2\\.c:7.*7.*return 2.x;" \
167 "run until breakpoint set at a function"
c906108c
SS
168
169
170#print shr1(1)
13a5e3b8
MS
171if ![gdb_skip_stdio_test "print shr1(1) 2nd time"] {
172 send_gdb "print shr1(1)\n"
173 gdb_expect {
174 -re ".*address of sgs is $hex.*\[0-9\]* = 2.*$gdb_prompt $" {
175 pass "print shr1(1) 2nd time"
176 }
177 -re ".*$gdb_prompt $" { fail "print shr1(1) 2nd time" }
178 timeout { fail "(timeout) print shr1(1) 2nd time" }
179 }
180}
c906108c
SS
181
182#print mainshr1(1)
183send_gdb "print mainshr1(1)\n"
184gdb_expect {
185 -re ".*\[0-9\]* = 2.*$gdb_prompt $" {
186 pass "print mainshr1(1) from shlib func"
187 }
188 -re ".*$gdb_prompt $" { fail "print mainshr1(1) from shlib func" }
189 timeout { fail "(timeout) print mainshr1(1) from shlib func" }
190 }
191
192#step -return
193 send_gdb "step\n"
6fde09ad
KB
194 # A step at this point will either take us entirely out of
195 # the function or into the function's epilogue. The exact
196 # behavior will differ depending upon upon whether or not
197 # the compiler emits line number information for the epilogue.
c906108c 198 gdb_expect {
6fde09ad
KB
199 -re "main \\(\\) at.*g = mainshr1\\(g\\);.*$gdb_prompt $" {
200 pass "step out of shr2 to main"
201 }
202 -re ".*\\\}.*$gdb_prompt $" {
203 pass "step out of shr2 to main (stopped in shr2 epilogue)"
204 send_gdb "step\n"
205 gdb_expect {
206 -re "main \\(\\) at.*g = mainshr1\\(g\\);.*$gdb_prompt $" { pass "step out of shr2 epilogue to main"}
207 -re ".*$gdb_prompt $" { fail "step out of shr2 epilogue to main" }
208 timeout { fail "step out of shr2 epilogue to main (timeout)" }
209 }
210 }
211 -re ".*$gdb_prompt $" { fail "step out of shr2" }
c906108c
SS
212 timeout { fail "step out of shr2 to main (timeout)" }
213 }
6fde09ad 214
c906108c
SS
215
216#print mainshr1(1)
217send_gdb "print mainshr1(1)\n"
218gdb_expect {
219 -re ".*\[0-9\]* = 2.*$gdb_prompt $" {
220 pass "print mainshr1(1)"
221 }
222 -re ".*$gdb_prompt $" { fail "print mainshr1(1) from main" }
223 timeout { fail "(timeout) print mainshr1(1) from main" }
224 }
225
226#step
227 send_gdb "step\n"
228 gdb_expect {
229 -re ".*mainshr1 \\(g=4\\) at.*return 2.g;.*$gdb_prompt $" { pass "step into mainshr1"}
230 -re ".*$gdb_prompt $" { fail "step into mainshr1" }
231 timeout { fail "step into mainshr1 (timeout)" }
232 }
233
234# Start with a fresh gdb.
235
236gdb_exit
237gdb_start
238gdb_reinitialize_dir $srcdir/$subdir
239gdb_load ${binfile}
240send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
241send_gdb "set print address off\n" ; gdb_expect -re "$gdb_prompt $"
242send_gdb "set width 0\n" ; gdb_expect -re "$gdb_prompt $"
243
244# PR's 16495, 18213
245# test that we can re-set breakpoints in shared libraries
55264cb4 246gdb_breakpoint "shr1" "allow-pending"
13a5e3b8
MS
247
248# FIXME: should not send "run" explicitly. Non-portable.
249
676a0442 250if ![is_remote target] {
55264cb4 251 gdb_test "run" "Starting program:.*Breakpoint .,.*" \
13a5e3b8
MS
252 "run to bp in shared library"
253
676a0442 254 gdb_test "cont" ".*Program exited normally..*"
13a5e3b8 255
55264cb4 256 gdb_test "run" "Starting program:.*Breakpoint .,.*" \
13a5e3b8
MS
257 "re-run to bp in shared library (PR's 16495, 18213)"
258
676a0442
DJ
259 gdb_test "cont" ".*Program exited normally..*"
260}
c906108c
SS
261
262return 0