crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianCodeLib/QueryAPI/CodeQueryAPI.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.Collections.Generic;
       
    20 using System.Text;
       
    21 using System.IO;
       
    22 using SymbianUtils;
       
    23 using SymbianUtils.Tracer;
       
    24 using SymbianUtils.FileTypes;
       
    25 using SymbianUtils.Range;
       
    26 using SymbianStructuresLib.Arm;
       
    27 using SymbianStructuresLib.Arm.Instructions;
       
    28 using SymbianStructuresLib.CodeSegments;
       
    29 using SymbianStructuresLib.Debug.Code;
       
    30 using SymbianStructuresLib.Debug.Common.FileName;
       
    31 using SymbianCodeLib.SourceManagement.Source;
       
    32 using SymbianCodeLib.Relocator;
       
    33 
       
    34 namespace SymbianCodeLib.QueryAPI
       
    35 {
       
    36     internal class CodeQueryAPI : IEnumerable<CodeCollection>
       
    37     {
       
    38         #region Constructors
       
    39         internal CodeQueryAPI( CodeRelocator aRelocator )
       
    40 		{
       
    41             iRelocator = aRelocator;
       
    42 		}
       
    43 		#endregion
       
    44 
       
    45         #region API
       
    46         public bool Contains( uint aAddress )
       
    47         {
       
    48             // First check with the relocated/activated symbol collections,
       
    49             // i.e. RAM-loaded code that has been fixed up.
       
    50             bool ret = iRelocator.CollectionList.Contains( aAddress );
       
    51             if ( ret == false )
       
    52             {
       
    53                 // Wasn't a relocated symbol collection, so search through
       
    54                 // all sources for ROM/XIP symbols that might match.
       
    55                 foreach ( CodeSource source in SourceManager )
       
    56                 {
       
    57                     if ( source.Contains( aAddress ) )
       
    58                     {
       
    59                         ret = true;
       
    60                         break;
       
    61                     }
       
    62                 }
       
    63             }
       
    64             //
       
    65             return ret;
       
    66         }
       
    67 
       
    68         public bool GetInstructions( uint aAddress, TArmInstructionSet aInstructionSet, int aCount, out IArmInstruction[] aInstructions )
       
    69         {
       
    70             // First check with the relocated/activated code collections,
       
    71             // i.e. RAM-loaded code that has been fixed up.
       
    72             bool ret = iRelocator.CollectionList.GetInstructions( aAddress, aInstructionSet, aCount, out aInstructions );
       
    73             if ( ret == false )
       
    74             {
       
    75                 foreach ( CodeSource source in SourceManager )
       
    76                 {
       
    77                     if ( source.Contains( aAddress ) )
       
    78                     {
       
    79                         ret = source.ProvideInstructions( aAddress, aInstructionSet, aCount, out aInstructions );
       
    80                         break;
       
    81                     }
       
    82                 }
       
    83             }
       
    84             //
       
    85             return ret;
       
    86         }
       
    87         #endregion
       
    88 
       
    89 		#region Properties
       
    90         public CodeCollection this[ CodeSegDefinition aCodeSeg ]
       
    91         {
       
    92             get
       
    93             {
       
    94                 CodeCollection ret = null;
       
    95                 CodeSourceAndCollection pair = SourceManager[ aCodeSeg ];
       
    96                 if ( pair != null )
       
    97                 {
       
    98                     ret = pair.Collection;
       
    99                 }
       
   100                 return ret;
       
   101             }
       
   102         }
       
   103 
       
   104         public CodeCollection this[ PlatformFileName aFileName ]
       
   105         {
       
   106             get
       
   107             {
       
   108                 CodeCollection ret = null;
       
   109                 //
       
   110                 foreach ( CodeSource source in SourceManager )
       
   111                 {
       
   112                     CodeCollection col = source[ aFileName ];
       
   113                     if ( col != null )
       
   114                     {
       
   115                         ret = col;
       
   116                         break;
       
   117                     }
       
   118                 }
       
   119                 //
       
   120                 return ret;
       
   121             }
       
   122         }
       
   123 		#endregion
       
   124 
       
   125         #region Internal methods
       
   126         internal CodeSourceManager SourceManager
       
   127         {
       
   128             get { return iRelocator.SourceManager; }
       
   129         }
       
   130         #endregion
       
   131 
       
   132         #region From IEnumerable<CodeCollection>
       
   133         public IEnumerator<CodeCollection> GetEnumerator()
       
   134         {
       
   135             // This gives us explicit activations
       
   136             CodeCollectionList list = iRelocator.CollectionList;
       
   137             foreach ( CodeCollection col in list )
       
   138             {
       
   139                 yield return col;
       
   140             }
       
   141 
       
   142             // Next we need fixed collections
       
   143             IEnumerable<CodeCollection> fixedCols = iRelocator.SourceManager.GetFixedCollectionEnumerator();
       
   144             foreach ( CodeCollection col in fixedCols )
       
   145             {
       
   146                 if ( col.IsFixed )
       
   147                 {
       
   148                     yield return col;
       
   149                 }
       
   150             }
       
   151         }
       
   152 
       
   153         System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
       
   154         {
       
   155             // This gives us explicit activations
       
   156             CodeCollectionList list = iRelocator.CollectionList;
       
   157             foreach ( CodeCollection col in list )
       
   158             {
       
   159                 yield return col;
       
   160             }
       
   161 
       
   162             // Next we need fixed collections
       
   163             IEnumerable<CodeCollection> fixedCols = iRelocator.SourceManager.GetFixedCollectionEnumerator();
       
   164             foreach ( CodeCollection col in fixedCols )
       
   165             {
       
   166                 if ( col.IsFixed )
       
   167                 {
       
   168                     yield return col;
       
   169                 }
       
   170             }
       
   171         }
       
   172         #endregion
       
   173 
       
   174         #region Data members
       
   175         private readonly CodeRelocator iRelocator;
       
   176         #endregion
       
   177     }
       
   178 }