1 package net.sourceforge.phpeclipse.xdebug.php.model;
4 import net.sourceforge.phpeclipse.xdebug.core.Base64;
5 import net.sourceforge.phpeclipse.xdebug.core.xdebug.XDebugConnection;
6 import net.sourceforge.phpeclipse.xdebug.core.xdebug.ResponseListener.DebugResponse;
7 import net.sourceforge.phpeclipse.xdebug.php.model.XDebugVariable;
8 import net.sourceforge.phpeclipse.xdebug.php.model.XDebugTarget;
9 import org.eclipse.debug.core.model.IDebugElement;
10 import org.eclipse.debug.core.model.IWatchExpressionDelegate;
11 import org.eclipse.debug.core.model.IWatchExpressionListener;
12 import org.eclipse.debug.core.model.IWatchExpressionResult;
13 import org.w3c.dom.Node;
15 public class XDebugWatchExpressionDelegate implements IWatchExpressionDelegate {
16 public void evaluateExpression(String expression, IDebugElement context, IWatchExpressionListener listener) {
17 IWatchExpressionResult x;
18 XDebugConnection connection;
21 x = new XDebugWatchExpressionResult(expression, null, null);
23 s = (XDebugTarget) context.getDebugTarget();
24 connection = (XDebugConnection) s.getDebugConnection();
26 if( connection != null ) {
28 if( ! connection.isClosed() ) {
29 String encoded = Base64.encodeBytes(expression.getBytes());
30 DebugResponse evalCommand = connection.sendRequestA( "eval", "-- "+encoded );
32 Node evalNode = evalCommand.getParentNode();
33 XDebugVariable var= connection.getVariableFromNodeA( null, evalNode.getFirstChild());
34 XDebugVariable result[] = {var};
36 if (result.length == 0) {
37 x = new XDebugWatchExpressionResult(expression, null, null);
39 x = new XDebugWatchExpressionResult(expression, result[0].getValue(), null);
42 } catch (Exception e) {
47 x = new XDebugWatchExpressionResult(expression, null, s1);
51 listener.watchEvaluationFinished(x);