From a5fdd63e34dd4d49f63c6975be12c8c478f631b8 Mon Sep 17 00:00:00 2001 From: Mikhail Khodjaiants Date: Fri, 29 Jul 2005 02:12:02 +0000 Subject: [PATCH] Bug 104421: Register view can not show correct value when switch between different thread or stack frame. --- debug/org.eclipse.cdt.debug.core/ChangeLog | 20 + .../debug/core/cdi/model/ICDIRegister.java | 49 ++- .../debug/core/cdi/model/ICDIStackFrame.java | 24 +- .../cdt/debug/core/cdi/model/ICDITarget.java | 27 +- .../cdt/debug/core/cdi/model/ICDIThread.java | 11 + .../debug/core/cdi/model/ICDIVariable.java | 8 - .../cdi/model/ICDIVariableDescriptor.java | 11 - .../debug/internal/core/CRegisterManager.java | 19 +- .../internal/core/model/CExpression.java | 2 +- .../internal/core/model/CGlobalVariable.java | 294 +++++++++++++ .../internal/core/model/CIndexedValue.java | 2 +- .../internal/core/model/CLocalVariable.java | 325 +++++++++++++++ .../debug/internal/core/model/CRegister.java | 342 ++++++++++++++- .../internal/core/model/CRegisterGroup.java | 13 +- .../internal/core/model/CStackFrame.java | 4 +- .../cdt/debug/internal/core/model/CValue.java | 2 +- .../debug/internal/core/model/CVariable.java | 389 +++--------------- .../internal/core/model/CVariableFactory.java | 8 +- debug/org.eclipse.cdt.debug.mi.core/ChangeLog | 12 + .../debug/mi/core/cdi/RegisterManager.java | 57 +++ .../cdt/debug/mi/core/cdi/model/Register.java | 36 ++ .../debug/mi/core/cdi/model/StackFrame.java | 28 ++ .../cdt/debug/mi/core/cdi/model/Target.java | 31 +- .../cdt/debug/mi/core/cdi/model/Thread.java | 13 + .../cdt/debug/mi/core/cdi/model/Value.java | 22 +- .../cdt/debug/mi/core/cdi/model/Variable.java | 10 +- .../mi/core/cdi/model/VariableDescriptor.java | 16 +- .../mi/core/cdi/model/type/ArrayValue.java | 5 +- 28 files changed, 1394 insertions(+), 386 deletions(-) create mode 100644 debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CLocalVariable.java diff --git a/debug/org.eclipse.cdt.debug.core/ChangeLog b/debug/org.eclipse.cdt.debug.core/ChangeLog index 28f61f069f9..02036fb86bb 100644 --- a/debug/org.eclipse.cdt.debug.core/ChangeLog +++ b/debug/org.eclipse.cdt.debug.core/ChangeLog @@ -1,3 +1,23 @@ +2005-07-28 Mikhail Khodjaiants + Bug 104421: Register view can not show correct value when switch between different thread or stack frame. + * ICDIRegister.java + * ICDIStackFrame.java + * ICDITarget.java + * ICDIThread.java + * ICDIVariable.java + * ICDIVariableDescriptor.java + * CRegisterManager.java + * CExpression.java + * CGlobalVariable.java + * CIndexedValue.java + + CLocalVariable.java + * CRegister.java + * CRegisterGroup.java + * CStackFrame.java + * CValue.java + * CVariable.java + * CVariableFactory.java + 2005-07-28 Mikhail Khodjaiants Bug 103567: breakpoints view of of sync w/CDT CVS HEAD * CBreakpointManager.java diff --git a/debug/org.eclipse.cdt.debug.core/cdi/org/eclipse/cdt/debug/core/cdi/model/ICDIRegister.java b/debug/org.eclipse.cdt.debug.core/cdi/org/eclipse/cdt/debug/core/cdi/model/ICDIRegister.java index da962582519..d0ae70eae4f 100644 --- a/debug/org.eclipse.cdt.debug.core/cdi/org/eclipse/cdt/debug/core/cdi/model/ICDIRegister.java +++ b/debug/org.eclipse.cdt.debug.core/cdi/org/eclipse/cdt/debug/core/cdi/model/ICDIRegister.java @@ -11,6 +11,8 @@ package org.eclipse.cdt.debug.core.cdi.model; +import org.eclipse.cdt.debug.core.cdi.CDIException; + /** * * A register is a special kind of variable that is contained @@ -18,5 +20,50 @@ package org.eclipse.cdt.debug.core.cdi.model; * * @since Jul 9, 2002 */ -public interface ICDIRegister extends ICDIVariable, ICDIRegisterDescriptor { +public interface ICDIRegister extends ICDIRegisterDescriptor { + /** + * Returns true if the value of this variable could be changed. + * + * @return true if the value of this variable could be changed + * @throws CDIException if this method fails. Reasons include: + */ + boolean isEditable() throws CDIException; + + /** + * Returns the value of this variable. + * + * @param context + * @return the value of this variable + * @throws CDIException if this method fails. Reasons include: + */ + ICDIValue getValue(ICDIStackFrame context) throws CDIException; + + /** + * Attempts to set the value of this variable to the value of + * the given expression. + * + * @param expression - an expression to generate a new value + * @throws CDIException if this method fails. Reasons include: + */ + void setValue(String expression) throws CDIException; + + /** + * Sets the value of this variable to the given value. + * + * @param value - a new value + * @throws CDIException if this method fails. Reasons include: + */ + void setValue(ICDIValue value) throws CDIException; + + /** + * Remove the variable from the manager list. + * + * @param var + * @return ICDIArgument + * @throws CDIException + */ + void dispose() throws CDIException; + + boolean equals(ICDIRegister reg); + } diff --git a/debug/org.eclipse.cdt.debug.core/cdi/org/eclipse/cdt/debug/core/cdi/model/ICDIStackFrame.java b/debug/org.eclipse.cdt.debug.core/cdi/org/eclipse/cdt/debug/core/cdi/model/ICDIStackFrame.java index 418b0362f78..ddde8e1bcd8 100644 --- a/debug/org.eclipse.cdt.debug.core/cdi/org/eclipse/cdt/debug/core/cdi/model/ICDIStackFrame.java +++ b/debug/org.eclipse.cdt.debug.core/cdi/org/eclipse/cdt/debug/core/cdi/model/ICDIStackFrame.java @@ -40,7 +40,29 @@ public interface ICDIStackFrame extends ICDIExecuteStepReturn, ICDIObject { * @throws CDIException if this method fails. Reasons include: */ ICDILocalVariableDescriptor[] getLocalVariableDescriptors() throws CDIException; - + + /** + * Create a variable from the descriptor for evaluation. A CreatedEvent will be trigger and + * ChangedEvent will also be trigger when the variable is assign a new value. + * DestroyedEvent is fired when the variable is out of scope and automatically + * removed from the manager list. + * @param varDesc ICDThreadStorageDesc + * @return + * @throws CDIException + */ + ICDIArgument createArgument(ICDIArgumentDescriptor varDesc) throws CDIException; + + /** + * Create a variable from the descriptor for evaluation. A CreatedEvent will be trigger and + * ChangedEvent will also be trigger when the variable is assign a new value. + * DestroyedEvent is fired when the variable is out of scope and automatically + * removed from the manager list. + * @param varDesc ICDThreadStorageDesc + * @return + * @throws CDIException + */ + ICDILocalVariable createLocalVariable(ICDILocalVariableDescriptor varDesc) throws CDIException; + /** * Returns the arguments in this stack frame. An empty collection * is returned if there are no arguments. diff --git a/debug/org.eclipse.cdt.debug.core/cdi/org/eclipse/cdt/debug/core/cdi/model/ICDITarget.java b/debug/org.eclipse.cdt.debug.core/cdi/org/eclipse/cdt/debug/core/cdi/model/ICDITarget.java index b9df1c67d6c..baf316edd20 100644 --- a/debug/org.eclipse.cdt.debug.core/cdi/org/eclipse/cdt/debug/core/cdi/model/ICDITarget.java +++ b/debug/org.eclipse.cdt.debug.core/cdi/org/eclipse/cdt/debug/core/cdi/model/ICDITarget.java @@ -77,10 +77,22 @@ public interface ICDITarget extends ICDIThreadGroup, ICDIExpressionManagement, * @param filename * @param function * @param name - * @return ICDIVariableDescriptor + * @return ICDIGlobalVariableDescriptor * @throws CDIException */ - ICDIVariableDescriptor getGlobalVariableDescriptors(String filename, String function, String name) throws CDIException; + ICDIGlobalVariableDescriptor getGlobalVariableDescriptors(String filename, String function, String name) throws CDIException; + + /** + * Create a variable from the descriptor for evaluation. A CreatedEvent will be trigger and + * ChangedEvent will also be trigger when the variable is assign a new value. + * DestroyedEvent is fired when the variable is out of scope and automatically + * removed from the manager list. + * + * @param varDesc ICDIGlobalVariableDescriptor + * @return ICDIGlobalVariable + * @throws CDIException + */ + ICDIGlobalVariable createGlobalVariable(ICDIGlobalVariableDescriptor varDesc) throws CDIException; /** * Return the register groups. @@ -89,6 +101,17 @@ public interface ICDITarget extends ICDIThreadGroup, ICDIExpressionManagement, */ ICDIRegisterGroup[] getRegisterGroups() throws CDIException; + /** + * Create a variable from the descriptor for evaluation. A CreatedEvent will be trigger and + * ChangedEvent will also be trigger when the variable is assign a new value. + * DestroyedEvent is fired when the variable is out of scope and automatically + * removed from the manager list. + * @param varDesc ICDThreadStorageDesc + * @return + * @throws CDIException + */ + ICDIRegister createRegister(ICDIRegisterDescriptor varDesc) throws CDIException; + /** * Returns whether this target is terminated. * diff --git a/debug/org.eclipse.cdt.debug.core/cdi/org/eclipse/cdt/debug/core/cdi/model/ICDIThread.java b/debug/org.eclipse.cdt.debug.core/cdi/org/eclipse/cdt/debug/core/cdi/model/ICDIThread.java index f42ad7de76e..a9f27c869f8 100644 --- a/debug/org.eclipse.cdt.debug.core/cdi/org/eclipse/cdt/debug/core/cdi/model/ICDIThread.java +++ b/debug/org.eclipse.cdt.debug.core/cdi/org/eclipse/cdt/debug/core/cdi/model/ICDIThread.java @@ -66,6 +66,17 @@ public interface ICDIThread extends ICDIExecuteStep, ICDIExecuteResume, ICDISusp */ ICDIThreadStorageDescriptor[] getThreadStorageDescriptors() throws CDIException; + /** + * Create a variable from the descriptor for evaluation. A CreatedEvent will be trigger and + * ChangedEvent will also be trigger when the variable is assign a new value. + * DestroyedEvent is fired when the variable is out of scope and automatically + * removed from the manager list. + * @param varDesc ICDThreadStorageDesc + * @return + * @throws CDIException + */ + ICDIThreadStorage createThreadStorage(ICDIThreadStorageDescriptor varDesc) throws CDIException; + /** * Equivalent to resume(false) * diff --git a/debug/org.eclipse.cdt.debug.core/cdi/org/eclipse/cdt/debug/core/cdi/model/ICDIVariable.java b/debug/org.eclipse.cdt.debug.core/cdi/org/eclipse/cdt/debug/core/cdi/model/ICDIVariable.java index 84f4d3fa023..d8b32c80ec2 100644 --- a/debug/org.eclipse.cdt.debug.core/cdi/org/eclipse/cdt/debug/core/cdi/model/ICDIVariable.java +++ b/debug/org.eclipse.cdt.debug.core/cdi/org/eclipse/cdt/debug/core/cdi/model/ICDIVariable.java @@ -55,14 +55,6 @@ public interface ICDIVariable extends ICDIVariableDescriptor { */ void setValue(ICDIValue value) throws CDIException; - /** - * Set the format of the variable. - * - * @param format - @see ICDIFormat - * @throws CDIException if this method fails. - */ - void setFormat(int format) throws CDIException; - /** * Remove the variable from the manager list. * diff --git a/debug/org.eclipse.cdt.debug.core/cdi/org/eclipse/cdt/debug/core/cdi/model/ICDIVariableDescriptor.java b/debug/org.eclipse.cdt.debug.core/cdi/org/eclipse/cdt/debug/core/cdi/model/ICDIVariableDescriptor.java index 2c17895cc7b..dec935db4b7 100644 --- a/debug/org.eclipse.cdt.debug.core/cdi/org/eclipse/cdt/debug/core/cdi/model/ICDIVariableDescriptor.java +++ b/debug/org.eclipse.cdt.debug.core/cdi/org/eclipse/cdt/debug/core/cdi/model/ICDIVariableDescriptor.java @@ -78,17 +78,6 @@ public interface ICDIVariableDescriptor extends ICDIObject { */ ICDIVariableDescriptor getVariableDescriptorAsType(String type) throws CDIException; - /** - * Create a Variable for evaluation. A CreatedEvent will be trigger and - * ChangedEvent will also be trigger when the variable is assign a new value. - * DestroyedEvent is fired when the variable is out of scope and automatically - * removed from the manager list. - * @param var - * @return ICDIVariable - * @throws CDIException - */ - ICDIVariable createVariable() throws CDIException; - /** * Returns true if the variable Object are the same, * For example event if the name is the same because of 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 CVariable 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 CVariable 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 CVariable 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 { +public abstract class CVariable extends AbstractCVariable implements ICDIEventListener { - /** - * Represents a single CDI variable. - */ - private class InternalVariable { - - /** - * The enclosing CVariable 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 ); - } + 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 ) { diff --git a/debug/org.eclipse.cdt.debug.mi.core/ChangeLog b/debug/org.eclipse.cdt.debug.mi.core/ChangeLog index 2170c4f8a83..061a45c405f 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/ChangeLog +++ b/debug/org.eclipse.cdt.debug.mi.core/ChangeLog @@ -1,3 +1,15 @@ +2005-07-28 Alain Magloire + Fix Pr 104421: The register did not update. + * cdi/org/eclipse/cdt/debug/mi/core/cdi/RegisterManager.java + * cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Register.java + * cdi/org/eclipse/cdt/debug/mi/core/cdi/model/StackFrame.java + * cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Target.java + * cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Thread.java + * cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Value.java + * cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Variable.java + * cdi/org/eclipse/cdt/debug/mi/core/cdi/model/VariableDescriptor.java + * cdi/org/eclipse/cdt/debug/mi/core/cdi/model/type/ArrayValue.java + 2005-07-26 Alain Magloire Fix for 92446 * cdi/org/eclipse/cdt/debug/mi/core/cdi/VariableManager.java diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/RegisterManager.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/RegisterManager.java index fadd60229d0..8901bcc189f 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/RegisterManager.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/RegisterManager.java @@ -20,10 +20,14 @@ import org.eclipse.cdt.debug.core.cdi.model.ICDIRegisterDescriptor; import org.eclipse.cdt.debug.core.cdi.model.ICDIRegisterGroup; import org.eclipse.cdt.debug.mi.core.MIException; import org.eclipse.cdt.debug.mi.core.MISession; +import org.eclipse.cdt.debug.mi.core.cdi.model.LocalVariable; import org.eclipse.cdt.debug.mi.core.cdi.model.Register; import org.eclipse.cdt.debug.mi.core.cdi.model.RegisterDescriptor; import org.eclipse.cdt.debug.mi.core.cdi.model.RegisterGroup; +import org.eclipse.cdt.debug.mi.core.cdi.model.StackFrame; import org.eclipse.cdt.debug.mi.core.cdi.model.Target; +import org.eclipse.cdt.debug.mi.core.cdi.model.Thread; +import org.eclipse.cdt.debug.mi.core.cdi.model.Variable; import org.eclipse.cdt.debug.mi.core.cdi.model.VariableDescriptor; import org.eclipse.cdt.debug.mi.core.command.CommandFactory; import org.eclipse.cdt.debug.mi.core.command.MIDataListChangedRegisters; @@ -46,11 +50,13 @@ import org.eclipse.cdt.debug.mi.core.output.MIVarUpdateInfo; public class RegisterManager extends Manager { Map regsMap; + Map varMap; MIVarChange[] noChanges = new MIVarChange[0]; public RegisterManager(Session session) { super(session, true); regsMap = new Hashtable(); + varMap = new Hashtable(); // The register bookkeeping provides better update control. setAutoUpdate( true ); } @@ -64,6 +70,15 @@ public class RegisterManager extends Manager { return regsList; } + synchronized List getVariableList(Target target) { + List varList = (List)varMap.get(target); + if (varList == null) { + varList = Collections.synchronizedList(new ArrayList()); + varMap.put(target, varList); + } + return varList; + } + public ICDIRegisterGroup[] getRegisterGroups(Target target) throws CDIException { RegisterGroup group = new RegisterGroup(target, "Main"); //$NON-NLS-1$ return new ICDIRegisterGroup[] { group }; @@ -152,6 +167,33 @@ public class RegisterManager extends Manager { } } + public Variable createVariable(StackFrame frame, String reg) throws CDIException { + Target target = (Target)frame.getTarget(); + Thread currentThread = (Thread)target.getCurrentThread(); + StackFrame currentFrame = currentThread.getCurrentStackFrame(); + target.setCurrentThread(frame.getThread(), false); + ((Thread)frame.getThread()).setCurrentStackFrame(frame, false); + try { + MISession mi = target.getMISession(); + CommandFactory factory = mi.getCommandFactory(); + MIVarCreate var = factory.createMIVarCreate(reg); + mi.postCommand(var); + MIVarCreateInfo info = var.getMIVarCreateInfo(); + if (info == null) { + throw new CDIException(CdiResources.getString("cdi.Common.No_answer")); //$NON-NLS-1$ + } + Variable variable = new LocalVariable(target, null, frame, reg, null, 0, 0, info.getMIVar()); + List varList = getVariableList(target); + varList.add(variable); + return variable; + } catch (MIException e) { + throw new MI2CDIException(e); + } finally { + target.setCurrentThread(currentThread, false); + currentThread.setCurrentStackFrame(currentFrame, false); + } + } + /** * Use by the eventManager to find the Register; */ @@ -192,6 +234,13 @@ public class RegisterManager extends Manager { public void update(Target target) throws CDIException { MISession mi = target.getMISession(); + +// Variable[] vars = getVariables(target); +// for (int i = 0; i < vars.length; ++i) { +// removeMIVar(mi, vars[i].getMIVar()); +// List varList = getVariableList(target); +// varList.remove(vars[i]); +// } CommandFactory factory = mi.getCommandFactory(); MIDataListChangedRegisters changed = factory.createMIDataListChangedRegisters(); try { @@ -251,6 +300,14 @@ public class RegisterManager extends Manager { return new Register[0]; } + private Variable[] getVariables(Target target) { + List varList = (List)varMap.get(target); + if (varList != null) { + return (Variable[]) varList.toArray(new Variable[varList.size()]); + } + return new Register[0]; + } + /** * Return the Element with this thread/stackframe, and with this name. * null is return if the element is not in the cache. diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Register.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Register.java index e214916970b..1ef44a0563e 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Register.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Register.java @@ -10,12 +10,24 @@ *******************************************************************************/ package org.eclipse.cdt.debug.mi.core.cdi.model; +import java.util.List; + import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.model.ICDIRegister; +import org.eclipse.cdt.debug.core.cdi.model.ICDIStackFrame; import org.eclipse.cdt.debug.core.cdi.model.ICDITarget; +import org.eclipse.cdt.debug.core.cdi.model.ICDIValue; +import org.eclipse.cdt.debug.mi.core.MIException; +import org.eclipse.cdt.debug.mi.core.MISession; +import org.eclipse.cdt.debug.mi.core.cdi.CdiResources; +import org.eclipse.cdt.debug.mi.core.cdi.ExpressionManager; +import org.eclipse.cdt.debug.mi.core.cdi.MI2CDIException; import org.eclipse.cdt.debug.mi.core.cdi.RegisterManager; import org.eclipse.cdt.debug.mi.core.cdi.Session; +import org.eclipse.cdt.debug.mi.core.command.CommandFactory; +import org.eclipse.cdt.debug.mi.core.command.MIVarCreate; import org.eclipse.cdt.debug.mi.core.output.MIVar; +import org.eclipse.cdt.debug.mi.core.output.MIVarCreateInfo; /** */ @@ -57,10 +69,34 @@ public class Register extends Variable implements ICDIRegister { return new Register(target, thread, frame, name, fullName, pos, depth, miVar); } + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#dispose() + */ public void dispose() throws CDIException { ICDITarget target = getTarget(); RegisterManager regMgr = ((Session)target.getSession()).getRegisterManager(); regMgr.destroyRegister(this); } + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.cdi.model.ICDIRegister#getValue(org.eclipse.cdt.debug.core.cdi.model.ICDIStackFrame) + */ + public ICDIValue getValue(ICDIStackFrame context) throws CDIException { + Session session = (Session)getTarget().getSession(); + RegisterManager mgr = session.getRegisterManager(); + Variable var = mgr.createVariable((StackFrame)context, getQualifiedName()); + return var.getValue(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.cdi.model.ICDIRegister#equals(org.eclipse.cdt.debug.core.cdi.model.ICDIRegister) + */ + public boolean equals(ICDIRegister register) { + if (register instanceof Register) { + Register reg = (Register) register; + return super.equals(reg); + } + return super.equals(register); + } + } diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/StackFrame.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/StackFrame.java index e7b7a16648d..f3ee447997d 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/StackFrame.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/StackFrame.java @@ -14,7 +14,9 @@ import java.math.BigInteger; import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.ICDILocator; +import org.eclipse.cdt.debug.core.cdi.model.ICDIArgument; import org.eclipse.cdt.debug.core.cdi.model.ICDIArgumentDescriptor; +import org.eclipse.cdt.debug.core.cdi.model.ICDILocalVariable; import org.eclipse.cdt.debug.core.cdi.model.ICDILocalVariableDescriptor; import org.eclipse.cdt.debug.core.cdi.model.ICDIStackFrame; import org.eclipse.cdt.debug.core.cdi.model.ICDIThread; @@ -109,6 +111,32 @@ public class StackFrame extends CObject implements ICDIStackFrame { return localDescs; } + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.cdi.model.ICDIStackFrame#createArgument(org.eclipse.cdt.debug.core.cdi.model.ICDIArgumentDescriptor) + */ + public ICDIArgument createArgument(ICDIArgumentDescriptor varDesc) throws CDIException { + if (varDesc instanceof ArgumentDescriptor) { + Session session = (Session)getTarget().getSession(); + VariableManager mgr = session.getVariableManager(); + return mgr.createArgument((ArgumentDescriptor)varDesc); + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.cdi.model.ICDIStackFrame#createLocalVariable(org.eclipse.cdt.debug.core.cdi.model.ICDILocalVariableDescriptor) + */ + public ICDILocalVariable createLocalVariable(ICDILocalVariableDescriptor varDesc) throws CDIException { + if (varDesc instanceof ArgumentDescriptor) { + return createArgument((ICDIArgumentDescriptor)varDesc); + } else if (varDesc instanceof LocalVariableDescriptor) { + Session session = (Session)getTarget().getSession(); + VariableManager mgr = session.getVariableManager(); + return mgr.createLocalVariable((LocalVariableDescriptor)varDesc); + } + return null; + } + /** * @see org.eclipse.cdt.debug.core.cdi.model.ICDIStackFrame#getLocation() */ diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Target.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Target.java index 438dc6b809e..53d7c2ebc85 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Target.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Target.java @@ -25,10 +25,14 @@ import org.eclipse.cdt.debug.core.cdi.model.ICDIBreakpoint; import org.eclipse.cdt.debug.core.cdi.model.ICDIExceptionpoint; import org.eclipse.cdt.debug.core.cdi.model.ICDIExpression; import org.eclipse.cdt.debug.core.cdi.model.ICDIFunctionBreakpoint; +import org.eclipse.cdt.debug.core.cdi.model.ICDIGlobalVariable; +import org.eclipse.cdt.debug.core.cdi.model.ICDIGlobalVariableDescriptor; import org.eclipse.cdt.debug.core.cdi.model.ICDIInstruction; import org.eclipse.cdt.debug.core.cdi.model.ICDILineBreakpoint; import org.eclipse.cdt.debug.core.cdi.model.ICDIMemoryBlock; import org.eclipse.cdt.debug.core.cdi.model.ICDIMixedInstruction; +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.ICDIRegisterGroup; import org.eclipse.cdt.debug.core.cdi.model.ICDIRuntimeOptions; import org.eclipse.cdt.debug.core.cdi.model.ICDISharedLibrary; @@ -37,7 +41,6 @@ import org.eclipse.cdt.debug.core.cdi.model.ICDIStackFrame; import org.eclipse.cdt.debug.core.cdi.model.ICDITarget; import org.eclipse.cdt.debug.core.cdi.model.ICDITargetConfiguration; import org.eclipse.cdt.debug.core.cdi.model.ICDIThread; -import org.eclipse.cdt.debug.core.cdi.model.ICDIVariableDescriptor; import org.eclipse.cdt.debug.core.cdi.model.ICDIWatchpoint; import org.eclipse.cdt.debug.mi.core.CoreProcess; import org.eclipse.cdt.debug.mi.core.MIException; @@ -1066,7 +1069,7 @@ public class Target extends SessionObject implements ICDITarget { /* (non-Javadoc) * @see org.eclipse.cdt.debug.core.cdi.model.ICDITarget#getGlobalVariableDescriptors(java.lang.String, java.lang.String, java.lang.String) */ - public ICDIVariableDescriptor getGlobalVariableDescriptors(String filename, String function, String name) throws CDIException { + public ICDIGlobalVariableDescriptor getGlobalVariableDescriptors(String filename, String function, String name) throws CDIException { VariableManager varMgr = ((Session)getSession()).getVariableManager(); return varMgr.getGlobalVariableDescriptor(this, filename, function, name); } @@ -1097,4 +1100,28 @@ public class Target extends SessionObject implements ICDITarget { return fConfiguration; } + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.cdi.model.ICDITarget#createGlobalVariable(org.eclipse.cdt.debug.core.cdi.model.ICDIGlobalVariableDescriptor) + */ + public ICDIGlobalVariable createGlobalVariable(ICDIGlobalVariableDescriptor varDesc) throws CDIException { + if (varDesc instanceof GlobalVariableDescriptor) { + VariableManager varMgr = ((Session)getSession()).getVariableManager(); + return varMgr.createGlobalVariable((GlobalVariableDescriptor)varDesc); + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.cdi.model.ICDITarget#createRegister(org.eclipse.cdt.debug.core.cdi.model.ICDIRegisterDescriptor) + */ + public ICDIRegister createRegister(ICDIRegisterDescriptor varDesc) throws CDIException { + if (varDesc instanceof RegisterDescriptor) { + Session session = (Session)getTarget().getSession(); + RegisterManager mgr = session.getRegisterManager(); + return mgr.createRegister((RegisterDescriptor)varDesc); + } + return null; + } + + } diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Thread.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Thread.java index d005ca8da66..a658e126880 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Thread.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Thread.java @@ -20,6 +20,7 @@ import org.eclipse.cdt.debug.core.cdi.model.ICDIBreakpoint; import org.eclipse.cdt.debug.core.cdi.model.ICDISignal; import org.eclipse.cdt.debug.core.cdi.model.ICDIStackFrame; import org.eclipse.cdt.debug.core.cdi.model.ICDIThread; +import org.eclipse.cdt.debug.core.cdi.model.ICDIThreadStorage; import org.eclipse.cdt.debug.core.cdi.model.ICDIThreadStorageDescriptor; import org.eclipse.cdt.debug.mi.core.MIException; import org.eclipse.cdt.debug.mi.core.MISession; @@ -499,4 +500,16 @@ public class Thread extends CObject implements ICDIThread { return varMgr.getThreadStorageDescriptors(this); } + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.cdi.model.ICDIThread#createThreadStorage(org.eclipse.cdt.debug.core.cdi.model.ICDIThreadStorageDescriptor) + */ + public ICDIThreadStorage createThreadStorage(ICDIThreadStorageDescriptor varDesc) throws CDIException { + if (varDesc instanceof ThreadStorageDescriptor) { + Session session = (Session)getTarget().getSession(); + VariableManager varMgr = session.getVariableManager(); + return varMgr.createThreadStorage((ThreadStorageDescriptor)varDesc); + } + return null; + } + } 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 ff6f4373e20..d179e1e9a6d 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 @@ -25,22 +25,22 @@ import org.eclipse.cdt.debug.mi.core.output.MIVarEvaluateExpressionInfo; */ public class Value extends CObject implements ICDIValue { - protected Variable variable; + protected Variable fVariable; public Value(Variable v) { super((Target)v.getTarget()); - variable = v; + fVariable = v; } - protected Variable getVariable() { - return variable; + protected Variable getVariable() throws CDIException { + return fVariable; } /** * @see org.eclipse.cdt.debug.core.cdi.model.ICDIValue#getTypeName() */ public String getTypeName() throws CDIException { - return variable.getTypeName(); + return getVariable().getTypeName(); } /** @@ -48,15 +48,15 @@ public class Value extends CObject implements ICDIValue { */ public String getValueString() throws CDIException { // make sure the variable is updated. - if (! variable.isUpdated()) { - variable.update(); + if (! getVariable().isUpdated()) { + getVariable().update(); } String result = ""; //$NON-NLS-1$ MISession mi = ((Target)getTarget()).getMISession(); CommandFactory factory = mi.getCommandFactory(); MIVarEvaluateExpression var = - factory.createMIVarEvaluateExpression(variable.getMIVar().getVarName()); + factory.createMIVarEvaluateExpression(getVariable().getMIVar().getVarName()); try { mi.postCommand(var); MIVarEvaluateExpressionInfo info = var.getMIVarEvaluateExpressionInfo(); @@ -74,7 +74,7 @@ public class Value extends CObject implements ICDIValue { * @see org.eclipse.cdt.debug.core.cdi.model.ICDIValue#getVariables() */ public int getChildrenNumber() throws CDIException { - return variable.getMIVar().getNumChild(); + return getVariable().getMIVar().getNumChild(); } /** @@ -106,14 +106,14 @@ public class Value extends CObject implements ICDIValue { * @see org.eclipse.cdt.debug.core.cdi.model.ICDIValue#getVariables() */ public ICDIVariable[] getVariables() throws CDIException { - return variable.getChildren(); + return getVariable().getChildren(); } /* (non-Javadoc) * @see org.eclipse.cdt.debug.core.cdi.model.ICDIValue#getType() */ public ICDIType getType() throws CDIException { - return variable.getType(); + return getVariable().getType(); } } 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 65e237e3687..abf53f959bf 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 @@ -422,11 +422,19 @@ public abstract class Variable extends VariableDescriptor implements ICDIVariabl public boolean equals(ICDIVariable var) { if (var instanceof Variable) { Variable variable = (Variable) var; - return fMiVar.getVarName().equals(variable.getMIVar().getVarName()); + return equals(variable); } return super.equals(var); } + /** + * @param variable + * @return + */ + public boolean equals(Variable variable) { + return fMiVar.getVarName().equals(variable.getMIVar().getVarName()); + } + /* (non-Javadoc) * @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#dispose() */ diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/VariableDescriptor.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/VariableDescriptor.java index 089d14c6d54..439e61d6475 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/VariableDescriptor.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/VariableDescriptor.java @@ -383,13 +383,13 @@ public abstract class VariableDescriptor extends CObject implements ICDIVariable return mgr.getVariableDescriptorAsType(this, type); } - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariableDescriptor#createVariable() - */ - public ICDIVariable createVariable() throws CDIException { - Session session = (Session)getTarget().getSession(); - VariableManager mgr = session.getVariableManager(); - return mgr.createVariable(this); - } +// /* (non-Javadoc) +// * @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariableDescriptor#createVariable() +// */ +// public ICDIVariable createVariable() throws CDIException { +// Session session = (Session)getTarget().getSession(); +// VariableManager mgr = session.getVariableManager(); +// return mgr.createVariable(this); +// } } diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/type/ArrayValue.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/type/ArrayValue.java index 8e9debc5919..e4813e91cb0 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/type/ArrayValue.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/type/ArrayValue.java @@ -44,9 +44,9 @@ public class ArrayValue extends DerivedValue implements ICDIArrayValue { * GDB time to respond. In the end perhaps we want a UI for this. As it * is, let's just make up a number that's 5 seconds for us plus one * second for every 128 entries. */ - int timeout = variable.getMIVar().getNumChild() * 8 + 5000; + int timeout = getVariable().getMIVar().getNumChild() * 8 + 5000; - return variable.getChildren(timeout); + return getVariable().getChildren(timeout); } /** @@ -60,6 +60,7 @@ public class ArrayValue extends DerivedValue implements ICDIArrayValue { //} // Overload for registers. + Variable variable = getVariable(); if (variable instanceof Register) { ICDIVariable[] vars = getVariables();