crashanalysercmd/Libraries/Engine/CrashDebuggerLib/Structures/Thread/ThreadStackData.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 SymbianUtils.Utilities;
       
    22 using CrashDebuggerLib.Structures.KernelObjects;
       
    23 using CrashDebuggerLib.Structures.Common;
       
    24 using CrashDebuggerLib.Structures.Process;
       
    25 using CrashDebuggerLib.Structures.CodeSeg;
       
    26 using CrashDebuggerLib.Structures.Register;
       
    27 using SymbianStackLib.Engine;
       
    28 using SymbianStackLib.Data.Output;
       
    29 using SymbianStructuresLib.CodeSegments;
       
    30 using SymbianStructuresLib.Debug.Symbols;
       
    31 using SymbianStructuresLib.Arm.Registers;
       
    32 using SymbianUtils.DataBuffer;
       
    33 using SymbianUtils.DataBuffer.Entry;
       
    34 using SymbianUtils.DataBuffer.Primer;
       
    35 
       
    36 namespace CrashDebuggerLib.Structures.Thread
       
    37 {
       
    38     public class ThreadStackData : CrashDebuggerAware
       
    39     {
       
    40         #region Constructors
       
    41         public ThreadStackData( CrashDebuggerInfo aCrashDebugger, ThreadStackInfo aInfo )
       
    42             : base( aCrashDebugger )
       
    43         {
       
    44             iInfo = aInfo;
       
    45             iStackBuilder = new ThreadStackBuilder( this);
       
    46         }
       
    47         #endregion
       
    48 
       
    49         #region API
       
    50         public void Add( uint aValue )
       
    51         {
       
    52             byte val = (byte) aValue;
       
    53             iDataSource.Add( val );
       
    54         }
       
    55 
       
    56         public void BuildCallStackSync()
       
    57         {
       
    58             if ( iStackBuilder.IsBusy )
       
    59             {
       
    60                 // Wait for it
       
    61                 while ( iStackBuilder.IsBusy )
       
    62                 {
       
    63                     System.Threading.Thread.Sleep( 100 );
       
    64                 }
       
    65             }
       
    66             else
       
    67             {
       
    68                 iStackBuilder.BuildSync();
       
    69             }
       
    70         }
       
    71 
       
    72         public void BuildCallStackAsync()
       
    73         {
       
    74             if ( iStackBuilder.IsBusy )
       
    75             {
       
    76                 throw new ArgumentException( "Stack builder is busy!" );
       
    77             }
       
    78 
       
    79             // Request call back when queue spot available. If it's the current
       
    80             // thread then we jump it to the start of the queue
       
    81             CrashDebugger.AsyncOperationManager.Queue( iStackBuilder, Info.Thread.IsCurrent );
       
    82         }
       
    83         #endregion
       
    84 
       
    85         #region String Conversion Support
       
    86         public string CallStackToString()
       
    87         {
       
    88             StringBuilder ret = new StringBuilder();
       
    89             //
       
    90             ret.Append( CallStackElements.ToString() );
       
    91             //
       
    92             return ret.ToString();
       
    93         }
       
    94         #endregion
       
    95 
       
    96         #region Properties
       
    97         public int Size
       
    98         {
       
    99             get { return iDataSource.Count; }
       
   100         }
       
   101 
       
   102         public StackOutputData CallStackElements
       
   103         {
       
   104             get
       
   105             {
       
   106                 if ( !iStackBuilder.CallStackConstructed )
       
   107                 {
       
   108                     BuildCallStackSync();
       
   109                 }
       
   110                 //
       
   111                 return iStackBuilder.CallStackElements;
       
   112             }
       
   113         }
       
   114         #endregion
       
   115 
       
   116         #region Internal methods
       
   117         internal void SetStartingAddress( uint aAddress )
       
   118         {
       
   119             if ( iDataSource.AddressOffset == 0 )
       
   120             {
       
   121                 iDataSource.AddressOffset = aAddress;
       
   122             }
       
   123         }
       
   124         
       
   125         internal DataBuffer Data
       
   126         {
       
   127             get { return iDataSource; }
       
   128         }
       
   129 
       
   130         internal ThreadStackInfo Info
       
   131         {
       
   132             get { return iInfo; }
       
   133         }
       
   134 
       
   135         internal DataBufferUint LastRawDataEntry
       
   136         {
       
   137             get
       
   138             {
       
   139                 if ( Size < 4 )
       
   140                 {
       
   141                     throw new ArgumentException();
       
   142                 }
       
   143                 //
       
   144                 DataBufferUint ret = null;
       
   145                 //
       
   146                 foreach ( DataBufferUint entry in iDataSource.GetUintEnumerator() )
       
   147                 {
       
   148                     // The enumerator works from bottom up, so just return the first one.
       
   149                     ret = entry;
       
   150                     break;
       
   151                 }
       
   152                 //
       
   153                 return ret;
       
   154             }
       
   155         }
       
   156         #endregion
       
   157 
       
   158         #region Internal constants
       
   159         #endregion
       
   160 
       
   161         #region From System.Object
       
   162         public override string ToString()
       
   163         {
       
   164             return base.ToString();
       
   165         }
       
   166         #endregion
       
   167 
       
   168         #region Data members
       
   169         private readonly ThreadStackInfo iInfo;
       
   170         private readonly ThreadStackBuilder iStackBuilder;
       
   171         private DataBuffer iDataSource = new DataBuffer();
       
   172         private StackOutputData iDataOutput = new StackOutputData();
       
   173         #endregion
       
   174     }
       
   175 }