Modified: 1764120 - Variables View doesn't show global vars in class context
[phpeclipse.git] / net.sourceforge.phpeclipse.debug.core / src / net / sourceforge / phpdt / internal / debug / core / PHPDBGInterface.java
index 5769aab..cf17c49 100644 (file)
@@ -421,24 +421,18 @@ 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);
+               Vector globalList = getVariables(DBGStackList[DBGStackList.length - 1], PHPDBGBase.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 +453,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 +472,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 +485,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 +500,7 @@ public class PHPDBGInterface {
                        return new Vector();
                }
                DBGPacket.sendPacket(os);
+
                waitResponse(1000);
                flushAllPackets();
 
@@ -514,6 +509,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 +580,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 +605,7 @@ public class PHPDBGInterface {
                waitResponse(1000);
                flushAllPackets();
 
-               PHPDBGEvalString evalStr=new PHPDBGEvalString(stack,evalRet);
+               PHPDBGEvalString evalStr=new PHPDBGEvalString(stack, evalRet);
 
                return evalStr.getVars();
        }
@@ -813,17 +836,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 +1024,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:                                                          //