mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 01:36:01 +02:00
Fixed 183108. Allow the CDI backend to dictate the format (hex/decimal/binary) to use for displaying an integral ICDIValue
This commit is contained in:
parent
af018d72e9
commit
5162005b2c
2 changed files with 73 additions and 8 deletions
|
@ -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();
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue