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