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 java.util.Vector;
16 import net.sourceforge.phpdt.internal.debug.core.PHPDBGProxy;
18 import org.eclipse.debug.core.DebugEvent;
19 import org.eclipse.debug.core.DebugException;
20 import org.eclipse.debug.core.DebugPlugin;
21 import org.eclipse.debug.core.ILaunch;
22 import org.eclipse.debug.core.model.IDebugTarget;
23 import org.eclipse.debug.core.model.IRegisterGroup;
24 import org.eclipse.debug.core.model.IStackFrame;
25 import org.eclipse.debug.core.model.IThread;
26 import org.eclipse.debug.core.model.IVariable;
30 * TODO Remove the variables array and use only the varList vector
31 * Have also to change hasVariables
33 public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Comparable{
35 private PHPThread thread; // The thread to which this stackframe belongs
36 private String file; // The file name???
37 private int lineNumber; //
40 private PHPVariable[] variables; // The array of variables TODO: better introduce a vector?
41 private Vector varList = new Vector ();
42 private String description; //
53 public PHPStackFrame (PHPThread thread, String file, int line, int index, String desc, int modno) {
56 this.lineNumber = line;
60 this.description = desc;
71 public PHPStackFrame (PHPThread thread, String file, int line, int index) {
74 this.lineNumber = line;
83 public IThread getThread () {
90 public void setThread (PHPThread thread) {
96 * This function returns the array of PHPVariables for this stackframe
97 * The PHPVariables should not change (newly build up) between two steps
99 * A PHPVariable with the same name but with different object ID is
100 * handled as a new variable.
102 * TODO Remove the intermediate storage array
104 * @return The array of PHPVariables for this stackframe.
106 public IVariable[] getVariables() throws DebugException {
107 //PHPVariable[] variablesNew; // The intermediate storage of the variable array we get from DBG proxy
109 //variablesNew = this.getPHPDBGProxy ().readVariables (this); // Get the variable array from DBG proxy
110 //variables = variablesNew; // Store the array the stackframes member variable
111 varList = this.getPHPDBGProxy ().readVariables (this);
113 variables = (PHPVariable[]) varList.toArray (new PHPVariable[varList.size ()]);
115 return variables; // Give the array back to user interface
121 private PHPVariable findVariable (Vector varList, String varname) {
122 PHPVariable variable;
126 for (i = 0; i < varList.size (); i++) { // For all variables
127 variable = (PHPVariable) varList.get (i); // Get the variable
128 value = (PHPValue) variable.getValue (); // Get the value of the variable
131 if (value.hasVariables ()) { // Does the variable/value have children
132 variable = findVariable (value.getChildVariables (), varname);
134 if (variable != null) {
138 else if ((variable.getName ()).equals (varname)) { //
142 catch (DebugException e) { // That's, because of the hasVariables method
150 * This method is called from the UI (e.g. from PHPDebugHover
151 * to find the variable the mouse is pointing to)
153 * @param s The variable name we are looking for.
156 public IVariable findVariable (String s) throws DebugException {
157 return (findVariable (varList, s)); // Prefix the variable name with $
163 public boolean hasVariables () throws DebugException {
164 if (variables == null) { // Do we have a variables array?
168 return variables.length > 0; // Is there something within the array?
171 public int getLineNumber() {
175 public void setLineNumber(int line) {
179 public int getCharStart() throws DebugException {
184 public int getCharEnd() throws DebugException {
189 public String getName() {
190 if(!this.getDescription().equals(""))
191 return this.getDescription() + " [line: " + this.getLineNumber() + "]";
193 return this.getFileName() + " [line: " + this.getLineNumber() + "]";
196 public String getFileName() {
200 public void setDescription(String desc) {
201 this.description= desc;
204 public String getDescription() {
205 return this.description;
208 public IRegisterGroup[] getRegisterGroups() throws DebugException {
212 public boolean hasRegisterGroups() throws DebugException {
216 public String getModelIdentifier() {
217 return this.getThread().getModelIdentifier();
220 public IDebugTarget getDebugTarget() {
221 return this.getThread().getDebugTarget();
224 public ILaunch getLaunch() {
225 return this.getDebugTarget().getLaunch();
228 public boolean canStepInto() {
232 public boolean canStepOver() {
236 public boolean canStepReturn() {
240 public boolean isStepping() {
247 public void stepInto () throws DebugException {
250 thread.prepareForResume (DebugEvent.STEP_INTO); // Don't know why, but this is necessary
251 this.getPHPDBGProxy ().readStepIntoEnd (PHPStackFrame.this);
253 ev = new DebugEvent (this.getThread (), DebugEvent.RESUME, DebugEvent.STEP_INTO);
254 DebugPlugin.getDefault().fireDebugEventSet (new DebugEvent[] { ev });
260 public void stepOver () throws DebugException {
263 thread.prepareForResume (DebugEvent.STEP_OVER);
264 this.getPHPDBGProxy ().readStepOverEnd (PHPStackFrame.this) ;
266 ev = new DebugEvent (this.getThread (), DebugEvent.RESUME, DebugEvent.STEP_OVER);
267 DebugPlugin.getDefault ().fireDebugEventSet (new DebugEvent[] { ev });
273 public void stepReturn () throws DebugException {
276 thread.prepareForResume (DebugEvent.STEP_RETURN);
277 this.getPHPDBGProxy ().readStepReturnEnd (PHPStackFrame.this) ;
279 ev = new DebugEvent (this.getThread (), DebugEvent.RESUME, DebugEvent.STEP_RETURN);
280 DebugPlugin.getDefault ().fireDebugEventSet (new DebugEvent[] { ev });
284 public boolean canResume() {
285 return this.getThread().canResume();
288 public boolean canSuspend() {
289 return this.getThread().canSuspend();
292 public boolean isSuspended() {
293 return this.getThread().isSuspended();
296 public void resume() throws DebugException {
297 this.getThread().resume();
300 public void suspend() throws DebugException {
303 public boolean canTerminate() {
304 return this.getThread().canTerminate();
307 public boolean isTerminated() {
308 return this.getThread().isTerminated();
311 public void terminate() throws DebugException {
312 getPHPDBGProxy().stop();
315 public int getIndex() {
319 public void setIndex (int index) {
323 public PHPDBGProxy getPHPDBGProxy() {
324 PHPDebugTarget DebugTarget;
326 DebugTarget = (PHPDebugTarget) thread.getDebugTarget ();
328 return DebugTarget.getPHPDBGProxy ();
331 public void setFile(String file) {
335 public int getModNo() {
340 * This function is needed when sorting the stackframes by their index numbers.
342 * @param obj The stackframe which this one is compared to.
345 * <li> -1 if the index of this stackframe is less.
346 * <li> 0 if the index of both stackfream is equal (should no happen).
347 * <li> 1 if the index of this stackfram is greater.
350 public int compareTo (Object obj)
352 if (index < ((PHPStackFrame) obj).getIndex ()) {
355 else if (index > ((PHPStackFrame) obj).getIndex ()) {