gdb/testsuite/
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / annota3.exp
CommitLineData
0fb0cc75
JB
1# Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009
2# Free Software Foundation, Inc.
6009d884
AC
3
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
e22f8b7c 6# the Free Software Foundation; either version 3 of the License, or
6009d884 7# (at your option) any later version.
e22f8b7c 8#
6009d884
AC
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.
e22f8b7c 13#
6009d884 14# You should have received a copy of the GNU General Public License
e22f8b7c 15# along with this program. If not, see <http://www.gnu.org/licenses/>.
6009d884 16
6009d884
AC
17# This file was written by Elena Zannoni (ezannoni@cygnus.com)
18
19if $tracelevel then {
20 strace $tracelevel
21}
22
23
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.
28#
29if [is_remote target] then {
30 return 0
31}
32
33
34#
35# test running programs
36#
37set prms_id 0
38set bug_id 0
39
40set testfile "annota3"
41set srcfile ${testfile}.c
1b572db9 42set binfile ${objdir}/${subdir}/${testfile}$EXEEXT
6009d884 43
fc91c6c2 44if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
b60f0898
JB
45 untested annota3.exp
46 return -1
6009d884
AC
47}
48
49
50gdb_exit
51gdb_start
52gdb_reinitialize_dir $srcdir/$subdir
53gdb_load ${binfile}
54
55if [target_info exists gdb_stub] {
56 gdb_step_for_stub;
57}
58
59#
60# the line at which break main will put the breakpoint
61#
62set main_line 32
63
64# The commands we test here produce many lines of output; disable "press
65# <return> to continue" prompts.
66send_gdb "set height 0\n"
67gdb_expect -re "$gdb_prompt $"
68
69#
70# break at main
71#
72gdb_test "break main" \
73 "Breakpoint.*at.* file .*$srcfile, line.*" \
74 "breakpoint main"
75
76
77# NOTE: this prompt is OK only when the annotation level is > 1
78
79# NOTE: When this prompt is in use the gdb_test procedure cannot be
80# used because it assumes that the last char after the gdb_prompt is a
81# white space. This is not true with this annotated prompt. So we must
82# use send_gdb and gdb_expect or gdb_expect_list.
83
84set old_gdb_prompt $gdb_prompt
85set gdb_prompt "\r\n\032\032pre-prompt\r\n$gdb_prompt \r\n\032\032prompt\r\n"
86
87
88
89#
90# set the annotation level to 3
91#
92# of course, this will test:
93# annotate-pre-prompt
94# annotate-prompt
95# annotate-post-prompt (in the next block)
96#
97send_gdb "set annotate 3\n"
98gdb_expect_list "annotation set at level 3" "\r\n$gdb_prompt$" {
99 "set annotate 3"
100}
101
1b05479a
DJ
102#
103# if construct:
104#
105send_gdb "if 1\n"
106gdb_expect {
107 -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$" {
108 pass "start if construct"
109 }
110 -re ".*\032\032commands\r\n" {
111 fail "start if construct"
112 }
113 timeout { fail "start if construct (timeout)" }
114}
115send_gdb "end\n"
116gdb_expect {
117 -re "^end\r\n\r\n\032\032post-commands\r\n$gdb_prompt$" {
118 pass "end if construct"
119 }
120 -re ".*$gdb_prompt$" {
121 fail "end if construct"
122 }
123 timeout { fail "end if construct (timeout)" }
124}
6009d884
AC
125#
126# info break:
127#
128send_gdb "info break\n"
129gdb_expect_list "breakpoint info" "$gdb_prompt$" {
130 "\r\n\032\032post-prompt\r\n"
54e52265
VP
131 "Num Type Disp Enb Address +What\r\n"
132 "1 breakpoint keep y 0x\[0-9a-zA-Z\]+ +in main at .*annota3.c:32\r\n"
6009d884
AC
133}
134
135
136#
137# run to a break point will test:
138#
139#exp_internal 1
140send_gdb "run\n"
141gdb_expect_list "run until main breakpoint" "$gdb_prompt$" {
142 "\r\n\032\032post-prompt\r\n"
1b572db9 143 "Starting program: .*annota3(|\.exe) \r\n"
6009d884 144 "\r\n\032\032starting\r\n"
6009d884
AC
145 "\r\n\032\032breakpoint 1\r\n"
146 "\r\n"
616f635d
NR
147 "Breakpoint 1, "
148 "\r\n\032\032frame-begin 0 0x\[0-9a-z\]+\r\n"
149 "main \\(\\) at .*annota3.c:32\r\n"
6009d884
AC
150 "\r\n\032\032source.*annota3.c:32:.*:beg:0x\[0-9a-z\]+\r\n"
151 "\r\n\032\032stopped\r\n"
152}
153#exp_internal 0
154#exit 0
155
156#
157# Let's do a next, to get to a point where the array is initialized
158# We don't care about the annotated output for this operation, it is the same as
159# the one produced by run above
160#
161send_gdb "next\n"
162gdb_expect_list "go after array init line" "$gdb_prompt$" {
163 "\r\n\032\032post-prompt\r\n"
164 "\r\n\032\032starting\r\n"
6009d884
AC
165 "\r\n\032\032source .*annota3.c:\[0-9\]+:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
166 "\r\n\032\032stopped\r\n"
167}
168
169
170#
171# printing the array:
172#
173send_gdb "print my_array\n"
174gdb_expect_list "print array" "$gdb_prompt$" {
175 "\r\n\032\032post-prompt\r\n"
176 ".*= .1, 2, 3.\r\n"
177}
178
179
180#
181# this should generate an error message, so to test:
182# annotate-error-begin
183# FIXME: annotate-error not tested
184#
185
186#exp_internal 1
187send_gdb "print non_existent_value\n"
188gdb_expect_list "print non_existent_value" "$gdb_prompt$" {
189 "\r\n\032\032post-prompt\r\n"
190 "\r\n\032\032error-begin\r\n"
191 "No symbol \"non_existent_value\" in current context.\r\n"
192 "\r\n\032\032error\r\n"
193}
194
195
196#
197# break at signal handler
198#
199send_gdb "break handle_USR1\n"
200gdb_expect_list "breakpoint handle_USR1" "$gdb_prompt$" {
201 "\r\n\032\032post-prompt\r\n"
6009d884
AC
202 "Breakpoint.*at 0x\[0-9a-z\]+: file.*annota3.c, line.*\r\n"
203}
204
205#
206# break at printf. When we are stopped at printf, we can test
207#
208send_gdb "break printf\n"
209gdb_expect_list "breakpoint printf" "$gdb_prompt$" {
210 "\r\n\032\032post-prompt\r\n"
6009d884
AC
211 "Breakpoint.*at 0x\[0-9a-z\]+.*"
212}
213
214#
215# get to printf
216#
217send_gdb "continue\n"
218gdb_expect_list "continue to printf" "$gdb_prompt$" {
219 "\r\n\032\032post-prompt\r\n"
220 "Continuing.\r\n"
221 "\r\n\032\032starting\r\n"
6009d884
AC
222 "\r\n\032\032breakpoint 3\r\n"
223 "\r\n"
224 "Breakpoint 3, \[^\r\n\]*\r\n"
225 "\r\n\032\032stopped\r\n"
226}
227
228send_gdb "backtrace\n"
229gdb_expect_list "backtrace from shlibrary" "$gdb_prompt$" {
230 "\r\n\032\032post-prompt\r\n"
e8f97270 231 "#0 .* .*printf(@\[^ ]*)? \[^\r\n\]*\r\n"
6009d884
AC
232 "#1 .* main \[^\r\n\]*\r\n"
233}
234
235
236#
237# test printing a frame with some arguments:
238#
6009d884 239
ab618a02
MC
240if [target_info exists gdb,nosignals] {
241 unsupported "send SIGUSR1"
242 unsupported "backtrace @ signal handler"
243} else {
244 send_gdb "signal SIGUSR1\n"
245 gdb_expect_list "send SIGUSR1" "$gdb_prompt$" {
246 "\r\n\032\032post-prompt\r\n"
247 "Continuing with signal SIGUSR1.\r\n"
248 "\r\n\032\032starting\r\n"
ab618a02 249 "\r\n\032\032breakpoint 2\r\n"
616f635d
NR
250 "\r\n"
251 "Breakpoint 2, "
252 "\r\n\032\032frame-begin 0 0x\[0-9a-z\]+\r\n"
253 "handle_USR1 \\(sig=\[0-9\]+\\) at .*annota3.c:\[0-9\]+\r\n"
ab618a02
MC
254 "\r\n\032\032source .*annota3.c:\[0-9\]+:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
255 "\r\n\032\032stopped\r\n"
256 }
6009d884 257
ab618a02
MC
258 #
259 # test:
260 #
ab618a02
MC
261 send_gdb "backtrace\n"
262 gdb_expect_list "backtrace @ signal handler" "$gdb_prompt$" {
263 "#0 +handle_USR1 \[^\r\n\]+\r\n"
264 "#1 +.signal handler called.\r\n"
e8f97270 265 "#2 .* .*printf(@\[^ \]*)? \[^\r\n\]+\r\n"
ab618a02
MC
266 "#3 .* main \[^\r\n\]+\r\n"
267 }
6009d884
AC
268}
269
270#
271# delete all the breakpoints
272#
273send_gdb "delete 1\n"
274gdb_expect_list "delete bp 1" "$gdb_prompt$" {
275 "\r\n\032\032post-prompt\r\n"
276}
277
278send_gdb "delete 2\n"
279gdb_expect_list "delete bp 2" "$gdb_prompt$" {
280 "\r\n\032\032post-prompt\r\n"
281}
282
283send_gdb "delete 3\n"
284gdb_expect_list "delete bp 3" "$gdb_prompt$" {
285 "\r\n\032\032post-prompt\r\n"
286}
287
288#
289# break at main, after value is initialized. This is in preparation
290# to test the annotate output for the display command.
291#
292send_gdb "break main\n"
293gdb_expect_list "break at 28" "$gdb_prompt$" {
294 "\r\n\032\032post-prompt\r\n"
6009d884
AC
295 "Breakpoint 4 at 0x\[0-9a-z\]+: file .*annota3.c, line 32.\r\n"
296}
297
298#
299# display the value
300#
301send_gdb "display value\n"
302gdb_expect_list "set up display" "$gdb_prompt$" {
303 "\r\n\032\032post-prompt\r\n"
304 "1: value = 7\r\n"
305}
306
307
308# should ask query. Test annotate-query.
309# we don't care about anything else here, only the query.
310
311send_gdb "run\n"
312gdb_expect {
313 -re "pre-query.*already.*\\(y or n\\).*query\r\n" {
314 send_gdb "y\n"
315 gdb_expect {
316 -re ".*post-query.*$gdb_prompt$" \
317 { pass "re-run" }
318 -re ".*$gdb_prompt$" { fail "re-run" }
319 timeout { fail "re-run (timeout)" }
320 }
321 }
322 -re ".*$gdb_prompt$" { fail "re-run" }
323 timeout { fail "re-run (timeout)" }
324}
325
326#
327# Test that breakpoints-invalid is issued once and only once for
328# breakpoint ignore count changes, after annotation stopped.
3ca42dbe
NR
329# NOTE: breakpoints-invalid annotations have been removed from
330# level 3 but keep these tests for continuity and comparison
331# with annota1.exp.
6009d884
AC
332send_gdb "break 46\n"
333gdb_expect_list "break at 46" "$gdb_prompt$" {
334 "\r\n\032\032post-prompt\r\n"
6009d884
AC
335 "Breakpoint 5 at 0x\[0-9a-z\]+: file .*annota3.c, line 46.\r\n"
336}
337
338send_gdb "ignore 5 4\n"
339gdb_expect_list "ignore 5 4" "$gdb_prompt$" {
340 "\r\n\032\032post-prompt\r\n"
341 "Will ignore next 4 crossings of breakpoint 5"
6009d884
AC
342 "\r\n"
343}
344
345send_gdb "continue\n"
346gdb_expect_list "annotate ignore count change" "$gdb_prompt$" {
347 "\r\n\032\032post-prompt\r\n"
6009d884 348 "\r\n\032\032breakpoint 5\r\n"
616f635d
NR
349 "\r\n"
350 "Breakpoint 5, "
351 "\r\n\032\032frame-begin 0 0x\[0-9a-z\]+\r\n"
352 "main \\(\\) at .*annota3.c:46\r\n"
6009d884
AC
353 "\r\n\032\032source .*annota3.c:46:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
354 "1: value = 11\r\n"
355 "\r\n\032\032stopped\r\n"
6009d884
AC
356}
357
358# check that ignore command is working, or the above can provide
359# misleading assurance ...
360
361send_gdb "next\n"
362gdb_expect_list "next to exit loop" "$gdb_prompt$" {
363 "\r\n\032\032post-prompt\r\n"
364 "\r\n\032\032starting\r\n"
6009d884
AC
365 "\r\n\032\032source.*annota3.c:\[0-9\]+:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
366 "1: value = 12\r\n"
367 "\r\n\032\032stopped\r\n"
368}
369
370send_gdb "next\n"
371gdb_expect_list "breakpoint ignore count" "$gdb_prompt$" {
372 "\r\n\032\032post-prompt\r\n"
373 "\r\n\032\032starting\r\n"
6009d884
AC
374 "\r\n\032\032source.*annota3.c:49:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
375 "1: value = 12\r\n"
376 "\r\n\032\032stopped\r\n"
377}
378
379#
380# Send a signal that is not handled
381#
382# SIGTRAP signals are dropped before they get to the inferior process
383# on hpux11. In theory, this behaivor can be controlled by setting
384# TTEO_NORM_SIGTRAP in the inferior, but doing so did not cause
385# the signal to be properly delivered.
386#
387# It has been verified that other signals will be delivered. However,
388# rather than twiddle the test, I choose to leave it as-is as it
389# exposes an interesting failure on hpux11.
ab618a02
MC
390
391if [target_info exists gdb,nosignals] {
392 unsupported "signal sent"
393} else {
394 setup_xfail hppa*-*-hpux11*
395 send_gdb "signal SIGTRAP\n"
396 gdb_expect_list "signal sent" "$gdb_prompt$" {
397 "\r\n\032\032post-prompt\r\n"
398 "Continuing with signal SIGTRAP.\r\n"
399 "\r\n\032\032starting\r\n"
ab618a02
MC
400 "\r\n\032\032signalled\r\n"
401 "\r\nProgram terminated with signal SIGTRAP, Trace.breakpoint trap.\r\n"
402 "The program no longer exists.\r\n"
403 "\r\n\032\032stopped\r\n"
404 }
6009d884
AC
405}
406
407
419e626b 408# Check for production of a core file and remove it!
6009d884
AC
409
410set exec_output [remote_exec build "ls core"]
411
419e626b 412set test "cleanup core file"
6009d884 413if [ regexp "core not found" $exec_output] {
419e626b 414 pass "$test (not dumped)"
6009d884 415} else {
419e626b
AC
416 if [ regexp "No such file or directory" $exec_output] {
417 pass "$test (not dumped)"
418 } else {
419 remote_exec build "rm -f core"
420 pass "$test (removed)"
421 }
6009d884
AC
422}
423
424# restore the original prompt for the rest of the testsuite
425
426set gdb_prompt $old_gdb_prompt
This page took 0.597554 seconds and 4 git commands to generate.