gdb/doc/
[external/binutils.git] / gdb / testsuite / gdb.base / pending.exp
1 #   Copyright 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
2 #   Free Software Foundation, Inc.
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
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
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.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 # This file was created by Jeff Johnston. (jjohnstn@redhat.com)
18
19 if $tracelevel then {
20     strace $tracelevel
21 }
22
23 #
24 # test running programs
25 #
26
27 if {[skip_shlib_tests]} {
28     return 0
29 }
30
31 set testfile "pending"
32 set libfile "pendshr"
33 set srcfile $testfile.c
34 set libsrc  $srcdir/$subdir/$libfile.c
35 set binfile $objdir/$subdir/$testfile
36 set lib_sl  $objdir/$subdir/$libfile.sl
37
38 set lib_opts  debug
39 set exec_opts [list debug shlib=$lib_sl]
40
41 if [get_compiler_info ${binfile}] {
42     return -1
43 }
44
45 if { [gdb_compile_shlib $libsrc $lib_sl $lib_opts] != ""
46      || [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $exec_opts] != ""} {
47     untested "Could not compile either $libsrc or $srcdir/$subdir/$srcfile."
48     return -1
49 }
50
51 # Start with a fresh gdb.
52
53 gdb_exit
54 gdb_start
55 gdb_reinitialize_dir $srcdir/$subdir
56
57 gdb_test_multiple "break pendfunc1" "set pending breakpoint" {
58      -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
59             gdb_test "y" "Breakpoint.*pendfunc1.*pending." "set pending breakpoint (without symbols)"
60      }
61 }
62
63 gdb_test "info break" \
64     "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
65 \[0-9\]+\[\t \]+breakpoint     keep y.*PENDING.*pendfunc1.*" \
66 "single pending breakpoint info (without symbols)"
67
68 gdb_load ${binfile}
69 gdb_load_shlibs $lib_sl
70
71 set pendfunc1_loc [gdb_get_line_number "y = x + 4" ${libfile}.c]
72
73 gdb_run_cmd
74
75 gdb_test "" \
76 ".*Breakpoint.*pendfunc1.*at.*pendshr.c:$pendfunc1_loc.*y = x \\+ 4.*" \
77 "run to resolved breakpoint 1 (without symbols)"
78
79 # Restart with a fresh gdb.
80
81 gdb_exit
82 gdb_start
83 gdb_reinitialize_dir $srcdir/$subdir
84
85 gdb_load ${binfile}
86 gdb_load_shlibs $lib_sl
87
88 #
89 # Test setting, querying, and modifying pending breakpoints
90 #
91
92 gdb_test_multiple "break pendfunc1" "set pending breakpoint" {
93      -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
94             gdb_test "y" "Breakpoint.*pendfunc1.*pending." "set pending breakpoint"
95      }
96 }
97
98 gdb_test "info break" \
99     "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
100 \[0-9\]+\[\t \]+breakpoint     keep y.*PENDING.*pendfunc1.*" \
101 "single pending breakpoint info"
102
103 #
104 # Test breaking at existing function
105 #
106
107 set mainline [gdb_get_line_number "break main here"]
108
109 gdb_test "break main" \
110     "Breakpoint.*at.* file .*$srcfile, line $mainline.*" \
111     "breakpoint function"
112
113 gdb_test "info break" \
114     "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
115 \[0-9\]+\[\t \]+breakpoint     keep y.*PENDING.*pendfunc1.*
116 \[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:$mainline" \
117 "pending plus real breakpoint info"
118
119
120
121 # Test not setting a pending breakpoint 
122 #
123 gdb_test "break pendfunc2" \
124     "" \
125     "Don't set pending breakpoint" \
126     ".*Make breakpoint pending.*y or \\\[n\\\]. $" \
127     "n"
128
129 #
130 # Add condition to pending breakpoint 
131 #
132
133 gdb_test_no_output "condition 1 k == 1"
134
135 gdb_test "info break" \
136     "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
137 \[0-9\]+\[\t \]+breakpoint     keep y.*PENDING.*pendfunc1.*
138 \[\t \]+stop only if k == 1.*
139 \[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:$mainline" \
140 "pending plus condition"
141
142 #
143 # Disable pending breakpoint
144 #
145
146 gdb_test_no_output "disable 1"
147
148 gdb_test "info break" \
149     "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
150 \[0-9\]+\[\t \]+breakpoint     keep n.*PENDING.*pendfunc1.*
151 \[\t \]+stop only if k == 1.*
152 \[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:$mainline" \
153 "pending disabled"
154
155 #
156 # Add commands to pending breakpoint
157 #
158 gdb_test "commands 1\nprint k\nend" "" \
159     "Set commands for pending breakpoint"
160
161 gdb_test "info break" \
162     "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
163 \[0-9\]+\[\t \]+breakpoint     keep n.*PENDING.*pendfunc1.*
164 \[\t \]+stop only if k == 1.*
165 \[\t \]+print k.*
166 \[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:$mainline" \
167 "pending disabled plus commands"
168
169 #
170 # Try a pending break for a line in a source file with a condition
171 #
172
173 set bp2_loc [gdb_get_line_number "y = x + 4" ${libfile}.c]
174 gdb_test_multiple "break pendshr.c:$bp2_loc if x > 3" "Set pending breakpoint 2" {
175      -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
176             gdb_test "y" "Breakpoint.*pendshr.c:$bp2_loc.*pending." \
177                 "Set pending breakpoint 2"
178      }
179 }
180
181 gdb_test "info break" \
182     "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
183 \[0-9\]+\[\t \]+breakpoint     keep n.*PENDING.*pendfunc1.*
184 \[\t \]+stop only if k == 1.*
185 \[\t \]+print k.*
186 \[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:$mainline.*
187 \[0-9\]+\[\t \]+breakpoint     keep y.*PENDING.*pendshr.c:$bp2_loc if x > 3.*" \
188 "multiple pending breakpoints"
189
190
191 #
192 # Try a pending break for a line in a source file with ignore count:
193 #
194
195 set bp3_loc [gdb_get_line_number "printf" ${libfile}.c]
196 gdb_test_multiple "break pendshr.c:$bp3_loc" "Set pending breakpoint 3" {
197      -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
198             gdb_test "y" "Breakpoint.*pendshr.c:$bp3_loc.*pending." \
199                 "Set pending breakpoint 3"
200      }
201 }
202
203 gdb_test {ignore $bpnum 2} "Will ignore next 2 crossings of breakpoint .*" \
204     "set ignore count on pending breakpoint 3"
205
206 gdb_test "info break" \
207     "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
208 \[0-9\]+\[\t \]+breakpoint     keep n.*PENDING.*pendfunc1.*
209 \[\t \]+stop only if k == 1.*
210 \[\t \]+print k.*
211 \[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:$mainline.*
212 \[0-9\]+\[\t \]+breakpoint     keep y.*PENDING.*pendshr.c:$bp2_loc if x > 3.*
213 \[0-9\]+\[\t \]+breakpoint     keep y.*PENDING.*pendshr.c:$bp3_loc.*ignore next 2 hits.*" \
214 "multiple pending breakpoints 2"
215
216 #
217 # Run to main which should resolve a pending breakpoint
218 #
219
220 gdb_run_cmd
221 gdb_test "" \
222 ".*Breakpoint.*, main.*$mainline.*" \
223 "running to main"
224
225 #
226 # Re-enable the first pending breakpoint which should resolve
227 #
228
229 gdb_test_no_output "enable 1" \
230 "re-enabling pending breakpoint that can resolve instantly"
231
232 #
233 # Continue to verify conditionals and commands for breakpoints are honored
234 #
235
236 gdb_test "continue" \
237 ".*Breakpoint.*pendfunc1.*at.*pendshr.c:$bp2_loc.*4;" \
238 "continue to resolved breakpoint 2"
239
240 gdb_test "continue" \
241 ".*Breakpoint.*pendfunc1.*at.*pendshr.c:$bp2_loc.*
242 \[$\]1 = 1." \
243 "continue to resolved breakpoint 1"
244
245 #
246 # Disable the other two breakpoints, and continue to the one with
247 # the ignore count.  Make sure you hit it the third time, x should
248 # be 3 then.
249 #
250
251 gdb_test "disable 7" "" "Disable other breakpoints"
252 gdb_test "disable 5" "" "Disable other breakpoints"
253
254 gdb_test "continue" \
255          ".*Breakpoint.*pendfunc1.*\\\(x=3\\\) at.*pendshr.c:$bp3_loc.*printf.*;" \
256 "continue to resolved breakpoint 3"
257
258 delete_breakpoints
259
260 gdb_breakpoint "main"
261
262 #
263 # Set non-existent pending breakpoint
264 #
265 gdb_test_multiple "break imaginary" "set imaginary pending breakpoint" {
266      -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
267             gdb_test "y" "Breakpoint.*imaginary.*pending." \
268                 "set imaginary pending breakpoint"
269      }
270 }
271
272 #
273 # rerun program and make sure that any pending breakpoint remains and no
274 # error messages are issued for the missing function
275 #
276
277 rerun_to_main
278
279 gdb_test "info break" \
280     "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
281 \[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:$mainline.*
282 \[0-9\]+\[\t \]+breakpoint     keep y.*PENDING.*imaginary.*" \
283 "verify pending breakpoint after restart"