]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/annota3.exp
* gdb.base/annota1.exp: Remove obsolete match_max increase.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / annota3.exp
1 # Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009
2 # Free Software Foundation, Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
18
19 if $tracelevel then {
20 strace $tracelevel
21 }
22
23
24 # are we on a target board? If so, don't run these tests.
25 # note: this is necessary because we cannot use runto_main (which would
26 # work for remote targets too) because of the different prompt we get
27 # when using annotation level 2.
28 #
29 if [is_remote target] then {
30 return 0
31 }
32
33
34 #
35 # test running programs
36 #
37 set prms_id 0
38 set bug_id 0
39
40 set testfile "annota3"
41 set srcfile ${testfile}.c
42 set binfile ${objdir}/${subdir}/${testfile}$EXEEXT
43
44 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
45 untested annota3.exp
46 return -1
47 }
48
49
50 gdb_exit
51 gdb_start
52 gdb_reinitialize_dir $srcdir/$subdir
53 gdb_load ${binfile}
54
55 if [target_info exists gdb_stub] {
56 gdb_step_for_stub;
57 }
58
59 #
60 # the line at which break main will put the breakpoint
61 #
62 set main_line 32
63
64 # The commands we test here produce many lines of output; disable "press
65 # <return> to continue" prompts.
66 send_gdb "set height 0\n"
67 gdb_expect -re "$gdb_prompt $"
68
69 #
70 # break at main
71 #
72 gdb_test "break main" \
73 "Breakpoint.*at.* file .*$srcfile, line.*" \
74 "breakpoint main"
75
76
77 # NOTE: this prompt is OK only when the annotation level is > 1
78
79 # NOTE: When this prompt is in use the gdb_test procedure cannot be
80 # used because it assumes that the last char after the gdb_prompt is a
81 # white space. This is not true with this annotated prompt. So we must
82 # use send_gdb and gdb_expect or gdb_expect_list.
83
84 set old_gdb_prompt $gdb_prompt
85 set gdb_prompt "\r\n\032\032pre-prompt\r\n$gdb_prompt \r\n\032\032prompt\r\n"
86
87
88
89 #
90 # set the annotation level to 3
91 #
92 # of course, this will test:
93 # annotate-pre-prompt
94 # annotate-prompt
95 # annotate-post-prompt (in the next block)
96 #
97 send_gdb "set annotate 3\n"
98 gdb_expect_list "annotation set at level 3" "\r\n$gdb_prompt$" {
99 "set annotate 3"
100 }
101
102 #
103 # if construct:
104 #
105 send_gdb "if 1\n"
106 gdb_expect {
107 -re "^if 1\r\n\r\n\032\032post-prompt\r\n\r\n\032\032pre-commands\r\n >\r\n\032\032commands\r\n$" {
108 pass "start if construct"
109 }
110 -re ".*\032\032commands\r\n" {
111 fail "start if construct"
112 }
113 timeout { fail "start if construct (timeout)" }
114 }
115 send_gdb "end\n"
116 gdb_expect {
117 -re "^end\r\n\r\n\032\032post-commands\r\n$gdb_prompt$" {
118 pass "end if construct"
119 }
120 -re ".*$gdb_prompt$" {
121 fail "end if construct"
122 }
123 timeout { fail "end if construct (timeout)" }
124 }
125 #
126 # info break:
127 #
128 send_gdb "info break\n"
129 gdb_expect_list "breakpoint info" "$gdb_prompt$" {
130 "\r\n\032\032post-prompt\r\n"
131 "Num Type Disp Enb Address +What\r\n"
132 "1 breakpoint keep y 0x\[0-9a-zA-Z\]+ +in main at .*annota3.c:32\r\n"
133 }
134
135
136 #
137 # run to a break point will test:
138 #
139 #exp_internal 1
140 send_gdb "run\n"
141 gdb_expect_list "run until main breakpoint" "$gdb_prompt$" {
142 "\r\n\032\032post-prompt\r\n"
143 "Starting program: .*annota3(|\.exe) \r\n"
144 "\r\n\032\032starting\r\n"
145 "\r\n\032\032breakpoint 1\r\n"
146 "\r\n"
147 "Breakpoint 1, "
148 "\r\n\032\032frame-begin 0 0x\[0-9a-z\]+\r\n"
149 "main \\(\\) at .*annota3.c:32\r\n"
150 "\r\n\032\032source.*annota3.c:32:.*:beg:0x\[0-9a-z\]+\r\n"
151 "\r\n\032\032stopped\r\n"
152 }
153 #exp_internal 0
154 #exit 0
155
156 #
157 # Let's do a next, to get to a point where the array is initialized
158 # We don't care about the annotated output for this operation, it is the same as
159 # the one produced by run above
160 #
161 send_gdb "next\n"
162 gdb_expect_list "go after array init line" "$gdb_prompt$" {
163 "\r\n\032\032post-prompt\r\n"
164 "\r\n\032\032starting\r\n"
165 "\r\n\032\032source .*annota3.c:\[0-9\]+:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
166 "\r\n\032\032stopped\r\n"
167 }
168
169
170 #
171 # printing the array:
172 #
173 send_gdb "print my_array\n"
174 gdb_expect_list "print array" "$gdb_prompt$" {
175 "\r\n\032\032post-prompt\r\n"
176 ".*= .1, 2, 3.\r\n"
177 }
178
179
180 #
181 # this should generate an error message, so to test:
182 # annotate-error-begin
183 # FIXME: annotate-error not tested
184 #
185
186 #exp_internal 1
187 send_gdb "print non_existent_value\n"
188 gdb_expect_list "print non_existent_value" "$gdb_prompt$" {
189 "\r\n\032\032post-prompt\r\n"
190 "\r\n\032\032error-begin\r\n"
191 "No symbol \"non_existent_value\" in current context.\r\n"
192 "\r\n\032\032error\r\n"
193 }
194
195
196 #
197 # break at signal handler
198 #
199 send_gdb "break handle_USR1\n"
200 gdb_expect_list "breakpoint handle_USR1" "$gdb_prompt$" {
201 "\r\n\032\032post-prompt\r\n"
202 "Breakpoint.*at 0x\[0-9a-z\]+: file.*annota3.c, line.*\r\n"
203 }
204
205 #
206 # break at printf. When we are stopped at printf, we can test
207 #
208 send_gdb "break printf\n"
209 gdb_expect_list "breakpoint printf" "$gdb_prompt$" {
210 "\r\n\032\032post-prompt\r\n"
211 "Breakpoint.*at 0x\[0-9a-z\]+.*"
212 }
213
214 #
215 # get to printf
216 #
217 send_gdb "continue\n"
218 gdb_expect_list "continue to printf" "$gdb_prompt$" {
219 "\r\n\032\032post-prompt\r\n"
220 "Continuing.\r\n"
221 "\r\n\032\032starting\r\n"
222 "\r\n\032\032breakpoint 3\r\n"
223 "\r\n"
224 "Breakpoint 3, \[^\r\n\]*\r\n"
225 "\r\n\032\032stopped\r\n"
226 }
227
228 send_gdb "backtrace\n"
229 gdb_expect_list "backtrace from shlibrary" "$gdb_prompt$" {
230 "\r\n\032\032post-prompt\r\n"
231 "#0 .* .*printf(@\[^ ]*)? \[^\r\n\]*\r\n"
232 "#1 .* main \[^\r\n\]*\r\n"
233 }
234
235
236 #
237 # test printing a frame with some arguments:
238 #
239
240 if [target_info exists gdb,nosignals] {
241 unsupported "send SIGUSR1"
242 unsupported "backtrace @ signal handler"
243 } else {
244 send_gdb "signal SIGUSR1\n"
245 gdb_expect_list "send SIGUSR1" "$gdb_prompt$" {
246 "\r\n\032\032post-prompt\r\n"
247 "Continuing with signal SIGUSR1.\r\n"
248 "\r\n\032\032starting\r\n"
249 "\r\n\032\032breakpoint 2\r\n"
250 "\r\n"
251 "Breakpoint 2, "
252 "\r\n\032\032frame-begin 0 0x\[0-9a-z\]+\r\n"
253 "handle_USR1 \\(sig=\[0-9\]+\\) at .*annota3.c:\[0-9\]+\r\n"
254 "\r\n\032\032source .*annota3.c:\[0-9\]+:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
255 "\r\n\032\032stopped\r\n"
256 }
257
258 #
259 # test:
260 #
261 send_gdb "backtrace\n"
262 gdb_expect_list "backtrace @ signal handler" "$gdb_prompt$" {
263 "#0 +handle_USR1 \[^\r\n\]+\r\n"
264 "#1 +.signal handler called.\r\n"
265 "#2 .* .*printf(@\[^ \]*)? \[^\r\n\]+\r\n"
266 "#3 .* main \[^\r\n\]+\r\n"
267 }
268 }
269
270 #
271 # delete all the breakpoints
272 #
273 send_gdb "delete 1\n"
274 gdb_expect_list "delete bp 1" "$gdb_prompt$" {
275 "\r\n\032\032post-prompt\r\n"
276 }
277
278 send_gdb "delete 2\n"
279 gdb_expect_list "delete bp 2" "$gdb_prompt$" {
280 "\r\n\032\032post-prompt\r\n"
281 }
282
283 send_gdb "delete 3\n"
284 gdb_expect_list "delete bp 3" "$gdb_prompt$" {
285 "\r\n\032\032post-prompt\r\n"
286 }
287
288 #
289 # break at main, after value is initialized. This is in preparation
290 # to test the annotate output for the display command.
291 #
292 send_gdb "break main\n"
293 gdb_expect_list "break at 28" "$gdb_prompt$" {
294 "\r\n\032\032post-prompt\r\n"
295 "Breakpoint 4 at 0x\[0-9a-z\]+: file .*annota3.c, line 32.\r\n"
296 }
297
298 #
299 # display the value
300 #
301 send_gdb "display value\n"
302 gdb_expect_list "set up display" "$gdb_prompt$" {
303 "\r\n\032\032post-prompt\r\n"
304 "1: value = 7\r\n"
305 }
306
307
308 # should ask query. Test annotate-query.
309 # we don't care about anything else here, only the query.
310
311 send_gdb "run\n"
312 gdb_expect {
313 -re "pre-query.*already.*\\(y or n\\).*query\r\n" {
314 send_gdb "y\n"
315 gdb_expect {
316 -re ".*post-query.*$gdb_prompt$" \
317 { pass "re-run" }
318 -re ".*$gdb_prompt$" { fail "re-run" }
319 timeout { fail "re-run (timeout)" }
320 }
321 }
322 -re ".*$gdb_prompt$" { fail "re-run" }
323 timeout { fail "re-run (timeout)" }
324 }
325
326 #
327 # Test that breakpoints-invalid is issued once and only once for
328 # breakpoint ignore count changes, after annotation stopped.
329 # NOTE: breakpoints-invalid annotations have been removed from
330 # level 3 but keep these tests for continuity and comparison
331 # with annota1.exp.
332 send_gdb "break 46\n"
333 gdb_expect_list "break at 46" "$gdb_prompt$" {
334 "\r\n\032\032post-prompt\r\n"
335 "Breakpoint 5 at 0x\[0-9a-z\]+: file .*annota3.c, line 46.\r\n"
336 }
337
338 send_gdb "ignore 5 4\n"
339 gdb_expect_list "ignore 5 4" "$gdb_prompt$" {
340 "\r\n\032\032post-prompt\r\n"
341 "Will ignore next 4 crossings of breakpoint 5"
342 "\r\n"
343 }
344
345 send_gdb "continue\n"
346 gdb_expect_list "annotate ignore count change" "$gdb_prompt$" {
347 "\r\n\032\032post-prompt\r\n"
348 "\r\n\032\032breakpoint 5\r\n"
349 "\r\n"
350 "Breakpoint 5, "
351 "\r\n\032\032frame-begin 0 0x\[0-9a-z\]+\r\n"
352 "main \\(\\) at .*annota3.c:46\r\n"
353 "\r\n\032\032source .*annota3.c:46:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
354 "1: value = 11\r\n"
355 "\r\n\032\032stopped\r\n"
356 }
357
358 # check that ignore command is working, or the above can provide
359 # misleading assurance ...
360
361 send_gdb "next\n"
362 gdb_expect_list "next to exit loop" "$gdb_prompt$" {
363 "\r\n\032\032post-prompt\r\n"
364 "\r\n\032\032starting\r\n"
365 "\r\n\032\032source.*annota3.c:\[0-9\]+:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
366 "1: value = 12\r\n"
367 "\r\n\032\032stopped\r\n"
368 }
369
370 send_gdb "next\n"
371 gdb_expect_list "breakpoint ignore count" "$gdb_prompt$" {
372 "\r\n\032\032post-prompt\r\n"
373 "\r\n\032\032starting\r\n"
374 "\r\n\032\032source.*annota3.c:49:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
375 "1: value = 12\r\n"
376 "\r\n\032\032stopped\r\n"
377 }
378
379 #
380 # Send a signal that is not handled
381 #
382 # SIGTRAP signals are dropped before they get to the inferior process
383 # on hpux11. In theory, this behaivor can be controlled by setting
384 # TTEO_NORM_SIGTRAP in the inferior, but doing so did not cause
385 # the signal to be properly delivered.
386 #
387 # It has been verified that other signals will be delivered. However,
388 # rather than twiddle the test, I choose to leave it as-is as it
389 # exposes an interesting failure on hpux11.
390
391 if [target_info exists gdb,nosignals] {
392 unsupported "signal sent"
393 } else {
394 setup_xfail hppa*-*-hpux11*
395 send_gdb "signal SIGTRAP\n"
396 gdb_expect_list "signal sent" "$gdb_prompt$" {
397 "\r\n\032\032post-prompt\r\n"
398 "Continuing with signal SIGTRAP.\r\n"
399 "\r\n\032\032starting\r\n"
400 "\r\n\032\032signalled\r\n"
401 "\r\nProgram terminated with signal SIGTRAP, Trace.breakpoint trap.\r\n"
402 "The program no longer exists.\r\n"
403 "\r\n\032\032stopped\r\n"
404 }
405 }
406
407
408 # Check for production of a core file and remove it!
409
410 set exec_output [remote_exec build "ls core"]
411
412 set test "cleanup core file"
413 if [ regexp "core not found" $exec_output] {
414 pass "$test (not dumped)"
415 } else {
416 if [ regexp "No such file or directory" $exec_output] {
417 pass "$test (not dumped)"
418 } else {
419 remote_exec build "rm -f core"
420 pass "$test (removed)"
421 }
422 }
423
424 # restore the original prompt for the rest of the testsuite
425
426 set gdb_prompt $old_gdb_prompt