* @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);
}
} 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?
// 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.
}
/**
*
- * @throws IOException
*/
private Vector getVariables(PHPStackFrame stack, int scope_id) throws IOException {
PHPDBGPacket DBGPacket = new PHPDBGPacket(PHPDBGBase.DBGA_REQUEST);
return new Vector();
}
DBGPacket.sendPacket(os);
+
waitResponse(1000);
flushAllPackets();
}
/**
+ * 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
*/
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
waitResponse(1000);
flushAllPackets();
- PHPDBGEvalString evalStr=new PHPDBGEvalString(stack,evalRet);
+ PHPDBGEvalString evalStr=new PHPDBGEvalString(stack, evalRet);
return evalStr.getVars();
}
// 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--);
}
}
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: //
/**
*
*/
- public PHPDBGEvalString (PHPStackFrame stack, String dataStr) {
- fStackFrame = stack;
- workStr = dataStr;
+ public PHPDBGEvalString(PHPStackFrame stack, String dataStr) {
+ fStackFrame = stack;
+ workStr = dataStr;
}
/**
*/
int ExtractInt (char chstart, char chend, int startIdx) throws DebugException {
String subs;
- int rslt;
subs = ExtractSubStr (chstart, chend, startIdx);
* @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;
*
* @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
}
/**
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
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();
+// }
+// }
+// }
}
/**
*
- * TODO Remove the variables array and use only the varList vector
- * Have also to change hasVariables
*/
public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Comparable {
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
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;
+// }
/**
*
*/
public void setScopeID(int scope_id) {
this.scope_id = scope_id;
- setUpToDate(false);
+ fUpToDate = false;
}
/**
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;
+// }
/**
*
*
* TODO Check where this recursion can come from.
* Whether this back reference is legal or a bug.
+ *
+ * Typically $GLOBALS contains $GLOBALS
*
* @param var
* @return
}
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
}
}
}
* 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()]);
}
* @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();
}
*
*/
public boolean hasVariables() throws DebugException {
- return true;
- // return (varList.size () > 0);
+ if (!fUpToDate) {
+ getVariables();
+ }
+
+ return (varList.size() > 0);
}
public int getLineNumber() {
*
*/
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);
*
*/
public void stepOver() throws DebugException {
- DebugEvent ev;
-
- setUpToDate(false);
+ fUpToDate = false;
thread.prepareForResume(DebugEvent.STEP_OVER);
this.getPHPDBGProxy().readStepOverEnd(PHPStackFrame.this);
*
*/
public void stepReturn() throws DebugException {
- DebugEvent ev;
-
- setUpToDate(false);
+ fUpToDate = false;
thread.prepareForResume(DebugEvent.STEP_RETURN);
this.getPHPDBGProxy().readStepReturnEnd(PHPStackFrame.this);
}
public void resume() throws DebugException {
- setUpToDate(false);
+ fUpToDate = false;
+
this.getThread().resume();
}
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;
+ }
+
}
* with a type specific explanation.
*/
public String toString() {
- int type = -1;
String str = "";
switch (getReferenceType()) {
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;
+ }
+
}