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