deletet because wrongly uploaded
[phpeclipse.git] / net.sourceforge.phpeclipse.debug.core / src / net / sourceforge / phpdt / internal / debug / core / PHPDBGProxy.java
index 3f6ca08..feb5325 100644 (file)
@@ -26,10 +26,7 @@ import net.sourceforge.phpdt.internal.debug.core.model.IPHPDebugTarget;
 import net.sourceforge.phpdt.internal.debug.core.model.PHPStackFrame;
 import net.sourceforge.phpdt.internal.debug.core.model.PHPThread;
 import net.sourceforge.phpdt.internal.debug.core.model.PHPVariable;
-import net.sourceforge.phpdt.internal.debug.core.SocketUtil;
-import net.sourceforge.phpdt.internal.debug.core.PHPDBGInterface;
 import net.sourceforge.phpdt.internal.debug.core.breakpoints.PHPLineBreakpoint;
-import net.sourceforge.phpdt.internal.debug.core.PHPDebugCorePlugin;
 
 public class PHPDBGProxy {
 
@@ -37,12 +34,14 @@ public class PHPDBGProxy {
        private Socket socket;
        private BufferedReader reader= null;
        private PHPDBGInterface DBGInt= null;
-       private IPHPDebugTarget debugTarget;
+       private IPHPDebugTarget debugTarget= null;
        private PHPLoop phpLoop;
        private PHPThread PHPMainThread;
+       private PHPDBGProxy thisProxy= null;
        private int port;
 
        public PHPDBGProxy() {
+               thisProxy= this;
        }
 
        public void start() {
@@ -53,6 +52,11 @@ public class PHPDBGProxy {
        public void stop() {
                phpLoop.setShouldStop();
                if(DBGInt != null) DBGInt.setShouldStop();
+               try {
+                       getDebugTarget().getProcess().terminate();
+               } catch (DebugException e) {
+                       e.printStackTrace();
+               }
                phpLoop.notifyWait();
        }
 
@@ -72,7 +76,7 @@ public class PHPDBGProxy {
                try {
                        if (server == null) {
                                server = new ServerSocket(port);
-                               System.out.println("ServerSocket on port: " + port);
+                               //System.out.println("ServerSocket on port: " + port);
                        } 
                } catch (IOException e) {
                        // IO Error
@@ -81,7 +85,7 @@ public class PHPDBGProxy {
                }
        }
 
-       protected Socket getSocket() throws IOException {
+       public Socket getSocket() throws IOException {
                return socket;
        }
 
@@ -90,7 +94,7 @@ public class PHPDBGProxy {
        }
 
        public BufferedReader getReader() throws IOException {
-               if (reader == null) {                   
+               if (reader == null) {
                        reader = new BufferedReader(new InputStreamReader(this.getSocket().getInputStream(), "ISO8859_1"));
                }
                return reader;
@@ -148,7 +152,7 @@ public class PHPDBGProxy {
                phpLoop.start();
        }
 
-       public void resume(PHPThread thread) {
+       public void resume() {
                try {
                        DBGInt.continueExecution();
                        phpLoop.notifyWait();
@@ -158,6 +162,14 @@ public class PHPDBGProxy {
                }
        }
 
+       public void pause() {
+               try {
+                       DBGInt.pauseExecution();
+               } catch (IOException e) {
+                       PHPDebugCorePlugin.log(e);
+                       stop();
+               }
+       }
        protected IPHPDebugTarget getDebugTarget() {
                return debugTarget;
        }
@@ -265,29 +277,36 @@ public class PHPDBGProxy {
                public void run() {
                        try {
                                char[] buf= new char[16];
-                               int i, pos;
+                               int i, pos, timeout;
                                long interval= 1000*20;
                                String line;
                                PHPStackFrame[] StackList;
                                
-                               System.out.println("Waiting for breakpoints.");                 
+                               //System.out.println("Waiting for breakpoints.");                       
                                try{
                                        socket = server.accept();
-                                       System.out.println("Accepted! : " + socket.toString());
+                                       //System.out.println("Accepted! : " + socket.toString());
                                } catch (IOException e) {
                                        PHPDebugCorePlugin.log(e);
-                                       return;                         
+                                       return;                 
                                }
                                
-                               PHPMainThread= new PHPThread(getDebugTarget(), 100);
+                               PHPMainThread= new PHPThread(getDebugTarget(), getPort());
                                PHPMainThread.setName("Thread [main]");
+                               timeout= 0;
+                               while((getDebugTarget() == null) && (timeout < 100)) {
+                                       sleep(100);
+                                       timeout++;
+                               }
+                               // Be sure debug target is set
+                               PHPMainThread.setDebugTarget(getDebugTarget());
                                getDebugTarget().addThread(PHPMainThread);
-                               setDBGInterface(new PHPDBGInterface(getReader(), getOutputStream()));
+                               setDBGInterface(new PHPDBGInterface(getReader(), getOutputStream(), thisProxy));
 
+                               DBGInt.waitResponse(1000);
                                DBGInt.flushAllPackets();
 
                                // Check version and session ID
-                               
                                setBreakPoints();
                                DBGInt.continueExecution();
 
@@ -300,11 +319,16 @@ public class PHPDBGProxy {
                                                if(StackList.length > 0) {
                                                        for(i=0; i < StackList.length; i++) {
                                                                StackList[i].setThread(PHPMainThread);
+                                                               if(DBGInt.getModByNo(StackList[i].getModNo()).equals("")) {
+                                                                       DBGInt.getSourceTree();
+                                                               }
+                                                               StackList[i].setFile(DBGInt.getModByNo(StackList[i].getModNo()));
                                                        }
                                                        PHPMainThread.setStackFrames(StackList);
                                                }
+                                               // Fire debug event
                                                PHPMainThread.suspend();
-                                               
+
                                                synchronized(this) {
                                                        wait();
                                                }
@@ -315,16 +339,16 @@ public class PHPDBGProxy {
                                PHPDebugCorePlugin.log(ex);
                                System.out.println(ex);
                        } finally {
-                               getDebugTarget().terminate();
                                try {
+                                       getDebugTarget().terminate();
                                        closeSocket();
                                        closeServerSocket();
                                } catch (IOException e) {
                                        PHPDebugCorePlugin.log(e);
                                        return;
                                }
-                               System.out.println("Socket loop finished.");
+                               //System.out.println("Socket loop finished.");
                        }
                }
-       }       
+       }
 }