1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

More implementation.

This commit is contained in:
Mikhail Khodjaiants 2002-08-08 21:51:16 +00:00
parent 7ce1db8c1d
commit b0b0574436
5 changed files with 225 additions and 185 deletions

View file

@ -1,149 +0,0 @@
/*
*(c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*
*/
package org.eclipse.cdt.debug.internal.core;
import org.eclipse.cdt.debug.core.cdi.ICSession;
/**
*
* Provides the convenience access methods to the configuration
* parameters of the debug session.
*
* @since Aug 6, 2002
*/
public class CDebugConfiguration
{
private ICSession fSession;
/**
* Constructor for CDebugConfiguration.
*/
public CDebugConfiguration( ICSession session )
{
fSession = session;
}
/**
* Returns whether this session supports termination.
*
* @return whether this session supports termination
*/
public boolean supportsTerminate()
{
return true;
}
/**
* Returns whether this session supports disconnecting.
*
* @return whether this session supports disconnecting
*/
public boolean supportsDisconnect()
{
return true;
}
/**
* Returns whether this session supports suspend/resume.
*
* @return whether this session supports suspend/resume
*/
public boolean supportsSuspendResume()
{
return true;
}
/**
* Returns whether this session supports restarting.
*
* @return whether this session supports restarting
*/
public boolean supportsRestart()
{
return true;
}
/**
* Returns whether this session supports stepping.
*
* @return whether this session supports stepping
*/
public boolean supportsStepping()
{
return true;
}
/**
* Returns whether this session supports instruction stepping.
*
* @return whether this session supports instruction stepping
*/
public boolean supportsInstructionStepping()
{
return true;
}
/**
* Returns whether this session supports breakpoints.
*
* @return whether this session supports breakpoints
*/
public boolean supportsBreakpoints()
{
return true;
}
/**
* Returns whether this session supports registers.
*
* @return whether this session supports registers
*/
public boolean supportsRegisters()
{
return true;
}
/**
* Returns whether this session supports register modification.
*
* @return whether this session supports registers modification
*/
public boolean supportsRegisterModification()
{
return true;
}
/**
* Returns whether this session supports memory retrieval.
*
* @return whether this session supports memory retrieval
*/
public boolean supportsMemoryRetrieval()
{
return true;
}
/**
* Returns whether this session supports memory modification.
*
* @return whether this session supports memory modification
*/
public boolean supportsMemoryModification()
{
return true;
}
/**
* Returns whether this session supports expression evaluation.
*
* @return whether this session supports expression evaluation
*/
public boolean supportsExpressionEvaluation()
{
return true;
}
}

View file

@ -13,11 +13,11 @@ import java.util.List;
import org.eclipse.cdt.debug.core.CDebugModel; import org.eclipse.cdt.debug.core.CDebugModel;
import org.eclipse.cdt.debug.core.IFormattedMemoryBlock; import org.eclipse.cdt.debug.core.IFormattedMemoryBlock;
import org.eclipse.cdt.debug.core.IFormattedMemoryRetrieval; import org.eclipse.cdt.debug.core.IFormattedMemoryRetrieval;
import org.eclipse.cdt.debug.core.IInstructionStep;
import org.eclipse.cdt.debug.core.IRestart; import org.eclipse.cdt.debug.core.IRestart;
import org.eclipse.cdt.debug.core.IState; import org.eclipse.cdt.debug.core.IState;
import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.ICBreakpoint; import org.eclipse.cdt.debug.core.cdi.ICBreakpoint;
import org.eclipse.cdt.debug.core.cdi.ICDebugConfiguration;
import org.eclipse.cdt.debug.core.cdi.ICEndSteppingRange; import org.eclipse.cdt.debug.core.cdi.ICEndSteppingRange;
import org.eclipse.cdt.debug.core.cdi.ICSessionObject; import org.eclipse.cdt.debug.core.cdi.ICSessionObject;
import org.eclipse.cdt.debug.core.cdi.ICSignal; import org.eclipse.cdt.debug.core.cdi.ICSignal;
@ -47,7 +47,6 @@ import org.eclipse.debug.core.model.IBreakpoint;
import org.eclipse.debug.core.model.IDebugTarget; import org.eclipse.debug.core.model.IDebugTarget;
import org.eclipse.debug.core.model.IMemoryBlock; import org.eclipse.debug.core.model.IMemoryBlock;
import org.eclipse.debug.core.model.IProcess; import org.eclipse.debug.core.model.IProcess;
import org.eclipse.debug.core.model.IStep;
import org.eclipse.debug.core.model.IThread; import org.eclipse.debug.core.model.IThread;
/** /**
@ -119,7 +118,7 @@ public class CDebugTarget extends CDebugElement
/** /**
* The debug configuration of this session * The debug configuration of this session
*/ */
private CDebugConfiguration fConfig; private ICDebugConfiguration fConfig;
/** /**
* Whether terminate is supported. * Whether terminate is supported.
@ -159,7 +158,7 @@ public class CDebugTarget extends CDebugElement
setName( name ); setName( name );
setProcess( process ); setProcess( process );
setCDITarget( cdiTarget ); setCDITarget( cdiTarget );
fConfig = new CDebugConfiguration( cdiTarget.getSession() ); fConfig = cdiTarget.getSession().getConfiguration();
fSupportsTerminate = allowsTerminate & fConfig.supportsTerminate(); fSupportsTerminate = allowsTerminate & fConfig.supportsTerminate();
fSupportsDisconnect = allowsDisconnect & fConfig.supportsDisconnect(); fSupportsDisconnect = allowsDisconnect & fConfig.supportsDisconnect();
setThreadList( new ArrayList( 5 ) ); setThreadList( new ArrayList( 5 ) );

View file

@ -23,6 +23,10 @@ public class CLocalVariable extends CDebugElement
implements IVariable, implements IVariable,
ICEventListener ICEventListener
{ {
/**
* Underlying CDI variable.
*/
private ICVariable fCDIVariable;
/** /**
* Constructor for CLocalVariable. * Constructor for CLocalVariable.
@ -31,6 +35,7 @@ public class CLocalVariable extends CDebugElement
public CLocalVariable( CStackFrame stackFrame, ICVariable cdiVariable ) public CLocalVariable( CStackFrame stackFrame, ICVariable cdiVariable )
{ {
super( (CDebugTarget)stackFrame.getDebugTarget() ); super( (CDebugTarget)stackFrame.getDebugTarget() );
fCDIVariable = cdiVariable;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -109,4 +114,15 @@ public class CLocalVariable extends CDebugElement
{ {
return false; return false;
} }
/**
* Returns the underlying CDI variable that this model object is
* a proxy to.
*
* @return the underlying CDI variable
*/
protected ICVariable getCDIVariable()
{
return fCDIVariable;
}
} }

View file

@ -7,13 +7,17 @@ package org.eclipse.cdt.debug.internal.core;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator;
import java.util.List; import java.util.List;
import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.ICLocation;
import org.eclipse.cdt.debug.core.cdi.event.ICEvent; import org.eclipse.cdt.debug.core.cdi.event.ICEvent;
import org.eclipse.cdt.debug.core.cdi.event.ICEventListener; import org.eclipse.cdt.debug.core.cdi.event.ICEventListener;
import org.eclipse.cdt.debug.core.cdi.model.ICArgument; import org.eclipse.cdt.debug.core.cdi.model.ICArgument;
import org.eclipse.cdt.debug.core.cdi.model.ICObject;
import org.eclipse.cdt.debug.core.cdi.model.ICStackFrame; import org.eclipse.cdt.debug.core.cdi.model.ICStackFrame;
import org.eclipse.cdt.debug.core.cdi.model.ICVariable; import org.eclipse.cdt.debug.core.cdi.model.ICVariable;
import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugException;
@ -37,6 +41,11 @@ public class CStackFrame extends CDebugElement
*/ */
private ICStackFrame fCDIStackFrame; private ICStackFrame fCDIStackFrame;
/**
* The last (previous) CDI stack frame.
*/
private ICStackFrame fLastCDIStackFrame;
/** /**
* Containing thread. * Containing thread.
*/ */
@ -85,9 +94,13 @@ public class CStackFrame extends CDebugElement
{ {
if ( fVariables == null ) if ( fVariables == null )
{ {
fVariables = new ArrayList(); List vars = getAllCDIVariables();
fVariables.addAll( getCDIArguments() ); fVariables = new ArrayList( vars.size() );
fVariables.addAll( getCDILocalVariables() ); Iterator it = vars.iterator();
while( it.hasNext() )
{
fVariables.add( new CLocalVariable( this, (ICVariable)it.next() ) );
}
} }
else if ( fRefreshVariables ) else if ( fRefreshVariables )
{ {
@ -98,11 +111,38 @@ public class CStackFrame extends CDebugElement
} }
/** /**
* Incrementally updates this stack frames variables. * Incrementally updates this stack frame's variables.
* *
*/ */
protected void updateVariables() throws DebugException protected void updateVariables() throws DebugException
{ {
List locals = null;
locals = getAllCDIVariables();
int localIndex = -1;
int index = 0;
while( index < fVariables.size() )
{
CLocalVariable local = (CLocalVariable)fVariables.get( index );
localIndex = locals.indexOf( local.getCDIVariable() );
if ( localIndex >= 0 )
{
// update variable with new underling CDI LocalVariable
locals.remove( localIndex );
index++;
}
else
{
// remove variable
fVariables.remove( index );
}
}
// add any new locals
Iterator newOnes = locals.iterator();
while( newOnes.hasNext() )
{
fVariables.add( new CLocalVariable( this, (ICVariable)newOnes.next() ) );
}
} }
/** /**
@ -128,7 +168,15 @@ public class CStackFrame extends CDebugElement
*/ */
public int getLineNumber() throws DebugException public int getLineNumber() throws DebugException
{ {
return 0; if ( isSuspended() )
{
ICLocation location = getCDIStackFrame().getLocation();
if ( location != null )
{
return location.getLineNumber();
}
}
return -1;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -136,7 +184,7 @@ public class CStackFrame extends CDebugElement
*/ */
public int getCharStart() throws DebugException public int getCharStart() throws DebugException
{ {
return 0; return -1;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -144,7 +192,7 @@ public class CStackFrame extends CDebugElement
*/ */
public int getCharEnd() throws DebugException public int getCharEnd() throws DebugException
{ {
return 0; return -1;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -160,7 +208,7 @@ public class CStackFrame extends CDebugElement
*/ */
public IRegisterGroup[] getRegisterGroups() throws DebugException public IRegisterGroup[] getRegisterGroups() throws DebugException
{ {
return null; return new IRegisterGroup[0];
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -168,13 +216,13 @@ public class CStackFrame extends CDebugElement
*/ */
public boolean hasRegisterGroups() throws DebugException public boolean hasRegisterGroups() throws DebugException
{ {
return false; return getRegisterGroups().length > 0;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.cdi.event.ICEventListener#handleDebugEvent(ICEvent) * @see org.eclipse.cdt.debug.core.cdi.event.ICEventListener#handleDebugEvent(ICEvent)
*/ */
public void handleDebugEvent(ICEvent event) public void handleDebugEvent( ICEvent event )
{ {
} }
@ -183,7 +231,15 @@ public class CStackFrame extends CDebugElement
*/ */
public boolean canStepInto() public boolean canStepInto()
{ {
return false; try
{
return exists() && isTopStackFrame() && getThread().canStepInto();
}
catch( DebugException e )
{
logError( e );
return false;
}
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -191,7 +247,15 @@ public class CStackFrame extends CDebugElement
*/ */
public boolean canStepOver() public boolean canStepOver()
{ {
return false; try
{
return exists() && getThread().canStepOver();
}
catch( DebugException e )
{
logError( e );
return false;
}
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -199,6 +263,24 @@ public class CStackFrame extends CDebugElement
*/ */
public boolean canStepReturn() public boolean canStepReturn()
{ {
try
{
if ( !exists() )
{
return false;
}
List frames = ((CThread)getThread()).computeStackFrames();
if ( frames != null && !frames.isEmpty() )
{
boolean bottomFrame = this.equals( frames.get( frames.size() - 1 ) );
boolean aboveObsoleteFrame = false;
return !bottomFrame && getThread().canStepReturn();
}
}
catch( DebugException e )
{
logError( e );
}
return false; return false;
} }
@ -207,7 +289,7 @@ public class CStackFrame extends CDebugElement
*/ */
public boolean isStepping() public boolean isStepping()
{ {
return false; return getThread().isStepping();
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -215,6 +297,11 @@ public class CStackFrame extends CDebugElement
*/ */
public void stepInto() throws DebugException public void stepInto() throws DebugException
{ {
if ( !canStepInto() )
{
return;
}
getThread().stepInto();
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -222,6 +309,18 @@ public class CStackFrame extends CDebugElement
*/ */
public void stepOver() throws DebugException public void stepOver() throws DebugException
{ {
if ( !canStepOver() )
{
return;
}
if ( isTopStackFrame() )
{
getThread().stepOver();
}
else
{
((CThread)getThread()).stepToFrame( this );
}
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -229,6 +328,24 @@ public class CStackFrame extends CDebugElement
*/ */
public void stepReturn() throws DebugException public void stepReturn() throws DebugException
{ {
if ( !canStepReturn() )
{
return;
}
if ( isTopStackFrame() )
{
getThread().stepReturn();
}
else
{
List frames = ((CThread)getThread()).computeStackFrames();
int index = frames.indexOf( this );
if ( index >= 0 && index < frames.size() - 1 )
{
IStackFrame nextFrame = (IStackFrame)frames.get( index + 1 );
((CThread)getThread()).stepToFrame( nextFrame );
}
}
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -236,7 +353,7 @@ public class CStackFrame extends CDebugElement
*/ */
public boolean canResume() public boolean canResume()
{ {
return false; return getThread().canResume();
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -244,7 +361,7 @@ public class CStackFrame extends CDebugElement
*/ */
public boolean canSuspend() public boolean canSuspend()
{ {
return false; return getThread().canSuspend();
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -252,7 +369,7 @@ public class CStackFrame extends CDebugElement
*/ */
public boolean isSuspended() public boolean isSuspended()
{ {
return false; return getThread().isSuspended();
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -260,6 +377,7 @@ public class CStackFrame extends CDebugElement
*/ */
public void resume() throws DebugException public void resume() throws DebugException
{ {
getThread().resume();
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -267,6 +385,7 @@ public class CStackFrame extends CDebugElement
*/ */
public void suspend() throws DebugException public void suspend() throws DebugException
{ {
getThread().suspend();
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -274,7 +393,16 @@ public class CStackFrame extends CDebugElement
*/ */
public boolean canTerminate() public boolean canTerminate()
{ {
return false; boolean exists = false;
try
{
exists = exists();
}
catch( DebugException e )
{
logError( e );
}
return exists && getThread().canTerminate() || getDebugTarget().canTerminate();
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -282,7 +410,7 @@ public class CStackFrame extends CDebugElement
*/ */
public boolean isTerminated() public boolean isTerminated()
{ {
return false; return getThread().isTerminated();
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -290,6 +418,14 @@ public class CStackFrame extends CDebugElement
*/ */
public void terminate() throws DebugException public void terminate() throws DebugException
{ {
if ( getThread().canTerminate() )
{
getThread().terminate();
}
else
{
getDebugTarget().terminate();
}
} }
/** /**
@ -311,6 +447,16 @@ public class CStackFrame extends CDebugElement
*/ */
protected void setCDIStackFrame( ICStackFrame frame ) protected void setCDIStackFrame( ICStackFrame frame )
{ {
if ( frame != null )
{
fLastCDIStackFrame = frame;
}
else
{
fLastCDIStackFrame = fCDIStackFrame;
}
fCDIStackFrame = frame;
fRefreshVariables = true;
} }
/** /**
@ -320,7 +466,7 @@ public class CStackFrame extends CDebugElement
*/ */
protected ICStackFrame getLastCDIStackFrame() protected ICStackFrame getLastCDIStackFrame()
{ {
return null; return fLastCDIStackFrame;
} }
/** /**
@ -330,7 +476,8 @@ public class CStackFrame extends CDebugElement
*/ */
protected static boolean equalFrame( ICStackFrame frameOne, ICStackFrame frameTwo ) protected static boolean equalFrame( ICStackFrame frameOne, ICStackFrame frameTwo )
{ {
return false; return ( frameOne.getParent().equals( frameTwo.getParent() ) &&
frameOne.getLocation().equals( frameTwo.getLocation() ) );
} }
protected boolean exists() throws DebugException protected boolean exists() throws DebugException
@ -366,13 +513,10 @@ public class CStackFrame extends CDebugElement
*/ */
protected List getCDILocalVariables() throws DebugException protected List getCDILocalVariables() throws DebugException
{ {
List list = Collections.EMPTY_LIST; List list = new ArrayList();
try try
{ {
ICVariable[] vars = getCDIStackFrame().getLocalVariables(); list.add( Arrays.asList( getCDIStackFrame().getLocalVariables() ) );
list = new ArrayList( vars.length );
for ( int i = 0; i < vars.length; ++i )
list.add( new CLocalVariable( this, vars[i] ) );
} }
catch( CDIException e ) catch( CDIException e )
{ {
@ -388,18 +532,29 @@ public class CStackFrame extends CDebugElement
*/ */
protected List getCDIArguments() throws DebugException protected List getCDIArguments() throws DebugException
{ {
List list = Collections.EMPTY_LIST; List list = new ArrayList();
try try
{ {
ICArgument[] args = getCDIStackFrame().getArguments(); list.add( Arrays.asList( getCDIStackFrame().getArguments() ) );
list = new ArrayList( args.length );
for ( int i = 0; i < args.length; ++i )
list.add( new CLocalVariable( this, args[i] ) );
} }
catch( CDIException e ) catch( CDIException e )
{ {
targetRequestFailed( MessageFormat.format( "{0} occurred retrieving arguments", new String[] { e.toString() } ), e ); targetRequestFailed( MessageFormat.format( "{0} occurred retrieving arguments", new String[] { e.toString() } ), e );
} }
return list; return list;
}
protected List getAllCDIVariables() throws DebugException
{
List list = new ArrayList();
list.add( getCDIArguments() );
list.add( getCDILocalVariables() );
return list;
} }
protected boolean isTopStackFrame() throws DebugException
{
IStackFrame tos = getThread().getTopStackFrame();
return tos != null && tos.equals( this );
}
} }

View file

@ -16,6 +16,7 @@ import org.eclipse.cdt.debug.core.IInstructionStep;
import org.eclipse.cdt.debug.core.IState; import org.eclipse.cdt.debug.core.IState;
import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.ICBreakpoint; import org.eclipse.cdt.debug.core.cdi.ICBreakpoint;
import org.eclipse.cdt.debug.core.cdi.ICDebugConfiguration;
import org.eclipse.cdt.debug.core.cdi.ICEndSteppingRange; import org.eclipse.cdt.debug.core.cdi.ICEndSteppingRange;
import org.eclipse.cdt.debug.core.cdi.ICSessionObject; import org.eclipse.cdt.debug.core.cdi.ICSessionObject;
import org.eclipse.cdt.debug.core.cdi.ICSignal; import org.eclipse.cdt.debug.core.cdi.ICSignal;
@ -83,7 +84,7 @@ public class CThread extends CDebugElement
/** /**
* The debug configuration of this session. * The debug configuration of this session.
*/ */
private CDebugConfiguration fConfig; private ICDebugConfiguration fConfig;
/** /**
* Constructor for CThread. * Constructor for CThread.
@ -93,7 +94,7 @@ public class CThread extends CDebugElement
{ {
super( target ); super( target );
setCDIThread( cdiThread ); setCDIThread( cdiThread );
fConfig = new CDebugConfiguration( getCDISession() ); fConfig = getCDISession().getConfiguration();
initialize(); initialize();
getCDISession().getEventManager().addEventListener( this ); getCDISession().getEventManager().addEventListener( this );
} }
@ -896,4 +897,22 @@ public class CThread extends CDebugElement
getCDISession().getEventManager().removeEventListener( this ); getCDISession().getEventManager().removeEventListener( this );
disposeStackFrames(); disposeStackFrames();
} }
/**
* Steps until the specified stack frame is the top frame. Provides
* ability to step over/return in the non-top stack frame.
* This method is synchronized, such that the step request
* begins before a background evaluation can be performed.
*
* @exception DebugException if this method fails. Reasons include:
* <ul>
* </ul>
*/
protected synchronized void stepToFrame( IStackFrame frame ) throws DebugException
{
if ( !canStepReturn() )
{
return;
}
}
} }