1 # Copyright 2020 Free Software Foundation, Inc. 2 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. 7 # 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. 12 # 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/>. 15 16 # Test defining bad conditions for breakpoints. 17 18 standard_testfile 19 20 if {[prepare_for_testing "failed to prepare" ${binfile} ${srcfile}]} { 21 return 22 } 23 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"] 27 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" 32 33 set fill "\[^\r\n\]*" 34 35 gdb_test "info break" \ 36 [multi_line \ 37 "Num${fill}What" \ 38 "${decimal}${fill}breakpoint${fill}keep y${fill}:${bp_location}"] \ 39 "breakpoint is unconditional" 40 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" 45 46 gdb_test "cond $bpnum gibberish" \ 47 "No symbol \"gibberish\" in current context." \ 48 "attempt a bad condition" 49 50 gdb_test "info break" \ 51 [multi_line \ 52 "Num${fill}What" \ 53 "${decimal}${fill}breakpoint${fill}keep y${fill}:${bp_location}" \ 54 "${fill}stop only if a == 10${fill}"] \ 55 "breakpoint condition is preserved" 56 57 # Run the code. We should hit the breakpoint, because the 58 # condition evaluates to true. 59 60 gdb_run_cmd 61 gdb_test "" ".*reakpoint .*, main .*${srcfile}.*" "run to the bp" 62 } 63 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" { 69 if {![runto_main]} { 70 fail "could not run to main" 71 return -1 72 } 73 74 gdb_breakpoint "$bp_location" 75 set bpnum [get_integer_valueof "\$bpnum" 0 "get bpnum"] 76 77 gdb_test_no_output "cond $bpnum a == 10" 78 79 gdb_test "cond $bpnum gibberish" \ 80 "No symbol \"gibberish\" in current context." \ 81 "attempt a bad condition" 82 83 # Resume. We should hit the breakpoint, because the 84 # condition evaluates to true. 85 gdb_continue_to_breakpoint "${srcfile}:${bp_location}" 86 } 87 88 # Repeat with a condition that evaluates to false. 89 with_test_prefix "with continue 2" { 90 if {![runto_main]} { 91 fail "could not run to main" 92 return -1 93 } 94 95 gdb_breakpoint "$bp_location" 96 set bpnum [get_integer_valueof "\$bpnum" 0 "get bpnum"] 97 98 gdb_test_no_output "cond $bpnum a == 999" 99 100 gdb_test "cond $bpnum gibberish" \ 101 "No symbol \"gibberish\" in current context." \ 102 "attempt a bad condition" 103 104 # Resume. We should *not* hit the breakpoint, because the 105 # condition evaluates to false. 106 gdb_continue_to_end 107 } 108 109 # Repeat with a condition that contains junk at the end. 110 with_test_prefix "with junk" { 111 if {![runto_main]} { 112 fail "could not run to main" 113 return -1 114 } 115 116 gdb_breakpoint "$bp_location" 117 set bpnum [get_integer_valueof "\$bpnum" 0 "get bpnum"] 118 119 gdb_test_no_output "cond $bpnum a == 999" 120 121 gdb_test "cond $bpnum a == 10 if" \ 122 "Junk at end of expression" \ 123 "attempt a bad condition" 124 125 # Resume. We should *not* hit the breakpoint, because the 126 # condition evaluates to false. 127 gdb_continue_to_end 128 } 129