1 # Copyright 1997-2019 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]} {
36 standard_testfile shmain.c shr1.c shr2.c
37 set srcfile ${srcdir}/${subdir}/${srcfile}
38 set lib1src ${srcdir}/${subdir}/${srcfile2}
39 set lib2src ${srcdir}/${subdir}/${srcfile3}
40 set lib1 [standard_output_file shr1.sl]
41 set lib2 [standard_output_file shr2.sl]
44 set exec_opts [list debug shlib=${lib1} shlib=${lib2}]
46 if [get_compiler_info] {
50 if { [gdb_compile_shlib ${lib1src} ${lib1} $lib_opts] != ""
51 || [gdb_compile_shlib ${lib2src} ${lib2} $lib_opts] != ""
52 || [gdb_compile ${srcfile} ${binfile} executable $exec_opts] != ""} {
53 untested "failed to compile"
57 # Start with a fresh gdb.
59 clean_restart ${binfile}
63 gdb_test_no_output "set print sevenbit-strings"
64 gdb_test_no_output "set print address off"
65 gdb_test_no_output "set width 0"
68 if ![runto_main] then {
69 perror "C function calling tests suppressed"
75 gdb_test "next 2" "g = shr1\\(g\\);" "next to shr1"
79 gdb_test "print g" "\[0-9\]* = 1" "print g"
82 if ![gdb_skip_stdio_test "next over shr1"] {
83 gdb_test_stdio "next" \
84 "address of sgs is $hex" \
88 gdb_test "next" ".*" ""
93 gdb_test "print g" "\[0-9\]* = 2" "print g"
96 if ![gdb_skip_stdio_test "print shr1(1)"] {
97 gdb_test_stdio "print shr1(1)" \
98 "address of sgs is $hex" \
104 if ![gdb_skip_stdio_test "print shr1(g)"] {
105 gdb_test_stdio "print shr1(g)" \
106 "address of sgs is $hex" \
113 gdb_test "break shr2" \
114 "Breakpoint.*file.*shr2.c, line.*" \
115 "breakpoint function shr2"
117 gdb_test "continue" \
118 "Continuing\\..*Breakpoint ${decimal}, shr2 \\(.*\\) at.*shr2\\.c:${decimal}.*shr2-return \\*\\/" \
119 "run until breakpoint set at a function"
123 if ![gdb_skip_stdio_test "print shr1(1) 2nd time"] {
124 gdb_test_stdio "print shr1(1)" \
125 "address of sgs is $hex" \
127 "print shr1(1) 2nd time"
131 gdb_test "print mainshr1(1)" "\[0-9\]* = 2" \
132 "print mainshr1(1) from shlib func"
135 # A step at this point will either take us entirely out of
136 # the function or into the function's epilogue. The exact
137 # behavior will differ depending upon upon whether or not
138 # the compiler emits line number information for the epilogue.
139 gdb_test_multiple "step" "step out of shr2 to main" {
140 -re "main \\(\\) at.*g = mainshr1\\(g\\);.*$gdb_prompt $" {
141 pass "step out of shr2 to main"
143 -re ".*\\\}.*$gdb_prompt $" {
144 pass "step out of shr2 to main (stopped in shr2 epilogue)"
146 "main \\(\\) at.*g = mainshr1\\(g\\);" \
147 "step out of shr2 epilogue to main"
152 gdb_test "print mainshr1(1)" "\[0-9\]* = 2" "print mainshr1(1)"
155 gdb_test "step" "mainshr1 \\(g=4\\) at.*return 2.g;" \
158 # Start with a fresh gdb.
162 gdb_reinitialize_dir $srcdir/$subdir
164 gdb_test_no_output "set print sevenbit-strings"
165 gdb_test_no_output "set print address off"
166 gdb_test_no_output "set width 0"
170 # test that we can re-set breakpoints in shared libraries
171 gdb_breakpoint "shr1" "allow-pending"
173 set test "run to bp in shared library"
175 gdb_test_multiple "" $test {
176 -re "Breakpoint .,.*${gdb_prompt} " {
181 gdb_continue_to_end "" continue 1
183 set test "re-run to bp in shared library (PR's 16495, 18213)"
185 gdb_test_multiple "" $test {
186 -re "Breakpoint .,.*${gdb_prompt} " {
191 gdb_continue_to_end "" continue 1