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 org.eclipse.debug.core.DebugEvent;
10 import org.eclipse.debug.core.DebugException;
11 import org.eclipse.debug.core.DebugPlugin;
12 import org.eclipse.debug.core.IDebugEventSetListener;
13 import org.eclipse.debug.core.model.IBreakpoint;
14 import org.eclipse.debug.core.model.IStackFrame;
15 import org.eclipse.debug.core.model.IThread;
20 * TODO To change the template for this generated type comment go to
21 * Window - Preferences - Java - Code Style - Code Templates
23 public class XDebugThread extends XDebugElement implements IThread, IDebugEventSetListener {
24 private IStackFrame[] fStackFrames;
26 private IBreakpoint[] fBreakpoints;
28 /* Whether this thread is stepping */
29 private boolean fStepping = false;
30 private boolean fTerminated = false;
32 private int fStepCount = 0;
33 private int fCurrentStepCount = 0;
36 * Constructs a new thread for the given target
40 public XDebugThread(XDebugTarget target) {
42 DebugPlugin.getDefault().addDebugEventListener(this);
46 public void incrementStepCounter() {
50 public IStackFrame[] getStackFrames() throws DebugException {
51 IStackFrame[] newStackFrames = null;
54 if (fStepCount > fCurrentStepCount) {
55 newStackFrames = ((XDebugTarget) getDebugTarget()).getStackFrames();
57 for (int i = 0; i < newStackFrames.length; i++) {
58 ((XDebugStackFrame)newStackFrames[i]).getVariables();
61 if (fStackFrames != null) {
62 if (newStackFrames.length >= fStackFrames.length) {
63 int delta = newStackFrames.length - fStackFrames.length + 1;
65 for (int i = fStackFrames.length - 1; i >= 0; i--) {
66 if (((XDebugStackFrame) fStackFrames[i]).equals(((XDebugStackFrame) newStackFrames[newStackFrames.length - delta]))) {
68 //((XDebugStackFrame) newStackFrames[newStackFrames.length - delta]).evaluateChange((XDebugStackFrame) fStackFrames[i]);
69 } else if (((XDebugStackFrame) fStackFrames[i]).isSameStackFrame(newStackFrames[newStackFrames.length - delta])) {
70 //((XDebugStackFrame) newStackFrames[newStackFrames.length - delta]).evaluateChange((XDebugStackFrame) fStackFrames[i]);
81 fStackFrames = newStackFrames;
85 return new IStackFrame[0];
90 * @see org.eclipse.debug.core.model.IThread#hasStackFrames()
92 public boolean hasStackFrames() throws DebugException {
97 * @see org.eclipse.debug.core.model.IThread#getPriority()
99 public int getPriority() throws DebugException {
104 * @see org.eclipse.debug.core.model.IThread#getTopStackFrame()
106 public IStackFrame getTopStackFrame() throws DebugException {
107 IStackFrame[] frames = getStackFrames();
108 if (frames.length > 0) {
116 * @see org.eclipse.debug.core.model.IThread#getName()
118 public String getName() throws DebugException {
123 * @see org.eclipse.debug.core.model.IThread#getBreakpoints()
125 public IBreakpoint[] getBreakpoints() {
126 if (fBreakpoints == null) {
127 return new IBreakpoint[0];
133 * Sets the breakpoints this thread is suspended at, or <code>null</code>
136 * @param breakpoints the breakpoints this thread is suspended at, or <code>null</code>
139 protected void setBreakpoints(IBreakpoint[] breakpoints) {
140 fBreakpoints = breakpoints;
144 * @see org.eclipse.debug.core.model.ISuspendResume#canResume()
146 public boolean canResume() {
147 return isSuspended();
151 * @see org.eclipse.debug.core.model.ISuspendResume#canSuspend()
153 public boolean canSuspend() {
154 return !isTerminated() && !isSuspended();
158 * @see org.eclipse.debug.core.model.ISuspendResume#isSuspended()
160 public boolean isSuspended() {
161 return fTarget.isSuspended();
165 * @see org.eclipse.debug.core.model.ISuspendResume#resume()
167 public void resume() throws DebugException {
173 * @see org.eclipse.debug.core.model.ISuspendResume#suspend()
175 public void suspend() throws DebugException {
180 * @see org.eclipse.debug.core.model.IStep#canStepInto()
182 public boolean canStepInto() {
183 return isSuspended();
187 * @see org.eclipse.debug.core.model.IStep#canStepOver()
189 public boolean canStepOver() {
190 return isSuspended();
194 * @see org.eclipse.debug.core.model.IStep#canStepReturn()
196 public boolean canStepReturn() {
197 if (fStackFrames != null) {
198 return (fStackFrames.length > 1);
205 * @see org.eclipse.debug.core.model.IStep#isStepping()
207 public boolean isStepping() {
212 * @see org.eclipse.debug.core.model.IStep#stepInto()
214 public void stepInto() throws DebugException {
220 * @see org.eclipse.debug.core.model.IStep#stepOver()
222 public void stepOver() throws DebugException {
228 * @see org.eclipse.debug.core.model.IStep#stepReturn()
230 public void stepReturn() throws DebugException {
236 * @see org.eclipse.debug.core.model.ITerminate#canTerminate()
238 public boolean canTerminate() {
239 return !isTerminated();
243 * @see org.eclipse.debug.core.model.ITerminate#isTerminated()
245 public boolean isTerminated() {
250 * @see org.eclipse.debug.core.model.ITerminate#terminate()
252 public void terminate() throws DebugException {
253 fTarget.getDebugConnection().stop();
257 public void terminated() throws DebugException {
262 * Sets whether this thread is stepping
264 * @param stepping whether stepping
266 protected void setStepping(boolean stepping) {
267 fStepping = stepping;
270 public void handleDebugEvents(DebugEvent[] events) {
271 DebugEvent de = events[0];
272 System.out.println(de.toString());
275 public void removeEventListeners() {
276 DebugPlugin.getDefault().removeDebugEventListener(this);