2000-10-16 Michael Snyder <msnyder@cleaver.cygnus.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / shlib-call.exp
CommitLineData
c906108c
SS
1# Copyright (C) 1997, 1998 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# 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"
68 } else {
69 # don't know what the compiler is...
70 set additional_flags ""
71 }
72} else {
73 set additional_flags "additional_flags=-fpic"
74}
75
76if {[gdb_compile "${srcdir}/${subdir}/${libfile}1.c" "${objdir}/${subdir}/${libfile}1.o" object [list debug $additional_flags]] != ""} {
77 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
78}
79
80if {[gdb_compile "${srcdir}/${subdir}/${libfile}2.c" "${objdir}/${subdir}/${libfile}2.o" object [list debug $additional_flags]] != ""} {
81 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
82}
83
84if [istarget "hppa*-*-hpux*"] {
85 remote_exec build "ld -b ${objdir}/${subdir}/${libfile}1.o -o ${objdir}/${subdir}/${libfile}1.sl"
86 remote_exec build "ld -b ${objdir}/${subdir}/${libfile}2.o -o ${objdir}/${subdir}/${libfile}2.sl"
87} else {
88 set additional_flags "additional_flags=-shared"
89 if {[gdb_compile "${objdir}/${subdir}/${libfile}1.o" "${objdir}/${subdir}/${libfile}1.sl" executable [list debug $additional_flags]] != ""} {
90 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
91 }
92 if {[gdb_compile "${objdir}/${subdir}/${libfile}2.o" "${objdir}/${subdir}/${libfile}2.sl" executable [list debug $additional_flags]] != ""} {
93 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
94 }
95}
96if {[gdb_compile "${objdir}/${subdir}/${testfile}.o ${objdir}/${subdir}/${libfile}1.sl ${objdir}/${subdir}/${libfile}2.sl" "${binfile}" executable {debug}] != ""} {
97 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
98}
99
100
101
102# Start with a fresh gdb.
103
104gdb_exit
105gdb_start
106gdb_reinitialize_dir $srcdir/$subdir
107gdb_load ${binfile}
108send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
109send_gdb "set print address off\n" ; gdb_expect -re "$gdb_prompt $"
110send_gdb "set width 0\n" ; gdb_expect -re "$gdb_prompt $"
111
112
113if ![runto_main] then {
114 perror "C function calling tests suppressed"
115}
116
117
118#step -over
119
120 send_gdb "next\n"
121 gdb_expect {
11cf8741
JM
122 -re ".*g = shr1\\(g\\).*$gdb_prompt $" {pass "next to shr1"}
123 -re ".*$gdb_prompt $" { fail "next to shr1" }
124 timeout { fail "next to shr1 (timeout)" }
c906108c
SS
125 }
126
127
128
129#print g
130
131send_gdb "print g\n"
132gdb_expect {
133 -re ".*\[0-9\]* = 1.*$gdb_prompt $" {
134 pass "print g"
135 }
136 -re ".*$gdb_prompt $" { fail "print g" }
137 timeout { fail "(timeout) print g" }
138 }
139
140
141#step -over
13a5e3b8
MS
142 if ![gdb_skip_stdio_test "next over shr1"] {
143 send_gdb "next\n"
144 gdb_expect {
145 -re ".*address of sgs is $hex.*g = shr2\\(g\\).*$gdb_prompt $" {
146 pass "next over shr1"
147 }
148 -re ".*$gdb_prompt $" { fail "next over shr1" }
149 timeout { fail "next over shr1 (timeout)" }
150 }
151 } else {
152 gdb_test "next" "" ""
153 }
154
c906108c
SS
155
156#print g
157send_gdb "print g\n"
158gdb_expect {
159 -re ".*\[0-9\]* = 2.*$gdb_prompt $" {
160 pass "print g" }
161 -re ".*$gdb_prompt $" { fail "print g" }
162 timeout { fail "(timeout) print g" }
163 }
164
165#print shr1(1)
13a5e3b8
MS
166 if ![gdb_skip_stdio_test "print shr1(1)"] {
167 send_gdb "print shr1(1)\n"
168 gdb_expect {
169 -re ".*address of sgs is $hex.*\[0-9\]* = 2.*$gdb_prompt $" {
170 pass "print shr1(1)"
171 }
172 -re ".*$gdb_prompt $" { fail "print shr1(1)" }
173 timeout { fail "(timeout) print shr1(1)" }
174 }
c906108c
SS
175 }
176
177#print shr1(g)
13a5e3b8
MS
178 if ![gdb_skip_stdio_test "print shr1(g)"] {
179 send_gdb "print shr1(g)\n"
180 gdb_expect {
181 -re ".*address of sgs is $hex.*\[0-9\]* = 4.*$gdb_prompt $" {
182 pass "print shr1(g)"
183 }
184 -re ".*$gdb_prompt $" { fail "print shr1(g)" }
185 timeout { fail "(timeout) print shr1(g)" }
186 }
c906108c
SS
187 }
188
189#break shr2
190#go
191gdb_test "break shr2" \
192 "Breakpoint.*file.*shr2.c, line.*" \
193 "breakpoint function shr2"
194
13a5e3b8
MS
195gdb_test "continue" \
196 "Continuing\\..*Breakpoint \[0-9\]+, shr2 \\(.*\\) at.*shr2\\.c:7.*7.*return 2.x;" \
197 "run until breakpoint set at a function"
c906108c
SS
198
199
200#print shr1(1)
13a5e3b8
MS
201if ![gdb_skip_stdio_test "print shr1(1) 2nd time"] {
202 send_gdb "print shr1(1)\n"
203 gdb_expect {
204 -re ".*address of sgs is $hex.*\[0-9\]* = 2.*$gdb_prompt $" {
205 pass "print shr1(1) 2nd time"
206 }
207 -re ".*$gdb_prompt $" { fail "print shr1(1) 2nd time" }
208 timeout { fail "(timeout) print shr1(1) 2nd time" }
209 }
210}
c906108c
SS
211
212#print mainshr1(1)
213send_gdb "print mainshr1(1)\n"
214gdb_expect {
215 -re ".*\[0-9\]* = 2.*$gdb_prompt $" {
216 pass "print mainshr1(1) from shlib func"
217 }
218 -re ".*$gdb_prompt $" { fail "print mainshr1(1) from shlib func" }
219 timeout { fail "(timeout) print mainshr1(1) from shlib func" }
220 }
221
222#step -return
223 send_gdb "step\n"
224 gdb_expect {
225 -re ".*\\\}.*$gdb_prompt $" { pass "step inside shr2 (shlib func)"}
226 -re ".*$gdb_prompt $" { fail "step inside shr2 (shlib func)" }
227 timeout { fail "step inside shr2 (shlib func) (timeout)" }
228 }
229
230 send_gdb "step\n"
231 gdb_expect {
232 -re "main \\(\\) at.*g = mainshr1\\(g\\);.*$gdb_prompt $" { pass "step out of shr2 to main"}
233 -re ".*$gdb_prompt $" { fail "step out of shr2 to main" }
234 timeout { fail "step out of shr2 to main (timeout)" }
235 }
236
237#print mainshr1(1)
238send_gdb "print mainshr1(1)\n"
239gdb_expect {
240 -re ".*\[0-9\]* = 2.*$gdb_prompt $" {
241 pass "print mainshr1(1)"
242 }
243 -re ".*$gdb_prompt $" { fail "print mainshr1(1) from main" }
244 timeout { fail "(timeout) print mainshr1(1) from main" }
245 }
246
247#step
248 send_gdb "step\n"
249 gdb_expect {
250 -re ".*mainshr1 \\(g=4\\) at.*return 2.g;.*$gdb_prompt $" { pass "step into mainshr1"}
251 -re ".*$gdb_prompt $" { fail "step into mainshr1" }
252 timeout { fail "step into mainshr1 (timeout)" }
253 }
254
255# Start with a fresh gdb.
256
257gdb_exit
258gdb_start
259gdb_reinitialize_dir $srcdir/$subdir
260gdb_load ${binfile}
261send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
262send_gdb "set print address off\n" ; gdb_expect -re "$gdb_prompt $"
263send_gdb "set width 0\n" ; gdb_expect -re "$gdb_prompt $"
264
265# PR's 16495, 18213
266# test that we can re-set breakpoints in shared libraries
085dd6e6 267gdb_test "break shr1" "Breakpoint 1.*" "set bp in shared library"
13a5e3b8
MS
268
269# FIXME: should not send "run" explicitly. Non-portable.
270
271gdb_test "run" "Starting program:.*Breakpoint 1,.*" \
272 "run to bp in shared library"
273
085dd6e6 274gdb_test "cont" ".*Program exited normally..*"
13a5e3b8
MS
275
276gdb_test "run" "Starting program:.*Breakpoint 1,.*" \
277 "re-run to bp in shared library (PR's 16495, 18213)"
278
085dd6e6 279gdb_test "cont" ".*Program exited normally..*"
c906108c
SS
280
281return 0
This page took 0.090758 seconds and 4 git commands to generate.