|
1 #!/usr/bin/perl |
|
2 # Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 # All rights reserved. |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of "Eclipse Public License v1.0" |
|
6 # which accompanies this distribution, and is available |
|
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Nokia Corporation - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: |
|
15 # Tool to convert xti ascii logs with freeway logging into btrace files |
|
16 # suitable for input to utracedecoder |
|
17 # |
|
18 |
|
19 my $input = $ARGV[0]; |
|
20 if (length($input) == 0) |
|
21 { |
|
22 print "Usage: xti2bt.pl <inputfile> <outputfile>"; |
|
23 exit(-1); |
|
24 } |
|
25 |
|
26 my $output = $ARGV[1]; |
|
27 if (length($output) == 0) |
|
28 { |
|
29 print "Outputting to btrace.bin\n"; |
|
30 $output = "btrace.bin"; |
|
31 } |
|
32 |
|
33 open INPUT, "< $input" or die "Couldn't open $input"; |
|
34 open BTRACE , "> $output" or die "Couldn't open $output"; |
|
35 binmode BTRACE; |
|
36 |
|
37 sub writePrintf |
|
38 { |
|
39 $trace = shift; |
|
40 $trace =~ s/¿/\t/g; |
|
41 $len = length($trace); |
|
42 if ($len > 104) |
|
43 { |
|
44 $trace = substr $trace, 0, 104; |
|
45 $len = length($trace); |
|
46 } |
|
47 $alignment = $len % 4; |
|
48 for ($i = 0; $i < (4-$alignment); $i++) |
|
49 { |
|
50 $trace = $trace."X"; |
|
51 } |
|
52 $len = length($trace) + 8; |
|
53 |
|
54 $header = pack("CCCC", $len, 0, 0, 0); |
|
55 print BTRACE $header; |
|
56 print BTRACE "0000"; |
|
57 print BTRACE $trace; |
|
58 } |
|
59 |
|
60 while (<INPUT>) |
|
61 { |
|
62 if (/IConsole/) |
|
63 { |
|
64 next; |
|
65 } elsif (/xti1:SYMBIAN_TRACE; channel:0xE0; \[([0-9a-f,]*)/) |
|
66 { |
|
67 @bytes = split(/,/, $1); |
|
68 |
|
69 $size = hex($bytes[0]); |
|
70 $flags = hex($bytes[1]); |
|
71 $size2 = scalar(@bytes); |
|
72 |
|
73 # $bytes[0] = sprintf "%x", $size2; |
|
74 # print "reported size $size\tarray size $size2 $trailing0\t"; |
|
75 # print "flags $flags\t"; |
|
76 # if ($flags & 1<<0) { |
|
77 # $flags2 = hex($bytes[4]); |
|
78 # $part = "?"; |
|
79 # if ($flags2 == 1) |
|
80 # { |
|
81 # $part = "S"; |
|
82 # } elsif ($flags2 == 2) |
|
83 # { |
|
84 # $part = "M"; |
|
85 # } elsif ($flags2 == 3) |
|
86 # { |
|
87 # $part = "E"; |
|
88 # } |
|
89 # print "H2[$part], "; |
|
90 # } |
|
91 |
|
92 # if ($flags & 1<<1) { |
|
93 # print "T,"; |
|
94 # } |
|
95 |
|
96 # if ($flags & 1<<2) { |
|
97 # print "T2, "; |
|
98 # } |
|
99 |
|
100 # if ($flags & 1<<3) { |
|
101 # print "Cid, "; |
|
102 # } |
|
103 |
|
104 # if ($flags & 1<<4) { |
|
105 # print "PC, "; |
|
106 # } |
|
107 |
|
108 # if ($flags & 1<<5) { |
|
109 # print "Ext, "; |
|
110 # } |
|
111 |
|
112 # if ($flags & 1<<6) { |
|
113 # print "Trunc, "; |
|
114 # } |
|
115 |
|
116 # if ($flags & 1<<7) { |
|
117 # print "Miss, "; |
|
118 # } |
|
119 # print "\t@bytes\n"; |
|
120 |
|
121 $moddedsize = $size; |
|
122 if (($moddedsize % 4) != 0) |
|
123 { |
|
124 $moddedsize += 4 - ($moddedsize % 4); |
|
125 } |
|
126 while (scalar(@bytes) < $moddedsize) |
|
127 { |
|
128 push @bytes, "00"; |
|
129 # print "Size all strange ( $size $size2 ): @bytes\n"; |
|
130 } |
|
131 |
|
132 foreach (@bytes) { |
|
133 my $out = pack("C", hex $_); |
|
134 print BTRACE $out; |
|
135 } |
|
136 } elsif (/xti1:MCU_ASCII_PRINTF; channel:0xE0; msg:(.*)/) |
|
137 { |
|
138 writePrintf($1); |
|
139 } elsif (/symb:(.*)/) |
|
140 { |
|
141 writePrintf($1); |
|
142 } |
|
143 } |
|
144 close BTRACE; |
|
145 close INPUT; |