fix #763.
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.core / src / net / sourceforge / phpeclipse / xdebug / php / model / XDebugTarget.java
index 339cf1b..06064eb 100644 (file)
@@ -3,13 +3,17 @@
  */
 package net.sourceforge.phpeclipse.xdebug.php.model;
 
-import java.net.MalformedURLException;
-import java.net.URL;
+//import java.io.ByteArrayInputStream;
+//import java.io.IOException;
 import java.util.List;
 
-import net.sourceforge.phpeclipse.xdebug.core.Base64;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
 import net.sourceforge.phpeclipse.xdebug.core.IPHPDebugEvent;
 import net.sourceforge.phpeclipse.xdebug.core.IProxyEventListener;
+import net.sourceforge.phpeclipse.xdebug.core.IXDebugPreferenceConstants;
 import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils;
 import net.sourceforge.phpeclipse.xdebug.core.PathMapItem;
 import net.sourceforge.phpeclipse.xdebug.core.XDebugCorePlugin;
@@ -26,28 +30,26 @@ import org.eclipse.debug.core.DebugPlugin;
 import org.eclipse.debug.core.IDebugEventSetListener;
 import org.eclipse.debug.core.ILaunch;
 
-import org.eclipse.debug.core.ILaunchListener;
-
 import org.eclipse.debug.core.model.IBreakpoint;
 import org.eclipse.debug.core.model.IDebugTarget;
 import org.eclipse.debug.core.model.ILineBreakpoint;
 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.debug.core.model.IValue;
-import org.eclipse.debug.core.model.IVariable;
+import org.w3c.dom.Document;
+import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
+//import org.xml.sax.SAXException;
 
+import net.sourceforge.phpeclipse.xdebug.core.xdebug.ResponseListener;
 import net.sourceforge.phpeclipse.xdebug.core.xdebug.XDebugConnection;
-import net.sourceforge.phpeclipse.xdebug.core.xdebug.ResponseListener.DebugResponse;
+import net.sourceforge.phpeclipse.xdebug.core.xdebug.XDebugResponse;
 
 /**
  * @author Christian
  *
  */
-public class XDebugTarget extends XDebugElement implements IDebugTarget, ILaunchListener, IDebugEventSetListener, IProxyEventListener {
+public class XDebugTarget extends XDebugElement implements IDebugTarget, IDebugEventSetListener, IProxyEventListener {
        private IProcess fProcess;
        
        private ILaunch fLaunch;
@@ -63,6 +65,8 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, ILaunch
        
        private XDebugConnection fDebugConnection;
 
+       private ResponseListener fResponseListener;
+
        private String fIdeKey;
 
 
@@ -74,26 +78,20 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, ILaunch
         * @param launch containing launch
         * @param process process of the interpreter
         * @param ideKey 
-        * @param pathMap Pathmap for the debug session
         * @exception CoreException if unable to connect to host
         */     
        public XDebugTarget(ILaunch launch, IProcess process, String ideKey) throws CoreException {
                fLaunch = launch;
                fProcess = process;
-               fTarget = this;
                fDebugConnection = null;
                fThread = null;
                fThreads = new IThread[0];
                fIdeKey = ideKey;
                
-               XDebugProxy proxy = XDebugCorePlugin.getDefault().getXDebugProxy();
-               proxy.addProxyEventListener(this,ideKey);
-               if (!proxy.isRunning())
-                       proxy.start();
-               
-               proxy.setTarget(this);
-
-               fDebugPort = proxy.getProxyPort();
+               fDebugPort = XDebugCorePlugin.getDefault().getPreferenceStore().getInt(IXDebugPreferenceConstants.DEBUGPORT_PREFERENCE);                
+               if (fDebugPort == 0) {
+                       fDebugPort = IXDebugPreferenceConstants.DEFAULT_DEBUGPORT;
+               }
                
                DebugPlugin.getDefault().getBreakpointManager().addBreakpointListener(this);
                DebugPlugin.getDefault().addDebugEventListener(this);
@@ -117,7 +115,7 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, ILaunch
         * @see org.eclipse.debug.core.model.IDebugTarget#hasThreads()
         */
        public boolean hasThreads() throws DebugException {
-               return (fThreads.length>0);
+               return (fThreads.length > 0);
        }
 
        /* (non-Javadoc)
@@ -172,18 +170,23 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, ILaunch
         * @see org.eclipse.debug.core.model.ITerminate#terminate()
         */
        public void terminate() throws DebugException {
-               XDebugProxy proxy=XDebugCorePlugin.getDefault().getXDebugProxy();
-               proxy.stop();
-               proxy.removeProxyEventListener(this,fIdeKey);
-               System.out.println("XDebug.Target: ProxyEventlistener removed");
-               fTerminated = true;
-               //fDisconnected = true;
-               fSuspended = false;
-               XDebugCorePlugin.getBreakpointManager().removeBreakpointListener(this);
-               fireTerminateEvent();
-               DebugPlugin.getDefault().removeDebugEventListener(this);
-               if (fThread!=null)
-                       fThread.removeEventListeners();
+               if(fTerminated) {
+                       return;
+               }
+               
+               if (XDebugCorePlugin.getDefault() != null) {
+                       XDebugProxy proxy = XDebugCorePlugin.getDefault().getXDebugProxy();
+                       proxy.removeProxyEventListener(this, fIdeKey);
+                       
+                       System.out.println("XDebug.Target: ProxyEventlistener removed");
+                       
+                       fTerminated = true;
+                       fSuspended = false;
+                       
+                       XDebugCorePlugin.getBreakpointManager().removeBreakpointListener(this);
+                       fireEvent(new DebugEvent(this, DebugEvent.TERMINATE));
+                       DebugPlugin.getDefault().removeDebugEventListener(this);
+               }
        }
 
        /* (non-Javadoc)
@@ -213,8 +216,9 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, ILaunch
        public void resume() throws DebugException {
                if (fDebugConnection != null) {
                        fThread.setBreakpoints(null);
+                       resumed(DebugEvent.RESUME);
                        fDebugConnection.run();
-               }                       
+               }               
        }
        
        /**
@@ -248,7 +252,7 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, ILaunch
         */
        public void breakpointAdded(IBreakpoint breakpoint) {
                IMarker marker = breakpoint.getMarker();
-               IPath path = marker.getResource().getFullPath();
+               IPath path = marker.getResource().getLocation();
                IPath cp = path.removeLastSegments(1);
                List pathMap = null;
                try {
@@ -258,6 +262,7 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, ILaunch
                        e2.printStackTrace();
                }
 
+               if (fDebugConnection != null)
                if (!fDebugConnection.isClosed()) {
                        if (fProcess == null) {
                                PathMapItem pmi = null;
@@ -274,8 +279,9 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, ILaunch
                                                        try {
                                                                if (breakpoint.isEnabled()) {
                                                                        if (marker != null) {
-                                                                               //fDebugConnection.addBreakpoint(breakpoint, newPath);
-                                                                               DebugResponse dr = fDebugConnection.breakpointSet(newPath.toString(), ((ILineBreakpoint)breakpoint).getLineNumber());
+                                                                               int id = fDebugConnection.breakpointSet(newPath.toString(), ((ILineBreakpoint)breakpoint).getLineNumber(), marker.getAttribute(XDebugBreakpoint.HIT_COUNT,-1));
+                                                                               XDebugResponse dr = getResponse(id);
+                                                                               
                                                                                String bpid = dr.getAttributeValue("id");
                                                                                
                                                                                if (!"".equals(bpid))
@@ -295,7 +301,8 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, ILaunch
                                        try {
                                                if (breakpoint.isEnabled()) {
                                                        if (marker != null) {
-                                                               DebugResponse dr = fDebugConnection.breakpointSet(path.toString(), ((ILineBreakpoint)breakpoint).getLineNumber());
+                                                               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))
@@ -359,7 +366,7 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, ILaunch
         * @see org.eclipse.debug.core.model.IDisconnect#isDisconnected()
         */
        public boolean isDisconnected() {
-               return (fDebugConnection==null);
+               return (false);
        }
 
        /* (non-Javadoc)
@@ -384,20 +391,24 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, ILaunch
                fThread.setBreakpoints(null);
                fThread.setStepping(false);
 
-               Integer.parseInt(fDebugConnection.featureGet("detach").getValue());
+               int id = fDebugConnection.featureGet("detach");
 
+               XDebugResponse response = getResponse(id);
+
+               Integer.parseInt(response.getValue());
                System.out.println("in Target.started()");
-               DebugResponse response = fDebugConnection.featureGet("max_children");
-               String a1 = response.getValue();
-               System.out.println("max children:"+a1);
-               DebugResponse response1 = fDebugConnection.featureGet("max_children");
-               String a2 = response1.getValue();
-               System.out.println("max depth:"+a2);
-               
-               
-               boolean res = fDebugConnection.featureSet("max_depth", "100" );
-               if( res == true ) {
-                       System.out.println("Set depth to 100 (hack)");
+
+               // Dirty hack
+               // Need to refactory plugin to get variables in lazy mode.
+               int id1 = fDebugConnection.featureSet("max_depth", "1024" );
+               XDebugResponse response1 = getResponse(id1);
+               if (response1.getAttributeValue("success").equals("1") ) {
+                       System.out.println("Set depth to 1024 (hack)");
+               }
+               int id2 = fDebugConnection.featureSet("max_children", "1024" );
+               XDebugResponse response2 = getResponse(id2);
+               if (response2.getAttributeValue("success").equals("1") ) {
+                       System.out.println("Set children to 1024 (hack)");
                }
                
                installDeferredBreakpoints();
@@ -420,59 +431,15 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, ILaunch
        }
        
        /**
-        * Called when this debug target terminates.
-        */
-       public void terminated() {
-               fTerminated = true;
-               fSuspended = false;
-               XDebugCorePlugin.getBreakpointManager().removeBreakpointListener(this);
-               fireTerminateEvent();
-               DebugPlugin.getDefault().removeDebugEventListener(this);
-               fThread.removeEventListeners(); 
-       }
-       
-       /**
         * Returns the current stack frames in the target.
         * 
         * @return the current stack frames in the target
         * @throws DebugException if unable to perform the request
         */
-       public IStackFrame[] getStackFrames() throws DebugException {
-               DebugResponse lastResponse = fDebugConnection.stackGet(0);
-
-               if (lastResponse.isError())
-                       return new IStackFrame[0];
-               Node response = lastResponse.getParentNode();
-               NodeList frames = response.getChildNodes();
-               IStackFrame[] theFrames = new IStackFrame[frames.getLength()];
-               for (int i = 0; i < frames.getLength(); i++) {
-                       Node stackNode = frames.item(i);
-                       XDebugStackFrame frame = new XDebugStackFrame(fThread, i);
-                       String level =PHPDebugUtils.getAttributeValue(stackNode,"level");
-                       if (!"".equals(level))
-                               frame.setLevel(Integer.parseInt(level));
-
-                       frame.setType(PHPDebugUtils.getAttributeValue(stackNode,"type"));
-                       String fileName=PHPDebugUtils.unescapeString(PHPDebugUtils.getAttributeValue(stackNode,"filename"));
-                       String lineNo=PHPDebugUtils.getAttributeValue(stackNode,"lineno");
-
-                       if (!"".equals(lineNo))
-                               frame.setLineNumber(Integer.parseInt(lineNo));
-                       
-                       frame.setWhere(PHPDebugUtils.getAttributeValue(stackNode,"where"));
-                       
-                       try {
-                               frame.setFullName(new URL(fileName));
-                       } catch (MalformedURLException e) {
-                               e.printStackTrace();
-                       }
-
-                       frame.incrementStepCounter();
-                       
-                       theFrames[i] = frame;
-               }
-               
-               return theFrames;
+       public XDebugResponse getStackFrames() throws DebugException {
+               int id = fDebugConnection.stackGet();
+               XDebugResponse lastResponse = getResponse(id);
+               return lastResponse;
        }
        
        /**
@@ -508,95 +475,156 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, ILaunch
                fDebugConnection.stepOut();
        }
        
-       /**
-        * Returns the current value of the given variable.
-        * 
-        * @param variable
-        * @return variable value
-        * @throws DebugException if the request fails
-        */
-       /*protected IValue getVariableValue(XDebugVariable variable) throws DebugException {
-               return null;
-       }*/
-       
-       /**
-        * Returns the values on the data stack (top down)
-        * 
-        * @return the values on the data stack (top down)
-        */
-       /*public IValue[] getDataStack() throws DebugException {
-               return new IValue[0];           
-       }*/
-       
        public boolean setVarValue(String name, String value) {
-               return fDebugConnection.setVarValue(name,value);
+               int id = fDebugConnection.setVarValue(name,value);
+               XDebugResponse response = getResponse(id);
+               
+               if ((response.getAttributeValue("success")).equals("1")) {
+                       return true;
+               } else {
+                       return false;
+               }
+       }
+       
+       public Node eval(String expression) throws DebugException {
+               Node evalProperty = null;
+               if (fDebugConnection != null) {
+                       int id = fDebugConnection.eval(expression);
+                       //Node evalProperty = new Node("");
+                       //if (id > 0) {
+                               XDebugResponse response = getResponse(id);
+               
+                               Node evalResponse = response.getParentNode();
+                               /*Node*/ evalProperty = evalResponse.getFirstChild();
+                       //} /*else {
+                               
+                       //}*/
+               } else {
+                       DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+                       DocumentBuilder builder = null;
+                       Document doc = null;
+                       
+                       try {
+                               builder = factory.newDocumentBuilder();
+                       } catch (ParserConfigurationException e) {
+                               e.printStackTrace();
+                       }
+                       //try {
+                               doc =  builder.newDocument(); // .parse("");
+                               evalProperty = doc.createElement("value");
+                       /*} catch (SAXException e) {
+                               e.printStackTrace();
+                       } catch (IOException e) {
+                               e.printStackTrace();
+                       }*/
+               }
+               
+               return evalProperty;
        }
        
        public void handleDebugEvents(DebugEvent[] events) {
                for (int i = 0; i < events.length; i++) {
                        DebugEvent event = events[i];
+                       
+                       if (fResponseListener != null) {
+                               Object s = null;
+                               s = event.getSource();
+                               if (s instanceof ResponseListener) {
+                                       if (!fResponseListener.equals((ResponseListener) s)) {
+                                               return;
+                                       }
+                               }
+                       } else {
+                               return;
+                       }
+                       
                        if (event.getKind() == DebugEvent.MODEL_SPECIFIC) {
                                switch (event.getDetail()) {
                                        case IPHPDebugEvent.BREAKPOINT_HIT:
-                                               DebugResponse lastResponse = ((XDebugConnection) fDebugConnection).stackGet(0);
+                                               int id = fDebugConnection.stackGet();
+                                               XDebugResponse lastResponse = getResponse(id);
 
                                                IBreakpoint breakpoint = breakpointHit(lastResponse.getParentNode());
-       
-                                               fThread.setBreakpoints(new IBreakpoint[]{breakpoint});
-                                               fThread.incrementStepCounter();
-                                               suspended(DebugEvent.BREAKPOINT);
+                                               
+                                               if (breakpoint != null) {
+                                                       fThread.setBreakpoints(new IBreakpoint[]{breakpoint});
+                                                       fThread.incrementStepCounter();
+                                                       suspended(DebugEvent.BREAKPOINT);
+                                               } else {
+                                                       try {
+                                                               resume();
+                                                       } catch (DebugException e ) {
+                                                               ; //nothing to do
+                                                       }
+                                               }
                                                break;
                                        case IPHPDebugEvent.STEP_END:
                                                fThread.incrementStepCounter();
                                                suspended(DebugEvent.STEP_END);
                                                break;
                                        case IPHPDebugEvent.STOPPED:
-                                               fThread.removeEventListeners();
-                                               fThread = null;
-                                               fThreads = new IThread[0];
-
-                                               fDebugConnection.close();
-
-                                               fSuspended = false;
-
-                                               // Dirty hack to check debugging mode (remote or local)
-                                               if (fProcess!=null) {
-                                                       try {
-                                                               terminate();
-                                                       } catch (DebugException e) {
-                                                               e.printStackTrace();
-                                                       }
-                                               } else {
-                                                       fDebugConnection = null;
-                                                       fireEvent(new DebugEvent(this, DebugEvent.CHANGE, DebugEvent.CONTENT));
-                                               }
+                                               stopped();
                                                break;
                                }
                        }
                }
        }
+       
+       public void stopped() {
+               if(fDebugConnection == null) {
+                       return;
+               }
+
+               resumed(DebugEvent.TERMINATE);
+
+               stopListener();
+               fDebugConnection.close();
+
+               fSuspended = false;
 
-       public void handleProxyEvent(String ideKey, String initString, /*AbstractDebugConnection*/ XDebugConnection connection) {
-               System.out.println("* New Connection - XDebug.Target: "+ideKey);
-               setDebugConnection(connection);
+               // Dirty hack to check debugging mode (remote or local)
+               if (fProcess != null) {
+                       try {
+                               terminate();
+                       } catch (DebugException e) {
+                               e.printStackTrace();
+                       }
+               } else {
+                       fDebugConnection = null;
+                       fireEvent(new DebugEvent(this, DebugEvent.CHANGE, DebugEvent.CONTENT));
+               }
                
-               XDebugProxy proxy=XDebugCorePlugin.getDefault().getXDebugProxy();
-               fDebugPort=proxy.getProxyPort();
-               fireEvent(new DebugEvent(this, DebugEvent.CHANGE, DebugEvent.CHANGE));
+               fThread.removeEventListeners();
+               fThread = null;
+               fThreads = new IThread[0];
+       }
+       
+       public void handleProxyEvent(XDebugConnection connection) {
+               //System.out.println("* New Connection - XDebug.Target: " + fDebugConnection.getSessionID());
                
-               fThread = new XDebugThread(this);
-               fThreads = new IThread[] {fThread};
-               try {
-                       started();
-               } catch( DebugException e ){
-                       e.printStackTrace();            
-               }               
+               if (setDebugConnection(connection)) {
+                       fThread = new XDebugThread(this);
+                       fThreads = new IThread[] {fThread};
+                       fireEvent(new DebugEvent(this, DebugEvent.CHANGE, DebugEvent.CHANGE));
+                       try {
+                               started();
+                       } catch( DebugException e ){
+                               e.printStackTrace();            
+                       }
+               }
        }
 
-       private void setDebugConnection(XDebugConnection connection) {
-               if (connection != null) {
+       private boolean setDebugConnection(XDebugConnection connection) {
+               if (connection != null && fDebugConnection == null) {
                        fDebugConnection = connection;
-                       fDebugConnection.startListener();
+                       fResponseListener = new ResponseListener(connection);
+                       startListener();
+                       
+                       return true;
+               } else {
+                       connection.close();
+                       
+                       return false;
                }
        }
        
@@ -611,125 +639,29 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, ILaunch
                fProcess = p;
 
        }
-
-       public void launchRemoved(ILaunch launch) {
-       }
-
-       /**
-        * Notifies this listener that the specified launch
-        * has been added.
-        * 
-        * @param launch the newly added launch
-        * @since 2.0
-        */
-       public void launchAdded(ILaunch launch){
-       }
-
-       /**
-        * Notifies this listener that the specified launch
-        * has changed. For example, a process or debug target
-        * has been added to the launch.
-        * 
-        * @param launch the changed launch
-        * @since 2.0
-        */
-       public void launchChanged(ILaunch launch) {
+       public Node getLocalVariables(int level) throws DebugException {
+               int id = fDebugConnection.contextGet(level, 0);
+               XDebugResponse response = getResponse(id);
+               
+               return response.getParentNode();
        }
        
-       public IVariable[] getVariables(XDebugStackFrame frame, int level)  throws DebugException {
-               IVariable[] variables = null;
-               
-               DebugResponse response = fDebugConnection.contextGet(level, 0);
-               Node responseNode = response.getParentNode();
-               NodeList property = responseNode.getChildNodes();
-               
-               DebugResponse responseGlobal = fDebugConnection.contextGet(level, 1);
-               Node responseGlobalNode = responseGlobal.getParentNode();
-               NodeList propertyGlobal = responseGlobalNode.getChildNodes();
+       public Node getGlobalVariables(int level) throws DebugException {
+               int id = fDebugConnection.contextGet(level, 1);
+               XDebugResponse response = getResponse(id);
                
-               variables = new IVariable[property.getLength() + propertyGlobal.getLength()];
-//             variables = new IVariable[property.getLength()]; // + propertyGlobal.getLength()];
-               
-               int length = property.getLength();
-               for (int i = 0; i < length; i++) {
-                       Node propertyNode = property.item(i);
-                       XDebugVariable var=/*fDebugConnection.*/getVariableFromNode(frame,propertyNode);
-                       variables[i]=var;
-               }
-
-               int globalLength = propertyGlobal.getLength();
-               for (int k = 0; k < globalLength; k++) {
-                       Node propertyGlobalNode = propertyGlobal.item(k);
-                       XDebugVariable var=/*fDebugConnection.*/getVariableFromNode(frame,propertyGlobalNode);
-                       variables[k + length]=var;
-               }
+               return response.getParentNode();
+       }
        
-               return variables;
-       }       
-
-       public XDebugVariable getVariableFromNode(XDebugStackFrame frame, Node property) {
-               String varFullName = PHPDebugUtils.getAttributeValue(property, "fullname");
-               String varName = PHPDebugUtils.getAttributeValue(property, "name");
-               String varEncoding = PHPDebugUtils.getAttributeValue(property, "encoding");
-               
-               int varNumChildren = 0;
-               if (PHPDebugUtils.getAttributeValue(property, "numchildren").equals("")) {
-                       varNumChildren = 0;
-               } else {
-                       varNumChildren = Integer.parseInt(PHPDebugUtils.getAttributeValue(property, "numchildren"));
-               }
-
-               String typeName = PHPDebugUtils.getAttributeValue(property,"type");
-
-               XDebugVariable variable = new XDebugVariable(frame,varFullName,varName,typeName);
-               variable.setEncoding(varEncoding);
-               variable.setNumChildren(varNumChildren);
-               XDebugAbstractValue val=null;
-               try {
-                       val = (XDebugAbstractValue) variable.getValue();
-               } catch (DebugException e1) {
-                       // TODO Auto-generated catch block
-                       e1.printStackTrace();
-               }
-               if (val.getType()!= XDebugAbstractValue.VALUETYPE_UNINITIALIZED) {
-                       if (variable.hasChildren()) {
-                               NodeList varNodes = property.getChildNodes();
-                               val.renderValueString(""+varNodes.getLength());
-                               IVariable[] variables = new IVariable[varNodes.getLength()];
-                               for (int i = 0; i<varNodes.getLength(); i++) {
-                                       Node propertyNode = varNodes.item(i);
-                                       variables[i] = getVariableFromNode(frame, propertyNode);
-                               }
-                               val.setChildVariables(variables);
-                       }else {
-                               String str="";
-                               try {
-                                       str=property.getFirstChild().getNodeValue();
-                               } catch (NullPointerException e) {
-                                       str="";
-                               }
-                               if (variable.getEncoding().equals("base64")) {
-                                       if (str.length()!=0)
-                                               str=new String(Base64.decode(str));
-                                       else
-                                               str="";
-                               }
-                               val.renderValueString(str);
-                       }
-                       
-                       String className=PHPDebugUtils.getAttributeValue(property,"classname");
-                       if(!"".equals(className))
-                               val.renderValueString(className);
-               }
-               return variable;
-               
+       public void stop() {
+               fDebugConnection.stop();
        }
-
+       
        protected IBreakpoint breakpointHit(Node node) {
-               Node child=node.getFirstChild();
+               Node child = node.getFirstChild();
                if (child.getNodeName().equals("stack")) {
                        int lineNumber = Integer.parseInt(PHPDebugUtils.getAttributeValue(child, "lineno"));
-                       String filename=PHPDebugUtils.getAttributeValue(child, "filename");  
+                       String filename = PHPDebugUtils.getAttributeValue(child, "filename");  
                        IBreakpoint[] breakpoints = XDebugCorePlugin.getBreakpoints();
                        for (int i = 0; i < breakpoints.length; i++) {
                                IBreakpoint breakpoint = breakpoints[i];
@@ -743,13 +675,33 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, ILaunch
                                                                        String endfilename;
                                                                        
                                                                        if (getProcess() == null) {
-                                                                               endfilename = marker.getResource().getFullPath().lastSegment(); 
+                                                                               endfilename = marker.getResource().getLocation().lastSegment(); 
                                                                        } else {
-                                                                               endfilename = marker.getResource().getFullPath().toOSString();
+                                                                               endfilename = marker.getResource().getLocation().toOSString();
+                                                                       }
+                                                                       
+                                                                       int id = fDebugConnection.breakpointGet(marker.getAttribute(XDebugLineBreakpoint.BREAKPOINT_ID,-1));
+                                                                       XDebugResponse dr = getResponse(id);
+                                                                       
+                                                                       Node hitCo = dr.getParentNode().getFirstChild();
+                                                                       int hitCount = 0;
+                                                                       if (hitCo.hasAttributes()) {
+                                                                               NamedNodeMap listAttribute = hitCo.getAttributes();
+                                                                               Node attribute = listAttribute.getNamedItem("hit_count");
+                                                                               if (attribute !=null) {
+                                                                                       hitCount = Integer.parseInt(attribute.getNodeValue());
+                                                                               }
                                                                        }
 
-                                                                       if(PHPDebugUtils.unescapeString(filename).endsWith(endfilename) && (lineBreakpoint.getLineNumber() == lineNumber) ) {
-                                                                               return (breakpoint);
+                                                                       if(PHPDebugUtils.unescapeString(filename).endsWith(endfilename)
+                                                                                       && (lineBreakpoint.getLineNumber() == lineNumber) ) {
+                                                                               if (marker.getAttribute(XDebugLineBreakpoint.HIT_COUNT, 0) > 0) {
+                                                                                       if (marker.getAttribute(XDebugLineBreakpoint.HIT_COUNT, 0) == hitCount) {
+                                                                                               return (breakpoint);                                                                                            
+                                                                                       }
+                                                                               } else {
+                                                                                       return (breakpoint);
+                                                                               }
                                                                        }
                                                                }
                                                        }
@@ -761,5 +713,18 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, ILaunch
                }
                
                return null;
-       }       
+       }
+       
+       public void startListener() {
+               fResponseListener.schedule();
+       }
+       
+       public void stopListener() {
+               fResponseListener.cancel();
+       }
+       public XDebugResponse getResponse(int id) {
+               XDebugResponse response = fResponseListener.getResponse(id);
+
+               return response;
+       }
 }
\ No newline at end of file