]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.mi/mi-break.exp
Update year range in copyright notice of all files owned by the GDB project.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-break.exp
1 # Copyright 1999-2015 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 # Test Machine interface (MI) operations
17 #
18 # Test MI breakpoint commands.
19 #
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.
22
23 load_lib mi-support.exp
24 set MIFLAGS "-i=mi"
25
26 gdb_exit
27 if [mi_gdb_start] {
28 continue
29 }
30
31 standard_testfile basics.c
32
33 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
34 untested mi-break.exp
35 return -1
36 }
37
38 mi_delete_breakpoints
39 mi_gdb_reinitialize_dir $srcdir/$subdir
40 mi_gdb_load ${binfile}
41
42 # Locate line numbers in basics.c.
43 set line_callee4_head [gdb_get_line_number "callee4 ("]
44 set line_callee4_body [expr $line_callee4_head + 2]
45 set line_callee3_head [gdb_get_line_number "callee3 ("]
46 set line_callee3_body [expr $line_callee3_head + 2]
47 set line_callee2_head [gdb_get_line_number "callee2 ("]
48 set line_callee2_body [expr $line_callee2_head + 2]
49 set line_callee1_head [gdb_get_line_number "callee1 ("]
50 set line_callee1_body [expr $line_callee1_head + 2]
51 set line_main_head [gdb_get_line_number "main ("]
52 set line_main_body [expr $line_main_head + 2]
53 set line_callme_head [gdb_get_line_number "callme ("]
54 set line_callme_body [expr $line_callme_head + 2]
55
56 set fullname "fullname=\"${fullname_syntax}${srcfile}\""
57
58 proc test_tbreak_creation_and_listing {} {
59 global srcfile
60 global line_callee4_head
61 global line_callee3_head
62 global line_callee2_body
63 global line_main_body
64
65 # Insert some breakpoints and list them
66 # Also, disable some so they do not interfere with other tests
67 # Tests:
68 # -break-insert -t main
69 # -break-insert -t basics.c:callee2
70 # -break-insert -t basics.c:$line_callee3_head
71 # -break-insert -t srcfile:$line_callee4_head
72 # -break-list
73
74 set bps {}
75 lappend bps [mi_create_breakpoint "-t main" "break-insert -t operation" \
76 -number 1 -disp del -func main -file ".*basics.c" \
77 -line $line_main_body]
78
79 lappend bps [mi_create_breakpoint "-t basics.c:callee2" \
80 "insert temp breakpoint at basics.c:callee2" \
81 -number 2 -disp del -func callee2 -file ".*basics.c" \
82 -line $line_callee2_body]
83
84 lappend bps [mi_create_breakpoint "-t basics.c:$line_callee3_head" \
85 "insert temp breakpoint at basics.c:\$line_callee3_head" \
86 -number 3 -disp del -func callee3 -file ".*basics.c" \
87 -line $line_callee3_head]
88
89 # Getting the quoting right is tricky.
90 # That is "\"<file>\":$line_callee4_head"
91 lappend bps [mi_create_breakpoint \
92 "-t \"\\\"${srcfile}\\\":$line_callee4_head\"" \
93 "insert temp breakpoint at \"<fullfilename>\":\$line_callee4_head" \
94 -number 4 -disp del -func callee4 -file ".*basics.c" \
95 -line $line_callee4_head]
96
97 mi_gdb_test "666-break-list" \
98 "666\\\^done,[mi_make_breakpoint_table $bps]" \
99 "list of breakpoints"
100
101 mi_gdb_test "777-break-delete" \
102 "777\\^done" \
103 "delete temp breakpoints"
104 }
105
106 proc test_rbreak_creation_and_listing {} {
107 global line_callee4_body
108 global line_callee3_body
109 global line_callee2_body
110 global line_callee1_body
111 global line_main_body
112
113 # Insert some breakpoints and list them
114 # Also, disable some so they do not interfere with other tests
115 # Tests:
116 # -break-insert -r main
117 # -break-insert -r callee2
118 # -break-insert -r callee
119 # -break-insert -r .*llee
120 # -break-list
121
122 setup_kfail "*-*-*" mi/14270
123 set bps {}
124 lappend bps [mi_make_breakpoint -number 5 -file ".*basics.c" \
125 -line $line_main_body]
126 mi_gdb_test "122-break-insert -r main" \
127 "122\\^done,[lindex $bps end]" \
128 "break-insert -r operation"
129
130 setup_kfail "*-*-*" mi/14270
131 lappend bps [mi_make_breakpoint -number 6 -file ".*basics.c" \
132 -line $line_callee2_body]
133 mi_gdb_test "133-break-insert -r callee2" \
134 "133\\^done,[lindex $bps end]" \
135 "insert breakpoint with regexp callee2"
136
137 setup_kfail "*-*-*" mi/14270
138 set start [llength $bps]
139 lappend bps [mi_make_breakpoint -number 7 -file ".*basics.c" \
140 -line $line_callee1_body]
141 lappend bps [mi_make_breakpoint -number 8 -file ".*basics.c" \
142 -line $line_callee2_body]
143 lappend bps [mi_make_breakpoint -number 9 -file ".*basics.c" \
144 -line $line_callee3_body]
145 lappend bps [mi_make_breakpoint -number 10 -file ".*basics.c" \
146 -line $line_callee4_body]
147 mi_gdb_test "144-break-insert -r callee" \
148 "144\\^done,[join [lrange $bps $start end] ,]" \
149 "insert breakpoint with regexp callee"
150
151 setup_kfail "*-*-*" mi/14270
152 set start [llength $bps]
153 lappend bps [mi_make_breakpoint -number 11 -file ".*basics.c" \
154 -line $line_callee1_body]
155 lappend bps [mi_make_breakpoint -number 12 -file ".*basics.c" \
156 -line $line_callee2_body]
157 lappend bps [mi_make_breakpoint -number 13 -file ".*basics.c" \
158 -line $line_callee3_body]
159 lappend bps [mi_make_breakpoint -number 14 -file ".*basics.c" \
160 -line $line_callee4_body]
161 mi_gdb_test "155-break-insert -r \.\*llee" \
162 "155\\^done,[join [lrange $bps $start end] ,]" \
163 "insert breakpoint with regexp .*llee"
164
165 setup_kfail "*-*-*" mi/14270
166 mi_gdb_test "166-break-list" \
167 "166\\^done,[mi_make_breakpoint_table $bps]" \
168 "list of breakpoints"
169
170 mi_gdb_test "177-break-delete" \
171 "177\\^done" \
172 "delete temp breakpoints"
173 }
174
175 proc test_abreak_creation {} {
176 mi_create_varobj tpnum \$tpnum "create local variable tpnum"
177 # Test that $tpnum is not set before creating a tracepoint.
178 mi_gdb_test "521-var-evaluate-expression tpnum" \
179 "521\\^done,value=\"void\"" "eval tpnum before tracepoint"
180
181 mi_gdb_test "522-break-insert -a main" \
182 "522\\^done,[mi_make_breakpoint -number 10 -type tracepoint]" \
183 "break-insert -a operation"
184
185 mi_gdb_test "523-var-update tpnum" \
186 "523\\^done,changelist=\\\[\{name=\"tpnum\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\}\\\]" \
187 "update tpnum"
188 # Test that $tpnum is updated after creating a tracepoint.
189 mi_gdb_test "524-var-evaluate-expression tpnum" \
190 "524\\^done,value=\"10\"" "eval tpnum after tracepoint"
191 }
192
193 proc test_ignore_count {} {
194 global line_callme_body
195
196 mi_gdb_test "-break-insert -i 1 callme" \
197 "\\^done,[mi_make_breakpoint -ignore 1]" \
198 "insert breakpoint with ignore count at callme"
199
200 mi_run_cmd
201
202 mi_expect_stop "breakpoint-hit" "callme" "\{name=\"i\",value=\"2\"\}" ".*basics.c" $line_callme_body \
203 {"" "disp=\"keep\"" } "run to breakpoint with ignore count"
204 }
205
206 proc test_error {} {
207 mi_gdb_test "-break-insert function_that_does_not_exist" \
208 ".*\\^error,msg=\"Function \\\\\"function_that_does_not_exist\\\\\" not defined.\"" \
209 "breakpoint at nonexistent function"
210
211 # We used to have a bug whereby -break-insert that failed would not
212 # clear some event hooks. As result, whenever we evaluate expression
213 # containing function call, the internal breakpoint created to handle
214 # function call would be reported, messing up MI output.
215 mi_gdb_test "-var-create V * return_1()" \
216 "\\^done,name=\"V\",numchild=\"0\",value=\"1\",type=\"int\",has_more=\"0\"" \
217 "create varobj for function call"
218
219 mi_gdb_test "-var-update *" \
220 "\\^done,changelist=\\\[\\\]" \
221 "update varobj for function call"
222
223 # Try setting breakpoints with garbage after the location.
224
225 # "if" only works in the CLI. It's not supposed to be accepted by
226 # MI. The way to specify a condition is with -c.
227 mi_gdb_test "-break-insert \"callme if i < 4\"" \
228 ".*\\^error,msg=\"Garbage 'if i < 4' at end of location\"" \
229 "breakpoint with garbage after location"
230
231 mi_gdb_test "-break-insert -c i==4 \"callme if i < 4\"" \
232 ".*\\^error,msg=\"Garbage 'if i < 4' at end of location\"" \
233 "conditional breakpoint with garbage after location"
234 }
235
236 proc test_disabled_creation {} {
237 global line_callee2_body
238
239 set bp [mi_make_breakpoint -number 6 -type breakpoint -disp keep \
240 -enabled n -func callee2 -file ".*basics.c" \
241 -line $line_callee2_body]
242 mi_gdb_test "-break-insert -d basics.c:callee2" \
243 "\\^done,$bp" \
244 "test disabled creation"
245
246 mi_gdb_test "-break-delete" \
247 "\\^done" \
248 "test disabled creation: cleanup"
249 }
250
251 proc test_breakpoint_commands {} {
252 global line_callee2_body
253
254 set bp_no_script \
255 [mi_create_breakpoint "basics.c:callee2" \
256 "breakpoint commands: insert breakpoint at basics.c:callee2" \
257 -number 7 -disp keep -func callee2 -file ".*basics.c" \
258 -line $line_callee2_body]
259
260 mi_gdb_test "-break-commands 7 \"print 10\" \"continue\"" \
261 "\\^done" \
262 "breakpoint commands: set commands"
263
264 # Rebuild the breakpoint regexp instead of using the one returned
265 # by mi_create_breakpoint. Only in -break-info is the actual script
266 # seen.
267 set bp_script [mi_make_breakpoint -number 7 -disp keep -func callee2 \
268 -file ".*basics.c" -line $line_callee2_body \
269 -script {\{"print 10","continue"\}}]
270 mi_gdb_test "-break-info 7" \
271 "\\^done,[mi_make_breakpoint_table [list $bp_script]]" \
272 "breakpoint commands: check that commands are set"
273
274 mi_gdb_test "-break-commands 7" \
275 "\\^done" \
276 "breakpoint commands: clear commands"
277
278 mi_gdb_test "-break-info" \
279 "\\^done,[mi_make_breakpoint_table [list $bp_no_script]]" \
280 "breakpoint commands: check that commands are cleared"
281
282 mi_run_to_main
283
284 mi_create_breakpoint "basics.c:callee2" \
285 "breakpoint commands: insert breakpoint at basics.c:callee2, again" \
286 -number 9 -disp keep -func callee2 -file ".*basics.c" \
287 -line $line_callee2_body
288
289 mi_gdb_test "-break-commands 9 \"set \$i=0\" \"while \$i<10\" \"print \$i\" \"set \$i=\$i+1\" \"end\" \"continue\" " \
290 "\\^done" \
291 "breakpoint commands: set commands"
292
293 mi_send_resuming_command "exec-continue" "breakpoint commands: continue"
294
295 set test "intermediate stop and continue"
296 gdb_expect {
297 -re ".*\\\$1 = 0.*\\\$10 = 9.*\\*running" {
298 pass $test
299 }
300 timeout {
301 fail $test
302 }
303 }
304
305 mi_expect_stop "exited-normally" "" "" "" "" "" "test hitting breakpoint with commands"
306 }
307
308 test_tbreak_creation_and_listing
309 test_rbreak_creation_and_listing
310
311 test_ignore_count
312
313 test_error
314
315 test_disabled_creation
316
317 test_breakpoint_commands
318
319 test_abreak_creation
320
321 mi_gdb_exit
322 return 0