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)
19 # test running programs
22 if {[skip_shlib_tests]} {
26 set testfile "pending"
28 set srcfile $testfile.c
29 set libsrc $srcdir/$subdir/$libfile.c
30 set binfile $objdir/$subdir/$testfile
31 set lib_sl $objdir/$subdir/$libfile.sl
34 set exec_opts [list debug shlib=$lib_sl]
36 if [get_compiler_info ${binfile}] {
40 if { [gdb_compile_shlib $libsrc $lib_sl $lib_opts] != ""
41 || [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $exec_opts] != ""} {
42 untested "Could not compile either $libsrc or $srcdir/$subdir/$srcfile."
46 # Start with a fresh gdb.
50 gdb_reinitialize_dir $srcdir/$subdir
52 gdb_test_multiple "break pendfunc1" "set pending breakpoint" {
53 -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
54 gdb_test "y" "Breakpoint.*pendfunc1.*pending." "set pending breakpoint (without symbols)"
58 gdb_test "info break" \
59 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
60 \[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendfunc1.*" \
61 "single pending breakpoint info (without symbols)"
64 gdb_load_shlibs $lib_sl
66 set pendfunc1_loc [gdb_get_line_number "y = x + 4" ${libfile}.c]
71 ".*Breakpoint.*pendfunc1.*at.*pendshr.c:$pendfunc1_loc.*y = x \\+ 4.*" \
72 "run to resolved breakpoint 1 (without symbols)"
74 # Restart with a fresh gdb.
78 gdb_reinitialize_dir $srcdir/$subdir
81 gdb_load_shlibs $lib_sl
84 # Test setting, querying, and modifying pending breakpoints
87 gdb_test_multiple "break pendfunc1" "set pending breakpoint" {
88 -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
89 gdb_test "y" "Breakpoint.*pendfunc1.*pending." "set pending breakpoint"
93 gdb_test "info break" \
94 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
95 \[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendfunc1.*" \
96 "single pending breakpoint info"
99 # Test breaking at existing function
102 set mainline [gdb_get_line_number "break main here"]
104 gdb_test "break main" \
105 "Breakpoint.*at.* file .*$srcfile, line $mainline.*" \
106 "breakpoint function"
108 gdb_test "info break" \
109 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
110 \[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendfunc1.*
111 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$mainline" \
112 "pending plus real breakpoint info"
116 # Test not setting a pending breakpoint
118 gdb_test "break pendfunc2" \
120 "Don't set pending breakpoint" \
121 ".*Make breakpoint pending.*y or \\\[n\\\]. $" \
125 # Add condition to pending breakpoint
128 gdb_test_no_output "condition 1 k == 1"
130 gdb_test "info break" \
131 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
132 \[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendfunc1.*
133 \[\t \]+stop only if k == 1.*
134 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$mainline" \
135 "pending plus condition"
138 # Disable pending breakpoint
141 gdb_test_no_output "disable 1"
143 gdb_test "info break" \
144 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
145 \[0-9\]+\[\t \]+breakpoint keep n.*PENDING.*pendfunc1.*
146 \[\t \]+stop only if k == 1.*
147 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$mainline" \
151 # Add commands to pending breakpoint
153 gdb_test "commands 1\nprint k\nend" "" \
154 "Set commands for pending breakpoint"
156 gdb_test "info break" \
157 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
158 \[0-9\]+\[\t \]+breakpoint keep n.*PENDING.*pendfunc1.*
159 \[\t \]+stop only if k == 1.*
161 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$mainline" \
162 "pending disabled plus commands"
165 # Try a pending break for a line in a source file with a condition
168 set bp2_loc [gdb_get_line_number "y = x + 4" ${libfile}.c]
169 gdb_test_multiple "break pendshr.c:$bp2_loc if x > 3" "Set pending breakpoint 2" {
170 -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
171 gdb_test "y" "Breakpoint.*pendshr.c:$bp2_loc.*pending." \
172 "Set pending breakpoint 2"
176 gdb_test "info break" \
177 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
178 \[0-9\]+\[\t \]+breakpoint keep n.*PENDING.*pendfunc1.*
179 \[\t \]+stop only if k == 1.*
181 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$mainline.*
182 \[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendshr.c:$bp2_loc if x > 3.*" \
183 "multiple pending breakpoints"
187 # Try a pending break for a line in a source file with ignore count:
190 set bp3_loc [gdb_get_line_number "printf" ${libfile}.c]
191 gdb_test_multiple "break pendshr.c:$bp3_loc" "Set pending breakpoint 3" {
192 -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
193 gdb_test "y" "Breakpoint.*pendshr.c:$bp3_loc.*pending." \
194 "Set pending breakpoint 3"
198 gdb_test {ignore $bpnum 2} "Will ignore next 2 crossings of breakpoint .*" \
199 "set ignore count on pending breakpoint 3"
201 gdb_test "info break" \
202 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
203 \[0-9\]+\[\t \]+breakpoint keep n.*PENDING.*pendfunc1.*
204 \[\t \]+stop only if k == 1.*
206 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$mainline.*
207 \[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendshr.c:$bp2_loc if x > 3.*
208 \[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendshr.c:$bp3_loc.*ignore next 2 hits.*" \
209 "multiple pending breakpoints 2"
212 # Run to main which should resolve a pending breakpoint
217 ".*Breakpoint.*, main.*$mainline.*" \
221 # Re-enable the first pending breakpoint which should resolve
224 gdb_test_no_output "enable 1" \
225 "re-enabling pending breakpoint that can resolve instantly"
228 # Continue to verify conditionals and commands for breakpoints are honored
231 gdb_test "continue" \
232 ".*Breakpoint.*pendfunc1.*at.*pendshr.c:$bp2_loc.*4;" \
233 "continue to resolved breakpoint 2"
235 gdb_test "continue" \
236 ".*Breakpoint.*pendfunc1.*at.*pendshr.c:$bp2_loc.*
238 "continue to resolved breakpoint 1"
241 # Disable the other two breakpoints, and continue to the one with
242 # the ignore count. Make sure you hit it the third time, x should
246 gdb_test "disable 7" "" "Disable other breakpoints"
247 gdb_test "disable 5" "" "Disable other breakpoints"
249 gdb_test "continue" \
250 ".*Breakpoint.*pendfunc1.*\\\(x=3\\\) at.*pendshr.c:$bp3_loc.*printf.*;" \
251 "continue to resolved breakpoint 3"
255 gdb_breakpoint "main"
258 # Set non-existent pending breakpoint
260 gdb_test_multiple "break imaginary" "set imaginary pending breakpoint" {
261 -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
262 gdb_test "y" "Breakpoint.*imaginary.*pending." \
263 "set imaginary pending breakpoint"
268 # rerun program and make sure that any pending breakpoint remains and no
269 # error messages are issued for the missing function
274 gdb_test "info break" \
275 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
276 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$mainline.*
277 \[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*imaginary.*" \
278 "verify pending breakpoint after restart"