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