37
|
1 |
/*******************************************************************************
|
|
2 |
* Copyright (c) 2006, 2008 Wind River Systems and others.
|
|
3 |
* All rights reserved. This program and the accompanying materials
|
|
4 |
* are made available under the terms of the Eclipse Public License v1.0
|
|
5 |
* which accompanies this distribution, and is available at
|
|
6 |
* http://www.eclipse.org/legal/epl-v10.html
|
|
7 |
*
|
|
8 |
* Contributors:
|
|
9 |
* Wind River Systems - initial API and implementation
|
|
10 |
*******************************************************************************/
|
|
11 |
|
|
12 |
package org.eclipse.cdt.dsf.debug.ui.viewmodel.variable;
|
|
13 |
|
|
14 |
import java.util.ArrayList;
|
|
15 |
import java.util.Arrays;
|
|
16 |
import java.util.List;
|
|
17 |
import java.util.Map;
|
|
18 |
import java.util.concurrent.RejectedExecutionException;
|
|
19 |
|
|
20 |
import org.eclipse.cdt.core.IAddress;
|
|
21 |
import org.eclipse.cdt.debug.internal.ui.CDebugImages;
|
|
22 |
import org.eclipse.cdt.dsf.concurrent.ConfinedToDsfExecutor;
|
|
23 |
import org.eclipse.cdt.dsf.concurrent.CountingRequestMonitor;
|
|
24 |
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
|
|
25 |
import org.eclipse.cdt.dsf.concurrent.DsfExecutor;
|
|
26 |
import org.eclipse.cdt.dsf.concurrent.DsfRunnable;
|
|
27 |
import org.eclipse.cdt.dsf.concurrent.IDsfStatusConstants;
|
|
28 |
import org.eclipse.cdt.dsf.concurrent.ImmediateExecutor;
|
|
29 |
import org.eclipse.cdt.dsf.concurrent.MultiRequestMonitor;
|
|
30 |
import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
|
|
31 |
import org.eclipse.cdt.dsf.datamodel.DMContexts;
|
|
32 |
import org.eclipse.cdt.dsf.datamodel.IDMContext;
|
|
33 |
import org.eclipse.cdt.dsf.debug.service.IExpressions;
|
|
34 |
import org.eclipse.cdt.dsf.debug.service.IFormattedValues;
|
|
35 |
import org.eclipse.cdt.dsf.debug.service.IStack;
|
|
36 |
import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionChangedDMEvent;
|
|
37 |
import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMAddress;
|
|
38 |
import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMContext;
|
|
39 |
import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMData;
|
|
40 |
import org.eclipse.cdt.dsf.debug.service.IMemory.IMemoryChangedEvent;
|
|
41 |
import org.eclipse.cdt.dsf.debug.service.IRunControl.ISuspendedDMEvent;
|
|
42 |
import org.eclipse.cdt.dsf.debug.service.IStack.IFrameDMContext;
|
|
43 |
import org.eclipse.cdt.dsf.debug.service.IStack.IVariableDMContext;
|
|
44 |
import org.eclipse.cdt.dsf.debug.service.IStack.IVariableDMData;
|
|
45 |
import org.eclipse.cdt.dsf.debug.ui.viewmodel.ErrorLabelText;
|
|
46 |
import org.eclipse.cdt.dsf.debug.ui.viewmodel.IDebugVMConstants;
|
|
47 |
import org.eclipse.cdt.dsf.debug.ui.viewmodel.expression.AbstractExpressionVMNode;
|
|
48 |
import org.eclipse.cdt.dsf.debug.ui.viewmodel.expression.IExpressionUpdate;
|
|
49 |
import org.eclipse.cdt.dsf.debug.ui.viewmodel.numberformat.FormattedValueLabelText;
|
|
50 |
import org.eclipse.cdt.dsf.debug.ui.viewmodel.numberformat.FormattedValueVMUtil;
|
|
51 |
import org.eclipse.cdt.dsf.debug.ui.viewmodel.numberformat.IFormattedValueVMContext;
|
|
52 |
import org.eclipse.cdt.dsf.internal.ui.DsfUIPlugin;
|
|
53 |
import org.eclipse.cdt.dsf.service.DsfSession;
|
|
54 |
import org.eclipse.cdt.dsf.ui.concurrent.ViewerDataRequestMonitor;
|
|
55 |
import org.eclipse.cdt.dsf.ui.viewmodel.VMDelta;
|
|
56 |
import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.AbstractDMVMProvider;
|
|
57 |
import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.IDMVMContext;
|
|
58 |
import org.eclipse.cdt.dsf.ui.viewmodel.properties.IElementPropertiesProvider;
|
|
59 |
import org.eclipse.cdt.dsf.ui.viewmodel.properties.IPropertiesUpdate;
|
|
60 |
import org.eclipse.cdt.dsf.ui.viewmodel.properties.LabelAttribute;
|
|
61 |
import org.eclipse.cdt.dsf.ui.viewmodel.properties.LabelBackground;
|
|
62 |
import org.eclipse.cdt.dsf.ui.viewmodel.properties.LabelColumnInfo;
|
|
63 |
import org.eclipse.cdt.dsf.ui.viewmodel.properties.LabelForeground;
|
|
64 |
import org.eclipse.cdt.dsf.ui.viewmodel.properties.LabelImage;
|
|
65 |
import org.eclipse.cdt.dsf.ui.viewmodel.properties.LabelText;
|
|
66 |
import org.eclipse.cdt.dsf.ui.viewmodel.properties.PropertiesBasedLabelProvider;
|
|
67 |
import org.eclipse.cdt.dsf.ui.viewmodel.update.ICachingVMProvider;
|
|
68 |
import org.eclipse.cdt.dsf.ui.viewmodel.update.StaleDataLabelBackground;
|
|
69 |
import org.eclipse.cdt.dsf.ui.viewmodel.update.StaleDataLabelForeground;
|
|
70 |
import org.eclipse.core.runtime.CoreException;
|
|
71 |
import org.eclipse.core.runtime.IStatus;
|
|
72 |
import org.eclipse.core.runtime.Status;
|
|
73 |
import org.eclipse.debug.core.DebugPlugin;
|
|
74 |
import org.eclipse.debug.core.model.IExpression;
|
|
75 |
import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenUpdate;
|
|
76 |
import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementCompareRequest;
|
|
77 |
import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementEditor;
|
|
78 |
import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementLabelProvider;
|
|
79 |
import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementMementoProvider;
|
|
80 |
import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementMementoRequest;
|
|
81 |
import org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate;
|
|
82 |
import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta;
|
|
83 |
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
|
|
84 |
import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate;
|
|
85 |
import org.eclipse.debug.ui.DebugUITools;
|
|
86 |
import org.eclipse.debug.ui.IDebugModelPresentation;
|
|
87 |
import org.eclipse.debug.ui.IDebugUIConstants;
|
|
88 |
import org.eclipse.debug.ui.actions.IWatchExpressionFactoryAdapter2;
|
|
89 |
import org.eclipse.jface.util.PropertyChangeEvent;
|
|
90 |
import org.eclipse.jface.viewers.CellEditor;
|
|
91 |
import org.eclipse.jface.viewers.ICellModifier;
|
|
92 |
import org.eclipse.jface.viewers.TextCellEditor;
|
|
93 |
import org.eclipse.jface.viewers.TreePath;
|
|
94 |
import org.eclipse.swt.graphics.RGB;
|
|
95 |
import org.eclipse.swt.widgets.Composite;
|
|
96 |
import org.eclipse.ui.IMemento;
|
|
97 |
|
|
98 |
@SuppressWarnings("restriction")
|
|
99 |
public class VariableVMNode extends AbstractExpressionVMNode
|
|
100 |
implements IElementEditor, IElementLabelProvider, IElementPropertiesProvider, IElementMementoProvider
|
|
101 |
{
|
|
102 |
/**
|
|
103 |
* @since 2.0
|
|
104 |
*/
|
|
105 |
private static final String PROP_VARIABLE_TYPE_NAME = "variable_type_name"; //$NON-NLS-1$
|
|
106 |
|
|
107 |
/**
|
|
108 |
* @since 2.0
|
|
109 |
*/
|
|
110 |
private static final String PROP_VARIABLE_BASIC_TYPE = "variable_basic_type"; //$NON-NLS-1$
|
|
111 |
|
|
112 |
/**
|
|
113 |
* @since 2.0
|
|
114 |
*/
|
|
115 |
private static final String PROP_VARIABLE_ADDRESS = "variable_address"; //$NON-NLS-1$
|
|
116 |
|
|
117 |
/**
|
|
118 |
* @since 2.0
|
|
119 |
*/
|
|
120 |
private static final String PROP_VARIABLE_SHOW_TYPE_NAMES = "variable_show_type_names"; //$NON-NLS-1$
|
|
121 |
|
|
122 |
/**
|
|
123 |
* @since 2.0
|
|
124 |
*/
|
|
125 |
private static final String PROP_VARIABLE_ADDRESS_CHANGED = ICachingVMProvider.PROP_IS_CHANGED_PREFIX + PROP_VARIABLE_ADDRESS;
|
|
126 |
|
|
127 |
private final SyncVariableDataAccess fSyncVariableDataAccess;
|
|
128 |
|
|
129 |
/**
|
|
130 |
* The label provider delegate. This VM node will delegate label updates to this provider
|
|
131 |
* which can be created by sub-classes.
|
|
132 |
*
|
|
133 |
* @since 2.0
|
|
134 |
*/
|
|
135 |
private IElementLabelProvider fLabelProvider;
|
|
136 |
|
|
137 |
public class VariableExpressionVMC extends DMVMContext implements IFormattedValueVMContext {
|
|
138 |
|
|
139 |
private IExpression fExpression;
|
|
140 |
|
|
141 |
public VariableExpressionVMC(IDMContext dmc) {
|
|
142 |
super(dmc);
|
|
143 |
}
|
|
144 |
|
|
145 |
public void setExpression(IExpression expression) {
|
|
146 |
fExpression = expression;
|
|
147 |
}
|
|
148 |
|
|
149 |
@Override
|
|
150 |
@SuppressWarnings("unchecked")
|
|
151 |
public Object getAdapter(Class adapter) {
|
|
152 |
if (fExpression != null && adapter.isAssignableFrom(fExpression.getClass())) {
|
|
153 |
return fExpression;
|
|
154 |
} else if (adapter.isAssignableFrom(IWatchExpressionFactoryAdapter2.class)) {
|
|
155 |
return fVariableExpressionFactory;
|
|
156 |
} else {
|
|
157 |
return super.getAdapter(adapter);
|
|
158 |
}
|
|
159 |
}
|
|
160 |
|
|
161 |
@Override
|
|
162 |
public boolean equals(Object other) {
|
|
163 |
if (other instanceof VariableExpressionVMC && super.equals(other)) {
|
|
164 |
VariableExpressionVMC otherGroup = (VariableExpressionVMC)other;
|
|
165 |
return (otherGroup.fExpression == null && fExpression == null) ||
|
|
166 |
(otherGroup.fExpression != null && otherGroup.fExpression.equals(fExpression));
|
|
167 |
}
|
|
168 |
return false;
|
|
169 |
}
|
|
170 |
|
|
171 |
@Override
|
|
172 |
public int hashCode() {
|
|
173 |
return super.hashCode() + (fExpression != null ? fExpression.hashCode() : 0);
|
|
174 |
}
|
|
175 |
}
|
|
176 |
|
|
177 |
protected class VariableExpressionFactory implements IWatchExpressionFactoryAdapter2 {
|
|
178 |
|
|
179 |
public boolean canCreateWatchExpression(Object element) {
|
|
180 |
return element instanceof VariableExpressionVMC;
|
|
181 |
}
|
|
182 |
|
|
183 |
public String createWatchExpression(Object element) throws CoreException {
|
|
184 |
|
|
185 |
VariableExpressionVMC exprVmc = (VariableExpressionVMC) element;
|
|
186 |
|
|
187 |
IExpressionDMContext exprDmc = DMContexts.getAncestorOfType(exprVmc.getDMContext(), IExpressionDMContext.class);
|
|
188 |
if (exprDmc != null) {
|
|
189 |
return exprDmc.getExpression();
|
|
190 |
}
|
|
191 |
|
|
192 |
return null;
|
|
193 |
}
|
|
194 |
}
|
|
195 |
|
|
196 |
final protected VariableExpressionFactory fVariableExpressionFactory = new VariableExpressionFactory();
|
|
197 |
|
|
198 |
public VariableVMNode(AbstractDMVMProvider provider, DsfSession session,
|
|
199 |
SyncVariableDataAccess syncVariableDataAccess)
|
|
200 |
{
|
|
201 |
super(provider, session, IExpressions.IExpressionDMContext.class);
|
|
202 |
fSyncVariableDataAccess = syncVariableDataAccess;
|
|
203 |
fLabelProvider = createLabelProvider();
|
|
204 |
}
|
|
205 |
|
|
206 |
/**
|
|
207 |
* Creates the label provider delegate. This VM node will delegate label
|
|
208 |
* updates to this provider which can be created by sub-classes.
|
|
209 |
*
|
|
210 |
* @return Returns the label provider for this node.
|
|
211 |
*
|
|
212 |
* @since 2.0
|
|
213 |
*/
|
|
214 |
protected IElementLabelProvider createLabelProvider() {
|
|
215 |
PropertiesBasedLabelProvider provider = new PropertiesBasedLabelProvider();
|
|
216 |
|
|
217 |
//
|
|
218 |
// Create label image objects which are used in more than one column.
|
|
219 |
//
|
|
220 |
|
|
221 |
// Pointer image is used for variable and function pointers.
|
|
222 |
LabelImage pointerLabelImage = new LabelImage(CDebugImages.DESC_OBJS_VARIABLE_POINTER) {
|
|
223 |
{ setPropertyNames(new String[] { PROP_VARIABLE_BASIC_TYPE }); }
|
|
224 |
|
|
225 |
@Override
|
|
226 |
public boolean isEnabled(IStatus status, java.util.Map<String,Object> properties) {
|
|
227 |
String type = (String)properties.get(PROP_VARIABLE_BASIC_TYPE);
|
|
228 |
return IExpressionDMData.BasicType.pointer.name().equals(type) ||
|
|
229 |
IExpressionDMData.BasicType.function.name().equals(type);
|
|
230 |
};
|
|
231 |
};
|
|
232 |
|
|
233 |
// Aggregate image is used for array, struct, etc.
|
|
234 |
LabelImage aggregateLabelImage = new LabelImage(CDebugImages.DESC_OBJS_VARIABLE_AGGREGATE) {
|
|
235 |
{ setPropertyNames(new String[] { PROP_VARIABLE_BASIC_TYPE }); }
|
|
236 |
|
|
237 |
@Override
|
|
238 |
public boolean isEnabled(IStatus status, java.util.Map<String,Object> properties) {
|
|
239 |
String type = (String)properties.get(PROP_VARIABLE_BASIC_TYPE);
|
|
240 |
return IExpressionDMData.BasicType.array.name().equals(type) ||
|
|
241 |
IExpressionDMData.BasicType.composite.name().equals(type);
|
|
242 |
};
|
|
243 |
};
|
|
244 |
|
|
245 |
// Simple variable image is used for all other types, except when there is no type specified.
|
|
246 |
LabelImage simpleLabelImage = new LabelImage(CDebugImages.DESC_OBJS_VARIABLE_SIMPLE) {
|
|
247 |
{ setPropertyNames(new String[] { PROP_VARIABLE_BASIC_TYPE }); }
|
|
248 |
|
|
249 |
@Override
|
|
250 |
public boolean isEnabled(IStatus status, java.util.Map<String,Object> properties) {
|
|
251 |
String type = (String)properties.get(PROP_VARIABLE_BASIC_TYPE);
|
|
252 |
return type != null;
|
|
253 |
};
|
|
254 |
};
|
|
255 |
|
|
256 |
// The name column consists of the expression name. The name column image depends on the variable type.
|
|
257 |
provider.setColumnInfo(
|
|
258 |
IDebugVMConstants.COLUMN_ID__NAME,
|
|
259 |
new LabelColumnInfo(new LabelAttribute[] {
|
|
260 |
new LabelText(
|
|
261 |
MessagesForVariablesVM.VariableVMNode_Name_column__text_format,
|
|
262 |
new String[] { PROP_NAME }),
|
|
263 |
pointerLabelImage,
|
|
264 |
aggregateLabelImage,
|
|
265 |
simpleLabelImage,
|
|
266 |
new StaleDataLabelForeground(),
|
|
267 |
new VariableLabelFont(),
|
|
268 |
}));
|
|
269 |
|
|
270 |
// Expression column is visible only in the expressions view. It shows the expression string that the user
|
|
271 |
// entered. Expression column images are the same as for the name column.
|
|
272 |
provider.setColumnInfo(
|
|
273 |
IDebugVMConstants.COLUMN_ID__EXPRESSION,
|
|
274 |
new LabelColumnInfo(new LabelAttribute[] {
|
|
275 |
new LabelText(
|
|
276 |
MessagesForVariablesVM.VariableVMNode_Expression_column__text_format,
|
|
277 |
new String[] { PROP_ELEMENT_EXPRESSION }),
|
|
278 |
pointerLabelImage,
|
|
279 |
aggregateLabelImage,
|
|
280 |
simpleLabelImage,
|
|
281 |
new StaleDataLabelForeground(),
|
|
282 |
new VariableLabelFont(),
|
|
283 |
}));
|
|
284 |
|
|
285 |
// Type column only contains the type name.
|
|
286 |
provider.setColumnInfo(
|
|
287 |
IDebugVMConstants.COLUMN_ID__TYPE,
|
|
288 |
new LabelColumnInfo(new LabelAttribute[] {
|
|
289 |
new LabelText(
|
|
290 |
MessagesForVariablesVM.VariableVMNode_Type_column__text_format,
|
|
291 |
new String[] { PROP_VARIABLE_TYPE_NAME }),
|
|
292 |
new LabelText( MessagesForVariablesVM.VariableVMNode_Type_column__Error__text_format, new String[] {}),
|
|
293 |
new StaleDataLabelForeground(),
|
|
294 |
new VariableLabelFont(),
|
|
295 |
}));
|
|
296 |
|
|
297 |
// Value column is more complicated:
|
|
298 |
// - If a STRING value format is supported. Then the value label consists of the active format label followed
|
|
299 |
// by the string format.
|
|
300 |
// - If the STRIGN value format is not supported. Then only show the active value format. The GDB reference
|
|
301 |
// implementation currently does not support the string format, but by default it does append extra
|
|
302 |
// information to the value label itself.
|
|
303 |
//
|
|
304 |
// In case of error, show the error message in the value column (instead of the usual "...". This is needed
|
|
305 |
// for the expressions view, where an invalid expression entered by the user is a normal use case.
|
|
306 |
//
|
|
307 |
// For changed value high-lighting check both the string value and the value in the active format. But,
|
|
308 |
// ignore the active format value change if the format itself has changed.
|
|
309 |
provider.setColumnInfo(
|
|
310 |
IDebugVMConstants.COLUMN_ID__VALUE,
|
|
311 |
new LabelColumnInfo(new LabelAttribute[] {
|
|
312 |
new FormattedValueLabelText(
|
|
313 |
MessagesForVariablesVM.VariableVMNode_Value_column__text_format,
|
|
314 |
new String[] {
|
|
315 |
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT_VALUE,
|
|
316 |
FormattedValueVMUtil.getPropertyForFormatId(IFormattedValues.STRING_FORMAT),
|
|
317 |
IDebugVMConstants.PROP_FORMATTED_VALUE_AVAILABLE_FORMATS})
|
|
318 |
{
|
|
319 |
@Override
|
|
320 |
public boolean isEnabled(IStatus status, Map<String, Object> properties) {
|
|
321 |
String[] formatIds =
|
|
322 |
(String[])properties.get(IDebugVMConstants.PROP_FORMATTED_VALUE_AVAILABLE_FORMATS);
|
|
323 |
String activeFormat = (String)properties.get(IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT);
|
|
324 |
return
|
|
325 |
!IFormattedValues.STRING_FORMAT.equals(activeFormat) &&
|
|
326 |
formatIds != null &&
|
|
327 |
Arrays.asList(formatIds).contains(IFormattedValues.STRING_FORMAT) &&
|
|
328 |
super.isEnabled(status, properties);
|
|
329 |
}
|
|
330 |
},
|
|
331 |
new FormattedValueLabelText(),
|
|
332 |
new ErrorLabelText(),
|
|
333 |
new LabelForeground(new RGB(255, 0, 0)) // TODO: replace with preference error color
|
|
334 |
{
|
|
335 |
{ setPropertyNames(new String[] { PROP_NAME }); }
|
|
336 |
|
|
337 |
@Override
|
|
338 |
public boolean isEnabled(IStatus status, java.util.Map<String,Object> properties) {
|
|
339 |
return !status.isOK();
|
|
340 |
}
|
|
341 |
},
|
|
342 |
//
|
|
343 |
new LabelBackground(
|
|
344 |
DebugUITools.getPreferenceColor(IDebugUIConstants.PREF_CHANGED_VALUE_BACKGROUND).getRGB())
|
|
345 |
{
|
|
346 |
{
|
|
347 |
setPropertyNames(new String[] {
|
|
348 |
FormattedValueVMUtil.getPropertyForFormatId(IFormattedValues.STRING_FORMAT),
|
|
349 |
ICachingVMProvider.PROP_IS_CHANGED_PREFIX + FormattedValueVMUtil.getPropertyForFormatId(IFormattedValues.STRING_FORMAT),
|
|
350 |
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT_VALUE,
|
|
351 |
ICachingVMProvider.PROP_IS_CHANGED_PREFIX + IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT_VALUE,
|
|
352 |
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT,
|
|
353 |
ICachingVMProvider.PROP_IS_CHANGED_PREFIX + IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT});
|
|
354 |
}
|
|
355 |
|
|
356 |
@Override
|
|
357 |
public boolean isEnabled(IStatus status, java.util.Map<String,Object> properties) {
|
|
358 |
Boolean activeFormatChanged = (Boolean)properties.get(
|
|
359 |
ICachingVMProvider.PROP_IS_CHANGED_PREFIX + IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT);
|
|
360 |
Boolean activeChanged = (Boolean)properties.get(
|
|
361 |
ICachingVMProvider.PROP_IS_CHANGED_PREFIX + IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT_VALUE);
|
|
362 |
Boolean stringChanged = (Boolean)properties.get(
|
|
363 |
ICachingVMProvider.PROP_IS_CHANGED_PREFIX + FormattedValueVMUtil.getPropertyForFormatId(IFormattedValues.STRING_FORMAT));
|
|
364 |
return Boolean.TRUE.equals(stringChanged) ||
|
|
365 |
( Boolean.TRUE.equals(activeChanged) && !Boolean.TRUE.equals(activeFormatChanged));
|
|
366 |
};
|
|
367 |
},
|
|
368 |
new StaleDataLabelForeground(),
|
|
369 |
new VariableLabelFont(),
|
|
370 |
}));
|
|
371 |
|
|
372 |
// Address column shows the variable's address. It is highlighted with the change background color when the
|
|
373 |
// address value changes.
|
|
374 |
provider.setColumnInfo(
|
|
375 |
IDebugVMConstants.COLUMN_ID__ADDRESS,
|
|
376 |
new LabelColumnInfo(new LabelAttribute[] {
|
|
377 |
new LabelText(
|
|
378 |
MessagesForVariablesVM.VariableVMNode_Address_column__text_format,
|
|
379 |
new String[] { PROP_VARIABLE_ADDRESS }),
|
|
380 |
new LabelText(MessagesForVariablesVM.VariableVMNode_Address_column__Error__text_format, new String[] {}),
|
|
381 |
new LabelBackground(
|
|
382 |
DebugUITools.getPreferenceColor(IDebugUIConstants.PREF_CHANGED_VALUE_BACKGROUND).getRGB())
|
|
383 |
{
|
|
384 |
{ setPropertyNames(new String[] { PROP_VARIABLE_ADDRESS, PROP_VARIABLE_ADDRESS_CHANGED}); }
|
|
385 |
|
|
386 |
@Override
|
|
387 |
public boolean isEnabled(IStatus status, java.util.Map<String,Object> properties) {
|
|
388 |
Boolean changed = (Boolean)properties.get(PROP_VARIABLE_ADDRESS_CHANGED);
|
|
389 |
return Boolean.TRUE.equals(changed);
|
|
390 |
};
|
|
391 |
},
|
|
392 |
new StaleDataLabelForeground(),
|
|
393 |
new VariableLabelFont(),
|
|
394 |
}));
|
|
395 |
|
|
396 |
// Description column is shown in the expression view, but is not supported for variables.
|
|
397 |
provider.setColumnInfo(
|
|
398 |
IDebugVMConstants.COLUMN_ID__DESCRIPTION,
|
|
399 |
|
|
400 |
new LabelColumnInfo(new LabelAttribute[] {
|
|
401 |
new LabelText(MessagesForVariablesVM.VariableVMNode_Description_column__text_format, new String[] {}),
|
|
402 |
new VariableLabelFont(),
|
|
403 |
}));
|
|
404 |
|
|
405 |
// Configure the case where there are no columns visible. It basically combines the name and the value columns only.
|
|
406 |
provider.setColumnInfo(
|
|
407 |
PropertiesBasedLabelProvider.ID_COLUMN_NO_COLUMNS,
|
|
408 |
new LabelColumnInfo(new LabelAttribute[] {
|
|
409 |
new FormattedValueLabelText(
|
|
410 |
MessagesForVariablesVM.VariableVMNode_NoColumns_column__text_format,
|
|
411 |
new String[] {
|
|
412 |
PROP_NAME,
|
|
413 |
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT_VALUE,
|
|
414 |
FormattedValueVMUtil.getPropertyForFormatId(IFormattedValues.STRING_FORMAT),
|
|
415 |
IDebugVMConstants.PROP_FORMATTED_VALUE_AVAILABLE_FORMATS,
|
|
416 |
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT,
|
|
417 |
IDebugVMConstants.PROP_FORMATTED_VALUE_FORMAT_PREFERENCE,
|
|
418 |
PROP_VARIABLE_SHOW_TYPE_NAMES})
|
|
419 |
{
|
|
420 |
@Override
|
|
421 |
public boolean isEnabled(IStatus status, Map<String, Object> properties) {
|
|
422 |
Boolean showTypeNames = (Boolean) properties.get(PROP_VARIABLE_SHOW_TYPE_NAMES);
|
|
423 |
String[] formatIds = (String[]) properties.get(IDebugVMConstants.PROP_FORMATTED_VALUE_AVAILABLE_FORMATS);
|
|
424 |
String activeFormat = (String) properties.get(IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT);
|
|
425 |
return
|
|
426 |
showTypeNames != null &&
|
|
427 |
!showTypeNames.booleanValue() &&
|
|
428 |
!IFormattedValues.STRING_FORMAT.equals(activeFormat) &&
|
|
429 |
formatIds != null &&
|
|
430 |
Arrays.asList(formatIds).contains(IFormattedValues.STRING_FORMAT) &&
|
|
431 |
super.isEnabled(status, properties);
|
|
432 |
}
|
|
433 |
},
|
|
434 |
new FormattedValueLabelText(
|
|
435 |
MessagesForVariablesVM.VariableVMNode_NoColumns_column__No_string__text_format,
|
|
436 |
new String[] {
|
|
437 |
PROP_NAME,
|
|
438 |
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT_VALUE,
|
|
439 |
IDebugVMConstants.PROP_FORMATTED_VALUE_AVAILABLE_FORMATS,
|
|
440 |
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT,
|
|
441 |
IDebugVMConstants.PROP_FORMATTED_VALUE_FORMAT_PREFERENCE,
|
|
442 |
PROP_VARIABLE_SHOW_TYPE_NAMES})
|
|
443 |
{
|
|
444 |
@Override
|
|
445 |
public boolean isEnabled(IStatus status, Map<String, Object> properties) {
|
|
446 |
Boolean showTypeNames = (Boolean) properties.get(PROP_VARIABLE_SHOW_TYPE_NAMES);
|
|
447 |
return
|
|
448 |
showTypeNames != null &&
|
|
449 |
!showTypeNames.booleanValue() &&
|
|
450 |
super.isEnabled(status, properties);
|
|
451 |
}
|
|
452 |
},
|
|
453 |
new FormattedValueLabelText(
|
|
454 |
MessagesForVariablesVM.VariableVMNode_NoColumns_column__text_format_with_type,
|
|
455 |
new String[] {
|
|
456 |
PROP_NAME,
|
|
457 |
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT_VALUE,
|
|
458 |
FormattedValueVMUtil.getPropertyForFormatId(IFormattedValues.STRING_FORMAT),
|
|
459 |
PROP_VARIABLE_TYPE_NAME,
|
|
460 |
IDebugVMConstants.PROP_FORMATTED_VALUE_AVAILABLE_FORMATS,
|
|
461 |
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT,
|
|
462 |
IDebugVMConstants.PROP_FORMATTED_VALUE_FORMAT_PREFERENCE,
|
|
463 |
PROP_VARIABLE_SHOW_TYPE_NAMES})
|
|
464 |
{
|
|
465 |
@Override
|
|
466 |
public boolean isEnabled(IStatus status, Map<String, Object> properties) {
|
|
467 |
Boolean showTypeNames = (Boolean) properties.get(PROP_VARIABLE_SHOW_TYPE_NAMES);
|
|
468 |
String[] formatIds = (String[]) properties.get(IDebugVMConstants.PROP_FORMATTED_VALUE_AVAILABLE_FORMATS);
|
|
469 |
String activeFormat = (String) properties.get(IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT);
|
|
470 |
return
|
|
471 |
showTypeNames != null &&
|
|
472 |
showTypeNames.booleanValue() &&
|
|
473 |
!IFormattedValues.STRING_FORMAT.equals(activeFormat) &&
|
|
474 |
formatIds != null &&
|
|
475 |
Arrays.asList(formatIds).contains(IFormattedValues.STRING_FORMAT) &&
|
|
476 |
super.isEnabled(status, properties);
|
|
477 |
}
|
|
478 |
},
|
|
479 |
new FormattedValueLabelText(
|
|
480 |
MessagesForVariablesVM.VariableVMNode_NoColumns_column__No_string__text_format_with_type,
|
|
481 |
new String[] {
|
|
482 |
PROP_NAME,
|
|
483 |
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT_VALUE,
|
|
484 |
PROP_VARIABLE_TYPE_NAME,
|
|
485 |
IDebugVMConstants.PROP_FORMATTED_VALUE_AVAILABLE_FORMATS,
|
|
486 |
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT,
|
|
487 |
IDebugVMConstants.PROP_FORMATTED_VALUE_FORMAT_PREFERENCE,
|
|
488 |
PROP_VARIABLE_SHOW_TYPE_NAMES})
|
|
489 |
{
|
|
490 |
@Override
|
|
491 |
public boolean isEnabled(IStatus status, Map<String, Object> properties) {
|
|
492 |
Boolean showTypeNames = (Boolean) properties.get(PROP_VARIABLE_SHOW_TYPE_NAMES);
|
|
493 |
return
|
|
494 |
showTypeNames != null &&
|
|
495 |
showTypeNames.booleanValue() &&
|
|
496 |
super.isEnabled(status, properties);
|
|
497 |
}
|
|
498 |
},
|
|
499 |
new ErrorLabelText(
|
|
500 |
MessagesForVariablesVM.VariableVMNode_NoColumns_column__Error__text_format,
|
|
501 |
new String[] { PROP_NAME }),
|
|
502 |
pointerLabelImage,
|
|
503 |
aggregateLabelImage,
|
|
504 |
simpleLabelImage,
|
|
505 |
new LabelForeground(new RGB(255, 0, 0)) // TODO: replace with preference error color
|
|
506 |
{
|
|
507 |
{ setPropertyNames(new String[] { PROP_NAME }); }
|
|
508 |
|
|
509 |
@Override
|
|
510 |
public boolean isEnabled(IStatus status, java.util.Map<String,Object> properties) {
|
|
511 |
return !status.isOK();
|
|
512 |
}
|
|
513 |
},
|
|
514 |
new LabelForeground(
|
|
515 |
DebugUITools.getPreferenceColor(IDebugUIConstants.PREF_CHANGED_DEBUG_ELEMENT_COLOR).getRGB())
|
|
516 |
{
|
|
517 |
{
|
|
518 |
setPropertyNames(new String[] {
|
|
519 |
FormattedValueVMUtil.getPropertyForFormatId(IFormattedValues.STRING_FORMAT),
|
|
520 |
IDebugVMConstants.PROP_IS_STRING_FORMAT_VALUE_CHANGED,
|
|
521 |
IDebugVMConstants.PROP_IS_ACTIVE_FORMATTED_VALUE_CHANGED});
|
|
522 |
}
|
|
523 |
|
|
524 |
@Override
|
|
525 |
public boolean isEnabled(IStatus status, java.util.Map<String,Object> properties) {
|
|
526 |
Boolean stringChanged =
|
|
527 |
(Boolean)properties.get(IDebugVMConstants.PROP_IS_STRING_FORMAT_VALUE_CHANGED);
|
|
528 |
Boolean activeChanged =
|
|
529 |
(Boolean)properties.get(IDebugVMConstants.PROP_IS_ACTIVE_FORMATTED_VALUE_CHANGED);
|
|
530 |
return Boolean.TRUE.equals(stringChanged) || Boolean.TRUE.equals(activeChanged);
|
|
531 |
};
|
|
532 |
},
|
|
533 |
new StaleDataLabelBackground(),
|
|
534 |
new VariableLabelFont(),
|
|
535 |
}));
|
|
536 |
|
|
537 |
return provider;
|
|
538 |
}
|
|
539 |
|
|
540 |
@Override
|
|
541 |
public String toString() {
|
|
542 |
return "VariableVMNode(" + getSession().getId() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
|
|
543 |
}
|
|
544 |
|
|
545 |
@Override
|
|
546 |
protected IDMVMContext createVMContext(IDMContext dmc) {
|
|
547 |
return new VariableExpressionVMC(dmc);
|
|
548 |
}
|
|
549 |
|
|
550 |
|
|
551 |
public void update(final ILabelUpdate[] updates) {
|
|
552 |
fLabelProvider.update(updates);
|
|
553 |
}
|
|
554 |
|
|
555 |
/**
|
|
556 |
* @see IElementPropertiesProvider#update(IPropertiesUpdate[])
|
|
557 |
*
|
|
558 |
* @since 2.0
|
|
559 |
*/
|
|
560 |
public void update(final IPropertiesUpdate[] updates) {
|
|
561 |
try {
|
|
562 |
getSession().getExecutor().execute(new DsfRunnable() {
|
|
563 |
public void run() {
|
|
564 |
updatePropertiesInSessionThread(updates);
|
|
565 |
}});
|
|
566 |
} catch (RejectedExecutionException e) {
|
|
567 |
for (IPropertiesUpdate update : updates) {
|
|
568 |
handleFailedUpdate(update);
|
|
569 |
}
|
|
570 |
}
|
|
571 |
}
|
|
572 |
|
|
573 |
//
|
|
574 |
// @param return-value Boolean.TRUE --> Show Types ICON is selected/depressed
|
|
575 |
// @param return-value Boolean.FALSE --> Show Types ICON is not selected/depressed
|
|
576 |
//
|
|
577 |
private Boolean getShowTypeNamesState( IPresentationContext context ) {
|
|
578 |
Boolean attribute = (Boolean) context.getProperty(IDebugModelPresentation.DISPLAY_VARIABLE_TYPE_NAMES);
|
|
579 |
|
|
580 |
if (attribute != null) {
|
|
581 |
return attribute;
|
|
582 |
}
|
|
583 |
|
|
584 |
return Boolean.FALSE;
|
|
585 |
}
|
|
586 |
|
|
587 |
/**
|
|
588 |
* @since 2.0
|
|
589 |
*/
|
|
590 |
@ConfinedToDsfExecutor("getSession().getExecutor()")
|
|
591 |
protected void updatePropertiesInSessionThread(final IPropertiesUpdate[] updates) {
|
|
592 |
IExpressions service = getServicesTracker().getService(IExpressions.class, null);
|
|
593 |
|
|
594 |
final CountingRequestMonitor countingRm = new CountingRequestMonitor(ImmediateExecutor.getInstance(), null) {
|
|
595 |
@Override
|
|
596 |
protected void handleCompleted() {
|
|
597 |
for (final IPropertiesUpdate update : updates) {
|
|
598 |
update.done();
|
|
599 |
}
|
|
600 |
};
|
|
601 |
};
|
|
602 |
int count = 0;
|
|
603 |
|
|
604 |
if (service != null) {
|
|
605 |
FormattedValueVMUtil.updateFormattedValues(updates, service, IExpressionDMContext.class, countingRm);
|
|
606 |
count++;
|
|
607 |
}
|
|
608 |
|
|
609 |
for (final IPropertiesUpdate update : updates) {
|
|
610 |
IExpression expression = (IExpression)DebugPlugin.getAdapter(update.getElement(), IExpression.class);
|
|
611 |
if (expression != null) {
|
|
612 |
update.setProperty(AbstractExpressionVMNode.PROP_ELEMENT_EXPRESSION, expression.getExpressionText());
|
|
613 |
}
|
|
614 |
|
|
615 |
// Capture the current "Show Type Names" ICON state in case there are no columns.
|
|
616 |
if (update.getProperties().contains(PROP_VARIABLE_SHOW_TYPE_NAMES)) {
|
|
617 |
update.setProperty(PROP_VARIABLE_SHOW_TYPE_NAMES, getShowTypeNamesState(update.getPresentationContext()));
|
|
618 |
}
|
|
619 |
|
|
620 |
IExpressionDMContext dmc = findDmcInPath(update.getViewerInput(), update.getElementPath(), IExpressions.IExpressionDMContext.class);
|
|
621 |
if ( dmc == null || service == null) {
|
|
622 |
update.setStatus(DsfUIPlugin.newErrorStatus(IDsfStatusConstants.INVALID_STATE, "Invalid context or service not available.", null)); //$NON-NLS-1$
|
|
623 |
continue;
|
|
624 |
}
|
|
625 |
|
|
626 |
if (update.getProperties().contains(PROP_NAME) ||
|
|
627 |
update.getProperties().contains(PROP_VARIABLE_TYPE_NAME) ||
|
|
628 |
update.getProperties().contains(PROP_VARIABLE_BASIC_TYPE))
|
|
629 |
{
|
|
630 |
service.getExpressionData(
|
|
631 |
dmc,
|
|
632 |
// Use the ViewerDataRequestMonitor in order to propagate the update's cancel request. Use an immediate
|
|
633 |
// executor to avoid the possibility of a rejected execution exception.
|
|
634 |
new ViewerDataRequestMonitor<IExpressionDMData>(ImmediateExecutor.getInstance(), update) {
|
|
635 |
@Override
|
|
636 |
protected void handleCompleted() {
|
|
637 |
if (isSuccess()) {
|
|
638 |
fillExpressionDataProperties(update, getData());
|
|
639 |
} else {
|
|
640 |
// In case of an error fill in the expression next in the name column.
|
|
641 |
IExpressionDMContext dmc = findDmcInPath(update.getViewerInput(), update.getElementPath(), IExpressions.IExpressionDMContext.class);
|
|
642 |
if (dmc != null && dmc.getExpression() != null) {
|
|
643 |
update.setProperty(PROP_NAME, dmc.getExpression());
|
|
644 |
}
|
|
645 |
update.setStatus(getStatus());
|
|
646 |
}
|
|
647 |
countingRm.done();
|
|
648 |
}
|
|
649 |
});
|
|
650 |
|
|
651 |
count++;
|
|
652 |
}
|
|
653 |
|
|
654 |
if (update.getProperties().contains(PROP_VARIABLE_ADDRESS)) {
|
|
655 |
service.getExpressionAddressData(
|
|
656 |
dmc,
|
|
657 |
// Use the ViewerDataRequestMonitor in order to propagate the update's cancel request. Use an immediate
|
|
658 |
// executor to avoid the possibility of a rejected execution exception.
|
|
659 |
new ViewerDataRequestMonitor<IExpressionDMAddress>(ImmediateExecutor.getInstance(), update) {
|
|
660 |
@Override
|
|
661 |
protected void handleCompleted() {
|
|
662 |
if (isSuccess()) {
|
|
663 |
fillAddressDataProperties(update, getData());
|
|
664 |
} else if (getStatus().getCode() != IDsfStatusConstants.NOT_SUPPORTED &&
|
|
665 |
getStatus().getCode() != IDsfStatusConstants.INVALID_STATE)
|
|
666 |
{
|
|
667 |
update.setStatus(getStatus());
|
|
668 |
}
|
|
669 |
countingRm.done();
|
|
670 |
}
|
|
671 |
});
|
|
672 |
count++;
|
|
673 |
}
|
|
674 |
}
|
|
675 |
countingRm.setDoneCount(count);
|
|
676 |
}
|
|
677 |
|
|
678 |
/**
|
|
679 |
* @since 2.0
|
|
680 |
*/
|
|
681 |
@ConfinedToDsfExecutor("getSession().getExecutor()")
|
|
682 |
protected void fillExpressionDataProperties(IPropertiesUpdate update, IExpressionDMData data)
|
|
683 |
{
|
|
684 |
update.setProperty(PROP_NAME, data.getName());
|
|
685 |
update.setProperty(PROP_VARIABLE_TYPE_NAME, data.getTypeName());
|
|
686 |
IExpressionDMData.BasicType type = data.getBasicType();
|
|
687 |
if (type != null) {
|
|
688 |
update.setProperty(PROP_VARIABLE_BASIC_TYPE, type.name());
|
|
689 |
}
|
|
690 |
|
|
691 |
//
|
|
692 |
// If this node has an expression then it has already been filled in by the higher
|
|
693 |
// level logic. If not then we need to supply something. In the previous version
|
|
694 |
// ( pre-property based ) we supplied the name. So we will do that here also.
|
|
695 |
//
|
|
696 |
IExpression expression = (IExpression)DebugPlugin.getAdapter(update.getElement(), IExpression.class);
|
|
697 |
if (expression == null) {
|
|
698 |
update.setProperty(AbstractExpressionVMNode.PROP_ELEMENT_EXPRESSION, data.getName());
|
|
699 |
}
|
|
700 |
}
|
|
701 |
|
|
702 |
/**
|
|
703 |
* Private data access routine which performs the extra level of data access needed to
|
|
704 |
* get the formatted data value for a specific register.
|
|
705 |
*/
|
|
706 |
@ConfinedToDsfExecutor("getSession().getExecutor()")
|
|
707 |
protected void fillAddressDataProperties(IPropertiesUpdate update, IExpressionDMAddress address)
|
|
708 |
{
|
|
709 |
IExpressionDMAddress expression = address;
|
|
710 |
IAddress expAddress = expression.getAddress();
|
|
711 |
update.setProperty(PROP_VARIABLE_ADDRESS, "0x" + expAddress.toString(16)); //$NON-NLS-1$
|
|
712 |
}
|
|
713 |
|
|
714 |
public CellEditor getCellEditor(IPresentationContext context, String columnId, Object element, Composite parent) {
|
|
715 |
if (IDebugVMConstants.COLUMN_ID__VALUE.equals(columnId)) {
|
|
716 |
return new TextCellEditor(parent);
|
|
717 |
}
|
|
718 |
else if (IDebugVMConstants.COLUMN_ID__EXPRESSION.equals(columnId)) {
|
|
719 |
return new TextCellEditor(parent);
|
|
720 |
}
|
|
721 |
|
|
722 |
return null;
|
|
723 |
}
|
|
724 |
|
|
725 |
public ICellModifier getCellModifier(IPresentationContext context, Object element) {
|
|
726 |
return new VariableCellModifier(getDMVMProvider(), fSyncVariableDataAccess);
|
|
727 |
}
|
|
728 |
|
|
729 |
public boolean canParseExpression(IExpression expression) {
|
|
730 |
// At this point we are going to say we will allow anything as an expression.
|
|
731 |
// Since the evaluation of VM Node implementations searches in the order of
|
|
732 |
// registration and we always make sure we register the VariableVMNode last,
|
|
733 |
// we know that the other possible handlers have passed the expression by. So
|
|
734 |
// we are going to say OK and let the expression evaluation of whatever debug
|
|
735 |
// backend is connected to decide. This does not allow us to put up any good
|
|
736 |
// diagnostic error message ( instead the error will come from the backend ).
|
|
737 |
// But it does allow for the most flexibility
|
|
738 |
|
|
739 |
return true;
|
|
740 |
}
|
|
741 |
|
|
742 |
@Override
|
|
743 |
public void update(final IExpressionUpdate update) {
|
|
744 |
try {
|
|
745 |
getSession().getExecutor().execute(new Runnable() {
|
|
746 |
public void run() {
|
|
747 |
final IExpressions expressionService = getServicesTracker().getService(IExpressions.class);
|
|
748 |
if (expressionService != null) {
|
|
749 |
IExpressionDMContext expressionDMC = expressionService.createExpression(
|
|
750 |
createCompositeDMVMContext(update),
|
|
751 |
update.getExpression().getExpressionText());
|
|
752 |
VariableExpressionVMC variableVmc = new VariableExpressionVMC(expressionDMC);
|
|
753 |
variableVmc.setExpression(update.getExpression());
|
|
754 |
|
|
755 |
update.setExpressionElement(variableVmc);
|
|
756 |
update.done();
|
|
757 |
} else {
|
|
758 |
handleFailedUpdate(update);
|
|
759 |
}
|
|
760 |
}
|
|
761 |
});
|
|
762 |
} catch (RejectedExecutionException e) {
|
|
763 |
handleFailedUpdate(update);
|
|
764 |
}
|
|
765 |
}
|
|
766 |
|
|
767 |
|
|
768 |
@Override
|
|
769 |
protected void handleFailedUpdate(IViewerUpdate update) {
|
|
770 |
if (update instanceof IExpressionUpdate) {
|
|
771 |
update.setStatus(new Status(IStatus.ERROR, DsfUIPlugin.PLUGIN_ID, IDsfStatusConstants.INVALID_STATE, "Update failed", null)); //$NON-NLS-1$
|
|
772 |
update.done();
|
|
773 |
} else {
|
|
774 |
super.handleFailedUpdate(update);
|
|
775 |
}
|
|
776 |
}
|
|
777 |
@Override
|
|
778 |
protected void associateExpression(Object element, IExpression expression) {
|
|
779 |
if (element instanceof VariableExpressionVMC) {
|
|
780 |
((VariableExpressionVMC)element).setExpression(expression);
|
|
781 |
}
|
|
782 |
}
|
|
783 |
|
|
784 |
@Override
|
|
785 |
protected void updateElementsInSessionThread(final IChildrenUpdate update) {
|
|
786 |
// Get the data model context object for the current node in the hierarchy.
|
|
787 |
|
|
788 |
final IExpressionDMContext expressionDMC = findDmcInPath(update.getViewerInput(), update.getElementPath(), IExpressionDMContext.class);
|
|
789 |
|
|
790 |
if ( expressionDMC != null ) {
|
|
791 |
getSubexpressionsUpdateElementsInSessionThread( update );
|
|
792 |
}
|
|
793 |
else {
|
|
794 |
getLocalsUpdateElementsInSessionThread( update );
|
|
795 |
}
|
|
796 |
}
|
|
797 |
|
|
798 |
private void getSubexpressionsUpdateElementsInSessionThread(final IChildrenUpdate update) {
|
|
799 |
|
|
800 |
final IExpressionDMContext expressionDMC = findDmcInPath(update.getViewerInput(), update.getElementPath(), IExpressionDMContext.class);
|
|
801 |
|
|
802 |
if ( expressionDMC != null ) {
|
|
803 |
|
|
804 |
// Get the services we need to use.
|
|
805 |
|
|
806 |
final IExpressions expressionService = getServicesTracker().getService(IExpressions.class);
|
|
807 |
|
|
808 |
if (expressionService == null) {
|
|
809 |
handleFailedUpdate(update);
|
|
810 |
return;
|
|
811 |
}
|
|
812 |
|
|
813 |
final DsfExecutor dsfExecutor = getSession().getExecutor();
|
|
814 |
|
|
815 |
// Call IExpressions.getSubExpressions() to get an Iterable of IExpressionDMContext objects representing
|
|
816 |
// the sub-expressions of the expression represented by the current expression node.
|
|
817 |
|
|
818 |
final DataRequestMonitor<IExpressionDMContext[]> rm =
|
|
819 |
new ViewerDataRequestMonitor<IExpressionDMContext[]>(dsfExecutor, update) {
|
|
820 |
@Override
|
|
821 |
public void handleCompleted() {
|
|
822 |
if (!isSuccess()) {
|
|
823 |
handleFailedUpdate(update);
|
|
824 |
return;
|
|
825 |
}
|
|
826 |
fillUpdateWithVMCs(update, getData());
|
|
827 |
update.done();
|
|
828 |
}
|
|
829 |
};
|
|
830 |
|
|
831 |
// Make the asynchronous call to IExpressions.getSubExpressions(). The results are processed in the
|
|
832 |
// DataRequestMonitor.handleCompleted() above.
|
|
833 |
|
|
834 |
expressionService.getSubExpressions(expressionDMC, rm);
|
|
835 |
} else {
|
|
836 |
handleFailedUpdate(update);
|
|
837 |
}
|
|
838 |
}
|
|
839 |
|
|
840 |
private void getLocalsUpdateElementsInSessionThread(final IChildrenUpdate update) {
|
|
841 |
|
|
842 |
final IFrameDMContext frameDmc = findDmcInPath(update.getViewerInput(), update.getElementPath(), IFrameDMContext.class);
|
|
843 |
|
|
844 |
// Get the services we need to use.
|
|
845 |
|
|
846 |
final IExpressions expressionService = getServicesTracker().getService(IExpressions.class);
|
|
847 |
final IStack stackFrameService = getServicesTracker().getService(IStack.class);
|
|
848 |
|
|
849 |
if ( frameDmc == null || expressionService == null || stackFrameService == null) {
|
|
850 |
handleFailedUpdate(update);
|
|
851 |
return;
|
|
852 |
}
|
|
853 |
|
|
854 |
final DsfExecutor dsfExecutor = getSession().getExecutor();
|
|
855 |
|
|
856 |
// Call IStack.getLocals() to get an array of IVariableDMContext objects representing the local
|
|
857 |
// variables in the stack frame represented by frameDmc.
|
|
858 |
|
|
859 |
final DataRequestMonitor<IVariableDMContext[]> rm =
|
|
860 |
new ViewerDataRequestMonitor<IVariableDMContext[]>(dsfExecutor, update) {
|
|
861 |
@Override
|
|
862 |
public void handleCompleted() {
|
|
863 |
if (!isSuccess()) {
|
|
864 |
handleFailedUpdate(update);
|
|
865 |
return;
|
|
866 |
}
|
|
867 |
|
|
868 |
// For each IVariableDMContext object returned by IStack.getLocals(), call
|
|
869 |
// MIStackFrameService.getModelData() to get the IVariableDMData object. This requires
|
|
870 |
// a MultiRequestMonitor object.
|
|
871 |
|
|
872 |
// First, get the data model context objects for the local variables.
|
|
873 |
|
|
874 |
IVariableDMContext[] localsDMCs = getData();
|
|
875 |
|
|
876 |
if (localsDMCs == null) {
|
|
877 |
handleFailedUpdate(update);
|
|
878 |
return;
|
|
879 |
}
|
|
880 |
|
|
881 |
if ( localsDMCs.length == 0 ) {
|
|
882 |
// There are no locals so just complete the request
|
|
883 |
update.done();
|
|
884 |
return;
|
|
885 |
}
|
|
886 |
|
|
887 |
// Create a List in which we store the DM data objects for the local variables. This is
|
|
888 |
// necessary because there is no MultiDataRequestMonitor. :)
|
|
889 |
|
|
890 |
final List<IVariableDMData> localsDMData = new ArrayList<IVariableDMData>();
|
|
891 |
|
|
892 |
// Create the MultiRequestMonitor to handle completion of the set of getModelData() calls.
|
|
893 |
|
|
894 |
final MultiRequestMonitor<DataRequestMonitor<IVariableDMData>> mrm =
|
|
895 |
new MultiRequestMonitor<DataRequestMonitor<IVariableDMData>>(dsfExecutor, null) {
|
|
896 |
@Override
|
|
897 |
public void handleCompleted() {
|
|
898 |
// Now that all the calls to getModelData() are complete, we create an
|
|
899 |
// IExpressionDMContext object for each local variable name, saving them all
|
|
900 |
// in an array.
|
|
901 |
|
|
902 |
if (!isSuccess()) {
|
|
903 |
handleFailedUpdate(update);
|
|
904 |
return;
|
|
905 |
}
|
|
906 |
|
|
907 |
IExpressionDMContext[] expressionDMCs = new IExpressionDMContext[localsDMData.size()];
|
|
908 |
|
|
909 |
int i = 0;
|
|
910 |
|
|
911 |
for (IVariableDMData localDMData : localsDMData) {
|
|
912 |
expressionDMCs[i++] = expressionService.createExpression(frameDmc, localDMData.getName());
|
|
913 |
}
|
|
914 |
|
|
915 |
// Lastly, we fill the update from the array of view model context objects
|
|
916 |
// that reference the ExpressionDMC objects for the local variables. This is
|
|
917 |
// the last code to run for a given call to updateElementsInSessionThread().
|
|
918 |
// We can now leave anonymous-inner-class hell.
|
|
919 |
|
|
920 |
fillUpdateWithVMCs(update, expressionDMCs);
|
|
921 |
update.done();
|
|
922 |
}
|
|
923 |
};
|
|
924 |
|
|
925 |
// Perform a set of getModelData() calls, one for each local variable's data model
|
|
926 |
// context object. In the handleCompleted() method of the DataRequestMonitor, add the
|
|
927 |
// IVariableDMData object to the localsDMData List for later processing (see above).
|
|
928 |
|
|
929 |
for (IVariableDMContext localDMC : localsDMCs) {
|
|
930 |
DataRequestMonitor<IVariableDMData> rm =
|
|
931 |
new ViewerDataRequestMonitor<IVariableDMData>(dsfExecutor, update) {
|
|
932 |
@Override
|
|
933 |
public void handleCompleted() {
|
|
934 |
localsDMData.add(getData());
|
|
935 |
mrm.requestMonitorDone(this);
|
|
936 |
}
|
|
937 |
};
|
|
938 |
|
|
939 |
mrm.add(rm);
|
|
940 |
|
|
941 |
stackFrameService.getVariableData(localDMC, rm);
|
|
942 |
}
|
|
943 |
}
|
|
944 |
};
|
|
945 |
|
|
946 |
// Make the asynchronous call to IStack.getLocals(). The results are processed in the
|
|
947 |
// DataRequestMonitor.handleCompleted() above.
|
|
948 |
|
|
949 |
stackFrameService.getLocals(frameDmc, rm);
|
|
950 |
}
|
|
951 |
|
|
952 |
public int getDeltaFlags(Object e) {
|
|
953 |
if ( e instanceof ISuspendedDMEvent ||
|
|
954 |
e instanceof IMemoryChangedEvent ||
|
|
955 |
e instanceof IExpressionChangedDMEvent ||
|
|
956 |
(e instanceof PropertyChangeEvent &&
|
|
957 |
((PropertyChangeEvent)e).getProperty() == IDebugVMConstants.PROP_FORMATTED_VALUE_FORMAT_PREFERENCE) )
|
|
958 |
{
|
|
959 |
// Create a delta that the whole register group has changed.
|
|
960 |
return IModelDelta.CONTENT;
|
|
961 |
}
|
|
962 |
|
|
963 |
return IModelDelta.NO_CHANGE;
|
|
964 |
}
|
|
965 |
|
|
966 |
public void buildDelta(final Object e, final VMDelta parentDelta, final int nodeOffset, final RequestMonitor requestMonitor) {
|
|
967 |
|
|
968 |
// The following events can affect any expression's values,
|
|
969 |
// refresh the contents of the parent element (i.e. all the expressions).
|
|
970 |
if ( e instanceof ISuspendedDMEvent ||
|
|
971 |
e instanceof IMemoryChangedEvent ||
|
|
972 |
e instanceof IExpressionChangedDMEvent ||
|
|
973 |
(e instanceof PropertyChangeEvent &&
|
|
974 |
((PropertyChangeEvent)e).getProperty() == IDebugVMConstants.PROP_FORMATTED_VALUE_FORMAT_PREFERENCE) )
|
|
975 |
{
|
|
976 |
// Create a delta that the whole register group has changed.
|
|
977 |
parentDelta.setFlags(parentDelta.getFlags() | IModelDelta.CONTENT);
|
|
978 |
}
|
|
979 |
|
|
980 |
requestMonitor.done();
|
|
981 |
}
|
|
982 |
|
|
983 |
public int getDeltaFlagsForExpression(IExpression expression, Object event) {
|
|
984 |
if ( event instanceof IExpressionChangedDMEvent ||
|
|
985 |
event instanceof IMemoryChangedEvent ||
|
|
986 |
(event instanceof PropertyChangeEvent &&
|
|
987 |
((PropertyChangeEvent)event).getProperty() == IDebugVMConstants.PROP_FORMATTED_VALUE_FORMAT_PREFERENCE) )
|
|
988 |
{
|
|
989 |
return IModelDelta.CONTENT;
|
|
990 |
}
|
|
991 |
|
|
992 |
if (event instanceof ISuspendedDMEvent)
|
|
993 |
{
|
|
994 |
return IModelDelta.CONTENT;
|
|
995 |
}
|
|
996 |
|
|
997 |
return IModelDelta.NO_CHANGE;
|
|
998 |
}
|
|
999 |
|
|
1000 |
public void buildDeltaForExpression(IExpression expression, int elementIdx, Object event, VMDelta parentDelta,
|
|
1001 |
TreePath path, RequestMonitor rm)
|
|
1002 |
{
|
|
1003 |
// Always refresh the contents of the view upon suspended event.
|
|
1004 |
if (event instanceof ISuspendedDMEvent) {
|
|
1005 |
parentDelta.setFlags(parentDelta.getFlags() | IModelDelta.CONTENT);
|
|
1006 |
}
|
|
1007 |
|
|
1008 |
rm.done();
|
|
1009 |
}
|
|
1010 |
|
|
1011 |
public void buildDeltaForExpressionElement(Object element, int elementIdx, Object event, VMDelta parentDelta,
|
|
1012 |
RequestMonitor rm)
|
|
1013 |
{
|
|
1014 |
// The following events can affect expression values, refresh the state
|
|
1015 |
// of the expression.
|
|
1016 |
if ( event instanceof IExpressionChangedDMEvent ||
|
|
1017 |
event instanceof IMemoryChangedEvent ||
|
|
1018 |
(event instanceof PropertyChangeEvent &&
|
|
1019 |
((PropertyChangeEvent)event).getProperty() == IDebugVMConstants.PROP_FORMATTED_VALUE_FORMAT_PREFERENCE) )
|
|
1020 |
{
|
|
1021 |
parentDelta.addNode(element, IModelDelta.CONTENT);
|
|
1022 |
}
|
|
1023 |
|
|
1024 |
rm.done();
|
|
1025 |
}
|
|
1026 |
|
|
1027 |
|
|
1028 |
|
|
1029 |
private String produceExpressionElementName( String viewName , IExpressionDMContext expression ) {
|
|
1030 |
|
|
1031 |
return "Variable." + expression.getExpression(); //$NON-NLS-1$
|
|
1032 |
}
|
|
1033 |
|
|
1034 |
private final String MEMENTO_NAME = "VARIABLE_MEMENTO_NAME"; //$NON-NLS-1$
|
|
1035 |
|
|
1036 |
public void compareElements(IElementCompareRequest[] requests) {
|
|
1037 |
|
|
1038 |
for ( IElementCompareRequest request : requests ) {
|
|
1039 |
|
|
1040 |
Object element = request.getElement();
|
|
1041 |
IMemento memento = request.getMemento();
|
|
1042 |
String mementoName = memento.getString(MEMENTO_NAME);
|
|
1043 |
|
|
1044 |
if (mementoName != null) {
|
|
1045 |
if (element instanceof IDMVMContext) {
|
|
1046 |
|
|
1047 |
IDMContext dmc = ((IDMVMContext)element).getDMContext();
|
|
1048 |
|
|
1049 |
if ( dmc instanceof IExpressionDMContext) {
|
|
1050 |
|
|
1051 |
String elementName = produceExpressionElementName( request.getPresentationContext().getId(), (IExpressionDMContext) dmc );
|
|
1052 |
request.setEqual( elementName.equals( mementoName ) );
|
|
1053 |
}
|
|
1054 |
}
|
|
1055 |
}
|
|
1056 |
request.done();
|
|
1057 |
}
|
|
1058 |
}
|
|
1059 |
|
|
1060 |
public void encodeElements(IElementMementoRequest[] requests) {
|
|
1061 |
|
|
1062 |
for ( IElementMementoRequest request : requests ) {
|
|
1063 |
|
|
1064 |
Object element = request.getElement();
|
|
1065 |
IMemento memento = request.getMemento();
|
|
1066 |
|
|
1067 |
if (element instanceof IDMVMContext) {
|
|
1068 |
|
|
1069 |
IDMContext dmc = ((IDMVMContext)element).getDMContext();
|
|
1070 |
|
|
1071 |
if ( dmc instanceof IExpressionDMContext) {
|
|
1072 |
|
|
1073 |
String elementName = produceExpressionElementName( request.getPresentationContext().getId(), (IExpressionDMContext) dmc );
|
|
1074 |
memento.putString(MEMENTO_NAME, elementName);
|
|
1075 |
}
|
|
1076 |
}
|
|
1077 |
request.done();
|
|
1078 |
}
|
|
1079 |
}
|
|
1080 |
}
|