Update copyright year range in header of all files managed by GDB
[binutils-gdb.git] / gdb / testsuite / gdb.base / shlib-call.exp
blob735b8fd5ba62b1a2f393ff909fd48f29d6aa5acd
1 #   Copyright 1997-2023 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:
19 # shmain.c
20 # shr1.c (shared lib)
21 # shr2.c (shared lib)
22 # ss.h (header for shr2.c)
24 # file written by Elena Zannoni: elz@ch.apollo.com
27 #debug shmain
28 #prop lib shr1.sl
29 #prop lib shr2.sl
32 if {[skip_shlib_tests]} {
33     return 0
36 if { [is_remote host] } {
37     gdb_remote_download host $srcdir/$subdir/ss.h
40 standard_testfile shmain.c shr1.c shr2.c
41 set srcfile  ${srcdir}/${subdir}/${srcfile}
42 set lib1src  ${srcdir}/${subdir}/${srcfile2}
43 set lib2src  ${srcdir}/${subdir}/${srcfile3}
44 set lib1     [standard_output_file shr1.sl]
45 set lib2     [standard_output_file shr2.sl]
47 set lib_opts "debug"
48 set exec_opts [list debug shlib=${lib1} shlib=${lib2}]
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"
54     return -1
57 # Start with a fresh gdb.
59 clean_restart ${binfile}
60 gdb_load_shlib $lib1
61 gdb_load_shlib $lib2
64 if {![runto_main]} {
65     return
69 #step -over
71 gdb_test "next 2" "g = shr1\\(g\\);" "next to shr1"
73 #print g
75 gdb_test "print g" "\[0-9\]* = 1"
77 #step -over
78 if ![gdb_skip_stdio_test "next over shr1"] {
79     gdb_test_stdio "next" \
80         "address of sgs is $hex" \
81         "g = shr2\\(g\\);" \
82         "next over shr1"
83 } else {
84     gdb_test "next" ".*" ""
88 #print g
89 gdb_test "print g" "\[0-9\]* = 2" "print g two"
91 #print shr1(1)
92 if ![gdb_skip_stdio_test "print shr1(1)"] {
93     gdb_test_stdio "print shr1(1)" \
94         "address of sgs is $hex" \
95         "\[0-9\]* = 2" \
96         "print shr1(1)"
99 #print shr1(g)
100 if ![gdb_skip_stdio_test "print shr1(g)"] {
101     gdb_test_stdio "print shr1(g)" \
102         "address of sgs is $hex" \
103         "\[0-9\]* = 4" \
104         "print shr1(g)"
107 #break shr2
109 gdb_test "break shr2" \
110     "Breakpoint.*file.*shr2.c, line.*" \
111     "breakpoint function shr2"
113 gdb_test "continue" \
114         "Continuing\\..*Breakpoint ${decimal}, shr2 \\(.*\\) at.*shr2\\.c:${decimal}.*shr2-return \\*\\/" \
115         "run until breakpoint set at a function"
118 #print shr1(1)
119 if ![gdb_skip_stdio_test "print shr1(1) 2nd time"] {
120     gdb_test_stdio "print shr1(1)" \
121         "address of sgs is $hex" \
122         "\[0-9\]* = 2" \
123         "print shr1(1) 2nd time"
126 #print mainshr1(1)
127 gdb_test "print mainshr1(1)" "\[0-9\]* = 2" \
128     "print mainshr1(1) from shlib func"
130 #step -return
131 # A step at this point will either take us entirely out of
132 # the function or into the function's epilogue.  The exact
133 # behavior will differ depending upon upon whether or not
134 # the compiler emits line number information for the epilogue.
135 gdb_test_multiple "step" "step out of shr2 to main" {
136     -re "main \\(\\) at.*g = mainshr1\\(g\\);.*$gdb_prompt $" {
137         pass "step out of shr2 to main"
138     }
139     -re ".*\\\}.*$gdb_prompt $" {
140         pass "step out of shr2 to main (stopped in shr2 epilogue)"
141         gdb_test_multiple "step" "step out of shr2 epilogue to main" {
142             -re -wrap "main \\(\\) at.*g = mainshr1\\(g\\);" {
143                 pass $gdb_test_name
144             }
145             -re -wrap "main \\(\\) at.*g = shr2\\(g\\);" {
146                 gdb_test "step" "g = mainshr1\\(g\\);" $gdb_test_name
147             }
148         }
149     }
152 #print mainshr1(1)
153 gdb_test "print mainshr1(1)" "\[0-9\]* = 2"
155 #step
156 gdb_test "step" "mainshr1 \\(g=4\\) at.*return 2.g;" \
157     "step into mainshr1"
159 # Start with a fresh gdb.
161 clean_restart $binfile
163 # PR's 16495, 18213
164 # test that we can re-set breakpoints in shared libraries
165 gdb_breakpoint "shr1" "allow-pending"
167 set test "run to bp in shared library"
168 gdb_run_cmd
169 gdb_test_multiple "" $test {
170     -re "Breakpoint .,.*${gdb_prompt} " {
171         pass $gdb_test_name
172     }
175 gdb_continue_to_end "" continue 1
177 set test "re-run to bp in shared library (PR's 16495, 18213)"
178 gdb_run_cmd
179 gdb_test_multiple "" $test {
180     -re "Breakpoint .,.*${gdb_prompt} " {
181         pass $gdb_test_name
182     }
185 gdb_continue_to_end "after re-run" continue 1