Fixup testcases outputting own name as a test name and standardize failed compilation...
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / annota3.exp
1 # Copyright 2003-2016 Free Software Foundation, Inc.
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
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
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.
12 #
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/>.
15
16 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
17
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 #
24 if [is_remote target] then {
25 return 0
26 }
27
28
29 #
30 # test running programs
31 #
32
33 standard_testfile .c
34
35 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
36 untested "failed to compile"
37 return -1
38 }
39
40
41 clean_restart ${binfile}
42
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"
46
47 #
48 # break in main
49 #
50
51 set main_line [gdb_get_line_number "break main"]
52
53 gdb_test "break ${srcfile}:${main_line}" \
54 "Breakpoint.*at.* file .*$srcfile, line $main_line\\." \
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
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"
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 #
78 send_gdb "set annotate 3\n"
79 gdb_expect_list "annotation set at level 3" "\r\n$gdb_prompt$" {
80 "set annotate 3"
81 }
82
83 #
84 # if construct:
85 #
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"
89 }
90 }
91
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"
95 }
96 }
97
98 #
99 # info break:
100 #
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"]]
106
107
108 #
109 # run to a break point will test:
110 #
111 #exp_internal 1
112 send_gdb "run\n"
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"
118 "\r\n"
119 "Breakpoint 1, "
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"
124 }]
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 #
133 send_gdb "next\n"
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"
139 }
140
141
142 #
143 # printing the array:
144 #
145 send_gdb "print my_array\n"
146 gdb_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
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"
165 }
166
167
168 #
169 # break at signal handler
170 #
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"
175 }
176
177 #
178 # break at printf. When we are stopped at printf, we can test
179 #
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\]+.*"
184 }
185
186 #
187 # get to printf
188 #
189 send_gdb "continue\n"
190 gdb_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"
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
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"
205 }
206
207
208 #
209 # test printing a frame with some arguments:
210 #
211
212 if [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"
221 "\r\n\032\032breakpoint 2\r\n"
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"
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 }
229
230 #
231 # test:
232 #
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"
239 }
240 }
241
242 #
243 # delete all the breakpoints
244 #
245 send_gdb "delete 1\n"
246 gdb_expect_list "delete bp 1" "$gdb_prompt$" {
247 "\r\n\032\032post-prompt\r\n"
248 }
249
250 send_gdb "delete 2\n"
251 gdb_expect_list "delete bp 2" "$gdb_prompt$" {
252 "\r\n\032\032post-prompt\r\n"
253 }
254
255 send_gdb "delete 3\n"
256 gdb_expect_list "delete bp 3" "$gdb_prompt$" {
257 "\r\n\032\032post-prompt\r\n"
258 }
259
260 #
261 # break in main, after value is initialized. This is in preparation
262 # to test the annotate output for the display command.
263 #
264 send_gdb "break ${srcfile}:${main_line}\n"
265 gdb_expect_list "break in 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"]]
268
269 #
270 # display the value
271 #
272 send_gdb "display value\n"
273 gdb_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
282 send_gdb "run\n"
283 gdb_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.
300 # NOTE: breakpoints-invalid annotations have been removed from
301 # level 3 but keep these tests for continuity and comparison
302 # with annota1.exp.
303
304 set value_inc_line [gdb_get_line_number "increment value"]
305
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"]]
310
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"
315 "\r\n"
316 }
317
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"
322 "\r\n"
323 "Breakpoint 5, "
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"] {
327 "1: value = 11\r\n"
328 "\r\n\032\032stopped\r\n"
329 }]
330
331 # check that ignore command is working, or the above can provide
332 # misleading assurance ...
333
334 send_gdb "next\n"
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"
339 "1: value = 12\r\n"
340 "\r\n\032\032stopped\r\n"
341 }
342
343 set after_loop_line [gdb_get_line_number "after loop"]
344
345 send_gdb "next\n"
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"] {
350 "1: value = 12\r\n"
351 "\r\n\032\032stopped\r\n"
352 }]
353
354 # Get the inferior's PID for later.
355
356 set test "get inferior pid"
357 set pid -1
358 gdb_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
365 # Send a signal that is not handled
366
367 if [target_info exists gdb,nosignals] {
368 unsupported "signal sent"
369 } else {
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"
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 }
380 }
381
382
383 # Check for production of a core file and remove it!
384
385 set test "cleanup core file"
386 if { [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)"
392 } else {
393 pass "$test (not dumped)"
394 }
395
396 # restore the original prompt for the rest of the testsuite
397
398 set gdb_prompt $old_gdb_prompt
This page took 0.062267 seconds and 4 git commands to generate.