From 4d899078f55e34a517bd997758762f2baaa3a5b5 Mon Sep 17 00:00:00 2001 From: Ken Ryall Date: Mon, 30 Apr 2007 12:30:00 +0000 Subject: [PATCH] Bug 159860, more formatting for bool. --- .../cdt/debug/internal/core/model/CValue.java | 29 ++++++++++++++++++- .../mi/core/cdi/model/type/BoolValue.java | 17 ++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) 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 34bd4bbb8f6..553a187237f 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 QNX Software Systems and others. + * Copyright (c) 2000, 2007 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * QNX Software Systems - Initial API and implementation * Mark Mitchell, CodeSourcery - Bug 136896: View variables in binary format + * Warren Paul (Nokia) - 150860 *******************************************************************************/ package org.eclipse.cdt.debug.internal.core.model; @@ -25,6 +26,7 @@ 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; +import org.eclipse.cdt.debug.core.cdi.model.type.ICDIBoolValue; 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; @@ -209,6 +211,8 @@ public class CValue extends AbstractCValue { private String processUnderlyingValue( ICDIValue cdiValue ) throws CDIException { if ( cdiValue != null ) { + if ( cdiValue instanceof ICDIBoolValue ) + return getBoolValueString( (ICDIBoolValue)cdiValue ); if ( cdiValue instanceof ICDICharValue ) return getCharValueString( (ICDICharValue)cdiValue ); else if ( cdiValue instanceof ICDIShortValue ) @@ -235,6 +239,29 @@ public class CValue extends AbstractCValue { return null; } + private String getBoolValueString( ICDIBoolValue value ) throws CDIException { + CVariableFormat format = getParentVariable().getFormat(); + if ( CVariableFormat.NATURAL.equals( format ) ) { + short byteValue = value.shortValue(); + if (byteValue == 0) + return "false";//$NON-NLS-1$ + else if (byteValue == 1) + return "true";//$NON-NLS-1$ + else + return Integer.toString( value.shortValue() ); + } + else if ( CVariableFormat.DECIMAL.equals( format ) ) { + return Integer.toString( value.shortValue() ); + } + else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) { + 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; + } + private String getCharValueString( ICDICharValue value ) throws CDIException { CVariableFormat format = getParentVariable().getFormat(); if ( CVariableFormat.NATURAL.equals( format ) ) { diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/type/BoolValue.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/type/BoolValue.java index 46348230b79..f4c93be5778 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/type/BoolValue.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/type/BoolValue.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 QNX Software Systems and others. + * Copyright (c) 2000, 2007 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,10 +7,14 @@ * * Contributors: * QNX Software Systems - Initial API and implementation + * Warren Paul (Nokia) - 150860 *******************************************************************************/ package org.eclipse.cdt.debug.mi.core.cdi.model.type; +import java.math.BigInteger; + +import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIBoolValue; import org.eclipse.cdt.debug.mi.core.cdi.model.Variable; @@ -25,4 +29,15 @@ public class BoolValue extends IntegralValue implements ICDIBoolValue { super(v); } + public BigInteger bigIntegerValue() throws CDIException { + String valueString = getValueString(); + if (valueString.equalsIgnoreCase("false"))//$NON-NLS-1$ + return BigInteger.ZERO; + else + if (valueString.equalsIgnoreCase("true"))//$NON-NLS-1$ + return BigInteger.ONE; + + return super.bigIntegerValue(); + } + }