1 # Copyright
1997, 1998, 1999, 2000, 2004, 2007
2 # Free Software Foundation
, Inc.
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.
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.
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
/>.
17 # Please email
any bugs
, comments
, and
/or additions to this file to
:
18 # bug
-gdb@prep.ai.mit.edu
20 # file to test calls into shared libraries
21 # the source files
for this test are
:
26 # ss.h
(header
for shr2.c
)
28 # file written by Elena Zannoni
: elz@ch.apollo.com
42 if {[skip_shlib_tests
]} {
49 set srcfile $
{srcdir
}/$
{subdir
}/$
{testfile
}.c
50 set lib1src $
{srcdir
}/$
{subdir
}/$
{libfile1
}.c
51 set lib2src $
{srcdir
}/$
{subdir
}/$
{libfile2
}.c
52 set lib1 $
{objdir
}/$
{subdir
}/$
{libfile1
}.sl
53 set lib2 $
{objdir
}/$
{subdir
}/$
{libfile2
}.sl
54 set binfile $
{objdir
}/$
{subdir
}/$
{testfile
}
57 set exec_opts
[list debug shlib
=$
{lib1
} shlib
=$
{lib2
}]
59 if [get_compiler_info $
{binfile
}] {
63 if { [gdb_compile_shlib $
{lib1src
} $
{lib1
} $lib_opts
] != ""
64 ||
[gdb_compile_shlib $
{lib2src
} $
{lib2
} $lib_opts
] != ""
65 ||
[gdb_compile $
{srcfile
} $
{binfile
} executable $exec_opts
] != ""} {
66 untested
"Could not compile $lib1, $lib2, or $srcfile."
70 # Start with a fresh gdb.
74 gdb_reinitialize_dir $srcdir
/$subdir
76 gdb_load_shlibs $lib1 $lib2
78 send_gdb
"set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
79 send_gdb
"set print address off\n" ; gdb_expect -re "$gdb_prompt $"
80 send_gdb
"set width 0\n" ; gdb_expect -re "$gdb_prompt $"
83 if ![runto_main
] then {
84 perror
"C function calling tests suppressed"
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)" }
103 -re
".*\[0-9\]* = 1.*$gdb_prompt $" {
106 -re
".*$gdb_prompt $" { fail "print g" }
107 timeout
{ fail
"(timeout) print g" }
112 if ![gdb_skip_stdio_test
"next over shr1"] {
115 -re
".*address of sgs is $hex.*g = shr2\\(g\\).*$gdb_prompt $" {
116 pass
"next over shr1"
118 -re
".*$gdb_prompt $" { fail "next over shr1" }
119 timeout
{ fail
"next over shr1 (timeout)" }
122 gdb_test
"next" "" ""
129 -re
".*\[0-9\]* = 2.*$gdb_prompt $" {
131 -re
".*$gdb_prompt $" { fail "print g" }
132 timeout
{ fail
"(timeout) print g" }
136 if ![gdb_skip_stdio_test
"print shr1(1)"] {
137 send_gdb
"print shr1(1)\n"
139 -re
".*address of sgs is $hex.*\[0-9\]* = 2.*$gdb_prompt $" {
142 -re
".*$gdb_prompt $" { fail "print shr1(1)" }
143 timeout
{ fail
"(timeout) print shr1(1)" }
148 if ![gdb_skip_stdio_test
"print shr1(g)"] {
149 send_gdb
"print shr1(g)\n"
151 -re
".*address of sgs is $hex.*\[0-9\]* = 4.*$gdb_prompt $" {
154 -re
".*$gdb_prompt $" { fail "print shr1(g)" }
155 timeout
{ fail
"(timeout) print shr1(g)" }
161 gdb_test
"break shr2" \
162 "Breakpoint.*file.*shr2.c, line.*" \
163 "breakpoint function shr2"
165 gdb_test
"continue" \
166 "Continuing\\..*Breakpoint \[0-9\]+, shr2 \\(.*\\) at.*shr2\\.c:7.*7.*return 2.x;" \
167 "run until breakpoint set at a function"
171 if ![gdb_skip_stdio_test
"print shr1(1) 2nd time"] {
172 send_gdb
"print shr1(1)\n"
174 -re
".*address of sgs is $hex.*\[0-9\]* = 2.*$gdb_prompt $" {
175 pass
"print shr1(1) 2nd time"
177 -re
".*$gdb_prompt $" { fail "print shr1(1) 2nd time" }
178 timeout
{ fail
"(timeout) print shr1(1) 2nd time" }
183 send_gdb
"print mainshr1(1)\n"
185 -re
".*\[0-9\]* = 2.*$gdb_prompt $" {
186 pass
"print mainshr1(1) from shlib func"
188 -re
".*$gdb_prompt $" { fail "print mainshr1(1) from shlib func" }
189 timeout
{ fail
"(timeout) print mainshr1(1) from shlib func" }
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.
199 -re "main \\(\\) at.*g = mainshr1\\(g\\);.*$gdb_prompt $" {
200 pass "step out of shr2 to main"
202 -re ".*\\\}.*$gdb_prompt $" {
203 pass "step out of shr2 to main (stopped in shr2 epilogue)"
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)" }
211 -re ".*$gdb_prompt $" { fail "step out of shr2" }
212 timeout { fail "step out of shr2 to main (timeout)" }
217 send_gdb "print mainshr1(1)\n"
219 -re ".*\[0-9\]* = 2.*$gdb_prompt $" {
220 pass "print mainshr1(1)"
222 -re ".*$gdb_prompt $" { fail "print mainshr1(1) from main" }
223 timeout { fail "(timeout) print mainshr1(1) from main" }
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)" }
234 # Start with a fresh gdb.
238 gdb_reinitialize_dir $srcdir/$subdir
240 send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
241 send_gdb "set print address off\n" ; gdb_expect -re "$gdb_prompt $"
242 send_gdb "set width 0\n" ; gdb_expect -re "$gdb_prompt $"
245 # test that we can re
-set breakpoints in shared libraries
246 gdb_breakpoint
"shr1" "allow-pending"
248 # FIXME
: should not send
"run" explicitly. Non-portable.
250 if ![is_remote target
] {
251 gdb_test
"run" "Starting program:.*Breakpoint .,.*" \
252 "run to bp in shared library"
254 gdb_test
"cont" ".*Program exited normally..*"
256 gdb_test
"run" "Starting program:.*Breakpoint .,.*" \
257 "re-run to bp in shared library (PR's 16495, 18213)"
259 gdb_test
"cont" ".*Program exited normally..*"