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