2 * Created on 23.11.2004
4 * TODO To change the template for this generated file go to
5 * Window - Preferences - Java - Code Style - Code Templates
7 package net.sourceforge.phpeclipse.xdebug.php.model;
9 import java.net.MalformedURLException;
12 import org.eclipse.core.runtime.IPath;
13 import org.eclipse.core.runtime.Path;
14 import org.eclipse.debug.core.DebugException;
15 import org.eclipse.debug.core.model.IRegisterGroup;
16 import org.eclipse.debug.core.model.IStackFrame;
17 import org.eclipse.debug.core.model.IThread;
18 import org.eclipse.debug.core.model.IVariable;
19 import org.w3c.dom.Node;
20 import org.w3c.dom.NodeList;
23 * @author PHPeclipse team
27 public class XDebugStackFrame extends XDebugElement implements IStackFrame {
28 private XDebugThread fThread;
30 private int fLineNumber;
33 private String fWhere;
34 private IVariable[] fVariables;
35 private int fStepCount = 0;
38 * Constructs a stack frame in the given thread with the given
42 * @param data frame data
43 * @param id stack frame id (0 is the bottom of the stack)
45 public XDebugStackFrame(XDebugThread thread, int id, String type, int lineNumber, String where, /*URL*/String filename) {
46 super(/*thread == null ? null : */(XDebugTarget) thread.getDebugTarget());
51 fLineNumber = lineNumber;
55 fName = new URL(filename);
56 } catch (MalformedURLException e) {
61 public void incrementStepCounter() {
66 * @see org.eclipse.debug.core.model.IStackFrame#getThread()
68 public IThread getThread() {
72 public IVariable[] getVariables() throws DebugException {
73 /* always read variables, poor performance
74 * but this fix bug #680.
75 * need to investigate on.
78 //if (fVariables == null) {
79 Node dfl = ((XDebugTarget) getDebugTarget()).getLocalVariables(fLevel);
80 Node dfg = ((XDebugTarget) getDebugTarget()).getGlobalVariables(fLevel);
81 parseVariable(dfl, dfg);
87 private void parseVariable(Node localVariables, Node globalVariables) throws DebugException {
88 NodeList property = localVariables.getChildNodes();
90 NodeList propertyGlobal = globalVariables.getChildNodes();
92 fVariables = new IVariable[property.getLength() + propertyGlobal.getLength()];
94 int length = property.getLength();
95 for (int i = 0; i < length; i++) {
96 XDebugVariable var = new XDebugVariable(this, property.item(i));
100 int globalLength = propertyGlobal.getLength();
101 for (int k = 0; k < globalLength; k++) {
102 XDebugVariable var = new XDebugVariable(this, propertyGlobal.item(k));
103 fVariables[k + length] = var;
107 /*public void evaluateChange(IStackFrame OldStackFrame) throws DebugException {
108 IVariable[] OldVariable = ((XDebugStackFrame) OldStackFrame).getVariables();
109 for (int i = 0; i < fVariables.length; i++) {
110 ((XDebugVariable) fVariables[i]).setChange(OldVariable[i]);
115 * @see org.eclipse.debug.core.model.IStackFrame#hasVariables()
117 public boolean hasVariables() throws DebugException {
118 /*return fVariables.length > 0;*/
123 * @see org.eclipse.debug.core.model.IStackFrame#getLineNumber()
125 public int getLineNumber() throws DebugException {
130 * @see org.eclipse.debug.core.model.IStackFrame#getCharStart()
132 public int getCharStart() throws DebugException {
137 * @see org.eclipse.debug.core.model.IStackFrame#getCharEnd()
139 public int getCharEnd() throws DebugException {
143 /* (non-Javadoc)fName
144 * @see org.eclipse.debug.core.model.IStackFrame#getName()
146 public String getName() throws DebugException {
147 return fName.toString()+"::"+fWhere+ " line: "+ fLineNumber;
151 * @see org.eclipse.debug.core.model.IStackFrame#getRegisterGroups()
153 public IRegisterGroup[] getRegisterGroups() throws DebugException {
158 * @see org.eclipse.debug.core.model.IStackFrame#hasRegisterGroups()
160 public boolean hasRegisterGroups() throws DebugException {
165 * @see org.eclipse.debug.core.model.IStep#canStepInto()
167 public boolean canStepInto() {
168 return fThread.canStepInto();
172 * @see org.eclipse.debug.core.model.IStep#canStepOver()
174 public boolean canStepOver() {
175 return fThread.canStepOver();
179 * @see org.eclipse.debug.core.model.IStep#canStepReturn()
181 public boolean canStepReturn() {
182 return fThread.canStepReturn();
186 * @see org.eclipse.debug.core.model.IStep#isStepping()
188 public boolean isStepping() {
189 return fThread.isStepping();
193 * @see org.eclipse.debug.core.model.IStep#stepInto()
195 public void stepInto() throws DebugException {
200 * @see org.eclipse.debug.core.model.IStep#stepOver()
202 public void stepOver() throws DebugException {
207 * @see org.eclipse.debug.core.model.IStep#stepReturn()
209 public void stepReturn() throws DebugException {
210 fThread.stepReturn();
214 * @see org.eclipse.debug.core.model.ISuspendResume#canResume()
216 public boolean canResume() {
217 return fThread.canResume();
221 * @see org.eclipse.debug.core.model.ISuspendResume#canSuspend()
223 public boolean canSuspend() {
224 return fThread.canSuspend();
228 * @see org.eclipse.debug.core.model.ISuspendResume#isSuspended()
230 public boolean isSuspended() {
231 return fThread.isSuspended();
235 * @see org.eclipse.debug.core.model.ISuspendResume#resume()
237 public void resume() throws DebugException {
242 * @see org.eclipse.debug.core.model.ISuspendResume#suspend()
244 public void suspend() throws DebugException {
249 * @see org.eclipse.debug.core.model.ITerminate#canTerminate()
251 public boolean canTerminate() {
252 return fThread.canTerminate();
256 * @see org.eclipse.debug.core.model.ITerminate#isTerminated()
258 public boolean isTerminated() {
259 return fThread.isTerminated();
263 * @see org.eclipse.debug.core.model.ITerminate#terminate()
265 public void terminate() throws DebugException {
270 * Returns the name of the source file this stack frame is associated
273 * @return the name of the source file this stack frame is associated
274 * with. If the file associated with this frame does not exists, it returns null.
276 public String getSourceName() {
280 IPath a = new Path(fName.getFile());
281 return a.lastSegment();
284 public boolean isSameStackFrame(Object obj) {
285 boolean isSameStackFrame = false;
287 if (obj instanceof XDebugStackFrame) {
288 XDebugStackFrame sf = (XDebugStackFrame)obj;
289 isSameStackFrame = sf.getSourceName().equals(getSourceName()) &&
290 sf.getType().equals(getType()) &&
291 sf.getWhere().equals(getWhere()); //&&
294 return isSameStackFrame;
298 * @see java.lang.Object#equals(java.lang.Object)
300 public boolean equals(Object obj) {
301 if (obj instanceof XDebugStackFrame) {
302 XDebugStackFrame sf = (XDebugStackFrame)obj;
304 return sf.getSourceName().equals(new Path(fName.getFile()).lastSegment()) &&
305 sf.getLineNumber() == fLineNumber &&
306 sf.getLevel() == fLevel &&
307 sf.getType().equals(fType) &&
308 sf.getWhere().equals(fWhere);
309 } catch (DebugException e) {
317 * @see java.lang.Object#hashCode()
319 public int hashCode() {
320 return getSourceName().hashCode() + fLevel;
323 public URL getFullName() {
327 public int getLevel() {
331 public String getType() {
335 public String getWhere() {
339 public boolean setVariableValue(XDebugVariable variable, String expression) throws DebugException {
340 return ((XDebugTarget) getDebugTarget()).setVarValue("$" + variable.getName(), expression);
343 public Node eval(String expression) throws DebugException {
344 return ((XDebugTarget) getDebugTarget()).eval(expression);