crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianETMLib/Common/State/Implementations/ETMDecodeStateBranch.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.BasicTypes;
       
    22 using SymbianStructuresLib.Arm;
       
    23 using SymbianStructuresLib.Arm.Exceptions;
       
    24 using SymbianETMLib.Common.Types;
       
    25 using SymbianETMLib.Common.Packets;
       
    26 using SymbianETMLib.Common.Utilities;
       
    27 using SymbianETMLib.Common.BranchDecoder;
       
    28 
       
    29 namespace SymbianETMLib.Common.State
       
    30 {
       
    31     public class ETMDecodeStateBranch : ETMDecodeState
       
    32     {
       
    33         #region Constructors
       
    34         public ETMDecodeStateBranch( ETMStateData aManager )
       
    35             : base( aManager )
       
    36         {
       
    37             iDecoder = ETMBranchDecoder.New( aManager );
       
    38         }
       
    39         #endregion
       
    40 
       
    41         #region API
       
    42         public override ETMDecodeState HandleByte( SymByte aByte )
       
    43         {
       
    44             // Handle the byte
       
    45             PerformStateOperation( aByte );
       
    46 
       
    47             // Decide what to return based upon current state
       
    48             ETMDecodeState nextState = this;
       
    49             if ( iState == TState.EStateFinished )
       
    50             {
       
    51                 iDecoder.FlushChanges();
       
    52                 nextState = new ETMDecodeStateSynchronized( base.StateData );
       
    53             }
       
    54 
       
    55             // Done.
       
    56             return nextState;
       
    57         }
       
    58         #endregion
       
    59 
       
    60         #region Properties
       
    61         #endregion
       
    62 
       
    63         #region Internal state handler
       
    64         private enum TState
       
    65         {
       
    66             EStateBranch = 0,
       
    67             EStateExceptionContinuation,
       
    68             EStateFinished
       
    69         }
       
    70 
       
    71         private void PerformStateOperation( SymByte aByte )
       
    72         {
       
    73             switch ( iState )
       
    74             {
       
    75             case TState.EStateBranch:
       
    76             {
       
    77                 iDecoder.Offer( aByte );
       
    78 
       
    79                 // Decode the branch if we have all the info we need
       
    80                 if ( iDecoder.IsBranchAddressAvailable )
       
    81                 {
       
    82                     iDecoder.DecodeBranch();
       
    83 
       
    84                     // Check if we expect an exception byte
       
    85                     if ( iDecoder.IsPacketComplete )
       
    86                     {
       
    87                         // Nope, we're done
       
    88                         iState = TState.EStateFinished;
       
    89                     }
       
    90                     else
       
    91                     {
       
    92                         iState = TState.EStateExceptionContinuation;
       
    93                     }
       
    94                 }
       
    95                 break;
       
    96             }
       
    97             case TState.EStateExceptionContinuation:
       
    98             {
       
    99                 iDecoder.DecodeException( aByte );
       
   100                 iState = TState.EStateFinished;
       
   101                 break;
       
   102             }
       
   103             default:
       
   104             case TState.EStateFinished:
       
   105                 System.Diagnostics.Debug.Assert( false );
       
   106                 break;
       
   107             }
       
   108         }
       
   109         #endregion
       
   110 
       
   111         #region Internal methods
       
   112         #endregion
       
   113 
       
   114         #region Data members
       
   115         private readonly ETMBranchDecoder iDecoder;
       
   116         private TState iState = TState.EStateBranch;
       
   117         #endregion
       
   118     }
       
   119 }