2 # Free Software Foundation, Inc.
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 2 of the License, or
7 # (at your option) any later version.
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.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 # Please email any bugs, comments, and/or additions to this file to:
19 # bug-gdb@prep.ai.mit.edu
21 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
29 # test running programs
34 set testfile "annota1"
35 set srcfile ${testfile}.c
36 set binfile ${objdir}/${subdir}/${testfile}
38 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-w}] != "" } {
39 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
43 # are we on a target board? If so, don't run these tests.
44 # note: this is necessary because we cannot use runto_main (which would
45 # work for remote targets too) because of the different prompt we get
46 # when using annotation level 2.
55 gdb_reinitialize_dir $srcdir/$subdir
58 if [target_info exists gdb_stub] {
63 # the line at which break main will put the breakpoint
67 # The commands we test here produce many lines of output; disable "press
68 # <return> to continue" prompts.
69 send_gdb "set height 0\n"
70 gdb_expect -re "$gdb_prompt $"
75 gdb_test "break main" \
76 "Breakpoint.*at.* file .*$srcfile, line.*" \
81 # NOTE: this prompt is OK only when the annotation level is > 1
82 # NOTE: When this prompt is in use the gdb_test procedure cannot be used because
83 # it assumes that the last char after the gdb_prompt is a white space. This is not
84 # true with this annotated prompt. So we must use send_gdb and gdb_expect.
87 set old_gdb_prompt $gdb_prompt
88 set gdb_prompt "\r\n\032\032pre-prompt\r\n$gdb_prompt \r\n\032\032prompt\r\n"
93 # set the annotation level to 2
95 # of course, this will test:
98 # annotate-post-prompt (in the next block)
100 send_gdb "set annotate 2\n"
102 -re "set annotate 2\r\n$gdb_prompt$" { pass "annotation set at level 2" }
103 -re ".*$gdb_prompt$" { fail "annotation set at level 2" }
104 timeout { fail "annotation set at level 2 (timeout)" }
109 # info break will test:
110 # annotate-breakpoints-headers
112 # annotate-breakpoints-table
114 # annotate-breakpoints-table-end
116 send_gdb "info break\n"
118 -re "\r\n\032\032post-prompt\r\n\r\n\032\032breakpoints-headers\r\n\r\n\032\032field 0\r\nNum \r\n\032\032field 1\r\nType \r\n\032\032field 2\r\nDisp \r\n\032\032field 3\r\nEnb \r\n\032\032field 4\r\nAddress \r\n\032\032field 5\r\nWhat\r\n\r\n\032\032breakpoints-table\r\n\r\n\032\032record\r\n\r\n\032\032field 0\r\n1 \r\n\032\032field 1\r\nbreakpoint \r\n\032\032field 2\r\nkeep \r\n\032\032field 3\r\ny \r\n\032\032field 4\r\n$hex \r\n\032\032field 5\r\nin main at ${srcdir}/${subdir}/${srcfile}:$main_line\r\n\r\n\032\032breakpoints-table-end\r\n$gdb_prompt$" \
119 {pass "breakpoint info"}
120 -re ".*$gdb_prompt$" { fail "breakpoint info" }
121 timeout { fail "breakpoint info (timeout)" }
126 # run to a break point will test:
127 # annotate-frames-invalid
128 # annotate-breakpoints-invalid (a.k.a. breakpoints-changed)
130 # annotate-breakpoint
131 # annotate-frame-begin
132 # annotate-frame-function-name
133 # annotate-frame-args
134 # annotate-frame-source-begin
135 # annotate-frame-source-file
136 # annotate-frame-source-file-end
137 # annotate-frame-source-line
138 # annotate-frame-source-end
146 -re "\r\n\032\032post-prompt\r\nStarting program: $binfile \(\r\n\r\n\032\032frames-invalid\)+\(\r\n\r\n\032\032breakpoints-invalid\)*.*\(\r\n\r\n\032\032frames-invalid\)*\r\n\r\n\032\032starting\(\r\n\r\n\032\032frames-invalid\)+\r\n\r\n\032\032breakpoint 1\r\n\r\nBreakpoint 1, \r\n\032\032frame-begin 0 $hex\r\n\r\n\032\032frame-function-name\r\nmain\r\n\032\032frame-args\r\n \\(\\)\r\n\032\032frame-source-begin\r\n at \r\n\032\032frame-source-file\r\n.*annota1.c\r\n\032\032frame-source-file-end\r\n:\r\n\032\032frame-source-line\r\n$main_line\r\n\032\032frame-source-end\r\n\r\n\r\n\032\032source.*$srcfile:$main_line:.*:beg:$hex\r\n\r\n\032\032frame-end\r\n\r\n\032\032stopped\r\n.*$gdb_prompt$" \
147 { pass "run until main breakpoint" }
148 -re ".*$gdb_prompt$" { fail "run until main breakpoint" }
149 timeout { fail "run until main breakpoint (timeout)" }
155 # Let's do a next, to get to a point where the array is initialized
156 # We don't care about the annotated output for this operation, it is the same as
157 # the one produced by run above
161 -re ".*$gdb_prompt$" { pass "go after array init line" }
162 timeout { fail "go after array init line (timeout)" }
167 # printing the array will test:
168 # annotate-value-history-begin
169 # annotate-value-history-value
170 # annotate-array-section-begin
172 # FIXME: annotate-elt-rep and annotate-elt-rep-end not tested
173 # annotate-array-section-end
174 # annotate-value-history-end
175 # FIXME: annotate-value-begin and annotate-value-end not tested (the gdb output
176 # command would cause them to be used)
178 send_gdb "print my_array\n"
180 -re "\r\n\032\032post-prompt\r\n\r\n\032\032value-history-begin 1 -\r\n.*= \r\n\032\032value-history-value\r\n.\r\n\032\032array-section-begin 0 -\r\n1\r\n\032\032elt\r\n, 2\r\n\032\032elt\r\n, 3\r\n\032\032elt\r\n\r\n\032\032array-section-end\r\n.\r\n\r\n\032\032value-history-end\r\n$gdb_prompt$" \
181 { pass "print array" }
182 -re ".*$gdb_prompt$" { fail "print array" }
183 timeout { fail "print array (timeout)" }
188 # this should generate an error message, so to test:
189 # annotate-error-begin
190 # FIXME: annotate-error not tested
194 send_gdb "print non_existent_value\n"
196 -re "\r\n\032\032post-prompt\r\n\r\n\032\032error-begin\r\nNo symbol \"non_existent_value\" in current context.\r\n\r\n\032\032error\r\n$gdb_prompt$" \
197 { pass "print non_existent_value" }
198 -re ".*$gdb_prompt$" { fail "print non_existent_value" }
199 timeout { fail "print non_existent_value (timeout)" }
204 # break at signal handler. So that, once we are in the sig handler, if we do a bt
205 # we can test annotate-signal-handler-caller
207 send_gdb "break handle_USR1\n"
209 -re "\r\n\032\032post-prompt\r\n\r\n\032\032breakpoints-invalid\r\nBreakpoint.*at $hex: file.*$srcfile, line.*\r\n$gdb_prompt$" \
210 { pass "breakpoint handle_USR1" }
211 -re ".*$gdb_prompt$" { fail "break at handle_USR1" }
212 timeout { fail "break at handle_USR1 (timeout)" }
216 # break at printf. When we are stopped at printf, we can test
218 send_gdb "break printf\n"
220 -re "\r\n\032\032post-prompt\r\n\r\n\032\032breakpoints-invalid\r\nBreakpoint.*at $hex.*$gdb_prompt$" \
221 { pass "breakpoint printf" }
222 -re ".*$gdb_prompt$" { fail "break printf" }
223 timeout { fail "break printf (timeout)" }
229 send_gdb "continue\n"
231 -re "\r\n\032\032post-prompt\r\nContinuing.\r\n\r\n\032\032starting\r\n\r\n\032\032frames-invalid\r\n\r\n\032\032breakpoint 3\r\n\r\nBreakpoint 3, \r\n\032\032frame-begin 0 $hex\r\n\r\n(\032\032frame-address\r\n$hex\r\n\032\032frame-address-end\r\n in \r\n)*\032\032frame-function-name\r\nprintf\r\n\032\032frame-args\r\n.*\032\032frame-end\r\n\r\n\032\032stopped\r\n$gdb_prompt$" \
232 { pass "continue to printf" }
233 -re ".*$gdb_prompt$" { fail "continue to printf" }
234 timeout { fail "continue to printf (timeout)" }
239 # annotate-frame-where
240 # annotate-frame-address
241 # annotate-frame-address-end
243 send_gdb "backtrace\n"
245 -re "\r\n\032\032post-prompt\r\n\r\n\032\032frame-begin 0 $hex\r\n.0 \r\n(\032\032frame-address\r\n$hex\r\n\032\032frame-address-end\r\n in \r\n)*\032\032frame-function-name\r\nprintf\r\n\032\032frame-args\r\n \\(.*frame-end\r\n\r\n\032\032frame-begin 1 $hex\r\n.1 \r\n\032\032frame-address\r\n$hex\r\n\032\032frame-address-end\r\n in \r\n\032\032frame-function-name\r\nmain\r\n\032\032frame-args\r\n \\(\\)\r\n\032\032frame-source-begin\r\n at \r\n\032\032frame-source-file\r\n${srcdir}/${subdir}/${srcfile}\r\n\032\032frame-source-file-end\r\n:\r\n\032\032frame-source-line\r\n.*\r\n\032\032frame-source-end\r\n\r\n\r\n\032\032frame-end\r\n$gdb_prompt$" \
246 { pass "bactrace from shlibrary" }
247 -re ".*$gdb_prompt$" { fail "backtrace from shlibrary" }
248 timeout { fail "backtrace from shlibrary (timeout)" }
253 # test printing a frame with some arguments:
255 # annotate-arg-name-end
259 send_gdb "signal SIGUSR1\n"
261 -re "\r\n\032\032post-prompt\r\nContinuing with signal SIGUSR1.\r\n\r\n\032\032starting\r\n\r\n\032\032frames-invalid\r\n\r\n\032\032breakpoint 2\r\n\r\nBreakpoint 2, \r\n\032\032frame-begin 0 $hex\r\n\r\n\032\032frame-function-name\r\nhandle_USR1\r\n\032\032frame-args\r\n \\(\r\n\032\032arg-begin\r\nsig\r\n\032\032arg-name-end\r\n=\r\n\032\032arg-value -\r\n$decimal\r\n\032\032arg-end\r\n\\)\r\n\032\032frame-source-begin\r\n at \r\n\032\032frame-source-file\r\n${srcdir}/${subdir}/${srcfile}\r\n\032\032frame-source-file-end\r\n:\r\n\032\032frame-source-line\r\n.*\r\n\032\032frame-source-end\r\n\r\n\r\n\032\032source.*annota1.c:.*:.*:beg:$hex\r\n\r\n\032\032frame-end\r\n\r\n\032\032stopped\r\n$gdb_prompt$" \
262 { pass "send SIGUSR1" }
263 -re ".*$gdb_prompt$" { fail "send SIGUSR1" }
264 timeout { fail "send SIGUSR1 (timeout)" }
270 # annotate-signal-handler-caller
272 verbose "match_max local is: [match_max]"
273 verbose "match_max default is: [match_max -d]"
274 # This is necessary because a 2000 buffer is not enought to get everything
275 # up to the prompt ad the test gets a timeout.
277 verbose "match_max now is: [match_max]"
278 send_gdb "backtrace\n"
280 -re "frame-begin 0 $hex.*0.*frame-end.*frame-begin 1 $hex.*1.*(\032\032signal-handler-caller\r\n.signal handler called.\r\n\r\n)*\032\032frame-end\r\n\r\n\032\032frame-begin 2 $hex.*2.*(frame-begin 3 $hex.*3.*)*frame-end.*$gdb_prompt$" \
281 { pass "backtrace @ signal handler" }
282 -re ".*$gdb_prompt$" { fail "backtrace @ signal handler" }
283 timeout { fail "backtrace @ signal handler (timeout)" }
287 # delete all the breakpoints
289 send_gdb "delete 1\n"
291 -re "\r\n\032\032post-prompt\r\n$gdb_prompt$" \
292 { pass "delete bp 1" }
293 -re ".*$gdb_prompt$" { fail "delete bp 1" }
294 timeout { fail "delete bp 1 (timeout)" }
297 send_gdb "delete 2\n"
299 -re "\r\n\032\032post-prompt\r\n$gdb_prompt$" \
300 { pass "delete bp 2" }
301 -re ".*$gdb_prompt$" { fail "delete bp 2 " }
302 timeout { fail "delete bp 2 (timeout)" }
305 send_gdb "delete 3\n"
307 -re "\r\n\032\032post-prompt\r\n$gdb_prompt$" \
308 { pass "delete bp 3" }
309 -re ".*$gdb_prompt$" { fail "delete bp 3" }
310 timeout { fail "delete bp 3 (timeout)" }
314 # break at main, after value is initialized. This is in preparation
315 # to test the annotate output for the display command.
317 send_gdb "break main\n"
319 -re "post-prompt.*\032\032breakpoints-invalid.*Breakpoint 4 at $hex: file ${srcdir}/${subdir}/${srcfile}, line $main_line.*$gdb_prompt$" \
320 { pass "break at 28" }
321 -re ".*$gdb_prompt$" { fail "break at 28" }
322 timeout { fail "break at 28 (timeout)" }
326 # display the value; test:
327 # annotate-display-begin
328 # annotate-display-number-end
329 # annotate-display-format
330 # annotate-display-expression
331 # annotate-display-expression-end
332 # annotate-display-end
333 # FIXME: annotate-display-value not tested
335 send_gdb "display value\n"
337 -re "post-prompt\r\n\r\n\032\032display-begin\r\n1\r\n\032\032display-number-end\r\n: \r\n\032\032display-format\r\n\r\n\032\032display-expression\r\nvalue\r\n\032\032display-expression-end\r\n = \r\n\032\032display-expression\r\n7\r\n\r\n\032\032display-end\r\n$gdb_prompt$" \
338 { pass "set up display" }
339 -re ".*$gdb_prompt$" { fail "set up display" }
340 timeout { fail "set up display (timeout)" }
344 # should ask query. Test annotate-query.
345 # we don't care about anything else here, only the query.
349 -re "pre-query.*already.*\\(y or n\\).*query\r\n" {
352 -re ".*post-query.*$gdb_prompt$" \
354 -re ".*$gdb_prompt$" { fail "re-run" }
355 timeout { fail "re-run (timeout)" }
358 -re ".*$gdb_prompt$" { fail "re-run" }
359 timeout { fail "re-run (timeout)" }
363 # Test that breakpoints-invalid is issued once and only once for
364 # breakpoint ignore count changes, after annotation stopped.
366 send_gdb "break 46\n"
368 -re "Breakpoint 5 at $hex: file .*$srcfile, line 46.*$gdb_prompt$" {
371 -re ".*$gdb_prompt$" { fail "break at 46" }
372 timeout { fail "break at 46 (timeout)" }
375 send_gdb "ignore 5 4\n"
377 -re "Will ignore next 4 crossings of breakpoint 5.*$gdb_prompt$" {
380 -re ".*$gdb_prompt$" { fail "ignore 5 4" }
381 timeout { fail "ignore 5 4 (timeout)" }
384 send_gdb "continue\n"
386 -re ".*$srcfile:46:.*\032\032stopped\r\n\r\n\032\032breakpoints-invalid\r\n$gdb_prompt$" {
387 pass "annotate ignore count change"
389 -re ".*$gdb_prompt$" { fail "annotate ignore count change" }
390 timeout { fail "annotate ignore count change (timeout)" }
393 # check that ignore command is working, or the above can provide
394 # misleading assurance ...
398 -re "$gdb_prompt$" {}
399 timeout { fail "next to exit loop" }
404 -re ".*$srcfile:49:.*$gdb_prompt$" {
405 pass "breakpoint ignore count"
407 -re ".*$gdb_prompt$" { fail "breakpoint ignore count" }
408 timeout { fail "breakpoint ignore count (timeout)" }
412 # Send a signal that is not handled; test:
414 # annotate-signal-name
415 # annotate-signal-name-end
416 # annotate-signal-string
417 # annotate-signal-string-end
418 # FIXME: annotate-signal not tested (requires that the inferior be
419 # stopped by a "random" signal)
421 send_gdb "signal SIGTRAP\n"
423 -re ".*\032\032post-prompt\r\nContinuing with signal SIGTRAP.\r\n\r\n\032\032starting\r\n\r\n\032\032frames-invalid\r\n\r\n\032\032signalled\r\n\r\n\032\032frames-invalid\r\n\r\nProgram terminated with signal \r\n\032\032signal-name\r\nSIGTRAP\r\n\032\032signal-name-end\r\n, \r\n\032\032signal-string\r\nTrace.breakpoint trap\r\n\032\032signal-string-end\r\n.\r\nThe program no longer exists.\r\n\r\n\032\032stopped\r\n$gdb_prompt$" \
424 { pass "signal sent" }
425 -re ".*$gdb_prompt$" { fail "signal sent" }
426 timeout { fail "signal sent (timeout)" }
430 # Check for production of a core file
433 set exec_output [remote_exec build "ls core"]
435 if [ regexp "core not found" $exec_output] {
436 pass "No core dumped"
438 if [ regexp "No such file or directory" $exec_output] {
439 pass "No core dumped"
441 remote_exec build "rm -f core"
442 pass "Core dumped and removed"
447 # restore the original prompt for the rest of the testsuite
449 set gdb_prompt $old_gdb_prompt