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