Fix more cases of improper test names
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-breakpoint.exp
index 1ae8fe63189849a6a18815b91d839564830c88e3..1d0e5b5f2da53b358f16830fcdf42f17a5b0f619 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2010-2014 Free Software Foundation, Inc.
+# Copyright (C) 2010-2016 Free Software Foundation, Inc.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -20,7 +20,7 @@ load_lib gdb-python.exp
 
 standard_testfile
 
-if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
+if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
     return -1
 }
 
@@ -34,18 +34,23 @@ proc 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."
+           fail "cannot run to main."
            return 0
        }
 
-       # Initially there should be one breakpoint: main.
+       # 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}
@@ -67,7 +72,7 @@ proc test_bkpt_basic { } {
 
        gdb_test "python print (blist\[1\].location)" \
            "py-breakpoint\.c:${mult_line}*" \
-           "Check breakpoint location @mult_line"
+           "check breakpoint location @mult_line"
 
        # Check hit and ignore counts. 
        gdb_test "python print (blist\[1\].hit_count)" \
@@ -118,7 +123,7 @@ proc test_bkpt_deletion { } {
        clean_restart ${testfile}
 
        if ![runto_main] then {
-           fail "Cannot run to main."
+           fail "cannot run to main."
            return 0
        }
 
@@ -133,7 +138,7 @@ proc test_bkpt_deletion { } {
        gdb_test "python print (len(del_list))" \
            "3" "Number of breakpoints before delete"
        gdb_continue_to_breakpoint "Break at multiply." \
-           ".*/$srcfile:$deltst_location.*"
+           ".*$srcfile:$deltst_location.*"
        gdb_py_test_silent_cmd  "python dp1.delete()" \
            "Delete Breakpoint" 0
        gdb_test "python print (dp1.number)" \
@@ -144,7 +149,7 @@ proc test_bkpt_deletion { } {
        gdb_test "python print (len(del_list))" \
            "2" "Number of breakpoints after delete"
        gdb_continue_to_breakpoint "Break at end." \
-           ".*/$srcfile:$end_location.*"
+           ".*$srcfile:$end_location.*"
     }
 }
 
@@ -156,7 +161,7 @@ proc test_bkpt_cond_and_cmds { } {
        clean_restart ${testfile}
 
        if ![runto_main] then {
-           fail "Cannot run to main."
+           fail "cannot run to main."
            return 0
        }
 
@@ -208,7 +213,7 @@ proc test_bkpt_invisible { } {
        clean_restart ${testfile}
 
        if ![runto_main] then {
-           fail "Cannot run to main."
+           fail "cannot run to main."
            return 0
        }
 
@@ -258,12 +263,13 @@ proc test_watchpoints { } {
        }
 
        if ![runto_main] then {
-           fail "Cannot run to main."
+           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"
@@ -282,7 +288,7 @@ proc test_bkpt_internal { } {
            gdb_test_no_output "set can-use-hw-watchpoints 0" ""
        }
        if ![runto_main] then {
-           fail "Cannot run to main."
+           fail "cannot run to main."
            return 0
        }
        delete_breakpoints
@@ -312,7 +318,7 @@ proc test_bkpt_eval_funcs { } {
            gdb_test_no_output "set can-use-hw-watchpoints 0" ""
        }
        if ![runto_main] then {
-           fail "Cannot run to main."
+           fail "cannot run to main."
            return 0
        }
        delete_breakpoints
@@ -356,7 +362,7 @@ proc test_bkpt_eval_funcs { } {
        gdb_py_test_silent_cmd "python never_eval_bp1 = bp_also_eval(\"$end_location\")" \
            "Set breakpoint" 0
        gdb_continue_to_breakpoint "Break at multiply, i==3" \
-           ".*/$srcfile:$bp_location2.*"
+           ".*$srcfile:$bp_location2.*"
        gdb_test "print i" \
            "3" "Check inferior value matches python accounting"
        gdb_test "python print (eval_bp1.inf_i)" \
@@ -372,7 +378,7 @@ proc test_bkpt_eval_funcs { } {
            "Set breakpoint" 0
        set test_cond {cond $bpnum}
        gdb_test "$test_cond \"foo==3\"" \
-           "Cannot set a condition where a Python.*" \
+           "Only one stop condition allowed.  There is currently a Python.*" \
            "Check you cannot add a CLI condition to a Python breakpoint that has defined stop"
        gdb_py_test_silent_cmd "python eval_bp2 = basic(\"$cond_bp\")" \
            "Set breakpoint" 0
@@ -385,8 +391,8 @@ proc test_bkpt_eval_funcs { } {
            "end" ""
 
        gdb_test "python eval_bp2.stop = stop_func"  \
-           "RuntimeError: Cannot set 'stop' method.*" \
-           "Assign stop function to a breakpoint that has a condition"
+           "RuntimeError: Only one stop condition allowed.  There is currently a GDB.*" \
+           "assign stop function to a breakpoint that has a condition"
 
        delete_breakpoints
        gdb_breakpoint [gdb_get_line_number "Break at multiply."]
@@ -395,7 +401,7 @@ proc test_bkpt_eval_funcs { } {
        gdb_test "python print (check_eval.count)" "0" \
            "Test that evaluate function has not been yet executed (ie count = 0)"
        gdb_continue_to_breakpoint "Break at multiply, count==1" \
-           ".*/$srcfile:$bp_location2.*"
+           ".*$srcfile:$bp_location2.*"
        gdb_test "python print (check_eval.count)" "1" \
            "Test that evaluate function is run when location also has normal bp"
 
@@ -428,7 +434,7 @@ proc test_bkpt_temporary { } {
        clean_restart ${testfile}
 
        if ![runto_main] then {
-           fail "Cannot run to main."
+           fail "cannot run to main."
            return 0
        }
        delete_breakpoints
@@ -452,7 +458,7 @@ proc test_bkpt_temporary { } {
        gdb_test "python print (ibp.temporary)" "True" \
            "Check breakpoint temporary status"
        gdb_continue_to_breakpoint "Break at multiply." \
-           ".*/$srcfile:$ibp_location.*"
+           ".*$srcfile:$ibp_location.*"
        gdb_test "python print (ibp.count)" "1" \
            "Check temporary stop callback executed before deletion."
        gdb_test "python print (ibp.temporary)" "RuntimeError: Breakpoint 2 is invalid.*" \
@@ -462,6 +468,85 @@ proc test_bkpt_temporary { } {
     }
 }
 
+# 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
+}
+
 test_bkpt_basic
 test_bkpt_deletion
 test_bkpt_cond_and_cmds
@@ -470,3 +555,6 @@ test_watchpoints
 test_bkpt_internal
 test_bkpt_eval_funcs
 test_bkpt_temporary
+test_bkpt_address
+test_bkpt_pending
+test_bkpt_events
This page took 0.030044 seconds and 4 git commands to generate.