crashanalysercmd/Libraries/Engine/CrashDebuggerLib/Parsers/State/Implementation/Stacks/StateThreadStacks.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 SymbianParserLib.Engine;
       
    22 using SymbianParserLib.BaseStructures;
       
    23 using CrashDebuggerLib.Structures.CodeSeg;
       
    24 using CrashDebuggerLib.Structures.Thread;
       
    25 using CrashDebuggerLib.Structures.Process;
       
    26 using CrashDebuggerLib.Structures.KernelObjects;
       
    27 using CrashDebuggerLib.Threading;
       
    28 using SymbianParserLib.Elements;
       
    29 using SymbianParserLib.Enums;
       
    30 
       
    31 namespace CrashDebuggerLib.Parsers.State.Implementation
       
    32 {
       
    33     internal class StateThreadStacks : State
       
    34     {
       
    35         #region Constructors
       
    36         public StateThreadStacks( CrashDebuggerParser aParser )
       
    37             : base( aParser )
       
    38         {
       
    39         }
       
    40         #endregion
       
    41 
       
    42         #region API
       
    43         public override void Prepare()
       
    44         {
       
    45             // First, we need to know which thread we're dealing with
       
    46             // so that means we must look for the thread info
       
    47             ParserParagraph para = new ParserParagraph( "STACK_THREAD_INFO" );
       
    48             //
       
    49             ParserLine l1 = ParserLine.NewSymFormat( "STACK DATA for thread at %8x" );
       
    50             l1.SetTargetMethod( this, "SetThreadAddress" );
       
    51             para.Add( l1 );
       
    52             ParserEngine.Add( para );
       
    53         }
       
    54 
       
    55         public override void Finalise()
       
    56         {
       
    57             if ( iCurrentThread != null )
       
    58             {
       
    59                 if ( iCurrentThread.OwningProcess != null )
       
    60                 {
       
    61                     iCurrentThread.OwningProcess.PrepareDebugView();
       
    62                 }
       
    63                 //
       
    64                 iCurrentThread.StackInfoUser.Data.BuildCallStackAsync();
       
    65                 iCurrentThread.StackInfoSupervisor.Data.BuildCallStackAsync();
       
    66             }
       
    67         }
       
    68         #endregion
       
    69 
       
    70         #region Properties
       
    71         #endregion
       
    72 
       
    73         #region Internal methods
       
    74         private void SetThreadAddress( uint aAddress )
       
    75         {
       
    76             // Look for the thread which we're about to process...
       
    77             iCurrentThread = CrashDebugger.ThreadByAddress( aAddress );
       
    78             if ( iCurrentThread != null )
       
    79             {
       
    80                 // Next we must start to process code segments for this
       
    81                 // thread. These lines contain additional information about
       
    82                 // the run address of the code segments, relative to the process.
       
    83                 ParserParagraph para = new ParserParagraph( "STACK_THREAD_INFO_CODESEGS" );
       
    84                 //
       
    85                 ParserLine l1 = ParserLine.NewSymFormat( "CodeSeg[%03d/%03d] @ %08x - %08X-%08X %S" );
       
    86                 l1.ElementComplete += new ParserElementBase.ElementCompleteHandler( CodeSegmentLineComplete );
       
    87                 //
       
    88                 para.Add( l1 );
       
    89                 ParserEngine.Add( para );
       
    90             }
       
    91         }
       
    92 
       
    93         void CodeSegmentLineComplete( ParserElementBase aElement )
       
    94         {
       
    95             System.Diagnostics.Debug.Assert( iCurrentThread != null );
       
    96             ParserLine line = (ParserLine) aElement;
       
    97             //
       
    98             int index = line[ 0 ].AsInt;
       
    99             int count = line[ 1 ].AsInt;
       
   100             uint codeSegAddress = line[ 2 ].AsUint;
       
   101             uint startAddress = line[ 3 ].AsUint;
       
   102             uint endAddress = line[ 4 ].AsUint;
       
   103             string fileName = line[ 5 ].AsString;
       
   104             //
       
   105             DProcess process = iCurrentThread.OwningProcess;
       
   106             if ( process != null )
       
   107             {
       
   108                 ProcessCodeSegCollection codeSegs = process.CodeSegments;
       
   109                 ProcessCodeSeg codeSeg = codeSegs[ codeSegAddress ];
       
   110                 //
       
   111                 if ( codeSeg == null )
       
   112                 {
       
   113                     // The code seg is not directly part of the process handle list
       
   114                     // but it is some how mapped into the process?
       
   115                     //
       
   116                     // Try looking up the underlying code seg entry details from
       
   117                     // the crash debugger data itself. It should be part of the code
       
   118                     // seg listing so this should always work.
       
   119                     codeSeg = new ProcessCodeSeg( CrashDebugger, codeSegAddress, 0 );
       
   120                     process.CodeSegments.Add( codeSeg );
       
   121                 }
       
   122                 //
       
   123                 codeSeg.ProcessLocalRunAddress = startAddress;
       
   124                 codeSeg.Size = ( endAddress - startAddress );
       
   125             }
       
   126             //
       
   127             int remaining = count - index;
       
   128             if ( remaining == 0 )
       
   129             {
       
   130                 // Queue up stack data...
       
   131                 iHelperStack.CreateStackParagraphs( ParserEngine, iCurrentThread );
       
   132             }
       
   133             else
       
   134             {
       
   135                 // So that we capture the next line
       
   136                 aElement.SetRepetitions( 1 );
       
   137             }
       
   138         }
       
   139         #endregion
       
   140 
       
   141         #region Data members
       
   142         private DThread iCurrentThread = null;
       
   143         private Helpers.HelperStack iHelperStack = new CrashDebuggerLib.Parsers.State.Implementation.Helpers.HelperStack();
       
   144         #endregion
       
   145     }
       
   146 }