crashanalysercmd/Libraries/Engine/CrashDebuggerLib/Parsers/State/Implementation/Helpers/HelperDProcess.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 SymbianParserLib.Elements;
       
    26 using SymbianParserLib.Enums;
       
    27 using SymbianParserLib.BaseStructures;
       
    28 
       
    29 namespace CrashDebuggerLib.Parsers.State.Implementation.Helpers
       
    30 {
       
    31     internal class HelperDProcess : HelperDObject
       
    32     {
       
    33         #region Constructors
       
    34         public HelperDProcess()
       
    35         {
       
    36         }
       
    37         #endregion
       
    38 
       
    39         #region API
       
    40         public void CreateMonitorProcess( ParserEngine aEngine, string aName, DProcess aProcess )
       
    41         {
       
    42             CreateMonitorProcess( aEngine, aName, aProcess, null );
       
    43         }
       
    44 
       
    45         public void CreateMonitorProcess( ParserEngine aEngine, string aName, DProcess aProcess, ParserElementBase.ElementCompleteHandler aLastFieldHandler )
       
    46         {
       
    47             ParserParagraph para0 = base.CreateMonitorObjectParagraph( aName, aProcess );
       
    48             aEngine.Add( para0 );
       
    49             ParserParagraph para1 = CreateMonitorProcessCommon( aName, aProcess );
       
    50             aEngine.Add( para1 );
       
    51             ParserParagraph para2 = CreateMonitorProcessCodeSegs( aName + "_CodeSegs", aProcess );
       
    52             aEngine.Add( para2 );
       
    53             ParserParagraph para3 = CreateMonitorProcessMemModelMultiple( aName + "_MemModel_Multiple", aProcess, aLastFieldHandler );
       
    54             aEngine.Add( para3 );
       
    55 
       
    56             // TODO: add support for older memory models?
       
    57         }
       
    58         #endregion
       
    59 
       
    60         #region Call-back methods
       
    61         public void AddCodeSegToProcess( ParserParagraph aParagraph, ParserFieldName aParameterName, uint aParameterValue )
       
    62         {
       
    63             System.Diagnostics.Debug.Assert( aParagraph.Tag is DProcess );
       
    64             DProcess process = (DProcess) aParagraph.Tag;
       
    65             ProcessCodeSegCollection codeSegs = process.CodeSegments;
       
    66             //
       
    67             if ( aParameterName == "lib" )
       
    68             {
       
    69                 int count = codeSegs.Count;
       
    70                 if ( count > 0 )
       
    71                 {
       
    72                     ProcessCodeSeg lastEntry = codeSegs[ count - 1 ];
       
    73                     lastEntry.LibraryAddress = aParameterValue;
       
    74                 }
       
    75             }
       
    76             else if ( aParameterName == "seg" )
       
    77             {
       
    78                 ProcessCodeSeg entry = new ProcessCodeSeg( process.CrashDebugger );
       
    79                 entry.CodeSegAddress = aParameterValue;
       
    80                 codeSegs.Add( entry );
       
    81             }
       
    82         }
       
    83 
       
    84         public void AddChunkToProcess( ParserParagraph aParagraph, ParserFieldName aParameterName, uint aParameterValue )
       
    85         {
       
    86             System.Diagnostics.Debug.Assert( aParagraph.Tag is DProcess );
       
    87             DProcess process = (DProcess) aParagraph.Tag;
       
    88             ProcessChunkCollection chunks = process.Chunks;
       
    89             //
       
    90             ProcessChunk chunk = new ProcessChunk( process.CrashDebugger, aParameterValue, 0 );
       
    91             chunks.Add( chunk );
       
    92         }
       
    93 
       
    94         public void SetChunkAccessCount( ParserParagraph aParagraph, ParserFieldName aParameterName, int aParameterValue )
       
    95         {
       
    96             System.Diagnostics.Debug.Assert( aParagraph.Tag is DProcess );
       
    97             DProcess process = (DProcess) aParagraph.Tag;
       
    98             ProcessChunkCollection chunks = process.Chunks;
       
    99             //
       
   100             int count = chunks.Count;
       
   101             if ( count > 0 )
       
   102             {
       
   103                 ProcessChunk lastEntry = chunks[ count - 1 ];
       
   104                 lastEntry.AccessCount = aParameterValue;
       
   105             }
       
   106         }
       
   107         #endregion
       
   108 
       
   109         #region Internal methods
       
   110         private ParserParagraph CreateMonitorProcessCommon( string aName, DProcess aProcess )
       
   111         {
       
   112             ParserParagraph para = new ParserParagraph( aName );
       
   113             //
       
   114             ParserLine l1 = ParserLine.NewSymFormat( "ExitInfo %d,%d,%lS\r\n" );
       
   115             l1.SetTargetProperties( aProcess.ExitInfo, "Type", "Reason", "Category" );
       
   116             //
       
   117             ParserLine l2 = ParserLine.NewSymFormat( "Flags %08x, Handles %08x, Attributes %08x\r\n" );
       
   118             l2.SetTargetProperties( aProcess, "Flags", "Handles", "Attributes" );
       
   119             //
       
   120             ParserLine l3 = ParserLine.NewSymFormat( "DataBssChunk %08x, CodeSeg %08x\r\n" );
       
   121             l3.SetTargetProperties( aProcess, "DataBssStackChunkAddress", "CodeSegAddress" );
       
   122             //
       
   123             ParserLine l4 = ParserLine.NewSymFormat( "DllLock %08x, Process Lock %08x SID %08x\r\n" );
       
   124             l4.SetTargetProperties( new object[] { aProcess.LockInfo, aProcess.LockInfo, aProcess }, "DllMutexAddress", "ProcessMutexAddress", "SID" );
       
   125             //
       
   126             ParserLine l5 = ParserLine.NewSymFormat( "TempCodeSeg %08x CodeSeg %08x Capability %08x %08x\r\n" );
       
   127             l5.SetTargetProperties( new object[] { aProcess, aProcess, aProcess.Capabilities, aProcess.Capabilities }, "TempCodeSegAddress", "CodeSegAddress", "HighDWord", "LowDWord" );
       
   128             //
       
   129             ParserLine l6 = ParserLine.NewSymFormat( "Id=%d" );
       
   130             l6.SetTargetProperties( aProcess, "Id" );
       
   131 
       
   132             para.Add( l1, l2, l3, l4, l5, l6 );
       
   133             return para;
       
   134         }
       
   135 
       
   136         private ParserParagraph CreateMonitorProcessCodeSegs( string aName, DProcess aProcess )
       
   137         {
       
   138             ParserParagraph para = new ParserParagraph( aName );
       
   139             para.Tag = aProcess;
       
   140 
       
   141             // Loop body - construct this first as we use it for the header line
       
   142             ParserLine l2 = ParserLine.NewSymFormat( "%2d: seg=%08x lib=%08x\r\n" );
       
   143             l2[ 0 ].SetTargetObject();
       
   144             l2.SetTargetMethod( this, "AddCodeSegToProcess" );
       
   145 
       
   146             // Loop header
       
   147             ParserLine l1 = ParserLine.NewSymFormat( "CodeSegs: Count=%d\r\n" );
       
   148             l1.SetTargetMethod( l2, "SetRepetitions" );
       
   149 
       
   150             para.Add( l1, l2 );
       
   151             return para;
       
   152         }
       
   153 
       
   154         private ParserParagraph CreateMonitorProcessMemModelMultiple( string aName, DProcess aProcess, ParserElementBase.ElementCompleteHandler aLastFieldHandler )
       
   155         {
       
   156             ParserParagraph para = new ParserParagraph( aName );
       
   157             para.Tag = aProcess;
       
   158             if ( aLastFieldHandler != null )
       
   159             {
       
   160                 para.ElementComplete += new ParserElementBase.ElementCompleteHandler( aLastFieldHandler );
       
   161             }
       
   162 
       
   163             // Misc
       
   164             ParserLine l0 = ParserLine.NewSymFormat( "OS ASID=%d, LPD=%08x, GPD=%08x\r\n" );
       
   165             l0.SetTargetProperties( aProcess, "OSASID", "LPD", "GPD" );
       
   166 
       
   167             // Loop body - construct this first as we use it for the header line
       
   168             ParserLine l2 = ParserLine.NewSymFormat( "%d: Chunk %08x, access count %d\r\n" );
       
   169             l2[ 0 ].SetTargetObject();
       
   170             l2[ 1 ].SetTargetMethod( this, "AddChunkToProcess" );
       
   171             l2[ 2 ].SetTargetMethod( this, "SetChunkAccessCount" );
       
   172 
       
   173             // Loop header
       
   174             ParserLine l1 = ParserLine.NewSymFormat( "ChunkCount=%d ChunkAlloc=%d\r\n" );
       
   175             l1[ 0 ].SetTargetMethod( l2, "SetRepetitions" );
       
   176 
       
   177             para.Add( l0, l1, l2 );
       
   178             return para;
       
   179         }
       
   180         #endregion
       
   181     }
       
   182 }