|
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 CrashDebuggerLib.Threading; |
|
22 using SymbianStructuresLib.Debug.Symbols; |
|
23 using SymbianStructuresLib.Arm.Registers; |
|
24 using SymbianStructuresLib.CodeSegments; |
|
25 using SymbianUtils.DataBuffer; |
|
26 using SymbianUtils.DataBuffer.Entry; |
|
27 using SymbianUtils.DataBuffer.Primer; |
|
28 using SymbianDebugLib.Engine; |
|
29 using SymbianUtils.Utilities; |
|
30 using CrashDebuggerLib.Structures.KernelObjects; |
|
31 using CrashDebuggerLib.Structures.Common; |
|
32 using CrashDebuggerLib.Structures.Process; |
|
33 using CrashDebuggerLib.Structures.CodeSeg; |
|
34 using CrashDebuggerLib.Structures.Register; |
|
35 using CrashDebuggerLib.Structures.Cpu; |
|
36 using SymbianStackLib.Engine; |
|
37 using SymbianStackLib.Data.Output; |
|
38 |
|
39 namespace CrashDebuggerLib.Structures.Thread |
|
40 { |
|
41 internal class ThreadStackBuilder : AsyncOperation |
|
42 { |
|
43 #region Constructors |
|
44 public ThreadStackBuilder( ThreadStackData aInfo ) |
|
45 { |
|
46 iInfo = aInfo; |
|
47 this.DoWork += new System.ComponentModel.DoWorkEventHandler( ThreadStackBuilder_DoWork ); |
|
48 } |
|
49 #endregion |
|
50 |
|
51 #region API |
|
52 public void BuildSync() |
|
53 { |
|
54 PrimeStackEngine(); |
|
55 iStackEngine.ReconstructSync(); |
|
56 } |
|
57 #endregion |
|
58 |
|
59 #region Properties |
|
60 public bool CallStackConstructed |
|
61 { |
|
62 get |
|
63 { |
|
64 return iIsReady; |
|
65 } |
|
66 } |
|
67 |
|
68 public StackOutputData CallStackElements |
|
69 { |
|
70 get |
|
71 { |
|
72 StackOutputData ret = new StackOutputData(); |
|
73 // |
|
74 if ( iStackEngine != null ) |
|
75 { |
|
76 ret = iStackEngine.DataOutput; |
|
77 } |
|
78 // |
|
79 return ret; |
|
80 } |
|
81 } |
|
82 #endregion |
|
83 |
|
84 #region Internal methods |
|
85 private void PrimeStackEngine() |
|
86 { |
|
87 // Create new engine (resets old data) |
|
88 iStackEngine = new StackEngine( iInfo.CrashDebugger.DebugEngine ); |
|
89 |
|
90 // Not yet ready |
|
91 iIsReady = false; |
|
92 |
|
93 // Get the data source |
|
94 DThread thread = iInfo.Info.Thread; |
|
95 string threadName = thread.Name.ToLower(); |
|
96 // |
|
97 DataBuffer dataSource = iInfo.Data; |
|
98 if ( dataSource.Count > 0 ) |
|
99 { |
|
100 // Prime stack engine with data & current stack pointer |
|
101 iStackEngine.Primer.Prime( dataSource ); |
|
102 iStackEngine.AddressInfo.Pointer = iInfo.Info.StackPointer; |
|
103 |
|
104 // Set us up so we know when the process finishes |
|
105 iStackEngine.EventHandler += new StackEngine.StackEngineEventHandler( StackEngine_EventHandler ); |
|
106 |
|
107 // Set up registers. First update them taking into account the |
|
108 // curent CPU regs. |
|
109 RegisterCollection.TType requiredType = RegisterCollection.TType.ETypeUser; |
|
110 if ( iInfo.Info.Type == ThreadStackInfo.TType.ETypeSupervisor ) |
|
111 { |
|
112 requiredType = RegisterCollection.TType.ETypeSupervisor; |
|
113 } |
|
114 |
|
115 RegisterCollection registers = thread.NThread.GetRegisters( requiredType ); |
|
116 iStackEngine.Registers = registers; |
|
117 |
|
118 // Get code segs |
|
119 DProcess process = thread.OwningProcess; |
|
120 if ( process != null ) |
|
121 { |
|
122 iStackEngine.CodeSegments = process.GetCodeSegDefinitions(); |
|
123 } |
|
124 } |
|
125 else |
|
126 { |
|
127 } |
|
128 } |
|
129 |
|
130 void ThreadStackBuilder_DoWork( object sender, System.ComponentModel.DoWorkEventArgs aArgs ) |
|
131 { |
|
132 PrimeStackEngine(); |
|
133 |
|
134 // Only reconstruct if we have some data |
|
135 if ( iStackEngine.DataSource.Count > 0 ) |
|
136 { |
|
137 iStackEngine.ReconstructSync(); |
|
138 } |
|
139 } |
|
140 #endregion |
|
141 |
|
142 #region Stack Engine event handler |
|
143 private void StackEngine_EventHandler( StackEngine.TEvent aEvent, StackEngine aEngine ) |
|
144 { |
|
145 if ( aEvent == StackEngine.TEvent.EStackBuildingComplete ) |
|
146 { |
|
147 iIsReady = true; |
|
148 } |
|
149 } |
|
150 #endregion |
|
151 |
|
152 #region Data members |
|
153 private readonly ThreadStackData iInfo; |
|
154 private StackEngine iStackEngine = null; |
|
155 private bool iIsReady = false; |
|
156 #endregion |
|
157 } |
|
158 } |