blob: d1a917891d1d1ade48c73e1082116d870499cb0f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
/*******************************************************************************
* Copyright (c) 2004, 2006 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui;
import org.eclipse.cdt.debug.core.model.ICStackFrame;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.model.IDebugElement;
import org.eclipse.debug.core.model.IValue;
import org.eclipse.debug.core.model.IWatchExpressionDelegate;
import org.eclipse.debug.core.model.IWatchExpressionListener;
import org.eclipse.debug.core.model.IWatchExpressionResult;
public class CWatchExpressionDelegate implements IWatchExpressionDelegate {
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IWatchExpressionDelegate#evaluateExpression(java.lang.String, org.eclipse.debug.core.model.IDebugElement, org.eclipse.debug.core.model.IWatchExpressionListener)
*/
public void evaluateExpression( final String expression, IDebugElement context, final IWatchExpressionListener listener ) {
if ( !(context instanceof ICStackFrame) ) {
listener.watchEvaluationFinished( null );
return;
}
final ICStackFrame frame = (ICStackFrame)context;
Runnable runnable = new Runnable() {
public void run() {
IValue value = null;
DebugException de = null;
try {
value = frame.evaluateExpression( expression );
}
catch( DebugException e ) {
de = e;
}
IWatchExpressionResult result = evaluationComplete( expression, value, de );
listener.watchEvaluationFinished( result );
}
};
DebugPlugin.getDefault().asyncExec( runnable );
}
protected IWatchExpressionResult evaluationComplete( final String expression, final IValue value, final DebugException de ) {
return new IWatchExpressionResult() {
public IValue getValue() {
return value;
}
public boolean hasErrors() {
return ( de != null );
}
public String getExpressionText() {
return expression;
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IWatchExpressionResult#getException()
*/
public DebugException getException() {
return de;
}
public String[] getErrorMessages() {
return ( de != null ) ? new String[] { de.getMessage() } : new String[0];
}
};
}
}
|