1 # Copyright 2020-2023 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 # Test defining bad conditions for breakpoints.
20 if {[prepare_for_testing "failed to prepare" ${binfile} ${srcfile}]} {
24 set bp_location [gdb_get_line_number "break-here"]
25 gdb_breakpoint "$bp_location"
26 set bpnum [get_integer_valueof "\$bpnum" 0 "get bpnum"]
28 # Define a 'bad' condition. The breakpoint should stay unconditional.
29 gdb_test "cond $bpnum gibberish" \
30 "No symbol \"gibberish\" in current context." \
31 "attempt a bad condition"
35 gdb_test "info break" \
38 "${decimal}${fill}breakpoint${fill}keep y${fill}:${bp_location}"] \
39 "breakpoint is unconditional"
41 # Now define a valid condition. Attempt to override that with a 'bad'
42 # condition again. The condition should be preserved.
43 with_test_prefix "with run" {
44 gdb_test_no_output "cond $bpnum a == 10"
46 gdb_test "cond $bpnum gibberish" \
47 "No symbol \"gibberish\" in current context." \
48 "attempt a bad condition"
50 gdb_test "info break" \
53 "${decimal}${fill}breakpoint${fill}keep y${fill}:${bp_location}" \
54 "${fill}stop only if a == 10${fill}"] \
55 "breakpoint condition is preserved"
57 # Run the code. We should hit the breakpoint, because the
58 # condition evaluates to true.
61 gdb_test "" ".*reakpoint .*, main .*${srcfile}.*" "run to the bp"
64 # Restart. Repeat the test above after the program has started.
65 # This is needed to check a scenario where the breakpoints are no
66 # longer re-inserted due to solib events. Note that runto_main
67 # deletes the breakpoints.
68 with_test_prefix "with continue 1" {
73 gdb_breakpoint "$bp_location"
74 set bpnum [get_integer_valueof "\$bpnum" 0 "get bpnum"]
76 gdb_test_no_output "cond $bpnum a == 10"
78 gdb_test "cond $bpnum gibberish" \
79 "No symbol \"gibberish\" in current context." \
80 "attempt a bad condition"
82 # Resume. We should hit the breakpoint, because the
83 # condition evaluates to true.
84 gdb_continue_to_breakpoint "${srcfile}:${bp_location}"
87 # Repeat with a condition that evaluates to false.
88 with_test_prefix "with continue 2" {
93 gdb_breakpoint "$bp_location"
94 set bpnum [get_integer_valueof "\$bpnum" 0 "get bpnum"]
96 gdb_test_no_output "cond $bpnum a == 999"
98 gdb_test "cond $bpnum gibberish" \
99 "No symbol \"gibberish\" in current context." \
100 "attempt a bad condition"
102 # Resume. We should *not* hit the breakpoint, because the
103 # condition evaluates to false.
107 # Repeat with a condition that contains junk at the end.
108 with_test_prefix "with junk" {
113 gdb_breakpoint "$bp_location"
114 set bpnum [get_integer_valueof "\$bpnum" 0 "get bpnum"]
116 gdb_test_no_output "cond $bpnum a == 999"
118 gdb_test "cond $bpnum a == 10 if" \
119 "Junk at end of expression" \
120 "attempt a bad condition"
122 # Resume. We should *not* hit the breakpoint, because the
123 # condition evaluates to false.