/******************************************************************************* * Copyright (c) 2004 IBM Corporation 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 API and implementation * Bjorn Freeman-Benson - initial API and implementation *******************************************************************************/ package rhogenwizard.debugger.model; import java.util.ArrayList; import java.util.List; import org.eclipse.debug.core.DebugException; 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; public class DebugStackFrame extends DebugElement implements IStackFrame { private static final String linePrefix = " Line: "; private DebugThread m_currThread = null; private String m_name = null; private int m_codeLine; private String m_fileName = null; private int m_id; private List<IVariable> m_variablesList; /** * Constructs a stack frame in the given thread with the given * frame data. * * @param thread * @param data frame data * @param id stack frame id (0 is the bottom of the stack) */ public DebugStackFrame(DebugThread thread, StackData stackData, int id) { super((DebugTarget) thread.getDebugTarget()); m_id = id; m_currThread = thread; init(stackData); } /** * Initializes this frame based on its data * * @param data */ private void init(StackData stackData) { m_fileName = stackData.m_resName; m_codeLine = stackData.m_codeLine; m_name = stackData.m_resName; m_variablesList = new ArrayList<IVariable>(); if (stackData.m_currVariables != null) { for (rhogenwizard.debugger.backend.DebugVariable var : stackData.m_currVariables) { try { DebugVariable stackVar = new DebugVariable((DebugTarget) this.getDebugTarget(), var.variable()); stackVar.setValue(new DebugValue(m_debugTarget, var.value())); m_variablesList.add(stackVar); } catch (DebugException e) { e.printStackTrace(); } } } } public void addVariables(IVariable variable) { m_variablesList.add(variable); } /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStackFrame#getThread() */ public IThread getThread() { return m_currThread; } /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStackFrame#getVariables() */ public IVariable[] getVariables() throws DebugException { IVariable[] array = new IVariable[m_variablesList.size()]; array = m_variablesList.toArray(array); return array; } /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStackFrame#hasVariables() */ public boolean hasVariables() throws DebugException { return m_variablesList.size() > 0; } /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStackFrame#getLineNumber() */ public int getLineNumber() throws DebugException { return m_codeLine; } /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStackFrame#getCharStart() */ public int getCharStart() throws DebugException { return -1; } /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStackFrame#getCharEnd() */ public int getCharEnd() throws DebugException { return -1; } /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStackFrame#getName() */ public String getName() throws DebugException { return m_name + linePrefix + m_codeLine; } /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStackFrame#getRegisterGroups() */ public IRegisterGroup[] getRegisterGroups() throws DebugException { return null; } /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStackFrame#hasRegisterGroups() */ public boolean hasRegisterGroups() throws DebugException { return false; } /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStep#canStepInto() */ public boolean canStepInto() { return getThread().canStepInto(); } /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStep#canStepOver() */ public boolean canStepOver() { return getThread().canStepOver(); } /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStep#canStepReturn() */ public boolean canStepReturn() { return getThread().canStepReturn(); } /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStep#isStepping() */ public boolean isStepping() { return getThread().isStepping(); } /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStep#stepInto() */ public void stepInto() throws DebugException { getThread().stepInto(); } /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStep#stepOver() */ public void stepOver() throws DebugException { getThread().stepOver(); } /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStep#stepReturn() */ public void stepReturn() throws DebugException { getThread().stepReturn(); } /* (non-Javadoc) * @see org.eclipse.debug.core.model.ISuspendResume#canResume() */ public boolean canResume() { return getThread().canResume(); } /* (non-Javadoc) * @see org.eclipse.debug.core.model.ISuspendResume#canSuspend() */ public boolean canSuspend() { return getThread().canSuspend(); } /* (non-Javadoc) * @see org.eclipse.debug.core.model.ISuspendResume#isSuspended() */ public boolean isSuspended() { return getThread().isSuspended(); } /* (non-Javadoc) * @see org.eclipse.debug.core.model.ISuspendResume#resume() */ public void resume() throws DebugException { getThread().resume(); } /* (non-Javadoc) * @see org.eclipse.debug.core.model.ISuspendResume#suspend() */ public void suspend() throws DebugException { getThread().suspend(); } /* (non-Javadoc) * @see org.eclipse.debug.core.model.ITerminate#canTerminate() */ public boolean canTerminate() { return getThread().canTerminate(); } /* (non-Javadoc) * @see org.eclipse.debug.core.model.ITerminate#isTerminated() */ public boolean isTerminated() { return getThread().isTerminated(); } /* (non-Javadoc) * @see org.eclipse.debug.core.model.ITerminate#terminate() */ public void terminate() throws DebugException { getThread().terminate(); } /** * Returns the name of the source file this stack frame is associated * with. * * @return the name of the source file this stack frame is associated * with */ public String getSourceName() { return m_fileName; } /* (non-Javadoc) * @see java.lang.Object#equals(java.lang.Object) */ public boolean equals(Object obj) { if (obj instanceof DebugStackFrame) { DebugStackFrame sf = (DebugStackFrame)obj; try { return sf.getSourceName().equals(getSourceName()) && sf.getLineNumber() == getLineNumber() && sf.m_id == m_id; } catch (DebugException e) { } } return false; } /* (non-Javadoc) * @see java.lang.Object#hashCode() */ public int hashCode() { return getSourceName().hashCode() + m_id; } /** * Returns this stack frame's unique identifier within its thread * * @return this stack frame's unique identifier within its thread */ protected int getIdentifier() { return m_id; } }