/********************************************************************** Copyright (c) 2000, 2002 IBM Corp. and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Common Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/cpl-v10.html Contributors: IBM Corporation - Initial implementation Vicente Fernando - www.alfersoft.com.ar **********************************************************************/ package net.sourceforge.phpdt.internal.debug.core.model; import org.eclipse.debug.core.DebugEvent; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.model.IDebugTarget; import org.eclipse.debug.core.model.IRegisterGroup; import org.eclipse.debug.core.model.IStackFrame; import org.eclipse.debug.core.model.IThread; import org.eclipse.debug.core.model.IVariable; import net.sourceforge.phpdt.internal.debug.core.PHPDBGProxy; import net.sourceforge.phpdt.internal.debug.core.model.PHPDebugTarget; public class PHPStackFrame implements IStackFrame { private PHPThread thread; private String file; private int lineNumber; private int index; private int modno; private PHPVariable[] variables; private String description; public PHPStackFrame(PHPThread thread, String file, int line, int index, String desc, int modno) { this.lineNumber = line; this.index = index; this.file = file; this.thread = thread; this.description = desc; this.modno = modno; } public PHPStackFrame(PHPThread thread, String file, int line, int index) { this.lineNumber = line; this.index = index; this.file = file; this.thread = thread; } public IThread getThread() { return thread; } public void setThread(PHPThread thread) { this.thread = thread; } public IVariable[] getVariables() throws DebugException { if (variables == null) { variables = this.getPHPDBGProxy().readVariables(this); } return variables; } public IVariable findVariable(String s) throws DebugException { if (this.hasVariables()) { String name="$"+s; for(int i= 0; i < variables.length; i++) { String n= variables[i].getName(); if((variables[i].getName()).equals(name)) return variables[i]; } } return null; } public boolean hasVariables() throws DebugException { if (variables == null) { return false; } return variables.length > 0; } public int getLineNumber() { return lineNumber; } public int getCharStart() throws DebugException { // not supported return -1; } public int getCharEnd() throws DebugException { // not supported return -1; } public String getName() { if(!this.getDescription().equals("")) return this.getDescription() + " [line: " + this.getLineNumber() + "]"; else return this.getFileName() + " [line: " + this.getLineNumber() + "]"; } public String getFileName() { return file; } public void setDescription(String desc) { this.description= desc; } public String getDescription() { return this.description; } public IRegisterGroup[] getRegisterGroups() throws DebugException { return null; } public boolean hasRegisterGroups() throws DebugException { return false; } public String getModelIdentifier() { return this.getThread().getModelIdentifier(); } public IDebugTarget getDebugTarget() { return this.getThread().getDebugTarget(); } public ILaunch getLaunch() { return this.getDebugTarget().getLaunch(); } public boolean canStepInto() { return canResume(); } public boolean canStepOver() { return canResume(); } public boolean canStepReturn() { return canResume(); } public boolean isStepping() { return false; } public void stepInto() throws DebugException { thread.prepareForResume() ; this.getPHPDBGProxy().readStepIntoEnd(PHPStackFrame.this) ; DebugEvent ev = new DebugEvent(this.getThread(), DebugEvent.RESUME, DebugEvent.STEP_INTO); DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { ev }); } public void stepOver() throws DebugException { thread.prepareForResume() ; this.getPHPDBGProxy().readStepOverEnd(PHPStackFrame.this) ; DebugEvent ev = new DebugEvent(this.getThread(), DebugEvent.RESUME, DebugEvent.STEP_OVER); DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { ev }); } public void stepReturn() throws DebugException { thread.prepareForResume() ; this.getPHPDBGProxy().readStepReturnEnd(PHPStackFrame.this) ; DebugEvent ev = new DebugEvent(this.getThread(), DebugEvent.RESUME, DebugEvent.STEP_RETURN); DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { ev }); } public boolean canResume() { return this.getThread().canResume(); } public boolean canSuspend() { return this.getThread().canSuspend(); } public boolean isSuspended() { return this.getThread().isSuspended(); } public void resume() throws DebugException { this.getThread().resume(); } public void suspend() throws DebugException { } public boolean canTerminate() { return this.getThread().canTerminate(); } public boolean isTerminated() { return this.getThread().isTerminated(); } public void terminate() throws DebugException { getPHPDBGProxy().stop(); } public Object getAdapter(Class arg0) { if (arg0==PHPStackFrame.class) return this; else return null; } public int getIndex() { return index; } public PHPDBGProxy getPHPDBGProxy() { PHPDebugTarget DebugTarget; DebugTarget= (PHPDebugTarget)thread.getDebugTarget(); return DebugTarget.getPHPDBGProxy(); } public void setFile(String file) { this.file = file; } public int getModNo() { return modno; } }