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