+# Test address locations.
+
+proc test_bkpt_address {} {
+ global gdb_prompt decimal srcfile
+
+ # Delete all breakpoints
+ delete_breakpoints
+
+ gdb_test "python gdb.Breakpoint(\"*main\")" \
+ ".*Breakpoint ($decimal)+ at .*$srcfile, line ($decimal)+\."
+
+ gdb_py_test_silent_cmd \
+ "python main_loc = gdb.parse_and_eval(\"main\").address" \
+ "eval address of main" 0
+
+ # Python 2 vs 3 ... Check `int' first. If that fails, try `long'.
+ gdb_test_multiple "python main_addr = int(main_loc)" "int value of main" {
+ -re "Traceback.*$gdb_prompt $" {
+ gdb_test_no_output "python main_addr = long(main_loc)" \
+ "long value of main"
+ }
+ -re "$gdb_prompt $" {
+ pass "int value of main"
+ }
+ }
+
+ # Include whitespace in the linespec to double-check proper
+ # grokking of argument to gdb.Breakpoint.
+ gdb_test "python gdb.Breakpoint(\" *{}\".format(str(main_addr)))" \
+ ".*Breakpoint ($decimal)+ at .*$srcfile, line ($decimal)+\."
+}
+
+proc test_bkpt_pending {} {
+ delete_breakpoints
+ gdb_breakpoint "nosuchfunction" allow-pending
+ gdb_test "python print (gdb.breakpoints()\[0\].pending)" "True" \
+ "Check pending status of pending breakpoint"
+}
+
+# Helper proc to install an event listener for a given breakpoint
+# event. NAME is the name of the event to listen for.
+proc connect_event {name} {
+ set lambda "lambda x: note_event(\"$name\")"
+ gdb_test_no_output "python gdb.events.$name.connect($lambda)" \
+ "install $name event listener"
+}
+
+# Helper proc to check that the most recently emitted breakpoint event
+# is EXPECTED.
+proc check_last_event {expected} {
+ gdb_test "python print (last_bp_event)" $expected \
+ "check for $expected event"
+}
+
+proc test_bkpt_events {} {
+ global testfile
+
+ clean_restart ${testfile}
+
+ gdb_py_test_multiple "Create event handler" \
+ "python" "" \
+ "def note_event(arg):" "" \
+ " global last_bp_event" "" \
+ " last_bp_event = arg" "" \
+ "end" ""
+ gdb_test_no_output "python last_bp_event = None"
+
+ connect_event breakpoint_created
+ connect_event breakpoint_modified
+ connect_event breakpoint_deleted
+
+ gdb_breakpoint [gdb_get_line_number "Break at add."]
+ check_last_event breakpoint_created
+ gdb_test_no_output "disable 1"
+ check_last_event breakpoint_modified
+ gdb_test_no_output "delete 1"
+ check_last_event breakpoint_deleted
+}
+