/******************************************************************************* * Copyright (c) 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation * Zend Technologies *******************************************************************************/ package org.eclipse.php.internal.debug.core.xdebug.dbgp.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.IStep; import org.eclipse.debug.core.model.IThread; import org.eclipse.php.internal.debug.core.PHPDebugCoreMessages; /** * Currently this implementation is for a single threaded language, so in the * case of ITerminate, ISuspendResume, IStep we just ask what the debug target * would do. IThread implementation is provided here. */ public class DBGpThread extends DBGpElement implements IThread { private IBreakpoint[] breakpoints; public DBGpThread(DBGpTarget target) { super(target); } /* * (non-Javadoc) * * @see org.eclipse.debug.core.model.IThread#getName() */ public String getName() throws DebugException { // PHP only has one thread, so no special naming required // PHP Thread return PHPDebugCoreMessages.XDebug_DBGpThread_0; } /* * (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#getBreakpoints() */ public IBreakpoint[] getBreakpoints() { if (breakpoints == null) { return new IBreakpoint[0]; } return breakpoints; } /* * (non-Javadoc) * * @see org.eclipse.debug.core.model.IThread#getStackFrames() */ public IStackFrame[] getStackFrames() throws DebugException { if (isSuspended()) { return ((DBGpTarget) getDebugTarget()).getCurrentStackFrames(); } else { return new IStackFrame[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#hasStackFrames() */ public boolean hasStackFrames() throws DebugException { return isSuspended(); } /* * (non-Javadoc) * * @see org.eclipse.debug.core.model.ISuspendResume#canResume() */ public boolean canResume() { return getDebugTarget().canResume(); } /* * (non-Javadoc) * * @see org.eclipse.debug.core.model.ISuspendResume#canSuspend() */ public boolean canSuspend() { return getDebugTarget().canSuspend(); } /* * (non-Javadoc) * * @see org.eclipse.debug.core.model.ISuspendResume#isSuspended() */ public boolean isSuspended() { return getDebugTarget().isSuspended(); } /* * (non-Javadoc) * * @see org.eclipse.debug.core.model.ITerminate#canTerminate() */ public boolean canTerminate() { return getDebugTarget().canTerminate(); } /* * (non-Javadoc) * * @see org.eclipse.debug.core.model.ITerminate#isTerminated() */ public boolean isTerminated() { return getDebugTarget().isTerminated(); } /* * (non-Javadoc) * * @see org.eclipse.debug.core.model.IStep#canStepInto() */ public boolean canStepInto() { return ((IStep) getDebugTarget()).canStepInto(); } /* * (non-Javadoc) * * @see org.eclipse.debug.core.model.IStep#canStepOver() */ public boolean canStepOver() { return ((IStep) getDebugTarget()).canStepOver(); } /* * (non-Javadoc) * * @see org.eclipse.debug.core.model.IStep#canStepReturn() */ public boolean canStepReturn() { return ((IStep) getDebugTarget()).canStepReturn(); } /* * (non-Javadoc) * * @see org.eclipse.debug.core.model.IStep#isStepping() */ public boolean isStepping() { return ((IStep) getDebugTarget()).isStepping(); } /* * (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#stepInto() */ public void stepInto() throws DebugException { ((IStep) getDebugTarget()).stepInto(); } /* * (non-Javadoc) * * @see org.eclipse.debug.core.model.IStep#stepOver() */ public void stepOver() throws DebugException { ((IStep) getDebugTarget()).stepOver(); } /* * (non-Javadoc) * * @see org.eclipse.debug.core.model.IStep#stepReturn() */ public void stepReturn() throws DebugException { ((IStep) getDebugTarget()).stepReturn(); } /* * (non-Javadoc) * * @see org.eclipse.debug.core.model.ITerminate#terminate() */ public void terminate() throws DebugException { getDebugTarget().terminate(); } /** * Set the breakpoints that caused this thread to suspend. The debug target * provides this info. * * @param breakpoints */ protected void setBreakpoints(IBreakpoint[] breakpoints) { this.breakpoints = breakpoints; } }