gdb/doc/
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / annota1.exp
1 # Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
2 # 2010, 2011 Free Software Foundation, Inc.
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
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
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.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
18
19 if $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 #
29 if [is_remote target] then {
30 return 0
31 }
32
33
34 #
35 # test running programs
36 #
37
38 set testfile "annota1"
39 set srcfile ${testfile}.c
40 set binfile ${objdir}/${subdir}/${testfile}
41
42 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
43 untested annota1.exp
44 return -1
45 }
46
47
48 gdb_exit
49 gdb_start
50 gdb_reinitialize_dir $srcdir/$subdir
51 gdb_load ${binfile}
52
53 #
54 # the line at which break main will put the breakpoint
55 #
56 set main_line 32
57
58 # The commands we test here produce many lines of output; disable "press
59 # <return> to continue" prompts.
60 gdb_test_no_output "set height 0"
61
62 #
63 # break at main
64 #
65 gdb_test "break main" \
66 "Breakpoint.*at.* file .*$srcfile, line.*" \
67 "breakpoint main"
68
69
70 #
71 # NOTE: this prompt is OK only when the annotation level is > 1
72 # NOTE: When this prompt is in use the gdb_test procedure cannot be used because
73 # it assumes that the last char after the gdb_prompt is a white space. This is not
74 # true with this annotated prompt. So we must use send_gdb and gdb_expect.
75 #
76
77 set old_gdb_prompt $gdb_prompt
78 set gdb_prompt "\r\n\032\032pre-prompt\r\n$gdb_prompt \r\n\032\032prompt\r\n"
79
80 #
81 # Escape all the characters in the path that need it. For instance
82 # the directory name could contain '+'.
83 #
84 set escapedsrcfile [string_to_regexp ${srcdir}/${subdir}/${srcfile}]
85
86
87 #
88 # set the annotation level to 2
89 #
90 # of course, this will test:
91 # annotate-pre-prompt
92 # annotate-prompt
93 # annotate-post-prompt (in the next block)
94 #
95 send_gdb "set annotate 2\n"
96 gdb_expect {
97 -re "set annotate 2\r\n$gdb_prompt$" { pass "annotation set at level 2" }
98 -re ".*$gdb_prompt$" { fail "annotation set at level 2" }
99 timeout { fail "annotation set at level 2 (timeout)" }
100 }
101
102
103 #
104 # info break will test:
105 # annotate-breakpoints-headers
106 # annotate-field
107 # annotate-breakpoints-table
108 # annotate-record
109 # annotate-breakpoints-table-end
110 #
111 gdb_test_multiple "info break" "breakpoint info" {
112 -re "\r\n\032\032post-prompt\r\n\r\n\032\032breakpoints-headers\r\n\r\n\032\032field 0\r\nNum \r\n\032\032field 1\r\nType \r\n\032\032field 2\r\nDisp \r\n\032\032field 3\r\nEnb \r\n\032\032field 4\r\nAddress +\r\n\032\032field 5\r\nWhat\r\n\r\n\032\032breakpoints-table\r\n\r\n\032\032record\r\n\r\n\032\032field 0\r\n1 \r\n\032\032field 1\r\nbreakpoint \r\n\032\032field 2\r\nkeep \r\n\032\032field 3\r\ny \r\n\032\032field 4\r\n$hex +\r\n\032\032field 5\r\nin main at ${escapedsrcfile}:$main_line\r\n\r\n\032\032breakpoints-table-end\r\n$gdb_prompt$" {
113 pass "breakpoint info"
114 }
115 -re "\r\n\032\032post-prompt\r\n\r\n\032\032breakpoints-headers\r\n\r\n\032\032field 0\r\nNum \r\n\032\032field 1\r\nType \r\n\032\032field 2\r\nDisp \r\n\032\032field 3\r\nEnb \r\n\032\032field 4\r\nAddress +\r\n\032\032field 5\r\nWhat\r\n\r\n\032\032breakpoints-table\r\n\r\n\032\032record\r\n\r\n\032\032field 0\r\n1 \r\n\032\032field 1\r\nbreakpoint \r\n\032\032field 2\r\nkeep \r\n\032\032field 3\r\ny \r\n\032\032field 4\r\n$hex +\r\n\032\032field 5\r\nin main at .*${srcfile}:$main_line\r\n\r\n\032\032breakpoints-table-end\r\n$gdb_prompt$" {
116 setup_xfail "*-*-*" 1270
117 fail "breakpoint info"
118 }
119 }
120
121
122 #
123 # run to a break point will test:
124 # annotate-frames-invalid
125 # annotate-breakpoints-invalid (a.k.a. breakpoints-changed)
126 # annotate-starting
127 # annotate-breakpoint
128 # annotate-frame-begin
129 # annotate-frame-function-name
130 # annotate-frame-args
131 # annotate-frame-source-begin
132 # annotate-frame-source-file
133 # annotate-frame-source-file-end
134 # annotate-frame-source-line
135 # annotate-frame-source-end
136 # annotate-source
137 # annotate-frame-end
138 # annotate-stopped
139 #
140 #exp_internal 1
141 set binexp [string_to_regexp $binfile]
142 gdb_test_multiple "run" "run until main breakpoint" {
143 -re "\r\n\032\032post-prompt\r\nStarting program: $binexp \(\(\r\n\r\n\032\032frames-invalid\)|\(\r\n\r\n\032\032breakpoints-invalid\)\)+\r\n\r\n\032\032starting\(\(\r\n\r\n\032\032frames-invalid\)|\(\r\n\r\n\032\032breakpoints-invalid\)\)*\r\n\r\n\032\032breakpoint 1\r\n\r\nBreakpoint 1, \r\n\032\032frame-begin 0 $hex\r\n\r\n\032\032frame-function-name\r\nmain\r\n\032\032frame-args\r\n \\(\\)\r\n\032\032frame-source-begin\r\n at \r\n\032\032frame-source-file\r\n.*annota1.c\r\n\032\032frame-source-file-end\r\n:\r\n\032\032frame-source-line\r\n$main_line\r\n\032\032frame-source-end\r\n\r\n\r\n\032\032source.*$srcfile:$main_line:.*:beg:$hex\r\n\r\n\032\032frame-end\r\n\r\n\032\032stopped.*$gdb_prompt$" {
144 pass "run until main breakpoint"
145 }
146 }
147 #exp_internal 0
148 #exit 0
149
150 #
151 # Let's do a next, to get to a point where the array is initialized
152 # We don't care about the annotated output for this operation, it is the same as
153 # the one produced by run above
154 #
155 gdb_test_multiple "next" "go after array init line" {
156 -re "source .*annota1.c.*$gdb_prompt$" {
157 pass "go after array init line"
158 }
159 }
160
161
162 #
163 # printing the array will test:
164 # annotate-value-history-begin
165 # annotate-value-history-value
166 # annotate-array-section-begin
167 # annotate-elt
168 # FIXME: annotate-elt-rep and annotate-elt-rep-end not tested
169 # annotate-array-section-end
170 # annotate-value-history-end
171 # FIXME: annotate-value-begin and annotate-value-end not tested (the gdb output
172 # command would cause them to be used)
173 #
174 gdb_test_multiple "print my_array" "print array" {
175 -re "\r\n\032\032post-prompt\r\n\r\n\032\032value-history-begin 1 -\r\n.*= \r\n\032\032value-history-value\r\n.\r\n\032\032array-section-begin 0 -\r\n1\r\n\032\032elt\r\n, 2\r\n\032\032elt\r\n, 3\r\n\032\032elt\r\n\r\n\032\032array-section-end\r\n.\r\n\r\n\032\032value-history-end\r\n$gdb_prompt$" {
176 pass "print array"
177 }
178 }
179
180
181 #
182 # this should generate an error message, so to test:
183 # annotate-error-begin
184 # FIXME: annotate-error not tested
185 #
186
187 #exp_internal 1
188 gdb_test_multiple "print non_existent_value" "print non_existent_value" {
189 -re "\r\n\032\032post-prompt\r\n\r\n\032\032error-begin\r\nNo symbol \"non_existent_value\" in current context.\r\n\r\n\032\032error\r\n$gdb_prompt$" {
190 pass "print non_existent_value"
191 }
192 }
193
194
195 #
196 # break at signal handler. So that, once we are in the sig handler, if we do a bt
197 # we can test annotate-signal-handler-caller
198 #
199 gdb_test_multiple "break handle_USR1" "break handle_USR1" {
200 -re "\r\n\032\032post-prompt\r\n\r\n\032\032breakpoints-invalid\r\nBreakpoint.*at $hex: file.*$srcfile, line.*\r\n$gdb_prompt$" {
201 pass "break handle_USR1"
202 }
203 }
204
205 #
206 # break at printf. When we are stopped at printf, we can test
207 #
208 gdb_test_multiple "break printf" "break printf" {
209 -re "\r\n\032\032post-prompt\r\n\r\n\032\032breakpoints-invalid\r\nBreakpoint.*at $hex.*$gdb_prompt$" {
210 pass "break printf"
211 }
212 -re "\r\n\032\032post-prompt\r\nwarning: Breakpoint address adjusted from $hex to $hex.\r\n\r\n\032\032breakpoints-invalid\r\nBreakpoint.*at $hex.*$gdb_prompt$" {
213 pass "break printf"
214 }
215 }
216
217 #
218 # get to printf
219 #
220 set pat_begin "\r\n\032\032post-prompt\r\nContinuing.\r\n\r\n\032\032starting\(\r\n\r\n\032\032frames-invalid\)+\r\n"
221 set pat_adjust "warning: Breakpoint 3 address previously adjusted from $hex to $hex.\r\n"
222 set pat_end "\r\n\032\032breakpoint 3\r\n\r\nBreakpoint 3, \r\n\032\032frame-begin 0 $hex\r\n\r\n(\032\032frame-address\r\n$hex\r\n\032\032frame-address-end\r\n in \r\n)*.*\032\032frame-function-name\r\n.*printf(@.*)?\r\n\032\032frame-args\r\n.*\032\032frame-end\r\n\r\n\032\032stopped\r\n$gdb_prompt$"
223
224 gdb_test_multiple "continue" "continue to printf" {
225 -re "${pat_begin}($pat_adjust)?$pat_end" {
226 pass "continue to printf"
227 }
228 -re ".*$gdb_prompt$" { fail "continue to printf" }
229 }
230
231 #
232 # test:
233 # annotate-frame-where
234 # annotate-frame-address
235 # annotate-frame-address-end
236 #
237 set pat_begin "\r\n\032\032post-prompt\r\n\r\n\032\032frame-begin 0 $hex\r\n.0 \r\n(\032\032frame-address\r\n$hex\r\n\032\032frame-address-end\r\n in \r\n)*\032\032frame-function-name\r\n.*printf(@.*)?\r\n\032\032frame-args\r\n \\(.*frame-end\r\n\r\n\032\032frame-begin 1 $hex\r\n.1 \r\n\032\032frame-address\r\n$hex\r\n\032\032frame-address-end\r\n in \r\n\032\032frame-function-name\r\nmain\r\n\032\032frame-args\r\n \\(\\)\r\n\032\032frame-source-begin\r\n at \r\n\032\032frame-source-file\r\n"
238
239 set pat_end "\r\n\032\032frame-source-file-end\r\n:\r\n\032\032frame-source-line\r\n.*\r\n\032\032frame-source-end\r\n\r\n\r\n\032\032frame-end\r\n(\r\n\032\032frame-begin .*\r\n\r\n\032\032frame-end\r\n)*$gdb_prompt$"
240
241 gdb_test_multiple "backtrace" "backtrace from shlibrary" {
242 -re "$pat_begin$escapedsrcfile$pat_end" {
243 pass "backtrace from shlibrary"
244 }
245 -re "$pat_begin.*$srcfile$pat_end" {
246 setup_xfail "*-*-*" 1270
247 fail "backtrace from shlibrary"
248 }
249 }
250
251
252 #
253 # test printing a frame with some arguments:
254 # annotate-arg-begin
255 # annotate-arg-name-end
256 # annotate-arg-value
257 # annotate-arg-end
258 #
259
260 if [target_info exists gdb,nosignals] {
261 unsupported "send SIGUSR1"
262 unsupported "backtrace @ signal handler"
263 } else {
264 gdb_test_multiple "signal SIGUSR1" "send SIGUSR1" {
265 -re "\r\n\032\032post-prompt\r\nContinuing with signal SIGUSR1.\r\n\r\n\032\032starting\(\(\r\n\r\n\032\032frames-invalid\)|\(\r\n\r\n\032\032breakpoints-invalid\)\)+\r\n\r\n\032\032breakpoint 2\r\n\r\nBreakpoint 2, \r\n\032\032frame-begin 0 $hex\r\n\r\n\032\032frame-function-name\r\nhandle_USR1\r\n\032\032frame-args\r\n \\(\r\n\032\032arg-begin\r\nsig\r\n\032\032arg-name-end\r\n=\r\n\032\032arg-value -\r\n$decimal\r\n\032\032arg-end\r\n\\)\r\n\032\032frame-source-begin\r\n at \r\n\032\032frame-source-file\r\n${escapedsrcfile}\r\n\032\032frame-source-file-end\r\n:\r\n\032\032frame-source-line\r\n.*\r\n\032\032frame-source-end\r\n\r\n\r\n\032\032source.*annota1.c:.*:.*:beg:$hex\r\n\r\n\032\032frame-end\r\n\r\n\032\032stopped\r\n$gdb_prompt$" {
266 pass "send SIGUSR1"
267 }
268 -re "\r\n\032\032post-prompt\r\nContinuing with signal SIGUSR1.\r\n\r\n\032\032starting\(\(\r\n\r\n\032\032frames-invalid\)|\(\r\n\r\n\032\032breakpoints-invalid\)\)+\r\n\r\n\032\032breakpoint 2\r\n\r\nBreakpoint 2, \r\n\032\032frame-begin 0 $hex\r\n\r\n\032\032frame-function-name\r\nhandle_USR1\r\n\032\032frame-args\r\n \\(\r\n\032\032arg-begin\r\nsig\r\n\032\032arg-name-end\r\n=\r\n\032\032arg-value -\r\n$decimal\r\n\032\032arg-end\r\n\\)\r\n\032\032frame-source-begin\r\n at \r\n\032\032frame-source-file\r\n.*${srcfile}\r\n\032\032frame-source-file-end\r\n:\r\n\032\032frame-source-line\r\n.*\r\n\032\032frame-source-end\r\n\r\n\r\n\032\032source.*annota1.c:.*:.*:beg:$hex\r\n\r\n\032\032frame-end\r\n\r\n\032\032stopped\r\n$gdb_prompt$" {
269 setup_xfail "*-*-*" 1270
270 fail "send SIGUSR1"
271 }
272 }
273
274 #
275 # test:
276 # annotate-signal-handler-caller
277 #
278 gdb_test_multiple "backtrace" "backtrace @ signal handler" {
279 -re "frame-begin 0 $hex\r\n#0.*frame-end.*frame-begin 1 $hex\r\n#1.*(\032\032signal-handler-caller\r\n.signal handler called.\r\n\r\n)+\032\032frame-end\r\n\r\n\032\032frame-begin 2 $hex\r\n#2.*(frame-begin 3 $hex\r\n#3.*)*frame-end.*$gdb_prompt$" {
280 pass "backtrace @ signal handler"
281 }
282 }
283 }
284
285 #
286 # delete all the breakpoints
287 #
288 gdb_test_multiple "delete 1" "delete bp 1" {
289 -re "\r\n\032\032post-prompt\r\n$gdb_prompt$" {
290 pass "delete bp 1"
291 }
292 }
293
294 gdb_test_multiple "delete 2" "delete bp 2" {
295 -re "\r\n\032\032post-prompt\r\n$gdb_prompt$" {
296 pass "delete bp 2"
297 }
298 }
299
300 gdb_test_multiple "delete 3" "delete bp 3" {
301 -re "\r\n\032\032post-prompt\r\n$gdb_prompt$" {
302 pass "delete bp 3"
303 }
304 }
305
306 #
307 # break at main, after value is initialized. This is in preparation
308 # to test the annotate output for the display command.
309 #
310 gdb_test_multiple "break main" "break at 28" {
311 -re "post-prompt.*\032\032breakpoints-invalid.*Breakpoint 4 at $hex: file ${escapedsrcfile}, line $main_line.*$gdb_prompt$" {
312 pass "break at 28"
313 }
314 -re "post-prompt.*\032\032breakpoints-invalid.*Breakpoint 4 at $hex: file .*${srcfile}, line $main_line.*$gdb_prompt$" {
315 setup_xfail "*-*-*" 1270
316 fail "break at 28"
317 }
318 }
319
320 #
321 # display the value; test:
322 # annotate-display-begin
323 # annotate-display-number-end
324 # annotate-display-format
325 # annotate-display-expression
326 # annotate-display-expression-end
327 # annotate-display-end
328 # FIXME: annotate-display-value not tested
329 #
330 gdb_test_multiple "display value" "set up display" {
331 -re "post-prompt\r\n\r\n\032\032display-begin\r\n1\r\n\032\032display-number-end\r\n: \r\n\032\032display-format\r\n\r\n\032\032display-expression\r\nvalue\r\n\032\032display-expression-end\r\n = \r\n\032\032display-expression\r\n7\r\n\r\n\032\032display-end\r\n$gdb_prompt$" {
332 pass "set up display"
333 }
334 }
335
336
337 # should ask query. Test annotate-query.
338 # we don't care about anything else here, only the query.
339
340 send_gdb "run\n"
341 gdb_expect {
342 -re "pre-query.*already.*\\(y or n\\).*query\r\n" {
343 send_gdb "y\n"
344 gdb_expect {
345 -re ".*post-query.*$gdb_prompt$" \
346 { pass "re-run" }
347 -re ".*$gdb_prompt$" { fail "re-run" }
348 timeout { fail "re-run (timeout)" }
349 }
350 }
351 -re ".*$gdb_prompt$" { fail "re-run" }
352 timeout { fail "re-run (timeout)" }
353 }
354
355 #
356 # Test that breakpoints-invalid is issued once and only once for
357 # breakpoint ignore count changes, after annotation stopped.
358 #
359 gdb_test_multiple "break 46" "break at 46" {
360 -re "Breakpoint 5 at $hex: file .*$srcfile, line 46.*$gdb_prompt$" {
361 pass "break at 46"
362 }
363 }
364
365 gdb_test_multiple "ignore 5 4" "ignore 5 4" {
366 -re "Will ignore next 4 crossings of breakpoint 5.*$gdb_prompt$" {
367 pass "ignore 5 4"
368 }
369 }
370
371 gdb_test_multiple "continue" "annotate ignore count change" {
372 -re ".*$srcfile:46:.*\032\032stopped\r\n\r\n\032\032breakpoints-invalid\r\n$gdb_prompt$" {
373 pass "annotate ignore count change"
374 }
375 }
376
377 # check that ignore command is working, or the above can provide
378 # misleading assurance ...
379
380 gdb_test_multiple "next" "next to exit loop" {
381 -re "source .*annota1.c.*$gdb_prompt$" {
382 }
383 }
384
385 gdb_test_multiple "next" "breakpoint ignore count" {
386 -re ".*$srcfile:49:.*$gdb_prompt$" {
387 pass "breakpoint ignore count"
388 }
389 }
390
391 # Get the inferior's PID for later.
392
393 set test "get inferior pid"
394 set pid -1
395 gdb_test_multiple "info inferior 1" "$test" {
396 -re "process (\[0-9\]*).*$gdb_prompt$" {
397 set pid $expect_out(1,string)
398 pass "$test"
399 }
400 }
401
402 #
403 # Send a signal that is not handled; test:
404 # annotate-signalled
405 # annotate-signal-name
406 # annotate-signal-name-end
407 # annotate-signal-string
408 # annotate-signal-string-end
409 # FIXME: annotate-signal not tested (requires that the inferior be
410 # stopped by a "random" signal)
411 #
412 # SIGTRAP signals are dropped before they get to the inferior process
413 # on hpux11. In theory, this behaivor can be controlled by setting
414 # TTEO_NORM_SIGTRAP in the inferior, but doing so did not cause
415 # the signal to be properly delivered.
416 #
417 # It has been verified that other signals will be delivered. However,
418 # rather than twiddle the test, I choose to leave it as-is as it
419 # exposes an interesting failure on hpux11.
420
421 if [target_info exists gdb,nosignals] {
422 unsupported "signal sent"
423 } else {
424 setup_xfail hppa*-*-hpux11*
425 gdb_test_multiple "signal SIGTRAP" "signal sent" {
426 -re ".*\032\032post-prompt\r\nContinuing with signal SIGTRAP.\r\n\r\n\032\032starting\(\r\n\r\n\032\032frames-invalid\)+\r\n\r\n\032\032signalled\r\n\r\nProgram terminated with signal \r\n\032\032signal-name\r\nSIGTRAP\r\n\032\032signal-name-end\r\n, \r\n\032\032signal-string\r\nTrace.breakpoint trap\r\n\032\032signal-string-end\r\n.\r\nThe program no longer exists.\r\n\r\n\032\032stopped\r\n$gdb_prompt$" {
427 pass "signal sent"
428 }
429 }
430 }
431
432 # Check for production of a core file and remove it!
433
434 set test "cleanup core file"
435 if { [remote_file host exists core] } {
436 remote_file host delete core
437 pass "$test (removed)"
438 } elseif { $pid != -1 && [remote_file host exists core.$pid] } {
439 remote_file host delete core.$pid
440 pass "$test (removed)"
441 } else {
442 pass "$test (not dumped)"
443 }
444
445 proc thread_test {} {
446 global objdir subdir srcdir testfile
447 global gdb_prompt old_gdb_prompt
448 set srcfile watch_thread_num.c
449 set binfile ${objdir}/${subdir}/${testfile}-watch_thread_num
450 set gdb_prompt $old_gdb_prompt
451
452 if { ![get_compiler_info ${binfile}] && [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] == "" } {
453
454 gdb_exit
455 gdb_start
456 gdb_reinitialize_dir $srcdir/$subdir
457 gdb_load ${binfile}
458 if { ![runto main] } then {
459 fail "run to main"
460 return
461 }
462
463 set gdb_prompt \
464 "\r\n\032\032pre-prompt\r\n$gdb_prompt \r\n\032\032prompt\r\n"
465
466 gdb_test_multiple "set annotate 2" "" {
467 -re "set annotate 2\r\n$gdb_prompt$" {
468 }
469 }
470
471 gdb_test_multiple "next 2" "new thread" {
472 -re ".*\032\032new-thread" {
473 pass "new thread"
474 }
475 }
476 }
477 }
478
479 proc thread_switch {} {
480 gdb_test_multiple "thread 1" "thread switch" {
481 -re ".*\032\032thread-changed" {
482 pass "thread switch"
483 }
484 }
485 }
486
487 thread_test
488 thread_switch
489
490 # restore the original prompt for the rest of the testsuite
491
492 set gdb_prompt $old_gdb_prompt
This page took 0.179261 seconds and 5 git commands to generate.