crashanalysercmd/Libraries/Engine/CrashItemLib/Crash/CodeSegs/CICodeSeg.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.Collections.Generic;
       
    20 using SymbianDebugLib.Engine;
       
    21 using SymbianDebugLib.PluginAPI.Types;
       
    22 using SymbianDebugLib.PluginAPI.Types.Symbol;
       
    23 using SymbianStructuresLib.Uids;
       
    24 using SymbianUtils.DataBuffer;
       
    25 using SymbianStructuresLib.CodeSegments;
       
    26 using SymbianStructuresLib.Debug.Symbols;
       
    27 using SymbianUtils;
       
    28 using SymbianUtils.Range;
       
    29 using CrashItemLib.Crash;
       
    30 using CrashItemLib.Crash.Base;
       
    31 using CrashItemLib.Crash.Messages;
       
    32 using CrashItemLib.Crash.Processes;
       
    33 using CrashItemLib.Crash.Symbols;
       
    34 
       
    35 namespace CrashItemLib.Crash.CodeSegs
       
    36 {
       
    37     public class CICodeSeg : CIElement
       
    38     {
       
    39         #region Constructors
       
    40         public CICodeSeg( CIProcess aProcess )
       
    41             : this( aProcess, new CodeSegDefinition() )
       
    42 		{
       
    43 		}
       
    44         
       
    45         public CICodeSeg( CIProcess aProcess, CodeSegDefinition aCodeSegDef )
       
    46             : base( aProcess.Container )
       
    47         {
       
    48             iOwningProcess = aProcess;
       
    49             iCodeSegDef = aCodeSegDef;
       
    50         }
       
    51         #endregion
       
    52 
       
    53         #region API
       
    54         public bool Contains( uint aAddress )
       
    55         {
       
    56             bool ret = Range.Contains( aAddress );
       
    57             return ret;
       
    58         }
       
    59 
       
    60         internal void Resolve( DbgEngineView aDebugEngineView )
       
    61         {
       
    62             base.Trace( "[CICodeSeg] Resolve() - START - this: {0}", this );
       
    63             ResetState();
       
    64 
       
    65             // Check whether we have a symbol already loaded for the code segment's base address
       
    66             uint baseAddress = this.Base;
       
    67             //
       
    68             SymbolCollection col = null;
       
    69             Symbol symbol = aDebugEngineView.Symbols.Lookup( baseAddress, out col );
       
    70             base.Trace( "[CICodeSeg] Resolve() - symbol: {0}, symbolCollection: {1}", symbol, col );
       
    71             //
       
    72             if ( symbol != null )
       
    73             {
       
    74                 // This must be valid if we found a symbol
       
    75                 System.Diagnostics.Debug.Assert( col != null );
       
    76             }
       
    77             else
       
    78             {
       
    79                 // Symbol engine is not aware of the code segment's base address, but we can check by name
       
    80                 // as well...
       
    81                 col = aDebugEngineView.Symbols[ iCodeSegDef ];
       
    82             }
       
    83 
       
    84             // Update state
       
    85             IsResolved = ( col != null );
       
    86             AssociatedSymbolCollection = col;
       
    87 
       
    88             base.Trace( "[CICodeSeg] Resolve() - END - this: {0}, resolved: {1}, iCodeSegDef.FileName: {2}", this, this.IsResolved, iCodeSegDef.FileName );
       
    89         }
       
    90         #endregion
       
    91 
       
    92         #region Properties
       
    93         public override string Name
       
    94         {
       
    95             get { return iCodeSegDef.FileName; }
       
    96             set 
       
    97             {
       
    98                 iCodeSegDef.FileName = value;
       
    99             }
       
   100         }
       
   101 
       
   102         public uint Base
       
   103         {
       
   104             get { return iCodeSegDef.Base; }
       
   105             set { iCodeSegDef.Base = value; }
       
   106         }
       
   107 
       
   108         public uint Limit
       
   109         {
       
   110             get { return iCodeSegDef.Limit; }
       
   111             set
       
   112             {
       
   113                 iCodeSegDef.Limit = value; 
       
   114             }
       
   115         }
       
   116 
       
   117         public uint Size
       
   118         {
       
   119             get 
       
   120             { 
       
   121                 // The address range contains all-inclusive values.
       
   122                 //
       
   123                 // E.g. a range of 0x00 -> 0x10 would include the values...:
       
   124                 //
       
   125                 //   0x00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 0A, 0B, 0C, 0D, 0E, 0F, 0x10
       
   126                 //
       
   127                 // ...and therefore AddressRange.Size would return 17.
       
   128                 //
       
   129                 // Symbian OS treats the range as non-inclusive, so the value is one too large.
       
   130                 // Hence we subtract one
       
   131                 uint ret = iCodeSegDef.Size - 1;
       
   132                 return ret;
       
   133             }
       
   134         }
       
   135 
       
   136         public uint Checksum
       
   137         {
       
   138             get { return iCodeSegDef.Checksum; }
       
   139             set { iCodeSegDef.Checksum = value; }
       
   140         }
       
   141 
       
   142         public bool IsResolved
       
   143         {
       
   144             get { return iIsResolved; }
       
   145             private set
       
   146             { 
       
   147                 iIsResolved = value;
       
   148                 base.Trace( "[CICodeSeg] Resolve() - this: {0}, resolved: {1}", this, iIsResolved );
       
   149             }
       
   150         }
       
   151 
       
   152         public bool IsMismatched
       
   153         {
       
   154             get { return MismatchAddress != KNoSymbolicMismatchAddress; }
       
   155         }
       
   156 
       
   157         public bool IsSpeculative
       
   158         {
       
   159             get { return !IsExplicit; }
       
   160         }
       
   161 
       
   162         public bool IsExplicit
       
   163         {
       
   164             get { return iIsExplicit; }
       
   165             internal set { iIsExplicit = value; }
       
   166         }
       
   167 
       
   168         public uint MismatchAddress
       
   169         {
       
   170             get { return iMismatchAddress; }
       
   171             private set { iMismatchAddress = value; }
       
   172         }
       
   173 
       
   174         public AddressRange Range
       
   175         {
       
   176             get
       
   177             {
       
   178                 // We do this so that calling Range.ToString() won't include a file name!
       
   179                 AddressRange ret = new AddressRange( iCodeSegDef );
       
   180                 return ret;
       
   181             }
       
   182         }
       
   183 
       
   184         public CIProcess OwningProcess
       
   185         {
       
   186             get 
       
   187             {
       
   188                 System.Diagnostics.Debug.Assert( iOwningProcess != null );
       
   189                 return iOwningProcess; 
       
   190             }
       
   191         }
       
   192 
       
   193         public SymbolCollection AssociatedSymbolCollection
       
   194         {
       
   195             get { return iAssociatedSymbolCollection; }
       
   196             private set
       
   197             {
       
   198                 iAssociatedSymbolCollection = value;
       
   199                 if ( iAssociatedSymbolCollection != null )
       
   200                 {
       
   201                     bool misMatch = ( iAssociatedSymbolCollection.BaseAddress != this.Base );
       
   202                     if ( misMatch )
       
   203                     {
       
   204                         MismatchAddress = iAssociatedSymbolCollection.BaseAddress;
       
   205                     }
       
   206                 }
       
   207             }
       
   208         }
       
   209         #endregion
       
   210 
       
   211         #region Operators
       
   212         public static implicit operator CodeSegDefinition( CICodeSeg aCodeSeg )
       
   213         {
       
   214             return aCodeSeg.iCodeSegDef;
       
   215         }
       
   216         #endregion
       
   217 
       
   218         #region Internal constants
       
   219         private const uint KNoSymbolicMismatchAddress = 0;
       
   220         #endregion
       
   221 
       
   222         #region Internal methods
       
   223         private void ResetState()
       
   224         {
       
   225             IsResolved = false;
       
   226             MismatchAddress = 0;
       
   227         }
       
   228 
       
   229         private Symbol BaseAddressSymbolAndCollection( DbgViewSymbol aSymbolView, out SymbolCollection aCollection )
       
   230         {
       
   231             Symbol ret = aSymbolView.Lookup( this.Base, out aCollection );
       
   232             return ret;
       
   233         }
       
   234         #endregion
       
   235 
       
   236         #region From CIElement
       
   237         internal override void OnFinalize( CIElementFinalizationParameters aParams )
       
   238         {
       
   239             try
       
   240             {
       
   241                 base.OnFinalize( aParams );
       
   242             }
       
   243             finally
       
   244             {
       
   245                 Resolve( aParams.DebugEngineView );
       
   246             }
       
   247         }
       
   248         #endregion
       
   249         
       
   250         #region From System.Object
       
   251         public override string ToString()
       
   252         {
       
   253             StringBuilder ret = new StringBuilder();
       
   254             ret.AppendFormat( "{0:x8}-{1:x8} {2}", this.Base, this.Limit, this.Name );
       
   255             return ret.ToString();
       
   256         }
       
   257         #endregion
       
   258 
       
   259         #region Data members
       
   260         private readonly CIProcess iOwningProcess;
       
   261         private bool iIsResolved = false;
       
   262         private bool iIsExplicit = false;
       
   263         private uint iMismatchAddress = KNoSymbolicMismatchAddress;
       
   264         private CodeSegDefinition iCodeSegDef = new CodeSegDefinition();
       
   265         private SymbolCollection iAssociatedSymbolCollection = null;
       
   266         #endregion
       
   267     }
       
   268 }