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