crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbolLib/Sources/Symbol/Symbol/SymbolSymbol.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.IO;
       
    19 using System.Text.RegularExpressions;
       
    20 using SymbolLib.Generics;
       
    21 using SymbolLib.Sources.Symbol.File;
       
    22 
       
    23 namespace SymbolLib.Sources.Symbol.Symbol
       
    24 {
       
    25 	public class SymbolSymbol : GenericSymbol
       
    26 	{
       
    27 		#region Constructors
       
    28         public static SymbolSymbol New( GenericSymbolCollection aCollection )
       
    29         {
       
    30             return new SymbolSymbol( aCollection );
       
    31         }
       
    32 
       
    33         public static SymbolSymbol NewUnknown()
       
    34         {
       
    35             return NewUnknown( new SymbolsForBinary( string.Empty ) );
       
    36         }
       
    37 
       
    38         public static SymbolSymbol NewUnknown( uint aAddress, uint aSize, string aObject )
       
    39         {
       
    40             SymbolSymbol ret = NewUnknown();
       
    41             //
       
    42             ret.OffsetAddress = aAddress;
       
    43             ret.Size = aSize;
       
    44             ret.Object = aObject;
       
    45             //
       
    46             return ret;
       
    47         }
       
    48 
       
    49         public static SymbolSymbol NewUnknown( GenericSymbolCollection aCollection )
       
    50         {
       
    51             SymbolSymbol symbol = new SymbolSymbol( aCollection );
       
    52             //
       
    53             symbol.OffsetAddress = GenericSymbol.KNullEntryAddress;
       
    54             symbol.Symbol = GenericSymbol.KNonMatchingSymbolName;
       
    55             if ( aCollection.HostBinaryFileName.Length > 0 )
       
    56             {
       
    57                 symbol.Object = Path.GetFileName( aCollection.HostBinaryFileName );
       
    58             }
       
    59             else
       
    60             {
       
    61                 symbol.Object = GenericSymbol.KNonMatchingObjectName;
       
    62             }
       
    63             //
       
    64             return symbol;
       
    65         }
       
    66         #endregion
       
    67 
       
    68         #region Internal constructors
       
    69         private SymbolSymbol( GenericSymbolCollection aCollection )
       
    70             : base( aCollection )
       
    71 		{
       
    72 		}
       
    73 
       
    74         private SymbolSymbol( string aSymbolName )
       
    75             : this( aSymbolName, 0 )
       
    76         {
       
    77 		}
       
    78 
       
    79         private SymbolSymbol( string aSymbolName, uint aAddress )
       
    80             : base( new SymbolsForBinary( string.Empty )  )
       
    81         {
       
    82             Symbol = aSymbolName;
       
    83             OffsetAddress = aAddress;
       
    84         }
       
    85         #endregion
       
    86 
       
    87         #region API
       
    88         public void ResetOffsetAddress( long aOffset )
       
    89         {
       
    90             // This resets the offset address
       
    91             OffsetAddress = aOffset;
       
    92 
       
    93             // This resets the OffsetEndAddress
       
    94             Size = Size;
       
    95         }
       
    96         #endregion
       
    97 
       
    98         #region From GenericSymbol
       
    99         public override bool Parse( string aLine )
       
   100 		{
       
   101             bool ret = false;
       
   102             //
       
   103             Match m = KSimpleSymbolRegEx.Match( aLine );
       
   104             if ( m.Success )
       
   105             {
       
   106                 ret = ExtractFromMatch( m );
       
   107             }
       
   108             //
       
   109             return ret;
       
   110 		}
       
   111 
       
   112         public override TSourceType SourceType
       
   113         {
       
   114             get { return GenericSymbol.TSourceType.ESourceTypeFileSymbol; }
       
   115         }
       
   116         #endregion
       
   117 
       
   118         #region Internal methods
       
   119         private bool ExtractFromMatch( Match aMatch )
       
   120         {
       
   121             bool ret = false;
       
   122             //
       
   123             long baseAddress = Collection.BaseAddress;
       
   124             long address = uint.Parse( aMatch.Groups[ "Address" ].Value, System.Globalization.NumberStyles.HexNumber );
       
   125             long offsetAddress = address - baseAddress;
       
   126             if ( address < baseAddress )
       
   127             {
       
   128                 ret = false;
       
   129             }
       
   130             else
       
   131             {
       
   132                 OffsetAddress = offsetAddress;
       
   133                 Size = uint.Parse( aMatch.Groups[ "Size" ].Value, System.Globalization.NumberStyles.HexNumber );
       
   134 
       
   135                 string symbolAndObject = aMatch.Groups[ "SymbolAndObject" ].Value;
       
   136                 ParseSymbolText( symbolAndObject );
       
   137 
       
   138                 System.Diagnostics.Debug.Assert( Address >= 0 );
       
   139                 System.Diagnostics.Debug.Assert( Address <= EndAddress );
       
   140 
       
   141                 ret = true;
       
   142             }
       
   143             //
       
   144             return ret;
       
   145         }
       
   146         #endregion
       
   147 
       
   148         #region Internal constants
       
   149         private static readonly Regex KSimpleSymbolRegEx = new Regex( "(?<Address>[A-Fa-f0-9]{8}) \\s+ (?<Size>[A-Fa-f0-9]{4,}) \\s+ (?<SymbolAndObject>.+)",
       
   150             RegexOptions.CultureInvariant
       
   151             | RegexOptions.Compiled
       
   152             );
       
   153         #endregion
       
   154 
       
   155         #region Internal methods
       
   156         protected void ParseSymbolText( string aText )
       
   157 		{
       
   158 			int splitPos = aText.LastIndexOf( ' ' );
       
   159 			if	( splitPos > 0 )
       
   160 			{
       
   161 				Symbol = aText.Substring( 0, splitPos ).TrimEnd();
       
   162 				Object = aText.Substring( splitPos ).TrimStart();
       
   163 			}
       
   164 			else
       
   165 			{
       
   166 				Symbol = aText;
       
   167                 Object = string.Empty;
       
   168 			}
       
   169 		}
       
   170 		#endregion
       
   171 	}
       
   172 }