Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Really Fixing Arrays

These patches contain the new implementation of the array variables partially based on the ideas of Chris Songer and Daniel Jacobowitz.
The basic idea is to create the var-objects only for requested array partitions and determine the size of array according to the array's type.
 
Mikhail Khodjaiants 
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.ui/ChangeLog,v
retrieving revision 1.176
diff -u -r1.176 ChangeLog
--- ChangeLog	30 Jul 2003 20:22:30 -0000	1.176
+++ ChangeLog	13 Aug 2003 18:15:52 -0000
@@ -1,3 +1,7 @@
+2003-08-13 Mikhail Khodjaiants
+	Display the proper image for reference types.
+	* CDTDebugModelPresentation.java
+
 2003-07-30 Mikhail Khodjaiants
 	Moved the 'getReferencedProject' method to 'CDebugUtils'. Added the cycle checking.
 	* SourceLookupBlock.java
Index: src/org/eclipse/cdt/debug/internal/ui/CDTDebugModelPresentation.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDTDebugModelPresentation.java,v
retrieving revision 1.69
diff -u -r1.69 CDTDebugModelPresentation.java
--- src/org/eclipse/cdt/debug/internal/ui/CDTDebugModelPresentation.java	29 Jul 2003 20:23:55 -0000	1.69
+++ src/org/eclipse/cdt/debug/internal/ui/CDTDebugModelPresentation.java	13 Aug 2003 18:15:58 -0000
@@ -894,12 +894,12 @@
 			{
 				// use default image
 			}
-			if ( type != null && ( type.isArray() || type.isStructure() ) )
-				return fDebugImageRegistry.get( ( ((ICVariable)element).isEnabled() ) ? 
-							CDebugImages.DESC_OBJS_VARIABLE_AGGREGATE : CDebugImages.DESC_OBJS_VARIABLE_AGGREGATE_DISABLED );
-			else if ( type != null && type.isPointer() )
+			if ( type != null && (type.isPointer() || type.isReference()) )
 				return fDebugImageRegistry.get( ( ((ICVariable)element).isEnabled() ) ?
 							CDebugImages.DESC_OBJS_VARIABLE_POINTER : CDebugImages.DESC_OBJS_VARIABLE_POINTER_DISABLED );
+			else if ( ((ICVariable)element).hasChildren() )
+				return fDebugImageRegistry.get( ( ((ICVariable)element).isEnabled() ) ? 
+							CDebugImages.DESC_OBJS_VARIABLE_AGGREGATE : CDebugImages.DESC_OBJS_VARIABLE_AGGREGATE_DISABLED );
 			else
 				return fDebugImageRegistry.get( ( ((ICVariable)element).isEnabled() ) ?
 							CDebugImages.DESC_OBJS_VARIABLE_SIMPLE : CDebugImages.DESC_OBJS_VARIABLE_SIMPLE_DISABLED );
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/ChangeLog,v
retrieving revision 1.230
diff -u -r1.230 ChangeLog
--- ChangeLog	8 Aug 2003 01:59:32 -0000	1.230
+++ ChangeLog	13 Aug 2003 18:15:18 -0000
@@ -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:
Index: src/org/eclipse/cdt/debug/core/cdi/model/ICDIVariable.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/cdi/model/ICDIVariable.java,v
retrieving revision 1.8
diff -u -r1.8 ICDIVariable.java
--- src/org/eclipse/cdt/debug/core/cdi/model/ICDIVariable.java	6 Aug 2003 19:51:58 -0000	1.8
+++ src/org/eclipse/cdt/debug/core/cdi/model/ICDIVariable.java	13 Aug 2003 18:15:21 -0000
@@ -27,12 +27,6 @@
 	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.
 	 * 
Index: src/org/eclipse/cdt/debug/core/cdi/model/ICDIVariableObject.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/cdi/model/ICDIVariableObject.java,v
retrieving revision 1.3
diff -u -r1.3 ICDIVariableObject.java
--- src/org/eclipse/cdt/debug/core/cdi/model/ICDIVariableObject.java	6 Aug 2003 20:18:33 -0000	1.3
+++ src/org/eclipse/cdt/debug/core/cdi/model/ICDIVariableObject.java	13 Aug 2003 18:15:21 -0000
@@ -48,7 +48,26 @@
 	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;
 }
Index: src/org/eclipse/cdt/debug/core/cdi/model/type/ICDIArrayValue.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/cdi/model/type/ICDIArrayValue.java,v
retrieving revision 1.1
diff -u -r1.1 ICDIArrayValue.java
--- src/org/eclipse/cdt/debug/core/cdi/model/type/ICDIArrayValue.java	23 May 2003 05:12:42 -0000	1.1
+++ src/org/eclipse/cdt/debug/core/cdi/model/type/ICDIArrayValue.java	13 Aug 2003 18:15:21 -0000
@@ -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 @@
  * @since April 15, 2003
  */
 public interface ICDIArrayValue extends ICDIDerivedValue {
+	ICDIVariable[] getVariables(int index, int length) throws CDIException;		
 }
Index: src/org/eclipse/cdt/debug/core/model/ICType.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICType.java,v
retrieving revision 1.1
diff -u -r1.1 ICType.java
--- src/org/eclipse/cdt/debug/core/model/ICType.java	10 Jun 2003 22:33:55 -0000	1.1
+++ src/org/eclipse/cdt/debug/core/model/ICType.java	13 Aug 2003 18:15:21 -0000
@@ -29,5 +29,7 @@
 
 	boolean isPointer();
 
+	boolean isReference();
+
 	void dispose();
 }
Index: src/org/eclipse/cdt/debug/core/model/ICValue.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICValue.java,v
retrieving revision 1.9
diff -u -r1.9 ICValue.java
--- src/org/eclipse/cdt/debug/core/model/ICValue.java	28 Jul 2003 19:59:26 -0000	1.9
+++ src/org/eclipse/cdt/debug/core/model/ICValue.java	13 Aug 2003 18:15:21 -0000
@@ -17,4 +17,6 @@
 public interface ICValue extends IValue
 {
 	String evaluateAsExpression();
+
+	void dispose();
 }
Index: src/org/eclipse/cdt/debug/internal/core/model/CArrayPartition.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CArrayPartition.java,v
retrieving revision 1.7
diff -u -r1.7 CArrayPartition.java
--- src/org/eclipse/cdt/debug/internal/core/model/CArrayPartition.java	20 Jun 2003 21:16:16 -0000	1.7
+++ src/org/eclipse/cdt/debug/internal/core/model/CArrayPartition.java	13 Aug 2003 18:15:22 -0000
@@ -13,6 +13,8 @@
 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 @@
 
 	private int fStart;
 	private int fEnd;
-	private List fCDIVariables;
+	private ICDIVariable fCDIVariable;
+	private ICType fType = null;
 
 	/**
 	 * Cache of value.
@@ -39,12 +42,12 @@
 	 * 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 @@
 	{
 		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;
 	}
@@ -143,5 +157,33 @@
 	public boolean canEnableDisable()
 	{
 		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;
 	}
 }
Index: src/org/eclipse/cdt/debug/internal/core/model/CArrayPartitionValue.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CArrayPartitionValue.java,v
retrieving revision 1.11
diff -u -r1.11 CArrayPartitionValue.java
--- src/org/eclipse/cdt/debug/internal/core/model/CArrayPartitionValue.java	11 Jun 2003 22:58:44 -0000	1.11
+++ src/org/eclipse/cdt/debug/internal/core/model/CArrayPartitionValue.java	13 Aug 2003 18:15:22 -0000
@@ -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 @@
 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 @@
 	 * 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 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 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 @@
 		return fParent;
 	}
 
-	/* (non-Javadoc)
-	 * @see org.eclipse.cdt.debug.core.model.ICValue#isNaN()
-	 */
-	public boolean isNaN()
-	{
-		return false;
-	}
-
-	/* (non-Javadoc)
-	 * @see org.eclipse.cdt.debug.core.model.ICValue#isNegativeInfinity()
-	 */
-	public boolean isNegativeInfinity()
+	protected ICDIVariable getCDIVariable()
 	{
-		return false;
+		return fCDIVariable;
 	}
 
-	/* (non-Javadoc)
-	 * @see org.eclipse.cdt.debug.core.model.ICValue#isPositiveInfinity()
-	 */
-	public boolean isPositiveInfinity()
+	public void dispose()
 	{
-		return false;
+		Iterator it = fVariables.iterator();
+		while( it.hasNext() )
+		{
+			((CVariable)it.next()).dispose();
+		}
 	}
 }
Index: src/org/eclipse/cdt/debug/internal/core/model/CGlobalVariable.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CGlobalVariable.java,v
retrieving revision 1.2
diff -u -r1.2 CGlobalVariable.java
--- src/org/eclipse/cdt/debug/internal/core/model/CGlobalVariable.java	2 Oct 2002 21:13:02 -0000	1.2
+++ src/org/eclipse/cdt/debug/internal/core/model/CGlobalVariable.java	13 Aug 2003 18:15:22 -0000
@@ -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 @@
 	{
 		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;
 	}
Index: src/org/eclipse/cdt/debug/internal/core/model/CType.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CType.java,v
retrieving revision 1.1
diff -u -r1.1 CType.java
--- src/org/eclipse/cdt/debug/internal/core/model/CType.java	10 Jun 2003 22:33:55 -0000	1.1
+++ src/org/eclipse/cdt/debug/internal/core/model/CType.java	13 Aug 2003 18:15:22 -0000
@@ -11,6 +11,7 @@
 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;
@@ -110,6 +111,14 @@
 	}
 
 	/* (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()
 	 */
 	public boolean isStructure()
@@ -125,5 +134,14 @@
 	protected void setCDIType( ICDIType 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;
 	}
 }
Index: src/org/eclipse/cdt/debug/internal/core/model/CValue.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValue.java,v
retrieving revision 1.34
diff -u -r1.34 CValue.java
--- src/org/eclipse/cdt/debug/internal/core/model/CValue.java	28 Jul 2003 19:59:26 -0000	1.34
+++ src/org/eclipse/cdt/debug/internal/core/model/CValue.java	13 Aug 2003 18:15:22 -0000
@@ -27,6 +27,7 @@
 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 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 @@
 		{
 			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 @@
 		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 @@
 		}
 	}
 
-	protected void dispose()
+	public void dispose()
 	{
 		Iterator it = fVariables.iterator();
 		while( it.hasNext() )
@@ -293,6 +240,8 @@
 				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();
 		}
@@ -499,6 +448,47 @@
 			}
 		}
 		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()
Index: src/org/eclipse/cdt/debug/internal/core/model/CValueFactory.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValueFactory.java,v
retrieving revision 1.6
diff -u -r1.6 CValueFactory.java
--- src/org/eclipse/cdt/debug/internal/core/model/CValueFactory.java	11 Jun 2003 22:58:44 -0000	1.6
+++ src/org/eclipse/cdt/debug/internal/core/model/CValueFactory.java	13 Aug 2003 18:15:22 -0000
@@ -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;
 
 /**
@@ -20,6 +21,11 @@
 	static public CValue createValue( CVariable parent, ICDIValue cdiValue ) throws DebugException
 	{
 		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
Index: src/org/eclipse/cdt/debug/internal/core/model/CVariable.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CVariable.java,v
retrieving revision 1.48
diff -u -r1.48 CVariable.java
--- src/org/eclipse/cdt/debug/internal/core/model/CVariable.java	6 Aug 2003 20:51:19 -0000	1.48
+++ src/org/eclipse/cdt/debug/internal/core/model/CVariable.java	13 Aug 2003 18:15:23 -0000
@@ -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 @@
 		{
 			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 @@
 			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 @@
 		{
 			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 @@
 		{
 			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 @@
 	/**
 	 * Cache of current value - see #getValue().
 	 */
-	protected CValue fValue;
+	protected ICValue fValue;
 
 	/**
 	 * The name of this variable.
@@ -368,6 +401,9 @@
 		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 @@
 			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 @@
 	 */
 	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 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 @@
 	{
 		if ( fQualifiedName == null )
 		{
-			LinkedList list = new LinkedList();
-			list.add( this );
-			CVariable var = getParentVariable();
-			while( var != null )
-			{
-				if ( !( var.getType().isArray() ) && !( var instanceof CArrayPartition ) && !var.isAccessSpecifier() )
-					list.addFirst( var );
-				var = var.getParentVariable();
-			}
-			StringBuffer sb = new StringBuffer();
-			CVariable[] vars = (CVariable[])list.toArray( new CVariable[list.size()] );
-			for ( int i = 0; i < vars.length; ++i )
+			try
 			{
-				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( ')' );
+				fQualifiedName = getInternalVariable().getQualifiedName();
+			}
+			catch( CDIException e )
+			{
+				requestFailed( "Qualified name is not available.", e );
 			}
-			fQualifiedName = sb.toString();
 		}
 		return fQualifiedName;
 	}
@@ -968,7 +996,7 @@
 	{
 		if ( fValue != null )
 		{
-			((CValue)fValue).dispose();
+			fValue.dispose();
 			fValue = null;
 		}
 	}
@@ -1013,5 +1041,10 @@
 	private InternalVariable getInternalVariable()
 	{
 		return ( getShadow() != null ) ? getShadow() : fOriginal;
+	}
+
+	protected int sizeof()
+	{
+		return getInternalVariable().sizeof();
 	}
 }

Back to the top