Refactory: remove unused classes, imports, fields and methods.
[phpeclipse.git] / net.sourceforge.phpeclipse.debug.core / src / net / sourceforge / phpdt / internal / debug / core / PHPDBGInterface.java
index 5769aab..4da1970 100644 (file)
@@ -17,6 +17,7 @@ import java.io.OutputStream;
 import java.util.Collections;
 import java.util.Vector;
 
+//import net.sourceforge.phpdt.internal.debug.core.PHPDBGProxy.PHPLoop;
 import net.sourceforge.phpdt.internal.debug.core.model.PHPDBGEvalString;
 import net.sourceforge.phpdt.internal.debug.core.model.PHPStackFrame;
 import net.sourceforge.phpdt.internal.debug.core.model.PHPValue;
@@ -48,7 +49,7 @@ public class PHPDBGInterface {
        private String                  evalRet = new String("");
        private int                             rawCounter = 1000;                                      // An rawData frame ID counter
        private PHPDBGProxy             proxy = null;
-       private int                             lastCmd = -1;
+       //private int                           lastCmd = -1;
        private int                             sid = 0;
        private boolean                         stopOnError = false;
        private char[]                  lastCommand = new char[4];
@@ -95,21 +96,21 @@ public class PHPDBGInterface {
         * Is this method used anywhere?
         *
         */
-       public void requestDBGVersion () throws IOException {
-               PHPDBGPacket DBGPacket;                                     // A DBG message packet
-               PHPDBGFrame  DBGFrame;                                      // A frame within a DBG packet
-
-               DBGPacket = new PHPDBGPacket (PHPDBGBase.DBGA_REQUEST);     // A request for DBG
-               DBGFrame  = new PHPDBGFrame (PHPDBGBase.FRAME_VER);         // We want the version of DBG
-
-               DBGPacket.addFrame (DBGFrame);                              // Add the 'what we want' to the DBG packet
-
-               if (proxy.getSocket ().isClosed ()) {                                           // Can we communiate with DBG?
-                       return;                                                 //  No
-               }
-
-               DBGPacket.sendPacket (os);                                                                      // Send the request to DBG
-       }
+//     public void requestDBGVersion () throws IOException {
+//             PHPDBGPacket DBGPacket;                                     // A DBG message packet
+//             PHPDBGFrame  DBGFrame;                                      // A frame within a DBG packet
+//
+//             DBGPacket = new PHPDBGPacket (PHPDBGBase.DBGA_REQUEST);     // A request for DBG
+//             DBGFrame  = new PHPDBGFrame (PHPDBGBase.FRAME_VER);         // We want the version of DBG
+//
+//             DBGPacket.addFrame (DBGFrame);                              // Add the 'what we want' to the DBG packet
+//
+//             if (proxy.getSocket ().isClosed ()) {                                           // Can we communiate with DBG?
+//                     return;                                                 //  No
+//             }
+//
+//             DBGPacket.sendPacket (os);                                                                      // Send the request to DBG
+//     }
 
        /**
         * Called by the proxy
@@ -139,27 +140,27 @@ public class PHPDBGInterface {
         *
         * @param modName The modul (filename).
         */
-       public void addDBGModName (String modName) throws IOException {
-               PHPDBGPacket DBGPacket;                                     // A DBG message packet
-               PHPDBGFrame  DBGFrame;                                      // A frame within a DBG packet
-
-               DBGPacket = new PHPDBGPacket (PHPDBGBase.DBGA_REQUEST);     // A request for DBG
-               DBGFrame  = new PHPDBGFrame (PHPDBGBase.FRAME_RAWDATA);     // We want Module name from DBG
-
-               rawCounter++;                                               // Increment the rawData ID counter
-               DBGFrame.addInt (rawCounter);                                                           // FRAME_RAWDATA ID
-               DBGFrame.addInt (modName.length () + 1);                                        // The length of rawdata string (incl. null char termination)
-               DBGFrame.addString (modName);                                                           // The file name (module name)
-               DBGFrame.addChar ('\0');                                                                        // Add the C-String null termination
-
-               DBGPacket.addFrame (DBGFrame);
-
-               if (proxy.getSocket ().isClosed ()) {                                           // Can we communiate with DBG?
-                       return;                                                                                                 //  No
-               }
-
-               DBGPacket.sendPacket (os);
-       }
+//     public void addDBGModName (String modName) throws IOException {
+//             PHPDBGPacket DBGPacket;                                     // A DBG message packet
+//             PHPDBGFrame  DBGFrame;                                      // A frame within a DBG packet
+//
+//             DBGPacket = new PHPDBGPacket (PHPDBGBase.DBGA_REQUEST);     // A request for DBG
+//             DBGFrame  = new PHPDBGFrame (PHPDBGBase.FRAME_RAWDATA);     // We want Module name from DBG
+//
+//             rawCounter++;                                               // Increment the rawData ID counter
+//             DBGFrame.addInt (rawCounter);                                                           // FRAME_RAWDATA ID
+//             DBGFrame.addInt (modName.length () + 1);                                        // The length of rawdata string (incl. null char termination)
+//             DBGFrame.addString (modName);                                                           // The file name (module name)
+//             DBGFrame.addChar ('\0');                                                                        // Add the C-String null termination
+//
+//             DBGPacket.addFrame (DBGFrame);
+//
+//             if (proxy.getSocket ().isClosed ()) {                                           // Can we communiate with DBG?
+//                     return;                                                                                                 //  No
+//             }
+//
+//             DBGPacket.sendPacket (os);
+//     }
 
        /**
         * This method is called for adding or removing breakpoints.
@@ -286,7 +287,6 @@ public class PHPDBGInterface {
                if (proxy.getSocket ().isClosed ()) {                                           // Can we communiate with DBG?
                        return;                                                 //  No
                }
-
                DBGPacket.sendPacket (os);                                  // Send the request to DBG
 
                lastCommand = PHPDBGBase.DBGA_CONTINUE;                     // Store the info about the command we sent
@@ -326,10 +326,10 @@ public class PHPDBGInterface {
                return BPUnder;
        }
 
-       public int getLastCmd()
-       {
-               return lastCmd;
-       }
+//     public int getLastCmd()
+//     {
+//             return lastCmd;
+//     }
 
        public int getSID()
        {
@@ -338,7 +338,7 @@ public class PHPDBGInterface {
 
        public void setLastCmd (int cmd)
        {
-               lastCmd = cmd;
+               //lastCmd = cmd;
        }
 
        /**
@@ -398,18 +398,18 @@ public class PHPDBGInterface {
        /**
         *
         */
-       public void stopExecution () throws IOException {
-               PHPDBGPacket DBGPacket;
-
-               BPUnderHit = 0;
-               DBGPacket  = new PHPDBGPacket (PHPDBGBase.DBGA_STOP);
-
-               if (proxy.getSocket ().isClosed ()) {                                           // Can we communiate with DBG?
-                       return;                                                 //  No
-               }
-
-               DBGPacket.sendPacket (os);                                  // Send the request to DBG
-       }
+//     public void stopExecution () throws IOException {
+//             PHPDBGPacket DBGPacket;
+//
+//             BPUnderHit = 0;
+//             DBGPacket  = new PHPDBGPacket (PHPDBGBase.DBGA_STOP);
+//
+//             if (proxy.getSocket ().isClosed ()) {                                           // Can we communiate with DBG?
+//                     return;                                                 //  No
+//             }
+//
+//             DBGPacket.sendPacket (os);                                  // Send the request to DBG
+//     }
 
        /**
         * This method is called by the proxy.
@@ -421,24 +421,23 @@ public class PHPDBGInterface {
         * @return      The array of variables
         */
        public synchronized Vector getVariables(PHPStackFrame stack) throws IOException, DebugException {
-               PHPDBGPacket            DBGPacket;
-               PHPDBGFrame             DBGFrame1;
-               PHPDBGEvalString        evalStr;
+               if (DBGStackList.length == 0) {
+                       DBGVarList.clear();
+                       return DBGVarList;
+               }
 
                // get global variables (and assign them to 'main()' stackframe)
-               Vector globalList = new Vector();
-               globalList = getVariables(DBGStackList[DBGStackList.length - 1], PHPDBGBase.GLOBAL_SCOPE_ID);
+               int global_scope_id = (DBGStackList.length > 1) ? 2 : PHPDBGBase.GLOBAL_SCOPE_ID;
+               // DBG 2.13.1 doesn't return Super Globals with GLOBAL_SCOPE_ID in nested stackframes,
+               // so using 2(most out-standing stack context) instead of GLOBAL_SCOPE_ID.
+               // Also note that 2.13.1 doesn't return $this in class context.
+               // (You can inspect $this in Expressions View. And once it is shown, 2.13.1 comes to return $this.)
+               Vector globalList = getVariables(DBGStackList[DBGStackList.length - 1], global_scope_id);
                if (!globalList.isEmpty()) {
-                       // remove unexpected '$this=?' variable
+                       // remove unresolved '$this=?' variable
+                       removeUnresolvedThisVar(globalList);
+
                        PHPVariable var = (PHPVariable) globalList.get(0);
-                       PHPValue val = (PHPValue) var.getValue();
-                       Vector workList = val.getChildVariables();
-                       for (int i = 0; i < workList.size(); i++) {
-                               if (((PHPVariable) workList.get(i)).getName().equals("$this")) {
-                                       workList.remove(i);
-                                       break;
-                               }
-                       }
                        var.setName(GlobalVariablesTitle);
                        var.setModifiable(false);
                }
@@ -459,9 +458,10 @@ public class PHPDBGInterface {
 
                } else {
                        // back-trace stackframe
-                       DBGVarList = getVariables(stack, scopeID);
-                       // DBG 2.15.5 causes Application Error (on win32) in some cases
-                       //DBGVarList.clear();
+                       //DBGVarList = getVariables(stack, scopeID);
+                       //removeUnresolvedThisVar(DBGVarList);
+                       // DBG 2.15.5 causes Application Error (on win32) in *some* cases.
+                       DBGVarList.clear();
                }
 
                if (DBGVarList.size() > 0) {                                                            // Did we get back variables?
@@ -477,7 +477,7 @@ public class PHPDBGInterface {
                                                                                                                                        // The eclipse variable view cannot handle Variables which have an empty name
                                                                                                                                        // when it comes to variable tree restore operation. Without a name, no restore!
                                //var.setName (" ");                                                            // Give a name to the variable root node. Even if it is only a space :-)
-                       }                                                                                                               // TODO the best would be to remove the empty root node, but this would
+                       }                                                                                                               // TO DO the best would be to remove the empty root node, but this would
                                                                                                                                        // require a understanding and reworking of the PHPDBGEvalstring class.
                }
 
@@ -490,7 +490,6 @@ public class PHPDBGInterface {
 
        /**
         * 
-        * @throws IOException 
         */
        private Vector getVariables(PHPStackFrame stack, int scope_id) throws IOException {
                PHPDBGPacket DBGPacket = new PHPDBGPacket(PHPDBGBase.DBGA_REQUEST);
@@ -506,6 +505,7 @@ public class PHPDBGInterface {
                        return new Vector();
                }
                DBGPacket.sendPacket(os);
+
                waitResponse(1000);
                flushAllPackets();
 
@@ -514,6 +514,32 @@ public class PHPDBGInterface {
        }
 
        /**
+        * Remove unresolved $this variable
+        * 
+        * DBG returns $this=? in function's or intermediate stackframes.
+        * (In current method's stackframe, DBG returns $this=classname)
+        * 
+        * @param varList
+        */
+       private void removeUnresolvedThisVar(Vector varList) {
+               if (varList.size() > 0) {
+                       PHPVariable var = (PHPVariable) varList.get(0);
+                       PHPValue val = (PHPValue) var.getValue();
+                       Vector workList = val.getChildVariables();
+                       for (int i = 0; i < workList.size(); i++) {
+                               PHPVariable workvar = (PHPVariable) workList.get(i);
+                               if (workvar.getName().equals("$this")) {
+                                       String workval = ((PHPValue) workvar.getValue()).getValueString();
+                                       if (workval.equals("?") || workval.equals("NULL")) {
+                                               workList.remove(i);
+                                       }
+                                       break;
+                               }
+                       }
+               }
+       }
+
+       /**
         *
         * @param logString
         */
@@ -559,9 +585,11 @@ public class PHPDBGInterface {
                DBGFrame1.addInt(rawCounter);                           // istr = raw data ID
                //DBGFrame1.addInt(1);                                          // scope_id = -1 means current location, 0 never used, +1 first depth
                int scope_id = stack.getScopeID();
-               if (DBGStackList.length == 1 || scope_id == PHPDBGBase.CURLOC_SCOPE_ID + 1) {
+               /* test code : unnecessary
+               if (DBGStackList.length == 1 || scope_id == (PHPDBGBase.CURLOC_SCOPE_ID + 1)) {
                        scope_id = PHPDBGBase.GLOBAL_SCOPE_ID;
-               } //-
+               }
+               */
                DBGFrame1.addInt(scope_id);
 
                DBGFrame2.addInt(rawCounter);                           // FRAME_RAWDATA ID
@@ -582,7 +610,7 @@ public class PHPDBGInterface {
                waitResponse(1000);
                flushAllPackets();
 
-               PHPDBGEvalString evalStr=new PHPDBGEvalString(stack,evalRet);
+               PHPDBGEvalString evalStr=new PHPDBGEvalString(stack, evalRet);
 
                return evalStr.getVars();
        }
@@ -813,17 +841,11 @@ public class PHPDBGInterface {
 
                // And now for removing unused stackframes from list
 
-               for (n = 0; n < stackListOld.size (); n++) {                                            // For all StackFrames in the StackFrame list
-                       stackFrameOld = (PHPStackFrame) stackListOld.get (n);                           //
-
-                       i = 0;
-                       if (!stackFrameOld.isAvailable ()) {
-                               i = stackList.size ();
-                       }
+               for (n = 0; n < stackListOld.size(); n++) {
+                       stackFrameOld = (PHPStackFrame) stackListOld.get(n);
 
-                       if (i == stackList.size ()) {                                           // Did not find the old stackframe within the list of new ones
-                                stackListOld.remove (n);                                       //  then remove the old stackframe from list
-                                n -= 1;                                                        // Adjust the stack list index
+                       if (!stackFrameOld.isAvailable()) {
+                               stackListOld.remove(n--);
                        }
                }
 
@@ -1007,15 +1029,15 @@ public class PHPDBGInterface {
                                                break;
 
                                        case PHPDBGBase.FRAME_EVAL:
-                                               String evalString;
+                                               //String evalString;
 
-                                               evalString      = new String ("");
+                                               //evalString      = new String ("");
                                                dbg_eval_tmp[0] = PHPDBGBase.Char4ToInt (entirePack, nextFrame + 0);                    // istr
                                                dbg_eval_tmp[1] = PHPDBGBase.Char4ToInt (entirePack, nextFrame + 4);                    // iresult
                                                dbg_eval_tmp[2] = PHPDBGBase.Char4ToInt (entirePack, nextFrame + 8);                    // ierror
 
                                                evalRet                 = getRawFrameData (entirePack, dbg_eval_tmp[1]);                //
-                                               evalString              = getRawFrameData (entirePack, dbg_eval_tmp[0]);                //
+                                               //evalString    = getRawFrameData (entirePack, dbg_eval_tmp[0]);                //
                                                break;
 
                                        case PHPDBGBase.FRAME_BPS:                                                          //
@@ -1105,8 +1127,8 @@ public class PHPDBGInterface {
                                        break;
 
                                case PHPDBGBase.DBGC_END:
-                                       sessionEnded = true;
-                                       this.proxy.setTerminated();
+                                        sessionEnded = true; 
+                                        this.proxy.setTerminated(); 
                                        break;
 
                                case PHPDBGBase.DBGC_BREAKPOINT: