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