python: Add qualified parameter to gdb.Breakpoint
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-breakpoint.exp
1 # Copyright (C) 2010-2017 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_test "python print (blist\[len(blist)-1\].commands)" \
201 "print \"Command for breakpoint has been executed.\".*print result"
202 }
203
204 proc_with_prefix test_bkpt_invisible { } {
205 global srcfile testfile hex decimal
206
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."]
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\])" \
222 "<gdb.Breakpoint object at $hex>" "Check invisible bp obj exists 1"
223 gdb_test "python print (ilist\[0\].location)" \
224 "py-breakpoint\.c:$ibp_location*" "Check breakpoint location 1"
225 gdb_test "python print (ilist\[0\].visible)" \
226 "True" "Check breakpoint visibility 1"
227 gdb_test "info breakpoints" "py-breakpoint\.c:$ibp_location.*" \
228 "Check info breakpoints shows visible breakpoints"
229 delete_breakpoints
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\])" \
235 "<gdb.Breakpoint object at $hex>" "Check invisible bp obj exists 2"
236 gdb_test "python print (ilist\[0\].location)" \
237 "py-breakpoint\.c:$ibp_location*" "Check breakpoint location 2"
238 gdb_test "python print (ilist\[0\].visible)" \
239 "False" "Check breakpoint visibility 2"
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"
245 }
246
247 proc_with_prefix test_watchpoints { } {
248 global srcfile testfile hex decimal
249
250 # Start with a fresh gdb.
251 clean_restart ${testfile}
252
253 # Disable hardware watchpoints if necessary.
254 if [target_info exists gdb,no_hardware_watchpoints] {
255 gdb_test_no_output "set can-use-hw-watchpoints 0" ""
256 }
257
258 if ![runto_main] then {
259 fail "cannot run to main."
260 return 0
261 }
262
263 gdb_py_test_silent_cmd "python wp1 = gdb.Breakpoint (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE )" \
264 "Set watchpoint" 0
265 gdb_test "python print (wp1.pending)" "False"
266 gdb_test "continue" \
267 ".*\[Ww\]atchpoint.*result.*Old value = 0.*New value = 25.*main.*" \
268 "Test watchpoint write"
269 }
270
271 proc_with_prefix test_bkpt_internal { } {
272 global srcfile testfile hex decimal
273
274 # Start with a fresh gdb.
275 clean_restart ${testfile}
276
277 # Disable hardware watchpoints if necessary.
278 if [target_info exists gdb,no_hardware_watchpoints] {
279 gdb_test_no_output "set can-use-hw-watchpoints 0" ""
280 }
281 if ![runto_main] then {
282 fail "cannot run to main."
283 return 0
284 }
285 delete_breakpoints
286 gdb_py_test_silent_cmd "python wp1 = gdb.Breakpoint (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE, internal=True )" \
287 "Set watchpoint" 0
288 gdb_test "info breakpoints" \
289 "No breakpoints or watchpoints.*" \
290 "Check info breakpoints does not show invisible breakpoints"
291 gdb_test "maint info breakpoints" \
292 ".*watchpoint.*result.*" \
293 "Check maint info breakpoints shows invisible breakpoints"
294 gdb_test "continue" \
295 ".*\[Ww\]atchpoint.*result.*Old value = 0.*New value = 25.*" \
296 "Test watchpoint write"
297 }
298
299 proc_with_prefix test_bkpt_eval_funcs { } {
300 global srcfile testfile hex decimal
301
302 # Start with a fresh gdb.
303 clean_restart ${testfile}
304
305 # Disable hardware watchpoints if necessary.
306 if [target_info exists gdb,no_hardware_watchpoints] {
307 gdb_test_no_output "set can-use-hw-watchpoints 0" ""
308 }
309 if ![runto_main] then {
310 fail "cannot run to main."
311 return 0
312 }
313 delete_breakpoints
314
315 gdb_py_test_multiple "Sub-class a breakpoint" \
316 "python" "" \
317 "class bp_eval (gdb.Breakpoint):" "" \
318 " inf_i = 0" "" \
319 " count = 0" "" \
320 " def stop (self):" "" \
321 " self.count = self.count + 1" "" \
322 " self.inf_i = gdb.parse_and_eval(\"i\")" "" \
323 " if self.inf_i == 3:" "" \
324 " return True" "" \
325 " return False" "" \
326 "end" ""
327
328 gdb_py_test_multiple "Sub-class a second breakpoint" \
329 "python" "" \
330 "class bp_also_eval (gdb.Breakpoint):" "" \
331 " count = 0" "" \
332 " def stop (self):" "" \
333 " self.count = self.count + 1" "" \
334 " if self.count == 9:" "" \
335 " return True" "" \
336 " return False" "" \
337 "end" ""
338
339 gdb_py_test_multiple "Sub-class a third breakpoint" \
340 "python" "" \
341 "class basic (gdb.Breakpoint):" "" \
342 " count = 0" "" \
343 "end" ""
344
345 set bp_location2 [gdb_get_line_number "Break at multiply."]
346 set end_location [gdb_get_line_number "Break at end."]
347 gdb_py_test_silent_cmd "python eval_bp1 = bp_eval(\"$bp_location2\")" \
348 "Set breakpoint" 0
349 gdb_py_test_silent_cmd "python also_eval_bp1 = bp_also_eval(\"$bp_location2\")" \
350 "Set breakpoint" 0
351 gdb_py_test_silent_cmd "python never_eval_bp1 = bp_also_eval(\"$end_location\")" \
352 "Set breakpoint" 0
353 gdb_continue_to_breakpoint "Break at multiply, i==3" \
354 ".*$srcfile:$bp_location2.*"
355 gdb_test "print i" \
356 "3" "Check inferior value matches python accounting"
357 gdb_test "python print (eval_bp1.inf_i)" \
358 "3" "Check python accounting matches inferior"
359 gdb_test "python print (also_eval_bp1.count)" "4" \
360 "Check non firing same-location also_eval_bp1 function was also called at each stop."
361 gdb_test "python print (eval_bp1.count)" "4" \
362 "Check non firing same-location eval_bp1 function was also called at each stop."
363
364 delete_breakpoints
365 set cond_bp [gdb_get_line_number "Break at multiply."]
366 gdb_py_test_silent_cmd "python eval_bp1 = bp_eval(\"$cond_bp\")" \
367 "Set breakpoint" 0
368 set test_cond {cond $bpnum}
369 gdb_test "$test_cond \"foo==3\"" \
370 "Only one stop condition allowed. There is currently a Python.*" \
371 "Check you cannot add a CLI condition to a Python breakpoint that has defined stop"
372 gdb_py_test_silent_cmd "python eval_bp2 = basic(\"$cond_bp\")" \
373 "Set breakpoint" 0
374 gdb_py_test_silent_cmd "python eval_bp2.condition = \"1==1\"" \
375 "Set a condition" 0
376 gdb_py_test_multiple "Construct an eval function" \
377 "python" "" \
378 "def stop_func ():" "" \
379 " return True" "" \
380 "end" ""
381
382 gdb_test "python eval_bp2.stop = stop_func" \
383 "RuntimeError: Only one stop condition allowed. There is currently a GDB.*" \
384 "assign stop function to a breakpoint that has a condition"
385
386 delete_breakpoints
387 gdb_breakpoint [gdb_get_line_number "Break at multiply."]
388 gdb_py_test_silent_cmd "python check_eval = bp_eval(\"$bp_location2\")" \
389 "Set breakpoint" 0
390 gdb_test "python print (check_eval.count)" "0" \
391 "Test that evaluate function has not been yet executed (ie count = 0)"
392 gdb_continue_to_breakpoint "Break at multiply, count==1" \
393 ".*$srcfile:$bp_location2.*"
394 gdb_test "python print (check_eval.count)" "1" \
395 "Test that evaluate function is run when location also has normal bp"
396
397 gdb_py_test_multiple "Sub-class a watchpoint" \
398 "python" "" \
399 "class wp_eval (gdb.Breakpoint):" "" \
400 " def stop (self):" "" \
401 " self.result = gdb.parse_and_eval(\"result\")" "" \
402 " if self.result == 788:" "" \
403 " return True" "" \
404 " return False" "" \
405 "end" ""
406
407 delete_breakpoints
408 gdb_py_test_silent_cmd "python wp1 = wp_eval (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE)" \
409 "Set watchpoint" 0
410 gdb_test "continue" \
411 ".*\[Ww\]atchpoint.*result.*Old value =.*New value = 788.*" \
412 "Test watchpoint write"
413 gdb_test "python print (never_eval_bp1.count)" "0" \
414 "Check that this unrelated breakpoints eval function was never called."
415 }
416
417 proc_with_prefix test_bkpt_temporary { } {
418 global srcfile testfile hex decimal
419
420 # Start with a fresh gdb.
421 clean_restart ${testfile}
422
423 if ![runto_main] then {
424 fail "cannot run to main."
425 return 0
426 }
427 delete_breakpoints
428
429 gdb_py_test_multiple "Sub-class and check temporary breakpoint" \
430 "python" "" \
431 "class temp_bp (gdb.Breakpoint):" "" \
432 " count = 0" "" \
433 " def stop (self):" "" \
434 " self.count = self.count + 1" "" \
435 " return True" "" \
436 "end" ""
437 set ibp_location [gdb_get_line_number "Break at multiply."]
438 gdb_py_test_silent_cmd "python ibp = temp_bp(\"$ibp_location\", temporary=True)" \
439 "Set temporary breakpoint" 0
440 gdb_test "info breakpoints" \
441 "2.*breakpoint.*del.*py-breakpoint\.c:$ibp_location.*" \
442 "Check info breakpoints shows breakpoint with temporary status"
443 gdb_test "python print (ibp.location)" "py-breakpoint\.c:$ibp_location*" \
444 "Check temporary breakpoint location"
445 gdb_test "python print (ibp.temporary)" "True" \
446 "Check breakpoint temporary status"
447 gdb_continue_to_breakpoint "Break at multiply." \
448 ".*$srcfile:$ibp_location.*"
449 gdb_test "python print (ibp.count)" "1" \
450 "Check temporary stop callback executed before deletion."
451 gdb_test "python print (ibp.temporary)" "RuntimeError: Breakpoint 2 is invalid.*" \
452 "Check temporary breakpoint is deleted after being hit"
453 gdb_test "info breakpoints" "No breakpoints or watchpoints.*" \
454 "Check info breakpoints shows temporary breakpoint is deleted"
455 }
456
457 # Test address locations.
458
459 proc_with_prefix test_bkpt_address {} {
460 global gdb_prompt decimal srcfile
461
462 # Delete all breakpoints
463 delete_breakpoints
464
465 gdb_test "python gdb.Breakpoint(\"*main\")" \
466 ".*Breakpoint ($decimal)+ at .*$srcfile, line ($decimal)+\."
467
468 gdb_py_test_silent_cmd \
469 "python main_loc = gdb.parse_and_eval(\"main\").address" \
470 "eval address of main" 0
471
472 # Python 2 vs 3 ... Check `int' first. If that fails, try `long'.
473 gdb_test_multiple "python main_addr = int(main_loc)" "int value of main" {
474 -re "Traceback.*$gdb_prompt $" {
475 gdb_test_no_output "python main_addr = long(main_loc)" \
476 "long value of main"
477 }
478 -re "$gdb_prompt $" {
479 pass "int value of main"
480 }
481 }
482
483 # Include whitespace in the linespec to double-check proper
484 # grokking of argument to gdb.Breakpoint.
485 gdb_test "python gdb.Breakpoint(\" *{}\".format(str(main_addr)))" \
486 ".*Breakpoint ($decimal)+ at .*$srcfile, line ($decimal)+\."
487 }
488
489 proc_with_prefix test_bkpt_pending {} {
490 delete_breakpoints
491 gdb_breakpoint "nosuchfunction" allow-pending
492 gdb_test "python print (gdb.breakpoints()\[0\].pending)" "True" \
493 "Check pending status of pending breakpoint"
494 }
495
496 # Helper proc to install an event listener for a given breakpoint
497 # event. NAME is the name of the event to listen for.
498 proc connect_event {name} {
499 set lambda "lambda x: note_event(\"$name\")"
500 gdb_test_no_output "python gdb.events.$name.connect($lambda)" \
501 "install $name event listener"
502 }
503
504 # Helper proc to check that the most recently emitted breakpoint event
505 # is EXPECTED.
506 proc check_last_event {expected} {
507 gdb_test "python print (last_bp_event)" $expected \
508 "check for $expected event"
509 }
510
511 proc_with_prefix test_bkpt_events {} {
512 global testfile
513
514 clean_restart ${testfile}
515
516 gdb_py_test_multiple "Create event handler" \
517 "python" "" \
518 "def note_event(arg):" "" \
519 " global last_bp_event" "" \
520 " last_bp_event = arg" "" \
521 "end" ""
522 gdb_test_no_output "python last_bp_event = None"
523
524 connect_event breakpoint_created
525 connect_event breakpoint_modified
526 connect_event breakpoint_deleted
527
528 gdb_breakpoint [gdb_get_line_number "Break at add."]
529 check_last_event breakpoint_created
530 gdb_test_no_output "disable 1"
531 check_last_event breakpoint_modified
532 gdb_test_no_output "delete 1"
533 check_last_event breakpoint_deleted
534 }
535
536 proc_with_prefix test_bkpt_explicit_loc {} {
537 global srcfile testfile
538
539 # Start with a fresh gdb.
540 clean_restart ${testfile}
541
542 if ![runto_main] then {
543 fail "cannot run to main."
544 return 0
545 }
546
547 delete_breakpoints
548
549 set bp_location1 [gdb_get_line_number "Break at multiply."]
550 set bp_location2 [gdb_get_line_number "Break at add."]
551
552 gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (line=$bp_location1)" \
553 "set explicit breakpoint by line" 0
554 gdb_continue_to_breakpoint "break at multiply for explicit line" \
555 ".*Break at multiply.*"
556
557 gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (line=\"+1\")" \
558 "set explicit breakpoint by relative line" 0
559 gdb_continue_to_breakpoint "break at add for relative line" \
560 ".*Break at add.*"
561
562 delete_breakpoints
563 gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (line=\"-1\")" \
564 "set explicit breakpoint by relative negative line" 0
565 gdb_continue_to_breakpoint "break at multiply for negative line" \
566 ".*Break at multiply.*"
567
568 delete_breakpoints
569 gdb_test "python bp1 = gdb.Breakpoint (line=bp1)" \
570 "RuntimeError: Line keyword should be an integer or a string.*" \
571 "set explicit breakpoint by invalid line type"
572
573 delete_breakpoints
574 gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (function=\"add\")" \
575 "set explicit breakpoint by function" 0
576 gdb_continue_to_breakpoint "break at function add for function" \
577 ".*Break at function add.*"
578
579 delete_breakpoints
580 gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (source=\"$srcfile\", function=\"add\")" \
581 "set explicit breakpoint by source file and function" 0
582 gdb_continue_to_breakpoint "break at function add for source and function" \
583 ".*Break at function add.*"
584
585 delete_breakpoints
586 gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (source=\"$srcfile\", line=\"$bp_location2\")" \
587 "set explicit breakpoint by source file and line number" 0
588 gdb_continue_to_breakpoint "break at add for source and line" \
589 ".*Break at add.*"
590
591 delete_breakpoints
592 gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (\"-source $srcfile -line $bp_location2\")" \
593 "set explicit breakpoint by source file and line number in spec" 0
594 gdb_continue_to_breakpoint "break at add for source and line in spec" \
595 ".*Break at add.*"
596
597 delete_breakpoints
598 gdb_test "python bp1 = gdb.Breakpoint (source=\"$srcfile\")" \
599 "RuntimeError: Specifying a source must also include a line, label or function.*" \
600 "set invalid explicit breakpoint by source only"
601
602 gdb_test "python bp1 = gdb.Breakpoint (source=\"foo.c\", line=\"5\")" \
603 "No source file named foo.*" \
604 "set invalid explicit breakpoint by missing source and line"
605 gdb_test "python bp1 = gdb.Breakpoint (source=\"$srcfile\", line=\"900\")" \
606 "No line 900 in file \"$srcfile\".*" \
607 "set invalid explicit breakpoint by source and invalid line"
608 gdb_test "python bp1 = gdb.Breakpoint (function=\"blah\")" \
609 "Function \"blah\" not defined.*" \
610 "set invalid explicit breakpoint by missing function"
611 }
612
613 proc_with_prefix test_bkpt_qualified {} {
614 global decimal hex testfile
615
616 # Start with a fresh gdb.
617 clean_restart ${testfile}
618
619 set one_location_re "Breakpoint $decimal at $hex:.*line $decimal."
620 set two_location_re "Breakpoint $decimal at $hex:.*2 locations."
621
622 if ![runto_main] then {
623 fail "cannot run to main."
624 return 0
625 }
626
627 # Test the default value of "qualified".
628 delete_breakpoints
629 gdb_test \
630 "python gdb.Breakpoint(\"multiply\")" \
631 $two_location_re \
632 "qualified implicitly false"
633
634 # Test qualified=False.
635 delete_breakpoints
636 gdb_test \
637 "python gdb.Breakpoint(\"multiply\", qualified=False)" \
638 $two_location_re \
639 "qualified false"
640
641 # Test qualified=True.
642 delete_breakpoints
643 gdb_test \
644 "python gdb.Breakpoint(\"multiply\", qualified=True)" \
645 $one_location_re \
646 "qualified true"
647
648 # Test qualified=True with an explicit function.
649 delete_breakpoints
650 gdb_test \
651 "python gdb.Breakpoint(function=\"multiply\", qualified=True)" \
652 $one_location_re \
653 "qualified true and explicit"
654
655 # Test qualified=False with an explicit function.
656 delete_breakpoints
657 gdb_test \
658 "python gdb.Breakpoint(function=\"multiply\", qualified=False)" \
659 $two_location_re \
660 "qualified false and explicit"
661
662 # Test -q in the spec string.
663 delete_breakpoints
664 gdb_test \
665 "python gdb.Breakpoint(\"-q multiply\")" \
666 $one_location_re \
667 "-q in spec string"
668
669 # Test -q in the spec string with explicit location.
670 delete_breakpoints
671 gdb_test \
672 "python gdb.Breakpoint(\"-q -function multiply\")" \
673 $one_location_re \
674 "-q in spec string with explicit location"
675
676 # Test -q in the spec string and qualified=False (-q should win).
677 delete_breakpoints
678 gdb_test \
679 "python gdb.Breakpoint(\"-q multiply\", qualified=False)" \
680 $one_location_re \
681 "-q in spec string and qualified false"
682 }
683
684 test_bkpt_basic
685 test_bkpt_deletion
686 test_bkpt_cond_and_cmds
687 test_bkpt_invisible
688 test_watchpoints
689 test_bkpt_internal
690 test_bkpt_eval_funcs
691 test_bkpt_temporary
692 test_bkpt_address
693 test_bkpt_pending
694 test_bkpt_events
695 test_bkpt_explicit_loc
696 test_bkpt_qualified
This page took 0.085036 seconds and 4 git commands to generate.