]>
Commit | Line | Data |
---|---|---|
e2882c85 | 1 | # Copyright 1999-2018 Free Software Foundation, Inc. |
fb40c209 AC |
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 | |
e22f8b7c | 5 | # the Free Software Foundation; either version 3 of the License, or |
fb40c209 | 6 | # (at your option) any later version. |
e22f8b7c | 7 | # |
fb40c209 AC |
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. | |
e22f8b7c | 12 | # |
fb40c209 | 13 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
fb40c209 | 15 | |
17282693 | 16 | # Test Machine interface (MI) operations |
fb40c209 | 17 | # |
17282693 | 18 | # Test MI breakpoint commands. |
fb40c209 | 19 | # |
17282693 PA |
20 | # The goal is not to test gdb functionality, which is done by other |
21 | # tests, but to verify the correct output response to MI operations. | |
fb40c209 AC |
22 | |
23 | load_lib mi-support.exp | |
b30bf9ee | 24 | set MIFLAGS "-i=mi" |
fb40c209 | 25 | |
298a9cf0 TT |
26 | standard_testfile basics.c |
27 | ||
9357e021 | 28 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { |
5b362f04 | 29 | untested "failed to compile" |
b60f0898 | 30 | return -1 |
fb40c209 AC |
31 | } |
32 | ||
deea8bb0 MC |
33 | # Locate line numbers in basics.c. |
34 | set line_callee4_head [gdb_get_line_number "callee4 ("] | |
35 | set line_callee4_body [expr $line_callee4_head + 2] | |
36 | set line_callee3_head [gdb_get_line_number "callee3 ("] | |
37 | set line_callee3_body [expr $line_callee3_head + 2] | |
38 | set line_callee2_head [gdb_get_line_number "callee2 ("] | |
39 | set line_callee2_body [expr $line_callee2_head + 2] | |
40 | set line_callee1_head [gdb_get_line_number "callee1 ("] | |
41 | set line_callee1_body [expr $line_callee1_head + 2] | |
42 | set line_main_head [gdb_get_line_number "main ("] | |
43 | set line_main_body [expr $line_main_head + 2] | |
dd322c54 JK |
44 | set line_callme_head [gdb_get_line_number "callme ("] |
45 | set line_callme_body [expr $line_callme_head + 2] | |
deea8bb0 | 46 | |
38fcd64c DJ |
47 | set fullname "fullname=\"${fullname_syntax}${srcfile}\"" |
48 | ||
fb40c209 | 49 | proc test_tbreak_creation_and_listing {} { |
fb40c209 | 50 | global srcfile |
5da151d4 | 51 | global line_callee4_head |
a9e40818 | 52 | global line_callee4_body |
5da151d4 | 53 | global line_callee3_head |
a9e40818 | 54 | global line_callee3_body |
5da151d4 KS |
55 | global line_callee2_body |
56 | global line_main_body | |
fb40c209 AC |
57 | |
58 | # Insert some breakpoints and list them | |
59 | # Also, disable some so they do not interfere with other tests | |
60 | # Tests: | |
61 | # -break-insert -t main | |
62 | # -break-insert -t basics.c:callee2 | |
deea8bb0 MC |
63 | # -break-insert -t basics.c:$line_callee3_head |
64 | # -break-insert -t srcfile:$line_callee4_head | |
fb40c209 AC |
65 | # -break-list |
66 | ||
4b48d439 KS |
67 | set bps {} |
68 | lappend bps [mi_create_breakpoint "-t main" "break-insert -t operation" \ | |
69 | -number 1 -disp del -func main -file ".*basics.c" \ | |
70 | -line $line_main_body] | |
71 | ||
72 | lappend bps [mi_create_breakpoint "-t basics.c:callee2" \ | |
73 | "insert temp breakpoint at basics.c:callee2" \ | |
74 | -number 2 -disp del -func callee2 -file ".*basics.c" \ | |
75 | -line $line_callee2_body] | |
76 | ||
77 | lappend bps [mi_create_breakpoint "-t basics.c:$line_callee3_head" \ | |
78 | "insert temp breakpoint at basics.c:\$line_callee3_head" \ | |
79 | -number 3 -disp del -func callee3 -file ".*basics.c" \ | |
a9e40818 | 80 | -line $line_callee3_body] |
4b48d439 KS |
81 | |
82 | # Getting the quoting right is tricky. | |
83 | # That is "\"<file>\":$line_callee4_head" | |
84 | lappend bps [mi_create_breakpoint \ | |
85 | "-t \"\\\"${srcfile}\\\":$line_callee4_head\"" \ | |
86 | "insert temp breakpoint at \"<fullfilename>\":\$line_callee4_head" \ | |
87 | -number 4 -disp del -func callee4 -file ".*basics.c" \ | |
a9e40818 | 88 | -line $line_callee4_body] |
fb40c209 AC |
89 | |
90 | mi_gdb_test "666-break-list" \ | |
4b48d439 KS |
91 | "666\\\^done,[mi_make_breakpoint_table $bps]" \ |
92 | "list of breakpoints" | |
fb40c209 AC |
93 | |
94 | mi_gdb_test "777-break-delete" \ | |
95 | "777\\^done" \ | |
96 | "delete temp breakpoints" | |
97 | } | |
98 | ||
99 | proc test_rbreak_creation_and_listing {} { | |
5da151d4 KS |
100 | global line_callee4_body |
101 | global line_callee3_body | |
102 | global line_callee2_body | |
103 | global line_callee1_body | |
104 | global line_main_body | |
fb40c209 AC |
105 | |
106 | # Insert some breakpoints and list them | |
107 | # Also, disable some so they do not interfere with other tests | |
108 | # Tests: | |
109 | # -break-insert -r main | |
110 | # -break-insert -r callee2 | |
111 | # -break-insert -r callee | |
112 | # -break-insert -r .*llee | |
113 | # -break-list | |
114 | ||
18b5ff1b | 115 | setup_kfail "*-*-*" mi/14270 |
4b48d439 KS |
116 | set bps {} |
117 | lappend bps [mi_make_breakpoint -number 5 -file ".*basics.c" \ | |
118 | -line $line_main_body] | |
fb40c209 | 119 | mi_gdb_test "122-break-insert -r main" \ |
4b48d439 KS |
120 | "122\\^done,[lindex $bps end]" \ |
121 | "break-insert -r operation" | |
fb40c209 | 122 | |
18b5ff1b | 123 | setup_kfail "*-*-*" mi/14270 |
4b48d439 KS |
124 | lappend bps [mi_make_breakpoint -number 6 -file ".*basics.c" \ |
125 | -line $line_callee2_body] | |
fb40c209 | 126 | mi_gdb_test "133-break-insert -r callee2" \ |
4b48d439 KS |
127 | "133\\^done,[lindex $bps end]" \ |
128 | "insert breakpoint with regexp callee2" | |
fb40c209 | 129 | |
18b5ff1b | 130 | setup_kfail "*-*-*" mi/14270 |
4b48d439 KS |
131 | set start [llength $bps] |
132 | lappend bps [mi_make_breakpoint -number 7 -file ".*basics.c" \ | |
133 | -line $line_callee1_body] | |
134 | lappend bps [mi_make_breakpoint -number 8 -file ".*basics.c" \ | |
135 | -line $line_callee2_body] | |
136 | lappend bps [mi_make_breakpoint -number 9 -file ".*basics.c" \ | |
137 | -line $line_callee3_body] | |
138 | lappend bps [mi_make_breakpoint -number 10 -file ".*basics.c" \ | |
139 | -line $line_callee4_body] | |
fb40c209 | 140 | mi_gdb_test "144-break-insert -r callee" \ |
4b48d439 KS |
141 | "144\\^done,[join [lrange $bps $start end] ,]" \ |
142 | "insert breakpoint with regexp callee" | |
fb40c209 | 143 | |
18b5ff1b | 144 | setup_kfail "*-*-*" mi/14270 |
4b48d439 KS |
145 | set start [llength $bps] |
146 | lappend bps [mi_make_breakpoint -number 11 -file ".*basics.c" \ | |
147 | -line $line_callee1_body] | |
148 | lappend bps [mi_make_breakpoint -number 12 -file ".*basics.c" \ | |
149 | -line $line_callee2_body] | |
150 | lappend bps [mi_make_breakpoint -number 13 -file ".*basics.c" \ | |
151 | -line $line_callee3_body] | |
152 | lappend bps [mi_make_breakpoint -number 14 -file ".*basics.c" \ | |
153 | -line $line_callee4_body] | |
fb40c209 | 154 | mi_gdb_test "155-break-insert -r \.\*llee" \ |
4b48d439 KS |
155 | "155\\^done,[join [lrange $bps $start end] ,]" \ |
156 | "insert breakpoint with regexp .*llee" | |
fb40c209 | 157 | |
18b5ff1b | 158 | setup_kfail "*-*-*" mi/14270 |
fb40c209 | 159 | mi_gdb_test "166-break-list" \ |
4b48d439 KS |
160 | "166\\^done,[mi_make_breakpoint_table $bps]" \ |
161 | "list of breakpoints" | |
fb40c209 AC |
162 | |
163 | mi_gdb_test "177-break-delete" \ | |
164 | "177\\^done" \ | |
165 | "delete temp breakpoints" | |
166 | } | |
167 | ||
558a9d82 YQ |
168 | proc test_abreak_creation {} { |
169 | mi_create_varobj tpnum \$tpnum "create local variable tpnum" | |
170 | # Test that $tpnum is not set before creating a tracepoint. | |
171 | mi_gdb_test "521-var-evaluate-expression tpnum" \ | |
172 | "521\\^done,value=\"void\"" "eval tpnum before tracepoint" | |
173 | ||
174 | mi_gdb_test "522-break-insert -a main" \ | |
4b48d439 | 175 | "522\\^done,[mi_make_breakpoint -number 10 -type tracepoint]" \ |
558a9d82 YQ |
176 | "break-insert -a operation" |
177 | ||
178 | mi_gdb_test "523-var-update tpnum" \ | |
179 | "523\\^done,changelist=\\\[\{name=\"tpnum\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\}\\\]" \ | |
180 | "update tpnum" | |
181 | # Test that $tpnum is updated after creating a tracepoint. | |
182 | mi_gdb_test "524-var-evaluate-expression tpnum" \ | |
183 | "524\\^done,value=\"10\"" "eval tpnum after tracepoint" | |
184 | } | |
185 | ||
60c46647 | 186 | proc test_ignore_count {} { |
dd322c54 | 187 | global line_callme_body |
60c46647 VP |
188 | |
189 | mi_gdb_test "-break-insert -i 1 callme" \ | |
4b48d439 | 190 | "\\^done,[mi_make_breakpoint -ignore 1]" \ |
60c46647 VP |
191 | "insert breakpoint with ignore count at callme" |
192 | ||
193 | mi_run_cmd | |
194 | ||
dd322c54 | 195 | mi_expect_stop "breakpoint-hit" "callme" "\{name=\"i\",value=\"2\"\}" ".*basics.c" $line_callme_body \ |
83408de7 | 196 | {"" "disp=\"keep\"" } "run to breakpoint with ignore count" |
60c46647 VP |
197 | } |
198 | ||
723a2275 | 199 | proc test_error {} { |
723a2275 VP |
200 | mi_gdb_test "-break-insert function_that_does_not_exist" \ |
201 | ".*\\^error,msg=\"Function \\\\\"function_that_does_not_exist\\\\\" not defined.\"" \ | |
202 | "breakpoint at nonexistent function" | |
98deb0da VP |
203 | |
204 | # We used to have a bug whereby -break-insert that failed would not | |
205 | # clear some event hooks. As result, whenever we evaluate expression | |
206 | # containing function call, the internal breakpoint created to handle | |
207 | # function call would be reported, messing up MI output. | |
208 | mi_gdb_test "-var-create V * return_1()" \ | |
0cc7d26f | 209 | "\\^done,name=\"V\",numchild=\"0\",value=\"1\",type=\"int\",has_more=\"0\"" \ |
98deb0da VP |
210 | "create varobj for function call" |
211 | ||
212 | mi_gdb_test "-var-update *" \ | |
213 | "\\^done,changelist=\\\[\\\]" \ | |
214 | "update varobj for function call" | |
f6de8ec2 PA |
215 | |
216 | # Try setting breakpoints with garbage after the location. | |
217 | ||
218 | # "if" only works in the CLI. It's not supposed to be accepted by | |
219 | # MI. The way to specify a condition is with -c. | |
220 | mi_gdb_test "-break-insert \"callme if i < 4\"" \ | |
221 | ".*\\^error,msg=\"Garbage 'if i < 4' at end of location\"" \ | |
222 | "breakpoint with garbage after location" | |
223 | ||
224 | mi_gdb_test "-break-insert -c i==4 \"callme if i < 4\"" \ | |
225 | ".*\\^error,msg=\"Garbage 'if i < 4' at end of location\"" \ | |
226 | "conditional breakpoint with garbage after location" | |
723a2275 VP |
227 | } |
228 | ||
41447f92 | 229 | proc test_disabled_creation {} { |
41447f92 VP |
230 | global line_callee2_body |
231 | ||
4b48d439 KS |
232 | set bp [mi_make_breakpoint -number 6 -type breakpoint -disp keep \ |
233 | -enabled n -func callee2 -file ".*basics.c" \ | |
234 | -line $line_callee2_body] | |
41447f92 | 235 | mi_gdb_test "-break-insert -d basics.c:callee2" \ |
4b48d439 KS |
236 | "\\^done,$bp" \ |
237 | "test disabled creation" | |
41447f92 VP |
238 | |
239 | mi_gdb_test "-break-delete" \ | |
240 | "\\^done" \ | |
241 | "test disabled creation: cleanup" | |
242 | } | |
243 | ||
48cb2d85 VP |
244 | proc test_breakpoint_commands {} { |
245 | global line_callee2_body | |
48cb2d85 | 246 | |
4b48d439 KS |
247 | set bp_no_script \ |
248 | [mi_create_breakpoint "basics.c:callee2" \ | |
249 | "breakpoint commands: insert breakpoint at basics.c:callee2" \ | |
250 | -number 7 -disp keep -func callee2 -file ".*basics.c" \ | |
251 | -line $line_callee2_body] | |
48cb2d85 VP |
252 | |
253 | mi_gdb_test "-break-commands 7 \"print 10\" \"continue\"" \ | |
254 | "\\^done" \ | |
255 | "breakpoint commands: set commands" | |
256 | ||
4b48d439 KS |
257 | # Rebuild the breakpoint regexp instead of using the one returned |
258 | # by mi_create_breakpoint. Only in -break-info is the actual script | |
259 | # seen. | |
260 | set bp_script [mi_make_breakpoint -number 7 -disp keep -func callee2 \ | |
261 | -file ".*basics.c" -line $line_callee2_body \ | |
262 | -script {\{"print 10","continue"\}}] | |
48cb2d85 | 263 | mi_gdb_test "-break-info 7" \ |
4b48d439 | 264 | "\\^done,[mi_make_breakpoint_table [list $bp_script]]" \ |
48cb2d85 VP |
265 | "breakpoint commands: check that commands are set" |
266 | ||
267 | mi_gdb_test "-break-commands 7" \ | |
268 | "\\^done" \ | |
269 | "breakpoint commands: clear commands" | |
270 | ||
4b48d439 KS |
271 | mi_gdb_test "-break-info" \ |
272 | "\\^done,[mi_make_breakpoint_table [list $bp_no_script]]" \ | |
48cb2d85 | 273 | "breakpoint commands: check that commands are cleared" |
5d4e2b76 VP |
274 | |
275 | mi_run_to_main | |
276 | ||
4b48d439 KS |
277 | mi_create_breakpoint "basics.c:callee2" \ |
278 | "breakpoint commands: insert breakpoint at basics.c:callee2, again" \ | |
279 | -number 9 -disp keep -func callee2 -file ".*basics.c" \ | |
280 | -line $line_callee2_body | |
5d4e2b76 | 281 | |
3a87ae65 | 282 | mi_gdb_test "-break-commands 9 \"bt\" \"set \$i=0\" \"while \$i<10\" \"print \$i\" \"set \$i=\$i+1\" \"end\" \"continue\" " \ |
5d4e2b76 VP |
283 | "\\^done" \ |
284 | "breakpoint commands: set commands" | |
285 | ||
4a07b7da PA |
286 | mi_send_resuming_command "exec-continue" "breakpoint commands: continue" |
287 | ||
ef274d26 PA |
288 | |
289 | # The breakpoint command's output is always sent to the main UI, | |
290 | # even when testing with MI running on a secondary UI. | |
291 | global gdb_main_spawn_id | |
292 | ||
293 | set test "intermediate stop and continue, bp commands" | |
4a07b7da | 294 | gdb_expect { |
ef274d26 | 295 | -i $gdb_main_spawn_id |
3a87ae65 | 296 | -re ".*callee2.*callee1.*main.*\\\$1 = 0.*\\\$10 = 9" { |
ef274d26 PA |
297 | pass $test |
298 | } | |
299 | timeout { | |
300 | fail $test | |
301 | } | |
302 | } | |
303 | ||
304 | set test "intermediate stop and continue, mi running" | |
305 | gdb_expect { | |
306 | -re "\\*running" { | |
4a07b7da PA |
307 | pass $test |
308 | } | |
309 | timeout { | |
310 | fail $test | |
311 | } | |
312 | } | |
313 | ||
314 | mi_expect_stop "exited-normally" "" "" "" "" "" "test hitting breakpoint with commands" | |
48cb2d85 VP |
315 | } |
316 | ||
eb8c4e2e KS |
317 | # Test explicit breakpoints. These tests only test the MI portion of the |
318 | # code. In-depth testing of explicit breakpoints is accomplished in | |
319 | # gdb.linespec tests. | |
320 | ||
321 | proc test_explicit_breakpoints {} { | |
322 | global srcfile | |
323 | global line_callee3_head line_callee4_head | |
a9e40818 | 324 | global line_callee3_body line_callee4_body |
eb8c4e2e KS |
325 | global line_callee2_body line_main_body |
326 | ||
327 | mi_delete_breakpoints | |
328 | ||
329 | # First check mixed explicit/parsed linespecs. | |
330 | mi_gdb_test "-break-insert --function main $srcfile:$line_callee3_head" \ | |
331 | ".*Garbage following explicit linespec" | |
332 | ||
333 | # Insert some breakpoints and list them | |
334 | # Also, disable some so they do not interfere with other tests | |
335 | # Tests: | |
336 | # -break-insert -t --function main | |
337 | # -break-insert -t --source basics.c --function callee2 | |
338 | # -break-insert -t --source basics.c --line $line_callee3_head | |
339 | # -break-insert -t --source srcfile --line $line_callee4_head | |
340 | # -break-list | |
341 | ||
342 | set bps {} | |
343 | lappend bps [mi_create_breakpoint "-t --function main" \ | |
344 | "insert temp explicit breakpoint in main" \ | |
345 | -func main -file ".*$srcfile" -line $line_main_body] | |
346 | ||
347 | lappend bps \ | |
348 | [mi_create_breakpoint "-t --source $srcfile --function callee2" \ | |
349 | "insert temp explicit breakpoint at $srcfile:callee2" \ | |
350 | -func callee2 -file ".*$srcfile" -line $line_callee2_body] | |
351 | ||
352 | lappend bps \ | |
353 | [mi_create_breakpoint "-t --source $srcfile --line $line_callee3_head" \ | |
354 | "insert temp explicit breakpoint at $srcfile:$line_callee3_head" \ | |
a9e40818 | 355 | -func callee3 -file ".*$srcfile" -line $line_callee3_body] |
eb8c4e2e KS |
356 | |
357 | lappend bps \ | |
358 | [mi_create_breakpoint \ | |
359 | "-t --source \"$srcfile\" --line $line_callee4_head" \ | |
360 | "insert temp explicit breakpoint at \"$srcfile\":$line_callee4_head" \ | |
a9e40818 | 361 | -func callee4 -file ".*$srcfile" -line $line_callee4_body] |
eb8c4e2e KS |
362 | |
363 | mi_gdb_test "-break-list" "\\^done,[mi_make_breakpoint_table $bps]" \ | |
364 | "list of explicit breakpoints" | |
365 | ||
366 | mi_gdb_test "-break-delete" \ | |
367 | "\\^done" \ | |
368 | "delete temp breakpoints" | |
369 | ||
370 | mi_create_breakpoint "-c \"intarg == 3\" --function callee2" \ | |
371 | "insert explicit conditional breakpoint in callee2" \ | |
372 | -func callee2 ".*$srcfile" -line $line_callee2_body \ | |
373 | -cond "intarg == 3" | |
374 | ||
375 | # mi_create_breakpoint cannot deal with displaying canonical | |
376 | # linespecs. | |
377 | mi_gdb_test \ | |
378 | "-break-insert -c \"foo == 3\" --source $srcfile --function main --label label" \ | |
379 | ".*No symbol \"foo\" in current context.*" | |
380 | ||
381 | mi_gdb_test \ | |
382 | "-break-insert --source foobar.c --line 3" \ | |
383 | ".*No source file named foobar.c.*" | |
384 | ||
385 | mi_gdb_test \ | |
386 | "-break-insert --source $srcfile --function foobar" \ | |
387 | ".*Function \"foobar\" not defined in \"$srcfile\".*" | |
388 | ||
389 | mi_gdb_test \ | |
390 | "-break-insert --source $srcfile --function main --label foobar" \ | |
391 | ".*No label \"foobar\" defined in function \"main\".*" | |
392 | ||
393 | mi_gdb_test \ | |
394 | "-break-insert --source $srcfile" \ | |
395 | ".*Source filename requires function, label, or line offset.*" | |
396 | } | |
397 | ||
ef274d26 PA |
398 | proc test_break {mi_mode} { |
399 | global srcdir subdir binfile | |
400 | ||
401 | mi_gdb_exit | |
402 | ||
403 | if {$mi_mode == "separate"} { | |
404 | set start_ops "separate-mi-tty" | |
405 | } else { | |
406 | set start_ops "" | |
407 | } | |
408 | if [mi_gdb_start $start_ops] { | |
409 | return | |
410 | } | |
411 | ||
412 | mi_delete_breakpoints | |
413 | mi_gdb_reinitialize_dir $srcdir/$subdir | |
414 | mi_gdb_load ${binfile} | |
fb40c209 | 415 | |
ef274d26 PA |
416 | test_tbreak_creation_and_listing |
417 | test_rbreak_creation_and_listing | |
60c46647 | 418 | |
ef274d26 | 419 | test_ignore_count |
723a2275 | 420 | |
ef274d26 | 421 | test_error |
41447f92 | 422 | |
ef274d26 | 423 | test_disabled_creation |
48cb2d85 | 424 | |
ef274d26 | 425 | test_breakpoint_commands |
558a9d82 | 426 | |
ef274d26 | 427 | test_abreak_creation |
eb8c4e2e | 428 | |
ef274d26 PA |
429 | test_explicit_breakpoints |
430 | } | |
431 | ||
432 | foreach_with_prefix mi-mode {"main" "separate"} { | |
433 | test_break ${mi-mode} | |
434 | } |