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 net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils;
13 import net.sourceforge.phpeclipse.xdebug.core.xdebug.ResponseListener.XDebugResponse;
15 import org.eclipse.debug.core.DebugEvent;
16 import org.eclipse.debug.core.DebugException;
17 import org.eclipse.debug.core.DebugPlugin;
18 import org.eclipse.debug.core.IDebugEventSetListener;
19 import org.eclipse.debug.core.model.IBreakpoint;
20 import org.eclipse.debug.core.model.IStackFrame;
21 import org.eclipse.debug.core.model.IThread;
22 import org.w3c.dom.Node;
23 import org.w3c.dom.NodeList;
28 * TODO To change the template for this generated type comment go to
29 * Window - Preferences - Java - Code Style - Code Templates
31 public class XDebugThread extends XDebugElement implements IThread, IDebugEventSetListener {
32 private XDebugStackFrame[] fStackFrames;
34 private IBreakpoint[] fBreakpoints;
36 /* Whether this thread is stepping */
37 private boolean fStepping = false;
38 private boolean fTerminated = false;
40 private int fStepCount = 0;
41 private int fCurrentStepCount = 0;
44 * Constructs a new thread for the given target
48 public XDebugThread(XDebugTarget target) {
50 DebugPlugin.getDefault().addDebugEventListener(this);
54 public void incrementStepCounter() {
57 public IStackFrame[] getStackFrames() throws DebugException {
59 return new IStackFrame[0];
62 if (fStepCount > fCurrentStepCount) {
63 XDebugResponse dr = ((XDebugTarget) getDebugTarget()).getStackFrames();
64 XDebugStackFrame[] newStackFrames = _getStackFrames(dr);
66 /*if (fStackFrames != null) {
67 if (newStackFrames.length >= fStackFrames.length) {
68 int delta = newStackFrames.length - fStackFrames.length + 1;
70 for (int i = fStackFrames.length - 1; i >= 0; i--) {
71 if (fStackFrames[i].equals(newStackFrames[newStackFrames.length - delta])) {
73 //((XDebugStackFrame) newStackFrames[newStackFrames.length - delta]).evaluateChange((XDebugStackFrame) fStackFrames[i]);
74 } else if (fStackFrames[i].isSameStackFrame(newStackFrames[newStackFrames.length - delta])) {
76 //((XDebugStackFrame) newStackFrames[newStackFrames.length - delta]).evaluateChange((XDebugStackFrame) fStackFrames[i]);
82 fStackFrames = newStackFrames;
85 fStackFrames = newStackFrames;
90 fStackFrames = newStackFrames;
97 private XDebugStackFrame[] _getStackFrames(XDebugResponse lastResponse) {
98 if (lastResponse.isError()) {
99 return new XDebugStackFrame[0];
102 Node response = lastResponse.getParentNode();
103 NodeList frames = response.getChildNodes();
104 XDebugStackFrame[] theFrames = new XDebugStackFrame[frames.getLength()];
105 for (int i = 0; i < frames.getLength(); i++) {
106 Node stackNode = frames.item(i);
107 XDebugStackFrame frame = new XDebugStackFrame(this/*fThread*/, i);
108 String level =PHPDebugUtils.getAttributeValue(stackNode,"level");
109 if (!"".equals(level))
110 frame.setLevel(Integer.parseInt(level));
112 frame.setType(PHPDebugUtils.getAttributeValue(stackNode,"type"));
113 String fileName=PHPDebugUtils.unescapeString(PHPDebugUtils.getAttributeValue(stackNode,"filename"));
114 String lineNo=PHPDebugUtils.getAttributeValue(stackNode,"lineno");
116 if (!"".equals(lineNo))
117 frame.setLineNumber(Integer.parseInt(lineNo));
119 frame.setWhere(PHPDebugUtils.getAttributeValue(stackNode,"where"));
122 frame.setFullName(new URL(fileName));
123 } catch (MalformedURLException e) {
127 frame.incrementStepCounter();
129 theFrames[i] = frame;
136 * @see org.eclipse.debug.core.model.IThread#hasStackFrames()
138 public boolean hasStackFrames() throws DebugException {
139 return isSuspended();
143 * @see org.eclipse.debug.core.model.IThread#getPriority()
145 public int getPriority() throws DebugException {
150 * @see org.eclipse.debug.core.model.IThread#getTopStackFrame()
152 public IStackFrame getTopStackFrame() throws DebugException {
153 IStackFrame[] frames = getStackFrames();
154 if (frames.length > 0) {
162 * @see org.eclipse.debug.core.model.IThread#getName()
164 public String getName() throws DebugException {
169 * @see org.eclipse.debug.core.model.IThread#getBreakpoints()
171 public IBreakpoint[] getBreakpoints() {
172 if (fBreakpoints == null) {
173 return new IBreakpoint[0];
179 * Sets the breakpoints this thread is suspended at, or <code>null</code>
182 * @param breakpoints the breakpoints this thread is suspended at, or <code>null</code>
185 protected void setBreakpoints(IBreakpoint[] breakpoints) {
186 fBreakpoints = breakpoints;
190 * @see org.eclipse.debug.core.model.ISuspendResume#canResume()
192 public boolean canResume() {
193 return isSuspended();
197 * @see org.eclipse.debug.core.model.ISuspendResume#canSuspend()
199 public boolean canSuspend() {
200 return !isTerminated() && !isSuspended();
204 * @see org.eclipse.debug.core.model.ISuspendResume#isSuspended()
206 public boolean isSuspended() {
207 return fTarget.isSuspended();
211 * @see org.eclipse.debug.core.model.ISuspendResume#resume()
213 public void resume() throws DebugException {
219 * @see org.eclipse.debug.core.model.ISuspendResume#suspend()
221 public void suspend() throws DebugException {
226 * @see org.eclipse.debug.core.model.IStep#canStepInto()
228 public boolean canStepInto() {
229 return isSuspended();
233 * @see org.eclipse.debug.core.model.IStep#canStepOver()
235 public boolean canStepOver() {
236 return isSuspended();
240 * @see org.eclipse.debug.core.model.IStep#canStepReturn()
242 public boolean canStepReturn() {
243 if (fStackFrames != null) {
244 return (fStackFrames.length > 1);
251 * @see org.eclipse.debug.core.model.IStep#isStepping()
253 public boolean isStepping() {
258 * @see org.eclipse.debug.core.model.IStep#stepInto()
260 public void stepInto() throws DebugException {
266 * @see org.eclipse.debug.core.model.IStep#stepOver()
268 public void stepOver() throws DebugException {
274 * @see org.eclipse.debug.core.model.IStep#stepReturn()
276 public void stepReturn() throws DebugException {
282 * @see org.eclipse.debug.core.model.ITerminate#canTerminate()
284 public boolean canTerminate() {
285 return !isTerminated();
289 * @see org.eclipse.debug.core.model.ITerminate#isTerminated()
291 public boolean isTerminated() {
296 * @see org.eclipse.debug.core.model.ITerminate#terminate()
298 public void terminate() throws DebugException {
299 fTarget.getDebugConnection().stop();
303 public void terminated() throws DebugException {
308 * Sets whether this thread is stepping
310 * @param stepping whether stepping
312 protected void setStepping(boolean stepping) {
313 fStepping = stepping;
316 public void handleDebugEvents(DebugEvent[] events) {
317 DebugEvent de = events[0];
318 System.out.println(de.toString());
321 public void removeEventListeners() {
322 DebugPlugin.getDefault().removeDebugEventListener(this);