1 1.1.1.2 christos # Copyright 2020-2023 Free Software Foundation, Inc. 2 1.1 christos 3 1.1 christos # This program is free software; you can redistribute it and/or modify 4 1.1 christos # it under the terms of the GNU General Public License as published by 5 1.1 christos # the Free Software Foundation; either version 3 of the License, or 6 1.1 christos # (at your option) any later version. 7 1.1 christos # 8 1.1 christos # This program is distributed in the hope that it will be useful, 9 1.1 christos # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 1.1 christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 1.1 christos # GNU General Public License for more details. 12 1.1 christos # 13 1.1 christos # You should have received a copy of the GNU General Public License 14 1.1 christos # along with this program. If not, see <http://www.gnu.org/licenses/>. 15 1.1 christos 16 1.1 christos # Test defining bad conditions for breakpoints. 17 1.1 christos 18 1.1 christos standard_testfile 19 1.1 christos 20 1.1 christos if {[prepare_for_testing "failed to prepare" ${binfile} ${srcfile}]} { 21 1.1 christos return 22 1.1 christos } 23 1.1 christos 24 1.1 christos set bp_location [gdb_get_line_number "break-here"] 25 1.1 christos gdb_breakpoint "$bp_location" 26 1.1 christos set bpnum [get_integer_valueof "\$bpnum" 0 "get bpnum"] 27 1.1 christos 28 1.1 christos # Define a 'bad' condition. The breakpoint should stay unconditional. 29 1.1 christos gdb_test "cond $bpnum gibberish" \ 30 1.1 christos "No symbol \"gibberish\" in current context." \ 31 1.1 christos "attempt a bad condition" 32 1.1 christos 33 1.1 christos set fill "\[^\r\n\]*" 34 1.1 christos 35 1.1 christos gdb_test "info break" \ 36 1.1 christos [multi_line \ 37 1.1 christos "Num${fill}What" \ 38 1.1 christos "${decimal}${fill}breakpoint${fill}keep y${fill}:${bp_location}"] \ 39 1.1 christos "breakpoint is unconditional" 40 1.1 christos 41 1.1 christos # Now define a valid condition. Attempt to override that with a 'bad' 42 1.1 christos # condition again. The condition should be preserved. 43 1.1 christos with_test_prefix "with run" { 44 1.1 christos gdb_test_no_output "cond $bpnum a == 10" 45 1.1 christos 46 1.1 christos gdb_test "cond $bpnum gibberish" \ 47 1.1 christos "No symbol \"gibberish\" in current context." \ 48 1.1 christos "attempt a bad condition" 49 1.1 christos 50 1.1 christos gdb_test "info break" \ 51 1.1 christos [multi_line \ 52 1.1 christos "Num${fill}What" \ 53 1.1 christos "${decimal}${fill}breakpoint${fill}keep y${fill}:${bp_location}" \ 54 1.1 christos "${fill}stop only if a == 10${fill}"] \ 55 1.1 christos "breakpoint condition is preserved" 56 1.1 christos 57 1.1 christos # Run the code. We should hit the breakpoint, because the 58 1.1 christos # condition evaluates to true. 59 1.1 christos 60 1.1 christos gdb_run_cmd 61 1.1 christos gdb_test "" ".*reakpoint .*, main .*${srcfile}.*" "run to the bp" 62 1.1 christos } 63 1.1 christos 64 1.1 christos # Restart. Repeat the test above after the program has started. 65 1.1 christos # This is needed to check a scenario where the breakpoints are no 66 1.1 christos # longer re-inserted due to solib events. Note that runto_main 67 1.1 christos # deletes the breakpoints. 68 1.1 christos with_test_prefix "with continue 1" { 69 1.1 christos if {![runto_main]} { 70 1.1 christos return -1 71 1.1 christos } 72 1.1 christos 73 1.1 christos gdb_breakpoint "$bp_location" 74 1.1 christos set bpnum [get_integer_valueof "\$bpnum" 0 "get bpnum"] 75 1.1 christos 76 1.1 christos gdb_test_no_output "cond $bpnum a == 10" 77 1.1 christos 78 1.1 christos gdb_test "cond $bpnum gibberish" \ 79 1.1 christos "No symbol \"gibberish\" in current context." \ 80 1.1 christos "attempt a bad condition" 81 1.1 christos 82 1.1 christos # Resume. We should hit the breakpoint, because the 83 1.1 christos # condition evaluates to true. 84 1.1 christos gdb_continue_to_breakpoint "${srcfile}:${bp_location}" 85 1.1 christos } 86 1.1 christos 87 1.1 christos # Repeat with a condition that evaluates to false. 88 1.1 christos with_test_prefix "with continue 2" { 89 1.1 christos if {![runto_main]} { 90 1.1 christos return -1 91 1.1 christos } 92 1.1 christos 93 1.1 christos gdb_breakpoint "$bp_location" 94 1.1 christos set bpnum [get_integer_valueof "\$bpnum" 0 "get bpnum"] 95 1.1 christos 96 1.1 christos gdb_test_no_output "cond $bpnum a == 999" 97 1.1 christos 98 1.1 christos gdb_test "cond $bpnum gibberish" \ 99 1.1 christos "No symbol \"gibberish\" in current context." \ 100 1.1 christos "attempt a bad condition" 101 1.1 christos 102 1.1 christos # Resume. We should *not* hit the breakpoint, because the 103 1.1 christos # condition evaluates to false. 104 1.1 christos gdb_continue_to_end 105 1.1 christos } 106 1.1 christos 107 1.1 christos # Repeat with a condition that contains junk at the end. 108 1.1 christos with_test_prefix "with junk" { 109 1.1 christos if {![runto_main]} { 110 1.1 christos return -1 111 1.1 christos } 112 1.1 christos 113 1.1 christos gdb_breakpoint "$bp_location" 114 1.1 christos set bpnum [get_integer_valueof "\$bpnum" 0 "get bpnum"] 115 1.1 christos 116 1.1 christos gdb_test_no_output "cond $bpnum a == 999" 117 1.1 christos 118 1.1 christos gdb_test "cond $bpnum a == 10 if" \ 119 1.1 christos "Junk at end of expression" \ 120 1.1 christos "attempt a bad condition" 121 1.1 christos 122 1.1 christos # Resume. We should *not* hit the breakpoint, because the 123 1.1 christos # condition evaluates to false. 124 1.1 christos gdb_continue_to_end 125 1.1 christos } 126