OSDN Git Service

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