Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / shlib-call.exp
CommitLineData
88b9d363 1# Copyright 1997-2022 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
0ab77f5f
TT
36standard_testfile shmain.c shr1.c shr2.c
37set srcfile ${srcdir}/${subdir}/${srcfile}
38set lib1src ${srcdir}/${subdir}/${srcfile2}
39set lib2src ${srcdir}/${subdir}/${srcfile3}
40set lib1 [standard_output_file shr1.sl]
41set lib2 [standard_output_file shr2.sl]
f07e55f0
PG
42
43set lib_opts "debug"
44set exec_opts [list debug shlib=${lib1} shlib=${lib2}]
c906108c 45
4c93b1db 46if [get_compiler_info] {
c906108c
SS
47 return -1
48}
49
f07e55f0
PG
50if { [gdb_compile_shlib ${lib1src} ${lib1} $lib_opts] != ""
51 || [gdb_compile_shlib ${lib2src} ${lib2} $lib_opts] != ""
52 || [gdb_compile ${srcfile} ${binfile} executable $exec_opts] != ""} {
84c93cd5 53 untested "failed to compile"
f07e55f0 54 return -1
c906108c
SS
55}
56
c906108c
SS
57# Start with a fresh gdb.
58
0ab77f5f 59clean_restart ${binfile}
d9019901
SM
60gdb_load_shlib $lib1
61gdb_load_shlib $lib2
93f02886 62
02746bbc
MS
63gdb_test_no_output "set print sevenbit-strings"
64gdb_test_no_output "set print address off"
65gdb_test_no_output "set width 0"
c906108c
SS
66
67
68if ![runto_main] then {
69 perror "C function calling tests suppressed"
70}
71
72
73#step -over
74
dedad4e3 75gdb_test "next 2" "g = shr1\\(g\\);" "next to shr1"
c906108c
SS
76
77#print g
78
11af934b 79gdb_test "print g" "\[0-9\]* = 1"
c906108c
SS
80
81#step -over
02746bbc 82if ![gdb_skip_stdio_test "next over shr1"] {
39413b29
PA
83 gdb_test_stdio "next" \
84 "address of sgs is $hex" \
85 "g = shr2\\(g\\);" \
02746bbc
MS
86 "next over shr1"
87} else {
de7ff789 88 gdb_test "next" ".*" ""
02746bbc 89}
13a5e3b8 90
c906108c
SS
91
92#print g
11af934b 93gdb_test "print g" "\[0-9\]* = 2"
c906108c
SS
94
95#print shr1(1)
02746bbc 96if ![gdb_skip_stdio_test "print shr1(1)"] {
39413b29
PA
97 gdb_test_stdio "print shr1(1)" \
98 "address of sgs is $hex" \
99 "\[0-9\]* = 2" \
02746bbc
MS
100 "print shr1(1)"
101}
c906108c
SS
102
103#print shr1(g)
02746bbc 104if ![gdb_skip_stdio_test "print shr1(g)"] {
39413b29
PA
105 gdb_test_stdio "print shr1(g)" \
106 "address of sgs is $hex" \
107 "\[0-9\]* = 4" \
02746bbc
MS
108 "print shr1(g)"
109}
c906108c
SS
110
111#break shr2
112#go
113gdb_test "break shr2" \
114 "Breakpoint.*file.*shr2.c, line.*" \
115 "breakpoint function shr2"
116
13a5e3b8 117gdb_test "continue" \
b0e59b8f 118 "Continuing\\..*Breakpoint ${decimal}, shr2 \\(.*\\) at.*shr2\\.c:${decimal}.*shr2-return \\*\\/" \
13a5e3b8 119 "run until breakpoint set at a function"
c906108c
SS
120
121
122#print shr1(1)
13a5e3b8 123if ![gdb_skip_stdio_test "print shr1(1) 2nd time"] {
39413b29
PA
124 gdb_test_stdio "print shr1(1)" \
125 "address of sgs is $hex" \
126 "\[0-9\]* = 2" \
02746bbc 127 "print shr1(1) 2nd time"
13a5e3b8 128}
c906108c
SS
129
130#print mainshr1(1)
02746bbc
MS
131gdb_test "print mainshr1(1)" "\[0-9\]* = 2" \
132 "print mainshr1(1) from shlib func"
c906108c
SS
133
134#step -return
02746bbc
MS
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.
139gdb_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"
142 }
143 -re ".*\\\}.*$gdb_prompt $" {
144 pass "step out of shr2 to main (stopped in shr2 epilogue)"
0fc2a808
TV
145 gdb_test_multiple "step" "step out of shr2 epilogue to main" {
146 -re -wrap "main \\(\\) at.*g = mainshr1\\(g\\);" {
147 pass $gdb_test_name
148 }
149 -re -wrap "main \\(\\) at.*g = shr2\\(g\\);" {
150 gdb_test "step" "g = mainshr1\\(g\\);" $gdb_test_name
151 }
152 }
c906108c 153 }
02746bbc 154}
6fde09ad 155
c906108c 156#print mainshr1(1)
11af934b 157gdb_test "print mainshr1(1)" "\[0-9\]* = 2"
c906108c
SS
158
159#step
02746bbc
MS
160gdb_test "step" "mainshr1 \\(g=4\\) at.*return 2.g;" \
161 "step into mainshr1"
c906108c
SS
162
163# Start with a fresh gdb.
164
165gdb_exit
166gdb_start
167gdb_reinitialize_dir $srcdir/$subdir
168gdb_load ${binfile}
02746bbc
MS
169gdb_test_no_output "set print sevenbit-strings"
170gdb_test_no_output "set print address off"
171gdb_test_no_output "set width 0"
172
c906108c
SS
173
174# PR's 16495, 18213
175# test that we can re-set breakpoints in shared libraries
55264cb4 176gdb_breakpoint "shr1" "allow-pending"
13a5e3b8 177
5e830d98
PA
178set test "run to bp in shared library"
179gdb_run_cmd
180gdb_test_multiple "" $test {
181 -re "Breakpoint .,.*${gdb_prompt} " {
182 pass $test
183 }
184}
13a5e3b8 185
5e830d98 186gdb_continue_to_end "" continue 1
13a5e3b8 187
5e830d98
PA
188set test "re-run to bp in shared library (PR's 16495, 18213)"
189gdb_run_cmd
190gdb_test_multiple "" $test {
191 -re "Breakpoint .,.*${gdb_prompt} " {
192 pass $test
193 }
676a0442 194}
c906108c 195
5e830d98 196gdb_continue_to_end "" continue 1
This page took 2.534143 seconds and 4 git commands to generate.