diff --git a/debug/org.eclipse.cdt.debug.core/ChangeLog b/debug/org.eclipse.cdt.debug.core/ChangeLog index fc7c49d07de..dc991a17291 100644 --- a/debug/org.eclipse.cdt.debug.core/ChangeLog +++ b/debug/org.eclipse.cdt.debug.core/ChangeLog @@ -1,3 +1,18 @@ +2003-08-13 Mikhail Khodjaiants + * ICDIVariable.java: removed the 'isEditable' method + * ICDIVariableObject.java: added the 'isEditable', 'getQualifiedName' and 'sizeof' methods + * ICDIArrayValue.java: added the 'getVariables(int start, int length)' method + * ICType.java: added the 'isReference' method + * ICValue.java: added the 'dispose' method + * CArrayPartition.java + * CArrayPartitionValue.java + * CGlobalVariable.java + * CType.java + * CValue.java + * CValueFactory.java + * CVariable.java + Create 'var-objects' only for the requested array partitions. + 2003-08-07 Alain Magloire * ICDIVariableManager.java: diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/cdi/model/ICDIVariable.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/cdi/model/ICDIVariable.java index 575161a2468..d384c9e2e54 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/cdi/model/ICDIVariable.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/cdi/model/ICDIVariable.java @@ -26,12 +26,6 @@ public interface ICDIVariable extends ICDIVariableObject { */ ICDIValue getValue() throws CDIException; - /** - * Returns true if the value could be changed. - * @trhows CDIException if the method fails. - */ - boolean isEditable() throws CDIException; - /** * Attempts to set the value of this variable to the value of * the given expression. diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/cdi/model/ICDIVariableObject.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/cdi/model/ICDIVariableObject.java index 3b03691caa4..1ed5f597fac 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/cdi/model/ICDIVariableObject.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/cdi/model/ICDIVariableObject.java @@ -48,7 +48,26 @@ public interface ICDIVariableObject extends ICDIObject { String getTypeName() throws CDIException; /** - * @return + * Returns the size of this variable. + * + * @return the size of this variable + * @throws CDIException if this method fails. Reasons include: */ int sizeof() throws CDIException; + + /** + * Returns true if the value of this variable could be changed. + * + * @return true if the value of this variable could be changed + * @throws CDIException if this method fails. Reasons include: + */ + boolean isEditable() throws CDIException; + + /** + * Returns the qualified name of this variable. + * + * @return the qualified name of this variable + * @throws CDIException if this method fails. Reasons include: + */ + String getQualifiedName() throws CDIException; } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/cdi/model/type/ICDIArrayValue.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/cdi/model/type/ICDIArrayValue.java index fd7682ebfdf..0848be85829 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/cdi/model/type/ICDIArrayValue.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/cdi/model/type/ICDIArrayValue.java @@ -5,6 +5,9 @@ */ package org.eclipse.cdt.debug.core.cdi.model.type; +import org.eclipse.cdt.debug.core.cdi.CDIException; +import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable; + /** * @@ -13,4 +16,5 @@ package org.eclipse.cdt.debug.core.cdi.model.type; * @since April 15, 2003 */ public interface ICDIArrayValue extends ICDIDerivedValue { + ICDIVariable[] getVariables(int index, int length) throws CDIException; } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICType.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICType.java index 782c002da55..c963d3e6ba2 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICType.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICType.java @@ -29,5 +29,7 @@ public interface ICType extends IAdaptable boolean isPointer(); + boolean isReference(); + void dispose(); } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICValue.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICValue.java index 48da065e6ba..32a1f3fe4a4 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICValue.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICValue.java @@ -17,4 +17,6 @@ import org.eclipse.debug.core.model.IValue; public interface ICValue extends IValue { String evaluateAsExpression(); + + void dispose(); } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CArrayPartition.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CArrayPartition.java index 1287814866e..727351b896a 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CArrayPartition.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CArrayPartition.java @@ -13,6 +13,8 @@ import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.event.ICDIEvent; import org.eclipse.cdt.debug.core.cdi.model.ICDIValue; import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable; +import org.eclipse.cdt.debug.core.cdi.model.type.ICDIArrayValue; +import org.eclipse.cdt.debug.core.model.ICType; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.model.IValue; @@ -28,7 +30,8 @@ public class CArrayPartition extends CVariable private int fStart; private int fEnd; - private List fCDIVariables; + private ICDIVariable fCDIVariable; + private ICType fType = null; /** * Cache of value. @@ -39,12 +42,12 @@ public class CArrayPartition extends CVariable * Constructor for CArrayPartition. * @param target */ - public CArrayPartition( CDebugElement parent, List cdiVariables, int start, int end ) + public CArrayPartition( CDebugElement parent, ICDIVariable cdiVariable, int start, int end ) { super( parent, null ); fStart = start; fEnd = end; - fCDIVariables = cdiVariables; + fCDIVariable = cdiVariable; } /* (non-Javadoc) @@ -91,38 +94,49 @@ public class CArrayPartition extends CVariable { if ( fArrayPartitionValue == null ) { - fArrayPartitionValue = new CArrayPartitionValue( this, fCDIVariables, getStart(), getEnd() ); + fArrayPartitionValue = new CArrayPartitionValue( this, fCDIVariable, getStart(), getEnd() ); } return fArrayPartitionValue; } - static public List splitArray( CDebugElement parent, List cdiVars, int start, int end ) + static public List splitArray( CDebugElement parent, ICDIVariable cdiVariable, int start, int end ) throws DebugException { ArrayList children = new ArrayList(); + int len = end - start + 1; int perSlot = 1; - int len = end - start; - while( perSlot * SLOT_SIZE < len ) + while( len > perSlot * SLOT_SIZE ) { - perSlot = perSlot * SLOT_SIZE; + perSlot *= SLOT_SIZE; } - - while( start <= end ) + if ( perSlot == 1 ) { - if ( start + perSlot > end ) + try { - perSlot = end - start + 1; + ICDIValue value = cdiVariable.getValue(); + if ( value instanceof ICDIArrayValue ) + { + ICDIVariable[] cdiVars = ((ICDIArrayValue)value).getVariables( start, len ); + for ( int i = 0; i < cdiVars.length; ++i ) + children.add( new CModificationVariable( parent, cdiVars[i] ) ); + } } - CVariable var = null; - if ( perSlot == 1 ) + catch( CDIException e ) { - var = new CModificationVariable( parent, (ICDIVariable)cdiVars.get( start ) ); + children.add( new CModificationVariable( parent, new CVariable.ErrorVariable( null, e ) ) ); } - else + } + else + { + int pos = start; + while( pos <= end ) { - var = new CArrayPartition( parent, cdiVars.subList( start, start + perSlot ), start, start + perSlot - 1 ); + if ( pos + perSlot > end ) + { + perSlot = end - pos + 1; + } + children.add( new CArrayPartition( parent, cdiVariable, pos, pos + perSlot - 1 ) ); + pos += perSlot; } - children.add( var ); - start += perSlot; } return children; } @@ -144,4 +158,32 @@ public class CArrayPartition extends CVariable { return false; } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.model.ICVariable#getType() + */ + public ICType getType() throws DebugException + { + if ( fType == null ) + { + try + { + if ( fCDIVariable != null && !(fCDIVariable instanceof ErrorVariable) ) + fType = new CType( fCDIVariable.getType() ); + } + catch (CDIException e) + { + requestFailed( "Type is not available.", e ); + } + } + return fType; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.model.ICVariable#hasChildren() + */ + public boolean hasChildren() + { + return true; + } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CArrayPartitionValue.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CArrayPartitionValue.java index fe41608bcc6..f70d536047a 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CArrayPartitionValue.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CArrayPartitionValue.java @@ -6,12 +6,12 @@ package org.eclipse.cdt.debug.internal.core.model; -import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable; +import org.eclipse.cdt.debug.core.model.ICExpressionEvaluator; import org.eclipse.cdt.debug.core.model.ICValue; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.model.IVariable; @@ -25,9 +25,9 @@ import org.eclipse.debug.core.model.IVariable; public class CArrayPartitionValue extends CDebugElement implements ICValue { /** - * The underlying CDI variables. + * The underlying CDI variable. */ - private List fCDIVariables; + private ICDIVariable fCDIVariable; /** * Parent variable. @@ -47,10 +47,10 @@ public class CArrayPartitionValue extends CDebugElement implements ICValue * Constructor for CArrayPartitionValue. * @param target */ - public CArrayPartitionValue( CVariable parent, List cdiVariables, int start, int end ) + public CArrayPartitionValue( CVariable parent, ICDIVariable cdiVariable, int start, int end ) { super( (CDebugTarget)parent.getDebugTarget() ); - fCDIVariables = cdiVariables; + fCDIVariable = cdiVariable; fParent = parent; fStart = start; fEnd = end; @@ -85,15 +85,19 @@ public class CArrayPartitionValue extends CDebugElement implements ICValue */ public IVariable[] getVariables() throws DebugException { - if ( fVariables.isEmpty() ) + List list = getVariables0(); + return (IVariable[])list.toArray( new IVariable[list.size()] ); + } + + protected synchronized List getVariables0() throws DebugException + { + if ( !isAllocated() || !hasVariables() ) + return Collections.EMPTY_LIST; + if ( fVariables.size() == 0 ) { - fVariables = new ArrayList( getEnd() - getStart() + 1 ); - for ( int i = getStart(); i <= getEnd(); ++i ) - { - fVariables.add( new CModificationVariable( this, (ICDIVariable)fCDIVariables.get( i - getStart() ) ) ); - } + fVariables = CArrayPartition.splitArray( this, getCDIVariable(), getStart(), getEnd() ); } - return (IVariable[])fVariables.toArray( new IVariable[fVariables.size()] ); + return fVariables; } /* (non-Javadoc) @@ -128,7 +132,21 @@ public class CArrayPartitionValue extends CDebugElement implements ICValue */ public String evaluateAsExpression() { - return null; + ICExpressionEvaluator ee = (ICExpressionEvaluator)getDebugTarget().getAdapter( ICExpressionEvaluator.class ); + String valueString = null; + if ( ee != null && ee.canEvaluate() ) + { + try + { + if ( getParentVariable() != null && !getParentVariable().isAccessSpecifier() ) + valueString = ee.evaluateExpressionToString( getParentVariable().getQualifiedName() ); + } + catch( DebugException e ) + { + valueString = e.getMessage(); + } + } + return valueString; } public CVariable getParentVariable() @@ -136,27 +154,17 @@ public class CArrayPartitionValue extends CDebugElement implements ICValue return fParent; } - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICValue#isNaN() - */ - public boolean isNaN() + protected ICDIVariable getCDIVariable() { - return false; + return fCDIVariable; } - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICValue#isNegativeInfinity() - */ - public boolean isNegativeInfinity() + public void dispose() { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICValue#isPositiveInfinity() - */ - public boolean isPositiveInfinity() - { - return false; + Iterator it = fVariables.iterator(); + while( it.hasNext() ) + { + ((CVariable)it.next()).dispose(); + } } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CGlobalVariable.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CGlobalVariable.java index 1a5bb21b012..6902c8e6bb9 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CGlobalVariable.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CGlobalVariable.java @@ -1,10 +1,13 @@ package org.eclipse.cdt.debug.internal.core.model; import org.eclipse.cdt.debug.core.CDebugCorePlugin; +import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.event.ICDIEvent; import org.eclipse.cdt.debug.core.cdi.event.ICDIResumedEvent; import org.eclipse.cdt.debug.core.cdi.model.ICDIObject; +import org.eclipse.cdt.debug.core.cdi.model.ICDIValue; import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable; +import org.eclipse.cdt.debug.core.cdi.model.type.ICDIArrayValue; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.model.IValue; @@ -36,7 +39,24 @@ public class CGlobalVariable extends CModificationVariable { if ( fValue == null ) { - fValue = CValueFactory.createGlobalValue( this, getCurrentValue() ); + ICDIValue cdiValue = getCurrentValue(); + if ( cdiValue instanceof ICDIArrayValue ) + { + ICDIVariable var = null; + try + { + var = getCDIVariable(); + } + catch( CDIException e ) + { + requestFailed( "", e ); + } + int[] dims = getType().getArrayDimensions(); + if ( dims.length > 0 && dims[0] > 0 ) + fValue = CValueFactory.createArrayValue( this, var, 0, dims.length - 1 ); + } + else + fValue = CValueFactory.createGlobalValue( this, getCurrentValue() ); } return fValue; } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CType.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CType.java index 8f7d0751996..f41cebef198 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CType.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CType.java @@ -11,6 +11,7 @@ import org.eclipse.cdt.debug.core.cdi.model.type.ICDICharType; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIDerivedType; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIFloatingPointType; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIPointerType; +import org.eclipse.cdt.debug.core.cdi.model.type.ICDIReferenceType; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIStructType; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIType; import org.eclipse.cdt.debug.core.model.ICType; @@ -109,6 +110,14 @@ public class CType implements ICType return ( getCDIType() instanceof ICDIPointerType ); } + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.model.ICType#isReference() + */ + public boolean isReference() + { + return ( getCDIType() instanceof ICDIReferenceType ); + } + /* (non-Javadoc) * @see org.eclipse.cdt.debug.core.model.type.ICType#isStructure() */ @@ -126,4 +135,13 @@ public class CType implements ICType { fCDIType = type; } + + protected boolean hasChildren() + { + ICDIType type = getCDIType(); + if ( type instanceof ICDIStructType || type instanceof ICDIArrayType || + type instanceof ICDIPointerType || type instanceof ICDIReferenceType ) + return true; + return false; + } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValue.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValue.java index 1de7873b2ab..520b224a5f9 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValue.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValue.java @@ -27,6 +27,7 @@ import org.eclipse.cdt.debug.core.cdi.model.type.ICDILongValue; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIPointerValue; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIReferenceValue; 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.ICDebugElementErrorStatus; import org.eclipse.cdt.debug.core.model.ICExpressionEvaluator; import org.eclipse.cdt.debug.core.model.ICValue; @@ -77,19 +78,7 @@ public class CValue extends CDebugElement implements ICValue */ public String getReferenceTypeName() throws DebugException { - String typeName = null; - try - { - if ( getUnderlyingValue() != null ) - { - typeName = getUnderlyingValue().getTypeName(); - } - } - catch( CDIException e ) - { - logError( e ); - } - return typeName; + return ( getParentVariable() != null ) ? getParentVariable().getReferenceTypeName() : null; } /* (non-Javadoc) @@ -136,18 +125,12 @@ public class CValue extends CDebugElement implements ICValue { try { - List vars = getCDIVariables(); - - if ( vars.size() > 1 ) - fVariables = CArrayPartition.splitArray( this, vars, 0, vars.size() - 1 ); - else + List vars = getCDIVariables(); + fVariables = new ArrayList( vars.size() ); + Iterator it = vars.iterator(); + while( it.hasNext() ) { - fVariables = new ArrayList( vars.size() ); - Iterator it = vars.iterator(); - while( it.hasNext() ) - { - fVariables.add( new CModificationVariable( this, (ICDIVariable)it.next() ) ); - } + fVariables.add( new CModificationVariable( this, (ICDIVariable)it.next() ) ); } } catch( DebugException e ) @@ -208,42 +191,6 @@ public class CValue extends CDebugElement implements ICValue return Arrays.asList( vars ); } - protected String processCDIValue( String cdiValue ) - { - String result = null; - if ( cdiValue != null ) - { - result = cdiValue.trim(); - if ( result.startsWith( "@" ) ) // Reference - { - int end = result.indexOf( ':' ); - if ( end == -1 ) - end = result.length(); - result = result.substring( 1, end ); - } - else if ( result.startsWith( "0x" ) ) - { - int end = result.indexOf( ' ' ); - if ( end == -1 ) - end = result.length(); - result = result.substring( 0, end ); - } - else if ( result.endsWith( "\'" ) ) - { - int start = result.indexOf( '\'' ); - if ( start != -1 && result.length() - start == 3 ) - { - result = result.substring( start ); - } - else - { - result = null; - } - } - } - return result; - } - public synchronized void setChanged( boolean changed ) throws DebugException { if ( changed ) @@ -257,7 +204,7 @@ public class CValue extends CDebugElement implements ICValue } } - protected void dispose() + public void dispose() { Iterator it = fVariables.iterator(); while( it.hasNext() ) @@ -293,6 +240,8 @@ public class CValue extends CDebugElement implements ICValue return getPointerValueString( (ICDIPointerValue)cdiValue ); else if ( cdiValue instanceof ICDIReferenceValue ) return getReferenceValueString( (ICDIReferenceValue)cdiValue ); + else if ( cdiValue instanceof ICDIWCharValue ) + return getWCharValueString( (ICDIWCharValue)cdiValue ); else return cdiValue.getValueString(); } @@ -501,6 +450,47 @@ public class CValue extends CDebugElement implements ICValue return null; } + private String getWCharValueString( ICDIWCharValue value ) throws CDIException + { + if ( getParentVariable() != null ) + { + int size = getParentVariable().sizeof(); + if ( size == 16 ) + { + switch( getParentVariable().getFormat() ) + { + case ICDIFormat.NATURAL: + case ICDIFormat.DECIMAL: + return ( isUnsigned() ) ? Integer.toString( value.intValue() ) : Short.toString( value.shortValue() ); + case ICDIFormat.HEXADECIMAL: + { + StringBuffer sb = new StringBuffer( "0x" ); + String stringValue = Integer.toHexString( ( isUnsigned() ) ? value.intValue() : value.shortValue() ); + sb.append( ( stringValue.length() > 4 ) ? stringValue.substring( stringValue.length() - 4 ) : stringValue ); + return sb.toString(); + } + } + } + if ( size == 32 ) + { + switch( getParentVariable().getFormat() ) + { + case ICDIFormat.NATURAL: + case ICDIFormat.DECIMAL: + return ( isUnsigned() ) ? Long.toString( value.longValue() ) : Integer.toString( value.intValue() ); + case ICDIFormat.HEXADECIMAL: + { + StringBuffer sb = new StringBuffer( "0x" ); + String stringValue = ( isUnsigned() ) ? Long.toHexString( value.longValue() ) : Integer.toHexString( value.intValue() ); + sb.append( ( stringValue.length() > 8 ) ? stringValue.substring( stringValue.length() - 8 ) : stringValue ); + return sb.toString(); + } + } + } + } + return value.getValueString(); + } + private boolean isUnsigned() { boolean result = false; diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValueFactory.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValueFactory.java index 2a9555b71a6..87b35c111aa 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValueFactory.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValueFactory.java @@ -7,6 +7,7 @@ package org.eclipse.cdt.debug.internal.core.model; import org.eclipse.cdt.debug.core.cdi.model.ICDIValue; +import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable; import org.eclipse.debug.core.DebugException; /** @@ -22,6 +23,11 @@ public class CValueFactory return new CValue( parent, cdiValue ); } + static public CArrayPartitionValue createArrayValue( CVariable parent, ICDIVariable cdiVariable, int start, int end ) throws DebugException + { + return new CArrayPartitionValue( parent, cdiVariable, start, end ); + } + static public CValue createGlobalValue( CVariable parent, ICDIValue cdiValue ) throws DebugException { return new CGlobalValue( parent, cdiValue ); diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CVariable.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CVariable.java index 846fb15e46f..16b75b754b6 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CVariable.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CVariable.java @@ -6,7 +6,6 @@ package org.eclipse.cdt.debug.internal.core.model; import java.text.MessageFormat; -import java.util.LinkedList; import org.eclipse.cdt.debug.core.CDebugCorePlugin; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; @@ -157,6 +156,14 @@ public abstract class CVariable extends CDebugElement { return 0; } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariableObject#getQualifiedName() + */ + public String getQualifiedName() throws CDIException + { + return ( fVariableObject != null ) ? fVariableObject.getQualifiedName() : null; + } } class InternalVariable @@ -206,7 +213,7 @@ public abstract class CVariable extends CDebugElement if ( fType == null ) { ICDIVariable var = getCDIVariable(); - if ( var != null ) + if ( var != null && !(var instanceof ErrorVariable) ) fType = new CType( var.getType() ); } return fType; @@ -216,13 +223,19 @@ public abstract class CVariable extends CDebugElement { if ( fEditable == null ) { - ICDIVariable var = getCDIVariable(); - if ( var != null ) - fEditable = new Boolean( var.isEditable() ); + ICDIVariableObject varObject = getCDIVariableObject(); + if ( varObject != null && !(varObject instanceof ErrorVariable) ) + fEditable = new Boolean( varObject.isEditable() ); } return ( fEditable != null ) ? fEditable.booleanValue() : false; } + protected boolean hasChildren() throws CDIException + { + CType type = (CType)getType(); + return ( type != null ) ? type.hasChildren() : false; + } + private void setCDIVariable( ICDIVariable variable ) { fCDIVariable = variable; @@ -261,6 +274,26 @@ public abstract class CVariable extends CDebugElement { return ( fCDIVariable != null ) ? fCDIVariable.equals( cdiVar ) : false; } + + protected int sizeof() + { + if ( getCDIVariableObject() != null ) + { + try + { + return getCDIVariableObject().sizeof(); + } + catch( CDIException e ) + { + } + } + return 0; + } + + protected String getQualifiedName() throws CDIException + { + return ( fCDIVariableObject != null ) ? fCDIVariableObject.getQualifiedName() : null; + } } /** @@ -281,7 +314,7 @@ public abstract class CVariable extends CDebugElement /** * Cache of current value - see #getValue(). */ - protected CValue fValue; + protected ICValue fValue; /** * The name of this variable. @@ -368,6 +401,9 @@ public abstract class CVariable extends CDebugElement fIsEnabled = !enableVariableBookkeeping(); fOriginal = createOriginal( cdiVariableObject ); fShadow = null; + if ( cdiVariableObject instanceof ErrorVariable ) + setStatus( ICDebugElementErrorStatus.ERROR, + MessageFormat.format( "not available: {0}", new String[] { ((ErrorVariable)cdiVariableObject).getException().getMessage() } ) ); fFormat = CDebugCorePlugin.getDefault().getPluginPreferences().getInt( ICDebugConstants.PREF_DEFAULT_VARIABLE_FORMAT ); getCDISession().getEventManager().addEventListener( this ); } @@ -390,9 +426,27 @@ public abstract class CVariable extends CDebugElement return fDisabledValue; if ( fValue == null ) { - ICDIValue cdiValue = getCurrentValue(); - if ( cdiValue != null ) - fValue = CValueFactory.createValue( this, cdiValue ); + if ( getType() != null && getType().isArray() ) + { + ICDIVariable var = null; + try + { + var = getInternalVariable().getCDIVariable(); + } + catch( CDIException e ) + { + requestFailed( "", e ); + } + int[] dims = getType().getArrayDimensions(); + if ( dims.length > 0 && dims[0] > 0 ) + fValue = CValueFactory.createArrayValue( this, var, 0, dims[0] - 1 ); + } + else + { + ICDIValue cdiValue = getCurrentValue(); + if ( cdiValue != null ) + fValue = CValueFactory.createValue( this, cdiValue ); + } } return fValue; } @@ -485,14 +539,14 @@ public abstract class CVariable extends CDebugElement */ protected ICDIValue getLastKnownValue() { - return ( fValue != null ) ? fValue.getUnderlyingValue() : null; + return ( fValue instanceof CValue ) ? ((CValue)fValue).getUnderlyingValue() : null; } protected void dispose() { if ( fValue != null ) { - ((CValue)fValue).dispose(); + fValue.dispose(); } getCDISession().getEventManager().removeEventListener( this ); if ( getShadow() != null ) @@ -822,15 +876,20 @@ public abstract class CVariable extends CDebugElement */ public boolean hasChildren() { + if ( !isEnabled() ) + return false; + boolean result = false; try { - return ( getValue() != null && getValue().hasVariables() ); + InternalVariable var = getInternalVariable(); + if ( var != null ) + result = var.hasChildren(); } - catch( DebugException e ) + catch( CDIException e ) { logError( e ); } - return false; + return result; } /* (non-Javadoc) @@ -858,45 +917,14 @@ public abstract class CVariable extends CDebugElement { if ( fQualifiedName == null ) { - LinkedList list = new LinkedList(); - list.add( this ); - CVariable var = getParentVariable(); - while( var != null ) + try { - if ( !( var.getType().isArray() ) && !( var instanceof CArrayPartition ) && !var.isAccessSpecifier() ) - list.addFirst( var ); - var = var.getParentVariable(); + fQualifiedName = getInternalVariable().getQualifiedName(); } - StringBuffer sb = new StringBuffer(); - CVariable[] vars = (CVariable[])list.toArray( new CVariable[list.size()] ); - for ( int i = 0; i < vars.length; ++i ) + catch( CDIException e ) { - sb.insert( 0, '(' ); - if ( i > 0 ) - { - if ( vars[i - 1].getType().isPointer() ) - { - if ( vars[i].getName().charAt( 0 ) == '*' && vars[i-1].getName().equals( vars[i].getName().substring( 1 ) ) ) - { - sb.insert( 0, '*' ); - } - else - { - sb.append( "->" ); - sb.append( vars[i].getName() ); - } - } - else - { - sb.append( '.' ); - sb.append( vars[i].getName() ); - } - } - else - sb.append( vars[i].getName() ); - sb.append( ')' ); + requestFailed( "Qualified name is not available.", e ); } - fQualifiedName = sb.toString(); } return fQualifiedName; } @@ -968,7 +996,7 @@ public abstract class CVariable extends CDebugElement { if ( fValue != null ) { - ((CValue)fValue).dispose(); + fValue.dispose(); fValue = null; } } @@ -1014,4 +1042,9 @@ public abstract class CVariable extends CDebugElement { return ( getShadow() != null ) ? getShadow() : fOriginal; } + + protected int sizeof() + { + return getInternalVariable().sizeof(); + } }