1 |
330 |
jeremybenn |
# Copyright (C) 2010 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 .
|
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 |
|
|
set testfile "py-breakpoint"
|
24 |
|
|
set srcfile ${testfile}.c
|
25 |
|
|
if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
|
26 |
|
|
return -1
|
27 |
|
|
}
|
28 |
|
|
|
29 |
|
|
# Run a command in GDB, and report a failure if a Python exception is thrown.
|
30 |
|
|
# If report_pass is true, report a pass if no exception is thrown.
|
31 |
|
|
proc gdb_py_test_silent_cmd {cmd name report_pass} {
|
32 |
|
|
global gdb_prompt
|
33 |
|
|
|
34 |
|
|
gdb_test_multiple $cmd $name {
|
35 |
|
|
-re "Traceback.*$gdb_prompt $" { fail $name }
|
36 |
|
|
-re "$gdb_prompt $" { if $report_pass { pass $name } }
|
37 |
|
|
}
|
38 |
|
|
}
|
39 |
|
|
|
40 |
|
|
# Start with a fresh gdb.
|
41 |
|
|
clean_restart ${testfile}
|
42 |
|
|
|
43 |
|
|
# Skip all tests if Python scripting is not enabled.
|
44 |
|
|
if { [skip_python_tests] } { continue }
|
45 |
|
|
|
46 |
|
|
if ![runto_main] then {
|
47 |
|
|
fail "Cannot run to main."
|
48 |
|
|
return 0
|
49 |
|
|
}
|
50 |
|
|
|
51 |
|
|
global hex decimal
|
52 |
|
|
|
53 |
|
|
# Initially there should be one breakpoint: main.
|
54 |
|
|
|
55 |
|
|
gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0
|
56 |
|
|
gdb_test "python print blist\[0\]" "" "Check obj exists"
|
57 |
|
|
gdb_test "python print blist\[0\].location" "main." "Check breakpoint location"
|
58 |
|
|
|
59 |
|
|
gdb_breakpoint [gdb_get_line_number "Break at multiply."]
|
60 |
|
|
gdb_continue_to_breakpoint "Break at multiply."
|
61 |
|
|
|
62 |
|
|
# Check that the Python breakpoint code noted the addition of a
|
63 |
|
|
# breakpoint "behind the scenes".
|
64 |
|
|
gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0
|
65 |
|
|
gdb_test "python print len(blist)" "2" "Check for two breakpoints"
|
66 |
|
|
gdb_test "python print blist\[0\]" "" "Check obj exists"
|
67 |
|
|
gdb_test "python print blist\[0\].location" "main." "Check breakpoint location"
|
68 |
|
|
gdb_test "python print blist\[1\]" "" "Check obj exists"
|
69 |
|
|
gdb_test "python print blist\[1\].location" "py-breakpoint\.c:41*" "Check breakpoint location"
|
70 |
|
|
|
71 |
|
|
# Check hit and ignore counts.
|
72 |
|
|
gdb_test "python print blist\[1\].hit_count" "1" "Check breakpoint hit count"
|
73 |
|
|
gdb_py_test_silent_cmd "python blist\[1\].ignore_count = 4" "Set breakpoint hit count" 0
|
74 |
|
|
gdb_continue_to_breakpoint "Break at multiply."
|
75 |
|
|
gdb_test "python print blist\[1\].hit_count" "6" "Check breakpoint hit count"
|
76 |
|
|
gdb_test "print result" "545" "Check expected variable result after 6 iterations"
|
77 |
|
|
|
78 |
|
|
# Test breakpoint is enabled and disabled correctly..
|
79 |
|
|
gdb_breakpoint [gdb_get_line_number "Break at add."]
|
80 |
|
|
gdb_continue_to_breakpoint "Break at add."
|
81 |
|
|
gdb_test "python print blist\[1\].enabled" "True" "Check breakpoint enabled."
|
82 |
|
|
gdb_py_test_silent_cmd "python blist\[1\].enabled = False" "Set breakpoint disabled." 0
|
83 |
|
|
gdb_continue_to_breakpoint "Break at add."
|
84 |
|
|
gdb_py_test_silent_cmd "python blist\[1\].enabled = True" "Set breakpoint enabled." 0
|
85 |
|
|
gdb_continue_to_breakpoint "Break at multiply."
|
86 |
|
|
|
87 |
|
|
# Test other getters and setters.
|
88 |
|
|
gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0
|
89 |
|
|
gdb_test "python print blist\[1\].thread" "None" "Check breakpoint thread"
|
90 |
|
|
gdb_test "python print blist\[1\].type == gdb.BP_BREAKPOINT" "True" "Check breakpoint type"
|
91 |
|
|
gdb_test "python print blist\[0\].number" "1" "Check breakpoint number"
|
92 |
|
|
gdb_test "python print blist\[1\].number" "2" "Check breakpoint number"
|
93 |
|
|
gdb_test "python print blist\[2\].number" "3" "Check breakpoint number"
|
94 |
|
|
|
95 |
|
|
# Start with a fresh gdb.
|
96 |
|
|
clean_restart ${testfile}
|
97 |
|
|
|
98 |
|
|
if ![runto_main] then {
|
99 |
|
|
fail "Cannot run to main."
|
100 |
|
|
return 0
|
101 |
|
|
}
|
102 |
|
|
|
103 |
|
|
# Test conditional setting.
|
104 |
|
|
set bp_location1 [gdb_get_line_number "Break at multiply."]
|
105 |
|
|
gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (\"$bp_location1\")" "Set breakpoint" 0
|
106 |
|
|
gdb_continue_to_breakpoint "Break at multiply."
|
107 |
|
|
gdb_py_test_silent_cmd "python bp1.condition = \"i == 5\"" "Set breakpoint" 0
|
108 |
|
|
gdb_test "python print bp1.condition" "i == 5" "Test conditional has been set"
|
109 |
|
|
gdb_continue_to_breakpoint "Break at multiply."
|
110 |
|
|
gdb_test "print i" "5" "Test conditional breakpoint stopped after five iterations"
|
111 |
|
|
gdb_py_test_silent_cmd "python bp1.condition = None" "Clear condition" 0
|
112 |
|
|
gdb_test "python print bp1.condition" "None" "Test conditional read"
|
113 |
|
|
gdb_continue_to_breakpoint "Break at multiply."
|
114 |
|
|
gdb_test "print i" "6" "Test breakpoint stopped after six iterations"
|
115 |
|
|
|
116 |
|
|
# Test commands.
|
117 |
|
|
gdb_breakpoint [gdb_get_line_number "Break at add."]
|
118 |
|
|
set test {commands $bpnum}
|
119 |
|
|
gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } }
|
120 |
|
|
set test {print "Command for breakpoint has been executed."}
|
121 |
|
|
gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } }
|
122 |
|
|
set test {print result}
|
123 |
|
|
gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } }
|
124 |
|
|
gdb_test "end"
|
125 |
|
|
|
126 |
|
|
gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0
|
127 |
|
|
gdb_test "python print blist\[len(blist)-1\].commands" "print \"Command for breakpoint has been executed.\".*print result"
|
128 |
|
|
|
129 |
|
|
# Watchpoints
|
130 |
|
|
# Start with a fresh gdb.
|
131 |
|
|
clean_restart ${testfile}
|
132 |
|
|
|
133 |
|
|
# Disable hardware watchpoints if necessary.
|
134 |
|
|
if [target_info exists gdb,no_hardware_watchpoints] {
|
135 |
|
|
gdb_test_no_output "set can-use-hw-watchpoints 0" ""
|
136 |
|
|
}
|
137 |
|
|
|
138 |
|
|
if ![runto_main] then {
|
139 |
|
|
fail "Cannot run to main."
|
140 |
|
|
return 0
|
141 |
|
|
}
|
142 |
|
|
|
143 |
|
|
gdb_py_test_silent_cmd "python wp1 = gdb.Breakpoint (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE )" "Set watchpoint" 0
|
144 |
|
|
gdb_test "continue" ".*\[Ww\]atchpoint.*result.*Old value = 0.*New value = 25.*main.*" "Test watchpoint write"
|
145 |
|
|
|
146 |
|
|
|
147 |
|
|
|