annota3.exp revision 1.8 1 1.8 christos # Copyright 2003-2019 Free Software Foundation, Inc.
2 1.1 christos
3 1.1 christos # This program is free software; you can redistribute it and/or modify
4 1.1 christos # it under the terms of the GNU General Public License as published by
5 1.1 christos # the Free Software Foundation; either version 3 of the License, or
6 1.1 christos # (at your option) any later version.
7 1.1 christos #
8 1.1 christos # This program is distributed in the hope that it will be useful,
9 1.1 christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 1.1 christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 1.1 christos # GNU General Public License for more details.
12 1.1 christos #
13 1.1 christos # You should have received a copy of the GNU General Public License
14 1.1 christos # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 1.1 christos
16 1.1 christos # This file was written by Elena Zannoni (ezannoni (at) cygnus.com)
17 1.1 christos
18 1.1 christos
19 1.8 christos # This testcase cannot use runto_main because of the different prompt
20 1.8 christos # we get when using annotation level 2.
21 1.1 christos #
22 1.8 christos if ![target_can_use_run_cmd] {
23 1.1 christos return 0
24 1.1 christos }
25 1.1 christos
26 1.1 christos
27 1.1 christos #
28 1.1 christos # test running programs
29 1.1 christos #
30 1.1 christos
31 1.1 christos standard_testfile .c
32 1.1 christos
33 1.1 christos if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
34 1.7 christos untested "failed to compile"
35 1.1 christos return -1
36 1.1 christos }
37 1.1 christos
38 1.1 christos
39 1.1 christos clean_restart ${binfile}
40 1.1 christos
41 1.1 christos # The commands we test here produce many lines of output; disable "press
42 1.1 christos # <return> to continue" prompts.
43 1.1 christos gdb_test_no_output "set height 0"
44 1.1 christos
45 1.1 christos #
46 1.6 christos # break in main
47 1.1 christos #
48 1.1 christos
49 1.1 christos set main_line [gdb_get_line_number "break main"]
50 1.1 christos
51 1.6 christos gdb_test "break ${srcfile}:${main_line}" \
52 1.1 christos "Breakpoint.*at.* file .*$srcfile, line $main_line\\." \
53 1.1 christos "breakpoint main"
54 1.1 christos
55 1.1 christos
56 1.1 christos # NOTE: this prompt is OK only when the annotation level is > 1
57 1.1 christos
58 1.1 christos # NOTE: When this prompt is in use the gdb_test procedure cannot be
59 1.1 christos # used because it assumes that the last char after the gdb_prompt is a
60 1.1 christos # white space. This is not true with this annotated prompt. So we must
61 1.1 christos # use send_gdb and gdb_expect or gdb_expect_list.
62 1.1 christos
63 1.1 christos set old_gdb_prompt $gdb_prompt
64 1.1 christos set gdb_prompt "\r\n\032\032pre-prompt\r\n$gdb_prompt \r\n\032\032prompt\r\n"
65 1.1 christos
66 1.1 christos
67 1.1 christos
68 1.1 christos #
69 1.1 christos # set the annotation level to 3
70 1.1 christos #
71 1.1 christos # of course, this will test:
72 1.1 christos # annotate-pre-prompt
73 1.1 christos # annotate-prompt
74 1.1 christos # annotate-post-prompt (in the next block)
75 1.1 christos #
76 1.1 christos send_gdb "set annotate 3\n"
77 1.1 christos gdb_expect_list "annotation set at level 3" "\r\n$gdb_prompt$" {
78 1.1 christos "set annotate 3"
79 1.1 christos }
80 1.1 christos
81 1.1 christos #
82 1.1 christos # if construct:
83 1.1 christos #
84 1.1 christos gdb_test_multiple "if 1" "start if construct" {
85 1.1 christos -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$" {
86 1.1 christos pass "start if construct"
87 1.1 christos }
88 1.1 christos }
89 1.1 christos
90 1.1 christos gdb_test_multiple "end" "end if construct" {
91 1.1 christos -re "^end\r\n\r\n\032\032post-commands\r\n$gdb_prompt$" {
92 1.1 christos pass "end if construct"
93 1.1 christos }
94 1.1 christos }
95 1.1 christos
96 1.1 christos #
97 1.1 christos # info break:
98 1.1 christos #
99 1.1 christos send_gdb "info break\n"
100 1.1 christos gdb_expect_list "breakpoint info" "$gdb_prompt$" [concat {
101 1.1 christos "\r\n\032\032post-prompt\r\n"
102 1.1 christos "Num Type Disp Enb Address +What\r\n" } [list \
103 1.1 christos "1 breakpoint keep y 0x\[0-9a-zA-Z\]+ +in main at .*annota3.c:$main_line\r\n"]]
104 1.1 christos
105 1.1 christos
106 1.1 christos #
107 1.1 christos # run to a break point will test:
108 1.1 christos #
109 1.1 christos #exp_internal 1
110 1.1 christos send_gdb "run\n"
111 1.1 christos gdb_expect_list "run until main breakpoint" "$gdb_prompt$" [concat {
112 1.1 christos "\r\n\032\032post-prompt\r\n"
113 1.1 christos "Starting program: .*annota3(|\.exe) \r\n"
114 1.1 christos "\r\n\032\032starting\r\n"
115 1.1 christos "\r\n\032\032breakpoint 1\r\n"
116 1.1 christos "\r\n"
117 1.1 christos "Breakpoint 1, "
118 1.1 christos "\r\n\032\032frame-begin 0 0x\[0-9a-z\]+\r\n" } [list \
119 1.1 christos "main \\(\\) at .*annota3.c:$main_line\r\n"] [list \
120 1.1 christos "\r\n\032\032source.*annota3.c:$main_line:.*:beg:0x\[0-9a-z\]+\r\n"] {
121 1.1 christos "\r\n\032\032stopped\r\n"
122 1.1 christos }]
123 1.1 christos #exp_internal 0
124 1.1 christos #exit 0
125 1.1 christos
126 1.1 christos #
127 1.1 christos # Let's do a next, to get to a point where the array is initialized
128 1.1 christos # We don't care about the annotated output for this operation, it is the same as
129 1.1 christos # the one produced by run above
130 1.1 christos #
131 1.1 christos send_gdb "next\n"
132 1.1 christos gdb_expect_list "go after array init line" "$gdb_prompt$" {
133 1.1 christos "\r\n\032\032post-prompt\r\n"
134 1.1 christos "\r\n\032\032starting\r\n"
135 1.1 christos "\r\n\032\032source .*annota3.c:\[0-9\]+:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
136 1.1 christos "\r\n\032\032stopped\r\n"
137 1.1 christos }
138 1.1 christos
139 1.1 christos
140 1.1 christos #
141 1.1 christos # printing the array:
142 1.1 christos #
143 1.1 christos send_gdb "print my_array\n"
144 1.1 christos gdb_expect_list "print array" "$gdb_prompt$" {
145 1.1 christos "\r\n\032\032post-prompt\r\n"
146 1.1 christos ".*= .1, 2, 3.\r\n"
147 1.1 christos }
148 1.1 christos
149 1.1 christos
150 1.1 christos #
151 1.1 christos # this should generate an error message, so to test:
152 1.1 christos # annotate-error-begin
153 1.1 christos # FIXME: annotate-error not tested
154 1.1 christos #
155 1.1 christos
156 1.1 christos #exp_internal 1
157 1.1 christos send_gdb "print non_existent_value\n"
158 1.1 christos gdb_expect_list "print non_existent_value" "$gdb_prompt$" {
159 1.1 christos "\r\n\032\032post-prompt\r\n"
160 1.1 christos "\r\n\032\032error-begin\r\n"
161 1.1 christos "No symbol \"non_existent_value\" in current context.\r\n"
162 1.1 christos "\r\n\032\032error\r\n"
163 1.1 christos }
164 1.1 christos
165 1.1 christos
166 1.1 christos #
167 1.1 christos # break at signal handler
168 1.1 christos #
169 1.1 christos send_gdb "break handle_USR1\n"
170 1.1 christos gdb_expect_list "breakpoint handle_USR1" "$gdb_prompt$" {
171 1.1 christos "\r\n\032\032post-prompt\r\n"
172 1.1 christos "Breakpoint.*at 0x\[0-9a-z\]+: file.*annota3.c, line.*\r\n"
173 1.1 christos }
174 1.1 christos
175 1.1 christos #
176 1.1 christos # break at printf. When we are stopped at printf, we can test
177 1.1 christos #
178 1.1 christos send_gdb "break printf\n"
179 1.1 christos gdb_expect_list "breakpoint printf" "$gdb_prompt$" {
180 1.1 christos "\r\n\032\032post-prompt\r\n"
181 1.1 christos "Breakpoint.*at 0x\[0-9a-z\]+.*"
182 1.1 christos }
183 1.1 christos
184 1.1 christos #
185 1.1 christos # get to printf
186 1.1 christos #
187 1.1 christos send_gdb "continue\n"
188 1.1 christos gdb_expect_list "continue to printf" "$gdb_prompt$" {
189 1.1 christos "\r\n\032\032post-prompt\r\n"
190 1.1 christos "Continuing.\r\n"
191 1.1 christos "\r\n\032\032starting\r\n"
192 1.1 christos "\r\n\032\032breakpoint 3\r\n"
193 1.1 christos "\r\n"
194 1.1 christos "Breakpoint 3, \[^\r\n\]*\r\n"
195 1.1 christos "\r\n\032\032stopped\r\n"
196 1.1 christos }
197 1.1 christos
198 1.1 christos send_gdb "backtrace\n"
199 1.1 christos gdb_expect_list "backtrace from shlibrary" "$gdb_prompt$" {
200 1.1 christos "\r\n\032\032post-prompt\r\n"
201 1.1 christos "#0 .* .*printf(@\[^ ]*)? \[^\r\n\]*\r\n"
202 1.1 christos "#1 .* main \[^\r\n\]*\r\n"
203 1.1 christos }
204 1.1 christos
205 1.1 christos
206 1.1 christos #
207 1.1 christos # test printing a frame with some arguments:
208 1.1 christos #
209 1.1 christos
210 1.1 christos if [target_info exists gdb,nosignals] {
211 1.1 christos unsupported "send SIGUSR1"
212 1.1 christos unsupported "backtrace @ signal handler"
213 1.1 christos } else {
214 1.1 christos send_gdb "signal SIGUSR1\n"
215 1.1 christos gdb_expect_list "send SIGUSR1" "$gdb_prompt$" {
216 1.1 christos "\r\n\032\032post-prompt\r\n"
217 1.1 christos "Continuing with signal SIGUSR1.\r\n"
218 1.1 christos "\r\n\032\032starting\r\n"
219 1.1 christos "\r\n\032\032breakpoint 2\r\n"
220 1.1 christos "\r\n"
221 1.1 christos "Breakpoint 2, "
222 1.1 christos "\r\n\032\032frame-begin 0 0x\[0-9a-z\]+\r\n"
223 1.1 christos "handle_USR1 \\(sig=\[0-9\]+\\) at .*annota3.c:\[0-9\]+\r\n"
224 1.1 christos "\r\n\032\032source .*annota3.c:\[0-9\]+:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
225 1.1 christos "\r\n\032\032stopped\r\n"
226 1.1 christos }
227 1.1 christos
228 1.1 christos #
229 1.1 christos # test:
230 1.1 christos #
231 1.1 christos send_gdb "backtrace\n"
232 1.1 christos gdb_expect_list "backtrace @ signal handler" "$gdb_prompt$" {
233 1.1 christos "#0 +handle_USR1 \[^\r\n\]+\r\n"
234 1.1 christos "#1 +.signal handler called.\r\n"
235 1.1 christos "#2 .* .*printf(@\[^ \]*)? \[^\r\n\]+\r\n"
236 1.1 christos "#3 .* main \[^\r\n\]+\r\n"
237 1.1 christos }
238 1.1 christos }
239 1.1 christos
240 1.1 christos #
241 1.1 christos # delete all the breakpoints
242 1.1 christos #
243 1.1 christos send_gdb "delete 1\n"
244 1.1 christos gdb_expect_list "delete bp 1" "$gdb_prompt$" {
245 1.1 christos "\r\n\032\032post-prompt\r\n"
246 1.1 christos }
247 1.1 christos
248 1.1 christos send_gdb "delete 2\n"
249 1.1 christos gdb_expect_list "delete bp 2" "$gdb_prompt$" {
250 1.1 christos "\r\n\032\032post-prompt\r\n"
251 1.1 christos }
252 1.1 christos
253 1.1 christos send_gdb "delete 3\n"
254 1.1 christos gdb_expect_list "delete bp 3" "$gdb_prompt$" {
255 1.1 christos "\r\n\032\032post-prompt\r\n"
256 1.1 christos }
257 1.1 christos
258 1.1 christos #
259 1.6 christos # break in main, after value is initialized. This is in preparation
260 1.1 christos # to test the annotate output for the display command.
261 1.1 christos #
262 1.6 christos send_gdb "break ${srcfile}:${main_line}\n"
263 1.6 christos gdb_expect_list "break in main" "$gdb_prompt$" [concat {
264 1.1 christos "\r\n\032\032post-prompt\r\n" } [list \
265 1.1 christos "Breakpoint 4 at 0x\[0-9a-z\]+: file .*annota3.c, line $main_line.\r\n"]]
266 1.1 christos
267 1.1 christos #
268 1.1 christos # display the value
269 1.1 christos #
270 1.1 christos send_gdb "display value\n"
271 1.1 christos gdb_expect_list "set up display" "$gdb_prompt$" {
272 1.1 christos "\r\n\032\032post-prompt\r\n"
273 1.1 christos "1: value = 7\r\n"
274 1.1 christos }
275 1.1 christos
276 1.1 christos
277 1.1 christos # should ask query. Test annotate-query.
278 1.1 christos # we don't care about anything else here, only the query.
279 1.1 christos
280 1.1 christos send_gdb "run\n"
281 1.1 christos gdb_expect {
282 1.1 christos -re "pre-query.*already.*\\(y or n\\).*query\r\n" {
283 1.1 christos send_gdb "y\n"
284 1.1 christos gdb_expect {
285 1.1 christos -re ".*post-query.*$gdb_prompt$" \
286 1.1 christos { pass "re-run" }
287 1.1 christos -re ".*$gdb_prompt$" { fail "re-run" }
288 1.1 christos timeout { fail "re-run (timeout)" }
289 1.1 christos }
290 1.1 christos }
291 1.1 christos -re ".*$gdb_prompt$" { fail "re-run" }
292 1.1 christos timeout { fail "re-run (timeout)" }
293 1.1 christos }
294 1.1 christos
295 1.1 christos #
296 1.1 christos # Test that breakpoints-invalid is issued once and only once for
297 1.1 christos # breakpoint ignore count changes, after annotation stopped.
298 1.1 christos # NOTE: breakpoints-invalid annotations have been removed from
299 1.1 christos # level 3 but keep these tests for continuity and comparison
300 1.1 christos # with annota1.exp.
301 1.1 christos
302 1.1 christos set value_inc_line [gdb_get_line_number "increment value"]
303 1.1 christos
304 1.1 christos send_gdb "break $value_inc_line\n"
305 1.1 christos gdb_expect_list "break at value++" "$gdb_prompt$" [concat {
306 1.1 christos "\r\n\032\032post-prompt\r\n" } [list \
307 1.1 christos "Breakpoint 5 at 0x\[0-9a-z\]+: file .*annota3.c, line $value_inc_line.\r\n"]]
308 1.1 christos
309 1.1 christos send_gdb "ignore 5 4\n"
310 1.1 christos gdb_expect_list "ignore 5 4" "$gdb_prompt$" {
311 1.1 christos "\r\n\032\032post-prompt\r\n"
312 1.1 christos "Will ignore next 4 crossings of breakpoint 5"
313 1.1 christos "\r\n"
314 1.1 christos }
315 1.1 christos
316 1.1 christos send_gdb "continue\n"
317 1.1 christos gdb_expect_list "annotate ignore count change" "$gdb_prompt$" [concat {
318 1.1 christos "\r\n\032\032post-prompt\r\n"
319 1.1 christos "\r\n\032\032breakpoint 5\r\n"
320 1.1 christos "\r\n"
321 1.1 christos "Breakpoint 5, "
322 1.1 christos "\r\n\032\032frame-begin 0 0x\[0-9a-z\]+\r\n" } [list \
323 1.1 christos "main \\(\\) at .*annota3.c:$value_inc_line\r\n"] [list \
324 1.1 christos "\r\n\032\032source .*annota3.c:$value_inc_line:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"] {
325 1.1 christos "1: value = 11\r\n"
326 1.1 christos "\r\n\032\032stopped\r\n"
327 1.1 christos }]
328 1.1 christos
329 1.1 christos # check that ignore command is working, or the above can provide
330 1.1 christos # misleading assurance ...
331 1.1 christos
332 1.1 christos send_gdb "next\n"
333 1.1 christos gdb_expect_list "next to exit loop" "$gdb_prompt$" {
334 1.1 christos "\r\n\032\032post-prompt\r\n"
335 1.1 christos "\r\n\032\032starting\r\n"
336 1.1 christos "\r\n\032\032source.*annota3.c:\[0-9\]+:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
337 1.1 christos "1: value = 12\r\n"
338 1.1 christos "\r\n\032\032stopped\r\n"
339 1.1 christos }
340 1.1 christos
341 1.1 christos set after_loop_line [gdb_get_line_number "after loop"]
342 1.1 christos
343 1.1 christos send_gdb "next\n"
344 1.1 christos gdb_expect_list "breakpoint ignore count" "$gdb_prompt$" [concat {
345 1.1 christos "\r\n\032\032post-prompt\r\n"
346 1.1 christos "\r\n\032\032starting\r\n" } [list \
347 1.1 christos "\r\n\032\032source.*annota3.c:$after_loop_line:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"] {
348 1.1 christos "1: value = 12\r\n"
349 1.1 christos "\r\n\032\032stopped\r\n"
350 1.1 christos }]
351 1.1 christos
352 1.1 christos # Get the inferior's PID for later.
353 1.1 christos
354 1.1 christos set test "get inferior pid"
355 1.1 christos set pid -1
356 1.1 christos gdb_test_multiple "info inferior 1" "$test" {
357 1.1 christos -re "process (\[0-9\]*).*$gdb_prompt$" {
358 1.1 christos set pid $expect_out(1,string)
359 1.1 christos pass "$test"
360 1.1 christos }
361 1.1 christos }
362 1.1 christos
363 1.1 christos # Send a signal that is not handled
364 1.1 christos
365 1.1 christos if [target_info exists gdb,nosignals] {
366 1.1 christos unsupported "signal sent"
367 1.1 christos } else {
368 1.1 christos send_gdb "signal SIGTRAP\n"
369 1.1 christos gdb_expect_list "signal sent" "$gdb_prompt$" {
370 1.1 christos "\r\n\032\032post-prompt\r\n"
371 1.1 christos "Continuing with signal SIGTRAP.\r\n"
372 1.1 christos "\r\n\032\032starting\r\n"
373 1.1 christos "\r\n\032\032signalled\r\n"
374 1.1 christos "\r\nProgram terminated with signal SIGTRAP, Trace.breakpoint trap.\r\n"
375 1.1 christos "The program no longer exists.\r\n"
376 1.1 christos "\r\n\032\032stopped\r\n"
377 1.1 christos }
378 1.1 christos }
379 1.1 christos
380 1.1 christos
381 1.1 christos # Check for production of a core file and remove it!
382 1.1 christos
383 1.1 christos set test "cleanup core file"
384 1.1 christos if { [remote_file host exists core] } {
385 1.1 christos remote_file host delete core
386 1.1 christos pass "$test (removed)"
387 1.1 christos } elseif { $pid != -1 && [remote_file host exists core.$pid] } {
388 1.1 christos remote_file host delete core.$pid
389 1.1 christos pass "$test (removed)"
390 1.1 christos } else {
391 1.1 christos pass "$test (not dumped)"
392 1.1 christos }
393 1.1 christos
394 1.1 christos # restore the original prompt for the rest of the testsuite
395 1.1 christos
396 1.1 christos set gdb_prompt $old_gdb_prompt
397