crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbolLib/Engines/SymbolManager.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;
       
    20 using System.Threading;
       
    21 using System.Collections;
       
    22 using System.Collections.Generic;
       
    23 using SymbianUtils;
       
    24 using SymbianUtils.Tracer;
       
    25 using SymbolLib.Generics;
       
    26 using SymbolLib.Engines.ROFS;
       
    27 using SymbolLib.Engines.ROM;
       
    28 using SymbolLib.Sources.Map.Engine;
       
    29 using SymbolLib.Sources.Symbol.Engine;
       
    30 using SymbolLib.CodeSegDef;
       
    31 
       
    32 namespace SymbolLib.Engines
       
    33 {
       
    34 	public class SymbolManager : ITracer
       
    35     {
       
    36         #region Construct & destruct
       
    37         public SymbolManager()
       
    38             : this( null )
       
    39 		{
       
    40 		}
       
    41 
       
    42         public SymbolManager( ITracer aTracer )
       
    43         {
       
    44             iTracer = aTracer;
       
    45             //
       
    46             iEngineROM = new ROMEngine( this );
       
    47             iEngineROFS = new ROFSEngine( this );
       
    48         }
       
    49 		#endregion
       
    50 
       
    51 		#region API
       
    52         public void Clear()
       
    53         {
       
    54             ClearTags();
       
    55             ROFSEngine.Reset();
       
    56             ROMEngine.Reset();
       
    57         }
       
    58 
       
    59         public Dictionary<string, string> GetSupportedExtensions()
       
    60         {
       
    61             Dictionary<string, string> ret = new Dictionary<string, string>();
       
    62             //
       
    63             ret.Add( "*.symbol", "Symbian OS Symbol File" );
       
    64             ret.Add( "*.map", "Symbian OS Map File" );
       
    65             ret.Add( "*.oby", "Symbian OS Obey File" );
       
    66             //
       
    67             return ret;
       
    68         }
       
    69 
       
    70 		public bool IsLoaded( string aFileName )
       
    71 		{
       
    72             string fileName = aFileName.ToLower();
       
    73 			bool loaded = iEngineROM.IsLoaded( fileName );
       
    74             //
       
    75             if  ( loaded == false )
       
    76             {
       
    77                 loaded = iEngineROFS.IsLoaded( fileName );
       
    78             }
       
    79             //
       
    80 			return loaded;
       
    81 		}
       
    82 
       
    83         public void ClearTags()
       
    84         {
       
    85             iEngineROM.ClearTags();
       
    86             iEngineROFS.ClearTags();
       
    87         }
       
    88 
       
    89         public void LoadDynamicCodeSegment( CodeSegDefinition aCodeSegment, TSynchronicity aSynchronicity )
       
    90         {
       
    91             ROFSEngine.LoadFromDefinition( aCodeSegment, aSynchronicity );
       
    92         }
       
    93 
       
    94         public void LoadDynamicCodeSegments( CodeSegDefinitionCollection aCodeSegments, TSynchronicity aSynchronicity )
       
    95         {
       
    96             // Unload any pre-existing dynamically loaded content
       
    97             ROFSEngine.UnloadAll();
       
    98 
       
    99             // We must attempt to dynamically load all the code segements listed. 
       
   100             // For codesegments that we have no corresponding collection for, we'll allow
       
   101             // a stub codesegment to be created in the ROFS engine - this ensures we
       
   102             // at least show the codesegment name (though not function addresses) when we
       
   103             // encounter an unrecognised address within the codesegment address space.
       
   104             //
       
   105             // For everything else, we load it (if it exists) or then if it's already been
       
   106             // loaded by the CORE ROM symbol file, we ignore the request.
       
   107 
       
   108             // These are the code segs that we'll eventually push through to the
       
   109             // ROFS engine.
       
   110             CodeSegDefinitionCollection codeSegsToAttemptToLoad = new CodeSegDefinitionCollection();
       
   111 
       
   112             // First pass - identify which code seg entries we already have loaded.
       
   113             foreach ( CodeSegDefinition def in aCodeSegments )
       
   114             {
       
   115                 // Check if there is already a valid definition for this entry in
       
   116                 // the CORE ROM symbol table. If there is, the we don't need to do
       
   117                 // anything.
       
   118                 bool loaded = ROMEngine.IsLoaded( def );
       
   119                 if ( !loaded )
       
   120                 {
       
   121                     Trace( "SymbolManager.LoadDynamicCodeSegments() - will attempt to load: " + def );
       
   122                     codeSegsToAttemptToLoad.Add( def );
       
   123                 }
       
   124                 else
       
   125                 {
       
   126                     Trace( "SymbolManager.LoadDynamicCodeSegments() - not loading XIP code seg: " + def );
       
   127                 }
       
   128             }
       
   129 
       
   130             // Now, we have a ratified list that contains only code segments that weren't already managed
       
   131             // by the CORE ROM engine.
       
   132             ROFSEngine.LoadFromDefinitionCollection( codeSegsToAttemptToLoad, aSynchronicity );
       
   133         }
       
   134 
       
   135         public static TFileType IsSupported( string aFileName )
       
   136         {
       
   137             TFileType ret = TFileType.EFileNotSupported;
       
   138             //
       
   139             FileInfo fileInfo = new FileInfo( aFileName );
       
   140             if ( fileInfo.Exists )
       
   141             {
       
   142                 // Try rom then rofs
       
   143                 ret = ROMEngine.IsSupported( aFileName );
       
   144                 if ( ret == TFileType.EFileNotSupported )
       
   145                 {
       
   146                     ret = ROFSEngine.IsSupported( aFileName );
       
   147                 }
       
   148             }
       
   149             //
       
   150             return ret;
       
   151         }
       
   152 		#endregion
       
   153 
       
   154 		#region Properties
       
   155         public ROMEngine ROMEngine
       
   156 		{
       
   157 			get { return iEngineROM; }
       
   158 		}
       
   159 		
       
   160 		public ROFSEngine ROFSEngine
       
   161 		{
       
   162 			get { return iEngineROFS; }
       
   163 		}
       
   164 
       
   165 		public int NumberOfCollections
       
   166 		{
       
   167 			get
       
   168 			{
       
   169 				int count = 0;
       
   170 				//
       
   171 				count += iEngineROM.NumberOfCollections;
       
   172 				count += iEngineROFS.NumberOfCollections;
       
   173 				//
       
   174 				return count;
       
   175 			}
       
   176 		}
       
   177 
       
   178 		public int NumberOfEntries
       
   179 		{
       
   180 			get
       
   181 			{
       
   182 				int count = 0;
       
   183 				//
       
   184 				count += iEngineROM.NumberOfEntries;
       
   185 				count += iEngineROFS.NumberOfEntries;
       
   186 				//
       
   187 				return count;
       
   188 			}
       
   189 		}
       
   190 
       
   191 		public bool IsReady
       
   192 		{
       
   193 			get
       
   194 			{
       
   195 				bool readyROM = iEngineROM.IsReady;
       
   196                 bool readyROFS = iEngineROFS.IsReady;
       
   197                 //
       
   198 				return ( readyROM && readyROFS );
       
   199 			}
       
   200 		}
       
   201 		#endregion
       
   202 
       
   203 		#region Lookup API
       
   204 		public bool AddressInRange( long aAddress )
       
   205 		{
       
   206 			bool ret = iEngineROFS.AddressInRange( aAddress );
       
   207 			if	( !ret )
       
   208 			{
       
   209 				ret = iEngineROM.AddressInRange( aAddress );
       
   210 			}
       
   211 			return ret;
       
   212 		}
       
   213 
       
   214         /// <summary>
       
   215         /// Performs as substring match within each collection's host binary file name
       
   216         /// for aFileName.
       
   217         /// </summary>
       
   218         /// <param name="aHostBinaryFileName"></param>
       
   219         /// <returns></returns>
       
   220         public GenericSymbolCollection[] CollectionsByHostBinarySearch( string aFileName )
       
   221         {
       
   222             List<GenericSymbolCollection> ret = new List<GenericSymbolCollection>();
       
   223             //
       
   224             ret.AddRange( iEngineROM.CollectionsByHostBinarySearch( aFileName ) );
       
   225             ret.AddRange( iEngineROFS.CollectionsByHostBinarySearch( aFileName ) );
       
   226             //
       
   227             return ret.ToArray();
       
   228         }
       
   229 
       
   230         public string SymbolNameByAddress( long aAddress )
       
   231         {
       
   232             string ret = string.Empty;
       
   233 
       
   234             SymbolLib.Generics.GenericSymbol symbol = EntryByAddress( aAddress );
       
   235             if  ( symbol != null )
       
   236             {
       
   237                 ret = symbol.Symbol;
       
   238             }
       
   239 
       
   240             return ret;
       
   241         }
       
   242 
       
   243 		public GenericSymbol EntryByAddress( long aAddress )
       
   244 		{
       
   245 			GenericSymbolCollection collection = null;
       
   246 			GenericSymbol ret = EntryByAddress( aAddress, out collection );
       
   247 			return ret;
       
   248 		}
       
   249 
       
   250 		public GenericSymbol EntryByAddress( long aAddress, out GenericSymbolCollection aCollection )
       
   251 		{
       
   252             aCollection = null;
       
   253             GenericSymbolCollection rofsCollection = null;
       
   254 
       
   255 			// First check with the map file engine to see if there is a loaded
       
   256 			// code segment entry that matches the specified address.
       
   257 			GenericSymbol ret = iEngineROFS.EntryByAddress( aAddress, ref rofsCollection );
       
   258 			//
       
   259 			if	( ret == null )
       
   260 			{
       
   261                 GenericSymbolCollection romCollection = null;
       
   262                 ret = iEngineROM.EntryByAddress( aAddress, ref romCollection );
       
   263 
       
   264                 // Decide which collection to return in the case that 
       
   265                 // a) we found a matching symbol, or 
       
   266                 // b) when we didn't.
       
   267                 if ( ret == null && rofsCollection != null )
       
   268                 {
       
   269                     // ROFS wins by default if we found something inside the ROFS engine...
       
   270                     aCollection = rofsCollection;
       
   271                 }
       
   272                 else
       
   273                 {
       
   274                     // Otherwise we'll use the ROM collection (irrespective of whether something
       
   275                     // was found or not)
       
   276                     aCollection = romCollection;
       
   277                 }
       
   278 			}
       
   279             else
       
   280             {
       
   281                 // ROFS wins
       
   282                 aCollection = rofsCollection;
       
   283             }
       
   284 
       
   285 			return ret;
       
   286 		}
       
   287 
       
   288 		public GenericSymbolCollection CollectionByAddress( long aAddress )
       
   289 		{
       
   290 			// First check with the map file engine to see if there is a loaded
       
   291 			// code segment entry that matches the specified address.
       
   292 			GenericSymbolCollection ret = iEngineROFS.CollectionByAddress( aAddress );
       
   293 			//
       
   294 			if	( ret == null )
       
   295 			{
       
   296 				ret = iEngineROM.CollectionByAddress( aAddress );
       
   297 			}
       
   298 			//
       
   299 			return ret;
       
   300 		}		
       
   301 		#endregion
       
   302 
       
   303         #region ITracer Members
       
   304         public void Trace( string aMessage )
       
   305         {
       
   306             if ( iTracer != null )
       
   307             {
       
   308                 iTracer.Trace( aMessage );
       
   309             }
       
   310         }
       
   311 
       
   312         public void Trace( string aFormat, params object[] aParams )
       
   313         {
       
   314             Trace( string.Format( aFormat, aParams ) );
       
   315         }
       
   316         #endregion
       
   317 
       
   318 		#region Data members
       
   319         private readonly ITracer iTracer;
       
   320         private readonly ROMEngine iEngineROM;
       
   321         private readonly ROFSEngine iEngineROFS;
       
   322 		#endregion
       
   323 	}
       
   324 }