1 # Copyright 2003-2005, 2007-2012 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 # This file was created by Jeff Johnston. (jjohnstn@redhat.com)
23 # test running programs
26 if {[skip_shlib_tests]} {
30 set testfile "pending"
32 set srcfile $testfile.c
33 set libsrc $srcdir/$subdir/$libfile.c
34 set binfile $objdir/$subdir/$testfile
35 set lib_sl $objdir/$subdir/$libfile.sl
38 set exec_opts [list debug shlib=$lib_sl]
40 if [get_compiler_info ${binfile}] {
44 if { [gdb_compile_shlib $libsrc $lib_sl $lib_opts] != ""
45 || [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $exec_opts] != ""} {
46 untested "Could not compile either $libsrc or $srcdir/$subdir/$srcfile."
50 # Start with a fresh gdb.
54 gdb_reinitialize_dir $srcdir/$subdir
56 gdb_test_multiple "break pendfunc1" "set pending breakpoint" {
57 -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
58 gdb_test "y" "Breakpoint.*pendfunc1.*pending." "set pending breakpoint (without symbols)"
62 gdb_test "info break" \
63 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
64 \[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendfunc1.*" \
65 "single pending breakpoint info (without symbols)"
68 gdb_load_shlibs $lib_sl
70 set pendfunc1_loc [gdb_get_line_number "y = x + 4" ${libfile}.c]
75 ".*Breakpoint.*pendfunc1.*at.*pendshr.c:$pendfunc1_loc.*y = x \\+ 4.*" \
76 "run to resolved breakpoint 1 (without symbols)"
78 # Restart with a fresh gdb.
82 gdb_reinitialize_dir $srcdir/$subdir
85 gdb_load_shlibs $lib_sl
88 # Test setting, querying, and modifying pending breakpoints
91 gdb_test_multiple "break pendfunc1" "set pending breakpoint" {
92 -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
93 gdb_test "y" "Breakpoint.*pendfunc1.*pending." "set pending breakpoint"
97 gdb_test "info break" \
98 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
99 \[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendfunc1.*" \
100 "single pending breakpoint info"
103 # Test breaking at existing function
106 set mainline [gdb_get_line_number "break main here"]
108 gdb_test "break main" \
109 "Breakpoint.*at.* file .*$srcfile, line $mainline.*" \
110 "breakpoint function"
112 gdb_test "info break" \
113 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
114 \[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendfunc1.*
115 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$mainline" \
116 "pending plus real breakpoint info"
120 # Test not setting a pending breakpoint
122 gdb_test "break pendfunc2" \
124 "Don't set pending breakpoint" \
125 ".*Make breakpoint pending.*y or \\\[n\\\]. $" \
129 # Add condition to pending breakpoint
132 gdb_test_no_output "condition 1 k == 1"
134 gdb_test "info break" \
135 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
136 \[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendfunc1.*
137 \[\t \]+stop only if k == 1.*
138 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$mainline" \
139 "pending plus condition"
142 # Disable pending breakpoint
145 gdb_test_no_output "disable 1"
147 gdb_test "info break" \
148 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
149 \[0-9\]+\[\t \]+breakpoint keep n.*PENDING.*pendfunc1.*
150 \[\t \]+stop only if k == 1.*
151 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$mainline" \
155 # Add commands to pending breakpoint
157 gdb_test "commands 1\nprint k\nend" "" \
158 "Set commands for pending breakpoint"
160 gdb_test "info break" \
161 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
162 \[0-9\]+\[\t \]+breakpoint keep n.*PENDING.*pendfunc1.*
163 \[\t \]+stop only if k == 1.*
165 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$mainline" \
166 "pending disabled plus commands"
169 # Try a pending break for a line in a source file with a condition
172 set bp2_loc [gdb_get_line_number "y = x + 4" ${libfile}.c]
173 gdb_test_multiple "break pendshr.c:$bp2_loc if x > 3" "Set pending breakpoint 2" {
174 -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
175 gdb_test "y" "Breakpoint.*pendshr.c:$bp2_loc.*pending." \
176 "Set pending breakpoint 2"
180 gdb_test "info break" \
181 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
182 \[0-9\]+\[\t \]+breakpoint keep n.*PENDING.*pendfunc1.*
183 \[\t \]+stop only if k == 1.*
185 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$mainline.*
186 \[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendshr.c:$bp2_loc if x > 3.*" \
187 "multiple pending breakpoints"
191 # Try a pending break for a line in a source file with ignore count:
194 set bp3_loc [gdb_get_line_number "printf" ${libfile}.c]
195 gdb_test_multiple "break pendshr.c:$bp3_loc" "Set pending breakpoint 3" {
196 -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
197 gdb_test "y" "Breakpoint.*pendshr.c:$bp3_loc.*pending." \
198 "Set pending breakpoint 3"
202 gdb_test {ignore $bpnum 2} "Will ignore next 2 crossings of breakpoint .*" \
203 "set ignore count on pending breakpoint 3"
205 gdb_test "info break" \
206 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
207 \[0-9\]+\[\t \]+breakpoint keep n.*PENDING.*pendfunc1.*
208 \[\t \]+stop only if k == 1.*
210 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$mainline.*
211 \[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendshr.c:$bp2_loc if x > 3.*
212 \[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendshr.c:$bp3_loc.*ignore next 2 hits.*" \
213 "multiple pending breakpoints 2"
216 # Run to main which should resolve a pending breakpoint
221 ".*Breakpoint.*, main.*$mainline.*" \
225 # Re-enable the first pending breakpoint which should resolve
228 gdb_test_no_output "enable 1" \
229 "re-enabling pending breakpoint that can resolve instantly"
232 # Continue to verify conditionals and commands for breakpoints are honored
235 gdb_test "continue" \
236 ".*Breakpoint.*pendfunc1.*at.*pendshr.c:$bp2_loc.*4;" \
237 "continue to resolved breakpoint 2"
239 gdb_test "continue" \
240 ".*Breakpoint.*pendfunc1.*at.*pendshr.c:$bp2_loc.*
242 "continue to resolved breakpoint 1"
245 # Disable the other two breakpoints, and continue to the one with
246 # the ignore count. Make sure you hit it the third time, x should
250 gdb_test "disable 7" "" "Disable other breakpoints"
251 gdb_test "disable 5" "" "Disable other breakpoints"
253 gdb_test "continue" \
254 ".*Breakpoint.*pendfunc1.*\\\(x=3\\\) at.*pendshr.c:$bp3_loc.*printf.*;" \
255 "continue to resolved breakpoint 3"
259 gdb_breakpoint "main"
262 # Set non-existent pending breakpoint
264 gdb_test_multiple "break imaginary" "set imaginary pending breakpoint" {
265 -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
266 gdb_test "y" "Breakpoint.*imaginary.*pending." \
267 "set imaginary pending breakpoint"
272 # rerun program and make sure that any pending breakpoint remains and no
273 # error messages are issued for the missing function
278 gdb_test "info break" \
279 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
280 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$mainline.*
281 \[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*imaginary.*" \
282 "verify pending breakpoint after restart"