+proc test_bkpt_basic { } {
+ global srcfile testfile hex decimal
+
+ with_test_prefix "test_bkpt_basic" {
+ # Start with a fresh gdb.
+ clean_restart ${testfile}
+
+ # We should start with no breakpoints.
+ gdb_test "python print (gdb.breakpoints())" "\\(\\)"
+
+ if ![runto_main] then {
+ fail "cannot run to main."
+ return 0
+ }
+
+ # Now there should be one breakpoint: main.
+ gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" \
+ "Get Breakpoint List" 0
+ gdb_test "python print (blist\[0\])" \
+ "<gdb.Breakpoint object at $hex>" "Check obj exists @main"
+ gdb_test "python print (blist\[0\].location)" \
+ "main." "Check breakpoint location @main"
+ gdb_test "python print (blist\[0\].pending)" "False" \
+ "Check pending status of main breakpoint"
+
+ set mult_line [gdb_get_line_number "Break at multiply."]
+ gdb_breakpoint ${mult_line}
+ gdb_continue_to_breakpoint "Break at multiply" \
+ ".*Break at multiply.*"
+
+ # Check that the Python breakpoint code noted the addition of a
+ # breakpoint "behind the scenes".
+ gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" \
+ "Get Breakpoint List" 0
+ gdb_test "python print (len(blist))" \
+ "2" "Check for two breakpoints"
+ gdb_test "python print (blist\[0\])" \
+ "<gdb.Breakpoint object at $hex>" "Check obj exists @main 2"
+ gdb_test "python print (blist\[0\].location)" \
+ "main." "Check breakpoint location @main 2"
+ gdb_test "python print (blist\[1\])" \
+ "<gdb.Breakpoint object at $hex>" "Check obj exists @mult_line"
+
+ gdb_test "python print (blist\[1\].location)" \
+ "py-breakpoint\.c:${mult_line}*" \
+ "check breakpoint location @mult_line"
+
+ # Check hit and ignore counts.
+ gdb_test "python print (blist\[1\].hit_count)" \
+ "1" "Check breakpoint hit count @1"
+ gdb_py_test_silent_cmd "python blist\[1\].ignore_count = 4" \
+ "Set breakpoint hit count" 0
+ gdb_continue_to_breakpoint "Break at multiply @6" \
+ ".*Break at multiply.*"
+ gdb_test "python print (blist\[1\].hit_count)" \
+ "6" "Check breakpoint hit count @6"
+ gdb_test "print result" \
+ " = 545" "Check expected variable result after 6 iterations"
+
+ # Test breakpoint is enabled and disabled correctly..
+ gdb_breakpoint [gdb_get_line_number "Break at add."]
+ gdb_continue_to_breakpoint "Break at add 1" ".*Break at add.*"
+ gdb_test "python print (blist\[1\].enabled)" \
+ "True" "Check breakpoint enabled."
+ gdb_py_test_silent_cmd "python blist\[1\].enabled = False" \
+ "Set breakpoint disabled." 0
+ gdb_continue_to_breakpoint "Break at add 2" ".*Break at add.*"
+ gdb_py_test_silent_cmd "python blist\[1\].enabled = True" \
+ "Set breakpoint enabled." 0
+ gdb_continue_to_breakpoint "Break at multiply after re-enable" \
+ ".*Break at multiply.*"
+
+ # Test other getters and setters.
+ gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" \
+ "Get Breakpoint List" 0
+ gdb_test "python print (blist\[1\].thread)" \
+ "None" "Check breakpoint thread"
+ gdb_test "python print (blist\[1\].type == gdb.BP_BREAKPOINT)" \
+ "True" "Check breakpoint type"
+ gdb_test "python print (blist\[0\].number)" \
+ "1" "Check breakpoint number 0"
+ gdb_test "python print (blist\[1\].number)" \
+ "2" "Check breakpoint number 1"
+ gdb_test "python print (blist\[2\].number)" \
+ "3" "Check breakpoint number 2"
+ }
+}
+
+proc test_bkpt_deletion { } {
+ global srcfile testfile hex decimal
+
+ with_test_prefix test_bkpt_deletion {
+ # Start with a fresh gdb.
+ clean_restart ${testfile}
+
+ if ![runto_main] then {
+ fail "cannot run to main."
+ return 0
+ }
+
+ # Test breakpoints are deleted correctly.
+ set deltst_location [gdb_get_line_number "Break at multiply."]
+ set end_location [gdb_get_line_number "Break at end."]
+ gdb_py_test_silent_cmd "python dp1 = gdb.Breakpoint (\"$deltst_location\")" \
+ "Set breakpoint" 0
+ gdb_breakpoint [gdb_get_line_number "Break at end."]
+ gdb_py_test_silent_cmd "python del_list = gdb.breakpoints()" \
+ "Get Breakpoint List" 0
+ gdb_test "python print (len(del_list))" \
+ "3" "Number of breakpoints before delete"
+ gdb_continue_to_breakpoint "Break at multiply." \
+ ".*$srcfile:$deltst_location.*"
+ gdb_py_test_silent_cmd "python dp1.delete()" \
+ "Delete Breakpoint" 0
+ gdb_test "python print (dp1.number)" \
+ "RuntimeError: Breakpoint 2 is invalid.*" \
+ "Check breakpoint invalidated"
+ gdb_py_test_silent_cmd "python del_list = gdb.breakpoints()" \
+ "Get Breakpoint List" 0
+ gdb_test "python print (len(del_list))" \
+ "2" "Number of breakpoints after delete"
+ gdb_continue_to_breakpoint "Break at end." \
+ ".*$srcfile:$end_location.*"
+ }
+}
+
+proc test_bkpt_cond_and_cmds { } {
+ global srcfile testfile hex decimal
+
+ with_test_prefix test_bkpt_cond_and_cmds {
+ # Start with a fresh gdb.
+ clean_restart ${testfile}
+
+ if ![runto_main] then {
+ fail "cannot run to main."
+ return 0
+ }
+
+ # Test conditional setting.
+ set bp_location1 [gdb_get_line_number "Break at multiply."]
+ gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (\"$bp_location1\")" \
+ "Set breakpoint" 0
+ gdb_continue_to_breakpoint "Break at multiply" \
+ ".*Break at multiply.*"
+ gdb_py_test_silent_cmd "python bp1.condition = \"i == 5\"" \
+ "Set breakpoint" 0
+ gdb_test "python print (bp1.condition)" "i == 5" \
+ "Test conditional has been set"
+ gdb_continue_to_breakpoint "Break at multiply @5" \
+ ".*Break at multiply.*"
+ gdb_test "print i" \
+ "5" "Test conditional breakpoint stopped after five iterations"
+ gdb_py_test_silent_cmd "python bp1.condition = None" \
+ "Clear condition" 0
+ gdb_test "python print (bp1.condition)" \
+ "None" "Test conditional read"
+ gdb_continue_to_breakpoint "Break at multiply @6" \
+ ".*Break at multiply.*"
+ gdb_test "print i" \
+ "6" "Test breakpoint stopped after six iterations"
+
+ # Test commands.
+ gdb_breakpoint [gdb_get_line_number "Break at add."]
+ set test {commands $bpnum}
+ gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } }
+ set test {print "Command for breakpoint has been executed."}
+ gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } }
+ set test {print result}
+ gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } }
+ gdb_test "end"
+
+ gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" \
+ "Get Breakpoint List" 0
+ gdb_test "python print (blist\[len(blist)-1\].commands)" \
+ "print \"Command for breakpoint has been executed.\".*print result"
+ }
+}
+
+proc test_bkpt_invisible { } {
+ global srcfile testfile hex decimal
+
+ with_test_prefix test_bkpt_invisible {
+ # Start with a fresh gdb.
+ clean_restart ${testfile}
+
+ if ![runto_main] then {
+ fail "cannot run to main."
+ return 0
+ }
+
+ delete_breakpoints
+ set ibp_location [gdb_get_line_number "Break at multiply."]
+ gdb_py_test_silent_cmd "python ibp = gdb.Breakpoint(\"$ibp_location\", internal=False)" \
+ "Set invisible breakpoint" 0
+ gdb_py_test_silent_cmd "python ilist = gdb.breakpoints()" \
+ "Get Breakpoint List" 0
+ gdb_test "python print (ilist\[0\])" \
+ "<gdb.Breakpoint object at $hex>" "Check invisible bp obj exists 1"
+ gdb_test "python print (ilist\[0\].location)" \
+ "py-breakpoint\.c:$ibp_location*" "Check breakpoint location 1"
+ gdb_test "python print (ilist\[0\].visible)" \
+ "True" "Check breakpoint visibility 1"
+ gdb_test "info breakpoints" "py-breakpoint\.c:$ibp_location.*" \
+ "Check info breakpoints shows visible breakpoints"
+ delete_breakpoints
+ gdb_py_test_silent_cmd "python ibp = gdb.Breakpoint(\"$ibp_location\", internal=True)" \
+ "Set invisible breakpoint" 0
+ gdb_py_test_silent_cmd "python ilist = gdb.breakpoints()" \
+ "Get Breakpoint List" 0
+ gdb_test "python print (ilist\[0\])" \
+ "<gdb.Breakpoint object at $hex>" "Check invisible bp obj exists 2"
+ gdb_test "python print (ilist\[0\].location)" \
+ "py-breakpoint\.c:$ibp_location*" "Check breakpoint location 2"
+ gdb_test "python print (ilist\[0\].visible)" \
+ "False" "Check breakpoint visibility 2"
+ gdb_test "info breakpoints" "No breakpoints or watchpoints.*" \
+ "Check info breakpoints does not show invisible breakpoints"
+ gdb_test "maint info breakpoints" \
+ "py-breakpoint\.c:$ibp_location.*" \
+ "Check maint info breakpoints shows invisible breakpoints"
+ }
+}
+
+proc test_watchpoints { } {
+ global srcfile testfile hex decimal
+
+ with_test_prefix test_watchpoints {
+ # Start with a fresh gdb.
+ clean_restart ${testfile}
+
+ # Disable hardware watchpoints if necessary.
+ if [target_info exists gdb,no_hardware_watchpoints] {
+ gdb_test_no_output "set can-use-hw-watchpoints 0" ""
+ }
+
+ if ![runto_main] then {
+ fail "cannot run to main."
+ return 0
+ }
+
+ gdb_py_test_silent_cmd "python wp1 = gdb.Breakpoint (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE )" \
+ "Set watchpoint" 0
+ gdb_test "python print (wp1.pending)" "False"
+ gdb_test "continue" \
+ ".*\[Ww\]atchpoint.*result.*Old value = 0.*New value = 25.*main.*" \
+ "Test watchpoint write"
+ }