]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/shlib-call.exp
run copyright.sh for 2011.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / shlib-call.exp
CommitLineData
7b6bb8da 1# Copyright 1997, 1998, 1999, 2000, 2004, 2007, 2008, 2009, 2010, 2011
6aba47ca 2# Free Software Foundation, Inc.
c906108c
SS
3
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
e22f8b7c 6# the Free Software Foundation; either version 3 of the License, or
c906108c 7# (at your option) any later version.
e22f8b7c 8#
c906108c
SS
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.
e22f8b7c 13#
c906108c 14# You should have received a copy of the GNU General Public License
e22f8b7c 15# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 16
c906108c
SS
17# file to test calls into shared libraries
18# the source files for this test are:
19#
20# shmain.c
21# shr1.c (shared lib)
22# shr2.c (shared lib)
23# ss.h (header for shr2.c)
24#
25# file written by Elena Zannoni: elz@ch.apollo.com
26#
27
28#debug shmain
29#prop lib shr1.sl
30#prop lib shr2.sl
31
32if $tracelevel then {
33 strace $tracelevel
34}
35
c906108c 36
93f02886 37if {[skip_shlib_tests]} {
c906108c
SS
38 return 0
39}
40
41set testfile "shmain"
f07e55f0
PG
42set libfile1 "shr1"
43set libfile2 "shr2"
44set srcfile ${srcdir}/${subdir}/${testfile}.c
45set lib1src ${srcdir}/${subdir}/${libfile1}.c
46set lib2src ${srcdir}/${subdir}/${libfile2}.c
47set lib1 ${objdir}/${subdir}/${libfile1}.sl
48set lib2 ${objdir}/${subdir}/${libfile2}.sl
49set binfile ${objdir}/${subdir}/${testfile}
50
51set lib_opts "debug"
52set exec_opts [list debug shlib=${lib1} shlib=${lib2}]
c906108c 53
c906108c
SS
54if [get_compiler_info ${binfile}] {
55 return -1
56}
57
f07e55f0
PG
58if { [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."
62 return -1
c906108c
SS
63}
64
c906108c
SS
65# Start with a fresh gdb.
66
67gdb_exit
68gdb_start
69gdb_reinitialize_dir $srcdir/$subdir
70gdb_load ${binfile}
93f02886
DJ
71gdb_load_shlibs $lib1 $lib2
72
02746bbc
MS
73gdb_test_no_output "set print sevenbit-strings"
74gdb_test_no_output "set print address off"
75gdb_test_no_output "set width 0"
c906108c
SS
76
77
78if ![runto_main] then {
79 perror "C function calling tests suppressed"
80}
81
82
83#step -over
84
02746bbc 85gdb_test "next" "g = shr1\\(g\\);" "next to shr1"
c906108c
SS
86
87#print g
88
02746bbc 89gdb_test "print g" "\[0-9\]* = 1" "print g"
c906108c
SS
90
91#step -over
02746bbc
MS
92if ![gdb_skip_stdio_test "next over shr1"] {
93 gdb_test "next" \
94 "address of sgs is $hex.*g = shr2\\(g\\);" \
95 "next over shr1"
96} else {
de7ff789 97 gdb_test "next" ".*" ""
02746bbc 98}
13a5e3b8 99
c906108c
SS
100
101#print g
02746bbc 102gdb_test "print g" "\[0-9\]* = 2" "print g"
c906108c
SS
103
104#print shr1(1)
02746bbc
MS
105if ![gdb_skip_stdio_test "print shr1(1)"] {
106 gdb_test "print shr1(1)" \
107 "address of sgs is $hex.*\[0-9\]* = 2" \
108 "print shr1(1)"
109}
c906108c
SS
110
111#print shr1(g)
02746bbc
MS
112if ![gdb_skip_stdio_test "print shr1(g)"] {
113 gdb_test "print shr1(g)" \
114 "address of sgs is $hex.*\[0-9\]* = 4" \
115 "print shr1(g)"
116}
c906108c
SS
117
118#break shr2
119#go
120gdb_test "break shr2" \
121 "Breakpoint.*file.*shr2.c, line.*" \
122 "breakpoint function shr2"
123
13a5e3b8
MS
124gdb_test "continue" \
125 "Continuing\\..*Breakpoint \[0-9\]+, shr2 \\(.*\\) at.*shr2\\.c:7.*7.*return 2.x;" \
126 "run until breakpoint set at a function"
c906108c
SS
127
128
129#print shr1(1)
13a5e3b8 130if ![gdb_skip_stdio_test "print shr1(1) 2nd time"] {
02746bbc
MS
131 gdb_test "print shr1(1)" \
132 "address of sgs is $hex.*\[0-9\]* = 2" \
133 "print shr1(1) 2nd time"
13a5e3b8 134}
c906108c
SS
135
136#print mainshr1(1)
02746bbc
MS
137gdb_test "print mainshr1(1)" "\[0-9\]* = 2" \
138 "print mainshr1(1) from shlib func"
c906108c
SS
139
140#step -return
02746bbc
MS
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.
145gdb_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"
148 }
149 -re ".*\\\}.*$gdb_prompt $" {
150 pass "step out of shr2 to main (stopped in shr2 epilogue)"
151 gdb_test "step" \
152 "main \\(\\) at.*g = mainshr1\\(g\\);" \
153 "step out of shr2 epilogue to main"
c906108c 154 }
02746bbc 155}
6fde09ad 156
c906108c 157#print mainshr1(1)
02746bbc 158gdb_test "print mainshr1(1)" "\[0-9\]* = 2" "print mainshr1(1)"
c906108c
SS
159
160#step
02746bbc
MS
161gdb_test "step" "mainshr1 \\(g=4\\) at.*return 2.g;" \
162 "step into mainshr1"
c906108c
SS
163
164# Start with a fresh gdb.
165
166gdb_exit
167gdb_start
168gdb_reinitialize_dir $srcdir/$subdir
169gdb_load ${binfile}
02746bbc
MS
170gdb_test_no_output "set print sevenbit-strings"
171gdb_test_no_output "set print address off"
172gdb_test_no_output "set width 0"
173
c906108c
SS
174
175# PR's 16495, 18213
176# test that we can re-set breakpoints in shared libraries
55264cb4 177gdb_breakpoint "shr1" "allow-pending"
13a5e3b8
MS
178
179# FIXME: should not send "run" explicitly. Non-portable.
180
676a0442 181if ![is_remote target] {
55264cb4 182 gdb_test "run" "Starting program:.*Breakpoint .,.*" \
13a5e3b8
MS
183 "run to bp in shared library"
184
676a0442 185 gdb_test "cont" ".*Program exited normally..*"
13a5e3b8 186
55264cb4 187 gdb_test "run" "Starting program:.*Breakpoint .,.*" \
13a5e3b8
MS
188 "re-run to bp in shared library (PR's 16495, 18213)"
189
676a0442
DJ
190 gdb_test "cont" ".*Program exited normally..*"
191}
c906108c
SS
192
193return 0