OSDN Git Service

c8a574582fb867fe7bfda87d65938280309c819f
[pf3gnuchains/pf3gnuchains4x.git] / gdb / testsuite / gdb.base / shlib-call.exp
1 #   Copyright 1997-2000, 2004, 2007-2012 Free Software Foundation, Inc.
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
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
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.
12 #
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/>.
15
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
31 if $tracelevel then {
32         strace $tracelevel
33 }
34
35
36 if {[skip_shlib_tests]} {
37     return 0
38 }
39
40 set testfile "shmain"
41 set libfile1 "shr1"
42 set libfile2 "shr2"
43 set srcfile  ${srcdir}/${subdir}/${testfile}.c
44 set lib1src  ${srcdir}/${subdir}/${libfile1}.c
45 set lib2src  ${srcdir}/${subdir}/${libfile2}.c
46 set lib1     ${objdir}/${subdir}/${libfile1}.sl
47 set lib2     ${objdir}/${subdir}/${libfile2}.sl
48 set binfile  ${objdir}/${subdir}/${testfile}
49
50 set lib_opts "debug"
51 set exec_opts [list debug shlib=${lib1} shlib=${lib2}]
52
53 if [get_compiler_info ${binfile}] {
54     return -1
55 }
56
57 if { [gdb_compile_shlib ${lib1src} ${lib1} $lib_opts] != ""
58      || [gdb_compile_shlib ${lib2src} ${lib2} $lib_opts] != ""
59      || [gdb_compile ${srcfile} ${binfile} executable $exec_opts] != ""} {
60     untested "Could not compile $lib1, $lib2, or $srcfile."
61     return -1
62 }
63
64 # Start with a fresh gdb.
65
66 gdb_exit
67 gdb_start
68 gdb_reinitialize_dir $srcdir/$subdir
69 gdb_load ${binfile}
70 gdb_load_shlibs $lib1 $lib2
71
72 gdb_test_no_output "set print sevenbit-strings"
73 gdb_test_no_output "set print address off"
74 gdb_test_no_output "set width 0"
75
76
77 if ![runto_main] then {
78         perror "C function calling tests suppressed"
79 }
80
81
82 #step -over
83
84 gdb_test "next" "g = shr1\\(g\\);" "next to shr1"
85
86 #print g
87
88 gdb_test "print g" "\[0-9\]* = 1" "print g"
89
90 #step -over
91 if ![gdb_skip_stdio_test "next over shr1"] {
92     gdb_test "next" \
93         "address of sgs is $hex.*g = shr2\\(g\\);" \
94         "next over shr1"
95 } else {
96     gdb_test "next" ".*" ""
97 }
98
99
100 #print g
101 gdb_test "print g" "\[0-9\]* = 2" "print g"
102
103 #print shr1(1)
104 if ![gdb_skip_stdio_test "print shr1(1)"] {
105     gdb_test "print shr1(1)" \
106         "address of sgs is $hex.*\[0-9\]* = 2" \
107         "print shr1(1)"
108 }
109
110 #print shr1(g)
111 if ![gdb_skip_stdio_test "print shr1(g)"] {
112     gdb_test "print shr1(g)" \
113         "address of sgs is $hex.*\[0-9\]* = 4" \
114         "print shr1(g)"
115 }
116
117 #break shr2
118 #go
119 gdb_test "break shr2" \
120     "Breakpoint.*file.*shr2.c, line.*" \
121     "breakpoint function shr2"
122
123 gdb_test "continue" \
124         "Continuing\\..*Breakpoint \[0-9\]+, shr2 \\(.*\\) at.*shr2\\.c:7.*7.*return 2.x;" \
125         "run until breakpoint set at a function"
126
127
128 #print shr1(1)
129 if ![gdb_skip_stdio_test "print shr1(1) 2nd time"] {
130     gdb_test "print shr1(1)" \
131         "address of sgs is $hex.*\[0-9\]* = 2" \
132         "print shr1(1) 2nd time"
133 }
134
135 #print mainshr1(1)
136 gdb_test "print mainshr1(1)" "\[0-9\]* = 2" \
137     "print mainshr1(1) from shlib func"
138
139 #step -return
140 # A step at this point will either take us entirely out of
141 # the function or into the function's epilogue.  The exact
142 # behavior will differ depending upon upon whether or not
143 # the compiler emits line number information for the epilogue.
144 gdb_test_multiple "step" "step out of shr2 to main" {
145     -re "main \\(\\) at.*g = mainshr1\\(g\\);.*$gdb_prompt $" { 
146         pass "step out of shr2 to main"
147     }
148     -re ".*\\\}.*$gdb_prompt $" {
149         pass "step out of shr2 to main (stopped in shr2 epilogue)"
150         gdb_test "step" \
151             "main \\(\\) at.*g = mainshr1\\(g\\);" \
152             "step out of shr2 epilogue to main"
153     }
154 }
155     
156 #print mainshr1(1)
157 gdb_test "print mainshr1(1)" "\[0-9\]* = 2" "print mainshr1(1)"
158
159 #step
160 gdb_test "step" "mainshr1 \\(g=4\\) at.*return 2.g;" \
161     "step into mainshr1"
162
163 # Start with a fresh gdb.
164
165 gdb_exit
166 gdb_start
167 gdb_reinitialize_dir $srcdir/$subdir
168 gdb_load ${binfile}
169 gdb_test_no_output "set print sevenbit-strings"
170 gdb_test_no_output "set print address off"
171 gdb_test_no_output "set width 0"
172
173
174 # PR's 16495, 18213
175 # test that we can re-set breakpoints in shared libraries
176 gdb_breakpoint "shr1" "allow-pending"
177
178 # FIXME: should not send "run" explicitly.  Non-portable.
179
180 if ![is_remote target] {
181   gdb_test "run" "Starting program:.*Breakpoint .,.*" \
182         "run to bp in shared library"
183
184   gdb_continue_to_end "" continue 1
185
186   gdb_test "run" "Starting program:.*Breakpoint .,.*" \
187         "re-run to bp in shared library (PR's 16495, 18213)"
188
189   gdb_continue_to_end "" continue 1
190 }
191
192 return 0