crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianSymbolLib/Plugins/SLPluginSymbol/Reader/SymbolCreator.cs
changeset 0 818e61de6cd1
equal deleted inserted replaced
-1:000000000000 0:818e61de6cd1
       
     1 /*
       
     2 * Copyright (c) 2004-2008 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.IO;
       
    20 using System.Collections.Generic;
       
    21 using System.Text;
       
    22 using System.Text.RegularExpressions;
       
    23 using SymbianStructuresLib.Debug.Symbols;
       
    24 using SymbianSymbolLib.SourceManagement.Source;
       
    25 using SymbianSymbolLib.SourceManagement.Provisioning;
       
    26 using SymbianUtils;
       
    27 using SymbianUtils.Tracer;
       
    28 using SymbianUtils.FileTypes;
       
    29 
       
    30 namespace SLPluginSymbol.Reader
       
    31 {
       
    32 	internal class SymbolCreator
       
    33 	{
       
    34 		#region Constructors
       
    35         public SymbolCreator()
       
    36 		{
       
    37 		}
       
    38         #endregion
       
    39 
       
    40         #region API
       
    41         public static BasicSymbol Parse( string aLine )
       
    42         {
       
    43             BasicSymbol ret = null;
       
    44             //
       
    45             Match m = KSimpleSymbolRegEx.Match( aLine );
       
    46             if ( m.Success )
       
    47             {
       
    48                 BasicSymbol symbol = new BasicSymbol();
       
    49 
       
    50                 symbol.iAddress = uint.Parse( m.Groups[ "Address" ].Value, System.Globalization.NumberStyles.HexNumber );
       
    51                 symbol.iSize = uint.Parse( m.Groups[ "Size" ].Value, System.Globalization.NumberStyles.HexNumber );
       
    52 
       
    53                 string symbolAndObject = m.Groups[ "SymbolAndObject" ].Value;
       
    54                 ParseSymbolText( symbolAndObject, out symbol.iName, out symbol.iObject );
       
    55 
       
    56                 ret = symbol;
       
    57             }
       
    58             //
       
    59             return ret;
       
    60         }
       
    61 
       
    62         public Symbol Parse( string aLine, SymbolCollection aCollection )
       
    63 		{
       
    64             Symbol ret = null;
       
    65             //
       
    66             BasicSymbol basicSymbol = Parse( aLine );
       
    67             if ( basicSymbol != null )
       
    68             {
       
    69                 uint baseAddress = aCollection.BaseAddress;
       
    70                 uint offsetAddress = basicSymbol.iAddress - baseAddress;
       
    71                 if ( basicSymbol.iAddress < baseAddress )
       
    72                 {
       
    73                     ret = null;
       
    74                 }
       
    75                 else
       
    76                 {
       
    77                     ret = Symbol.New( aCollection );
       
    78                     //
       
    79                     ret.OffsetAddress = offsetAddress;
       
    80                     ret.Size = basicSymbol.iSize;
       
    81                     ret.Name = basicSymbol.iName;
       
    82                     ret.Object = basicSymbol.iObject;
       
    83 
       
    84                     // Make sure it's tagged as coming from a symbol file
       
    85                     ret.Source = TSymbolSource.ESourceWasSymbolFile;
       
    86                 }
       
    87             }
       
    88 			//
       
    89             return ret;
       
    90 		}
       
    91         #endregion
       
    92 
       
    93         #region Classes
       
    94         public class BasicSymbol
       
    95         {
       
    96             #region Data members
       
    97             public uint iAddress = 0;
       
    98             public uint iSize = 0;
       
    99             public string iName = string.Empty;
       
   100             public string iObject = string.Empty;
       
   101             #endregion
       
   102         }
       
   103         #endregion
       
   104 
       
   105         #region Internal constants
       
   106         private static readonly Regex KSimpleSymbolRegEx = new Regex( "(?<Address>[A-Fa-f0-9]{8}) \\s+ (?<Size>[A-Fa-f0-9]{4,}) \\s+ (?<SymbolAndObject>.+)",
       
   107             RegexOptions.CultureInvariant
       
   108             | RegexOptions.Compiled
       
   109             );
       
   110         #endregion
       
   111 
       
   112         #region Internal methods
       
   113         private static void ParseSymbolText( string aText, out string aName, out string aObject )
       
   114 		{
       
   115 			int splitPos = aText.LastIndexOf( ' ' );
       
   116 			if	( splitPos > 0 )
       
   117 			{
       
   118 				aName = aText.Substring( 0, splitPos ).TrimEnd();
       
   119 				aObject = aText.Substring( splitPos ).TrimStart();
       
   120 			}
       
   121 			else
       
   122 			{
       
   123 				aName = aText;
       
   124                 aObject = string.Empty;
       
   125 			}
       
   126 		}
       
   127 		#endregion
       
   128 	}
       
   129 }