X-Git-Url: http://secure.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 af564eb..a819140 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,6 +11,8 @@ Contributors: **********************************************************************/ package net.sourceforge.phpdt.internal.debug.core.model; +import java.util.Vector; + import net.sourceforge.phpdt.internal.debug.core.PHPDBGProxy; import org.eclipse.debug.core.DebugEvent; @@ -23,80 +25,167 @@ import org.eclipse.debug.core.model.IStackFrame; import org.eclipse.debug.core.model.IThread; import org.eclipse.debug.core.model.IVariable; -public class PHPStackFrame implements IStackFrame { +/** + * + * 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 PHPThread thread; - private String file; - private int lineNumber; - private int index; - private int modno; - private PHPVariable[] variables; - private String description; + private PHPThread thread; // The thread to which this stackframe belongs + private String file; // The file name??? + private int lineNumber; // + private int index; // + private int modno; // + private PHPVariable[] variables; // The array of variables TODO: better introduce a vector? + private Vector varList = new Vector (); + private String description; // - public PHPStackFrame(PHPThread thread, String file, int line, int index, String desc, int modno) { - this.lineNumber = line; - this.index = index; - this.file = file; - this.thread = thread; + /** + * + * @param thread + * @param file + * @param line + * @param index + * @param desc + * @param modno + */ + public PHPStackFrame (PHPThread thread, String file, int line, int index, String desc, int modno) { + super (null); + + this.lineNumber = line; + this.index = index; + this.file = file; + this.thread = thread; this.description = desc; - this.modno = modno; - } - - public PHPStackFrame(PHPThread thread, String file, int line, int index) { + this.modno = modno; + } + + /** + * + * @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; - } - - public IThread getThread() { + this.index = index; + this.file = file; + this.thread = thread; + } + + /** + * + */ + public IThread getThread () { return thread; } - - public void setThread(PHPThread thread) { + + /** + * @param thread + */ + public void setThread (PHPThread thread) { this.thread = thread; } - + + /** + * + * This function returns the array of PHPVariables for this stackframe + * The PHPVariables should not change (newly build up) between two steps + * (or breaks). + * 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 (variables == null) { - variables = this.getPHPDBGProxy().readVariables(this); - } - return variables; - } - - public IVariable findVariable(String s) throws DebugException { - if (this.hasVariables()) { - String name="$"+s; - for(int i= 0; i < variables.length; i++) { - String n= variables[i].getName(); - if((variables[i].getName()).equals(name)) - return variables[i]; + //PHPVariable[] variablesNew; // The intermediate storage of the variable array we get from DBG proxy + + //variablesNew = this.getPHPDBGProxy ().readVariables (this); // Get the variable array from DBG proxy + //variables = variablesNew; // Store the array the stackframes member variable + varList = this.getPHPDBGProxy ().readVariables (this); + + variables = (PHPVariable[]) varList.toArray (new PHPVariable[varList.size ()]); + + return variables; // Give the array back to user interface + } + + /** + * + */ + 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 + + try { + if (value.hasVariables ()) { // Does the variable/value have children + variable = findVariable (value.getChildVariables (), varname); + + if (variable != null) { + return variable; + } + } + else if ((variable.getName ()).equals (varname)) { // + return variable; // + } } - } + catch (DebugException e) { // That's, because of the hasVariables method + } + } + return null; } - - public boolean hasVariables() throws DebugException { - if (variables == null) { - return false; + + /** + * This method is called from the UI (e.g. from PHPDebugHover + * to find the variable the mouse is pointing to) + * + * @param s The variable name we are looking for. + * @return + */ + public IVariable findVariable (String s) throws DebugException { + return (findVariable (varList, s)); // Prefix the variable name with $ + } + + /** + * + */ + public boolean hasVariables () throws DebugException { + if (variables == null) { // Do we have a variables array? + return false; // No } - return variables.length > 0; + + return variables.length > 0; // Is there something within the array? } - + public int getLineNumber() { return lineNumber; } - + + public void setLineNumber(int line) { + lineNumber = line; + } + public int getCharStart() throws DebugException { // not supported return -1; } - + public int getCharEnd() throws DebugException { // not supported return -1; } - + public String getName() { if(!this.getDescription().equals("")) return this.getDescription() + " [line: " + this.getLineNumber() + "]"; @@ -107,7 +196,7 @@ public class PHPStackFrame implements IStackFrame { public String getFileName() { return file; } - + public void setDescription(String desc) { this.description= desc; } @@ -115,118 +204,158 @@ public class PHPStackFrame implements IStackFrame { public String getDescription() { return this.description; } - + public IRegisterGroup[] getRegisterGroups() throws DebugException { return null; } - + public boolean hasRegisterGroups() throws DebugException { return false; } - + public String getModelIdentifier() { return this.getThread().getModelIdentifier(); } - + public IDebugTarget getDebugTarget() { return this.getThread().getDebugTarget(); } - + public ILaunch getLaunch() { return this.getDebugTarget().getLaunch(); } - + public boolean canStepInto() { return canResume(); } - + public boolean canStepOver() { return canResume(); } - + public boolean canStepReturn() { return canResume(); } - + public boolean isStepping() { return false; } - - public void stepInto() throws DebugException { - thread.prepareForResume() ; - this.getPHPDBGProxy().readStepIntoEnd(PHPStackFrame.this) ; - DebugEvent ev = new DebugEvent(this.getThread(), DebugEvent.RESUME, DebugEvent.STEP_INTO); - DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { ev }); + + /** + * + */ + public void stepInto () throws DebugException { + DebugEvent ev; + + thread.prepareForResume (DebugEvent.STEP_INTO); // Don't know why, but this is necessary + this.getPHPDBGProxy ().readStepIntoEnd (PHPStackFrame.this); + + ev = new DebugEvent (this.getThread (), DebugEvent.RESUME, DebugEvent.STEP_INTO); + DebugPlugin.getDefault().fireDebugEventSet (new DebugEvent[] { ev }); } - - public void stepOver() throws DebugException { - thread.prepareForResume() ; - this.getPHPDBGProxy().readStepOverEnd(PHPStackFrame.this) ; - DebugEvent ev = new DebugEvent(this.getThread(), DebugEvent.RESUME, DebugEvent.STEP_OVER); - DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { ev }); + + /** + * + */ + public void stepOver () throws DebugException { + DebugEvent ev; + + thread.prepareForResume (DebugEvent.STEP_OVER); + this.getPHPDBGProxy ().readStepOverEnd (PHPStackFrame.this) ; + + ev = new DebugEvent (this.getThread (), DebugEvent.RESUME, DebugEvent.STEP_OVER); + DebugPlugin.getDefault ().fireDebugEventSet (new DebugEvent[] { ev }); } - public void stepReturn() throws DebugException { - thread.prepareForResume() ; - this.getPHPDBGProxy().readStepReturnEnd(PHPStackFrame.this) ; - DebugEvent ev = new DebugEvent(this.getThread(), DebugEvent.RESUME, DebugEvent.STEP_RETURN); - DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { ev }); + /** + * + */ + public void stepReturn () throws DebugException { + DebugEvent ev; + + 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(); } - + public boolean canSuspend() { return this.getThread().canSuspend(); } - + public boolean isSuspended() { return this.getThread().isSuspended(); - } - + } + public void resume() throws DebugException { this.getThread().resume(); } - + public void suspend() throws DebugException { } - + public boolean canTerminate() { return this.getThread().canTerminate(); } - + public boolean isTerminated() { return this.getThread().isTerminated(); - } - + } + public void terminate() throws DebugException { getPHPDBGProxy().stop(); - } - - public Object getAdapter(Class arg0) { - if (arg0==PHPStackFrame.class) - return this; - else - return null; } public int getIndex() { return index; } + public void setIndex (int index) { + this.index = index; + } + public PHPDBGProxy getPHPDBGProxy() { PHPDebugTarget DebugTarget; - DebugTarget= (PHPDebugTarget)thread.getDebugTarget(); - return DebugTarget.getPHPDBGProxy(); + + DebugTarget = (PHPDebugTarget) thread.getDebugTarget (); + + return DebugTarget.getPHPDBGProxy (); } public void setFile(String file) { this.file = file; } - + public int getModNo() { return modno; } + + /** + * This function is needed when sorting the stackframes by their index numbers. + * + * @param obj The stackframe which this one is compared to. + * @return + * + */ + public int compareTo (Object obj) + { + if (index < ((PHPStackFrame) obj).getIndex ()) { + return -1; + } + else if (index > ((PHPStackFrame) obj).getIndex ()) { + return 1; + } + + return 0; + } }