| 1 | # Copyright (C) 2010, 2011 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 | # This file is part of the GDB testsuite. It tests the mechanism |
| 17 | # exposing values to Python. |
| 18 | |
| 19 | if $tracelevel then { |
| 20 | strace $tracelevel |
| 21 | } |
| 22 | |
| 23 | load_lib gdb-python.exp |
| 24 | |
| 25 | set testfile "py-breakpoint" |
| 26 | set srcfile ${testfile}.c |
| 27 | if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } { |
| 28 | return -1 |
| 29 | } |
| 30 | |
| 31 | # Skip all tests if Python scripting is not enabled. |
| 32 | if { [skip_python_tests] } { continue } |
| 33 | |
| 34 | if ![runto_main] then { |
| 35 | fail "Cannot run to main." |
| 36 | return 0 |
| 37 | } |
| 38 | |
| 39 | global hex decimal |
| 40 | |
| 41 | # Initially there should be one breakpoint: main. |
| 42 | |
| 43 | gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0 |
| 44 | gdb_test "python print blist\[0\]" "<gdb.Breakpoint object at $hex>" "Check obj exists" |
| 45 | gdb_test "python print blist\[0\].location" "main." "Check breakpoint location" |
| 46 | |
| 47 | gdb_breakpoint [gdb_get_line_number "Break at multiply."] |
| 48 | gdb_continue_to_breakpoint "Break at multiply." |
| 49 | |
| 50 | # Check that the Python breakpoint code noted the addition of a |
| 51 | # breakpoint "behind the scenes". |
| 52 | gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0 |
| 53 | gdb_test "python print len(blist)" "2" "Check for two breakpoints" |
| 54 | gdb_test "python print blist\[0\]" "<gdb.Breakpoint object at $hex>" "Check obj exists" |
| 55 | gdb_test "python print blist\[0\].location" "main." "Check breakpoint location" |
| 56 | gdb_test "python print blist\[1\]" "<gdb.Breakpoint object at $hex>" "Check obj exists" |
| 57 | gdb_test "python print blist\[1\].location" "py-breakpoint\.c:41*" "Check breakpoint location" |
| 58 | |
| 59 | # Check hit and ignore counts. |
| 60 | gdb_test "python print blist\[1\].hit_count" "1" "Check breakpoint hit count" |
| 61 | gdb_py_test_silent_cmd "python blist\[1\].ignore_count = 4" "Set breakpoint hit count" 0 |
| 62 | gdb_continue_to_breakpoint "Break at multiply." |
| 63 | gdb_test "python print blist\[1\].hit_count" "6" "Check breakpoint hit count" |
| 64 | gdb_test "print result" " = 545" "Check expected variable result after 6 iterations" |
| 65 | |
| 66 | # Test breakpoint is enabled and disabled correctly.. |
| 67 | gdb_breakpoint [gdb_get_line_number "Break at add."] |
| 68 | gdb_continue_to_breakpoint "Break at add." |
| 69 | gdb_test "python print blist\[1\].enabled" "True" "Check breakpoint enabled." |
| 70 | gdb_py_test_silent_cmd "python blist\[1\].enabled = False" "Set breakpoint disabled." 0 |
| 71 | gdb_continue_to_breakpoint "Break at add." |
| 72 | gdb_py_test_silent_cmd "python blist\[1\].enabled = True" "Set breakpoint enabled." 0 |
| 73 | gdb_continue_to_breakpoint "Break at multiply." |
| 74 | |
| 75 | # Test other getters and setters. |
| 76 | gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0 |
| 77 | gdb_test "python print blist\[1\].thread" "None" "Check breakpoint thread" |
| 78 | gdb_test "python print blist\[1\].type == gdb.BP_BREAKPOINT" "True" "Check breakpoint type" |
| 79 | gdb_test "python print blist\[0\].number" "1" "Check breakpoint number" |
| 80 | gdb_test "python print blist\[1\].number" "2" "Check breakpoint number" |
| 81 | gdb_test "python print blist\[2\].number" "3" "Check breakpoint number" |
| 82 | |
| 83 | # Start with a fresh gdb. |
| 84 | clean_restart ${testfile} |
| 85 | |
| 86 | if ![runto_main] then { |
| 87 | fail "Cannot run to main." |
| 88 | return 0 |
| 89 | } |
| 90 | |
| 91 | # Test breakpoints are deleted correctly. |
| 92 | set deltst_location [gdb_get_line_number "Break at multiply."] |
| 93 | set end_location [gdb_get_line_number "Break at end."] |
| 94 | gdb_py_test_silent_cmd "python dp1 = gdb.Breakpoint (\"$deltst_location\")" "Set breakpoint" 0 |
| 95 | gdb_breakpoint [gdb_get_line_number "Break at end."] |
| 96 | gdb_py_test_silent_cmd "python del_list = gdb.breakpoints()" "Get Breakpoint List" 0 |
| 97 | gdb_test "python print len(del_list)" "3" "Number of breakpoints before delete" |
| 98 | gdb_continue_to_breakpoint "Break at multiply." ".*/$srcfile:$deltst_location.*" |
| 99 | gdb_py_test_silent_cmd "python dp1.delete()" "Delete Breakpoint" 0 |
| 100 | gdb_test "python print dp1.number" "RuntimeError: Breakpoint 2 is invalid.*" "Check breakpoint invalidated" |
| 101 | gdb_py_test_silent_cmd "python del_list = gdb.breakpoints()" "Get Breakpoint List" 0 |
| 102 | gdb_test "python print len(del_list)" "2" "Number of breakpoints after delete" |
| 103 | gdb_continue_to_breakpoint "Break at end." ".*/$srcfile:$end_location.*" |
| 104 | |
| 105 | |
| 106 | # Start with a fresh gdb. |
| 107 | clean_restart ${testfile} |
| 108 | |
| 109 | if ![runto_main] then { |
| 110 | fail "Cannot run to main." |
| 111 | return 0 |
| 112 | } |
| 113 | |
| 114 | # Test conditional setting. |
| 115 | set bp_location1 [gdb_get_line_number "Break at multiply."] |
| 116 | gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (\"$bp_location1\")" "Set breakpoint" 0 |
| 117 | gdb_continue_to_breakpoint "Break at multiply." |
| 118 | gdb_py_test_silent_cmd "python bp1.condition = \"i == 5\"" "Set breakpoint" 0 |
| 119 | gdb_test "python print bp1.condition" "i == 5" "Test conditional has been set" |
| 120 | gdb_continue_to_breakpoint "Break at multiply." |
| 121 | gdb_test "print i" "5" "Test conditional breakpoint stopped after five iterations" |
| 122 | gdb_py_test_silent_cmd "python bp1.condition = None" "Clear condition" 0 |
| 123 | gdb_test "python print bp1.condition" "None" "Test conditional read" |
| 124 | gdb_continue_to_breakpoint "Break at multiply." |
| 125 | gdb_test "print i" "6" "Test breakpoint stopped after six iterations" |
| 126 | |
| 127 | # Test commands. |
| 128 | gdb_breakpoint [gdb_get_line_number "Break at add."] |
| 129 | set test {commands $bpnum} |
| 130 | gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } } |
| 131 | set test {print "Command for breakpoint has been executed."} |
| 132 | gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } } |
| 133 | set test {print result} |
| 134 | gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } } |
| 135 | gdb_test "end" |
| 136 | |
| 137 | gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0 |
| 138 | gdb_test "python print blist\[len(blist)-1\].commands" "print \"Command for breakpoint has been executed.\".*print result" |
| 139 | |
| 140 | # Start with a fresh gdb. |
| 141 | clean_restart ${testfile} |
| 142 | |
| 143 | if ![runto_main] then { |
| 144 | fail "Cannot run to main." |
| 145 | return 0 |
| 146 | } |
| 147 | |
| 148 | # Test invisible breakpoints. |
| 149 | delete_breakpoints |
| 150 | set ibp_location [gdb_get_line_number "Break at multiply."] |
| 151 | gdb_py_test_silent_cmd "python ibp = gdb.Breakpoint(\"$ibp_location\", internal=False)" "Set invisible breakpoint" 0 |
| 152 | gdb_py_test_silent_cmd "python ilist = gdb.breakpoints()" "Get Breakpoint List" 0 |
| 153 | gdb_test "python print ilist\[0\]" "<gdb.Breakpoint object at $hex>" "Check invisible bp obj exists" |
| 154 | gdb_test "python print ilist\[0\].location" "py-breakpoint\.c:$ibp_location*" "Check breakpoint location" |
| 155 | gdb_test "python print ilist\[0\].visible" "True" "Check breakpoint visibility" |
| 156 | gdb_test "info breakpoints" "py-breakpoint\.c:$ibp_location.*" "Check info breakpoints shows visible breakpoints" |
| 157 | delete_breakpoints |
| 158 | gdb_py_test_silent_cmd "python ibp = gdb.Breakpoint(\"$ibp_location\", internal=True)" "Set invisible breakpoint" 0 |
| 159 | gdb_py_test_silent_cmd "python ilist = gdb.breakpoints()" "Get Breakpoint List" 0 |
| 160 | gdb_test "python print ilist\[0\]" "<gdb.Breakpoint object at $hex>" "Check invisible bp obj exists" |
| 161 | gdb_test "python print ilist\[0\].location" "py-breakpoint\.c:$ibp_location*" "Check breakpoint location" |
| 162 | gdb_test "python print ilist\[0\].visible" "False" "Check breakpoint visibility" |
| 163 | gdb_test "info breakpoints" "No breakpoints or watchpoints.*" "Check info breakpoints does not show invisible breakpoints" |
| 164 | gdb_test "maint info breakpoints" "py-breakpoint\.c:$ibp_location.*" "Check maint info breakpoints shows invisible breakpoints" |
| 165 | |
| 166 | |
| 167 | # Watchpoints |
| 168 | # Start with a fresh gdb. |
| 169 | clean_restart ${testfile} |
| 170 | |
| 171 | # Disable hardware watchpoints if necessary. |
| 172 | if [target_info exists gdb,no_hardware_watchpoints] { |
| 173 | gdb_test_no_output "set can-use-hw-watchpoints 0" "" |
| 174 | } |
| 175 | |
| 176 | if ![runto_main] then { |
| 177 | fail "Cannot run to main." |
| 178 | return 0 |
| 179 | } |
| 180 | |
| 181 | gdb_py_test_silent_cmd "python wp1 = gdb.Breakpoint (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE )" "Set watchpoint" 0 |
| 182 | gdb_test "continue" ".*\[Ww\]atchpoint.*result.*Old value = 0.*New value = 25.*main.*" "Test watchpoint write" |
| 183 | |
| 184 | # Internal breakpoints. |
| 185 | |
| 186 | # Start with a fresh gdb. |
| 187 | clean_restart ${testfile} |
| 188 | |
| 189 | if ![runto_main] then { |
| 190 | fail "Cannot run to main." |
| 191 | return 0 |
| 192 | } |
| 193 | delete_breakpoints |
| 194 | gdb_py_test_silent_cmd "python wp1 = gdb.Breakpoint (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE, internal=True )" "Set watchpoint" 0 |
| 195 | gdb_test "info breakpoints" "No breakpoints or watchpoints.*" "Check info breakpoints does not show invisible breakpoints" |
| 196 | gdb_test "maint info breakpoints" ".*watchpoint.*result.*" "Check maint info breakpoints shows invisible breakpoints" |
| 197 | gdb_test "continue" ".*\[Ww\]atchpoint.*result.*Old value = 0.*New value = 25.*" "Test watchpoint write" |