From 3f748dd72c5ad2e9b9135c7179904187d1312bac Mon Sep 17 00:00:00 2001 From: incastrix Date: Mon, 10 Dec 2007 17:50:20 +0000 Subject: [PATCH] refactory whole plugin --- .../phpeclipse/xdebug/core/XDebugCorePlugin.java | 16 +- .../phpeclipse/xdebug/core/XDebugProxy.java | 14 +- .../xdebug/core/xdebug/ResponseListener.java | 380 ++++++---------- .../xdebug/core/xdebug/XDebugConnection.java | 471 ++++---------------- .../phpeclipse/xdebug/php/model/XDebugTarget.java | 345 ++++++++++---- .../php/model/XDebugWatchExpressionDelegate.java | 72 +++- 6 files changed, 559 insertions(+), 739 deletions(-) diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/XDebugCorePlugin.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/XDebugCorePlugin.java index bbba27c..f7ca94b 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/XDebugCorePlugin.java +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/XDebugCorePlugin.java @@ -2,22 +2,15 @@ package net.sourceforge.phpeclipse.xdebug.core; import net.sourceforge.phpeclipse.xdebug.php.launching.IXDebugConstants; -//import org.eclipse.ui.plugin.AbstractUIPlugin;// *; import org.eclipse.ui.preferences.ScopedPreferenceStore; -//import org.eclipse.core.resources.IWorkspace; -//import org.eclipse.core.resources.ResourcesPlugin; -//import org.eclipse.core.resources.IWorkspace; -//import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Plugin; -//import org.eclipse.core.runtime.Plugin; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.IBreakpointManager; import org.eclipse.debug.core.model.IBreakpoint; import org.eclipse.jface.preference.IPreferenceStore; -//import org.eclipse.jface.resource.ImageDescriptor; import org.osgi.framework.BundleContext; public class XDebugCorePlugin extends Plugin { @@ -33,6 +26,7 @@ public class XDebugCorePlugin extends Plugin { * The constructor. */ public XDebugCorePlugin() { + super(); plugin = this; } @@ -60,17 +54,13 @@ public class XDebugCorePlugin extends Plugin { return plugin; } - /*public static IWorkspace getWorkspace() { - return ResourcesPlugin.getWorkspace(); - }*/ - public static IBreakpoint[] getBreakpoints() { return getBreakpointManager().getBreakpoints(IXDebugConstants.ID_PHP_DEBUG_MODEL); } - public static /*static*/ IBreakpointManager getBreakpointManager() { + public static IBreakpointManager getBreakpointManager() { return DebugPlugin.getDefault().getBreakpointManager(); - } + } public static void log(int severity, String message) { Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null) ; diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/XDebugProxy.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/XDebugProxy.java index d572ba2..93294b2 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/XDebugProxy.java +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/XDebugProxy.java @@ -16,7 +16,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.debug.core.DebugException; +//import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.IDebugEventFilter; import org.eclipse.debug.core.IDebugEventSetListener; @@ -28,7 +28,7 @@ public class XDebugProxy { protected String fInitString; protected String fIdeKey; - protected AbstractDebugConnection fConnection; + /*protected*/ private /*AbstractDebugConnection*/ XDebugConnection fConnection; class ProxyListenerJob extends Job { public ProxyListenerJob() { @@ -69,7 +69,7 @@ public class XDebugProxy { // TODO Auto-generated catch block e.printStackTrace(); } - fConnection=(AbstractDebugConnection) new XDebugConnection(socket,reader,writer); + fConnection=/*(AbstractDebugConnection)*/ new XDebugConnection(socket,reader,writer); if (fConnection.isInitialized()) { fIdeKey=fConnection.getSessionID(); XDebugCorePlugin.log(IStatus.INFO,""); @@ -114,13 +114,13 @@ public class XDebugProxy { */ public void dispatch() { fListener = (IProxyEventListener) getEventListener(fIdeKey); - if (fListener==null) { // no listener is found so start the script - try { + if (fListener == null) { // no listener is found so start the script + //try { fConnection.run(); - } catch (DebugException e) { + /*} catch (DebugException e) { // TODO Auto-generated catch block e.printStackTrace(); - } + }*/ } else Platform.run(this); fListener = null; diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/ResponseListener.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/ResponseListener.java index d700859..32e9e90 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/ResponseListener.java +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/ResponseListener.java @@ -9,26 +9,26 @@ import javax.xml.parsers.ParserConfigurationException; import net.sourceforge.phpeclipse.xdebug.core.IPHPDebugEvent; import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils; -import net.sourceforge.phpeclipse.xdebug.core.PathMapItem; +//import net.sourceforge.phpeclipse.xdebug.core.PathMapItem; import net.sourceforge.phpeclipse.xdebug.core.XDebugCorePlugin; -import net.sourceforge.phpeclipse.xdebug.php.launching.IXDebugConstants; -import net.sourceforge.phpeclipse.xdebug.php.model.XDebugLineBreakpoint; -import net.sourceforge.phpeclipse.xdebug.php.model.XDebugTarget; +//import net.sourceforge.phpeclipse.xdebug.php.launching.IXDebugConstants; +//import net.sourceforge.phpeclipse.xdebug.php.model.XDebugLineBreakpoint; +//import net.sourceforge.phpeclipse.xdebug.php.model.XDebugTarget; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; +//import org.eclipse.core.runtime.IPath; +//import org.eclipse.core.runtime.Path; -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.runtime.CoreException; +//import org.eclipse.core.resources.IMarker; +//import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.debug.core.DebugEvent; -import org.eclipse.debug.core.DebugException; +//import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.model.IBreakpoint; -import org.eclipse.debug.core.model.ILineBreakpoint; +//import org.eclipse.debug.core.model.IBreakpoint; +//import org.eclipse.debug.core.model.ILineBreakpoint; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; @@ -41,162 +41,156 @@ import org.w3c.dom.CDATASection; */ public class ResponseListener extends Job { - - public class DebugResponse { + private Node parentNode; + private int fTransactionID=-1; + private String fCommand=""; + private String fStatus; + private String fReason; + private String fName; + private boolean fError; - private Node parentNode; - private int fTransactionID=-1; - private String fCommand=""; - private String fStatus; - private String fReason; - private String fName; - private boolean fError; - - private String fValue; - private String fType; - private String fAddress; + private String fValue; + private String fType; + private String fAddress; + + public synchronized void setParentNode (String xmlInput){ + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder=null; + Document doc=null; + try { + builder = factory.newDocumentBuilder(); + } catch (ParserConfigurationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + ByteArrayInputStream InputXMLStream = new ByteArrayInputStream(xmlInput.getBytes()); + + try { + doc = builder.parse(InputXMLStream); + } catch (SAXException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } - public synchronized void setParentNode (String xmlInput){ - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder=null; - Document doc=null; - try { - builder = factory.newDocumentBuilder(); - } catch (ParserConfigurationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - ByteArrayInputStream InputXMLStream = new ByteArrayInputStream(xmlInput.getBytes()); - - try { - doc = builder.parse(InputXMLStream); - } catch (SAXException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - parentNode=doc.getFirstChild(); - - fName=parentNode.getNodeName(); - String idStr = getAttributeValue("transaction_id"); - if (!"".equals(idStr)) - fTransactionID = Integer.parseInt(idStr); - fCommand = getAttributeValue("command"); - fStatus = getAttributeValue("status"); - fReason = getAttributeValue("reason"); + parentNode=doc.getFirstChild(); + + fName=parentNode.getNodeName(); + String idStr = getAttributeValue("transaction_id"); + if (!"".equals(idStr)) + fTransactionID = Integer.parseInt(idStr); + fCommand = getAttributeValue("command"); + fStatus = getAttributeValue("status"); + fReason = getAttributeValue("reason"); - if( fCommand.compareTo("eval") == 0 ) { - try { - Node property = parentNode.getFirstChild(); + if( fCommand.compareTo("eval") == 0 ) { + try { + Node property = parentNode.getFirstChild(); - NamedNodeMap listAttribute = property.getAttributes(); - Node attribute = listAttribute.getNamedItem("type"); - if (attribute !=null) { - fType = attribute.getNodeValue(); - } + NamedNodeMap listAttribute = property.getAttributes(); + Node attribute = listAttribute.getNamedItem("type"); + if (attribute !=null) { + fType = attribute.getNodeValue(); + } - Node attribute1 = listAttribute.getNamedItem("address"); - if (attribute1 !=null) { - fAddress = attribute1.getNodeValue(); - } - - Node firstChild1 = (Node) property.getFirstChild(); - - if( firstChild1 != null ) { - fValue = firstChild1.getNodeValue(); - } - } catch (Exception e) { - // TODO: handle exception + Node attribute1 = listAttribute.getNamedItem("address"); + if (attribute1 !=null) { + fAddress = attribute1.getNodeValue(); } - } else { - try { - CDATASection firstChild = (CDATASection) parentNode.getFirstChild(); - - if( firstChild != null ) { - fValue = parentNode.getFirstChild().getNodeValue(); - } - } catch (Exception e) { - // TODO: handle exception + + Node firstChild1 = (Node) property.getFirstChild(); + + if( firstChild1 != null ) { + fValue = firstChild1.getNodeValue(); } + } catch (Exception e) { + // TODO: handle exception } - } - - public String getAttributeValue (String AttributeName) { - String strValue = ""; - if (parentNode.hasAttributes()) { - NamedNodeMap listAttribute = parentNode.getAttributes(); - Node attribute = listAttribute.getNamedItem(AttributeName); - if (attribute !=null) - strValue = attribute.getNodeValue(); + } else { + try { + CDATASection firstChild = (CDATASection) parentNode.getFirstChild(); + + if( firstChild != null ) { + fValue = parentNode.getFirstChild().getNodeValue(); + } + } catch (Exception e) { + // TODO: handle exception } - return strValue; - } - - public synchronized Node getParentNode(){ - return parentNode; } - - public synchronized String getCommand() { - return fCommand; - } - public synchronized String getName() { - return fName; - } - - public synchronized String getValue() { - return fValue; - } - - public synchronized String getType() { - return fType; + } + + public String getAttributeValue (String AttributeName) { + String strValue = ""; + if (parentNode.hasAttributes()) { + NamedNodeMap listAttribute = parentNode.getAttributes(); + Node attribute = listAttribute.getNamedItem(AttributeName); + if (attribute !=null) + strValue = attribute.getNodeValue(); } + return strValue; + } + + public synchronized Node getParentNode(){ + return parentNode; + } + + public synchronized String getCommand() { + return fCommand; + } + public synchronized String getName() { + return fName; + } + + public synchronized String getValue() { + return fValue; + } - public synchronized String getAddress() { - return fAddress; - } + public synchronized String getType() { + return fType; + } - DebugResponse () { - fTransactionID = -1; - fCommand = ""; - fStatus = ""; - fReason = ""; - fName= ""; - } - - DebugResponse (String XMLInput) { - setParentNode(XMLInput); - } + public synchronized String getAddress() { + return fAddress; + } - public synchronized String getReason() { - return fReason; - } + DebugResponse() { + fTransactionID = -1; + fCommand = ""; + fStatus = ""; + fReason = ""; + fName= ""; + } + + DebugResponse(String XMLInput) { + setParentNode(XMLInput); + } - public synchronized String getStatus() { - return fStatus; - } + public synchronized String getReason() { + return fReason; + } - public synchronized int getTransactionID() { - return fTransactionID; - } - - public boolean isError() { - return fError; - } + public synchronized String getStatus() { + return fStatus; + } - public void setError(boolean error) { - fError = error; - } - + public synchronized int getTransactionID() { + return fTransactionID; + } + + public boolean isError() { + return fError; } - + public void setError(boolean error) { + fError = error; + } + } + private XDebugConnection fConnection; - //private XDebugTarget fDebugTarget; private DebugResponse lastResponse; public ResponseListener(XDebugConnection connection) { @@ -205,10 +199,7 @@ public class ResponseListener extends Job { fConnection=connection; lastResponse= new DebugResponse(); } - - - - + private void checkResponse(DebugResponse response) { Node node=response.getParentNode(); if (node.hasChildNodes()) { @@ -223,37 +214,19 @@ public class ResponseListener extends Job { } lastResponse.setError(false); if (response.getStatus().equals("stopping")) { - //if (response.getStatus().equals("stopped")) { - fConnection.close(); + //this.cancel(); fireEvent(IPHPDebugEvent.STOPPED); } else if (response.getStatus().equals("break") && response.getReason().equals("ok")){ - if (response.getCommand().equals("run")) { // breakpoint hit - int id=-1; - try { - id=fConnection.sendRequest("stack_get"); - } catch (DebugException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - String InputXML = fConnection.readData(); - if (InputXML != null) { - XDebugCorePlugin.log(IStatus.INFO, InputXML); - lastResponse.setParentNode(InputXML); - breakpointHit(lastResponse.getParentNode()); - } - - } else if (response.getCommand().equals("step_into")) { // step_into + if (response.getCommand().equals("run")) { + fireEvent(IPHPDebugEvent.BREAKPOINT_HIT, null); + } else if (response.getCommand().equals("step_into")) { fireEvent(IPHPDebugEvent.STEP_END); -// XDebugCorePlugin.log(IStatus.INFO,response.getCommand()+" STEP_END sent"); - } else if (response.getCommand().equals("step_over")) { // step_over + } else if (response.getCommand().equals("step_over")) { fireEvent(IPHPDebugEvent.STEP_END); -// XDebugCorePlugin.log(IStatus.INFO,response.getCommand()+" STEP_END sent"); - } else if (response.getCommand().equals("step_out")) { // step_over + } else if (response.getCommand().equals("step_out")) { fireEvent(IPHPDebugEvent.STEP_END); -// XDebugCorePlugin.log(IStatus.INFO,response.getCommand()+" STEP_END sent"); } } - } protected void fireEvent(int detail) { @@ -266,56 +239,6 @@ public class ResponseListener extends Job { event.setData(data); DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] {event}); } - - - protected void 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"); - IBreakpoint[] breakpoints = XDebugCorePlugin.getBreakpoints(); - for (int i = 0; i < breakpoints.length; i++) { - IBreakpoint breakpoint = breakpoints[i]; - if (supportsBreakpoint(breakpoint)) { - if (breakpoint instanceof ILineBreakpoint) { - ILineBreakpoint lineBreakpoint = (ILineBreakpoint) breakpoint; - try { - if (breakpoint.isEnabled()) { - IMarker marker = breakpoint.getMarker(); - if (marker != null) { - String endfilename; - - if( XDebugCorePlugin.getDefault().getXDebugProxy().getTarget().getProcess() == null ) { - endfilename = marker.getResource().getLocation().lastSegment(); - } else { - endfilename = marker.getResource().getLocation().toOSString(); - } - - if(PHPDebugUtils.unescapeString(filename).endsWith(endfilename) && (lineBreakpoint.getLineNumber() == lineNumber) ) { - fireEvent(IPHPDebugEvent.BREAKPOINT_HIT,breakpoint); - break; - } - } - } - } catch (CoreException e) { - } - } - } - } - } - -// DebugEvent event = new DebugEvent(this, DebugEvent.MODEL_SPECIFIC, IPHPDebugEvent.STEP_END); -// DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] {event}); - } - - private boolean supportsBreakpoint(IBreakpoint breakpoint) { - if (breakpoint.getModelIdentifier().equals(IXDebugConstants.ID_PHP_DEBUG_MODEL)) { - return true; - } - return false; - } - - /* (non-Javadoc) * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) @@ -327,21 +250,12 @@ public class ResponseListener extends Job { if (InputXML != null) { XDebugCorePlugin.log(IStatus.INFO, InputXML); lastResponse.setParentNode(InputXML); -// if (lastResponse.getName() == "init") { -// Node myNode=lastResponse.getParentNode(); -// appID = PHPDebugUtils.getAttributeValue(myNode, "appid"); -// fileuri = PHPDebugUtils.getAttributeValue(myNode, "fileuri"); -// fDebugTarget.started(); -// fDebugTarget.fireCreationEvent(); if (lastResponse.getName() == "response") { fConnection.addResponse(lastResponse,lastResponse.getTransactionID()); checkResponse(lastResponse); } -// fConnection.addResponse(lastResponse,lastResponse.getTransactionID()); -// lastResponse.notifyWait(); } } return Status.OK_STATUS; } - -} +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/XDebugConnection.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/XDebugConnection.java index c2d800c..415a808 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/XDebugConnection.java +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/XDebugConnection.java @@ -7,41 +7,19 @@ import java.io.DataInputStream; import java.io.EOFException; import java.io.IOException; import java.io.OutputStreamWriter; -//import java.io.UnsupportedEncodingException; -import java.net.MalformedURLException; import java.net.Socket; -import java.net.URL; -import net.sourceforge.phpeclipse.xdebug.core.AbstractDebugConnection; import net.sourceforge.phpeclipse.xdebug.core.Base64; import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils; import net.sourceforge.phpeclipse.xdebug.core.XDebugCorePlugin; import net.sourceforge.phpeclipse.xdebug.core.xdebug.ResponseListener.DebugResponse; -import net.sourceforge.phpeclipse.xdebug.php.model.XDebugAbstractValue; -import net.sourceforge.phpeclipse.xdebug.php.model.XDebugLineBreakpoint; -import net.sourceforge.phpeclipse.xdebug.php.model.XDebugStackFrame; -import net.sourceforge.phpeclipse.xdebug.php.model.XDebugThread; -import net.sourceforge.phpeclipse.xdebug.php.model.XDebugVariable; - -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; -//import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.IBreakpoint; -import org.eclipse.debug.core.model.ILineBreakpoint; -import org.eclipse.debug.core.model.IStackFrame; -import org.eclipse.debug.core.model.IVariable; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; /** * @author Christian Perkonig * */ -public class XDebugConnection extends AbstractDebugConnection { +public class XDebugConnection { int fTransactionID = 0; private Socket fDebugSocket; private OutputStreamWriter fDebugWriter; @@ -49,35 +27,47 @@ public class XDebugConnection extends AbstractDebugConnection { private ResponseList fResponseList; private ResponseListener fResponseListener; + protected boolean fInitialized = false; + protected boolean fIsClosed = true; + + protected String fSessionID = ""; + + public String getSessionID() { + return fSessionID; + } + public boolean isInitialized() { + return fInitialized; + } + + public boolean isClosed() { + return fIsClosed; + } + public XDebugConnection(Socket debugSocket, DataInputStream reader, OutputStreamWriter writer) { fResponseList = new ResponseList(); fDebugWriter = writer; fDebugReader = reader; fDebugSocket = debugSocket; fTransactionID = 0; - init(); - } - - private void init() { fInitialized = false; - String initString=readData(); + String initString = readData(); XDebugCorePlugin.log(IStatus.INFO,initString); - int startIdx=initString.indexOf("idekey=\""); - if (startIdx==-1) + int startIdx = initString.indexOf("idekey=\""); + if (startIdx == -1) return; - startIdx+=8; + startIdx += 8; int endIdx=initString.indexOf('"',startIdx); if (endIdx==-1) return; - fSessionID=initString.substring(startIdx,endIdx); + fSessionID = initString.substring(startIdx,endIdx); - fInitialized=true; - fIsClosed=false; - fResponseListener=new ResponseListener(this); + fInitialized = true; + fIsClosed = false; + fResponseListener = new ResponseListener(this); } - + protected String readData() { byte byteBuffer[]=null,b; int count=0; @@ -87,12 +77,10 @@ public class XDebugConnection extends AbstractDebugConnection { count = count * 10 + b - '0'; // count=count*10+Integer.parseInt(b); } -// System.out.println(count); byteBuffer = new byte[count]; int readCount=0; int attempts=0; - while ((count >0) && (attempts < 50)) { -// while ((count >0) && (attempts <5)) { + while ((count >0) && (attempts <5)) { int rc=fDebugReader.read(byteBuffer,readCount,count); count-=rc; readCount+=rc; @@ -115,43 +103,17 @@ public class XDebugConnection extends AbstractDebugConnection { return new String(byteBuffer); } - - /** - * Sends a request to the Debugengine and waits for an OK. - * - * @param command debug command - * @throws DebugException if the request fails - */ - - - public int sendRequest(String command) throws DebugException { - return sendRequest(command,""); - } - - public DebugResponse sendRequestA(String command, String parameter) { - int result = -1; + public DebugResponse sendRequest(String command, String arguments) { + int id = -1; - try { - result = sendRequest(command, parameter); - } catch( DebugException e ){ - e.printStackTrace(); - } + id = _sendRequest(command, arguments); + + DebugResponse response = getResponse(id); - DebugResponse response = getResponse(result); - return response; } - - /** - * Sends a request to the Debugengine. - * - * @param command debug command - * @arguments arguments for the command - * @throws DebugException if the request fails - */ - - public synchronized int sendRequest(String command, String arguments) throws DebugException { - + + private synchronized int _sendRequest(String command, String arguments) { XDebugCorePlugin.log(IStatus.INFO,command+" -i "+fTransactionID+" "+arguments); synchronized (fDebugSocket) { try { @@ -162,41 +124,27 @@ public class XDebugConnection extends AbstractDebugConnection { fDebugWriter.write(0); fDebugWriter.flush(); } catch (IOException e) { - //e.printStackTrace(); + e.printStackTrace(); } } + return fTransactionID++; } - /* (non-Javadoc) - * @see net.sourceforge.phpeclipse.xdebug.core.IDebugConnection#featureGet(java.lang.String) - */ - public DebugResponse featureGet(String featureName) { - int id=-1; + public DebugResponse eval(String Expression) { + String encoded = Base64.encodeBytes(Expression.getBytes()); - try { - id= sendRequest("feature_get","-n "+featureName); - } catch (DebugException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - DebugResponse response = getResponse(id); + return sendRequest("eval", "-- "+encoded); + } - return response; + public DebugResponse featureGet(String featureName) { + return sendRequest("feature_get","-n "+featureName); } public boolean featureSet(String featureName, String value) { - int id=-1; - - try { - id= sendRequest("feature_set","-n "+featureName + " -v " + value); - } catch (DebugException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + DebugResponse id = sendRequest("feature_set","-n "+featureName + " -v " + value); - if (getResponse(id).getAttributeValue("success").equals("1") ) + if (id.getAttributeValue("success").equals("1") ) return true; else return false; @@ -207,161 +155,73 @@ public class XDebugConnection extends AbstractDebugConnection { } protected void addResponse(DebugResponse response, int id) { - fResponseList.add(response,id); - + fResponseList.add(response, id); } - /* (non-Javadoc) - * @see net.sourceforge.phpeclipse.xdebug.core.IDebugConnection#addBreakpoint(org.eclipse.debug.core.model.IBreakpoint) - */ - public void addBreakpoint(IBreakpoint breakpoint, IPath filePath) throws DebugException { - try { - if (breakpoint.isEnabled()) { - IMarker marker = breakpoint.getMarker(); - if (marker != null) { - try { - String arg; - - arg = "-t line -f file://"+PHPDebugUtils.escapeString(filePath.toString())+" -n "+((ILineBreakpoint)breakpoint).getLineNumber(); - int id = sendRequest("breakpoint_set", arg); - String bpid = getResponse(id).getAttributeValue("id"); - - if (!"".equals(bpid)) - marker.setAttribute(XDebugLineBreakpoint.BREAKPOINT_ID,Integer.parseInt(bpid)); - - } catch (CoreException e) { - XDebugCorePlugin.log(IStatus.INFO,"Exception set break point"); - } - } - } - } catch (CoreException e) { - XDebugCorePlugin.log(IStatus.INFO,"Exception in breakpoint"); - } - } - - /* (non-Javadoc) - * @see net.sourceforge.phpeclipse.xdebug.core.IDebugConnection#removeBreakpoint(int) - */ - public void removeBreakpoint(IBreakpoint breakpoint) throws DebugException { - try { - int id =((XDebugLineBreakpoint)breakpoint).getID(); - if (id >0) - sendRequest("breakpoint_remove","-d "+id); - } catch (CoreException e) { - } - } - - /* (non-Javadoc) - * @see net.sourceforge.phpeclipse.xdebug.core.IDebugConnection#getStackFrames(net.sourceforge.phpeclipse.xdebug.php.model.XDebugThread) - */ - public IStackFrame[] getStackFrames(XDebugThread thread) throws DebugException { - int id = sendRequest("stack_get"); - DebugResponse lastResponse = getResponse(id); - if (lastResponse.isError()) - return new IStackFrame[0]; - Node response = lastResponse.getParentNode(); - NodeList frames = response.getChildNodes(); - IStackFrame[] theFrames = new IStackFrame[frames.getLength()]; - for (int i = 0; i < frames.getLength(); i++) { - Node stackNode = frames.item(i); - XDebugStackFrame frame = new XDebugStackFrame(thread, i); - String level =PHPDebugUtils.getAttributeValue(stackNode,"level"); - if (!"".equals(level)) - frame.setLevel(Integer.parseInt(level)); - - frame.setType(PHPDebugUtils.getAttributeValue(stackNode,"type")); - String fileName=PHPDebugUtils.unescapeString(PHPDebugUtils.getAttributeValue(stackNode,"filename")); - String lineNo=PHPDebugUtils.getAttributeValue(stackNode,"lineno"); - - if (!"".equals(lineNo)) - frame.setLineNumber(Integer.parseInt(lineNo)); - - frame.setWhere(PHPDebugUtils.getAttributeValue(stackNode,"where")); - - try { - frame.setFullName(new URL(fileName)); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - - frame.incrementStepCounter(); - - theFrames[i] = frame; - } + + public DebugResponse breakpointSet(String file, int lineNumber) { + String arg; - return theFrames; + arg = "-t line -f file://"+PHPDebugUtils.escapeString(file)+" -n " + lineNumber; + return sendRequest("breakpoint_set", arg); } - - /* (non-Javadoc) - * @see net.sourceforge.phpeclipse.xdebug.core.IDebugConnection#stepOver() - */ - public void stepOver() throws DebugException { - sendRequest ("step_over"); + + public DebugResponse breakpointRemove(int id) { + return sendRequest("breakpoint_set", "-d " + id); } - /* (non-Javadoc) - * @see net.sourceforge.phpeclipse.xdebug.core.IDebugConnection#stepInto() - */ - public void stepInto() throws DebugException { - sendRequest("step_into"); + public DebugResponse stackGet(int Level) { + /*if (Level > -1) { + return sendRequest("stack_get", "-d " + Level); + } else {*/ + return sendRequest("stack_get", ""); + //} + } + + public void stepOver() { + sendRequest("step_over", ""); } - /* (non-Javadoc) - * @see net.sourceforge.phpeclipse.xdebug.core.IDebugConnection#stepOut() - */ - public void stepOut() throws DebugException { - sendRequest ("step_out"); + public void stepInto() { + sendRequest("step_into", ""); } - /* (non-Javadoc) - * @see net.sourceforge.phpeclipse.xdebug.core.IDebugConnection#run() - */ - public void run() throws DebugException { - sendRequest ("run"); + public void stepOut() { + sendRequest("step_out", ""); } - /* (non-Javadoc) - * @see net.sourceforge.phpeclipse.xdebug.core.IDebugConnection#stop() - */ - public void stop() throws DebugException { - sendRequest ("stop"); + public void run() { + sendRequest("run", ""); } - /* (non-Javadoc) - * @see net.sourceforge.phpeclipse.xdebug.core.IDebugConnection#setResponseListerner(org.eclipse.core.runtime.jobs.Job) - */ - public void setResponseListerner(Job listener) { -// fResponseListener=(ResponseListener)listener;; + public void stop() { + sendRequest("stop", ""); } - /* (non-Javadoc) - * @see net.sourceforge.phpeclipse.xdebug.core.IDebugConnection#startListener() - */ public void startListener() { fResponseListener.schedule(); } + + public DebugResponse propertySet(String Name, String Value) { + String str = Base64.encodeBytes(Value.getBytes()); + int len = str.length(); - public boolean setVarValue(String name, String value) { - int id=-1; - String str=Base64.encodeBytes(value.getBytes()); - int len=str.length(); + return sendRequest("property_set", "-n " + Name + " -l " + len + " -- " + str); + } + + public boolean setVarValue(String Name, String Value) { + DebugResponse dr = propertySet(Name, Value); - try { - id =sendRequest("property_set","-n "+name+" -l "+len + " -- "+str); - } catch (DebugException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - DebugResponse dr=getResponse(id); if ((dr.getAttributeValue("success")).equals("1")) return true; return false; - } public void close() { - fResponseListener.cancel(); + fIsClosed = true; + //fResponseListener.cancel(); + //fResponseListener = null; try { fDebugReader.close(); fDebugWriter.close(); @@ -369,170 +229,11 @@ public class XDebugConnection extends AbstractDebugConnection { } catch (IOException e) { e.printStackTrace(); } + fResponseListener.cancel(); fIsClosed=true; } - - - public XDebugVariable getVariableFromNodeA(XDebugStackFrame frame, Node property) { - String address = PHPDebugUtils.getAttributeValue(property, "address"); - String varName; - String Name = PHPDebugUtils.getAttributeValue(property,"name"); - if ("".equals(Name)) { - varName = address; - } else { - varName = Name; - } - - String varEncoding=PHPDebugUtils.getAttributeValue(property,"encoding"); - int varNumChildren = 0; - if (PHPDebugUtils.getAttributeValue(property,"numchildren").equals("")) - varNumChildren = 0; - else - varNumChildren=Integer.parseInt(PHPDebugUtils.getAttributeValue(property,"numchildren")); - - String typeName=PHPDebugUtils.getAttributeValue(property,"type"); - - XDebugVariable variable = new XDebugVariable(typeName, varName); - variable.setEncoding(varEncoding); - variable.setNumChildren(varNumChildren); - XDebugAbstractValue val=null; - try { - val = (XDebugAbstractValue) variable.getValue(); - } catch (DebugException e1) { - e1.printStackTrace(); - } - if (val.getType()!= XDebugAbstractValue.VALUETYPE_UNINITIALIZED) { - if (variable.hasChildren()) { - NodeList varNodes = property.getChildNodes(); - val.renderValueString(""+varNodes.getLength()); - IVariable[] variables = new IVariable[varNodes.getLength()]; - for (int i = 0; i pathMap) throws CoreException { - super(null); - init(launch, process, ideKey,pathMap); - }*/ - - private void init(ILaunch launch, IProcess process, String ideKey/*,List pathMap*/) { + */ + public XDebugTarget(ILaunch launch, IProcess process, String ideKey) throws CoreException { fLaunch = launch; fProcess = process; fTarget = this; @@ -197,8 +172,6 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, ILaunch * @see org.eclipse.debug.core.model.ITerminate#terminate() */ public void terminate() throws DebugException { - //IThread t = fThreads.length(); - //fTerminated=true; XDebugProxy proxy=XDebugCorePlugin.getDefault().getXDebugProxy(); proxy.stop(); proxy.removeProxyEventListener(this,fIdeKey); @@ -217,7 +190,6 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, ILaunch * @see org.eclipse.debug.core.model.ISuspendResume#canResume() */ public boolean canResume() { -// return !isTerminated() && isSuspended(); return false; } @@ -225,7 +197,6 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, ILaunch * @see org.eclipse.debug.core.model.ISuspendResume#canSuspend() */ public boolean canSuspend() { -// return !isTerminated() && !isSuspended(); return false; } @@ -293,18 +264,28 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, ILaunch for (int i = 0; i < pathMap.size(); i++) { pmi = new PathMapItem((String) pathMap.get(i)); IPath local = (IPath)pmi.getLocalPath().clone(); - local = local./*removeFirstSegments(1).*/makeAbsolute(); + local = local.makeAbsolute(); int matchedSegments = local.segmentCount(); if (local.matchingFirstSegments(cp) == matchedSegments) { IPath newPath = pmi.getRemotePath(); - //newPath = newPath.removeFirstSegments(1); newPath = newPath.append(path.removeFirstSegments(matchedSegments)); newPath = newPath.makeAbsolute(); if (supportsBreakpoint(breakpoint)) { try { - fDebugConnection.addBreakpoint(breakpoint, newPath); + if (breakpoint.isEnabled()) { + if (marker != null) { + //fDebugConnection.addBreakpoint(breakpoint, newPath); + DebugResponse dr = fDebugConnection.breakpointSet(newPath.toString(), ((ILineBreakpoint)breakpoint).getLineNumber()); + String bpid = dr.getAttributeValue("id"); + + if (!"".equals(bpid)) + marker.setAttribute(XDebugLineBreakpoint.BREAKPOINT_ID,Integer.parseInt(bpid)); + } + } } catch (DebugException e) { e.printStackTrace(); + } catch (CoreException e) { + e.printStackTrace(); } } } @@ -312,9 +293,19 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, ILaunch } else { if (supportsBreakpoint(breakpoint)) { try { - fDebugConnection.addBreakpoint(breakpoint, path); + if (breakpoint.isEnabled()) { + if (marker != null) { + DebugResponse dr = fDebugConnection.breakpointSet(path.toString(), ((ILineBreakpoint)breakpoint).getLineNumber()); + String bpid = dr.getAttributeValue("id"); + + if (!"".equals(bpid)) + marker.setAttribute(XDebugLineBreakpoint.BREAKPOINT_ID,Integer.parseInt(bpid)); + } + } } catch (DebugException e) { e.printStackTrace(); + } catch (CoreException e) { + e.printStackTrace(); } } } @@ -327,7 +318,9 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, ILaunch public void breakpointRemoved(IBreakpoint breakpoint, IMarkerDelta delta) { if (supportsBreakpoint(breakpoint)) { try { - fDebugConnection.removeBreakpoint(breakpoint); + int id =((XDebugLineBreakpoint)breakpoint).getID(); + if (id >0) + fDebugConnection.breakpointRemove(id); } catch (CoreException e) { } } @@ -391,7 +384,7 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, ILaunch fThread.setBreakpoints(null); fThread.setStepping(false); - /*boolean CanDisconnect =*/ Integer.parseInt(fDebugConnection.featureGet("detach").getValue()) /*!= 0*/; + Integer.parseInt(fDebugConnection.featureGet("detach").getValue()); System.out.println("in Target.started()"); DebugResponse response = fDebugConnection.featureGet("max_children"); @@ -410,7 +403,6 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, ILaunch installDeferredBreakpoints(); try { resume(); -// step(); } catch (DebugException e) { e.printStackTrace(); } @@ -445,8 +437,42 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, ILaunch * @return the current stack frames in the target * @throws DebugException if unable to perform the request */ - protected IStackFrame[] getStackFrames() throws DebugException { - return fDebugConnection.getStackFrames(fThread); + public IStackFrame[] getStackFrames() throws DebugException { + DebugResponse lastResponse = fDebugConnection.stackGet(0); + + if (lastResponse.isError()) + return new IStackFrame[0]; + Node response = lastResponse.getParentNode(); + NodeList frames = response.getChildNodes(); + IStackFrame[] theFrames = new IStackFrame[frames.getLength()]; + for (int i = 0; i < frames.getLength(); i++) { + Node stackNode = frames.item(i); + XDebugStackFrame frame = new XDebugStackFrame(fThread, i); + String level =PHPDebugUtils.getAttributeValue(stackNode,"level"); + if (!"".equals(level)) + frame.setLevel(Integer.parseInt(level)); + + frame.setType(PHPDebugUtils.getAttributeValue(stackNode,"type")); + String fileName=PHPDebugUtils.unescapeString(PHPDebugUtils.getAttributeValue(stackNode,"filename")); + String lineNo=PHPDebugUtils.getAttributeValue(stackNode,"lineno"); + + if (!"".equals(lineNo)) + frame.setLineNumber(Integer.parseInt(lineNo)); + + frame.setWhere(PHPDebugUtils.getAttributeValue(stackNode,"where")); + + try { + frame.setFullName(new URL(fileName)); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + + frame.incrementStepCounter(); + + theFrames[i] = frame; + } + + return theFrames; } /** @@ -489,75 +515,75 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, ILaunch * @return variable value * @throws DebugException if the request fails */ - protected IValue getVariableValue(XDebugVariable variable) throws DebugException { + /*protected IValue getVariableValue(XDebugVariable variable) throws DebugException { return null; - } + }*/ /** * Returns the values on the data stack (top down) * * @return the values on the data stack (top down) */ - public IValue[] getDataStack() throws DebugException { + /*public IValue[] getDataStack() throws DebugException { return new IValue[0]; - } + }*/ public boolean setVarValue(String name, String value) { return fDebugConnection.setVarValue(name,value); } public void handleDebugEvents(DebugEvent[] events) { - for (int i=0;i