diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/IStackFrameInfo.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/IStackFrameInfo.java index 7d5031a6f8e..65958648035 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/IStackFrameInfo.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/IStackFrameInfo.java @@ -6,6 +6,8 @@ package org.eclipse.cdt.debug.core; +import org.eclipse.debug.core.model.IVariable; + /** * * Provides the access to the stack frame information. @@ -51,4 +53,11 @@ public interface IStackFrameInfo * @return the level of this stack frame */ int getLevel(); + + /** + * Returns the arguments of this stack frame. + * + * @return the arguments of this stack frame + */ + IVariable[] getArguments(); } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CLocalVariable.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CLocalVariable.java index 612915355aa..2744a571f48 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CLocalVariable.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CLocalVariable.java @@ -116,6 +116,11 @@ public class CLocalVariable extends CModificationVariable return fCDIVariable; } + protected void setCDIVariable( ICDIVariable newVar ) + { + fCDIVariable = newVar; + } + /** * Returns the stack frame this variable is contained in. * @@ -152,7 +157,11 @@ public class CLocalVariable extends CModificationVariable try { setValue( getCurrentValue() ); - fireChangeEvent( DebugEvent.CONTENT ); + if ( !getValue().hasVariables() ) + { + setChanged( true ); + getStackFrame().fireChangeEvent( DebugEvent.CONTENT ); + } } catch( DebugException e ) { diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CStackFrame.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CStackFrame.java index 0ea1d4cfe8a..d0d0bbde286 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CStackFrame.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CStackFrame.java @@ -12,11 +12,13 @@ import java.util.Arrays; import java.util.Iterator; import java.util.List; +import org.eclipse.cdt.debug.core.CDebugCorePlugin; import org.eclipse.cdt.debug.core.IStackFrameInfo; import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.ICDILocation; 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.model.ICDIArgument; import org.eclipse.cdt.debug.core.cdi.model.ICDIStackFrame; import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable; import org.eclipse.debug.core.DebugException; @@ -52,7 +54,7 @@ public class CStackFrame extends CDebugElement private CThread fThread; /** - * Visible variables. + * List of visible variable (includes arguments). */ private List fVariables; @@ -68,7 +70,7 @@ public class CStackFrame extends CDebugElement public CStackFrame( CThread thread, ICDIStackFrame cdiFrame ) { super( (CDebugTarget)thread.getDebugTarget() ); - fCDIStackFrame = cdiFrame; + setCDIStackFrame( cdiFrame ); setThread( thread ); getCDISession().getEventManager().addEventListener( this ); } @@ -116,18 +118,21 @@ public class CStackFrame extends CDebugElement */ protected void updateVariables() throws DebugException { - List locals = null; - locals = getAllCDIVariables(); + List locals = getAllCDIVariables(); int localIndex = -1; int index = 0; while( index < fVariables.size() ) { CLocalVariable local = (CLocalVariable)fVariables.get( index ); - localIndex = locals.indexOf( local.getCDIVariable() ); - if ( localIndex >= 0 ) + ICDIVariable var = findVariable( locals, local.getCDIVariable() ); + if ( var != null ) { // update variable with new underling CDI LocalVariable - locals.remove( localIndex ); + if ( !var.equals( local.getCDIVariable() ) ) + { + local.setCDIVariable( var ); + } + locals.remove( var ); index++; } else @@ -480,7 +485,40 @@ public class CStackFrame extends CDebugElement */ protected static boolean equalFrame( ICDIStackFrame frameOne, ICDIStackFrame frameTwo ) { - return ( frameOne != null && frameTwo != null && frameOne.getLocation().equals( frameTwo.getLocation() ) ); + if ( frameOne == null || frameTwo == null ) + return false; + ICDILocation loc1 = frameOne.getLocation(); + ICDILocation loc2 = frameTwo.getLocation(); + if ( loc1 == null || loc2 == null ) + return false; + if ( loc1.getFile() != null && loc1.getFile().length() > 0 && + loc2.getFile() != null && loc2.getFile().length() > 0 && + loc1.getFile().equals( loc2.getFile() ) ) + + { + if ( loc1.getFunction() != null && loc1.getFunction().length() > 0 && + loc2.getFunction() != null && loc2.getFunction().length() > 0 && + loc1.getFunction().equals( loc2.getFunction() ) ) + return true; + } + if ( ( loc1.getFile() == null || loc1.getFile().length() < 1 ) && + ( loc2.getFile() == null || loc2.getFile().length() < 1 ) ) + + { + if ( loc1.getFunction() != null && loc1.getFunction().length() > 0 && + loc2.getFunction() != null && loc2.getFunction().length() > 0 && + loc1.getFunction().equals( loc2.getFunction() ) ) + return true; + } + if ( ( loc1.getFile() == null || loc1.getFile().length() < 1 ) && + ( loc2.getFile() == null || loc2.getFile().length() < 1 ) && + ( loc1.getFunction() == null || loc1.getFunction().length() < 1 ) && + ( loc2.getFunction() == null || loc2.getFunction().length() < 1 ) ) + { + if ( loc1.getAddress() == loc2.getAddress() ) + return true; + } + return false; } protected boolean exists() throws DebugException @@ -575,6 +613,7 @@ public class CStackFrame extends CDebugElement { ((CVariable)it.next()).dispose(); } + fVariables = null; } /* (non-Javadoc) * @see org.eclipse.cdt.debug.core.IStackFrameInfo#getAddress() @@ -614,4 +653,67 @@ public class CStackFrame extends CDebugElement { return getCDIStackFrame().getLocation().getLineNumber(); } + + /* + * @see org.eclipse.cdt.debug.core.IStackFrameInfo#getArguments() + */ + public IVariable[] getArguments() + { + ArrayList list = new ArrayList(); + IVariable[] vars = new IVariable[0]; + try + { + vars = getVariables(); + } + catch( DebugException e ) + { + CDebugCorePlugin.log( e ); + } + for ( int i = 0; i < vars.length; ++i ) + { + if ( vars[i] instanceof CLocalVariable && + ((CLocalVariable)vars[i]).getCDIVariable() instanceof ICDIArgument ) + { + list.add( vars[i] ); + } + } + return (IVariable[])list.toArray( new IVariable[list.size()] ); + } + + protected synchronized void preserveVariables() + { + if ( fVariables == null ) + return; + try + { + Iterator it = fVariables.iterator(); + while( it.hasNext() ) + { + ((CVariable)it.next()).setChanged( false ); + } + } + catch( DebugException e ) + { + CDebugCorePlugin.log( e ); + } + } + + // temporary solution + protected ICDIVariable findVariable( List list, ICDIVariable var ) + { + Iterator it = list.iterator(); + while( it.hasNext() ) + { + ICDIVariable newVar = (ICDIVariable)it.next(); + try + { + if ( newVar.getName().equals( var.getName() ) ) + return newVar; + } + catch( CDIException e ) + { + } + } + return null; + } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CThread.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CThread.java index 6bbb7698a76..fb0a0261b2e 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CThread.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CThread.java @@ -650,8 +650,13 @@ public class CThread extends CDebugElement * * @see computeStackFrames() */ - protected void preserveStackFrames() + protected synchronized void preserveStackFrames() { + Iterator it = fStackFrames.iterator(); + while( it.hasNext() ) + { + ((CStackFrame)it.next()).preserveVariables(); + } setRefreshChildren( true ); } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CValue.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CValue.java index cdc6aabb321..9e1509cfc60 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CValue.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CValue.java @@ -6,6 +6,7 @@ package org.eclipse.cdt.debug.internal.core; +import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.model.ICDIValue; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.model.IValue; @@ -47,7 +48,20 @@ public class CValue extends CDebugElement implements IValue */ public String getValueString() throws DebugException { - return null; + String result = null; + if ( getUnderlyingValue() != null ) + { + try + { + result = getUnderlyingValue().getValueString(); + } + catch( CDIException e ) + { + // change this + requestFailed( "", e ); + } + } + return result; } /* (non-Javadoc) diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CVariable.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CVariable.java index 1605013e781..3aa38f0d4d8 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CVariable.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CVariable.java @@ -38,6 +38,11 @@ public abstract class CVariable extends CDebugElement */ private int fLastChangeIndex = -1; + /** + * Change flag. + */ + private boolean fChanged = false; + /** * Constructor for CVariable. * @param target @@ -62,24 +67,6 @@ public abstract class CVariable extends CDebugElement { fValue = CValue.createValue( (CDebugTarget)getDebugTarget(), currentValue ); } - else - { - ICDIValue previousValue = fValue.getUnderlyingValue(); - if ( currentValue == previousValue ) - { - return fValue; - } - if ( previousValue == null || currentValue == null ) - { - fValue = CValue.createValue( (CDebugTarget)getDebugTarget(), currentValue ); - setChangeCount( ((CDebugTarget)getDebugTarget()).getSuspendCount()); - } - else if ( !previousValue.equals( currentValue ) ) - { - fValue = CValue.createValue( (CDebugTarget)getDebugTarget(), currentValue ); - setChangeCount( ((CDebugTarget)getDebugTarget()).getSuspendCount()); - } - } return fValue; } @@ -88,7 +75,7 @@ public abstract class CVariable extends CDebugElement */ public boolean hasValueChanged() throws DebugException { - return getChangeCount() == ((CDebugTarget)getDebugTarget()).getSuspendCount(); + return ( getValue().hasVariables() ) ? false : fChanged; } /* (non-Javadoc) @@ -209,4 +196,20 @@ public abstract class CVariable extends CDebugElement { getCDISession().getEventManager().removeEventListener( this ); } + + protected synchronized void setChanged( boolean changed ) throws DebugException + { + if ( getValue().hasVariables() ) + { + IVariable[] vars = getValue().getVariables(); + for ( int i = 0; i < vars.length; ++i ) + { + ((CVariable)vars[i]).setChanged( changed ); + } + } + else + { + fChanged = changed; + } + } } diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDTDebugModelPresentation.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDTDebugModelPresentation.java index 6fae7766a44..932fefa4ad3 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDTDebugModelPresentation.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDTDebugModelPresentation.java @@ -24,6 +24,7 @@ import org.eclipse.debug.core.model.IStackFrame; import org.eclipse.debug.core.model.ITerminate; import org.eclipse.debug.core.model.IThread; import org.eclipse.debug.core.model.IValue; +import org.eclipse.debug.core.model.IVariable; import org.eclipse.debug.ui.IDebugModelPresentation; import org.eclipse.debug.ui.IValueDetailListener; import org.eclipse.jface.viewers.LabelProvider; @@ -151,6 +152,12 @@ public class CDTDebugModelPresentation extends LabelProvider StringBuffer label = new StringBuffer(); try { + if ( element instanceof IVariable ) + { + label.append( getVariableText( (IVariable)element ) ); + return label.toString(); + } + if ( element instanceof IStackFrame ) { label.append( getStackFrameText( (IStackFrame)element, showQualified ) ); @@ -268,6 +275,19 @@ public class CDTDebugModelPresentation extends LabelProvider return stackFrame.getName(); } + protected String getVariableText( IVariable var ) throws DebugException + { + // temporary + String label = new String(); + if ( var != null ) + { + label += var.getName(); + IValue value = var.getValue(); + label += "= " + value.getValueString(); + } + return label; + } + /** * Plug in the single argument to the resource String for the key to * get a formatted resource String.