]>
Commit | Line | Data |
---|---|---|
61baf725 | 1 | # Copyright (C) 2010-2017 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 | |
330a7fce | 17 | # exposing breakpoints to Python. |
adc36818 | 18 | |
a2c09bd0 DE |
19 | load_lib gdb-python.exp |
20 | ||
b4a58790 TT |
21 | standard_testfile |
22 | ||
5b362f04 | 23 | if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } { |
adc36818 PM |
24 | return -1 |
25 | } | |
26 | ||
adc36818 PM |
27 | # Skip all tests if Python scripting is not enabled. |
28 | if { [skip_python_tests] } { continue } | |
29 | ||
330a7fce DE |
30 | proc test_bkpt_basic { } { |
31 | global srcfile testfile hex decimal | |
32 | ||
33 | with_test_prefix "test_bkpt_basic" { | |
34 | # Start with a fresh gdb. | |
35 | clean_restart ${testfile} | |
36 | ||
1957f6b8 TT |
37 | # We should start with no breakpoints. |
38 | gdb_test "python print (gdb.breakpoints())" "\\(\\)" | |
39 | ||
330a7fce | 40 | if ![runto_main] then { |
bc6c7af4 | 41 | fail "cannot run to main." |
330a7fce DE |
42 | return 0 |
43 | } | |
44 | ||
1957f6b8 | 45 | # Now there should be one breakpoint: main. |
8abea1a1 DE |
46 | gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" \ |
47 | "Get Breakpoint List" 0 | |
48 | gdb_test "python print (blist\[0\])" \ | |
9abb1bd6 | 49 | "<gdb.Breakpoint object at $hex>" "Check obj exists @main" |
8abea1a1 | 50 | gdb_test "python print (blist\[0\].location)" \ |
9abb1bd6 | 51 | "main." "Check breakpoint location @main" |
93daf339 TT |
52 | gdb_test "python print (blist\[0\].pending)" "False" \ |
53 | "Check pending status of main breakpoint" | |
330a7fce DE |
54 | |
55 | set mult_line [gdb_get_line_number "Break at multiply."] | |
56 | gdb_breakpoint ${mult_line} | |
9abb1bd6 DE |
57 | gdb_continue_to_breakpoint "Break at multiply" \ |
58 | ".*Break at multiply.*" | |
330a7fce DE |
59 | |
60 | # Check that the Python breakpoint code noted the addition of a | |
61 | # breakpoint "behind the scenes". | |
8abea1a1 DE |
62 | gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" \ |
63 | "Get Breakpoint List" 0 | |
64 | gdb_test "python print (len(blist))" \ | |
65 | "2" "Check for two breakpoints" | |
66 | gdb_test "python print (blist\[0\])" \ | |
9abb1bd6 | 67 | "<gdb.Breakpoint object at $hex>" "Check obj exists @main 2" |
8abea1a1 | 68 | gdb_test "python print (blist\[0\].location)" \ |
9abb1bd6 | 69 | "main." "Check breakpoint location @main 2" |
8abea1a1 | 70 | gdb_test "python print (blist\[1\])" \ |
9abb1bd6 | 71 | "<gdb.Breakpoint object at $hex>" "Check obj exists @mult_line" |
8abea1a1 DE |
72 | |
73 | gdb_test "python print (blist\[1\].location)" \ | |
74 | "py-breakpoint\.c:${mult_line}*" \ | |
bb95117e | 75 | "check breakpoint location @mult_line" |
330a7fce DE |
76 | |
77 | # Check hit and ignore counts. | |
8abea1a1 | 78 | gdb_test "python print (blist\[1\].hit_count)" \ |
9abb1bd6 | 79 | "1" "Check breakpoint hit count @1" |
8abea1a1 DE |
80 | gdb_py_test_silent_cmd "python blist\[1\].ignore_count = 4" \ |
81 | "Set breakpoint hit count" 0 | |
9abb1bd6 DE |
82 | gdb_continue_to_breakpoint "Break at multiply @6" \ |
83 | ".*Break at multiply.*" | |
8abea1a1 | 84 | gdb_test "python print (blist\[1\].hit_count)" \ |
9abb1bd6 | 85 | "6" "Check breakpoint hit count @6" |
8abea1a1 DE |
86 | gdb_test "print result" \ |
87 | " = 545" "Check expected variable result after 6 iterations" | |
330a7fce DE |
88 | |
89 | # Test breakpoint is enabled and disabled correctly.. | |
90 | gdb_breakpoint [gdb_get_line_number "Break at add."] | |
9abb1bd6 | 91 | gdb_continue_to_breakpoint "Break at add 1" ".*Break at add.*" |
8abea1a1 DE |
92 | gdb_test "python print (blist\[1\].enabled)" \ |
93 | "True" "Check breakpoint enabled." | |
94 | gdb_py_test_silent_cmd "python blist\[1\].enabled = False" \ | |
95 | "Set breakpoint disabled." 0 | |
9abb1bd6 | 96 | gdb_continue_to_breakpoint "Break at add 2" ".*Break at add.*" |
8abea1a1 DE |
97 | gdb_py_test_silent_cmd "python blist\[1\].enabled = True" \ |
98 | "Set breakpoint enabled." 0 | |
9abb1bd6 DE |
99 | gdb_continue_to_breakpoint "Break at multiply after re-enable" \ |
100 | ".*Break at multiply.*" | |
330a7fce DE |
101 | |
102 | # Test other getters and setters. | |
8abea1a1 DE |
103 | gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" \ |
104 | "Get Breakpoint List" 0 | |
105 | gdb_test "python print (blist\[1\].thread)" \ | |
106 | "None" "Check breakpoint thread" | |
107 | gdb_test "python print (blist\[1\].type == gdb.BP_BREAKPOINT)" \ | |
108 | "True" "Check breakpoint type" | |
109 | gdb_test "python print (blist\[0\].number)" \ | |
9abb1bd6 | 110 | "1" "Check breakpoint number 0" |
8abea1a1 | 111 | gdb_test "python print (blist\[1\].number)" \ |
9abb1bd6 | 112 | "2" "Check breakpoint number 1" |
8abea1a1 | 113 | gdb_test "python print (blist\[2\].number)" \ |
9abb1bd6 | 114 | "3" "Check breakpoint number 2" |
330a7fce | 115 | } |
adc36818 PM |
116 | } |
117 | ||
330a7fce DE |
118 | proc test_bkpt_deletion { } { |
119 | global srcfile testfile hex decimal | |
120 | ||
121 | with_test_prefix test_bkpt_deletion { | |
122 | # Start with a fresh gdb. | |
123 | clean_restart ${testfile} | |
124 | ||
125 | if ![runto_main] then { | |
bc6c7af4 | 126 | fail "cannot run to main." |
330a7fce DE |
127 | return 0 |
128 | } | |
129 | ||
130 | # Test breakpoints are deleted correctly. | |
131 | set deltst_location [gdb_get_line_number "Break at multiply."] | |
132 | set end_location [gdb_get_line_number "Break at end."] | |
8abea1a1 DE |
133 | gdb_py_test_silent_cmd "python dp1 = gdb.Breakpoint (\"$deltst_location\")" \ |
134 | "Set breakpoint" 0 | |
330a7fce | 135 | gdb_breakpoint [gdb_get_line_number "Break at end."] |
8abea1a1 DE |
136 | gdb_py_test_silent_cmd "python del_list = gdb.breakpoints()" \ |
137 | "Get Breakpoint List" 0 | |
138 | gdb_test "python print (len(del_list))" \ | |
139 | "3" "Number of breakpoints before delete" | |
140 | gdb_continue_to_breakpoint "Break at multiply." \ | |
a80db015 | 141 | ".*$srcfile:$deltst_location.*" |
8abea1a1 DE |
142 | gdb_py_test_silent_cmd "python dp1.delete()" \ |
143 | "Delete Breakpoint" 0 | |
144 | gdb_test "python print (dp1.number)" \ | |
145 | "RuntimeError: Breakpoint 2 is invalid.*" \ | |
146 | "Check breakpoint invalidated" | |
147 | gdb_py_test_silent_cmd "python del_list = gdb.breakpoints()" \ | |
148 | "Get Breakpoint List" 0 | |
149 | gdb_test "python print (len(del_list))" \ | |
150 | "2" "Number of breakpoints after delete" | |
151 | gdb_continue_to_breakpoint "Break at end." \ | |
a80db015 | 152 | ".*$srcfile:$end_location.*" |
330a7fce | 153 | } |
94b6973e PM |
154 | } |
155 | ||
330a7fce DE |
156 | proc test_bkpt_cond_and_cmds { } { |
157 | global srcfile testfile hex decimal | |
158 | ||
159 | with_test_prefix test_bkpt_cond_and_cmds { | |
160 | # Start with a fresh gdb. | |
161 | clean_restart ${testfile} | |
162 | ||
163 | if ![runto_main] then { | |
bc6c7af4 | 164 | fail "cannot run to main." |
330a7fce DE |
165 | return 0 |
166 | } | |
167 | ||
168 | # Test conditional setting. | |
169 | set bp_location1 [gdb_get_line_number "Break at multiply."] | |
8abea1a1 DE |
170 | gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (\"$bp_location1\")" \ |
171 | "Set breakpoint" 0 | |
9abb1bd6 DE |
172 | gdb_continue_to_breakpoint "Break at multiply" \ |
173 | ".*Break at multiply.*" | |
8abea1a1 DE |
174 | gdb_py_test_silent_cmd "python bp1.condition = \"i == 5\"" \ |
175 | "Set breakpoint" 0 | |
176 | gdb_test "python print (bp1.condition)" "i == 5" \ | |
177 | "Test conditional has been set" | |
9abb1bd6 DE |
178 | gdb_continue_to_breakpoint "Break at multiply @5" \ |
179 | ".*Break at multiply.*" | |
8abea1a1 DE |
180 | gdb_test "print i" \ |
181 | "5" "Test conditional breakpoint stopped after five iterations" | |
182 | gdb_py_test_silent_cmd "python bp1.condition = None" \ | |
183 | "Clear condition" 0 | |
184 | gdb_test "python print (bp1.condition)" \ | |
185 | "None" "Test conditional read" | |
9abb1bd6 DE |
186 | gdb_continue_to_breakpoint "Break at multiply @6" \ |
187 | ".*Break at multiply.*" | |
8abea1a1 DE |
188 | gdb_test "print i" \ |
189 | "6" "Test breakpoint stopped after six iterations" | |
330a7fce DE |
190 | |
191 | # Test commands. | |
192 | gdb_breakpoint [gdb_get_line_number "Break at add."] | |
193 | set test {commands $bpnum} | |
194 | gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } } | |
195 | set test {print "Command for breakpoint has been executed."} | |
196 | gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } } | |
197 | set test {print result} | |
198 | gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } } | |
199 | gdb_test "end" | |
200 | ||
8abea1a1 DE |
201 | gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" \ |
202 | "Get Breakpoint List" 0 | |
203 | gdb_test "python print (blist\[len(blist)-1\].commands)" \ | |
204 | "print \"Command for breakpoint has been executed.\".*print result" | |
330a7fce | 205 | } |
adc36818 PM |
206 | } |
207 | ||
330a7fce DE |
208 | proc test_bkpt_invisible { } { |
209 | global srcfile testfile hex decimal | |
210 | ||
211 | with_test_prefix test_bkpt_invisible { | |
212 | # Start with a fresh gdb. | |
213 | clean_restart ${testfile} | |
214 | ||
215 | if ![runto_main] then { | |
bc6c7af4 | 216 | fail "cannot run to main." |
330a7fce DE |
217 | return 0 |
218 | } | |
219 | ||
220 | delete_breakpoints | |
221 | set ibp_location [gdb_get_line_number "Break at multiply."] | |
8abea1a1 DE |
222 | gdb_py_test_silent_cmd "python ibp = gdb.Breakpoint(\"$ibp_location\", internal=False)" \ |
223 | "Set invisible breakpoint" 0 | |
224 | gdb_py_test_silent_cmd "python ilist = gdb.breakpoints()" \ | |
225 | "Get Breakpoint List" 0 | |
226 | gdb_test "python print (ilist\[0\])" \ | |
9abb1bd6 | 227 | "<gdb.Breakpoint object at $hex>" "Check invisible bp obj exists 1" |
8abea1a1 | 228 | gdb_test "python print (ilist\[0\].location)" \ |
9abb1bd6 | 229 | "py-breakpoint\.c:$ibp_location*" "Check breakpoint location 1" |
8abea1a1 | 230 | gdb_test "python print (ilist\[0\].visible)" \ |
9abb1bd6 | 231 | "True" "Check breakpoint visibility 1" |
8abea1a1 DE |
232 | gdb_test "info breakpoints" "py-breakpoint\.c:$ibp_location.*" \ |
233 | "Check info breakpoints shows visible breakpoints" | |
330a7fce | 234 | delete_breakpoints |
8abea1a1 DE |
235 | gdb_py_test_silent_cmd "python ibp = gdb.Breakpoint(\"$ibp_location\", internal=True)" \ |
236 | "Set invisible breakpoint" 0 | |
237 | gdb_py_test_silent_cmd "python ilist = gdb.breakpoints()" \ | |
238 | "Get Breakpoint List" 0 | |
239 | gdb_test "python print (ilist\[0\])" \ | |
9abb1bd6 | 240 | "<gdb.Breakpoint object at $hex>" "Check invisible bp obj exists 2" |
8abea1a1 | 241 | gdb_test "python print (ilist\[0\].location)" \ |
9abb1bd6 | 242 | "py-breakpoint\.c:$ibp_location*" "Check breakpoint location 2" |
8abea1a1 | 243 | gdb_test "python print (ilist\[0\].visible)" \ |
9abb1bd6 | 244 | "False" "Check breakpoint visibility 2" |
8abea1a1 DE |
245 | gdb_test "info breakpoints" "No breakpoints or watchpoints.*" \ |
246 | "Check info breakpoints does not show invisible breakpoints" | |
247 | gdb_test "maint info breakpoints" \ | |
248 | "py-breakpoint\.c:$ibp_location.*" \ | |
249 | "Check maint info breakpoints shows invisible breakpoints" | |
330a7fce | 250 | } |
84f4c1fe PM |
251 | } |
252 | ||
330a7fce DE |
253 | proc test_watchpoints { } { |
254 | global srcfile testfile hex decimal | |
adc36818 | 255 | |
330a7fce DE |
256 | with_test_prefix test_watchpoints { |
257 | # Start with a fresh gdb. | |
258 | clean_restart ${testfile} | |
adc36818 | 259 | |
330a7fce DE |
260 | # Disable hardware watchpoints if necessary. |
261 | if [target_info exists gdb,no_hardware_watchpoints] { | |
262 | gdb_test_no_output "set can-use-hw-watchpoints 0" "" | |
263 | } | |
adc36818 | 264 | |
330a7fce | 265 | if ![runto_main] then { |
bc6c7af4 | 266 | fail "cannot run to main." |
330a7fce DE |
267 | return 0 |
268 | } | |
adc36818 | 269 | |
8abea1a1 DE |
270 | gdb_py_test_silent_cmd "python wp1 = gdb.Breakpoint (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE )" \ |
271 | "Set watchpoint" 0 | |
93daf339 | 272 | gdb_test "python print (wp1.pending)" "False" |
8abea1a1 DE |
273 | gdb_test "continue" \ |
274 | ".*\[Ww\]atchpoint.*result.*Old value = 0.*New value = 25.*main.*" \ | |
275 | "Test watchpoint write" | |
330a7fce | 276 | } |
182b9acc | 277 | } |
7371cf6d | 278 | |
330a7fce DE |
279 | proc test_bkpt_internal { } { |
280 | global srcfile testfile hex decimal | |
281 | ||
282 | with_test_prefix test_bkpt_internal { | |
283 | # Start with a fresh gdb. | |
284 | clean_restart ${testfile} | |
285 | ||
286 | # Disable hardware watchpoints if necessary. | |
287 | if [target_info exists gdb,no_hardware_watchpoints] { | |
288 | gdb_test_no_output "set can-use-hw-watchpoints 0" "" | |
289 | } | |
290 | if ![runto_main] then { | |
bc6c7af4 | 291 | fail "cannot run to main." |
330a7fce DE |
292 | return 0 |
293 | } | |
294 | delete_breakpoints | |
8abea1a1 DE |
295 | gdb_py_test_silent_cmd "python wp1 = gdb.Breakpoint (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE, internal=True )" \ |
296 | "Set watchpoint" 0 | |
297 | gdb_test "info breakpoints" \ | |
298 | "No breakpoints or watchpoints.*" \ | |
299 | "Check info breakpoints does not show invisible breakpoints" | |
300 | gdb_test "maint info breakpoints" \ | |
301 | ".*watchpoint.*result.*" \ | |
302 | "Check maint info breakpoints shows invisible breakpoints" | |
303 | gdb_test "continue" \ | |
304 | ".*\[Ww\]atchpoint.*result.*Old value = 0.*New value = 25.*" \ | |
305 | "Test watchpoint write" | |
330a7fce | 306 | } |
182b9acc | 307 | } |
330a7fce DE |
308 | |
309 | proc test_bkpt_eval_funcs { } { | |
310 | global srcfile testfile hex decimal | |
311 | ||
312 | with_test_prefix test_bkpt_eval_funcs { | |
313 | # Start with a fresh gdb. | |
314 | clean_restart ${testfile} | |
315 | ||
316 | # Disable hardware watchpoints if necessary. | |
317 | if [target_info exists gdb,no_hardware_watchpoints] { | |
318 | gdb_test_no_output "set can-use-hw-watchpoints 0" "" | |
319 | } | |
320 | if ![runto_main] then { | |
bc6c7af4 | 321 | fail "cannot run to main." |
330a7fce DE |
322 | return 0 |
323 | } | |
324 | delete_breakpoints | |
325 | ||
326 | gdb_py_test_multiple "Sub-class a breakpoint" \ | |
327 | "python" "" \ | |
328 | "class bp_eval (gdb.Breakpoint):" "" \ | |
329 | " inf_i = 0" "" \ | |
330 | " count = 0" "" \ | |
331 | " def stop (self):" "" \ | |
332 | " self.count = self.count + 1" "" \ | |
333 | " self.inf_i = gdb.parse_and_eval(\"i\")" "" \ | |
334 | " if self.inf_i == 3:" "" \ | |
335 | " return True" "" \ | |
336 | " return False" "" \ | |
337 | "end" "" | |
338 | ||
339 | gdb_py_test_multiple "Sub-class a second breakpoint" \ | |
340 | "python" "" \ | |
341 | "class bp_also_eval (gdb.Breakpoint):" "" \ | |
342 | " count = 0" "" \ | |
343 | " def stop (self):" "" \ | |
344 | " self.count = self.count + 1" "" \ | |
345 | " if self.count == 9:" "" \ | |
346 | " return True" "" \ | |
347 | " return False" "" \ | |
348 | "end" "" | |
349 | ||
350 | gdb_py_test_multiple "Sub-class a third breakpoint" \ | |
351 | "python" "" \ | |
352 | "class basic (gdb.Breakpoint):" "" \ | |
353 | " count = 0" "" \ | |
354 | "end" "" | |
355 | ||
356 | set bp_location2 [gdb_get_line_number "Break at multiply."] | |
357 | set end_location [gdb_get_line_number "Break at end."] | |
8abea1a1 DE |
358 | gdb_py_test_silent_cmd "python eval_bp1 = bp_eval(\"$bp_location2\")" \ |
359 | "Set breakpoint" 0 | |
360 | gdb_py_test_silent_cmd "python also_eval_bp1 = bp_also_eval(\"$bp_location2\")" \ | |
361 | "Set breakpoint" 0 | |
362 | gdb_py_test_silent_cmd "python never_eval_bp1 = bp_also_eval(\"$end_location\")" \ | |
363 | "Set breakpoint" 0 | |
9abb1bd6 | 364 | gdb_continue_to_breakpoint "Break at multiply, i==3" \ |
a80db015 | 365 | ".*$srcfile:$bp_location2.*" |
8abea1a1 DE |
366 | gdb_test "print i" \ |
367 | "3" "Check inferior value matches python accounting" | |
368 | gdb_test "python print (eval_bp1.inf_i)" \ | |
369 | "3" "Check python accounting matches inferior" | |
330a7fce | 370 | gdb_test "python print (also_eval_bp1.count)" "4" \ |
9abb1bd6 | 371 | "Check non firing same-location also_eval_bp1 function was also called at each stop." |
330a7fce | 372 | gdb_test "python print (eval_bp1.count)" "4" \ |
9abb1bd6 | 373 | "Check non firing same-location eval_bp1 function was also called at each stop." |
330a7fce DE |
374 | |
375 | delete_breakpoints | |
376 | set cond_bp [gdb_get_line_number "Break at multiply."] | |
8abea1a1 DE |
377 | gdb_py_test_silent_cmd "python eval_bp1 = bp_eval(\"$cond_bp\")" \ |
378 | "Set breakpoint" 0 | |
330a7fce | 379 | set test_cond {cond $bpnum} |
8abea1a1 | 380 | gdb_test "$test_cond \"foo==3\"" \ |
6dddc817 | 381 | "Only one stop condition allowed. There is currently a Python.*" \ |
8abea1a1 DE |
382 | "Check you cannot add a CLI condition to a Python breakpoint that has defined stop" |
383 | gdb_py_test_silent_cmd "python eval_bp2 = basic(\"$cond_bp\")" \ | |
384 | "Set breakpoint" 0 | |
385 | gdb_py_test_silent_cmd "python eval_bp2.condition = \"1==1\"" \ | |
386 | "Set a condition" 0 | |
330a7fce DE |
387 | gdb_py_test_multiple "Construct an eval function" \ |
388 | "python" "" \ | |
389 | "def stop_func ():" "" \ | |
390 | " return True" "" \ | |
391 | "end" "" | |
392 | ||
393 | gdb_test "python eval_bp2.stop = stop_func" \ | |
6dddc817 | 394 | "RuntimeError: Only one stop condition allowed. There is currently a GDB.*" \ |
bb95117e | 395 | "assign stop function to a breakpoint that has a condition" |
330a7fce DE |
396 | |
397 | delete_breakpoints | |
398 | gdb_breakpoint [gdb_get_line_number "Break at multiply."] | |
8abea1a1 DE |
399 | gdb_py_test_silent_cmd "python check_eval = bp_eval(\"$bp_location2\")" \ |
400 | "Set breakpoint" 0 | |
330a7fce DE |
401 | gdb_test "python print (check_eval.count)" "0" \ |
402 | "Test that evaluate function has not been yet executed (ie count = 0)" | |
9abb1bd6 | 403 | gdb_continue_to_breakpoint "Break at multiply, count==1" \ |
a80db015 | 404 | ".*$srcfile:$bp_location2.*" |
330a7fce DE |
405 | gdb_test "python print (check_eval.count)" "1" \ |
406 | "Test that evaluate function is run when location also has normal bp" | |
407 | ||
408 | gdb_py_test_multiple "Sub-class a watchpoint" \ | |
409 | "python" "" \ | |
410 | "class wp_eval (gdb.Breakpoint):" "" \ | |
411 | " def stop (self):" "" \ | |
412 | " self.result = gdb.parse_and_eval(\"result\")" "" \ | |
413 | " if self.result == 788:" "" \ | |
414 | " return True" "" \ | |
415 | " return False" "" \ | |
416 | "end" "" | |
417 | ||
418 | delete_breakpoints | |
8abea1a1 DE |
419 | gdb_py_test_silent_cmd "python wp1 = wp_eval (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE)" \ |
420 | "Set watchpoint" 0 | |
421 | gdb_test "continue" \ | |
422 | ".*\[Ww\]atchpoint.*result.*Old value =.*New value = 788.*" \ | |
423 | "Test watchpoint write" | |
330a7fce DE |
424 | gdb_test "python print (never_eval_bp1.count)" "0" \ |
425 | "Check that this unrelated breakpoints eval function was never called." | |
426 | } | |
7371cf6d | 427 | } |
330a7fce DE |
428 | |
429 | proc test_bkpt_temporary { } { | |
430 | global srcfile testfile hex decimal | |
431 | ||
432 | with_test_prefix test_bkpt_temporary { | |
433 | # Start with a fresh gdb. | |
434 | clean_restart ${testfile} | |
435 | ||
436 | if ![runto_main] then { | |
bc6c7af4 | 437 | fail "cannot run to main." |
330a7fce DE |
438 | return 0 |
439 | } | |
440 | delete_breakpoints | |
441 | ||
442 | gdb_py_test_multiple "Sub-class and check temporary breakpoint" \ | |
443 | "python" "" \ | |
444 | "class temp_bp (gdb.Breakpoint):" "" \ | |
445 | " count = 0" "" \ | |
446 | " def stop (self):" "" \ | |
447 | " self.count = self.count + 1" "" \ | |
448 | " return True" "" \ | |
449 | "end" "" | |
450 | set ibp_location [gdb_get_line_number "Break at multiply."] | |
8abea1a1 | 451 | gdb_py_test_silent_cmd "python ibp = temp_bp(\"$ibp_location\", temporary=True)" \ |
330a7fce | 452 | "Set temporary breakpoint" 0 |
8abea1a1 DE |
453 | gdb_test "info breakpoints" \ |
454 | "2.*breakpoint.*del.*py-breakpoint\.c:$ibp_location.*" \ | |
330a7fce DE |
455 | "Check info breakpoints shows breakpoint with temporary status" |
456 | gdb_test "python print (ibp.location)" "py-breakpoint\.c:$ibp_location*" \ | |
457 | "Check temporary breakpoint location" | |
458 | gdb_test "python print (ibp.temporary)" "True" \ | |
459 | "Check breakpoint temporary status" | |
8abea1a1 | 460 | gdb_continue_to_breakpoint "Break at multiply." \ |
a80db015 | 461 | ".*$srcfile:$ibp_location.*" |
330a7fce DE |
462 | gdb_test "python print (ibp.count)" "1" \ |
463 | "Check temporary stop callback executed before deletion." | |
464 | gdb_test "python print (ibp.temporary)" "RuntimeError: Breakpoint 2 is invalid.*" \ | |
465 | "Check temporary breakpoint is deleted after being hit" | |
466 | gdb_test "info breakpoints" "No breakpoints or watchpoints.*" \ | |
467 | "Check info breakpoints shows temporary breakpoint is deleted" | |
468 | } | |
f76c27b5 | 469 | } |
330a7fce | 470 | |
9f61929f KS |
471 | # Test address locations. |
472 | ||
473 | proc test_bkpt_address {} { | |
474 | global gdb_prompt decimal srcfile | |
475 | ||
476 | # Delete all breakpoints | |
477 | delete_breakpoints | |
478 | ||
479 | gdb_test "python gdb.Breakpoint(\"*main\")" \ | |
480 | ".*Breakpoint ($decimal)+ at .*$srcfile, line ($decimal)+\." | |
481 | ||
482 | gdb_py_test_silent_cmd \ | |
483 | "python main_loc = gdb.parse_and_eval(\"main\").address" \ | |
484 | "eval address of main" 0 | |
485 | ||
486 | # Python 2 vs 3 ... Check `int' first. If that fails, try `long'. | |
487 | gdb_test_multiple "python main_addr = int(main_loc)" "int value of main" { | |
488 | -re "Traceback.*$gdb_prompt $" { | |
489 | gdb_test_no_output "python main_addr = long(main_loc)" \ | |
490 | "long value of main" | |
491 | } | |
492 | -re "$gdb_prompt $" { | |
493 | pass "int value of main" | |
494 | } | |
495 | } | |
496 | ||
497 | # Include whitespace in the linespec to double-check proper | |
498 | # grokking of argument to gdb.Breakpoint. | |
499 | gdb_test "python gdb.Breakpoint(\" *{}\".format(str(main_addr)))" \ | |
500 | ".*Breakpoint ($decimal)+ at .*$srcfile, line ($decimal)+\." | |
501 | } | |
502 | ||
93daf339 TT |
503 | proc test_bkpt_pending {} { |
504 | delete_breakpoints | |
505 | gdb_breakpoint "nosuchfunction" allow-pending | |
506 | gdb_test "python print (gdb.breakpoints()\[0\].pending)" "True" \ | |
507 | "Check pending status of pending breakpoint" | |
508 | } | |
509 | ||
dac790e1 TT |
510 | # Helper proc to install an event listener for a given breakpoint |
511 | # event. NAME is the name of the event to listen for. | |
512 | proc connect_event {name} { | |
513 | set lambda "lambda x: note_event(\"$name\")" | |
514 | gdb_test_no_output "python gdb.events.$name.connect($lambda)" \ | |
515 | "install $name event listener" | |
516 | } | |
517 | ||
518 | # Helper proc to check that the most recently emitted breakpoint event | |
519 | # is EXPECTED. | |
520 | proc check_last_event {expected} { | |
521 | gdb_test "python print (last_bp_event)" $expected \ | |
522 | "check for $expected event" | |
523 | } | |
524 | ||
525 | proc test_bkpt_events {} { | |
526 | global testfile | |
527 | ||
528 | clean_restart ${testfile} | |
529 | ||
530 | gdb_py_test_multiple "Create event handler" \ | |
531 | "python" "" \ | |
532 | "def note_event(arg):" "" \ | |
533 | " global last_bp_event" "" \ | |
534 | " last_bp_event = arg" "" \ | |
535 | "end" "" | |
536 | gdb_test_no_output "python last_bp_event = None" | |
537 | ||
538 | connect_event breakpoint_created | |
539 | connect_event breakpoint_modified | |
540 | connect_event breakpoint_deleted | |
541 | ||
542 | gdb_breakpoint [gdb_get_line_number "Break at add."] | |
543 | check_last_event breakpoint_created | |
544 | gdb_test_no_output "disable 1" | |
545 | check_last_event breakpoint_modified | |
546 | gdb_test_no_output "delete 1" | |
547 | check_last_event breakpoint_deleted | |
548 | } | |
549 | ||
330a7fce DE |
550 | test_bkpt_basic |
551 | test_bkpt_deletion | |
552 | test_bkpt_cond_and_cmds | |
553 | test_bkpt_invisible | |
554 | test_watchpoints | |
555 | test_bkpt_internal | |
556 | test_bkpt_eval_funcs | |
557 | test_bkpt_temporary | |
9f61929f | 558 | test_bkpt_address |
93daf339 | 559 | test_bkpt_pending |
dac790e1 | 560 | test_bkpt_events |