|
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 HelperDThread : HelperDObject |
|
33 { |
|
34 #region Constructors |
|
35 public HelperDThread() |
|
36 { |
|
37 } |
|
38 #endregion |
|
39 |
|
40 #region API |
|
41 public void CreateMonitorThread( ParserEngine aEngine, string aName, DThread aThread ) |
|
42 { |
|
43 CreateMonitorThread( aEngine, aName, aThread, null ); |
|
44 } |
|
45 |
|
46 public void CreateMonitorThread( ParserEngine aEngine, string aName, DThread aThread, ParserElementBase.ElementCompleteHandler aLastFieldHandler ) |
|
47 { |
|
48 // Create DObject paragraph |
|
49 ParserParagraph para0 = base.CreateMonitorObjectParagraph( aName, aThread ); |
|
50 aEngine.Add( para0 ); |
|
51 |
|
52 // Create MState paragraphs |
|
53 ParserParagraph para1 = new ParserParagraph( aName + "_MSTATE" ); |
|
54 para1.Tag = aThread; |
|
55 aEngine.Add( para1 ); |
|
56 CreateThreadMState( para1, DThread.TThreadState.ECreated, "CREATED", false ); |
|
57 CreateThreadMState( para1, DThread.TThreadState.EDead, "DEAD", false ); |
|
58 CreateThreadMState( para1, DThread.TThreadState.EReady, "READY", false ); |
|
59 CreateThreadMState( para1, DThread.TThreadState.EWaitSemaphore, "WAITSEM", true ); |
|
60 CreateThreadMState( para1, DThread.TThreadState.EWaitSemaphoreSuspended, "WAITSEMS", true ); |
|
61 CreateThreadMState( para1, DThread.TThreadState.EWaitMutex, "WAITMUTEX", true ); |
|
62 CreateThreadMState( para1, DThread.TThreadState.EWaitMutexSuspended, "WAITMUTXS", true ); |
|
63 CreateThreadMState( para1, DThread.TThreadState.EHoldMutexPending, "HOLDMUTXP", true ); |
|
64 CreateThreadMState( para1, DThread.TThreadState.EWaitCondVar, "WAITCONDVAR", true ); |
|
65 CreateThreadMState( para1, DThread.TThreadState.EWaitCondVarSuspended, "WAITCONDVRS", true ); |
|
66 CreateThreadMState( para1, DThread.TThreadState.EUnknown, "??", true ); |
|
67 |
|
68 // Create common thread paragraph |
|
69 ParserParagraph para2 = CreateThreadCommon( aName, aThread ); |
|
70 aEngine.Add( para2 ); |
|
71 |
|
72 // Create NThread paragraphs |
|
73 iHelper.CreateMonitorNThread( aEngine, aName + "_NTHREAD", aThread.NThread, aLastFieldHandler ); |
|
74 |
|
75 // TODO: add support for older memory models? |
|
76 } |
|
77 #endregion |
|
78 |
|
79 #region Call-back methods |
|
80 void ThreadMState_ElementComplete( ParserElementBase aElement ) |
|
81 { |
|
82 ParserLine line = (ParserLine) aElement; |
|
83 ParserParagraph paragraph = line.Paragraph; |
|
84 System.Diagnostics.Debug.Assert( paragraph.Tag is DThread ); |
|
85 DThread thread = (DThread) paragraph.Tag; |
|
86 DThread.TThreadState state = (DThread.TThreadState) line.Tag; |
|
87 thread.MState = state; |
|
88 } |
|
89 |
|
90 public void SetThreadMStateWaitObject( ParserParagraph aParagraph, ParserLine aLine, ParserFieldName aParameterName, uint aWaitObjectAddress ) |
|
91 { |
|
92 System.Diagnostics.Debug.Assert( aParagraph.Tag is DThread ); |
|
93 DThread thread = (DThread) aParagraph.Tag; |
|
94 thread.WaitObj = aWaitObjectAddress; |
|
95 } |
|
96 #endregion |
|
97 |
|
98 #region Internal methods |
|
99 private void CreateThreadMState( ParserParagraph aParagraph, DThread.TThreadState aState, string aMStateName, bool aCapturesWaitObject ) |
|
100 { |
|
101 StringBuilder format = new StringBuilder( "Thread MState" ); |
|
102 format.Append( " " + aMStateName ); |
|
103 // |
|
104 if ( aCapturesWaitObject ) |
|
105 { |
|
106 format.Append( " %8x" ); |
|
107 } |
|
108 // |
|
109 string finalFormat = format.ToString(); |
|
110 ParserLine l1 = null; |
|
111 // |
|
112 if ( aCapturesWaitObject ) |
|
113 { |
|
114 l1 = ParserLine.NewSymFormat( finalFormat ); |
|
115 } |
|
116 else |
|
117 { |
|
118 l1 = ParserLine.New( finalFormat ); |
|
119 } |
|
120 |
|
121 l1.Tag = aState; |
|
122 l1.ElementComplete += new ParserElementBase.ElementCompleteHandler( ThreadMState_ElementComplete ); |
|
123 // |
|
124 if ( aCapturesWaitObject ) |
|
125 { |
|
126 l1[ 0 ].SetTargetMethod( this, "SetThreadMStateWaitObject" ); |
|
127 } |
|
128 // |
|
129 aParagraph.Add( l1 ); |
|
130 } |
|
131 |
|
132 private ParserParagraph CreateThreadCommon( string aName, DThread aThread ) |
|
133 { |
|
134 ParserParagraph para = new ParserParagraph( aName ); |
|
135 // |
|
136 ParserLine l1 = ParserLine.NewSymFormat( "Default priority %d WaitLink Priority %d\r\n" ); |
|
137 l1.SetTargetProperties( aThread.Priorities, "Default", "WaitLink" ); |
|
138 // |
|
139 ParserLine l2 = ParserLine.NewSymFormat( "ExitInfo %d,%d,%lS\r\n" ); |
|
140 l2.SetTargetProperties( aThread.ExitInfo, "Type", "Reason", "Category" ); |
|
141 // |
|
142 ParserLine l3 = ParserLine.NewSymFormat( "Flags %08x, Handles %08x\r\n" ); |
|
143 l3.SetTargetProperties( aThread, "Flags", "Handles" ); |
|
144 // |
|
145 ParserLine l4 = ParserLine.NewSymFormat( "Supervisor stack base %08x size %x\r\n" ); |
|
146 l4.SetTargetProperties( aThread.StackInfoSupervisor, "BaseAddress", "Size" ); |
|
147 // |
|
148 ParserLine l5 = ParserLine.NewSymFormat( "User stack base %08x size %x\r\n" ); |
|
149 l5.SetTargetProperties( aThread.StackInfoUser, "BaseAddress", "Size" ); |
|
150 // |
|
151 ParserLine l6 = ParserLine.NewSymFormat( "Id=%d, Alctr=%08x, Created alctr=%08x, Frame=%08x\r\n" ); |
|
152 l6.SetTargetProperties( new object[] { aThread, aThread.AllocatorInfo, aThread.AllocatorInfo, aThread }, "Id", "Allocator", "CreatedAllocator", "Frame" ); |
|
153 // |
|
154 ParserLine l7 = ParserLine.NewSymFormat( "Trap handler=%08x, ActiveScheduler=%08x, Exception handler=%08x\r\n" ); |
|
155 l7.SetTargetProperties( aThread.Handlers, "TrapHandler", "ActiveScheduler", "ExceptionHandler" ); |
|
156 // |
|
157 ParserLine l8 = ParserLine.NewSymFormat( "TempObj=%08x TempAlloc=%08x IpcCount=%08x\r\n" ); |
|
158 l8.SetTargetProperties( new object[] { aThread.Temporaries, aThread.Temporaries, aThread }, "TempObj", "TempAlloc", "IpcCount" ); |
|
159 // |
|
160 para.Add( l1, l2, l3, l4, l5, l6, l7, l8 ); |
|
161 return para; |
|
162 } |
|
163 #endregion |
|
164 |
|
165 #region Data members |
|
166 private HelperNThread iHelper = new HelperNThread(); |
|
167 #endregion |
|
168 } |
|
169 } |