]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.trace/report.exp
2012-01-16 Pedro Alves <palves@redhat.com>
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.trace / report.exp
1 # Copyright 1998, 2007-2012 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 Michael Snyder (msnyder@cygnus.com)
17
18 load_lib "trace-support.exp";
19
20
21 gdb_exit
22 gdb_start
23
24 set testfile "actions"
25 set srcfile ${testfile}.c
26 set binfile $objdir/$subdir/report
27 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
28 executable {debug nowarnings}] != "" } {
29 untested report.exp
30 return -1
31 }
32 gdb_load $binfile
33 gdb_test "tstop" ".*" ""
34 gdb_test "tfind none" ".*" ""
35 runto_main
36 gdb_reinitialize_dir $srcdir/$subdir
37
38 # We generously give ourselves one "pass" if we successfully
39 # detect that this test cannot be run on this target!
40 if { ![gdb_target_supports_trace] } then {
41 pass "Current target does not support trace"
42 return 1;
43
44 }
45
46 set cr "\[\r\n\]+"
47
48 # If testing on a remote host, download the source file.
49 # remote_download host $srcdir/$subdir/$srcfile
50
51 #
52 # test general reporting of trace experiment results
53 #
54
55 set testline1 0
56 set testline2 0
57 set testline3 0
58 set testline4 0
59 set testline5 0
60 set testline6 0
61
62 set arg1 1
63 set arg2 2
64 set arg3 3
65 set arg4 4
66 set arg5 5
67 set arg6 6
68
69 set gdb_recursion_test_baseline [gdb_find_recursion_test_baseline $srcfile];
70 if { $gdb_recursion_test_baseline == -1 } {
71 fail "Could not find gdb_recursion_test function"
72 return;
73 }
74
75 set return_me 0
76
77 gdb_test_multiple "list $gdb_recursion_test_baseline, +12" "" {
78 -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+gdbtestline 1 " {
79 set testline1 $expect_out(1,string)
80 exp_continue
81 }
82 -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+gdbtestline 2 " {
83 set testline2 $expect_out(1,string)
84 exp_continue
85 }
86 -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+gdbtestline 3 " {
87 set testline3 $expect_out(1,string)
88 exp_continue
89 }
90 -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+gdbtestline 4 " {
91 set testline4 $expect_out(1,string)
92 exp_continue
93 }
94 -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+gdbtestline 5 " {
95 set testline5 $expect_out(1,string)
96 exp_continue
97 }
98 -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+gdbtestline 6 " {
99 set testline6 $expect_out(1,string)
100 exp_continue
101 }
102 -re ".*$gdb_prompt $" {
103 if { ($testline1 == 0) || ($testline2 == 0) || ($testline3 == 0) || ($testline4 == 0) || ($testline5 == 0) || ($testline6 == 0) } {
104 untested report.exp
105 set return_me 1
106 all tests in this module will fail."
107 }
108 }
109 default {
110 untested report.exp
111 set return_me 1
112 all tests in this module will fail."
113 }
114 }
115
116 if { $return_me == 1 } then {
117 return -1;
118 }
119
120 #
121 # Setup trace experiment. This will involve:
122 # 1) a tracepoint where nothing is collected
123 # 2) a tracepoint where only regs are collected
124 # 3) a tracepoint where only args are collected
125 # 4) a tracepoint where only locals are collected
126 # 5) a tracepoint where some amount of stack memory is collected.
127 # 6) a tracepoint where some expressions are collected.
128 #
129
130 gdb_delete_tracepoints
131 set tdp1 [gdb_gettpnum $testline1]
132 set tdp2 [gdb_gettpnum $testline2]
133 set tdp3 [gdb_gettpnum $testline3]
134 set tdp4 [gdb_gettpnum $testline4]
135 set tdp5 [gdb_gettpnum $testline5]
136 set tdp6 [gdb_gettpnum $testline6]
137
138 if { $tdp1 <= 0 || $tdp2 <= 0 || $tdp3 <= 0 || \
139 $tdp4 <= 0 || $tdp5 <= 0 || $tdp6 <= 0 } then {
140 fail "setting tracepoints failed"
141 return;
142 }
143
144 gdb_trace_setactions "9.x: setup TP to collect regs" \
145 "$tdp2" \
146 "collect \$regs" "^$"
147
148
149 gdb_trace_setactions "9.x: setup TP to collect args" \
150 "$tdp3" \
151 "collect \$args" "^$"
152
153 gdb_trace_setactions "9.x: setup TP to collect locals" \
154 "$tdp4" \
155 "collect \$locs" "^$"
156
157 if [is_amd64_regs_target] {
158 set fpreg "rbp"
159 set spreg "rsp"
160 set pcreg "rip"
161 } elseif [is_x86_like_target] {
162 set fpreg "ebp"
163 set spreg "esp"
164 set pcreg "eip"
165 } else {
166 set fpreg "fp"
167 set spreg "sp"
168 set pcreg "pc"
169 }
170
171 gdb_trace_setactions "9.x: setup TP to collect stack memory" \
172 "$tdp5" \
173 "collect \$$fpreg, \*\(void \*\*\) \$$spreg @ 64" "^$"
174
175 gdb_trace_setactions "9.x: setup TP to collect expressions" \
176 "$tdp6" \
177 "collect gdb_char_test, gdb_short_test, gdb_long_test" "^$"
178
179 gdb_test "tstart" ".*" ""
180
181 gdb_test "break end" ".*" ""
182 gdb_test "continue" \
183 "Continuing.*Breakpoint $decimal, end.*" \
184 "run trace experiment"
185
186 gdb_test "tstop" ".*" ""
187
188 #
189 # 9.1 test the tdump command
190 #
191
192 set timeout 60
193
194 gdb_tfind_test "9.1: init: make sure not debugging any trace frame" "none" "-1"
195
196 gdb_tfind_test "9.1: find frame for TP $tdp1" "tracepoint $tdp1" \
197 "\$tracepoint" "$tdp1"
198
199 # Nothing was collected at tdp1, so this tdump should be empty.
200 gdb_test "tdump" \
201 "Data collected at tracepoint $tdp1, trace frame $decimal:" \
202 "9.1: tdump, nothing collected"
203
204 gdb_tfind_test "9.1: find frame for TP $tdp2" "tracepoint $tdp2" \
205 "\$tracepoint" "$tdp2"
206
207 # regs were collected at tdp2.
208 # How to match for the output of "info registers" on an unknown architecture?
209 # For now, assume that most architectures have a register called "pc".
210
211 gdb_test "tdump" \
212 "\[\r\n\]$pcreg .*" \
213 "9.1: tdump, regs collected"
214
215 gdb_tfind_test "9.1: find frame for TP $tdp3" "tracepoint $tdp3" \
216 "\$tracepoint" "$tdp3"
217
218 # args were collected at tdp3
219 gdb_test "tdump" \
220 "depth = 3.*q1 = 2.*q2 = 2.*q3 = 3.*q4 = 4.*q5 = 5.*q6 = 6" \
221 "9.1: tdump, args collected"
222
223 gdb_tfind_test "9.1: find frame for TP $tdp4" "tracepoint $tdp4" \
224 "\$tracepoint" "$tdp4"
225
226 # locals were collected at tdp4
227 gdb_test "tdump" \
228 "q = 1" \
229 "9.1: tdump, locals collected"
230
231 gdb_tfind_test "9.1: find frame for TP $tdp5" "tracepoint $tdp5" \
232 "\$tracepoint" "$tdp5"
233
234 # stack was collected at tdp5, plus the frame pointer
235 gdb_test "tdump" \
236 ".$fpreg = .*$spreg @ 64 = .*" \
237 "9.1: tdump, memrange collected"
238
239 gdb_tfind_test "9.1: find frame for TP $tdp6" "tracepoint $tdp6" \
240 "\$tracepoint" "$tdp6"
241
242 # globals were collected at tdp6
243 gdb_test "tdump" \
244 "gdb_char_test = 1.*gdb_short_test = 2.*gdb_long_test = 3" \
245 "9.1: tdump, global variables collected"
246
247 # 9.2 test tdump with arguments
248 # [no go, tdump doesn't have any arguments]
249
250 # 9.3 help tdump
251
252 gdb_test "help tdump" "Print everything collected at the current.*" \
253 "9.3: help tdump"
254
255 set linecount1 0
256 set linecount2 0
257 set linecount3 0
258 set linecount4 0
259 set linecount5 0
260 set linecount6 0
261
262 gdb_tfind_test "11.x, 12.1: find start frame" "start" "0"
263
264 #
265 # 11.x test built-in trace variables $trace_frame, $trace_line etc.
266 #
267
268 gdb_test "printf \"x %d x\\n\", \$trace_frame" "x 0 x" \
269 "11.1: test \$trace_frame"
270
271 gdb_test "printf \"x %d x\\n\", \$tracepoint" "x $tdp1 x" \
272 "11.2: test \$tracepoint"
273
274 gdb_test "printf \"x %d x\\n\", \$trace_line" "x $testline1 x" \
275 "11.3: test \$trace_line"
276
277 gdb_test_multiple "print \$trace_file" "11.4: test \$trace_file" {
278 -re "\\$\[0-9\]+ = \"$srcfile\"\[\r\n\]+$gdb_prompt $" {
279 pass "11.4: test \$trace_file"
280 }
281 -re "\\$\[0-9\]+ = \"$srcdir/$subdir/$srcfile\"\[\r\n\]+$gdb_prompt $" {
282 pass "11.4: test \$trace_file"
283 }
284 }
285
286 #gdb_test "print \$trace_file" "\"$srcdir/$subdir/$srcfile\"" \
287 # "11.4: test \$trace_file"
288
289 #
290 # 12.x test report generation using arbitrary GDB commands, loops etc.
291 #
292
293 gdb_test_multiple "while \$trace_frame != -1\n output \$trace_file\n printf \", line \%d \(tracepoint #\%d\)\\n\", \$trace_line, \$tracepoint\n tfind\n end" "12.1: trace report #1" {
294 -re "> end\r\n" {
295 exp_continue
296 }
297 -re "^Found trace frame \[0-9\]+, tracepoint \[0-9\]+\r\n" {
298 exp_continue
299 }
300 -re "^\[^\r\n\]* line $testline1 .tracepoint .$tdp1\\)\r\n" {
301 set linecount1 [expr $linecount1 + 1]
302 exp_continue
303 }
304 -re "^\[^\r\n\]* line $testline2 .tracepoint .$tdp2\\)\r\n" {
305 set linecount2 [expr $linecount2 + 1]
306 exp_continue
307 }
308 -re "^\[^\r\n\]* line $testline3 .tracepoint .$tdp3\\)\r\n" {
309 set linecount3 [expr $linecount3 + 1]
310 exp_continue
311 }
312 -re "^\[^\r\n\]* line $testline4 .tracepoint .$tdp4\\)\r\n" {
313 set linecount4 [expr $linecount4 + 1]
314 exp_continue
315 }
316 -re "^\[^\r\n\]* line $testline5 .tracepoint .$tdp5\\)\r\n" {
317 set linecount5 [expr $linecount5 + 1]
318 exp_continue
319 }
320 -re "^\[^\r\n\]* line $testline6 .tracepoint .$tdp6\\)\r\n" {
321 set linecount6 [expr $linecount6 + 1]
322 exp_continue
323 }
324 -re "^No trace frame found\r\n$gdb_prompt $" {
325 if { ($linecount1 < 4) || ($linecount2 < 4) || ($linecount3 < 4) || ($linecount4 < 4) || ($linecount5 < 4) || ($linecount6 < 4) } {
326 fail "12.1: trace report #1"
327 } else {
328 pass "12.1: trace report #1"
329 }
330 }
331 }
332
333 gdb_tfind_test "12.2: tfind end, selects no frame" "end" "-1"
334 gdb_tfind_test "12.2: find first TDP #2 frame" "tracepoint $tdp2" \
335 "\$tracepoint" "$tdp2"
336
337 set linecount2 0
338
339 gdb_test_multiple "while \$trace_frame != -1\n printf \"tracepoint #\%d, FP 0x\%08x, SP 0x\%08x, PC 0x%08x\\n\", \$tracepoint, \$fp, \$sp, \$pc\n tfind tracepoint\n end" "12.2: trace report #2" {
340 -re "tracepoint #$tdp2, FP $hex, SP $hex, PC $hex" {
341 set linecount2 [expr $linecount2 + 1]
342 exp_continue
343 }
344 -re ".*$gdb_prompt $" {
345 if { ($linecount2 < 4) } {
346 fail "12.2: trace report #2"
347 } else {
348 pass "12.2: trace report #2"
349 }
350 }
351 }
352
353 gdb_tfind_test "12.3: tfind end, selects no frame" "end" "-1"
354 gdb_tfind_test "12.3: find first TDP #3 frame" "tracepoint $tdp3" \
355 "\$tracepoint" "$tdp3"
356
357 set linecount3 0
358
359 gdb_test_multiple "while \$trace_frame != -1\n printf \"TDP #\%d, frame \%d: depth = \%d, q1 = \%d\\n\", \$tracepoint, \$trace_frame, depth, q1\n tfind tracepoint\n end" "12.3: trace report #3" {
360 -re "TDP #$tdp3, frame $decimal: depth = $decimal, q1 = $decimal" {
361 set linecount3 [expr $linecount3 + 1]
362 exp_continue
363 }
364 -re ".*$gdb_prompt $" {
365 if { ($linecount3 < 4) } {
366 fail "12.3: trace report #3"
367 } else {
368 pass "12.3: trace report #3"
369 }
370 }
371 }
372
373 gdb_tfind_test "12.4: tfind end, selects no frame" "end" "-1"
374 gdb_tfind_test "12.4: find first TDP #6 frame" "tracepoint $tdp6" \
375 "\$tracepoint" "$tdp6"
376
377 set linecount6 0
378
379 gdb_test_multiple "while \$trace_frame != -1\n printf \"TDP #\%d, frame %d: char_test = \%d, long_test = \%d\\n\", \$tracepoint, \$trace_frame, gdb_char_test, gdb_long_test\n tfind tracepoint\n end" "12.4: trace report #4" {
380 -re "TDP #$tdp6, frame $decimal: char_test = $arg1, long_test = $arg3" {
381 set linecount6 [expr $linecount6 + 1]
382 exp_continue
383 }
384 -re ".*$gdb_prompt $" {
385 if { ($linecount6 < 4) } {
386 fail "12.4: trace report #4"
387 } else {
388 pass "12.4: trace report #4"
389 }
390 }
391 }
392
393 # Finished!
394 gdb_tfind_test "finished: make sure not debugging any trace frame" "none" "-1"