crashanalysercmd/Libraries/Engine/CrashDebuggerLib/Parsers/State/Implementation/Helpers/HelperStack.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 CrashDebuggerLib.Structures.KernelObjects;
       
    23 using CrashDebuggerLib.Structures.Process;
       
    24 using CrashDebuggerLib.Structures.CodeSeg;
       
    25 using CrashDebuggerLib.Structures.Thread;
       
    26 using SymbianParserLib.Elements;
       
    27 using SymbianParserLib.Enums;
       
    28 using SymbianParserLib.BaseStructures;
       
    29 
       
    30 namespace CrashDebuggerLib.Parsers.State.Implementation.Helpers
       
    31 {
       
    32     internal class HelperStack
       
    33     {
       
    34         #region Constructors
       
    35         public HelperStack()
       
    36         {
       
    37         }
       
    38         #endregion
       
    39 
       
    40         #region API
       
    41         public void CreateStackParagraphs( ParserEngine aEngine, DThread aThread )
       
    42         {
       
    43             ParserParagraph p1 = PrepareUserStack( aThread.StackInfoUser );
       
    44             ParserParagraph p2 = PrepareSupervisorStack( aThread.StackInfoSupervisor );
       
    45             //
       
    46             aEngine.Add( p1, p2 );
       
    47         }
       
    48         #endregion
       
    49 
       
    50         #region Internal constants
       
    51         private const string KParagraphUser = "STACK_USER";
       
    52         #endregion
       
    53 
       
    54         #region Call-back methods
       
    55         void NoUserStackCallBack( ParserElementBase aElement )
       
    56         {
       
    57             // Called back when a thread has no user stack - in which case, dump the
       
    58             // user-stack items as they will prevent us gathering the supervisor info.
       
    59             ParserLine line = (ParserLine) aElement;
       
    60             ParserParagraph para = line.Paragraph;
       
    61             //
       
    62             foreach ( ParserLine l in para )
       
    63             {
       
    64                 l.IsDisabled = true;
       
    65             }
       
    66         }
       
    67 
       
    68         void DisableUserStackParagraph( ParserElementBase aElement )
       
    69         {
       
    70             // Called back when the first supervisor stack item fires. We
       
    71             // must disable all items in the user-paragraph so that they don't
       
    72             // intercept things like the current stack pointer.
       
    73             ParserLine line = (ParserLine) aElement;
       
    74             ParserParagraph para = line.Paragraph;
       
    75             ParserEngine engine = (ParserEngine) para.Parent;
       
    76             //
       
    77             foreach ( ParserParagraph paragraph in engine )
       
    78             {
       
    79                 if ( paragraph.Name == KParagraphUser )
       
    80                 {
       
    81                     paragraph.IsDisabled = true;
       
    82                     break;
       
    83                 }
       
    84             }
       
    85         }
       
    86 
       
    87         void SetFirstStackBytesStartingAddress( ParserField aField, uint aValue )
       
    88         {
       
    89             ThreadStackInfo stackInfo = (ThreadStackInfo) aField.Tag;
       
    90             ThreadStackData stackData = stackInfo.Data;
       
    91             stackData.SetStartingAddress( aValue );
       
    92         }
       
    93         #endregion
       
    94 
       
    95         #region Internal methods
       
    96         private ParserParagraph PrepareUserStack( ThreadStackInfo aStackInfo )
       
    97         {
       
    98             ParserParagraph para = new ParserParagraph( KParagraphUser );
       
    99             //
       
   100             ParserLine l0 = ParserLine.New( "No user-mode stack" );
       
   101             l0.ElementComplete += new ParserElementBase.ElementCompleteHandler( NoUserStackCallBack );
       
   102             //
       
   103             ParserLine l1 = ParserLine.NewSymFormat( "User stack base at %08x, size == %x\r\n" );
       
   104             l1.SetTargetProperties( aStackInfo, "BaseAddress", "Size" );
       
   105             //
       
   106             ParserLine l2 = ParserLine.NewSymFormat( "Stack pointer == %08x\r\n" );
       
   107             l2.SetTargetProperties( aStackInfo, "StackPointer" );
       
   108             //
       
   109             // Not needed - ParserLine l3 = ParserLine.NewSymFormat( "Stack mapped at %08x\r\n" );
       
   110             //l3.SetTargetProperties( aStackInfo.Data, "MappedAddress" );
       
   111 
       
   112             // Collect the raw stack bytes
       
   113             ParserLine l4 = ParserLine.NewSymFormat( "%08x: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x" );
       
   114             l4.IsNeverEnding = true;
       
   115             l4.DisableWhenComplete = false;
       
   116             l4.SetTargetMethod( aStackInfo.Data, "Add" );
       
   117 
       
   118             // Record the starting address of the stack data
       
   119             l4[ 0 ].SetTargetMethod( this, "SetFirstStackBytesStartingAddress" );
       
   120             l4[ 0 ].Tag = aStackInfo;
       
   121             //
       
   122             para.Add( l0, l1, l2, l4 );
       
   123             return para;
       
   124         }
       
   125 
       
   126         private ParserParagraph PrepareSupervisorStack( ThreadStackInfo aStackInfo )
       
   127         {
       
   128             ParserParagraph para = new ParserParagraph( "STACK_SUPERVISOR" );
       
   129             //
       
   130             ParserLine l1 = ParserLine.NewSymFormat( "Supervisor stack base at %08x, size == %x\r\n" );
       
   131             l1.ElementComplete += new ParserElementBase.ElementCompleteHandler( DisableUserStackParagraph );
       
   132             l1.SetTargetProperties( aStackInfo, "BaseAddress", "Size" );
       
   133             //
       
   134             ParserLine l2 = ParserLine.NewSymFormat( "Stack pointer == %08x\r\n" );
       
   135             l2.SetTargetProperties( aStackInfo, "StackPointer" );
       
   136             
       
   137             // Collect the raw stack bytes
       
   138             ParserLine l3 = ParserLine.NewSymFormat( "%08x: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x" );
       
   139             l3.IsNeverEnding = true;
       
   140             l3.DisableWhenComplete = false;
       
   141             l3.SetTargetMethod( aStackInfo.Data, "Add" );
       
   142 
       
   143             // Record the starting address of the stack data
       
   144             l3[ 0 ].SetTargetMethod( this, "SetFirstStackBytesStartingAddress" );
       
   145             l3[ 0 ].Tag = aStackInfo;
       
   146             //
       
   147             para.Add( l1, l2, l3 );
       
   148             return para;
       
   149         }
       
   150         #endregion
       
   151 
       
   152         #region Data members
       
   153         #endregion
       
   154     }
       
   155 }