1) Although dbg will be dropped from being supported or bundled with PHPeclipse,...
[phpeclipse.git] / net.sourceforge.phpeclipse.debug.core / src / net / sourceforge / phpdt / internal / debug / core / model / PHPDebugTarget.java
index 36d415b..3f64b31 100644 (file)
@@ -29,6 +29,7 @@ import org.eclipse.debug.core.model.IBreakpoint;
 import org.eclipse.debug.core.model.IDebugTarget;
 import org.eclipse.debug.core.model.IMemoryBlock;
 import org.eclipse.debug.core.model.IProcess;
+import org.eclipse.debug.core.model.IStackFrame;
 import org.eclipse.debug.core.model.IThread;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.ui.model.IWorkbenchAdapter;
@@ -39,18 +40,14 @@ import org.eclipse.ui.model.IWorkbenchAdapter;
 public class PHPDebugTarget extends PHPDebugElement implements IPHPDebugTarget, ILaunchListener,
                IDebugEventSetListener {
 
-       private IProcess process;
-
-       private ILaunch launch;
-
-       private PHPThread[] threads = new PHPThread[0];
-
-       private PHPDBGProxy phpDBGProxy;
+       private IProcess      process;
+       private ILaunch       launch;
+       private PHPThread[]   threads = new PHPThread[0];
+       private PHPDBGProxy   phpDBGProxy;
 
        private class State {
                private boolean isTerminated = false;
-
-               private boolean isSuspended = false;
+               private boolean isSuspended  = false;
 
                boolean isTerminated() {
                        return isTerminated;
@@ -106,6 +103,11 @@ public class PHPDebugTarget extends PHPDebugElement implements IPHPDebugTarget,
                fireThreadCreateEvent(phpThread);
        }
 
+       public void updateThreads (PHPThread phpThread) {
+               fireChangeEvent ();
+               fireThreadCreateEvent (phpThread);
+       }
+
        private void fireChangeEvent() {
                DebugEvent ev = new DebugEvent(this, DebugEvent.CHANGE);
                DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { ev });
@@ -116,14 +118,14 @@ public class PHPDebugTarget extends PHPDebugElement implements IPHPDebugTarget,
                DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { ev });
        }
 
-       protected PHPThread getThreadById(int id) {
-               for (int i = 0; i < threads.length; i++) {
-                       if (threads[i].getId() == id) {
-                               return threads[i];
-                       }
-               }
-               return null;
-       }
+//     protected PHPThread getThreadById(int id) {
+//             for (int i = 0; i < threads.length; i++) {
+//                     if (threads[i].getId() == id) {
+//                             return threads[i];
+//                     }
+//             }
+//             return null;
+//     }
 
        public IThread[] getThreads() {
                return threads;
@@ -148,6 +150,10 @@ public class PHPDebugTarget extends PHPDebugElement implements IPHPDebugTarget,
                return PHPDebugCorePlugin.PLUGIN_ID;
        }
 
+       public IStackFrame[] getStackFrames () throws DebugException {
+               return (IStackFrame[]) this.phpDBGProxy.getDBGInterface ().getStackList ();
+       }
+
        public IDebugTarget getDebugTarget() {
                return this;
        }
@@ -164,6 +170,17 @@ public class PHPDebugTarget extends PHPDebugElement implements IPHPDebugTarget,
                return state.isTerminated();
        }
 
+       private synchronized void terminateThreads () {
+               int i;
+
+               try {
+                       for (i = 0; i < threads.length; i++) {
+                               threads[i].terminate ();
+                       }
+               } catch (DebugException e) {
+               }
+       }
+
        public synchronized void terminate() {
                // This method is synchronized to control a race condition between the
                // UI thread that terminates the debugging session, and the slave
@@ -173,6 +190,7 @@ public class PHPDebugTarget extends PHPDebugElement implements IPHPDebugTarget,
                        return;
                state.setTerminated(true);
                phpDBGProxy.stop();
+               terminateThreads ();
                this.threads = new PHPThread[0];
                fireChangeEvent();
                IBreakpointManager manager = DebugPlugin.getDefault()
@@ -239,12 +257,12 @@ public class PHPDebugTarget extends PHPDebugElement implements IPHPDebugTarget,
        public void breakpointChanged (IBreakpoint breakpoint, IMarkerDelta arg1) {
                PHPLineBreakpoint bp;
                bp = (PHPLineBreakpoint) breakpoint;
-               
+
                try {
-                       if (breakpoint.isEnabled ()     &&                                                                      // Check if breakpoint state changed from disabled to enabled 
+                       if (breakpoint.isEnabled ()     &&                                                                      // Check if breakpoint state changed from disabled to enabled
                                !arg1.getAttribute ("org.eclipse.debug.core.enabled", false)) {
                                this.getPHPDBGProxy().addBreakpoint(breakpoint);
-                       } 
+                       }
                        else if (!breakpoint.isEnabled () &&                                                    // Check if breakpoint state changed from enabled to disabled
                            arg1.getAttribute ("org.eclipse.debug.core.enabled", true)) {
                                this.getPHPDBGProxy().removeBreakpoint(breakpoint);
@@ -255,7 +273,7 @@ public class PHPDebugTarget extends PHPDebugElement implements IPHPDebugTarget,
                                        this.getPHPDBGProxy().addBreakpoint(breakpoint);                // and then we add again (else DBG would have two breakpoints!).
                                }
                                else {
-                                       this.getPHPDBGProxy().removeBreakpoint(breakpoint);             
+                                       this.getPHPDBGProxy().removeBreakpoint(breakpoint);
                                }
                        }
                        else {                                                                                                                  // All other cases will terminate the debugger
@@ -319,7 +337,13 @@ public class PHPDebugTarget extends PHPDebugElement implements IPHPDebugTarget,
                                }
                        };
                }
-               return null;
+               else {
+                   if (arg0 == PHPDebugElement.class) {
+                       return this;
+                   }
+
+                   return super.getAdapter(arg0);
+               }
        }
 
        public IProcess getProcess() {