gdb/testsuite: add simavr.exp board
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-breakpoint.exp
1 # Copyright (C) 2010-2020 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 <http://www.gnu.org/licenses/>.
15
16 # This file is part of the GDB testsuite. It tests the mechanism
17 # exposing breakpoints to Python.
18
19 load_lib gdb-python.exp
20
21 standard_testfile
22
23 set options {debug c++}
24
25 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} ${options}] } {
26 return -1
27 }
28
29 # Skip all tests if Python scripting is not enabled.
30 if { [skip_python_tests] } { continue }
31
32 proc_with_prefix test_bkpt_basic { } {
33 global srcfile testfile hex decimal
34
35 # Start with a fresh gdb.
36 clean_restart ${testfile}
37
38 # We should start with no breakpoints.
39 gdb_test "python print (gdb.breakpoints())" "\\(\\)"
40
41 if ![runto_main] then {
42 fail "cannot run to main."
43 return 0
44 }
45
46 # Now there should be one breakpoint: main.
47 gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" \
48 "Get Breakpoint List" 0
49 gdb_test "python print (blist\[0\])" \
50 "<gdb.Breakpoint object at $hex>" "Check obj exists @main"
51 gdb_test "python print (blist\[0\].location)" \
52 "main." "Check breakpoint location @main"
53 gdb_test "python print (blist\[0\].pending)" "False" \
54 "Check pending status of main breakpoint"
55
56 set mult_line [gdb_get_line_number "Break at multiply."]
57 gdb_breakpoint ${mult_line}
58 gdb_continue_to_breakpoint "Break at multiply" \
59 ".*Break at multiply.*"
60
61 # Check that the Python breakpoint code noted the addition of a
62 # breakpoint "behind the scenes".
63 gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" \
64 "Get Breakpoint List" 0
65 gdb_test "python print (len(blist))" \
66 "2" "Check for two breakpoints"
67 gdb_test "python print (blist\[0\])" \
68 "<gdb.Breakpoint object at $hex>" "Check obj exists @main 2"
69 gdb_test "python print (blist\[0\].location)" \
70 "main." "Check breakpoint location @main 2"
71 gdb_test "python print (blist\[1\])" \
72 "<gdb.Breakpoint object at $hex>" "Check obj exists @mult_line"
73
74 gdb_test "python print (blist\[1\].location)" \
75 "py-breakpoint\.c:${mult_line}*" \
76 "check breakpoint location @mult_line"
77
78 # Check hit and ignore counts.
79 gdb_test "python print (blist\[1\].hit_count)" \
80 "1" "Check breakpoint hit count @1"
81 gdb_py_test_silent_cmd "python blist\[1\].ignore_count = 4" \
82 "Set breakpoint hit count" 0
83 gdb_continue_to_breakpoint "Break at multiply @6" \
84 ".*Break at multiply.*"
85 gdb_test "python print (blist\[1\].hit_count)" \
86 "6" "Check breakpoint hit count @6"
87 gdb_test "print result" \
88 " = 545" "Check expected variable result after 6 iterations"
89
90 # Test breakpoint is enabled and disabled correctly..
91 gdb_breakpoint [gdb_get_line_number "Break at add."]
92 gdb_continue_to_breakpoint "Break at add 1" ".*Break at add.*"
93 gdb_test "python print (blist\[1\].enabled)" \
94 "True" "Check breakpoint enabled."
95 gdb_py_test_silent_cmd "python blist\[1\].enabled = False" \
96 "Set breakpoint disabled." 0
97 gdb_continue_to_breakpoint "Break at add 2" ".*Break at add.*"
98 gdb_py_test_silent_cmd "python blist\[1\].enabled = True" \
99 "Set breakpoint enabled." 0
100 gdb_continue_to_breakpoint "Break at multiply after re-enable" \
101 ".*Break at multiply.*"
102
103 # Test other getters and setters.
104 gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" \
105 "Get Breakpoint List" 0
106 gdb_test "python print (blist\[1\].thread)" \
107 "None" "Check breakpoint thread"
108 gdb_test "python print (blist\[1\].type == gdb.BP_BREAKPOINT)" \
109 "True" "Check breakpoint type"
110 gdb_test "python print (blist\[0\].number)" \
111 "1" "Check breakpoint number 0"
112 gdb_test "python print (blist\[1\].number)" \
113 "2" "Check breakpoint number 1"
114 gdb_test "python print (blist\[2\].number)" \
115 "3" "Check breakpoint number 2"
116 }
117
118 proc_with_prefix test_bkpt_deletion { } {
119 global srcfile testfile hex decimal
120
121 # Start with a fresh gdb.
122 clean_restart ${testfile}
123
124 if ![runto_main] then {
125 fail "cannot run to main."
126 return 0
127 }
128
129 # Test breakpoints are deleted correctly.
130 set deltst_location [gdb_get_line_number "Break at multiply."]
131 set end_location [gdb_get_line_number "Break at end."]
132 gdb_py_test_silent_cmd "python dp1 = gdb.Breakpoint (\"$deltst_location\")" \
133 "Set breakpoint" 0
134 gdb_breakpoint [gdb_get_line_number "Break at end."]
135 gdb_py_test_silent_cmd "python del_list = gdb.breakpoints()" \
136 "Get Breakpoint List" 0
137 gdb_test "python print (len(del_list))" \
138 "3" "Number of breakpoints before delete"
139 gdb_continue_to_breakpoint "Break at multiply." \
140 ".*$srcfile:$deltst_location.*"
141 gdb_py_test_silent_cmd "python dp1.delete()" \
142 "Delete Breakpoint" 0
143 gdb_test "python print (dp1.number)" \
144 "RuntimeError: Breakpoint 2 is invalid.*" \
145 "Check breakpoint invalidated"
146 gdb_py_test_silent_cmd "python del_list = gdb.breakpoints()" \
147 "Get Breakpoint List" 0
148 gdb_test "python print (len(del_list))" \
149 "2" "Number of breakpoints after delete"
150 gdb_continue_to_breakpoint "Break at end." \
151 ".*$srcfile:$end_location.*"
152 }
153
154 proc_with_prefix test_bkpt_cond_and_cmds { } {
155 global srcfile testfile hex decimal
156
157 # Start with a fresh gdb.
158 clean_restart ${testfile}
159
160 if ![runto_main] then {
161 fail "cannot run to main."
162 return 0
163 }
164
165 # Test conditional setting.
166 set bp_location1 [gdb_get_line_number "Break at multiply."]
167 gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (\"$bp_location1\")" \
168 "Set breakpoint" 0
169 gdb_continue_to_breakpoint "Break at multiply" \
170 ".*Break at multiply.*"
171 gdb_py_test_silent_cmd "python bp1.condition = \"i == 5\"" \
172 "Set breakpoint" 0
173 gdb_test "python print (bp1.condition)" "i == 5" \
174 "Test conditional has been set"
175 gdb_continue_to_breakpoint "Break at multiply @5" \
176 ".*Break at multiply.*"
177 gdb_test "print i" \
178 "5" "Test conditional breakpoint stopped after five iterations"
179 gdb_py_test_silent_cmd "python bp1.condition = None" \
180 "Clear condition" 0
181 gdb_test "python print (bp1.condition)" \
182 "None" "Test conditional read"
183 gdb_continue_to_breakpoint "Break at multiply @6" \
184 ".*Break at multiply.*"
185 gdb_test "print i" \
186 "6" "Test breakpoint stopped after six iterations"
187
188 # Test commands.
189 gdb_breakpoint [gdb_get_line_number "Break at add."]
190 set test {commands $bpnum}
191 gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } }
192 set test {print "Command for breakpoint has been executed."}
193 gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } }
194 set test {print result}
195 gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } }
196 gdb_test "end"
197
198 gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" \
199 "Get Breakpoint List" 0
200 gdb_py_test_silent_cmd "python last_bp = blist\[len(blist)-1\]" \
201 "Find last breakpoint" 0
202 gdb_test "python print (last_bp.commands)" \
203 "print \"Command for breakpoint has been executed.\".*print result"
204
205 gdb_test_no_output "python last_bp.commands = 'echo hi\\necho there'" \
206 "set commands"
207 # Note the length is 3 because the string ends in a \n.
208 gdb_test "python print (len(last_bp.commands.split('\\n')))" "3" \
209 "check number of lines in commands"
210 }
211
212 proc_with_prefix test_bkpt_invisible { } {
213 global srcfile testfile hex decimal
214
215 # Start with a fresh gdb.
216 clean_restart ${testfile}
217
218 if ![runto_main] then {
219 fail "cannot run to main."
220 return 0
221 }
222
223 delete_breakpoints
224 set ibp_location [gdb_get_line_number "Break at multiply."]
225 gdb_py_test_silent_cmd "python ibp = gdb.Breakpoint(\"$ibp_location\", internal=False)" \
226 "Set invisible breakpoint" 0
227 gdb_py_test_silent_cmd "python ilist = gdb.breakpoints()" \
228 "Get Breakpoint List" 0
229 gdb_test "python print (ilist\[0\])" \
230 "<gdb.Breakpoint object at $hex>" "Check invisible bp obj exists 1"
231 gdb_test "python print (ilist\[0\].location)" \
232 "py-breakpoint\.c:$ibp_location*" "Check breakpoint location 1"
233 gdb_test "python print (ilist\[0\].visible)" \
234 "True" "Check breakpoint visibility 1"
235 gdb_test "info breakpoints" "py-breakpoint\.c:$ibp_location.*" \
236 "Check info breakpoints shows visible breakpoints"
237 delete_breakpoints
238 gdb_py_test_silent_cmd "python ibp = gdb.Breakpoint(\"$ibp_location\", internal=True)" \
239 "Set invisible breakpoint" 0
240 gdb_py_test_silent_cmd "python ilist = gdb.breakpoints()" \
241 "Get Breakpoint List" 0
242 gdb_test "python print (ilist\[0\])" \
243 "<gdb.Breakpoint object at $hex>" "Check invisible bp obj exists 2"
244 gdb_test "python print (ilist\[0\].location)" \
245 "py-breakpoint\.c:$ibp_location*" "Check breakpoint location 2"
246 gdb_test "python print (ilist\[0\].visible)" \
247 "False" "Check breakpoint visibility 2"
248 gdb_test "info breakpoints" "No breakpoints or watchpoints.*" \
249 "Check info breakpoints does not show invisible breakpoints"
250 gdb_test "maint info breakpoints" \
251 "py-breakpoint\.c:$ibp_location.*" \
252 "Check maint info breakpoints shows invisible breakpoints"
253 }
254
255 proc_with_prefix test_watchpoints { } {
256 global srcfile testfile hex decimal
257
258 # Start with a fresh gdb.
259 clean_restart ${testfile}
260
261 # Disable hardware watchpoints if necessary.
262 if [target_info exists gdb,no_hardware_watchpoints] {
263 gdb_test_no_output "set can-use-hw-watchpoints 0" ""
264 }
265
266 if ![runto_main] then {
267 fail "cannot run to main."
268 return 0
269 }
270
271 gdb_py_test_silent_cmd "python wp1 = gdb.Breakpoint (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE )" \
272 "Set watchpoint" 0
273 gdb_test "python print (wp1.pending)" "False"
274 gdb_test "continue" \
275 ".*\[Ww\]atchpoint.*result.*Old value = 0.*New value = 25.*main.*" \
276 "Test watchpoint write"
277 }
278
279 proc_with_prefix test_bkpt_internal { } {
280 global srcfile testfile hex decimal
281
282 # Start with a fresh gdb.
283 clean_restart ${testfile}
284
285 # Disable hardware watchpoints if necessary.
286 if [target_info exists gdb,no_hardware_watchpoints] {
287 gdb_test_no_output "set can-use-hw-watchpoints 0" ""
288 }
289 if ![runto_main] then {
290 fail "cannot run to main."
291 return 0
292 }
293 delete_breakpoints
294 gdb_py_test_silent_cmd "python wp1 = gdb.Breakpoint (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE, internal=True )" \
295 "Set watchpoint" 0
296 gdb_test "info breakpoints" \
297 "No breakpoints or watchpoints.*" \
298 "Check info breakpoints does not show invisible breakpoints"
299 gdb_test "maint info breakpoints" \
300 ".*watchpoint.*result.*" \
301 "Check maint info breakpoints shows invisible breakpoints"
302 gdb_test "continue" \
303 ".*\[Ww\]atchpoint.*result.*Old value = 0.*New value = 25.*" \
304 "Test watchpoint write"
305 }
306
307 proc_with_prefix test_bkpt_eval_funcs { } {
308 global srcfile testfile hex decimal
309
310 # Start with a fresh gdb.
311 clean_restart ${testfile}
312
313 # Disable hardware watchpoints if necessary.
314 if [target_info exists gdb,no_hardware_watchpoints] {
315 gdb_test_no_output "set can-use-hw-watchpoints 0" ""
316 }
317 if ![runto_main] then {
318 fail "cannot run to main."
319 return 0
320 }
321 delete_breakpoints
322
323 gdb_py_test_multiple "Sub-class a breakpoint" \
324 "python" "" \
325 "class bp_eval (gdb.Breakpoint):" "" \
326 " inf_i = 0" "" \
327 " count = 0" "" \
328 " def stop (self):" "" \
329 " self.count = self.count + 1" "" \
330 " self.inf_i = gdb.parse_and_eval(\"i\")" "" \
331 " if self.inf_i == 3:" "" \
332 " return True" "" \
333 " return False" "" \
334 "end" ""
335
336 gdb_py_test_multiple "Sub-class a second breakpoint" \
337 "python" "" \
338 "class bp_also_eval (gdb.Breakpoint):" "" \
339 " count = 0" "" \
340 " def stop (self):" "" \
341 " self.count = self.count + 1" "" \
342 " if self.count == 9:" "" \
343 " return True" "" \
344 " return False" "" \
345 "end" ""
346
347 gdb_py_test_multiple "Sub-class a third breakpoint" \
348 "python" "" \
349 "class basic (gdb.Breakpoint):" "" \
350 " count = 0" "" \
351 "end" ""
352
353 set bp_location2 [gdb_get_line_number "Break at multiply."]
354 set end_location [gdb_get_line_number "Break at end."]
355 gdb_py_test_silent_cmd "python eval_bp1 = bp_eval(\"$bp_location2\")" \
356 "Set breakpoint" 0
357 gdb_py_test_silent_cmd "python also_eval_bp1 = bp_also_eval(\"$bp_location2\")" \
358 "Set breakpoint" 0
359 gdb_py_test_silent_cmd "python never_eval_bp1 = bp_also_eval(\"$end_location\")" \
360 "Set breakpoint" 0
361 gdb_continue_to_breakpoint "Break at multiply, i==3" \
362 ".*$srcfile:$bp_location2.*"
363 gdb_test "print i" \
364 "3" "Check inferior value matches python accounting"
365 gdb_test "python print (eval_bp1.inf_i)" \
366 "3" "Check python accounting matches inferior"
367 gdb_test "python print (also_eval_bp1.count)" "4" \
368 "Check non firing same-location also_eval_bp1 function was also called at each stop."
369 gdb_test "python print (eval_bp1.count)" "4" \
370 "Check non firing same-location eval_bp1 function was also called at each stop."
371
372 delete_breakpoints
373 set cond_bp [gdb_get_line_number "Break at multiply."]
374 gdb_py_test_silent_cmd "python eval_bp1 = bp_eval(\"$cond_bp\")" \
375 "Set breakpoint" 0
376 set test_cond {cond $bpnum}
377 gdb_test "$test_cond \"foo==3\"" \
378 "Only one stop condition allowed. There is currently a Python.*" \
379 "Check you cannot add a CLI condition to a Python breakpoint that has defined stop"
380 gdb_py_test_silent_cmd "python eval_bp2 = basic(\"$cond_bp\")" \
381 "Set breakpoint" 0
382 gdb_py_test_silent_cmd "python eval_bp2.condition = \"1==1\"" \
383 "Set a condition" 0
384 gdb_py_test_multiple "Construct an eval function" \
385 "python" "" \
386 "def stop_func ():" "" \
387 " return True" "" \
388 "end" ""
389
390 gdb_test "python eval_bp2.stop = stop_func" \
391 "RuntimeError: Only one stop condition allowed. There is currently a GDB.*" \
392 "assign stop function to a breakpoint that has a condition"
393
394 delete_breakpoints
395 gdb_breakpoint [gdb_get_line_number "Break at multiply."]
396 gdb_py_test_silent_cmd "python check_eval = bp_eval(\"$bp_location2\")" \
397 "Set breakpoint" 0
398 gdb_test "python print (check_eval.count)" "0" \
399 "Test that evaluate function has not been yet executed (ie count = 0)"
400 gdb_continue_to_breakpoint "Break at multiply, count==1" \
401 ".*$srcfile:$bp_location2.*"
402 gdb_test "python print (check_eval.count)" "1" \
403 "Test that evaluate function is run when location also has normal bp"
404
405 gdb_py_test_multiple "Sub-class a watchpoint" \
406 "python" "" \
407 "class wp_eval (gdb.Breakpoint):" "" \
408 " def stop (self):" "" \
409 " self.result = gdb.parse_and_eval(\"result\")" "" \
410 " if self.result == 788:" "" \
411 " return True" "" \
412 " return False" "" \
413 "end" ""
414
415 delete_breakpoints
416 gdb_py_test_silent_cmd "python wp1 = wp_eval (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE)" \
417 "Set watchpoint" 0
418 gdb_test "continue" \
419 ".*\[Ww\]atchpoint.*result.*Old value =.*New value = 788.*" \
420 "Test watchpoint write"
421 gdb_test "python print (never_eval_bp1.count)" "0" \
422 "Check that this unrelated breakpoints eval function was never called."
423 }
424
425 proc_with_prefix test_bkpt_temporary { } {
426 global srcfile testfile hex decimal
427
428 # Start with a fresh gdb.
429 clean_restart ${testfile}
430
431 if ![runto_main] then {
432 fail "cannot run to main."
433 return 0
434 }
435 delete_breakpoints
436
437 gdb_py_test_multiple "Sub-class and check temporary breakpoint" \
438 "python" "" \
439 "class temp_bp (gdb.Breakpoint):" "" \
440 " count = 0" "" \
441 " def stop (self):" "" \
442 " self.count = self.count + 1" "" \
443 " return True" "" \
444 "end" ""
445 set ibp_location [gdb_get_line_number "Break at multiply."]
446 gdb_py_test_silent_cmd "python ibp = temp_bp(\"$ibp_location\", temporary=True)" \
447 "Set temporary breakpoint" 0
448 gdb_test "info breakpoints" \
449 "2.*breakpoint.*del.*py-breakpoint\.c:$ibp_location.*" \
450 "Check info breakpoints shows breakpoint with temporary status"
451 gdb_test "python print (ibp.location)" "py-breakpoint\.c:$ibp_location*" \
452 "Check temporary breakpoint location"
453 gdb_test "python print (ibp.temporary)" "True" \
454 "Check breakpoint temporary status"
455 gdb_continue_to_breakpoint "Break at multiply." \
456 ".*$srcfile:$ibp_location.*"
457 gdb_test "python print (ibp.count)" "1" \
458 "Check temporary stop callback executed before deletion."
459 gdb_test "python print (ibp.temporary)" "RuntimeError: Breakpoint 2 is invalid.*" \
460 "Check temporary breakpoint is deleted after being hit"
461 gdb_test "info breakpoints" "No breakpoints or watchpoints.*" \
462 "Check info breakpoints shows temporary breakpoint is deleted"
463 }
464
465 # Test address locations.
466
467 proc_with_prefix test_bkpt_address {} {
468 global gdb_prompt decimal srcfile
469
470 # Delete all breakpoints
471 delete_breakpoints
472
473 gdb_test "python gdb.Breakpoint(\"*main\")" \
474 ".*Breakpoint ($decimal)+ at .*$srcfile, line ($decimal)+\."
475
476 gdb_py_test_silent_cmd \
477 "python main_loc = gdb.parse_and_eval(\"main\").address" \
478 "eval address of main" 0
479
480 # Python 2 vs 3 ... Check `int' first. If that fails, try `long'.
481 gdb_test_multiple "python main_addr = int(main_loc)" "int value of main" {
482 -re "Traceback.*$gdb_prompt $" {
483 gdb_test_no_output "python main_addr = long(main_loc)" \
484 "long value of main"
485 }
486 -re "$gdb_prompt $" {
487 pass "int value of main"
488 }
489 }
490
491 # Include whitespace in the linespec to double-check proper
492 # grokking of argument to gdb.Breakpoint.
493 gdb_test "python gdb.Breakpoint(\" *{}\".format(str(main_addr)))" \
494 ".*Breakpoint ($decimal)+ at .*$srcfile, line ($decimal)+\."
495 }
496
497 proc_with_prefix test_bkpt_pending {} {
498 delete_breakpoints
499 gdb_breakpoint "nosuchfunction" allow-pending
500 gdb_test "python print (gdb.breakpoints()\[0\].pending)" "True" \
501 "Check pending status of pending breakpoint"
502 }
503
504 # Helper proc to install an event listener for a given breakpoint
505 # event. NAME is the name of the event to listen for.
506 proc connect_event {name} {
507 set lambda "lambda x: note_event(\"$name\")"
508 gdb_test_no_output "python gdb.events.$name.connect($lambda)" \
509 "install $name event listener"
510 }
511
512 # Helper proc to check that the most recently emitted breakpoint event
513 # is EXPECTED.
514 proc check_last_event {expected} {
515 gdb_test "python print (last_bp_event)" $expected \
516 "check for $expected event"
517 }
518
519 proc_with_prefix test_bkpt_events {} {
520 global testfile
521
522 clean_restart ${testfile}
523
524 gdb_py_test_multiple "Create event handler" \
525 "python" "" \
526 "def note_event(arg):" "" \
527 " global last_bp_event" "" \
528 " last_bp_event = arg" "" \
529 "end" ""
530 gdb_test_no_output "python last_bp_event = None"
531
532 connect_event breakpoint_created
533 connect_event breakpoint_modified
534 connect_event breakpoint_deleted
535
536 gdb_breakpoint [gdb_get_line_number "Break at add."]
537 check_last_event breakpoint_created
538 gdb_test_no_output "disable 1"
539 check_last_event breakpoint_modified
540 gdb_test_no_output "delete 1"
541 check_last_event breakpoint_deleted
542 }
543
544 proc_with_prefix test_bkpt_explicit_loc {} {
545 global srcfile testfile
546
547 # Start with a fresh gdb.
548 clean_restart ${testfile}
549
550 if ![runto_main] then {
551 fail "cannot run to main."
552 return 0
553 }
554
555 delete_breakpoints
556
557 set bp_location1 [gdb_get_line_number "Break at multiply."]
558 set bp_location2 [gdb_get_line_number "Break at add."]
559
560 gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (line=$bp_location1)" \
561 "set explicit breakpoint by line" 0
562 gdb_continue_to_breakpoint "break at multiply for explicit line" \
563 ".*Break at multiply.*"
564
565 gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (line=\"+1\")" \
566 "set explicit breakpoint by relative line" 0
567 gdb_continue_to_breakpoint "break at add for relative line" \
568 ".*Break at add.*"
569
570 delete_breakpoints
571 gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (line=\"-1\")" \
572 "set explicit breakpoint by relative negative line" 0
573 gdb_continue_to_breakpoint "break at multiply for negative line" \
574 ".*Break at multiply.*"
575
576 delete_breakpoints
577 gdb_test "python bp1 = gdb.Breakpoint (line=bp1)" \
578 "RuntimeError: Line keyword should be an integer or a string.*" \
579 "set explicit breakpoint by invalid line type"
580
581 delete_breakpoints
582 gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (function=\"add\")" \
583 "set explicit breakpoint by function" 0
584 gdb_continue_to_breakpoint "break at function add for function" \
585 ".*Break at function add.*"
586
587 delete_breakpoints
588 gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (source=\"$srcfile\", function=\"add\")" \
589 "set explicit breakpoint by source file and function" 0
590 gdb_continue_to_breakpoint "break at function add for source and function" \
591 ".*Break at function add.*"
592
593 delete_breakpoints
594 gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (source=\"$srcfile\", line=\"$bp_location2\")" \
595 "set explicit breakpoint by source file and line number" 0
596 gdb_continue_to_breakpoint "break at add for source and line" \
597 ".*Break at add.*"
598
599 delete_breakpoints
600 gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (\"-source $srcfile -line $bp_location2\")" \
601 "set explicit breakpoint by source file and line number in spec" 0
602 gdb_continue_to_breakpoint "break at add for source and line in spec" \
603 ".*Break at add.*"
604
605 delete_breakpoints
606 gdb_test "python bp1 = gdb.Breakpoint (source=\"$srcfile\")" \
607 "RuntimeError: Specifying a source must also include a line, label or function.*" \
608 "set invalid explicit breakpoint by source only"
609
610 gdb_test "python bp1 = gdb.Breakpoint (source=\"foo.c\", line=\"5\")" \
611 "No source file named foo.*" \
612 "set invalid explicit breakpoint by missing source and line"
613 gdb_test "python bp1 = gdb.Breakpoint (source=\"$srcfile\", line=\"900\")" \
614 "No line 900 in file \"$srcfile\".*" \
615 "set invalid explicit breakpoint by source and invalid line"
616 gdb_test "python bp1 = gdb.Breakpoint (function=\"blah\")" \
617 "Function \"blah\" not defined.*" \
618 "set invalid explicit breakpoint by missing function"
619
620 delete_breakpoints
621 gdb_test "catch throw" "Catchpoint .* \\(throw\\)"
622 gdb_test "python print (gdb.breakpoints())" \
623 "\(\)" \
624 "catch throw is not a breakpoint"
625 }
626
627 proc_with_prefix test_bkpt_qualified {} {
628 global decimal hex testfile
629
630 # Start with a fresh gdb.
631 clean_restart ${testfile}
632
633 set one_location_re "Breakpoint $decimal at $hex:.*line $decimal."
634 set two_location_re "Breakpoint $decimal at $hex:.*2 locations."
635
636 if ![runto_main] then {
637 fail "cannot run to main."
638 return 0
639 }
640
641 # Test the default value of "qualified".
642 delete_breakpoints
643 gdb_test \
644 "python gdb.Breakpoint(\"multiply\")" \
645 $two_location_re \
646 "qualified implicitly false"
647
648 # Test qualified=False.
649 delete_breakpoints
650 gdb_test \
651 "python gdb.Breakpoint(\"multiply\", qualified=False)" \
652 $two_location_re \
653 "qualified false"
654
655 # Test qualified=True.
656 delete_breakpoints
657 gdb_test \
658 "python gdb.Breakpoint(\"multiply\", qualified=True)" \
659 $one_location_re \
660 "qualified true"
661
662 # Test qualified=True with an explicit function.
663 delete_breakpoints
664 gdb_test \
665 "python gdb.Breakpoint(function=\"multiply\", qualified=True)" \
666 $one_location_re \
667 "qualified true and explicit"
668
669 # Test qualified=False with an explicit function.
670 delete_breakpoints
671 gdb_test \
672 "python gdb.Breakpoint(function=\"multiply\", qualified=False)" \
673 $two_location_re \
674 "qualified false and explicit"
675
676 # Test -q in the spec string.
677 delete_breakpoints
678 gdb_test \
679 "python gdb.Breakpoint(\"-q multiply\")" \
680 $one_location_re \
681 "-q in spec string"
682
683 # Test -q in the spec string with explicit location.
684 delete_breakpoints
685 gdb_test \
686 "python gdb.Breakpoint(\"-q -function multiply\")" \
687 $one_location_re \
688 "-q in spec string with explicit location"
689
690 # Test -q in the spec string and qualified=False (-q should win).
691 delete_breakpoints
692 gdb_test \
693 "python gdb.Breakpoint(\"-q multiply\", qualified=False)" \
694 $one_location_re \
695 "-q in spec string and qualified false"
696 }
697
698 proc_with_prefix test_bkpt_probe {} {
699 global decimal hex testfile srcfile
700
701 if { [prepare_for_testing "failed to prepare" ${testfile}-probes \
702 ${srcfile} {debug c++ additional_flags=-DUSE_PROBES}] } {
703 return -1
704 }
705
706 if ![runto_main] then {
707 fail "cannot run to main."
708 return 0
709 }
710
711 gdb_test \
712 "python gdb.Breakpoint(\"-probe test:result_updated\")" \
713 "Breakpoint $decimal at $hex" \
714 "-probe in spec string"
715 }
716
717 test_bkpt_basic
718 test_bkpt_deletion
719 test_bkpt_cond_and_cmds
720 test_bkpt_invisible
721 test_watchpoints
722 test_bkpt_internal
723 test_bkpt_eval_funcs
724 test_bkpt_temporary
725 test_bkpt_address
726 test_bkpt_pending
727 test_bkpt_events
728 test_bkpt_explicit_loc
729 test_bkpt_qualified
730 test_bkpt_probe
This page took 0.046508 seconds and 4 git commands to generate.