Update copyright year range in header of all files managed by GDB
[binutils-gdb.git] / gdb / testsuite / gdb.base / annota3.exp
blob7aaf6df6deeedf15a1994b8cd13faa0e180ee477
1 # Copyright 2003-2023 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] {
23     return 0
28 # test running programs
31 standard_testfile .c
33 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
34     untested "failed to compile"
35     return -1
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"
46 # break in main
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\\." \
53     "breakpoint main"
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:
72 # annotate-pre-prompt
73 # annotate-prompt
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$" {
78     "set annotate 3"
82 # if construct:
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"
87     }
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"
93     }
97 # info break:
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:
109 #exp_internal 1
110 send_gdb "run\n"
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"
116     "\r\n"
117     "Breakpoint 1, "
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"
123 #exp_internal 0
124 #exit 0
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
131 send_gdb "next\n" 
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"
146     ".*= .1, 2, 3.\r\n"
151 # this should generate an error message, so to test:
152 # annotate-error-begin
153 # FIXME: annotate-error not tested
156 #exp_internal 1
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\]+.*"
185 # get to printf
187 send_gdb "continue\n"
188 gdb_expect_list "continue to printf" "$gdb_prompt$" {
189     "\r\n\032\032post-prompt\r\n"
190     "Continuing.\r\n"
191     "\r\n\032\032starting\r\n"
192     "\r\n\032\032breakpoint 3\r\n"
193     "\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"
213 } else {
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"
220         "\r\n"
221         "Breakpoint 2, "
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"
226     }
228     #
229     # test:
230     #
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"
237     }
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"]]
268 # display the value
270 send_gdb "display value\n"
271 gdb_expect_list "set up display" "$gdb_prompt$" {
272     "\r\n\032\032post-prompt\r\n"
273     "1: value = 7\r\n"
276 # Get the core into the output directory.
277 if {![is_remote host]} {
278     gdb_test -prompt "$gdb_prompt$" \
279         "set cwd [file dirname $binfile]" "" \
280         "set inferior cwd to test directory"
283 # should ask query. Test annotate-query.
284 # we don't care about anything else here, only the query.
286 send_gdb "run\n"
287 gdb_expect {
288   -re "pre-query.*already.*\\(y or n\\).*query\r\n" {
289          send_gdb "y\n"
290          gdb_expect {
291              -re ".*post-query.*$gdb_prompt$" \
292                      { pass "re-run" }
293              -re ".*$gdb_prompt$"  { fail "re-run" }
294              timeout { fail "re-run (timeout)" }
295          }
296      }
297   -re ".*$gdb_prompt$"  { fail "re-run" }
298   timeout { fail "re-run (timeout)" }
302 # Test that breakpoints-invalid is issued once and only once for
303 # breakpoint ignore count changes, after annotation stopped.
304 # NOTE: breakpoints-invalid annotations have been removed from
305 # level 3 but keep these tests for continuity and comparison
306 # with annota1.exp.
308 set value_inc_line [gdb_get_line_number "increment value"]
310 send_gdb "break $value_inc_line\n"
311 gdb_expect_list  "break at value++" "$gdb_prompt$" [concat {
312     "\r\n\032\032post-prompt\r\n" } [list \
313     "Breakpoint 5 at 0x\[0-9a-z\]+: file .*annota3.c, line $value_inc_line.\r\n"]]
315 send_gdb "ignore 5 4\n"
316 gdb_expect_list "ignore 5 4" "$gdb_prompt$" {
317     "\r\n\032\032post-prompt\r\n"
318     "Will ignore next 4 crossings of breakpoint 5"
319     "\r\n"
322 send_gdb "continue\n"
323 gdb_expect_list "annotate ignore count change" "$gdb_prompt$" [concat {
324     "\r\n\032\032post-prompt\r\n"
325     "\r\n\032\032breakpoint 5\r\n"
326     "\r\n"
327     "Breakpoint 5, "
328     "\r\n\032\032frame-begin 0 0x\[0-9a-z\]+\r\n" } [list \
329     "main \\(\\) at .*annota3.c:$value_inc_line\r\n"] [list \
330     "\r\n\032\032source .*annota3.c:$value_inc_line:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"] {
331     "1: value = 11\r\n"
332     "\r\n\032\032stopped\r\n"
335 # check that ignore command is working, or the above can provide
336 # misleading assurance ...
338 send_gdb "next\n"
339 gdb_expect_list "next to exit loop" "$gdb_prompt$"  {
340     "\r\n\032\032post-prompt\r\n"
341     "\r\n\032\032starting\r\n"
342     "\r\n\032\032source.*annota3.c:\[0-9\]+:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
343     "1: value = 12\r\n"
344     "\r\n\032\032stopped\r\n"
347 set after_loop_line [gdb_get_line_number "after loop"]
349 send_gdb "next\n"
350 gdb_expect_list "breakpoint ignore count" "$gdb_prompt$" [concat {
351     "\r\n\032\032post-prompt\r\n"
352     "\r\n\032\032starting\r\n" } [list \
353     "\r\n\032\032source.*annota3.c:$after_loop_line:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"] {
354     "1: value = 12\r\n"
355     "\r\n\032\032stopped\r\n"
358 # Get the inferior's PID for later.
360 set test "get inferior pid"
361 set pid -1
362 gdb_test_multiple "info inferior 1" "$test" {
363     -re "process (\[0-9\]*).*$gdb_prompt$" {
364         set pid $expect_out(1,string)
365         pass "$test"
366     }
369 # Send a signal that is not handled
371 if [target_info exists gdb,nosignals] {
372     unsupported "signal sent"
373 } else {
374     send_gdb "signal SIGTRAP\n"
375     gdb_expect_list "signal sent" "$gdb_prompt$" {
376         "\r\n\032\032post-prompt\r\n"
377         "Continuing with signal SIGTRAP.\r\n"
378         "\r\n\032\032starting\r\n"
379         "\r\n\032\032signalled\r\n"
380         "\r\nProgram terminated with signal SIGTRAP, Trace.breakpoint trap.\r\n"
381         "The program no longer exists.\r\n"
382         "\r\n\032\032stopped\r\n"
383     }
387 # Check for production of a core file and remove it!
388 remove_core $pid
390 # restore the original prompt for the rest of the testsuite
392 set gdb_prompt $old_gdb_prompt