1 # Copyright (C) 2010-2021 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This file is part of the GDB testsuite. It tests the mechanism
17 # exposing breakpoints to Python.
19 load_lib gdb-python.exp
23 set options {debug c++}
25 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} ${options}] } {
29 # Skip all tests if Python scripting is not enabled.
30 if { [skip_python_tests] } { continue }
32 proc_with_prefix test_bkpt_basic { } {
33 global srcfile testfile hex decimal
35 # Start with a fresh gdb.
36 clean_restart ${testfile}
38 # We should start with no breakpoints.
39 gdb_test "python print (gdb.breakpoints())" "\\(\\)"
41 if ![runto_main] then {
42 fail "cannot run to main."
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"
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.*"
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"
74 gdb_test "python print (blist\[1\].location)" \
75 "py-breakpoint\.c:${mult_line}*" \
76 "check breakpoint location @mult_line"
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"
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.*"
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"
118 proc_with_prefix test_bkpt_deletion { } {
119 global srcfile testfile hex decimal
121 # Start with a fresh gdb.
122 clean_restart ${testfile}
124 if ![runto_main] then {
125 fail "cannot run to main."
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\")" \
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.*"
154 proc_with_prefix test_bkpt_cond_and_cmds { } {
155 global srcfile testfile hex decimal
157 # Start with a fresh gdb.
158 clean_restart ${testfile}
160 if ![runto_main] then {
161 fail "cannot run to main."
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\")" \
169 gdb_continue_to_breakpoint "Break at multiply" \
170 ".*Break at multiply.*"
171 gdb_py_test_silent_cmd "python bp1.condition = \"i == 5\"" \
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.*"
178 "5" "Test conditional breakpoint stopped after five iterations"
179 gdb_py_test_silent_cmd "python bp1.condition = None" \
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.*"
186 "6" "Test breakpoint stopped after six iterations"
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 } }
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"
205 gdb_test_no_output "python last_bp.commands = 'echo hi\\necho there'" \
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"
212 proc_with_prefix test_bkpt_invisible { } {
213 global srcfile testfile hex decimal
215 # Start with a fresh gdb.
216 clean_restart ${testfile}
218 if ![runto_main] then {
219 fail "cannot run to main."
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"
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"
255 proc_with_prefix test_hardware_breakpoints { } {
256 global srcfile testfile hex decimal
258 # Start with a fresh gdb.
259 clean_restart ${testfile}
261 if ![runto_main] then {
262 fail "cannot run to main."
268 gdb_test "python hbp1 = gdb.Breakpoint(\"add\", type=gdb.BP_HARDWARE_BREAKPOINT)" \
269 ".*Hardware assisted breakpoint ($decimal)+ at .*$srcfile, line ($decimal)+\." \
270 "Set hardware breakpoint"
271 gdb_test "python print (gdb.breakpoints()\[0\].type == gdb.BP_HARDWARE_BREAKPOINT)" \
272 "True" "Check hardware breakpoint type"
273 gdb_test "continue" \
274 ".*Breakpoint ($decimal)+, add.*" \
275 "Test hardware breakpoint stop"
278 proc_with_prefix test_watchpoints { } {
279 global srcfile testfile hex decimal
281 # Start with a fresh gdb.
282 clean_restart ${testfile}
284 # Disable hardware watchpoints if necessary.
285 if [target_info exists gdb,no_hardware_watchpoints] {
286 gdb_test_no_output "set can-use-hw-watchpoints 0" ""
289 if ![runto_main] then {
290 fail "cannot run to main."
294 gdb_py_test_silent_cmd "python wp1 = gdb.Breakpoint (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE )" \
296 gdb_test "python print (wp1.pending)" "False"
297 gdb_test "continue" \
298 ".*\[Ww\]atchpoint.*result.*Old value = 0.*New value = 25.*main.*" \
299 "Test watchpoint write"
302 proc_with_prefix test_bkpt_internal { } {
303 global srcfile testfile hex decimal
305 # Start with a fresh gdb.
306 clean_restart ${testfile}
308 # Disable hardware watchpoints if necessary.
309 if [target_info exists gdb,no_hardware_watchpoints] {
310 gdb_test_no_output "set can-use-hw-watchpoints 0" ""
312 if ![runto_main] then {
313 fail "cannot run to main."
317 gdb_py_test_silent_cmd "python wp1 = gdb.Breakpoint (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE, internal=True )" \
319 gdb_test "info breakpoints" \
320 "No breakpoints or watchpoints.*" \
321 "Check info breakpoints does not show invisible breakpoints"
322 gdb_test "maint info breakpoints" \
323 ".*watchpoint.*result.*" \
324 "Check maint info breakpoints shows invisible breakpoints"
325 gdb_test "continue" \
326 ".*\[Ww\]atchpoint.*result.*Old value = 0.*New value = 25.*" \
327 "Test watchpoint write"
330 proc_with_prefix test_bkpt_eval_funcs { } {
331 global srcfile testfile hex decimal
333 # Start with a fresh gdb.
334 clean_restart ${testfile}
336 # Disable hardware watchpoints if necessary.
337 if [target_info exists gdb,no_hardware_watchpoints] {
338 gdb_test_no_output "set can-use-hw-watchpoints 0" ""
340 if ![runto_main] then {
341 fail "cannot run to main."
346 gdb_test_multiline "Sub-class a breakpoint" \
348 "class bp_eval (gdb.Breakpoint):" "" \
351 " def stop (self):" "" \
352 " self.count = self.count + 1" "" \
353 " self.inf_i = gdb.parse_and_eval(\"i\")" "" \
354 " if self.inf_i == 3:" "" \
359 gdb_test_multiline "Sub-class a second breakpoint" \
361 "class bp_also_eval (gdb.Breakpoint):" "" \
363 " def stop (self):" "" \
364 " self.count = self.count + 1" "" \
365 " if self.count == 9:" "" \
370 gdb_test_multiline "Sub-class a third breakpoint" \
372 "class basic (gdb.Breakpoint):" "" \
376 set bp_location2 [gdb_get_line_number "Break at multiply."]
377 set end_location [gdb_get_line_number "Break at end."]
378 gdb_py_test_silent_cmd "python eval_bp1 = bp_eval(\"$bp_location2\")" \
380 gdb_py_test_silent_cmd "python also_eval_bp1 = bp_also_eval(\"$bp_location2\")" \
382 gdb_py_test_silent_cmd "python never_eval_bp1 = bp_also_eval(\"$end_location\")" \
384 gdb_continue_to_breakpoint "Break at multiply, i==3" \
385 ".*$srcfile:$bp_location2.*"
387 "3" "Check inferior value matches python accounting"
388 gdb_test "python print (eval_bp1.inf_i)" \
389 "3" "Check python accounting matches inferior"
390 gdb_test "python print (also_eval_bp1.count)" "4" \
391 "Check non firing same-location also_eval_bp1 function was also called at each stop."
392 gdb_test "python print (eval_bp1.count)" "4" \
393 "Check non firing same-location eval_bp1 function was also called at each stop."
396 set cond_bp [gdb_get_line_number "Break at multiply."]
397 gdb_py_test_silent_cmd "python eval_bp1 = bp_eval(\"$cond_bp\")" \
399 set test_cond {cond $bpnum}
400 gdb_test "$test_cond \"foo==3\"" \
401 "Only one stop condition allowed. There is currently a Python.*" \
402 "Check you cannot add a CLI condition to a Python breakpoint that has defined stop"
403 gdb_py_test_silent_cmd "python eval_bp2 = basic(\"$cond_bp\")" \
405 gdb_py_test_silent_cmd "python eval_bp2.condition = \"1==1\"" \
407 gdb_test_multiline "Construct an eval function" \
409 "def stop_func ():" "" \
413 gdb_test "python eval_bp2.stop = stop_func" \
414 "RuntimeError: Only one stop condition allowed. There is currently a GDB.*" \
415 "assign stop function to a breakpoint that has a condition"
418 gdb_breakpoint [gdb_get_line_number "Break at multiply."]
419 gdb_py_test_silent_cmd "python check_eval = bp_eval(\"$bp_location2\")" \
421 gdb_test "python print (check_eval.count)" "0" \
422 "Test that evaluate function has not been yet executed (ie count = 0)"
423 gdb_continue_to_breakpoint "Break at multiply, count==1" \
424 ".*$srcfile:$bp_location2.*"
425 gdb_test "python print (check_eval.count)" "1" \
426 "Test that evaluate function is run when location also has normal bp"
428 gdb_test_multiline "Sub-class a watchpoint" \
430 "class wp_eval (gdb.Breakpoint):" "" \
431 " def stop (self):" "" \
432 " self.result = gdb.parse_and_eval(\"result\")" "" \
433 " if self.result == 788:" "" \
439 gdb_py_test_silent_cmd "python wp1 = wp_eval (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE)" \
441 gdb_test "continue" \
442 ".*\[Ww\]atchpoint.*result.*Old value =.*New value = 788.*" \
443 "Test watchpoint write"
444 gdb_test "python print (never_eval_bp1.count)" "0" \
445 "Check that this unrelated breakpoints eval function was never called."
448 proc_with_prefix test_bkpt_temporary { } {
449 global srcfile testfile hex decimal
451 # Start with a fresh gdb.
452 clean_restart ${testfile}
454 if ![runto_main] then {
455 fail "cannot run to main."
460 gdb_test_multiline "Sub-class and check temporary breakpoint" \
462 "class temp_bp (gdb.Breakpoint):" "" \
464 " def stop (self):" "" \
465 " self.count = self.count + 1" "" \
468 set ibp_location [gdb_get_line_number "Break at multiply."]
469 gdb_py_test_silent_cmd "python ibp = temp_bp(\"$ibp_location\", temporary=True)" \
470 "Set temporary breakpoint" 0
471 gdb_test "info breakpoints" \
472 "2.*breakpoint.*del.*py-breakpoint\.c:$ibp_location.*" \
473 "Check info breakpoints shows breakpoint with temporary status"
474 gdb_test "python print (ibp.location)" "py-breakpoint\.c:$ibp_location*" \
475 "Check temporary breakpoint location"
476 gdb_test "python print (ibp.temporary)" "True" \
477 "Check breakpoint temporary status"
478 gdb_continue_to_breakpoint "Break at multiply." \
479 ".*$srcfile:$ibp_location.*"
480 gdb_test "python print (ibp.count)" "1" \
481 "Check temporary stop callback executed before deletion."
482 gdb_test "python print (ibp.temporary)" "RuntimeError: Breakpoint 2 is invalid.*" \
483 "Check temporary breakpoint is deleted after being hit"
484 gdb_test "info breakpoints" "No breakpoints or watchpoints.*" \
485 "Check info breakpoints shows temporary breakpoint is deleted"
488 # Test address locations.
490 proc_with_prefix test_bkpt_address {} {
491 global gdb_prompt decimal srcfile
493 # Delete all breakpoints
496 gdb_test "python gdb.Breakpoint(\"*main\")" \
497 ".*Breakpoint ($decimal)+ at .*$srcfile, line ($decimal)+\."
499 gdb_py_test_silent_cmd \
500 "python main_loc = gdb.parse_and_eval(\"main\").address" \
501 "eval address of main" 0
503 # Python 2 vs 3 ... Check `int' first. If that fails, try `long'.
504 gdb_test_multiple "python main_addr = int(main_loc)" "int value of main" {
505 -re "Traceback.*$gdb_prompt $" {
506 gdb_test_no_output "python main_addr = long(main_loc)" \
509 -re "$gdb_prompt $" {
510 pass "int value of main"
514 # Include whitespace in the linespec to double-check proper
515 # grokking of argument to gdb.Breakpoint.
516 gdb_test "python gdb.Breakpoint(\" *{}\".format(str(main_addr)))" \
517 ".*Breakpoint ($decimal)+ at .*$srcfile, line ($decimal)+\."
520 proc_with_prefix test_bkpt_pending {} {
522 gdb_breakpoint "nosuchfunction" allow-pending
523 gdb_test "python print (gdb.breakpoints()\[0\].pending)" "True" \
524 "Check pending status of pending breakpoint"
527 # Helper proc to install an event listener for a given breakpoint
528 # event. NAME is the name of the event to listen for.
529 proc connect_event {name} {
530 set lambda "lambda x: note_event(\"$name\")"
531 gdb_test_no_output "python gdb.events.$name.connect($lambda)" \
532 "install $name event listener"
535 # Helper proc to check that the most recently emitted breakpoint event
537 proc check_last_event {expected} {
538 gdb_test "python print (last_bp_event)" $expected \
539 "check for $expected event"
542 proc_with_prefix test_bkpt_events {} {
545 clean_restart ${testfile}
547 gdb_test_multiline "Create event handler" \
549 "def note_event(arg):" "" \
550 " global last_bp_event" "" \
551 " last_bp_event = arg" "" \
553 gdb_test_no_output "python last_bp_event = None"
555 connect_event breakpoint_created
556 connect_event breakpoint_modified
557 connect_event breakpoint_deleted
559 gdb_breakpoint [gdb_get_line_number "Break at add."]
560 check_last_event breakpoint_created
561 gdb_test_no_output "disable 1"
562 check_last_event breakpoint_modified
563 gdb_test_no_output "delete 1"
564 check_last_event breakpoint_deleted
567 proc_with_prefix test_bkpt_explicit_loc {} {
568 global srcfile testfile
570 # Start with a fresh gdb.
571 clean_restart ${testfile}
573 if ![runto_main] then {
574 fail "cannot run to main."
580 set bp_location1 [gdb_get_line_number "Break at multiply."]
581 set bp_location2 [gdb_get_line_number "Break at add."]
583 gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (line=$bp_location1)" \
584 "set explicit breakpoint by line" 0
585 gdb_continue_to_breakpoint "break at multiply for explicit line" \
586 ".*Break at multiply.*"
588 gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (line=\"+1\")" \
589 "set explicit breakpoint by relative line" 0
590 gdb_continue_to_breakpoint "break at add for relative line" \
594 gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (line=\"-1\")" \
595 "set explicit breakpoint by relative negative line" 0
596 gdb_continue_to_breakpoint "break at multiply for negative line" \
597 ".*Break at multiply.*"
600 gdb_test "python bp1 = gdb.Breakpoint (line=bp1)" \
601 "RuntimeError: Line keyword should be an integer or a string.*" \
602 "set explicit breakpoint by invalid line type"
605 gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (function=\"add\")" \
606 "set explicit breakpoint by function" 0
607 gdb_continue_to_breakpoint "break at function add for function" \
608 ".*Break at function add.*"
611 gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (source=\"$srcfile\", function=\"add\")" \
612 "set explicit breakpoint by source file and function" 0
613 gdb_continue_to_breakpoint "break at function add for source and function" \
614 ".*Break at function add.*"
617 gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (source=\"$srcfile\", line=\"$bp_location2\")" \
618 "set explicit breakpoint by source file and line number" 0
619 gdb_continue_to_breakpoint "break at add for source and line" \
623 gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (\"-source $srcfile -line $bp_location2\")" \
624 "set explicit breakpoint by source file and line number in spec" 0
625 gdb_continue_to_breakpoint "break at add for source and line in spec" \
629 gdb_test "python bp1 = gdb.Breakpoint (source=\"$srcfile\")" \
630 "RuntimeError: Specifying a source must also include a line, label or function.*" \
631 "set invalid explicit breakpoint by source only"
633 gdb_test "python bp1 = gdb.Breakpoint (source=\"foo.c\", line=\"5\")" \
634 "No source file named foo.*" \
635 "set invalid explicit breakpoint by missing source and line"
636 gdb_test "python bp1 = gdb.Breakpoint (source=\"$srcfile\", line=\"900\")" \
637 "No line 900 in file \"$srcfile\".*" \
638 "set invalid explicit breakpoint by source and invalid line"
639 gdb_test "python bp1 = gdb.Breakpoint (function=\"blah\")" \
640 "Function \"blah\" not defined.*" \
641 "set invalid explicit breakpoint by missing function"
644 gdb_test "catch throw" "Catchpoint .* \\(throw\\)"
645 gdb_test "python print (gdb.breakpoints())" \
647 "catch throw is not a breakpoint"
650 proc_with_prefix test_bkpt_qualified {} {
651 global decimal hex testfile
653 # Start with a fresh gdb.
654 clean_restart ${testfile}
656 set one_location_re "Breakpoint $decimal at $hex:.*line $decimal."
657 set two_location_re "Breakpoint $decimal at $hex:.*2 locations."
659 if ![runto_main] then {
660 fail "cannot run to main."
664 # Test the default value of "qualified".
667 "python gdb.Breakpoint(\"multiply\")" \
669 "qualified implicitly false"
671 # Test qualified=False.
674 "python gdb.Breakpoint(\"multiply\", qualified=False)" \
678 # Test qualified=True.
681 "python gdb.Breakpoint(\"multiply\", qualified=True)" \
685 # Test qualified=True with an explicit function.
688 "python gdb.Breakpoint(function=\"multiply\", qualified=True)" \
690 "qualified true and explicit"
692 # Test qualified=False with an explicit function.
695 "python gdb.Breakpoint(function=\"multiply\", qualified=False)" \
697 "qualified false and explicit"
699 # Test -q in the spec string.
702 "python gdb.Breakpoint(\"-q multiply\")" \
706 # Test -q in the spec string with explicit location.
709 "python gdb.Breakpoint(\"-q -function multiply\")" \
711 "-q in spec string with explicit location"
713 # Test -q in the spec string and qualified=False (-q should win).
716 "python gdb.Breakpoint(\"-q multiply\", qualified=False)" \
718 "-q in spec string and qualified false"
721 proc_with_prefix test_bkpt_probe {} {
722 global decimal hex testfile srcfile
724 if { [prepare_for_testing "failed to prepare" ${testfile}-probes \
725 ${srcfile} {debug c++ additional_flags=-DUSE_PROBES}] } {
729 if ![runto_main] then {
730 fail "cannot run to main."
735 "python gdb.Breakpoint(\"-probe test:result_updated\")" \
736 "Breakpoint $decimal at $hex" \
737 "-probe in spec string"
740 proc_with_prefix test_catchpoints {} {
741 global srcfile testfile
742 global gdb_prompt decimal
744 # Start with a fresh gdb.
745 clean_restart ${testfile}
747 if ![runto_main] then {
748 fail "cannot run to main."
752 # Try to create a catchpoint, currently this isn't supported via
754 gdb_test "python gdb.Breakpoint (\"syscall\", type=gdb.BP_CATCHPOINT)" \
756 "gdb.error: BP_CATCHPOINT not supported" \
757 "Error while executing Python code\\."] \
758 "create a catchpoint via the api"
760 # Setup a catchpoint.
762 gdb_test_multiple "catch throw" "" {
763 -re "The feature \'catch throw\' is not supported.*\r\n$gdb_prompt $" {
764 unsupported "catch syscall isn't supported"
767 -re "Catchpoint ($decimal) \\(throw\\)\r\n$gdb_prompt $" {
768 set num $expect_out(1,string)
773 # Look for the catchpoint in the breakpoint list.
774 gdb_test_multiline "scan breakpoint list for BP_CATCHPOINT" \
776 "def scan_bp_list ():" "" \
777 " for b in gdb.breakpoints():" "" \
778 " if b.type == gdb.BP_CATCHPOINT:" "" \
779 " print(\"breakpoint #%d, type BP_CATCHPOINT\" % b.number)" "" \
781 gdb_test "python scan_bp_list ()" \
782 "breakpoint #${num}, type BP_CATCHPOINT" \
783 "scan breakpoint for BP_CATCHPOINT"
785 # Arrange to print something when GDB stops, then continue to the
786 # catchpoint and check we get the expected event.
787 gdb_test_multiline "setup stop event handler" \
789 "def stop_handler (event):" "" \
790 " if (isinstance (event, gdb.BreakpointEvent)" "" \
791 " and isinstance (event.breakpoint, gdb.Breakpoint)" "" \
792 " and event.breakpoint.type == gdb.BP_CATCHPOINT):" "" \
793 " print (\"Stopped at catchpoint event: %d\" % event.breakpoint.number)" "" \
795 "python gdb.events.stop.connect (stop_handler)" ""
796 gdb_test "continue" "Stopped at catchpoint event: ${num}"
801 test_bkpt_cond_and_cmds
803 test_hardware_breakpoints
812 test_bkpt_explicit_loc