Commit | Line | Data |
---|---|---|
32d0add0 | 1 | # Copyright (C) 2010-2015 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 | ||
adc36818 PM |
23 | if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } { |
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 | ||
37 | if ![runto_main] then { | |
38 | fail "Cannot run to main." | |
39 | return 0 | |
40 | } | |
41 | ||
42 | # Initially there should be one breakpoint: main. | |
8abea1a1 DE |
43 | gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" \ |
44 | "Get Breakpoint List" 0 | |
45 | gdb_test "python print (blist\[0\])" \ | |
9abb1bd6 | 46 | "<gdb.Breakpoint object at $hex>" "Check obj exists @main" |
8abea1a1 | 47 | gdb_test "python print (blist\[0\].location)" \ |
9abb1bd6 | 48 | "main." "Check breakpoint location @main" |
330a7fce DE |
49 | |
50 | set mult_line [gdb_get_line_number "Break at multiply."] | |
51 | gdb_breakpoint ${mult_line} | |
9abb1bd6 DE |
52 | gdb_continue_to_breakpoint "Break at multiply" \ |
53 | ".*Break at multiply.*" | |
330a7fce DE |
54 | |
55 | # Check that the Python breakpoint code noted the addition of a | |
56 | # breakpoint "behind the scenes". | |
8abea1a1 DE |
57 | gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" \ |
58 | "Get Breakpoint List" 0 | |
59 | gdb_test "python print (len(blist))" \ | |
60 | "2" "Check for two breakpoints" | |
61 | gdb_test "python print (blist\[0\])" \ | |
9abb1bd6 | 62 | "<gdb.Breakpoint object at $hex>" "Check obj exists @main 2" |
8abea1a1 | 63 | gdb_test "python print (blist\[0\].location)" \ |
9abb1bd6 | 64 | "main." "Check breakpoint location @main 2" |
8abea1a1 | 65 | gdb_test "python print (blist\[1\])" \ |
9abb1bd6 | 66 | "<gdb.Breakpoint object at $hex>" "Check obj exists @mult_line" |
8abea1a1 DE |
67 | |
68 | gdb_test "python print (blist\[1\].location)" \ | |
69 | "py-breakpoint\.c:${mult_line}*" \ | |
9abb1bd6 | 70 | "Check breakpoint location @mult_line" |
330a7fce DE |
71 | |
72 | # Check hit and ignore counts. | |
8abea1a1 | 73 | gdb_test "python print (blist\[1\].hit_count)" \ |
9abb1bd6 | 74 | "1" "Check breakpoint hit count @1" |
8abea1a1 DE |
75 | gdb_py_test_silent_cmd "python blist\[1\].ignore_count = 4" \ |
76 | "Set breakpoint hit count" 0 | |
9abb1bd6 DE |
77 | gdb_continue_to_breakpoint "Break at multiply @6" \ |
78 | ".*Break at multiply.*" | |
8abea1a1 | 79 | gdb_test "python print (blist\[1\].hit_count)" \ |
9abb1bd6 | 80 | "6" "Check breakpoint hit count @6" |
8abea1a1 DE |
81 | gdb_test "print result" \ |
82 | " = 545" "Check expected variable result after 6 iterations" | |
330a7fce DE |
83 | |
84 | # Test breakpoint is enabled and disabled correctly.. | |
85 | gdb_breakpoint [gdb_get_line_number "Break at add."] | |
9abb1bd6 | 86 | gdb_continue_to_breakpoint "Break at add 1" ".*Break at add.*" |
8abea1a1 DE |
87 | gdb_test "python print (blist\[1\].enabled)" \ |
88 | "True" "Check breakpoint enabled." | |
89 | gdb_py_test_silent_cmd "python blist\[1\].enabled = False" \ | |
90 | "Set breakpoint disabled." 0 | |
9abb1bd6 | 91 | gdb_continue_to_breakpoint "Break at add 2" ".*Break at add.*" |
8abea1a1 DE |
92 | gdb_py_test_silent_cmd "python blist\[1\].enabled = True" \ |
93 | "Set breakpoint enabled." 0 | |
9abb1bd6 DE |
94 | gdb_continue_to_breakpoint "Break at multiply after re-enable" \ |
95 | ".*Break at multiply.*" | |
330a7fce DE |
96 | |
97 | # Test other getters and setters. | |
8abea1a1 DE |
98 | gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" \ |
99 | "Get Breakpoint List" 0 | |
100 | gdb_test "python print (blist\[1\].thread)" \ | |
101 | "None" "Check breakpoint thread" | |
102 | gdb_test "python print (blist\[1\].type == gdb.BP_BREAKPOINT)" \ | |
103 | "True" "Check breakpoint type" | |
104 | gdb_test "python print (blist\[0\].number)" \ | |
9abb1bd6 | 105 | "1" "Check breakpoint number 0" |
8abea1a1 | 106 | gdb_test "python print (blist\[1\].number)" \ |
9abb1bd6 | 107 | "2" "Check breakpoint number 1" |
8abea1a1 | 108 | gdb_test "python print (blist\[2\].number)" \ |
9abb1bd6 | 109 | "3" "Check breakpoint number 2" |
330a7fce | 110 | } |
adc36818 PM |
111 | } |
112 | ||
330a7fce DE |
113 | proc test_bkpt_deletion { } { |
114 | global srcfile testfile hex decimal | |
115 | ||
116 | with_test_prefix test_bkpt_deletion { | |
117 | # Start with a fresh gdb. | |
118 | clean_restart ${testfile} | |
119 | ||
120 | if ![runto_main] then { | |
121 | fail "Cannot run to main." | |
122 | return 0 | |
123 | } | |
124 | ||
125 | # Test breakpoints are deleted correctly. | |
126 | set deltst_location [gdb_get_line_number "Break at multiply."] | |
127 | set end_location [gdb_get_line_number "Break at end."] | |
8abea1a1 DE |
128 | gdb_py_test_silent_cmd "python dp1 = gdb.Breakpoint (\"$deltst_location\")" \ |
129 | "Set breakpoint" 0 | |
330a7fce | 130 | gdb_breakpoint [gdb_get_line_number "Break at end."] |
8abea1a1 DE |
131 | gdb_py_test_silent_cmd "python del_list = gdb.breakpoints()" \ |
132 | "Get Breakpoint List" 0 | |
133 | gdb_test "python print (len(del_list))" \ | |
134 | "3" "Number of breakpoints before delete" | |
135 | gdb_continue_to_breakpoint "Break at multiply." \ | |
a80db015 | 136 | ".*$srcfile:$deltst_location.*" |
8abea1a1 DE |
137 | gdb_py_test_silent_cmd "python dp1.delete()" \ |
138 | "Delete Breakpoint" 0 | |
139 | gdb_test "python print (dp1.number)" \ | |
140 | "RuntimeError: Breakpoint 2 is invalid.*" \ | |
141 | "Check breakpoint invalidated" | |
142 | gdb_py_test_silent_cmd "python del_list = gdb.breakpoints()" \ | |
143 | "Get Breakpoint List" 0 | |
144 | gdb_test "python print (len(del_list))" \ | |
145 | "2" "Number of breakpoints after delete" | |
146 | gdb_continue_to_breakpoint "Break at end." \ | |
a80db015 | 147 | ".*$srcfile:$end_location.*" |
330a7fce | 148 | } |
94b6973e PM |
149 | } |
150 | ||
330a7fce DE |
151 | proc test_bkpt_cond_and_cmds { } { |
152 | global srcfile testfile hex decimal | |
153 | ||
154 | with_test_prefix test_bkpt_cond_and_cmds { | |
155 | # Start with a fresh gdb. | |
156 | clean_restart ${testfile} | |
157 | ||
158 | if ![runto_main] then { | |
159 | fail "Cannot run to main." | |
160 | return 0 | |
161 | } | |
162 | ||
163 | # Test conditional setting. | |
164 | set bp_location1 [gdb_get_line_number "Break at multiply."] | |
8abea1a1 DE |
165 | gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (\"$bp_location1\")" \ |
166 | "Set breakpoint" 0 | |
9abb1bd6 DE |
167 | gdb_continue_to_breakpoint "Break at multiply" \ |
168 | ".*Break at multiply.*" | |
8abea1a1 DE |
169 | gdb_py_test_silent_cmd "python bp1.condition = \"i == 5\"" \ |
170 | "Set breakpoint" 0 | |
171 | gdb_test "python print (bp1.condition)" "i == 5" \ | |
172 | "Test conditional has been set" | |
9abb1bd6 DE |
173 | gdb_continue_to_breakpoint "Break at multiply @5" \ |
174 | ".*Break at multiply.*" | |
8abea1a1 DE |
175 | gdb_test "print i" \ |
176 | "5" "Test conditional breakpoint stopped after five iterations" | |
177 | gdb_py_test_silent_cmd "python bp1.condition = None" \ | |
178 | "Clear condition" 0 | |
179 | gdb_test "python print (bp1.condition)" \ | |
180 | "None" "Test conditional read" | |
9abb1bd6 DE |
181 | gdb_continue_to_breakpoint "Break at multiply @6" \ |
182 | ".*Break at multiply.*" | |
8abea1a1 DE |
183 | gdb_test "print i" \ |
184 | "6" "Test breakpoint stopped after six iterations" | |
330a7fce DE |
185 | |
186 | # Test commands. | |
187 | gdb_breakpoint [gdb_get_line_number "Break at add."] | |
188 | set test {commands $bpnum} | |
189 | gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } } | |
190 | set test {print "Command for breakpoint has been executed."} | |
191 | gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } } | |
192 | set test {print result} | |
193 | gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } } | |
194 | gdb_test "end" | |
195 | ||
8abea1a1 DE |
196 | gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" \ |
197 | "Get Breakpoint List" 0 | |
198 | gdb_test "python print (blist\[len(blist)-1\].commands)" \ | |
199 | "print \"Command for breakpoint has been executed.\".*print result" | |
330a7fce | 200 | } |
adc36818 PM |
201 | } |
202 | ||
330a7fce DE |
203 | proc test_bkpt_invisible { } { |
204 | global srcfile testfile hex decimal | |
205 | ||
206 | with_test_prefix test_bkpt_invisible { | |
207 | # Start with a fresh gdb. | |
208 | clean_restart ${testfile} | |
209 | ||
210 | if ![runto_main] then { | |
211 | fail "Cannot run to main." | |
212 | return 0 | |
213 | } | |
214 | ||
215 | delete_breakpoints | |
216 | set ibp_location [gdb_get_line_number "Break at multiply."] | |
8abea1a1 DE |
217 | gdb_py_test_silent_cmd "python ibp = gdb.Breakpoint(\"$ibp_location\", internal=False)" \ |
218 | "Set invisible breakpoint" 0 | |
219 | gdb_py_test_silent_cmd "python ilist = gdb.breakpoints()" \ | |
220 | "Get Breakpoint List" 0 | |
221 | gdb_test "python print (ilist\[0\])" \ | |
9abb1bd6 | 222 | "<gdb.Breakpoint object at $hex>" "Check invisible bp obj exists 1" |
8abea1a1 | 223 | gdb_test "python print (ilist\[0\].location)" \ |
9abb1bd6 | 224 | "py-breakpoint\.c:$ibp_location*" "Check breakpoint location 1" |
8abea1a1 | 225 | gdb_test "python print (ilist\[0\].visible)" \ |
9abb1bd6 | 226 | "True" "Check breakpoint visibility 1" |
8abea1a1 DE |
227 | gdb_test "info breakpoints" "py-breakpoint\.c:$ibp_location.*" \ |
228 | "Check info breakpoints shows visible breakpoints" | |
330a7fce | 229 | delete_breakpoints |
8abea1a1 DE |
230 | gdb_py_test_silent_cmd "python ibp = gdb.Breakpoint(\"$ibp_location\", internal=True)" \ |
231 | "Set invisible breakpoint" 0 | |
232 | gdb_py_test_silent_cmd "python ilist = gdb.breakpoints()" \ | |
233 | "Get Breakpoint List" 0 | |
234 | gdb_test "python print (ilist\[0\])" \ | |
9abb1bd6 | 235 | "<gdb.Breakpoint object at $hex>" "Check invisible bp obj exists 2" |
8abea1a1 | 236 | gdb_test "python print (ilist\[0\].location)" \ |
9abb1bd6 | 237 | "py-breakpoint\.c:$ibp_location*" "Check breakpoint location 2" |
8abea1a1 | 238 | gdb_test "python print (ilist\[0\].visible)" \ |
9abb1bd6 | 239 | "False" "Check breakpoint visibility 2" |
8abea1a1 DE |
240 | gdb_test "info breakpoints" "No breakpoints or watchpoints.*" \ |
241 | "Check info breakpoints does not show invisible breakpoints" | |
242 | gdb_test "maint info breakpoints" \ | |
243 | "py-breakpoint\.c:$ibp_location.*" \ | |
244 | "Check maint info breakpoints shows invisible breakpoints" | |
330a7fce | 245 | } |
84f4c1fe PM |
246 | } |
247 | ||
330a7fce DE |
248 | proc test_watchpoints { } { |
249 | global srcfile testfile hex decimal | |
adc36818 | 250 | |
330a7fce DE |
251 | with_test_prefix test_watchpoints { |
252 | # Start with a fresh gdb. | |
253 | clean_restart ${testfile} | |
adc36818 | 254 | |
330a7fce DE |
255 | # Disable hardware watchpoints if necessary. |
256 | if [target_info exists gdb,no_hardware_watchpoints] { | |
257 | gdb_test_no_output "set can-use-hw-watchpoints 0" "" | |
258 | } | |
adc36818 | 259 | |
330a7fce DE |
260 | if ![runto_main] then { |
261 | fail "Cannot run to main." | |
262 | return 0 | |
263 | } | |
adc36818 | 264 | |
8abea1a1 DE |
265 | gdb_py_test_silent_cmd "python wp1 = gdb.Breakpoint (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE )" \ |
266 | "Set watchpoint" 0 | |
267 | gdb_test "continue" \ | |
268 | ".*\[Ww\]atchpoint.*result.*Old value = 0.*New value = 25.*main.*" \ | |
269 | "Test watchpoint write" | |
330a7fce | 270 | } |
182b9acc | 271 | } |
7371cf6d | 272 | |
330a7fce DE |
273 | proc test_bkpt_internal { } { |
274 | global srcfile testfile hex decimal | |
275 | ||
276 | with_test_prefix test_bkpt_internal { | |
277 | # Start with a fresh gdb. | |
278 | clean_restart ${testfile} | |
279 | ||
280 | # Disable hardware watchpoints if necessary. | |
281 | if [target_info exists gdb,no_hardware_watchpoints] { | |
282 | gdb_test_no_output "set can-use-hw-watchpoints 0" "" | |
283 | } | |
284 | if ![runto_main] then { | |
285 | fail "Cannot run to main." | |
286 | return 0 | |
287 | } | |
288 | delete_breakpoints | |
8abea1a1 DE |
289 | gdb_py_test_silent_cmd "python wp1 = gdb.Breakpoint (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE, internal=True )" \ |
290 | "Set watchpoint" 0 | |
291 | gdb_test "info breakpoints" \ | |
292 | "No breakpoints or watchpoints.*" \ | |
293 | "Check info breakpoints does not show invisible breakpoints" | |
294 | gdb_test "maint info breakpoints" \ | |
295 | ".*watchpoint.*result.*" \ | |
296 | "Check maint info breakpoints shows invisible breakpoints" | |
297 | gdb_test "continue" \ | |
298 | ".*\[Ww\]atchpoint.*result.*Old value = 0.*New value = 25.*" \ | |
299 | "Test watchpoint write" | |
330a7fce | 300 | } |
182b9acc | 301 | } |
330a7fce DE |
302 | |
303 | proc test_bkpt_eval_funcs { } { | |
304 | global srcfile testfile hex decimal | |
305 | ||
306 | with_test_prefix test_bkpt_eval_funcs { | |
307 | # Start with a fresh gdb. | |
308 | clean_restart ${testfile} | |
309 | ||
310 | # Disable hardware watchpoints if necessary. | |
311 | if [target_info exists gdb,no_hardware_watchpoints] { | |
312 | gdb_test_no_output "set can-use-hw-watchpoints 0" "" | |
313 | } | |
314 | if ![runto_main] then { | |
315 | fail "Cannot run to main." | |
316 | return 0 | |
317 | } | |
318 | delete_breakpoints | |
319 | ||
320 | gdb_py_test_multiple "Sub-class a breakpoint" \ | |
321 | "python" "" \ | |
322 | "class bp_eval (gdb.Breakpoint):" "" \ | |
323 | " inf_i = 0" "" \ | |
324 | " count = 0" "" \ | |
325 | " def stop (self):" "" \ | |
326 | " self.count = self.count + 1" "" \ | |
327 | " self.inf_i = gdb.parse_and_eval(\"i\")" "" \ | |
328 | " if self.inf_i == 3:" "" \ | |
329 | " return True" "" \ | |
330 | " return False" "" \ | |
331 | "end" "" | |
332 | ||
333 | gdb_py_test_multiple "Sub-class a second breakpoint" \ | |
334 | "python" "" \ | |
335 | "class bp_also_eval (gdb.Breakpoint):" "" \ | |
336 | " count = 0" "" \ | |
337 | " def stop (self):" "" \ | |
338 | " self.count = self.count + 1" "" \ | |
339 | " if self.count == 9:" "" \ | |
340 | " return True" "" \ | |
341 | " return False" "" \ | |
342 | "end" "" | |
343 | ||
344 | gdb_py_test_multiple "Sub-class a third breakpoint" \ | |
345 | "python" "" \ | |
346 | "class basic (gdb.Breakpoint):" "" \ | |
347 | " count = 0" "" \ | |
348 | "end" "" | |
349 | ||
350 | set bp_location2 [gdb_get_line_number "Break at multiply."] | |
351 | set end_location [gdb_get_line_number "Break at end."] | |
8abea1a1 DE |
352 | gdb_py_test_silent_cmd "python eval_bp1 = bp_eval(\"$bp_location2\")" \ |
353 | "Set breakpoint" 0 | |
354 | gdb_py_test_silent_cmd "python also_eval_bp1 = bp_also_eval(\"$bp_location2\")" \ | |
355 | "Set breakpoint" 0 | |
356 | gdb_py_test_silent_cmd "python never_eval_bp1 = bp_also_eval(\"$end_location\")" \ | |
357 | "Set breakpoint" 0 | |
9abb1bd6 | 358 | gdb_continue_to_breakpoint "Break at multiply, i==3" \ |
a80db015 | 359 | ".*$srcfile:$bp_location2.*" |
8abea1a1 DE |
360 | gdb_test "print i" \ |
361 | "3" "Check inferior value matches python accounting" | |
362 | gdb_test "python print (eval_bp1.inf_i)" \ | |
363 | "3" "Check python accounting matches inferior" | |
330a7fce | 364 | gdb_test "python print (also_eval_bp1.count)" "4" \ |
9abb1bd6 | 365 | "Check non firing same-location also_eval_bp1 function was also called at each stop." |
330a7fce | 366 | gdb_test "python print (eval_bp1.count)" "4" \ |
9abb1bd6 | 367 | "Check non firing same-location eval_bp1 function was also called at each stop." |
330a7fce DE |
368 | |
369 | delete_breakpoints | |
370 | set cond_bp [gdb_get_line_number "Break at multiply."] | |
8abea1a1 DE |
371 | gdb_py_test_silent_cmd "python eval_bp1 = bp_eval(\"$cond_bp\")" \ |
372 | "Set breakpoint" 0 | |
330a7fce | 373 | set test_cond {cond $bpnum} |
8abea1a1 | 374 | gdb_test "$test_cond \"foo==3\"" \ |
6dddc817 | 375 | "Only one stop condition allowed. There is currently a Python.*" \ |
8abea1a1 DE |
376 | "Check you cannot add a CLI condition to a Python breakpoint that has defined stop" |
377 | gdb_py_test_silent_cmd "python eval_bp2 = basic(\"$cond_bp\")" \ | |
378 | "Set breakpoint" 0 | |
379 | gdb_py_test_silent_cmd "python eval_bp2.condition = \"1==1\"" \ | |
380 | "Set a condition" 0 | |
330a7fce DE |
381 | gdb_py_test_multiple "Construct an eval function" \ |
382 | "python" "" \ | |
383 | "def stop_func ():" "" \ | |
384 | " return True" "" \ | |
385 | "end" "" | |
386 | ||
387 | gdb_test "python eval_bp2.stop = stop_func" \ | |
6dddc817 | 388 | "RuntimeError: Only one stop condition allowed. There is currently a GDB.*" \ |
330a7fce DE |
389 | "Assign stop function to a breakpoint that has a condition" |
390 | ||
391 | delete_breakpoints | |
392 | gdb_breakpoint [gdb_get_line_number "Break at multiply."] | |
8abea1a1 DE |
393 | gdb_py_test_silent_cmd "python check_eval = bp_eval(\"$bp_location2\")" \ |
394 | "Set breakpoint" 0 | |
330a7fce DE |
395 | gdb_test "python print (check_eval.count)" "0" \ |
396 | "Test that evaluate function has not been yet executed (ie count = 0)" | |
9abb1bd6 | 397 | gdb_continue_to_breakpoint "Break at multiply, count==1" \ |
a80db015 | 398 | ".*$srcfile:$bp_location2.*" |
330a7fce DE |
399 | gdb_test "python print (check_eval.count)" "1" \ |
400 | "Test that evaluate function is run when location also has normal bp" | |
401 | ||
402 | gdb_py_test_multiple "Sub-class a watchpoint" \ | |
403 | "python" "" \ | |
404 | "class wp_eval (gdb.Breakpoint):" "" \ | |
405 | " def stop (self):" "" \ | |
406 | " self.result = gdb.parse_and_eval(\"result\")" "" \ | |
407 | " if self.result == 788:" "" \ | |
408 | " return True" "" \ | |
409 | " return False" "" \ | |
410 | "end" "" | |
411 | ||
412 | delete_breakpoints | |
8abea1a1 DE |
413 | gdb_py_test_silent_cmd "python wp1 = wp_eval (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE)" \ |
414 | "Set watchpoint" 0 | |
415 | gdb_test "continue" \ | |
416 | ".*\[Ww\]atchpoint.*result.*Old value =.*New value = 788.*" \ | |
417 | "Test watchpoint write" | |
330a7fce DE |
418 | gdb_test "python print (never_eval_bp1.count)" "0" \ |
419 | "Check that this unrelated breakpoints eval function was never called." | |
420 | } | |
7371cf6d | 421 | } |
330a7fce DE |
422 | |
423 | proc test_bkpt_temporary { } { | |
424 | global srcfile testfile hex decimal | |
425 | ||
426 | with_test_prefix test_bkpt_temporary { | |
427 | # Start with a fresh gdb. | |
428 | clean_restart ${testfile} | |
429 | ||
430 | if ![runto_main] then { | |
431 | fail "Cannot run to main." | |
432 | return 0 | |
433 | } | |
434 | delete_breakpoints | |
435 | ||
436 | gdb_py_test_multiple "Sub-class and check temporary breakpoint" \ | |
437 | "python" "" \ | |
438 | "class temp_bp (gdb.Breakpoint):" "" \ | |
439 | " count = 0" "" \ | |
440 | " def stop (self):" "" \ | |
441 | " self.count = self.count + 1" "" \ | |
442 | " return True" "" \ | |
443 | "end" "" | |
444 | set ibp_location [gdb_get_line_number "Break at multiply."] | |
8abea1a1 | 445 | gdb_py_test_silent_cmd "python ibp = temp_bp(\"$ibp_location\", temporary=True)" \ |
330a7fce | 446 | "Set temporary breakpoint" 0 |
8abea1a1 DE |
447 | gdb_test "info breakpoints" \ |
448 | "2.*breakpoint.*del.*py-breakpoint\.c:$ibp_location.*" \ | |
330a7fce DE |
449 | "Check info breakpoints shows breakpoint with temporary status" |
450 | gdb_test "python print (ibp.location)" "py-breakpoint\.c:$ibp_location*" \ | |
451 | "Check temporary breakpoint location" | |
452 | gdb_test "python print (ibp.temporary)" "True" \ | |
453 | "Check breakpoint temporary status" | |
8abea1a1 | 454 | gdb_continue_to_breakpoint "Break at multiply." \ |
a80db015 | 455 | ".*$srcfile:$ibp_location.*" |
330a7fce DE |
456 | gdb_test "python print (ibp.count)" "1" \ |
457 | "Check temporary stop callback executed before deletion." | |
458 | gdb_test "python print (ibp.temporary)" "RuntimeError: Breakpoint 2 is invalid.*" \ | |
459 | "Check temporary breakpoint is deleted after being hit" | |
460 | gdb_test "info breakpoints" "No breakpoints or watchpoints.*" \ | |
461 | "Check info breakpoints shows temporary breakpoint is deleted" | |
462 | } | |
f76c27b5 | 463 | } |
330a7fce DE |
464 | |
465 | test_bkpt_basic | |
466 | test_bkpt_deletion | |
467 | test_bkpt_cond_and_cmds | |
468 | test_bkpt_invisible | |
469 | test_watchpoints | |
470 | test_bkpt_internal | |
471 | test_bkpt_eval_funcs | |
472 | test_bkpt_temporary |