1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 17:56:01 +02:00

New implementation of the variable types.

This commit is contained in:
Mikhail Khodjaiants 2004-08-04 21:06:56 +00:00
parent aed28a3861
commit 172c988cf8
37 changed files with 1606 additions and 1898 deletions

View file

@ -1,3 +1,33 @@
2004-08-04 Mikhail Khodjaiants
New implementation of the variable types.
* CDIDebugModel.java
* CVariableFormat.java: new
* ICastToArray.java
* ICastToType.java
* ICGlobalVariable.java
* ICType.java
* ICValue.java
* ICVariable.java
* IFormatSupport.java: new
* CGlobalVariableManager.java
* CoreModelMessages.properties
* AbstractCValue.java: new
* AbstractCVariable.java: new
* CArrayPartition.java
* CArrayPartitionValue.java
* CDebugTarget.java
* CExpression.java
* CGlobalVariable.java
* CRegister.java
* CRegisterGroup.java
* CStackFrame.java
* CType.java
* CValue.java
* CValueFactory.java
* CVariable.java
* CVariableFactory.java: new
* CModificationVariable: deleted
2004-07-23 Mikhail Khodjaiants 2004-07-23 Mikhail Khodjaiants
Marked the expression creation methods as deprecated in CDebugModel. Marked the expression creation methods as deprecated in CDebugModel.
* CDebugModel.java * CDebugModel.java

View file

@ -12,7 +12,6 @@ package org.eclipse.cdt.debug.core;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.HashMap; import java.util.HashMap;
import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.ICDIConfiguration; import org.eclipse.cdt.debug.core.cdi.ICDIConfiguration;
import org.eclipse.cdt.debug.core.cdi.ICDILocation; import org.eclipse.cdt.debug.core.cdi.ICDILocation;
@ -39,7 +38,7 @@ import org.eclipse.cdt.debug.internal.core.breakpoints.CWatchpoint;
import org.eclipse.cdt.debug.internal.core.model.CCoreFileDebugTarget; import org.eclipse.cdt.debug.internal.core.model.CCoreFileDebugTarget;
import org.eclipse.cdt.debug.internal.core.model.CDebugTarget; import org.eclipse.cdt.debug.internal.core.model.CDebugTarget;
import org.eclipse.cdt.debug.internal.core.model.CExpression; import org.eclipse.cdt.debug.internal.core.model.CExpression;
import org.eclipse.cdt.debug.internal.core.model.CGlobalVariable; import org.eclipse.cdt.debug.internal.core.model.CVariableFactory;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
@ -543,8 +542,7 @@ public class CDIDebugModel {
ICDIVariableObject vo = null; ICDIVariableObject vo = null;
try { try {
vo = ((CDebugTarget)target).getCDISession().getVariableManager().getGlobalVariableObject( info.getPath().lastSegment(), null, info.getName() ); vo = ((CDebugTarget)target).getCDISession().getVariableManager().getGlobalVariableObject( info.getPath().lastSegment(), null, info.getName() );
ICDIVariable cdiVariable = ((CDebugTarget)target).getCDISession().getVariableManager().createVariable( vo ); return CVariableFactory.createGlobalVariable( (CDebugTarget)target, vo );
return new CGlobalVariable( (CDebugTarget)target, cdiVariable );
} }
catch( CDIException e ) { catch( CDIException e ) {
throw new DebugException( new Status( IStatus.ERROR, getPluginIdentifier(), DebugException.TARGET_REQUEST_FAILED, (vo != null) ? vo.getName() + ": " + e.getMessage() : e.getMessage(), null ) ); //$NON-NLS-1$ throw new DebugException( new Status( IStatus.ERROR, getPluginIdentifier(), DebugException.TARGET_REQUEST_FAILED, (vo != null) ? vo.getName() + ": " + e.getMessage() : e.getMessage(), null ) ); //$NON-NLS-1$

View file

@ -0,0 +1,50 @@
/**********************************************************************
* Copyright (c) 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.debug.core.model;
/**
* Defines the variable format types.
*/
public class CVariableFormat {
private final String fName;
private CVariableFormat( String name ) {
this.fName = name;
}
public String toString() {
return this.fName;
}
public static CVariableFormat getFormat( int code ) {
switch( code ) {
case 0:
return NATURAL;
case 1:
return DECIMAL;
case 2:
return BINARY;
case 3:
return OCTAL;
case 4:
return HEXADECIMAL;
default:
return NATURAL;
}
}
public static final CVariableFormat NATURAL = new CVariableFormat( "natural" ); //$NON-NLS-1$
public static final CVariableFormat DECIMAL = new CVariableFormat( "decimal" ); //$NON-NLS-1$
public static final CVariableFormat BINARY = new CVariableFormat( "binary" ); //$NON-NLS-1$
public static final CVariableFormat OCTAL = new CVariableFormat( "octal" ); //$NON-NLS-1$
public static final CVariableFormat HEXADECIMAL = new CVariableFormat( "hexadecimal" ); //$NON-NLS-1$
}

View file

@ -14,5 +14,4 @@ package org.eclipse.cdt.debug.core.model;
* Represents a global C/C++ variable. * Represents a global C/C++ variable.
*/ */
public interface ICGlobalVariable extends ICVariable { public interface ICGlobalVariable extends ICVariable {
public void dispose();
} }

View file

@ -8,33 +8,75 @@
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.debug.core.model; package org.eclipse.cdt.debug.core.model;
import org.eclipse.core.runtime.IAdaptable;
/** /**
* Enter type comment. * Represents a type of a varibale.
* * Used by the UI responsible components for variable rendering.
* @since Jun 10, 2003
*/ */
public interface ICType extends IAdaptable public interface ICType {
{
/**
* Returns the name of this type.
*
* @return the name of this type
*/
String getName(); String getName();
/**
* Returns whether this is an array type.
*
* @return whether this is an array type
*/
boolean isArray(); boolean isArray();
/**
* Returns the array dimensions for array types,
* otherwise returns an empty array.
*
* @return the array dimensions
*/
int[] getArrayDimensions(); int[] getArrayDimensions();
/**
* Returns whether this is a structure or a class type.
*
* @return whether this is a structure or a class type
*/
boolean isStructure(); boolean isStructure();
/**
* Returns whether this is a character type.
*
* @return whether this is a character type
*/
boolean isCharacter(); boolean isCharacter();
/**
* Returns whether this is a floating point type.
*
* @return whether this is a floating point type
*/
boolean isFloatingPointType(); boolean isFloatingPointType();
/**
* Returns whether this is a pointer type.
*
* @return whether this is a pointer type
*/
boolean isPointer(); boolean isPointer();
/**
* Returns whether this is a reference type.
*
* @return whether this is a reference type
*/
boolean isReference(); boolean isReference();
void dispose(); /**
* Returns whether this is an unsigned type.
*
* @return whether this is an unsigned type
*/
boolean isUnsigned();
} }

View file

@ -8,20 +8,14 @@
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.debug.core.model; package org.eclipse.cdt.debug.core.model;
import org.eclipse.debug.core.model.IValue; import org.eclipse.debug.core.model.IValue;
/** /**
*
* Extends the IValue interface by C/C++ specific functionality. * Extends the IValue interface by C/C++ specific functionality.
*
* @since Sep 9, 2002
*/ */
public interface ICValue extends IValue public interface ICValue extends IValue, ICDebugElement {
{
String evaluateAsExpression();
void dispose(); String evaluateAsExpression();
} }

View file

@ -11,31 +11,48 @@
package org.eclipse.cdt.debug.core.model; package org.eclipse.cdt.debug.core.model;
import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IValueModification;
import org.eclipse.debug.core.model.IVariable; import org.eclipse.debug.core.model.IVariable;
/** /**
* * C/C++ specific extension <code>IVariable</code>.
* Enter type comment.
*
* @since Dec 15, 2002
*/ */
public interface ICVariable extends IVariable public interface ICVariable extends IVariable, ICDebugElement, IFormatSupport, ICastToArray, IValueModification {
{
int getFormat();
void setFormat( int format ) throws DebugException;
/**
* Returns the type of this variable.
*
* @return the type of this variable
* @throws DebugException
*/
ICType getType() throws DebugException; ICType getType() throws DebugException;
boolean isEditable(); /**
* Returns whether this variable is enabled.
boolean hasChildren(); *
* @return whether this variable is enabled
*/
boolean isEnabled(); boolean isEnabled();
/**
* Sets the enabled state of this action.
*
* @param enabled <code>true</code> to enable, and <code>false</code> to disable
* @throws DebugException
*/
void setEnabled( boolean enabled ) throws DebugException; void setEnabled( boolean enabled ) throws DebugException;
/**
* Returns whether this variable supports enable/disable operation.
*
* @return whether this variable supports enable/disable operation
*/
boolean canEnableDisable(); boolean canEnableDisable();
/**
* Returns whether this variable is an argument.
*
* @return whether this variable is an argument
*/
boolean isArgument(); boolean isArgument();
} }

View file

@ -8,19 +8,29 @@
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.debug.core.model; package org.eclipse.cdt.debug.core.model;
import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugException;
/** /**
* Enter type comment. * Provides the ability to present a variable as an array of the same type.
*
* @since Mar 10, 2003
*/ */
public interface ICastToArray extends ICastToType public interface ICastToArray extends ICastToType {
{
boolean supportsCastToArray();
/**
* Returns whether this element can be currently casted to array.
*
* @return whether this element can be currently casted to array
*/
boolean canCastToArray();
/**
* Performs the casting. The element is transformed to the array of the same type.
*
* @param startIndex the index of the first element of the array. 0 means that
* the original element is the first member of the array.
* @param length tha array size
* @throws DebugException
*/
void castToArray( int startIndex, int length ) throws DebugException; void castToArray( int startIndex, int length ) throws DebugException;
} }

View file

@ -8,26 +8,49 @@
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.debug.core.model; package org.eclipse.cdt.debug.core.model;
import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugException;
/** /**
* Enter type comment. * Provides the ability to cast a variable to the given type.
*
* @since Mar 7, 2003
*/ */
public interface ICastToType extends IAdaptable public interface ICastToType extends IAdaptable {
{
boolean supportsCasting();
/**
* Returns whether this element can currently be casted.
*
* @return whether this element can currently be casted
*/
boolean canCast();
/**
* Returns the string presentation of the current type.
*
* @return the string presentation of the current type
*/
String getCurrentType(); String getCurrentType();
/**
* Performs the casting to the given type.
*
* @param type a type to cast to.
* @throws DebugException
*/
void cast( String type ) throws DebugException; void cast( String type ) throws DebugException;
void restoreDefault() throws DebugException; /**
* Restores the original type.
*
* @throws DebugException
*/
void restoreOriginal() throws DebugException;
/**
* Returns whether this element is casted.
*
* @return whether this element is casted
*/
boolean isCasted(); boolean isCasted();
} }

View file

@ -0,0 +1,41 @@
/**********************************************************************
* Copyright (c) 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.debug.core.model;
import org.eclipse.debug.core.DebugException;
/**
* Provides the ability to set and get the format of a variable.
*/
public interface IFormatSupport {
/**
* Returns whether this variable supports formatting operations.
*
* @return whether this variable supports formatting operations
*/
boolean supportsFormatting();
/**
* Returns the current format of this variable.
*
* @return the current format of this variable
*/
CVariableFormat getFormat();
/**
* Sets the current format of this variable to <code>format</code>.
*
* @param format the new format type
* @throws DebugException if this method fails.
*/
void changeFormat( CVariableFormat format ) throws DebugException;
}

View file

@ -86,7 +86,8 @@ public class CGlobalVariableManager implements ICGlobalVariableManager {
fGlobals.removeAll( Arrays.asList( globals ) ); fGlobals.removeAll( Arrays.asList( globals ) );
} }
for ( int i = 0; i < globals.length; ++i ) { for ( int i = 0; i < globals.length; ++i ) {
globals[i].dispose(); if ( globals[i] instanceof CVariable )
((CVariable)globals[i]).dispose();
} }
getDebugTarget().fireChangeEvent( DebugEvent.CONTENT ); getDebugTarget().fireChangeEvent( DebugEvent.CONTENT );
} }
@ -101,7 +102,8 @@ public class CGlobalVariableManager implements ICGlobalVariableManager {
fGlobals.clear(); fGlobals.clear();
} }
for ( int i = 0; i < globals.length; ++i ) { for ( int i = 0; i < globals.length; ++i ) {
((CVariable)globals[i]).dispose(); if ( globals[i] instanceof CVariable )
((CVariable)globals[i]).dispose();
} }
getDebugTarget().fireChangeEvent( DebugEvent.CONTENT ); getDebugTarget().fireChangeEvent( DebugEvent.CONTENT );
} }
@ -109,7 +111,7 @@ public class CGlobalVariableManager implements ICGlobalVariableManager {
public void dispose() { public void dispose() {
Iterator it = fGlobals.iterator(); Iterator it = fGlobals.iterator();
while( it.hasNext() ) { while( it.hasNext() ) {
((ICGlobalVariable)it.next()).dispose(); ((CVariable)it.next()).dispose();
} }
fGlobals.clear(); fGlobals.clear();
} }

View file

@ -0,0 +1,28 @@
/**********************************************************************
* Copyright (c) 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.debug.internal.core.model;
import org.eclipse.cdt.debug.core.model.ICValue;
/**
* The abstract super class for the C/C++ value types.
*/
public abstract class AbstractCValue extends CDebugElement implements ICValue {
/**
* Constructor for AbstractCValue.
*/
public AbstractCValue( CDebugTarget target ) {
super( target );
}
abstract public void dispose();
}

View file

@ -0,0 +1,37 @@
/**********************************************************************
* Copyright (c) 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.debug.internal.core.model;
import org.eclipse.cdt.debug.core.model.ICVariable;
import org.eclipse.debug.core.DebugException;
/**
* The super class for all variable types.
*/
public abstract class AbstractCVariable extends CDebugElement implements ICVariable {
/**
* Constructor for AbstractCVariable.
*/
public AbstractCVariable( CDebugTarget target ) {
super( target );
}
/**
* Returns the text presentation of this variable as an expression.
*
* @return the text presentation of this variable as an expression
* @throws DebugException
*/
public abstract String getExpressionString() throws DebugException;
public abstract void dispose();
}

View file

@ -1,75 +1,119 @@
/******************************************************************************* /**********************************************************************
* Copyright (c) 2000, 2004 QNX Software Systems and others. * Copyright (c) 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0 * are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html * http://www.eclipse.org/legal/cpl-v10.html
* *
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
*******************************************************************************/ ***********************************************************************/
package org.eclipse.cdt.debug.internal.core.model; package org.eclipse.cdt.debug.internal.core.model;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.eclipse.cdt.debug.core.cdi.CDIException; 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.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.ICDIVariableObject; import org.eclipse.cdt.debug.core.cdi.model.ICDIVariableObject;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIArrayValue; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIArrayValue;
import org.eclipse.cdt.debug.core.model.CVariableFormat;
import org.eclipse.cdt.debug.core.model.ICType; 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;
/** /**
*
* A sub-range of an array. * A sub-range of an array.
*
* @since Sep 9, 2002
*/ */
public class CArrayPartition extends CVariable public class CArrayPartition extends AbstractCVariable {
{
static final protected int SLOT_SIZE = 100; static final protected int SLOT_SIZE = 100;
private int fStart; private int fStart;
private int fEnd; private int fEnd;
private ICDIVariableObject fCDIVariableObject; private ICDIVariableObject fCDIVariableObject;
private ICDIVariable fCDIVariable; private ICDIVariable fCDIVariable;
private ICType fType = null; private ICType fType = null;
private String fQualifiedName = null; private String fQualifiedName = null;
/** /**
* Cache of value. * Cached value.
*/ */
private CArrayPartitionValue fArrayPartitionValue = null; private CArrayPartitionValue fArrayPartitionValue = null;
/** /**
* Constructor for CArrayPartition. * Constructor for CArrayPartition.
* @param target
*/ */
public CArrayPartition( CDebugElement parent, ICDIVariable cdiVariable, int start, int end ) private CArrayPartition( CDebugElement parent, ICDIVariable cdiVariable, int start, int end ) {
{ super( (CDebugTarget)parent.getDebugTarget() );
super( parent, null );
fStart = start; fStart = start;
fEnd = end; fEnd = end;
fCDIVariable = cdiVariable; fCDIVariable = cdiVariable;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.internal.core.model.CVariable#retrieveValue() * @see org.eclipse.cdt.debug.core.model.ICVariable#getType()
*/ */
protected ICDIValue retrieveValue() throws DebugException, CDIException public ICType getType() throws DebugException {
{ if ( fType == null ) {
return null; try {
ICDIVariableObject varObject = getVariableObject();
if ( varObject != null )
fType = new CType( varObject.getType() );
}
catch( CDIException e ) {
requestFailed( CoreModelMessages.getString( "CArrayPartition.0" ), e ); //$NON-NLS-1$
}
}
return fType;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICVariable#isEnabled()
*/
public boolean isEnabled() {
return true;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICVariable#setEnabled(boolean)
*/
public void setEnabled( boolean enabled ) throws DebugException {
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICVariable#canEnableDisable()
*/
public boolean canEnableDisable() {
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICVariable#isArgument()
*/
public boolean isArgument() {
return false;
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IVariable#getValue()
*/
public IValue getValue() throws DebugException {
if ( fArrayPartitionValue == null ) {
fArrayPartitionValue = CValueFactory.createArrayValue( this, getCDIVariable(), getStart(), getEnd() );
}
return fArrayPartitionValue;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.debug.core.model.IVariable#getName() * @see org.eclipse.debug.core.model.IVariable#getName()
*/ */
public String getName() throws DebugException public String getName() throws DebugException {
{
StringBuffer name = new StringBuffer(); StringBuffer name = new StringBuffer();
name.append( '[' ); name.append( '[' );
name.append( fStart ); name.append( fStart );
@ -82,63 +126,160 @@ public class CArrayPartition extends CVariable
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.debug.core.model.IVariable#getReferenceTypeName() * @see org.eclipse.debug.core.model.IVariable#getReferenceTypeName()
*/ */
public String getReferenceTypeName() throws DebugException public String getReferenceTypeName() throws DebugException {
{ ICType type = getType();
return ( type != null ) ? type.getName() : null;
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IVariable#hasValueChanged()
*/
public boolean hasValueChanged() throws DebugException {
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.IFormatSupport#supportsFormatting()
*/
public boolean supportsFormatting() {
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.IFormatSupport#getFormat()
*/
public CVariableFormat getFormat() {
return null; return null;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener#handleDebugEvents(ICDIEvent) * @see org.eclipse.cdt.debug.core.model.IFormatSupport#changeFormat(org.eclipse.cdt.debug.core.model.CVariableFormat)
*/ */
public void handleDebugEvents( ICDIEvent[] events ) public void changeFormat( CVariableFormat format ) throws DebugException {
{
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.debug.core.model.IVariable#getValue() * @see org.eclipse.cdt.debug.core.model.ICastToArray#canCastToArray()
*/ */
public IValue getValue() throws DebugException public boolean canCastToArray() {
{ return false;
if ( fArrayPartitionValue == null )
{
fArrayPartitionValue = new CArrayPartitionValue( this, fCDIVariable, getStart(), getEnd() );
}
return fArrayPartitionValue;
} }
static public List splitArray( CDebugElement parent, ICDIVariable cdiVariable, int start, int end ) throws DebugException /* (non-Javadoc)
{ * @see org.eclipse.cdt.debug.core.model.ICastToArray#castToArray(int, int)
*/
public void castToArray( int startIndex, int length ) throws DebugException {
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IValueModification#setValue(java.lang.String)
*/
public void setValue( String expression ) throws DebugException {
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IValueModification#setValue(org.eclipse.debug.core.model.IValue)
*/
public void setValue( IValue value ) throws DebugException {
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IValueModification#supportsValueModification()
*/
public boolean supportsValueModification() {
return false;
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IValueModification#verifyValue(java.lang.String)
*/
public boolean verifyValue( String expression ) throws DebugException {
return false;
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IValueModification#verifyValue(org.eclipse.debug.core.model.IValue)
*/
public boolean verifyValue( IValue value ) throws DebugException {
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICastToType#canCast()
*/
public boolean canCast() {
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICastToType#getCurrentType()
*/
public String getCurrentType() {
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICastToType#cast(java.lang.String)
*/
public void cast( String type ) throws DebugException {
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICastToType#restoreOriginal()
*/
public void restoreOriginal() throws DebugException {
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICastToType#isCasted()
*/
public boolean isCasted() {
return false;
}
private ICDIVariableObject getVariableObject() throws CDIException {
if ( fCDIVariableObject == null ) {
fCDIVariableObject = getCDISession().getVariableManager().getVariableObjectAsArray( getCDIVariable(), getStart(), getEnd() - getStart() + 1 );
}
return fCDIVariableObject;
}
private ICDIVariable getCDIVariable() {
return fCDIVariable;
}
private int getEnd() {
return fEnd;
}
private int getStart() {
return fStart;
}
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 len = end - start + 1;
int perSlot = 1; int perSlot = 1;
while( len > perSlot * SLOT_SIZE ) while( len > perSlot * SLOT_SIZE ) {
{
perSlot *= SLOT_SIZE; perSlot *= SLOT_SIZE;
} }
if ( perSlot == 1 ) if ( perSlot == 1 ) {
{ try {
try
{
ICDIValue value = cdiVariable.getValue(); ICDIValue value = cdiVariable.getValue();
if ( value instanceof ICDIArrayValue ) if ( value instanceof ICDIArrayValue ) {
{
ICDIVariable[] cdiVars = ((ICDIArrayValue)value).getVariables( start, len ); ICDIVariable[] cdiVars = ((ICDIArrayValue)value).getVariables( start, len );
for ( int i = 0; i < cdiVars.length; ++i ) for( int i = 0; i < cdiVars.length; ++i )
children.add( new CModificationVariable( parent, cdiVars[i] ) ); children.add( CVariableFactory.createVariable( parent, cdiVars[i] ) );
} }
} }
catch( CDIException e ) catch( CDIException e ) {
{ // children.add( CVariableFactory.createVariableWithError( parent, e.getMessage() ) );
children.add( new CModificationVariable( parent, new CVariable.ErrorVariable( null, e ) ) );
} }
} }
else else {
{
int pos = start; int pos = start;
while( pos <= end ) while( pos <= end ) {
{ if ( pos + perSlot > end ) {
if ( pos + perSlot > end )
{
perSlot = end - pos + 1; perSlot = end - pos + 1;
} }
children.add( new CArrayPartition( parent, cdiVariable, pos, pos + perSlot - 1 ) ); children.add( new CArrayPartition( parent, cdiVariable, pos, pos + perSlot - 1 ) );
@ -148,81 +289,34 @@ public class CArrayPartition extends CVariable
return children; return children;
} }
protected int getStart()
{
return fStart;
}
protected int getEnd()
{
return fEnd;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICVariable#canEnableDisable() * @see org.eclipse.cdt.debug.internal.core.model.AbstractCVariable#getExpressionString()
*/ */
public boolean canEnableDisable() public String getExpressionString() throws DebugException {
{ if ( fQualifiedName == null ) {
return false; try {
} if ( getVariableObject() != null ) {
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICVariable#getType()
*/
public ICType getType() throws DebugException
{
if ( fType == null )
{
try
{
ICDIVariableObject varObject = getVariableObject();
if ( varObject != null )
fType = new CType( varObject.getType() );
}
catch (CDIException e)
{
requestFailed( CoreModelMessages.getString( "CArrayPartition.0" ), e ); //$NON-NLS-1$
}
}
return fType;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICVariable#hasChildren()
*/
public boolean hasChildren()
{
return true;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.internal.core.model.CVariable#getQualifiedName()
*/
protected String getQualifiedName() throws DebugException
{
if ( fQualifiedName == null )
{
try
{
if ( getVariableObject() != null )
{
fQualifiedName = getVariableObject().getQualifiedName(); fQualifiedName = getVariableObject().getQualifiedName();
} }
} }
catch( CDIException e ) catch( CDIException e ) {
{
requestFailed( CoreModelMessages.getString( "CArrayPartition.1" ), e ); //$NON-NLS-1$ requestFailed( CoreModelMessages.getString( "CArrayPartition.1" ), e ); //$NON-NLS-1$
} }
} }
return fQualifiedName; return fQualifiedName;
} }
private ICDIVariableObject getVariableObject() throws CDIException /* (non-Javadoc)
{ * @see org.eclipse.cdt.debug.internal.core.model.AbstractCVariable#dispose()
if ( fCDIVariableObject == null ) */
{ public void dispose() {
fCDIVariableObject = getCDISession().getVariableManager().getVariableObjectAsArray( fCDIVariable, getStart(), getEnd() - getStart() + 1 ); if ( fType != null ) {
((CType)fType).dispose();
fType = null;
}
if ( fArrayPartitionValue != null ) {
fArrayPartitionValue.dispose();
fArrayPartitionValue = null;
} }
return fCDIVariableObject;
} }
} }

View file

@ -8,27 +8,21 @@
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.debug.internal.core.model; package org.eclipse.cdt.debug.internal.core.model;
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.ICExpressionEvaluator;
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;
/** /**
* * A value for an array partition.
* The value for an array partition.
*
* @since Sep 9, 2002
*/ */
public class CArrayPartitionValue extends CDebugElement implements ICValue public class CArrayPartitionValue extends AbstractCValue {
{
/** /**
* The underlying CDI variable. * The underlying CDI variable.
*/ */
@ -37,7 +31,7 @@ public class CArrayPartitionValue extends CDebugElement implements ICValue
/** /**
* Parent variable. * Parent variable.
*/ */
private CVariable fParent = null; private AbstractCVariable fParent = null;
/** /**
* List of child variables. * List of child variables.
@ -50,10 +44,8 @@ public class CArrayPartitionValue extends CDebugElement implements ICValue
/** /**
* Constructor for CArrayPartitionValue. * Constructor for CArrayPartitionValue.
* @param target
*/ */
public CArrayPartitionValue( CVariable parent, ICDIVariable cdiVariable, int start, int end ) public CArrayPartitionValue( AbstractCVariable parent, ICDIVariable cdiVariable, int start, int end ) {
{
super( (CDebugTarget)parent.getDebugTarget() ); super( (CDebugTarget)parent.getDebugTarget() );
fCDIVariable = cdiVariable; fCDIVariable = cdiVariable;
fParent = parent; fParent = parent;
@ -61,115 +53,108 @@ public class CArrayPartitionValue extends CDebugElement implements ICValue
fEnd = end; fEnd = end;
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.IValue#getReferenceTypeName() * @see org.eclipse.debug.core.model.IValue#getReferenceTypeName()
*/ */
public String getReferenceTypeName() throws DebugException public String getReferenceTypeName() throws DebugException {
{ return ( getParentVariable() != null ) ? getParentVariable().getReferenceTypeName() : null;
return null;
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.IValue#getValueString() * @see org.eclipse.debug.core.model.IValue#getValueString()
*/ */
public String getValueString() throws DebugException public String getValueString() throws DebugException {
{ return ""; //$NON-NLS-1$
return null;
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.IValue#isAllocated() * @see org.eclipse.debug.core.model.IValue#isAllocated()
*/ */
public boolean isAllocated() throws DebugException public boolean isAllocated() throws DebugException {
{
return true; return true;
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.IValue#getVariables() * @see org.eclipse.debug.core.model.IValue#getVariables()
*/ */
public IVariable[] getVariables() throws DebugException public IVariable[] getVariables() throws DebugException {
{
List list = getVariables0(); List list = getVariables0();
return (IVariable[])list.toArray( new IVariable[list.size()] ); return (IVariable[])list.toArray( new IVariable[list.size()] );
} }
protected synchronized List getVariables0() throws DebugException protected synchronized List getVariables0() throws DebugException {
{
if ( !isAllocated() || !hasVariables() ) if ( !isAllocated() || !hasVariables() )
return Collections.EMPTY_LIST; return Collections.EMPTY_LIST;
if ( fVariables.size() == 0 ) if ( fVariables.size() == 0 ) {
{
fVariables = CArrayPartition.splitArray( this, getCDIVariable(), getStart(), getEnd() ); fVariables = CArrayPartition.splitArray( this, getCDIVariable(), getStart(), getEnd() );
} }
return fVariables; return fVariables;
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.IValue#hasVariables() * @see org.eclipse.debug.core.model.IValue#hasVariables()
*/ */
public boolean hasVariables() throws DebugException public boolean hasVariables() throws DebugException {
{
return true; return true;
} }
protected int getStart() protected int getStart() {
{
return fStart; return fStart;
} }
protected int getEnd() protected int getEnd() {
{
return fEnd; return fEnd;
} }
public void setChanged( boolean changed ) throws DebugException public void setChanged( boolean changed ) throws DebugException {
{
Iterator it = fVariables.iterator(); Iterator it = fVariables.iterator();
while( it.hasNext() ) while( it.hasNext() ) {
{
((CVariable)it.next()).setChanged( changed ); ((CVariable)it.next()).setChanged( changed );
} }
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.debug.core.model.ICValue#computeDetail() * @see org.eclipse.cdt.debug.core.model.ICValue#computeDetail()
*/ */
public String evaluateAsExpression() public String evaluateAsExpression() {
{
ICExpressionEvaluator ee = (ICExpressionEvaluator)getDebugTarget().getAdapter( ICExpressionEvaluator.class ); ICExpressionEvaluator ee = (ICExpressionEvaluator)getDebugTarget().getAdapter( ICExpressionEvaluator.class );
String valueString = null; String valueString = null;
if ( ee != null && ee.canEvaluate() ) if ( ee != null && ee.canEvaluate() ) {
{ try {
try
{
if ( getParentVariable() != null ) if ( getParentVariable() != null )
valueString = ee.evaluateExpressionToString( getParentVariable().getQualifiedName() ); valueString = ee.evaluateExpressionToString( getParentVariable().getExpressionString() );
} }
catch( DebugException e ) catch( DebugException e ) {
{
valueString = e.getMessage(); valueString = e.getMessage();
} }
} }
return valueString; return valueString;
} }
public CVariable getParentVariable() public AbstractCVariable getParentVariable() {
{
return fParent; return fParent;
} }
protected ICDIVariable getCDIVariable() protected ICDIVariable getCDIVariable() {
{
return fCDIVariable; return fCDIVariable;
} }
public void dispose() public void dispose() {
{
Iterator it = fVariables.iterator(); Iterator it = fVariables.iterator();
while( it.hasNext() ) while( it.hasNext() ) {
{ ((AbstractCVariable)it.next()).dispose();
((CVariable)it.next()).dispose();
} }
} }
} }

View file

@ -34,7 +34,6 @@ import org.eclipse.cdt.debug.core.cdi.ICDIBreakpointHit;
import org.eclipse.cdt.debug.core.cdi.ICDIConfiguration; import org.eclipse.cdt.debug.core.cdi.ICDIConfiguration;
import org.eclipse.cdt.debug.core.cdi.ICDIEndSteppingRange; import org.eclipse.cdt.debug.core.cdi.ICDIEndSteppingRange;
import org.eclipse.cdt.debug.core.cdi.ICDIErrorInfo; import org.eclipse.cdt.debug.core.cdi.ICDIErrorInfo;
import org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager;
import org.eclipse.cdt.debug.core.cdi.ICDILocation; import org.eclipse.cdt.debug.core.cdi.ICDILocation;
import org.eclipse.cdt.debug.core.cdi.ICDISession; import org.eclipse.cdt.debug.core.cdi.ICDISession;
import org.eclipse.cdt.debug.core.cdi.ICDISessionObject; import org.eclipse.cdt.debug.core.cdi.ICDISessionObject;
@ -1294,14 +1293,8 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv
* @see org.eclipse.debug.core.IExpressionListener#expressionRemoved(org.eclipse.debug.core.model.IExpression) * @see org.eclipse.debug.core.IExpressionListener#expressionRemoved(org.eclipse.debug.core.model.IExpression)
*/ */
public void expressionRemoved( IExpression expression ) { public void expressionRemoved( IExpression expression ) {
if ( expression != null && expression.getDebugTarget().equals( this ) && expression instanceof CExpression ) { if ( expression instanceof CExpression && expression.getDebugTarget().equals( this ) ) {
ICDIExpressionManager em = getCDISession().getExpressionManager(); ((CExpression)expression).dispose();
try {
em.destroyExpression( ((CExpression)expression).getCDIExpression() );
}
catch( CDIException e ) {
// do nothing
}
} }
} }

View file

@ -12,139 +12,88 @@ 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.ICDebugConstants; import org.eclipse.cdt.debug.core.ICDebugConstants;
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.ICDIExpression; import org.eclipse.cdt.debug.core.cdi.model.ICDIExpression;
import org.eclipse.cdt.debug.core.cdi.model.ICDITarget; import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable;
import org.eclipse.cdt.debug.core.cdi.model.ICDIVariableObject; import org.eclipse.cdt.debug.core.cdi.model.ICDIVariableObject;
import org.eclipse.cdt.debug.core.model.CVariableFormat;
import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.model.IExpression; import org.eclipse.debug.core.model.IExpression;
import org.eclipse.debug.core.model.IValue; import org.eclipse.debug.core.model.IValue;
/** /**
* * Represents an expression in the CDI model.
* Enter type comment.
*
* @since Sep 17, 2002
*/ */
public class CExpression extends CModificationVariable public class CExpression extends CVariable implements IExpression {
implements IExpression
{
/** /**
* Constructor for CExpression. * Constructor for CExpression.
* @param target
* @param cdiExpression
*/ */
public CExpression( CDebugTarget target, ICDIExpression cdiExpression ) public CExpression( CDebugTarget target, ICDIExpression cdiExpression ) {
{
super( target, cdiExpression ); super( target, cdiExpression );
fFormat = CDebugCorePlugin.getDefault().getPluginPreferences().getInt( ICDebugConstants.PREF_DEFAULT_EXPRESSION_FORMAT ); setFormat( CVariableFormat.getFormat( CDebugCorePlugin.getDefault().getPluginPreferences().getInt( ICDebugConstants.PREF_DEFAULT_EXPRESSION_FORMAT ) ) );
} }
/** /**
* Constructor for CExpression. * Constructor for CExpression.
* @param target
* @param cdiExpression
*/ */
public CExpression( CDebugTarget target, ICDIVariableObject cdiVariableObject ) public CExpression( CDebugTarget target, ICDIVariableObject cdiVariableObject ) {
{
super( target, cdiVariableObject ); super( target, cdiVariableObject );
fFormat = CDebugCorePlugin.getDefault().getPluginPreferences().getInt( ICDebugConstants.PREF_DEFAULT_EXPRESSION_FORMAT ); setFormat( CVariableFormat.getFormat( CDebugCorePlugin.getDefault().getPluginPreferences().getInt( ICDebugConstants.PREF_DEFAULT_EXPRESSION_FORMAT ) ) );
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.debug.core.model.IExpression#getExpressionText() * @see org.eclipse.debug.core.model.IExpression#getExpressionText()
*/ */
public String getExpressionText() public String getExpressionText() {
{ try {
try
{
return getName(); return getName();
} }
catch( DebugException e ) catch( DebugException e ) {
{
} }
return null; return null;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.debug.core.model.IExpression#getValue() * @see org.eclipse.debug.core.model.IVariable#getValue()
*/ */
public IValue getValue() public IValue getValue() {
{ try {
try
{
return super.getValue(); return super.getValue();
} }
catch( DebugException e ) catch( DebugException e ) {
{
} }
return null; return null;
} }
public void dispose() /* (non-Javadoc)
{ * @see org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener#handleDebugEvents(org.eclipse.cdt.debug.core.cdi.event.ICDIEvent[])
super.dispose();
try {
ICDIExpression cdiExpression = getCDIExpression();
if ( cdiExpression != null ) {
getCDISession().getExpressionManager().destroyExpression( cdiExpression );
}
}
catch( CDIException e ) {
DebugPlugin.log( e );
}
}
protected ICDIExpression getCDIExpression() throws CDIException
{
ICDIVariable var = getCDIVariable();
return ( var instanceof ICDIExpression ) ? (ICDIExpression)var : null;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener#handleDebugEvents(ICDIEvent)
*/ */
public void handleDebugEvents( ICDIEvent[] events ) public void handleDebugEvents( ICDIEvent[] events ) {
{ for( int i = 0; i < events.length; i++ ) {
for (int i = 0; i < events.length; i++)
{
ICDIEvent event = events[i]; ICDIEvent event = events[i];
if ( event instanceof ICDIResumedEvent ) if ( event instanceof ICDIResumedEvent ) {
{ if ( event.getSource() instanceof ICDITarget && getCDITarget().equals( event.getSource() ) ) {
if ( event.getSource() instanceof ICDITarget && getCDITarget().equals( event.getSource() ) ) setChanged( false );
{
try
{
setChanged( false );
}
catch( DebugException e )
{
CDebugCorePlugin.log( e );
}
} }
break; break;
} }
} }
super.handleDebugEvents(events); super.handleDebugEvents( events );
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICVariable#isEnabled() * @see org.eclipse.cdt.debug.core.model.ICVariable#isEnabled()
*/ */
public boolean isEnabled() public boolean isEnabled() {
{
return true; return true;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICVariable#canEnableDisable() * @see org.eclipse.cdt.debug.core.model.ICVariable#canEnableDisable()
*/ */
public boolean canEnableDisable() public boolean canEnableDisable() {
{
return false; return false;
} }
} }

View file

@ -7,116 +7,29 @@
* *
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
***********************************************************************/ ***********************************************************************/
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.cdi.model.ICDIVariableObject;
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.cdt.debug.core.model.ICGlobalVariable; import org.eclipse.cdt.debug.core.model.ICGlobalVariable;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IValue;
/** /**
* * Represents a global variable.
* Enter type comment.
*
* @since: Oct 2, 2002
*/ */
public class CGlobalVariable extends CModificationVariable implements ICGlobalVariable public class CGlobalVariable extends CVariable implements ICGlobalVariable {
{
/** /**
* Constructor for CGlobalVariable. * Constructor for CGlobalVariable.
* @param parent
* @param cdiVariable
*/ */
public CGlobalVariable( CDebugElement parent, ICDIVariable cdiVariable ) protected CGlobalVariable( CDebugElement parent, ICDIVariableObject cdiVariableObject ) {
{ super( parent, cdiVariableObject );
super( parent, cdiVariable );
} }
/** /**
* Returns the current value of this variable. The value * Constructor for CGlobalVariable.
* is cached.
*
* @see org.eclipse.debug.core.model.IVariable#getValue()
*/ */
public IValue getValue() throws DebugException protected CGlobalVariable( CDebugElement parent, ICDIVariableObject cdiVariableObject, String message ) {
{ super( parent, cdiVariableObject, message );
if ( !isEnabled() )
return fDisabledValue;
if ( fValue == null )
{
ICDIValue cdiValue = getCurrentValue();
if ( cdiValue instanceof ICDIArrayValue )
{
ICDIVariable var = null;
try
{
var = getCDIVariable();
}
catch( CDIException e )
{
requestFailed( "", e ); //$NON-NLS-1$
}
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;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener#handleDebugEvents(ICDIEvent)
*/
public void handleDebugEvents( ICDIEvent[] events )
{
super.handleDebugEvents( events );
for (int i = 0; i < events.length; i++)
{
ICDIEvent event = events[i];
ICDIObject source = event.getSource();
if (source == null)
continue;
if ( source.getTarget().equals( getCDITarget() ) )
{
if ( event instanceof ICDIResumedEvent )
{
try
{
setChanged( false );
}
catch( DebugException e )
{
CDebugCorePlugin.log( e );
}
}
}
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.internal.core.model.CVariable#dispose()
*/
public void dispose() {
if ( getShadow() != null )
getShadow().dispose();
try {
getCDISession().getVariableManager().destroyVariable( getCDIVariable() );
}
catch( CDIException e ) {
}
super.dispose();
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -1,115 +0,0 @@
/*******************************************************************************
* Copyright (c) 2000, 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.debug.internal.core.model;
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.cdi.model.ICDIVariableObject;
import org.eclipse.cdt.debug.core.model.CDebugElementState;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IValue;
import org.eclipse.debug.core.model.IValueModification;
/**
*
* Common functionality for variables that support value modification
*
* @since Aug 9, 2002
*/
public class CModificationVariable extends CVariable
{
/**
* Constructor for CModificationVariable.
* @param parent
* @param cdiVariable
*/
public CModificationVariable( CDebugElement parent, ICDIVariableObject cdiVariableObject )
{
super( parent, cdiVariableObject );
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IValueModification#supportsValueModification()
*/
public boolean supportsValueModification()
{
CDebugTarget target = (CDebugTarget)getDebugTarget().getAdapter( CDebugTarget.class );
return ( target != null && CDebugElementState.SUSPENDED.equals( target.getState() ) && isEditable() );
}
/**
* @see IValueModification#verifyValue(String)
*/
public boolean verifyValue( String expression )
{
return true;
}
/**
* @see IValueModification#verifyValue(IValue)
*/
public boolean verifyValue( IValue value )
{
return value.getDebugTarget().equals( getDebugTarget() );
}
/**
* @see IValueModification#setValue(String)
*/
public final void setValue( String expression ) throws DebugException
{
String newExpression = processExpression( expression );
ICDIVariable cdiVariable = null;
try
{
cdiVariable = getCDIVariable();
if ( cdiVariable != null )
cdiVariable.setValue( newExpression );
else
requestFailed( CoreModelMessages.getString( "CModificationVariable.0" ), null ); //$NON-NLS-1$
}
catch( CDIException e )
{
targetRequestFailed( e.getMessage(), null );
}
}
/**
* Set this variable's value to the given value
*/
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.internal.core.CModificationVariable#setValue(ICDIValue)
*/
protected void setValue( ICDIValue value ) throws DebugException
{
ICDIVariable cdiVariable = null;
try
{
cdiVariable = getCDIVariable();
if ( cdiVariable != null )
cdiVariable.setValue( value );
else
requestFailed( CoreModelMessages.getString( "CModificationVariable.1" ), null ); //$NON-NLS-1$
}
catch( CDIException e )
{
targetRequestFailed( e.getMessage(), null );
}
}
private String processExpression( String oldExpression ) throws DebugException
{
return oldExpression;
}
}

View file

@ -13,70 +13,44 @@ 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.ICDebugConstants; import org.eclipse.cdt.debug.core.ICDebugConstants;
import org.eclipse.cdt.debug.core.cdi.model.ICDIRegister; import org.eclipse.cdt.debug.core.cdi.model.ICDIRegister;
import org.eclipse.cdt.debug.core.cdi.model.ICDIVariableObject; import org.eclipse.cdt.debug.core.cdi.model.ICDIRegisterObject;
import org.eclipse.cdt.debug.core.model.CVariableFormat;
import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IRegister; import org.eclipse.debug.core.model.IRegister;
import org.eclipse.debug.core.model.IRegisterGroup; import org.eclipse.debug.core.model.IRegisterGroup;
import org.eclipse.debug.core.model.IValue;
/** /**
* * Represents a register in the CDI model.
* Enter type comment.
*
* @since Sep 16, 2002
*/ */
public class CRegister extends CGlobalVariable implements IRegister public class CRegister extends CGlobalVariable implements IRegister {
{
public static class ErrorRegister extends ErrorVariable implements ICDIRegister /**
{ * Constructor for CRegister.
public ErrorRegister( ICDIVariableObject varObject, Exception e ) */
{ protected CRegister( CRegisterGroup parent, ICDIRegister cdiRegister ) {
super( varObject, e ); super( parent, cdiRegister );
} setFormat( CVariableFormat.getFormat( CDebugCorePlugin.getDefault().getPluginPreferences().getInt( ICDebugConstants.PREF_DEFAULT_REGISTER_FORMAT ) ) );
} }
/** /**
* Constructor for CRegister. * Constructor for CRegister.
* @param parent
* @param cdiVariable
*/ */
public CRegister( CRegisterGroup parent, ICDIRegister cdiRegister ) protected CRegister( CRegisterGroup parent, ICDIRegisterObject registerObject, String message ) {
{ super( parent, registerObject, message );
super( parent, cdiRegister ); setFormat( CVariableFormat.getFormat( CDebugCorePlugin.getDefault().getPluginPreferences().getInt( ICDebugConstants.PREF_DEFAULT_REGISTER_FORMAT ) ) );
fFormat = CDebugCorePlugin.getDefault().getPluginPreferences().getInt( ICDebugConstants.PREF_DEFAULT_REGISTER_FORMAT );
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.debug.core.model.IRegister#getRegisterGroup() * @see org.eclipse.debug.core.model.IRegister#getRegisterGroup()
*/ */
public IRegisterGroup getRegisterGroup() throws DebugException public IRegisterGroup getRegisterGroup() throws DebugException {
{
return (IRegisterGroup)getParent(); return (IRegisterGroup)getParent();
} }
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IVariable#hasValueChanged()
*/
public boolean hasValueChanged() throws DebugException
{
try {
IValue value = getValue();
if ( value != null )
{
return ( value.hasVariables() ) ? false : fChanged;
}
}
catch( DebugException e ) {
// ignore to prevent logging.
}
return false;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICVariable#isEnabled() * @see org.eclipse.cdt.debug.core.model.ICVariable#isEnabled()
*/ */
public boolean isEnabled() public boolean isEnabled() {
{
return true; return true;
} }
} }

View file

@ -14,12 +14,11 @@ import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.model.ICDIRegister; import org.eclipse.cdt.debug.core.cdi.model.ICDIRegister;
import org.eclipse.cdt.debug.core.cdi.model.ICDIRegisterObject; import org.eclipse.cdt.debug.core.cdi.model.ICDIRegisterObject;
import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.model.IRegister; import org.eclipse.debug.core.model.IRegister;
import org.eclipse.debug.core.model.IRegisterGroup; import org.eclipse.debug.core.model.IRegisterGroup;
/** /**
* Represents a group of registers of a debug target. * Represents a group of registers.
*/ */
public class CRegisterGroup extends CDebugElement implements IRegisterGroup { public class CRegisterGroup extends CDebugElement implements IRegisterGroup {
@ -39,32 +38,31 @@ public class CRegisterGroup extends CDebugElement implements IRegisterGroup {
fRegisters = new IRegister[regObjects.length]; fRegisters = new IRegister[regObjects.length];
} }
/* /* (non-Javadoc)
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.IRegisterGroup#getName() * @see org.eclipse.debug.core.model.IRegisterGroup#getName()
*/ */
public String getName() throws DebugException { public String getName() throws DebugException {
return fName; return fName;
} }
/* /* (non-Javadoc)
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.IRegisterGroup#getRegisters() * @see org.eclipse.debug.core.model.IRegisterGroup#getRegisters()
*/ */
public IRegister[] getRegisters() throws DebugException { public IRegister[] getRegisters() throws DebugException {
for ( int i = 0; i < fRegisters.length; ++i ) { for ( int i = 0; i < fRegisters.length; ++i ) {
if ( fRegisters[i] == null ) { if ( fRegisters[i] == null ) {
fRegisters[i] = new CRegister( this, getCDIRegister( fRegisterObjects[i] ) ); try {
fRegisters[i] = new CRegister( this, getCDIRegister( fRegisterObjects[i] ) );
}
catch( DebugException e ) {
fRegisters[i] = new CRegister( this, fRegisterObjects[i], e.getMessage() );
}
} }
} }
return fRegisters; return fRegisters;
} }
/* /* (non-Javadoc)
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.IRegisterGroup#hasRegisters() * @see org.eclipse.debug.core.model.IRegisterGroup#hasRegisters()
*/ */
public boolean hasRegisters() throws DebugException { public boolean hasRegisters() throws DebugException {
@ -81,23 +79,20 @@ public class CRegisterGroup extends CDebugElement implements IRegisterGroup {
} }
private ICDIRegister getCDIRegister( ICDIRegisterObject ro ) throws DebugException { private ICDIRegister getCDIRegister( ICDIRegisterObject ro ) throws DebugException {
ICDIRegister register = null;
try { try {
return ((CDebugTarget)getDebugTarget()).getCDISession().getRegisterManager().createRegister( ro ); register = ((CDebugTarget)getDebugTarget()).getCDISession().getRegisterManager().createRegister( ro );
} }
catch( CDIException e ) { catch( CDIException e ) {
return new CRegister.ErrorRegister( ro, e ); requestFailed( e.getMessage(), null );
} }
return register;
} }
public void resetChangeFlags() { public void resetChangeFlags() {
for ( int i = 0; i < fRegisters.length; ++i ) { for ( int i = 0; i < fRegisters.length; ++i ) {
if ( fRegisters[i] != null ) { if ( fRegisters[i] != null ) {
try { ((CRegister)fRegisters[i]).setChanged( false );
((CRegister)fRegisters[i]).setChanged( false );
}
catch( DebugException e ) {
DebugPlugin.log( e );
}
} }
} }
} }

View file

@ -16,7 +16,6 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.ICDILocation; import org.eclipse.cdt.debug.core.cdi.ICDILocation;
import org.eclipse.cdt.debug.core.cdi.event.ICDIEvent; import org.eclipse.cdt.debug.core.cdi.event.ICDIEvent;
@ -109,7 +108,7 @@ public class CStackFrame extends CDebugElement implements ICStackFrame, IRestart
fVariables = new ArrayList( vars.size() ); fVariables = new ArrayList( vars.size() );
Iterator it = vars.iterator(); Iterator it = vars.iterator();
while( it.hasNext() ) { while( it.hasNext() ) {
fVariables.add( new CModificationVariable( this, (ICDIVariableObject)it.next() ) ); fVariables.add( CVariableFactory.createVariable( this, (ICDIVariableObject)it.next() ) );
} }
} }
else if ( refreshVariables() ) { else if ( refreshVariables() ) {
@ -140,7 +139,7 @@ public class CStackFrame extends CDebugElement implements ICStackFrame, IRestart
// add any new locals // add any new locals
Iterator newOnes = locals.iterator(); Iterator newOnes = locals.iterator();
while( newOnes.hasNext() ) { while( newOnes.hasNext() ) {
fVariables.add( new CModificationVariable( this, (ICDIVariableObject)newOnes.next() ) ); fVariables.add( CVariableFactory.createVariable( this, (ICDIVariableObject)newOnes.next() ) );
} }
} }
@ -582,14 +581,9 @@ public class CStackFrame extends CDebugElement implements ICStackFrame, IRestart
private void preserveVariables() { private void preserveVariables() {
if ( fVariables == null ) if ( fVariables == null )
return; return;
try { Iterator it = fVariables.iterator();
Iterator it = fVariables.iterator(); while( it.hasNext() ) {
while( it.hasNext() ) { ((CVariable)it.next()).setChanged( false );
((CVariable)it.next()).setChanged( false );
}
}
catch( DebugException e ) {
CDebugCorePlugin.log( e );
} }
} }
@ -597,7 +591,7 @@ public class CStackFrame extends CDebugElement implements ICStackFrame, IRestart
Iterator it = list.iterator(); Iterator it = list.iterator();
while( it.hasNext() ) { while( it.hasNext() ) {
ICDIVariableObject newVarObject = (ICDIVariableObject)it.next(); ICDIVariableObject newVarObject = (ICDIVariableObject)it.next();
if ( var.sameVariableObject( newVarObject ) ) if ( var.sameVariable( newVarObject ) )
return newVarObject; return newVarObject;
} }
return null; return null;

View file

@ -8,13 +8,13 @@
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.debug.internal.core.model; package org.eclipse.cdt.debug.internal.core.model;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIArrayType; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIArrayType;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDICharType; 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.ICDIIntegralType;
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.ICDIReferenceType;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIStructType; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIStructType;
@ -22,61 +22,46 @@ 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;
/** /**
* Enter type comment. * The CDI-based implementation of <code>ICType</code>.
*
* @since Jun 10, 2003
*/ */
public class CType implements ICType public class CType implements ICType {
{
/**
* The underlying CDI type.
*/
private ICDIType fCDIType; private ICDIType fCDIType;
public CType( ICDIType cdiType ) /**
{ * Constructor for CType.
*/
public CType( ICDIType cdiType ) {
setCDIType( cdiType ); setCDIType( cdiType );
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.type.ICType#getName() * @see org.eclipse.cdt.debug.core.model.ICType#getName()
*/ */
public String getName() public String getName() {
{
return ( fCDIType != null ) ? fCDIType.getTypeName() : null; return ( fCDIType != null ) ? fCDIType.getTypeName() : null;
} }
/* (non-Javadoc) public void dispose() {
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
*/
public Object getAdapter( Class adapter )
{
if ( ICType.class.equals( adapter ) )
return this;
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.type.ICType#dispose()
*/
public void dispose()
{
fCDIType = null; fCDIType = null;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.type.ICType#getArrayDimensions() * @see org.eclipse.cdt.debug.core.model.ICType#getArrayDimensions()
*/ */
public int[] getArrayDimensions() public int[] getArrayDimensions() {
{
int length = 0; int length = 0;
ICDIType type = getCDIType(); ICDIType type = getCDIType();
while( type instanceof ICDIArrayType ) while( type instanceof ICDIArrayType ) {
{
++length; ++length;
type = ( type instanceof ICDIDerivedType ) ? ((ICDIDerivedType)type).getComponentType() : null; type = ( type instanceof ICDIDerivedType ) ? ((ICDIDerivedType)type).getComponentType() : null;
} }
int[] dims = new int[length]; int[] dims = new int[length];
type = getCDIType(); type = getCDIType();
for ( int i = length; i > 0; --i ) for( int i = length; i > 0; --i ) {
{
dims[i - 1] = ((ICDIArrayType)type).getDimension(); dims[i - 1] = ((ICDIArrayType)type).getDimension();
type = ((ICDIDerivedType)type).getComponentType(); type = ((ICDIDerivedType)type).getComponentType();
} }
@ -84,69 +69,64 @@ public class CType implements ICType
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.type.ICType#isArray() * @see org.eclipse.cdt.debug.core.model.ICType#isArray()
*/ */
public boolean isArray() public boolean isArray() {
{
return ( getCDIType() instanceof ICDIArrayType ); return ( getCDIType() instanceof ICDIArrayType );
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.type.ICType#isCharacter() * @see org.eclipse.cdt.debug.core.model.ICType#isCharacter()
*/ */
public boolean isCharacter() public boolean isCharacter() {
{
return ( getCDIType() instanceof ICDICharType ); return ( getCDIType() instanceof ICDICharType );
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.type.ICType#isFloatingPointType() * @see org.eclipse.cdt.debug.core.model.ICType#isFloatingPointType()
*/ */
public boolean isFloatingPointType() public boolean isFloatingPointType() {
{
return ( getCDIType() instanceof ICDIFloatingPointType ); return ( getCDIType() instanceof ICDIFloatingPointType );
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.type.ICType#isPointer() * @see org.eclipse.cdt.debug.core.model.ICType#isPointer()
*/ */
public boolean isPointer() public boolean isPointer() {
{
return ( getCDIType() instanceof ICDIPointerType ); return ( getCDIType() instanceof ICDIPointerType );
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICType#isReference() * @see org.eclipse.cdt.debug.core.model.ICType#isReference()
*/ */
public boolean isReference() public boolean isReference() {
{
return ( getCDIType() instanceof ICDIReferenceType ); 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.ICType#isStructure()
*/ */
public boolean isStructure() public boolean isStructure() {
{
return ( getCDIType() instanceof ICDIStructType ); return ( getCDIType() instanceof ICDIStructType );
} }
protected ICDIType getCDIType() /* (non-Javadoc)
{ * @see org.eclipse.cdt.debug.core.model.ICType#isUnsigned()
*/
public boolean isUnsigned() {
ICDIType cdiType = getCDIType();
return ( cdiType instanceof ICDIIntegralType ) ? ((ICDIIntegralType)cdiType).isUnsigned() : false;
}
protected ICDIType getCDIType() {
return fCDIType; return fCDIType;
} }
protected void setCDIType( ICDIType type ) protected void setCDIType( ICDIType type ) {
{
fCDIType = type; fCDIType = type;
} }
protected boolean hasChildren() protected boolean isAggregate() {
{ return ( isArray() || isStructure() || isPointer() || isReference() );
ICDIType type = getCDIType();
if ( type instanceof ICDIStructType || type instanceof ICDIArrayType ||
type instanceof ICDIPointerType || type instanceof ICDIReferenceType )
return true;
return false;
} }
} }

View file

@ -8,7 +8,6 @@
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.debug.internal.core.model; package org.eclipse.cdt.debug.internal.core.model;
import java.math.BigInteger; import java.math.BigInteger;
@ -18,34 +17,30 @@ 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.CDIException; import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.ICDIFormat;
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.ICDICharValue; import org.eclipse.cdt.debug.core.cdi.model.type.ICDICharValue;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIDoubleValue; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIDoubleValue;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIFloatValue; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIFloatValue;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIIntValue; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIIntValue;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIIntegralType;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDILongLongValue; import org.eclipse.cdt.debug.core.cdi.model.type.ICDILongLongValue;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDILongValue; 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.cdi.model.type.ICDIWCharValue;
import org.eclipse.cdt.debug.core.model.CVariableFormat;
import org.eclipse.cdt.debug.core.model.ICDebugElementStatus; import org.eclipse.cdt.debug.core.model.ICDebugElementStatus;
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.ICType;
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;
/** /**
* * Represents the value of a variable in the CDI model.
* The value of a variable.
*
* @since Aug 9, 2002
*/ */
public class CValue extends CDebugElement implements ICValue public class CValue extends AbstractCValue {
{
/** /**
* Parent variable. * Parent variable.
*/ */
@ -68,37 +63,40 @@ public class CValue extends CDebugElement implements ICValue
/** /**
* Constructor for CValue. * Constructor for CValue.
* @param target
*/ */
public CValue( CVariable parent, ICDIValue cdiValue ) protected CValue( CVariable parent, ICDIValue cdiValue ) {
{
super( (CDebugTarget)parent.getDebugTarget() ); super( (CDebugTarget)parent.getDebugTarget() );
fParent = parent; fParent = parent;
fCDIValue = cdiValue; fCDIValue = cdiValue;
} }
/**
* Constructor for CValue.
*/
protected CValue( CVariable parent, String message ) {
super( (CDebugTarget)parent.getDebugTarget() );
fParent = parent;
setStatus( ICDebugElementStatus.ERROR, message );
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.debug.core.model.IValue#getReferenceTypeName() * @see org.eclipse.debug.core.model.IValue#getReferenceTypeName()
*/ */
public String getReferenceTypeName() throws DebugException public String getReferenceTypeName() throws DebugException {
{
return ( getParentVariable() != null ) ? getParentVariable().getReferenceTypeName() : null; return ( getParentVariable() != null ) ? getParentVariable().getReferenceTypeName() : null;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.debug.core.model.IValue#getValueString() * @see org.eclipse.debug.core.model.IValue#getValueString()
*/ */
public String getValueString() throws DebugException public String getValueString() throws DebugException {
{ if ( fValueString == null && getUnderlyingValue() != null ) {
if ( fValueString == null && getUnderlyingValue() != null ) try {
{
try
{
fValueString = processUnderlyingValue( getUnderlyingValue() ); fValueString = processUnderlyingValue( getUnderlyingValue() );
resetStatus();
} }
catch( CDIException e ) catch( CDIException e ) {
{ setStatus( ICDebugElementStatus.ERROR, e.getMessage() );
fValueString = e.getMessage();
} }
} }
return fValueString; return fValueString;
@ -107,42 +105,33 @@ public class CValue extends CDebugElement implements ICValue
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.debug.core.model.IValue#isAllocated() * @see org.eclipse.debug.core.model.IValue#isAllocated()
*/ */
public boolean isAllocated() throws DebugException public boolean isAllocated() throws DebugException {
{
return true; return true;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.debug.core.model.IValue#getVariables() * @see org.eclipse.debug.core.model.IValue#getVariables()
*/ */
public IVariable[] getVariables() throws DebugException public IVariable[] getVariables() throws DebugException {
{
List list = getVariables0(); List list = getVariables0();
return (IVariable[])list.toArray( new IVariable[list.size()] ); return (IVariable[])list.toArray( new IVariable[list.size()] );
} }
protected synchronized List getVariables0() throws DebugException protected synchronized List getVariables0() throws DebugException {
{
if ( !isAllocated() || !hasVariables() ) if ( !isAllocated() || !hasVariables() )
return Collections.EMPTY_LIST; return Collections.EMPTY_LIST;
if ( fVariables.size() == 0 ) if ( fVariables.size() == 0 ) {
{ try {
try
{
List vars = getCDIVariables(); List vars = getCDIVariables();
fVariables = new ArrayList( vars.size() ); fVariables = new ArrayList( vars.size() );
Iterator it = vars.iterator(); Iterator it = vars.iterator();
while( it.hasNext() ) while( it.hasNext() ) {
{ fVariables.add( CVariableFactory.createVariable( this, (ICDIVariable)it.next() ) );
fVariables.add( new CModificationVariable( this, (ICDIVariable)it.next() ) );
} }
resetStatus();
} }
catch( DebugException e ) catch( DebugException e ) {
{ setStatus( ICDebugElementStatus.ERROR, e.getMessage() );
fVariables = new ArrayList( 1 );
CModificationVariable var = new CModificationVariable( this, new CVariable.ErrorVariable( null, e ) );
var.setStatus( ICDebugElementStatus.ERROR, e.getMessage() );
fVariables.add( var );
} }
} }
return fVariables; return fVariables;
@ -151,81 +140,65 @@ public class CValue extends CDebugElement implements ICValue
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.debug.core.model.IValue#hasVariables() * @see org.eclipse.debug.core.model.IValue#hasVariables()
*/ */
public boolean hasVariables() throws DebugException public boolean hasVariables() throws DebugException {
{ try {
try
{
ICDIValue value = getUnderlyingValue(); ICDIValue value = getUnderlyingValue();
if ( value != null ) if ( value != null )
return value.getChildrenNumber() > 0; return value.getChildrenNumber() > 0;
} }
catch( CDIException e ) catch( CDIException e ) {
{
targetRequestFailed( e.getMessage(), null ); targetRequestFailed( e.getMessage(), null );
} }
return false; return false;
} }
public ICDIValue getUnderlyingValue() public ICDIValue getUnderlyingValue() {
{
return fCDIValue; return fCDIValue;
} }
protected List getCDIVariables() throws DebugException protected List getCDIVariables() throws DebugException {
{
ICDIVariable[] vars = null; ICDIVariable[] vars = null;
try try {
{
ICDIValue value = getUnderlyingValue(); ICDIValue value = getUnderlyingValue();
if ( value != null ) if ( value != null ) {
{
vars = value.getVariables(); vars = value.getVariables();
// Quick fix. // Quick fix.
// getVariables should return an empty array instead of null. // getVariables should return an empty array instead of null.
if ( vars == null ) if ( vars == null ) {
{
vars = new ICDIVariable[0]; vars = new ICDIVariable[0];
} }
} }
} }
catch( CDIException e ) catch( CDIException e ) {
{ requestFailed( e.getMessage(), e ); //$NON-NLS-1$
requestFailed( CoreModelMessages.getString( "CValue.0" ), e ); //$NON-NLS-1$
} }
return Arrays.asList( vars ); return Arrays.asList( vars );
} }
public synchronized void setChanged( boolean changed ) throws DebugException public synchronized void setChanged( boolean changed ) /*throws DebugException*/ {
{ if ( changed ) {
if ( changed )
{
fValueString = null; fValueString = null;
resetStatus();
} }
Iterator it = fVariables.iterator(); Iterator it = fVariables.iterator();
while( it.hasNext() ) while( it.hasNext() ) {
{
((CVariable)it.next()).setChanged( changed ); ((CVariable)it.next()).setChanged( changed );
} }
} }
public void dispose() public void dispose() {
{
Iterator it = fVariables.iterator(); Iterator it = fVariables.iterator();
while( it.hasNext() ) while( it.hasNext() ) {
{ ((AbstractCVariable)it.next()).dispose();
((CVariable)it.next()).dispose();
} }
} }
public CVariable getParentVariable() public CVariable getParentVariable() {
{
return fParent; return fParent;
} }
private String processUnderlyingValue( ICDIValue cdiValue ) throws CDIException private String processUnderlyingValue( ICDIValue cdiValue ) throws CDIException {
{ if ( cdiValue != null ) {
if ( cdiValue != null )
{
if ( cdiValue instanceof ICDICharValue ) if ( cdiValue instanceof ICDICharValue )
return getCharValueString( (ICDICharValue)cdiValue ); return getCharValueString( (ICDICharValue)cdiValue );
else if ( cdiValue instanceof ICDIShortValue ) else if ( cdiValue instanceof ICDIShortValue )
@ -252,259 +225,200 @@ public class CValue extends CDebugElement implements ICValue
return null; return null;
} }
private String getCharValueString( ICDICharValue value ) throws CDIException private String getCharValueString( ICDICharValue value ) throws CDIException {
{ CVariableFormat format = getParentVariable().getFormat();
switch( getParentVariable().getFormat() ) if ( CVariableFormat.NATURAL.equals( format ) ) {
{ byte byteValue = (byte)value.byteValue();
case ICDIFormat.NATURAL: return ((Character.isISOControl( (char)byteValue ) && byteValue != '\b' && byteValue != '\t' && byteValue != '\n' && byteValue != '\f' && byteValue != '\r') || byteValue < 0) ? "" : new String( new byte[]{ '\'', byteValue, '\'' } ); //$NON-NLS-1$
{ }
byte byteValue = (byte)value.byteValue(); else if ( CVariableFormat.DECIMAL.equals( format ) ) {
return ( ( Character.isISOControl( (char)byteValue ) && return (isUnsigned()) ? Integer.toString( value.shortValue() ) : Integer.toString( (byte)value.byteValue() );
byteValue != '\b' && }
byteValue != '\t' && else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) {
byteValue != '\n' && StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$
byteValue != '\f' && String stringValue = (isUnsigned()) ? Integer.toHexString( value.shortValue() ) : Integer.toHexString( (byte)value.byteValue() );
byteValue != '\r' ) || byteValue < 0 ) ? "" : new String( new byte[] { '\'', byteValue, '\'' } ); //$NON-NLS-1$ sb.append( (stringValue.length() > 2) ? stringValue.substring( stringValue.length() - 2 ) : stringValue );
} return sb.toString();
case ICDIFormat.DECIMAL:
{
return ( isUnsigned() ) ? Integer.toString( value.shortValue() ) :
Integer.toString( (byte)value.byteValue() );
}
case ICDIFormat.HEXADECIMAL:
{
StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$
String stringValue = ( isUnsigned() ) ? Integer.toHexString( value.shortValue() ) : Integer.toHexString( (byte)value.byteValue() );
sb.append( ( stringValue.length() > 2 ) ? stringValue.substring( stringValue.length() - 2 ) : stringValue );
return sb.toString();
}
} }
return null; return null;
} }
private String getShortValueString( ICDIShortValue value ) throws CDIException private String getShortValueString( ICDIShortValue value ) throws CDIException {
{ CVariableFormat format = getParentVariable().getFormat();
switch( getParentVariable().getFormat() ) if ( CVariableFormat.NATURAL.equals( format ) || CVariableFormat.DECIMAL.equals( format ) ) {
{ return (isUnsigned()) ? Integer.toString( value.intValue() ) : Short.toString( value.shortValue() );
case ICDIFormat.NATURAL: }
case ICDIFormat.DECIMAL: else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) {
return ( isUnsigned() ) ? Integer.toString( value.intValue() ) : Short.toString( value.shortValue() ); StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$
case ICDIFormat.HEXADECIMAL: String stringValue = Integer.toHexString( (isUnsigned()) ? value.intValue() : value.shortValue() );
{ sb.append( (stringValue.length() > 4) ? stringValue.substring( stringValue.length() - 4 ) : stringValue );
StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$ return sb.toString();
String stringValue = Integer.toHexString( ( isUnsigned() ) ? value.intValue() : value.shortValue() );
sb.append( ( stringValue.length() > 4 ) ? stringValue.substring( stringValue.length() - 4 ) : stringValue );
return sb.toString();
}
} }
return null; return null;
} }
private String getIntValueString( ICDIIntValue value ) throws CDIException private String getIntValueString( ICDIIntValue value ) throws CDIException {
{ CVariableFormat format = getParentVariable().getFormat();
switch( getParentVariable().getFormat() ) if ( CVariableFormat.NATURAL.equals( format ) || CVariableFormat.DECIMAL.equals( format ) ) {
{ return (isUnsigned()) ? Long.toString( value.longValue() ) : Integer.toString( value.intValue() );
case ICDIFormat.NATURAL: }
case ICDIFormat.DECIMAL: else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) {
return ( isUnsigned() ) ? Long.toString( value.longValue() ) : Integer.toString( value.intValue() ); StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$
case ICDIFormat.HEXADECIMAL: String stringValue = (isUnsigned()) ? Long.toHexString( value.longValue() ) : Integer.toHexString( value.intValue() );
{ sb.append( (stringValue.length() > 8) ? stringValue.substring( stringValue.length() - 8 ) : stringValue );
StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$ return sb.toString();
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 null; return null;
} }
private String getLongValueString( ICDILongValue value ) throws CDIException private String getLongValueString( ICDILongValue value ) throws CDIException {
{ CVariableFormat format = getParentVariable().getFormat();
switch( getParentVariable().getFormat() ) if ( CVariableFormat.NATURAL.equals( format ) || CVariableFormat.DECIMAL.equals( format ) ) {
{ return (isUnsigned()) ? Long.toString( value.longValue() ) : Integer.toString( value.intValue() );
case ICDIFormat.NATURAL: }
case ICDIFormat.DECIMAL: else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) {
return ( isUnsigned() ) ? Long.toString( value.longValue() ) : Integer.toString( value.intValue() ); StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$
case ICDIFormat.HEXADECIMAL: String stringValue = Long.toHexString( (isUnsigned()) ? value.longValue() : value.intValue() );
{ sb.append( (stringValue.length() > 8) ? stringValue.substring( stringValue.length() - 8 ) : stringValue );
StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$ return sb.toString();
String stringValue = Long.toHexString( ( isUnsigned() ) ? value.longValue() : value.intValue() );
sb.append( ( stringValue.length() > 8 ) ? stringValue.substring( stringValue.length() - 8 ) : stringValue );
return sb.toString();
}
} }
return null; return null;
} }
private String getLongLongValueString( ICDILongLongValue value ) throws CDIException private String getLongLongValueString( ICDILongLongValue value ) throws CDIException {
{ CVariableFormat format = getParentVariable().getFormat();
switch( getParentVariable().getFormat() ) if ( CVariableFormat.NATURAL.equals( format ) || CVariableFormat.DECIMAL.equals( format ) ) {
{ if ( isUnsigned() ) {
case ICDIFormat.NATURAL: BigInteger bigValue = new BigInteger( value.getValueString() );
case ICDIFormat.DECIMAL: return bigValue.toString();
{
if ( isUnsigned() )
{
BigInteger bigValue = new BigInteger( value.getValueString() );
return bigValue.toString();
}
return Long.toString( value.longValue() );
} }
case ICDIFormat.HEXADECIMAL: return Long.toString( value.longValue() );
{ }
StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$ else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) {
StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$
if ( isUnsigned() ) if ( isUnsigned() ) {
{ BigInteger bigValue = new BigInteger( value.getValueString() );
BigInteger bigValue = new BigInteger( value.getValueString() ); sb.append( bigValue.toString( 16 ) );
sb.append( bigValue.toString( 16 ) );
}
else
sb.append( Long.toHexString( value.longValue() ) );
return sb.toString();
} }
else
sb.append( Long.toHexString( value.longValue() ) );
return sb.toString();
} }
return null; return null;
} }
private String getFloatValueString( ICDIFloatValue value ) throws CDIException private String getFloatValueString( ICDIFloatValue value ) throws CDIException {
{
float floatValue = value.floatValue(); float floatValue = value.floatValue();
Float flt = new Float( floatValue ); Float flt = new Float( floatValue );
if ( flt.isNaN() || flt.isInfinite() ) if ( flt.isNaN() || flt.isInfinite() )
return ""; //$NON-NLS-1$ return ""; //$NON-NLS-1$
long longValue = flt.longValue(); long longValue = flt.longValue();
switch( getParentVariable().getFormat() ) CVariableFormat format = getParentVariable().getFormat();
{ if ( CVariableFormat.NATURAL.equals( format ) ) {
case ICDIFormat.NATURAL: return Float.toString( floatValue );
return Float.toString( floatValue ); }
case ICDIFormat.DECIMAL: else if ( CVariableFormat.DECIMAL.equals( format ) ) {
return Long.toString( longValue ); return Long.toString( longValue );
case ICDIFormat.HEXADECIMAL: }
{ else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) {
StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$ StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$
String stringValue = Long.toHexString( longValue ); String stringValue = Long.toHexString( longValue );
sb.append( ( stringValue.length() > 8 ) ? stringValue.substring( stringValue.length() - 8 ) : stringValue ); sb.append( (stringValue.length() > 8) ? stringValue.substring( stringValue.length() - 8 ) : stringValue );
return sb.toString(); return sb.toString();
}
} }
return null; return null;
} }
private String getDoubleValueString( ICDIDoubleValue value ) throws CDIException private String getDoubleValueString( ICDIDoubleValue value ) throws CDIException {
{
double doubleValue = value.doubleValue(); double doubleValue = value.doubleValue();
Double dbl = new Double( doubleValue ); Double dbl = new Double( doubleValue );
if ( dbl.isNaN() || dbl.isInfinite() ) if ( dbl.isNaN() || dbl.isInfinite() )
return ""; //$NON-NLS-1$ return ""; //$NON-NLS-1$
long longValue = dbl.longValue(); long longValue = dbl.longValue();
switch( getParentVariable().getFormat() ) CVariableFormat format = getParentVariable().getFormat();
{ if ( CVariableFormat.NATURAL.equals( format ) ) {
case ICDIFormat.NATURAL: return dbl.toString();
return dbl.toString(); }
case ICDIFormat.DECIMAL: else if ( CVariableFormat.DECIMAL.equals( format ) ) {
return Long.toString( longValue ); return Long.toString( longValue );
case ICDIFormat.HEXADECIMAL: }
{ else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) {
StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$ StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$
String stringValue = Long.toHexString( longValue ); String stringValue = Long.toHexString( longValue );
sb.append( ( stringValue.length() > 16 ) ? stringValue.substring( stringValue.length() - 16 ) : stringValue ); sb.append( (stringValue.length() > 16) ? stringValue.substring( stringValue.length() - 16 ) : stringValue );
return sb.toString(); return sb.toString();
}
} }
return null; return null;
} }
private String getPointerValueString( ICDIPointerValue value ) throws CDIException private String getPointerValueString( ICDIPointerValue value ) throws CDIException {
{
long longValue = value.pointerValue(); long longValue = value.pointerValue();
switch( getParentVariable().getFormat() ) CVariableFormat format = getParentVariable().getFormat();
{ if ( CVariableFormat.DECIMAL.equals( format ) ) {
case ICDIFormat.DECIMAL: return Long.toString( longValue );
return Long.toString( longValue ); }
case ICDIFormat.NATURAL: else if ( CVariableFormat.NATURAL.equals( format ) || CVariableFormat.HEXADECIMAL.equals( format ) ) {
case ICDIFormat.HEXADECIMAL: StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$
{ String stringValue = Long.toHexString( longValue );
StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$ sb.append( (stringValue.length() > 8) ? stringValue.substring( stringValue.length() - 8 ) : stringValue );
String stringValue = Long.toHexString( longValue ); return sb.toString();
sb.append( ( stringValue.length() > 8 ) ? stringValue.substring( stringValue.length() - 8 ) : stringValue );
return sb.toString();
}
} }
return null; return null;
} }
private String getReferenceValueString( ICDIReferenceValue value ) throws CDIException private String getReferenceValueString( ICDIReferenceValue value ) throws CDIException {
{
long longValue = value.referenceValue(); long longValue = value.referenceValue();
switch( getParentVariable().getFormat() ) CVariableFormat format = getParentVariable().getFormat();
{ if ( CVariableFormat.DECIMAL.equals( format ) ) {
case ICDIFormat.DECIMAL: return Long.toString( longValue );
return Long.toString( longValue ); }
case ICDIFormat.NATURAL: else if ( CVariableFormat.NATURAL.equals( format ) || CVariableFormat.HEXADECIMAL.equals( format ) ) {
case ICDIFormat.HEXADECIMAL: StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$
{ String stringValue = Long.toHexString( longValue );
StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$ sb.append( (stringValue.length() > 8) ? stringValue.substring( stringValue.length() - 8 ) : stringValue );
String stringValue = Long.toHexString( longValue ); return sb.toString();
sb.append( ( stringValue.length() > 8 ) ? stringValue.substring( stringValue.length() - 8 ) : stringValue );
return sb.toString();
}
} }
return null; return null;
} }
private String getWCharValueString( ICDIWCharValue value ) throws CDIException private String getWCharValueString( ICDIWCharValue value ) throws CDIException {
{ if ( getParentVariable() != null ) {
if ( getParentVariable() != null )
{
int size = getParentVariable().sizeof(); int size = getParentVariable().sizeof();
if ( size == 2 ) if ( size == 2 ) {
{ CVariableFormat format = getParentVariable().getFormat();
switch( getParentVariable().getFormat() ) if ( CVariableFormat.NATURAL.equals( format ) || CVariableFormat.DECIMAL.equals( format ) ) {
{ return (isUnsigned()) ? Integer.toString( value.intValue() ) : Short.toString( value.shortValue() );
case ICDIFormat.NATURAL: }
case ICDIFormat.DECIMAL: else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) {
return ( isUnsigned() ) ? Integer.toString( value.intValue() ) : Short.toString( value.shortValue() ); StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$
case ICDIFormat.HEXADECIMAL: String stringValue = Integer.toHexString( (isUnsigned()) ? value.intValue() : value.shortValue() );
{ sb.append( (stringValue.length() > 4) ? stringValue.substring( stringValue.length() - 4 ) : stringValue );
StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$ return sb.toString();
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 == 4 ) if ( size == 4 ) {
{ CVariableFormat format = getParentVariable().getFormat();
switch( getParentVariable().getFormat() ) if ( CVariableFormat.NATURAL.equals( format ) || CVariableFormat.DECIMAL.equals( format ) ) {
{ return (isUnsigned()) ? Long.toString( value.longValue() ) : Integer.toString( value.intValue() );
case ICDIFormat.NATURAL: }
case ICDIFormat.DECIMAL: else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) {
return ( isUnsigned() ) ? Long.toString( value.longValue() ) : Integer.toString( value.intValue() ); StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$
case ICDIFormat.HEXADECIMAL: String stringValue = (isUnsigned()) ? Long.toHexString( value.longValue() ) : Integer.toHexString( value.intValue() );
{ sb.append( (stringValue.length() > 8) ? stringValue.substring( stringValue.length() - 8 ) : stringValue );
StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$ return sb.toString();
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(); return value.getValueString();
} }
private boolean isUnsigned() private boolean isUnsigned() {
{
boolean result = false; boolean result = false;
try try {
{ ICType type = getParentVariable().getType();
if ( getParentVariable().getCDIVariable() != null ) result = type.isUnsigned();
result = ( getParentVariable().getCDIVariable().getType() instanceof ICDIIntegralType ) ?
((ICDIIntegralType)getParentVariable().getCDIVariable().getType()).isUnsigned() : false;
} }
catch( CDIException e ) catch( DebugException e ) {
{
} }
return result; return result;
} }
@ -512,32 +426,29 @@ public class CValue extends CDebugElement implements ICValue
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICValue#evaluateAsExpression() * @see org.eclipse.cdt.debug.core.model.ICValue#evaluateAsExpression()
*/ */
public String evaluateAsExpression() public String evaluateAsExpression() {
{
ICExpressionEvaluator ee = (ICExpressionEvaluator)getDebugTarget().getAdapter( ICExpressionEvaluator.class ); ICExpressionEvaluator ee = (ICExpressionEvaluator)getDebugTarget().getAdapter( ICExpressionEvaluator.class );
String valueString = null; String valueString = null;
if ( ee != null && ee.canEvaluate() ) if ( ee != null && ee.canEvaluate() ) {
{ try {
try
{
if ( getParentVariable() != null ) if ( getParentVariable() != null )
valueString = ee.evaluateExpressionToString( getParentVariable().getQualifiedName() ); valueString = ee.evaluateExpressionToString( getParentVariable().getExpressionString() );
} }
catch( DebugException e ) catch( DebugException e ) {
{
valueString = e.getMessage(); valueString = e.getMessage();
} }
} }
return valueString; return valueString;
} }
protected void reset() throws DebugException /**
{ * Invalidates the string cache.
*/
protected void reset() {
fValueString = null; fValueString = null;
Iterator it = fVariables.iterator(); Iterator it = fVariables.iterator();
while( it.hasNext() ) while( it.hasNext() ) {
{ ((CVariable)it.next()).resetValue();
((CVariable)it.next()).reset();
} }
} }
} }

View file

@ -8,37 +8,34 @@
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
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.cdt.debug.core.cdi.model.ICDIVariable;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIFloatingPointValue; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIFloatingPointValue;
import org.eclipse.debug.core.DebugException; import org.eclipse.cdt.debug.core.model.ICValue;
/** /**
* * The value factory for variable and expressions.
* Generates values for variable and expressions.
*
* @since Sep 9, 2002
*/ */
public class CValueFactory public class CValueFactory {
{
static public CValue createValue( CVariable parent, ICDIValue cdiValue ) throws DebugException static public CValue createValue( CVariable parent, ICDIValue cdiValue ) {
{
if ( cdiValue instanceof ICDIFloatingPointValue ) { if ( cdiValue instanceof ICDIFloatingPointValue ) {
return new CFloatingPointValue( parent, cdiValue ); return new CFloatingPointValue( parent, cdiValue );
} }
return new CValue( parent, cdiValue ); return new CValue( parent, cdiValue );
} }
static public CArrayPartitionValue createArrayValue( CVariable parent, ICDIVariable cdiVariable, int start, int end ) throws DebugException static public CArrayPartitionValue createArrayValue( AbstractCVariable parent, ICDIVariable cdiVariable, int start, int end ) {
{
return new CArrayPartitionValue( parent, cdiVariable, start, end ); 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 ) {
{
return new CGlobalValue( parent, cdiValue ); return new CGlobalValue( parent, cdiValue );
} }
static public ICValue createValueWithError( CVariable parent, String message ) {
return new CValue( parent, message );
}
} }

View file

@ -0,0 +1,31 @@
/**********************************************************************
* Copyright (c) 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.debug.internal.core.model;
import org.eclipse.cdt.debug.core.cdi.model.ICDIVariableObject;
/**
* Provides factory methods for the variable types.
*/
public class CVariableFactory {
public static CVariable createVariable( CDebugElement parent, ICDIVariableObject cdiVariableObject ) {
return new CVariable( parent, cdiVariableObject );
}
public static CVariable createVariableWithError( CDebugElement parent, ICDIVariableObject cdiVariableObject, String message ) {
return new CVariable( parent, cdiVariableObject, message );
}
public static CGlobalVariable createGlobalVariable( CDebugElement parent, ICDIVariableObject cdiVariableObject ) {
return new CGlobalVariable( parent, cdiVariableObject );
}
}

View file

@ -23,7 +23,7 @@ CThread.3=Suspend failed.
CThread.4=Step failed. CThread.4=Step failed.
CThread.5=Step failed. CThread.5=Step failed.
CThread.6=Step failed. CThread.6=Step failed.
CValue.0=not available: CValue.0=not available: {0}
CVariable.0=not available: {0} CVariable.0=not available: {0}
CVariable.1=not available: {0} CVariable.1=not available: {0}
CVariable.2=Variable does not support value modification. CVariable.2=Variable does not support value modification.

View file

@ -1,3 +1,14 @@
2004-08-04 Mikhail Khodjaiants
New implementation of the variable types.
* CDTDebugModelPresentation.java
* CastToArrayActionDelegate.java
* CastToTypeActionDelegate.java
* DecVariableFormatActionDelegate.java
* HexVariableFormatActionDelegate.java
* NaturalVariableFormatActionDelegate.java
* RestoreDefaultTypeActionDelegate.java
* VariableFormatActionDelegate.java
2004-07-30 Mikhail Khodjaiants 2004-07-30 Mikhail Khodjaiants
Display the error message in the variable's label if the value of variable can not be retrieved. Display the error message in the variable's label if the value of variable can not be retrieved.
* CDebugUIMessages.properties * CDebugUIMessages.properties

View file

@ -478,6 +478,16 @@ public class CDTDebugModelPresentation extends LabelProvider implements IDebugMo
if ( valueString.length() > 0 ) { if ( valueString.length() > 0 ) {
result.append( " = " ).append( valueString ); //$NON-NLS-1$ result.append( " = " ).append( valueString ); //$NON-NLS-1$
} }
if ( isShowVariableTypeNames() ) {
String type = null;
try {
type = value.getReferenceTypeName();
}
catch( DebugException e ) {
}
if ( !isEmpty( type ) )
result.insert( 0, type + ' ' );
}
} }
} }
if ( !expression.isEnabled() ) { if ( !expression.isEnabled() ) {

View file

@ -280,7 +280,7 @@ public class CastToArrayActionDelegate extends ActionDelegate implements IObject
if ( selection instanceof IStructuredSelection ) { if ( selection instanceof IStructuredSelection ) {
Object element = ((IStructuredSelection)selection).getFirstElement(); Object element = ((IStructuredSelection)selection).getFirstElement();
if ( element instanceof ICastToArray ) { if ( element instanceof ICastToArray ) {
boolean enabled = ((ICastToArray)element).supportsCastToArray(); boolean enabled = ((ICastToArray)element).canCastToArray();
action.setEnabled( enabled ); action.setEnabled( enabled );
if ( enabled ) { if ( enabled ) {
setCastToArray( (ICastToArray)element ); setCastToArray( (ICastToArray)element );

View file

@ -129,7 +129,7 @@ public class CastToTypeActionDelegate extends ActionDelegate implements IObjectA
if ( selection instanceof IStructuredSelection ) { if ( selection instanceof IStructuredSelection ) {
Object element = ((IStructuredSelection)selection).getFirstElement(); Object element = ((IStructuredSelection)selection).getFirstElement();
if ( element instanceof ICastToType ) { if ( element instanceof ICastToType ) {
boolean enabled = ((ICastToType)element).supportsCasting(); boolean enabled = ((ICastToType)element).canCast();
action.setEnabled( enabled ); action.setEnabled( enabled );
if ( enabled ) { if ( enabled ) {
setCastToType( (ICastToType)element ); setCastToType( (ICastToType)element );

View file

@ -10,23 +10,17 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions; package org.eclipse.cdt.debug.internal.ui.actions;
import org.eclipse.cdt.debug.core.cdi.ICDIFormat; import org.eclipse.cdt.debug.core.model.CVariableFormat;
/** /**
* * The delegate of the "Decimal Format" action.
* Enter type comment.
*
* @since Dec 16, 2002
*/ */
public class DecVariableFormatActionDelegate extends VariableFormatActionDelegate public class DecVariableFormatActionDelegate extends VariableFormatActionDelegate {
{
/** /**
* Constructor for DecVariableFormatActionDelegate. * Constructor for DecVariableFormatActionDelegate.
* @param format
*/ */
public DecVariableFormatActionDelegate() public DecVariableFormatActionDelegate() {
{ super( CVariableFormat.DECIMAL );
super( ICDIFormat.DECIMAL );
} }
} }

View file

@ -10,22 +10,17 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions; package org.eclipse.cdt.debug.internal.ui.actions;
import org.eclipse.cdt.debug.core.cdi.ICDIFormat; import org.eclipse.cdt.debug.core.model.CVariableFormat;
/** /**
* * The delegate of the "Hexadecimal Format" action.
* Enter type comment.
*
* @since Dec 16, 2002
*/ */
public class HexVariableFormatActionDelegate extends VariableFormatActionDelegate public class HexVariableFormatActionDelegate extends VariableFormatActionDelegate {
{
/** /**
* Constructor for HexVariableFormatActionDelegate. * Constructor for HexVariableFormatActionDelegate.
* @param format
*/ */
public HexVariableFormatActionDelegate() public HexVariableFormatActionDelegate() {
{ super( CVariableFormat.HEXADECIMAL );
super( ICDIFormat.HEXADECIMAL );
} }
} }

View file

@ -10,23 +10,17 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions; package org.eclipse.cdt.debug.internal.ui.actions;
import org.eclipse.cdt.debug.core.cdi.ICDIFormat; import org.eclipse.cdt.debug.core.model.CVariableFormat;
/** /**
* * The delegate of the "Natural Format" action.
* Enter type comment.
*
* @since Dec 16, 2002
*/ */
public class NaturalVariableFormatActionDelegate extends VariableFormatActionDelegate public class NaturalVariableFormatActionDelegate extends VariableFormatActionDelegate {
{
/** /**
* Constructor for NaturalVariableFormatActionDelegate. * Constructor for NaturalVariableFormatActionDelegate.
* @param format
*/ */
public NaturalVariableFormatActionDelegate() public NaturalVariableFormatActionDelegate() {
{ super( CVariableFormat.NATURAL );
super( ICDIFormat.NATURAL );
} }
} }

View file

@ -110,6 +110,6 @@ public class RestoreDefaultTypeActionDelegate extends ActionDelegate implements
} }
protected void doAction( ICastToType castToType ) throws DebugException { protected void doAction( ICastToType castToType ) throws DebugException {
castToType.restoreDefault(); castToType.restoreOriginal();
} }
} }

View file

@ -13,7 +13,7 @@ package org.eclipse.cdt.debug.internal.ui.actions;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import org.eclipse.cdt.debug.core.cdi.ICDIFormat; import org.eclipse.cdt.debug.core.model.CVariableFormat;
import org.eclipse.cdt.debug.core.model.ICVariable; import org.eclipse.cdt.debug.core.model.ICVariable;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin; import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.core.runtime.MultiStatus; import org.eclipse.core.runtime.MultiStatus;
@ -28,18 +28,18 @@ import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindow;
/** /**
* The delegate of the "Format" action. * The superclass of the all format action delegates.
*/ */
public class VariableFormatActionDelegate implements IObjectActionDelegate { public abstract class VariableFormatActionDelegate implements IObjectActionDelegate {
private int fFormat = ICDIFormat.NATURAL; private CVariableFormat fFormat = CVariableFormat.NATURAL;
private ICVariable[] fVariables = null; private ICVariable[] fVariables = null;
/** /**
* Constructor for VariableFormatActionDelegate. * Constructor for VariableFormatActionDelegate.
*/ */
public VariableFormatActionDelegate( int format ) { public VariableFormatActionDelegate( CVariableFormat format ) {
fFormat = format; fFormat = format;
} }
@ -91,7 +91,7 @@ public class VariableFormatActionDelegate implements IObjectActionDelegate {
Object o = i.next(); Object o = i.next();
if ( o instanceof ICVariable ) { if ( o instanceof ICVariable ) {
ICVariable var = (ICVariable)o; ICVariable var = (ICVariable)o;
boolean enabled = var.isEditable(); boolean enabled = var.supportsFormatting();
action.setEnabled( enabled ); action.setEnabled( enabled );
if ( enabled ) { if ( enabled ) {
action.setChecked( var.getFormat() == fFormat ); action.setChecked( var.getFormat() == fFormat );
@ -109,7 +109,7 @@ public class VariableFormatActionDelegate implements IObjectActionDelegate {
protected void doAction( ICVariable[] vars ) throws DebugException { protected void doAction( ICVariable[] vars ) throws DebugException {
for( int i = 0; i < vars.length; i++ ) { for( int i = 0; i < vars.length; i++ ) {
vars[i].setFormat( fFormat ); vars[i].changeFormat( fFormat );
} }
} }