* @param var_list
* @param startIdx
*/
- private 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; // The ref ID (index into vector list)
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())) {
+ if ((var_list == null) ||
+ (v < 0) || (v >= var_list.size ())) { // Check ref ID (index) bounds
//item.ref = item; // self-resolving
return true;
- } else {
- var_item = (PHPVariable) var_list.get(v);
+ }
+ else {
+// This is the original code without the problems of stackframe overflow
+ var_item = (PHPVariable) var_list.get (v); // Get the variable from the list of all variables
+
+ try {
+ item.setValue (var_item.getValue ());
+ item.setReferenceType (var_item.getReferenceType ());
+// ((PHPValue) item.getValue ()).setParent (item); // Set the new variable as parent for all child variables
+ } catch (DebugException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace ();
+ }
+
+ list.add (item);
+
+/*************
+ * this code produces a stackframe overflow if the reference contains loop references
+ var_item = (PHPVariable) var_list.get (v); // Get the referenced variable from the list of variables
+
+ PHPValue new_val = (PHPValue) var_item.getValue ();
- 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);
+ new_val = copyItems (new_val, 0); // Copy the child variables to the new referenced variable
} catch (CloneNotSupportedException e) {
// never occurs
}
//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);
+ item.setValue (new_val);
+ item.setReferenceType (var_item.getReferenceType ());
+ new_val.setParent (item);
} catch (DebugException e) {
// never occurs
}
- list.add(item);
+ list.add (item);
+ */
}
return true;
/*
* Copy referenced items tree
+ *
+ * @note We have to take care of recursion. We have to stop on recursion else
+ * we get a stack overflow!
+ *
+ * @param val The variable for which we build the tree of all childs
*/
- private PHPValue copyItems(PHPValue val) throws CloneNotSupportedException {
- PHPValue newVal = (PHPValue) val.clone();
- Vector vars = newVal.getChildVariables();
- Vector newVars = new Vector();
+ private PHPValue copyItems (PHPValue val, int nDepth) throws CloneNotSupportedException {
+ PHPValue newVal = (PHPValue) val.clone();
+ Vector vars = newVal.getChildVariables();
+ Vector newVars = new Vector();
+
+ nDepth++;
+
+ if (nDepth >= 10) { // A very quick and very dirty way to avoid stack overflow
+ return newVal;
+ }
+
for (int i = 0; i < vars.size(); i++) {
PHPVariable newVar = (PHPVariable) ((PHPVariable) vars.get(i)).clone();
+
try {
- newVar.setValue(copyItems((PHPValue) newVar.getValue()));
+ newVar.setValue (copyItems ((PHPValue) newVar.getValue(), nDepth));
} catch (DebugException e) {
// never occurs
}
- newVars.add(newVar);
+
+ newVars.add (newVar);
}
- val.setVariables(newVars);
+
+ val.setVariables (newVars);
+
return newVal;
}