1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 01:15:29 +02:00

Implementation of variables presentation in Variables view.

This commit is contained in:
Mikhail Khodjaiants 2002-09-10 22:41:10 +00:00
parent 841c4d9b89
commit 43e52e0f88
20 changed files with 602 additions and 43 deletions

View file

@ -0,0 +1,39 @@
/*
*(c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*
*/
package org.eclipse.cdt.debug.core;
import org.eclipse.cdt.debug.core.cdi.model.ICDIValue;
import org.eclipse.debug.core.model.IValue;
/**
*
* Extends the IValue interface by C/C++ specific functionality.
*
* @since Sep 9, 2002
*/
public interface ICValue extends IValue
{
static final public int TYPE_SIMPLE = 0;
static final public int TYPE_ARRAY = 1;
static final public int TYPE_STRUCTURE = 2;
static final public int TYPE_STRING = 3;
static final public int TYPE_POINTER = 4;
static final public int TYPE_ARRAY_PARTITION = 5;
static final public int TYPE_ARRAY_ENTRY = 7;
/**
* Returns the type of this value.
*
* @return the type of this value
*/
int getType();
/**
* Returns the underlying CDI value for this value.
*/
ICDIValue getUnderlyingValue();
}

View file

@ -0,0 +1,78 @@
/*
*(c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*
*/
package org.eclipse.cdt.debug.internal.core.model;
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.debug.core.DebugException;
/**
*
* An entry in an array.
*
* @since Sep 9, 2002
*/
public class CArrayEntryVariable extends CLocalVariable
{
/**
* The index of the variable entry.
*/
private int fIndex;
/**
* The type name of this variable. Cached lazily.
*/
private String fReferenceTypeName = null;
/**
* Constructor for CArrayEntryVariable.
* @param target
*/
public CArrayEntryVariable( CDebugTarget target, ICDIVariable cdiVariable, int index )
{
super( target, cdiVariable );
fIndex = index;
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IVariable#getName()
*/
public String getName() throws DebugException
{
return "[" + getIndex() + "]";
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IVariable#getReferenceTypeName()
*/
public String getReferenceTypeName() throws DebugException
{
return stripBrackets( super.getReferenceTypeName() );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener#handleDebugEvent(ICDIEvent)
*/
public void handleDebugEvent(ICDIEvent event)
{
}
protected int getIndex()
{
return fIndex;
}
protected String stripBrackets( String typeName )
{
int index = typeName.lastIndexOf( '[' );
if ( index < 0 )
return typeName;
return typeName.substring( 0, index );
}
}

View file

@ -0,0 +1,141 @@
/*
*(c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*
*/
package org.eclipse.cdt.debug.internal.core.model;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.event.ICDIChangedEvent;
import org.eclipse.cdt.debug.core.cdi.event.ICDIEvent;
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.debug.core.DebugException;
import org.eclipse.debug.core.model.IValue;
/**
*
* A sub-range of an array.
*
* @since Sep 9, 2002
*/
public class CArrayPartition extends CVariable
{
static final protected int SLOT_SIZE = 100;
private int fStart;
private int fEnd;
private List fCDIVariables;
/**
* Cache of value.
*/
private CArrayPartitionValue fArrayPartitionValue = null;
/**
* Constructor for CArrayPartition.
* @param target
*/
public CArrayPartition( CDebugTarget target, List cdiVariables, int start, int end )
{
super( target );
fStart = start;
fEnd = end;
fCDIVariables = cdiVariables;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.internal.core.model.CVariable#retrieveValue()
*/
protected ICDIValue retrieveValue() throws DebugException, CDIException
{
return null;
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IVariable#getName()
*/
public String getName() throws DebugException
{
StringBuffer name = new StringBuffer();
name.append( '[' );
name.append( fStart );
name.append( ".." );
name.append( fEnd );
name.append( ']' );
return name.toString();
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IVariable#getReferenceTypeName()
*/
public String getReferenceTypeName() throws DebugException
{
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener#handleDebugEvent(ICDIEvent)
*/
public void handleDebugEvent( ICDIEvent event )
{
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IVariable#getValue()
*/
public IValue getValue() throws DebugException
{
if ( fArrayPartitionValue == null )
{
fArrayPartitionValue = new CArrayPartitionValue( (CDebugTarget)getDebugTarget(), fCDIVariables, 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 - 1 ), start, start + perSlot - 1 );
}
children.add( var );
start += perSlot;
}
return children;
}
protected int getStart()
{
return fStart;
}
protected int getEnd()
{
return fEnd;
}
}

View file

@ -0,0 +1,124 @@
/*
*(c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*
*/
package org.eclipse.cdt.debug.internal.core.model;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.eclipse.cdt.debug.core.ICValue;
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.model.IVariable;
/**
*
* The value for an array partition.
*
* @since Sep 9, 2002
*/
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;
/**
* Constructor for CArrayPartitionValue.
* @param target
*/
public CArrayPartitionValue( CDebugTarget target, List cdiVariables, int start, int end )
{
super( target );
fCDIVariables = cdiVariables;
fStart = start;
fEnd = end;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.ICValue#getType()
*/
public int getType()
{
return 0;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.ICValue#getUnderlyingValue()
*/
public ICDIValue getUnderlyingValue()
{
return null;
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IValue#getReferenceTypeName()
*/
public String getReferenceTypeName() throws DebugException
{
return null;
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IValue#getValueString()
*/
public String getValueString() throws DebugException
{
return null;
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IValue#isAllocated()
*/
public boolean isAllocated() throws DebugException
{
return true;
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IValue#getVariables()
*/
public IVariable[] getVariables() throws DebugException
{
if ( fVariables.isEmpty() )
{
fVariables = new ArrayList( getEnd() - getStart() + 1 );
for ( int i = getStart(); i <= getEnd(); ++i )
fVariables.add( new CArrayEntryVariable( (CDebugTarget)getDebugTarget(), (ICDIVariable)fCDIVariables.get( i - getStart() ), i ) );
}
return (IVariable[])fVariables.toArray( new IVariable[fVariables.size()] );
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IValue#hasVariables()
*/
public boolean hasVariables() throws DebugException
{
return true;
}
protected int getStart()
{
return fStart;
}
protected int getEnd()
{
return fEnd;
}
}

View file

@ -158,11 +158,8 @@ public class CLocalVariable extends CModificationVariable
try
{
//setValue( getCurrentValue() );
if ( !getValue().hasVariables() )
{
setChanged( true );
getParent().fireChangeEvent( DebugEvent.CONTENT );
}
setChanged( true );
getParent().fireChangeEvent( DebugEvent.CONTENT );
}
catch( DebugException e )
{

View file

@ -12,6 +12,7 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.debug.core.ICValue;
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;
@ -25,26 +26,37 @@ import org.eclipse.debug.core.model.IVariable;
*
* @since Aug 9, 2002
*/
public class CValue extends CDebugElement implements IValue
public class CValue extends CDebugElement implements ICValue
{
/**
* Cached value.
*/
private String fValueString = null;
/**
* Underlying CDI value.
*/
private ICDIValue fValue;
private ICDIValue fCDIValue;
/**
* List of child variables.
*/
private List fVariables = Collections.EMPTY_LIST;
/**
* Type (simple, array, structure or string) of this value.
*/
private int fType = TYPE_SIMPLE;
/**
* Constructor for CValue.
* @param target
*/
public CValue( CDebugTarget target, ICDIValue cdiValue )
public CValue( CDebugTarget target, ICDIValue cdiValue ) throws DebugException
{
super( target );
fValue = cdiValue;
fCDIValue = cdiValue;
calculateType();
}
/* (non-Javadoc)
@ -52,7 +64,19 @@ public class CValue extends CDebugElement implements IValue
*/
public String getReferenceTypeName() throws DebugException
{
return null;
String typeName = null;
try
{
if ( fCDIValue != null )
{
typeName = fCDIValue.getTypeName();
}
}
catch( CDIException e )
{
targetRequestFailed( "Operation failed. Reason: ", e );
}
return typeName;
}
/* (non-Javadoc)
@ -60,12 +84,11 @@ public class CValue extends CDebugElement implements IValue
*/
public String getValueString() throws DebugException
{
String result = null;
if ( getUnderlyingValue() != null )
if ( fValueString == null && getUnderlyingValue() != null )
{
try
{
result = getUnderlyingValue().getValueString();
fValueString = processCDIValue( getUnderlyingValue().getValueString() );
}
catch( CDIException e )
{
@ -73,7 +96,7 @@ public class CValue extends CDebugElement implements IValue
requestFailed( "", e );
}
}
return result;
return fValueString;
}
/* (non-Javadoc)
@ -100,11 +123,20 @@ public class CValue extends CDebugElement implements IValue
if ( fVariables.size() == 0 )
{
List vars = getCDIVariables();
fVariables = new ArrayList( vars.size() );
Iterator it = vars.iterator();
while( it.hasNext() )
if ( getType() == ICValue.TYPE_ARRAY )
{
fVariables.add( new CLocalVariable( this, (ICDIVariable)it.next() ) );
int length = getNumberOfChildren();
if ( length > 0 )
fVariables = CArrayPartition.splitArray( (CDebugTarget)getDebugTarget(), vars, 0, length - 1 );
}
else
{
fVariables = new ArrayList( vars.size() );
Iterator it = vars.iterator();
while( it.hasNext() )
{
fVariables.add( new CLocalVariable( this, (ICDIVariable)it.next() ) );
}
}
}
return fVariables;
@ -119,7 +151,7 @@ public class CValue extends CDebugElement implements IValue
{
ICDIValue value = getUnderlyingValue();
if ( value != null )
return value.hasChildren();
return value.getChildrenNumber() > 0;
}
catch( CDIException e )
{
@ -128,21 +160,12 @@ public class CValue extends CDebugElement implements IValue
return false;
}
/**
* Creates the appropriate kind of value, or <code>null</code>.
*
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.ICValue#getUnderlyingValue()
*/
public static CValue createValue( CDebugTarget target, ICDIValue value )
public ICDIValue getUnderlyingValue()
{
return new CValue( target, value );
}
/**
* Returns this value's underlying CDI value
*/
protected ICDIValue getUnderlyingValue()
{
return fValue;
return fCDIValue;
}
protected List getCDIVariables() throws DebugException
@ -161,4 +184,70 @@ public class CValue extends CDebugElement implements IValue
}
return Collections.EMPTY_LIST;
}
protected void calculateType() throws DebugException
{
String stringValue = getValueString();
if ( stringValue != null && stringValue.trim().length() > 0 )
{
stringValue = stringValue.trim();
if ( stringValue.charAt( 0 ) == '[' )
{
fType = TYPE_ARRAY;
}
else if ( stringValue.charAt( 0 ) == '{' )
{
fType = TYPE_STRUCTURE;
}
else if ( stringValue.startsWith( "0x" ) )
{
fType = TYPE_POINTER;
}
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.ICValue#getType()
*/
public int getType()
{
return fType;
}
protected int getNumberOfChildren() throws DebugException
{
int result = 0;
try
{
result = getUnderlyingValue().getChildrenNumber();
}
catch( CDIException e )
{
targetRequestFailed( "Operation failed. Reason: ", e );
}
return result;
}
protected String processCDIValue( String cdiValue )
{
return cdiValue;
}
public synchronized void setChanged( boolean changed ) throws DebugException
{
if ( changed )
{
fValueString = null;
}
/*
if ( hasVariables() )
{
IVariable[] vars = getVariables();
for ( int i = 0; i < vars.length; ++i )
{
((CVariable)vars[i]).setChanged( changed );
}
}
*/
}
}

View file

@ -0,0 +1,29 @@
/*
*(c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*
*/
package org.eclipse.cdt.debug.internal.core.model;
import org.eclipse.cdt.debug.core.ICValue;
import org.eclipse.cdt.debug.core.cdi.model.ICDIValue;
import org.eclipse.debug.core.DebugException;
/**
*
* Generates variable values.
*
* @since Sep 9, 2002
*/
public class CValueFactory
{
/**
* Creates the appropriate kind of value, or <code>null</code>.
*
*/
static public ICValue createValue( CDebugTarget target, ICDIValue cdiValue ) throws DebugException
{
return new CValue( target, cdiValue );
}
}

View file

@ -7,6 +7,7 @@ package org.eclipse.cdt.debug.internal.core.model;
import java.text.MessageFormat;
import org.eclipse.cdt.debug.core.ICValue;
import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener;
import org.eclipse.cdt.debug.core.cdi.model.ICDIValue;
@ -27,7 +28,7 @@ public abstract class CVariable extends CDebugElement
/**
* Cache of current value - see #getValue().
*/
private CValue fValue;
private ICValue fValue;
/**
* Counter corresponding to this variable's debug target
@ -65,7 +66,7 @@ public abstract class CVariable extends CDebugElement
ICDIValue currentValue = getCurrentValue();
if ( fValue == null )
{
fValue = CValue.createValue( (CDebugTarget)getDebugTarget(), currentValue );
fValue = CValueFactory.createValue( (CDebugTarget)getDebugTarget(), currentValue );
}
return fValue;
}
@ -199,17 +200,13 @@ public abstract class CVariable extends CDebugElement
protected synchronized void setChanged( boolean changed ) throws DebugException
{
if ( getValue().hasVariables() )
if ( getValue() != null )
{
IVariable[] vars = getValue().getVariables();
for ( int i = 0; i < vars.length; ++i )
((CValue)getValue()).setChanged( changed );
if ( !getValue().hasVariables() )
{
((CVariable)vars[i]).setChanged( changed );
fChanged = changed;
}
}
else
{
fChanged = changed;
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 132 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 132 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 132 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 B

View file

@ -13,6 +13,7 @@ import org.eclipse.cdt.debug.core.ICAddressBreakpoint;
import org.eclipse.cdt.debug.core.ICBreakpoint;
import org.eclipse.cdt.debug.core.ICFunctionBreakpoint;
import org.eclipse.cdt.debug.core.ICLineBreakpoint;
import org.eclipse.cdt.debug.core.ICValue;
import org.eclipse.cdt.debug.core.ICWatchpoint;
import org.eclipse.cdt.debug.core.IStackFrameInfo;
import org.eclipse.cdt.debug.core.IState;
@ -21,6 +22,7 @@ import org.eclipse.cdt.debug.core.cdi.ICDIExitInfo;
import org.eclipse.cdt.debug.core.cdi.ICDISignal;
import org.eclipse.cdt.debug.core.cdi.ICDIWatchpointScope;
import org.eclipse.cdt.debug.core.cdi.ICDIWatchpointTrigger;
import org.eclipse.cdt.debug.internal.core.model.CValue;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
@ -173,6 +175,10 @@ public class CDTDebugModelPresentation extends LabelProvider
{
return getBreakpointImage( (ICBreakpoint)element );
}
if ( element instanceof IVariable )
{
return getVariableImage( (IVariable)element );
}
}
catch( CoreException e )
{
@ -366,9 +372,34 @@ public class CDTDebugModelPresentation extends LabelProvider
String label = new String();
if ( var != null )
{
if ( isShowVariableTypeNames() )
{
label += var.getReferenceTypeName() + " ";
}
label += var.getName();
IValue value = var.getValue();
label += "= " + value.getValueString();
if ( value != null && value.getValueString() != null )
{
if ( value instanceof ICValue )
{
switch( ((ICValue)value).getType() )
{
case ICValue.TYPE_ARRAY:
label += value.getValueString();
break;
case ICValue.TYPE_STRUCTURE:
break;
default:
label += "= " + value.getValueString();
break;
}
}
else
{
label += "= " + value.getValueString();
}
}
}
return label;
}
@ -585,4 +616,30 @@ public class CDTDebugModelPresentation extends LabelProvider
}
return flags;
}
protected Image getVariableImage( IVariable element ) throws DebugException
{
if ( element != null )
{
IValue value = element.getValue();
if ( value instanceof ICValue )
return getValueTypeImage( (ICValue)value );
}
return null;
}
protected Image getValueTypeImage( ICValue element )
{
if ( element != null )
{
if ( element.getType() == ICValue.TYPE_ARRAY ||
element.getType() == ICValue.TYPE_STRUCTURE )
return fDebugImageRegistry.get( new CImageDescriptor( CDebugImages.DESC_OBJS_VARIABLE_AGGREGATE, 0 ) );
else if ( element.getType() == ICValue.TYPE_POINTER )
return fDebugImageRegistry.get( new CImageDescriptor( CDebugImages.DESC_OBJS_VARIABLE_POINTER, 0 ) );
else
return fDebugImageRegistry.get( new CImageDescriptor( CDebugImages.DESC_OBJS_VARIABLE_SIMPLE, 0 ) );
}
return null;
}
}

View file

@ -54,6 +54,10 @@ public class CDebugImages
public static final String IMG_OBJS_READ_WATCHPOINT_DISABLED = NAME_PREFIX + "read_obj_disabled.gif"; //$NON-NLS-1$
public static final String IMG_OBJS_WRITE_WATCHPOINT_ENABLED = NAME_PREFIX + "write_obj.gif"; //$NON-NLS-1$
public static final String IMG_OBJS_WRITE_WATCHPOINT_DISABLED = NAME_PREFIX + "write_obj_disabled.gif"; //$NON-NLS-1$
public static final String IMG_OBJS_VARIABLE_SIMPLE = NAME_PREFIX + "var_simple.gif"; //$NON-NLS-1$
public static final String IMG_OBJS_VARIABLE_AGGREGATE = NAME_PREFIX + "var_aggr.gif"; //$NON-NLS-1$
public static final String IMG_OBJS_VARIABLE_POINTER = NAME_PREFIX + "var_pointer.gif"; //$NON-NLS-1$
public static final String IMG_OBJS_VARIABLE_STRING = NAME_PREFIX + "var_string.gif"; //$NON-NLS-1$
/*
* Set of predefined Image Descriptors.
@ -75,6 +79,10 @@ public class CDebugImages
public static final ImageDescriptor DESC_OBJS_READ_WATCHPOINT_DISABLED = createManaged( T_OBJ, IMG_OBJS_READ_WATCHPOINT_DISABLED );
public static final ImageDescriptor DESC_OBJS_WRITE_WATCHPOINT_ENABLED = createManaged( T_OBJ, IMG_OBJS_WRITE_WATCHPOINT_ENABLED );
public static final ImageDescriptor DESC_OBJS_WRITE_WATCHPOINT_DISABLED = createManaged( T_OBJ, IMG_OBJS_WRITE_WATCHPOINT_DISABLED );
public static final ImageDescriptor DESC_OBJS_VARIABLE_SIMPLE = createManaged( T_OBJ, IMG_OBJS_VARIABLE_SIMPLE );
public static final ImageDescriptor DESC_OBJS_VARIABLE_AGGREGATE = createManaged( T_OBJ, IMG_OBJS_VARIABLE_AGGREGATE );
public static final ImageDescriptor DESC_OBJS_VARIABLE_POINTER = createManaged( T_OBJ, IMG_OBJS_VARIABLE_POINTER );
public static final ImageDescriptor DESC_OBJS_VARIABLE_STRING = createManaged( T_OBJ, IMG_OBJS_VARIABLE_STRING );
/**
* Returns the image managed under the given key in this registry.