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
32 if {[skip_shlib_tests]} {
39 set srcfile ${srcdir}/${subdir}/${testfile}.c
40 set lib1src ${srcdir}/${subdir}/${libfile1}.c
41 set lib2src ${srcdir}/${subdir}/${libfile2}.c
42 set lib1 ${objdir}/${subdir}/${libfile1}.sl
43 set lib2 ${objdir}/${subdir}/${libfile2}.sl
44 set binfile ${objdir}/${subdir}/${testfile}
47 set exec_opts [list debug shlib=${lib1} shlib=${lib2}]
49 if [get_compiler_info ${binfile}] {
53 if { [gdb_compile_shlib ${lib1src} ${lib1} $lib_opts] != ""
54 || [gdb_compile_shlib ${lib2src} ${lib2} $lib_opts] != ""
55 || [gdb_compile ${srcfile} ${binfile} executable $exec_opts] != ""} {
56 untested "Could not compile $lib1, $lib2, or $srcfile."
60 # Start with a fresh gdb.
64 gdb_reinitialize_dir $srcdir/$subdir
66 gdb_load_shlibs $lib1 $lib2
68 gdb_test_no_output "set print sevenbit-strings"
69 gdb_test_no_output "set print address off"
70 gdb_test_no_output "set width 0"
73 if ![runto_main] then {
74 perror "C function calling tests suppressed"
80 gdb_test "next" "g = shr1\\(g\\);" "next to shr1"
84 gdb_test "print g" "\[0-9\]* = 1" "print g"
87 if ![gdb_skip_stdio_test "next over shr1"] {
89 "address of sgs is $hex.*g = shr2\\(g\\);" \
92 gdb_test "next" ".*" ""
97 gdb_test "print g" "\[0-9\]* = 2" "print g"
100 if ![gdb_skip_stdio_test "print shr1(1)"] {
101 gdb_test "print shr1(1)" \
102 "address of sgs is $hex.*\[0-9\]* = 2" \
107 if ![gdb_skip_stdio_test "print shr1(g)"] {
108 gdb_test "print shr1(g)" \
109 "address of sgs is $hex.*\[0-9\]* = 4" \
115 gdb_test "break shr2" \
116 "Breakpoint.*file.*shr2.c, line.*" \
117 "breakpoint function shr2"
119 gdb_test "continue" \
120 "Continuing\\..*Breakpoint \[0-9\]+, shr2 \\(.*\\) at.*shr2\\.c:7.*7.*return 2.x;" \
121 "run until breakpoint set at a function"
125 if ![gdb_skip_stdio_test "print shr1(1) 2nd time"] {
126 gdb_test "print shr1(1)" \
127 "address of sgs is $hex.*\[0-9\]* = 2" \
128 "print shr1(1) 2nd time"
132 gdb_test "print mainshr1(1)" "\[0-9\]* = 2" \
133 "print mainshr1(1) from shlib func"
136 # A step at this point will either take us entirely out of
137 # the function or into the function's epilogue. The exact
138 # behavior will differ depending upon upon whether or not
139 # the compiler emits line number information for the epilogue.
140 gdb_test_multiple "step" "step out of shr2 to main" {
141 -re "main \\(\\) at.*g = mainshr1\\(g\\);.*$gdb_prompt $" {
142 pass "step out of shr2 to main"
144 -re ".*\\\}.*$gdb_prompt $" {
145 pass "step out of shr2 to main (stopped in shr2 epilogue)"
147 "main \\(\\) at.*g = mainshr1\\(g\\);" \
148 "step out of shr2 epilogue to main"
153 gdb_test "print mainshr1(1)" "\[0-9\]* = 2" "print mainshr1(1)"
156 gdb_test "step" "mainshr1 \\(g=4\\) at.*return 2.g;" \
159 # Start with a fresh gdb.
163 gdb_reinitialize_dir $srcdir/$subdir
165 gdb_test_no_output "set print sevenbit-strings"
166 gdb_test_no_output "set print address off"
167 gdb_test_no_output "set width 0"
171 # test that we can re-set breakpoints in shared libraries
172 gdb_breakpoint "shr1" "allow-pending"
174 # FIXME: should not send "run" explicitly. Non-portable.
176 if ![is_remote target] {
177 gdb_test "run" "Starting program:.*Breakpoint .,.*" \
178 "run to bp in shared library"
180 gdb_continue_to_end "" continue 1
182 gdb_test "run" "Starting program:.*Breakpoint .,.*" \
183 "re-run to bp in shared library (PR's 16495, 18213)"
185 gdb_continue_to_end "" continue 1