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 c9cde49..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
@@ -11,11 +11,11 @@ Contributors:
**********************************************************************/
package net.sourceforge.phpdt.internal.debug.core.model;
-import java.util.Arrays;
+import java.util.Collections;
import java.util.Vector;
-import net.sourceforge.phpdt.internal.debug.core.PHPDBGBase;
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;
@@ -29,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 {
@@ -40,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
@@ -69,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;
+// }
/**
*
@@ -102,52 +100,51 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
*/
public void setScopeID(int scope_id) {
this.scope_id = scope_id;
- setUpToDate(false);
+ fUpToDate = false;
}
/**
*
*/
- public IThread getThread () {
+ public IThread getThread() {
return thread;
}
/**
* @param thread
*/
- public void setThread (PHPThread thread) {
+ public void setThread(PHPThread thread) {
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;
+// }
/**
*
*/
- public void setAvailable (boolean available) {
+ public void setAvailable(boolean available) {
fAvailable = available;
}
/**
*
*/
- public boolean isAvailable () {
+ public boolean isAvailable() {
return fAvailable;
}
-
/**
* @see IAdaptable#getAdapter(Class)
*/
@@ -161,28 +158,26 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
/**
*
- *
*/
- private void resetHasChangedInfo (Vector varList) {
+ private void resetHasChangedInfo(Vector varList) {
int n;
PHPVariable var;
- PHPValue val;
+ PHPValue val;
- for (n = 0; n < varList.size (); n++) { // For every variable in 'DBG list'
- var = (PHPVariable) varList.get (n); // Get the variable
- val = (PHPValue) var.getValue (); // Get the variable's value
+ for (n = 0; n < varList.size(); n++) { // For every variable in 'DBG list'
+ var = (PHPVariable) varList.get(n); // Get the variable
+ val = (PHPValue) var.getValue(); // Get the variable's value
try {
- if (val.hasVariables ()) { // Do we have other variables within the value
- if (!hasRecursion (var)) { // Is this variable (value) branch recursive?
- resetHasChangedInfo (val.getChildVariables ()); // No, go into branch
+ if (val.hasVariables()) { // Do we have other variables within the value
+ if (!hasRecursion(var)) { // Is this variable (value) branch recursive?
+ resetHasChangedInfo(val.getChildVariables()); // No, go into branch
}
}
- }
- catch (DebugException e) { // That's, because of the hasVariables method
+ } catch (DebugException e) { // That's, because of the hasVariables method
}
- var.setValueChanged (false); // Reset the 'has changed' flag
+ var.setValueChanged(false); // Reset the 'has changed' flag
}
}
@@ -192,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
@@ -200,26 +197,26 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
*
true if the PHPValue is
*
*/
- private boolean hasRecursion (PHPVariable var) {
+ private boolean hasRecursion(PHPVariable var) {
PHPVariable parentVar;
- PHPValue val;
+ PHPValue val;
- val = (PHPValue) var.getValue (); // Get the PHPValue from the current PHPVariable
+ val = (PHPValue) var.getValue(); // Get the PHPValue from the current PHPVariable
- while (var != null) { // As long as we have PHPVariable
- parentVar = var.getParent (); // Get the parent PHPVariable
+ while (var != null) { // As long as we have PHPVariable
+ parentVar = var.getParent(); // Get the parent PHPVariable
- if (parentVar != null) { // Is there a parent?
- if (parentVar.getValue ().equals (val)) { // Get the PHPValue for the parent PHPVariable and check
+ if (parentVar != null) { // Is there a parent?
+ if (parentVar.getValue().equals(val)) { // Get the PHPValue for the parent PHPVariable and check
// whether it is the same
- return true; // Return, if we have recursion
+ return true; // Return, if we have recursion
}
}
var = parentVar;
}
- return false; // No recursion found
+ return false; // No recursion found
}
/**
@@ -241,76 +238,70 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
* @param varListOld The 'static' list of variables which are to be updated.
* @param varListNew The new list of (current) variables from DBG.
*/
- private void updateVariableList (Vector varListOld, Vector varListNew)
- {
- PHPVariable varOld; // The variable from the 'static' list
- PHPVariable varNew; // The variable from the DBG list
- PHPValue valOld; // The value of the current variable from 'static' list
- PHPValue valNew; // The value of the current variable from DBG list
- int n; // Index for the DBG list
- int o; // Index for the static list
+ private void updateVariableList(Vector varListOld, Vector varListNew) {
+ PHPVariable varOld; // The variable from the 'static' list
+ PHPVariable varNew; // The variable from the DBG list
+ PHPValue valOld; // The value of the current variable from 'static' list
+ PHPValue valNew; // The value of the current variable from DBG list
+ int n; // Index for the DBG list
+ int o; // Index for the static list
// Add the variables (and childs) to the static list if they are new
// and update the values of variables which are already existend within
// the 'static' list.
- for (n = 0; n < varListNew.size (); n++) { // For every variable in 'DBG list'
- varNew = (PHPVariable) varListNew.get (n); // Get the DBG variable
+ for (n = 0; n < varListNew.size(); n++) { // For every variable in 'DBG list'
+ varNew = (PHPVariable) varListNew.get(n); // Get the DBG variable
- for (o = 0; o < varListOld.size (); o++) { // For every variable in static list
- varOld = (PHPVariable) varListOld.get (o); // Get the static variable
+ for (o = 0; o < varListOld.size(); o++) { // For every variable in static list
+ varOld = (PHPVariable) varListOld.get(o); // Get the static variable
- if (varNew.getName ().equals (varOld.getName ())) { // Did we found the variable within the 'static' list?
- valOld = (PHPValue) varOld.getValue (); // Get the value from 'static'
- valNew = (PHPValue) varNew.getValue (); // Get the value from DBG
+ if (varNew.getName().equals(varOld.getName())) { // Did we found the variable within the 'static' list?
+ valOld = (PHPValue) varOld.getValue(); // Get the value from 'static'
+ valNew = (PHPValue) varNew.getValue(); // Get the value from DBG
try {
- if (valOld.hasVariables () || // If the 'static' value has child variables
- valNew.hasVariables ()) { // or if the DBG value has child variables
- if (!hasRecursion (varOld) &&
- !hasRecursion (varNew)) { // Both branches should not have a recursion
- updateVariableList (valOld.getChildVariables (), // Update the variable list for the child variables
- valNew.getChildVariables ());
+ if (valOld.hasVariables() || // If the 'static' value has child variables
+ valNew.hasVariables()) { // or if the DBG value has child variables
+ if (!hasRecursion(varOld) && !hasRecursion(varNew)) { // Both branches should not have a recursion
+ updateVariableList(valOld.getChildVariables(), // Update the variable list for the child variables
+ valNew.getChildVariables());
}
}
- else 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
+ 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
+ } catch (DebugException e) { // That's, because of the hasVariables method
}
- break; // Found the variable,
+ break; // Found the variable,
}
}
- if (o == varListOld.size ()) { // Did we found the variable within the static list?
- varListOld.add (varNew); // No, then add the DBG variable to the static list
+ if (o == varListOld.size()) { // Did we found the variable within the static list?
+ varListOld.add(varNew); // No, then add the DBG variable to the static list
}
}
// Look for the variables we can remove from the 'static' list
- for (o = 0; o < varListOld.size (); o++) { // For every variable in 'static' list
- varOld = (PHPVariable) varListOld.get (o); // Get the static variable
+ for (o = 0; o < varListOld.size(); o++) { // For every variable in 'static' list
+ varOld = (PHPVariable) varListOld.get(o); // Get the static variable
- for (n = 0; n < varListNew.size (); n++) { // For all variables in 'DBG' list
- varNew = (PHPVariable) varListNew.get (n); // Get the variable from the 'DBG' list
+ for (n = 0; n < varListNew.size(); n++) { // For all variables in 'DBG' list
+ varNew = (PHPVariable) varListNew.get(n); // Get the variable from the 'DBG' list
- if (varNew.getName ().equals (varOld.getName ())) { // Did we found the 'static' list variable within the 'DBG' list?
- break; // Yes we found the variable, then leave the loop
+ if (varNew.getName().equals(varOld.getName())) { // Did we found the 'static' list variable within the 'DBG' list?
+ break; // Yes we found the variable, then leave the loop
}
}
- 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
+ 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
}
}
}
@@ -323,51 +314,45 @@ 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);
-
- variables = (PHPVariable[]) varList.toArray(new PHPVariable[varList.size()]);
- Arrays.sort(variables, new PHPVariableComparator());
+ fUpToDate = true;
+ Collections.sort(varList, new PHPVariableComparator());
}
- return variables; // Give the array back to user interface
+ return (PHPVariable[]) varList.toArray(new PHPVariable[varList.size()]);
}
/**
*
*/
- private PHPVariable findVariable (Vector varList, String varname) {
- PHPVariable variable;
- PHPValue value;
- int i;
+ private PHPVariable findVariable(Vector varList, String varname) {
+ PHPVariable variable;
+ PHPValue value;
+ int i;
- for (i = 0; i < varList.size (); i++) { // For all variables
- variable = (PHPVariable) varList.get (i); // Get the variable
- value = (PHPValue) variable.getValue (); // Get the value of the variable
+ for (i = 0; i < varList.size(); i++) { // For all variables
+ variable = (PHPVariable) varList.get(i); // Get the variable
+ value = (PHPValue) variable.getValue(); // Get the value of the variable
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;
+ if (value.hasVariables()) { // Does the variable/value have children
+ if (!hasRecursion(variable)) { // Don't follow recursive variable/values
+ 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
}
- catch (DebugException e) { // That's, because of the hasVariables method
- }
}
return null;
@@ -380,24 +365,23 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
* @param s The variable name we are looking for.
* @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 ()]);
+ public IVariable findVariable(String s) throws DebugException {
+ if (!fUpToDate) {
+ getVariables();
}
- return (findVariable (varList, s)); // Prefix the variable name with $
+ return (findVariable(varList, s)); // Prefix the variable name with $
}
/**
*
*/
- public boolean hasVariables () throws DebugException {
- return true;
- // return (varList.size () > 0);
+ public boolean hasVariables() throws DebugException {
+ if (!fUpToDate) {
+ getVariables();
+ }
+
+ return (varList.size() > 0);
}
public int getLineNumber() {
@@ -421,16 +405,15 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
public String getName() {
StringBuffer name = new StringBuffer();
- if (!this.getDescription().equals ("")) {
- name.append (this.getDescription ());
- }
- else {
- name.append (this.getFileName ());
+ if (!this.getDescription().equals("")) {
+ name.append(this.getDescription());
+ } else {
+ name.append(this.getFileName());
}
- name.append (" [line ");
- name.append (this.getLineNumber ());
- name.append ("]");
+ name.append(" [line ");
+ name.append(this.getLineNumber());
+ name.append("]");
return name.toString();
}
@@ -440,7 +423,7 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
}
public void setDescription(String desc) {
- this.description= desc;
+ this.description = desc;
}
public String getDescription() {
@@ -486,13 +469,11 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
/**
*
*/
- public void stepInto () throws DebugException {
- DebugEvent ev;
-
- setUpToDate (false);
+ public void stepInto() throws DebugException {
+ fUpToDate = false;
- thread.prepareForResume (DebugEvent.STEP_INTO); // Don't know why, but this is necessary
- this.getPHPDBGProxy ().readStepIntoEnd (PHPStackFrame.this);
+ thread.prepareForResume(DebugEvent.STEP_INTO); // Don't know why, but this is necessary
+ this.getPHPDBGProxy().readStepIntoEnd(PHPStackFrame.this);
// Commented out sending the RESUME event because it was already sent by prepareForResume.
// The second RESUME event leads only to a little flickering within the variables view.
@@ -508,13 +489,11 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
/**
*
*/
- public void stepOver () throws DebugException {
- DebugEvent ev;
-
- setUpToDate (false);
+ public void stepOver() throws DebugException {
+ fUpToDate = false;
- thread.prepareForResume (DebugEvent.STEP_OVER);
- this.getPHPDBGProxy ().readStepOverEnd (PHPStackFrame.this) ;
+ thread.prepareForResume(DebugEvent.STEP_OVER);
+ this.getPHPDBGProxy().readStepOverEnd(PHPStackFrame.this);
// See comment within the previous stepInto method.
//
@@ -525,19 +504,16 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
/**
*
*/
- public void stepReturn () throws DebugException {
- DebugEvent ev;
+ public void stepReturn() throws DebugException {
+ fUpToDate = false;
- setUpToDate (false);
-
- thread.prepareForResume (DebugEvent.STEP_RETURN);
- this.getPHPDBGProxy ().readStepReturnEnd (PHPStackFrame.this) ;
+ thread.prepareForResume(DebugEvent.STEP_RETURN);
+ this.getPHPDBGProxy().readStepReturnEnd(PHPStackFrame.this);
//ev = new DebugEvent (this.getThread (), DebugEvent.RESUME, DebugEvent.STEP_RETURN);
//DebugPlugin.getDefault ().fireDebugEventSet (new DebugEvent[] { ev });
}
-
public boolean canResume() {
return this.getThread().canResume();
}
@@ -551,7 +527,8 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
}
public void resume() throws DebugException {
- setUpToDate (false);
+ fUpToDate = false;
+
this.getThread().resume();
}
@@ -574,20 +551,50 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
return index;
}
- public void setIndex (int index) {
+ public void setIndex(int index) {
this.index = index;
}
public PHPDBGProxy getPHPDBGProxy() {
PHPDebugTarget DebugTarget;
- DebugTarget = (PHPDebugTarget) thread.getDebugTarget ();
+ DebugTarget = (PHPDebugTarget) thread.getDebugTarget();
- return DebugTarget.getPHPDBGProxy ();
+ return DebugTarget.getPHPDBGProxy();
}
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() {
@@ -601,19 +608,20 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
* @return
*
* - -1 if the index of this stackframe is less.
- *
- 0 if the index of both stackfream is equal (should no happen).
- *
- 1 if the index of this stackfram is greater.
+ *
- 0 if the index of both stackframes are equal (should no happen).
+ *
- 1 if the index of this stackframe is greater.
*
*/
- public int compareTo (Object obj)
- {
- if (index < ((PHPStackFrame) obj).getIndex ()) {
- return -1;
+ public int compareTo(Object obj) {
+ if (!(obj instanceof PHPStackFrame)) {
+ throw new IllegalArgumentException("A PHPStackFrame can only be compared with another PHPStackFrame");
}
- else if (index > ((PHPStackFrame) obj).getIndex ()) {
+ int frameIndex = ((PHPStackFrame) obj).getIndex();
+ if (index < frameIndex) {
+ return -1;
+ } else if (index > frameIndex) {
return 1;
}
-
return 0;
}
}