From 5162005b2cb83184a241dc5ae19750e09d98a50f Mon Sep 17 00:00:00 2001 From: John Cortell Date: Tue, 24 Apr 2007 02:46:09 +0000 Subject: [PATCH] Fixed 183108. Allow the CDI backend to dictate the format (hex/decimal/binary) to use for displaying an integral ICDIValue --- .../cdt/debug/core/cdi/ICDIFormattable.java | 26 +++++++++ .../cdt/debug/internal/core/model/CValue.java | 55 ++++++++++++++++--- 2 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 debug/org.eclipse.cdt.debug.core/cdi/org/eclipse/cdt/debug/core/cdi/ICDIFormattable.java diff --git a/debug/org.eclipse.cdt.debug.core/cdi/org/eclipse/cdt/debug/core/cdi/ICDIFormattable.java b/debug/org.eclipse.cdt.debug.core/cdi/org/eclipse/cdt/debug/core/cdi/ICDIFormattable.java new file mode 100644 index 00000000000..2a41362a4e2 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.core/cdi/org/eclipse/cdt/debug/core/cdi/ICDIFormattable.java @@ -0,0 +1,26 @@ +package org.eclipse.cdt.debug.core.cdi; + + +/** + * The CDI client's implementation of ICDIValue should implement this interface + * if it wants to dictate the variable/register's natural format. If it doesn't, + * CDT will provide a default behavior (e.g., all integral, non-pointer + * ICDIValue variants will display as decimal). + * + * CDT will exercise this interface only for ICDIValue's whose natural + * format isn't obvious or implied. For example, it will not be exercised for + * ICDIDoubleValue, ICDICharValue or ICDIBoolValue, to name a few. + * + * + */ +public interface ICDIFormattable { + /** + * Called when there is no obvious or implied natural format for the + * ICDIValue. + * + * @return one of the ICDIFormat constants, excluding 'NATURAL' and 'OCTAL'. + * Octal is not supported simply because the general support for it + * is lacking in CDT (apparently no one is asking for it). + */ + int getNaturalFormat(); +} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValue.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValue.java index 6f69fb66d8c..d349058a252 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValue.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValue.java @@ -20,6 +20,8 @@ import java.util.List; import org.eclipse.cdt.core.IAddress; import org.eclipse.cdt.core.IAddressFactory; import org.eclipse.cdt.debug.core.cdi.CDIException; +import org.eclipse.cdt.debug.core.cdi.ICDIFormat; +import org.eclipse.cdt.debug.core.cdi.ICDIFormattable; import org.eclipse.cdt.debug.core.cdi.model.ICDITargetConfiguration2; import org.eclipse.cdt.debug.core.cdi.model.ICDIValue; import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable; @@ -258,8 +260,13 @@ public class CValue extends AbstractCValue { } private String getShortValueString( ICDIShortValue value ) throws CDIException { - CVariableFormat format = getParentVariable().getFormat(); - if ( CVariableFormat.NATURAL.equals( format ) || CVariableFormat.DECIMAL.equals( format ) ) { + CVariableFormat format = getParentVariable().getFormat(); + + if (CVariableFormat.NATURAL.equals(format)) { + format = getNaturalFormat(value, CVariableFormat.DECIMAL); + } + + if ( CVariableFormat.DECIMAL.equals( format ) ) { return (isUnsigned()) ? Integer.toString( value.intValue() ) : Short.toString( value.shortValue() ); } else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) { @@ -278,8 +285,13 @@ public class CValue extends AbstractCValue { } private String getIntValueString( ICDIIntValue value ) throws CDIException { - CVariableFormat format = getParentVariable().getFormat(); - if ( CVariableFormat.NATURAL.equals( format ) || CVariableFormat.DECIMAL.equals( format ) ) { + CVariableFormat format = getParentVariable().getFormat(); + + if (CVariableFormat.NATURAL.equals(format)) { + format = getNaturalFormat(value, CVariableFormat.DECIMAL); + } + + if ( CVariableFormat.DECIMAL.equals( format ) ) { return (isUnsigned()) ? Long.toString( value.longValue() ) : Integer.toString( value.intValue() ); } else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) { @@ -299,8 +311,13 @@ public class CValue extends AbstractCValue { private String getLongValueString( ICDILongValue value ) throws CDIException { try { - CVariableFormat format = getParentVariable().getFormat(); - if ( CVariableFormat.NATURAL.equals( format ) || CVariableFormat.DECIMAL.equals( format ) ) { + CVariableFormat format = getParentVariable().getFormat(); + + if (CVariableFormat.NATURAL.equals(format)) { + format = getNaturalFormat(value, CVariableFormat.DECIMAL); + } + + if ( CVariableFormat.DECIMAL.equals( format ) ) { if ( isUnsigned() ) { BigInteger bigValue = new BigInteger( value.getValueString() ); return bigValue.toString(); @@ -335,8 +352,13 @@ public class CValue extends AbstractCValue { private String getLongLongValueString( ICDILongLongValue value ) throws CDIException { try { - CVariableFormat format = getParentVariable().getFormat(); - if ( CVariableFormat.NATURAL.equals( format ) || CVariableFormat.DECIMAL.equals( format ) ) { + CVariableFormat format = getParentVariable().getFormat(); + + if (CVariableFormat.NATURAL.equals(format)) { + format = getNaturalFormat(value, CVariableFormat.DECIMAL); + } + + if ( CVariableFormat.DECIMAL.equals( format ) ) { if ( isUnsigned() ) { BigInteger bigValue = new BigInteger( value.getValueString() ); return bigValue.toString(); @@ -543,4 +565,21 @@ public class CValue extends AbstractCValue { ((AbstractCVariable)it.next()).preserve(); } } + + private static CVariableFormat getNaturalFormat(ICDIValue value, CVariableFormat defaultFormat) { + if (value instanceof ICDIFormattable) { + int naturalFormat = ((ICDIFormattable)value).getNaturalFormat(); + switch (naturalFormat) { + case ICDIFormat.DECIMAL: + return CVariableFormat.DECIMAL; + case ICDIFormat.BINARY: + return CVariableFormat.BINARY; + case ICDIFormat.OCTAL: + return CVariableFormat.OCTAL; + case ICDIFormat.HEXADECIMAL: + return CVariableFormat.HEXADECIMAL; + } + } + return defaultFormat; + } }