Importing the XDebugProxy code in the HEAD. The repo was tagged with T_BEFORE_XDEBUGP...
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.core / src / net / sourceforge / phpeclipse / xdebug / php / model / XDebugThread.java
index 5c7b936..366badf 100644 (file)
@@ -16,77 +16,91 @@ import org.eclipse.debug.core.model.IThread;
 
 /**
  * @author Axel
- * 
- * TODO To change the template for this generated type comment go to Window -
- * Preferences - Java - Code Style - Code Templates
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
  */
-public class XDebugThread extends XDebugElement implements IThread,
-               IDebugEventSetListener {
-
-       /**
-        * Breakpoints this thread is suspended at or <code>null</code> if none.
-        */
-
-       private IStackFrame[] fStackFrames = null;
-
+public class XDebugThread extends XDebugElement implements IThread, IDebugEventSetListener {
+       private IStackFrame[]  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
         * 
-        * @param target
-        *            VM
+        * @param target VM
         */
        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");
+               IStackFrame[] newStackFrames = null;
+               
+               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 ++;
+                                               }
+                                       } else {
+                                       }
+                               }
+
+                               fCurrentStepCount++;
+
+                               fStackFrames = newStackFrames;
                        }
                        return fStackFrames;
                } else {
                        return new IStackFrame[0];
                }
        }
-
-       /*
-        * (non-Javadoc)
-        * 
+       
+       /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.IThread#hasStackFrames()
         */
        public boolean hasStackFrames() throws DebugException {
                return isSuspended();
        }
-
-       /*
-        * (non-Javadoc)
-        * 
+       
+       /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.IThread#getPriority()
         */
        public int getPriority() throws DebugException {
                return 0;
        }
-
-       /*
-        * (non-Javadoc)
-        * 
+       
+       /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.IThread#getTopStackFrame()
         */
        public IStackFrame getTopStackFrame() throws DebugException {
@@ -94,24 +108,18 @@ public class XDebugThread extends XDebugElement implements IThread,
                if (frames.length > 0) {
                        return frames[0];
                }
+               
                return null;
        }
-
-       /*
-        * (non-Javadoc)
-        * 
+       
+       /* (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]";
        }
 
-       /*
-        * (non-Javadoc)
-        * 
+       /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.IThread#getBreakpoints()
         */
        public IBreakpoint[] getBreakpoints() {
@@ -120,171 +128,140 @@ public class XDebugThread extends XDebugElement implements IThread,
                }
                return fBreakpoints;
        }
-
+       
        /**
         * Sets the breakpoints this thread is suspended at, or <code>null</code>
         * if none.
         * 
-        * @param breakpoints
-        *            the breakpoints this thread is suspended at, or
-        *            <code>null</code> if none
+        * @param breakpoints the breakpoints this thread is suspended at, or <code>null</code>
+        * if none
         */
        protected void setBreakpoints(IBreakpoint[] breakpoints) {
                fBreakpoints = breakpoints;
        }
-
-       /*
-        * (non-Javadoc)
-        * 
+       
+       /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.ISuspendResume#canResume()
         */
        public boolean canResume() {
                return isSuspended();
        }
-
-       /*
-        * (non-Javadoc)
-        * 
+       
+       /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.ISuspendResume#canSuspend()
         */
        public boolean canSuspend() {
-               return !isSuspended();
+               return !isTerminated() && !isSuspended();
        }
-
-       /*
-        * (non-Javadoc)
-        * 
+       
+       /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.ISuspendResume#isSuspended()
         */
        public boolean isSuspended() {
-               return getDebugTarget().isSuspended();
+               return fTarget.isSuspended();
        }
-
-       /*
-        * (non-Javadoc)
-        * 
+       
+       /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.ISuspendResume#resume()
         */
        public void resume() throws DebugException {
-               fStackFrames = null;
-               fBreakpoints = null;
-               getDebugTarget().resume();
+               fBreakpoints=null;
+               fTarget.resume();
        }
-
-       /*
-        * (non-Javadoc)
-        * 
+       
+       /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.ISuspendResume#suspend()
         */
        public void suspend() throws DebugException {
-               getDebugTarget().suspend();
+               fTarget.suspend();
        }
-
-       /*
-        * (non-Javadoc)
-        * 
+       
+       /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.IStep#canStepInto()
         */
        public boolean canStepInto() {
                return isSuspended();
        }
-
-       /*
-        * (non-Javadoc)
-        * 
+       
+       /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.IStep#canStepOver()
         */
        public boolean canStepOver() {
                return isSuspended();
        }
-
-       /*
-        * (non-Javadoc)
-        * 
+       
+       /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.IStep#canStepReturn()
         */
        public boolean canStepReturn() {
-               if (fStackFrames != null)
+               if (fStackFrames != null) {
                        return (fStackFrames.length > 1);
-               else
+               } else {
                        return false;
+               }
        }
 
-       /*
-        * (non-Javadoc)
-        * 
+       /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.IStep#isStepping()
         */
        public boolean isStepping() {
                return fStepping;
        }
 
-       /*
-        * (non-Javadoc)
-        * 
+       /* (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;
+               fTarget.step_into();
        }
 
-       /*
-        * (non-Javadoc)
-        * 
+       /* (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;
+               fTarget.step_over();
        }
 
-       /*
-        * (non-Javadoc)
-        * 
+       /* (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;
+               fTarget.step_out();
        }
 
-       /*
-        * (non-Javadoc)
-        * 
+       /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.ITerminate#canTerminate()
         */
        public boolean canTerminate() {
                return !isTerminated();
        }
 
-       /*
-        * (non-Javadoc)
-        * 
+       /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.ITerminate#isTerminated()
         */
        public boolean isTerminated() {
-               return getDebugTarget().isTerminated();
+               return fTerminated;
        }
 
-       /*
-        * (non-Javadoc)
-        * 
+       /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.ITerminate#terminate()
         */
        public void terminate() throws DebugException {
-               getDebugTarget().terminate();
+               fTarget.getDebugConnection().stop();
+               fTerminated = true;
+       }
+       
+       public void terminated() throws DebugException {
+               fTerminated = true;
        }
 
        /**
         * Sets whether this thread is stepping
         * 
-        * @param stepping
-        *            whether stepping
+        * @param stepping whether stepping
         */
        protected void setStepping(boolean stepping) {
                fStepping = stepping;
@@ -292,12 +269,10 @@ public class XDebugThread extends XDebugElement implements IThread,
 
        public void handleDebugEvents(DebugEvent[] events) {
                DebugEvent de = events[0];
-               System.out.println(de.toString());
-
+               System.out.println(de.toString());      
        }
 
        public void removeEventListeners() {
                DebugPlugin.getDefault().removeDebugEventListener(this);
-
        }
-}
+}
\ No newline at end of file