diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Value.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Value.java index 134d819549a..34b29779a14 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Value.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Value.java @@ -27,6 +27,14 @@ public class Value extends CObject implements ICDIValue { protected Variable fVariable; + /** + * Indicates whether this Value object is for a C++ reference variable. If + * it is, then some decoding is needed on the value string we get from gdb, + * since it will contain two things: the address of the variable being + * referenced and the value. + */ + protected boolean fIsReference; + public Value(Variable v) { super((Target)v.getTarget()); fVariable = v; @@ -64,6 +72,19 @@ public class Value extends CObject implements ICDIValue { throw new CDIException(CdiResources.getString("cdi.Common.No_answer")); //$NON-NLS-1$ } result = info.getValue(); + + // Reference variables get back a string with two things: the address of the + // variable being referenced and the value of the variable. The expected + // format is, by example (for a float&): "@0x22cc98: 3.19616001e-39" + // We need to dig out the latter. + if (fIsReference) { + if (result.startsWith("@0x")) { + int index = result.indexOf(':'); + if (index > 0 && ((index + 1) < result.length())) { + result = result.substring(index+1).trim(); + } + } + } } catch (MIException e) { throw new CDIException(e.getMessage()); } @@ -116,4 +137,17 @@ public class Value extends CObject implements ICDIValue { return getVariable().getType(); } + /** + * Call this after construction with 'true' if the Value is for a reference + * variable. See {@link #fIsReference}. + * + * Ideally, this property would be passed to the constructor. However + * introducing it that way at this point in time would cause a lot of churn + * in the codebase, since this class is not directly instantiated, and it + * has many subclasses. + */ + public void setIsReference(boolean isReference) { + fIsReference = isReference; + } + } diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Variable.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Variable.java index 5188e17e759..eb80fef034a 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Variable.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Variable.java @@ -348,7 +348,7 @@ public abstract class Variable extends VariableDescriptor implements ICDIVariabl } else if (t instanceof ICDIPointerType) { value = new PointerValue(this); } else if (t instanceof ICDIReferenceType) { - value = new ReferenceValue(this, getHexAddress()); + value = new ReferenceValue(this); } else if (t instanceof ICDIArrayType) { value = new ArrayValue(this, getHexAddress()); } else if (t instanceof ICDIStructType) { diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/type/ReferenceValue.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/type/ReferenceValue.java index 1a423f92843..4d6657d7d1c 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/type/ReferenceValue.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/type/ReferenceValue.java @@ -11,11 +11,9 @@ 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.ICDIValue; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDIArrayType; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIBoolType; import org.eclipse.cdt.debug.core.cdi.model.type.ICDICharType; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIDoubleType; @@ -26,7 +24,6 @@ import org.eclipse.cdt.debug.core.cdi.model.type.ICDIIntType; import org.eclipse.cdt.debug.core.cdi.model.type.ICDILongLongType; import org.eclipse.cdt.debug.core.cdi.model.type.ICDILongType; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIPointerType; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDIPointerValue; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIReferenceType; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIReferenceValue; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIShortType; @@ -41,23 +38,14 @@ import org.eclipse.cdt.debug.mi.core.cdi.model.Variable; * * @since Jun 3, 2003 */ -public class ReferenceValue extends DerivedValue implements ICDIReferenceValue, ICDIPointerValue { +public class ReferenceValue extends DerivedValue implements ICDIReferenceValue { - private String hexAddress; - /** - * Construct a value object for the referred variable, including the actual - * hexadecimal address of the variable. + * Construct a value object for the referred variable * @param v - * @param hexAddress */ - public ReferenceValue(Variable v, String hexAddress) { + public ReferenceValue(Variable v) { super(v); - if (hexAddress.startsWith("0x") || hexAddress.startsWith("0X")) { - this.hexAddress = hexAddress.substring(2); - } else { - this.hexAddress = hexAddress; - } } /* (non-Javadoc) @@ -93,17 +81,20 @@ public class ReferenceValue extends DerivedValue implements ICDIReferenceValue, value = new PointerValue(getVariable()); // } else if (t instanceof ICDIReferenceType) { // value = new ReferenceValue(getVariable()); - } else if (t instanceof ICDIArrayType) { - value = new ArrayValue(getVariable(), hexAddress); +// +// Don't think you can have a reference to an array variable, making +// the following case pointless. Removing it since it would otherwise +// require us to be constructed with a hexAddress qualifier. +// } else if (t instanceof ICDIArrayType) { +// value = new ArrayValue(getVariable(), hexAddress); +// } else if (t instanceof ICDIStructType) { value = new StructValue(getVariable()); } else { value = new Value(getVariable()); } + + value.setIsReference(true); return value; } - - public BigInteger pointerValue() throws CDIException { - return new BigInteger(hexAddress, 16); - } }