1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

Evaluate expressions on stack frame instead of target to provide evaluation context.

This commit is contained in:
Mikhail Khodjaiants 2004-09-20 20:17:07 +00:00
parent cfb7157606
commit 1c54168e72
14 changed files with 177 additions and 184 deletions

View file

@ -1,3 +1,19 @@
2004-09-20 Mikhail Khodjaiants
Evaluate expressions on stack frame instead of target to provide evaluation context.
* ICDebugTarget.java
* ICStackFrame.java
* ICExpressionEvaluator.java
* AbstractCValue.java
* AbstractCVariable.java
* CArrayPartition.java
* CArrayPartitionValue.java
* CDebugTarget.java
* CFormattedMemoryBlock.java
* CStackFrame.java
* CThread.java
* CValue.java
* CVariable.java
2004-09-17 Alain Magloire
Support for 64 bits application
PR 74056. Pathc from Artyom Kuanbekov

View file

@ -17,7 +17,6 @@ import org.eclipse.debug.core.model.IDebugTarget;
* C/C++ extension of <code>IDebugTarget</code>.
*/
public interface ICDebugTarget extends IDebugTarget,
ICExpressionEvaluator,
IExecFileInfo,
IRestart,
IRunToLine,

View file

@ -1,39 +0,0 @@
/*******************************************************************************
* Copyright (c) 2000, 2004 QNX Software Systems 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:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.debug.core.model;
import org.eclipse.debug.core.DebugException;
/**
*
* Supports the evaluation of C/C++ expressions.
*
* @since Sep 13, 2002
*/
public interface ICExpressionEvaluator
{
/**
* Evaluates the specified expression and returns evaluation result
* as a string.
*
* @param expression the expression to evaluate
* @return the evaluation result
* @throws DebugException on failure. Reasons include:
*/
String evaluateExpressionToString( String expression ) throws DebugException;
/**
* Returns whether this object can currently evaluate an expression.
*
* @return whether this object can currently evaluate an expression
*/
boolean canEvaluate();
}

View file

@ -66,4 +66,21 @@ public interface ICStackFrame extends IStackFrame, ICDebugElement {
* @throws DebugException if this method fails.
*/
public IValue evaluateExpression( String expression ) throws DebugException;
/**
* Evaluates the specified expression in the context of this stack frame
* and returns the evaluation result as a string.
*
* @param expression the expression to evaluate
* @return the evaluation result
* @throws DebugException on failure. Reasons include:
*/
public String evaluateExpressionToString( String expression ) throws DebugException;
/**
* Returns whether this stack frame can currently evaluate an expression.
*
* @return whether this stack frame can currently evaluate an expression
*/
boolean canEvaluate();
}

View file

@ -17,11 +17,21 @@ import org.eclipse.cdt.debug.core.model.ICValue;
*/
public abstract class AbstractCValue extends CDebugElement implements ICValue {
/**
* Parent variable.
*/
private AbstractCVariable fParent = null;
/**
* Constructor for AbstractCValue.
*/
public AbstractCValue( CDebugTarget target ) {
super( target );
public AbstractCValue( AbstractCVariable parent ) {
super( (CDebugTarget)parent.getDebugTarget() );
fParent = parent;
}
public AbstractCVariable getParentVariable() {
return fParent;
}
abstract protected void setChanged( boolean changed );

View file

@ -10,6 +10,7 @@
***********************************************************************/
package org.eclipse.cdt.debug.internal.core.model;
import org.eclipse.cdt.debug.core.model.ICStackFrame;
import org.eclipse.cdt.debug.core.model.ICVariable;
import org.eclipse.debug.core.DebugException;
@ -18,11 +19,37 @@ import org.eclipse.debug.core.DebugException;
*/
public abstract class AbstractCVariable extends CDebugElement implements ICVariable {
/**
* The parent object this variable is contained in.
*/
private CDebugElement fParent;
/**
* Constructor for AbstractCVariable.
*/
public AbstractCVariable( CDebugTarget target ) {
super( target );
public AbstractCVariable( CDebugElement parent ) {
super( (CDebugTarget)parent.getDebugTarget() );
setParent( parent );
}
protected CDebugElement getParent() {
return fParent;
}
private void setParent( CDebugElement parent ) {
fParent = parent;
}
protected ICStackFrame getStackFrame() {
CDebugElement parent = getParent();
if ( parent instanceof AbstractCValue ) {
AbstractCVariable pv = ((AbstractCValue)parent).getParentVariable();
if ( pv != null )
return pv.getStackFrame();
}
if ( parent instanceof CStackFrame )
return (CStackFrame)parent;
return null;
}
/**

View file

@ -51,7 +51,7 @@ public class CArrayPartition extends AbstractCVariable {
* Constructor for CArrayPartition.
*/
private CArrayPartition( CDebugElement parent, ICDIVariable cdiVariable, int start, int end ) {
super( (CDebugTarget)parent.getDebugTarget() );
super( parent );
fStart = start;
fEnd = end;
fCDIVariable = cdiVariable;

View file

@ -15,7 +15,7 @@ import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable;
import org.eclipse.cdt.debug.core.model.ICDebugElementStatus;
import org.eclipse.cdt.debug.core.model.ICExpressionEvaluator;
import org.eclipse.cdt.debug.core.model.ICStackFrame;
import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IVariable;
@ -30,11 +30,6 @@ public class CArrayPartitionValue extends AbstractCValue {
*/
private ICDIVariable fCDIVariable;
/**
* Parent variable.
*/
private AbstractCVariable fParent = null;
/**
* List of child variables.
*/
@ -48,9 +43,8 @@ public class CArrayPartitionValue extends AbstractCValue {
* Constructor for CArrayPartitionValue.
*/
public CArrayPartitionValue( AbstractCVariable parent, ICDIVariable cdiVariable, int start, int end ) {
super( (CDebugTarget)parent.getDebugTarget() );
super( parent );
fCDIVariable = cdiVariable;
fParent = parent;
fStart = start;
fEnd = end;
}
@ -134,30 +128,23 @@ public class CArrayPartitionValue extends AbstractCValue {
}
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.debug.core.model.ICValue#computeDetail()
*/
public String evaluateAsExpression() {
ICExpressionEvaluator ee = (ICExpressionEvaluator)getDebugTarget().getAdapter( ICExpressionEvaluator.class );
String valueString = null;
if ( ee != null && ee.canEvaluate() ) {
try {
if ( getParentVariable() != null )
valueString = ee.evaluateExpressionToString( getParentVariable().getExpressionString() );
}
catch( DebugException e ) {
valueString = e.getMessage();
AbstractCVariable parent = getParentVariable();
if ( parent != null ) {
ICStackFrame frame = parent.getStackFrame();
if ( frame != null && frame.canEvaluate() ) {
try {
valueString = frame.evaluateExpressionToString( parent.getExpressionString() );
}
catch( DebugException e ) {
valueString = e.getMessage();
}
}
}
return valueString;
}
public AbstractCVariable getParentVariable() {
return fParent;
}
protected ICDIVariable getCDIVariable() {
return fCDIVariable;
}

View file

@ -68,7 +68,6 @@ import org.eclipse.cdt.debug.core.model.ICBreakpoint;
import org.eclipse.cdt.debug.core.model.ICDebugElement;
import org.eclipse.cdt.debug.core.model.ICDebugElementStatus;
import org.eclipse.cdt.debug.core.model.ICDebugTarget;
import org.eclipse.cdt.debug.core.model.ICExpressionEvaluator;
import org.eclipse.cdt.debug.core.model.ICLineBreakpoint;
import org.eclipse.cdt.debug.core.model.ICSharedLibrary;
import org.eclipse.cdt.debug.core.model.ICSignal;
@ -760,8 +759,7 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv
* @see org.eclipse.debug.core.model.IMemoryBlockRetrieval#getMemoryBlock(long, long)
*/
public IMemoryBlock getMemoryBlock( long startAddress, long length ) throws DebugException {
//TODO:IPF_TODO look into implementation
throw new RuntimeException("Method getMemoryBlock should not be called from CDT");
return null;
}
/* (non-Javadoc)
@ -819,8 +817,6 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv
return this;
if ( adapter.equals( ICDITarget.class ) )
return fCDITarget;
if ( adapter.equals( ICExpressionEvaluator.class ) )
return this;
if ( adapter.equals( ICMemoryManager.class ) )
return getMemoryManager();
if ( adapter.equals( IDebuggerProcessSupport.class ) )
@ -1288,26 +1284,6 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv
return getConfiguration().supportsExpressionEvaluation();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICExpressionEvaluator#evaluateExpressionToString(java.lang.String)
*/
public String evaluateExpressionToString( String expression ) throws DebugException {
try {
return getCDITarget().evaluateExpressionToString( expression );
}
catch( CDIException e ) {
targetRequestFailed( e.getMessage(), null );
}
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICExpressionEvaluator#canEvaluate()
*/
public boolean canEvaluate() {
return supportsExpressionEvaluation() && isSuspended();
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.IExpressionListener#expressionAdded(org.eclipse.debug.core.model.IExpression)
*/
@ -1503,7 +1479,7 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.IRunToAddress#canRunToAddress(long)
* @see org.eclipse.cdt.debug.core.model.IRunToAddress#canRunToAddress(org.eclipse.cdt.core.IAddress)
*/
public boolean canRunToAddress( IAddress address ) {
// for now
@ -1511,7 +1487,7 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.IRunToAddress#runToAddress(long, boolean)
* @see org.eclipse.cdt.debug.core.model.IRunToAddress#runToAddress(org.eclipse.cdt.core.IAddress, boolean)
*/
public void runToAddress( IAddress address, boolean skipBreakpoints ) throws DebugException {
if ( !canRunToAddress( address ) )
@ -1607,7 +1583,7 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.IJumpToAddress#canJumpToAddress(long)
* @see org.eclipse.cdt.debug.core.model.IJumpToAddress#canJumpToAddress(org.eclipse.cdt.core.IAddress)
*/
public boolean canJumpToAddress( IAddress address ) {
// check if supports jump to address
@ -1615,7 +1591,7 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.IJumpToAddress#jumpToAddress(long)
* @see org.eclipse.cdt.debug.core.model.IJumpToAddress#jumpToAddress(org.eclipse.cdt.core.IAddress)
*/
public void jumpToAddress( IAddress address ) throws DebugException {
if ( !canJumpToAddress( address ) )
@ -1846,20 +1822,15 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv
return false;
}
public IAddressFactory getAddressFactory()
{
if ( fAddressFactory == null )
{
if ( getExecFile() != null && CoreModel.getDefault().isBinary( getExecFile() ) )
{
ICElement cFile = CCorePlugin.getDefault().getCoreModel().create( getExecFile() );
if ( cFile instanceof IBinary )
{
fAddressFactory = ((IBinary)cFile).getAddressFactory();
}
}
}
return fAddressFactory;
}
}
public IAddressFactory getAddressFactory() {
if ( fAddressFactory == null ) {
if ( getExecFile() != null && CoreModel.getDefault().isBinary( getExecFile() ) ) {
ICElement cFile = CCorePlugin.getDefault().getCoreModel().create( getExecFile() );
if ( cFile instanceof IBinary ) {
fAddressFactory = ((IBinary)cFile).getAddressFactory();
}
}
}
return fAddressFactory;
}
}

View file

@ -288,8 +288,7 @@ public class CFormattedMemoryBlock extends CDebugElement
*/
public long getStartAddress()
{
//IPF_TODO look into implementation
throw new RuntimeException("Method IMemoryBlock.getStartAddress shoud not be called in CDT debug");
return 0;
}
public IAddress getRealStartAddress()
@ -301,6 +300,7 @@ public class CFormattedMemoryBlock extends CDebugElement
}
return factory.getZero();
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IMemoryBlock#getLength()
*/

View file

@ -655,4 +655,25 @@ public class CStackFrame extends CDebugElement implements ICStackFrame, IRestart
return e.getLocalizedMessage();
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICStackFrame#evaluateExpressionToString(java.lang.String)
*/
public String evaluateExpressionToString( String expression ) throws DebugException {
try {
return getCDITarget().evaluateExpressionToString( expression );
}
catch( CDIException e ) {
targetRequestFailed( e.getMessage(), null );
}
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICStackFrame#canEvaluate()
*/
public boolean canEvaluate() {
CDebugTarget target = ((CDebugTarget)getDebugTarget());
return target.supportsExpressionEvaluation() && target.isSuspended();
}
}

View file

@ -37,6 +37,7 @@ import org.eclipse.cdt.debug.core.cdi.model.ICDIStackFrame;
import org.eclipse.cdt.debug.core.cdi.model.ICDIThread;
import org.eclipse.cdt.debug.core.model.CDebugElementState;
import org.eclipse.cdt.debug.core.model.ICDebugElementStatus;
import org.eclipse.cdt.debug.core.model.ICStackFrame;
import org.eclipse.cdt.debug.core.model.ICThread;
import org.eclipse.cdt.debug.core.model.IDummyStackFrame;
import org.eclipse.cdt.debug.core.model.IRestart;
@ -830,6 +831,14 @@ public class CThread extends CDebugElement implements ICThread, IRestart, IResum
return this;
if ( adapter.equals( CDebugElementState.class ) )
return this;
if ( adapter == ICStackFrame.class ) {
try {
return (ICStackFrame)getTopStackFrame();
}
catch( DebugException e ) {
// do nothing
}
}
return super.getAdapter( adapter );
}

View file

@ -34,7 +34,7 @@ import org.eclipse.cdt.debug.core.cdi.model.type.ICDIShortValue;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIWCharValue;
import org.eclipse.cdt.debug.core.model.CVariableFormat;
import org.eclipse.cdt.debug.core.model.ICDebugElementStatus;
import org.eclipse.cdt.debug.core.model.ICExpressionEvaluator;
import org.eclipse.cdt.debug.core.model.ICStackFrame;
import org.eclipse.cdt.debug.core.model.ICType;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IVariable;
@ -44,11 +44,6 @@ import org.eclipse.debug.core.model.IVariable;
*/
public class CValue extends AbstractCValue {
/**
* Parent variable.
*/
private CVariable fParent = null;
/**
* Cached value.
*/
@ -68,8 +63,7 @@ public class CValue extends AbstractCValue {
* Constructor for CValue.
*/
protected CValue( CVariable parent, ICDIValue cdiValue ) {
super( (CDebugTarget)parent.getDebugTarget() );
fParent = parent;
super( parent );
fCDIValue = cdiValue;
}
@ -77,8 +71,7 @@ public class CValue extends AbstractCValue {
* Constructor for CValue.
*/
protected CValue( CVariable parent, String message ) {
super( (CDebugTarget)parent.getDebugTarget() );
fParent = parent;
super( parent );
setStatus( ICDebugElementStatus.ERROR, message );
}
@ -196,10 +189,6 @@ public class CValue extends AbstractCValue {
}
}
public CVariable getParentVariable() {
return fParent;
}
private String processUnderlyingValue( ICDIValue cdiValue ) throws CDIException {
if ( cdiValue != null ) {
if ( cdiValue instanceof ICDICharValue )
@ -362,42 +351,41 @@ public class CValue extends AbstractCValue {
return null;
}
private String getPointerValueString( ICDIPointerValue value ) throws CDIException
{
//TODO:IPF_TODO Workaround to solve incorrect handling of structures referenced by pointers or references
private String getPointerValueString( ICDIPointerValue value ) throws CDIException {
//TODO:IPF_TODO Workaround to solve incorrect handling of structures referenced by pointers or references
IAddressFactory factory = ((CDebugTarget)getDebugTarget()).getAddressFactory();
IAddress address = factory.createAddress(value.pointerValue().toString());
if ( address == null )
return ""; //$NON-NLS-1$
CVariableFormat format = getParentVariable().getFormat();
if( CVariableFormat.NATURAL.equals( format ) ||
CVariableFormat.HEXADECIMAL.equals( format ) )
return address.toHexAddressString();
if( CVariableFormat.DECIMAL.equals( format ))
return address.toString();
IAddress address = factory.createAddress( value.pointerValue().toString() );
if ( address == null )
return ""; //$NON-NLS-1$
CVariableFormat format = getParentVariable().getFormat();
if ( CVariableFormat.NATURAL.equals( format ) || CVariableFormat.HEXADECIMAL.equals( format ) )
return address.toHexAddressString();
if ( CVariableFormat.DECIMAL.equals( format ) )
return address.toString();
return null;
}
private String getReferenceValueString( ICDIReferenceValue value ) throws CDIException
{
//NOTE: Reference should be displayed identically to address
//TODO:IPF_TODO Workaround to solve incoorect handling of structures referenced by pointers or references
private String getReferenceValueString( ICDIReferenceValue value ) throws CDIException {
//NOTE: Reference should be displayed identically to address
//TODO:IPF_TODO Workaround to solve incoorect handling of structures referenced by pointers or references
IAddressFactory factory = ((CDebugTarget)getDebugTarget()).getAddressFactory();
IAddress address = factory.createAddress( value.referenceValue().toString() );
if (address == null)
return ""; //$NON-NLS-1$
CVariableFormat format = getParentVariable().getFormat();
if( CVariableFormat.NATURAL.equals( format ) ||
CVariableFormat.HEXADECIMAL.equals( format ) )
return address.toHexAddressString();
if( CVariableFormat.DECIMAL.equals( format ))
return address.toString();
BigInteger refValue = value.referenceValue();
if ( refValue == null )
return ""; //$NON-NLS-1$
IAddress address = factory.createAddress( refValue.toString() );
if ( address == null )
return ""; //$NON-NLS-1$
CVariableFormat format = getParentVariable().getFormat();
if ( CVariableFormat.NATURAL.equals( format ) || CVariableFormat.HEXADECIMAL.equals( format ) )
return address.toHexAddressString();
if ( CVariableFormat.DECIMAL.equals( format ) )
return address.toString();
return null;
}
private String getWCharValueString( ICDIWCharValue value ) throws CDIException {
if ( getParentVariable() != null ) {
int size = getParentVariable().sizeof();
if ( getParentVariable() instanceof CVariable ) {
int size = ((CVariable)getParentVariable()).sizeof();
if ( size == 2 ) {
CVariableFormat format = getParentVariable().getFormat();
if ( CVariableFormat.NATURAL.equals( format ) || CVariableFormat.DECIMAL.equals( format ) ) {
@ -441,15 +429,17 @@ public class CValue extends AbstractCValue {
* @see org.eclipse.cdt.debug.core.model.ICValue#evaluateAsExpression()
*/
public String evaluateAsExpression() {
ICExpressionEvaluator ee = (ICExpressionEvaluator)getDebugTarget().getAdapter( ICExpressionEvaluator.class );
String valueString = null;
if ( ee != null && ee.canEvaluate() ) {
try {
if ( getParentVariable() != null )
valueString = ee.evaluateExpressionToString( getParentVariable().getExpressionString() );
}
catch( DebugException e ) {
valueString = e.getMessage();
AbstractCVariable parent = getParentVariable();
if ( parent != null ) {
ICStackFrame frame = parent.getStackFrame();
if ( frame != null && frame.canEvaluate() ) {
try {
valueString = frame.evaluateExpressionToString( parent.getExpressionString() );
}
catch( DebugException e ) {
valueString = e.getMessage();
}
}
}
return valueString;

View file

@ -306,11 +306,6 @@ public class CVariable extends AbstractCVariable implements ICDIEventListener {
*/
private boolean fIsEnabled = true;
/**
* The parent object this variable is contained in.
*/
private CDebugElement fParent;
/**
* The original internal variable.
*/
@ -335,8 +330,7 @@ public class CVariable extends AbstractCVariable implements ICDIEventListener {
* Constructor for CVariable.
*/
protected CVariable( CDebugElement parent, ICDIVariableObject cdiVariableObject ) {
super( (CDebugTarget)parent.getDebugTarget() );
setParent( parent );
super( parent );
if ( cdiVariableObject != null ) {
fName = cdiVariableObject.getName();
createOriginal( cdiVariableObject );
@ -349,8 +343,7 @@ public class CVariable extends AbstractCVariable implements ICDIEventListener {
* Constructor for CVariable.
*/
protected CVariable( CDebugElement parent, ICDIVariableObject cdiVariableObject, String errorMessage ) {
super( (CDebugTarget)parent.getDebugTarget() );
setParent( parent );
super( parent );
if ( cdiVariableObject != null ) {
fName = cdiVariableObject.getName();
createOriginal( cdiVariableObject );
@ -701,14 +694,6 @@ public class CVariable extends AbstractCVariable implements ICDIEventListener {
fOriginal = original;
}
protected CDebugElement getParent() {
return fParent;
}
private void setParent( CDebugElement parent ) {
fParent = parent;
}
private InternalVariable getShadow() {
return fShadow;
}