Initial implementation of the new Debug Plugin
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.core / src / net / sourceforge / phpeclipse / xdebug / php / model / XDebugThread.java
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
new file mode 100644 (file)
index 0000000..4581ee5
--- /dev/null
@@ -0,0 +1,237 @@
+/*
+ * Created on 23.11.2004
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package net.sourceforge.phpeclipse.xdebug.php.model;
+
+import org.eclipse.debug.core.DebugEvent;
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.DebugPlugin;
+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;
+
+/**
+ * @author Axel
+ *
+ * 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;
+       
+       private IBreakpoint[] fBreakpoints;
+       
+       /**
+        * Whether this thread is stepping
+        */
+       private boolean fStepping = false;
+       
+       /**
+        * Constructs a new thread for the given target
+        * 
+        * @param target VM
+        */
+       public XDebugThread(XDebugTarget target) {
+               super(target);
+               DebugPlugin.getDefault().addDebugEventListener(this);
+       }
+       
+       /* (non-Javadoc)
+        * @see org.eclipse.debug.core.model.IThread#getStackFrames()
+        */
+       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 {
+                       return new IStackFrame[0];
+               }
+       }
+       /* (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()
+        */
+       public IStackFrame getTopStackFrame() throws DebugException {
+               IStackFrame[] frames = getStackFrames();
+               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]";
+       }
+       /* (non-Javadoc)
+        * @see org.eclipse.debug.core.model.IThread#getBreakpoints()
+        */
+       public IBreakpoint[] getBreakpoints() {
+               if (fBreakpoints == null) {
+                       return new IBreakpoint[0];
+               }
+               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
+        */
+       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();
+       }
+       /* (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;
+               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
+                       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();
+       }
+       /* (non-Javadoc)
+        * @see org.eclipse.debug.core.model.IStep#stepOver()
+        */
+       public void stepOver() throws DebugException {
+               fStackFrames=null;
+               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();
+
+       }
+       /* (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();
+       }
+       /* (non-Javadoc)
+        * @see org.eclipse.debug.core.model.ITerminate#terminate()
+        */
+       public void terminate() throws DebugException {
+               getDebugTarget().terminate();
+       }
+       
+       /**
+        * Sets whether this thread is stepping
+        * 
+        * @param stepping whether stepping
+        */
+       protected void setStepping(boolean stepping) {
+               fStepping = stepping;
+       }
+
+       public void handleDebugEvents(DebugEvent[] events) {
+               DebugEvent de=events[0];
+               System.out.println(de.toString());
+               
+       }
+
+       public void removeEventListeners() {
+               DebugPlugin.getDefault().removeDebugEventListener(this);
+               
+       }
+}