1 # Copyright 2003, 2004, 2005, 2007, 2008, 2009
2 # Free Software Foundation, Inc.
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.
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.
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/>.
17 # This file was created by Jeff Johnston. (jjohnstn@redhat.com)
24 # test running programs
29 if {[skip_shlib_tests]} {
33 set testfile "pending"
35 set srcfile $testfile.c
36 set libsrc $srcdir/$subdir/$libfile.c
37 set binfile $objdir/$subdir/$testfile
38 set lib_sl $objdir/$subdir/$libfile.sl
41 set exec_opts [list debug shlib=$lib_sl]
43 if [get_compiler_info ${binfile}] {
47 if { [gdb_compile_shlib $libsrc $lib_sl $lib_opts] != ""
48 || [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $exec_opts] != ""} {
49 untested "Could not compile either $libsrc or $srcdir/$subdir/$srcfile."
53 # Start with a fresh gdb.
57 gdb_reinitialize_dir $srcdir/$subdir
59 gdb_test_multiple "break pendfunc1" "set pending breakpoint" {
60 -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
61 gdb_test "y" "Breakpoint.*pendfunc1.*pending." "set pending breakpoint (without symbols)"
65 gdb_test "info break" \
66 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
67 \[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendfunc1.*" \
68 "single pending breakpoint info (without symbols)"
71 gdb_load_shlibs $lib_sl
73 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
87 if [target_info exists gdb_stub] {
91 # Test setting, querying, and modifying pending breakpoints
94 gdb_test_multiple "break pendfunc1" "set pending breakpoint" {
95 -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
96 gdb_test "y" "Breakpoint.*pendfunc1.*pending." "set pending breakpoint"
100 gdb_test "info break" \
101 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
102 \[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendfunc1.*" \
103 "single pending breakpoint info"
106 # Test breaking at existing function
109 set mainline [gdb_get_line_number "break main here"]
111 gdb_test "break main" \
112 "Breakpoint.*at.* file .*$srcfile, line $mainline.*" \
113 "breakpoint function"
115 gdb_test "info break" \
116 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
117 \[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendfunc1.*
118 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$mainline" \
119 "pending plus real breakpoint info"
123 # Test not setting a pending breakpoint
125 gdb_test_multiple "break pendfunc2" "Don't set pending breakpoint" {
126 -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
127 gdb_test "n" "" "Don't set pending breakpoint"
132 # Add condition to pending breakpoint
135 gdb_test "condition 1 k == 1" ""
137 gdb_test "info break" \
138 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
139 \[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendfunc1.*
140 \[\t \]+stop only if k == 1.*
141 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$mainline" \
142 "pending plus condition"
145 # Disable pending breakpoint
148 gdb_test "disable 1" ""
150 gdb_test "info break" \
151 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
152 \[0-9\]+\[\t \]+breakpoint keep n.*PENDING.*pendfunc1.*
153 \[\t \]+stop only if k == 1.*
154 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$mainline" \
158 # Add commands to pending breakpoint
160 gdb_test "commands 1\nprint k\nend" "" \
161 "Set commands for pending breakpoint"
163 gdb_test "info break" \
164 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
165 \[0-9\]+\[\t \]+breakpoint keep n.*PENDING.*pendfunc1.*
166 \[\t \]+stop only if k == 1.*
168 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$mainline" \
169 "pending disabled plus commands"
172 # Try a pending break for a line in a source file with a condition
175 set bp2_loc [gdb_get_line_number "y = x + 4" ${libfile}.c]
176 gdb_test_multiple "break pendshr.c:$bp2_loc if x > 3" "Set pending breakpoint 2" {
177 -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
178 gdb_test "y" "Breakpoint.*pendshr.c:$bp2_loc.*pending." \
179 "Set pending breakpoint 2"
183 gdb_test "info break" \
184 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
185 \[0-9\]+\[\t \]+breakpoint keep n.*PENDING.*pendfunc1.*
186 \[\t \]+stop only if k == 1.*
188 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$mainline.*
189 \[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendshr.c:$bp2_loc if x > 3.*" \
190 "multiple pending breakpoints"
194 # Try a pending break for a line in a source file with ignore count:
197 set bp3_loc [gdb_get_line_number "printf" ${libfile}.c]
198 gdb_test_multiple "break pendshr.c:$bp3_loc" "Set pending breakpoint 3" {
199 -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
200 gdb_test "y" "Breakpoint.*pendshr.c:$bp3_loc.*pending." \
201 "Set pending breakpoint 3"
205 gdb_test {ignore $bpnum 2} "Will ignore next 2 crossings of breakpoint .*" \
206 "set ignore count on pending breakpoint 3"
208 gdb_test "info break" \
209 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
210 \[0-9\]+\[\t \]+breakpoint keep n.*PENDING.*pendfunc1.*
211 \[\t \]+stop only if k == 1.*
213 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$mainline.*
214 \[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendshr.c:$bp2_loc if x > 3.*
215 \[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendshr.c:$bp3_loc.*ignore next 2 hits.*" \
216 "multiple pending breakpoints 2"
219 # Run to main which should resolve a pending breakpoint
224 ".*Breakpoint.*, main.*$mainline.*" \
228 # Re-enable the first pending breakpoint which should resolve
231 gdb_test "enable 1" \
233 "re-enabling pending breakpoint that can resolve instantly"
236 # Continue to verify conditionals and commands for breakpoints are honored
239 gdb_test "continue" \
240 ".*Breakpoint.*pendfunc1.*at.*pendshr.c:$bp2_loc.*4;" \
241 "continue to resolved breakpoint 2"
243 gdb_test "continue" \
244 ".*Breakpoint.*pendfunc1.*at.*pendshr.c:$bp2_loc.*
246 "continue to resolved breakpoint 1"
249 # Disable the other two breakpoints, and continue to the one with
250 # the ignore count. Make sure you hit it the third time, x should
254 gdb_test "disable 7" "" "Disable other breakpoints"
255 gdb_test "disable 5" "" "Disable other breakpoints"
257 gdb_test "continue" \
258 ".*Breakpoint.*pendfunc1.*\\\(x=3\\\) at.*pendshr.c:$bp3_loc.*printf.*;" \
259 "continue to resolved breakpoint 3"
263 gdb_breakpoint "main"
266 # Set non-existent pending breakpoint
268 gdb_test_multiple "break imaginary" "set imaginary pending breakpoint" {
269 -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
270 gdb_test "y" "Breakpoint.*imaginary.*pending." \
271 "set imaginary pending breakpoint"
276 # rerun program and make sure that any pending breakpoint remains and no
277 # error messages are issued for the missing function
282 gdb_test "info break" \
283 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
284 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$mainline.*
285 \[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*imaginary.*" \
286 "verify pending breakpoint after restart"