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 implements IThread {
29 private PHPStackFrame[] frames;
30 private IDebugTarget target;
31 private boolean isSuspended = false;
32 private boolean isTerminated = false;
33 private boolean isStepping = false;
37 public PHPThread(IDebugTarget target, int id) {
43 public IStackFrame[] getStackFrames() throws DebugException {
47 public int getStackFramesSize() {
51 public boolean hasStackFrames() {
55 return frames.length > 0;
58 public int getPriority() throws DebugException {
62 public IStackFrame getTopStackFrame() throws DebugException {
63 if (frames == null || frames.length == 0) {
66 return (IStackFrame) frames[0];
70 public IBreakpoint[] getBreakpoints() {
74 public String getModelIdentifier() {
75 return this.getDebugTarget().getModelIdentifier();
78 public IDebugTarget getDebugTarget() {
82 public void setDebugTarget(IDebugTarget target) {
86 public ILaunch getLaunch() {
87 return this.getDebugTarget().getLaunch();
90 public boolean canResume() {
94 public boolean canSuspend() {
98 public boolean isSuspended() {
102 protected void setSuspended(boolean isSuspended) {
103 this.isSuspended = isSuspended;
106 protected void prepareForResume() {
110 DebugEvent ev = new DebugEvent(this, DebugEvent.RESUME, DebugEvent.CLIENT_REQUEST);
111 DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { ev });
114 public void resume() throws DebugException {
115 this.prepareForResume() ;
116 ((PHPDebugTarget) this.getDebugTarget()).getPHPDBGProxy().resume();
120 public void doSuspend(SuspensionPoint suspensionPoint) {
121 // this.getPHPDebuggerProxy().readFrames(this);
122 this.createName(suspensionPoint) ;
127 public void suspend() {
130 DebugEvent ev = new DebugEvent(this, DebugEvent.SUSPEND, DebugEvent.BREAKPOINT);
131 DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { ev });
134 public boolean canStepInto() {
135 return isSuspended && this.hasStackFrames();
138 public boolean canStepOver() {
139 return isSuspended && this.hasStackFrames();
142 public boolean canStepReturn() {
146 public boolean isStepping() {
150 public void stepInto() throws DebugException {
154 frames[0].stepInto();
157 public void stepOver() throws DebugException {
161 frames[0].stepOver() ;
164 public void stepReturn() throws DebugException {
167 public boolean canTerminate() {
168 return !isTerminated;
171 public boolean isTerminated() {
175 public void terminate() throws DebugException {
178 getDebugTarget().terminate();
181 public Object getAdapter(Class arg0) {
182 if (IWorkbenchAdapter.class.equals(arg0)) {
183 return new IWorkbenchAdapter() {
184 public Object[] getChildren(Object o) {
185 Object[] children = null;
187 IStackFrame[] frames = getStackFrames();
188 if (null != frames) {
189 children = new Object[frames.length];
190 for (int i = 0; i < frames.length; ++i)
191 children[i] = frames[i];
193 } catch (DebugException x) {
194 PHPeclipsePlugin.log("Unable to get stack frames.", x);
198 public ImageDescriptor getImageDescriptor(Object object) {
201 public String getLabel(Object o) {
202 throw new UnsupportedOperationException();
204 public Object getParent(Object o) {
205 return getDebugTarget();
212 public void setStackFrames(PHPStackFrame[] frames) {
213 this.frames = frames;
216 public String getName() {
220 public void setName(String name) {
224 protected void createName() {
225 //this.createName(null) ;
229 protected void createName(SuspensionPoint suspensionPoint) {
230 this.name = "PHP Thread - " + this.getId() ;
231 if (suspensionPoint != null) {
232 this.name += " (" + suspensionPoint + ")" ;
241 public void setId(int id) {