crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianETMLib/Common/State/Base/ETMDecodeState.cs
changeset 0 818e61de6cd1
equal deleted inserted replaced
-1:000000000000 0:818e61de6cd1
       
     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 SymbianUtils.Tracer;
       
    22 using SymbianUtils.BasicTypes;
       
    23 using SymbianStructuresLib.Arm;
       
    24 using SymbianStructuresLib.Arm.Exceptions;
       
    25 using SymbianETMLib.Common.Types;
       
    26 
       
    27 namespace SymbianETMLib.Common.State
       
    28 {
       
    29     public abstract class ETMDecodeState : ITracer
       
    30     {
       
    31         #region Constructors
       
    32         protected ETMDecodeState( ETMStateData aStateData )
       
    33         {
       
    34             iStateData = aStateData;
       
    35         }
       
    36         #endregion
       
    37 
       
    38         #region API
       
    39         public virtual ETMDecodeState PrepareToHandleByte( SymByte aByte )
       
    40         {
       
    41             iCurrentRawByte = aByte;
       
    42             //
       
    43             ETMDecodeState ret = HandleByte( aByte );
       
    44             return ret;
       
    45         }
       
    46 
       
    47         public abstract ETMDecodeState HandleByte( SymByte aByte );
       
    48 
       
    49         public static string MakeInstructionSetPrefix( TArmInstructionSet aInstructionSet )
       
    50         {
       
    51             string instSet;
       
    52             switch ( aInstructionSet )
       
    53             {
       
    54             default:
       
    55             case TArmInstructionSet.EARM:
       
    56                 instSet = "[A]";
       
    57                 break;
       
    58             case TArmInstructionSet.ETHUMB:
       
    59                 instSet = "[T]";
       
    60                 break;
       
    61             case TArmInstructionSet.EJAZELLE:
       
    62                 instSet = "[J]";
       
    63                 break;
       
    64             }
       
    65             return instSet;
       
    66         }
       
    67         #endregion
       
    68 
       
    69         #region Properties
       
    70         public byte CurrentRawByte
       
    71         {
       
    72             get { return iCurrentRawByte; }
       
    73         }
       
    74 
       
    75         public string Binary
       
    76         {
       
    77             get
       
    78             {
       
    79                 StringBuilder ret = new StringBuilder();
       
    80                 ret.Append( Convert.ToString( CurrentRawByte, 2 ).PadLeft( 8, '0' ) );
       
    81                 return ret.ToString();
       
    82             }
       
    83         }
       
    84 
       
    85         protected ETMStateData StateData
       
    86         {
       
    87             get { return iStateData; }
       
    88         }
       
    89         #endregion
       
    90 
       
    91         #region Internal methods
       
    92         protected StringBuilder MakeTracePacketPrefix( string aPacketName )
       
    93         {
       
    94             StringBuilder ret = new StringBuilder();
       
    95             ret.AppendFormat( " {0} [PKT] {1}", MakeInstructionSetPrefix( StateData.CurrentInstructionSet ), aPacketName.ToUpper().PadRight( 16, ' ' ) );
       
    96             return ret;
       
    97         }
       
    98 
       
    99         protected virtual void DbgTrace( string aPrefix, string aPostfix )
       
   100         {
       
   101             StringBuilder trace = MakeTracePacketPrefix( aPrefix );
       
   102             trace.AppendFormat( " - 0x{0:x8} [{1:d2}] {2} {3} {4}{5}",
       
   103                 StateData.CurrentAddress,
       
   104                 StateData.LastBranch.KnownBits,
       
   105                 StateData.CurrentAddress.AddressBinary,
       
   106                 StateData.LastBranch.IsKnown ? StateData.Engine.LookUpSymbol( StateData.CurrentAddress ) : string.Empty,
       
   107                 aPostfix,
       
   108                 System.Environment.NewLine
       
   109               );
       
   110             //
       
   111             Trace( trace.ToString() );
       
   112         }
       
   113 
       
   114         protected virtual void DbgTrace( string aPrefix )
       
   115         {
       
   116             DbgTrace( aPrefix, string.Empty );
       
   117         }
       
   118         #endregion
       
   119 
       
   120         #region From System.Object
       
   121         #endregion
       
   122 
       
   123         #region From ITracer
       
   124         public void Trace( string aText )
       
   125         {
       
   126             iStateData.Engine.Trace( aText );
       
   127         }
       
   128 
       
   129         public void Trace( string aFormat, params object[] aParams )
       
   130         {
       
   131             iStateData.Engine.Trace( aFormat, aParams );
       
   132         }
       
   133         #endregion
       
   134 
       
   135         #region Data members
       
   136         private readonly ETMStateData iStateData;
       
   137         private byte iCurrentRawByte = 0;
       
   138         #endregion
       
   139     }
       
   140 }