diff options
author | Mikhail Khodjaiants | 2005-07-29 02:12:02 +0000 |
---|---|---|
committer | Mikhail Khodjaiants | 2005-07-29 02:12:02 +0000 |
commit | a5fdd63e34dd4d49f63c6975be12c8c478f631b8 (patch) | |
tree | 24ebdd6222b9f5fb86bcefdc5b29d540131f0248 /debug/org.eclipse.cdt.debug.core/src/org | |
parent | fb81386aa2c85d44fd2593ef71595d4cbe78d68b (diff) | |
download | org.eclipse.cdt-a5fdd63e34dd4d49f63c6975be12c8c478f631b8.tar.gz org.eclipse.cdt-a5fdd63e34dd4d49f63c6975be12c8c478f631b8.tar.xz org.eclipse.cdt-a5fdd63e34dd4d49f63c6975be12c8c478f631b8.zip |
Bug 104421: Register view can not show correct value when switch between different thread or stack frame.
Diffstat (limited to 'debug/org.eclipse.cdt.debug.core/src/org')
11 files changed, 1062 insertions, 340 deletions
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CRegisterManager.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CRegisterManager.java index ef9e1c3ac7c..92e9379b698 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CRegisterManager.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CRegisterManager.java @@ -65,6 +65,8 @@ public class CRegisterManager { private boolean fUseDefaultRegisterGroups = true; + private CStackFrame fCurrentFrame; + /** * Constructor for CRegisterManager. */ @@ -101,7 +103,14 @@ public class CRegisterManager { } public IRegisterGroup[] getRegisterGroups( CStackFrame frame ) throws DebugException { - return (IRegisterGroup[])fRegisterGroups.toArray( new IRegisterGroup[fRegisterGroups.size()] ); + IRegisterGroup[] groups = (IRegisterGroup[])fRegisterGroups.toArray( new IRegisterGroup[fRegisterGroups.size()] ); + if ( getCurrentFrame() != frame ) { + for ( int i = 0; i < groups.length; ++i ) { + ((CRegisterGroup)groups[i]).resetRegisterValues(); + } + setCurrentFrame( frame ); + } + return groups; } public void initialize() { @@ -328,4 +337,12 @@ public class CRegisterManager { protected void setUseDefaultRegisterGroups( boolean useDefaultRegisterGroups ) { fUseDefaultRegisterGroups = useDefaultRegisterGroups; } + + public CStackFrame getCurrentFrame() { + return fCurrentFrame; + } + + private void setCurrentFrame( CStackFrame currentFrame ) { + fCurrentFrame = currentFrame; + } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CExpression.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CExpression.java index 46a3459d316..65e7ecb34f9 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CExpression.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CExpression.java @@ -31,7 +31,7 @@ import org.eclipse.debug.core.model.IValue; /** * Represents an expression in the CDI model. */ -public class CExpression extends CVariable implements IExpression { +public class CExpression extends CLocalVariable implements IExpression { private String fText; diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CGlobalVariable.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CGlobalVariable.java index cd64543e08b..e92525d4467 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CGlobalVariable.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CGlobalVariable.java @@ -10,19 +10,306 @@ *******************************************************************************/ package org.eclipse.cdt.debug.internal.core.model; +import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.event.ICDIEvent; import org.eclipse.cdt.debug.core.cdi.event.ICDIResumedEvent; +import org.eclipse.cdt.debug.core.cdi.model.ICDIArgumentDescriptor; +import org.eclipse.cdt.debug.core.cdi.model.ICDIGlobalVariableDescriptor; import org.eclipse.cdt.debug.core.cdi.model.ICDIObject; 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; 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.ICDIType; import org.eclipse.cdt.debug.core.model.ICGlobalVariable; +import org.eclipse.cdt.debug.core.model.ICType; +import org.eclipse.cdt.debug.core.model.ICValue; import org.eclipse.cdt.debug.core.model.IGlobalVariableDescriptor; +import org.eclipse.debug.core.DebugException; /** * Represents a global variable. */ public class CGlobalVariable extends CVariable implements ICGlobalVariable { + private class InternalVariable implements IInternalVariable { + + /** + * The enclosing <code>CVariable</code> instance. + */ + private CVariable fVariable; + + /** + * The CDI variable object this variable is based on. + */ + private ICDIVariableDescriptor fCDIVariableObject; + + /** + * The underlying CDI variable. + */ + private ICDIVariable fCDIVariable; + + /** + * The type of this variable. + */ + private CType fType; + + /** + * The expression used to eveluate the value of this variable. + */ + private String fQualifiedName; + + /** + * The cache of the current value. + */ + private ICValue fValue = CValueFactory.NULL_VALUE; + + /** + * The change flag. + */ + private boolean fChanged = false; + + /** + * Constructor for InternalVariable. + */ + InternalVariable( CVariable var, ICDIVariableDescriptor varObject ) { + setVariable( var ); + setCDIVariableObject( varObject ); + setCDIVariable( (varObject instanceof ICDIVariable) ? (ICDIVariable)varObject : null ); + } + + public IInternalVariable createShadow( int start, int length ) throws DebugException { + IInternalVariable iv = null; + try { + iv = new InternalVariable( getVariable(), getCDIVariableObject().getVariableDescriptorAsArray( start, length ) ); + } + catch( CDIException e ) { + requestFailed( e.getMessage(), null ); + } + return iv; + } + + public IInternalVariable createShadow( String type ) throws DebugException { + IInternalVariable iv = null; + try { + iv = new InternalVariable( getVariable(), getCDIVariableObject().getVariableDescriptorAsType( type ) ); + } + catch( CDIException e ) { + requestFailed( e.getMessage(), null ); + } + return iv; + } + + private synchronized ICDIVariable getCDIVariable() throws DebugException { + if ( fCDIVariable == null ) { + try { + fCDIVariable = getCDITarget().createGlobalVariable( (ICDIGlobalVariableDescriptor)getCDIVariableObject() ); + } + catch( CDIException e ) { + requestFailed( e.getMessage(), null ); + } + } + return fCDIVariable; + } + + private void setCDIVariable( ICDIVariable variable ) { + fCDIVariable = variable; + } + + private ICDIVariableDescriptor getCDIVariableObject() { + if ( fCDIVariable != null ) { + return fCDIVariable; + } + return fCDIVariableObject; + } + + private void setCDIVariableObject( ICDIVariableDescriptor variableObject ) { + fCDIVariableObject = variableObject; + } + + public String getQualifiedName() throws DebugException { + if ( fQualifiedName == null ) { + try { + fQualifiedName = (fCDIVariableObject != null) ? fCDIVariableObject.getQualifiedName() : null; + } + catch( CDIException e ) { + requestFailed( e.getMessage(), null ); + } + } + return fQualifiedName; + } + + public CType getType() throws DebugException { + if ( fType == null ) { + ICDIVariableDescriptor varObject = getCDIVariableObject(); + if ( varObject != null ) { + synchronized( this ) { + if ( fType == null ) { + try { + fType = new CType( varObject.getType() ); + } + catch( CDIException e ) { + requestFailed( e.getMessage(), null ); + } + } + } + } + } + return fType; + } + + private synchronized void invalidate( boolean destroy ) { + try { + if ( destroy && fCDIVariable != null ) + fCDIVariable.dispose(); + } + catch( CDIException e ) { + logError( e.getMessage() ); + } + invalidateValue(); + setCDIVariable( null ); + if ( fType != null ) + fType.dispose(); + fType = null; + } + + public void dispose( boolean destroy ) { + invalidate( destroy ); + } + + public boolean isSameVariable( ICDIVariable cdiVar ) { + return ( fCDIVariable != null ) ? fCDIVariable.equals( cdiVar ) : false; + } + + public int sizeof() { + if ( getCDIVariableObject() != null ) { + try { + return getCDIVariableObject().sizeof(); + } + catch( CDIException e ) { + } + } + return 0; + } + + public boolean isArgument() { + return ( getCDIVariableObject() instanceof ICDIArgumentDescriptor ); + } + + public void setValue( String expression ) throws DebugException { + ICDIVariable cdiVariable = null; + try { + cdiVariable = getCDIVariable(); + if ( cdiVariable != null ) + cdiVariable.setValue( expression ); + else + requestFailed( CoreModelMessages.getString( "CModificationVariable.0" ), null ); //$NON-NLS-1$ + } + catch( CDIException e ) { + targetRequestFailed( e.getMessage(), null ); + } + } + + public synchronized ICValue getValue() throws DebugException { + if ( fValue.equals( CValueFactory.NULL_VALUE ) ) { + ICDIVariable var = getCDIVariable(); + if ( var != null ) { + try { + ICDIValue cdiValue = var.getValue(); + if ( cdiValue != null ) { + ICDIType cdiType = cdiValue.getType(); + if ( cdiValue instanceof ICDIArrayValue && cdiType != null ) { + ICType type = new CType( cdiType ); + if ( type.isArray() ) { + int[] dims = type.getArrayDimensions(); + if ( dims.length > 0 && dims[0] > 0 ) + fValue = CValueFactory.createIndexedValue( getVariable(), (ICDIArrayValue)cdiValue, 0, dims[0] ); + } + } + else { + fValue = CValueFactory.createValue( getVariable(), cdiValue ); + } + } + } + catch( CDIException e ) { + requestFailed( e.getMessage(), e ); + } + } + } + return fValue; + } + + public void invalidateValue() { + if ( fValue instanceof AbstractCValue ) { + ((AbstractCValue)fValue).dispose(); + fValue = CValueFactory.NULL_VALUE; + } + } + + public boolean isChanged() { + return fChanged; + } + + public synchronized void setChanged( boolean changed ) { + if ( changed ) { + invalidateValue(); + } + if ( fValue instanceof AbstractCValue ) { + ((AbstractCValue)fValue).setChanged( changed ); + } + fChanged = changed; + } + + public synchronized void preserve() { + setChanged( false ); + if ( fValue instanceof AbstractCValue ) { + ((AbstractCValue)fValue).preserve(); + } + } + + CVariable getVariable() { + return fVariable; + } + + private void setVariable( CVariable variable ) { + fVariable = variable; + } + + public void resetValue() { + if ( fValue instanceof AbstractCValue ) { + ((AbstractCValue)fValue).reset(); + } + } + + public boolean isEditable() throws DebugException { + ICDIVariable var = getCDIVariable(); + if ( var != null ) { + try { + return var.isEditable(); + } + catch( CDIException e ) { + } + } + return false; + } + + /** + * Compares the underlying variable objects. + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals( Object obj ) { + if ( obj instanceof InternalVariable ) { + return getCDIVariableObject().equals( ((InternalVariable)obj).getCDIVariableObject() ); + } + return false; + } + + public boolean isSameDescriptor( ICDIVariableDescriptor desc ) { + return getCDIVariableObject().equals( desc ); + } + } + private IGlobalVariableDescriptor fDescriptor; /** @@ -81,4 +368,11 @@ public class CGlobalVariable extends CVariable implements ICGlobalVariable { internalDispose( true ); setDisposed( true ); } + + protected void createOriginal( ICDIVariableDescriptor vo ) { + if ( vo != null ) { + setName( vo.getName() ); + setOriginal( new InternalVariable( this, vo ) ); + } + } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CIndexedValue.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CIndexedValue.java index 5c81901a759..1456905681d 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CIndexedValue.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CIndexedValue.java @@ -250,7 +250,7 @@ public class CIndexedValue extends AbstractCValue implements IIndexedValue { requestFailed( e.getMessage(), null ); } for( int i = 0; i < cdiVars.length; ++i ) - fVariables[i + index * prefSize] = CVariableFactory.createVariable( getParentVariable(), cdiVars[i] ); + fVariables[i + index * prefSize] = CVariableFactory.createLocalVariable( getParentVariable(), cdiVars[i] ); } private int getSize0() { diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CLocalVariable.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CLocalVariable.java new file mode 100644 index 00000000000..609d27d47ca --- /dev/null +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CLocalVariable.java @@ -0,0 +1,325 @@ +/********************************************************************** + * Copyright (c) 2004 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + ***********************************************************************/ +package org.eclipse.cdt.debug.internal.core.model; + +import org.eclipse.cdt.debug.core.cdi.CDIException; +import org.eclipse.cdt.debug.core.cdi.model.ICDIArgumentDescriptor; +import org.eclipse.cdt.debug.core.cdi.model.ICDILocalVariableDescriptor; +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.ICDIVariableDescriptor; +import org.eclipse.cdt.debug.core.cdi.model.type.ICDIArrayValue; +import org.eclipse.cdt.debug.core.cdi.model.type.ICDIType; +import org.eclipse.cdt.debug.core.model.ICType; +import org.eclipse.cdt.debug.core.model.ICValue; +import org.eclipse.debug.core.DebugException; + + +public class CLocalVariable extends CVariable { + + private class InternalVariable implements IInternalVariable { + + /** + * The enclosing <code>CVariable</code> instance. + */ + private CVariable fVariable; + + /** + * The CDI variable object this variable is based on. + */ + private ICDIVariableDescriptor fCDIVariableObject; + + /** + * The underlying CDI variable. + */ + private ICDIVariable fCDIVariable; + + /** + * The type of this variable. + */ + private CType fType; + + /** + * The expression used to eveluate the value of this variable. + */ + private String fQualifiedName; + + /** + * The cache of the current value. + */ + private ICValue fValue = CValueFactory.NULL_VALUE; + + /** + * The change flag. + */ + private boolean fChanged = false; + + /** + * Constructor for InternalVariable. + */ + InternalVariable( CVariable var, ICDIVariableDescriptor varObject ) { + setVariable( var ); + setCDIVariableObject( varObject ); + setCDIVariable( (varObject instanceof ICDIVariable) ? (ICDIVariable)varObject : null ); + } + + public IInternalVariable createShadow( int start, int length ) throws DebugException { + IInternalVariable iv = null; + try { + iv = new InternalVariable( getVariable(), getCDIVariableObject().getVariableDescriptorAsArray( start, length ) ); + } + catch( CDIException e ) { + requestFailed( e.getMessage(), null ); + } + return iv; + } + + public IInternalVariable createShadow( String type ) throws DebugException { + IInternalVariable iv = null; + try { + iv = new InternalVariable( getVariable(), getCDIVariableObject().getVariableDescriptorAsType( type ) ); + } + catch( CDIException e ) { + requestFailed( e.getMessage(), null ); + } + return iv; + } + + private synchronized ICDIVariable getCDIVariable() throws DebugException { + if ( fCDIVariable == null ) { + try { + fCDIVariable = ((CStackFrame)getStackFrame()).getCDIStackFrame().createLocalVariable( (ICDILocalVariableDescriptor)getCDIVariableObject() ); + } + catch( CDIException e ) { + requestFailed( e.getMessage(), null ); + } + } + return fCDIVariable; + } + + private void setCDIVariable( ICDIVariable variable ) { + fCDIVariable = variable; + } + + private ICDIVariableDescriptor getCDIVariableObject() { + if ( fCDIVariable != null ) { + return fCDIVariable; + } + return fCDIVariableObject; + } + + private void setCDIVariableObject( ICDIVariableDescriptor variableObject ) { + fCDIVariableObject = variableObject; + } + + public String getQualifiedName() throws DebugException { + if ( fQualifiedName == null ) { + try { + fQualifiedName = (fCDIVariableObject != null) ? fCDIVariableObject.getQualifiedName() : null; + } + catch( CDIException e ) { + requestFailed( e.getMessage(), null ); + } + } + return fQualifiedName; + } + + public CType getType() throws DebugException { + if ( fType == null ) { + ICDIVariableDescriptor varObject = getCDIVariableObject(); + if ( varObject != null ) { + synchronized( this ) { + if ( fType == null ) { + try { + fType = new CType( varObject.getType() ); + } + catch( CDIException e ) { + requestFailed( e.getMessage(), null ); + } + } + } + } + } + return fType; + } + + private synchronized void invalidate( boolean destroy ) { + try { + if ( destroy && fCDIVariable != null ) + fCDIVariable.dispose(); + } + catch( CDIException e ) { + logError( e.getMessage() ); + } + invalidateValue(); + setCDIVariable( null ); + if ( fType != null ) + fType.dispose(); + fType = null; + } + + public void dispose( boolean destroy ) { + invalidate( destroy ); + } + + public boolean isSameVariable( ICDIVariable cdiVar ) { + return ( fCDIVariable != null ) ? fCDIVariable.equals( cdiVar ) : false; + } + + public int sizeof() { + if ( getCDIVariableObject() != null ) { + try { + return getCDIVariableObject().sizeof(); + } + catch( CDIException e ) { + } + } + return 0; + } + + public boolean isArgument() { + return ( getCDIVariableObject() instanceof ICDIArgumentDescriptor ); + } + + public void setValue( String expression ) throws DebugException { + ICDIVariable cdiVariable = null; + try { + cdiVariable = getCDIVariable(); + if ( cdiVariable != null ) + cdiVariable.setValue( expression ); + else + requestFailed( CoreModelMessages.getString( "CModificationVariable.0" ), null ); //$NON-NLS-1$ + } + catch( CDIException e ) { + targetRequestFailed( e.getMessage(), null ); + } + } + + public synchronized ICValue getValue() throws DebugException { + if ( fValue.equals( CValueFactory.NULL_VALUE ) ) { + ICDIVariable var = getCDIVariable(); + if ( var != null ) { + try { + ICDIValue cdiValue = var.getValue(); + if ( cdiValue != null ) { + ICDIType cdiType = cdiValue.getType(); + if ( cdiValue instanceof ICDIArrayValue && cdiType != null ) { + ICType type = new CType( cdiType ); + if ( type.isArray() ) { + int[] dims = type.getArrayDimensions(); + if ( dims.length > 0 && dims[0] > 0 ) + fValue = CValueFactory.createIndexedValue( getVariable(), (ICDIArrayValue)cdiValue, 0, dims[0] ); + } + } + else { + fValue = CValueFactory.createValue( getVariable(), cdiValue ); + } + } + } + catch( CDIException e ) { + requestFailed( e.getMessage(), e ); + } + } + } + return fValue; + } + + public void invalidateValue() { + if ( fValue instanceof AbstractCValue ) { + ((AbstractCValue)fValue).dispose(); + fValue = CValueFactory.NULL_VALUE; + } + } + + public boolean isChanged() { + return fChanged; + } + + public synchronized void setChanged( boolean changed ) { + if ( changed ) { + invalidateValue(); + } + if ( fValue instanceof AbstractCValue ) { + ((AbstractCValue)fValue).setChanged( changed ); + } + fChanged = changed; + } + + public synchronized void preserve() { + setChanged( false ); + if ( fValue instanceof AbstractCValue ) { + ((AbstractCValue)fValue).preserve(); + } + } + + CVariable getVariable() { + return fVariable; + } + + private void setVariable( CVariable variable ) { + fVariable = variable; + } + + public void resetValue() { + if ( fValue instanceof AbstractCValue ) { + ((AbstractCValue)fValue).reset(); + } + } + + public boolean isEditable() throws DebugException { + ICDIVariable var = getCDIVariable(); + if ( var != null ) { + try { + return var.isEditable(); + } + catch( CDIException e ) { + } + } + return false; + } + + /** + * Compares the underlying variable objects. + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals( Object obj ) { + if ( obj instanceof InternalVariable ) { + return getCDIVariableObject().equals( ((InternalVariable)obj).getCDIVariableObject() ); + } + return false; + } + + public boolean isSameDescriptor( ICDIVariableDescriptor desc ) { + return getCDIVariableObject().equals( desc ); + } + } + + /** + * Constructor for CLocalVariable. + */ + public CLocalVariable( CDebugElement parent, ICDIVariableDescriptor cdiVariableObject, String errorMessage ) { + super( parent, cdiVariableObject, errorMessage ); + } + + /** + * Constructor for CLocalVariable. + */ + public CLocalVariable( CDebugElement parent, ICDIVariableDescriptor cdiVariableObject ) { + super( parent, cdiVariableObject ); + } + + protected void createOriginal( ICDIVariableDescriptor vo ) { + if ( vo != null ) { + setName( vo.getName() ); + setOriginal( new InternalVariable( this, vo ) ); + } + } +} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CRegister.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CRegister.java index 917a49454de..6d28d024afe 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CRegister.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CRegister.java @@ -13,7 +13,22 @@ package org.eclipse.cdt.debug.internal.core.model; import org.eclipse.cdt.debug.core.CDebugCorePlugin; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.debug.core.ICDebugConstants; +import org.eclipse.cdt.debug.core.cdi.CDIException; +import org.eclipse.cdt.debug.core.cdi.event.ICDIEvent; +import org.eclipse.cdt.debug.core.cdi.event.ICDIResumedEvent; +import org.eclipse.cdt.debug.core.cdi.model.ICDIArgumentDescriptor; +import org.eclipse.cdt.debug.core.cdi.model.ICDIObject; +import org.eclipse.cdt.debug.core.cdi.model.ICDIRegister; +import org.eclipse.cdt.debug.core.cdi.model.ICDIRegisterDescriptor; +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; +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.ICDIType; import org.eclipse.cdt.debug.core.model.CVariableFormat; +import org.eclipse.cdt.debug.core.model.ICType; +import org.eclipse.cdt.debug.core.model.ICValue; import org.eclipse.cdt.debug.core.model.IRegisterDescriptor; import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.DebugException; @@ -23,13 +38,289 @@ import org.eclipse.debug.core.model.IRegisterGroup; /** * Represents a register in the CDI model. */ -public class CRegister extends CGlobalVariable implements IRegister { +public class CRegister extends CVariable implements IRegister { + + private class InternalVariable implements IInternalVariable { + + /** + * The enclosing <code>CVariable</code> instance. + */ + private CVariable fVariable; + + /** + * The CDI variable object this variable is based on. + */ + private ICDIVariableDescriptor fCDIVariableObject; + + /** + * The underlying CDI register. + */ + private ICDIRegister fCDIRegister; + + /** + * The type of this variable. + */ + private CType fType; + + /** + * The expression used to eveluate the value of this variable. + */ + private String fQualifiedName; + + /** + * The cache of the current value. + */ + private ICValue fValue = CValueFactory.NULL_VALUE; + + /** + * The change flag. + */ + private boolean fChanged = false; + + /** + * Constructor for InternalVariable. + */ + InternalVariable( CVariable var, ICDIVariableDescriptor varObject ) { + setVariable( var ); + setCDIVariableObject( varObject ); + setCDIRegister( (varObject instanceof ICDIRegister) ? (ICDIRegister)varObject : null ); + } + + public IInternalVariable createShadow( int start, int length ) throws DebugException { + IInternalVariable iv = null; + try { + iv = new InternalVariable( getVariable(), getCDIVariableObject().getVariableDescriptorAsArray( start, length ) ); + } + catch( CDIException e ) { + requestFailed( e.getMessage(), null ); + } + return iv; + } + + public IInternalVariable createShadow( String type ) throws DebugException { + IInternalVariable iv = null; + try { + iv = new InternalVariable( getVariable(), getCDIVariableObject().getVariableDescriptorAsType( type ) ); + } + catch( CDIException e ) { + requestFailed( e.getMessage(), null ); + } + return iv; + } + + private synchronized ICDIRegister getCDIRegister() throws DebugException { + if ( fCDIRegister == null ) { + try { + fCDIRegister = getCDITarget().createRegister( (ICDIRegisterDescriptor)getCDIVariableObject() ); + } + catch( CDIException e ) { + requestFailed( e.getMessage(), null ); + } + } + return fCDIRegister; + } + + private void setCDIRegister( ICDIRegister register ) { + fCDIRegister = register; + } + + private ICDIVariableDescriptor getCDIVariableObject() { + if ( fCDIRegister != null ) { + return fCDIRegister; + } + return fCDIVariableObject; + } + + private void setCDIVariableObject( ICDIVariableDescriptor variableObject ) { + fCDIVariableObject = variableObject; + } + + public String getQualifiedName() throws DebugException { + if ( fQualifiedName == null ) { + try { + fQualifiedName = (fCDIVariableObject != null) ? fCDIVariableObject.getQualifiedName() : null; + } + catch( CDIException e ) { + requestFailed( e.getMessage(), null ); + } + } + return fQualifiedName; + } + + public CType getType() throws DebugException { + if ( fType == null ) { + ICDIVariableDescriptor varObject = getCDIVariableObject(); + if ( varObject != null ) { + synchronized( this ) { + if ( fType == null ) { + try { + fType = new CType( varObject.getType() ); + } + catch( CDIException e ) { + requestFailed( e.getMessage(), null ); + } + } + } + } + } + return fType; + } + + private synchronized void invalidate( boolean destroy ) { + try { + if ( destroy && fCDIRegister != null ) + fCDIRegister.dispose(); + } + catch( CDIException e ) { + logError( e.getMessage() ); + } + invalidateValue(); + setCDIRegister( null ); + if ( fType != null ) + fType.dispose(); + fType = null; + } + + public void dispose( boolean destroy ) { + invalidate( destroy ); + } + + public boolean isSameVariable( ICDIVariable cdiVar ) { + return ( fCDIRegister != null ) ? fCDIRegister.equals( cdiVar ) : false; + } + + public int sizeof() { + if ( getCDIVariableObject() != null ) { + try { + return getCDIVariableObject().sizeof(); + } + catch( CDIException e ) { + } + } + return 0; + } + + public boolean isArgument() { + return ( getCDIVariableObject() instanceof ICDIArgumentDescriptor ); + } + + public void setValue( String expression ) throws DebugException { + ICDIRegister cdiRegister = null; + try { + cdiRegister = getCDIRegister(); + if ( cdiRegister != null ) + cdiRegister.setValue( expression ); + else + requestFailed( CoreModelMessages.getString( "CModificationVariable.0" ), null ); //$NON-NLS-1$ + } + catch( CDIException e ) { + targetRequestFailed( e.getMessage(), null ); + } + } + + public synchronized ICValue getValue() throws DebugException { + if ( fValue.equals( CValueFactory.NULL_VALUE ) ) { + ICDIRegister reg = getCDIRegister(); + if ( reg != null ) { + try { + ICDIValue cdiValue = reg.getValue( getCurrentStackFrame().getCDIStackFrame() ); + if ( cdiValue != null ) { + ICDIType cdiType = cdiValue.getType(); + if ( cdiValue instanceof ICDIArrayValue && cdiType != null ) { + ICType type = new CType( cdiType ); + if ( type.isArray() ) { + int[] dims = type.getArrayDimensions(); + if ( dims.length > 0 && dims[0] > 0 ) + fValue = CValueFactory.createIndexedValue( getVariable(), (ICDIArrayValue)cdiValue, 0, dims[0] ); + } + } + else { + fValue = CValueFactory.createValue( getVariable(), cdiValue ); + } + } + } + catch( CDIException e ) { + requestFailed( e.getMessage(), e ); + } + } + } + return fValue; + } + + public void invalidateValue() { + if ( fValue instanceof AbstractCValue ) { + ((AbstractCValue)fValue).dispose(); + fValue = CValueFactory.NULL_VALUE; + } + } + + public boolean isChanged() { + return fChanged; + } + + public synchronized void setChanged( boolean changed ) { + if ( changed ) { + invalidateValue(); + } + if ( fValue instanceof AbstractCValue ) { + ((AbstractCValue)fValue).setChanged( changed ); + } + fChanged = changed; + } + + public synchronized void preserve() { + setChanged( false ); + if ( fValue instanceof AbstractCValue ) { + ((AbstractCValue)fValue).preserve(); + } + } + + CVariable getVariable() { + return fVariable; + } + + private void setVariable( CVariable variable ) { + fVariable = variable; + } + + public void resetValue() { + if ( fValue instanceof AbstractCValue ) { + ((AbstractCValue)fValue).reset(); + } + } + + public boolean isEditable() throws DebugException { + ICDIRegister reg = getCDIRegister(); + if ( reg != null ) { + try { + return reg.isEditable(); + } + catch( CDIException e ) { + } + } + return false; + } + /** + * Compares the underlying variable objects. + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals( Object obj ) { + if ( obj instanceof InternalVariable ) { + return getCDIVariableObject().equals( ((InternalVariable)obj).getCDIVariableObject() ); + } + return false; + } + + public boolean isSameDescriptor( ICDIVariableDescriptor desc ) { + return getCDIVariableObject().equals( desc ); + } + } /** * Constructor for CRegister. */ protected CRegister( CRegisterGroup parent, IRegisterDescriptor descriptor ) { - super( parent, null, ((CRegisterDescriptor)descriptor).getCDIDescriptor() ); + super( parent, ((CRegisterDescriptor)descriptor).getCDIDescriptor() ); setFormat( CVariableFormat.getFormat( CDebugCorePlugin.getDefault().getPluginPreferences().getInt( ICDebugConstants.PREF_DEFAULT_REGISTER_FORMAT ) ) ); } @@ -37,7 +328,7 @@ public class CRegister extends CGlobalVariable implements IRegister { * Constructor for CRegister. */ protected CRegister( CRegisterGroup parent, IRegisterDescriptor descriptor, String message ) { - super( parent, null, ((CRegisterDescriptor)descriptor).getCDIDescriptor(), message ); + super( parent, ((CRegisterDescriptor)descriptor).getCDIDescriptor(), message ); setFormat( CVariableFormat.getFormat( CDebugCorePlugin.getDefault().getPluginPreferences().getInt( ICDebugConstants.PREF_DEFAULT_REGISTER_FORMAT ) ) ); } @@ -60,4 +351,49 @@ public class CRegister extends CGlobalVariable implements IRegister { } return result; } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.model.ICVariable#canEnableDisable() + */ + public boolean canEnableDisable() { + return true; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener#handleDebugEvents(org.eclipse.cdt.debug.core.cdi.event.ICDIEvent[]) + */ + public void handleDebugEvents( ICDIEvent[] events ) { + for( int i = 0; i < events.length; i++ ) { + ICDIEvent event = events[i]; + if ( event instanceof ICDIResumedEvent ) { + ICDIObject source = event.getSource(); + if ( source != null ) { + ICDITarget cdiTarget = source.getTarget(); + if ( getCDITarget().equals( cdiTarget ) ) { + setChanged( false ); + } + } + } + } + super.handleDebugEvents( events ); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.internal.core.model.AbstractCVariable#dispose() + */ + public void dispose() { + internalDispose( true ); + setDisposed( true ); + } + + protected CStackFrame getCurrentStackFrame() { + return ((CDebugTarget)getDebugTarget()).getRegisterManager().getCurrentFrame(); + } + + protected void createOriginal( ICDIVariableDescriptor vo ) { + if ( vo != null ) { + setName( vo.getName() ); + setOriginal( new InternalVariable( this, vo ) ); + } + } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CRegisterGroup.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CRegisterGroup.java index 6b41a2d0955..bb9773523e5 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CRegisterGroup.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CRegisterGroup.java @@ -241,7 +241,7 @@ public class CRegisterGroup extends CDebugElement implements IPersistableRegiste } private void invalidate() { - if (fRegisters == null) { + if ( fRegisters == null ) { return; } for ( int i = 0; i < fRegisters.length; ++i ) { @@ -251,4 +251,15 @@ public class CRegisterGroup extends CDebugElement implements IPersistableRegiste } fRegisters = null; } + + public void resetRegisterValues() { + if ( fRegisters == null ) { + return; + } + for ( int i = 0; i < fRegisters.length; ++i ) { + if ( fRegisters[i] != null ) { + ((CRegister)fRegisters[i]).invalidateValue(); + } + } + } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CStackFrame.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CStackFrame.java index 5d44ac84058..593df825ed1 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CStackFrame.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CStackFrame.java @@ -127,7 +127,7 @@ public class CStackFrame extends CDebugElement implements ICStackFrame, IRestart fVariables = new ArrayList( vars.size() ); Iterator it = vars.iterator(); while( it.hasNext() ) { - fVariables.add( CVariableFactory.createVariable( this, (ICDIVariableDescriptor)it.next() ) ); + fVariables.add( CVariableFactory.createLocalVariable( this, (ICDIVariableDescriptor)it.next() ) ); } } else if ( refreshVariables() ) { @@ -158,7 +158,7 @@ public class CStackFrame extends CDebugElement implements ICStackFrame, IRestart // add any new locals Iterator newOnes = locals.iterator(); while( newOnes.hasNext() ) { - fVariables.add( CVariableFactory.createVariable( this, (ICDIVariableDescriptor)newOnes.next() ) ); + fVariables.add( CVariableFactory.createLocalVariable( this, (ICDIVariableDescriptor)newOnes.next() ) ); } } 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 ef677d31a7c..b5e540f2c73 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 @@ -126,7 +126,7 @@ public class CValue extends AbstractCValue { fVariables = new ArrayList( vars.size() ); Iterator it = vars.iterator(); while( it.hasNext() ) { - fVariables.add( CVariableFactory.createVariable( this, (ICDIVariable)it.next() ) ); + fVariables.add( CVariableFactory.createLocalVariable( this, (ICDIVariable)it.next() ) ); } resetStatus(); } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CVariable.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CVariable.java index 3addeb30fed..66ffbd70fe2 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CVariable.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CVariable.java @@ -14,19 +14,14 @@ import java.text.MessageFormat; import org.eclipse.cdt.debug.core.CDebugCorePlugin; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.debug.core.ICDebugConstants; -import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.event.ICDIChangedEvent; import org.eclipse.cdt.debug.core.cdi.event.ICDIEvent; import org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener; import org.eclipse.cdt.debug.core.cdi.event.ICDIResumedEvent; -import org.eclipse.cdt.debug.core.cdi.model.ICDIArgumentDescriptor; import org.eclipse.cdt.debug.core.cdi.model.ICDIObject; 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; 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.ICDIType; import org.eclipse.cdt.debug.core.model.CVariableFormat; import org.eclipse.cdt.debug.core.model.ICDebugElementStatus; import org.eclipse.cdt.debug.core.model.ICType; @@ -39,289 +34,26 @@ import org.eclipse.debug.core.model.IValue; /** * Represents a variable in the CDI model. */ -public class CVariable extends AbstractCVariable implements ICDIEventListener { - - /** - * Represents a single CDI variable. - */ - private class InternalVariable { - - /** - * The enclosing <code>CVariable</code> instance. - */ - private CVariable fVariable; - - /** - * The CDI variable object this variable is based on. - */ - private ICDIVariableDescriptor fCDIVariableObject; - - /** - * The underlying CDI variable. - */ - private ICDIVariable fCDIVariable; - - /** - * The type of this variable. - */ - private CType fType; - - /** - * The expression used to eveluate the value of this variable. - */ - private String fQualifiedName; - - /** - * The cache of the current value. - */ - private ICValue fValue = CValueFactory.NULL_VALUE; - - /** - * The change flag. - */ - private boolean fChanged = false; - - /** - * Constructor for InternalVariable. - */ - InternalVariable( CVariable var, ICDIVariableDescriptor varObject ) { - setVariable( var ); - setCDIVariableObject( varObject ); - setCDIVariable( (varObject instanceof ICDIVariable) ? (ICDIVariable)varObject : null ); - } - - InternalVariable createShadow( int start, int length ) throws DebugException { - InternalVariable iv = null; - try { - iv = new InternalVariable( getVariable(), getCDIVariableObject().getVariableDescriptorAsArray( start, length ) ); - } - catch( CDIException e ) { - requestFailed( e.getMessage(), null ); - } - return iv; - } - - InternalVariable createShadow( String type ) throws DebugException { - InternalVariable iv = null; - try { - iv = new InternalVariable( getVariable(), getCDIVariableObject().getVariableDescriptorAsType( type ) ); - } - catch( CDIException e ) { - requestFailed( e.getMessage(), null ); - } - return iv; - } - - private synchronized ICDIVariable getCDIVariable() throws DebugException { - if ( fCDIVariable == null ) { - try { - fCDIVariable = getCDIVariableObject().createVariable( ); - } - catch( CDIException e ) { - requestFailed( e.getMessage(), null ); - } - } - return fCDIVariable; - } - - private void setCDIVariable( ICDIVariable variable ) { - fCDIVariable = variable; - } - - private ICDIVariableDescriptor getCDIVariableObject() { - if ( fCDIVariable != null ) { - return fCDIVariable; - } - return fCDIVariableObject; - } - - private void setCDIVariableObject( ICDIVariableDescriptor variableObject ) { - fCDIVariableObject = variableObject; - } - - String getQualifiedName() throws DebugException { - if ( fQualifiedName == null ) { - try { - fQualifiedName = (fCDIVariableObject != null) ? fCDIVariableObject.getQualifiedName() : null; - } - catch( CDIException e ) { - requestFailed( e.getMessage(), null ); - } - } - return fQualifiedName; - } - - CType getType() throws DebugException { - if ( fType == null ) { - ICDIVariableDescriptor varObject = getCDIVariableObject(); - if ( varObject != null ) { - synchronized( this ) { - if ( fType == null ) { - try { - fType = new CType( varObject.getType() ); - } - catch( CDIException e ) { - requestFailed( e.getMessage(), null ); - } - } - } - } - } - return fType; - } - - synchronized void invalidate( boolean destroy ) { - try { - if ( destroy && fCDIVariable != null ) - fCDIVariable.dispose(); - } - catch( CDIException e ) { - logError( e.getMessage() ); - } - invalidateValue(); - setCDIVariable( null ); - if ( fType != null ) - fType.dispose(); - fType = null; - } - - void dispose( boolean destroy ) { - invalidate( destroy ); - } - - boolean isSameVariable( ICDIVariable cdiVar ) { - return ( fCDIVariable != null ) ? fCDIVariable.equals( cdiVar ) : false; - } - - int sizeof() { - if ( getCDIVariableObject() != null ) { - try { - return getCDIVariableObject().sizeof(); - } - catch( CDIException e ) { - } - } - return 0; - } - - boolean isArgument() { - return ( getCDIVariableObject() instanceof ICDIArgumentDescriptor ); - } - - void setValue( String expression ) throws DebugException { - ICDIVariable cdiVariable = null; - try { - cdiVariable = getCDIVariable(); - if ( cdiVariable != null ) - cdiVariable.setValue( expression ); - else - requestFailed( CoreModelMessages.getString( "CModificationVariable.0" ), null ); //$NON-NLS-1$ - } - catch( CDIException e ) { - targetRequestFailed( e.getMessage(), null ); - } - } - - void setValue( ICValue value ) { - fValue = value; - } - - synchronized ICValue getValue() throws DebugException { - if ( fValue.equals( CValueFactory.NULL_VALUE ) ) { - ICDIVariable var = getCDIVariable(); - if ( var != null ) { - try { - ICDIValue cdiValue = var.getValue(); - if ( cdiValue != null ) { - ICDIType cdiType = cdiValue.getType(); - if ( cdiValue instanceof ICDIArrayValue && cdiType != null ) { - ICType type = new CType( cdiType ); - if ( type.isArray() ) { - int[] dims = type.getArrayDimensions(); - if ( dims.length > 0 && dims[0] > 0 ) - fValue = CValueFactory.createIndexedValue( getVariable(), (ICDIArrayValue)cdiValue, 0, dims[0] ); - } - } - else { - fValue = CValueFactory.createValue( getVariable(), cdiValue ); - } - } - } - catch( CDIException e ) { - requestFailed( e.getMessage(), e ); - } - } - } - return fValue; - } - - void invalidateValue() { - if ( fValue instanceof AbstractCValue ) { - ((AbstractCValue)fValue).dispose(); - fValue = CValueFactory.NULL_VALUE; - } - } - - boolean isChanged() { - return fChanged; - } - - synchronized void setChanged( boolean changed ) { - if ( changed ) { - invalidateValue(); - } - if ( fValue instanceof AbstractCValue ) { - ((AbstractCValue)fValue).setChanged( changed ); - } - fChanged = changed; - } - - synchronized void preserve() { - setChanged( false ); - if ( fValue instanceof AbstractCValue ) { - ((AbstractCValue)fValue).preserve(); - } - } - - CVariable getVariable() { - return fVariable; - } - - private void setVariable( CVariable variable ) { - fVariable = variable; - } - - void resetValue() { - if ( fValue instanceof AbstractCValue ) { - ((AbstractCValue)fValue).reset(); - } - } - - boolean isEditable() throws DebugException { - ICDIVariable var = getCDIVariable(); - if ( var != null ) { - try { - return var.isEditable(); - } - catch( CDIException e ) { - } - } - return false; - } - /** - * Compares the underlying variable objects. - * @see java.lang.Object#equals(java.lang.Object) - */ - public boolean equals( Object obj ) { - if ( obj instanceof InternalVariable ) { - return getCDIVariableObject().equals( ((InternalVariable)obj).getCDIVariableObject() ); - } - return false; - } - - boolean sameVariable( ICDIVariableDescriptor vo ) { - return getCDIVariableObject().equals( vo ); - } +public abstract class CVariable extends AbstractCVariable implements ICDIEventListener { + + interface IInternalVariable { + IInternalVariable createShadow( int start, int length ) throws DebugException; + IInternalVariable createShadow( String type ) throws DebugException; + CType getType() throws DebugException; + String getQualifiedName() throws DebugException; + ICValue getValue() throws DebugException; + void setValue( String expression ) throws DebugException; + boolean isChanged(); + void setChanged( boolean changed ); + void dispose( boolean destroy ); + boolean isSameDescriptor( ICDIVariableDescriptor desc ); + boolean isSameVariable( ICDIVariable cdiVar ); + void resetValue(); + boolean isEditable() throws DebugException; + boolean isArgument(); + int sizeof(); + void invalidateValue(); + void preserve(); } /** @@ -332,12 +64,12 @@ public class CVariable extends AbstractCVariable implements ICDIEventListener { /** * The original internal variable. */ - private InternalVariable fOriginal; + private IInternalVariable fOriginal; /** * The shadow internal variable used for casting. */ - private InternalVariable fShadow; + private IInternalVariable fShadow; /** * The name of this variable. @@ -360,7 +92,7 @@ public class CVariable extends AbstractCVariable implements ICDIEventListener { protected CVariable( CDebugElement parent, ICDIVariableDescriptor cdiVariableObject ) { super( parent ); if ( cdiVariableObject != null ) { - fName = cdiVariableObject.getName(); + setName( cdiVariableObject.getName() ); createOriginal( cdiVariableObject ); } fIsEnabled = ( parent instanceof AbstractCValue ) ? ((AbstractCValue)parent).getParentVariable().isEnabled() : !isBookkeepingEnabled(); @@ -373,7 +105,7 @@ public class CVariable extends AbstractCVariable implements ICDIEventListener { protected CVariable( CDebugElement parent, ICDIVariableDescriptor cdiVariableObject, String errorMessage ) { super( parent ); if ( cdiVariableObject != null ) { - fName = cdiVariableObject.getName(); + setName( cdiVariableObject.getName() ); createOriginal( cdiVariableObject ); } fIsEnabled = !isBookkeepingEnabled(); @@ -389,7 +121,7 @@ public class CVariable extends AbstractCVariable implements ICDIEventListener { public ICType getType() throws DebugException { if ( isDisposed() ) return null; - InternalVariable iv = getCurrentInternalVariable(); + IInternalVariable iv = getCurrentInternalVariable(); return ( iv != null ) ? iv.getType() : null; } @@ -408,7 +140,7 @@ public class CVariable extends AbstractCVariable implements ICDIEventListener { * @see org.eclipse.cdt.debug.core.model.ICVariable#setEnabled(boolean) */ public void setEnabled( boolean enabled ) throws DebugException { - InternalVariable iv = getOriginal(); + IInternalVariable iv = getOriginal(); if ( iv != null ) iv.dispose( true ); iv = getShadow(); @@ -433,7 +165,7 @@ public class CVariable extends AbstractCVariable implements ICDIEventListener { * @see org.eclipse.cdt.debug.core.model.ICVariable#isArgument() */ public boolean isArgument() { - InternalVariable iv = getOriginal(); + IInternalVariable iv = getOriginal(); return ( iv != null ) ? iv.isArgument() : false; } @@ -444,7 +176,7 @@ public class CVariable extends AbstractCVariable implements ICDIEventListener { */ public IValue getValue() throws DebugException { if ( !isDisposed() && isEnabled() ) { - InternalVariable iv = getCurrentInternalVariable(); + IInternalVariable iv = getCurrentInternalVariable(); if ( iv != null ) { try { return iv.getValue(); @@ -484,7 +216,7 @@ public class CVariable extends AbstractCVariable implements ICDIEventListener { public boolean hasValueChanged() throws DebugException { if ( isDisposed() ) return false; - InternalVariable iv = getCurrentInternalVariable(); + IInternalVariable iv = getCurrentInternalVariable(); return ( iv != null ) ? iv.isChanged() : false; } @@ -539,9 +271,9 @@ public class CVariable extends AbstractCVariable implements ICDIEventListener { * @see org.eclipse.cdt.debug.core.model.ICastToArray#castToArray(int, int) */ public void castToArray( int startIndex, int length ) throws DebugException { - InternalVariable current = getCurrentInternalVariable(); + IInternalVariable current = getCurrentInternalVariable(); if ( current != null ) { - InternalVariable newVar = current.createShadow( startIndex, length ); + IInternalVariable newVar = current.createShadow( startIndex, length ); if ( getShadow() != null ) getShadow().dispose( true ); setShadow( newVar ); @@ -557,7 +289,7 @@ public class CVariable extends AbstractCVariable implements ICDIEventListener { * @see org.eclipse.debug.core.model.IValueModification#setValue(java.lang.String) */ public void setValue( String expression ) throws DebugException { - InternalVariable iv = getCurrentInternalVariable(); + IInternalVariable iv = getCurrentInternalVariable(); if ( iv != null ) { String newExpression = processExpression( expression ); iv.setValue( newExpression ); @@ -635,9 +367,9 @@ public class CVariable extends AbstractCVariable implements ICDIEventListener { * @see org.eclipse.cdt.debug.core.model.ICastToType#cast(java.lang.String) */ public void cast( String type ) throws DebugException { - InternalVariable current = getCurrentInternalVariable(); + IInternalVariable current = getCurrentInternalVariable(); if ( current != null ) { - InternalVariable newVar = current.createShadow( type ); + IInternalVariable newVar = current.createShadow( type ); if ( getShadow() != null ) getShadow().dispose( true ); setShadow( newVar ); @@ -653,11 +385,11 @@ public class CVariable extends AbstractCVariable implements ICDIEventListener { * @see org.eclipse.cdt.debug.core.model.ICastToType#restoreOriginal() */ public void restoreOriginal() throws DebugException { - InternalVariable oldVar = getShadow(); + IInternalVariable oldVar = getShadow(); setShadow( null ); if ( oldVar != null ) oldVar.dispose( true ); - InternalVariable iv = getOriginal(); + IInternalVariable iv = getOriginal(); if ( iv != null ) iv.invalidateValue(); // If casting of variable to a type or array causes an error, the status @@ -680,7 +412,7 @@ public class CVariable extends AbstractCVariable implements ICDIEventListener { * @see org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener#handleDebugEvents(org.eclipse.cdt.debug.core.cdi.event.ICDIEvent[]) */ public void handleDebugEvents( ICDIEvent[] events ) { - InternalVariable iv = getCurrentInternalVariable(); + IInternalVariable iv = getCurrentInternalVariable(); if ( iv == null ) return; for( int i = 0; i < events.length; i++ ) { @@ -707,7 +439,7 @@ public class CVariable extends AbstractCVariable implements ICDIEventListener { if ( hasErrors() ) { resetStatus(); changed = true; - InternalVariable iv = getCurrentInternalVariable(); + IInternalVariable iv = getCurrentInternalVariable(); if ( iv != null ) iv.invalidateValue(); } @@ -716,32 +448,32 @@ public class CVariable extends AbstractCVariable implements ICDIEventListener { } private void handleChangedEvent( ICDIChangedEvent event ) { - InternalVariable iv = getCurrentInternalVariable(); + IInternalVariable iv = getCurrentInternalVariable(); if ( iv != null ) { iv.setChanged( true ); fireChangeEvent( DebugEvent.STATE ); } } - private InternalVariable getCurrentInternalVariable() { + private IInternalVariable getCurrentInternalVariable() { if ( getShadow() != null ) return getShadow(); return getOriginal(); } - private InternalVariable getOriginal() { + private IInternalVariable getOriginal() { return fOriginal; } - private void setOriginal( InternalVariable original ) { + protected void setOriginal( IInternalVariable original ) { fOriginal = original; } - private InternalVariable getShadow() { + private IInternalVariable getShadow() { return fShadow; } - private void setShadow( InternalVariable shadow ) { + private void setShadow( IInternalVariable shadow ) { fShadow = shadow; } @@ -755,25 +487,21 @@ public class CVariable extends AbstractCVariable implements ICDIEventListener { return result; } - private void createOriginal( ICDIVariableDescriptor vo ) { - if ( vo != null ) - fName = vo.getName(); - setOriginal( new InternalVariable( this, vo ) ); - } + abstract protected void createOriginal( ICDIVariableDescriptor vo ); protected boolean hasErrors() { return !isOK(); } protected void setChanged( boolean changed ) { - InternalVariable iv = getCurrentInternalVariable(); + IInternalVariable iv = getCurrentInternalVariable(); if ( iv != null ) { iv.setChanged( changed ); } } protected void resetValue() { - InternalVariable iv = getCurrentInternalVariable(); + IInternalVariable iv = getCurrentInternalVariable(); if ( iv != null ) { resetStatus(); iv.resetValue(); @@ -795,7 +523,7 @@ public class CVariable extends AbstractCVariable implements ICDIEventListener { } protected int sizeof() { - InternalVariable iv = getCurrentInternalVariable(); + IInternalVariable iv = getCurrentInternalVariable(); return ( iv != null ) ? iv.sizeof() : -1; } @@ -805,15 +533,15 @@ public class CVariable extends AbstractCVariable implements ICDIEventListener { */ public boolean equals( Object obj ) { if ( obj instanceof CVariable ) { - InternalVariable iv = getOriginal(); + IInternalVariable iv = getOriginal(); return ( iv != null ) ? iv.equals( ((CVariable)obj).getOriginal() ) : false; } return false; } protected boolean sameVariable( ICDIVariableDescriptor vo ) { - InternalVariable iv = getOriginal(); - return ( iv != null && iv.sameVariable( vo ) ); + IInternalVariable iv = getOriginal(); + return ( iv != null && iv.isSameDescriptor( vo ) ); } protected void setFormat( CVariableFormat format ) { @@ -824,7 +552,7 @@ public class CVariable extends AbstractCVariable implements ICDIEventListener { * @see org.eclipse.cdt.debug.core.model.ICVariable#getExpressionString() */ public String getExpressionString() throws DebugException { - InternalVariable iv = getCurrentInternalVariable(); + IInternalVariable iv = getCurrentInternalVariable(); return ( iv != null ) ? iv.getQualifiedName() : null; } @@ -833,14 +561,14 @@ public class CVariable extends AbstractCVariable implements ICDIEventListener { */ protected void preserve() { resetStatus(); - InternalVariable iv = getCurrentInternalVariable(); + IInternalVariable iv = getCurrentInternalVariable(); if ( iv != null ) iv.preserve(); } protected void internalDispose( boolean destroy ) { getCDISession().getEventManager().removeEventListener( this ); - InternalVariable iv = getOriginal(); + IInternalVariable iv = getOriginal(); if ( iv != null ) iv.dispose( destroy ); iv = getShadow(); @@ -855,4 +583,15 @@ public class CVariable extends AbstractCVariable implements ICDIEventListener { protected void setDisposed( boolean isDisposed ) { fIsDisposed = isDisposed; } + + protected void invalidateValue() { + resetStatus(); + IInternalVariable iv = getCurrentInternalVariable(); + if ( iv != null ) + iv.invalidateValue(); + } + + protected void setName( String name ) { + fName = name; + } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CVariableFactory.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CVariableFactory.java index 94d435aa2cf..fc59eb021b8 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CVariableFactory.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CVariableFactory.java @@ -25,12 +25,12 @@ import org.eclipse.core.runtime.Path; */ public class CVariableFactory { - public static CVariable createVariable( CDebugElement parent, ICDIVariableDescriptor cdiVariableObject ) { - return new CVariable( parent, cdiVariableObject ); + public static CLocalVariable createLocalVariable( CDebugElement parent, ICDIVariableDescriptor cdiVariableObject ) { + return new CLocalVariable( parent, cdiVariableObject ); } - public static CVariable createVariableWithError( CDebugElement parent, ICDIVariableDescriptor cdiVariableObject, String message ) { - return new CVariable( parent, cdiVariableObject, message ); + public static CLocalVariable createLocalVariableWithError( CDebugElement parent, ICDIVariableDescriptor cdiVariableObject, String message ) { + return new CLocalVariable( parent, cdiVariableObject, message ); } public static IGlobalVariableDescriptor createGlobalVariableDescriptor( final String name, final IPath path ) { |