crashanalysercmd/Libraries/File Formats/Plugins/CrashXmlPlugin/FileFormat/Segment/Entries/Threads/CXmlThread.cs
changeset 0 818e61de6cd1
equal deleted inserted replaced
-1:000000000000 0:818e61de6cd1
       
     1 /*
       
     2 * Copyright (c) 2009 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 using System;
       
    18 using System.Text;
       
    19 using System.Collections.Generic;
       
    20 using CrashItemLib.Crash.Base;
       
    21 using CrashItemLib.Crash.Registers;
       
    22 using CrashItemLib.Crash.Threads;
       
    23 using CrashItemLib.Crash.Stacks;
       
    24 using CrashXmlPlugin.FileFormat.Node;
       
    25 
       
    26 namespace CrashXmlPlugin.FileFormat.Segment.Entries.Threads
       
    27 {
       
    28     internal class CXmlThread : CXmlNode
       
    29 	{
       
    30 		#region Constructors
       
    31         public CXmlThread( CIThread aThread )
       
    32             : base( SegConstants.Threads_Thread )
       
    33 		{
       
    34             iThread = aThread;
       
    35 		}
       
    36 		#endregion
       
    37 
       
    38         #region From CXmlNode
       
    39         protected override void XmlSerializeContent( CrashXmlPlugin.FileFormat.Document.CXmlDocumentSerializationParameters aParameters )
       
    40         {
       
    41             CXmlNode.WriteId( iThread, aParameters.Writer );
       
    42 
       
    43             aParameters.Writer.WriteElementString( SegConstants.CmnName, iThread.Name );
       
    44             aParameters.Writer.WriteElementString( SegConstants.Threads_Thread_FullName, iThread.FullName );
       
    45 
       
    46             // Parent process
       
    47             if ( iThread.OwningProcess != null )
       
    48             {
       
    49                 CXmlNode.WriteLink( iThread.OwningProcess.Id, SegConstants.Processes, aParameters.Writer );
       
    50             }
       
    51 
       
    52             // Thread priority
       
    53             if ( iThread.Priority != 0 )
       
    54             {
       
    55                 aParameters.Writer.WriteElementString( SegConstants.CmnPriority, iThread.Priority.ToString() );
       
    56             }
       
    57 
       
    58             // Write any messages
       
    59             CXmlSegBase.XmlSerializeMessages( aParameters, iThread );
       
    60         }
       
    61 
       
    62         protected override void XmlSerializeChildren( CrashXmlPlugin.FileFormat.Document.CXmlDocumentSerializationParameters aParameters )
       
    63         {
       
    64             // Exit info
       
    65             CXmlExitInfo xmlExitInfo = new CXmlExitInfo( iThread.ExitInfo );
       
    66             xmlExitInfo.XmlSerialize( aParameters );
       
    67 
       
    68             // Stacks
       
    69             XmlSerializeStacks( aParameters );
       
    70 
       
    71             // Registers
       
    72             XmlSerializeRegisters( aParameters );
       
    73         }
       
    74         #endregion
       
    75 
       
    76         #region Internal methods
       
    77         private void XmlSerializeRegisters( CrashXmlPlugin.FileFormat.Document.CXmlDocumentSerializationParameters aParameters )
       
    78         {
       
    79             // Must obtain the registers in advance to avoid creating an empty list.
       
    80             List<CIRegisterList> regs = new List<CIRegisterList>();
       
    81 
       
    82             // Find register lists
       
    83             CIElementList<CIRegisterListCollection> allRegs = iThread.ChildrenByType<CIRegisterListCollection>();
       
    84             foreach ( CIRegisterListCollection registerListCol in allRegs )
       
    85             {
       
    86                 foreach ( CIRegisterList registerList in registerListCol )
       
    87                 {
       
    88                     if ( registerList.Count > 0 )
       
    89                     {
       
    90                         regs.Add( registerList );
       
    91                     }
       
    92                 }
       
    93             }
       
    94 
       
    95             // Only write something if we have some entries
       
    96             if ( regs.Count > 0 )
       
    97             {
       
    98                 CXmlNode.WriteLinkListStart( aParameters.Writer, SegConstants.Registers );
       
    99                 foreach ( CIRegisterList registerList in regs )
       
   100                 {
       
   101                     CXmlNode.WriteLink( registerList.Id, SegConstants.Registers, aParameters.Writer );
       
   102                 }
       
   103                 CXmlNode.WriteLinkListEnd( aParameters.Writer );
       
   104             }
       
   105         }
       
   106 
       
   107         private void XmlSerializeStacks( CrashXmlPlugin.FileFormat.Document.CXmlDocumentSerializationParameters aParameters )
       
   108         {
       
   109             // Find stacks
       
   110             CIElementList<CIStack> stacks = iThread.ChildrenByType<CIStack>();
       
   111 
       
   112             // Only write something if we have some entries
       
   113             if ( stacks.Count > 0 )
       
   114             {
       
   115                 CXmlNode.WriteLinkListStart( aParameters.Writer, SegConstants.Stacks );
       
   116                 foreach ( CIStack item in stacks )
       
   117                 {
       
   118                     CXmlNode.WriteLink( item.Id, SegConstants.Stacks, aParameters.Writer );
       
   119                 }
       
   120                 CXmlNode.WriteLinkListEnd( aParameters.Writer );
       
   121             }
       
   122         }
       
   123         #endregion
       
   124 
       
   125         #region Data members
       
   126         private readonly CIThread iThread;
       
   127 		#endregion
       
   128 	}
       
   129 }