crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianStructuresLib/CodeSegments/CodeSegDefinition.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.Collections.Generic;
       
    21 using SymbianUtils;
       
    22 using SymbianUtils.Range;
       
    23 using SymbianStructuresLib.MemoryModel;
       
    24 
       
    25 namespace SymbianStructuresLib.CodeSegments
       
    26 {
       
    27     public class CodeSegDefinition : AddressRange
       
    28 	{
       
    29         #region Enumerations
       
    30         [Flags]
       
    31         public enum TAttributes
       
    32         {
       
    33             EAttributeNone = 0,
       
    34             EAttributeXIP = 1,
       
    35             EAttributeRAM = 2,
       
    36         }
       
    37         #endregion
       
    38 
       
    39         #region Constructors
       
    40 		public CodeSegDefinition()
       
    41             : this( string.Empty )
       
    42 		{
       
    43 		}
       
    44 
       
    45 		public CodeSegDefinition( string aFileName )
       
    46             : this( aFileName, 0, 0 )
       
    47         {
       
    48 		}
       
    49 
       
    50         public CodeSegDefinition( string aFileName, uint aBase, uint aLimit )
       
    51             : base( aBase, aLimit )
       
    52         {
       
    53             iFileName = aFileName;
       
    54         }
       
    55         #endregion
       
    56 
       
    57         #region Properties
       
    58         public uint Checksum
       
    59         {
       
    60             get { return iChecksum; }
       
    61             set { iChecksum = value; }
       
    62         }
       
    63 
       
    64         public string FileName
       
    65         {
       
    66             get { return iFileName; }
       
    67             set { iFileName = value; }
       
    68         }
       
    69 
       
    70         public uint Base
       
    71         {
       
    72             get { return base.Min; }
       
    73             set { base.Min = value; }
       
    74         }
       
    75 
       
    76         public uint Limit
       
    77         {
       
    78             get { return base.Max; }
       
    79             set { base.Max = value; }
       
    80         }
       
    81 
       
    82         public TAttributes Attributes
       
    83         {
       
    84             get { return iAttributes; }
       
    85         }
       
    86 		#endregion
       
    87 
       
    88         #region From AddressRange
       
    89         protected override void OnChanged()
       
    90         {
       
    91             base.OnChanged();
       
    92             //
       
    93             UpdateAttributes();
       
    94         }
       
    95         #endregion
       
    96 
       
    97         #region From System.Object
       
    98 		public override string ToString()
       
    99 		{
       
   100             StringBuilder ret = new StringBuilder();
       
   101             //
       
   102             ret.Append( base.ToString() );
       
   103             ret.Append( " " );
       
   104             ret.Append( iFileName );
       
   105             //
       
   106             return ret.ToString();
       
   107 		}
       
   108 
       
   109         public override int GetHashCode()
       
   110         {
       
   111             return iFileName.ToUpper().GetHashCode();
       
   112         }
       
   113 
       
   114         public override bool Equals( object aObject )
       
   115         {
       
   116             bool ret = false;
       
   117             //
       
   118             if ( aObject is CodeSegDefinition )
       
   119             {
       
   120                 CodeSegDefinition other = (CodeSegDefinition) aObject;
       
   121                 //
       
   122                 string myName = this.FileName;
       
   123                 string otherName = other.FileName;
       
   124                 //
       
   125                 ret = string.Compare( myName, otherName, StringComparison.CurrentCultureIgnoreCase ) == 0;
       
   126             }
       
   127             else
       
   128             {
       
   129                 ret = base.Equals( aObject );
       
   130             }
       
   131             //
       
   132             return ret;
       
   133         }
       
   134         #endregion
       
   135 
       
   136         #region Internal methods
       
   137         private void UpdateAttributes()
       
   138         {
       
   139             // Remove XIP/RAM attrib before we work out the type...
       
   140             iAttributes &= ~TAttributes.EAttributeRAM;
       
   141             iAttributes &= ~TAttributes.EAttributeXIP;
       
   142 
       
   143             MemoryModel.TMemoryModelType type = MMUtilities.TypeByAddress( Base );
       
   144             if ( type != MemoryModel.TMemoryModelType.EMemoryModelUnknown )
       
   145             {
       
   146                 MemoryModel.TMemoryModelRegion region = MMUtilities.RegionByAddress( Base, type );
       
   147                 //
       
   148                 if ( region == MemoryModel.TMemoryModelRegion.EMemoryModelRegionROM )
       
   149                 {
       
   150                     iAttributes |= TAttributes.EAttributeXIP;
       
   151                 }
       
   152                 else if ( region == MemoryModel.TMemoryModelRegion.EMemoryModelRegionRAMLoadedCode )
       
   153                 {
       
   154                     iAttributes |= TAttributes.EAttributeRAM;
       
   155                 }
       
   156             }
       
   157         }
       
   158 		#endregion
       
   159 
       
   160 		#region Data members
       
   161         private string iFileName = string.Empty;
       
   162         private uint iChecksum = 0;
       
   163         private TAttributes iAttributes = TAttributes.EAttributeNone;
       
   164 		#endregion
       
   165 	}
       
   166 }