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;
10 import java.net.URISyntaxException;
12 import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils;
13 import net.sourceforge.phpeclipse.xdebug.core.DebugConnection.DebugResponse;
15 import org.eclipse.core.runtime.Path;
16 import org.eclipse.debug.core.DebugException;
17 import org.eclipse.debug.core.model.IRegisterGroup;
18 import org.eclipse.debug.core.model.IStackFrame;
19 import org.eclipse.debug.core.model.IThread;
20 import org.eclipse.debug.core.model.IVariable;
21 import org.w3c.dom.Node;
22 import org.w3c.dom.NodeList;
27 * TODO To change the template for this generated type comment go to
28 * Window - Preferences - Java - Code Style - Code Templates
30 public class XDebugStackFrame extends XDebugElement implements IStackFrame {
32 private XDebugThread fThread;
33 // private String fName;
35 private String fFileName;
37 private IVariable[] fVariables;
38 private String fLevel;
40 private String fWhere;
43 * Constructs a stack frame in the given thread with the given
47 * @param data frame data
48 * @param id stack frame id (0 is the bottom of the stack)
50 public XDebugStackFrame(XDebugThread thread, Node stackNode, int id) {
51 super((XDebugTarget) thread.getDebugTarget());
58 * Initializes this frame based on its data
62 private void init(Node stackNode) {
64 fLevel=PHPDebugUtils.getAttributeValue(stackNode,"level");
65 fType=PHPDebugUtils.getAttributeValue(stackNode,"type");
66 String fileName=PHPDebugUtils.unescapeString(PHPDebugUtils.getAttributeValue(stackNode,"filename"));
67 String lineNo=PHPDebugUtils.getAttributeValue(stackNode,"lineno");
70 fLineNo= Integer.parseInt(lineNo);
72 fWhere=PHPDebugUtils.getAttributeValue(stackNode,"where");
74 fFileName = (new Path(fileName)).lastSegment();
77 id=((XDebugTarget)getDebugTarget()).sendRequest("context_get","-d "+fLevel);
78 } catch (DebugException e) {
79 // TODO Auto-generated catch block
82 DebugResponse response=((XDebugTarget)getDebugTarget()).getResponse(id);
83 Node responseNode = response.getParentNode();
84 NodeList property = responseNode.getChildNodes();
85 fVariables = new IVariable[property.getLength()];
86 for (int i = 0; i < property.getLength(); i++) {
87 Node propertyNode = property.item(i);
88 fVariables[i] = new XDebugVariable(this, propertyNode);
91 // int numVars = strings.length - 3;
92 // fVariables = new IVariable[numVars];
93 // for (int i = 0; i < numVars; i++) {
94 // fVariables[i] = new XDebugVariable(this, strings[i + 3]);
99 * @see org.eclipse.debug.core.model.IStackFrame#getThread()
101 public IThread getThread() {
105 * @see org.eclipse.debug.core.model.IStackFrame#getVariables()
107 public IVariable[] getVariables() throws DebugException {
111 * @see org.eclipse.debug.core.model.IStackFrame#hasVariables()
113 public boolean hasVariables() throws DebugException {
114 return fVariables.length > 0;
117 * @see org.eclipse.debug.core.model.IStackFrame#getLineNumber()
119 public int getLineNumber() throws DebugException {
123 * @see org.eclipse.debug.core.model.IStackFrame#getCharStart()
125 public int getCharStart() throws DebugException {
129 * @see org.eclipse.debug.core.model.IStackFrame#getCharEnd()
131 public int getCharEnd() throws DebugException {
135 * @see org.eclipse.debug.core.model.IStackFrame#getName()
137 public String getName() throws DebugException {
138 return fFileName+"::"+fWhere+ " : lineno "+ fLineNo;
141 * @see org.eclipse.debug.core.model.IStackFrame#getRegisterGroups()
143 public IRegisterGroup[] getRegisterGroups() throws DebugException {
147 * @see org.eclipse.debug.core.model.IStackFrame#hasRegisterGroups()
149 public boolean hasRegisterGroups() throws DebugException {
153 * @see org.eclipse.debug.core.model.IStep#canStepInto()
155 public boolean canStepInto() {
156 return getThread().canStepInto();
159 * @see org.eclipse.debug.core.model.IStep#canStepOver()
161 public boolean canStepOver() {
162 return getThread().canStepOver();
165 * @see org.eclipse.debug.core.model.IStep#canStepReturn()
167 public boolean canStepReturn() {
168 return getThread().canStepReturn();
171 * @see org.eclipse.debug.core.model.IStep#isStepping()
173 public boolean isStepping() {
174 return getThread().isStepping();
177 * @see org.eclipse.debug.core.model.IStep#stepInto()
179 public void stepInto() throws DebugException {
180 getThread().stepInto();
183 * @see org.eclipse.debug.core.model.IStep#stepOver()
185 public void stepOver() throws DebugException {
186 getThread().stepOver();
189 * @see org.eclipse.debug.core.model.IStep#stepReturn()
191 public void stepReturn() throws DebugException {
192 getThread().stepReturn();
195 * @see org.eclipse.debug.core.model.ISuspendResume#canResume()
197 public boolean canResume() {
198 return getThread().canResume();
201 * @see org.eclipse.debug.core.model.ISuspendResume#canSuspend()
203 public boolean canSuspend() {
204 return getThread().canSuspend();
207 * @see org.eclipse.debug.core.model.ISuspendResume#isSuspended()
209 public boolean isSuspended() {
210 return getThread().isSuspended();
213 * @see org.eclipse.debug.core.model.ISuspendResume#resume()
215 public void resume() throws DebugException {
216 getThread().resume();
219 * @see org.eclipse.debug.core.model.ISuspendResume#suspend()
221 public void suspend() throws DebugException {
222 getThread().suspend();
225 * @see org.eclipse.debug.core.model.ITerminate#canTerminate()
227 public boolean canTerminate() {
228 return getThread().canTerminate();
231 * @see org.eclipse.debug.core.model.ITerminate#isTerminated()
233 public boolean isTerminated() {
234 return getThread().isTerminated();
237 * @see org.eclipse.debug.core.model.ITerminate#terminate()
239 public void terminate() throws DebugException {
240 getThread().terminate();
244 * Returns the name of the source file this stack frame is associated
247 * @return the name of the source file this stack frame is associated
250 public String getSourceName() {
254 * @see java.lang.Object#equals(java.lang.Object)
256 public boolean equals(Object obj) {
257 if (obj instanceof XDebugStackFrame) {
258 XDebugStackFrame sf = (XDebugStackFrame)obj;
260 return sf.getSourceName().equals(getSourceName()) &&
261 sf.getLineNumber() == getLineNumber() &&
263 } catch (DebugException e) {
269 * @see java.lang.Object#hashCode()
271 public int hashCode() {
272 return getSourceName().hashCode() + fId;
276 * Returns this stack frame's unique identifier within its thread
278 * @return this stack frame's unique identifier within its thread
280 protected int getIdentifier() {