1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 09:46:02 +02:00

Applied patch from 116302. Only difference from patch is a comment correction.

This commit is contained in:
John Cortell 2007-05-16 19:11:50 +00:00
parent 4f61ae0217
commit 809ce2a43e
6 changed files with 124 additions and 11 deletions

View file

@ -241,9 +241,8 @@ public class CMemoryBlockRetrievalExtension extends PlatformObject implements IM
IValue value = exp.getValue();
if ( value instanceof ICValue ) {
ICType type = ((ICValue)value).getType();
if ( type != null && (type.isPointer() || type.isIntegralType()) ) {
if ( type != null && (type.isPointer() || type.isIntegralType() || type.isArray()) ) {
address = value.getValueString();
exp.dispose();
if ( address != null ) {
// ???
BigInteger a = ( address.startsWith( "0x" ) ) ? new BigInteger( address.substring( 2 ), 16 ) : new BigInteger( address ); //$NON-NLS-1$
@ -266,6 +265,12 @@ public class CMemoryBlockRetrievalExtension extends PlatformObject implements IM
catch( NumberFormatException e ) {
msg = MessageFormat.format( InternalDebugCoreMessages.getString( "CMemoryBlockRetrievalExtension.0" ), new String[] { expression, address } ); //$NON-NLS-1$
}
finally {
if (exp != null) {
exp.dispose();
}
}
throw new DebugException( new Status( IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), DebugException.REQUEST_FAILED, msg, null ) );
}

View file

@ -10,10 +10,16 @@
*******************************************************************************/
package org.eclipse.cdt.debug.internal.core.model;
import java.math.BigInteger;
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.model.ICDIVariable;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIArrayValue;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIPointerValue;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIType;
import org.eclipse.cdt.debug.core.model.CVariableFormat;
import org.eclipse.cdt.debug.core.model.ICType;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IIndexedValue;
@ -134,10 +140,35 @@ public class CIndexedValue extends AbstractCValue implements IIndexedValue {
return ( type != null ) ? type.getName() : ""; //$NON-NLS-1$
}
/* (non-Javadoc)
/**
* Please note that this function returns the address of the array, not the
* contents of the array, as long as the underlying ICDIArrayValue is an
* instance of ICDIPointerValue. Otherwise, it returns an empty string.
*
* @see org.eclipse.debug.core.model.IValue#getValueString()
*/
public String getValueString() throws DebugException {
if ( fCDIValue instanceof ICDIPointerValue ) {
try {
IAddressFactory factory = ((CDebugTarget)getDebugTarget()).getAddressFactory();
BigInteger pv = ((ICDIPointerValue)fCDIValue).pointerValue();
if ( pv == null )
return ""; //$NON-NLS-1$
IAddress address = factory.createAddress( pv );
if ( address == null )
return ""; //$NON-NLS-1$
CVariableFormat format = getParentVariable().getFormat();
if ( CVariableFormat.NATURAL.equals( format ) || CVariableFormat.HEXADECIMAL.equals( format ) )
return address.toHexAddressString();
if ( CVariableFormat.DECIMAL.equals( format ) )
return address.toString();
if ( CVariableFormat.BINARY.equals( format ) )
return address.toBinaryAddressString();
return null;
} catch (CDIException e) {
requestFailed( e.getMessage(), null );
}
}
return ""; //$NON-NLS-1$
}

View file

@ -595,7 +595,7 @@ public class CValue extends AbstractCValue {
}
}
private static CVariableFormat getNaturalFormat(ICDIValue value, CVariableFormat defaultFormat) throws CDIException {
protected static CVariableFormat getNaturalFormat(ICDIValue value, CVariableFormat defaultFormat) throws CDIException {
if (value instanceof ICDIFormattable) {
int naturalFormat = ((ICDIFormattable)value).getNaturalFormat();
switch (naturalFormat) {

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.debug.mi.core.cdi.model;
import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.ICDIFormat;
import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
import org.eclipse.cdt.debug.core.cdi.model.ICDIValue;
import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable;
@ -87,6 +88,7 @@ public abstract class Variable extends VariableDescriptor implements ICDIVariabl
String language;
boolean isFake = false;
boolean isUpdated = true;
private String hexAddress;
public Variable(VariableDescriptor obj, MIVarCreate var) {
super(obj);
@ -150,6 +152,37 @@ public abstract class Variable extends VariableDescriptor implements ICDIVariabl
return fMIVar;
}
private String getHexAddress() throws CDIException {
if (hexAddress != null) {
return hexAddress;
}
MISession mi = ((Target)getTarget()).getMISession();
CommandFactory factory = mi.getCommandFactory();
String name = "&(" + getName() + ")";
MIVarCreate varCreateCmd = factory.createMIVarCreate(name);
try {
if (mi.getCommandTimeout() >= 0) {
mi.postCommand(varCreateCmd, mi.getCommandTimeout());
} else {
mi.postCommand(varCreateCmd);
}
MIVarCreateInfo info = varCreateCmd.getMIVarCreateInfo();
if (info == null) {
throw new CDIException(CdiResources.getString("cdi.Common.No_answer")); //$NON-NLS-1$
}
MIVar var = info.getMIVar();
Variable v = createVariable((Target)getTarget(), (Thread)getThread(), (StackFrame)getStackFrame(),
name, name, getPosition(), getStackDepth(), var);
v.setFormat(ICDIFormat.HEXADECIMAL);
hexAddress = v.getValue().getValueString();
} catch (MIException e) {
throw new MI2CDIException(e);
}
return hexAddress;
}
public Variable getChild(String name) {
for (int i = 0; i < children.length; i++) {
Variable variable = (Variable) children[i];
@ -351,9 +384,9 @@ 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);
value = new ReferenceValue(this, getHexAddress());
} else if (t instanceof ICDIArrayType) {
value = new ArrayValue(this);
value = new ArrayValue(this, getHexAddress());
} else if (t instanceof ICDIStructType) {
value = new StructValue(this);
} else {

View file

@ -11,11 +11,14 @@
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.ICDITarget;
import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable;
import org.eclipse.cdt.debug.core.cdi.model.ICDIVariableDescriptor;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIArrayValue;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIPointerValue;
import org.eclipse.cdt.debug.mi.core.cdi.Session;
import org.eclipse.cdt.debug.mi.core.cdi.VariableManager;
import org.eclipse.cdt.debug.mi.core.cdi.model.Register;
@ -27,10 +30,27 @@ import org.eclipse.cdt.debug.mi.core.cdi.model.VariableDescriptor;
*
* @since Jun 3, 2003
*/
public class ArrayValue extends DerivedValue implements ICDIArrayValue {
public class ArrayValue extends DerivedValue implements ICDIArrayValue, ICDIPointerValue {
public ArrayValue(Variable v) {
private String hexAddress;
/**
* Construct the array value object given a variable and the
* hexadecimal address of the variable.
*
* @param v
* @param hexAddress
*/
public ArrayValue(Variable v, String hexAddress) {
super(v);
if (hexAddress == null) {
return;
}
if (hexAddress.startsWith("0x") || hexAddress.startsWith("0X")) {
this.hexAddress = hexAddress.substring(2);
} else {
this.hexAddress = hexAddress;
}
}
/* (non-Javadoc)
@ -78,4 +98,11 @@ public class ArrayValue extends DerivedValue implements ICDIArrayValue {
ICDIVariableDescriptor vo = mgr.getVariableDescriptorAsArray(variable, index, length);
return mgr.createVariable((VariableDescriptor)vo).getValue().getVariables();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.cdi.model.type.ICDIPointerValue#pointerValue()
*/
public BigInteger pointerValue() throws CDIException {
return new BigInteger(hexAddress, 16);
}
}

View file

@ -11,6 +11,8 @@
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;
@ -24,6 +26,7 @@ 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;
@ -38,13 +41,23 @@ import org.eclipse.cdt.debug.mi.core.cdi.model.Variable;
*
* @since Jun 3, 2003
*/
public class ReferenceValue extends DerivedValue implements ICDIReferenceValue {
public class ReferenceValue extends DerivedValue implements ICDIReferenceValue, ICDIPointerValue {
private String hexAddress;
/**
* Construct a value object for the referred variable, including the actual
* hexadecimal address of the variable.
* @param v
* @param hexAddress
*/
public ReferenceValue(Variable v) {
public ReferenceValue(Variable v, String hexAddress) {
super(v);
if (hexAddress.startsWith("0x") || hexAddress.startsWith("0X")) {
this.hexAddress = hexAddress.substring(2);
} else {
this.hexAddress = hexAddress;
}
}
/* (non-Javadoc)
@ -81,7 +94,7 @@ public class ReferenceValue extends DerivedValue implements ICDIReferenceValue {
// } else if (t instanceof ICDIReferenceType) {
// value = new ReferenceValue(getVariable());
} else if (t instanceof ICDIArrayType) {
value = new ArrayValue(getVariable());
value = new ArrayValue(getVariable(), hexAddress);
} else if (t instanceof ICDIStructType) {
value = new StructValue(getVariable());
} else {
@ -89,4 +102,8 @@ public class ReferenceValue extends DerivedValue implements ICDIReferenceValue {
}
return value;
}
public BigInteger pointerValue() throws CDIException {
return new BigInteger(hexAddress, 16);
}
}