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