]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/annota3.exp
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / annota3.exp
1 # Copyright 2003, 2004, 2005, 2006, 2007 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 2 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, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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 #
104 # info break:
105 #
106 send_gdb "info break\n"
107 gdb_expect_list "breakpoint info" "$gdb_prompt$" {
108 "\r\n\032\032post-prompt\r\n"
109 "Num Type Disp Enb Address +What\r\n"
110 "1 breakpoint keep y 0x\[0-9a-zA-Z\]+ +in main at .*annota3.c:32\r\n"
111 }
112
113
114 #
115 # run to a break point will test:
116 #
117 #exp_internal 1
118 send_gdb "run\n"
119 gdb_expect_list "run until main breakpoint" "$gdb_prompt$" {
120 "\r\n\032\032post-prompt\r\n"
121 "Starting program: .*annota3(|\.exe) \r\n"
122 "\r\n\032\032starting\r\n"
123 "\r\n\032\032breakpoint 1\r\n"
124 "\r\n"
125 "Breakpoint 1, "
126 "\r\n\032\032frame-begin 0 0x\[0-9a-z\]+\r\n"
127 "main \\(\\) at .*annota3.c:32\r\n"
128 "\r\n\032\032source.*annota3.c:32:.*:beg:0x\[0-9a-z\]+\r\n"
129 "\r\n\032\032stopped\r\n"
130 }
131 #exp_internal 0
132 #exit 0
133
134 #
135 # Let's do a next, to get to a point where the array is initialized
136 # We don't care about the annotated output for this operation, it is the same as
137 # the one produced by run above
138 #
139 send_gdb "next\n"
140 gdb_expect_list "go after array init line" "$gdb_prompt$" {
141 "\r\n\032\032post-prompt\r\n"
142 "\r\n\032\032starting\r\n"
143 "\r\n\032\032source .*annota3.c:\[0-9\]+:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
144 "\r\n\032\032stopped\r\n"
145 }
146
147
148 #
149 # printing the array:
150 #
151 send_gdb "print my_array\n"
152 gdb_expect_list "print array" "$gdb_prompt$" {
153 "\r\n\032\032post-prompt\r\n"
154 ".*= .1, 2, 3.\r\n"
155 }
156
157
158 #
159 # this should generate an error message, so to test:
160 # annotate-error-begin
161 # FIXME: annotate-error not tested
162 #
163
164 #exp_internal 1
165 send_gdb "print non_existent_value\n"
166 gdb_expect_list "print non_existent_value" "$gdb_prompt$" {
167 "\r\n\032\032post-prompt\r\n"
168 "\r\n\032\032error-begin\r\n"
169 "No symbol \"non_existent_value\" in current context.\r\n"
170 "\r\n\032\032error\r\n"
171 }
172
173
174 #
175 # break at signal handler
176 #
177 send_gdb "break handle_USR1\n"
178 gdb_expect_list "breakpoint handle_USR1" "$gdb_prompt$" {
179 "\r\n\032\032post-prompt\r\n"
180 "Breakpoint.*at 0x\[0-9a-z\]+: file.*annota3.c, line.*\r\n"
181 }
182
183 #
184 # break at printf. When we are stopped at printf, we can test
185 #
186 send_gdb "break printf\n"
187 gdb_expect_list "breakpoint printf" "$gdb_prompt$" {
188 "\r\n\032\032post-prompt\r\n"
189 "Breakpoint.*at 0x\[0-9a-z\]+.*"
190 }
191
192 #
193 # get to printf
194 #
195 send_gdb "continue\n"
196 gdb_expect_list "continue to printf" "$gdb_prompt$" {
197 "\r\n\032\032post-prompt\r\n"
198 "Continuing.\r\n"
199 "\r\n\032\032starting\r\n"
200 "\r\n\032\032breakpoint 3\r\n"
201 "\r\n"
202 "Breakpoint 3, \[^\r\n\]*\r\n"
203 "\r\n\032\032stopped\r\n"
204 }
205
206 send_gdb "backtrace\n"
207 gdb_expect_list "backtrace from shlibrary" "$gdb_prompt$" {
208 "\r\n\032\032post-prompt\r\n"
209 "#0 .* .*printf \[^\r\n\]*\r\n"
210 "#1 .* main \[^\r\n\]*\r\n"
211 }
212
213
214 #
215 # test printing a frame with some arguments:
216 #
217
218 if [target_info exists gdb,nosignals] {
219 unsupported "send SIGUSR1"
220 unsupported "backtrace @ signal handler"
221 } else {
222 send_gdb "signal SIGUSR1\n"
223 gdb_expect_list "send SIGUSR1" "$gdb_prompt$" {
224 "\r\n\032\032post-prompt\r\n"
225 "Continuing with signal SIGUSR1.\r\n"
226 "\r\n\032\032starting\r\n"
227 "\r\n\032\032breakpoint 2\r\n"
228 "\r\n"
229 "Breakpoint 2, "
230 "\r\n\032\032frame-begin 0 0x\[0-9a-z\]+\r\n"
231 "handle_USR1 \\(sig=\[0-9\]+\\) at .*annota3.c:\[0-9\]+\r\n"
232 "\r\n\032\032source .*annota3.c:\[0-9\]+:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
233 "\r\n\032\032stopped\r\n"
234 }
235
236 #
237 # test:
238 #
239 verbose "match_max local is: [match_max]"
240 verbose "match_max default is: [match_max -d]"
241 # This is necessary because a 2000 buffer is not enought to get everything
242 # up to the prompt ad the test gets a timeout.
243 match_max 3000
244 verbose "match_max now is: [match_max]"
245 send_gdb "backtrace\n"
246 gdb_expect_list "backtrace @ signal handler" "$gdb_prompt$" {
247 "#0 +handle_USR1 \[^\r\n\]+\r\n"
248 "#1 +.signal handler called.\r\n"
249 "#2 .* .*printf \[^\r\n\]+\r\n"
250 "#3 .* main \[^\r\n\]+\r\n"
251 }
252 }
253
254 #
255 # delete all the breakpoints
256 #
257 send_gdb "delete 1\n"
258 gdb_expect_list "delete bp 1" "$gdb_prompt$" {
259 "\r\n\032\032post-prompt\r\n"
260 }
261
262 send_gdb "delete 2\n"
263 gdb_expect_list "delete bp 2" "$gdb_prompt$" {
264 "\r\n\032\032post-prompt\r\n"
265 }
266
267 send_gdb "delete 3\n"
268 gdb_expect_list "delete bp 3" "$gdb_prompt$" {
269 "\r\n\032\032post-prompt\r\n"
270 }
271
272 #
273 # break at main, after value is initialized. This is in preparation
274 # to test the annotate output for the display command.
275 #
276 send_gdb "break main\n"
277 gdb_expect_list "break at 28" "$gdb_prompt$" {
278 "\r\n\032\032post-prompt\r\n"
279 "Breakpoint 4 at 0x\[0-9a-z\]+: file .*annota3.c, line 32.\r\n"
280 }
281
282 #
283 # display the value
284 #
285 send_gdb "display value\n"
286 gdb_expect_list "set up display" "$gdb_prompt$" {
287 "\r\n\032\032post-prompt\r\n"
288 "1: value = 7\r\n"
289 }
290
291
292 # should ask query. Test annotate-query.
293 # we don't care about anything else here, only the query.
294
295 send_gdb "run\n"
296 gdb_expect {
297 -re "pre-query.*already.*\\(y or n\\).*query\r\n" {
298 send_gdb "y\n"
299 gdb_expect {
300 -re ".*post-query.*$gdb_prompt$" \
301 { pass "re-run" }
302 -re ".*$gdb_prompt$" { fail "re-run" }
303 timeout { fail "re-run (timeout)" }
304 }
305 }
306 -re ".*$gdb_prompt$" { fail "re-run" }
307 timeout { fail "re-run (timeout)" }
308 }
309
310 #
311 # Test that breakpoints-invalid is issued once and only once for
312 # breakpoint ignore count changes, after annotation stopped.
313 # NOTE: breakpoints-invalid annotations have been removed from
314 # level 3 but keep these tests for continuity and comparison
315 # with annota1.exp.
316 send_gdb "break 46\n"
317 gdb_expect_list "break at 46" "$gdb_prompt$" {
318 "\r\n\032\032post-prompt\r\n"
319 "Breakpoint 5 at 0x\[0-9a-z\]+: file .*annota3.c, line 46.\r\n"
320 }
321
322 send_gdb "ignore 5 4\n"
323 gdb_expect_list "ignore 5 4" "$gdb_prompt$" {
324 "\r\n\032\032post-prompt\r\n"
325 "Will ignore next 4 crossings of breakpoint 5"
326 "\r\n"
327 }
328
329 send_gdb "continue\n"
330 gdb_expect_list "annotate ignore count change" "$gdb_prompt$" {
331 "\r\n\032\032post-prompt\r\n"
332 "\r\n\032\032breakpoint 5\r\n"
333 "\r\n"
334 "Breakpoint 5, "
335 "\r\n\032\032frame-begin 0 0x\[0-9a-z\]+\r\n"
336 "main \\(\\) at .*annota3.c:46\r\n"
337 "\r\n\032\032source .*annota3.c:46:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
338 "1: value = 11\r\n"
339 "\r\n\032\032stopped\r\n"
340 }
341
342 # check that ignore command is working, or the above can provide
343 # misleading assurance ...
344
345 send_gdb "next\n"
346 gdb_expect_list "next to exit loop" "$gdb_prompt$" {
347 "\r\n\032\032post-prompt\r\n"
348 "\r\n\032\032starting\r\n"
349 "\r\n\032\032source.*annota3.c:\[0-9\]+:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
350 "1: value = 12\r\n"
351 "\r\n\032\032stopped\r\n"
352 }
353
354 send_gdb "next\n"
355 gdb_expect_list "breakpoint ignore count" "$gdb_prompt$" {
356 "\r\n\032\032post-prompt\r\n"
357 "\r\n\032\032starting\r\n"
358 "\r\n\032\032source.*annota3.c:49:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
359 "1: value = 12\r\n"
360 "\r\n\032\032stopped\r\n"
361 }
362
363 #
364 # Send a signal that is not handled
365 #
366 # SIGTRAP signals are dropped before they get to the inferior process
367 # on hpux11. In theory, this behaivor can be controlled by setting
368 # TTEO_NORM_SIGTRAP in the inferior, but doing so did not cause
369 # the signal to be properly delivered.
370 #
371 # It has been verified that other signals will be delivered. However,
372 # rather than twiddle the test, I choose to leave it as-is as it
373 # exposes an interesting failure on hpux11.
374
375 if [target_info exists gdb,nosignals] {
376 unsupported "signal sent"
377 } else {
378 setup_xfail hppa*-*-hpux11*
379 send_gdb "signal SIGTRAP\n"
380 gdb_expect_list "signal sent" "$gdb_prompt$" {
381 "\r\n\032\032post-prompt\r\n"
382 "Continuing with signal SIGTRAP.\r\n"
383 "\r\n\032\032starting\r\n"
384 "\r\n\032\032signalled\r\n"
385 "\r\nProgram terminated with signal SIGTRAP, Trace.breakpoint trap.\r\n"
386 "The program no longer exists.\r\n"
387 "\r\n\032\032stopped\r\n"
388 }
389 }
390
391
392 # Check for production of a core file and remove it!
393
394 set exec_output [remote_exec build "ls core"]
395
396 set test "cleanup core file"
397 if [ regexp "core not found" $exec_output] {
398 pass "$test (not dumped)"
399 } else {
400 if [ regexp "No such file or directory" $exec_output] {
401 pass "$test (not dumped)"
402 } else {
403 remote_exec build "rm -f core"
404 pass "$test (removed)"
405 }
406 }
407
408 # restore the original prompt for the rest of the testsuite
409
410 set gdb_prompt $old_gdb_prompt