]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/annota3.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / annota3.exp
1 # Copyright 2003-2024 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 # This testcase cannot use runto_main because of the different prompt
20 # we get when using annotation level 2.
21 #
22 require target_can_use_run_cmd
23
24
25 #
26 # test running programs
27 #
28
29 standard_testfile .c
30
31 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
32 untested "failed to compile"
33 return -1
34 }
35
36
37 clean_restart ${binfile}
38
39 # The commands we test here produce many lines of output; disable "press
40 # <return> to continue" prompts.
41 gdb_test_no_output "set height 0"
42
43 #
44 # break in main
45 #
46
47 set main_line [gdb_get_line_number "break main"]
48
49 gdb_test "break ${srcfile}:${main_line}" \
50 "Breakpoint.*at.* file .*$srcfile, line $main_line\\." \
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
79 #
80 # if construct:
81 #
82 gdb_test_multiple "if 1" "start if construct" {
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 }
86 }
87
88 gdb_test_multiple "end" "end if construct" {
89 -re "^end\r\n\r\n\032\032post-commands\r\n$gdb_prompt$" {
90 pass "end if construct"
91 }
92 }
93
94 #
95 # info break:
96 #
97 send_gdb "info break\n"
98 gdb_expect_list "breakpoint info" "$gdb_prompt$" [concat {
99 "\r\n\032\032post-prompt\r\n"
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"]]
102
103
104 #
105 # run to a break point will test:
106 #
107 #exp_internal 1
108 send_gdb "run\n"
109 gdb_expect_list "run until main breakpoint" "$gdb_prompt$" [concat {
110 "\r\n\032\032post-prompt\r\n"
111 "Starting program: .*annota3(|\.exe) \r\n"
112 "\r\n\032\032starting\r\n"
113 "\r\n\032\032breakpoint 1\r\n"
114 "\r\n"
115 "Breakpoint 1, "
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"] {
119 "\r\n\032\032stopped\r\n"
120 }]
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"
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"
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"
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"
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"
199 "#0 .* .*printf(@\[^ ]*)? \[^\r\n\]*\r\n"
200 "#1 .* main \[^\r\n\]*\r\n"
201 }
202
203
204 #
205 # test printing a frame with some arguments:
206 #
207
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"
217 "\r\n\032\032breakpoint 2\r\n"
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"
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 }
225
226 #
227 # test:
228 #
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"
233 "#2 .* .*printf(@\[^ \]*)? \[^\r\n\]+\r\n"
234 "#3 .* main \[^\r\n\]+\r\n"
235 }
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 #
257 # break in main, after value is initialized. This is in preparation
258 # to test the annotate output for the display command.
259 #
260 send_gdb "break ${srcfile}:${main_line}\n"
261 gdb_expect_list "break in main" "$gdb_prompt$" [concat {
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"]]
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
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 }
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.
302 # NOTE: breakpoints-invalid annotations have been removed from
303 # level 3 but keep these tests for continuity and comparison
304 # with annota1.exp.
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"]]
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"
317 "\r\n"
318 }
319
320 send_gdb "continue\n"
321 gdb_expect_list "annotate ignore count change" "$gdb_prompt$" [concat {
322 "\r\n\032\032post-prompt\r\n"
323 "\r\n\032\032breakpoint 5\r\n"
324 "\r\n"
325 "Breakpoint 5, "
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"] {
329 "1: value = 11\r\n"
330 "\r\n\032\032stopped\r\n"
331 }]
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"
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
345 set after_loop_line [gdb_get_line_number "after loop"]
346
347 send_gdb "next\n"
348 gdb_expect_list "breakpoint ignore count" "$gdb_prompt$" [concat {
349 "\r\n\032\032post-prompt\r\n"
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"] {
352 "1: value = 12\r\n"
353 "\r\n\032\032stopped\r\n"
354 }]
355
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
367 # Send a signal that is not handled
368
369 if [target_info exists gdb,nosignals] {
370 unsupported "signal sent"
371 } else {
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"
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 }
382 }
383
384
385 # Check for production of a core file and remove it!
386 remove_core $pid
387
388 # restore the original prompt for the rest of the testsuite
389
390 set gdb_prompt $old_gdb_prompt