crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbolLib/CodeSeg/CodeSegDefinitionParser.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.Text.RegularExpressions;
       
    20 using SymbianUtils;
       
    21 using SymbolLib.Sources.Map.Engine;
       
    22 
       
    23 namespace SymbolLib.CodeSegDef
       
    24 {
       
    25 	public class CodeSegDefinitionParser
       
    26 	{
       
    27         #region Constructors & destructor
       
    28         public CodeSegDefinitionParser()
       
    29         {
       
    30             iResolver = null;
       
    31         }
       
    32 
       
    33 	    public CodeSegDefinitionParser( CodeSegResolver aResolver )
       
    34 		{
       
    35             iResolver = aResolver;
       
    36 		}
       
    37         #endregion
       
    38 
       
    39         #region Properties
       
    40         public bool MapFileMustExistsWhenCreatingEntry
       
    41         {
       
    42             get { return iMapFileMustExistsWhenCreatingEntry; }
       
    43             set { iMapFileMustExistsWhenCreatingEntry = value; }
       
    44         }
       
    45         #endregion
       
    46 
       
    47         #region API
       
    48         public CodeSegDefinition ParseDefinition( string aLine )
       
    49         {
       
    50             CodeSegDefinition ret = null;
       
    51             //
       
    52             Match m = iCodeSegRegEx.Match( aLine );
       
    53             if ( m.Success )
       
    54             {
       
    55                 ret = new CodeSegDefinition();
       
    56                 //
       
    57                 string gpAddressStart = m.Groups[ "StartAddress" ].Value;
       
    58                 string gpAddressEnd = m.Groups[ "EndAddress" ].Value;
       
    59                 string gpBinary = m.Groups[ "Binary" ].Value;
       
    60                 //
       
    61                 ret.AddressStart = uint.Parse( gpAddressStart, System.Globalization.NumberStyles.HexNumber );
       
    62                 ret.AddressEnd = uint.Parse( gpAddressEnd, System.Globalization.NumberStyles.HexNumber );
       
    63                 ret.ImageFileNameAndPath = gpBinary;
       
    64             }
       
    65             //
       
    66             return ret;
       
    67         }
       
    68 
       
    69         public CodeSegDefinition ParseAndResolveDefinition( string aLine )
       
    70         {
       
    71             if ( iResolver == null )
       
    72             {
       
    73                 throw new Exception( "Resolver is not initialised" );
       
    74             }
       
    75             //
       
    76             CodeSegDefinition ret = null;
       
    77             CodeSegDefinition entry = ParseDefinition( aLine );
       
    78             if ( entry != null )
       
    79             {
       
    80                 ret = iResolver.Resolve( entry, MapFileMustExistsWhenCreatingEntry );
       
    81             }
       
    82             //
       
    83             return ret;
       
    84         }
       
    85         #endregion
       
    86 
       
    87         #region Internal constants
       
    88         private static readonly Regex iCodeSegRegEx = new Regex(
       
    89             @"(?<StartAddress>[a-fA-F0-9]{8})-(?<EndAddress>[a-fA-F0-9]{8})\s{1}(?<Binary>.+)",
       
    90             RegexOptions.IgnoreCase
       
    91             );
       
    92         private const int KBaseHex = 16;
       
    93         #endregion
       
    94 
       
    95         #region Data members
       
    96         private readonly CodeSegResolver iResolver;
       
    97         private bool iMapFileMustExistsWhenCreatingEntry = false;
       
    98         #endregion
       
    99     }
       
   100 }