|
1 /* |
|
2 * Copyright (c) 2010 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 package com.nokia.s60tools.crashanalyser.ui.editors; |
|
18 |
|
19 import java.util.List; |
|
20 import org.eclipse.jface.resource.FontRegistry; |
|
21 import org.eclipse.swt.SWT; |
|
22 import org.eclipse.swt.custom.SashForm; |
|
23 import org.eclipse.swt.events.SelectionEvent; |
|
24 import org.eclipse.swt.events.SelectionListener; |
|
25 import org.eclipse.swt.graphics.FontData; |
|
26 import org.eclipse.swt.layout.GridData; |
|
27 import org.eclipse.swt.layout.GridLayout; |
|
28 import org.eclipse.swt.widgets.*; |
|
29 import org.eclipse.swt.graphics.Color; |
|
30 import org.eclipse.ui.PlatformUI; |
|
31 |
|
32 import com.nokia.s60tools.crashanalyser.files.CrashFile; |
|
33 import com.nokia.s60tools.crashanalyser.files.SummaryFile; |
|
34 import com.nokia.s60tools.crashanalyser.resources.HelpContextIDs; |
|
35 import com.nokia.s60tools.crashanalyser.ui.viewers.CallStackTableViewer; |
|
36 import com.nokia.s60tools.crashanalyser.ui.views.MainView; |
|
37 import com.nokia.s60tools.crashanalyser.containers.Stack; |
|
38 import com.nokia.s60tools.crashanalyser.containers.StackEntry; |
|
39 import com.nokia.s60tools.crashanalyser.containers.Thread; |
|
40 |
|
41 public class CallStackPage implements SelectionListener { |
|
42 |
|
43 // call stack group UI items |
|
44 private Combo comboCallStack; |
|
45 private Label labelStackWarning; |
|
46 private Button buttonDecodeFile; |
|
47 private Table tableCallStack; |
|
48 private CallStackTableViewer tableViewerCallStack; |
|
49 private Button buttonAllStackEntries; |
|
50 private Button buttonSymbolStackEntries; |
|
51 |
|
52 private SummaryFile crashFile = null; |
|
53 private FontRegistry fontRegistry; |
|
54 private Thread selectedThread = null; |
|
55 |
|
56 /** |
|
57 * Creates the page |
|
58 * @param parent composite |
|
59 * @param file summary file |
|
60 * @return composite |
|
61 */ |
|
62 public Composite createPage(Composite parent, SummaryFile file) { |
|
63 crashFile = file; |
|
64 return doCreate(parent); |
|
65 } |
|
66 |
|
67 /** |
|
68 * Creates the page |
|
69 * @param parent composite |
|
70 * @return composite |
|
71 */ |
|
72 public Composite createPage(Composite parent) { |
|
73 return doCreate(parent); |
|
74 } |
|
75 |
|
76 public void update() { |
|
77 // AutoSizeCallStackTableCells(); |
|
78 } |
|
79 |
|
80 /** |
|
81 * Loads data from given file into UI elements. |
|
82 * @param file crash file |
|
83 */ |
|
84 public void setFile(CrashFile file) { |
|
85 if (file != null) { |
|
86 crashFile = file; |
|
87 initialCallStackTableLoad(); |
|
88 } |
|
89 } |
|
90 |
|
91 /** |
|
92 * Creates all UI elements to the page |
|
93 * @param parent |
|
94 * @return composite |
|
95 */ |
|
96 Composite doCreate(Composite parent) { |
|
97 GridLayout layout = new GridLayout(); |
|
98 layout.numColumns = 1; |
|
99 parent.setLayout(layout); |
|
100 parent.setLayoutData(new GridData(GridData.FILL_BOTH)); |
|
101 fontRegistry = new FontRegistry(Display.getCurrent()); |
|
102 fontRegistry.put("monospace", new FontData[]{new FontData("Courier", 8, SWT.NORMAL)}); |
|
103 SashForm sashFormMain = new SashForm(parent, SWT.VERTICAL); |
|
104 sashFormMain.setLayoutData(new GridData(GridData.FILL_BOTH)); |
|
105 createCallStackGroup(sashFormMain); |
|
106 |
|
107 setHelps(); |
|
108 |
|
109 return parent; |
|
110 } |
|
111 |
|
112 /** |
|
113 * Creates call stack group |
|
114 * @param parent |
|
115 */ |
|
116 |
|
117 void createCallStackGroup(Composite parent) { |
|
118 Group groupCallStack = new Group(parent, SWT.NONE); |
|
119 GridLayout layout = new GridLayout(); |
|
120 layout.numColumns = 3; |
|
121 groupCallStack.setLayout(layout); |
|
122 GridData groupGD = new GridData(GridData.FILL_BOTH); |
|
123 groupGD.horizontalSpan = 3; |
|
124 groupCallStack.setText("Call Stack"); |
|
125 groupCallStack.setLayoutData(groupGD); |
|
126 |
|
127 comboCallStack = new Combo(groupCallStack, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY); |
|
128 comboCallStack.addSelectionListener(this); |
|
129 |
|
130 labelStackWarning = new Label(groupCallStack, SWT.NONE); |
|
131 labelStackWarning.setText("(selected stack is build with heuristic algorithm)"); |
|
132 labelStackWarning.setVisible(false); |
|
133 |
|
134 buttonDecodeFile = new Button(groupCallStack, SWT.PUSH); |
|
135 buttonDecodeFile.setText("Decode"); |
|
136 buttonDecodeFile.setVisible(false); |
|
137 buttonDecodeFile.addSelectionListener(this); |
|
138 |
|
139 tableCallStack = new Table(groupCallStack, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION | |
|
140 SWT.V_SCROLL | SWT.H_SCROLL); |
|
141 tableCallStack.setHeaderVisible(true); |
|
142 tableCallStack.setFont(fontRegistry.get("monospace")); |
|
143 |
|
144 GridData tableGD = new GridData(GridData.FILL_BOTH); |
|
145 tableGD.horizontalSpan = 3; |
|
146 tableCallStack.setLayoutData(tableGD); |
|
147 |
|
148 GridData buttonGD = new GridData(GridData.FILL_HORIZONTAL); |
|
149 buttonGD.horizontalSpan = 3; |
|
150 |
|
151 buttonAllStackEntries = new Button(groupCallStack, SWT.RADIO); |
|
152 buttonAllStackEntries.setText("Show all stack entries"); |
|
153 buttonAllStackEntries.addSelectionListener(this); |
|
154 buttonAllStackEntries.setLayoutData(buttonGD); |
|
155 |
|
156 buttonSymbolStackEntries = new Button(groupCallStack, SWT.RADIO); |
|
157 buttonSymbolStackEntries.setText("Show stack entries which have associated symbols"); |
|
158 buttonSymbolStackEntries.addSelectionListener(this); |
|
159 buttonSymbolStackEntries.setLayoutData(buttonGD); |
|
160 buttonSymbolStackEntries.setSelection(true); |
|
161 |
|
162 tableViewerCallStack = new CallStackTableViewer(tableCallStack); |
|
163 |
|
164 initialCallStackTableLoad(); |
|
165 AutoSizeCallStackTableCells(); |
|
166 } |
|
167 |
|
168 /** |
|
169 * Packs columns in call stack table nicely |
|
170 */ |
|
171 void AutoSizeCallStackTableCells() { |
|
172 int tableWidth = tableCallStack.getBounds().width; |
|
173 tableCallStack.getColumn(CallStackTableViewer.COLUMN_ADDRESS).setWidth(80); |
|
174 tableCallStack.getColumn(CallStackTableViewer.COLUMN_VALUE).setWidth(80); |
|
175 tableCallStack.getColumn(CallStackTableViewer.COLUMN_OFFSET).setWidth(65); |
|
176 tableCallStack.getColumn(CallStackTableViewer.COLUMN_TEXT).setWidth(60); |
|
177 int space = tableWidth - 80 - 80 - 65 - 60 - 25; |
|
178 int object = space / 3; |
|
179 if (object < 70) |
|
180 object = 70; |
|
181 tableCallStack.getColumn(CallStackTableViewer.COLUMN_OBJECT).setWidth(object); |
|
182 tableCallStack.getColumn(CallStackTableViewer.COLUMN_SYMBOL).setWidth(object*2); |
|
183 } |
|
184 |
|
185 /** |
|
186 * Loads stacks to combo, selects the correct stack as |
|
187 * default set and then loads stack's data to table. |
|
188 */ |
|
189 void initialCallStackTableLoad() { |
|
190 if (crashFile == null) |
|
191 return; |
|
192 |
|
193 // int defaultSelectionIndex = 0; |
|
194 |
|
195 // show the data of crashed process |
|
196 com.nokia.s60tools.crashanalyser.containers.Process process = null; |
|
197 |
|
198 if (crashFile.getThread() != null) { |
|
199 process = crashFile.getProcessByThread(crashFile.getThread().getId()); |
|
200 } else { |
|
201 process = crashFile.getCrashedProcess(); |
|
202 } |
|
203 |
|
204 if (process != null) { |
|
205 // current UI support only one thread, so show the first thread of first process |
|
206 |
|
207 if (crashFile.getThread() != null) { |
|
208 // Show only thread information (no crash info) |
|
209 selectedThread = crashFile.getThread(); |
|
210 } else { |
|
211 selectedThread = crashFile.getCrashedThread(); |
|
212 } |
|
213 /* |
|
214 if (selectedThread != null) { |
|
215 List<RegisterSet> registerSets = selectedThread.getRegisters(); |
|
216 if (registerSets != null && !registerSets.isEmpty()) { |
|
217 // load all register sets to combo |
|
218 for (int i = 0; i < registerSets.size(); i++) { |
|
219 RegisterSet registerSet = registerSets.get(i); |
|
220 // default register to show is the one that contains CPSR register |
|
221 if (registerSet.containsCPSR()) |
|
222 defaultSelectionIndex = i; |
|
223 comboRegisters.add(registerSet.getName()); |
|
224 comboRegisters.setData(registerSet.getName(), registerSet); |
|
225 } |
|
226 } |
|
227 |
|
228 } |
|
229 */ |
|
230 } |
|
231 |
|
232 |
|
233 int selectedIndex = 0; |
|
234 if (selectedThread != null) { |
|
235 List<Stack> stacks = selectedThread.getStacks(); |
|
236 if (stacks != null && !stacks.isEmpty()) { |
|
237 // add all stacks into combo |
|
238 for (int i = 0; i < stacks.size(); i++) { |
|
239 Stack stack = stacks.get(i); |
|
240 // show stack which contains CPSR register as default |
|
241 if (stack.stackRegisterContainsCpsr()) |
|
242 selectedIndex = i; |
|
243 comboCallStack.add(stack.getStackType()); |
|
244 comboCallStack.setData(stack.getStackType(), stack); |
|
245 } |
|
246 } |
|
247 } |
|
248 |
|
249 List<Stack> standAloneStacks = crashFile.getStandAloneStacks(); |
|
250 if (standAloneStacks != null && !standAloneStacks.isEmpty()) { |
|
251 for (int i = 0; i < standAloneStacks.size(); i++) { |
|
252 Stack stack = standAloneStacks.get(i); |
|
253 if (stack.stackRegisterContainsCpsr()) |
|
254 selectedIndex = comboCallStack.getItemCount() + i; |
|
255 comboCallStack.add(stack.getStackType()); |
|
256 comboCallStack.setData(stack.getStackType(), stack); |
|
257 } |
|
258 } |
|
259 |
|
260 if (comboCallStack.getItemCount() > 0) { |
|
261 comboCallStack.select(selectedIndex); |
|
262 loadCallStackTable(true); |
|
263 } |
|
264 } |
|
265 |
|
266 /** |
|
267 * Loads call stack table according to which stack is |
|
268 * selected in combo. |
|
269 */ |
|
270 void loadCallStackTable(boolean autoSizeCells) { |
|
271 tableCallStack.removeAll(); |
|
272 labelStackWarning.setVisible(false); |
|
273 |
|
274 if (comboCallStack.getItemCount() < 1) |
|
275 return; |
|
276 |
|
277 try { |
|
278 Stack stack = (Stack)comboCallStack.getData(comboCallStack.getText()); |
|
279 boolean containsAccurate = stack.containsAccurateStackEntries(); |
|
280 labelStackWarning.setVisible(!containsAccurate); |
|
281 List<StackEntry> stackEntries = stack.getStackEntries(); |
|
282 if (stackEntries != null && !stackEntries.isEmpty()) { |
|
283 for (int i = 0; i < stackEntries.size(); i++) { |
|
284 StackEntry stackEntry = stackEntries.get(i); |
|
285 newStackTableItem(stackEntry, containsAccurate); |
|
286 } |
|
287 if (autoSizeCells) |
|
288 AutoSizeCallStackTableCells(); |
|
289 } |
|
290 |
|
291 // nothing in stack |
|
292 if (stackEntries == null || stackEntries.isEmpty()) { |
|
293 disableStack(); |
|
294 } |
|
295 |
|
296 } catch (Exception e) { |
|
297 e.printStackTrace(); |
|
298 } |
|
299 } |
|
300 |
|
301 /** |
|
302 * Disables stack UI elements |
|
303 */ |
|
304 void disableStack() { |
|
305 labelStackWarning.setVisible(true); |
|
306 labelStackWarning.setText("Symbols were not available while creating stack."); |
|
307 buttonDecodeFile.setVisible(true); |
|
308 comboCallStack.setEnabled(false); |
|
309 buttonAllStackEntries.setEnabled(false); |
|
310 buttonSymbolStackEntries.setEnabled(false); |
|
311 tableCallStack.setEnabled(false); |
|
312 } |
|
313 |
|
314 |
|
315 |
|
316 public void widgetDefaultSelected(SelectionEvent arg0) { |
|
317 // no implementation required |
|
318 } |
|
319 |
|
320 public void widgetSelected(SelectionEvent event) { |
|
321 // stack was changed in combo |
|
322 if (event.widget == comboCallStack) { |
|
323 loadCallStackTable(true); |
|
324 // stack radio button changes |
|
325 } else if (event.widget == buttonAllStackEntries || |
|
326 event.widget == buttonSymbolStackEntries) { |
|
327 loadCallStackTable(false); |
|
328 // decode button was pressed |
|
329 } else if (event.widget == buttonDecodeFile) { |
|
330 MainView mv = MainView.showAndReturnYourself(true); |
|
331 mv.decodeFile(crashFile); |
|
332 } |
|
333 } |
|
334 |
|
335 /** |
|
336 * Adds new stack table row. |
|
337 * @param stackEntry row data |
|
338 * @param stackContainsAccurateEntries affects row colorings |
|
339 */ |
|
340 void newStackTableItem(StackEntry stackEntry, boolean stackContainsAccurateEntries) { |
|
341 // if 'Show stack entries which have associated symbols' radio button is selected and |
|
342 // if stack contains accurate stack entries, and this stack entry is not accurate |
|
343 // don't add it to table (unless this stack entry is current stack pointer or register based) |
|
344 if (buttonSymbolStackEntries.getSelection() && |
|
345 stackContainsAccurateEntries && |
|
346 !stackEntry.accurate() && |
|
347 !stackEntry.currentStackPointer() && |
|
348 !stackEntry.registerBased()) { |
|
349 return; |
|
350 // if 'Show stack entries which have associated symbols' radio button is selected |
|
351 // if stack doesn't contain accurate stack entries, don't show current stack entry |
|
352 // if it doesn't have associated symbol (unless this stack entry is current stack pointer or register based) |
|
353 } else if (buttonSymbolStackEntries.getSelection() && |
|
354 !stackContainsAccurateEntries && |
|
355 "".equals(stackEntry.getSymbol()) && |
|
356 !stackEntry.currentStackPointer() && |
|
357 !stackEntry.registerBased()) |
|
358 return; |
|
359 |
|
360 TableItem item = new TableItem(tableCallStack, SWT.NONE); |
|
361 item.setText(new String[] {stackEntry.getAddress(), |
|
362 stackEntry.getSymbol(), |
|
363 stackEntry.getValue(), |
|
364 stackEntry.getOffset(), |
|
365 stackEntry.getObject(), |
|
366 stackEntry.getText()}); |
|
367 |
|
368 item.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
|
369 item.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK)); |
|
370 |
|
371 // item is current stack pointer FG black, BG light pink |
|
372 if (stackEntry.currentStackPointer()) { |
|
373 item.setBackground(new Color(Display.getCurrent(), 255, 182, 193)); // light pink |
|
374 // PC or LR |
|
375 } else if (stackEntry.registerBased()) { |
|
376 item.setBackground(new Color(Display.getCurrent(), 173, 216, 230)); // light blue |
|
377 // item is out of stack bound FG gray, BG white |
|
378 } else if (stackEntry.outsideStackBounds()) { |
|
379 item.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY)); |
|
380 // item has no symbols, FG black, BG white |
|
381 } else if ("".equals(stackEntry.getSymbol())) { |
|
382 } else |
|
383 // if stack contains accurate entries, show "ghost" entries as gray |
|
384 if (stackContainsAccurateEntries) { |
|
385 // color accurate stack entries black or blue |
|
386 if (stackEntry.accurate()) { |
|
387 // ram loaded code (instead of execute-in-place code) FG blue |
|
388 if (!stackEntry.xip()) { |
|
389 item.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_BLUE)); |
|
390 } |
|
391 // not accurate stack entry FG gray |
|
392 } else { |
|
393 item.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY)); |
|
394 } |
|
395 // stack isn't accurate, |
|
396 } else { |
|
397 // ram loaded code (instead of execute-in-place code) |
|
398 if (!stackEntry.xip()) { |
|
399 item.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_BLUE)); |
|
400 } |
|
401 } |
|
402 |
|
403 item.setData(stackEntry); |
|
404 } |
|
405 |
|
406 /** |
|
407 * Sets context sensitive help ids to UI elements |
|
408 */ |
|
409 void setHelps() { |
|
410 |
|
411 PlatformUI.getWorkbench().getHelpSystem().setHelp(tableCallStack, |
|
412 HelpContextIDs.CRASH_ANALYSER_HELP_CRASH_VISUALISER); |
|
413 PlatformUI.getWorkbench().getHelpSystem().setHelp(comboCallStack, |
|
414 HelpContextIDs.CRASH_ANALYSER_HELP_CRASH_VISUALISER); |
|
415 PlatformUI.getWorkbench().getHelpSystem().setHelp(buttonAllStackEntries, |
|
416 HelpContextIDs.CRASH_ANALYSER_HELP_CRASH_VISUALISER); |
|
417 PlatformUI.getWorkbench().getHelpSystem().setHelp(buttonDecodeFile, |
|
418 HelpContextIDs.CRASH_ANALYSER_HELP_CRASH_VISUALISER); |
|
419 PlatformUI.getWorkbench().getHelpSystem().setHelp(buttonSymbolStackEntries, |
|
420 HelpContextIDs.CRASH_ANALYSER_HELP_CRASH_VISUALISER); |
|
421 } |
|
422 |
|
423 } |