crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianStackLib/Prefixes/StackPrefixManager.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.Collections.Generic;
       
    19 using SymbianUtils;
       
    20 using SymbianParserLib.Engine;
       
    21 using SymbianParserLib.Elements;
       
    22 using SymbianStructuresLib.CodeSegments;
       
    23 using SymbianStackLib.Engine;
       
    24 
       
    25 namespace SymbianStackLib.Prefixes
       
    26 {
       
    27 	public class StackPrefixManager
       
    28 	{
       
    29 		#region Constructors
       
    30         internal StackPrefixManager( StackEngine aEngine )
       
    31 		{
       
    32             iEngine = aEngine;
       
    33             //
       
    34             PreparePrefixes_CodeSegment();
       
    35             PreparePrefixes_Pointer();
       
    36             //
       
    37             iParserEntries.Add( iPrefixEngine_Pointer );
       
    38             iParserEntries.Add( iPrefixEngine_CodeSegment );
       
    39         }
       
    40 		#endregion
       
    41 
       
    42 		#region API
       
    43         public void SetCustomPointer( string aPrefix )
       
    44         {
       
    45             // Find any existing custom entry and remove it
       
    46             int paraCount = iPrefixEngine_Pointer.Count;
       
    47             System.Diagnostics.Debug.Assert( paraCount >= 1 );
       
    48             if ( paraCount > 1 )
       
    49             {
       
    50                 iPrefixEngine_Pointer.RemoveRange( 1 );
       
    51             }
       
    52 
       
    53             string prefixText = aPrefix.Trim();
       
    54             if ( prefixText != string.Empty )
       
    55             {
       
    56                 ParserParagraph para = new ParserParagraph( "Dynamic_Pointer" );
       
    57                 //
       
    58                 prefixText += "%08x";
       
    59                 //
       
    60                 ParserLine l1 = ParserLine.NewSymFormat( prefixText );
       
    61                 l1.SetTargetProperty( iEngine.AddressInfo, "Pointer" );
       
    62                 para.Add( l1 );
       
    63                 iPrefixEngine_Pointer.Add( para );
       
    64             }
       
    65         }
       
    66 
       
    67         public void SetCustomCodeSegment( string aPrefix )
       
    68         {
       
    69             // Find any existing custom entry and remove it
       
    70             int paraCount = iPrefixEngine_CodeSegment.Count;
       
    71             System.Diagnostics.Debug.Assert( paraCount >= 1 );
       
    72             if ( paraCount > 1 )
       
    73             {
       
    74                 iPrefixEngine_CodeSegment.RemoveRange( 1 );
       
    75             }
       
    76 
       
    77             string prefixText = aPrefix.Trim();
       
    78             if ( prefixText != string.Empty )
       
    79             {
       
    80                 ParserParagraph para = new ParserParagraph( "Dynamic_CodeSegment" );
       
    81                 //
       
    82                 prefixText += "%08x-%08x %S";
       
    83                 //
       
    84                 ParserLine l1 = ParserLine.NewSymFormat( prefixText );
       
    85                 l1.SetTargetMethod( this, "TryToParseCodeSegment" );
       
    86                 l1.DisableWhenComplete = false;
       
    87                 para.Add( l1 );
       
    88                 para.DisableWhenComplete = false;
       
    89                 iPrefixEngine_CodeSegment.Add( para );
       
    90             }
       
    91         }
       
    92         #endregion
       
    93 
       
    94         #region Properties
       
    95         public string CodeSegment
       
    96         {
       
    97             get
       
    98             {
       
    99                 string ret = string.Empty;
       
   100                 //
       
   101                 int count = iPrefixEngine_CodeSegment.Count;
       
   102                 if ( count > 0 )
       
   103                 {
       
   104                     ParserParagraph para = iPrefixEngine_CodeSegment[ count - 1 ];
       
   105                     count = para.Count;
       
   106                     if ( count > 0 )
       
   107                     {
       
   108                         ParserLine line = para[ count - 1 ];
       
   109                         //
       
   110                         if ( line.LineType == ParserLine.TLineType.ELineTypeSimpleStringMatch )
       
   111                         {
       
   112                             ret = line.OriginalValue;
       
   113                         }
       
   114                     }
       
   115                 }
       
   116                 //
       
   117                 return ret;
       
   118             }
       
   119         }
       
   120 
       
   121         public string Pointer
       
   122         {
       
   123             get
       
   124             {
       
   125                 string ret = "CurrentSP - ";
       
   126                 //
       
   127                 int count = iPrefixEngine_Pointer.Count;
       
   128                 if ( count > 0 )
       
   129                 {
       
   130                     ParserParagraph para = iPrefixEngine_Pointer[ count - 1 ];
       
   131                     count = para.Count;
       
   132                     if ( count > 0 )
       
   133                     {
       
   134                         ParserLine line = para[ count - 1 ];
       
   135                         //
       
   136                         if ( line.LineType == ParserLine.TLineType.ELineTypeSimpleStringMatch )
       
   137                         {
       
   138                             ret = line.OriginalValue;
       
   139                         }
       
   140                     }
       
   141                 }
       
   142                 //
       
   143                 return ret;
       
   144             }
       
   145         }
       
   146         #endregion
       
   147 
       
   148         #region Internal methods
       
   149         internal void TryAgainstPrefixes( string aLine )
       
   150         {
       
   151             string line = aLine;
       
   152             foreach ( ParserEngine engine in iParserEntries )
       
   153             {
       
   154                 if ( engine.OfferLine( ref line ) )
       
   155                 {
       
   156                     break;
       
   157                 }
       
   158             }
       
   159         }
       
   160 
       
   161         private void TryToParseCodeSegment( ParserLine aLine )
       
   162         {
       
   163             string line = aLine.GetCurrentLine();
       
   164             CodeSegDefinition codeSegDef = CodeSegDefinitionParser.ParseDefinition( line );
       
   165             if ( codeSegDef != null )
       
   166             {
       
   167                 iEngine.CodeSegments.Add( codeSegDef );
       
   168             }
       
   169         }
       
   170 
       
   171         private void PreparePrefixes_Pointer()
       
   172         {
       
   173             ParserParagraph para = new ParserParagraph( "Fixed_Pointer" );
       
   174             //
       
   175             ParserLine l1 = ParserLine.NewSymFormat( "CurrentSP - 0x%08x" );
       
   176             l1.SetTargetProperty( iEngine.AddressInfo, "Pointer" );
       
   177             //
       
   178             ParserLine l2 = ParserLine.NewSymFormat( "CurrentSP - %08x" );
       
   179             l2.SetTargetProperty( iEngine.AddressInfo, "Pointer" );
       
   180             //
       
   181             ParserLine l3 = ParserLine.NewSymFormat( "CurrentSP: 0x%08x" );
       
   182             l3.SetTargetProperty( iEngine.AddressInfo, "Pointer" );
       
   183             //
       
   184             ParserLine l4 = ParserLine.NewSymFormat( "CurrentSP: %08x" );
       
   185             l4.SetTargetProperty( iEngine.AddressInfo, "Pointer" );
       
   186             //
       
   187             ParserLine l5 = ParserLine.NewSymFormat( "r12=%08x %08x %08x %08x" );
       
   188             l5[1].SetTargetProperty( iEngine.AddressInfo, "Pointer" );
       
   189             //
       
   190             ParserLine l6 = ParserLine.NewSymFormat( "Current stack pointer: 0x%08x" );
       
   191             l6.SetTargetProperty( iEngine.AddressInfo, "Pointer" );
       
   192             //
       
   193             ParserLine l7 = ParserLine.NewSymFormat( "sp: 0x%08x" );
       
   194             l7.SetTargetProperty( iEngine.AddressInfo, "Pointer" );
       
   195             //
       
   196             ParserLine l8 = ParserLine.NewSymFormat( "sp: %08x" );
       
   197             l8.SetTargetProperty( iEngine.AddressInfo, "Pointer" );
       
   198             //
       
   199             para.Add( l1, l2, l3, l4, l5, l6, l7, l8 );
       
   200             //
       
   201             iPrefixEngine_Pointer.Add( para );
       
   202         }
       
   203 
       
   204         private void PreparePrefixes_CodeSegment()
       
   205         {
       
   206             ParserParagraph para = new ParserParagraph( "Fixed_CodeSegment" );
       
   207             //
       
   208             ParserLine l1 = ParserLine.NewSymFormat( "%08x-%08x %S" );
       
   209             l1.SetTargetMethod( this, "TryToParseCodeSegment" );
       
   210             l1.DisableWhenComplete = false;
       
   211             //
       
   212             para.Add( l1 );
       
   213             para.DisableWhenComplete = false;
       
   214             //
       
   215             iPrefixEngine_CodeSegment.Add( para );
       
   216         }
       
   217         #endregion
       
   218 
       
   219         #region Constants
       
   220 		#endregion
       
   221 
       
   222 		#region Data members
       
   223         private readonly StackEngine iEngine;
       
   224         private ParserEngine iPrefixEngine_Pointer = new ParserEngine();
       
   225         private ParserEngine iPrefixEngine_CodeSegment = new ParserEngine();
       
   226         private List<ParserEngine> iParserEntries = new List<ParserEngine>();
       
   227 		#endregion
       
   228     }
       
   229 }