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