|
1 /* |
|
2 * Copyright (c) 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 * |
|
16 */ |
|
17 |
|
18 using System; |
|
19 using System.Collections.Generic; |
|
20 using System.Text; |
|
21 using SymbianStructuresLib.Debug.Symbols; |
|
22 using SymbianUtils.BasicTypes; |
|
23 using SymbianStructuresLib.Arm; |
|
24 using SymbianStructuresLib.Arm.Exceptions; |
|
25 using SymbianStructuresLib.Arm.SecurityMode; |
|
26 using SymbianETMLib.Common.Utilities; |
|
27 |
|
28 namespace SymbianETMLib.Common.Types |
|
29 { |
|
30 public class ETMBranch |
|
31 { |
|
32 #region Constructors |
|
33 public ETMBranch( SymAddress aAddress, int aNumber, TETMBranchType aType, TArmInstructionSet aInstructionSet, TArmExceptionType aExceptionType ) |
|
34 { |
|
35 iAddress = aAddress; |
|
36 iNumber = aNumber; |
|
37 iType = aType; |
|
38 iInstructionSet = aInstructionSet; |
|
39 iExceptionType = aExceptionType; |
|
40 } |
|
41 #endregion |
|
42 |
|
43 #region API |
|
44 #endregion |
|
45 |
|
46 #region Properties |
|
47 public SymAddress Address |
|
48 { |
|
49 get { return iAddress; } |
|
50 } |
|
51 |
|
52 public int Number |
|
53 { |
|
54 get { return iNumber; } |
|
55 } |
|
56 |
|
57 public TETMBranchType Type |
|
58 { |
|
59 get { return iType; } |
|
60 } |
|
61 |
|
62 public TArmInstructionSet InstructionSet |
|
63 { |
|
64 get { return iInstructionSet; } |
|
65 } |
|
66 |
|
67 public TArmExceptionType ExceptionType |
|
68 { |
|
69 get { return iExceptionType; } |
|
70 } |
|
71 |
|
72 public Symbol Symbol |
|
73 { |
|
74 get { return iSymbol; } |
|
75 set |
|
76 { |
|
77 if ( iSymbol != value ) |
|
78 { |
|
79 iFlags &= ~TFlags.EFlagsSymbolTextSetExplicitly; |
|
80 iSymbol = value; |
|
81 BuildSymbolText(); |
|
82 } |
|
83 } |
|
84 } |
|
85 |
|
86 public uint SymbolAddressOffset |
|
87 { |
|
88 get |
|
89 { |
|
90 uint ret = 0; |
|
91 if ( iSymbol != null ) |
|
92 { |
|
93 ret = iSymbol.Offset( iAddress ); |
|
94 } |
|
95 return ret; |
|
96 } |
|
97 } |
|
98 |
|
99 public string SymbolText |
|
100 { |
|
101 get { return iSymbolText; } |
|
102 set |
|
103 { |
|
104 iSymbolText = value; |
|
105 iFlags |= TFlags.EFlagsSymbolTextSetExplicitly; |
|
106 } |
|
107 } |
|
108 #endregion |
|
109 |
|
110 #region From System.Object |
|
111 public override string ToString() |
|
112 { |
|
113 string ret = ToString( 0 ); |
|
114 return ret; |
|
115 } |
|
116 |
|
117 public string ToString( int aDepth ) |
|
118 { |
|
119 StringBuilder text = new StringBuilder(); |
|
120 |
|
121 // Counter |
|
122 text.AppendFormat( "[{0:d4}] ", iNumber ); |
|
123 |
|
124 // Instruction set |
|
125 text.Append( ETMEnumToTextConverter.ToString( this.InstructionSet ) ); |
|
126 |
|
127 // Exception mode |
|
128 string processorState = ETMEnumToTextConverter.ToString( this.ExceptionType ); |
|
129 text.AppendFormat( string.Format( " [{0}]", processorState ).PadRight( 33, ' ' ) ); |
|
130 |
|
131 // Address |
|
132 text.AppendFormat( " @ 0x{0} ", iAddress.AddressHex ); |
|
133 |
|
134 // Symbol |
|
135 if ( this.Symbol != null ) |
|
136 { |
|
137 text.AppendFormat( "[0x{0:x8} +0x{1:x4}] ", this.Symbol.Address, this.SymbolAddressOffset ); |
|
138 } |
|
139 else |
|
140 { |
|
141 text.Append( "[ ???????? +????] " ); |
|
142 } |
|
143 |
|
144 // Add padding for depth |
|
145 for ( int i = 0; i < aDepth; i++ ) |
|
146 { |
|
147 text.Append( " " ); |
|
148 } |
|
149 |
|
150 // Finally, add the symbol |
|
151 text.Append( this.SymbolText ); |
|
152 |
|
153 return text.ToString(); |
|
154 } |
|
155 #endregion |
|
156 |
|
157 #region Internal enumerations |
|
158 [Flags] |
|
159 private enum TFlags : byte |
|
160 { |
|
161 EFlagsNone = 0, |
|
162 EFlagsSymbolTextSetExplicitly |
|
163 } |
|
164 #endregion |
|
165 |
|
166 #region Internal constants |
|
167 private const string KUnknownSymbol = "????"; |
|
168 #endregion |
|
169 |
|
170 #region Internal methods |
|
171 private void BuildSymbolText() |
|
172 { |
|
173 if ( ( iFlags & TFlags.EFlagsSymbolTextSetExplicitly ) != TFlags.EFlagsSymbolTextSetExplicitly ) |
|
174 { |
|
175 if ( iSymbol != null ) |
|
176 { |
|
177 StringBuilder ret = new StringBuilder(); |
|
178 ret.AppendFormat( "{0} [{1}]", iSymbol.Name, iSymbol.Object ); |
|
179 iSymbolText = ret.ToString(); |
|
180 } |
|
181 else |
|
182 { |
|
183 iSymbolText = KUnknownSymbol; |
|
184 } |
|
185 } |
|
186 } |
|
187 #endregion |
|
188 |
|
189 #region Data members |
|
190 private readonly int iNumber; |
|
191 private readonly SymAddress iAddress; |
|
192 private readonly TETMBranchType iType; |
|
193 private readonly TArmInstructionSet iInstructionSet; |
|
194 private readonly TArmExceptionType iExceptionType; |
|
195 private Symbol iSymbol = null; |
|
196 private string iSymbolText = string.Empty; |
|
197 private TFlags iFlags = TFlags.EFlagsNone; |
|
198 #endregion |
|
199 } |
|
200 } |