Merge xdebug from 1.3.x.
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.core / src / net / sourceforge / phpeclipse / xdebug / php / model / XDebugThread.java
index 366badf..505b5a6 100644 (file)
@@ -6,6 +6,13 @@
  */
 package net.sourceforge.phpeclipse.xdebug.php.model;
 
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils;
+//import net.sourceforge.phpeclipse.xdebug.core.xdebug.ResponseListener.DebugResponse;
+import net.sourceforge.phpeclipse.xdebug.core.xdebug.ResponseListener.XDebugResponse;
+
 import org.eclipse.debug.core.DebugEvent;
 import org.eclipse.debug.core.DebugException;
 import org.eclipse.debug.core.DebugPlugin;
@@ -13,6 +20,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
@@ -52,8 +61,11 @@ public class XDebugThread extends XDebugElement implements IThread, IDebugEventS
                
                if (isSuspended()) {    
                        if (fStepCount > fCurrentStepCount) {
-                               newStackFrames = ((XDebugTarget) getDebugTarget()).getStackFrames();
+                               //newStackFrames = ((XDebugTarget) getDebugTarget()).getStackFrames();
                                
+                               XDebugResponse dr = ((XDebugTarget) getDebugTarget()).getStackFrames();
+                               newStackFrames = _getStackFrames(dr);
+
                                for (int i = 0; i < newStackFrames.length; i++) {
                                        ((XDebugStackFrame)newStackFrames[i]).getVariables();
                                }
@@ -86,6 +98,43 @@ public class XDebugThread extends XDebugElement implements IThread, IDebugEventS
                }
        }
        
+       private IStackFrame[] _getStackFrames(XDebugResponse lastResponse) {
+               //IStackFrame[] newStackFrames = null;
+
+       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(this/*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 /*newStackFrames*/theFrames;
+       }
+                       
        /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.IThread#hasStackFrames()
         */