Commit | Line | Data |
---|---|---|
7b6bb8da | 1 | # Copyright (C) 2010, 2011 Free Software Foundation, Inc. |
adc36818 PM |
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 | ||
a2c09bd0 DE |
23 | load_lib gdb-python.exp |
24 | ||
adc36818 PM |
25 | set testfile "py-breakpoint" |
26 | set srcfile ${testfile}.c | |
27 | if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } { | |
28 | return -1 | |
29 | } | |
30 | ||
adc36818 PM |
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 | ||
cc72b2a2 KP |
47 | set mult_line [gdb_get_line_number "Break at multiply."] |
48 | gdb_breakpoint ${mult_line} | |
adc36818 PM |
49 | gdb_continue_to_breakpoint "Break at multiply." |
50 | ||
51 | # Check that the Python breakpoint code noted the addition of a | |
52 | # breakpoint "behind the scenes". | |
53 | gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0 | |
54 | gdb_test "python print len(blist)" "2" "Check for two breakpoints" | |
55 | gdb_test "python print blist\[0\]" "<gdb.Breakpoint object at $hex>" "Check obj exists" | |
56 | gdb_test "python print blist\[0\].location" "main." "Check breakpoint location" | |
57 | gdb_test "python print blist\[1\]" "<gdb.Breakpoint object at $hex>" "Check obj exists" | |
cc72b2a2 KP |
58 | |
59 | gdb_test "python print blist\[1\].location" "py-breakpoint\.c:${mult_line}*" \ | |
60 | "Check breakpoint location" | |
adc36818 PM |
61 | |
62 | # Check hit and ignore counts. | |
63 | gdb_test "python print blist\[1\].hit_count" "1" "Check breakpoint hit count" | |
64 | gdb_py_test_silent_cmd "python blist\[1\].ignore_count = 4" "Set breakpoint hit count" 0 | |
65 | gdb_continue_to_breakpoint "Break at multiply." | |
66 | gdb_test "python print blist\[1\].hit_count" "6" "Check breakpoint hit count" | |
8bfb830f | 67 | gdb_test "print result" " = 545" "Check expected variable result after 6 iterations" |
adc36818 PM |
68 | |
69 | # Test breakpoint is enabled and disabled correctly.. | |
70 | gdb_breakpoint [gdb_get_line_number "Break at add."] | |
71 | gdb_continue_to_breakpoint "Break at add." | |
72 | gdb_test "python print blist\[1\].enabled" "True" "Check breakpoint enabled." | |
73 | gdb_py_test_silent_cmd "python blist\[1\].enabled = False" "Set breakpoint disabled." 0 | |
74 | gdb_continue_to_breakpoint "Break at add." | |
75 | gdb_py_test_silent_cmd "python blist\[1\].enabled = True" "Set breakpoint enabled." 0 | |
76 | gdb_continue_to_breakpoint "Break at multiply." | |
77 | ||
78 | # Test other getters and setters. | |
79 | gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0 | |
80 | gdb_test "python print blist\[1\].thread" "None" "Check breakpoint thread" | |
81 | gdb_test "python print blist\[1\].type == gdb.BP_BREAKPOINT" "True" "Check breakpoint type" | |
82 | gdb_test "python print blist\[0\].number" "1" "Check breakpoint number" | |
83 | gdb_test "python print blist\[1\].number" "2" "Check breakpoint number" | |
84 | gdb_test "python print blist\[2\].number" "3" "Check breakpoint number" | |
85 | ||
94b6973e PM |
86 | # Start with a fresh gdb. |
87 | clean_restart ${testfile} | |
88 | ||
89 | if ![runto_main] then { | |
90 | fail "Cannot run to main." | |
91 | return 0 | |
92 | } | |
93 | ||
94 | # Test breakpoints are deleted correctly. | |
95 | set deltst_location [gdb_get_line_number "Break at multiply."] | |
96 | set end_location [gdb_get_line_number "Break at end."] | |
97 | gdb_py_test_silent_cmd "python dp1 = gdb.Breakpoint (\"$deltst_location\")" "Set breakpoint" 0 | |
98 | gdb_breakpoint [gdb_get_line_number "Break at end."] | |
99 | gdb_py_test_silent_cmd "python del_list = gdb.breakpoints()" "Get Breakpoint List" 0 | |
100 | gdb_test "python print len(del_list)" "3" "Number of breakpoints before delete" | |
101 | gdb_continue_to_breakpoint "Break at multiply." ".*/$srcfile:$deltst_location.*" | |
102 | gdb_py_test_silent_cmd "python dp1.delete()" "Delete Breakpoint" 0 | |
103 | gdb_test "python print dp1.number" "RuntimeError: Breakpoint 2 is invalid.*" "Check breakpoint invalidated" | |
104 | gdb_py_test_silent_cmd "python del_list = gdb.breakpoints()" "Get Breakpoint List" 0 | |
105 | gdb_test "python print len(del_list)" "2" "Number of breakpoints after delete" | |
106 | gdb_continue_to_breakpoint "Break at end." ".*/$srcfile:$end_location.*" | |
107 | ||
108 | ||
adc36818 PM |
109 | # Start with a fresh gdb. |
110 | clean_restart ${testfile} | |
111 | ||
112 | if ![runto_main] then { | |
113 | fail "Cannot run to main." | |
114 | return 0 | |
115 | } | |
116 | ||
117 | # Test conditional setting. | |
118 | set bp_location1 [gdb_get_line_number "Break at multiply."] | |
119 | gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (\"$bp_location1\")" "Set breakpoint" 0 | |
120 | gdb_continue_to_breakpoint "Break at multiply." | |
121 | gdb_py_test_silent_cmd "python bp1.condition = \"i == 5\"" "Set breakpoint" 0 | |
122 | gdb_test "python print bp1.condition" "i == 5" "Test conditional has been set" | |
123 | gdb_continue_to_breakpoint "Break at multiply." | |
124 | gdb_test "print i" "5" "Test conditional breakpoint stopped after five iterations" | |
125 | gdb_py_test_silent_cmd "python bp1.condition = None" "Clear condition" 0 | |
126 | gdb_test "python print bp1.condition" "None" "Test conditional read" | |
127 | gdb_continue_to_breakpoint "Break at multiply." | |
128 | gdb_test "print i" "6" "Test breakpoint stopped after six iterations" | |
129 | ||
130 | # Test commands. | |
131 | gdb_breakpoint [gdb_get_line_number "Break at add."] | |
132 | set test {commands $bpnum} | |
133 | gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } } | |
134 | set test {print "Command for breakpoint has been executed."} | |
135 | gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } } | |
136 | set test {print result} | |
137 | gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } } | |
138 | gdb_test "end" | |
139 | ||
140 | gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0 | |
141 | gdb_test "python print blist\[len(blist)-1\].commands" "print \"Command for breakpoint has been executed.\".*print result" | |
142 | ||
84f4c1fe PM |
143 | # Start with a fresh gdb. |
144 | clean_restart ${testfile} | |
145 | ||
146 | if ![runto_main] then { | |
147 | fail "Cannot run to main." | |
148 | return 0 | |
149 | } | |
150 | ||
8bfb830f | 151 | # Test invisible breakpoints. |
84f4c1fe PM |
152 | delete_breakpoints |
153 | set ibp_location [gdb_get_line_number "Break at multiply."] | |
154 | gdb_py_test_silent_cmd "python ibp = gdb.Breakpoint(\"$ibp_location\", internal=False)" "Set invisible breakpoint" 0 | |
155 | gdb_py_test_silent_cmd "python ilist = gdb.breakpoints()" "Get Breakpoint List" 0 | |
156 | gdb_test "python print ilist\[0\]" "<gdb.Breakpoint object at $hex>" "Check invisible bp obj exists" | |
157 | gdb_test "python print ilist\[0\].location" "py-breakpoint\.c:$ibp_location*" "Check breakpoint location" | |
158 | gdb_test "python print ilist\[0\].visible" "True" "Check breakpoint visibility" | |
159 | gdb_test "info breakpoints" "py-breakpoint\.c:$ibp_location.*" "Check info breakpoints shows visible breakpoints" | |
160 | delete_breakpoints | |
161 | gdb_py_test_silent_cmd "python ibp = gdb.Breakpoint(\"$ibp_location\", internal=True)" "Set invisible breakpoint" 0 | |
162 | gdb_py_test_silent_cmd "python ilist = gdb.breakpoints()" "Get Breakpoint List" 0 | |
163 | gdb_test "python print ilist\[0\]" "<gdb.Breakpoint object at $hex>" "Check invisible bp obj exists" | |
164 | gdb_test "python print ilist\[0\].location" "py-breakpoint\.c:$ibp_location*" "Check breakpoint location" | |
165 | gdb_test "python print ilist\[0\].visible" "False" "Check breakpoint visibility" | |
166 | gdb_test "info breakpoints" "No breakpoints or watchpoints.*" "Check info breakpoints does not show invisible breakpoints" | |
167 | gdb_test "maint info breakpoints" "py-breakpoint\.c:$ibp_location.*" "Check maint info breakpoints shows invisible breakpoints" | |
168 | ||
169 | ||
adc36818 PM |
170 | # Watchpoints |
171 | # Start with a fresh gdb. | |
172 | clean_restart ${testfile} | |
173 | ||
e0756905 UW |
174 | # Disable hardware watchpoints if necessary. |
175 | if [target_info exists gdb,no_hardware_watchpoints] { | |
176 | gdb_test_no_output "set can-use-hw-watchpoints 0" "" | |
177 | } | |
178 | ||
adc36818 PM |
179 | if ![runto_main] then { |
180 | fail "Cannot run to main." | |
181 | return 0 | |
182 | } | |
183 | ||
184 | gdb_py_test_silent_cmd "python wp1 = gdb.Breakpoint (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE )" "Set watchpoint" 0 | |
468b1aa7 | 185 | gdb_test "continue" ".*\[Ww\]atchpoint.*result.*Old value = 0.*New value = 25.*main.*" "Test watchpoint write" |
adc36818 | 186 | |
84f4c1fe | 187 | # Internal breakpoints. |
adc36818 | 188 | |
84f4c1fe PM |
189 | # Start with a fresh gdb. |
190 | clean_restart ${testfile} | |
adc36818 | 191 | |
182b9acc UW |
192 | # Disable hardware watchpoints if necessary. |
193 | if [target_info exists gdb,no_hardware_watchpoints] { | |
194 | gdb_test_no_output "set can-use-hw-watchpoints 0" "" | |
195 | } | |
84f4c1fe PM |
196 | if ![runto_main] then { |
197 | fail "Cannot run to main." | |
198 | return 0 | |
199 | } | |
200 | delete_breakpoints | |
201 | gdb_py_test_silent_cmd "python wp1 = gdb.Breakpoint (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE, internal=True )" "Set watchpoint" 0 | |
202 | gdb_test "info breakpoints" "No breakpoints or watchpoints.*" "Check info breakpoints does not show invisible breakpoints" | |
b9b35694 | 203 | gdb_test "maint info breakpoints" ".*watchpoint.*result.*" "Check maint info breakpoints shows invisible breakpoints" |
84f4c1fe | 204 | gdb_test "continue" ".*\[Ww\]atchpoint.*result.*Old value = 0.*New value = 25.*" "Test watchpoint write" |
7371cf6d PM |
205 | |
206 | # Breakpoints that have an evaluation function. | |
207 | ||
208 | # Start with a fresh gdb. | |
209 | clean_restart ${testfile} | |
210 | ||
182b9acc UW |
211 | # Disable hardware watchpoints if necessary. |
212 | if [target_info exists gdb,no_hardware_watchpoints] { | |
213 | gdb_test_no_output "set can-use-hw-watchpoints 0" "" | |
214 | } | |
7371cf6d PM |
215 | if ![runto_main] then { |
216 | fail "Cannot run to main." | |
217 | return 0 | |
218 | } | |
219 | delete_breakpoints | |
220 | ||
221 | gdb_py_test_multiple "Sub-class a breakpoint" \ | |
222 | "python" "" \ | |
223 | "class bp_eval (gdb.Breakpoint):" "" \ | |
224 | " inf_i = 0" "" \ | |
225 | " count = 0" "" \ | |
226 | " def stop (self):" "" \ | |
227 | " self.count = self.count + 1" "" \ | |
228 | " self.inf_i = gdb.parse_and_eval(\"i\")" "" \ | |
229 | " if self.inf_i == 3:" "" \ | |
230 | " return True" "" \ | |
231 | " return False" "" \ | |
232 | "end" "" | |
233 | ||
234 | gdb_py_test_multiple "Sub-class a second breakpoint" \ | |
235 | "python" "" \ | |
236 | "class bp_also_eval (gdb.Breakpoint):" "" \ | |
237 | " count = 0" "" \ | |
238 | " def stop (self):" "" \ | |
239 | " self.count = self.count + 1" "" \ | |
240 | " if self.count == 9:" "" \ | |
241 | " return True" "" \ | |
242 | " return False" "" \ | |
243 | "end" "" | |
244 | ||
245 | gdb_py_test_multiple "Sub-class a third breakpoint" \ | |
246 | "python" "" \ | |
247 | "class basic (gdb.Breakpoint):" "" \ | |
248 | " count = 0" "" \ | |
249 | "end" "" | |
250 | ||
251 | set bp_location2 [gdb_get_line_number "Break at multiply."] | |
252 | set end_location [gdb_get_line_number "Break at end."] | |
253 | gdb_py_test_silent_cmd "python eval_bp1 = bp_eval(\"$bp_location2\")" "Set breakpoint" 0 | |
254 | gdb_py_test_silent_cmd "python also_eval_bp1 = bp_also_eval(\"$bp_location2\")" "Set breakpoint" 0 | |
255 | gdb_py_test_silent_cmd "python never_eval_bp1 = bp_also_eval(\"$end_location\")" "Set breakpoint" 0 | |
256 | gdb_continue_to_breakpoint "Break at multiply." ".*/$srcfile:$bp_location2.*" | |
257 | gdb_test "print i" "3" "Check inferior value matches python accounting" | |
258 | gdb_test "python print eval_bp1.inf_i" "3" "Check python accounting matches inferior" | |
259 | gdb_test "python print also_eval_bp1.count" "4" \ | |
260 | "Check non firing same-location breakpoint eval function was also called at each stop." | |
261 | gdb_test "python print eval_bp1.count" "4" \ | |
262 | "Check non firing same-location breakpoint eval function was also called at each stop." | |
263 | ||
264 | delete_breakpoints | |
265 | set cond_bp [gdb_get_line_number "Break at multiply."] | |
266 | gdb_py_test_silent_cmd "python eval_bp1 = bp_eval(\"$cond_bp\")" "Set breakpoint" 0 | |
267 | set test_cond {cond $bpnum} | |
268 | gdb_test "$test_cond \"foo==3\"" "Cannot set a condition where a Python.*" \ | |
269 | "Check you cannot add a CLI condition to a Python breakpoint that" \ | |
270 | "has defined stop" | |
271 | gdb_py_test_silent_cmd "python eval_bp2 = basic(\"$cond_bp\")" "Set breakpoint" 0 | |
272 | gdb_py_test_silent_cmd "python eval_bp2.condition = \"1==1\"" "Set a condition" 0 | |
273 | gdb_py_test_multiple "Construct an eval function" \ | |
274 | "python" "" \ | |
275 | "def stop_func ():" "" \ | |
276 | " return True" "" \ | |
277 | "end" "" | |
278 | ||
279 | gdb_test "python eval_bp2.stop = stop_func" \ | |
280 | "RuntimeError: Cannot set 'stop' method.*" \ | |
281 | "Assign stop function to a breakpoint that has a condition" | |
282 | ||
283 | delete_breakpoints | |
284 | gdb_breakpoint [gdb_get_line_number "Break at multiply."] | |
285 | gdb_py_test_silent_cmd "python check_eval = bp_eval(\"$bp_location2\")" "Set breakpoint" 0 | |
286 | gdb_test "python print check_eval.count" "0" \ | |
287 | "Test that evaluate function has not been yet executed (ie count = 0)" | |
288 | gdb_continue_to_breakpoint "Break at multiply." ".*/$srcfile:$bp_location2.*" | |
289 | gdb_test "python print check_eval.count" "1" \ | |
290 | "Test that evaluate function is run when location also has normal bp" | |
291 | ||
292 | gdb_py_test_multiple "Sub-class a watchpoint" \ | |
293 | "python" "" \ | |
294 | "class wp_eval (gdb.Breakpoint):" "" \ | |
295 | " def stop (self):" "" \ | |
296 | " self.result = gdb.parse_and_eval(\"result\")" "" \ | |
297 | " if self.result == 788:" "" \ | |
298 | " return True" "" \ | |
299 | " return False" "" \ | |
300 | "end" "" | |
301 | ||
302 | delete_breakpoints | |
303 | gdb_py_test_silent_cmd "python wp1 = wp_eval (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE)" "Set watchpoint" 0 | |
304 | gdb_test "continue" ".*\[Ww\]atchpoint.*result.*Old value =.*New value = 788.*" "Test watchpoint write" | |
305 | gdb_test "python print never_eval_bp1.count" "0" \ | |
306 | "Check that this unrelated breakpoints eval function was never called." |