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