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