gdb.python/python.exp: Update filename paths.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-breakpoint.exp
CommitLineData
7b6bb8da 1# Copyright (C) 2010, 2011 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
17# exposing values to Python.
18
19if $tracelevel then {
20 strace $tracelevel
21}
22
a2c09bd0
DE
23load_lib gdb-python.exp
24
adc36818
PM
25set testfile "py-breakpoint"
26set srcfile ${testfile}.c
27if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
28 return -1
29}
30
adc36818
PM
31# Skip all tests if Python scripting is not enabled.
32if { [skip_python_tests] } { continue }
33
34if ![runto_main] then {
35 fail "Cannot run to main."
36 return 0
37}
38
39global hex decimal
40
41# Initially there should be one breakpoint: main.
42
43gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0
44gdb_test "python print blist\[0\]" "<gdb.Breakpoint object at $hex>" "Check obj exists"
45gdb_test "python print blist\[0\].location" "main." "Check breakpoint location"
46
47gdb_breakpoint [gdb_get_line_number "Break at multiply."]
48gdb_continue_to_breakpoint "Break at multiply."
49
50# Check that the Python breakpoint code noted the addition of a
51# breakpoint "behind the scenes".
52gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0
53gdb_test "python print len(blist)" "2" "Check for two breakpoints"
54gdb_test "python print blist\[0\]" "<gdb.Breakpoint object at $hex>" "Check obj exists"
55gdb_test "python print blist\[0\].location" "main." "Check breakpoint location"
56gdb_test "python print blist\[1\]" "<gdb.Breakpoint object at $hex>" "Check obj exists"
57gdb_test "python print blist\[1\].location" "py-breakpoint\.c:41*" "Check breakpoint location"
58
59# Check hit and ignore counts.
60gdb_test "python print blist\[1\].hit_count" "1" "Check breakpoint hit count"
61gdb_py_test_silent_cmd "python blist\[1\].ignore_count = 4" "Set breakpoint hit count" 0
62gdb_continue_to_breakpoint "Break at multiply."
63gdb_test "python print blist\[1\].hit_count" "6" "Check breakpoint hit count"
8bfb830f 64gdb_test "print result" " = 545" "Check expected variable result after 6 iterations"
adc36818
PM
65
66# Test breakpoint is enabled and disabled correctly..
67gdb_breakpoint [gdb_get_line_number "Break at add."]
68gdb_continue_to_breakpoint "Break at add."
69gdb_test "python print blist\[1\].enabled" "True" "Check breakpoint enabled."
70gdb_py_test_silent_cmd "python blist\[1\].enabled = False" "Set breakpoint disabled." 0
71gdb_continue_to_breakpoint "Break at add."
72gdb_py_test_silent_cmd "python blist\[1\].enabled = True" "Set breakpoint enabled." 0
73gdb_continue_to_breakpoint "Break at multiply."
74
75# Test other getters and setters.
76gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0
77gdb_test "python print blist\[1\].thread" "None" "Check breakpoint thread"
78gdb_test "python print blist\[1\].type == gdb.BP_BREAKPOINT" "True" "Check breakpoint type"
79gdb_test "python print blist\[0\].number" "1" "Check breakpoint number"
80gdb_test "python print blist\[1\].number" "2" "Check breakpoint number"
81gdb_test "python print blist\[2\].number" "3" "Check breakpoint number"
82
94b6973e
PM
83# Start with a fresh gdb.
84clean_restart ${testfile}
85
86if ![runto_main] then {
87 fail "Cannot run to main."
88 return 0
89}
90
91# Test breakpoints are deleted correctly.
92set deltst_location [gdb_get_line_number "Break at multiply."]
93set end_location [gdb_get_line_number "Break at end."]
94gdb_py_test_silent_cmd "python dp1 = gdb.Breakpoint (\"$deltst_location\")" "Set breakpoint" 0
95gdb_breakpoint [gdb_get_line_number "Break at end."]
96gdb_py_test_silent_cmd "python del_list = gdb.breakpoints()" "Get Breakpoint List" 0
97gdb_test "python print len(del_list)" "3" "Number of breakpoints before delete"
98gdb_continue_to_breakpoint "Break at multiply." ".*/$srcfile:$deltst_location.*"
99gdb_py_test_silent_cmd "python dp1.delete()" "Delete Breakpoint" 0
100gdb_test "python print dp1.number" "RuntimeError: Breakpoint 2 is invalid.*" "Check breakpoint invalidated"
101gdb_py_test_silent_cmd "python del_list = gdb.breakpoints()" "Get Breakpoint List" 0
102gdb_test "python print len(del_list)" "2" "Number of breakpoints after delete"
103gdb_continue_to_breakpoint "Break at end." ".*/$srcfile:$end_location.*"
104
105
adc36818
PM
106# Start with a fresh gdb.
107clean_restart ${testfile}
108
109if ![runto_main] then {
110 fail "Cannot run to main."
111 return 0
112}
113
114# Test conditional setting.
115set bp_location1 [gdb_get_line_number "Break at multiply."]
116gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (\"$bp_location1\")" "Set breakpoint" 0
117gdb_continue_to_breakpoint "Break at multiply."
118gdb_py_test_silent_cmd "python bp1.condition = \"i == 5\"" "Set breakpoint" 0
119gdb_test "python print bp1.condition" "i == 5" "Test conditional has been set"
120gdb_continue_to_breakpoint "Break at multiply."
121gdb_test "print i" "5" "Test conditional breakpoint stopped after five iterations"
122gdb_py_test_silent_cmd "python bp1.condition = None" "Clear condition" 0
123gdb_test "python print bp1.condition" "None" "Test conditional read"
124gdb_continue_to_breakpoint "Break at multiply."
125gdb_test "print i" "6" "Test breakpoint stopped after six iterations"
126
127# Test commands.
128gdb_breakpoint [gdb_get_line_number "Break at add."]
129set test {commands $bpnum}
130gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } }
131set test {print "Command for breakpoint has been executed."}
132gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } }
133set test {print result}
134gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } }
135gdb_test "end"
136
137gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0
138gdb_test "python print blist\[len(blist)-1\].commands" "print \"Command for breakpoint has been executed.\".*print result"
139
84f4c1fe
PM
140# Start with a fresh gdb.
141clean_restart ${testfile}
142
143if ![runto_main] then {
144 fail "Cannot run to main."
145 return 0
146}
147
8bfb830f 148# Test invisible breakpoints.
84f4c1fe
PM
149delete_breakpoints
150set ibp_location [gdb_get_line_number "Break at multiply."]
151gdb_py_test_silent_cmd "python ibp = gdb.Breakpoint(\"$ibp_location\", internal=False)" "Set invisible breakpoint" 0
152gdb_py_test_silent_cmd "python ilist = gdb.breakpoints()" "Get Breakpoint List" 0
153gdb_test "python print ilist\[0\]" "<gdb.Breakpoint object at $hex>" "Check invisible bp obj exists"
154gdb_test "python print ilist\[0\].location" "py-breakpoint\.c:$ibp_location*" "Check breakpoint location"
155gdb_test "python print ilist\[0\].visible" "True" "Check breakpoint visibility"
156gdb_test "info breakpoints" "py-breakpoint\.c:$ibp_location.*" "Check info breakpoints shows visible breakpoints"
157delete_breakpoints
158gdb_py_test_silent_cmd "python ibp = gdb.Breakpoint(\"$ibp_location\", internal=True)" "Set invisible breakpoint" 0
159gdb_py_test_silent_cmd "python ilist = gdb.breakpoints()" "Get Breakpoint List" 0
160gdb_test "python print ilist\[0\]" "<gdb.Breakpoint object at $hex>" "Check invisible bp obj exists"
161gdb_test "python print ilist\[0\].location" "py-breakpoint\.c:$ibp_location*" "Check breakpoint location"
162gdb_test "python print ilist\[0\].visible" "False" "Check breakpoint visibility"
163gdb_test "info breakpoints" "No breakpoints or watchpoints.*" "Check info breakpoints does not show invisible breakpoints"
164gdb_test "maint info breakpoints" "py-breakpoint\.c:$ibp_location.*" "Check maint info breakpoints shows invisible breakpoints"
165
166
adc36818
PM
167# Watchpoints
168# Start with a fresh gdb.
169clean_restart ${testfile}
170
e0756905
UW
171# Disable hardware watchpoints if necessary.
172if [target_info exists gdb,no_hardware_watchpoints] {
173 gdb_test_no_output "set can-use-hw-watchpoints 0" ""
174}
175
adc36818
PM
176if ![runto_main] then {
177 fail "Cannot run to main."
178 return 0
179}
180
181gdb_py_test_silent_cmd "python wp1 = gdb.Breakpoint (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE )" "Set watchpoint" 0
468b1aa7 182gdb_test "continue" ".*\[Ww\]atchpoint.*result.*Old value = 0.*New value = 25.*main.*" "Test watchpoint write"
adc36818 183
84f4c1fe 184# Internal breakpoints.
adc36818 185
84f4c1fe
PM
186# Start with a fresh gdb.
187clean_restart ${testfile}
adc36818 188
84f4c1fe
PM
189if ![runto_main] then {
190 fail "Cannot run to main."
191 return 0
192}
193delete_breakpoints
194gdb_py_test_silent_cmd "python wp1 = gdb.Breakpoint (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE, internal=True )" "Set watchpoint" 0
195gdb_test "info breakpoints" "No breakpoints or watchpoints.*" "Check info breakpoints does not show invisible breakpoints"
b9b35694 196gdb_test "maint info breakpoints" ".*watchpoint.*result.*" "Check maint info breakpoints shows invisible breakpoints"
84f4c1fe 197gdb_test "continue" ".*\[Ww\]atchpoint.*result.*Old value = 0.*New value = 25.*" "Test watchpoint write"
7371cf6d
PM
198
199# Breakpoints that have an evaluation function.
200
201# Start with a fresh gdb.
202clean_restart ${testfile}
203
204if ![runto_main] then {
205 fail "Cannot run to main."
206 return 0
207}
208delete_breakpoints
209
210gdb_py_test_multiple "Sub-class a breakpoint" \
211 "python" "" \
212 "class bp_eval (gdb.Breakpoint):" "" \
213 " inf_i = 0" "" \
214 " count = 0" "" \
215 " def stop (self):" "" \
216 " self.count = self.count + 1" "" \
217 " self.inf_i = gdb.parse_and_eval(\"i\")" "" \
218 " if self.inf_i == 3:" "" \
219 " return True" "" \
220 " return False" "" \
221 "end" ""
222
223gdb_py_test_multiple "Sub-class a second breakpoint" \
224 "python" "" \
225 "class bp_also_eval (gdb.Breakpoint):" "" \
226 " count = 0" "" \
227 " def stop (self):" "" \
228 " self.count = self.count + 1" "" \
229 " if self.count == 9:" "" \
230 " return True" "" \
231 " return False" "" \
232 "end" ""
233
234gdb_py_test_multiple "Sub-class a third breakpoint" \
235 "python" "" \
236 "class basic (gdb.Breakpoint):" "" \
237 " count = 0" "" \
238 "end" ""
239
240set bp_location2 [gdb_get_line_number "Break at multiply."]
241set end_location [gdb_get_line_number "Break at end."]
242gdb_py_test_silent_cmd "python eval_bp1 = bp_eval(\"$bp_location2\")" "Set breakpoint" 0
243gdb_py_test_silent_cmd "python also_eval_bp1 = bp_also_eval(\"$bp_location2\")" "Set breakpoint" 0
244gdb_py_test_silent_cmd "python never_eval_bp1 = bp_also_eval(\"$end_location\")" "Set breakpoint" 0
245gdb_continue_to_breakpoint "Break at multiply." ".*/$srcfile:$bp_location2.*"
246gdb_test "print i" "3" "Check inferior value matches python accounting"
247gdb_test "python print eval_bp1.inf_i" "3" "Check python accounting matches inferior"
248gdb_test "python print also_eval_bp1.count" "4" \
249 "Check non firing same-location breakpoint eval function was also called at each stop."
250gdb_test "python print eval_bp1.count" "4" \
251 "Check non firing same-location breakpoint eval function was also called at each stop."
252
253delete_breakpoints
254set cond_bp [gdb_get_line_number "Break at multiply."]
255gdb_py_test_silent_cmd "python eval_bp1 = bp_eval(\"$cond_bp\")" "Set breakpoint" 0
256set test_cond {cond $bpnum}
257gdb_test "$test_cond \"foo==3\"" "Cannot set a condition where a Python.*" \
258 "Check you cannot add a CLI condition to a Python breakpoint that" \
259 "has defined stop"
260gdb_py_test_silent_cmd "python eval_bp2 = basic(\"$cond_bp\")" "Set breakpoint" 0
261gdb_py_test_silent_cmd "python eval_bp2.condition = \"1==1\"" "Set a condition" 0
262gdb_py_test_multiple "Construct an eval function" \
263 "python" "" \
264 "def stop_func ():" "" \
265 " return True" "" \
266 "end" ""
267
268gdb_test "python eval_bp2.stop = stop_func" \
269 "RuntimeError: Cannot set 'stop' method.*" \
270 "Assign stop function to a breakpoint that has a condition"
271
272delete_breakpoints
273gdb_breakpoint [gdb_get_line_number "Break at multiply."]
274gdb_py_test_silent_cmd "python check_eval = bp_eval(\"$bp_location2\")" "Set breakpoint" 0
275gdb_test "python print check_eval.count" "0" \
276 "Test that evaluate function has not been yet executed (ie count = 0)"
277gdb_continue_to_breakpoint "Break at multiply." ".*/$srcfile:$bp_location2.*"
278gdb_test "python print check_eval.count" "1" \
279 "Test that evaluate function is run when location also has normal bp"
280
281gdb_py_test_multiple "Sub-class a watchpoint" \
282 "python" "" \
283 "class wp_eval (gdb.Breakpoint):" "" \
284 " def stop (self):" "" \
285 " self.result = gdb.parse_and_eval(\"result\")" "" \
286 " if self.result == 788:" "" \
287 " return True" "" \
288 " return False" "" \
289 "end" ""
290
291delete_breakpoints
292gdb_py_test_silent_cmd "python wp1 = wp_eval (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE)" "Set watchpoint" 0
293gdb_test "continue" ".*\[Ww\]atchpoint.*result.*Old value =.*New value = 788.*" "Test watchpoint write"
294gdb_test "python print never_eval_bp1.count" "0" \
295 "Check that this unrelated breakpoints eval function was never called."
This page took 0.172878 seconds and 4 git commands to generate.