1) Fixed breakpoint with skip count (or hit count).
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.core / src / net / sourceforge / phpeclipse / xdebug / php / model / XDebugTarget.java
index 11bb134..ad0d7a6 100644 (file)
@@ -3,7 +3,6 @@
  */
 package net.sourceforge.phpeclipse.xdebug.php.model;
 
-//import java.io.ByteArrayInputStream;
 //import java.io.IOException;
 import java.util.List;
 
@@ -329,7 +328,11 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, IDebugE
                                                try {
                                                        if (breakpoint.isEnabled()) {
                                                                if (marker != null) {
-                                                                       int id = fDebugConnection.breakpointSet(newPath.toString(), ((ILineBreakpoint)breakpoint).getLineNumber(), marker.getAttribute(XDebugBreakpoint.HIT_COUNT,-1));
+                                                                       int id = fDebugConnection.breakpointSet (newPath.toString(),
+                                                                                                                ((ILineBreakpoint)breakpoint).getLineNumber(),
+                                                                                                                marker.getAttribute (XDebugBreakpoint.HIT_COUNT, -1),
+                                                                             marker.getAttribute (XDebugBreakpoint.CONDITION_ENABLED, false),
+                                                                                                                marker.getAttribute (XDebugBreakpoint.CONDITION, ""));
                                                                        XDebugResponse dr = getResponse(id);
 
                                                                        String bpid = dr.getAttributeValue("id");
@@ -346,28 +349,6 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, IDebugE
                                        }
                                }
                        }
-               } else {
-                       if (supportsBreakpoint(breakpoint)) {
-                               try {
-                                       if (breakpoint.isEnabled()) {
-                                               if (marker != null) {
-                                                       int            id   = fDebugConnection.breakpointSet (path.toString(),
-                                                                                                             ((ILineBreakpoint) breakpoint).getLineNumber(),
-                                                                                                                                                                 marker.getAttribute (XDebugBreakpoint.HIT_COUNT, -1));
-                                                       XDebugResponse dr   = getResponse(id);
-                                                       String         bpid = dr.getAttributeValue("id");
-
-                                                       if (!"".equals(bpid)) {
-                                                               marker.setAttribute(XDebugLineBreakpoint.BREAKPOINT_ID,Integer.parseInt(bpid));
-                                                       }
-                                               }
-                                       }
-                               } catch (DebugException e) {
-                                       e.printStackTrace();
-                               } catch (CoreException e) {
-                                       e.printStackTrace();
-                               }
-                       }
                }
        }
 
@@ -375,13 +356,14 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, IDebugE
         * @see org.eclipse.debug.core.IBreakpointListener#breakpointRemoved(org.eclipse.debug.core.model.IBreakpoint, org.eclipse.core.resources.IMarkerDelta)
         */
        public void breakpointRemoved(IBreakpoint breakpoint, IMarkerDelta delta) {
+               IMarker marker   = breakpoint.getMarker();                  // Get the breakpoints marker info (It's the local workspace path)
+
                if (supportsBreakpoint(breakpoint)) {
-                       try {
-                               int id =((XDebugLineBreakpoint)breakpoint).getID();
-                               if (id >0)
-                                       fDebugConnection.breakpointRemove(id);
-                       } catch (CoreException e) {
-                       }
+                       int id = marker.getAttribute (XDebugLineBreakpoint.BREAKPOINT_ID, -1);
+
+            if (id > 0) {
+               fDebugConnection.breakpointRemove(id);
+            }
                }
        }
 
@@ -389,16 +371,32 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, IDebugE
         * @see org.eclipse.debug.core.IBreakpointListener#breakpointChanged(org.eclipse.debug.core.model.IBreakpoint, org.eclipse.core.resources.IMarkerDelta)
         */
        public void breakpointChanged(IBreakpoint breakpoint, IMarkerDelta delta) {
-//             if (supportsBreakpoint(breakpoint)) {
-//                     try {
-//                             if (breakpoint.isEnabled()) {
-//                                     breakpointAdded(breakpoint);
-//                             } else {
-//                                     breakpointRemoved(breakpoint, null);
-//                             }
-//                     } catch (CoreException e) {
-//                     }
-//             }
+       IMarker oldmarker = breakpoint.getMarker ();
+
+       if (supportsBreakpoint(breakpoint)) {
+                       try {
+                               if (breakpoint.isEnabled ()     &&                                                                      // Check if breakpoint state changed from disabled to enabled
+                                       !delta.getAttribute ("org.eclipse.debug.core.enabled", false)) {
+                                       breakpointAdded (breakpoint);
+                               }
+                               else if (!breakpoint.isEnabled () &&                                                    // Check if breakpoint state changed from enabled to disabled
+                                   delta.getAttribute ("org.eclipse.debug.core.enabled", true)) {
+                                       breakpointRemoved (breakpoint, null);
+                               }
+                               else if (oldmarker.getAttribute (XDebugLineBreakpoint.CHANGE_ID, 1) !=
+                                        delta.getAttribute (XDebugLineBreakpoint.CHANGE_ID, 0)) {
+                                       if (breakpoint.isEnabled ()) {                                                          // If the breakpoint is already enabled
+                                               breakpointRemoved (breakpoint, null);                                   // we remove this breakpoint first
+                                               breakpointAdded (breakpoint);                                                   // and then we add again (else XDebug would have two breakpoints!).
+                                       }
+                                       else {
+                                               breakpointRemoved (breakpoint, null);
+                                       }
+                               }
+                       } catch (CoreException e) {
+                               // Do nothing
+                       }
+               }
        }
 
        /* (non-Javadoc)
@@ -744,12 +742,12 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, IDebugE
                                                                                        hitCount = Integer.parseInt(attribute.getNodeValue());
                                                                                }
                                                                        }
-                                                                       
-                                                                       Path path1 = new Path (PHPDebugUtils.unescapeString (filename)); 
+
+                                                                       Path path1 = new Path (PHPDebugUtils.unescapeString (filename));
                                                                        Path path2 = new Path (endfilename);
-       
+
                                                                        if (path1.toString ().endsWith (path2.toString ())
-//                                                                     if (strPath1.endsWith (strPath2)                                                                        
+//                                                                     if (strPath1.endsWith (strPath2)
                                                                        //if(PHPDebugUtils.unescapeString(filename).endsWith(endfilename)
                                                                                        && (lineBreakpoint.getLineNumber() == lineNumber) ) {
                                                                                if (marker.getAttribute(XDebugLineBreakpoint.HIT_COUNT, 0) > 0) {