[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] 1.0.1 Array Change
|
Hi,
I expect that the head has moved far enough away that this will not be
especially helpful, but please find attached a patch that prevents Eclipse
from requesting all of a 16k array when it is only going to look at one
small section of that array.
Thanks!
-Chris
diff -r -u xide/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/cdi/model/ICDIValue.java xide_compare/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/cdi/model/ICDIValue.java
--- xide/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/cdi/model/ICDIValue.java Tue Mar 11 13:52:12 2003
+++ xide_compare/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/cdi/model/ICDIValue.java Mon Jul 21 14:03:51 2003
@@ -52,4 +52,9 @@
* @throws CDIException if this method fails. Reasons include:
*/
ICDIVariable[] getVariables() throws CDIException;
+
+ /**
+ * Returns the variables requested.
+ */
+ ICDIVariable[] getVariables( int start, int num ) throws CDIException;
}
diff -r -u xide/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CArrayPartition.java xide_compare/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CArrayPartition.java
--- xide/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CArrayPartition.java Tue Mar 11 13:52:13 2003
+++ xide_compare/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CArrayPartition.java Mon Jul 21 14:17:05 2003
@@ -24,12 +24,12 @@
*/
public class CArrayPartition extends CVariable
{
- static final protected int SLOT_SIZE = 100;
+ static final protected int SLOT_SIZE = 64;
private int fStart;
private int fEnd;
- private List fCDIVariables;
-
+ protected CValue fVal;
+
/**
* Cache of value.
*/
@@ -39,12 +39,18 @@
* Constructor for CArrayPartition.
* @param target
*/
- public CArrayPartition( CDebugElement parent, List cdiVariables, int start, int end )
+ public CArrayPartition( CDebugElement parent, CValue val, int start, int end )
{
super( parent, null );
fStart = start;
fEnd = end;
- fCDIVariables = cdiVariables;
+ fVal = val;
+ }
+
+ /** @return true if the size should be partitioned */
+ public static boolean needsPartition( int size )
+ {
+ return size > SLOT_SIZE;
}
/* (non-Javadoc)
@@ -91,38 +97,41 @@
{
if ( fArrayPartitionValue == null )
{
- fArrayPartitionValue = new CArrayPartitionValue( (CDebugTarget)getDebugTarget(), fCDIVariables, getStart(), getEnd() );
+ fArrayPartitionValue = new CArrayPartitionValue( (CDebugTarget)getDebugTarget(), fVal, getStart(), getEnd() );
}
return fArrayPartitionValue;
}
-
- static public List splitArray( CDebugTarget target, List cdiVars, int start, int end )
- {
- ArrayList children = new ArrayList();
- int perSlot = 1;
- int len = end - start;
- while( perSlot * SLOT_SIZE < len )
- {
- perSlot = perSlot * SLOT_SIZE;
- }
-
- while( start <= end )
- {
- if ( start + perSlot > end )
- {
- perSlot = end - start + 1;
- }
- CVariable var = null;
- if ( perSlot == 1 )
- {
- var = new CArrayEntryVariable( target, (ICDIVariable)cdiVars.get( start ), start );
- }
- else
- {
- var = new CArrayPartition( target, cdiVars.subList( start, start + perSlot ), start, start + perSlot - 1 );
- }
+
+ /**
+ * It's the old steps problem. You basically want a partition size
+ * that is sqrt(arraySize) to get the optimal tradeoff between number
+ * of partitions and size of each partition.
+ * <p>
+ * The bounds make the solutions much more bounded.
+ * Up to 4k arrays( 2^12 ) we use sized 64 chunks. Beyond that we use
+ * 128 sized chunks. Larger can start to be slow on certain GDBs and
+ * 128 lines of array info is visually a lot anyway.
+ */
+ static public int partitionSize( int arraySize )
+ {
+ if( arraySize <= 4096 )
+ return 64;
+ else
+ return 128;
+ }
+
+ static public List splitArray( CDebugTarget target, CValue val, int size )
+ {
+ ArrayList children = new ArrayList( size );
+ int psize = partitionSize( size );
+ for( int start = 0 ; start < size ; start += psize )
+ {
+ int next = start + psize - 1;
+ if( next >= size )
+ next = size - 1;
+ CVariable var =
+ var = new CArrayPartition( target, val, start, next );
children.add( var );
- start += perSlot;
}
return children;
}
diff -r -u xide/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CArrayPartitionValue.java xide_compare/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CArrayPartitionValue.java
--- xide/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CArrayPartitionValue.java Tue Mar 11 13:52:13 2003
+++ xide_compare/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CArrayPartitionValue.java Mon Jul 21 14:03:51 2003
@@ -11,6 +11,7 @@
import java.util.Iterator;
import java.util.List;
+import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.model.ICDIValue;
import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable;
import org.eclipse.cdt.debug.core.model.ICValue;
@@ -26,29 +27,31 @@
public class CArrayPartitionValue extends CDebugElement implements ICValue
{
/**
- * The underlying CDI variables.
- */
- private List fCDIVariables;
-
- /**
* List of child variables.
*/
- private List fVariables = Collections.EMPTY_LIST;
-
private int fStart;
private int fEnd;
+
+ protected CValue fVal;
+
+ protected CArrayEntryVariable fVariables[];
/**
* Constructor for CArrayPartitionValue.
* @param target
*/
- public CArrayPartitionValue( CDebugTarget target, List cdiVariables, int start, int end )
+ public CArrayPartitionValue( CDebugTarget target, CValue val, int start, int end )
{
super( target );
- fCDIVariables = cdiVariables;
fStart = start;
fEnd = end;
+ fVal = val;
+ }
+
+ public int size()
+ {
+ return fEnd - fStart + 1;
}
/* (non-Javadoc)
@@ -96,15 +99,34 @@
*/
public IVariable[] getVariables() throws DebugException
{
- if ( fVariables.isEmpty() )
+ if ( fVariables == null )
{
- fVariables = new ArrayList( getEnd() - getStart() + 1 );
+ CDebugTarget debugTarget = (CDebugTarget)getDebugTarget();
+ fVariables = new CArrayEntryVariable[ fEnd - fStart + 1 ];
+ ICDIVariable baseVars[] = getArrayVariables( fVal, getStart(), size() );
+
for ( int i = getStart(); i <= getEnd(); ++i )
{
- fVariables.add( new CArrayEntryVariable( (CDebugTarget)getDebugTarget(), (ICDIVariable)fCDIVariables.get( i - getStart() ), i ) );
+ /** CMS HERE */
+ fVariables[i - fStart] = new CArrayEntryVariable(
+ (CDebugTarget)getDebugTarget(), baseVars[i - fStart],
+ i );
}
}
- return (IVariable[])fVariables.toArray( new IVariable[fVariables.size()] );
+ return fVariables;
+ }
+
+ protected ICDIVariable[] getArrayVariables( CValue val, int index,
+ int len ) throws DebugException
+ {
+ ICDIVariable var[] = new ICDIVariable[0];
+ try {
+ var = val.getUnderlyingValue().getVariables( index, len );
+ } catch( CDIException e ) {
+ throw new DebugException(null);
+ }
+
+ return var;
}
/* (non-Javadoc)
@@ -130,10 +152,14 @@
*/
public void setChanged( boolean changed ) throws DebugException
{
- Iterator it = fVariables.iterator();
- while( it.hasNext() )
+ /* if the user has not yet opened this partition, leave it alone. */
+ if( fVariables == null )
+ return;
+
+ int size = size();
+ for( int i = 0 ; i < size ; i++ )
{
- ((CVariable)it.next()).setChanged( changed );
+ fVariables[i].setChanged( changed );
}
- }
+ }
}
diff -r -u xide/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValue.java xide_compare/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValue.java
--- xide/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValue.java Tue Mar 11 13:52:13 2003
+++ xide_compare/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValue.java Mon Jul 21 14:03:51 2003
@@ -119,6 +119,35 @@
List list = getVariables0();
return (IVariable[])list.toArray( new IVariable[list.size()] );
}
+
+ /** @return a list containing CVariables that has the array entries */
+ protected List createFlatArray( CDebugTarget target ) throws DebugException
+ {
+ /* for a flat array, just use the old style and ask GDB for everything
+ * right now */
+ List vars = getCDIVariables();
+ ArrayList children = new ArrayList();
+
+ Iterator i = vars.iterator();
+ int count = 0;
+ while( i.hasNext() )
+ {
+ CVariable var = new CArrayEntryVariable( target,
+ (ICDIVariable)i.next(), count++ );
+ children.add( var );
+ }
+
+ return children;
+ }
+
+ protected static int getArraySize( String arrayValueString )
+ {
+ String number = arrayValueString.substring(1, arrayValueString.length() - 1);
+ int val = Integer.parseInt(number);
+
+ return val;
+ }
+
protected synchronized List getVariables0() throws DebugException
{
@@ -126,14 +155,18 @@
return Collections.EMPTY_LIST;
if ( fVariables.size() == 0 )
{
- List vars = getCDIVariables();
if ( getType() == ICValue.TYPE_ARRAY )
{
- if ( vars.size() > 0 )
- fVariables = CArrayPartition.splitArray( (CDebugTarget)getDebugTarget(), vars, 0, vars.size() - 1 );
+ int arraySize = getArraySize( getValueString() );
+ if( CArrayPartition.needsPartition( arraySize ) )
+ fVariables = CArrayPartition.splitArray( (CDebugTarget)getDebugTarget(), this, arraySize );
+ else
+ fVariables = createFlatArray((CDebugTarget)getDebugTarget());
+
}
else
{
+ List vars = getCDIVariables();
fVariables = new ArrayList( vars.size() );
Iterator it = vars.iterator();
while( it.hasNext() )
diff -r -u xide/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/Register.java xide_compare/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/Register.java
--- xide/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/Register.java Tue Mar 11 13:52:15 2003
+++ xide_compare/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/Register.java Mon Jul 21 14:03:51 2003
@@ -269,6 +269,13 @@
}
return (ICDIVariable[])aList.toArray(new ICDIVariable[0]);
}
+
+ public ICDIVariable[] getVariables( int start, int len ) throws CDIException
+ {
+ if( start != 0 && len != 1 )
+ throw new CDIException("Register request included a range" );
+ return getVariables();
+ }
/**
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIValue#hasChildren()
diff -r -u xide/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/Value.java xide_compare/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/Value.java
--- xide/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/Value.java Wed Jun 25 14:48:42 2003
+++ xide_compare/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/Value.java Mon Jul 21 14:03:51 2003
@@ -127,5 +127,21 @@
}
return variables;
}
+
+ /** this should be called only for arrays, it uses array specific syntax */
+ public ICDIVariable[] getVariables(int start, int len) throws CDIException {
+ ICDIVariable ret[] = new ICDIVariable[ len ];
+ CSession session = getCTarget().getCSession();
+ VariableManager mgr = (VariableManager)session.getVariableManager();
+
+ for( int i = 0 ; i < len ; i++ )
+ {
+ String arrayref = variable.getName() + "[" + (i + start) + "]";
+ ret[i] = mgr.createVariable( variable.getStackFrame(), arrayref );
+ }
+
+ return ret;
+
+ }
}