1 # Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
2 # 2010 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 3 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, see <http://www.gnu.org/licenses/>.
17 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
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.
29 if [is_remote target] then {
35 # test running programs
38 set testfile "annota1"
39 set srcfile ${testfile}.c
40 set binfile ${objdir}/${subdir}/${testfile}
42 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
50 gdb_reinitialize_dir $srcdir/$subdir
53 if [target_info exists gdb_stub] {
58 # the line at which break main will put the breakpoint
62 # The commands we test here produce many lines of output; disable "press
63 # <return> to continue" prompts.
64 send_gdb "set height 0\n"
65 gdb_expect -re "$gdb_prompt $"
70 gdb_test "break main" \
71 "Breakpoint.*at.* file .*$srcfile, line.*" \
76 # NOTE: this prompt is OK only when the annotation level is > 1
77 # NOTE: When this prompt is in use the gdb_test procedure cannot be used because
78 # it assumes that the last char after the gdb_prompt is a white space. This is not
79 # true with this annotated prompt. So we must use send_gdb and gdb_expect.
82 set old_gdb_prompt $gdb_prompt
83 set gdb_prompt "\r\n\032\032pre-prompt\r\n$gdb_prompt \r\n\032\032prompt\r\n"
86 # Escape all the characters in the path that need it. For instance
87 # the directory name could contain '+'.
89 set escapedsrcfile [string_to_regexp ${srcdir}/${subdir}/${srcfile}]
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 ${escapedsrcfile}:$main_line\r\n\r\n\032\032breakpoints-table-end\r\n$gdb_prompt$" \
119 {pass "breakpoint info"}
120 -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 .*${srcfile}:$main_line\r\n\r\n\032\032breakpoints-table-end\r\n$gdb_prompt$" \
121 { setup_xfail "*-*-*" 1270
122 fail "breakpoint info"}
123 -re ".*$gdb_prompt$" { fail "breakpoint info" }
124 timeout { fail "breakpoint info (timeout)" }
129 # run to a break point will test:
130 # annotate-frames-invalid
131 # annotate-breakpoints-invalid (a.k.a. breakpoints-changed)
133 # annotate-breakpoint
134 # annotate-frame-begin
135 # annotate-frame-function-name
136 # annotate-frame-args
137 # annotate-frame-source-begin
138 # annotate-frame-source-file
139 # annotate-frame-source-file-end
140 # annotate-frame-source-line
141 # annotate-frame-source-end
147 set binexp [string_to_regexp $binfile]
150 -re "\r\n\032\032post-prompt\r\nStarting program: $binexp \(\(\r\n\r\n\032\032frames-invalid\)|\(\r\n\r\n\032\032breakpoints-invalid\)\)+\r\n\r\n\032\032starting\(\(\r\n\r\n\032\032frames-invalid\)|\(\r\n\r\n\032\032breakpoints-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.*$gdb_prompt$" {
151 pass "run until main breakpoint"
153 -re ".*$gdb_prompt$" {
154 fail "run until main breakpoint"
157 fail "run until main breakpoint (timeout)"
164 # Let's do a next, to get to a point where the array is initialized
165 # We don't care about the annotated output for this operation, it is the same as
166 # the one produced by run above
170 -re ".*$gdb_prompt$" { pass "go after array init line" }
171 timeout { fail "go after array init line (timeout)" }
176 # printing the array will test:
177 # annotate-value-history-begin
178 # annotate-value-history-value
179 # annotate-array-section-begin
181 # FIXME: annotate-elt-rep and annotate-elt-rep-end not tested
182 # annotate-array-section-end
183 # annotate-value-history-end
184 # FIXME: annotate-value-begin and annotate-value-end not tested (the gdb output
185 # command would cause them to be used)
187 send_gdb "print my_array\n"
189 -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$" \
190 { pass "print array" }
191 -re ".*$gdb_prompt$" { fail "print array" }
192 timeout { fail "print array (timeout)" }
197 # this should generate an error message, so to test:
198 # annotate-error-begin
199 # FIXME: annotate-error not tested
203 send_gdb "print non_existent_value\n"
205 -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$" \
206 { pass "print non_existent_value" }
207 -re ".*$gdb_prompt$" { fail "print non_existent_value" }
208 timeout { fail "print non_existent_value (timeout)" }
213 # break at signal handler. So that, once we are in the sig handler, if we do a bt
214 # we can test annotate-signal-handler-caller
216 send_gdb "break handle_USR1\n"
218 -re "\r\n\032\032post-prompt\r\n\r\n\032\032breakpoints-invalid\r\nBreakpoint.*at $hex: file.*$srcfile, line.*\r\n$gdb_prompt$" \
219 { pass "break handle_USR1" }
220 -re ".*$gdb_prompt$" { fail "break handle_USR1" }
221 timeout { fail "break handle_USR1 (timeout)" }
225 # break at printf. When we are stopped at printf, we can test
227 send_gdb "break printf\n"
229 -re "\r\n\032\032post-prompt\r\n\r\n\032\032breakpoints-invalid\r\nBreakpoint.*at $hex.*$gdb_prompt$" \
230 { pass "break printf" }
231 -re "\r\n\032\032post-prompt\r\nwarning: Breakpoint address adjusted from $hex to $hex.\r\n\r\n\032\032breakpoints-invalid\r\nBreakpoint.*at $hex.*$gdb_prompt$" \
232 { pass "break printf" }
233 -re ".*$gdb_prompt$" { fail "break printf" }
234 timeout { fail "break printf (timeout)" }
240 set pat_begin "\r\n\032\032post-prompt\r\nContinuing.\r\n\r\n\032\032starting\(\r\n\r\n\032\032frames-invalid\)+\r\n"
241 set pat_adjust "warning: Breakpoint 3 address previously adjusted from $hex to $hex.\r\n"
242 set pat_end "\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\n.*printf(@.*)?\r\n\032\032frame-args\r\n.*\032\032frame-end\r\n\r\n\032\032stopped\r\n$gdb_prompt$"
244 gdb_test_multiple "continue" "continue to printf" {
245 -re "${pat_begin}($pat_adjust)?$pat_end" {
246 pass "continue to printf"
248 -re ".*$gdb_prompt$" { fail "continue to printf" }
253 # annotate-frame-where
254 # annotate-frame-address
255 # annotate-frame-address-end
257 set pat_begin "\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\n.*printf(@.*)?\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"
258 set pat_end "\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(\r\n\032\032frame-begin .*\r\n\r\n\032\032frame-end\r\n)*$gdb_prompt$"
259 send_gdb "backtrace\n"
261 -re "$pat_begin$escapedsrcfile$pat_end"
262 { pass "backtrace from shlibrary" }
263 -re "$pat_begin.*$srcfile$pat_end"
264 { setup_xfail "*-*-*" 1270
265 fail "backtrace from shlibrary" }
266 -re ".*$gdb_prompt$" { fail "backtrace from shlibrary" }
267 timeout { fail "backtrace from shlibrary (timeout)" }
272 # test printing a frame with some arguments:
274 # annotate-arg-name-end
279 if [target_info exists gdb,nosignals] {
280 unsupported "send SIGUSR1"
281 unsupported "backtrace @ signal handler"
283 send_gdb "signal SIGUSR1\n"
285 -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${escapedsrcfile}\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$" \
286 { pass "send SIGUSR1" }
287 -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.*${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$" \
288 { setup_xfail "*-*-*" 1270
289 fail "send SIGUSR1" }
290 -re ".*$gdb_prompt$" { fail "send SIGUSR1" }
291 timeout { fail "send SIGUSR1 (timeout)" }
296 # annotate-signal-handler-caller
298 send_gdb "backtrace\n"
300 -re "frame-begin 0 $hex\r\n#0.*frame-end.*frame-begin 1 $hex\r\n#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\r\n#2.*(frame-begin 3 $hex\r\n#3.*)*frame-end.*$gdb_prompt$" {
301 pass "backtrace @ signal handler"
303 -re ".*$gdb_prompt$" { fail "backtrace @ signal handler" }
304 timeout { fail "backtrace @ signal handler (timeout)" }
309 # delete all the breakpoints
311 send_gdb "delete 1\n"
313 -re "\r\n\032\032post-prompt\r\n$gdb_prompt$" \
314 { pass "delete bp 1" }
315 -re ".*$gdb_prompt$" { fail "delete bp 1" }
316 timeout { fail "delete bp 1 (timeout)" }
319 send_gdb "delete 2\n"
321 -re "\r\n\032\032post-prompt\r\n$gdb_prompt$" \
322 { pass "delete bp 2" }
323 -re ".*$gdb_prompt$" { fail "delete bp 2 " }
324 timeout { fail "delete bp 2 (timeout)" }
327 send_gdb "delete 3\n"
329 -re "\r\n\032\032post-prompt\r\n$gdb_prompt$" \
330 { pass "delete bp 3" }
331 -re ".*$gdb_prompt$" { fail "delete bp 3" }
332 timeout { fail "delete bp 3 (timeout)" }
336 # break at main, after value is initialized. This is in preparation
337 # to test the annotate output for the display command.
339 send_gdb "break main\n"
341 -re "post-prompt.*\032\032breakpoints-invalid.*Breakpoint 4 at $hex: file ${escapedsrcfile}, line $main_line.*$gdb_prompt$" \
342 { pass "break at 28" }
343 -re "post-prompt.*\032\032breakpoints-invalid.*Breakpoint 4 at $hex: file .*${srcfile}, line $main_line.*$gdb_prompt$" \
344 { setup_xfail "*-*-*" 1270
346 -re ".*$gdb_prompt$" { fail "break at 28" }
347 timeout { fail "break at 28 (timeout)" }
351 # display the value; test:
352 # annotate-display-begin
353 # annotate-display-number-end
354 # annotate-display-format
355 # annotate-display-expression
356 # annotate-display-expression-end
357 # annotate-display-end
358 # FIXME: annotate-display-value not tested
360 send_gdb "display value\n"
362 -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$" \
363 { pass "set up display" }
364 -re ".*$gdb_prompt$" { fail "set up display" }
365 timeout { fail "set up display (timeout)" }
369 # should ask query. Test annotate-query.
370 # we don't care about anything else here, only the query.
374 -re "pre-query.*already.*\\(y or n\\).*query\r\n" {
377 -re ".*post-query.*$gdb_prompt$" \
379 -re ".*$gdb_prompt$" { fail "re-run" }
380 timeout { fail "re-run (timeout)" }
383 -re ".*$gdb_prompt$" { fail "re-run" }
384 timeout { fail "re-run (timeout)" }
388 # Test that breakpoints-invalid is issued once and only once for
389 # breakpoint ignore count changes, after annotation stopped.
391 send_gdb "break 46\n"
393 -re "Breakpoint 5 at $hex: file .*$srcfile, line 46.*$gdb_prompt$" {
396 -re ".*$gdb_prompt$" { fail "break at 46" }
397 timeout { fail "break at 46 (timeout)" }
400 send_gdb "ignore 5 4\n"
402 -re "Will ignore next 4 crossings of breakpoint 5.*$gdb_prompt$" {
405 -re ".*$gdb_prompt$" { fail "ignore 5 4" }
406 timeout { fail "ignore 5 4 (timeout)" }
409 send_gdb "continue\n"
411 -re ".*$srcfile:46:.*\032\032stopped\r\n\r\n\032\032breakpoints-invalid\r\n$gdb_prompt$" {
412 pass "annotate ignore count change"
414 -re ".*$gdb_prompt$" { fail "annotate ignore count change" }
415 timeout { fail "annotate ignore count change (timeout)" }
418 # check that ignore command is working, or the above can provide
419 # misleading assurance ...
423 -re "$gdb_prompt$" {}
424 timeout { fail "next to exit loop" }
429 -re ".*$srcfile:49:.*$gdb_prompt$" {
430 pass "breakpoint ignore count"
432 -re ".*$gdb_prompt$" { fail "breakpoint ignore count" }
433 timeout { fail "breakpoint ignore count (timeout)" }
437 # Send a signal that is not handled; test:
439 # annotate-signal-name
440 # annotate-signal-name-end
441 # annotate-signal-string
442 # annotate-signal-string-end
443 # FIXME: annotate-signal not tested (requires that the inferior be
444 # stopped by a "random" signal)
446 # SIGTRAP signals are dropped before they get to the inferior process
447 # on hpux11. In theory, this behaivor can be controlled by setting
448 # TTEO_NORM_SIGTRAP in the inferior, but doing so did not cause
449 # the signal to be properly delivered.
451 # It has been verified that other signals will be delivered. However,
452 # rather than twiddle the test, I choose to leave it as-is as it
453 # exposes an interesting failure on hpux11.
455 if [target_info exists gdb,nosignals] {
456 unsupported "signal sent"
458 setup_xfail hppa*-*-hpux11*
459 send_gdb "signal SIGTRAP\n"
461 -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\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$" \
462 { pass "signal sent" }
463 -re ".*$gdb_prompt$" { fail "signal sent" }
464 timeout { fail "signal sent (timeout)" }
469 # Check for production of a core file and remove it!
471 set exec_output [remote_exec build "ls core"]
473 set test "cleanup core file"
474 if [ regexp "core not found" $exec_output] {
475 pass "$test (not dumped)"
477 if [ regexp "No such file or directory" $exec_output] {
478 pass "$test (not dumped)"
480 remote_exec build "rm -f core"
481 pass "$test (removed)"
485 proc thread_test {} {
486 global objdir subdir srcdir testfile
487 global gdb_prompt old_gdb_prompt
488 set srcfile watch_thread_num.c
489 set binfile ${objdir}/${subdir}/${testfile}-watch_thread_num
490 set gdb_prompt $old_gdb_prompt
492 if { ![get_compiler_info ${binfile}] && [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] == "" } {
496 gdb_reinitialize_dir $srcdir/$subdir
498 if { ![runto main] } then {
504 "\r\n\032\032pre-prompt\r\n$gdb_prompt \r\n\032\032prompt\r\n"
506 send_gdb "set annotate 2\n"
508 -re "set annotate 2\r\n$gdb_prompt$" {}
513 -re ".*\032\032new-thread" {
516 timeout { fail "new thread (timeout)" }
521 proc thread_switch {} {
522 send_gdb "thread 1\n"
524 -re ".*\032\032thread-changed" {
527 timeout { fail "thread switch (timeout)" }
534 # restore the original prompt for the rest of the testsuite
536 set gdb_prompt $old_gdb_prompt