|
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 * The class CCrashInfoCallStack is part of CrashAnalyser CrashInfoFile plugin. |
|
16 * It is a temporary container for thread call stack. |
|
17 * Call stack is stored in fully decoded form as lines of text |
|
18 * |
|
19 */ |
|
20 |
|
21 using System; |
|
22 using System.Collections.Generic; |
|
23 using System.Text; |
|
24 using CrashItemLib.Crash.Stacks; |
|
25 using CrashItemLib.Crash.Registers; |
|
26 using CrashItemLib.Crash.Symbols; |
|
27 using XmlFilePlugin.PluginImplementations.FileFormat; |
|
28 |
|
29 namespace XmlFilePlugin.FileFormat |
|
30 { |
|
31 class CXmlCallStack |
|
32 { |
|
33 |
|
34 #region Constructors |
|
35 public CXmlCallStack() |
|
36 { |
|
37 |
|
38 } |
|
39 #endregion |
|
40 |
|
41 |
|
42 |
|
43 public void Read(CIStack aStack) |
|
44 { |
|
45 foreach (CIStackEntry entry in aStack) |
|
46 { |
|
47 CCrashInfoCSItem csItem = new CCrashInfoCSItem(); |
|
48 if (entry.IsCurrentStackPointerEntry) |
|
49 { |
|
50 iStackPointerLocation = iCallStack.Count; |
|
51 csItem.iIsStackPointer = true; |
|
52 } |
|
53 |
|
54 CIRegister register = entry.Register; |
|
55 if (register != null) //entry is from registers |
|
56 { |
|
57 csItem.iIsRegisterEntry = true; |
|
58 if (register.Name == "PC") |
|
59 { |
|
60 csItem.iRegisterName = "Program counter"; |
|
61 } |
|
62 else if (register.Name == "LR") |
|
63 { |
|
64 csItem.iRegisterName = "Link register"; |
|
65 } |
|
66 else //other register |
|
67 { |
|
68 csItem.iRegisterName = register.Name; |
|
69 } |
|
70 } |
|
71 else //entry is from memory (normal case) |
|
72 { |
|
73 csItem.iMemoryAddress = entry.Address; |
|
74 } |
|
75 |
|
76 //Add data contained in the memory location |
|
77 csItem.iItemData = entry.Data; |
|
78 csItem.iItemDataString = entry.DataAsString; |
|
79 |
|
80 if (entry.Symbol != null) //add symbol if possible |
|
81 { |
|
82 csItem.iHasSymbol = true; |
|
83 csItem.iSymbolName = entry.Symbol.Symbol.Name; |
|
84 csItem.iSymbolOffset = entry.FunctionOffset; |
|
85 csItem.iSymbolObject = entry.Symbol.Symbol.Object; |
|
86 |
|
87 |
|
88 } |
|
89 // else symbol is not available |
|
90 |
|
91 iCallStack.Add(csItem); |
|
92 |
|
93 } |
|
94 |
|
95 } |
|
96 public void CleanStack() |
|
97 { |
|
98 //Clean elements far above stack pointer |
|
99 if (iStackPointerLocation != null) |
|
100 { |
|
101 int removeAmount = (int)iStackPointerLocation - XmlConsts.KMaxItemAboveSP; |
|
102 |
|
103 if (removeAmount > 0) |
|
104 { |
|
105 iCallStack.RemoveRange(0, removeAmount); |
|
106 } |
|
107 |
|
108 //Clean symbolless items far below stack pointer |
|
109 for (int i = (int)iStackPointerLocation + XmlConsts.KNonSymbolItemsAfterSP; i < iCallStack.Count; ) |
|
110 { |
|
111 if (!iCallStack[i].iHasSymbol) |
|
112 { |
|
113 iCallStack.RemoveAt(i); |
|
114 } |
|
115 else |
|
116 { |
|
117 ++i; |
|
118 } |
|
119 } |
|
120 } |
|
121 } |
|
122 |
|
123 |
|
124 public override string ToString() |
|
125 { |
|
126 MakeWritableStack(); |
|
127 |
|
128 System.Text.StringBuilder output = new System.Text.StringBuilder(); |
|
129 foreach (string line in iTextContent) |
|
130 { |
|
131 if (output.Length + line.Length + XmlConsts.Kxml_EOL.Length >= XmlConsts.KMaxStackSize) |
|
132 { |
|
133 break; |
|
134 } |
|
135 |
|
136 output.AppendLine(line); |
|
137 } |
|
138 return output.ToString(); |
|
139 |
|
140 } |
|
141 |
|
142 private void MakeWritableStack() |
|
143 { |
|
144 |
|
145 foreach (CCrashInfoCSItem csItem in iCallStack) |
|
146 { |
|
147 System.Text.StringBuilder line = new System.Text.StringBuilder(); |
|
148 if (csItem.iIsStackPointer) |
|
149 { |
|
150 line.Append("This is current stack pointer "); |
|
151 } |
|
152 |
|
153 |
|
154 if (csItem.iIsRegisterEntry) //entry is from registers |
|
155 { |
|
156 line.Append(csItem.iRegisterName + " "); |
|
157 } |
|
158 else //entry is from memory (normal case) |
|
159 { |
|
160 line.Append(csItem.iMemoryAddress.ToString("X").PadLeft(8, '0')); |
|
161 } |
|
162 |
|
163 line.Append(" " + csItem.iItemData.ToString("X").PadLeft(8, '0')); |
|
164 |
|
165 |
|
166 |
|
167 if (csItem.iHasSymbol) //symbol if available |
|
168 { |
|
169 line.Append(" " + csItem.iSymbolName); |
|
170 |
|
171 line.Append(" " + csItem.iSymbolOffset.ToString("X").PadLeft(4, '0')); |
|
172 |
|
173 line.Append(" " + csItem.iSymbolObject); |
|
174 } |
|
175 else //symbol is not available, print content in ascii (may contain some readable text) |
|
176 { |
|
177 line.Append(" " + csItem.iItemDataString); |
|
178 } |
|
179 iTextContent.Add(line.ToString()); |
|
180 |
|
181 } |
|
182 } |
|
183 |
|
184 #region Data Members |
|
185 |
|
186 |
|
187 private List<string> iTextContent = new List<string>(); |
|
188 |
|
189 private List<CCrashInfoCSItem> iCallStack = new List<CCrashInfoCSItem>(); |
|
190 private int? iStackPointerLocation = null; |
|
191 #endregion |
|
192 |
|
193 #region Nested Classes |
|
194 private class CCrashInfoCSItem |
|
195 { |
|
196 #region Constructors |
|
197 public CCrashInfoCSItem() |
|
198 { |
|
199 |
|
200 } |
|
201 #endregion |
|
202 |
|
203 #region Data Members |
|
204 |
|
205 public uint iMemoryAddress = 0; |
|
206 public uint iItemData = 0; |
|
207 public string iItemDataString = string.Empty; |
|
208 |
|
209 public bool iIsStackPointer = false; |
|
210 public bool iIsRegisterEntry = false; |
|
211 public string iRegisterName = string.Empty; |
|
212 |
|
213 public bool iHasSymbol = false; |
|
214 public string iSymbolName = string.Empty; |
|
215 public string iSymbolObject = string.Empty; |
|
216 public uint iSymbolOffset = 0; |
|
217 |
|
218 #endregion |
|
219 } |
|
220 |
|
221 #endregion |
|
222 |
|
223 } |
|
224 |
|
225 |
|
226 |
|
227 } |