X-Git-Url: http://secure.phpeclipse.com
diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugThread.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugThread.java
index 4581ee5..2e00970 100644
--- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugThread.java
+++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugThread.java
@@ -6,6 +6,9 @@
*/
package net.sourceforge.phpeclipse.xdebug.php.model;
+import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils;
+import net.sourceforge.phpeclipse.xdebug.core.xdebug.XDebugResponse;
+
import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.DebugPlugin;
@@ -13,6 +16,8 @@ import org.eclipse.debug.core.IDebugEventSetListener;
import org.eclipse.debug.core.model.IBreakpoint;
import org.eclipse.debug.core.model.IStackFrame;
import org.eclipse.debug.core.model.IThread;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
/**
* @author Axel
@@ -21,20 +26,16 @@ import org.eclipse.debug.core.model.IThread;
* Window - Preferences - Java - Code Style - Code Templates
*/
public class XDebugThread extends XDebugElement implements IThread, IDebugEventSetListener {
-
- /**
- * Breakpoints this thread is suspended at or null
- * if none.
- */
-
- private IStackFrame[] fStackFrames=null;
+ private XDebugStackFrame[] fStackFrames;
private IBreakpoint[] fBreakpoints;
- /**
- * Whether this thread is stepping
- */
+ /* Whether this thread is stepping */
private boolean fStepping = false;
+ private boolean fTerminated = false;
+
+ private int fStepCount = 0;
+ private int fCurrentStepCount = 0;
/**
* Constructs a new thread for the given target
@@ -44,36 +45,90 @@ public class XDebugThread extends XDebugElement implements IThread, IDebugEventS
public XDebugThread(XDebugTarget target) {
super(target);
DebugPlugin.getDefault().addDebugEventListener(this);
+ fStackFrames = null;
}
- /* (non-Javadoc)
- * @see org.eclipse.debug.core.model.IThread#getStackFrames()
- */
+ public void incrementStepCounter() {
+ fStepCount++;
+ }
public IStackFrame[] getStackFrames() throws DebugException {
- if (isSuspended()) {
- if (fStackFrames==null)
- {
-// XDebugCorePlugin.log(IStatus.INFO,"vor getStackFrames");
- fStackFrames=((XDebugTarget) getDebugTarget()).getStackFrames();
-// XDebugCorePlugin.log(IStatus.INFO,"nach getStackFrames");
- }
- return fStackFrames;
- } else {
+ if (!isSuspended()) {
return new IStackFrame[0];
}
+
+ if (fStepCount > fCurrentStepCount) {
+ XDebugResponse dr = ((XDebugTarget) getDebugTarget()).getStackFrames();
+ XDebugStackFrame[] newStackFrames = _getStackFrames(dr);
+
+ /*if (fStackFrames != null) {
+ if (newStackFrames.length >= fStackFrames.length) {
+ int delta = newStackFrames.length - fStackFrames.length + 1;
+
+ for (int i = fStackFrames.length - 1; i >= 0; i--) {
+ if (fStackFrames[i].equals(newStackFrames[newStackFrames.length - delta])) {
+ int b = 2; b++;
+ //((XDebugStackFrame) newStackFrames[newStackFrames.length - delta]).evaluateChange((XDebugStackFrame) fStackFrames[i]);
+ } else if (fStackFrames[i].isSameStackFrame(newStackFrames[newStackFrames.length - delta])) {
+ int b = 2; b++;
+ //((XDebugStackFrame) newStackFrames[newStackFrames.length - delta]).evaluateChange((XDebugStackFrame) fStackFrames[i]);
+ }
+
+ delta ++;
+ }
+ } else {
+ fStackFrames = newStackFrames;
+ }
+ } else {
+ fStackFrames = newStackFrames;
+ }*/
+
+ fCurrentStepCount++;
+
+ fStackFrames = newStackFrames;
+ }
+
+ return fStackFrames;
+ }
+
+
+ private XDebugStackFrame[] _getStackFrames(XDebugResponse lastResponse) {
+ if (lastResponse.isError()) {
+ return new XDebugStackFrame[0];
+ }
+
+ Node response = lastResponse.getParentNode();
+ NodeList frames = response.getChildNodes();
+ XDebugStackFrame[] theFrames = new XDebugStackFrame[frames.getLength()];
+
+ for (int i = 0; i < frames.getLength(); i++) {
+ Node stackNode = frames.item(i);
+ String fileName=PHPDebugUtils.unescapeString(PHPDebugUtils.getAttributeValue(stackNode,"filename"));
+ String lineNo = PHPDebugUtils.getAttributeValue(stackNode,"lineno");
+
+ XDebugStackFrame frame = new XDebugStackFrame(this/*fThread*/, i, /*type*/PHPDebugUtils.getAttributeValue(stackNode,"type"), /*lineno*/Integer.parseInt(lineNo), /*where*/PHPDebugUtils.getAttributeValue(stackNode,"where"), fileName);
+
+ frame.incrementStepCounter();
+
+ theFrames[i] = frame;
+ }
+
+ return theFrames;
}
+
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IThread#hasStackFrames()
*/
public boolean hasStackFrames() throws DebugException {
return isSuspended();
}
+
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IThread#getPriority()
*/
public int getPriority() throws DebugException {
return 0;
}
+
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IThread#getTopStackFrame()
*/
@@ -82,17 +137,17 @@ public class XDebugThread extends XDebugElement implements IThread, IDebugEventS
if (frames.length > 0) {
return frames[0];
}
+
return null;
}
+
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IThread#getName()
*/
public String getName() throws DebugException {
-// if (fStackFrames!=null)
-// return fStackFrames[0].getName();
-// else
- return "Thread[1]";
+ return "Thread[1]";
}
+
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IThread#getBreakpoints()
*/
@@ -102,6 +157,7 @@ public class XDebugThread extends XDebugElement implements IThread, IDebugEventS
}
return fBreakpoints;
}
+
/**
* Sets the breakpoints this thread is suspended at, or null
* if none.
@@ -112,109 +168,125 @@ public class XDebugThread extends XDebugElement implements IThread, IDebugEventS
protected void setBreakpoints(IBreakpoint[] breakpoints) {
fBreakpoints = breakpoints;
}
+
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.ISuspendResume#canResume()
*/
public boolean canResume() {
return isSuspended();
}
+
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.ISuspendResume#canSuspend()
*/
public boolean canSuspend() {
- return !isSuspended();
+ return !isTerminated() && !isSuspended();
}
+
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.ISuspendResume#isSuspended()
*/
public boolean isSuspended() {
return getDebugTarget().isSuspended();
}
+
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.ISuspendResume#resume()
*/
public void resume() throws DebugException {
- fStackFrames=null;
- fBreakpoints=null;
+ fBreakpoints = null;
getDebugTarget().resume();
}
+
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.ISuspendResume#suspend()
*/
public void suspend() throws DebugException {
getDebugTarget().suspend();
}
+
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IStep#canStepInto()
*/
public boolean canStepInto() {
return isSuspended();
}
+
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IStep#canStepOver()
*/
public boolean canStepOver() {
return isSuspended();
}
+
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IStep#canStepReturn()
*/
public boolean canStepReturn() {
- if (fStackFrames!=null)
- return (fStackFrames.length>1);
- else
+ if (fStackFrames != null) {
+ return (fStackFrames.length > 1);
+ } else {
return false;
+ }
}
+
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IStep#isStepping()
*/
public boolean isStepping() {
return fStepping;
}
+
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IStep#stepInto()
*/
public void stepInto() throws DebugException {
- fStackFrames=null;
- fBreakpoints=null;
- ((XDebugTarget)getDebugTarget()).step_into();
+ fBreakpoints = null;
+ ((XDebugTarget) getDebugTarget()).step_into();
}
+
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IStep#stepOver()
*/
public void stepOver() throws DebugException {
- fStackFrames=null;
- fBreakpoints=null;
- ((XDebugTarget)getDebugTarget()).step_over();
+ fBreakpoints = null;
+ ((XDebugTarget) getDebugTarget()).step_over();
}
+
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IStep#stepReturn()
*/
public void stepReturn() throws DebugException {
- fStackFrames=null;
- fBreakpoints=null;
- ((XDebugTarget)getDebugTarget()).step_out();
-
+ fBreakpoints = null;
+ ((XDebugTarget) getDebugTarget()).step_out();
}
+
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.ITerminate#canTerminate()
*/
public boolean canTerminate() {
return !isTerminated();
}
+
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.ITerminate#isTerminated()
*/
public boolean isTerminated() {
- return getDebugTarget().isTerminated();
+ return fTerminated;
}
+
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.ITerminate#terminate()
*/
public void terminate() throws DebugException {
- getDebugTarget().terminate();
+ ((XDebugTarget) getDebugTarget()).getDebugConnection().stop();
+ fTerminated = true;
}
+ public void terminated() throws DebugException {
+ fTerminated = true;
+ }
+
/**
* Sets whether this thread is stepping
*
@@ -225,13 +297,31 @@ public class XDebugThread extends XDebugElement implements IThread, IDebugEventS
}
public void handleDebugEvents(DebugEvent[] events) {
- DebugEvent de=events[0];
- System.out.println(de.toString());
-
+ DebugEvent de = events[0];
+ System.out.println(de.toString());
}
public void removeEventListeners() {
DebugPlugin.getDefault().removeDebugEventListener(this);
-
}
-}
+
+ /**
+ * Fires a RESUME
event for this element with
+ * the given detail.
+ *
+ * @param detail event detail code
+ */
+ public void fireResumeEvent(int detail) {
+ fireEvent(new DebugEvent(this, DebugEvent.RESUME, detail));
+ }
+
+ /**
+ * Fires a SUSPEND
event for this element with
+ * the given detail.
+ *
+ * @param detail event detail code
+ */
+ public void fireSuspendEvent(int detail) {
+ fireEvent(new DebugEvent(this, DebugEvent.SUSPEND, detail));
+ }
+}
\ No newline at end of file