X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugTarget.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugTarget.java index 43f7c9c..06064eb 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugTarget.java +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugTarget.java @@ -3,8 +3,14 @@ */ package net.sourceforge.phpeclipse.xdebug.php.model; +//import java.io.ByteArrayInputStream; +//import java.io.IOException; import java.util.List; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + import net.sourceforge.phpeclipse.xdebug.core.IPHPDebugEvent; import net.sourceforge.phpeclipse.xdebug.core.IProxyEventListener; import net.sourceforge.phpeclipse.xdebug.core.IXDebugPreferenceConstants; @@ -30,12 +36,14 @@ import org.eclipse.debug.core.model.ILineBreakpoint; import org.eclipse.debug.core.model.IMemoryBlock; import org.eclipse.debug.core.model.IProcess; import org.eclipse.debug.core.model.IThread; +import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; +//import org.xml.sax.SAXException; import net.sourceforge.phpeclipse.xdebug.core.xdebug.ResponseListener; import net.sourceforge.phpeclipse.xdebug.core.xdebug.XDebugConnection; -import net.sourceforge.phpeclipse.xdebug.core.xdebug.ResponseListener.XDebugResponse; +import net.sourceforge.phpeclipse.xdebug.core.xdebug.XDebugResponse; /** * @author Christian @@ -70,7 +78,6 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, IDebugE * @param launch containing launch * @param process process of the interpreter * @param ideKey - * @param pathMap Pathmap for the debug session * @exception CoreException if unable to connect to host */ public XDebugTarget(ILaunch launch, IProcess process, String ideKey) throws CoreException { @@ -177,10 +184,8 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, IDebugE fSuspended = false; XDebugCorePlugin.getBreakpointManager().removeBreakpointListener(this); - fireTerminateEvent(); + fireEvent(new DebugEvent(this, DebugEvent.TERMINATE)); DebugPlugin.getDefault().removeDebugEventListener(this); - /*if (fThread!=null) - fThread.removeEventListeners();*/ } } @@ -211,8 +216,9 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, IDebugE public void resume() throws DebugException { if (fDebugConnection != null) { fThread.setBreakpoints(null); + resumed(DebugEvent.RESUME); fDebugConnection.run(); - } + } } /** @@ -273,8 +279,6 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, IDebugE try { if (breakpoint.isEnabled()) { if (marker != null) { - //XDebugResponse dr = fDebugConnection.breakpointSet(newPath.toString(), ((ILineBreakpoint)breakpoint).getLineNumber()); - int id = fDebugConnection.breakpointSet(newPath.toString(), ((ILineBreakpoint)breakpoint).getLineNumber(), marker.getAttribute(XDebugBreakpoint.HIT_COUNT,-1)); XDebugResponse dr = getResponse(id); @@ -363,7 +367,6 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, IDebugE */ public boolean isDisconnected() { return (false); -// return (fDebugConnection==null); } /* (non-Javadoc) @@ -394,14 +397,9 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, IDebugE Integer.parseInt(response.getValue()); System.out.println("in Target.started()"); - /*XDebugResponse response = fDebugConnection.featureGet("max_children"); - String a1 = response.getValue(); - System.out.println("max children:"+a1); - XDebugResponse response1 = fDebugConnection.featureGet("max_children"); - String a2 = response1.getValue(); - System.out.println("max depth:"+a2);*/ - - + + // Dirty hack + // Need to refactory plugin to get variables in lazy mode. int id1 = fDebugConnection.featureSet("max_depth", "1024" ); XDebugResponse response1 = getResponse(id1); if (response1.getAttributeValue("success").equals("1") ) { @@ -488,6 +486,42 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, IDebugE } } + public Node eval(String expression) throws DebugException { + Node evalProperty = null; + if (fDebugConnection != null) { + int id = fDebugConnection.eval(expression); + //Node evalProperty = new Node(""); + //if (id > 0) { + XDebugResponse response = getResponse(id); + + Node evalResponse = response.getParentNode(); + /*Node*/ evalProperty = evalResponse.getFirstChild(); + //} /*else { + + //}*/ + } else { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = null; + Document doc = null; + + try { + builder = factory.newDocumentBuilder(); + } catch (ParserConfigurationException e) { + e.printStackTrace(); + } + //try { + doc = builder.newDocument(); // .parse(""); + evalProperty = doc.createElement("value"); + /*} catch (SAXException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + }*/ + } + + return evalProperty; + } + public void handleDebugEvents(DebugEvent[] events) { for (int i = 0; i < events.length; i++) { DebugEvent event = events[i]; @@ -541,20 +575,15 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, IDebugE return; } + resumed(DebugEvent.TERMINATE); + stopListener(); fDebugConnection.close(); - fThread.removeEventListeners(); - fThread = null; - fThreads = new IThread[0]; - -/* stopListener(); - fDebugConnection.close();*/ - fSuspended = false; // Dirty hack to check debugging mode (remote or local) - if (fProcess!=null) { + if (fProcess != null) { try { terminate(); } catch (DebugException e) { @@ -563,29 +592,39 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, IDebugE } else { fDebugConnection = null; fireEvent(new DebugEvent(this, DebugEvent.CHANGE, DebugEvent.CONTENT)); - } + } + + fThread.removeEventListeners(); + fThread = null; + fThreads = new IThread[0]; } - public void handleProxyEvent(/*String ideKey,*/ XDebugConnection connection) { - setDebugConnection(connection); - System.out.println("* New Connection - XDebug.Target: " + fDebugConnection.getSessionID()); - - fireEvent(new DebugEvent(this, DebugEvent.CHANGE, DebugEvent.CHANGE)); + public void handleProxyEvent(XDebugConnection connection) { + //System.out.println("* New Connection - XDebug.Target: " + fDebugConnection.getSessionID()); - fThread = new XDebugThread(this); - fThreads = new IThread[] {fThread}; - try { - started(); - } catch( DebugException e ){ - e.printStackTrace(); - } + if (setDebugConnection(connection)) { + fThread = new XDebugThread(this); + fThreads = new IThread[] {fThread}; + fireEvent(new DebugEvent(this, DebugEvent.CHANGE, DebugEvent.CHANGE)); + try { + started(); + } catch( DebugException e ){ + e.printStackTrace(); + } + } } - private void setDebugConnection(XDebugConnection connection) { - if (connection != null) { + private boolean setDebugConnection(XDebugConnection connection) { + if (connection != null && fDebugConnection == null) { fDebugConnection = connection; fResponseListener = new ResponseListener(connection); startListener(); + + return true; + } else { + connection.close(); + + return false; } } @@ -601,7 +640,6 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, IDebugE } public Node getLocalVariables(int level) throws DebugException { -// XDebugResponse response = fDebugConnection.contextGet(level, 0); int id = fDebugConnection.contextGet(level, 0); XDebugResponse response = getResponse(id); @@ -609,19 +647,21 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, IDebugE } public Node getGlobalVariables(int level) throws DebugException { - //XDebugResponse response = fDebugConnection.contextGet(level, 1); - int id = fDebugConnection.contextGet(level, 1); XDebugResponse response = getResponse(id); return response.getParentNode(); } + public void stop() { + fDebugConnection.stop(); + } + protected IBreakpoint breakpointHit(Node node) { Node child = node.getFirstChild(); if (child.getNodeName().equals("stack")) { int lineNumber = Integer.parseInt(PHPDebugUtils.getAttributeValue(child, "lineno")); - String filename=PHPDebugUtils.getAttributeValue(child, "filename"); + String filename = PHPDebugUtils.getAttributeValue(child, "filename"); IBreakpoint[] breakpoints = XDebugCorePlugin.getBreakpoints(); for (int i = 0; i < breakpoints.length; i++) { IBreakpoint breakpoint = breakpoints[i]; @@ -643,7 +683,6 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, IDebugE int id = fDebugConnection.breakpointGet(marker.getAttribute(XDebugLineBreakpoint.BREAKPOINT_ID,-1)); XDebugResponse dr = getResponse(id); - //String bpid = dr.getAttributeValue("command"); Node hitCo = dr.getParentNode().getFirstChild(); int hitCount = 0; if (hitCo.hasAttributes()) { @@ -654,7 +693,6 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, IDebugE } } - //String hitCount = hitCo.getAttributeValue("hit_count"); if(PHPDebugUtils.unescapeString(filename).endsWith(endfilename) && (lineBreakpoint.getLineNumber() == lineNumber) ) { if (marker.getAttribute(XDebugLineBreakpoint.HIT_COUNT, 0) > 0) { @@ -681,8 +719,8 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, IDebugE fResponseListener.schedule(); } - public /*boolean*/ void stopListener() { - /*return*/ fResponseListener.cancel(); //done(null); //.cancel(); + public void stopListener() { + fResponseListener.cancel(); } public XDebugResponse getResponse(int id) { XDebugResponse response = fResponseListener.getResponse(id);