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 9f31828..d032172 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,12 +3,14 @@ */ package net.sourceforge.phpeclipse.xdebug.php.model; +import java.net.MalformedURLException; +import java.net.URL; import java.util.List; -import net.sourceforge.phpeclipse.xdebug.core.AbstractDebugConnection; -import net.sourceforge.phpeclipse.xdebug.core.IDebugConnection; +import net.sourceforge.phpeclipse.xdebug.core.Base64; import net.sourceforge.phpeclipse.xdebug.core.IPHPDebugEvent; import net.sourceforge.phpeclipse.xdebug.core.IProxyEventListener; +import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils; import net.sourceforge.phpeclipse.xdebug.core.PathMapItem; import net.sourceforge.phpeclipse.xdebug.core.XDebugCorePlugin; import net.sourceforge.phpeclipse.xdebug.core.XDebugProxy; @@ -28,63 +30,42 @@ import org.eclipse.debug.core.ILaunchListener; import org.eclipse.debug.core.model.IBreakpoint; import org.eclipse.debug.core.model.IDebugTarget; +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.IStackFrame; import org.eclipse.debug.core.model.IThread; -import org.eclipse.debug.core.model.IValue; +//import org.eclipse.debug.core.model.IValue; import org.eclipse.debug.core.model.IVariable; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import net.sourceforge.phpeclipse.xdebug.core.xdebug.XDebugConnection; import net.sourceforge.phpeclipse.xdebug.core.xdebug.ResponseListener.DebugResponse; /** * @author Christian * */ -public class XDebugTarget extends XDebugElement implements IDebugTarget, ILaunchListener, IDebugEventSetListener, IProxyEventListener{ - // associated system process (VM) +public class XDebugTarget extends XDebugElement implements IDebugTarget, ILaunchListener, IDebugEventSetListener, IProxyEventListener { private IProcess fProcess; - // containing launch object private ILaunch fLaunch; - // debugPort private int fDebugPort; - // suspend state private boolean fSuspended = false; - // terminated state private boolean fTerminated = false; - // threads private XDebugThread fThread; private IThread[] fThreads; - private AbstractDebugConnection fDebugConnection; + private XDebugConnection fDebugConnection; private String fIdeKey; - public XDebugTarget() { - super(null); - } - - /** - * Constructs a new debug target in the given launch and waits until - * someone with the ideKey connects to the Debugproxy - * - * - * @param launch containing launch - * @param process process of the interpreter - * @param ideKey - * @exception CoreException if unable to connect to host - */ - - public XDebugTarget(ILaunch launch, IProcess process, String ideKey) throws CoreException { - init(launch, process, ideKey); - } - /** * Constructs a new debug target in the given launch and waits until * someone with the ideKey connects to the Debugproxy @@ -95,14 +76,8 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, ILaunch * @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, List 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