1 # Copyright 1997, 1998, 1999, 2000, 2004, 2007, 2008, 2009, 2010, 2011
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 # file to test calls into shared libraries
18 # the source files for this test are:
23 # ss.h (header for shr2.c)
25 # file written by Elena Zannoni: elz@ch.apollo.com
37 if {[skip_shlib_tests]} {
44 set srcfile ${srcdir}/${subdir}/${testfile}.c
45 set lib1src ${srcdir}/${subdir}/${libfile1}.c
46 set lib2src ${srcdir}/${subdir}/${libfile2}.c
47 set lib1 ${objdir}/${subdir}/${libfile1}.sl
48 set lib2 ${objdir}/${subdir}/${libfile2}.sl
49 set binfile ${objdir}/${subdir}/${testfile}
52 set exec_opts [list debug shlib=${lib1} shlib=${lib2}]
54 if [get_compiler_info ${binfile}] {
58 if { [gdb_compile_shlib ${lib1src} ${lib1} $lib_opts] != ""
59 || [gdb_compile_shlib ${lib2src} ${lib2} $lib_opts] != ""
60 || [gdb_compile ${srcfile} ${binfile} executable $exec_opts] != ""} {
61 untested "Could not compile $lib1, $lib2, or $srcfile."
65 # Start with a fresh gdb.
69 gdb_reinitialize_dir $srcdir/$subdir
71 gdb_load_shlibs $lib1 $lib2
73 gdb_test_no_output "set print sevenbit-strings"
74 gdb_test_no_output "set print address off"
75 gdb_test_no_output "set width 0"
78 if ![runto_main] then {
79 perror "C function calling tests suppressed"
85 gdb_test "next" "g = shr1\\(g\\);" "next to shr1"
89 gdb_test "print g" "\[0-9\]* = 1" "print g"
92 if ![gdb_skip_stdio_test "next over shr1"] {
94 "address of sgs is $hex.*g = shr2\\(g\\);" \
97 gdb_test "next" ".*" ""
102 gdb_test "print g" "\[0-9\]* = 2" "print g"
105 if ![gdb_skip_stdio_test "print shr1(1)"] {
106 gdb_test "print shr1(1)" \
107 "address of sgs is $hex.*\[0-9\]* = 2" \
112 if ![gdb_skip_stdio_test "print shr1(g)"] {
113 gdb_test "print shr1(g)" \
114 "address of sgs is $hex.*\[0-9\]* = 4" \
120 gdb_test "break shr2" \
121 "Breakpoint.*file.*shr2.c, line.*" \
122 "breakpoint function shr2"
124 gdb_test "continue" \
125 "Continuing\\..*Breakpoint \[0-9\]+, shr2 \\(.*\\) at.*shr2\\.c:7.*7.*return 2.x;" \
126 "run until breakpoint set at a function"
130 if ![gdb_skip_stdio_test "print shr1(1) 2nd time"] {
131 gdb_test "print shr1(1)" \
132 "address of sgs is $hex.*\[0-9\]* = 2" \
133 "print shr1(1) 2nd time"
137 gdb_test "print mainshr1(1)" "\[0-9\]* = 2" \
138 "print mainshr1(1) from shlib func"
141 # A step at this point will either take us entirely out of
142 # the function or into the function's epilogue. The exact
143 # behavior will differ depending upon upon whether or not
144 # the compiler emits line number information for the epilogue.
145 gdb_test_multiple "step" "step out of shr2 to main" {
146 -re "main \\(\\) at.*g = mainshr1\\(g\\);.*$gdb_prompt $" {
147 pass "step out of shr2 to main"
149 -re ".*\\\}.*$gdb_prompt $" {
150 pass "step out of shr2 to main (stopped in shr2 epilogue)"
152 "main \\(\\) at.*g = mainshr1\\(g\\);" \
153 "step out of shr2 epilogue to main"
158 gdb_test "print mainshr1(1)" "\[0-9\]* = 2" "print mainshr1(1)"
161 gdb_test "step" "mainshr1 \\(g=4\\) at.*return 2.g;" \
164 # Start with a fresh gdb.
168 gdb_reinitialize_dir $srcdir/$subdir
170 gdb_test_no_output "set print sevenbit-strings"
171 gdb_test_no_output "set print address off"
172 gdb_test_no_output "set width 0"
176 # test that we can re-set breakpoints in shared libraries
177 gdb_breakpoint "shr1" "allow-pending"
179 # FIXME: should not send "run" explicitly. Non-portable.
181 if ![is_remote target] {
182 gdb_test "run" "Starting program:.*Breakpoint .,.*" \
183 "run to bp in shared library"
187 gdb_test "run" "Starting program:.*Breakpoint .,.*" \
188 "re-run to bp in shared library (PR's 16495, 18213)"