/*******************************************************************************
* 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 org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IBreakpoint;
import org.eclipse.debug.core.model.IStackFrame;
import org.eclipse.debug.core.model.IThread;
/**
* A PDA VM thread. A PDA VM is single threaded.
*/
public class DebugThread extends DebugElement implements IThread
{
/**
* Breakpoints this thread is suspended at or <code>null</code>
* if none.
*/
private IBreakpoint[] m_breakpoints;
/**
* Whether this thread is stepping
*/
private boolean m_isStepping = false;
/**
* Constructs a new thread for the given target
*
* @param target VM
*/
public DebugThread(DebugTarget target)
{
super(target);
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IThread#getStackFrames()
*/
public IStackFrame[] getStackFrames() throws DebugException
{
if (isSuspended())
{
IStackFrame[] stacks = ((DebugTarget)getDebugTarget()).getStackFrames();
if (stacks[0] instanceof DebugStackFrame)
{
DebugStackFrame frame = (DebugStackFrame)stacks[0];
if (frame.getSourceName().equals(""))
return new IStackFrame[0];
}
return stacks;
}
else
{
return new IStackFrame[0];
}
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IThread#hasStackFrames()
*/
public boolean hasStackFrames() throws DebugException
{
return isSuspended();
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IThread#getPriority()
*/
public int getPriority() throws DebugException
{
return 0;
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IThread#getTopStackFrame()
*/
public IStackFrame getTopStackFrame() throws DebugException
{
IStackFrame[] frames = getStackFrames();
if (frames.length > 0) {
return frames[0];
}
return null;
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IThread#getName()
*/
public String getName() throws DebugException
{
return "Main Ruby Thread";
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IThread#getBreakpoints()
*/
public IBreakpoint[] getBreakpoints()
{
if (m_breakpoints == null)
{
return new IBreakpoint[0];
}
return m_breakpoints;
}
/**
* Sets the breakpoints this thread is suspended at, or <code>null</code>
* if none.
*
* @param breakpoints the breakpoints this thread is suspended at, or <code>null</code>
* if none
*/
protected void setBreakpoints(IBreakpoint[] breakpoints)
{
m_breakpoints = breakpoints;
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.ISuspendResume#canResume()
*/
public boolean canResume()
{
return isSuspended();
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.ISuspendResume#canSuspend()
*/
public boolean canSuspend()
{
return !isSuspended();
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.ISuspendResume#isSuspended()
*/
public boolean isSuspended()
{
return getDebugTarget().isSuspended();
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.ISuspendResume#resume()
*/
public void resume() throws DebugException
{
getDebugTarget().resume();
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.ISuspendResume#suspend()
*/
public void suspend() throws DebugException
{
getDebugTarget().suspend();
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IStep#canStepInto()
*/
public boolean canStepInto()
{
//return false;
return isSuspended();
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IStep#canStepOver()
*/
public boolean canStepOver()
{
//return false;
return isSuspended();
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IStep#canStepReturn()
*/
public boolean canStepReturn()
{
//return false;
return isSuspended();
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IStep#isStepping()
*/
public boolean isStepping()
{
return m_isStepping;
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IStep#stepInto()
*/
public void stepInto() throws DebugException
{
((DebugTarget)getDebugTarget()).stepInto();
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IStep#stepOver()
*/
public void stepOver() throws DebugException
{
((DebugTarget)getDebugTarget()).stepOver();
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IStep#stepReturn()
*/
public void stepReturn() throws DebugException
{
((DebugTarget)getDebugTarget()).stepReturn();
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.ITerminate#canTerminate()
*/
public boolean canTerminate()
{
return !isTerminated();
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.ITerminate#isTerminated()
*/
public boolean isTerminated()
{
return getDebugTarget().isTerminated();
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.ITerminate#terminate()
*/
public void terminate() throws DebugException
{
getDebugTarget().terminate();
}
/**
* Sets whether this thread is stepping
*
* @param stepping whether stepping
*/
protected void setStepping(boolean stepping)
{
m_isStepping = stepping;
}
}