crashanalysercmd/Libraries/Engine/CrashDebuggerLib/Structures/Thread/DThread.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 CrashDebuggerLib.Structures.Common;
       
    22 using CrashDebuggerLib.Structures.KernelObjects;
       
    23 using CrashDebuggerLib.Structures.Process;
       
    24 using CrashDebuggerLib.Structures.NThread;
       
    25 using SymbianStructuresLib.Debug.Symbols;
       
    26 
       
    27 namespace CrashDebuggerLib.Structures.Thread
       
    28 {
       
    29     public class DThread : DObject
       
    30     {
       
    31         #region Enumerations
       
    32         [System.ComponentModel.TypeConverter( typeof( SymbianParserLib.TypeConverters.SymbianEnumConverter ) )]
       
    33         public enum TThreadState
       
    34         {
       
    35             EUnknown = -1,
       
    36             ECreated = 0,
       
    37             EDead,
       
    38             EReady,
       
    39             EWaitSemaphore,
       
    40             EWaitSemaphoreSuspended,
       
    41             EWaitMutex,
       
    42             EWaitMutexSuspended,
       
    43             EHoldMutexPending,
       
    44             EWaitCondVar,
       
    45             EWaitCondVarSuspended,
       
    46         }
       
    47 
       
    48         [Flags, System.ComponentModel.TypeConverter( typeof( SymbianParserLib.TypeConverters.SymbianEnumConverter ) )]
       
    49         public enum TThreadFlags
       
    50         {
       
    51             EThreadFlagNone                 = 0x00000000,
       
    52             EThreadFlagProcessCritical		= 0x00000001,	// thread panic panics process
       
    53             EThreadFlagProcessPermanent		= 0x00000002,	// thread exit of any kind causes process to exit (=main)
       
    54             EThreadFlagSystemCritical		= 0x00000004,	// thread panic reboots entire system
       
    55             EThreadFlagSystemPermanent		= 0x00000008,	// thread exit of any kind reboots entire system
       
    56             EThreadFlagOriginal				= 0x00000010,
       
    57             EThreadFlagLastChance			= 0x00000020,
       
    58             EThreadFlagRealtime				= 0x00000040,	// thread will be panicked when using some non-realtime functions
       
    59             EThreadFlagRealtimeTest			= 0x00000080	// non-realtime functions only warn rather than panic
       
    60         }
       
    61 
       
    62         public enum TThreadWaitType
       
    63         {
       
    64             EThreadWaitingUnknown = 0,
       
    65             EThreadWaitingReady,
       
    66             EThreadWaitingOnSemaphore,
       
    67             EThreadWaitingOnMutex,
       
    68             EThreadWaitingOnDfc,
       
    69             EThreadWaitingOnResumption,
       
    70             EThreadWaitingOnRequestSemaphore,
       
    71             EThreadWaitingOnRequestSemaphoreInsideSchedulerWaitLoop
       
    72         }
       
    73         #endregion
       
    74 
       
    75         #region Constructors
       
    76         public DThread( CrashDebuggerInfo aCrashDebugger )
       
    77             : base( aCrashDebugger, TObjectType.EThread )
       
    78         {
       
    79             iNThread = new CrashDebuggerLib.Structures.NThread.NThread( aCrashDebugger, this );
       
    80             iStackInfoSupervisor = new ThreadStackInfo( aCrashDebugger, this, ThreadStackInfo.TType.ETypeSupervisor );
       
    81             iStackInfoUser = new ThreadStackInfo( aCrashDebugger, this, ThreadStackInfo.TType.ETypeUser );
       
    82         }
       
    83         #endregion
       
    84 
       
    85         #region API
       
    86         #endregion
       
    87 
       
    88         #region Properties
       
    89         public TThreadState MState
       
    90         {
       
    91             get { return iState; }
       
    92             set { iState = value; }
       
    93         }
       
    94 
       
    95         public uint WaitObj
       
    96         {
       
    97             get { return iStateWaitObjectAddress; }
       
    98             set { iStateWaitObjectAddress = value; }
       
    99         }
       
   100 
       
   101         public TThreadFlags Flags
       
   102         {
       
   103             get { return iFlags; }
       
   104             set { iFlags = value; }
       
   105         }
       
   106 
       
   107         public uint Handles
       
   108         {
       
   109             get { return iHandles; }
       
   110             set { iHandles = value; }
       
   111         }
       
   112 
       
   113         public long Id
       
   114         {
       
   115             get { return iId; }
       
   116             set { iId = value; }
       
   117         }
       
   118 
       
   119         public ThreadAllocatorInfo AllocatorInfo
       
   120         {
       
   121             get { return iAllocatorInfo; }
       
   122         }
       
   123 
       
   124         public uint Frame
       
   125         {
       
   126             get { return iFrame; }
       
   127             set { iFrame = value; }
       
   128         }
       
   129 
       
   130         public ThreadPriorities Priorities
       
   131         {
       
   132             get { return iPriorities; }
       
   133         }
       
   134 
       
   135         public ExitInfo ExitInfo
       
   136         {
       
   137             get { return iExitInfo; }
       
   138         }
       
   139 
       
   140         public ThreadStackInfo StackInfoUser
       
   141         {
       
   142             get { return iStackInfoUser; }
       
   143         }
       
   144 
       
   145         public ThreadStackInfo StackInfoSupervisor
       
   146         {
       
   147             get { return iStackInfoSupervisor; }
       
   148         }
       
   149 
       
   150         public ThreadHandlers Handlers
       
   151         {
       
   152             get { return iHandlers; }
       
   153         }
       
   154 
       
   155         public ThreadTemporaries Temporaries
       
   156         {
       
   157             get { return iTemporaries; }
       
   158         }
       
   159 
       
   160         public uint IpcCount
       
   161         {
       
   162             get { return iIpcCount; }
       
   163             set { iIpcCount = value; }
       
   164         }
       
   165 
       
   166         public DProcess OwningProcess
       
   167         {
       
   168             get
       
   169             {
       
   170                 DProcess ret = null;
       
   171                 //
       
   172                 DObject owner = Owner;
       
   173                 if ( owner != null && owner is DProcess )
       
   174                 {
       
   175                     ret = (DProcess) owner;
       
   176                 }
       
   177                 //
       
   178                 return ret;
       
   179             }
       
   180         }
       
   181 
       
   182         public NThread.NThread NThread
       
   183         {
       
   184             get { return iNThread; }
       
   185         }
       
   186 
       
   187         public bool HasActiveScheduler
       
   188         {
       
   189             get
       
   190             {
       
   191                 return ( iHandlers.ActiveScheduler != 0 );
       
   192             }
       
   193         }
       
   194 
       
   195         public TThreadWaitType WaitType
       
   196         {
       
   197             get
       
   198             {
       
   199                 TThreadWaitType waitType = TThreadWaitType.EThreadWaitingUnknown;
       
   200                 //
       
   201                 if ( NThread.NState == CrashDebuggerLib.Structures.NThread.NThread.TNThreadState.EWaitDfc )
       
   202                 {
       
   203                     waitType = TThreadWaitType.EThreadWaitingOnDfc;
       
   204                 }
       
   205                 else if ( NThread.NState == CrashDebuggerLib.Structures.NThread.NThread.TNThreadState.EReady )
       
   206                 {
       
   207                     waitType = TThreadWaitType.EThreadWaitingReady;
       
   208                 }
       
   209                 else if ( NThread.NState == CrashDebuggerLib.Structures.NThread.NThread.TNThreadState.ESuspended )
       
   210                 {
       
   211                     waitType = TThreadWaitType.EThreadWaitingOnResumption;
       
   212                 }
       
   213                 else if ( NThread.NState == CrashDebuggerLib.Structures.NThread.NThread.TNThreadState.EBlocked )
       
   214                 {
       
   215                     bool blockdOnSemaphore = IsBlockedOnSemaphore;
       
   216                     if ( blockdOnSemaphore )
       
   217                     {
       
   218                         waitType = TThreadWaitType.EThreadWaitingOnSemaphore;
       
   219                     }
       
   220                 }
       
   221                 else if ( NThread.NState == CrashDebuggerLib.Structures.NThread.NThread.TNThreadState.EWaitFastSemaphore )
       
   222                 {
       
   223                     // Check that the fast semaphore is definitely the NThread's request semaphore.
       
   224                     uint nThreadRequestSemaphoreAddress = NThread.RequestSemaphoreAddress;
       
   225                     if ( NThread.WaitObj != 0 && NThread.WaitObj == nThreadRequestSemaphoreAddress )
       
   226                     {
       
   227                         CrashDebuggerLib.Structures.NThread.NThread.TWaitType nThreadWaitType = NThread.WaitType;
       
   228                         //
       
   229                         if ( nThreadWaitType == CrashDebuggerLib.Structures.NThread.NThread.TWaitType.EWaitTypeUserWaitForAnyRequest )
       
   230                         {
       
   231                             if ( HasActiveScheduler )
       
   232                             {
       
   233                                 waitType = TThreadWaitType.EThreadWaitingOnRequestSemaphoreInsideSchedulerWaitLoop;
       
   234                             }
       
   235                             else
       
   236                             {
       
   237                                 waitType = TThreadWaitType.EThreadWaitingOnRequestSemaphore;
       
   238                             }
       
   239                         }
       
   240                         else if ( nThreadWaitType == CrashDebuggerLib.Structures.NThread.NThread.TWaitType.EWaitTypeUserWaitForRequest )
       
   241                         {
       
   242                             waitType = TThreadWaitType.EThreadWaitingOnRequestSemaphore;
       
   243                         }
       
   244                     }
       
   245                 }
       
   246                 //
       
   247                 return waitType;
       
   248             }
       
   249         }
       
   250 
       
   251         public bool IsUserThread
       
   252         {
       
   253             get
       
   254             {
       
   255                 bool ret = false;
       
   256                 //
       
   257                 DProcess parent = OwningProcess;
       
   258                 if ( parent != null )
       
   259                 {
       
   260                     string name = parent.Name.ToLower();
       
   261                     ret = ( name != Platform.ProcessNames.KKernel.ToLower() );
       
   262                 }
       
   263                 //
       
   264                 return ret;
       
   265             }
       
   266         }
       
   267 
       
   268         public bool IsCurrent
       
   269         {
       
   270             get
       
   271             {
       
   272                 bool ret = CrashDebugger.IsCurrentThread( this );
       
   273                 return ret;
       
   274             }
       
   275         }
       
   276         #endregion
       
   277 
       
   278         #region Internal methods
       
   279         private bool IsBlockedOnSemaphore
       
   280         {
       
   281             get
       
   282             {
       
   283                 bool ret = false;
       
   284                 //
       
   285                 if ( NThread.NState == CrashDebuggerLib.Structures.NThread.NThread.TNThreadState.EBlocked )
       
   286                 {
       
   287                     Register.RegisterEntry linkReg = NThread.Registers[ "R14_USR" ];
       
   288                     if ( linkReg.Symbol != null )
       
   289                     {
       
   290                         string symbolText = linkReg.Symbol.Name;
       
   291                         if ( symbolText.Contains( "RSemaphore::Wait" ) || symbolText.Contains( "RCriticalSection::Wait" ) )
       
   292                         {
       
   293                             ret = true;
       
   294                         }
       
   295                         else if ( symbolText.Contains( "Exec::SemaphoreWait" ) )
       
   296                         {
       
   297                             ret = true;
       
   298                         }
       
   299                     }
       
   300                 }
       
   301                 //
       
   302                 return ret;
       
   303             }
       
   304         }
       
   305         #endregion
       
   306 
       
   307         #region Internal constants
       
   308         #endregion
       
   309 
       
   310         #region From DBase
       
   311         public override string ToClipboard()
       
   312         {
       
   313             StringBuilder ret = new StringBuilder();
       
   314             //
       
   315             ret.AppendLine( base.ToClipboard() );
       
   316             ret.AppendFormat( "MState: {0}, Id: {1}, ExitInfo: {2}" + System.Environment.NewLine, MState, Id, ExitInfo );
       
   317             ret.AppendLine( iNThread.ToClipboard() );
       
   318             ret.AppendLine( iStackInfoUser.ToClipboard() );
       
   319             ret.AppendLine( iStackInfoSupervisor.ToClipboard() );
       
   320             //
       
   321             return ret.ToString();
       
   322         }
       
   323         #endregion
       
   324 
       
   325         #region From System.Object
       
   326         public override string ToString()
       
   327         {
       
   328             return base.ToString();
       
   329         }
       
   330         #endregion
       
   331 
       
   332         #region Data members
       
   333         private readonly NThread.NThread iNThread;
       
   334         private readonly ThreadStackInfo iStackInfoSupervisor;
       
   335         private readonly ThreadStackInfo iStackInfoUser;
       
   336 
       
   337         private TThreadState iState = TThreadState.EUnknown;
       
   338         private TThreadFlags iFlags = TThreadFlags.EThreadFlagNone;
       
   339         
       
   340         private uint iStateWaitObjectAddress = 0;
       
   341         private uint iHandles = 0;
       
   342         private long iId = 0;
       
   343         private uint iFrame = 0;
       
   344         private uint iIpcCount = 0;
       
   345 
       
   346         private ThreadAllocatorInfo iAllocatorInfo = new ThreadAllocatorInfo();
       
   347         private ThreadPriorities iPriorities = new ThreadPriorities();
       
   348         private ExitInfo iExitInfo = new ExitInfo();
       
   349         private ThreadHandlers iHandlers = new ThreadHandlers();
       
   350         private ThreadTemporaries iTemporaries = new ThreadTemporaries();
       
   351         #endregion
       
   352     }
       
   353 }