1 /**********************************************************************
2 Copyright (c) 2000, 2002 IBM Corp. and others.
3 All rights reserved. This program and the accompanying materials
4 are made available under the terms of the Common Public License v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v10.html
9 IBM Corporation - Initial implementation
10 Vicente Fernando - www.alfersoft.com.ar
11 **********************************************************************/
12 package net.sourceforge.phpdt.internal.debug.core.model;
14 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
16 import org.eclipse.debug.core.DebugEvent;
17 import org.eclipse.debug.core.DebugException;
18 import org.eclipse.debug.core.DebugPlugin;
19 import org.eclipse.debug.core.ILaunch;
20 import org.eclipse.debug.core.model.IBreakpoint;
21 import org.eclipse.debug.core.model.IDebugTarget;
22 import org.eclipse.debug.core.model.IStackFrame;
23 import org.eclipse.debug.core.model.IThread;
24 import org.eclipse.jface.resource.ImageDescriptor;
25 import org.eclipse.ui.model.IWorkbenchAdapter;
27 public class PHPThread extends PHPDebugElement implements IThread {
29 private PHPStackFrame[] frames;
31 private PHPDebugTarget target;
38 private boolean isSuspended = false;
40 private boolean isTerminated = false;
42 private boolean isStepping = false;
44 boolean isSuspended() {
48 boolean isTerminated() {
52 boolean isStepping() {
56 void setSuspended(boolean suspended) {
58 throw new IllegalStateException();
59 if (suspended && isStepping())
60 throw new IllegalStateException();
61 isSuspended = suspended;
64 void setStepping(boolean stepping) {
65 if (stepping && !isSuspended())
66 throw new IllegalStateException();
68 throw new IllegalStateException();
69 isStepping = stepping;
72 void setTerminated(boolean terminated) {
73 isTerminated = terminated;
77 private final State state = new State();
79 public PHPThread (PHPDebugTarget target, int id) {
85 public IStackFrame[] getStackFrames() throws DebugException {
89 public int getStackFramesSize() {
93 public boolean hasStackFrames() {
97 return frames.length > 0;
100 public int getPriority() throws DebugException {
104 public IStackFrame getTopStackFrame() throws DebugException {
105 if (frames == null || frames.length == 0) {
108 return (IStackFrame) frames[0];
111 public IBreakpoint[] getBreakpoints() {
115 public String getModelIdentifier() {
116 return this.getDebugTarget().getModelIdentifier();
119 public IDebugTarget getDebugTarget() {
123 public void setDebugTarget(PHPDebugTarget target) {
124 this.target = target;
127 public ILaunch getLaunch() {
128 return this.getDebugTarget().getLaunch();
131 public synchronized boolean canResume() {
132 return isSuspended();
135 public synchronized boolean canSuspend() {
136 return !isSuspended();
139 public synchronized boolean isSuspended() {
140 return state.isSuspended;
143 protected void prepareForResume() {
144 state.setSuspended(false);
146 DebugEvent ev = new DebugEvent(this, DebugEvent.RESUME,
147 DebugEvent.CLIENT_REQUEST);
148 DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { ev });
151 public synchronized void resume() throws DebugException {
154 this.prepareForResume();
155 ((PHPDebugTarget) this.getDebugTarget()).getPHPDBGProxy().resume();
159 * public void doSuspend(SuspensionPoint suspensionPoint) { //
160 * this.getPHPDebuggerProxy().readFrames(this);
161 * this.createName(suspensionPoint) ; this.suspend() ; }
164 public synchronized void suspend() throws DebugException {
167 state.setSuspended(true);
168 state.setStepping(false);
169 getDebugTarget().suspend();
170 DebugEvent ev = new DebugEvent(this, DebugEvent.SUSPEND,
171 DebugEvent.BREAKPOINT);
172 DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { ev });
175 public boolean canStepInto() {
176 return isSuspended() && isStepping() && this.hasStackFrames();
179 public boolean canStepOver() {
180 return isSuspended() && isStepping() && this.hasStackFrames();
183 public boolean canStepReturn() {
184 return isSuspended() && isStepping() && this.hasStackFrames();
187 public boolean isStepping() {
188 return state.isStepping();
191 public void stepInto() throws DebugException {
192 try { state.setStepping(true); }
193 catch (IllegalStateException x) {
194 throw new DebugException(PHPeclipsePlugin.error(x));
197 frames[0].stepInto();
200 public void stepOver() throws DebugException {
201 state.setStepping(true);
203 frames[0].stepOver();
206 public void stepReturn() throws DebugException {
209 public boolean canTerminate() {
210 return !isTerminated();
213 public boolean isTerminated() {
214 return state.isTerminated();
217 public synchronized void terminate() throws DebugException {
220 state.setTerminated(true);
222 getDebugTarget().terminate();
225 public Object getAdapter(Class arg0) {
226 if (IWorkbenchAdapter.class.equals(arg0)) {
227 return new IWorkbenchAdapter() {
228 public Object[] getChildren(Object o) {
229 Object[] children = null;
231 IStackFrame[] frames = getStackFrames();
232 if (null != frames) {
233 children = new Object[frames.length];
234 for (int i = 0; i < frames.length; ++i)
235 children[i] = frames[i];
237 } catch (DebugException x) {
238 PHPeclipsePlugin.log("Unable to get stack frames.", x);
243 public ImageDescriptor getImageDescriptor(Object object) {
247 public String getLabel(Object o) {
248 throw new UnsupportedOperationException();
251 public Object getParent(Object o) {
252 return getDebugTarget();
259 public void setStackFrames(PHPStackFrame[] frames) {
260 this.frames = frames;
263 public String getName() {
264 String name = this.name;
266 name = name + " (suspended)";
270 public void setName(String name) {
275 * protected void createName(SuspensionPoint suspensionPoint) { this.name =
276 * "PHP Thread - " + this.getId() ; if (suspensionPoint != null) { this.name += " (" +
277 * suspensionPoint + ")" ; } }
284 public void setId(int id) {