1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-31 21:05:37 +02:00

Implementing the core support of UI features for types and internal formating (instead of using the format features provided by gdb).

This commit is contained in:
Mikhail Khodjaiants 2003-06-04 16:13:14 +00:00
parent 55253c4df9
commit 6472982fc0
8 changed files with 287 additions and 57 deletions

View file

@ -1,3 +1,14 @@
2003-06-04 Mikhail Khodjaiants
Implementing the core support of UI features for types and internal formating
(instead of using the format features provided by gdb).
* src/org/eclipse/cdt/debug/core/cdi/model/type/ICDIFloatingPointValue.java
* src/org/eclipse/cdt/debug/core/cdi/model/type/ICDIPointerValue.java
* src/org/eclipse/cdt/debug/core/cdi/model/type/ICDIReferenceValue.java
* src/org/eclipse/cdt/debug/core/cdi/model/ICDIPointerValue.java: removed
* src/org/eclipse/cdt/debug/core/model/ICVariable.java
* src/org/eclipse/cdt/debug/internal/core/model/CVariable.java
* src/org/eclipse/cdt/debug/core/model/CValue.java
2003-05-29 Alain Magloire 2003-05-29 Alain Magloire
* src/org/eclipse/cdt/debug/core/cdi/model/type/ICDIIntegralValue.java: * src/org/eclipse/cdt/debug/core/cdi/model/type/ICDIIntegralValue.java:

View file

@ -1,15 +0,0 @@
/*
*(c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*
*/
package org.eclipse.cdt.debug.core.cdi.model;
/**
*
* Represents a value of a pointer type.
*
* @since Aug 9, 2002
*/
public interface ICDIPointerValue extends ICDIValue {
}

View file

@ -6,9 +6,9 @@
package org.eclipse.cdt.debug.core.cdi.model.type; package org.eclipse.cdt.debug.core.cdi.model.type;
import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.model.ICDIValue; import org.eclipse.cdt.debug.core.cdi.model.ICDIValue;
/** /**
* *
* Represents the value of a variable. * Represents the value of a variable.
@ -17,5 +17,13 @@ import org.eclipse.cdt.debug.core.cdi.model.ICDIValue;
*/ */
public interface ICDIFloatingPointValue extends ICDIValue { public interface ICDIFloatingPointValue extends ICDIValue {
// Implement type conversion here float floatValue() throws CDIException;
double doubleValue() throws CDIException;
long longValue() throws CDIException;
boolean isNaN();
boolean isInfinite();
} }

View file

@ -6,6 +6,8 @@
package org.eclipse.cdt.debug.core.cdi.model.type; package org.eclipse.cdt.debug.core.cdi.model.type;
import org.eclipse.cdt.debug.core.cdi.CDIException;
/** /**
* *
@ -14,5 +16,6 @@ package org.eclipse.cdt.debug.core.cdi.model.type;
* @since Apr 15, 2003 * @since Apr 15, 2003
*/ */
public interface ICDIPointerValue extends ICDIDerivedValue { public interface ICDIPointerValue extends ICDIDerivedValue {
long pointerValue() throws CDIException;
} }

View file

@ -4,9 +4,11 @@
*/ */
package org.eclipse.cdt.debug.core.cdi.model.type; package org.eclipse.cdt.debug.core.cdi.model.type;
import org.eclipse.cdt.debug.core.cdi.CDIException;
/** /**
*/ */
public interface ICDIReferenceValue extends ICDIDerivedValue { public interface ICDIReferenceValue extends ICDIDerivedValue {
long referenceValue() throws CDIException;
} }

View file

@ -31,4 +31,10 @@ public interface ICVariable extends IVariable
int[] getArrayDimensions(); int[] getArrayDimensions();
boolean isStructure(); boolean isStructure();
boolean isCharacter();
boolean isFloatingPointType();
boolean isNaN();
} }

View file

@ -6,6 +6,7 @@
package org.eclipse.cdt.debug.internal.core.model; package org.eclipse.cdt.debug.internal.core.model;
import java.math.BigInteger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -13,8 +14,18 @@ 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.ICDIDoubleValue;
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.ICDIIntegralType;
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.ICDIPointerValue;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIShortValue;
import org.eclipse.cdt.debug.core.model.ICValue; import org.eclipse.cdt.debug.core.model.ICValue;
import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IVariable; import org.eclipse.debug.core.model.IVariable;
@ -87,15 +98,14 @@ public class CValue extends CDebugElement implements ICValue
{ {
try try
{ {
// fValueString = processCDIValue( getUnderlyingValue().getValueString() ); fValueString = processUnderlyingValue( getUnderlyingValue() );
fValueString = getUnderlyingValue().getValueString();
} }
catch( CDIException e ) catch( CDIException e )
{ {
fValueString = e.getMessage(); fValueString = e.getMessage();
} }
} }
return ( fValueString != null ) ? processCDIValue( fValueString ) : null; return fValueString;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -266,40 +276,218 @@ public class CValue extends CDebugElement implements ICValue
return fParent; return fParent;
} }
public String getUnderlyingValueString() private String processUnderlyingValue( ICDIValue cdiValue ) throws CDIException
{ {
if ( fValueString == null && getUnderlyingValue() != null ) if ( cdiValue != null )
{ {
try if ( cdiValue instanceof ICDICharValue )
{ return getCharValueString( (ICDICharValue)cdiValue );
fValueString = getUnderlyingValue().getValueString(); else if ( cdiValue instanceof ICDIShortValue )
} return getShortValueString( (ICDIShortValue)cdiValue );
catch( CDIException e ) else if ( cdiValue instanceof ICDIIntValue )
{ return getIntValueString( (ICDIIntValue)cdiValue );
fValueString = e.getMessage(); else if ( cdiValue instanceof ICDILongValue )
} return getLongValueString( (ICDILongValue)cdiValue );
else if ( cdiValue instanceof ICDILongLongValue )
return getLongLongValueString( (ICDILongLongValue)cdiValue );
else if ( cdiValue instanceof ICDIFloatValue )
return getFloatValueString( (ICDIFloatValue)cdiValue );
else if ( cdiValue instanceof ICDIDoubleValue )
return getDoubleValueString( (ICDIDoubleValue)cdiValue );
else if ( cdiValue instanceof ICDIPointerValue )
return getPointerValueString( (ICDIPointerValue)cdiValue );
else
return cdiValue.getValueString();
} }
return fValueString; return null;
}
public boolean isCharPointer()
{
String value = getUnderlyingValueString();
if ( value != null )
{
value = value.trim();
return ( value.startsWith( "0x" ) && value.indexOf( ' ' ) != -1 );
}
return false;
} }
public boolean isCharacter() private String getCharValueString( ICDICharValue value ) throws CDIException
{ {
String value = getUnderlyingValueString(); byte byteValue = (byte)value.byteValue();
if ( value != null ) short shortValue = value.shortValue();
switch( getParentVariable().getFormat() )
{ {
return ( value.trim().endsWith( "\'" ) ); 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, '\'' } );
}
case ICDIFormat.DECIMAL:
{
return ( isUnsigned() ) ? Integer.toString( shortValue ) : Integer.toString( byteValue );
}
case ICDIFormat.HEXADECIMAL:
{
StringBuffer sb = new StringBuffer( "0x" );
String stringValue = Integer.toHexString( ( isUnsigned() ) ? shortValue : byteValue );
sb.append( ( stringValue.length() > 2 ) ? stringValue.substring( stringValue.length() - 2 ) : stringValue );
return sb.toString();
}
} }
return false; return null;
}
private String getShortValueString( ICDIShortValue value ) throws CDIException
{
short shortValue = value.shortValue();
int intValue = value.intValue();
switch( getParentVariable().getFormat() )
{
case ICDIFormat.NATURAL:
case ICDIFormat.DECIMAL:
return ( isUnsigned() ) ? Integer.toString( intValue ) : Short.toString( shortValue );
case ICDIFormat.HEXADECIMAL:
{
StringBuffer sb = new StringBuffer( "0x" );
String stringValue = Integer.toHexString( ( isUnsigned() ) ? intValue : shortValue );
sb.append( ( stringValue.length() > 4 ) ? stringValue.substring( stringValue.length() - 4 ) : stringValue );
return sb.toString();
}
}
return null;
}
private String getIntValueString( ICDIIntValue value ) throws CDIException
{
int intValue = value.intValue();
long longValue = value.longValue();
switch( getParentVariable().getFormat() )
{
case ICDIFormat.NATURAL:
case ICDIFormat.DECIMAL:
return ( isUnsigned() ) ? Long.toString( longValue ) : Integer.toString( intValue );
case ICDIFormat.HEXADECIMAL:
{
StringBuffer sb = new StringBuffer( "0x" );
String stringValue = ( isUnsigned() ) ? Long.toHexString( longValue ) : Integer.toHexString( intValue );
sb.append( ( stringValue.length() > 8 ) ? stringValue.substring( stringValue.length() - 8 ) : stringValue );
return sb.toString();
}
}
return null;
}
private String getLongValueString( ICDILongValue value ) throws CDIException
{
int intValue = value.intValue();
long longValue = value.longValue();
switch( getParentVariable().getFormat() )
{
case ICDIFormat.NATURAL:
case ICDIFormat.DECIMAL:
return ( isUnsigned() ) ? Long.toString( longValue ) : Integer.toString( intValue );
case ICDIFormat.HEXADECIMAL:
{
StringBuffer sb = new StringBuffer( "0x" );
String stringValue = Long.toHexString( ( isUnsigned() ) ? longValue : intValue );
sb.append( ( stringValue.length() > 8 ) ? stringValue.substring( stringValue.length() - 8 ) : stringValue );
return sb.toString();
}
}
return null;
}
private String getLongLongValueString( ICDILongLongValue value ) throws CDIException
{
BigInteger bigValue = new BigInteger( value.getValueString() );
long longValue = value.longValue();
switch( getParentVariable().getFormat() )
{
case ICDIFormat.NATURAL:
case ICDIFormat.DECIMAL:
return ( isUnsigned() ) ? bigValue.toString() : Long.toString( longValue );
case ICDIFormat.HEXADECIMAL:
{
StringBuffer sb = new StringBuffer( "0x" );
sb.append( ( isUnsigned() ) ? bigValue.toString( 16 ) : Long.toHexString( longValue ) );
return sb.toString();
}
}
return null;
}
private String getFloatValueString( ICDIFloatValue value ) throws CDIException
{
if ( value.isNaN() )
return "";
float floatValue = value.floatValue();
long longValue = value.longValue();
switch( getParentVariable().getFormat() )
{
case ICDIFormat.NATURAL:
return Float.toString( floatValue );
case ICDIFormat.DECIMAL:
return Long.toString( longValue );
case ICDIFormat.HEXADECIMAL:
{
StringBuffer sb = new StringBuffer( "0x" );
String stringValue = Long.toHexString( longValue );
sb.append( ( stringValue.length() > 8 ) ? stringValue.substring( stringValue.length() - 8 ) : stringValue );
return sb.toString();
}
}
return null;
}
private String getDoubleValueString( ICDIDoubleValue value ) throws CDIException
{
if ( value.isNaN() )
return "";
double doubleValue = value.doubleValue();
long longValue = value.longValue();
switch( getParentVariable().getFormat() )
{
case ICDIFormat.NATURAL:
return Double.toString( doubleValue );
case ICDIFormat.DECIMAL:
return Long.toString( longValue );
case ICDIFormat.HEXADECIMAL:
{
StringBuffer sb = new StringBuffer( "0x" );
String stringValue = Long.toHexString( longValue );
sb.append( ( stringValue.length() > 16 ) ? stringValue.substring( stringValue.length() - 16 ) : stringValue );
return sb.toString();
}
}
return null;
}
private String getPointerValueString( ICDIPointerValue value ) throws CDIException
{
long longValue = value.pointerValue();
switch( getParentVariable().getFormat() )
{
case ICDIFormat.DECIMAL:
return Long.toString( longValue );
case ICDIFormat.NATURAL:
case ICDIFormat.HEXADECIMAL:
{
StringBuffer sb = new StringBuffer( "0x" );
String stringValue = Long.toHexString( longValue );
sb.append( ( stringValue.length() > 8 ) ? stringValue.substring( stringValue.length() - 8 ) : stringValue );
return sb.toString();
}
}
return null;
}
private boolean isUnsigned()
{
boolean result = false;
try
{
if ( getParentVariable().getCDIVariable() != null )
result = ( getParentVariable().getCDIVariable().getType() instanceof ICDIIntegralType ) ?
((ICDIIntegralType)getParentVariable().getCDIVariable().getType()).isUnsigned() : false;
}
catch( CDIException e )
{
}
return result;
} }
} }

View file

@ -16,7 +16,10 @@ 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.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.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.ICDIFloatingPointValue;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIStructType; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIStructType;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIType; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIType;
import org.eclipse.cdt.debug.core.model.ICValue; import org.eclipse.cdt.debug.core.model.ICValue;
@ -384,15 +387,7 @@ public abstract class CVariable extends CDebugElement
*/ */
public void setFormat( int format ) throws DebugException public void setFormat( int format ) throws DebugException
{ {
try fFormat = format;
{
getCDIVariable().setFormat( format );
fFormat = format;
}
catch( CDIException e )
{
targetRequestFailed( e.getMessage(), null );
}
} }
/** /**
@ -662,4 +657,36 @@ public abstract class CVariable extends CDebugElement
} }
return type; return type;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICVariable#isCharacter()
*/
public boolean isCharacter()
{
return ( getType() instanceof ICDICharType );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICVariable#isNaN()
*/
public boolean isNaN()
{
try
{
return ( getCDIVariable().getValue() instanceof ICDIFloatingPointValue ) ?
((ICDIFloatingPointValue)getCDIVariable().getValue()).isNaN() : false;
}
catch( CDIException e )
{
}
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICVariable#isFloatingPointType()
*/
public boolean isFloatingPointType()
{
return ( getType() instanceof ICDIFloatingPointType );
}
} }