GDB copyright headers update after running GDB's copyright.py script.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / annota3.exp
CommitLineData
618f726f 1# Copyright 2003-2016 Free Software Foundation, Inc.
6009d884
AC
2
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
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
6009d884 6# (at your option) any later version.
e22f8b7c 7#
6009d884
AC
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.
e22f8b7c 12#
6009d884 13# You should have received a copy of the GNU General Public License
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
6009d884 15
6009d884
AC
16# This file was written by Elena Zannoni (ezannoni@cygnus.com)
17
6009d884
AC
18
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.
23#
24if [is_remote target] then {
25 return 0
26}
27
28
29#
30# test running programs
31#
6009d884 32
a64d2530 33standard_testfile .c
6009d884 34
fc91c6c2 35if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
b60f0898
JB
36 untested annota3.exp
37 return -1
6009d884
AC
38}
39
40
a64d2530 41clean_restart ${binfile}
6009d884 42
6009d884
AC
43# The commands we test here produce many lines of output; disable "press
44# <return> to continue" prompts.
6acb16a2 45gdb_test_no_output "set height 0"
6009d884
AC
46
47#
48# break at main
49#
2c8910ba
TS
50
51set main_line [gdb_get_line_number "break main"]
52
6009d884 53gdb_test "break main" \
2c8910ba 54 "Breakpoint.*at.* file .*$srcfile, line $main_line\\." \
6009d884
AC
55 "breakpoint main"
56
57
58# NOTE: this prompt is OK only when the annotation level is > 1
59
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.
64
65set old_gdb_prompt $gdb_prompt
66set gdb_prompt "\r\n\032\032pre-prompt\r\n$gdb_prompt \r\n\032\032prompt\r\n"
67
68
69
70#
71# set the annotation level to 3
72#
73# of course, this will test:
74# annotate-pre-prompt
75# annotate-prompt
76# annotate-post-prompt (in the next block)
77#
78send_gdb "set annotate 3\n"
79gdb_expect_list "annotation set at level 3" "\r\n$gdb_prompt$" {
80 "set annotate 3"
81}
82
1b05479a
DJ
83#
84# if construct:
85#
6acb16a2 86gdb_test_multiple "if 1" "start if construct" {
1b05479a
DJ
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"
89 }
1b05479a 90}
6acb16a2
MS
91
92gdb_test_multiple "end" "end if construct" {
1b05479a
DJ
93 -re "^end\r\n\r\n\032\032post-commands\r\n$gdb_prompt$" {
94 pass "end if construct"
95 }
1b05479a 96}
6acb16a2 97
6009d884
AC
98#
99# info break:
100#
101send_gdb "info break\n"
2c8910ba 102gdb_expect_list "breakpoint info" "$gdb_prompt$" [concat {
6009d884 103 "\r\n\032\032post-prompt\r\n"
2c8910ba
TS
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"]]
6009d884
AC
106
107
108#
109# run to a break point will test:
110#
111#exp_internal 1
112send_gdb "run\n"
2c8910ba 113gdb_expect_list "run until main breakpoint" "$gdb_prompt$" [concat {
6009d884 114 "\r\n\032\032post-prompt\r\n"
1b572db9 115 "Starting program: .*annota3(|\.exe) \r\n"
6009d884 116 "\r\n\032\032starting\r\n"
6009d884
AC
117 "\r\n\032\032breakpoint 1\r\n"
118 "\r\n"
616f635d 119 "Breakpoint 1, "
2c8910ba
TS
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"] {
6009d884 123 "\r\n\032\032stopped\r\n"
2c8910ba 124}]
6009d884
AC
125#exp_internal 0
126#exit 0
127
128#
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
132#
133send_gdb "next\n"
134gdb_expect_list "go after array init line" "$gdb_prompt$" {
135 "\r\n\032\032post-prompt\r\n"
136 "\r\n\032\032starting\r\n"
6009d884
AC
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"
139}
140
141
142#
143# printing the array:
144#
145send_gdb "print my_array\n"
146gdb_expect_list "print array" "$gdb_prompt$" {
147 "\r\n\032\032post-prompt\r\n"
148 ".*= .1, 2, 3.\r\n"
149}
150
151
152#
153# this should generate an error message, so to test:
154# annotate-error-begin
155# FIXME: annotate-error not tested
156#
157
158#exp_internal 1
159send_gdb "print non_existent_value\n"
160gdb_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"
165}
166
167
168#
169# break at signal handler
170#
171send_gdb "break handle_USR1\n"
172gdb_expect_list "breakpoint handle_USR1" "$gdb_prompt$" {
173 "\r\n\032\032post-prompt\r\n"
6009d884
AC
174 "Breakpoint.*at 0x\[0-9a-z\]+: file.*annota3.c, line.*\r\n"
175}
176
177#
178# break at printf. When we are stopped at printf, we can test
179#
180send_gdb "break printf\n"
181gdb_expect_list "breakpoint printf" "$gdb_prompt$" {
182 "\r\n\032\032post-prompt\r\n"
6009d884
AC
183 "Breakpoint.*at 0x\[0-9a-z\]+.*"
184}
185
186#
187# get to printf
188#
189send_gdb "continue\n"
190gdb_expect_list "continue to printf" "$gdb_prompt$" {
191 "\r\n\032\032post-prompt\r\n"
192 "Continuing.\r\n"
193 "\r\n\032\032starting\r\n"
6009d884
AC
194 "\r\n\032\032breakpoint 3\r\n"
195 "\r\n"
196 "Breakpoint 3, \[^\r\n\]*\r\n"
197 "\r\n\032\032stopped\r\n"
198}
199
200send_gdb "backtrace\n"
201gdb_expect_list "backtrace from shlibrary" "$gdb_prompt$" {
202 "\r\n\032\032post-prompt\r\n"
e8f97270 203 "#0 .* .*printf(@\[^ ]*)? \[^\r\n\]*\r\n"
6009d884
AC
204 "#1 .* main \[^\r\n\]*\r\n"
205}
206
207
208#
209# test printing a frame with some arguments:
210#
6009d884 211
ab618a02
MC
212if [target_info exists gdb,nosignals] {
213 unsupported "send SIGUSR1"
214 unsupported "backtrace @ signal handler"
215} else {
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"
ab618a02 221 "\r\n\032\032breakpoint 2\r\n"
616f635d
NR
222 "\r\n"
223 "Breakpoint 2, "
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"
ab618a02
MC
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"
228 }
6009d884 229
ab618a02
MC
230 #
231 # test:
232 #
ab618a02
MC
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"
e8f97270 237 "#2 .* .*printf(@\[^ \]*)? \[^\r\n\]+\r\n"
ab618a02
MC
238 "#3 .* main \[^\r\n\]+\r\n"
239 }
6009d884
AC
240}
241
242#
243# delete all the breakpoints
244#
245send_gdb "delete 1\n"
246gdb_expect_list "delete bp 1" "$gdb_prompt$" {
247 "\r\n\032\032post-prompt\r\n"
248}
249
250send_gdb "delete 2\n"
251gdb_expect_list "delete bp 2" "$gdb_prompt$" {
252 "\r\n\032\032post-prompt\r\n"
253}
254
255send_gdb "delete 3\n"
256gdb_expect_list "delete bp 3" "$gdb_prompt$" {
257 "\r\n\032\032post-prompt\r\n"
258}
259
260#
261# break at main, after value is initialized. This is in preparation
262# to test the annotate output for the display command.
263#
264send_gdb "break main\n"
2c8910ba
TS
265gdb_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"]]
6009d884
AC
268
269#
270# display the value
271#
272send_gdb "display value\n"
273gdb_expect_list "set up display" "$gdb_prompt$" {
274 "\r\n\032\032post-prompt\r\n"
275 "1: value = 7\r\n"
276}
277
278
279# should ask query. Test annotate-query.
280# we don't care about anything else here, only the query.
281
282send_gdb "run\n"
283gdb_expect {
284 -re "pre-query.*already.*\\(y or n\\).*query\r\n" {
285 send_gdb "y\n"
286 gdb_expect {
287 -re ".*post-query.*$gdb_prompt$" \
288 { pass "re-run" }
289 -re ".*$gdb_prompt$" { fail "re-run" }
290 timeout { fail "re-run (timeout)" }
291 }
292 }
293 -re ".*$gdb_prompt$" { fail "re-run" }
294 timeout { fail "re-run (timeout)" }
295}
296
297#
298# Test that breakpoints-invalid is issued once and only once for
299# breakpoint ignore count changes, after annotation stopped.
3ca42dbe
NR
300# NOTE: breakpoints-invalid annotations have been removed from
301# level 3 but keep these tests for continuity and comparison
302# with annota1.exp.
2c8910ba
TS
303
304set value_inc_line [gdb_get_line_number "increment value"]
305
306send_gdb "break $value_inc_line\n"
307gdb_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"]]
6009d884
AC
310
311send_gdb "ignore 5 4\n"
312gdb_expect_list "ignore 5 4" "$gdb_prompt$" {
313 "\r\n\032\032post-prompt\r\n"
314 "Will ignore next 4 crossings of breakpoint 5"
6009d884
AC
315 "\r\n"
316}
317
318send_gdb "continue\n"
2c8910ba 319gdb_expect_list "annotate ignore count change" "$gdb_prompt$" [concat {
6009d884 320 "\r\n\032\032post-prompt\r\n"
6009d884 321 "\r\n\032\032breakpoint 5\r\n"
616f635d
NR
322 "\r\n"
323 "Breakpoint 5, "
2c8910ba
TS
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"] {
6009d884
AC
327 "1: value = 11\r\n"
328 "\r\n\032\032stopped\r\n"
2c8910ba 329}]
6009d884
AC
330
331# check that ignore command is working, or the above can provide
332# misleading assurance ...
333
334send_gdb "next\n"
335gdb_expect_list "next to exit loop" "$gdb_prompt$" {
336 "\r\n\032\032post-prompt\r\n"
337 "\r\n\032\032starting\r\n"
6009d884
AC
338 "\r\n\032\032source.*annota3.c:\[0-9\]+:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
339 "1: value = 12\r\n"
340 "\r\n\032\032stopped\r\n"
341}
342
2c8910ba
TS
343set after_loop_line [gdb_get_line_number "after loop"]
344
6009d884 345send_gdb "next\n"
2c8910ba 346gdb_expect_list "breakpoint ignore count" "$gdb_prompt$" [concat {
6009d884 347 "\r\n\032\032post-prompt\r\n"
2c8910ba
TS
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"] {
6009d884
AC
350 "1: value = 12\r\n"
351 "\r\n\032\032stopped\r\n"
2c8910ba 352}]
6009d884 353
a391a2f6
PA
354# Get the inferior's PID for later.
355
356set test "get inferior pid"
357set pid -1
358gdb_test_multiple "info inferior 1" "$test" {
359 -re "process (\[0-9\]*).*$gdb_prompt$" {
360 set pid $expect_out(1,string)
361 pass "$test"
362 }
363}
364
6009d884 365# Send a signal that is not handled
ab618a02
MC
366
367if [target_info exists gdb,nosignals] {
368 unsupported "signal sent"
369} else {
ab618a02
MC
370 send_gdb "signal SIGTRAP\n"
371 gdb_expect_list "signal sent" "$gdb_prompt$" {
372 "\r\n\032\032post-prompt\r\n"
373 "Continuing with signal SIGTRAP.\r\n"
374 "\r\n\032\032starting\r\n"
ab618a02
MC
375 "\r\n\032\032signalled\r\n"
376 "\r\nProgram terminated with signal SIGTRAP, Trace.breakpoint trap.\r\n"
377 "The program no longer exists.\r\n"
378 "\r\n\032\032stopped\r\n"
379 }
6009d884
AC
380}
381
382
419e626b 383# Check for production of a core file and remove it!
6009d884 384
419e626b 385set test "cleanup core file"
a391a2f6
PA
386if { [remote_file host exists core] } {
387 remote_file host delete core
388 pass "$test (removed)"
389} elseif { $pid != -1 && [remote_file host exists core.$pid] } {
390 remote_file host delete core.$pid
391 pass "$test (removed)"
6009d884 392} else {
a391a2f6 393 pass "$test (not dumped)"
6009d884
AC
394}
395
396# restore the original prompt for the rest of the testsuite
397
398set gdb_prompt $old_gdb_prompt
This page took 1.287357 seconds and 4 git commands to generate.