1 # Copyright 2003-2024 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 require allow_shlib_tests
26 set libsrc $srcdir/$subdir/$libfile.c
27 set lib_sl [standard_output_file $libfile.sl]
30 set exec_opts [list debug shlib=$lib_sl]
32 if { [gdb_compile_shlib $libsrc $lib_sl $lib_opts] != ""
33 || [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $exec_opts] != ""} {
34 untested "failed to compile"
40 gdb_test_multiple "break pendfunc1" "set pending breakpoint" {
41 -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
42 gdb_test "y" "Breakpoint.*pendfunc1.*pending." "set pending breakpoint, without symbols"
46 # Complete the condition (PR 15413).
47 gdb_test "complete condition " "condition 1"
49 gdb_test "info break" \
50 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
51 \[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendfunc1.*" \
52 "single pending breakpoint info, without symbols"
54 with_test_prefix "first load" {
56 gdb_load_shlib $lib_sl
59 set pendfunc1_loc [gdb_get_line_number "y = x + 4" ${libfile}.c]
64 ".*Breakpoint.*pendfunc1.*at.*pendshr.c:$pendfunc1_loc.*y = x \\+ 4.*" \
65 "run to resolved breakpoint 1 (without symbols)"
69 with_test_prefix "second load" {
71 gdb_load_shlib $lib_sl
75 # Test setting, querying, and modifying pending breakpoints
78 gdb_test_multiple "break pendfunc1" "set pending breakpoint" {
79 -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
80 gdb_test "y" "Breakpoint.*pendfunc1.*pending." "set pending breakpoint"
84 gdb_test "info break" \
85 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
86 \[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendfunc1.*" \
87 "single pending breakpoint info"
90 # Test breaking at existing function
93 set mainline [gdb_get_line_number "break main here"]
95 gdb_test "break -q main" \
96 "Breakpoint.*at.* file .*$srcfile, line $mainline.*" \
99 gdb_test "info break" \
100 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
101 \[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendfunc1.*
102 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$mainline" \
103 "pending plus real breakpoint info"
107 # Test not setting a pending breakpoint
109 gdb_test "break pendfunc2" \
111 "Don't set pending breakpoint" \
112 ".*Make breakpoint pending.*y or \\\[n\\\]. $" \
116 # Add condition to pending breakpoint
119 gdb_test_no_output "condition 1 k == 1"
121 gdb_test "info break" \
122 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
123 \[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendfunc1.*
124 \[\t \]+stop only if k == 1.*
125 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$mainline" \
126 "pending plus condition"
129 # Disable pending breakpoint
132 gdb_test_no_output "disable 1"
134 gdb_test "info break" \
135 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
136 \[0-9\]+\[\t \]+breakpoint keep n.*PENDING.*pendfunc1.*
137 \[\t \]+stop only if k == 1.*
138 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$mainline" \
142 # Add commands to pending breakpoint
144 gdb_test "commands 1\nprint k\nend" "" \
145 "Set commands for pending breakpoint"
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.*
152 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$mainline" \
153 "pending disabled plus commands"
156 # Try a pending break for a line in a source file with a condition
159 set bp2_loc [gdb_get_line_number "y = x + 4" ${libfile}.c]
160 gdb_test_multiple "break pendshr.c:$bp2_loc if x > 3" "set pending breakpoint 2" {
161 -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
162 gdb_test "y" "Breakpoint.*pendshr.c:$bp2_loc.*pending." \
163 "Set pending breakpoint 2"
167 gdb_test "info break" \
168 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
169 \[0-9\]+\[\t \]+breakpoint keep n.*PENDING.*pendfunc1.*
170 \[\t \]+stop only if k == 1.*
172 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$mainline.*
173 \[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendshr.c:$bp2_loc.*
174 \\s+stop only if x > 3.*" \
175 "multiple pending breakpoints"
179 # Try a pending break for a line in a source file with ignore count:
182 set bp3_loc [gdb_get_line_number "printf" ${libfile}.c]
183 gdb_test_multiple "break pendshr.c:$bp3_loc" "set pending breakpoint 3" {
184 -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
185 gdb_test "y" "Breakpoint.*pendshr.c:$bp3_loc.*pending." \
186 "Set pending breakpoint 3"
190 gdb_test {ignore $bpnum 2} "Will ignore next 2 crossings of breakpoint .*" \
191 "set ignore count on pending breakpoint 3"
193 gdb_test "info break" \
194 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
195 \[0-9\]+\[\t \]+breakpoint keep n.*PENDING.*pendfunc1.*
196 \[\t \]+stop only if k == 1.*
198 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$mainline.*
199 \[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendshr.c:$bp2_loc.*
200 \\s+stop only if x > 3.*
201 \[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendshr.c:$bp3_loc.*
202 \\s+ignore next 2 hits.*" \
203 "multiple pending breakpoints 2"
206 # Run to main which should resolve a pending breakpoint
211 ".*Breakpoint.*, main.*$mainline.*" \
215 # Re-enable the first pending breakpoint which should resolve
218 gdb_test_no_output "enable 1" \
219 "re-enabling pending breakpoint that can resolve instantly"
222 # Continue to verify conditionals and commands for breakpoints are honored
225 gdb_test "continue" \
226 ".*Breakpoint.*pendfunc1.*at.*pendshr.c:$bp2_loc.*4;" \
227 "continue to resolved breakpoint 2"
229 gdb_test "continue" \
230 ".*Breakpoint.*pendfunc1.*at.*pendshr.c:$bp2_loc.*
232 "continue to resolved breakpoint 1"
235 # Disable the other two breakpoints, and continue to the one with
236 # the ignore count. Make sure you hit it the third time, x should
240 gdb_test "disable 7" "" "disable breakpoint 7"
241 gdb_test "disable 5" "" "disable breakpoint 5"
243 gdb_test "continue" \
244 ".*Breakpoint.*pendfunc1.*\\\(x=3\\\) at.*pendshr.c:$bp3_loc.*printf.*;" \
245 "continue to resolved breakpoint 3"
249 gdb_breakpoint "main"
252 # Set non-existent pending breakpoint
254 gdb_test_multiple "break imaginary" "set imaginary pending breakpoint" {
255 -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
256 gdb_test "y" "Breakpoint.*imaginary.*pending." \
257 "set imaginary pending breakpoint"
262 # rerun program and make sure that any pending breakpoint remains and no
263 # error messages are issued for the missing function
268 gdb_test "info break" \
269 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
270 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$mainline.*
271 \[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*imaginary.*" \
272 "verify pending breakpoint after restart"
274 # Test GDB's parsing of pending breakpoint thread and condition.
276 gdb_test_no_output "set breakpoint pending on"
277 gdb_test "break foo if (unknown_var && another_unknown_var) thread 1" \
278 "Breakpoint $decimal \\(foo\\) pending\\."
279 set bpnum [get_integer_valueof "\$bpnum" "*INVALID" \
280 "get number for foo breakpoint"]
282 if {[gdb_protocol_is_remote]} {
283 set evals_re "(?: \\(\[^) \]+ evals\\))?"
288 gdb_test "info breakpoints $bpnum" \
290 "$bpnum\\s+breakpoint\\s+keep\\s+y\\s+<PENDING>\\s+foo" \
291 "\\s+stop only if \\(unknown_var && another_unknown_var\\)${evals_re}" \
292 "\\s+stop only in thread 1"] \
293 "check pending breakpoint on foo"