]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.cp/annota2.exp
PR 31882 libctf: test suite incorrect format specifiers
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.cp / annota2.exp
1 # Copyright 1999-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 #
20 # test running programs
21 #
22
23 require allow_cplus_tests
24
25 standard_testfile .cc
26
27 if {[prepare_for_testing "failed to prepare" $testfile $srcfile \
28 {debug c++ nowarnings}]} {
29 return -1
30 }
31
32 # This testcase cannot use runto_main because of the different prompt
33 # we get when using annotation level 2.
34 #
35 require target_can_use_run_cmd
36
37 set breakpoints_invalid "\r\n\032\032breakpoints-invalid\r\n"
38 set frames_invalid "\r\n\032\032frames-invalid\r\n"
39
40 #
41 # line number where we need to stop in main
42 #
43 set main_line 25
44
45 # The commands we test here produce many lines of output; disable "press
46 # <return> to continue" prompts.
47 gdb_test_no_output "set height 0"
48
49 #
50 # break at main
51 #
52 gdb_test "break 25" \
53 "Breakpoint.*at.* file .*$srcfile, line.*" \
54 "breakpoint main"
55
56
57 #
58 # NOTE: this prompt is OK only when the annotation level is > 1
59 # NOTE: When this prompt is in use the gdb_test procedure cannot be used because
60 # it assumes that the last char of the gdb_prompt is a white space. This is not
61 # true with this annotated prompt. So we must use send_gdb and gdb_expect.
62 #
63
64 set old_gdb_prompt $gdb_prompt
65 set gdb_prompt "\r\n\032\032pre-prompt\r\n$gdb_prompt \r\n\032\032prompt\r\n"
66
67 send_gdb "set annotate 2\n"
68 gdb_expect {
69 -re "set annotate 2\r\n$gdb_prompt$" { pass "annotation set at level 2" }
70 -re ".*$gdb_prompt$" { fail "annotation set at level 2" }
71 timeout { fail "annotation set at level 2 (timeout)" }
72 }
73
74 gdb_test_multiple "run" "run until main breakpoint, first time" {
75 -re "$main_line.*$gdb_prompt$" {
76 pass $gdb_test_name
77 }
78 }
79
80 #
81 # print class 'a' with public fields.
82 # this will test:
83 # annotate-field-begin
84 # annotate-field-name-end
85 # annotate-field-value
86 # annotate-field-end
87 #
88
89 set pat [multi_line "" \
90 "\032\032post-prompt" \
91 "" \
92 "\032\032value-history-begin 1 -" \
93 ".*= " \
94 "\032\032value-history-value" \
95 "\\{" \
96 "\032\032field-begin -" \
97 "x" \
98 "\032\032field-name-end" \
99 " = " \
100 "\032\032field-value" \
101 "1" \
102 "\032\032field-end" \
103 ", " \
104 "\032\032field-begin -" \
105 "y" \
106 "\032\032field-name-end" \
107 " = " \
108 "\032\032field-value" \
109 "2" \
110 "\032\032field-end" \
111 "\\}" \
112 "" \
113 "\032\032value-history-end" \
114 $gdb_prompt$]
115
116 gdb_test_multiple "print a" "print class" {
117 -re "$pat" {
118 pass "print class"
119 }
120 }
121
122 #
123 # continue until exit
124 # this will test:
125 # annotate-exited
126 # `a.x is 1' is asynchronous regarding to `frames-invalid'.
127 #
128
129 if { $gdb_spawn_id == $inferior_spawn_id } {
130 set match_output \
131 [multi_line \
132 "\($frames_invalid\)*a.x is 1" \
133 "\($frames_invalid\)*"]
134 } else {
135 # Usually we'd handle this using gdb_test_stdio, but that looks too
136 # complicated in combination with annotations, so just ignore the inferior
137 # output.
138 set match_output "\($frames_invalid\)*"
139 }
140
141 set pat [multi_line "" \
142 "\032\032post-prompt" \
143 "Continuing." \
144 "" \
145 "\032\032starting" \
146 $match_output \
147 "\032\032exited 0" \
148 "$inferior_exited_re normally." \
149 "" \
150 "\032\032thread-exited,id=\"1\",group-id=\"i1\"" \
151 "" \
152 "\032\032stopped" \
153 $gdb_prompt$]
154 gdb_test_multiple "continue" "continue until exit" {
155 -re "$pat" {
156 pass "continue until exit"
157 }
158 }
159
160 #
161 # delete all breakpoints, watchpoints, tracepoints, and catchpoints
162 #
163 send_gdb "delete\n"
164 gdb_expect {
165 -re ".*Delete all breakpoints, watchpoints, tracepoints, and catchpoints. \\(y or n\\) \r\n\032\032query.*$" {
166 send_gdb "y\n"
167 gdb_expect {
168 -re "\r\n\032\032post-query\r\n${breakpoints_invalid}$gdb_prompt$" { pass "delete bps" }
169 -re ".*$gdb_prompt$" { fail "delete bps" }
170 timeout { fail "delete bps (timeout)" }
171 }
172 }
173 -re ".*$gdb_prompt$" { fail "delete bps" }
174 timeout { fail "delete bps (timeout)" }
175 }
176
177 #
178 # break at first line of main.
179 #
180 set pat [multi_line "" \
181 "\032\032post-prompt" \
182 "Breakpoint.*at $hex: file.*$srcfile, line.*" \
183 "\032\032breakpoints-invalid.*" \
184 $gdb_prompt$]
185
186 gdb_test_multiple "break 22" "break at main" {
187 -re "$pat" {
188 pass "breakpoint at main"
189 }
190 }
191
192 #
193 # change value of main_line
194 #
195 set main_line 22
196
197 #
198 # run program up to breakpoint.
199 #
200
201 gdb_test_multiple "run" "run until main breakpoint, second time" {
202 -re "$main_line.*$gdb_prompt$" {
203 pass $gdb_test_name
204 }
205 }
206
207 #
208 # set up a watch point on a.x
209 #
210 set pat [multi_line "" \
211 "\032\032post-prompt" \
212 ".*atchpoint 3: a.x" \
213 "" \
214 "\032\032breakpoints-invalid" \
215 $gdb_prompt$]
216 gdb_test_multiple "watch a.x" "set watch on a.x" {
217 -re "$pat" {
218 pass "set watch on a.x"
219 }
220 }
221
222 #
223 # do a next, so that the watchpoint triggers. This will test:
224 # annotate-watchpoint
225 #
226 set pat [multi_line "" \
227 "\032\032post-prompt" \
228 "" \
229 "\032\032starting" \
230 "\(${frames_invalid}\)*${breakpoints_invalid}\(${frames_invalid}\)*" \
231 "\032\032watchpoint 3" \
232 ".*atchpoint 3: a.x" \
233 "" \
234 "Old value = 0" \
235 "New value = 1" \
236 "" \
237 "\032\032frame-begin 0 $hex" \
238 "" \
239 "\032\032frame-function-name" \
240 "main" \
241 "\032\032frame-args" \
242 " \\(\\)" \
243 "\032\032frame-source-begin" \
244 " at " \
245 "\032\032frame-source-file" \
246 ".*$srcfile" \
247 "\032\032frame-source-file-end" \
248 ":" \
249 "\032\032frame-source-line" \
250 "$decimal" \
251 "\032\032frame-source-end" \
252 "" \
253 "" \
254 "\032\032source .*$srcfile.*beg:$hex" \
255 "" \
256 "\032\032frame-end" \
257 "" \
258 "\032\032stopped" \
259 $gdb_prompt$]
260
261 gdb_test_multiple "next" "watch triggered on a.x" {
262 -re "$pat" {
263 pass "watch triggered on a.x"
264 }
265 }
266
267
268 #
269 # send ^C to gdb, so that the quit() function gets called
270 # and annotate-quit is tested
271 # test:
272 # annotate-quit
273 #
274 if ![target_info exists gdb,nointerrupts] {
275 send_gdb "\003"
276 gdb_expect {
277 -re "\r\n\032\032error-begin\r\nQuit\r\n\r\n\032\032quit\r\n$gdb_prompt$" \
278 { pass "annotate-quit" }
279 -re ".*$gdb_prompt$" { fail "annotate-quit" }
280 timeout { fail "annotate-quit (timeout)" }
281 }
282 }
283
284 #
285 # FIXME: the testsuite does not currently have tests for
286 # annotate_catchpoints and annotate_function_call
287 # and a few variants of the annotations that are
288 # tested (marked by FIXME on the annot?.exp files)
289 #
290
291 # reinstall the old prompt for the rest of the testsuite.
292
293 set gdb_prompt $old_gdb_prompt
294