Fixed problem opening other sources
authorfvicente <fvicente>
Tue, 11 Nov 2003 03:51:47 +0000 (03:51 +0000)
committerfvicente <fvicente>
Tue, 11 Nov 2003 03:51:47 +0000 (03:51 +0000)
net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDBGInterface.java
net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDBGProxy.java
net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPDebugTarget.java
net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPThread.java

index e7bf98e..72edfed 100644 (file)
@@ -44,11 +44,13 @@ public class PHPDBGInterface {
        private String typeRead= new String("");
        private String className= new String("");
        private int finalPos=0, refCounter=0, rawCounter=1000;
+       private PHPDBGProxy proxy= null;
         
-       public PHPDBGInterface(BufferedReader in, OutputStream os) {
+       public PHPDBGInterface(BufferedReader in, OutputStream os, PHPDBGProxy proxy) {
                DBGBPList.clear();
                this.in= in;
                this.os= os;
+               this.proxy= proxy;
        }
 
        public int addBreakpoint(String mod_name, int line) throws IOException {
@@ -64,8 +66,23 @@ public class PHPDBGInterface {
                PHPDBGFrame DBGFrame= new PHPDBGFrame(PHPDBGBase.FRAME_VER);
                
                DBGPacket.addFrame(DBGFrame);
+
+               if(proxy.getSocket().isClosed()) return;
+               DBGPacket.sendPacket(os);
+       }
+
+       public void getSourceTree() throws IOException {
+               PHPDBGPacket DBGPacket= new PHPDBGPacket(PHPDBGBase.DBGA_REQUEST);
+               PHPDBGFrame DBGFrame= new PHPDBGFrame(PHPDBGBase.FRAME_SRC_TREE);
                
+               DBGPacket.addFrame(DBGFrame);
+               
+               if(proxy.getSocket().isClosed()) return;
                DBGPacket.sendPacket(os);
+
+               // Wait response (1 second) and read response
+               waitResponse(1000);
+               flushAllPackets();
        }
 
        public void addDBGModName(String modName) throws IOException {
@@ -80,6 +97,7 @@ public class PHPDBGInterface {
 
                DBGPacket.addFrame(DBGFrame);
                
+               if(proxy.getSocket().isClosed()) return;
                DBGPacket.sendPacket(os);
        }
 
@@ -128,6 +146,7 @@ public class PHPDBGInterface {
                // Second add command data
                DBGPacket.addFrame(DBGFrame1);
 
+               if(proxy.getSocket().isClosed()) return 0;
                DBGPacket.sendPacket(os);
 
                clearLastBP();
@@ -156,6 +175,7 @@ public class PHPDBGInterface {
        public void continueExecution() throws IOException {
                BPUnderHit= 0;
                PHPDBGPacket DBGPacket= new PHPDBGPacket(PHPDBGBase.DBGA_CONTINUE);
+               if(proxy.getSocket().isClosed()) return;
                DBGPacket.sendPacket(os);
        }
 
@@ -176,24 +196,28 @@ public class PHPDBGInterface {
        public void stepInto() throws IOException {
                BPUnderHit= 0;
                PHPDBGPacket DBGPacket= new PHPDBGPacket(PHPDBGBase.DBGA_STEPINTO);
+               if(proxy.getSocket().isClosed()) return;
                DBGPacket.sendPacket(os);
        }
 
        public void stepOver() throws IOException {
                BPUnderHit= 0;
                PHPDBGPacket DBGPacket= new PHPDBGPacket(PHPDBGBase.DBGA_STEPOVER);
+               if(proxy.getSocket().isClosed()) return;
                DBGPacket.sendPacket(os);
        }
 
        public void stepOut() throws IOException {
                BPUnderHit= 0;
                PHPDBGPacket DBGPacket= new PHPDBGPacket(PHPDBGBase.DBGA_STEPOUT);
+               if(proxy.getSocket().isClosed()) return;
                DBGPacket.sendPacket(os);
        }
 
        public void stopExecution() throws IOException {
                BPUnderHit= 0;
                PHPDBGPacket DBGPacket= new PHPDBGPacket(PHPDBGBase.DBGA_STOP);
+               if(proxy.getSocket().isClosed()) return;
                DBGPacket.sendPacket(os);
        }
 
@@ -216,6 +240,7 @@ public class PHPDBGInterface {
                // Add command data
                DBGPacket.addFrame(DBGFrame1);
                
+               if(proxy.getSocket().isClosed()) return null;
                DBGPacket.sendPacket(os);
 
                waitResponse(1000);
@@ -246,6 +271,7 @@ public class PHPDBGInterface {
                // Add command data
                DBGPacket.addFrame(DBGFrame1);
                
+               if(proxy.getSocket().isClosed()) return;
                DBGPacket.sendPacket(os);
 
                waitResponse(1000);
@@ -538,6 +564,7 @@ public class PHPDBGInterface {
                int[] dbg_bpl_tmp= new int[10];
                int[] dbg_frame= new int[2];
                int[] dbg_eval_tmp= new int[3];
+               int[] dbg_src_tree_tmp= new int[4];
                Vector rawList= new Vector();
                Vector stackList= new Vector();
                PHPStackFrame[] newStackList;
@@ -588,6 +615,21 @@ public class PHPDBGInterface {
                                        case PHPDBGBase.FRAME_SOURCE:
                                                break;
                                        case PHPDBGBase.FRAME_SRC_TREE:
+                                               dbg_src_tree_tmp[0] = PHPDBGBase.Char4ToInt(entirePack, nextFrame + 0);         // parent_mod_no
+                                               dbg_src_tree_tmp[1] = PHPDBGBase.Char4ToInt(entirePack, nextFrame + 4);         // parent_line_no               /* NOT USED */
+                                               dbg_src_tree_tmp[2] = PHPDBGBase.Char4ToInt(entirePack, nextFrame + 8);         // mod_no
+                                               dbg_src_tree_tmp[3] = PHPDBGBase.Char4ToInt(entirePack, nextFrame + 12);        // imod_name
+
+                                               if(getModByNo(dbg_src_tree_tmp[2]).equals("")) {
+                                                       String fileName= new String(getRawFrameData(entirePack, dbg_src_tree_tmp[3]));
+                                                       // Remove '\0' char
+                                                       if(fileName.length() > 0) fileName= fileName.substring(0, fileName.length() - 1);
+
+                                                       if(dbg_src_tree_tmp[2] != 0) {
+                                                               PHPDBGMod modNew= new PHPDBGMod(dbg_src_tree_tmp[2], fileName);
+                                                               DBGMods.add(modNew);
+                                                       }
+                                               }
                                                break;
                                        case PHPDBGBase.FRAME_RAWDATA:
                                                break;
index b9bf0f2..aecbdf0 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 {
 
@@ -40,9 +37,11 @@ public class PHPDBGProxy {
        private IPHPDebugTarget debugTarget= null;
        private PHPLoop phpLoop;
        private PHPThread PHPMainThread;
+       private PHPDBGProxy thisProxy= null;
        private int port;
 
        public PHPDBGProxy() {
+               thisProxy= this;
        }
 
        public void start() {
@@ -81,7 +80,7 @@ public class PHPDBGProxy {
                }
        }
 
-       protected Socket getSocket() throws IOException {
+       public Socket getSocket() throws IOException {
                return socket;
        }
 
@@ -265,7 +264,7 @@ 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;
@@ -279,13 +278,17 @@ public class PHPDBGProxy {
                                        return;                 
                                }
                                
-                               PHPMainThread= new PHPThread(getDebugTarget(), 100);
+                               PHPMainThread= new PHPThread(getDebugTarget(), getPort());
                                PHPMainThread.setName("Thread [main]");
-                               while(getDebugTarget() == null) {
-                                       sleep(1000);
+                               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();
@@ -303,12 +306,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();
                                                }
index 9ecd65e..4f8f8f6 100644 (file)
@@ -231,8 +231,12 @@ public class PHPDebugTarget implements IPHPDebugTarget, ILaunchListener, IDebugE
                        DebugEvent event = events[i];
                        if (event.getKind() == DebugEvent.TERMINATE) {
                                Object source = event.getSource();
-                               if (source instanceof PHPDebugTarget || source instanceof IDebugTarget || source instanceof IProcess) {
+                               if (source instanceof PHPDebugTarget || source instanceof IDebugTarget) {
                                        getPHPDBGProxy().stop();
+                               } else if(source instanceof IProcess) {
+                                       if(getDebugTarget().getProcess() == (IProcess)source) {
+                                               getPHPDBGProxy().stop();
+                                       }
                                }
                        }
                }
index 3d4c2b0..2aad677 100644 (file)
@@ -75,6 +75,10 @@ public class PHPThread implements IThread {
                return target;
        }
 
+       public void setDebugTarget(IDebugTarget target) {
+               this.target= target;
+       }
+       
        public ILaunch getLaunch() {
                return this.getDebugTarget().getLaunch();
        }
@@ -117,7 +121,7 @@ public class PHPThread implements IThread {
        */
 
        public void suspend()  {
-               isStepping = false ;
+               isStepping = false;
                isSuspended = true;
                DebugEvent ev = new DebugEvent(this, DebugEvent.SUSPEND, DebugEvent.BREAKPOINT);
                DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { ev });
@@ -167,6 +171,7 @@ public class PHPThread implements IThread {
        public void terminate() throws DebugException {
                isTerminated = true;
                this.frames = null;
+               getDebugTarget().terminate();
        }
 
        public Object getAdapter(Class arg0) {