From 4907b4f35a582cb3d80cd9d7610a3b40fc991cae Mon Sep 17 00:00:00 2001 From: Mikhail Khodjaiants Date: Fri, 6 Sep 2002 21:13:57 +0000 Subject: [PATCH] Implementation of variable expansion. --- .../internal/core/model/CLocalVariable.java | 21 ++++---- .../cdt/debug/internal/core/model/CValue.java | 51 ++++++++++++++++++- 2 files changed, 60 insertions(+), 12 deletions(-) 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 index d7cb1c41fd0..dbf250a9d0e 100644 --- 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 @@ -16,6 +16,7 @@ import org.eclipse.cdt.debug.core.cdi.model.ICDIValue; import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable; import org.eclipse.debug.core.DebugEvent; import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.model.IDebugTarget; import org.eclipse.debug.core.model.IValue; /** @@ -33,18 +34,18 @@ public class CLocalVariable extends CModificationVariable private ICDIVariable fCDIVariable; /** - * The stack frame this variable is contained in. + * The parent object this variable is contained in. */ - private CStackFrame fStackFrame; + private CDebugElement fParent; /** * Constructor for CLocalVariable. * @param target */ - public CLocalVariable( CStackFrame stackFrame, ICDIVariable cdiVariable ) + public CLocalVariable( CDebugElement parent, ICDIVariable cdiVariable ) { - super( (CDebugTarget)stackFrame.getDebugTarget() ); - fStackFrame = stackFrame; + super( (CDebugTarget)parent.getDebugTarget() ); + fParent = parent; fCDIVariable = cdiVariable; } @@ -68,8 +69,8 @@ public class CLocalVariable extends CModificationVariable */ protected ICDIValue retrieveValue() throws DebugException, CDIException { - return ( getStackFrame().isSuspended() ) ? - getCDIVariable().getValue() : getLastKnownValue(); + return ( ((IDebugTarget)getParent().getDebugTarget()).isSuspended() ) ? + getCDIVariable().getValue() : getLastKnownValue(); } /* (non-Javadoc) @@ -126,9 +127,9 @@ public class CLocalVariable extends CModificationVariable * * @return the stack frame */ - protected CStackFrame getStackFrame() + protected CDebugElement getParent() { - return fStackFrame; + return fParent; } /* (non-Javadoc) @@ -160,7 +161,7 @@ public class CLocalVariable extends CModificationVariable if ( !getValue().hasVariables() ) { setChanged( true ); - getStackFrame().fireChangeEvent( DebugEvent.CONTENT ); + getParent().fireChangeEvent( DebugEvent.CONTENT ); } } catch( DebugException e ) 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 5476a20391c..65f3117e94a 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 @@ -6,8 +6,15 @@ package org.eclipse.cdt.debug.internal.core.model; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.model.ICDIValue; +import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.model.IValue; import org.eclipse.debug.core.model.IVariable; @@ -25,6 +32,11 @@ public class CValue extends CDebugElement implements IValue */ private ICDIValue fValue; + /** + * List of child variables. + */ + private List fVariables = Collections.EMPTY_LIST; + /** * Constructor for CValue. * @param target @@ -69,7 +81,7 @@ public class CValue extends CDebugElement implements IValue */ public boolean isAllocated() throws DebugException { - return false; + return true; } /* (non-Javadoc) @@ -77,7 +89,25 @@ public class CValue extends CDebugElement implements IValue */ public IVariable[] getVariables() throws DebugException { - return null; + List list = getVariables0(); + return (IVariable[])list.toArray( new IVariable[list.size()] ); + } + + protected synchronized List getVariables0() throws DebugException + { + if ( !isAllocated() ) + return Collections.EMPTY_LIST; + if ( fVariables.size() == 0 ) + { + List vars = getCDIVariables(); + fVariables = new ArrayList( vars.size() ); + Iterator it = vars.iterator(); + while( it.hasNext() ) + { + fVariables.add( new CLocalVariable( this, (ICDIVariable)it.next() ) ); + } + } + return fVariables; } /* (non-Javadoc) @@ -114,4 +144,21 @@ public class CValue extends CDebugElement implements IValue { return fValue; } + + protected List getCDIVariables() throws DebugException + { + try + { + ICDIValue value = getUnderlyingValue(); + if ( value != null ) + { + return Arrays.asList( value.getVariables() ); + } + } + catch( CDIException e ) + { + targetRequestFailed( "Operation failed. Reason: ", e ); + } + return Collections.EMPTY_LIST; + } }