1 # Copyright 2003-2019 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 # This testcase cannot use runto_main because of the different prompt
20 # we get when using annotation level 2.
22 if ![target_can_use_run_cmd] {
28 # test running programs
33 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
34 untested "failed to compile"
39 clean_restart ${binfile}
41 # The commands we test here produce many lines of output; disable "press
42 # <return> to continue" prompts.
43 gdb_test_no_output "set height 0"
49 set main_line [gdb_get_line_number "break main"]
51 gdb_test "break ${srcfile}:${main_line}" \
52 "Breakpoint.*at.* file .*$srcfile, line $main_line\\." \
56 # NOTE: this prompt is OK only when the annotation level is > 1
58 # NOTE: When this prompt is in use the gdb_test procedure cannot be
59 # used because it assumes that the last char after the gdb_prompt is a
60 # white space. This is not true with this annotated prompt. So we must
61 # use send_gdb and gdb_expect or gdb_expect_list.
63 set old_gdb_prompt $gdb_prompt
64 set gdb_prompt "\r\n\032\032pre-prompt\r\n$gdb_prompt \r\n\032\032prompt\r\n"
69 # set the annotation level to 3
71 # of course, this will test:
74 # annotate-post-prompt (in the next block)
76 send_gdb "set annotate 3\n"
77 gdb_expect_list "annotation set at level 3" "\r\n$gdb_prompt$" {
84 gdb_test_multiple "if 1" "start if construct" {
85 -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$" {
86 pass "start if construct"
90 gdb_test_multiple "end" "end if construct" {
91 -re "^end\r\n\r\n\032\032post-commands\r\n$gdb_prompt$" {
92 pass "end if construct"
99 send_gdb "info break\n"
100 gdb_expect_list "breakpoint info" "$gdb_prompt$" [concat {
101 "\r\n\032\032post-prompt\r\n"
102 "Num Type Disp Enb Address +What\r\n" } [list \
103 "1 breakpoint keep y 0x\[0-9a-zA-Z\]+ +in main at .*annota3.c:$main_line\r\n"]]
107 # run to a break point will test:
111 gdb_expect_list "run until main breakpoint" "$gdb_prompt$" [concat {
112 "\r\n\032\032post-prompt\r\n"
113 "Starting program: .*annota3(|\.exe) \r\n"
114 "\r\n\032\032starting\r\n"
115 "\r\n\032\032breakpoint 1\r\n"
118 "\r\n\032\032frame-begin 0 0x\[0-9a-z\]+\r\n" } [list \
119 "main \\(\\) at .*annota3.c:$main_line\r\n"] [list \
120 "\r\n\032\032source.*annota3.c:$main_line:.*:beg:0x\[0-9a-z\]+\r\n"] {
121 "\r\n\032\032stopped\r\n"
127 # Let's do a next, to get to a point where the array is initialized
128 # We don't care about the annotated output for this operation, it is the same as
129 # the one produced by run above
132 gdb_expect_list "go after array init line" "$gdb_prompt$" {
133 "\r\n\032\032post-prompt\r\n"
134 "\r\n\032\032starting\r\n"
135 "\r\n\032\032source .*annota3.c:\[0-9\]+:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
136 "\r\n\032\032stopped\r\n"
141 # printing the array:
143 send_gdb "print my_array\n"
144 gdb_expect_list "print array" "$gdb_prompt$" {
145 "\r\n\032\032post-prompt\r\n"
151 # this should generate an error message, so to test:
152 # annotate-error-begin
153 # FIXME: annotate-error not tested
157 send_gdb "print non_existent_value\n"
158 gdb_expect_list "print non_existent_value" "$gdb_prompt$" {
159 "\r\n\032\032post-prompt\r\n"
160 "\r\n\032\032error-begin\r\n"
161 "No symbol \"non_existent_value\" in current context.\r\n"
162 "\r\n\032\032error\r\n"
167 # break at signal handler
169 send_gdb "break handle_USR1\n"
170 gdb_expect_list "breakpoint handle_USR1" "$gdb_prompt$" {
171 "\r\n\032\032post-prompt\r\n"
172 "Breakpoint.*at 0x\[0-9a-z\]+: file.*annota3.c, line.*\r\n"
176 # break at printf. When we are stopped at printf, we can test
178 send_gdb "break printf\n"
179 gdb_expect_list "breakpoint printf" "$gdb_prompt$" {
180 "\r\n\032\032post-prompt\r\n"
181 "Breakpoint.*at 0x\[0-9a-z\]+.*"
187 send_gdb "continue\n"
188 gdb_expect_list "continue to printf" "$gdb_prompt$" {
189 "\r\n\032\032post-prompt\r\n"
191 "\r\n\032\032starting\r\n"
192 "\r\n\032\032breakpoint 3\r\n"
194 "Breakpoint 3, \[^\r\n\]*\r\n"
195 "\r\n\032\032stopped\r\n"
198 send_gdb "backtrace\n"
199 gdb_expect_list "backtrace from shlibrary" "$gdb_prompt$" {
200 "\r\n\032\032post-prompt\r\n"
201 "#0 .* .*printf(@\[^ ]*)? \[^\r\n\]*\r\n"
202 "#1 .* main \[^\r\n\]*\r\n"
207 # test printing a frame with some arguments:
210 if [target_info exists gdb,nosignals] {
211 unsupported "send SIGUSR1"
212 unsupported "backtrace @ signal handler"
214 send_gdb "signal SIGUSR1\n"
215 gdb_expect_list "send SIGUSR1" "$gdb_prompt$" {
216 "\r\n\032\032post-prompt\r\n"
217 "Continuing with signal SIGUSR1.\r\n"
218 "\r\n\032\032starting\r\n"
219 "\r\n\032\032breakpoint 2\r\n"
222 "\r\n\032\032frame-begin 0 0x\[0-9a-z\]+\r\n"
223 "handle_USR1 \\(sig=\[0-9\]+\\) at .*annota3.c:\[0-9\]+\r\n"
224 "\r\n\032\032source .*annota3.c:\[0-9\]+:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
225 "\r\n\032\032stopped\r\n"
231 send_gdb "backtrace\n"
232 gdb_expect_list "backtrace @ signal handler" "$gdb_prompt$" {
233 "#0 +handle_USR1 \[^\r\n\]+\r\n"
234 "#1 +.signal handler called.\r\n"
235 "#2 .* .*printf(@\[^ \]*)? \[^\r\n\]+\r\n"
236 "#3 .* main \[^\r\n\]+\r\n"
241 # delete all the breakpoints
243 send_gdb "delete 1\n"
244 gdb_expect_list "delete bp 1" "$gdb_prompt$" {
245 "\r\n\032\032post-prompt\r\n"
248 send_gdb "delete 2\n"
249 gdb_expect_list "delete bp 2" "$gdb_prompt$" {
250 "\r\n\032\032post-prompt\r\n"
253 send_gdb "delete 3\n"
254 gdb_expect_list "delete bp 3" "$gdb_prompt$" {
255 "\r\n\032\032post-prompt\r\n"
259 # break in main, after value is initialized. This is in preparation
260 # to test the annotate output for the display command.
262 send_gdb "break ${srcfile}:${main_line}\n"
263 gdb_expect_list "break in main" "$gdb_prompt$" [concat {
264 "\r\n\032\032post-prompt\r\n" } [list \
265 "Breakpoint 4 at 0x\[0-9a-z\]+: file .*annota3.c, line $main_line.\r\n"]]
270 send_gdb "display value\n"
271 gdb_expect_list "set up display" "$gdb_prompt$" {
272 "\r\n\032\032post-prompt\r\n"
277 # should ask query. Test annotate-query.
278 # we don't care about anything else here, only the query.
282 -re "pre-query.*already.*\\(y or n\\).*query\r\n" {
285 -re ".*post-query.*$gdb_prompt$" \
287 -re ".*$gdb_prompt$" { fail "re-run" }
288 timeout { fail "re-run (timeout)" }
291 -re ".*$gdb_prompt$" { fail "re-run" }
292 timeout { fail "re-run (timeout)" }
296 # Test that breakpoints-invalid is issued once and only once for
297 # breakpoint ignore count changes, after annotation stopped.
298 # NOTE: breakpoints-invalid annotations have been removed from
299 # level 3 but keep these tests for continuity and comparison
302 set value_inc_line [gdb_get_line_number "increment value"]
304 send_gdb "break $value_inc_line\n"
305 gdb_expect_list "break at value++" "$gdb_prompt$" [concat {
306 "\r\n\032\032post-prompt\r\n" } [list \
307 "Breakpoint 5 at 0x\[0-9a-z\]+: file .*annota3.c, line $value_inc_line.\r\n"]]
309 send_gdb "ignore 5 4\n"
310 gdb_expect_list "ignore 5 4" "$gdb_prompt$" {
311 "\r\n\032\032post-prompt\r\n"
312 "Will ignore next 4 crossings of breakpoint 5"
316 send_gdb "continue\n"
317 gdb_expect_list "annotate ignore count change" "$gdb_prompt$" [concat {
318 "\r\n\032\032post-prompt\r\n"
319 "\r\n\032\032breakpoint 5\r\n"
322 "\r\n\032\032frame-begin 0 0x\[0-9a-z\]+\r\n" } [list \
323 "main \\(\\) at .*annota3.c:$value_inc_line\r\n"] [list \
324 "\r\n\032\032source .*annota3.c:$value_inc_line:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"] {
326 "\r\n\032\032stopped\r\n"
329 # check that ignore command is working, or the above can provide
330 # misleading assurance ...
333 gdb_expect_list "next to exit loop" "$gdb_prompt$" {
334 "\r\n\032\032post-prompt\r\n"
335 "\r\n\032\032starting\r\n"
336 "\r\n\032\032source.*annota3.c:\[0-9\]+:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
338 "\r\n\032\032stopped\r\n"
341 set after_loop_line [gdb_get_line_number "after loop"]
344 gdb_expect_list "breakpoint ignore count" "$gdb_prompt$" [concat {
345 "\r\n\032\032post-prompt\r\n"
346 "\r\n\032\032starting\r\n" } [list \
347 "\r\n\032\032source.*annota3.c:$after_loop_line:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"] {
349 "\r\n\032\032stopped\r\n"
352 # Get the inferior's PID for later.
354 set test "get inferior pid"
356 gdb_test_multiple "info inferior 1" "$test" {
357 -re "process (\[0-9\]*).*$gdb_prompt$" {
358 set pid $expect_out(1,string)
363 # Send a signal that is not handled
365 if [target_info exists gdb,nosignals] {
366 unsupported "signal sent"
368 send_gdb "signal SIGTRAP\n"
369 gdb_expect_list "signal sent" "$gdb_prompt$" {
370 "\r\n\032\032post-prompt\r\n"
371 "Continuing with signal SIGTRAP.\r\n"
372 "\r\n\032\032starting\r\n"
373 "\r\n\032\032signalled\r\n"
374 "\r\nProgram terminated with signal SIGTRAP, Trace.breakpoint trap.\r\n"
375 "The program no longer exists.\r\n"
376 "\r\n\032\032stopped\r\n"
381 # Check for production of a core file and remove it!
383 set test "cleanup core file"
384 if { [remote_file host exists core] } {
385 remote_file host delete core
386 pass "$test (removed)"
387 } elseif { $pid != -1 && [remote_file host exists core.$pid] } {
388 remote_file host delete core.$pid
389 pass "$test (removed)"
391 pass "$test (not dumped)"
394 # restore the original prompt for the rest of the testsuite
396 set gdb_prompt $old_gdb_prompt