crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbolLib/Sources/Symbol/Engine/SymbolFileEngineCollection.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.Range;
       
    25 using SymbianUtils.Tracer;
       
    26 using SymbolLib.Generics;
       
    27 using SymbolLib.CodeSegDef;
       
    28 using SymbolLib.Sources.Symbol.Symbol;
       
    29 using SymbolLib.Sources.Symbol.File;
       
    30 using SymbolLib.Sources.Symbol.Parser;
       
    31 using SymbolLib.Sources.Symbol.Collection;
       
    32 
       
    33 namespace SymbolLib.Sources.Symbol.Engine
       
    34 {
       
    35     public class SymbolFileEngineCollection : GenericSymbolEngine
       
    36     {
       
    37         #region Delegates & Events
       
    38         public event AsyncReaderBase.Observer Observer;
       
    39         #endregion
       
    40 
       
    41         #region Constructorss
       
    42         internal SymbolFileEngineCollection( ITracer aTracer, SymbolFileEngine.TActivationType aActivationType, bool aAllowNonRomSymbols )
       
    43             : base( aTracer )
       
    44         {
       
    45             iActivationType = aActivationType;
       
    46             iAllowNonRomSymbols = aAllowNonRomSymbols;
       
    47         }
       
    48         #endregion
       
    49 
       
    50         #region API
       
    51         public static bool IsSymbolFile( string aFileName )
       
    52         {
       
    53             return SymbolFileEngine.IsSymbolFile( aFileName );
       
    54         }
       
    55 
       
    56         public void LoadFromFile( string aSymbolFileName, TSynchronicity aSynchronicity )
       
    57         {
       
    58             // Check if already exists
       
    59             SymbolFileEngine engine = null;
       
    60             //
       
    61             lock ( this )
       
    62             {
       
    63                 engine = EngineByFileName( aSymbolFileName );
       
    64                 if ( engine != null )
       
    65                 {
       
    66                     iFiles.Remove( engine );
       
    67                 }
       
    68             }
       
    69 
       
    70             engine = new SymbolFileEngine( this, iActivationType, iAllowNonRomSymbols );
       
    71             
       
    72             lock ( this )
       
    73             {
       
    74                 iFiles.Add( engine );
       
    75             }
       
    76 
       
    77             engine.Observer += new AsyncReaderBase.Observer( SymbolEngine_ObserverProxy );
       
    78             engine.LoadFromFile( aSymbolFileName, aSynchronicity );
       
    79         }
       
    80 
       
    81         public bool Load( CodeSegDefinition aDefinition )
       
    82         {
       
    83             bool ret = false;
       
    84             //
       
    85             foreach ( SymbolFileEngine engine in iFiles )
       
    86             {
       
    87                 if ( engine.Load( aDefinition ) )
       
    88                 {
       
    89                     ret = true;
       
    90                     break;
       
    91                 }
       
    92             }
       
    93             //
       
    94             return ret;
       
    95         }
       
    96 
       
    97         public bool Unload( CodeSegDefinition aDefinition )
       
    98         {
       
    99             bool ret = false;
       
   100             //
       
   101             foreach ( SymbolFileEngine engine in iFiles )
       
   102             {
       
   103                 if ( engine.Unload( aDefinition ) )
       
   104                 {
       
   105                     ret = true;
       
   106                     break;
       
   107                 }
       
   108             }
       
   109             //
       
   110             return ret;
       
   111         }
       
   112 
       
   113         public void UnloadAll()
       
   114         {
       
   115             foreach ( SymbolFileEngine engine in iFiles )
       
   116             {
       
   117                 engine.UnloadAll();
       
   118             }
       
   119         }
       
   120 
       
   121         public bool IsLoaded( CodeSegDefinition aDefinition )
       
   122         {
       
   123             bool ret = false;
       
   124             //
       
   125             foreach ( SymbolFileEngine engine in iFiles )
       
   126             {
       
   127                 if ( engine.IsLoaded( aDefinition ) )
       
   128                 {
       
   129                     ret = true;
       
   130                     break;
       
   131                 }
       
   132             }
       
   133             //
       
   134             return ret;
       
   135         }
       
   136 
       
   137         public string SymbolFileName( int aIndex )
       
   138         {
       
   139             return iFiles[ aIndex ].SymbolFileName;
       
   140         }
       
   141         #endregion
       
   142 
       
   143         #region Properties
       
   144         public int SymbolFileCount
       
   145         {
       
   146             get { return iFiles.Count; }
       
   147         }
       
   148 
       
   149         public GenericSymbolEngine SymbolFileEngineAt( int aIndex )
       
   150         {
       
   151             return iFiles[ aIndex ];
       
   152         }
       
   153 
       
   154         public string[] BinaryFileNames
       
   155         {
       
   156             get
       
   157             {
       
   158                 List<string> fileNames = new List<string>( AllSymbols.Count );
       
   159                 //
       
   160                 foreach ( GenericSymbolCollection collection in AllSymbols )
       
   161                 {
       
   162                     fileNames.Add( collection.HostBinaryFileName );
       
   163                 }
       
   164                 //
       
   165                 return fileNames.ToArray();
       
   166             }
       
   167         }
       
   168 
       
   169         public string[] SymbolFileNames
       
   170         {
       
   171             get
       
   172             {
       
   173                 List<string> fileNames = new List<string>( iFiles.Count );
       
   174                 //
       
   175                 foreach ( SymbolFileEngine engine in iFiles )
       
   176                 {
       
   177                     fileNames.Add( engine.SymbolFileName );
       
   178                 }
       
   179                 //
       
   180                 return fileNames.ToArray();
       
   181             }
       
   182         }
       
   183 
       
   184         public SymbolsForBinaryCollection AllSymbols
       
   185         {
       
   186             get
       
   187             {
       
   188                 SymbolsForBinaryCollection ret = new SymbolsForBinaryCollection();
       
   189                 //
       
   190                 foreach ( SymbolFileEngine engine in iFiles )
       
   191                 {
       
   192                     ret.Add( engine.AllSymbols );
       
   193                 }
       
   194                 //
       
   195                 return ret;
       
   196             }
       
   197         }
       
   198         #endregion
       
   199 
       
   200         #region From GenericSymbolEngine
       
   201         public override void Reset()
       
   202         {
       
   203             iFiles.Clear();
       
   204         }
       
   205 
       
   206         public override bool IsLoaded( string aFileName )
       
   207         {
       
   208             SymbolFileEngine engine = EngineByFileName( aFileName );
       
   209             return engine != null;
       
   210         }
       
   211 
       
   212         public override bool IsReady
       
   213         {
       
   214             get
       
   215             {
       
   216                 int readyCount = 0;
       
   217                 //
       
   218                 foreach ( SymbolFileEngine engine in iFiles )
       
   219                 {
       
   220                     if ( engine.IsReady )
       
   221                     {
       
   222                         ++readyCount;
       
   223                     }
       
   224                 }
       
   225                 //
       
   226                 return ( readyCount == iFiles.Count );
       
   227             }
       
   228         }
       
   229 
       
   230         public override GenericSymbolCollection this[ int aIndex ]
       
   231         {
       
   232             get
       
   233             {
       
   234                 GenericSymbolCollection ret = null;
       
   235                 //
       
   236                 foreach ( SymbolFileEngine engine in iFiles )
       
   237                 {
       
   238                     int count = engine.NumberOfCollections;
       
   239                     if ( aIndex < count )
       
   240                     {
       
   241                         ret = engine[ aIndex ];
       
   242                         break;
       
   243                     }
       
   244                     else
       
   245                     {
       
   246                         aIndex -= count;
       
   247                     }
       
   248                 }
       
   249                 //
       
   250                 return ret;
       
   251             }
       
   252         }
       
   253 
       
   254         public override AddressRange Range
       
   255         {
       
   256             get
       
   257             {
       
   258                 AddressRange ret = new AddressRange();
       
   259                 //
       
   260                 foreach ( SymbolFileEngine engine in iFiles )
       
   261                 {
       
   262                     ret.Update( engine.Range );
       
   263                 }
       
   264                 //
       
   265                 return ret;
       
   266             }
       
   267         }
       
   268 
       
   269         internal override void UnloadUntagged()
       
   270         {
       
   271 
       
   272         }
       
   273         #endregion
       
   274 
       
   275         #region From IGenericSymbolCollectionStatisticsInterface
       
   276         public override int NumberOfCollections
       
   277         {
       
   278             get
       
   279             {
       
   280                 int count = 0;
       
   281                 //
       
   282                 foreach ( SymbolFileEngine engine in iFiles )
       
   283                 {
       
   284                     count += engine.NumberOfCollections;
       
   285                 }
       
   286                 //
       
   287                 return count;
       
   288             }
       
   289         }
       
   290         #endregion
       
   291 
       
   292         #region Event handlers
       
   293         private void SymbolEngine_ObserverProxy( SymbianUtils.AsyncReaderBase.TEvent aEvent, SymbianUtils.AsyncReaderBase aSender )
       
   294         {
       
   295             if ( Observer != null )
       
   296             {
       
   297                 Observer( aEvent, aSender );
       
   298             }
       
   299         }
       
   300         #endregion
       
   301 
       
   302         #region Internal methods
       
   303         private SymbolFileEngine EngineByFileName( string aFileName )
       
   304         {
       
   305             SymbolFileEngine ret = null;
       
   306             //
       
   307             foreach ( SymbolFileEngine engine in iFiles )
       
   308             {
       
   309                 if ( engine.SymbolFileName.ToLower() == aFileName.ToLower() )
       
   310                 {
       
   311                     ret = engine;
       
   312                     break;
       
   313                 }
       
   314             }
       
   315             //
       
   316             return ret;
       
   317         }
       
   318         #endregion
       
   319 
       
   320         #region Data members
       
   321         private readonly SymbolFileEngine.TActivationType iActivationType;
       
   322         private readonly bool iAllowNonRomSymbols;
       
   323         private List<SymbolFileEngine> iFiles = new List<SymbolFileEngine>();
       
   324         #endregion
       
   325     }
       
   326 }