X-Git-Url: http://git.phpeclipse.com 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..245dc76 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 @@ -15,6 +15,7 @@ import java.util.Collections; import java.util.Vector; import net.sourceforge.phpdt.internal.debug.core.PHPDBGProxy; +import net.sourceforge.phpdt.internal.debug.core.PHPDebugCorePlugin; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.debug.core.DebugEvent; @@ -28,8 +29,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 +38,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 +66,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 +100,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 +117,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 +187,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 @@ -266,16 +267,14 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa updateVariableList(valOld.getChildVariables(), // Update the variable list for the child variables valNew.getChildVariables()); } - } else if (!valOld.getValueString().equals( + } + if (!valOld.getValueString().equals( valNew.getValueString())) { // Has the value changed? valOld.setValueString(valNew.getValueString()); // Yes, set the 'static' value (variable) to the new value varOld.setValueChanged(true); // and set the 'has changed' flag, so that the variable view // could show the user the changed status with a different // color } - //else { - // varOld.setValueChanged (false); // Reset the 'has changed' flag - //} } catch (DebugException e) { // That's, because of the hasVariables method } @@ -302,8 +301,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 +314,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()]); } @@ -349,15 +342,14 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa try { if (value.hasVariables()) { // Does the variable/value have children if (!hasRecursion(variable)) { // Don't follow recursive variable/values - variable = findVariable(value.getChildVariables(), - varname); - - if (variable != null) { - return variable; + PHPVariable var = findVariable(value.getChildVariables(), varname); + if (var != null) { + return var; } } - } else if ((variable.getName()).equals(varname)) { // - return variable; // + } + if (variable.getName().equals(varname)) { + return variable; } } catch (DebugException e) { // That's, because of the hasVariables method } @@ -374,11 +366,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 +377,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 +470,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 +490,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 +505,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 +527,8 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa } public void resume() throws DebugException { - setUpToDate(false); + fUpToDate = false; + this.getThread().resume(); } @@ -579,6 +565,36 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa public void setFile(String file) { this.file = file; + + final String COMPILED_EVAL = "eval()'d code"; + final String COMPILED_LAMBDA = "runtime-created function"; + + int i = 0; + if (file.endsWith(COMPILED_EVAL)) { + i = file.length() - COMPILED_EVAL.length(); + } else if (file.endsWith(COMPILED_LAMBDA)) { + i = file.length() - COMPILED_LAMBDA.length(); + } + if (i > 0) { + // assume COMPILED_STRING_DESCRIPTION_FORMAT + // "filename(linenumber) : string" + int j = i; + while (--i > 0) { + switch (file.charAt(i)) { + case ')': + j = i; + break; + case '(': + this.file = file.substring(0, i); + try { + lineNumber = Integer.parseInt(file.substring(i + 1, j)); + } catch (NumberFormatException e) { + PHPDebugCorePlugin.log(e); + } + return; + } + } + } } public int getModNo() { @@ -592,18 +608,20 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa * @return * */ public int compareTo(Object obj) { - //if (index < ((PHPStackFrame) obj).getIndex()) { - // return -1; - //} else if (index > ((PHPStackFrame) obj).getIndex()) { - // return 1; - //} - - //return 0; - return Integer.signum(index - ((PHPStackFrame) obj).getIndex()); + if (!(obj instanceof PHPStackFrame)) { + throw new IllegalArgumentException("A PHPStackFrame can only be compared with another PHPStackFrame"); + } + int frameIndex = ((PHPStackFrame) obj).getIndex(); + if (index < frameIndex) { + return -1; + } else if (index > frameIndex) { + return 1; + } + return 0; } }