crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianStackLib/Plugins/Basic/StackAlgBasic.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 using System;
       
    18 using System.Text;
       
    19 using System.Threading;
       
    20 using System.ComponentModel;
       
    21 using System.Collections.Generic;
       
    22 using System.IO;
       
    23 using SymbianUtils.DataBuffer.Entry;
       
    24 using SymbianStructuresLib.Arm.Registers;
       
    25 using SymbianStructuresLib.CodeSegments;
       
    26 using SymbianStructuresLib.Debug.Symbols;
       
    27 using SymbianUtils;
       
    28 using SymbianUtils.Range;
       
    29 using SymbianUtils.Utilities;
       
    30 using SymbianDebugLib.PluginAPI.Types;
       
    31 using SymbianDebugLib.Engine;
       
    32 using SymbianStackLib.Data.Source;
       
    33 using SymbianStackLib.Data.Output;
       
    34 using SymbianStackLib.Data.Output.Entry;
       
    35 using SymbianStackLib.Interfaces;
       
    36 using SymbianStackLib.Algorithms;
       
    37 
       
    38 namespace SymbianStackAlgorithmBasic
       
    39 {
       
    40     internal class StackAlgBasic : StackAlgorithm
       
    41     {
       
    42         #region Constructors
       
    43         public StackAlgBasic( IStackAlgorithmManager aManager, IStackAlgorithmObserver aObserver )
       
    44             : base( aManager, aObserver )
       
    45         {
       
    46         }
       
    47         #endregion
       
    48 
       
    49         #region API
       
    50         #endregion
       
    51 
       
    52         #region Properties
       
    53         #endregion
       
    54 
       
    55         #region From StackAlgorithm
       
    56         public override bool IsAvailable()
       
    57         {
       
    58             // This is always available
       
    59             return true;
       
    60         }
       
    61 
       
    62         public override string Name
       
    63         {
       
    64             get { return "Basic"; }
       
    65         }
       
    66 
       
    67         public override int Priority
       
    68         {
       
    69             get { return 200; }
       
    70         }
       
    71         #endregion
       
    72 
       
    73         #region From AsyncReaderBase
       
    74         protected override void PerformOperation()
       
    75         {
       
    76             // Get the source data we need to reconstruct and signal we're about to start
       
    77             StackSourceData sourceData = base.SourceData;
       
    78 
       
    79             // Get the output data sink
       
    80             StackOutputData outputData = base.OutputData;
       
    81             outputData.Clear();
       
    82             outputData.AlgorithmName = Name;
       
    83 
       
    84             // Get the address range of the stack pointer data
       
    85             AddressRange pointerRange = base.Engine.AddressInfo.StackPointerRange;
       
    86             AddressRange pointerRangeExtended = base.Engine.AddressInfo.StackPointerRangeWithExtensionArea;
       
    87 
       
    88             // Indicates if we added LR and PC to the call stack
       
    89             bool addedLRandPC = false;
       
    90 
       
    91             // Get registers
       
    92             ArmRegisterCollection regs = base.Engine.Registers;
       
    93 
       
    94             foreach ( DataBufferUint sourceEntry in sourceData.GetUintEnumerator() )
       
    95             {
       
    96                 // Check if it is within the stack domain, taking into account
       
    97                 // our extended range
       
    98                 if ( pointerRangeExtended.Contains( sourceEntry.Address ) )
       
    99                 {
       
   100                     StackOutputEntry outputEntry = new StackOutputEntry( sourceEntry.Address, sourceEntry.Uint );
       
   101 
       
   102                     // Is it the element tht corresponds to the current value of SP?
       
   103                     bool isCurrentSPEntry = ( outputEntry.AddressRange.Contains( base.Engine.AddressInfo.Pointer ) );
       
   104                     outputEntry.IsCurrentStackPointerEntry = isCurrentSPEntry;
       
   105 
       
   106                     // Is it within the pure 'stack pointer' address range?
       
   107                     bool outsidePureStackPointerRange = !pointerRange.Contains( sourceEntry.Address );
       
   108                     outputEntry.IsOutsideCurrentStackRange = outsidePureStackPointerRange;
       
   109 
       
   110                     // These are never accurate, but neither are they ghosts
       
   111                     outputEntry.IsAccurate = false;
       
   112                     outputEntry.IsGhost = false;
       
   113 
       
   114                     // Save entry
       
   115                     EmitElement( outputEntry );
       
   116 
       
   117                     // If we're inside the stack address range, then poke in the PC and LR values
       
   118                     if ( isCurrentSPEntry )
       
   119                     {
       
   120                         System.Diagnostics.Debug.Assert( !addedLRandPC );
       
   121                         addedLRandPC = AddLRAndPC();
       
   122                     }
       
   123                 }
       
   124                 else
       
   125                 {
       
   126                     // Nope, ignore it...
       
   127                 }
       
   128 
       
   129                 NotifyEvent( TEvent.EReadingProgress );
       
   130                 ++iDWordIndex;
       
   131             }
       
   132 
       
   133             // If the stack overflowed, then SP might be outside of the stack range. Therefore
       
   134             // LR and PC will not be added yet.
       
   135             if ( !addedLRandPC )
       
   136             {
       
   137                 AddLRAndPC();
       
   138             }
       
   139         }
       
   140 
       
   141         protected override long Size
       
   142         {
       
   143             get
       
   144             {
       
   145                 int bytes = base.SourceData.Count;
       
   146                 int dWords = bytes / 4;
       
   147                 return dWords;
       
   148             }
       
   149         }
       
   150 
       
   151         protected override long Position
       
   152         {
       
   153             get
       
   154             {
       
   155                 return iDWordIndex;
       
   156             }
       
   157         }
       
   158         #endregion
       
   159 
       
   160         #region Internal methods
       
   161         private bool AddLRAndPC()
       
   162         {
       
   163             bool addedLRandPC = false;
       
   164             //
       
   165             ArmRegisterCollection regs = base.Engine.Registers;
       
   166 
       
   167             // If we're inside the stack address range, then poke in the PC and LR values
       
   168             if ( regs.Count > 0 )
       
   169             {
       
   170                 // Working bottom up, so LR should go on the stack first
       
   171                 if ( regs.Contains( TArmRegisterType.EArmReg_LR ) )
       
   172                 {
       
   173                     ArmRegister regLR = regs[ TArmRegisterType.EArmReg_LR ];
       
   174 
       
   175                     StackOutputEntry entryLR = new StackOutputEntry( 0, regLR.Value );
       
   176                     entryLR.IsRegisterBasedEntry = true;
       
   177                     entryLR.IsOutsideCurrentStackRange = true;
       
   178                     entryLR.AssociatedRegister = regLR.RegType;
       
   179                     EmitElement( entryLR );
       
   180                 }
       
   181 
       
   182                 // Then the PC...
       
   183                 if ( regs.Contains( TArmRegisterType.EArmReg_PC ) )
       
   184                 {
       
   185                     ArmRegister regPC = regs[ TArmRegisterType.EArmReg_PC ];
       
   186 
       
   187                     StackOutputEntry entryPC = new StackOutputEntry( 0, regPC.Value );
       
   188                     entryPC.IsRegisterBasedEntry = true;
       
   189                     entryPC.IsOutsideCurrentStackRange = true;
       
   190                     entryPC.AssociatedRegister = regPC.RegType;
       
   191                     EmitElement( entryPC );
       
   192                 }
       
   193 
       
   194                 // Even if they weren't added, we at least attempted to addd them
       
   195                 addedLRandPC = true;
       
   196             }
       
   197 
       
   198             return addedLRandPC;
       
   199         }
       
   200 
       
   201         private void EmitElement( StackOutputEntry aEntry )
       
   202         {
       
   203             // Flush entry
       
   204             base.StackObserver.StackBuildingElementConstructed( this, aEntry );
       
   205         }
       
   206         #endregion
       
   207 
       
   208         #region Data members
       
   209         private int iDWordIndex = 0;
       
   210         #endregion
       
   211     }
       
   212 }