*/
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;
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
* Window - Preferences - Java - Code Style - Code Templates
*/
public class XDebugThread extends XDebugElement implements IThread, IDebugEventSetListener {
- private IStackFrame[] fStackFrames;
+ private XDebugStackFrame[] fStackFrames;
private IBreakpoint[] fBreakpoints;
public void incrementStepCounter() {
fStepCount++;
}
-
public IStackFrame[] getStackFrames() throws DebugException {
- IStackFrame[] newStackFrames = null;
+ if (!isSuspended()) {
+ return new IStackFrame[0];
+ }
- if (isSuspended()) {
- if (fStepCount > fCurrentStepCount) {
- newStackFrames = ((XDebugTarget) getDebugTarget()).getStackFrames();
-
- for (int i = 0; i < newStackFrames.length; i++) {
- ((XDebugStackFrame)newStackFrames[i]).getVariables();
- }
-
- 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 (((XDebugStackFrame) fStackFrames[i]).equals(((XDebugStackFrame) newStackFrames[newStackFrames.length - delta]))) {
- int b = 2; b++;
- //((XDebugStackFrame) newStackFrames[newStackFrames.length - delta]).evaluateChange((XDebugStackFrame) fStackFrames[i]);
- } else if (((XDebugStackFrame) fStackFrames[i]).isSameStackFrame(newStackFrames[newStackFrames.length - delta])) {
- //((XDebugStackFrame) newStackFrames[newStackFrames.length - delta]).evaluateChange((XDebugStackFrame) fStackFrames[i]);
- }
-
- delta ++;
+ 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]);
}
- } else {
+
+ delta ++;
}
+ } else {
+ fStackFrames = newStackFrames;
}
+ } else {
+ fStackFrames = newStackFrames;
+ }*/
- fCurrentStepCount++;
+ fCurrentStepCount++;
- fStackFrames = newStackFrames;
- }
- return fStackFrames;
- } else {
- return new IStackFrame[0];
+ 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()
*/
* @see org.eclipse.debug.core.model.ISuspendResume#isSuspended()
*/
public boolean isSuspended() {
- return fTarget.isSuspended();
+ return getDebugTarget().isSuspended();
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.ISuspendResume#resume()
*/
public void resume() throws DebugException {
- fBreakpoints=null;
- fTarget.resume();
+ fBreakpoints = null;
+ getDebugTarget().resume();
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.ISuspendResume#suspend()
*/
public void suspend() throws DebugException {
- fTarget.suspend();
+ getDebugTarget().suspend();
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IStep#stepInto()
*/
public void stepInto() throws DebugException {
- fBreakpoints=null;
- fTarget.step_into();
+ fBreakpoints = null;
+ ((XDebugTarget) getDebugTarget()).step_into();
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IStep#stepOver()
*/
public void stepOver() throws DebugException {
- fBreakpoints=null;
- fTarget.step_over();
+ fBreakpoints = null;
+ ((XDebugTarget) getDebugTarget()).step_over();
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IStep#stepReturn()
*/
public void stepReturn() throws DebugException {
- fBreakpoints=null;
- fTarget.step_out();
+ fBreakpoints = null;
+ ((XDebugTarget) getDebugTarget()).step_out();
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.ITerminate#terminate()
*/
public void terminate() throws DebugException {
- fTarget.getDebugConnection().stop();
+ ((XDebugTarget) getDebugTarget()).getDebugConnection().stop();
fTerminated = true;
}
public void removeEventListeners() {
DebugPlugin.getDefault().removeDebugEventListener(this);
}
+
+ /**
+ * Fires a <code>RESUME</code> 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 <code>SUSPEND</code> 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