1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-02 05:45:58 +02:00

Moved some methods from ICDIVariable to ICDIVariableObject.

Create 'var-objects' only for the requested array partitions.
This commit is contained in:
Mikhail Khodjaiants 2003-08-13 18:19:53 +00:00
parent df11a294b8
commit 0627136ff0
13 changed files with 322 additions and 169 deletions

View file

@ -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 2003-08-07 Alain Magloire
* ICDIVariableManager.java: * ICDIVariableManager.java:

View file

@ -26,12 +26,6 @@ public interface ICDIVariable extends ICDIVariableObject {
*/ */
ICDIValue getValue() throws CDIException; 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 * Attempts to set the value of this variable to the value of
* the given expression. * the given expression.

View file

@ -48,7 +48,26 @@ public interface ICDIVariableObject extends ICDIObject {
String getTypeName() throws CDIException; 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; 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;
} }

View file

@ -5,6 +5,9 @@
*/ */
package org.eclipse.cdt.debug.core.cdi.model.type; 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 * @since April 15, 2003
*/ */
public interface ICDIArrayValue extends ICDIDerivedValue { public interface ICDIArrayValue extends ICDIDerivedValue {
ICDIVariable[] getVariables(int index, int length) throws CDIException;
} }

View file

@ -29,5 +29,7 @@ public interface ICType extends IAdaptable
boolean isPointer(); boolean isPointer();
boolean isReference();
void dispose(); void dispose();
} }

View file

@ -17,4 +17,6 @@ import org.eclipse.debug.core.model.IValue;
public interface ICValue extends IValue public interface ICValue extends IValue
{ {
String evaluateAsExpression(); String evaluateAsExpression();
void dispose();
} }

View file

@ -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.event.ICDIEvent;
import org.eclipse.cdt.debug.core.cdi.model.ICDIValue; 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.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.DebugException;
import org.eclipse.debug.core.model.IValue; import org.eclipse.debug.core.model.IValue;
@ -28,7 +30,8 @@ public class CArrayPartition extends CVariable
private int fStart; private int fStart;
private int fEnd; private int fEnd;
private List fCDIVariables; private ICDIVariable fCDIVariable;
private ICType fType = null;
/** /**
* Cache of value. * Cache of value.
@ -39,12 +42,12 @@ public class CArrayPartition extends CVariable
* Constructor for CArrayPartition. * Constructor for CArrayPartition.
* @param target * @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 ); super( parent, null );
fStart = start; fStart = start;
fEnd = end; fEnd = end;
fCDIVariables = cdiVariables; fCDIVariable = cdiVariable;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -91,38 +94,49 @@ public class CArrayPartition extends CVariable
{ {
if ( fArrayPartitionValue == null ) if ( fArrayPartitionValue == null )
{ {
fArrayPartitionValue = new CArrayPartitionValue( this, fCDIVariables, getStart(), getEnd() ); fArrayPartitionValue = new CArrayPartitionValue( this, fCDIVariable, getStart(), getEnd() );
} }
return fArrayPartitionValue; 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(); ArrayList children = new ArrayList();
int len = end - start + 1;
int perSlot = 1; int perSlot = 1;
int len = end - start; while( len > perSlot * SLOT_SIZE )
while( perSlot * SLOT_SIZE < len )
{ {
perSlot = perSlot * SLOT_SIZE; perSlot *= SLOT_SIZE;
} }
while( start <= end )
{
if ( start + perSlot > end )
{
perSlot = end - start + 1;
}
CVariable var = null;
if ( perSlot == 1 ) if ( perSlot == 1 )
{ {
var = new CModificationVariable( parent, (ICDIVariable)cdiVars.get( start ) ); try
{
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] ) );
}
}
catch( CDIException e )
{
children.add( new CModificationVariable( parent, new CVariable.ErrorVariable( null, e ) ) );
}
} }
else else
{ {
var = new CArrayPartition( parent, cdiVars.subList( start, start + perSlot ), start, start + perSlot - 1 ); int pos = start;
while( pos <= end )
{
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; return children;
} }
@ -144,4 +158,32 @@ public class CArrayPartition extends CVariable
{ {
return false; 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;
}
} }

View file

@ -6,12 +6,12 @@
package org.eclipse.cdt.debug.internal.core.model; package org.eclipse.cdt.debug.internal.core.model;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable; 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.cdt.debug.core.model.ICValue;
import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IVariable; 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 public class CArrayPartitionValue extends CDebugElement implements ICValue
{ {
/** /**
* The underlying CDI variables. * The underlying CDI variable.
*/ */
private List fCDIVariables; private ICDIVariable fCDIVariable;
/** /**
* Parent variable. * Parent variable.
@ -47,10 +47,10 @@ public class CArrayPartitionValue extends CDebugElement implements ICValue
* Constructor for CArrayPartitionValue. * Constructor for CArrayPartitionValue.
* @param target * @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() ); super( (CDebugTarget)parent.getDebugTarget() );
fCDIVariables = cdiVariables; fCDIVariable = cdiVariable;
fParent = parent; fParent = parent;
fStart = start; fStart = start;
fEnd = end; fEnd = end;
@ -85,15 +85,19 @@ public class CArrayPartitionValue extends CDebugElement implements ICValue
*/ */
public IVariable[] getVariables() throws DebugException public IVariable[] getVariables() throws DebugException
{ {
if ( fVariables.isEmpty() ) List list = getVariables0();
{ return (IVariable[])list.toArray( new IVariable[list.size()] );
fVariables = new ArrayList( getEnd() - getStart() + 1 );
for ( int i = getStart(); i <= getEnd(); ++i )
{
fVariables.add( new CModificationVariable( this, (ICDIVariable)fCDIVariables.get( i - getStart() ) ) );
} }
protected synchronized List getVariables0() throws DebugException
{
if ( !isAllocated() || !hasVariables() )
return Collections.EMPTY_LIST;
if ( fVariables.size() == 0 )
{
fVariables = CArrayPartition.splitArray( this, getCDIVariable(), getStart(), getEnd() );
} }
return (IVariable[])fVariables.toArray( new IVariable[fVariables.size()] ); return fVariables;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -128,7 +132,21 @@ public class CArrayPartitionValue extends CDebugElement implements ICValue
*/ */
public String evaluateAsExpression() 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() public CVariable getParentVariable()
@ -136,27 +154,17 @@ public class CArrayPartitionValue extends CDebugElement implements ICValue
return fParent; return fParent;
} }
/* (non-Javadoc) protected ICDIVariable getCDIVariable()
* @see org.eclipse.cdt.debug.core.model.ICValue#isNaN()
*/
public boolean isNaN()
{ {
return false; return fCDIVariable;
} }
/* (non-Javadoc) public void dispose()
* @see org.eclipse.cdt.debug.core.model.ICValue#isNegativeInfinity()
*/
public boolean isNegativeInfinity()
{ {
return false; Iterator it = fVariables.iterator();
} while( it.hasNext() )
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICValue#isPositiveInfinity()
*/
public boolean isPositiveInfinity()
{ {
return false; ((CVariable)it.next()).dispose();
}
} }
} }

View file

@ -1,10 +1,13 @@
package org.eclipse.cdt.debug.internal.core.model; package org.eclipse.cdt.debug.internal.core.model;
import org.eclipse.cdt.debug.core.CDebugCorePlugin; 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.ICDIEvent;
import org.eclipse.cdt.debug.core.cdi.event.ICDIResumedEvent; 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.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.ICDIVariable;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIArrayValue;
import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IValue; import org.eclipse.debug.core.model.IValue;
@ -36,6 +39,23 @@ public class CGlobalVariable extends CModificationVariable
{ {
if ( fValue == null ) if ( fValue == null )
{ {
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() ); fValue = CValueFactory.createGlobalValue( this, getCurrentValue() );
} }
return fValue; return fValue;

View file

@ -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.ICDIDerivedType;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIFloatingPointType; 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.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.ICDIStructType;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIType; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIType;
import org.eclipse.cdt.debug.core.model.ICType; import org.eclipse.cdt.debug.core.model.ICType;
@ -109,6 +110,14 @@ public class CType implements ICType
return ( getCDIType() instanceof ICDIPointerType ); return ( getCDIType() instanceof ICDIPointerType );
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICType#isReference()
*/
public boolean isReference()
{
return ( getCDIType() instanceof ICDIReferenceType );
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.type.ICType#isStructure() * @see org.eclipse.cdt.debug.core.model.type.ICType#isStructure()
*/ */
@ -126,4 +135,13 @@ public class CType implements ICType
{ {
fCDIType = type; 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;
}
} }

View file

@ -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.ICDIPointerValue;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIReferenceValue; 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.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.ICDebugElementErrorStatus;
import org.eclipse.cdt.debug.core.model.ICExpressionEvaluator; import org.eclipse.cdt.debug.core.model.ICExpressionEvaluator;
import org.eclipse.cdt.debug.core.model.ICValue; import org.eclipse.cdt.debug.core.model.ICValue;
@ -77,19 +78,7 @@ public class CValue extends CDebugElement implements ICValue
*/ */
public String getReferenceTypeName() throws DebugException public String getReferenceTypeName() throws DebugException
{ {
String typeName = null; return ( getParentVariable() != null ) ? getParentVariable().getReferenceTypeName() : null;
try
{
if ( getUnderlyingValue() != null )
{
typeName = getUnderlyingValue().getTypeName();
}
}
catch( CDIException e )
{
logError( e );
}
return typeName;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -137,11 +126,6 @@ public class CValue extends CDebugElement implements ICValue
try try
{ {
List vars = getCDIVariables(); List vars = getCDIVariables();
if ( vars.size() > 1 )
fVariables = CArrayPartition.splitArray( this, vars, 0, vars.size() - 1 );
else
{
fVariables = new ArrayList( vars.size() ); fVariables = new ArrayList( vars.size() );
Iterator it = vars.iterator(); Iterator it = vars.iterator();
while( it.hasNext() ) while( it.hasNext() )
@ -149,7 +133,6 @@ public class CValue extends CDebugElement implements ICValue
fVariables.add( new CModificationVariable( this, (ICDIVariable)it.next() ) ); fVariables.add( new CModificationVariable( this, (ICDIVariable)it.next() ) );
} }
} }
}
catch( DebugException e ) catch( DebugException e )
{ {
fVariables = new ArrayList( 1 ); fVariables = new ArrayList( 1 );
@ -208,42 +191,6 @@ public class CValue extends CDebugElement implements ICValue
return Arrays.asList( vars ); 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 public synchronized void setChanged( boolean changed ) throws DebugException
{ {
if ( changed ) if ( changed )
@ -257,7 +204,7 @@ public class CValue extends CDebugElement implements ICValue
} }
} }
protected void dispose() public void dispose()
{ {
Iterator it = fVariables.iterator(); Iterator it = fVariables.iterator();
while( it.hasNext() ) while( it.hasNext() )
@ -293,6 +240,8 @@ public class CValue extends CDebugElement implements ICValue
return getPointerValueString( (ICDIPointerValue)cdiValue ); return getPointerValueString( (ICDIPointerValue)cdiValue );
else if ( cdiValue instanceof ICDIReferenceValue ) else if ( cdiValue instanceof ICDIReferenceValue )
return getReferenceValueString( (ICDIReferenceValue)cdiValue ); return getReferenceValueString( (ICDIReferenceValue)cdiValue );
else if ( cdiValue instanceof ICDIWCharValue )
return getWCharValueString( (ICDIWCharValue)cdiValue );
else else
return cdiValue.getValueString(); return cdiValue.getValueString();
} }
@ -501,6 +450,47 @@ public class CValue extends CDebugElement implements ICValue
return null; 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() private boolean isUnsigned()
{ {
boolean result = false; boolean result = false;

View file

@ -7,6 +7,7 @@
package org.eclipse.cdt.debug.internal.core.model; 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.ICDIValue;
import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable;
import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugException;
/** /**
@ -22,6 +23,11 @@ public class CValueFactory
return new CValue( parent, cdiValue ); 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 static public CValue createGlobalValue( CVariable parent, ICDIValue cdiValue ) throws DebugException
{ {
return new CGlobalValue( parent, cdiValue ); return new CGlobalValue( parent, cdiValue );

View file

@ -6,7 +6,6 @@
package org.eclipse.cdt.debug.internal.core.model; package org.eclipse.cdt.debug.internal.core.model;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.LinkedList;
import org.eclipse.cdt.debug.core.CDebugCorePlugin; import org.eclipse.cdt.debug.core.CDebugCorePlugin;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
@ -157,6 +156,14 @@ public abstract class CVariable extends CDebugElement
{ {
return 0; 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 class InternalVariable
@ -206,7 +213,7 @@ public abstract class CVariable extends CDebugElement
if ( fType == null ) if ( fType == null )
{ {
ICDIVariable var = getCDIVariable(); ICDIVariable var = getCDIVariable();
if ( var != null ) if ( var != null && !(var instanceof ErrorVariable) )
fType = new CType( var.getType() ); fType = new CType( var.getType() );
} }
return fType; return fType;
@ -216,13 +223,19 @@ public abstract class CVariable extends CDebugElement
{ {
if ( fEditable == null ) if ( fEditable == null )
{ {
ICDIVariable var = getCDIVariable(); ICDIVariableObject varObject = getCDIVariableObject();
if ( var != null ) if ( varObject != null && !(varObject instanceof ErrorVariable) )
fEditable = new Boolean( var.isEditable() ); fEditable = new Boolean( varObject.isEditable() );
} }
return ( fEditable != null ) ? fEditable.booleanValue() : false; 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 ) private void setCDIVariable( ICDIVariable variable )
{ {
fCDIVariable = variable; fCDIVariable = variable;
@ -261,6 +274,26 @@ public abstract class CVariable extends CDebugElement
{ {
return ( fCDIVariable != null ) ? fCDIVariable.equals( cdiVar ) : false; 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(). * Cache of current value - see #getValue().
*/ */
protected CValue fValue; protected ICValue fValue;
/** /**
* The name of this variable. * The name of this variable.
@ -368,6 +401,9 @@ public abstract class CVariable extends CDebugElement
fIsEnabled = !enableVariableBookkeeping(); fIsEnabled = !enableVariableBookkeeping();
fOriginal = createOriginal( cdiVariableObject ); fOriginal = createOriginal( cdiVariableObject );
fShadow = null; 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 ); fFormat = CDebugCorePlugin.getDefault().getPluginPreferences().getInt( ICDebugConstants.PREF_DEFAULT_VARIABLE_FORMAT );
getCDISession().getEventManager().addEventListener( this ); getCDISession().getEventManager().addEventListener( this );
} }
@ -389,11 +425,29 @@ public abstract class CVariable extends CDebugElement
if ( !isEnabled() ) if ( !isEnabled() )
return fDisabledValue; return fDisabledValue;
if ( fValue == null ) if ( fValue == null )
{
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(); ICDIValue cdiValue = getCurrentValue();
if ( cdiValue != null ) if ( cdiValue != null )
fValue = CValueFactory.createValue( this, cdiValue ); fValue = CValueFactory.createValue( this, cdiValue );
} }
}
return fValue; return fValue;
} }
@ -485,14 +539,14 @@ public abstract class CVariable extends CDebugElement
*/ */
protected ICDIValue getLastKnownValue() protected ICDIValue getLastKnownValue()
{ {
return ( fValue != null ) ? fValue.getUnderlyingValue() : null; return ( fValue instanceof CValue ) ? ((CValue)fValue).getUnderlyingValue() : null;
} }
protected void dispose() protected void dispose()
{ {
if ( fValue != null ) if ( fValue != null )
{ {
((CValue)fValue).dispose(); fValue.dispose();
} }
getCDISession().getEventManager().removeEventListener( this ); getCDISession().getEventManager().removeEventListener( this );
if ( getShadow() != null ) if ( getShadow() != null )
@ -822,15 +876,20 @@ public abstract class CVariable extends CDebugElement
*/ */
public boolean hasChildren() public boolean hasChildren()
{ {
if ( !isEnabled() )
return false;
boolean result = false;
try try
{ {
return ( getValue() != null && getValue().hasVariables() ); InternalVariable var = getInternalVariable();
if ( var != null )
result = var.hasChildren();
} }
catch( DebugException e ) catch( CDIException e )
{ {
logError( e ); logError( e );
} }
return false; return result;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -858,45 +917,14 @@ public abstract class CVariable extends CDebugElement
{ {
if ( fQualifiedName == null ) if ( fQualifiedName == null )
{ {
LinkedList list = new LinkedList(); try
list.add( this );
CVariable var = getParentVariable();
while( var != null )
{ {
if ( !( var.getType().isArray() ) && !( var instanceof CArrayPartition ) && !var.isAccessSpecifier() ) fQualifiedName = getInternalVariable().getQualifiedName();
list.addFirst( var );
var = var.getParentVariable();
} }
StringBuffer sb = new StringBuffer(); catch( CDIException e )
CVariable[] vars = (CVariable[])list.toArray( new CVariable[list.size()] );
for ( int i = 0; i < vars.length; ++i )
{ {
sb.insert( 0, '(' ); requestFailed( "Qualified name is not available.", e );
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( ')' );
}
fQualifiedName = sb.toString();
} }
return fQualifiedName; return fQualifiedName;
} }
@ -968,7 +996,7 @@ public abstract class CVariable extends CDebugElement
{ {
if ( fValue != null ) if ( fValue != null )
{ {
((CValue)fValue).dispose(); fValue.dispose();
fValue = null; fValue = null;
} }
} }
@ -1014,4 +1042,9 @@ public abstract class CVariable extends CDebugElement
{ {
return ( getShadow() != null ) ? getShadow() : fOriginal; return ( getShadow() != null ) ? getShadow() : fOriginal;
} }
protected int sizeof()
{
return getInternalVariable().sizeof();
}
} }