1 # Copyright 1997-2000, 2004, 2007-2012 Free Software Foundation, Inc.
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 3 of the License, or
6 # (at your option) any later version.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # file to test calls into shared libraries
17 # the source files for this test are:
22 # ss.h (header for shr2.c)
24 # file written by Elena Zannoni: elz@ch.apollo.com
36 if {[skip_shlib_tests]} {
43 set srcfile ${srcdir}/${subdir}/${testfile}.c
44 set lib1src ${srcdir}/${subdir}/${libfile1}.c
45 set lib2src ${srcdir}/${subdir}/${libfile2}.c
46 set lib1 ${objdir}/${subdir}/${libfile1}.sl
47 set lib2 ${objdir}/${subdir}/${libfile2}.sl
48 set binfile ${objdir}/${subdir}/${testfile}
51 set exec_opts [list debug shlib=${lib1} shlib=${lib2}]
53 if [get_compiler_info ${binfile}] {
57 if { [gdb_compile_shlib ${lib1src} ${lib1} $lib_opts] != ""
58 || [gdb_compile_shlib ${lib2src} ${lib2} $lib_opts] != ""
59 || [gdb_compile ${srcfile} ${binfile} executable $exec_opts] != ""} {
60 untested "Could not compile $lib1, $lib2, or $srcfile."
64 # Start with a fresh gdb.
68 gdb_reinitialize_dir $srcdir/$subdir
70 gdb_load_shlibs $lib1 $lib2
72 gdb_test_no_output "set print sevenbit-strings"
73 gdb_test_no_output "set print address off"
74 gdb_test_no_output "set width 0"
77 if ![runto_main] then {
78 perror "C function calling tests suppressed"
84 gdb_test "next" "g = shr1\\(g\\);" "next to shr1"
88 gdb_test "print g" "\[0-9\]* = 1" "print g"
91 if ![gdb_skip_stdio_test "next over shr1"] {
93 "address of sgs is $hex.*g = shr2\\(g\\);" \
96 gdb_test "next" ".*" ""
101 gdb_test "print g" "\[0-9\]* = 2" "print g"
104 if ![gdb_skip_stdio_test "print shr1(1)"] {
105 gdb_test "print shr1(1)" \
106 "address of sgs is $hex.*\[0-9\]* = 2" \
111 if ![gdb_skip_stdio_test "print shr1(g)"] {
112 gdb_test "print shr1(g)" \
113 "address of sgs is $hex.*\[0-9\]* = 4" \
119 gdb_test "break shr2" \
120 "Breakpoint.*file.*shr2.c, line.*" \
121 "breakpoint function shr2"
123 gdb_test "continue" \
124 "Continuing\\..*Breakpoint \[0-9\]+, shr2 \\(.*\\) at.*shr2\\.c:7.*7.*return 2.x;" \
125 "run until breakpoint set at a function"
129 if ![gdb_skip_stdio_test "print shr1(1) 2nd time"] {
130 gdb_test "print shr1(1)" \
131 "address of sgs is $hex.*\[0-9\]* = 2" \
132 "print shr1(1) 2nd time"
136 gdb_test "print mainshr1(1)" "\[0-9\]* = 2" \
137 "print mainshr1(1) from shlib func"
140 # A step at this point will either take us entirely out of
141 # the function or into the function's epilogue. The exact
142 # behavior will differ depending upon upon whether or not
143 # the compiler emits line number information for the epilogue.
144 gdb_test_multiple "step" "step out of shr2 to main" {
145 -re "main \\(\\) at.*g = mainshr1\\(g\\);.*$gdb_prompt $" {
146 pass "step out of shr2 to main"
148 -re ".*\\\}.*$gdb_prompt $" {
149 pass "step out of shr2 to main (stopped in shr2 epilogue)"
151 "main \\(\\) at.*g = mainshr1\\(g\\);" \
152 "step out of shr2 epilogue to main"
157 gdb_test "print mainshr1(1)" "\[0-9\]* = 2" "print mainshr1(1)"
160 gdb_test "step" "mainshr1 \\(g=4\\) at.*return 2.g;" \
163 # Start with a fresh gdb.
167 gdb_reinitialize_dir $srcdir/$subdir
169 gdb_test_no_output "set print sevenbit-strings"
170 gdb_test_no_output "set print address off"
171 gdb_test_no_output "set width 0"
175 # test that we can re-set breakpoints in shared libraries
176 gdb_breakpoint "shr1" "allow-pending"
178 # FIXME: should not send "run" explicitly. Non-portable.
180 if ![is_remote target] {
181 gdb_test "run" "Starting program:.*Breakpoint .,.*" \
182 "run to bp in shared library"
184 gdb_continue_to_end "" continue 1
186 gdb_test "run" "Starting program:.*Breakpoint .,.*" \
187 "re-run to bp in shared library (PR's 16495, 18213)"
189 gdb_continue_to_end "" continue 1