1) Not really necessary changes (made minor code changes when looking for the 'stackf...
[phpeclipse.git] / net.sourceforge.phpeclipse.debug.core / src / net / sourceforge / phpdt / internal / debug / core / model / PHPDebugTarget.java
index c86bbbe..36d415b 100644 (file)
@@ -13,9 +13,11 @@ package net.sourceforge.phpdt.internal.debug.core.model;
 
 import net.sourceforge.phpdt.internal.debug.core.PHPDBGProxy;
 import net.sourceforge.phpdt.internal.debug.core.PHPDebugCorePlugin;
+import net.sourceforge.phpdt.internal.debug.core.breakpoints.PHPLineBreakpoint;
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 
 import org.eclipse.core.resources.IMarkerDelta;
+import org.eclipse.core.runtime.CoreException;
 import org.eclipse.debug.core.DebugEvent;
 import org.eclipse.debug.core.DebugException;
 import org.eclipse.debug.core.DebugPlugin;
@@ -34,7 +36,7 @@ import org.eclipse.ui.model.IWorkbenchAdapter;
 /**
  * Debug target for PHP debug model.
  */
-public class PHPDebugTarget implements IPHPDebugTarget, ILaunchListener,
+public class PHPDebugTarget extends PHPDebugElement implements IPHPDebugTarget, ILaunchListener,
                IDebugEventSetListener {
 
        private IProcess process;
@@ -72,6 +74,7 @@ public class PHPDebugTarget implements IPHPDebugTarget, ILaunchListener,
        private final State state = new State();
 
        public PHPDebugTarget(ILaunch launch, IProcess process) {
+               super (null);
                if (null == launch && null == process)
                        throw new IllegalArgumentException();
                this.launch = launch;
@@ -222,11 +225,45 @@ public class PHPDebugTarget implements IPHPDebugTarget, ILaunchListener,
                this.getPHPDBGProxy().removeBreakpoint(breakpoint);
        }
 
-       public void breakpointChanged(IBreakpoint breakpoint, IMarkerDelta arg1) {
-               // is called e.g. after a line has been inserted before a breakpoint
-               // but then the debugger is out of sync with the file anyway, so
-               // debugging
-               // should be stopped here.
+       /**
+        * The method will be called when the user enables/disables
+        * breakpoints. In this case we add or remove the breakpoint.
+        * It's also called when leaving the breakpoint properties dialog
+        * (skip count and breakpoint condition) with the OK button.
+        *
+        * This method is also called whenever a source file has changed.
+        * In this case we terminate since the source will be out of sync with the debugger.
+        * TODO Is it correct to call this method when a sourcefile is modified?
+        *
+        */
+       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 
+                               !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);
+                       }
+                       else if (bp.getChangeID() != arg1.getAttribute ("net.sourceforge.phpeclipse.debug.changeID", 0)) {
+                               if (breakpoint.isEnabled()) {                                                           // If the breakpoint is already enabled
+                                       this.getPHPDBGProxy().removeBreakpoint(breakpoint);             // we remove this breakpoint first
+                                       this.getPHPDBGProxy().addBreakpoint(breakpoint);                // and then we add again (else DBG would have two breakpoints!).
+                               }
+                               else {
+                                       this.getPHPDBGProxy().removeBreakpoint(breakpoint);             
+                               }
+                       }
+                       else {                                                                                                                  // All other cases will terminate the debugger
+                               terminate ();
+                       }
+               } catch (CoreException e) {
+                       // Do nothing
+               }
        }
 
        public boolean canDisconnect() {
@@ -330,7 +367,7 @@ public class PHPDebugTarget implements IPHPDebugTarget, ILaunchListener,
 
        /**
         * When a debug target or process terminates, terminate DBG Proxy.
-        * 
+        *
         * @see IDebugEventSetListener#handleDebugEvents(DebugEvent[])
         */
        public void handleDebugEvents(DebugEvent[] events) {