|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * |
|
5 * Redistribution and use in source and binary forms, with or without |
|
6 * modification, are permitted provided that the following conditions are met: |
|
7 * |
|
8 * - Redistributions of source code must retain the above copyright notice, |
|
9 * this list of conditions and the following disclaimer. |
|
10 * - Redistributions in binary form must reproduce the above copyright notice, |
|
11 * this list of conditions and the following disclaimer in the documentation |
|
12 * and/or other materials provided with the distribution. |
|
13 * - Neither the name of Nokia Corporation nor the names of its contributors |
|
14 * may be used to endorse or promote products derived from this software |
|
15 * without specific prior written permission. |
|
16 * |
|
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 * POSSIBILITY OF SUCH DAMAGE. |
|
28 * |
|
29 * Initial Contributors: |
|
30 * Nokia Corporation - initial contribution. |
|
31 * |
|
32 * Contributors: |
|
33 * |
|
34 * Description: |
|
35 * |
|
36 */ |
|
37 |
|
38 using System; |
|
39 using System.Collections.Generic; |
|
40 using System.Text; |
|
41 using System.Text.RegularExpressions; |
|
42 |
|
43 namespace HeapLib.Reconstructor.DataSources.Analyser.Extractor |
|
44 { |
|
45 internal sealed class ExtractorBinary//: ExtractorBase |
|
46 { |
|
47 /* |
|
48 #region Constructors & destructor |
|
49 public ExtractorBinary() |
|
50 { |
|
51 } |
|
52 #endregion |
|
53 |
|
54 #region API |
|
55 public override ExtractedData ProcessLine( string aLine ) |
|
56 { |
|
57 // [14:39:24.344] xti2:MCU_ASCII_PRINTF; channel:0xE0; msg:[BinHeap:00000131]<BinHeapData:00000131:00000130:000000000001346e> |
|
58 // [14:39:24.344] xti2:MCU_ASCII_PRINTF; channel:0xE0; msg:[BinHeap:00000131]00000000: be d0 be d0 ba da ba da 00 00 00 d0 01 00 00 00 ................ |
|
59 // [14:39:24.344] xti2:MCU_ASCII_PRINTF; channel:0xE0; msg:[BinHeap:00000131]00000010: 6e 34 01 00 82 00 00 00 83 00 00 00 01 00 00 00 n4.............. |
|
60 // [14:39:24.344] xti2:MCU_ASCII_PRINTF; channel:0xE0; msg:[BinHeap:00000131]00000020: 2c 00 00 00 61 6b 6e 73 6b 69 6e 73 72 76 2e 65 ,...aknskinsrv.e |
|
61 // |
|
62 // or |
|
63 // |
|
64 // <BinHeapData:00000131:00000130:000000000001346e> |
|
65 // 00000000: be d0 be d0 ba da ba da 00 00 00 d0 01 00 00 00 ................ |
|
66 // 00000010: 6e 34 01 00 82 00 00 00 83 00 00 00 01 00 00 00 n4.............. |
|
67 // 00000020: 2c 00 00 00 61 6b 6e 73 6b 69 6e 73 72 76 2e 65 ,...aknskinsrv.e |
|
68 string line = aLine; |
|
69 ExtractedData ret = new ExtractedData(); |
|
70 |
|
71 // Check if it's a "[BinHeap:" line... |
|
72 bool isTaggedWithBinaryPrefix = KRegExHeapInfoTraceBinaryPrefix.IsMatch( line ); |
|
73 if ( isTaggedWithBinaryPrefix ) |
|
74 { |
|
75 Match m = KRegExHeapInfoTraceBinaryPrefix.Match( line ); |
|
76 Group gpThreadId = m.Groups[ "TID" ]; |
|
77 Group gpLine = m.Groups[ "LINE" ]; |
|
78 |
|
79 ret.ThreadId = ThreadIdFromText( gpThreadId.Value ); |
|
80 |
|
81 // Continue with rest of data... |
|
82 line = gpLine.Value; |
|
83 } |
|
84 |
|
85 // Check if it is a "<BinHeapData" line... |
|
86 bool accept = KRegExHeapInfoBinaryTag.IsMatch( aLine ); |
|
87 if ( accept ) |
|
88 { |
|
89 Match m = KRegExHeapInfoBinaryTag.Match( aLine ); |
|
90 Group gpThreadId = m.Groups[ "TID" ]; |
|
91 Group gpProcessId = m.Groups[ "PID" ]; |
|
92 Group gpLength = m.Groups[ "LENGTH" ]; |
|
93 |
|
94 // Get the thread id. |
|
95 uint tid = ThreadIdFromText( gpThreadId.Value ); |
|
96 System.Diagnostics.Debug.Assert( ret.ThreadId == 0 || ret.ThreadId == tid ); |
|
97 ret.ThreadId = tid; |
|
98 } |
|
99 else |
|
100 { |
|
101 // If we still didn't match, then it might be a MemSpy log file, in which case it'll just |
|
102 // contain address lines |
|
103 accept = KRegExHeapInfoAddress.IsMatch( aLine ); |
|
104 if ( accept ) |
|
105 { |
|
106 Match m = KRegExHeapInfoAddress.Match( aLine ); |
|
107 Group gpAddress = m.Groups[ "ADDRESS" ]; |
|
108 Group gpLine = m.Groups[ "LINE" ]; |
|
109 |
|
110 ret.Address = AddressFromText( gpAddress.Value ); |
|
111 ret.Payload = gpLine.Value; |
|
112 } |
|
113 } |
|
114 |
|
115 // Our hash is the thread id. |
|
116 ret.Hash = ret.ThreadId.ToString( "x8" ); |
|
117 |
|
118 return ret; |
|
119 } |
|
120 #endregion |
|
121 |
|
122 #region Internal methods |
|
123 private static uint ThreadIdFromText( string aText ) |
|
124 { |
|
125 uint ret = SymbianUtils.PrefixParser.ReadUint( ref aText ); |
|
126 return ret; |
|
127 } |
|
128 |
|
129 private static uint AddressFromText( string aText ) |
|
130 { |
|
131 uint ret = SymbianUtils.PrefixParser.ReadUint( ref aText ); |
|
132 return ret; |
|
133 } |
|
134 #endregion |
|
135 |
|
136 #region Internal constants |
|
137 private const string KMemSpyBinaryHeapDumpTrace = "[BinHeap:"; |
|
138 private const string KMemSpyBinaryHeapDumpLog = "<BinHeapData:"; |
|
139 #endregion |
|
140 |
|
141 #region Internal regular expressions |
|
142 private static readonly Regex KRegExHeapInfoBinaryTag = new Regex( @"<(?<TYPE>\x2F?)BinHeapData\x3A(?<TID>[a-fA-F0-9]{8})\x3A(?<PID>[a-fA-F0-9]{8})\x3A(?<LENGTH>[a-fA-F0-9]{16})>", RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.Compiled | RegexOptions.IgnoreCase ); |
|
143 private static readonly Regex KRegExHeapInfoAddress = new Regex( @"(?<ADDRESS>[a-fA-F0-9]{8})\x5d(?<LINE>.+)", RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.Compiled | RegexOptions.IgnoreCase ); |
|
144 private static readonly Regex KRegExHeapInfoTraceBinaryPrefix = new Regex( @"^\x5bBinHeap\x3a(?<TID>[a-fA-F0-9]{8})\x5d(?<LINE>.+)", RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.Compiled | RegexOptions.IgnoreCase ); |
|
145 #endregion |
|
146 |
|
147 #region Data members |
|
148 #endregion |
|
149 */ |
|
150 } |
|
151 } |