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 net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils;
10 import net.sourceforge.phpeclipse.xdebug.core.xdebug.XDebugResponse;
12 import org.eclipse.debug.core.DebugEvent;
13 import org.eclipse.debug.core.DebugException;
14 import org.eclipse.debug.core.DebugPlugin;
15 import org.eclipse.debug.core.IDebugEventSetListener;
16 import org.eclipse.debug.core.model.IBreakpoint;
17 import org.eclipse.debug.core.model.IStackFrame;
18 import org.eclipse.debug.core.model.IThread;
19 import org.w3c.dom.Node;
20 import org.w3c.dom.NodeList;
25 * TODO To change the template for this generated type comment go to
26 * Window - Preferences - Java - Code Style - Code Templates
28 public class XDebugThread extends XDebugElement implements IThread, IDebugEventSetListener {
29 private XDebugStackFrame[] fStackFrames;
31 private IBreakpoint[] fBreakpoints;
33 /* Whether this thread is stepping */
34 private boolean fStepping = false;
35 private boolean fTerminated = false;
37 private int fStepCount = 0;
38 private int fCurrentStepCount = 0;
41 * Constructs a new thread for the given target
45 public XDebugThread(XDebugTarget target) {
47 DebugPlugin.getDefault().addDebugEventListener(this);
51 public void incrementStepCounter() {
54 public IStackFrame[] getStackFrames() throws DebugException {
56 return new IStackFrame[0];
59 if (fStepCount > fCurrentStepCount) {
60 XDebugResponse dr = ((XDebugTarget) getDebugTarget()).getStackFrames();
61 XDebugStackFrame[] newStackFrames = _getStackFrames(dr);
63 /*if (fStackFrames != null) {
64 if (newStackFrames.length >= fStackFrames.length) {
65 int delta = newStackFrames.length - fStackFrames.length + 1;
67 for (int i = fStackFrames.length - 1; i >= 0; i--) {
68 if (fStackFrames[i].equals(newStackFrames[newStackFrames.length - delta])) {
70 //((XDebugStackFrame) newStackFrames[newStackFrames.length - delta]).evaluateChange((XDebugStackFrame) fStackFrames[i]);
71 } else if (fStackFrames[i].isSameStackFrame(newStackFrames[newStackFrames.length - delta])) {
73 //((XDebugStackFrame) newStackFrames[newStackFrames.length - delta]).evaluateChange((XDebugStackFrame) fStackFrames[i]);
79 fStackFrames = newStackFrames;
82 fStackFrames = newStackFrames;
87 fStackFrames = newStackFrames;
94 private XDebugStackFrame[] _getStackFrames(XDebugResponse lastResponse) {
95 if (lastResponse.isError()) {
96 return new XDebugStackFrame[0];
99 Node response = lastResponse.getParentNode();
100 NodeList frames = response.getChildNodes();
101 XDebugStackFrame[] theFrames = new XDebugStackFrame[frames.getLength()];
103 for (int i = 0; i < frames.getLength(); i++) {
104 Node stackNode = frames.item(i);
105 String fileName=PHPDebugUtils.unescapeString(PHPDebugUtils.getAttributeValue(stackNode,"filename"));
106 String lineNo = PHPDebugUtils.getAttributeValue(stackNode,"lineno");
108 XDebugStackFrame frame = new XDebugStackFrame(this/*fThread*/, i, /*type*/PHPDebugUtils.getAttributeValue(stackNode,"type"), /*lineno*/Integer.parseInt(lineNo), /*where*/PHPDebugUtils.getAttributeValue(stackNode,"where"), fileName);
110 frame.incrementStepCounter();
112 theFrames[i] = frame;
119 * @see org.eclipse.debug.core.model.IThread#hasStackFrames()
121 public boolean hasStackFrames() throws DebugException {
122 return isSuspended();
126 * @see org.eclipse.debug.core.model.IThread#getPriority()
128 public int getPriority() throws DebugException {
133 * @see org.eclipse.debug.core.model.IThread#getTopStackFrame()
135 public IStackFrame getTopStackFrame() throws DebugException {
136 IStackFrame[] frames = getStackFrames();
137 if (frames.length > 0) {
145 * @see org.eclipse.debug.core.model.IThread#getName()
147 public String getName() throws DebugException {
152 * @see org.eclipse.debug.core.model.IThread#getBreakpoints()
154 public IBreakpoint[] getBreakpoints() {
155 if (fBreakpoints == null) {
156 return new IBreakpoint[0];
162 * Sets the breakpoints this thread is suspended at, or <code>null</code>
165 * @param breakpoints the breakpoints this thread is suspended at, or <code>null</code>
168 protected void setBreakpoints(IBreakpoint[] breakpoints) {
169 fBreakpoints = breakpoints;
173 * @see org.eclipse.debug.core.model.ISuspendResume#canResume()
175 public boolean canResume() {
176 return isSuspended();
180 * @see org.eclipse.debug.core.model.ISuspendResume#canSuspend()
182 public boolean canSuspend() {
183 return !isTerminated() && !isSuspended();
187 * @see org.eclipse.debug.core.model.ISuspendResume#isSuspended()
189 public boolean isSuspended() {
190 return getDebugTarget().isSuspended();
194 * @see org.eclipse.debug.core.model.ISuspendResume#resume()
196 public void resume() throws DebugException {
198 getDebugTarget().resume();
202 * @see org.eclipse.debug.core.model.ISuspendResume#suspend()
204 public void suspend() throws DebugException {
205 getDebugTarget().suspend();
209 * @see org.eclipse.debug.core.model.IStep#canStepInto()
211 public boolean canStepInto() {
212 return isSuspended();
216 * @see org.eclipse.debug.core.model.IStep#canStepOver()
218 public boolean canStepOver() {
219 return isSuspended();
223 * @see org.eclipse.debug.core.model.IStep#canStepReturn()
225 public boolean canStepReturn() {
226 if (fStackFrames != null) {
227 return (fStackFrames.length > 1);
234 * @see org.eclipse.debug.core.model.IStep#isStepping()
236 public boolean isStepping() {
241 * @see org.eclipse.debug.core.model.IStep#stepInto()
243 public void stepInto() throws DebugException {
245 ((XDebugTarget) getDebugTarget()).step_into();
249 * @see org.eclipse.debug.core.model.IStep#stepOver()
251 public void stepOver() throws DebugException {
253 ((XDebugTarget) getDebugTarget()).step_over();
257 * @see org.eclipse.debug.core.model.IStep#stepReturn()
259 public void stepReturn() throws DebugException {
261 ((XDebugTarget) getDebugTarget()).step_out();
265 * @see org.eclipse.debug.core.model.ITerminate#canTerminate()
267 public boolean canTerminate() {
268 return !isTerminated();
272 * @see org.eclipse.debug.core.model.ITerminate#isTerminated()
274 public boolean isTerminated() {
279 * @see org.eclipse.debug.core.model.ITerminate#terminate()
281 public void terminate() throws DebugException {
282 ((XDebugTarget) getDebugTarget()).getDebugConnection().stop();
286 public void terminated() throws DebugException {
291 * Sets whether this thread is stepping
293 * @param stepping whether stepping
295 protected void setStepping(boolean stepping) {
296 fStepping = stepping;
299 public void handleDebugEvents(DebugEvent[] events) {
300 DebugEvent de = events[0];
301 System.out.println(de.toString());
304 public void removeEventListeners() {
305 DebugPlugin.getDefault().removeDebugEventListener(this);
309 * Fires a <code>RESUME</code> event for this element with
312 * @param detail event detail code
314 public void fireResumeEvent(int detail) {
315 fireEvent(new DebugEvent(this, DebugEvent.RESUME, detail));
319 * Fires a <code>SUSPEND</code> event for this element with
322 * @param detail event detail code
324 public void fireSuspendEvent(int detail) {
325 fireEvent(new DebugEvent(this, DebugEvent.SUSPEND, detail));