1 # Copyright 2003-2014 Free Software Foundation, Inc.
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 3 of the License, or
6 # (at your option) any later version.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
19 # are we on a target board? If so, don't run these tests.
20 # note: this is necessary because we cannot use runto_main (which would
21 # work for remote targets too) because of the different prompt we get
22 # when using annotation level 2.
24 if [is_remote target] then {
30 # test running programs
35 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
41 clean_restart ${binfile}
43 # The commands we test here produce many lines of output; disable "press
44 # <return> to continue" prompts.
45 gdb_test_no_output "set height 0"
51 set main_line [gdb_get_line_number "break main"]
53 gdb_test "break main" \
54 "Breakpoint.*at.* file .*$srcfile, line $main_line\\." \
58 # NOTE: this prompt is OK only when the annotation level is > 1
60 # NOTE: When this prompt is in use the gdb_test procedure cannot be
61 # used because it assumes that the last char after the gdb_prompt is a
62 # white space. This is not true with this annotated prompt. So we must
63 # use send_gdb and gdb_expect or gdb_expect_list.
65 set old_gdb_prompt $gdb_prompt
66 set gdb_prompt "\r\n\032\032pre-prompt\r\n$gdb_prompt \r\n\032\032prompt\r\n"
71 # set the annotation level to 3
73 # of course, this will test:
76 # annotate-post-prompt (in the next block)
78 send_gdb "set annotate 3\n"
79 gdb_expect_list "annotation set at level 3" "\r\n$gdb_prompt$" {
86 gdb_test_multiple "if 1" "start if construct" {
87 -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$" {
88 pass "start if construct"
92 gdb_test_multiple "end" "end if construct" {
93 -re "^end\r\n\r\n\032\032post-commands\r\n$gdb_prompt$" {
94 pass "end if construct"
101 send_gdb "info break\n"
102 gdb_expect_list "breakpoint info" "$gdb_prompt$" [concat {
103 "\r\n\032\032post-prompt\r\n"
104 "Num Type Disp Enb Address +What\r\n" } [list \
105 "1 breakpoint keep y 0x\[0-9a-zA-Z\]+ +in main at .*annota3.c:$main_line\r\n"]]
109 # run to a break point will test:
113 gdb_expect_list "run until main breakpoint" "$gdb_prompt$" [concat {
114 "\r\n\032\032post-prompt\r\n"
115 "Starting program: .*annota3(|\.exe) \r\n"
116 "\r\n\032\032starting\r\n"
117 "\r\n\032\032breakpoint 1\r\n"
120 "\r\n\032\032frame-begin 0 0x\[0-9a-z\]+\r\n" } [list \
121 "main \\(\\) at .*annota3.c:$main_line\r\n"] [list \
122 "\r\n\032\032source.*annota3.c:$main_line:.*:beg:0x\[0-9a-z\]+\r\n"] {
123 "\r\n\032\032stopped\r\n"
129 # Let's do a next, to get to a point where the array is initialized
130 # We don't care about the annotated output for this operation, it is the same as
131 # the one produced by run above
134 gdb_expect_list "go after array init line" "$gdb_prompt$" {
135 "\r\n\032\032post-prompt\r\n"
136 "\r\n\032\032starting\r\n"
137 "\r\n\032\032source .*annota3.c:\[0-9\]+:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
138 "\r\n\032\032stopped\r\n"
143 # printing the array:
145 send_gdb "print my_array\n"
146 gdb_expect_list "print array" "$gdb_prompt$" {
147 "\r\n\032\032post-prompt\r\n"
153 # this should generate an error message, so to test:
154 # annotate-error-begin
155 # FIXME: annotate-error not tested
159 send_gdb "print non_existent_value\n"
160 gdb_expect_list "print non_existent_value" "$gdb_prompt$" {
161 "\r\n\032\032post-prompt\r\n"
162 "\r\n\032\032error-begin\r\n"
163 "No symbol \"non_existent_value\" in current context.\r\n"
164 "\r\n\032\032error\r\n"
169 # break at signal handler
171 send_gdb "break handle_USR1\n"
172 gdb_expect_list "breakpoint handle_USR1" "$gdb_prompt$" {
173 "\r\n\032\032post-prompt\r\n"
174 "Breakpoint.*at 0x\[0-9a-z\]+: file.*annota3.c, line.*\r\n"
178 # break at printf. When we are stopped at printf, we can test
180 send_gdb "break printf\n"
181 gdb_expect_list "breakpoint printf" "$gdb_prompt$" {
182 "\r\n\032\032post-prompt\r\n"
183 "Breakpoint.*at 0x\[0-9a-z\]+.*"
189 send_gdb "continue\n"
190 gdb_expect_list "continue to printf" "$gdb_prompt$" {
191 "\r\n\032\032post-prompt\r\n"
193 "\r\n\032\032starting\r\n"
194 "\r\n\032\032breakpoint 3\r\n"
196 "Breakpoint 3, \[^\r\n\]*\r\n"
197 "\r\n\032\032stopped\r\n"
200 send_gdb "backtrace\n"
201 gdb_expect_list "backtrace from shlibrary" "$gdb_prompt$" {
202 "\r\n\032\032post-prompt\r\n"
203 "#0 .* .*printf(@\[^ ]*)? \[^\r\n\]*\r\n"
204 "#1 .* main \[^\r\n\]*\r\n"
209 # test printing a frame with some arguments:
212 if [target_info exists gdb,nosignals] {
213 unsupported "send SIGUSR1"
214 unsupported "backtrace @ signal handler"
216 send_gdb "signal SIGUSR1\n"
217 gdb_expect_list "send SIGUSR1" "$gdb_prompt$" {
218 "\r\n\032\032post-prompt\r\n"
219 "Continuing with signal SIGUSR1.\r\n"
220 "\r\n\032\032starting\r\n"
221 "\r\n\032\032breakpoint 2\r\n"
224 "\r\n\032\032frame-begin 0 0x\[0-9a-z\]+\r\n"
225 "handle_USR1 \\(sig=\[0-9\]+\\) at .*annota3.c:\[0-9\]+\r\n"
226 "\r\n\032\032source .*annota3.c:\[0-9\]+:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
227 "\r\n\032\032stopped\r\n"
233 send_gdb "backtrace\n"
234 gdb_expect_list "backtrace @ signal handler" "$gdb_prompt$" {
235 "#0 +handle_USR1 \[^\r\n\]+\r\n"
236 "#1 +.signal handler called.\r\n"
237 "#2 .* .*printf(@\[^ \]*)? \[^\r\n\]+\r\n"
238 "#3 .* main \[^\r\n\]+\r\n"
243 # delete all the breakpoints
245 send_gdb "delete 1\n"
246 gdb_expect_list "delete bp 1" "$gdb_prompt$" {
247 "\r\n\032\032post-prompt\r\n"
250 send_gdb "delete 2\n"
251 gdb_expect_list "delete bp 2" "$gdb_prompt$" {
252 "\r\n\032\032post-prompt\r\n"
255 send_gdb "delete 3\n"
256 gdb_expect_list "delete bp 3" "$gdb_prompt$" {
257 "\r\n\032\032post-prompt\r\n"
261 # break at main, after value is initialized. This is in preparation
262 # to test the annotate output for the display command.
264 send_gdb "break main\n"
265 gdb_expect_list "break at main" "$gdb_prompt$" [concat {
266 "\r\n\032\032post-prompt\r\n" } [list \
267 "Breakpoint 4 at 0x\[0-9a-z\]+: file .*annota3.c, line $main_line.\r\n"]]
272 send_gdb "display value\n"
273 gdb_expect_list "set up display" "$gdb_prompt$" {
274 "\r\n\032\032post-prompt\r\n"
279 # should ask query. Test annotate-query.
280 # we don't care about anything else here, only the query.
284 -re "pre-query.*already.*\\(y or n\\).*query\r\n" {
287 -re ".*post-query.*$gdb_prompt$" \
289 -re ".*$gdb_prompt$" { fail "re-run" }
290 timeout { fail "re-run (timeout)" }
293 -re ".*$gdb_prompt$" { fail "re-run" }
294 timeout { fail "re-run (timeout)" }
298 # Test that breakpoints-invalid is issued once and only once for
299 # breakpoint ignore count changes, after annotation stopped.
300 # NOTE: breakpoints-invalid annotations have been removed from
301 # level 3 but keep these tests for continuity and comparison
304 set value_inc_line [gdb_get_line_number "increment value"]
306 send_gdb "break $value_inc_line\n"
307 gdb_expect_list "break at value++" "$gdb_prompt$" [concat {
308 "\r\n\032\032post-prompt\r\n" } [list \
309 "Breakpoint 5 at 0x\[0-9a-z\]+: file .*annota3.c, line $value_inc_line.\r\n"]]
311 send_gdb "ignore 5 4\n"
312 gdb_expect_list "ignore 5 4" "$gdb_prompt$" {
313 "\r\n\032\032post-prompt\r\n"
314 "Will ignore next 4 crossings of breakpoint 5"
318 send_gdb "continue\n"
319 gdb_expect_list "annotate ignore count change" "$gdb_prompt$" [concat {
320 "\r\n\032\032post-prompt\r\n"
321 "\r\n\032\032breakpoint 5\r\n"
324 "\r\n\032\032frame-begin 0 0x\[0-9a-z\]+\r\n" } [list \
325 "main \\(\\) at .*annota3.c:$value_inc_line\r\n"] [list \
326 "\r\n\032\032source .*annota3.c:$value_inc_line:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"] {
328 "\r\n\032\032stopped\r\n"
331 # check that ignore command is working, or the above can provide
332 # misleading assurance ...
335 gdb_expect_list "next to exit loop" "$gdb_prompt$" {
336 "\r\n\032\032post-prompt\r\n"
337 "\r\n\032\032starting\r\n"
338 "\r\n\032\032source.*annota3.c:\[0-9\]+:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
340 "\r\n\032\032stopped\r\n"
343 set after_loop_line [gdb_get_line_number "after loop"]
346 gdb_expect_list "breakpoint ignore count" "$gdb_prompt$" [concat {
347 "\r\n\032\032post-prompt\r\n"
348 "\r\n\032\032starting\r\n" } [list \
349 "\r\n\032\032source.*annota3.c:$after_loop_line:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"] {
351 "\r\n\032\032stopped\r\n"
354 # Get the inferior's PID for later.
356 set test "get inferior pid"
358 gdb_test_multiple "info inferior 1" "$test" {
359 -re "process (\[0-9\]*).*$gdb_prompt$" {
360 set pid $expect_out(1,string)
366 # Send a signal that is not handled
368 # SIGTRAP signals are dropped before they get to the inferior process
369 # on hpux11. In theory, this behaivor can be controlled by setting
370 # TTEO_NORM_SIGTRAP in the inferior, but doing so did not cause
371 # the signal to be properly delivered.
373 # It has been verified that other signals will be delivered. However,
374 # rather than twiddle the test, I choose to leave it as-is as it
375 # exposes an interesting failure on hpux11.
377 if [target_info exists gdb,nosignals] {
378 unsupported "signal sent"
380 setup_xfail hppa*-*-hpux11*
381 send_gdb "signal SIGTRAP\n"
382 gdb_expect_list "signal sent" "$gdb_prompt$" {
383 "\r\n\032\032post-prompt\r\n"
384 "Continuing with signal SIGTRAP.\r\n"
385 "\r\n\032\032starting\r\n"
386 "\r\n\032\032signalled\r\n"
387 "\r\nProgram terminated with signal SIGTRAP, Trace.breakpoint trap.\r\n"
388 "The program no longer exists.\r\n"
389 "\r\n\032\032stopped\r\n"
394 # Check for production of a core file and remove it!
396 set test "cleanup core file"
397 if { [remote_file host exists core] } {
398 remote_file host delete core
399 pass "$test (removed)"
400 } elseif { $pid != -1 && [remote_file host exists core.$pid] } {
401 remote_file host delete core.$pid
402 pass "$test (removed)"
404 pass "$test (not dumped)"
407 # restore the original prompt for the rest of the testsuite
409 set gdb_prompt $old_gdb_prompt