* [PATCH 1/2] Check trace data from trace file
@ 2013-02-25 2:58 Yao Qi
2013-02-25 2:58 ` [PATCH 2/2] Find the next matched trace file in 'tfile target' Yao Qi
` (2 more replies)
0 siblings, 3 replies; 12+ messages in thread
From: Yao Qi @ 2013-02-25 2:58 UTC (permalink / raw)
To: gdb-patches
GDB is able to save trace data to trace file via 'tsave' and read
trace data by target 'tfile', however, we don't have a test case. We
have some test cases getting trace data from live inferior, so I have
an idea to "refactor" the test case, so it gets trace data from either
live inferior or trace file. This is also useful to verify that GDB
behaves the same way when data is from either live inferior or trace
file. Secondly, when we support a new trace file format, such as CTF,
it is easy to change test cases to test GDB still behaves correctly on
the new trace file format.
This patch moves code about checking trace data into a proc
"use_collected_data", and invoke it for different targets (live
inferior and tfile). This patch causes an endless loop when executing
this in GDB, which is a bug in GDB.
(gdb) while $trace_frame != -1
> printf "tracepoint #%d, FP 0x%08x, SP 0x%08x, PC 0x%08x\n",
> $tracepoint, $fp, $sp, $pc
> tfind tracepoint
> end
tracepoint #3, FP 0xbfffe808, SP 0xbfffe7d0, PC 0x080483d0^M
Found trace frame 1, tracepoint 3^M
tracepoint #3, FP 0xbfffe808, SP 0xbfffe7d0, PC 0x080483d0
Found trace frame 1, tracepoint 3^M
tracepoint #3, FP 0xbfffe808, SP 0xbfffe7d0, PC 0x080483d0^
The next patch is to fix this bug.
gdb/testsuite:
2013-02-25 Yao Qi <yao@codesourcery.com>
* gdb.trace/report.exp: Move some code to ...
(use_collected_data): ... here. New.
---
gdb/testsuite/gdb.trace/report.exp | 315 ++++++++++++++++++++----------------
1 files changed, 174 insertions(+), 141 deletions(-)
diff --git a/gdb/testsuite/gdb.trace/report.exp b/gdb/testsuite/gdb.trace/report.exp
index e8aa597..6139485 100644
--- a/gdb/testsuite/gdb.trace/report.exp
+++ b/gdb/testsuite/gdb.trace/report.exp
@@ -181,210 +181,243 @@ gdb_test "continue" \
gdb_test "tstop" ".*" ""
-#
-# 9.1 test the tdump command
-#
+gdb_tfind_test "9.1: init: make sure not debugging any trace frame" \
+ "none" "-1"
-set timeout 60
+# 9.3 help tdump
-gdb_tfind_test "9.1: init: make sure not debugging any trace frame" "none" "-1"
+gdb_test "help tdump" "Print everything collected at the current.*" \
+ "9.3: help tdump"
-gdb_tfind_test "9.1: find frame for TP $tdp1" "tracepoint $tdp1" \
+# Check the collected trace data from different sources, such as live
+# infeiror and tfile.
+
+proc use_collected_data { data_source } { with_test_prefix "${data_source}" {
+ global tdp1 tdp2 tdp3 tdp4 tdp5 tdp6
+ global testline1 testline2 testline3 testline4 testline5 testline6
+ global pcreg fpreg spreg
+ global srcfile srcdir subdir
+ global arg1 arg3
+ global decimal hex gdb_prompt
+ #
+ # 9.1 test the tdump command
+ #
+
+ set timeout 60
+
+ gdb_tfind_test "9.1: find frame for TP $tdp1" "tracepoint $tdp1" \
"\$tracepoint" "$tdp1"
-# Nothing was collected at tdp1, so this tdump should be empty.
-gdb_test "tdump" \
- "Data collected at tracepoint $tdp1, trace frame $decimal:" \
+ # Nothing was collected at tdp1, so this tdump should be empty.
+ gdb_test "tdump" \
+ "Data collected at tracepoint $tdp1, trace frame $decimal:\(\|\\r\\nPC register is not available\)" \
"9.1: tdump, nothing collected"
-gdb_tfind_test "9.1: find frame for TP $tdp2" "tracepoint $tdp2" \
+ gdb_tfind_test "9.1: find frame for TP $tdp2" "tracepoint $tdp2" \
"\$tracepoint" "$tdp2"
-# regs were collected at tdp2.
-# How to match for the output of "info registers" on an unknown architecture?
-# For now, assume that most architectures have a register called "pc".
+ # regs were collected at tdp2.
+ # How to match for the output of "info registers" on an unknown architecture?
+ # For now, assume that most architectures have a register called "pc".
-gdb_test "tdump" \
- "\[\r\n\]$pcreg .*" \
- "9.1: tdump, regs collected"
+ gdb_test "tdump" \
+ "\[\r\n\]$pcreg .*" \
+ "9.1: tdump, regs collected"
-gdb_tfind_test "9.1: find frame for TP $tdp3" "tracepoint $tdp3" \
+ gdb_tfind_test "9.1: find frame for TP $tdp3" "tracepoint $tdp3" \
"\$tracepoint" "$tdp3"
-# args were collected at tdp3
-gdb_test "tdump" \
+ # args were collected at tdp3
+ gdb_test "tdump" \
"depth = 3.*q1 = 2.*q2 = 2.*q3 = 3.*q4 = 4.*q5 = 5.*q6 = 6" \
"9.1: tdump, args collected"
-gdb_tfind_test "9.1: find frame for TP $tdp4" "tracepoint $tdp4" \
+ gdb_tfind_test "9.1: find frame for TP $tdp4" "tracepoint $tdp4" \
"\$tracepoint" "$tdp4"
-# locals were collected at tdp4
-gdb_test "tdump" \
+ # locals were collected at tdp4
+ gdb_test "tdump" \
"q = 1" \
"9.1: tdump, locals collected"
-gdb_tfind_test "9.1: find frame for TP $tdp5" "tracepoint $tdp5" \
+ gdb_tfind_test "9.1: find frame for TP $tdp5" "tracepoint $tdp5" \
"\$tracepoint" "$tdp5"
-# stack was collected at tdp5, plus the frame pointer
-gdb_test "tdump" \
- ".$fpreg = .*$spreg @ 64 = .*" \
- "9.1: tdump, memrange collected"
+ # stack was collected at tdp5, plus the frame pointer
+ gdb_test "tdump" \
+ ".$fpreg = .*$spreg @ 64 = .*" \
+ "9.1: tdump, memrange collected"
-gdb_tfind_test "9.1: find frame for TP $tdp6" "tracepoint $tdp6" \
+ gdb_tfind_test "9.1: find frame for TP $tdp6" "tracepoint $tdp6" \
"\$tracepoint" "$tdp6"
-# globals were collected at tdp6
-gdb_test "tdump" \
+ # globals were collected at tdp6
+ gdb_test "tdump" \
"gdb_char_test = 1.*gdb_short_test = 2.*gdb_long_test = 3" \
"9.1: tdump, global variables collected"
-# 9.2 test tdump with arguments
-# [no go, tdump doesn't have any arguments]
+ # 9.2 test tdump with arguments
+ # [no go, tdump doesn't have any arguments]
-# 9.3 help tdump
+ set linecount1 0
+ set linecount2 0
+ set linecount3 0
+ set linecount4 0
+ set linecount5 0
+ set linecount6 0
-gdb_test "help tdump" "Print everything collected at the current.*" \
- "9.3: help tdump"
-
-set linecount1 0
-set linecount2 0
-set linecount3 0
-set linecount4 0
-set linecount5 0
-set linecount6 0
-
-gdb_tfind_test "11.x, 12.1: find start frame" "start" "0"
+ gdb_tfind_test "11.x, 12.1: find start frame" "start" "0"
-#
-# 11.x test built-in trace variables $trace_frame, $trace_line etc.
-#
+ #
+ # 11.x test built-in trace variables $trace_frame, $trace_line etc.
+ #
-gdb_test "printf \"x %d x\\n\", \$trace_frame" "x 0 x" \
+ gdb_test "printf \"x %d x\\n\", \$trace_frame" "x 0 x" \
"11.1: test \$trace_frame"
-gdb_test "printf \"x %d x\\n\", \$tracepoint" "x $tdp1 x" \
+ gdb_test "printf \"x %d x\\n\", \$tracepoint" "x $tdp1 x" \
"11.2: test \$tracepoint"
-gdb_test "printf \"x %d x\\n\", \$trace_line" "x $testline1 x" \
+ gdb_test "printf \"x %d x\\n\", \$trace_line" "x $testline1 x" \
"11.3: test \$trace_line"
-gdb_test_multiple "print \$trace_file" "11.4: test \$trace_file" {
- -re "\\$\[0-9\]+ = \"$srcfile\"\[\r\n\]+$gdb_prompt $" {
- pass "11.4: test \$trace_file"
- }
- -re "\\$\[0-9\]+ = \"$srcdir/$subdir/$srcfile\"\[\r\n\]+$gdb_prompt $" {
- pass "11.4: test \$trace_file"
+ gdb_test_multiple "print \$trace_file" "11.4: test \$trace_file" {
+ -re "\\$\[0-9\]+ = \"$srcfile\"\[\r\n\]+$gdb_prompt $" {
+ pass "11.4: test \$trace_file"
+ }
+ -re "\\$\[0-9\]+ = \"$srcdir/$subdir/$srcfile\"\[\r\n\]+$gdb_prompt $" {
+ pass "11.4: test \$trace_file"
+ }
}
-}
-#gdb_test "print \$trace_file" "\"$srcdir/$subdir/$srcfile\"" \
-# "11.4: test \$trace_file"
+ #gdb_test "print \$trace_file" "\"$srcdir/$subdir/$srcfile\"" \
+ # "11.4: test \$trace_file"
-#
-# 12.x test report generation using arbitrary GDB commands, loops etc.
-#
+ #
+ # 12.x test report generation using arbitrary GDB commands, loops etc.
+ #
-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" {
- -re "> end\r\n" {
- exp_continue
- }
- -re "^Found trace frame \[0-9\]+, tracepoint \[0-9\]+\r\n" {
- exp_continue
- }
- -re "^\[^\r\n\]* line $testline1 .tracepoint .$tdp1\\)\r\n" {
- set linecount1 [expr $linecount1 + 1]
- exp_continue
- }
- -re "^\[^\r\n\]* line $testline2 .tracepoint .$tdp2\\)\r\n" {
- set linecount2 [expr $linecount2 + 1]
- exp_continue
- }
- -re "^\[^\r\n\]* line $testline3 .tracepoint .$tdp3\\)\r\n" {
- set linecount3 [expr $linecount3 + 1]
- exp_continue
- }
- -re "^\[^\r\n\]* line $testline4 .tracepoint .$tdp4\\)\r\n" {
- set linecount4 [expr $linecount4 + 1]
- exp_continue
- }
- -re "^\[^\r\n\]* line $testline5 .tracepoint .$tdp5\\)\r\n" {
- set linecount5 [expr $linecount5 + 1]
- exp_continue
- }
- -re "^\[^\r\n\]* line $testline6 .tracepoint .$tdp6\\)\r\n" {
- set linecount6 [expr $linecount6 + 1]
- exp_continue
- }
- -re "^No trace frame found\r\n$gdb_prompt $" {
- if { ($linecount1 < 4) || ($linecount2 < 4) || ($linecount3 < 4) || ($linecount4 < 4) || ($linecount5 < 4) || ($linecount6 < 4) } {
- fail "12.1: trace report #1"
- } else {
- pass "12.1: trace report #1"
+ 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" {
+ -re "> end\r\n" {
+ exp_continue
+ }
+ -re "^Found trace frame \[0-9\]+, tracepoint \[0-9\]+\r\n" {
+ exp_continue
+ }
+ -re "^\[^\r\n\]* line $testline1 .tracepoint .$tdp1\\)\r\n" {
+ set linecount1 [expr $linecount1 + 1]
+ exp_continue
+ }
+ -re "^\[^\r\n\]* line $testline2 .tracepoint .$tdp2\\)\r\n" {
+ set linecount2 [expr $linecount2 + 1]
+ exp_continue
+ }
+ -re "^\[^\r\n\]* line $testline3 .tracepoint .$tdp3\\)\r\n" {
+ set linecount3 [expr $linecount3 + 1]
+ exp_continue
+ }
+ -re "^\[^\r\n\]* line $testline4 .tracepoint .$tdp4\\)\r\n" {
+ set linecount4 [expr $linecount4 + 1]
+ exp_continue
+ }
+ -re "^\[^\r\n\]* line $testline5 .tracepoint .$tdp5\\)\r\n" {
+ set linecount5 [expr $linecount5 + 1]
+ exp_continue
+ }
+ -re "^\[^\r\n\]* line $testline6 .tracepoint .$tdp6\\)\r\n" {
+ set linecount6 [expr $linecount6 + 1]
+ exp_continue
+ }
+ -re "^No trace frame found\r\n$gdb_prompt $" {
+ if { ($linecount1 < 4) || ($linecount2 < 4) || ($linecount3 < 4) || ($linecount4 < 4) || ($linecount5 < 4) || ($linecount6 < 4) } {
+ fail "12.1: trace report #1"
+ } else {
+ pass "12.1: trace report #1"
+ }
}
}
-}
-gdb_tfind_test "12.2: tfind end, selects no frame" "end" "-1"
-gdb_tfind_test "12.2: find first TDP #2 frame" "tracepoint $tdp2" \
+ gdb_tfind_test "12.2: tfind end, selects no frame" "end" "-1"
+ gdb_tfind_test "12.2: find first TDP #2 frame" "tracepoint $tdp2" \
"\$tracepoint" "$tdp2"
-set linecount2 0
+ set linecount2 0
-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" {
- -re "tracepoint #$tdp2, FP $hex, SP $hex, PC $hex" {
- set linecount2 [expr $linecount2 + 1]
- exp_continue
- }
- -re ".*$gdb_prompt $" {
- if { ($linecount2 < 4) } {
- fail "12.2: trace report #2"
- } else {
- pass "12.2: trace report #2"
+ 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" {
+ -re "tracepoint #$tdp2, FP $hex, SP $hex, PC $hex" {
+ set linecount2 [expr $linecount2 + 1]
+ exp_continue
+ }
+ -re ".*$gdb_prompt $" {
+ if { ($linecount2 < 4) } {
+ fail "12.2: trace report #2"
+ } else {
+ pass "12.2: trace report #2"
+ }
}
}
-}
-gdb_tfind_test "12.3: tfind end, selects no frame" "end" "-1"
-gdb_tfind_test "12.3: find first TDP #3 frame" "tracepoint $tdp3" \
+ gdb_tfind_test "12.3: tfind end, selects no frame" "end" "-1"
+ gdb_tfind_test "12.3: find first TDP #3 frame" "tracepoint $tdp3" \
"\$tracepoint" "$tdp3"
-set linecount3 0
+ set linecount3 0
-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" {
- -re "TDP #$tdp3, frame $decimal: depth = $decimal, q1 = $decimal" {
- set linecount3 [expr $linecount3 + 1]
- exp_continue
- }
- -re ".*$gdb_prompt $" {
- if { ($linecount3 < 4) } {
- fail "12.3: trace report #3"
- } else {
- pass "12.3: trace report #3"
+ 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" {
+ -re "TDP #$tdp3, frame $decimal: depth = $decimal, q1 = $decimal" {
+ set linecount3 [expr $linecount3 + 1]
+ exp_continue
+ }
+ -re ".*$gdb_prompt $" {
+ if { ($linecount3 < 4) } {
+ fail "12.3: trace report #3"
+ } else {
+ pass "12.3: trace report #3"
+ }
}
}
-}
-gdb_tfind_test "12.4: tfind end, selects no frame" "end" "-1"
-gdb_tfind_test "12.4: find first TDP #6 frame" "tracepoint $tdp6" \
+ gdb_tfind_test "12.4: tfind end, selects no frame" "end" "-1"
+ gdb_tfind_test "12.4: find first TDP #6 frame" "tracepoint $tdp6" \
"\$tracepoint" "$tdp6"
-set linecount6 0
+ set linecount6 0
-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" {
- -re "TDP #$tdp6, frame $decimal: char_test = $arg1, long_test = $arg3" {
- set linecount6 [expr $linecount6 + 1]
- exp_continue
- }
- -re ".*$gdb_prompt $" {
- if { ($linecount6 < 4) } {
- fail "12.4: trace report #4"
- } else {
- pass "12.4: trace report #4"
+ 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" {
+ -re "TDP #$tdp6, frame $decimal: char_test = $arg1, long_test = $arg3" {
+ set linecount6 [expr $linecount6 + 1]
+ exp_continue
+ }
+ -re ".*$gdb_prompt $" {
+ if { ($linecount6 < 4) } {
+ fail "12.4: trace report #4"
+ } else {
+ pass "12.4: trace report #4"
+ }
}
}
}
+}
+
+use_collected_data "live"
# Finished!
-gdb_tfind_test "finished: make sure not debugging any trace frame" "none" "-1"
+gdb_tfind_test "finished: make sure not debugging any trace frame" \
+ "none" "-1"
+
+# Save trace frames to tfile.
+gdb_test "tsave report.tf" "Trace data saved to file 'report.tf'.*"
+
+# Change target to tfile.
+set test "change to tfile target"
+gdb_test_multiple "target tfile report.tf" "$test" {
+ -re "A program is being debugged already. Kill it. .y or n. " {
+ send_gdb "y\n"
+ exp_continue
+ }
+ -re "$gdb_prompt $" {
+ pass "$test"
+ }
+}
+# Test the collected trace frames from tfile.
+use_collected_data "tfile"
--
1.7.7.6
^ permalink raw reply [flat|nested] 12+ messages in thread* [PATCH 2/2] Find the next matched trace file in 'tfile target'. 2013-02-25 2:58 [PATCH 1/2] Check trace data from trace file Yao Qi @ 2013-02-25 2:58 ` Yao Qi 2013-02-26 19:53 ` Pedro Alves 2013-02-25 3:10 ` [PATCH 1/2] Check trace data from trace file Yao Qi 2013-02-25 12:03 ` Abid, Hafiz 2 siblings, 1 reply; 12+ messages in thread From: Yao Qi @ 2013-02-25 2:58 UTC (permalink / raw) To: gdb-patches The previous patch exposes a bug in tfile target when finding a trace frame. Every time, GDB will scan tfile from the starting offset and initialize trace frame number to zero. When TYPE is not tfind_number, it means GDB wants to find the *next* matched trace frame of current one. So we need to check the tfile trace frame number iterator is greater than the current trace frame number (which means *next*). This is mainly what this patch does. Regression tested on x86_64-linux. gdb: 2013-02-25 Yao Qi <yao@codesourcery.com> * tracepoint.c (tfile_trace_find): Find the next matched trace frame. --- gdb/tracepoint.c | 20 ++++++++++++++++---- 1 files changed, 16 insertions(+), 4 deletions(-) diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c index ca104aa..f7a3650 100644 --- a/gdb/tracepoint.c +++ b/gdb/tracepoint.c @@ -4324,22 +4324,34 @@ tfile_trace_find (enum trace_find_type type, int num, break; case tfind_pc: tfaddr = tfile_get_traceframe_address (tframe_offset); - if (tfaddr == addr1) + if (tfaddr == addr1 + /* Looks for the next trace frame if matched. */ + && (tfnum > traceframe_number + || (tfnum == traceframe_number && tfnum == 0))) found = 1; break; case tfind_tp: tp = get_tracepoint (num); - if (tp && tpnum == tp->number_on_target) + if (tp && tpnum == tp->number_on_target + /* Looks for the next trace frame if matched. */ + && (tfnum > traceframe_number + || (tfnum == traceframe_number && tfnum == 0))) found = 1; break; case tfind_range: tfaddr = tfile_get_traceframe_address (tframe_offset); - if (addr1 <= tfaddr && tfaddr <= addr2) + if (addr1 <= tfaddr && tfaddr <= addr2 + /* Looks for the next trace frame if matched. */ + && (tfnum > traceframe_number + || (tfnum == traceframe_number && tfnum == 0))) found = 1; break; case tfind_outside: tfaddr = tfile_get_traceframe_address (tframe_offset); - if (!(addr1 <= tfaddr && tfaddr <= addr2)) + if (!(addr1 <= tfaddr && tfaddr <= addr2) + /* Looks for the next trace frame if matched. */ + && (tfnum > traceframe_number + || (tfnum == traceframe_number && tfnum == 0))) found = 1; break; default: -- 1.7.7.6 ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/2] Find the next matched trace file in 'tfile target'. 2013-02-25 2:58 ` [PATCH 2/2] Find the next matched trace file in 'tfile target' Yao Qi @ 2013-02-26 19:53 ` Pedro Alves 2013-02-27 1:37 ` Yao Qi 0 siblings, 1 reply; 12+ messages in thread From: Pedro Alves @ 2013-02-26 19:53 UTC (permalink / raw) To: Yao Qi; +Cc: gdb-patches [-- Attachment #1: Type: text/plain, Size: 2557 bytes --] On 02/25/2013 02:57 AM, Yao Qi wrote: > The previous patch exposes a bug in tfile target when finding a trace > frame. Every time, GDB will scan tfile from the starting offset and > initialize trace frame number to zero. When TYPE is not tfind_number, > it means GDB wants to find the *next* matched trace frame of current > one. So we need to check the tfile trace frame number iterator is > greater than the current trace frame number (which means *next*). > This is mainly what this patch does. Thanks. Good catch. > diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c > index ca104aa..f7a3650 100644 > --- a/gdb/tracepoint.c > +++ b/gdb/tracepoint.c > @@ -4324,22 +4324,34 @@ tfile_trace_find (enum trace_find_type type, int num, > break; > case tfind_pc: > tfaddr = tfile_get_traceframe_address (tframe_offset); > - if (tfaddr == addr1) > + if (tfaddr == addr1 > + /* Looks for the next trace frame if matched. */ > + && (tfnum > traceframe_number > + || (tfnum == traceframe_number && tfnum == 0))) > found = 1; > break; > case tfind_tp: > tp = get_tracepoint (num); > - if (tp && tpnum == tp->number_on_target) > + if (tp && tpnum == tp->number_on_target > + /* Looks for the next trace frame if matched. */ > + && (tfnum > traceframe_number > + || (tfnum == traceframe_number && tfnum == 0))) > found = 1; > break; > case tfind_range: > tfaddr = tfile_get_traceframe_address (tframe_offset); > - if (addr1 <= tfaddr && tfaddr <= addr2) > + if (addr1 <= tfaddr && tfaddr <= addr2 > + /* Looks for the next trace frame if matched. */ > + && (tfnum > traceframe_number > + || (tfnum == traceframe_number && tfnum == 0))) > found = 1; > break; > case tfind_outside: > tfaddr = tfile_get_traceframe_address (tframe_offset); > - if (!(addr1 <= tfaddr && tfaddr <= addr2)) > + if (!(addr1 <= tfaddr && tfaddr <= addr2) > + /* Looks for the next trace frame if matched. */ > + && (tfnum > traceframe_number > + || (tfnum == traceframe_number && tfnum == 0))) I'm confused on why this bit of the predicate (tfnum == traceframe_number && tfnum == 0) is necessary. traceframe_number is -1 when not looking at a traceframe yet, so "tfnum > traceframe_number" should be sufficient, no? I find it clearer to move the frame skipping a bit higher up, even before the specific tfind tp/range/etc. matching. Doing it this way also avoids unnecessary read/lseek system calls done by tfile_get_traceframe_address. WDYT? [-- Attachment #2: tfile_find.diff --] [-- Type: text/x-patch, Size: 3039 bytes --] commit f837913c7a153a0e40a15f4a283deea201cbcbe7 Author: Pedro Alves <palves@redhat.com> Date: Tue Feb 26 19:43:21 2013 +0000 Find the next matched trace file in 'tfile target'. The previous patch exposes a bug in the tfile target when finding a trace frame. Every time, GDB will scan tfile from the starting offset and look for a matching trace frame starting from frame zero. But, except when TYPE is tfind_number, GDB wants to find the *next* matched trace frame after the current selected frame. So we need to check the tfile trace frame number iterator is greater than the current trace frame number (which means *next*), meaning skip all frames up to and including the current. Regression tested on x86_64 Fedora 17. gdb/ 2013-02-25 Yao Qi <yao@codesourcery.com> Pedro Alves <palves@redhat.com> * tracepoint.c (tfile_trace_find): For tfind pc/tp/range/outside, look for the next trace frame instead of always starting from frame 0. diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c index ca104aa..9a80aa3 100644 --- a/gdb/tracepoint.c +++ b/gdb/tracepoint.c @@ -4316,35 +4316,46 @@ tfile_trace_find (enum trace_find_type type, int num, ((gdb_byte *) &data_size, 4, gdbarch_byte_order (target_gdbarch ())); offset += 4; - switch (type) + + if (type == tfind_number) { - case tfind_number: + /* Looking for a specific trace frame. */ if (tfnum == num) found = 1; - break; - case tfind_pc: - tfaddr = tfile_get_traceframe_address (tframe_offset); - if (tfaddr == addr1) - found = 1; - break; - case tfind_tp: - tp = get_tracepoint (num); - if (tp && tpnum == tp->number_on_target) - found = 1; - break; - case tfind_range: - tfaddr = tfile_get_traceframe_address (tframe_offset); - if (addr1 <= tfaddr && tfaddr <= addr2) - found = 1; - break; - case tfind_outside: - tfaddr = tfile_get_traceframe_address (tframe_offset); - if (!(addr1 <= tfaddr && tfaddr <= addr2)) - found = 1; - break; - default: - internal_error (__FILE__, __LINE__, _("unknown tfind type")); } + else + { + /* Start from the _next_ trace frame. */ + if (tfnum > traceframe_number) + { + switch (type) + { + case tfind_pc: + tfaddr = tfile_get_traceframe_address (tframe_offset); + if (tfaddr == addr1) + found = 1; + break; + case tfind_tp: + tp = get_tracepoint (num); + if (tp && tpnum == tp->number_on_target) + found = 1; + break; + case tfind_range: + tfaddr = tfile_get_traceframe_address (tframe_offset); + if (addr1 <= tfaddr && tfaddr <= addr2) + found = 1; + break; + case tfind_outside: + tfaddr = tfile_get_traceframe_address (tframe_offset); + if (!(addr1 <= tfaddr && tfaddr <= addr2)) + found = 1; + break; + default: + internal_error (__FILE__, __LINE__, _("unknown tfind type")); + } + } + } + if (found) { if (tpp) ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/2] Find the next matched trace file in 'tfile target'. 2013-02-26 19:53 ` Pedro Alves @ 2013-02-27 1:37 ` Yao Qi 0 siblings, 0 replies; 12+ messages in thread From: Yao Qi @ 2013-02-27 1:37 UTC (permalink / raw) To: Pedro Alves; +Cc: gdb-patches On 02/27/2013 03:52 AM, Pedro Alves wrote: > I'm confused on why this bit of the predicate > > (tfnum == traceframe_number && tfnum == 0) > > is necessary. traceframe_number is -1 when not looking > at a traceframe yet, so "tfnum > traceframe_number" > should be sufficient, no? > This condition was added to handle the case like this below: (gdb) tfind 0 Found trace frame 0, tracepoint 2 (gdb) tfind tracepoint 2 Found trace frame 0, tracepoint 2 It is not necessary, and doesn't match the documentation. We start from trace frame zero, and look for *next* frame from trace frame one. This predicate can be removed. > I find it clearer to move the frame skipping a bit higher > up, even before the specific tfind tp/range/etc. matching. > Doing it this way also avoids unnecessary read/lseek system > calls done by tfile_get_traceframe_address. > > WDYT? > That makes sense to me. > > Regression tested on x86_64 Fedora 17. > > gdb/ > 2013-02-25 Yao Qi<yao@codesourcery.com> > Pedro Alves<palves@redhat.com> > > * tracepoint.c (tfile_trace_find): For tfind > pc/tp/range/outside, look for the next trace frame instead of > always starting from frame 0. Committed. -- Yao (é½å°§) ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/2] Check trace data from trace file 2013-02-25 2:58 [PATCH 1/2] Check trace data from trace file Yao Qi 2013-02-25 2:58 ` [PATCH 2/2] Find the next matched trace file in 'tfile target' Yao Qi @ 2013-02-25 3:10 ` Yao Qi 2013-02-26 18:44 ` Pedro Alves 2013-02-26 18:57 ` Pedro Alves 2013-02-25 12:03 ` Abid, Hafiz 2 siblings, 2 replies; 12+ messages in thread From: Yao Qi @ 2013-02-25 3:10 UTC (permalink / raw) To: gdb-patches Here is the same patch with spaces ignored. It is easier to read. Note that I modified a matched pattern "PC register is not available" for tfile target, as the regcache is not available when switch to tfind mode (no regcache has been read out of 'R' block yet). diff --git a/gdb/testsuite/gdb.trace/report.exp b/gdb/testsuite/gdb.trace/report.exp index e8aa597..6139485 100644 --- a/gdb/testsuite/gdb.trace/report.exp +++ b/gdb/testsuite/gdb.trace/report.exp @@ -181,20 +181,36 @@ gdb_test "continue" \ gdb_test "tstop" ".*" "" +gdb_tfind_test "9.1: init: make sure not debugging any trace frame" \ + "none" "-1" + +# 9.3 help tdump + +gdb_test "help tdump" "Print everything collected at the current.*" \ + "9.3: help tdump" + +# Check the collected trace data from different sources, such as live +# infeiror and tfile. + +proc use_collected_data { data_source } { with_test_prefix "${data_source}" { + global tdp1 tdp2 tdp3 tdp4 tdp5 tdp6 + global testline1 testline2 testline3 testline4 testline5 testline6 + global pcreg fpreg spreg + global srcfile srcdir subdir + global arg1 arg3 + global decimal hex gdb_prompt # # 9.1 test the tdump command # set timeout 60 -gdb_tfind_test "9.1: init: make sure not debugging any trace frame" "none" "-1" - gdb_tfind_test "9.1: find frame for TP $tdp1" "tracepoint $tdp1" \ "\$tracepoint" "$tdp1" # Nothing was collected at tdp1, so this tdump should be empty. gdb_test "tdump" \ - "Data collected at tracepoint $tdp1, trace frame $decimal:" \ + "Data collected at tracepoint $tdp1, trace frame $decimal:\(\|\\r\\nPC register is not available\)" \ "9.1: tdump, nothing collected" gdb_tfind_test "9.1: find frame for TP $tdp2" "tracepoint $tdp2" \ @@ -243,11 +259,6 @@ gdb_test "tdump" \ # 9.2 test tdump with arguments # [no go, tdump doesn't have any arguments] -# 9.3 help tdump - -gdb_test "help tdump" "Print everything collected at the current.*" \ - "9.3: help tdump" - set linecount1 0 set linecount2 0 set linecount3 0 @@ -385,6 +396,28 @@ gdb_test_multiple "while \$trace_frame != -1\n printf \"TDP #\%d, frame %d: char } } } +} +} + +use_collected_data "live" # Finished! -gdb_tfind_test "finished: make sure not debugging any trace frame" "none" "-1" +gdb_tfind_test "finished: make sure not debugging any trace frame" \ + "none" "-1" + +# Save trace frames to tfile. +gdb_test "tsave report.tf" "Trace data saved to file 'report.tf'.*" + +# Change target to tfile. +set test "change to tfile target" +gdb_test_multiple "target tfile report.tf" "$test" { + -re "A program is being debugged already. Kill it. .y or n. " { + send_gdb "y\n" + exp_continue + } + -re "$gdb_prompt $" { + pass "$test" + } +} +# Test the collected trace frames from tfile. +use_collected_data "tfile" ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/2] Check trace data from trace file 2013-02-25 3:10 ` [PATCH 1/2] Check trace data from trace file Yao Qi @ 2013-02-26 18:44 ` Pedro Alves 2013-02-26 18:57 ` Pedro Alves 1 sibling, 0 replies; 12+ messages in thread From: Pedro Alves @ 2013-02-26 18:44 UTC (permalink / raw) To: Yao Qi; +Cc: gdb-patches On 02/25/2013 03:08 AM, Yao Qi wrote: > Here is the same patch with spaces ignored. It is easier to read. > Note that I modified a matched pattern "PC register is not > available" for tfile target, as the regcache is not available when > switch to tfind mode (no regcache has been read out of 'R' block yet). Hmmm. Not sure. Shouldn't something have caught that exception? IOW, could that be a bug? I'm having difficulty figuring it out, because when I run the test I don't see that output anywhere in the gdb.log: (gdb) printf "x %d x\n", $tracepoint x 2 x (gdb) PASS: gdb.trace/report.exp: tfile: 9.1: find frame for TP 2 tdump Data collected at tracepoint 2, trace frame 0: (gdb) PASS: gdb.trace/report.exp: tfile: 9.1: tdump, nothing collected I wonder what's different in our environments. > > # Nothing was collected at tdp1, so this tdump should be empty. > gdb_test "tdump" \ > - "Data collected at tracepoint $tdp1, trace frame $decimal:" \ > + "Data collected at tracepoint $tdp1, trace frame $decimal:\(\|\\r\\nPC register is not available\)" \ > "9.1: tdump, nothing collected" -- Pedro Alves ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/2] Check trace data from trace file 2013-02-25 3:10 ` [PATCH 1/2] Check trace data from trace file Yao Qi 2013-02-26 18:44 ` Pedro Alves @ 2013-02-26 18:57 ` Pedro Alves 2013-02-27 1:54 ` Yao Qi 1 sibling, 1 reply; 12+ messages in thread From: Pedro Alves @ 2013-02-26 18:57 UTC (permalink / raw) To: Yao Qi; +Cc: gdb-patches On 02/25/2013 03:08 AM, Yao Qi wrote: > +# Check the collected trace data from different sources, such as live > +# infeiror and tfile. Typo "inferior". > 2013-02-25 Yao Qi <yao@codesourcery.com> > > * gdb.trace/report.exp: Move some code to ... > (use_collected_data): ... here. New. Add something like: (top level): Call use_collected_data once on the live target. Save a tfile of the current trace session, load it with target tfile, and call use_collected_data again. -- Pedro Alves ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/2] Check trace data from trace file 2013-02-26 18:57 ` Pedro Alves @ 2013-02-27 1:54 ` Yao Qi 2013-02-27 15:23 ` Pedro Alves 0 siblings, 1 reply; 12+ messages in thread From: Yao Qi @ 2013-02-27 1:54 UTC (permalink / raw) To: Pedro Alves; +Cc: gdb-patches On 02/27/2013 02:44 AM, Pedro Alves wrote:> On 02/25/2013 03:08 AM, Yao Qi wrote: >> >Here is the same patch with spaces ignored. It is easier to read. >> >Note that I modified a matched pattern "PC register is not >> >available" for tfile target, as the regcache is not available when >> >switch to tfind mode (no regcache has been read out of 'R' block yet). > Hmmm. Not sure. Shouldn't something have caught that exception? IOW, > could that be a bug? > > I'm having difficulty figuring it out, because when I run the test > I don't see that output anywhere in the gdb.log: > > (gdb) printf "x %d x\n", $tracepoint > x 2 x > (gdb) PASS: gdb.trace/report.exp: tfile: 9.1: find frame for TP 2 > tdump > Data collected at tracepoint 2, trace frame 0: > (gdb) PASS: gdb.trace/report.exp: tfile: 9.1: tdump, nothing collected > > I wonder what's different in our environments. > Yeah, it shows up in one build server. I tried the test on my laptop (Fedora 16) and the other build server, it is OK. Then, I get rid of the pattern to match "PC register is not available". I'll check it on that build server. On 02/27/2013 02:57 AM, Pedro Alves wrote: > Typo "inferior". > Fixed. >> >2013-02-25 Yao Qi<yao@codesourcery.com> >> > >> > * gdb.trace/report.exp: Move some code to ... >> > (use_collected_data): ... here. New. > Add something like: > > (top level): Call use_collected_data once on the live > target. Save a tfile of the current trace session, > load it with target tfile, and call use_collected_data > again. The changelog entry is completed as you suggested (wo/ "top level"). -- Yao (é½å°§) gdb/testsuite: 2013-02-27 Yao Qi <yao@codesourcery.com> * gdb.trace/report.exp: Move some code to ... (use_collected_data): New. Call use_collected_data once on the live target. Save a tfile of the current trace session, load it with target tfile, and call use_collected_data again. --- gdb/testsuite/gdb.trace/report.exp | 313 ++++++++++++++++++++---------------- 1 files changed, 173 insertions(+), 140 deletions(-) diff --git a/gdb/testsuite/gdb.trace/report.exp b/gdb/testsuite/gdb.trace/report.exp index e8aa597..b32bca1 100644 --- a/gdb/testsuite/gdb.trace/report.exp +++ b/gdb/testsuite/gdb.trace/report.exp @@ -181,210 +181,243 @@ gdb_test "continue" \ gdb_test "tstop" ".*" "" -# -# 9.1 test the tdump command -# +gdb_tfind_test "9.1: init: make sure not debugging any trace frame" \ + "none" "-1" -set timeout 60 +# 9.3 help tdump -gdb_tfind_test "9.1: init: make sure not debugging any trace frame" "none" "-1" +gdb_test "help tdump" "Print everything collected at the current.*" \ + "9.3: help tdump" -gdb_tfind_test "9.1: find frame for TP $tdp1" "tracepoint $tdp1" \ +# Check the collected trace data from different sources, such as live +# inferior and tfile. + +proc use_collected_data { data_source } { with_test_prefix "${data_source}" { + global tdp1 tdp2 tdp3 tdp4 tdp5 tdp6 + global testline1 testline2 testline3 testline4 testline5 testline6 + global pcreg fpreg spreg + global srcfile srcdir subdir + global arg1 arg3 + global decimal hex gdb_prompt + # + # 9.1 test the tdump command + # + + set timeout 60 + + gdb_tfind_test "9.1: find frame for TP $tdp1" "tracepoint $tdp1" \ "\$tracepoint" "$tdp1" -# Nothing was collected at tdp1, so this tdump should be empty. -gdb_test "tdump" \ + # Nothing was collected at tdp1, so this tdump should be empty. + gdb_test "tdump" \ "Data collected at tracepoint $tdp1, trace frame $decimal:" \ "9.1: tdump, nothing collected" -gdb_tfind_test "9.1: find frame for TP $tdp2" "tracepoint $tdp2" \ + gdb_tfind_test "9.1: find frame for TP $tdp2" "tracepoint $tdp2" \ "\$tracepoint" "$tdp2" -# regs were collected at tdp2. -# How to match for the output of "info registers" on an unknown architecture? -# For now, assume that most architectures have a register called "pc". + # regs were collected at tdp2. + # How to match for the output of "info registers" on an unknown architecture? + # For now, assume that most architectures have a register called "pc". -gdb_test "tdump" \ - "\[\r\n\]$pcreg .*" \ - "9.1: tdump, regs collected" + gdb_test "tdump" \ + "\[\r\n\]$pcreg .*" \ + "9.1: tdump, regs collected" -gdb_tfind_test "9.1: find frame for TP $tdp3" "tracepoint $tdp3" \ + gdb_tfind_test "9.1: find frame for TP $tdp3" "tracepoint $tdp3" \ "\$tracepoint" "$tdp3" -# args were collected at tdp3 -gdb_test "tdump" \ + # args were collected at tdp3 + gdb_test "tdump" \ "depth = 3.*q1 = 2.*q2 = 2.*q3 = 3.*q4 = 4.*q5 = 5.*q6 = 6" \ "9.1: tdump, args collected" -gdb_tfind_test "9.1: find frame for TP $tdp4" "tracepoint $tdp4" \ + gdb_tfind_test "9.1: find frame for TP $tdp4" "tracepoint $tdp4" \ "\$tracepoint" "$tdp4" -# locals were collected at tdp4 -gdb_test "tdump" \ + # locals were collected at tdp4 + gdb_test "tdump" \ "q = 1" \ "9.1: tdump, locals collected" -gdb_tfind_test "9.1: find frame for TP $tdp5" "tracepoint $tdp5" \ + gdb_tfind_test "9.1: find frame for TP $tdp5" "tracepoint $tdp5" \ "\$tracepoint" "$tdp5" -# stack was collected at tdp5, plus the frame pointer -gdb_test "tdump" \ - ".$fpreg = .*$spreg @ 64 = .*" \ - "9.1: tdump, memrange collected" + # stack was collected at tdp5, plus the frame pointer + gdb_test "tdump" \ + ".$fpreg = .*$spreg @ 64 = .*" \ + "9.1: tdump, memrange collected" -gdb_tfind_test "9.1: find frame for TP $tdp6" "tracepoint $tdp6" \ + gdb_tfind_test "9.1: find frame for TP $tdp6" "tracepoint $tdp6" \ "\$tracepoint" "$tdp6" -# globals were collected at tdp6 -gdb_test "tdump" \ + # globals were collected at tdp6 + gdb_test "tdump" \ "gdb_char_test = 1.*gdb_short_test = 2.*gdb_long_test = 3" \ "9.1: tdump, global variables collected" -# 9.2 test tdump with arguments -# [no go, tdump doesn't have any arguments] + # 9.2 test tdump with arguments + # [no go, tdump doesn't have any arguments] -# 9.3 help tdump + set linecount1 0 + set linecount2 0 + set linecount3 0 + set linecount4 0 + set linecount5 0 + set linecount6 0 -gdb_test "help tdump" "Print everything collected at the current.*" \ - "9.3: help tdump" - -set linecount1 0 -set linecount2 0 -set linecount3 0 -set linecount4 0 -set linecount5 0 -set linecount6 0 - -gdb_tfind_test "11.x, 12.1: find start frame" "start" "0" + gdb_tfind_test "11.x, 12.1: find start frame" "start" "0" -# -# 11.x test built-in trace variables $trace_frame, $trace_line etc. -# + # + # 11.x test built-in trace variables $trace_frame, $trace_line etc. + # -gdb_test "printf \"x %d x\\n\", \$trace_frame" "x 0 x" \ + gdb_test "printf \"x %d x\\n\", \$trace_frame" "x 0 x" \ "11.1: test \$trace_frame" -gdb_test "printf \"x %d x\\n\", \$tracepoint" "x $tdp1 x" \ + gdb_test "printf \"x %d x\\n\", \$tracepoint" "x $tdp1 x" \ "11.2: test \$tracepoint" -gdb_test "printf \"x %d x\\n\", \$trace_line" "x $testline1 x" \ + gdb_test "printf \"x %d x\\n\", \$trace_line" "x $testline1 x" \ "11.3: test \$trace_line" -gdb_test_multiple "print \$trace_file" "11.4: test \$trace_file" { - -re "\\$\[0-9\]+ = \"$srcfile\"\[\r\n\]+$gdb_prompt $" { - pass "11.4: test \$trace_file" - } - -re "\\$\[0-9\]+ = \"$srcdir/$subdir/$srcfile\"\[\r\n\]+$gdb_prompt $" { - pass "11.4: test \$trace_file" + gdb_test_multiple "print \$trace_file" "11.4: test \$trace_file" { + -re "\\$\[0-9\]+ = \"$srcfile\"\[\r\n\]+$gdb_prompt $" { + pass "11.4: test \$trace_file" + } + -re "\\$\[0-9\]+ = \"$srcdir/$subdir/$srcfile\"\[\r\n\]+$gdb_prompt $" { + pass "11.4: test \$trace_file" + } } -} -#gdb_test "print \$trace_file" "\"$srcdir/$subdir/$srcfile\"" \ -# "11.4: test \$trace_file" + #gdb_test "print \$trace_file" "\"$srcdir/$subdir/$srcfile\"" \ + # "11.4: test \$trace_file" -# -# 12.x test report generation using arbitrary GDB commands, loops etc. -# + # + # 12.x test report generation using arbitrary GDB commands, loops etc. + # -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" { - -re "> end\r\n" { - exp_continue - } - -re "^Found trace frame \[0-9\]+, tracepoint \[0-9\]+\r\n" { - exp_continue - } - -re "^\[^\r\n\]* line $testline1 .tracepoint .$tdp1\\)\r\n" { - set linecount1 [expr $linecount1 + 1] - exp_continue - } - -re "^\[^\r\n\]* line $testline2 .tracepoint .$tdp2\\)\r\n" { - set linecount2 [expr $linecount2 + 1] - exp_continue - } - -re "^\[^\r\n\]* line $testline3 .tracepoint .$tdp3\\)\r\n" { - set linecount3 [expr $linecount3 + 1] - exp_continue - } - -re "^\[^\r\n\]* line $testline4 .tracepoint .$tdp4\\)\r\n" { - set linecount4 [expr $linecount4 + 1] - exp_continue - } - -re "^\[^\r\n\]* line $testline5 .tracepoint .$tdp5\\)\r\n" { - set linecount5 [expr $linecount5 + 1] - exp_continue - } - -re "^\[^\r\n\]* line $testline6 .tracepoint .$tdp6\\)\r\n" { - set linecount6 [expr $linecount6 + 1] - exp_continue - } - -re "^No trace frame found\r\n$gdb_prompt $" { - if { ($linecount1 < 4) || ($linecount2 < 4) || ($linecount3 < 4) || ($linecount4 < 4) || ($linecount5 < 4) || ($linecount6 < 4) } { - fail "12.1: trace report #1" - } else { - pass "12.1: trace report #1" + 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" { + -re "> end\r\n" { + exp_continue + } + -re "^Found trace frame \[0-9\]+, tracepoint \[0-9\]+\r\n" { + exp_continue + } + -re "^\[^\r\n\]* line $testline1 .tracepoint .$tdp1\\)\r\n" { + set linecount1 [expr $linecount1 + 1] + exp_continue + } + -re "^\[^\r\n\]* line $testline2 .tracepoint .$tdp2\\)\r\n" { + set linecount2 [expr $linecount2 + 1] + exp_continue + } + -re "^\[^\r\n\]* line $testline3 .tracepoint .$tdp3\\)\r\n" { + set linecount3 [expr $linecount3 + 1] + exp_continue + } + -re "^\[^\r\n\]* line $testline4 .tracepoint .$tdp4\\)\r\n" { + set linecount4 [expr $linecount4 + 1] + exp_continue + } + -re "^\[^\r\n\]* line $testline5 .tracepoint .$tdp5\\)\r\n" { + set linecount5 [expr $linecount5 + 1] + exp_continue + } + -re "^\[^\r\n\]* line $testline6 .tracepoint .$tdp6\\)\r\n" { + set linecount6 [expr $linecount6 + 1] + exp_continue + } + -re "^No trace frame found\r\n$gdb_prompt $" { + if { ($linecount1 < 4) || ($linecount2 < 4) || ($linecount3 < 4) || ($linecount4 < 4) || ($linecount5 < 4) || ($linecount6 < 4) } { + fail "12.1: trace report #1" + } else { + pass "12.1: trace report #1" + } } } -} -gdb_tfind_test "12.2: tfind end, selects no frame" "end" "-1" -gdb_tfind_test "12.2: find first TDP #2 frame" "tracepoint $tdp2" \ + gdb_tfind_test "12.2: tfind end, selects no frame" "end" "-1" + gdb_tfind_test "12.2: find first TDP #2 frame" "tracepoint $tdp2" \ "\$tracepoint" "$tdp2" -set linecount2 0 + set linecount2 0 -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" { - -re "tracepoint #$tdp2, FP $hex, SP $hex, PC $hex" { - set linecount2 [expr $linecount2 + 1] - exp_continue - } - -re ".*$gdb_prompt $" { - if { ($linecount2 < 4) } { - fail "12.2: trace report #2" - } else { - pass "12.2: trace report #2" + 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" { + -re "tracepoint #$tdp2, FP $hex, SP $hex, PC $hex" { + set linecount2 [expr $linecount2 + 1] + exp_continue + } + -re ".*$gdb_prompt $" { + if { ($linecount2 < 4) } { + fail "12.2: trace report #2" + } else { + pass "12.2: trace report #2" + } } } -} -gdb_tfind_test "12.3: tfind end, selects no frame" "end" "-1" -gdb_tfind_test "12.3: find first TDP #3 frame" "tracepoint $tdp3" \ + gdb_tfind_test "12.3: tfind end, selects no frame" "end" "-1" + gdb_tfind_test "12.3: find first TDP #3 frame" "tracepoint $tdp3" \ "\$tracepoint" "$tdp3" -set linecount3 0 + set linecount3 0 -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" { - -re "TDP #$tdp3, frame $decimal: depth = $decimal, q1 = $decimal" { - set linecount3 [expr $linecount3 + 1] - exp_continue - } - -re ".*$gdb_prompt $" { - if { ($linecount3 < 4) } { - fail "12.3: trace report #3" - } else { - pass "12.3: trace report #3" + 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" { + -re "TDP #$tdp3, frame $decimal: depth = $decimal, q1 = $decimal" { + set linecount3 [expr $linecount3 + 1] + exp_continue + } + -re ".*$gdb_prompt $" { + if { ($linecount3 < 4) } { + fail "12.3: trace report #3" + } else { + pass "12.3: trace report #3" + } } } -} -gdb_tfind_test "12.4: tfind end, selects no frame" "end" "-1" -gdb_tfind_test "12.4: find first TDP #6 frame" "tracepoint $tdp6" \ + gdb_tfind_test "12.4: tfind end, selects no frame" "end" "-1" + gdb_tfind_test "12.4: find first TDP #6 frame" "tracepoint $tdp6" \ "\$tracepoint" "$tdp6" -set linecount6 0 + set linecount6 0 -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" { - -re "TDP #$tdp6, frame $decimal: char_test = $arg1, long_test = $arg3" { - set linecount6 [expr $linecount6 + 1] - exp_continue - } - -re ".*$gdb_prompt $" { - if { ($linecount6 < 4) } { - fail "12.4: trace report #4" - } else { - pass "12.4: trace report #4" + 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" { + -re "TDP #$tdp6, frame $decimal: char_test = $arg1, long_test = $arg3" { + set linecount6 [expr $linecount6 + 1] + exp_continue + } + -re ".*$gdb_prompt $" { + if { ($linecount6 < 4) } { + fail "12.4: trace report #4" + } else { + pass "12.4: trace report #4" + } } } } +} + +use_collected_data "live" # Finished! -gdb_tfind_test "finished: make sure not debugging any trace frame" "none" "-1" +gdb_tfind_test "finished: make sure not debugging any trace frame" \ + "none" "-1" + +# Save trace frames to tfile. +gdb_test "tsave report.tf" "Trace data saved to file 'report.tf'.*" + +# Change target to tfile. +set test "change to tfile target" +gdb_test_multiple "target tfile report.tf" "$test" { + -re "A program is being debugged already. Kill it. .y or n. " { + send_gdb "y\n" + exp_continue + } + -re "$gdb_prompt $" { + pass "$test" + } +} +# Test the collected trace frames from tfile. +use_collected_data "tfile" -- 1.7.7.6 ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/2] Check trace data from trace file 2013-02-27 1:54 ` Yao Qi @ 2013-02-27 15:23 ` Pedro Alves 2013-02-28 1:14 ` Yao Qi 0 siblings, 1 reply; 12+ messages in thread From: Pedro Alves @ 2013-02-27 15:23 UTC (permalink / raw) To: Yao Qi; +Cc: gdb-patches On 02/27/2013 01:53 AM, Yao Qi wrote: > On 02/27/2013 02:44 AM, Pedro Alves wrote:> On 02/25/2013 03:08 AM, Yao Qi wrote: >>>> Here is the same patch with spaces ignored. It is easier to read. >>>> Note that I modified a matched pattern "PC register is not >>>> available" for tfile target, as the regcache is not available when >>>> switch to tfind mode (no regcache has been read out of 'R' block yet). >> Hmmm. Not sure. Shouldn't something have caught that exception? IOW, >> could that be a bug? >> >> I'm having difficulty figuring it out, because when I run the test >> I don't see that output anywhere in the gdb.log: >> >> (gdb) printf "x %d x\n", $tracepoint >> x 2 x >> (gdb) PASS: gdb.trace/report.exp: tfile: 9.1: find frame for TP 2 >> tdump >> Data collected at tracepoint 2, trace frame 0: >> (gdb) PASS: gdb.trace/report.exp: tfile: 9.1: tdump, nothing collected >> >> I wonder what's different in our environments. >> > > Yeah, it shows up in one build server. I tried the test on my laptop > (Fedora 16) and the other build server, it is OK. Then, I get rid of > the pattern to match "PC register is not available". I'll check it > on that build server. Thanks. > The changelog entry is completed as you suggested (wo/ "top level"). I'd prefer keeping it actually. It's there to disambiguate with the case of the new line of text being a continuation of the previous context, that happens to end up on a new line just because that's how the text flowed. Like: (foo_function_foo): New blah foo bar yum foo foo foo. Call use_collected_data once on the live target. What called "use_collected_data"? foo_function_foo, or the top level? Otherwise this version is OK. Thanks. -- Pedro Alves ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/2] Check trace data from trace file 2013-02-27 15:23 ` Pedro Alves @ 2013-02-28 1:14 ` Yao Qi 0 siblings, 0 replies; 12+ messages in thread From: Yao Qi @ 2013-02-28 1:14 UTC (permalink / raw) To: Pedro Alves; +Cc: gdb-patches On 02/27/2013 11:23 PM, Pedro Alves wrote: > I'd prefer keeping it actually. It's there to disambiguate with > the case of the new line of text being a continuation of the previous > context, that happens to end up on a new line just because that's how the > text flowed. Like: > > (foo_function_foo): New blah foo bar yum foo foo foo. > Call use_collected_data once on the live target. > > What called "use_collected_data"? foo_function_foo, or the top level? I grep'ed ChangeLog in gdb/testuite, and find "top level" has been used many times before. I didn't notice this. > > Otherwise this version is OK. Thanks. Committed with the changelog fix. -- Yao (é½å°§) ^ permalink raw reply [flat|nested] 12+ messages in thread
* RE: [PATCH 1/2] Check trace data from trace file 2013-02-25 2:58 [PATCH 1/2] Check trace data from trace file Yao Qi 2013-02-25 2:58 ` [PATCH 2/2] Find the next matched trace file in 'tfile target' Yao Qi 2013-02-25 3:10 ` [PATCH 1/2] Check trace data from trace file Yao Qi @ 2013-02-25 12:03 ` Abid, Hafiz 2013-02-25 14:10 ` Abid, Hafiz 2 siblings, 1 reply; 12+ messages in thread From: Abid, Hafiz @ 2013-02-25 12:03 UTC (permalink / raw) To: Qi, Yao, gdb-patches Hi Yao, FWIW, the loop that you mentioned below works OK for me and terminates correctly. I tried it on GDB that came with the distribution and one built from the recent sources. Regards, Abid ________________________________________ From: gdb-patches-owner@sourceware.org [gdb-patches-owner@sourceware.org] on behalf of Qi, Yao Sent: Monday, February 25, 2013 2:57 AM To: gdb-patches@sourceware.org Subject: [PATCH 1/2] Check trace data from trace file GDB is able to save trace data to trace file via 'tsave' and read trace data by target 'tfile', however, we don't have a test case. We have some test cases getting trace data from live inferior, so I have an idea to "refactor" the test case, so it gets trace data from either live inferior or trace file. This is also useful to verify that GDB behaves the same way when data is from either live inferior or trace file. Secondly, when we support a new trace file format, such as CTF, it is easy to change test cases to test GDB still behaves correctly on the new trace file format. This patch moves code about checking trace data into a proc "use_collected_data", and invoke it for different targets (live inferior and tfile). This patch causes an endless loop when executing this in GDB, which is a bug in GDB. (gdb) while $trace_frame != -1 > printf "tracepoint #%d, FP 0x%08x, SP 0x%08x, PC 0x%08x\n", > $tracepoint, $fp, $sp, $pc > tfind tracepoint > end tracepoint #3, FP 0xbfffe808, SP 0xbfffe7d0, PC 0x080483d0^M Found trace frame 1, tracepoint 3^M tracepoint #3, FP 0xbfffe808, SP 0xbfffe7d0, PC 0x080483d0 Found trace frame 1, tracepoint 3^M tracepoint #3, FP 0xbfffe808, SP 0xbfffe7d0, PC 0x080483d0^ The next patch is to fix this bug. gdb/testsuite: 2013-02-25 Yao Qi <yao@codesourcery.com> * gdb.trace/report.exp: Move some code to ... (use_collected_data): ... here. New. --- gdb/testsuite/gdb.trace/report.exp | 315 ++++++++++++++++++++---------------- 1 files changed, 174 insertions(+), 141 deletions(-) diff --git a/gdb/testsuite/gdb.trace/report.exp b/gdb/testsuite/gdb.trace/report.exp index e8aa597..6139485 100644 --- a/gdb/testsuite/gdb.trace/report.exp +++ b/gdb/testsuite/gdb.trace/report.exp @@ -181,210 +181,243 @@ gdb_test "continue" \ gdb_test "tstop" ".*" "" -# -# 9.1 test the tdump command -# +gdb_tfind_test "9.1: init: make sure not debugging any trace frame" \ + "none" "-1" -set timeout 60 +# 9.3 help tdump -gdb_tfind_test "9.1: init: make sure not debugging any trace frame" "none" "-1" +gdb_test "help tdump" "Print everything collected at the current.*" \ + "9.3: help tdump" -gdb_tfind_test "9.1: find frame for TP $tdp1" "tracepoint $tdp1" \ +# Check the collected trace data from different sources, such as live +# infeiror and tfile. + +proc use_collected_data { data_source } { with_test_prefix "${data_source}" { + global tdp1 tdp2 tdp3 tdp4 tdp5 tdp6 + global testline1 testline2 testline3 testline4 testline5 testline6 + global pcreg fpreg spreg + global srcfile srcdir subdir + global arg1 arg3 + global decimal hex gdb_prompt + # + # 9.1 test the tdump command + # + + set timeout 60 + + gdb_tfind_test "9.1: find frame for TP $tdp1" "tracepoint $tdp1" \ "\$tracepoint" "$tdp1" -# Nothing was collected at tdp1, so this tdump should be empty. -gdb_test "tdump" \ - "Data collected at tracepoint $tdp1, trace frame $decimal:" \ + # Nothing was collected at tdp1, so this tdump should be empty. + gdb_test "tdump" \ + "Data collected at tracepoint $tdp1, trace frame $decimal:\(\|\\r\\nPC register is not available\)" \ "9.1: tdump, nothing collected" -gdb_tfind_test "9.1: find frame for TP $tdp2" "tracepoint $tdp2" \ + gdb_tfind_test "9.1: find frame for TP $tdp2" "tracepoint $tdp2" \ "\$tracepoint" "$tdp2" -# regs were collected at tdp2. -# How to match for the output of "info registers" on an unknown architecture? -# For now, assume that most architectures have a register called "pc". + # regs were collected at tdp2. + # How to match for the output of "info registers" on an unknown architecture? + # For now, assume that most architectures have a register called "pc". -gdb_test "tdump" \ - "\[\r\n\]$pcreg .*" \ - "9.1: tdump, regs collected" + gdb_test "tdump" \ + "\[\r\n\]$pcreg .*" \ + "9.1: tdump, regs collected" -gdb_tfind_test "9.1: find frame for TP $tdp3" "tracepoint $tdp3" \ + gdb_tfind_test "9.1: find frame for TP $tdp3" "tracepoint $tdp3" \ "\$tracepoint" "$tdp3" -# args were collected at tdp3 -gdb_test "tdump" \ + # args were collected at tdp3 + gdb_test "tdump" \ "depth = 3.*q1 = 2.*q2 = 2.*q3 = 3.*q4 = 4.*q5 = 5.*q6 = 6" \ "9.1: tdump, args collected" -gdb_tfind_test "9.1: find frame for TP $tdp4" "tracepoint $tdp4" \ + gdb_tfind_test "9.1: find frame for TP $tdp4" "tracepoint $tdp4" \ "\$tracepoint" "$tdp4" -# locals were collected at tdp4 -gdb_test "tdump" \ + # locals were collected at tdp4 + gdb_test "tdump" \ "q = 1" \ "9.1: tdump, locals collected" -gdb_tfind_test "9.1: find frame for TP $tdp5" "tracepoint $tdp5" \ + gdb_tfind_test "9.1: find frame for TP $tdp5" "tracepoint $tdp5" \ "\$tracepoint" "$tdp5" -# stack was collected at tdp5, plus the frame pointer -gdb_test "tdump" \ - ".$fpreg = .*$spreg @ 64 = .*" \ - "9.1: tdump, memrange collected" + # stack was collected at tdp5, plus the frame pointer + gdb_test "tdump" \ + ".$fpreg = .*$spreg @ 64 = .*" \ + "9.1: tdump, memrange collected" -gdb_tfind_test "9.1: find frame for TP $tdp6" "tracepoint $tdp6" \ + gdb_tfind_test "9.1: find frame for TP $tdp6" "tracepoint $tdp6" \ "\$tracepoint" "$tdp6" -# globals were collected at tdp6 -gdb_test "tdump" \ + # globals were collected at tdp6 + gdb_test "tdump" \ "gdb_char_test = 1.*gdb_short_test = 2.*gdb_long_test = 3" \ "9.1: tdump, global variables collected" -# 9.2 test tdump with arguments -# [no go, tdump doesn't have any arguments] + # 9.2 test tdump with arguments + # [no go, tdump doesn't have any arguments] -# 9.3 help tdump + set linecount1 0 + set linecount2 0 + set linecount3 0 + set linecount4 0 + set linecount5 0 + set linecount6 0 -gdb_test "help tdump" "Print everything collected at the current.*" \ - "9.3: help tdump" - -set linecount1 0 -set linecount2 0 -set linecount3 0 -set linecount4 0 -set linecount5 0 -set linecount6 0 - -gdb_tfind_test "11.x, 12.1: find start frame" "start" "0" + gdb_tfind_test "11.x, 12.1: find start frame" "start" "0" -# -# 11.x test built-in trace variables $trace_frame, $trace_line etc. -# + # + # 11.x test built-in trace variables $trace_frame, $trace_line etc. + # -gdb_test "printf \"x %d x\\n\", \$trace_frame" "x 0 x" \ + gdb_test "printf \"x %d x\\n\", \$trace_frame" "x 0 x" \ "11.1: test \$trace_frame" -gdb_test "printf \"x %d x\\n\", \$tracepoint" "x $tdp1 x" \ + gdb_test "printf \"x %d x\\n\", \$tracepoint" "x $tdp1 x" \ "11.2: test \$tracepoint" -gdb_test "printf \"x %d x\\n\", \$trace_line" "x $testline1 x" \ + gdb_test "printf \"x %d x\\n\", \$trace_line" "x $testline1 x" \ "11.3: test \$trace_line" -gdb_test_multiple "print \$trace_file" "11.4: test \$trace_file" { - -re "\\$\[0-9\]+ = \"$srcfile\"\[\r\n\]+$gdb_prompt $" { - pass "11.4: test \$trace_file" - } - -re "\\$\[0-9\]+ = \"$srcdir/$subdir/$srcfile\"\[\r\n\]+$gdb_prompt $" { - pass "11.4: test \$trace_file" + gdb_test_multiple "print \$trace_file" "11.4: test \$trace_file" { + -re "\\$\[0-9\]+ = \"$srcfile\"\[\r\n\]+$gdb_prompt $" { + pass "11.4: test \$trace_file" + } + -re "\\$\[0-9\]+ = \"$srcdir/$subdir/$srcfile\"\[\r\n\]+$gdb_prompt $" { + pass "11.4: test \$trace_file" + } } -} -#gdb_test "print \$trace_file" "\"$srcdir/$subdir/$srcfile\"" \ -# "11.4: test \$trace_file" + #gdb_test "print \$trace_file" "\"$srcdir/$subdir/$srcfile\"" \ + # "11.4: test \$trace_file" -# -# 12.x test report generation using arbitrary GDB commands, loops etc. -# + # + # 12.x test report generation using arbitrary GDB commands, loops etc. + # -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" { - -re "> end\r\n" { - exp_continue - } - -re "^Found trace frame \[0-9\]+, tracepoint \[0-9\]+\r\n" { - exp_continue - } - -re "^\[^\r\n\]* line $testline1 .tracepoint .$tdp1\\)\r\n" { - set linecount1 [expr $linecount1 + 1] - exp_continue - } - -re "^\[^\r\n\]* line $testline2 .tracepoint .$tdp2\\)\r\n" { - set linecount2 [expr $linecount2 + 1] - exp_continue - } - -re "^\[^\r\n\]* line $testline3 .tracepoint .$tdp3\\)\r\n" { - set linecount3 [expr $linecount3 + 1] - exp_continue - } - -re "^\[^\r\n\]* line $testline4 .tracepoint .$tdp4\\)\r\n" { - set linecount4 [expr $linecount4 + 1] - exp_continue - } - -re "^\[^\r\n\]* line $testline5 .tracepoint .$tdp5\\)\r\n" { - set linecount5 [expr $linecount5 + 1] - exp_continue - } - -re "^\[^\r\n\]* line $testline6 .tracepoint .$tdp6\\)\r\n" { - set linecount6 [expr $linecount6 + 1] - exp_continue - } - -re "^No trace frame found\r\n$gdb_prompt $" { - if { ($linecount1 < 4) || ($linecount2 < 4) || ($linecount3 < 4) || ($linecount4 < 4) || ($linecount5 < 4) || ($linecount6 < 4) } { - fail "12.1: trace report #1" - } else { - pass "12.1: trace report #1" + 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" { + -re "> end\r\n" { + exp_continue + } + -re "^Found trace frame \[0-9\]+, tracepoint \[0-9\]+\r\n" { + exp_continue + } + -re "^\[^\r\n\]* line $testline1 .tracepoint .$tdp1\\)\r\n" { + set linecount1 [expr $linecount1 + 1] + exp_continue + } + -re "^\[^\r\n\]* line $testline2 .tracepoint .$tdp2\\)\r\n" { + set linecount2 [expr $linecount2 + 1] + exp_continue + } + -re "^\[^\r\n\]* line $testline3 .tracepoint .$tdp3\\)\r\n" { + set linecount3 [expr $linecount3 + 1] + exp_continue + } + -re "^\[^\r\n\]* line $testline4 .tracepoint .$tdp4\\)\r\n" { + set linecount4 [expr $linecount4 + 1] + exp_continue + } + -re "^\[^\r\n\]* line $testline5 .tracepoint .$tdp5\\)\r\n" { + set linecount5 [expr $linecount5 + 1] + exp_continue + } + -re "^\[^\r\n\]* line $testline6 .tracepoint .$tdp6\\)\r\n" { + set linecount6 [expr $linecount6 + 1] + exp_continue + } + -re "^No trace frame found\r\n$gdb_prompt $" { + if { ($linecount1 < 4) || ($linecount2 < 4) || ($linecount3 < 4) || ($linecount4 < 4) || ($linecount5 < 4) || ($linecount6 < 4) } { + fail "12.1: trace report #1" + } else { + pass "12.1: trace report #1" + } } } -} -gdb_tfind_test "12.2: tfind end, selects no frame" "end" "-1" -gdb_tfind_test "12.2: find first TDP #2 frame" "tracepoint $tdp2" \ + gdb_tfind_test "12.2: tfind end, selects no frame" "end" "-1" + gdb_tfind_test "12.2: find first TDP #2 frame" "tracepoint $tdp2" \ "\$tracepoint" "$tdp2" -set linecount2 0 + set linecount2 0 -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" { - -re "tracepoint #$tdp2, FP $hex, SP $hex, PC $hex" { - set linecount2 [expr $linecount2 + 1] - exp_continue - } - -re ".*$gdb_prompt $" { - if { ($linecount2 < 4) } { - fail "12.2: trace report #2" - } else { - pass "12.2: trace report #2" + 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" { + -re "tracepoint #$tdp2, FP $hex, SP $hex, PC $hex" { + set linecount2 [expr $linecount2 + 1] + exp_continue + } + -re ".*$gdb_prompt $" { + if { ($linecount2 < 4) } { + fail "12.2: trace report #2" + } else { + pass "12.2: trace report #2" + } } } -} -gdb_tfind_test "12.3: tfind end, selects no frame" "end" "-1" -gdb_tfind_test "12.3: find first TDP #3 frame" "tracepoint $tdp3" \ + gdb_tfind_test "12.3: tfind end, selects no frame" "end" "-1" + gdb_tfind_test "12.3: find first TDP #3 frame" "tracepoint $tdp3" \ "\$tracepoint" "$tdp3" -set linecount3 0 + set linecount3 0 -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" { - -re "TDP #$tdp3, frame $decimal: depth = $decimal, q1 = $decimal" { - set linecount3 [expr $linecount3 + 1] - exp_continue - } - -re ".*$gdb_prompt $" { - if { ($linecount3 < 4) } { - fail "12.3: trace report #3" - } else { - pass "12.3: trace report #3" + 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" { + -re "TDP #$tdp3, frame $decimal: depth = $decimal, q1 = $decimal" { + set linecount3 [expr $linecount3 + 1] + exp_continue + } + -re ".*$gdb_prompt $" { + if { ($linecount3 < 4) } { + fail "12.3: trace report #3" + } else { + pass "12.3: trace report #3" + } } } -} -gdb_tfind_test "12.4: tfind end, selects no frame" "end" "-1" -gdb_tfind_test "12.4: find first TDP #6 frame" "tracepoint $tdp6" \ + gdb_tfind_test "12.4: tfind end, selects no frame" "end" "-1" + gdb_tfind_test "12.4: find first TDP #6 frame" "tracepoint $tdp6" \ "\$tracepoint" "$tdp6" -set linecount6 0 + set linecount6 0 -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" { - -re "TDP #$tdp6, frame $decimal: char_test = $arg1, long_test = $arg3" { - set linecount6 [expr $linecount6 + 1] - exp_continue - } - -re ".*$gdb_prompt $" { - if { ($linecount6 < 4) } { - fail "12.4: trace report #4" - } else { - pass "12.4: trace report #4" + 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" { + -re "TDP #$tdp6, frame $decimal: char_test = $arg1, long_test = $arg3" { + set linecount6 [expr $linecount6 + 1] + exp_continue + } + -re ".*$gdb_prompt $" { + if { ($linecount6 < 4) } { + fail "12.4: trace report #4" + } else { + pass "12.4: trace report #4" + } } } } +} + +use_collected_data "live" # Finished! -gdb_tfind_test "finished: make sure not debugging any trace frame" "none" "-1" +gdb_tfind_test "finished: make sure not debugging any trace frame" \ + "none" "-1" + +# Save trace frames to tfile. +gdb_test "tsave report.tf" "Trace data saved to file 'report.tf'.*" + +# Change target to tfile. +set test "change to tfile target" +gdb_test_multiple "target tfile report.tf" "$test" { + -re "A program is being debugged already. Kill it. .y or n. " { + send_gdb "y\n" + exp_continue + } + -re "$gdb_prompt $" { + pass "$test" + } +} +# Test the collected trace frames from tfile. +use_collected_data "tfile" -- 1.7.7.6 ^ permalink raw reply [flat|nested] 12+ messages in thread
* RE: [PATCH 1/2] Check trace data from trace file 2013-02-25 12:03 ` Abid, Hafiz @ 2013-02-25 14:10 ` Abid, Hafiz 0 siblings, 0 replies; 12+ messages in thread From: Abid, Hafiz @ 2013-02-25 14:10 UTC (permalink / raw) To: Qi, Yao, gdb-patches Yao, To avoid confusion, previously, I was using GDB command line and there the loop was terminating OK. I just tried your patched report.exp file and it does give an infinite loop. Regards, Abid ________________________________________ From: gdb-patches-owner@sourceware.org [gdb-patches-owner@sourceware.org] on behalf of Abid, Hafiz Sent: Monday, February 25, 2013 12:03 PM To: Qi, Yao; gdb-patches@sourceware.org Subject: RE: [PATCH 1/2] Check trace data from trace file Hi Yao, FWIW, the loop that you mentioned below works OK for me and terminates correctly. I tried it on GDB that came with the distribution and one built from the recent sources. Regards, Abid ________________________________________ From: gdb-patches-owner@sourceware.org [gdb-patches-owner@sourceware.org] on behalf of Qi, Yao Sent: Monday, February 25, 2013 2:57 AM To: gdb-patches@sourceware.org Subject: [PATCH 1/2] Check trace data from trace file GDB is able to save trace data to trace file via 'tsave' and read trace data by target 'tfile', however, we don't have a test case. We have some test cases getting trace data from live inferior, so I have an idea to "refactor" the test case, so it gets trace data from either live inferior or trace file. This is also useful to verify that GDB behaves the same way when data is from either live inferior or trace file. Secondly, when we support a new trace file format, such as CTF, it is easy to change test cases to test GDB still behaves correctly on the new trace file format. This patch moves code about checking trace data into a proc "use_collected_data", and invoke it for different targets (live inferior and tfile). This patch causes an endless loop when executing this in GDB, which is a bug in GDB. (gdb) while $trace_frame != -1 > printf "tracepoint #%d, FP 0x%08x, SP 0x%08x, PC 0x%08x\n", > $tracepoint, $fp, $sp, $pc > tfind tracepoint > end tracepoint #3, FP 0xbfffe808, SP 0xbfffe7d0, PC 0x080483d0^M Found trace frame 1, tracepoint 3^M tracepoint #3, FP 0xbfffe808, SP 0xbfffe7d0, PC 0x080483d0 Found trace frame 1, tracepoint 3^M tracepoint #3, FP 0xbfffe808, SP 0xbfffe7d0, PC 0x080483d0^ The next patch is to fix this bug. gdb/testsuite: 2013-02-25 Yao Qi <yao@codesourcery.com> * gdb.trace/report.exp: Move some code to ... (use_collected_data): ... here. New. --- gdb/testsuite/gdb.trace/report.exp | 315 ++++++++++++++++++++---------------- 1 files changed, 174 insertions(+), 141 deletions(-) diff --git a/gdb/testsuite/gdb.trace/report.exp b/gdb/testsuite/gdb.trace/report.exp index e8aa597..6139485 100644 --- a/gdb/testsuite/gdb.trace/report.exp +++ b/gdb/testsuite/gdb.trace/report.exp @@ -181,210 +181,243 @@ gdb_test "continue" \ gdb_test "tstop" ".*" "" -# -# 9.1 test the tdump command -# +gdb_tfind_test "9.1: init: make sure not debugging any trace frame" \ + "none" "-1" -set timeout 60 +# 9.3 help tdump -gdb_tfind_test "9.1: init: make sure not debugging any trace frame" "none" "-1" +gdb_test "help tdump" "Print everything collected at the current.*" \ + "9.3: help tdump" -gdb_tfind_test "9.1: find frame for TP $tdp1" "tracepoint $tdp1" \ +# Check the collected trace data from different sources, such as live +# infeiror and tfile. + +proc use_collected_data { data_source } { with_test_prefix "${data_source}" { + global tdp1 tdp2 tdp3 tdp4 tdp5 tdp6 + global testline1 testline2 testline3 testline4 testline5 testline6 + global pcreg fpreg spreg + global srcfile srcdir subdir + global arg1 arg3 + global decimal hex gdb_prompt + # + # 9.1 test the tdump command + # + + set timeout 60 + + gdb_tfind_test "9.1: find frame for TP $tdp1" "tracepoint $tdp1" \ "\$tracepoint" "$tdp1" -# Nothing was collected at tdp1, so this tdump should be empty. -gdb_test "tdump" \ - "Data collected at tracepoint $tdp1, trace frame $decimal:" \ + # Nothing was collected at tdp1, so this tdump should be empty. + gdb_test "tdump" \ + "Data collected at tracepoint $tdp1, trace frame $decimal:\(\|\\r\\nPC register is not available\)" \ "9.1: tdump, nothing collected" -gdb_tfind_test "9.1: find frame for TP $tdp2" "tracepoint $tdp2" \ + gdb_tfind_test "9.1: find frame for TP $tdp2" "tracepoint $tdp2" \ "\$tracepoint" "$tdp2" -# regs were collected at tdp2. -# How to match for the output of "info registers" on an unknown architecture? -# For now, assume that most architectures have a register called "pc". + # regs were collected at tdp2. + # How to match for the output of "info registers" on an unknown architecture? + # For now, assume that most architectures have a register called "pc". -gdb_test "tdump" \ - "\[\r\n\]$pcreg .*" \ - "9.1: tdump, regs collected" + gdb_test "tdump" \ + "\[\r\n\]$pcreg .*" \ + "9.1: tdump, regs collected" -gdb_tfind_test "9.1: find frame for TP $tdp3" "tracepoint $tdp3" \ + gdb_tfind_test "9.1: find frame for TP $tdp3" "tracepoint $tdp3" \ "\$tracepoint" "$tdp3" -# args were collected at tdp3 -gdb_test "tdump" \ + # args were collected at tdp3 + gdb_test "tdump" \ "depth = 3.*q1 = 2.*q2 = 2.*q3 = 3.*q4 = 4.*q5 = 5.*q6 = 6" \ "9.1: tdump, args collected" -gdb_tfind_test "9.1: find frame for TP $tdp4" "tracepoint $tdp4" \ + gdb_tfind_test "9.1: find frame for TP $tdp4" "tracepoint $tdp4" \ "\$tracepoint" "$tdp4" -# locals were collected at tdp4 -gdb_test "tdump" \ + # locals were collected at tdp4 + gdb_test "tdump" \ "q = 1" \ "9.1: tdump, locals collected" -gdb_tfind_test "9.1: find frame for TP $tdp5" "tracepoint $tdp5" \ + gdb_tfind_test "9.1: find frame for TP $tdp5" "tracepoint $tdp5" \ "\$tracepoint" "$tdp5" -# stack was collected at tdp5, plus the frame pointer -gdb_test "tdump" \ - ".$fpreg = .*$spreg @ 64 = .*" \ - "9.1: tdump, memrange collected" + # stack was collected at tdp5, plus the frame pointer + gdb_test "tdump" \ + ".$fpreg = .*$spreg @ 64 = .*" \ + "9.1: tdump, memrange collected" -gdb_tfind_test "9.1: find frame for TP $tdp6" "tracepoint $tdp6" \ + gdb_tfind_test "9.1: find frame for TP $tdp6" "tracepoint $tdp6" \ "\$tracepoint" "$tdp6" -# globals were collected at tdp6 -gdb_test "tdump" \ + # globals were collected at tdp6 + gdb_test "tdump" \ "gdb_char_test = 1.*gdb_short_test = 2.*gdb_long_test = 3" \ "9.1: tdump, global variables collected" -# 9.2 test tdump with arguments -# [no go, tdump doesn't have any arguments] + # 9.2 test tdump with arguments + # [no go, tdump doesn't have any arguments] -# 9.3 help tdump + set linecount1 0 + set linecount2 0 + set linecount3 0 + set linecount4 0 + set linecount5 0 + set linecount6 0 -gdb_test "help tdump" "Print everything collected at the current.*" \ - "9.3: help tdump" - -set linecount1 0 -set linecount2 0 -set linecount3 0 -set linecount4 0 -set linecount5 0 -set linecount6 0 - -gdb_tfind_test "11.x, 12.1: find start frame" "start" "0" + gdb_tfind_test "11.x, 12.1: find start frame" "start" "0" -# -# 11.x test built-in trace variables $trace_frame, $trace_line etc. -# + # + # 11.x test built-in trace variables $trace_frame, $trace_line etc. + # -gdb_test "printf \"x %d x\\n\", \$trace_frame" "x 0 x" \ + gdb_test "printf \"x %d x\\n\", \$trace_frame" "x 0 x" \ "11.1: test \$trace_frame" -gdb_test "printf \"x %d x\\n\", \$tracepoint" "x $tdp1 x" \ + gdb_test "printf \"x %d x\\n\", \$tracepoint" "x $tdp1 x" \ "11.2: test \$tracepoint" -gdb_test "printf \"x %d x\\n\", \$trace_line" "x $testline1 x" \ + gdb_test "printf \"x %d x\\n\", \$trace_line" "x $testline1 x" \ "11.3: test \$trace_line" -gdb_test_multiple "print \$trace_file" "11.4: test \$trace_file" { - -re "\\$\[0-9\]+ = \"$srcfile\"\[\r\n\]+$gdb_prompt $" { - pass "11.4: test \$trace_file" - } - -re "\\$\[0-9\]+ = \"$srcdir/$subdir/$srcfile\"\[\r\n\]+$gdb_prompt $" { - pass "11.4: test \$trace_file" + gdb_test_multiple "print \$trace_file" "11.4: test \$trace_file" { + -re "\\$\[0-9\]+ = \"$srcfile\"\[\r\n\]+$gdb_prompt $" { + pass "11.4: test \$trace_file" + } + -re "\\$\[0-9\]+ = \"$srcdir/$subdir/$srcfile\"\[\r\n\]+$gdb_prompt $" { + pass "11.4: test \$trace_file" + } } -} -#gdb_test "print \$trace_file" "\"$srcdir/$subdir/$srcfile\"" \ -# "11.4: test \$trace_file" + #gdb_test "print \$trace_file" "\"$srcdir/$subdir/$srcfile\"" \ + # "11.4: test \$trace_file" -# -# 12.x test report generation using arbitrary GDB commands, loops etc. -# + # + # 12.x test report generation using arbitrary GDB commands, loops etc. + # -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" { - -re "> end\r\n" { - exp_continue - } - -re "^Found trace frame \[0-9\]+, tracepoint \[0-9\]+\r\n" { - exp_continue - } - -re "^\[^\r\n\]* line $testline1 .tracepoint .$tdp1\\)\r\n" { - set linecount1 [expr $linecount1 + 1] - exp_continue - } - -re "^\[^\r\n\]* line $testline2 .tracepoint .$tdp2\\)\r\n" { - set linecount2 [expr $linecount2 + 1] - exp_continue - } - -re "^\[^\r\n\]* line $testline3 .tracepoint .$tdp3\\)\r\n" { - set linecount3 [expr $linecount3 + 1] - exp_continue - } - -re "^\[^\r\n\]* line $testline4 .tracepoint .$tdp4\\)\r\n" { - set linecount4 [expr $linecount4 + 1] - exp_continue - } - -re "^\[^\r\n\]* line $testline5 .tracepoint .$tdp5\\)\r\n" { - set linecount5 [expr $linecount5 + 1] - exp_continue - } - -re "^\[^\r\n\]* line $testline6 .tracepoint .$tdp6\\)\r\n" { - set linecount6 [expr $linecount6 + 1] - exp_continue - } - -re "^No trace frame found\r\n$gdb_prompt $" { - if { ($linecount1 < 4) || ($linecount2 < 4) || ($linecount3 < 4) || ($linecount4 < 4) || ($linecount5 < 4) || ($linecount6 < 4) } { - fail "12.1: trace report #1" - } else { - pass "12.1: trace report #1" + 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" { + -re "> end\r\n" { + exp_continue + } + -re "^Found trace frame \[0-9\]+, tracepoint \[0-9\]+\r\n" { + exp_continue + } + -re "^\[^\r\n\]* line $testline1 .tracepoint .$tdp1\\)\r\n" { + set linecount1 [expr $linecount1 + 1] + exp_continue + } + -re "^\[^\r\n\]* line $testline2 .tracepoint .$tdp2\\)\r\n" { + set linecount2 [expr $linecount2 + 1] + exp_continue + } + -re "^\[^\r\n\]* line $testline3 .tracepoint .$tdp3\\)\r\n" { + set linecount3 [expr $linecount3 + 1] + exp_continue + } + -re "^\[^\r\n\]* line $testline4 .tracepoint .$tdp4\\)\r\n" { + set linecount4 [expr $linecount4 + 1] + exp_continue + } + -re "^\[^\r\n\]* line $testline5 .tracepoint .$tdp5\\)\r\n" { + set linecount5 [expr $linecount5 + 1] + exp_continue + } + -re "^\[^\r\n\]* line $testline6 .tracepoint .$tdp6\\)\r\n" { + set linecount6 [expr $linecount6 + 1] + exp_continue + } + -re "^No trace frame found\r\n$gdb_prompt $" { + if { ($linecount1 < 4) || ($linecount2 < 4) || ($linecount3 < 4) || ($linecount4 < 4) || ($linecount5 < 4) || ($linecount6 < 4) } { + fail "12.1: trace report #1" + } else { + pass "12.1: trace report #1" + } } } -} -gdb_tfind_test "12.2: tfind end, selects no frame" "end" "-1" -gdb_tfind_test "12.2: find first TDP #2 frame" "tracepoint $tdp2" \ + gdb_tfind_test "12.2: tfind end, selects no frame" "end" "-1" + gdb_tfind_test "12.2: find first TDP #2 frame" "tracepoint $tdp2" \ "\$tracepoint" "$tdp2" -set linecount2 0 + set linecount2 0 -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" { - -re "tracepoint #$tdp2, FP $hex, SP $hex, PC $hex" { - set linecount2 [expr $linecount2 + 1] - exp_continue - } - -re ".*$gdb_prompt $" { - if { ($linecount2 < 4) } { - fail "12.2: trace report #2" - } else { - pass "12.2: trace report #2" + 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" { + -re "tracepoint #$tdp2, FP $hex, SP $hex, PC $hex" { + set linecount2 [expr $linecount2 + 1] + exp_continue + } + -re ".*$gdb_prompt $" { + if { ($linecount2 < 4) } { + fail "12.2: trace report #2" + } else { + pass "12.2: trace report #2" + } } } -} -gdb_tfind_test "12.3: tfind end, selects no frame" "end" "-1" -gdb_tfind_test "12.3: find first TDP #3 frame" "tracepoint $tdp3" \ + gdb_tfind_test "12.3: tfind end, selects no frame" "end" "-1" + gdb_tfind_test "12.3: find first TDP #3 frame" "tracepoint $tdp3" \ "\$tracepoint" "$tdp3" -set linecount3 0 + set linecount3 0 -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" { - -re "TDP #$tdp3, frame $decimal: depth = $decimal, q1 = $decimal" { - set linecount3 [expr $linecount3 + 1] - exp_continue - } - -re ".*$gdb_prompt $" { - if { ($linecount3 < 4) } { - fail "12.3: trace report #3" - } else { - pass "12.3: trace report #3" + 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" { + -re "TDP #$tdp3, frame $decimal: depth = $decimal, q1 = $decimal" { + set linecount3 [expr $linecount3 + 1] + exp_continue + } + -re ".*$gdb_prompt $" { + if { ($linecount3 < 4) } { + fail "12.3: trace report #3" + } else { + pass "12.3: trace report #3" + } } } -} -gdb_tfind_test "12.4: tfind end, selects no frame" "end" "-1" -gdb_tfind_test "12.4: find first TDP #6 frame" "tracepoint $tdp6" \ + gdb_tfind_test "12.4: tfind end, selects no frame" "end" "-1" + gdb_tfind_test "12.4: find first TDP #6 frame" "tracepoint $tdp6" \ "\$tracepoint" "$tdp6" -set linecount6 0 + set linecount6 0 -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" { - -re "TDP #$tdp6, frame $decimal: char_test = $arg1, long_test = $arg3" { - set linecount6 [expr $linecount6 + 1] - exp_continue - } - -re ".*$gdb_prompt $" { - if { ($linecount6 < 4) } { - fail "12.4: trace report #4" - } else { - pass "12.4: trace report #4" + 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" { + -re "TDP #$tdp6, frame $decimal: char_test = $arg1, long_test = $arg3" { + set linecount6 [expr $linecount6 + 1] + exp_continue + } + -re ".*$gdb_prompt $" { + if { ($linecount6 < 4) } { + fail "12.4: trace report #4" + } else { + pass "12.4: trace report #4" + } } } } +} + +use_collected_data "live" # Finished! -gdb_tfind_test "finished: make sure not debugging any trace frame" "none" "-1" +gdb_tfind_test "finished: make sure not debugging any trace frame" \ + "none" "-1" + +# Save trace frames to tfile. +gdb_test "tsave report.tf" "Trace data saved to file 'report.tf'.*" + +# Change target to tfile. +set test "change to tfile target" +gdb_test_multiple "target tfile report.tf" "$test" { + -re "A program is being debugged already. Kill it. .y or n. " { + send_gdb "y\n" + exp_continue + } + -re "$gdb_prompt $" { + pass "$test" + } +} +# Test the collected trace frames from tfile. +use_collected_data "tfile" -- 1.7.7.6 ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2013-02-28 0:44 UTC | newest] Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2013-02-25 2:58 [PATCH 1/2] Check trace data from trace file Yao Qi 2013-02-25 2:58 ` [PATCH 2/2] Find the next matched trace file in 'tfile target' Yao Qi 2013-02-26 19:53 ` Pedro Alves 2013-02-27 1:37 ` Yao Qi 2013-02-25 3:10 ` [PATCH 1/2] Check trace data from trace file Yao Qi 2013-02-26 18:44 ` Pedro Alves 2013-02-26 18:57 ` Pedro Alves 2013-02-27 1:54 ` Yao Qi 2013-02-27 15:23 ` Pedro Alves 2013-02-28 1:14 ` Yao Qi 2013-02-25 12:03 ` Abid, Hafiz 2013-02-25 14:10 ` Abid, Hafiz
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox