From: toshihiro Date: Sun, 12 Aug 2007 00:32:45 +0000 (+0000) Subject: Modified: 1764120 - Variables View doesn't show global vars in class context X-Git-Url: http://secure.phpeclipse.com Modified: 1764120 - Variables View doesn't show global vars in class context --- diff --git a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDBGInterface.java b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDBGInterface.java index 5769aab..cf17c49 100644 --- a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDBGInterface.java +++ b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDBGInterface.java @@ -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: // diff --git a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPDBGEvalString.java b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPDBGEvalString.java index 8916bce..1439ed9 100644 --- a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPDBGEvalString.java +++ b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPDBGEvalString.java @@ -31,9 +31,9 @@ public class PHPDBGEvalString { /** * */ - public PHPDBGEvalString (PHPStackFrame stack, String dataStr) { - fStackFrame = stack; - workStr = dataStr; + public PHPDBGEvalString(PHPStackFrame stack, String dataStr) { + fStackFrame = stack; + workStr = dataStr; } /** @@ -107,7 +107,6 @@ public class PHPDBGEvalString { */ int ExtractInt (char chstart, char chend, int startIdx) throws DebugException { String subs; - int rslt; subs = ExtractSubStr (chstart, chend, startIdx); @@ -396,34 +395,47 @@ public class PHPDBGEvalString { * @param var_list * @param startIdx */ - boolean ParseEvalRef (String name, PHPVariable parent, Vector list, Vector var_list, boolean isSoftRef, int startIdx) throws DebugException { - int v; + private boolean ParseEvalRef(String name, PHPVariable parent, Vector list, + Vector var_list, boolean isSoftRef, int startIdx) + throws DebugException { + int v; PHPVariable item; PHPVariable var_item; - v = ExtractInt(':', ';',startIdx); - item = new PHPVariable (fStackFrame, name, parent, "", (isSoftRef) ? (PHPValue.PEVT_SOFTREF) : (PHPValue.PEVT_REF), null); - v--; // ref ID is 1-based, EvalList is 0-based + v = ExtractInt(':', ';', startIdx); + item = new PHPVariable(fStackFrame, name, parent, "", + isSoftRef ? PHPValue.PEVT_SOFTREF : PHPValue.PEVT_REF, null); + v--; // ref ID is 1-based, EvalList is 0-based - if ((var_list == null) || - (v < 0) || - (v >= var_list.size ())) { -// item.ref = item; // self-resolving -// + if ((var_list == null) || (v < 0) || (v >= var_list.size())) { + //item.ref = item; // self-resolving return true; } else { - var_item = (PHPVariable) var_list.get (v); + var_item = (PHPVariable) var_list.get(v); + + PHPValue new_val = (PHPValue) var_item.getValue(); + if (isSoftRef) { + // expand reduced structure to full tree + // each value must have its appropriate parent + try { + new_val = copyItems(new_val); + } catch (CloneNotSupportedException e) { + // never occurs + } + } try { - item.setValue (var_item.getValue ()); - item.setReferenceType (var_item.getReferenceType ()); - ((PHPValue) item.getValue ()).setParent (item); + //item.setValue(var_item.getValue()); + //item.setReferenceType(var_item.getReferenceType()); + //((PHPValue) item.getValue()).setParent(item); + item.setValue(new_val); + item.setReferenceType(var_item.getReferenceType()); + new_val.setParent(item); } catch (DebugException e) { - // TODO Auto-generated catch block - e.printStackTrace (); + // never occurs } - list.add (item); + list.add(item); } return true; @@ -433,26 +445,27 @@ public class PHPDBGEvalString { * * @return The array of PHPVariables */ - public PHPVariable[] getVars () { - Vector list = new Vector (); - Vector var_list = new Vector (); + public PHPVariable[] getVars() { + Vector list = new Vector(); + Vector var_list = new Vector(); - parse ("", null, list, var_list, false, 0); + parse("", null, list, var_list, false, 0); - return (PHPVariable[]) list.toArray (new PHPVariable[list.size ()]); // Convert the list to an array and return the array + return (PHPVariable[]) list.toArray(new PHPVariable[list.size()]); // Convert the list to an array and return the array } /** * * @return The PHPVariables as list */ - public Vector getVariables () { - Vector list = new Vector (); - Vector var_list = new Vector (); + public Vector getVariables() { + Vector list = new Vector(); + Vector var_list = new Vector(); - parse ("", null, list, var_list, false, 0); + parse("", null, list, var_list, false, 0); - return list; // return the PHPVariable list + //debugDump(list, ""); + return list; // return the PHPVariable list } /** @@ -492,8 +505,7 @@ public class PHPDBGEvalString { case '?': ParseEvalUnknown(name, parent, list, var_list, startIdx); break; } } catch (DebugException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + PHPDebugCorePlugin.log(e); } /* if (!ret_val) { // try to recover @@ -537,4 +549,43 @@ public class PHPDBGEvalString { var_list.add(item); } } + + /* + * Copy referenced items tree + */ + private PHPValue copyItems(PHPValue val) throws CloneNotSupportedException { + PHPValue newVal = (PHPValue) val.clone(); + Vector vars = newVal.getChildVariables(); + Vector newVars = new Vector(); + for (int i = 0; i < vars.size(); i++) { + PHPVariable newVar = (PHPVariable) ((PHPVariable) vars.get(i)).clone(); + try { + newVar.setValue(copyItems((PHPValue) newVar.getValue())); + } catch (DebugException e) { + // never occurs + } + newVars.add(newVar); + } + val.setVariables(newVars); + return newVal; + } + +// private void debugDump(Vector list, String indent) { +// for (int i = 0; i < list.size(); i++) { +// PHPVariable var = (PHPVariable) list.get(i); +// System.out.print(indent + var.getName()); +// PHPValue val = (PHPValue) var.getValue(); +// try { +// if (val.hasVariables() && !var.getName().equals("['GLOBALS']")) { +// System.out.println(); +// debugDump(val.getChildVariables(), indent + " "); +// } else { +// PHPVariable parent = var.getParent(); +// System.out.println(val.getValueString() + " \t>>" + (parent == null ? "null" : parent.getLongName())); +// } +// } catch (DebugException e) { +// e.printStackTrace(); +// } +// } +// } } diff --git a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPStackFrame.java b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPStackFrame.java index 19a0843..43b2117 100644 --- a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPStackFrame.java +++ b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPStackFrame.java @@ -28,8 +28,6 @@ import org.eclipse.debug.core.model.IVariable; /** * - * TODO Remove the variables array and use only the varList vector - * Have also to change hasVariables */ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Comparable { @@ -39,8 +37,7 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa private int index; private int modno; private int scope_id; // scope id - //private PHPVariable[] variables; // The array of variables TODO: better introduce a vector? - private Vector varList = new Vector(); + private Vector varList; // Variables list private String description; // The source file name with the full path on target/remote system private boolean fUpToDate; // Indicates whether the variable list within this stackframe is // up-to-date @@ -68,25 +65,26 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa this.description = desc; this.modno = modno; this.scope_id = scope_id; + this.varList = new Vector(); this.fUpToDate = false; } - /** - * - * @param thread - * @param file - * @param line - * @param index - */ - public PHPStackFrame(PHPThread thread, String file, int line, int index) { - super(null); - - this.lineNumber = line; - this.index = index; - this.file = file; - this.thread = thread; - this.fUpToDate = false; - } +// /** +// * +// * @param thread +// * @param file +// * @param line +// * @param index +// */ +// public PHPStackFrame(PHPThread thread, String file, int line, int index) { +// super(null); +// +// this.lineNumber = line; +// this.index = index; +// this.file = file; +// this.thread = thread; +// this.fUpToDate = false; +// } /** * @@ -101,7 +99,7 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa */ public void setScopeID(int scope_id) { this.scope_id = scope_id; - setUpToDate(false); + fUpToDate = false; } /** @@ -118,19 +116,19 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa this.thread = thread; } - /** - * - */ - private void setUpToDate(boolean upToDate) { - fUpToDate = upToDate; - } +// /** +// * +// */ +// private void setUpToDate(boolean upToDate) { +// fUpToDate = upToDate; +// } - /** - * - */ - private boolean isUpToDate() { - return fUpToDate; - } +// /** +// * +// */ +// private boolean isUpToDate() { +// return fUpToDate; +// } /** * @@ -188,6 +186,8 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa * * TODO Check where this recursion can come from. * Whether this back reference is legal or a bug. + * + * Typically $GLOBALS contains $GLOBALS * * @param var * @return @@ -302,8 +302,7 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa } if (n == varListNew.size()) { // Did not find the 'static' list variable within the 'DBG' list? - varListOld.remove(o); // then remove the 'static' list variable from list - o -= 1; // Adjust the 'static' list index + varListOld.remove(o--); // then remove the 'static' list variable from list } } } @@ -316,21 +315,16 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa * A PHPVariable with the same name but with different object ID is * handled as a new variable. * - * TODO Remove the intermediate storage array - * * @return The array of PHPVariables for this stackframe. */ public IVariable[] getVariables() throws DebugException { - if (!isUpToDate()) { + if (!fUpToDate) { resetHasChangedInfo(varList); updateVariableList(varList, this.getPHPDBGProxy().readVariables(this)); - setUpToDate(true); + fUpToDate = true; Collections.sort(varList, new PHPVariableComparator()); - //variables = (PHPVariable[]) varList.toArray(new PHPVariable[varList.size()]); - //Arrays.sort(variables, new PHPVariableComparator()); } - //return variables; // Give the array back to user interface return (PHPVariable[]) varList.toArray(new PHPVariable[varList.size()]); } @@ -374,11 +368,7 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa * @return */ public IVariable findVariable(String s) throws DebugException { - if (!isUpToDate()) { - //resetHasChangedInfo(varList); - //updateVariableList(varList, this.getPHPDBGProxy().readVariables(this)); - //setUpToDate(true); - //variables = (PHPVariable[]) varList.toArray(new PHPVariable[varList.size()]); + if (!fUpToDate) { getVariables(); } @@ -389,8 +379,11 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa * */ public boolean hasVariables() throws DebugException { - return true; - // return (varList.size () > 0); + if (!fUpToDate) { + getVariables(); + } + + return (varList.size() > 0); } public int getLineNumber() { @@ -479,9 +472,7 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa * */ public void stepInto() throws DebugException { - DebugEvent ev; - - setUpToDate(false); + fUpToDate = false; thread.prepareForResume(DebugEvent.STEP_INTO); // Don't know why, but this is necessary this.getPHPDBGProxy().readStepIntoEnd(PHPStackFrame.this); @@ -501,9 +492,7 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa * */ public void stepOver() throws DebugException { - DebugEvent ev; - - setUpToDate(false); + fUpToDate = false; thread.prepareForResume(DebugEvent.STEP_OVER); this.getPHPDBGProxy().readStepOverEnd(PHPStackFrame.this); @@ -518,9 +507,7 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa * */ public void stepReturn() throws DebugException { - DebugEvent ev; - - setUpToDate(false); + fUpToDate = false; thread.prepareForResume(DebugEvent.STEP_RETURN); this.getPHPDBGProxy().readStepReturnEnd(PHPStackFrame.this); @@ -542,7 +529,8 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa } public void resume() throws DebugException { - setUpToDate(false); + fUpToDate = false; + this.getThread().resume(); } diff --git a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPValue.java b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPValue.java index ef5d52d..4d511ee 100644 --- a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPValue.java +++ b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPValue.java @@ -236,4 +236,25 @@ public class PHPValue implements IValue { fHasChanged = changed; } + /* + * ONLY FOR net.sourceforge.phpdt.internal.debug.core.model.PHPDBGEvalString#copyItems(PHPVariable, PHPValue) + */ + protected void setVariables(Vector variables) { + fVariables = variables; + } + + /* + * ONLY FOR net.sourceforge.phpdt.internal.debug.core.model.PHPDBGEvalString#copyItems(PHPVariable, PHPValue) + */ + protected Object clone() throws CloneNotSupportedException { + PHPValue val = new PHPValue(); + val.fValueType = fValueType; + val.fValueString = fValueString; + val.fVariables = fVariables; + val.fStackFrame = fStackFrame; + val.fHasChanged = fHasChanged; + val.fSorted = fSorted; + return val; + } + } diff --git a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPVariable.java b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPVariable.java index e452669..94d3c99 100644 --- a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPVariable.java +++ b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPVariable.java @@ -297,7 +297,6 @@ public class PHPVariable implements IVariable { * with a type specific explanation. */ public String toString() { - int type = -1; String str = ""; switch (getReferenceType()) { @@ -335,4 +334,19 @@ public class PHPVariable implements IVariable { return str; } + + /* + * ONLY FOR net.sourceforge.phpdt.internal.debug.core.model.PHPDBGEvalString#copyItems(PHPVariable, PHPValue) + */ + protected Object clone() throws CloneNotSupportedException { + PHPVariable var = new PHPVariable(); + var.fValue = fValue; + var.fName = fName; + var.fStackFrame = fStackFrame; + var.fParent = fParent; + var.fLongName = fLongName; + var.fModifiable = fModifiable; + return var; + } + }